Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mfd: adp5585: Only add devices given in FW

Not all devices (features) of the adp5585 device are mandatory to be
used in all platforms. Hence, check what's given in FW and dynamically
create the mfd_cell array to be given to devm_mfd_add_devices().

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20250701-dev-adp5589-fw-v7-2-b1fcfe9e9826@analog.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Nuno Sá and committed by
Lee Jones
175f1990 09d55a54

+29 -9
+29 -9
drivers/mfd/adp5585.c
··· 17 17 #include <linux/regmap.h> 18 18 #include <linux/types.h> 19 19 20 - static const struct mfd_cell adp5585_devs[] = { 20 + enum { 21 + ADP5585_DEV_GPIO, 22 + ADP5585_DEV_PWM, 23 + ADP5585_DEV_MAX 24 + }; 25 + 26 + static const struct mfd_cell adp5585_devs[ADP5585_DEV_MAX] = { 21 27 { .name = "adp5585-gpio", }, 22 28 { .name = "adp5585-pwm", }, 23 29 }; ··· 116 110 }, 117 111 }; 118 112 113 + static int adp5585_add_devices(struct device *dev) 114 + { 115 + int ret; 116 + 117 + if (device_property_present(dev, "#pwm-cells")) { 118 + ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, 119 + &adp5585_devs[ADP5585_DEV_PWM], 1, NULL, 0, NULL); 120 + if (ret) 121 + return dev_err_probe(dev, ret, "Failed to add PWM device\n"); 122 + } 123 + 124 + if (device_property_present(dev, "#gpio-cells")) { 125 + ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, 126 + &adp5585_devs[ADP5585_DEV_GPIO], 1, NULL, 0, NULL); 127 + if (ret) 128 + return dev_err_probe(dev, ret, "Failed to add GPIO device\n"); 129 + } 130 + 131 + return 0; 132 + } 133 + 119 134 static int adp5585_i2c_probe(struct i2c_client *i2c) 120 135 { 121 136 const struct regmap_config *regmap_config; ··· 165 138 return dev_err_probe(&i2c->dev, -ENODEV, 166 139 "Invalid device ID 0x%02x\n", id); 167 140 168 - ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO, 169 - adp5585_devs, ARRAY_SIZE(adp5585_devs), 170 - NULL, 0, NULL); 171 - if (ret) 172 - return dev_err_probe(&i2c->dev, ret, 173 - "Failed to add child devices\n"); 174 - 175 - return 0; 141 + return adp5585_add_devices(&i2c->dev); 176 142 } 177 143 178 144 static int adp5585_suspend(struct device *dev)