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

regulator: Allow parsing custom properties when using simplified DT parsing

When drivers use simplified DT parsing method (they provide
'regulator_desc.of_match') they still may want to parse custom
properties for some of the regulators. For example some of the
regulators support GPIO enable control.

Add a driver-supplied callback for such case. This way the regulator
core parses common bindings offloading a lot of code from drivers and
still custom properties may be used.

The callback, called for each parsed regulator, may modify the
'regulator_config' initially passed to regulator_register().

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Mark Brown
bfa21a0d 1b3de223

+27 -1
+1 -1
drivers/regulator/core.c
··· 3635 3635 return ERR_PTR(-ENOMEM); 3636 3636 } 3637 3637 3638 - init_data = regulator_of_get_init_data(dev, regulator_desc, 3638 + init_data = regulator_of_get_init_data(dev, regulator_desc, config, 3639 3639 &rdev->dev.of_node); 3640 3640 if (!init_data) { 3641 3641 init_data = config->init_data;
+2
drivers/regulator/internal.h
··· 38 38 #ifdef CONFIG_OF 39 39 struct regulator_init_data *regulator_of_get_init_data(struct device *dev, 40 40 const struct regulator_desc *desc, 41 + struct regulator_config *config, 41 42 struct device_node **node); 42 43 #else 43 44 static inline struct regulator_init_data * 44 45 regulator_of_get_init_data(struct device *dev, 45 46 const struct regulator_desc *desc, 47 + struct regulator_config *config, 46 48 struct device_node **node) 47 49 { 48 50 return NULL;
+11
drivers/regulator/of_regulator.c
··· 270 270 271 271 struct regulator_init_data *regulator_of_get_init_data(struct device *dev, 272 272 const struct regulator_desc *desc, 273 + struct regulator_config *config, 273 274 struct device_node **node) 274 275 { 275 276 struct device_node *search, *child; ··· 306 305 "failed to parse DT for regulator %s\n", 307 306 child->name); 308 307 break; 308 + } 309 + 310 + if (desc->of_parse_cb) { 311 + if (desc->of_parse_cb(child, desc, config)) { 312 + dev_err(dev, 313 + "driver callback failed to parse DT for regulator %s\n", 314 + child->name); 315 + init_data = NULL; 316 + break; 317 + } 309 318 } 310 319 311 320 of_node_get(child);
+13
include/linux/regulator/driver.h
··· 21 21 22 22 struct regmap; 23 23 struct regulator_dev; 24 + struct regulator_config; 24 25 struct regulator_init_data; 25 26 struct regulator_enable_gpio; 26 27 ··· 206 205 * @supply_name: Identifying the regulator supply 207 206 * @of_match: Name used to identify regulator in DT. 208 207 * @regulators_node: Name of node containing regulator definitions in DT. 208 + * @of_parse_cb: Optional callback called only if of_match is present. 209 + * Will be called for each regulator parsed from DT, during 210 + * init_data parsing. 211 + * The regulator_config passed as argument to the callback will 212 + * be a copy of config passed to regulator_register, valid only 213 + * for this particular call. Callback may freely change the 214 + * config but it cannot store it for later usage. 215 + * Callback should return 0 on success or negative ERRNO 216 + * indicating failure. 209 217 * @id: Numerical identifier for the regulator. 210 218 * @ops: Regulator operations table. 211 219 * @irq: Interrupt number for the regulator. ··· 261 251 const char *supply_name; 262 252 const char *of_match; 263 253 const char *regulators_node; 254 + int (*of_parse_cb)(struct device_node *, 255 + const struct regulator_desc *, 256 + struct regulator_config *); 264 257 int id; 265 258 bool continuous_voltage_range; 266 259 unsigned n_voltages;