Device tree support for regulators
Subsystems (4)
v2 cover Device tree support for regulators
Hi Mark, Grant,
I have reworked the regulator-dt-suppport series based on your reviews and also split it so I remove any dependency with the omap specific dt conversion for i2c/twl. So this latest series is based on mainline 3.1-rc9.
I will post the twl-regulator driver adaptation to dt and the omap-panda/omap-sdp board regulator data being passed from dt as a seperate series.
changes in v2:
-1- removed the int to u32 convertions as -ve voltages do exist -2- merged patches to support fixed voltage regulator dt adaptation -3- added support for regulator_get() without a device associated (ex: cpufreq) -4- used same binding for regulator<->consumer and regulator<->parent mapping
regards,
Rajendra
Rajendra Nayak (5):
regulator: twl: Remove hardcoded board constraints from driver
dt: add empty dt helpers for non-dt build
regulator: helper routine to extract regulator_init_data
regulator: adapt fixed regulator driver to dt
regulator: map consumer regulator based on device tree
.../bindings/regulator/fixed-regulator.txt | 24 +++++ .../devicetree/bindings/regulator/regulator.txt | 44 +++++++++ drivers/regulator/Kconfig | 8 ++ drivers/regulator/Makefile | 1 + drivers/regulator/core.c | 91 ++++++++++++++++--- drivers/regulator/fixed.c | 58 ++++++++++++ drivers/regulator/of_regulator.c | 93 ++++++++++++++++++++ drivers/regulator/twl-regulator.c | 8 -- include/linux/of.h | 19 ++++ include/linux/regulator/driver.h | 2 + include/linux/regulator/of_regulator.h | 21 +++++ 11 files changed, 346 insertions(+), 23 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/fixed-regulator.txt create mode 100644 Documentation/devicetree/bindings/regulator/regulator.txt create mode 100644 drivers/regulator/of_regulator.c create mode 100644 include/linux/regulator/of_regulator.h
PATCH v2 1/5 regulator: twl: Remove hardcoded board constraints from driver
Remove the hardcoded .valid_modes_mask and .valid_ops_mask for each regulator from the twl driver and let the boards pass it.
--- drivers/regulator/twl-regulator.c | 8 -------- 1 files changed, 0 insertions(+), 8 deletions(-)
drivers/regulator/twl-regulator.c +0 -8
@@ -1027,14 +1027,6 @@ static int __devinit twlreg_probe(struct platform_device *pdev)/* copy the features into regulator data */ info->features = (unsigned long )initdata->driver_data; -/* Constrain board-specific capabilities according to what -* this driver and the chip itself can actually do. -*/ - c = &initdata->constraints; - c->valid_modes_mask &=REGULATOR_MODE_NORMAL |REGULATOR_MODE_STANDBY ; - c->valid_ops_mask &=REGULATOR_CHANGE_VOLTAGE - |REGULATOR_CHANGE_MODE - |REGULATOR_CHANGE_STATUS ;switch (pdev->id) {case TWL4030_REG_VIO :case TWL4030_REG_VDD1 :
Signature · 1 line
1.7.1
Re: [PATCH v2 1/5] regulator: twl: Remove hardcoded board constraints from driver
Quoted 5 lines · Rajendra Nayak
Remove the hardcoded .valid_modes_mask and .valid_ops_mask for each regulator from the twl driver and let the boards pass it.
Signed-off-by Rajendra Nayak <[email protected]>Acked-by Mark Brown <[email protected]>
Please update this changelog - as I said in reply to your previous posting this isn't actually hardcoding anything, it's dropping things from the constraints which the hardware doesn't support.
Re: [PATCH v2 1/5] regulator: twl: Remove hardcoded board constraints from driver
Quoted 10 lines · Mark Brown
Quoted 5 lines · Rajendra Nayak
Remove the hardcoded .valid_modes_mask and .valid_ops_mask for each regulator from the twl driver and let the boards pass it.
Signed-off-by Rajendra Nayak<[email protected]>Acked-by Mark Brown<[email protected]>Please update this changelog - as I said in reply to your previous posting this isn't actually hardcoding anything, it's dropping things from the constraints which the hardware doesn't support.
Looks like I completely missed the "&=" and your comment on the previous posting. Looking at it now, seems to me this patch is just un-necessary and what the driver seems to be doing (preventing users from setting flags which the hardware does not support) seems perfectly fine. I will just go ahead and drop this patch.
PATCH v2 2/5 dt: add empty dt helpers for non-dt build
In reply to Rajendra NayakAdd empty of_device_is_compatible(), of_find_property() and of_parse_phandle() for non-dt builds to work.
--- include/linux/of.h | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
include/linux/of.h +19 -0
@@ -263,6 +263,25 @@ static inline const void *of_get_property(const struct device_node *node,return NULL ; } +static inline int of_device_is_compatible (const struct device_node *device, +const char *name) +{ +return 0 ; +} + +static inline struct property *of_find_property (const struct device_node *np, +const char *name, +int *lenp) +{ +return NULL ; +} + +static inline struct device_node *of_parse_phandle (struct device_node *np, +const char *phandle_name, +int index) +{ +return NULL ; +}#endif /* CONFIG_OF */ static inline int of_property_read_u32(const struct device_node *np,
Signature · 1 line
1.7.1
Grant Likely
AppliedRe: [PATCH v2 2/5] dt: add empty dt helpers for non-dt build
Quoted 4 lines · Rajendra Nayak
Add empty
of_device_is_compatible(),of_find_property()andof_parse_phandle()for non-dt builds to work.Signed-off-by Rajendra Nayak <[email protected]>
Applied, thanks. The of_find_property() already had an empty version in devicetree/next, but I've picked up the other two.
g.
Quoted 42 lines
--- include/linux/of.h | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)include/linux/of.h +19
-0@@ -263,6 +263,25 @@ static inline const void *of_get_property(const struct device_node *node,return NULL ; } +static inline int of_device_is_compatible (const struct device_node *device, +const char *name) +{ +return 0 ; +} + +static inline struct property *of_find_property (const struct device_node *np, +const char *name, +int *lenp) +{ +return NULL ; +} + +static inline struct device_node *of_parse_phandle (struct device_node *np, +const char *phandle_name, +int index) +{ +return NULL ; +}#endif /* CONFIG_OF */ static inline int of_property_read_u32(const struct device_node *np,Signature · 7 lines
1.7.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 3/5 regulator: helper routine to extract regulator_init_data
In reply to Rajendra NayakThe helper routine is meant to be used by regulator drivers to extract the regulator_init_data structure from the data that is passed from device tree.
'consumer_supplies' which is part of regulator_init_data is not extracted as the regulator consumer mappings are passed through DT differently, implemented in subsequent patches.
Similarly the regulator<-->parent/supply mapping is handled in subsequent patches.
Also add documentation for regulator bindings to be used to pass regulator_init_data struct information from device tree.
--- .../devicetree/bindings/regulator/regulator.txt | 44 +++++++++ drivers/regulator/Kconfig | 8 ++ drivers/regulator/Makefile | 1 + drivers/regulator/of_regulator.c | 93 ++++++++++++++++++++ include/linux/regulator/of_regulator.h | 21 +++++ 5 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/regulator.txt create mode 100644 drivers/regulator/of_regulator.c create mode 100644 include/linux/regulator/of_regulator.h
Documentation/devicetree/bindings/regulator/regulator.txt new file +44 -0
@@ -0,0 +1,44 @@ +Voltage/Current Regulators + +Optional properties: +- regulator-min-uV: smallest voltage consumers may set +- regulator-max-uV: largest voltage consumers may set +- regulator-uV-offset: Offset applied to voltages to compensate for voltage drops +- regulator-min-uA: smallest current consumers may set +- regulator-max-uA: largest current consumers may set +- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software +- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator +- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabled +- regulator-boot-on: bootloader/firmware enabled regulator +- <name>-supply: phandle to the parent supply/regulator node + +Example: + + xyzreg: regulator at 0 { + regulator-min-uV = <1000000>; + regulator-max-uV = <2500000>; + regulator-mode-fast; + regulator-change-voltage; + regulator-always-on; + vin-supply = <&vin>; + }; + +The same binding used by a regulator to reference its +supply can be used by any consumer to reference its +regulator/supply + +Example of a device node referencing a regulator node, + + devicenode: node at 0x0 { + ... + ... + <name>-supply = <&xyzreg>; + };
drivers/regulator/Kconfig +8 -0
@@ -64,6 +64,14 @@ config REGULATOR_USERSPACE_CONSUMER If unsure, say no. +config OF_REGULATOR + tristate "OF regulator helpers" + depends on OF + default y if OF + help + OpenFirmware regulator framework helper routines that can + used by regulator drivers to extract data from device tree. + config REGULATOR_BQ24022 tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" help
drivers/regulator/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_REGULATOR) += core.o dummy.o obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o +obj-$(CONFIG_OF_REGULATOR) += of_regulator.o obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
drivers/regulator/of_regulator.c new file +93 -0
93 lines not on this page · raw message
include/linux/regulator/of_regulator.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* OpenFirmware regulator support routines +* +*/ + +#ifndef __LINUX_OF_REG_H +#define __LINUX_OF_REG_H + +#if defined(CONFIG_OF_REGULATOR ) +extern struct regulator_init_data + *of_get_regulator_init_data (struct device *dev); +#else +static inline struct regulator_init_data + *of_get_regulator_init_data (struct device *dev) +{ +return NULL ; +} +#endif /* CONFIG_OF_REGULATOR */ + +#endif /* __LINUX_OF_REG_H */ +
Signature · 1 line
1.7.1
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 11 lines · Rajendra Nayak
+- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software +- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator +- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabled
Thinking about this I'm not sure that these should go in the device tree, they're as much talking about what Linux is able to cope with as they are talking about what the hardware is able to do. Sometimes they'll be fixed by the design but they are sometimes also restricted by what the software is currently capable of. DRMS is a prime example here, it depends on how good we are at telling the API about how much current we're using.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 14 lines · Mark Brown
Quoted 11 lines · Rajendra Nayak
+- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software +- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator +- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabled
Quoted 7 lines
Thinking about this I'm not sure that these should go in the device tree, they're as much talking about what Linux is able to cope with as they are talking about what the hardware is able to do. Sometimes they'll be fixed by the design but they are sometimes also restricted by what the software is currently capable of. DRMS is a prime example here, it depends on how good we are at telling the API about how much current we're using.
So is there another way of passing these, if not through device tree? There are other linux specific things that need to be passed to the framework as well, like the state of the regulator in the various linux specific suspend states, like standby/mem/disk.
So if these can't be passed through device tree, should they still be passed in some way through platform_data? Or is it best to identify the bindings as being linux specific and not generic by appending a "linux," to the bindings.
Grant, need some help and advice.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 32 lines · Rajendra Nayak
Quoted 14 lines · Mark Brown
Quoted 11 lines · Rajendra Nayak
+- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software +- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator +- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabledQuoted 7 lines
Thinking about this I'm not sure that these should go in the device tree, they're as much talking about what Linux is able to cope with as they are talking about what the hardware is able to do. Sometimes they'll be fixed by the design but they are sometimes also restricted by what the software is currently capable of. DRMS is a prime example here, it depends on how good we are at telling the API about how much current we're using.
So is there another way of passing these, if not through device tree? There are other linux specific things that need to be passed to the framework as well, like the state of the regulator in the various linux specific suspend states, like standby/mem/disk.
So if these can't be passed through device tree, should they still be passed in some way throughplatform_data? Or is it best to identify the bindings as being linux specific and not generic by appending a "linux," to the bindings.
Quoted 2 lines
Grant, need some help and advice.
I can't really help much here. If it is a property of the hardware, then it absolutely needs to be in the device tree. If it is a limitation of Linux, or the Linux driver, then I would say that it should be encoded in the driver. I don't understand enough of the problem space of regulators to give a good answer about what you should do.
These *sound* like flags that the driver would set based on its own capabilities; in which case it is something that would be encoded directly into the driver.
g.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 3 lines · Grant Likely
These *sound* like flags that the driver would set based on its own capabilities; in which case it is something that would be encoded directly into the driver.
They're almost entirely a combination of system specifics and software capabilities - it's not even reliably one or the other. For example the ability to switch regulator modes is going to depend on a combination of the modes a specific regulator offers, the set of things connected to the regulator in the current system (not all of which will be software visible), how good all the connected consumer drivers are at providing accurate information about what they're going to need from the system in terms of quality of regulation and current draw and how good the board design is in making these things reality.
For robustness (for some of these things if you get it wrong we're talking catastrophic hardware failure) the Linux regulator API is extremely conservative and won't touch the hardware unless explicitly told that a specific thing is OK on a given board.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Rajendra NayakQuoted 79 lines · Rajendra Nayak
The helper routine is meant to be used by regulator drivers to extract the
regulator_init_datastructure from the data that is passed from device tree.
'consumer_supplies' which is part ofregulator_init_datais not extracted as the regulator consumer mappings are passed through DT differently, implemented in subsequent patches.
Similarly the regulator<-->parent/supply mapping is handled in subsequent patches.Also add documentation for regulator bindings to be used to pass
regulator_init_datastruct information from device tree.Signed-off-by Rajendra Nayak <[email protected]>--- .../devicetree/bindings/regulator/regulator.txt | 44 +++++++++ drivers/regulator/Kconfig | 8 ++ drivers/regulator/Makefile | 1 + drivers/regulator/of_regulator.c | 93 ++++++++++++++++++++ include/linux/regulator/of_regulator.h | 21 +++++ 5 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/regulator.txt create mode 100644 drivers/regulator/of_regulator.c create mode 100644 include/linux/regulator/of_regulator.hDocumentation/devicetree/bindings/regulator/regulator.txt new file +44
-0@@ -0,0 +1,44 @@ +Voltage/Current Regulators + +Optional properties: +- regulator-min-uV: smallest voltage consumers may set +- regulator-max-uV: largest voltage consumers may set +- regulator-uV-offset: Offset applied to voltages to compensate for voltage drops +- regulator-min-uA: smallest current consumers may set +- regulator-max-uA: largest current consumers may set +- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software +- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator +- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabled +- regulator-boot-on: bootloader/firmware enabled regulator +- <name>-supply: phandle to the parent supply/regulator node + +Example: + + xyzreg: regulator at 0 { + regulator-min-uV = <1000000>; + regulator-max-uV = <2500000>; + regulator-mode-fast; + regulator-change-voltage; + regulator-always-on; + vin-supply = <&vin>; + }; + +The same binding used by a regulator to reference its +supply can be used by any consumer to reference its +regulator/supply + +Example of a device node referencing a regulator node, + + devicenode: node at 0x0 { + ... + ... + <name>-supply = <&xyzreg>; + };drivers/regulator/Kconfig +0
-0
drivers/regulator/Kconfig config REGULATOR_USERSPACE_CONSUMER · line 70
Quoted 7 lines
drivers/regulator/Kconfig +4
-0@@ -64,6 +64,14 @@ config REGULATOR_USERSPACE_CONSUMER If unsure, say no. +config OF_REGULATOR + tristate "OF regulator helpers" + depends on OF + default y if OF
drop the default y line. This probably shouldn't even be a user-visible option. Make drivers select OF_REGULATOR if it needs it.
Quoted 148 lines
drivers/regulator/Kconfig +4
-0+ help + OpenFirmware regulator framework helper routines that can + used by regulator drivers to extract data from device tree. + config REGULATOR_BQ24022 tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" helpdrivers/regulator/Makefile +1
-0@@ -7,6 +7,7 @@ obj-$(CONFIG_REGULATOR) += core.o dummy.o obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o +obj-$(CONFIG_OF_REGULATOR) += of_regulator.o obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.odrivers/regulator/of_regulator.c new file +93
-0@@ -0,0 +1,93 @@ +/* +* OF helpers for regulator framework +* +* Copyright (C) 2011 Texas Instruments, Inc. +* Rajendra Nayak <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/regulator/machine.h> + +static void of_get_regulation_constraints (struct device_node *np, +struct regulator_init_data **init_data) +{ +const __be32 *min_uV, *max_uV, *uV_offset; +const __be32 *min_uA, *max_uA, *input_uV; +unsigned int valid_modes_mask =0 , valid_ops_mask =0 ; + + min_uV =of_get_property (np,"regulator-min-uV" ,NULL ); +if (min_uV) + (*init_data)->constraints.min_uV =be32_to_cpu (*min_uV); + max_uV =of_get_property (np,"regulator-max-uV" ,NULL ); +if (max_uV) + (*init_data)->constraints.max_uV =be32_to_cpu (*max_uV); + uV_offset =of_get_property (np,"regulator-uV-offset" ,NULL ); +if (uV_offset) + (*init_data)->constraints.uV_offset =be32_to_cpu (*uV_offset); + min_uA =of_get_property (np,"regulator-min-uA" ,NULL ); +if (min_uA) + (*init_data)->constraints.min_uA =be32_to_cpu (*min_uA); + max_uA =of_get_property (np,"regulator-max-uA" ,NULL ); +if (max_uA) + (*init_data)->constraints.max_uA =be32_to_cpu (*max_uA); + input_uV =of_get_property (np,"regulator-input-uV" ,NULL ); +if (input_uV) + (*init_data)->constraints.input_uV =be32_to_cpu (*input_uV); + +/* valid modes mask */ +if (of_find_property (np,"regulator-mode-fast" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_FAST ; +if (of_find_property (np,"regulator-mode-normal" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_NORMAL ; +if (of_find_property (np,"regulator-mode-idle" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_IDLE ; +if (of_find_property (np,"regulator-mode-standby" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_STANDBY ; + +/* valid ops mask */ +if (of_find_property (np,"regulator-change-voltage" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_VOLTAGE ; +if (of_find_property (np,"regulator-change-current" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_CURRENT ; +if (of_find_property (np,"regulator-change-mode" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_MODE ; +if (of_find_property (np,"regulator-change-status" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_STATUS ; + + (*init_data)->constraints.valid_modes_mask = valid_modes_mask; + (*init_data)->constraints.valid_ops_mask = valid_ops_mask; + +if (of_find_property (np,"regulator-always-on" ,NULL )) + (*init_data)->constraints.always_on = true; +if (of_find_property (np,"regulator-boot-on" ,NULL )) + (*init_data)->constraints.boot_on = true; +} + +/** +* of_get_regulator_init_data - extract regulator_init_data structure info +* @dev: device requesting for regulator_init_data +* +* Populates regulator_init_data structure by extracting data from device +* tree node, returns a pointer to the populated struture or NULL if memory +* alloc fails. +*/ +struct regulator_init_data *of_get_regulator_init_data (struct device *dev) +{ +struct regulator_init_data *init_data; + +if (!dev->of_node) +return NULL ; + + init_data =devm_kzalloc (dev,sizeof (*init_data),GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ + +of_get_regulation_constraints (dev->of_node, &init_data); +return init_data; +}include/linux/regulator/of_regulator.h new file +21
-0@@ -0,0 +1,21 @@ +/* +* OpenFirmware regulator support routines +* +*/ + +#ifndef __LINUX_OF_REG_H +#define __LINUX_OF_REG_H + +#if defined(CONFIG_OF_REGULATOR ) +extern struct regulator_init_data + *of_get_regulator_init_data (struct device *dev); +#else +static inline struct regulator_init_data + *of_get_regulator_init_data (struct device *dev) +{ +return NULL ; +} +#endif /* CONFIG_OF_REGULATOR */ + +#endif /* __LINUX_OF_REG_H */ +Signature · 1 line
1.7.1
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Rajendra NayakQuoted 172 lines · Rajendra Nayak
The helper routine is meant to be used by regulator drivers to extract the
regulator_init_datastructure from the data that is passed from device tree.
'consumer_supplies' which is part ofregulator_init_datais not extracted as the regulator consumer mappings are passed through DT differently, implemented in subsequent patches.
Similarly the regulator<-->parent/supply mapping is handled in subsequent patches.Also add documentation for regulator bindings to be used to pass
regulator_init_datastruct information from device tree.Signed-off-by Rajendra Nayak <[email protected]>--- .../devicetree/bindings/regulator/regulator.txt | 44 +++++++++ drivers/regulator/Kconfig | 8 ++ drivers/regulator/Makefile | 1 + drivers/regulator/of_regulator.c | 93 ++++++++++++++++++++ include/linux/regulator/of_regulator.h | 21 +++++ 5 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/regulator.txt create mode 100644 drivers/regulator/of_regulator.c create mode 100644 include/linux/regulator/of_regulator.hDocumentation/devicetree/bindings/regulator/regulator.txt new file +44
-0@@ -0,0 +1,44 @@ +Voltage/Current Regulators + +Optional properties: +- regulator-min-uV: smallest voltage consumers may set +- regulator-max-uV: largest voltage consumers may set +- regulator-uV-offset: Offset applied to voltages to compensate for voltage drops +- regulator-min-uA: smallest current consumers may set +- regulator-max-uA: largest current consumers may set +- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software +- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator +- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabled +- regulator-boot-on: bootloader/firmware enabled regulator +- <name>-supply: phandle to the parent supply/regulator node + +Example: + + xyzreg: regulator@0 { + regulator-min-uV = <1000000>; + regulator-max-uV = <2500000>; + regulator-mode-fast; + regulator-change-voltage; + regulator-always-on; + vin-supply = <&vin>; + }; + +The same binding used by a regulator to reference its +supply can be used by any consumer to reference its +regulator/supply + +Example of a device node referencing a regulator node, + + devicenode: node@0x0 { + ... + ... + <name>-supply = <&xyzreg>; + };drivers/regulator/Kconfig +8
-0@@ -64,6 +64,14 @@ config REGULATOR_USERSPACE_CONSUMER If unsure, say no. +config OF_REGULATOR + tristate "OF regulator helpers" + depends on OF + default y if OF + help + OpenFirmware regulator framework helper routines that can + used by regulator drivers to extract data from device tree. + config REGULATOR_BQ24022 tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" helpdrivers/regulator/Makefile +1
-0@@ -7,6 +7,7 @@ obj-$(CONFIG_REGULATOR) += core.o dummy.o obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o +obj-$(CONFIG_OF_REGULATOR) += of_regulator.o obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.odrivers/regulator/of_regulator.c new file +61
-0@@ -0,0 +1,93 @@ +/* +* OF helpers for regulator framework +* +* Copyright (C) 2011 Texas Instruments, Inc. +* Rajendra Nayak <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/regulator/machine.h> + +static void of_get_regulation_constraints (struct device_node *np, +struct regulator_init_data **init_data) +{ +const __be32 *min_uV, *max_uV, *uV_offset; +const __be32 *min_uA, *max_uA, *input_uV; +unsigned int valid_modes_mask =0 , valid_ops_mask =0 ; + + min_uV =of_get_property (np,"regulator-min-uV" ,NULL ); +if (min_uV) + (*init_data)->constraints.min_uV =be32_to_cpu (*min_uV); + max_uV =of_get_property (np,"regulator-max-uV" ,NULL ); +if (max_uV) + (*init_data)->constraints.max_uV =be32_to_cpu (*max_uV); + uV_offset =of_get_property (np,"regulator-uV-offset" ,NULL ); +if (uV_offset) + (*init_data)->constraints.uV_offset =be32_to_cpu (*uV_offset); + min_uA =of_get_property (np,"regulator-min-uA" ,NULL ); +if (min_uA) + (*init_data)->constraints.min_uA =be32_to_cpu (*min_uA); + max_uA =of_get_property (np,"regulator-max-uA" ,NULL ); +if (max_uA) + (*init_data)->constraints.max_uA =be32_to_cpu (*max_uA); + input_uV =of_get_property (np,"regulator-input-uV" ,NULL ); +if (input_uV) + (*init_data)->constraints.input_uV =be32_to_cpu (*input_uV); + +/* valid modes mask */ +if (of_find_property (np,"regulator-mode-fast" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_FAST ; +if (of_find_property (np,"regulator-mode-normal" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_NORMAL ; +if (of_find_property (np,"regulator-mode-idle" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_IDLE ; +if (of_find_property (np,"regulator-mode-standby" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_STANDBY ; + +/* valid ops mask */ +if (of_find_property (np,"regulator-change-voltage" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_VOLTAGE ; +if (of_find_property (np,"regulator-change-current" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_CURRENT ; +if (of_find_property (np,"regulator-change-mode" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_MODE ; +if (of_find_property (np,"regulator-change-status" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_STATUS ;
drivers/regulator/of_regulator.c line 71
Quoted 10 lines
drivers/regulator/of_regulator.c new file +10
-0+ + (*init_data)->constraints.valid_modes_mask = valid_modes_mask; + (*init_data)->constraints.valid_ops_mask = valid_ops_mask; + +if (of_find_property (np,"regulator-always-on" ,NULL )) + (*init_data)->constraints.always_on = true; +if (of_find_property (np,"regulator-boot-on" ,NULL )) + (*init_data)->constraints.boot_on = true; +} +
I do not see that of_get_regulation_constraints() covers the following fields. We do not support them for DT probe?
struct regulation_constraints {
char *name;
...
/* regulator suspend states for global PMIC STANDBY/HIBERNATE */
struct regulator_state state_disk;
struct regulator_state state_mem;
struct regulator_state state_standby;
suspend_state_t initial_state; /* suspend state to set at init */
/* mode to set on startup */
unsigned int initial_mode;
/* constraint flags */
...
unsigned apply_uV:1; /* apply uV constraint if min == max */
};Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 3 lines
I do not see that
of_get_regulation_constraints()covers the following fields. We do not support them for DT probe?
I left these out as I wasn't sure how such (if at all) Linux specific params should be passed through dt, and I am still not quite sure :(
Quoted 21 lines
struct
regulation_constraints{char *name; ... /* regulator suspend states for global PMIC STANDBY/HIBERNATE */ struct regulator_state state_disk; struct regulator_state state_mem; struct regulator_state state_standby; suspend_state_t initial_state; /* suspend state to set at init */ /* mode to set on startup */ unsigned int initial_mode; /* constraint flags */ ... unsigned apply_uV:1; /* apply uV constraint if min == max */ };
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 8 lines · Rajendra Nayak
Quoted 3 lines
I do not see that
of_get_regulation_constraints()covers the following fields. We do not support them for DT probe?I left these out as I wasn't sure how such (if at all) Linux specific params should be passed through dt, and I am still not quite sure :(
I'm seeing some linux specific parameters encoded in the device tree below.
Documentation/devicetree/bindings/gpio/gpio_keys.txt Documentation/devicetree/bindings/gpio/led.txt
Mark,
I understand that ideally device tree is supposed to describe pure hardware configurations. But practically, when migrating a driver to device tree probe, we are trying to move the configurations described by platform_data into device tree to save the use of platform_data for device tree probe. Then some of the configuration may not be so purely hardware related. But I do not see this is a critical problem.
What do you think? Is it what you want that we classify the configurations clearly and put only strict hardware configurations into device tree and keep others still in platform_data?
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 7 lines · Shawn Guo
I understand that ideally device tree is supposed to describe pure hardware configurations. But practically, when migrating a driver to device tree probe, we are trying to move the configurations described by
platform_datainto device tree to save the use ofplatform_datafor device tree probe. Then some of the configuration may not be so purely hardware related. But I do not see this is a critical problem.
It's not just Linux-specific stuff, some of this is even specific to what current Linux drivers can do - updating the kernel could mean a different set of constraints.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 10 lines · Mark Brown
Quoted 7 lines · Shawn Guo
I understand that ideally device tree is supposed to describe pure hardware configurations. But practically, when migrating a driver to device tree probe, we are trying to move the configurations described by
platform_datainto device tree to save the use ofplatform_datafor device tree probe. Then some of the configuration may not be so purely hardware related. But I do not see this is a critical problem.
Quoted 4 lines
It's not just Linux-specific stuff, some of this is even specific to what current Linux drivers can do - updating the kernel could mean a different set of constraints.
Well, from what I see, the 'struct regulation_constraints' is defined in machine.h and meant to be the regulator machine/board interface. With the example I'm looking at, mc13892, the regulation_constraints configuration is fully passed from machine/board file. If there is something specific to what drivers can do, it probably should be encoded in regulator driver rather than staying in regulation_constraints.
So how do you think we should proceed here?
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 8 lines · Shawn Guo
Quoted 3 lines · Mark Brown
It's not just Linux-specific stuff, some of this is even specific to what current Linux drivers can do - updating the kernel could mean a different set of constraints.
Well, from what I see, the 'struct
regulation_constraints' is defined inmachine.hand meant to be the regulator machine/board interface.
...which will depend on the system integrator's understanding of what their system is capable of right now.
Quoted 4 lines
With the example I'm looking at, mc13892, the
regulation_constraintsconfiguration is fully passed from machine/board file. If there is something specific to what drivers can do, it probably should be encoded in regulator driver rather than staying inregulation_constraints.
I don't think you're quite understanding the issue - it's an integration problem with three different variables. It's a combination of what the chips can do, what the drivers can do and if the board design affects any of this stuff. Only the board can come to a final decision.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 18 lines · Mark Brown
Quoted 8 lines · Shawn Guo
Quoted 3 lines · Mark Brown
It's not just Linux-specific stuff, some of this is even specific to what current Linux drivers can do - updating the kernel could mean a different set of constraints.
Well, from what I see, the 'struct
regulation_constraints' is defined inmachine.hand meant to be the regulator machine/board interface....which will depend on the system integrator's understanding of what their system is capable of right now.
Quoted 4 lines
With the example I'm looking at, mc13892, the
regulation_constraintsconfiguration is fully passed from machine/board file. If there is something specific to what drivers can do, it probably should be encoded in regulator driver rather than staying inregulation_constraints.
Quoted 5 lines
I don't think you're quite understanding the issue - it's an integration problem with three different variables. It's a combination of what the chips can do, what the drivers can do and if the board design affects any of this stuff.
Honestly, I'm still pretty new to regulator subsystem, so really need your help to understand the situation.
Quoted 2 lines
Only the board can come to a final decision.
The dts is very capable and suitable to describe the board's decision. But you disagree that we put all constraints description into DT. I'm a pretty confused here. So again, what is your suggestion to this 'problem'?
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 8 lines · Shawn Guo
Quoted 1 line · Mark Brown
Only the board can come to a final decision.
The dts is very capable and suitable to describe the board's decision. But you disagree that we put all constraints description into DT. I'm a pretty confused here. So again, what is your suggestion to this 'problem'?
The problem is that the DT is supposed to be separate to the kernel and the decisions can depend on what the kernel is currently capable of. When the data is embedded in the kernel it's not an issue as the data is attached to the rest of the code, when the data becomes detatched from the kernel it becomes an issue.
I don't see any issue with leaving some things out of the DT bindings; you were the one raising that as a concern.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 5 lines · Mark Brown
The problem is that the DT is supposed to be separate to the kernel and the decisions can depend on what the kernel is currently capable of. When the data is embedded in the kernel it's not an issue as the data is attached to the rest of the code, when the data becomes detatched from the kernel it becomes an issue.
completely agreed.
Quoted 3 lines
I don't see any issue with leaving some things out of the DT bindings; you were the one raising that as a concern.
The problem is, that there doesn't seem to be a clean way to embed *board data* into the kernel with DT, if left out of the DT bindings. There is the auxdata way of still attaching platform_data, but that I thought was a stopgap for just handling function pointers.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 9 lines · Rajendra Nayak
Quoted 2 lines · Mark Brown
I don't see any issue with leaving some things out of the DT bindings; you were the one raising that as a concern.
The problem is, that there doesn't seem to be a clean way to embed *board data* into the kernel with DT, if left out of the DT bindings. There is the auxdata way of still attaching
platform_data, but that I thought was a stopgap for just handling function pointers.
We can always start off just completely omitting the data and then see how we go from there. If we only cover 50% of users that's still 50% more than are currently covered with device tree right now and it means we can then spin round and look at the bits that are hard again without review fatigue on the bits that are easy.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 6 lines
We can always start off just completely omitting the data and then see how we go from there. If we only cover 50% of users that's still 50% more than are currently covered with device tree right now and it means we can then spin round and look at the bits that are hard again without review fatigue on the bits that are easy.
Ok, will drop the problematic bindings for now and repost.
Tony Lindgren
maintainerRe: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Mark BrownQuoted 11 lines · Mark Brown
Quoted 9 lines · Rajendra Nayak
Quoted 2 lines · Mark Brown
I don't see any issue with leaving some things out of the DT bindings; you were the one raising that as a concern.
The problem is, that there doesn't seem to be a clean way to embed *board data* into the kernel with DT, if left out of the DT bindings. There is the auxdata way of still attaching
platform_data, but that I thought was a stopgap for just handling function pointers.
Quoted 5 lines
We can always start off just completely omitting the data and then see how we go from there. If we only cover 50% of users that's still 50% more than are currently covered with device tree right now and it means we can then spin round and look at the bits that are hard again without review fatigue on the bits that are easy.
We still need to pass the board configuration somehow, otherwise we can never remove all the platform data glue layers. And if we can't do that, we'll forever have all the nasty merge conflicts when adding new drivers. And there's an unnecessary dependency between adding drivers and the core SoC code.
So we really need to remove all the platform data glue layers so driver probe can initialize things automagically.
Kernel cmdline is of course one way to pass options, but probably won't scale for all the board wirings.. And the kernel cmdline should really be for user configurable options.
So should we just have a cmdline string for each DT entry to pass the board specific options from DT to the driver? Something along the lines module options?
Regards,
Tony
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 8 lines · Tony Lindgren
Quoted 5 lines · Mark Brown
We can always start off just completely omitting the data and then see how we go from there. If we only cover 50% of users that's still 50% more than are currently covered with device tree right now and it means we can then spin round and look at the bits that are hard again without review fatigue on the bits that are easy.
Quoted 5 lines
We still need to pass the board configuration somehow, otherwise we can never remove all the platform data glue layers. And if we can't do that, we'll forever have all the nasty merge conflicts when adding new drivers. And there's an unnecessary dependency between adding drivers and the core SoC code.
The current patches cover the overwhelming majority of the existing board configuration - the stuff that's Linux specific is also relatively rarely used in actual systems. For example all the board I work with regularly would be perfectly happy with the generic stuff - the Linux specific stuff is relatively rarely used.
Tony Lindgren
maintainerRe: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 15 lines · Mark Brown
Quoted 8 lines · Tony Lindgren
Quoted 5 lines · Mark Brown
We can always start off just completely omitting the data and then see how we go from there. If we only cover 50% of users that's still 50% more than are currently covered with device tree right now and it means we can then spin round and look at the bits that are hard again without review fatigue on the bits that are easy.
Quoted 5 lines
We still need to pass the board configuration somehow, otherwise we can never remove all the platform data glue layers. And if we can't do that, we'll forever have all the nasty merge conflicts when adding new drivers. And there's an unnecessary dependency between adding drivers and the core SoC code.
Quoted 5 lines
The current patches cover the overwhelming majority of the existing board configuration - the stuff that's Linux specific is also relatively rarely used in actual systems. For example all the board I work with regularly would be perfectly happy with the generic stuff - the Linux specific stuff is relatively rarely used.
Right, but in addition the board specific integration variables still need to be passed somehow to the driver.
That's where a DT entry specific configuration string might be the best option as it still allows describing the hardware using DT standards, while also allowing board specific configuration too.
The issue there is then how do we keep these options from getting out of control..
BTW, of course this issue is generic to all drivers, not specific to this patchset. With this patchset leaving out the non-standard entries is the right way to go to so we can merge it.
Cheers,
Tony
Tony Lindgren
maintainerRe: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 4 lines · Tony Lindgren
That's where a DT entry specific configuration string might be the best option as it still allows describing the hardware using DT standards, while also allowing board specific configuration too.
Hmm, actually, can't we just pass the board specific configuration in the board specific .dts file and then it gets merged in with the arch independent DT node?
Regards,
Tony
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 3 lines · Tony Lindgren
Hmm, actually, can't we just pass the board specific configuration in the board specific .dts file and then it gets merged in with the arch independent DT node?
I don't understand what an "arch independent DT node" would be?
Tony Lindgren
maintainerRe: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 7 lines · Mark Brown
Quoted 3 lines · Tony Lindgren
Hmm, actually, can't we just pass the board specific configuration in the board specific .dts file and then it gets merged in with the arch independent DT node?
I don't understand what an "arch independent DT node" would be?
Well that's the standard non-Linux specific parts. Basically what's in the $Subject patch minus what you commented on earlier:
Quoted 11 lines
+- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software +- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator +- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabled
We still need to figure out how to get the above board specific data to the device driver probe in a way where we can avoid having platform glue code. Any thoughts on that?
Tony
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 6 lines · Tony Lindgren
Quoted 1 line · Mark Brown
I don't understand what an "arch independent DT node" would be?
Well that's the standard non-Linux specific parts. Basically what's in the $Subject patch minus what you commented on earlier:
Oh, you don't mean arch specific at all then.
Quoted 2 lines
Quoted 2 lines
+- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software
These aren't really Linux specific, and you could probably just infer them from having a voltage/current range anyway.
Quoted 10 lines
Quoted 9 lines
+- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator +- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabled
Quoted 3 lines
We still need to figure out how to get the above board specific data to the device driver probe in a way where we can avoid having platform glue code. Any thoughts on that?
I think we should just not bother with most of the above and see if anyone notices, with the exception of always on and status changes it's vanishingly rare for anyone to actually do anything constructive with them.
Neither of the two I mentioned are Linux specific either, they mean somehing useful for any OS it's just that the decision is policy which is going to depend on the OS version. Status changes we can probably allow people to enable, it'll just mean that older device trees won't get good power use out of newer kernels and if you move to an older kernel things will start exploding as drivers loose regulator support. Always on we can probably live without, it's a combination of overspecification and interaction with _has_full_constraints() which isn't represented in this binding anyway.
Tony Lindgren
maintainerRe: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 10 lines · Mark Brown
Quoted 3 lines · Tony Lindgren
We still need to figure out how to get the above board specific data to the device driver probe in a way where we can avoid having platform glue code. Any thoughts on that?
I think we should just not bother with most of the above and see if anyone notices, with the exception of always on and status changes it's vanishingly rare for anyone to actually do anything constructive with them.
OK
Quoted 9 lines
Neither of the two I mentioned are Linux specific either, they mean somehing useful for any OS it's just that the decision is policy which is going to depend on the OS version. Status changes we can probably allow people to enable, it'll just mean that older device trees won't get good power use out of newer kernels and if you move to an older kernel things will start exploding as drivers loose regulator support. Always on we can probably live without, it's a combination of overspecification and interaction with
_has_full_constraints()which isn't represented in this binding anyway.
Yeah, lot of these are "how the regulator using driver is using the regulator" or "how the operating system is using the regulator" type policies.
Regards,
Tony
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Tony LindgrenQuoted 9 lines · Tony Lindgren
Quoted 4 lines · Tony Lindgren
That's where a DT entry specific configuration string might be the best option as it still allows describing the hardware using DT standards, while also allowing board specific configuration too.
Hmm, actually, can't we just pass the board specific configuration in the board specific .dts file and then it gets merged in with the arch independent DT node?
It would be fine to, say, have a omap-specific board configuration node for collecting things that really don't fit anywhere else. That would be in some ways analogous to the way we've decided to use top a top level node for describing a machines audio complex.
g.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Tony LindgrenQuoted 2 lines · Tony Lindgren
Right, but in addition the board specific integration variables still need to be passed somehow to the driver.
I'm not sure you're aware of what the regulator bindings that are being discussed are - they're entirely board specific. The discussion was about how to handle certain parts of the feature set Linux currently has.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Rajendra NayakQuoted 45 lines · Rajendra Nayak
The helper routine is meant to be used by regulator drivers to extract the
regulator_init_datastructure from the data that is passed from device tree.
'consumer_supplies' which is part ofregulator_init_datais not extracted as the regulator consumer mappings are passed through DT differently, implemented in subsequent patches.
Similarly the regulator<-->parent/supply mapping is handled in subsequent patches.Also add documentation for regulator bindings to be used to pass
regulator_init_datastruct information from device tree.Signed-off-by Rajendra Nayak <[email protected]>--- .../devicetree/bindings/regulator/regulator.txt | 44 +++++++++ drivers/regulator/Kconfig | 8 ++ drivers/regulator/Makefile | 1 + drivers/regulator/of_regulator.c | 93 ++++++++++++++++++++ include/linux/regulator/of_regulator.h | 21 +++++ 5 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/regulator.txt create mode 100644 drivers/regulator/of_regulator.c create mode 100644 include/linux/regulator/of_regulator.hDocumentation/devicetree/bindings/regulator/regulator.txt new file +15
-0@@ -0,0 +1,44 @@ +Voltage/Current Regulators + +Optional properties: +- regulator-min-uV: smallest voltage consumers may set +- regulator-max-uV: largest voltage consumers may set +- regulator-uV-offset: Offset applied to voltages to compensate for voltage drops +- regulator-min-uA: smallest current consumers may set +- regulator-max-uA: largest current consumers may set +- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software +- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator
Documentation/devicetree/bindings/regulator/regulator.txt line 25
Quoted 10 lines
Documentation/devicetree/bindings/regulator/regulator.txt new file +10
-0+- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabled +- regulator-boot-on: bootloader/firmware enabled regulator +- <name>-supply: phandle to the parent supply/regulator node + +Example: + + xyzreg: regulator@0 {
Does this node have a compatible string? With looking at the code, I guess it has a compatible string in your dts file.
Quoted 126 lines
Documentation/devicetree/bindings/regulator/regulator.txt new file +19
-0+ regulator-min-uV = <1000000>; + regulator-max-uV = <2500000>; + regulator-mode-fast; + regulator-change-voltage; + regulator-always-on; + vin-supply = <&vin>; + }; + +The same binding used by a regulator to reference its +supply can be used by any consumer to reference its +regulator/supply + +Example of a device node referencing a regulator node, + + devicenode: node@0x0 { + ... + ... + <name>-supply = <&xyzreg>; + };drivers/regulator/Kconfig +8
-0@@ -64,6 +64,14 @@ config REGULATOR_USERSPACE_CONSUMER If unsure, say no. +config OF_REGULATOR + tristate "OF regulator helpers" + depends on OF + default y if OF + help + OpenFirmware regulator framework helper routines that can + used by regulator drivers to extract data from device tree. + config REGULATOR_BQ24022 tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" helpdrivers/regulator/Makefile +1
-0@@ -7,6 +7,7 @@ obj-$(CONFIG_REGULATOR) += core.o dummy.o obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o +obj-$(CONFIG_OF_REGULATOR) += of_regulator.o obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.odrivers/regulator/of_regulator.c new file +70
-0@@ -0,0 +1,93 @@ +/* +* OF helpers for regulator framework +* +* Copyright (C) 2011 Texas Instruments, Inc. +* Rajendra Nayak <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/regulator/machine.h> + +static void of_get_regulation_constraints (struct device_node *np, +struct regulator_init_data **init_data) +{ +const __be32 *min_uV, *max_uV, *uV_offset; +const __be32 *min_uA, *max_uA, *input_uV; +unsigned int valid_modes_mask =0 , valid_ops_mask =0 ; + + min_uV =of_get_property (np,"regulator-min-uV" ,NULL ); +if (min_uV) + (*init_data)->constraints.min_uV =be32_to_cpu (*min_uV); + max_uV =of_get_property (np,"regulator-max-uV" ,NULL ); +if (max_uV) + (*init_data)->constraints.max_uV =be32_to_cpu (*max_uV); + uV_offset =of_get_property (np,"regulator-uV-offset" ,NULL ); +if (uV_offset) + (*init_data)->constraints.uV_offset =be32_to_cpu (*uV_offset); + min_uA =of_get_property (np,"regulator-min-uA" ,NULL ); +if (min_uA) + (*init_data)->constraints.min_uA =be32_to_cpu (*min_uA); + max_uA =of_get_property (np,"regulator-max-uA" ,NULL ); +if (max_uA) + (*init_data)->constraints.max_uA =be32_to_cpu (*max_uA); + input_uV =of_get_property (np,"regulator-input-uV" ,NULL ); +if (input_uV) + (*init_data)->constraints.input_uV =be32_to_cpu (*input_uV); + +/* valid modes mask */ +if (of_find_property (np,"regulator-mode-fast" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_FAST ; +if (of_find_property (np,"regulator-mode-normal" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_NORMAL ; +if (of_find_property (np,"regulator-mode-idle" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_IDLE ; +if (of_find_property (np,"regulator-mode-standby" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_STANDBY ; + +/* valid ops mask */ +if (of_find_property (np,"regulator-change-voltage" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_VOLTAGE ; +if (of_find_property (np,"regulator-change-current" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_CURRENT ; +if (of_find_property (np,"regulator-change-mode" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_MODE ; +if (of_find_property (np,"regulator-change-status" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_STATUS ; + + (*init_data)->constraints.valid_modes_mask = valid_modes_mask; + (*init_data)->constraints.valid_ops_mask = valid_ops_mask; + +if (of_find_property (np,"regulator-always-on" ,NULL )) + (*init_data)->constraints.always_on = true; +if (of_find_property (np,"regulator-boot-on" ,NULL )) + (*init_data)->constraints.boot_on = true; +}
drivers/regulator/of_regulator.c line 80
Quoted 10 lines
drivers/regulator/of_regulator.c new file +10
-0+ +/** +* of_get_regulator_init_data - extract regulator_init_data structure info +* @dev: device requesting for regulator_init_data +* +* Populates regulator_init_data structure by extracting data from device +* tree node, returns a pointer to the populated struture or NULL if memory +* alloc fails. +*/ +struct regulator_init_data *of_get_regulator_init_data (struct device *dev)
I remember that Mark ever had a comment on a previous regulator DT series from Haojian Zhuang, saying this DT parsing procedure can probably just be private to regulator core and invisible to regulator drivers. That said whenever regulator_register() gets called with parameter init_data as NULL, it should try to retrieve regulator_init_data from device tree. It will ease regulator drivers a little. They will only need to call regulator_register() with NULL init_data for DT case. More importantly, doing so will help solve the dual 'dev' problem I see below.
drivers/regulator/of_regulator.c line 91
Quoted 11 lines
drivers/regulator/of_regulator.c new file +11
-0+{ +struct regulator_init_data *init_data; + +if (!dev->of_node) +return NULL ; + + init_data =devm_kzalloc (dev,sizeof (*init_data),GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ + +of_get_regulation_constraints (dev->of_node, &init_data);
Beside the 'dev' here with of_node attached, there will be another 'dev' created by regulator core function regulator_register(), which is wrapped by 'regulator_dev'.
So we have two 'dev'. One is created by DT core with of_node attached, and used to retrieve regulator_init_data from device tree. Another one is created in regulator_register() and used by regulator core.
IMO, this is not what we want. Instead of having two 'dev' for given regulator, we should use the same 'dev' created in regulator_register() to retrieve regulator_init_data from device tree, so that we do not need the 'dev' created by DT core. That said, with DT parsing procedure moved into regulator core, we can get of_node for given regulator and attach it to the 'dev' created by regulator core.
Will elaborate it a little more in patch #5.
Regards,
Shawn
Quoted 37 lines
drivers/regulator/of_regulator.c new file +2
-0+return init_data; +}include/linux/regulator/of_regulator.h new file +21
-0@@ -0,0 +1,21 @@ +/* +* OpenFirmware regulator support routines +* +*/ + +#ifndef __LINUX_OF_REG_H +#define __LINUX_OF_REG_H + +#if defined(CONFIG_OF_REGULATOR ) +extern struct regulator_init_data + *of_get_regulator_init_data (struct device *dev); +#else +static inline struct regulator_init_data + *of_get_regulator_init_data (struct device *dev) +{ +return NULL ; +} +#endif /* CONFIG_OF_REGULATOR */ + +#endif /* __LINUX_OF_REG_H */ +Signature · 6 lines
1.7.1 _______________________________________________ devicetree-discuss mailing list [email protected] https://lists.ozlabs.org/listinfo/devicetree-discuss
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 51 lines · Shawn Guo
Quoted 50 lines · Rajendra Nayak
The helper routine is meant to be used by regulator drivers to extract the
regulator_init_datastructure from the data that is passed from device tree.
'consumer_supplies' which is part ofregulator_init_datais not extracted as the regulator consumer mappings are passed through DT differently, implemented in subsequent patches.
Similarly the regulator<-->parent/supply mapping is handled in subsequent patches.Also add documentation for regulator bindings to be used to pass
regulator_init_datastruct information from device tree.Signed-off-by Rajendra Nayak<[email protected]>--- .../devicetree/bindings/regulator/regulator.txt | 44 +++++++++ drivers/regulator/Kconfig | 8 ++ drivers/regulator/Makefile | 1 + drivers/regulator/of_regulator.c | 93 ++++++++++++++++++++ include/linux/regulator/of_regulator.h | 21 +++++ 5 files changed, 167 insertions(+), 0 deletions(-)create mode 100644
Documentation/devicetree/bindings/regulator/regulator.txtcreate mode 100644drivers/regulator/of_regulator.c
create mode 100644include/linux/regulator/of_regulator.hDocumentation/devicetree/bindings/regulator/regulator.txt new file +20
-0@@ -0,0 +1,44 @@ +Voltage/Current Regulators + +Optional properties: +- regulator-min-uV: smallest voltage consumers may set +- regulator-max-uV: largest voltage consumers may set +- regulator-uV-offset: Offset applied to voltages to compensate for voltage drops +- regulator-min-uA: smallest current consumers may set +- regulator-max-uA: largest current consumers may set +- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software +- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator +- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabled +- regulator-boot-on: bootloader/firmware enabled regulator
Quoted 8 lines
Documentation/devicetree/bindings/regulator/regulator.txt line 25
Quoted 5 lines
Documentation/devicetree/bindings/regulator/regulator.txt new file +5
-0+-<name>-supply: phandle to the parent supply/regulator node + +Example: + + xyzreg: regulator at 0 {Does this node have a compatible string? With looking at the code, I guess it has a compatible string in your dts file.
The compatible string depends on the regulator driver used. I added one for the twl regulators when I added support for them.
Quoted 139 lines
Quoted 127 lines
Documentation/devicetree/bindings/regulator/regulator.txt new file +19
-0+ regulator-min-uV =<1000000>; + regulator-max-uV =<2500000>; + regulator-mode-fast; + regulator-change-voltage; + regulator-always-on; + vin-supply =<&vin>; + }; + +The same binding used by a regulator to reference its +supply can be used by any consumer to reference its +regulator/supply + +Example of a device node referencing a regulator node, + + devicenode: node at 0x0 { + ... + ... + <name>-supply =<&xyzreg>; + };drivers/regulator/Kconfig +8
-0@@ -64,6 +64,14 @@ config REGULATOR_USERSPACE_CONSUMER If unsure, say no. +config OF_REGULATOR + tristate "OF regulator helpers" + depends on OF + default y if OF + help + OpenFirmware regulator framework helper routines that can + used by regulator drivers to extract data from device tree. + config REGULATOR_BQ24022 tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" helpdrivers/regulator/Makefile +1
-0@@ -7,6 +7,7 @@ obj-$(CONFIG_REGULATOR) += core.o dummy.o obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o +obj-$(CONFIG_OF_REGULATOR) += of_regulator.o obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.odrivers/regulator/of_regulator.c new file +70
-0@@ -0,0 +1,93 @@ +/* +* OF helpers for regulator framework +* +* Copyright (C) 2011 Texas Instruments, Inc. +* Rajendra Nayak<[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/regulator/machine.h> + +static void of_get_regulation_constraints (struct device_node *np, +struct regulator_init_data **init_data) +{ +const __be32 *min_uV, *max_uV, *uV_offset; +const __be32 *min_uA, *max_uA, *input_uV; +unsigned int valid_modes_mask =0 , valid_ops_mask =0 ; + + min_uV =of_get_property (np,"regulator-min-uV" ,NULL ); +if (min_uV) + (*init_data)->constraints.min_uV =be32_to_cpu (*min_uV); + max_uV =of_get_property (np,"regulator-max-uV" ,NULL ); +if (max_uV) + (*init_data)->constraints.max_uV =be32_to_cpu (*max_uV); + uV_offset =of_get_property (np,"regulator-uV-offset" ,NULL ); +if (uV_offset) + (*init_data)->constraints.uV_offset =be32_to_cpu (*uV_offset); + min_uA =of_get_property (np,"regulator-min-uA" ,NULL ); +if (min_uA) + (*init_data)->constraints.min_uA =be32_to_cpu (*min_uA); + max_uA =of_get_property (np,"regulator-max-uA" ,NULL ); +if (max_uA) + (*init_data)->constraints.max_uA =be32_to_cpu (*max_uA); + input_uV =of_get_property (np,"regulator-input-uV" ,NULL ); +if (input_uV) + (*init_data)->constraints.input_uV =be32_to_cpu (*input_uV); + +/* valid modes mask */ +if (of_find_property (np,"regulator-mode-fast" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_FAST ; +if (of_find_property (np,"regulator-mode-normal" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_NORMAL ; +if (of_find_property (np,"regulator-mode-idle" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_IDLE ; +if (of_find_property (np,"regulator-mode-standby" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_STANDBY ; + +/* valid ops mask */ +if (of_find_property (np,"regulator-change-voltage" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_VOLTAGE ; +if (of_find_property (np,"regulator-change-current" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_CURRENT ; +if (of_find_property (np,"regulator-change-mode" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_MODE ; +if (of_find_property (np,"regulator-change-status" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_STATUS ; + + (*init_data)->constraints.valid_modes_mask = valid_modes_mask; + (*init_data)->constraints.valid_ops_mask = valid_ops_mask; + +if (of_find_property (np,"regulator-always-on" ,NULL )) + (*init_data)->constraints.always_on = true; +if (of_find_property (np,"regulator-boot-on" ,NULL )) + (*init_data)->constraints.boot_on = true; +}drivers/regulator/of_regulator.c line 80
Quoted 10 lines
drivers/regulator/of_regulator.c new file +10
-0+ +/** +* of_get_regulator_init_data - extract regulator_init_data structure info +* @dev: device requesting for regulator_init_data +* +* Populates regulator_init_data structure by extracting data from device +* tree node, returns a pointer to the populated struture or NULL if memory +* alloc fails. +*/ +struct regulator_init_data *of_get_regulator_init_data (struct device *dev)I remember that Mark ever had a comment on a previous regulator DT
Quoted 8 lines
series from Haojian Zhuang, saying this DT parsing procedure can probably just be private to regulator core and invisible to regulator drivers. That said whenever
regulator_register()gets called with parameterinit_dataas NULL, it should try to retrieveregulator_init_datafrom device tree. It will ease regulator drivers a little. They will only need to callregulator_register()with NULLinit_datafor DT case. More importantly, doing so will help solve the dual 'dev' problem I see below.
Yes, it seems like a good idea given that most drivers seem to blindly pass the regulator_init_data onto regulator_register, however there are cases like the twl regulator driver which seems to peek into the constraints passed from the board to make sure it drops anything that the hardware does not support, or cases like the db8500 where regulator_init_data for all regulators are bundled together and the driver extracts and registers them as separate regulators. Exporting an api instead to extract regulator_init_data to the driver might help in those cases.
Quoted 17 lines
drivers/regulator/of_regulator.c
Quoted 12 lines
drivers/regulator/of_regulator.c new file +11
-0+{ +struct regulator_init_data *init_data; + +if (!dev->of_node) +return NULL ; + + init_data =devm_kzalloc (dev,sizeof (*init_data),GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ + +of_get_regulation_constraints (dev->of_node,&init_data);Beside the 'dev' here with
of_nodeattached, there will be another 'dev' created by regulator core functionregulator_register(), which is wrapped by 'regulator_dev'.
Quoted 3 lines
So we have two 'dev'. One is created by DT core with
of_nodeattached, and used to retrieveregulator_init_datafrom device tree. Another one is created inregulator_register()and used by regulator core.
But thats not something newly done now with DT. Thats how it was even in the non-DT world. There were always two devices with the regulator_dev device as the child.
Quoted 51 lines
IMO, this is not what we want. Instead of having two 'dev' for given regulator, we should use the same 'dev' created in
regulator_register()to retrieveregulator_init_datafrom device tree, so that we do not need the 'dev' created by DT core. That said, with DT parsing procedure moved into regulator core, we can getof_nodefor given regulator and attach it to the 'dev' created by regulator core.Will elaborate it a little more in patch #5.
Regards,
ShawnQuoted 37 lines
drivers/regulator/of_regulator.c new file +2
-0+return init_data; +}include/linux/regulator/of_regulator.h new file +21
-1@@ -0,0 +1,21 @@ +/* +* OpenFirmware regulator support routines +* +*/ + +#ifndef __LINUX_OF_REG_H +#define __LINUX_OF_REG_H + +#if defined(CONFIG_OF_REGULATOR ) +extern struct regulator_init_data + *of_get_regulator_init_data (struct device *dev); +#else +static inline struct regulator_init_data + *of_get_regulator_init_data (struct device *dev) +{ +return NULL ; +} +#endif /* CONFIG_OF_REGULATOR */ + +#endif /* __LINUX_OF_REG_H */ + --1.7.1
_______________________________________________
devicetree-discuss mailing list
devicetree-discuss at lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 213 lines · Rajendra Nayak
Quoted 51 lines · Shawn Guo
Quoted 50 lines · Rajendra Nayak
The helper routine is meant to be used by regulator drivers to extract the
regulator_init_datastructure from the data that is passed from device tree.
'consumer_supplies' which is part ofregulator_init_datais not extracted as the regulator consumer mappings are passed through DT differently, implemented in subsequent patches.
Similarly the regulator<-->parent/supply mapping is handled in subsequent patches.Also add documentation for regulator bindings to be used to pass
regulator_init_datastruct information from device tree.Signed-off-by Rajendra Nayak<[email protected]>--- .../devicetree/bindings/regulator/regulator.txt | 44 +++++++++ drivers/regulator/Kconfig | 8 ++ drivers/regulator/Makefile | 1 + drivers/regulator/of_regulator.c | 93 ++++++++++++++++++++ include/linux/regulator/of_regulator.h | 21 +++++ 5 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/regulator.txt create mode 100644 drivers/regulator/of_regulator.c create mode 100644 include/linux/regulator/of_regulator.hDocumentation/devicetree/bindings/regulator/regulator.txt new file +20
-0@@ -0,0 +1,44 @@ +Voltage/Current Regulators + +Optional properties: +- regulator-min-uV: smallest voltage consumers may set +- regulator-max-uV: largest voltage consumers may set +- regulator-uV-offset: Offset applied to voltages to compensate for voltage drops +- regulator-min-uA: smallest current consumers may set +- regulator-max-uA: largest current consumers may set +- regulator-change-voltage: boolean, Output voltage can be changed by software +- regulator-change-current: boolean, Output current can be chnaged by software +- regulator-change-mode: boolean, Operating mode can be changed by software +- regulator-change-status: boolean, Enable/Disable control for regulator exists +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled +- regulator-mode-fast: boolean, allow/set fast mode for the regulator +- regulator-mode-normal: boolean, allow/set normal mode for the regulator +- regulator-mode-idle: boolean, allow/set idle mode for the regulator +- regulator-mode-standby: boolean, allow/set standby mode for the regulator +- regulator-input-uV: Input voltage for regulator when supplied by another regulator +- regulator-always-on: boolean, regulator should never be disabled +- regulator-boot-on: bootloader/firmware enabled regulatorQuoted 8 lines
Documentation/devicetree/bindings/regulator/regulator.txt
Quoted 5 lines
Documentation/devicetree/bindings/regulator/regulator.txt new file +5
-0+-<name>-supply: phandle to the parent supply/regulator node + +Example: + + xyzreg: regulator@0 {Does this node have a compatible string? With looking at the code, I guess it has a compatible string in your dts file.
The compatible string depends on the regulator driver used. I added one for the twl regulators when I added support for them.
Quoted 139 lines
Quoted 127 lines
Documentation/devicetree/bindings/regulator/regulator.txt new file +19
-0+ regulator-min-uV =<1000000>; + regulator-max-uV =<2500000>; + regulator-mode-fast; + regulator-change-voltage; + regulator-always-on; + vin-supply =<&vin>; + }; + +The same binding used by a regulator to reference its +supply can be used by any consumer to reference its +regulator/supply + +Example of a device node referencing a regulator node, + + devicenode: node@0x0 { + ... + ... + <name>-supply =<&xyzreg>; + };drivers/regulator/Kconfig +8
-0@@ -64,6 +64,14 @@ config REGULATOR_USERSPACE_CONSUMER If unsure, say no. +config OF_REGULATOR + tristate "OF regulator helpers" + depends on OF + default y if OF + help + OpenFirmware regulator framework helper routines that can + used by regulator drivers to extract data from device tree. + config REGULATOR_BQ24022 tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" helpdrivers/regulator/Makefile +1
-0@@ -7,6 +7,7 @@ obj-$(CONFIG_REGULATOR) += core.o dummy.o obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o +obj-$(CONFIG_OF_REGULATOR) += of_regulator.o obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.odrivers/regulator/of_regulator.c new file +70
-0@@ -0,0 +1,93 @@ +/* +* OF helpers for regulator framework +* +* Copyright (C) 2011 Texas Instruments, Inc. +* Rajendra Nayak<[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/regulator/machine.h> + +static void of_get_regulation_constraints (struct device_node *np, +struct regulator_init_data **init_data) +{ +const __be32 *min_uV, *max_uV, *uV_offset; +const __be32 *min_uA, *max_uA, *input_uV; +unsigned int valid_modes_mask =0 , valid_ops_mask =0 ; + + min_uV =of_get_property (np,"regulator-min-uV" ,NULL ); +if (min_uV) + (*init_data)->constraints.min_uV =be32_to_cpu (*min_uV); + max_uV =of_get_property (np,"regulator-max-uV" ,NULL ); +if (max_uV) + (*init_data)->constraints.max_uV =be32_to_cpu (*max_uV); + uV_offset =of_get_property (np,"regulator-uV-offset" ,NULL ); +if (uV_offset) + (*init_data)->constraints.uV_offset =be32_to_cpu (*uV_offset); + min_uA =of_get_property (np,"regulator-min-uA" ,NULL ); +if (min_uA) + (*init_data)->constraints.min_uA =be32_to_cpu (*min_uA); + max_uA =of_get_property (np,"regulator-max-uA" ,NULL ); +if (max_uA) + (*init_data)->constraints.max_uA =be32_to_cpu (*max_uA); + input_uV =of_get_property (np,"regulator-input-uV" ,NULL ); +if (input_uV) + (*init_data)->constraints.input_uV =be32_to_cpu (*input_uV); + +/* valid modes mask */ +if (of_find_property (np,"regulator-mode-fast" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_FAST ; +if (of_find_property (np,"regulator-mode-normal" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_NORMAL ; +if (of_find_property (np,"regulator-mode-idle" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_IDLE ; +if (of_find_property (np,"regulator-mode-standby" ,NULL )) + valid_modes_mask |=REGULATOR_MODE_STANDBY ; + +/* valid ops mask */ +if (of_find_property (np,"regulator-change-voltage" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_VOLTAGE ; +if (of_find_property (np,"regulator-change-current" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_CURRENT ; +if (of_find_property (np,"regulator-change-mode" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_MODE ; +if (of_find_property (np,"regulator-change-status" ,NULL )) + valid_ops_mask |=REGULATOR_CHANGE_STATUS ; + + (*init_data)->constraints.valid_modes_mask = valid_modes_mask; + (*init_data)->constraints.valid_ops_mask = valid_ops_mask; + +if (of_find_property (np,"regulator-always-on" ,NULL )) + (*init_data)->constraints.always_on = true; +if (of_find_property (np,"regulator-boot-on" ,NULL )) + (*init_data)->constraints.boot_on = true; +}drivers/regulator/of_regulator.c line 80
Quoted 10 lines
drivers/regulator/of_regulator.c new file +10
-0+ +/** +* of_get_regulator_init_data - extract regulator_init_data structure info +* @dev: device requesting for regulator_init_data +* +* Populates regulator_init_data structure by extracting data from device +* tree node, returns a pointer to the populated struture or NULL if memory +* alloc fails. +*/ +struct regulator_init_data *of_get_regulator_init_data (struct device *dev)I remember that Mark ever had a comment on a previous regulator DT
Quoted 8 lines
series from Haojian Zhuang, saying this DT parsing procedure can probably just be private to regulator core and invisible to regulator drivers. That said whenever
regulator_register()gets called with parameterinit_dataas NULL, it should try to retrieveregulator_init_datafrom device tree. It will ease regulator drivers a little. They will only need to callregulator_register()with NULLinit_datafor DT case. More importantly, doing so will help solve the dual 'dev' problem I see below.
Quoted 5 lines
Yes, it seems like a good idea given that most drivers seem to blindly pass the
regulator_init_dataontoregulator_register, however there are cases like the twl regulator driver which seems to peek into the constraints passed from the board to make sure it drops anything that the hardware does not support,
I'm not sure why twl works in that way. Is it a sign that those configuration peeked by twl regulator driver should be encoded in twl regulator driver itself instead of being passed from the board? Or why the board does not pass something matching driver/hardware capability to save that peek?
Quoted 3 lines
or cases like the db8500 where
regulator_init_datafor all regulators are bundled together and the driver extracts and registers them as separate regulators.
For this particular case, we just end up with having some duplicated constraints description in the dts file. To me, it's not a problem.
Quoted 4 lines
Exporting an
api instead to extractregulator_init_datato the driver might help in those cases.
IMO, these cases should be generalized to fit the common pattern of regulator drivers.
Quoted 17 lines
Quoted 17 lines
drivers/regulator/of_regulator.c
Quoted 12 lines
drivers/regulator/of_regulator.c new file +11
-0+{ +struct regulator_init_data *init_data; + +if (!dev->of_node) +return NULL ; + + init_data =devm_kzalloc (dev,sizeof (*init_data),GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ + +of_get_regulation_constraints (dev->of_node,&init_data);Beside the 'dev' here with
of_nodeattached, there will be another 'dev' created by regulator core functionregulator_register(), which is wrapped by 'regulator_dev'.
Quoted 8 lines
Quoted 3 lines
So we have two 'dev'. One is created by DT core with
of_nodeattached, and used to retrieveregulator_init_datafrom device tree. Another one is created inregulator_register()and used by regulator core.But thats not something newly done now with DT. Thats how it was even in the non-DT world. There were always two devices with the
regulator_devdevice as the child.
Let's look at mc13892-regulator driver. There are 23 regulators defined in array mc13892_regulators. Needless to say, there is a dev behind mc13892-regulator driver. And when getting probed, this driver will call regulator_register() to register those 23 regulators individually. That said, for non-dt world, we have 1 + 23 'dev' with that 1 as the parent of all other 23 'dev' (wrapped by regulator_dev). But with the current DT implementation, we will have at least 1 + 23 * 2 'dev'. These extra 23 'dev' is totally new with DT.
Regards,
Shawn
Quoted 53 lines
Quoted 51 lines
IMO, this is not what we want. Instead of having two 'dev' for given regulator, we should use the same 'dev' created in
regulator_register()to retrieveregulator_init_datafrom device tree, so that we do not need the 'dev' created by DT core. That said, with DT parsing procedure moved into regulator core, we can getof_nodefor given regulator and attach it to the 'dev' created by regulator core.Will elaborate it a little more in patch #5.
Regards,
ShawnQuoted 37 lines
drivers/regulator/of_regulator.c new file +2
-0+return init_data; +}include/linux/regulator/of_regulator.h new file +21
-1@@ -0,0 +1,21 @@ +/* +* OpenFirmware regulator support routines +* +*/ + +#ifndef __LINUX_OF_REG_H +#define __LINUX_OF_REG_H + +#if defined(CONFIG_OF_REGULATOR ) +extern struct regulator_init_data + *of_get_regulator_init_data (struct device *dev); +#else +static inline struct regulator_init_data + *of_get_regulator_init_data (struct device *dev) +{ +return NULL ; +} +#endif /* CONFIG_OF_REGULATOR */ + +#endif /* __LINUX_OF_REG_H */ + --1.7.1
_______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
On Wed, Oct 19, 2011 at 10:42:16PM +0800, Shawn Guo wrote:
*Please* delete irrelevant quotes from mails.
Quoted 8 lines · Rajendra Nayak
Quoted 6 lines
Yes, it seems like a good idea given that most drivers seem to blindly pass the
regulator_init_dataontoregulator_register, however there are cases like the twl regulator driver which seems to peek into the constraints passed from the board to make sure it drops anything that the hardware does not support,
Quoted 5 lines
I'm not sure why twl works in that way. Is it a sign that those configuration peeked by twl regulator driver should be encoded in twl regulator driver itself instead of being passed from the board? Or why the board does not pass something matching driver/hardware capability to save that peek?
It's completely unneeded but harmless, it's there because there were a large number of discussions going on with the original author and it was easier to merge the code.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Shawn GuoQuoted 4 lines
I'm not sure why twl works in that way. Is it a sign that those configuration peeked by twl regulator driver should be encoded in twl regulator driver itself instead of being passed from the board? Or
No, the driver is just trying to make sure that nothing invalid (not supported by hardware) gets passed from the boards.
Quoted 42 lines
why the board does not pass something matching driver/hardware capability to save that peek?
Quoted 3 lines
or cases like the db8500 where
regulator_init_datafor all regulators are bundled together and the driver extracts and registers them as separate regulators.For this particular case, we just end up with having some duplicated constraints description in the dts file. To me, it's not a problem.
Quoted 4 lines
Exporting an
api instead to extractregulator_init_datato the driver might help in those cases.IMO, these cases should be generalized to fit the common pattern of regulator drivers.
Quoted 17 lines
Quoted 17 lines
drivers/regulator/of_regulator.c
Quoted 12 lines
drivers/regulator/of_regulator.c new file +11
-0+{ +struct regulator_init_data *init_data; + +if (!dev->of_node) +return NULL ; + + init_data =devm_kzalloc (dev,sizeof (*init_data),GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ + +of_get_regulation_constraints (dev->of_node,&init_data);Beside the 'dev' here with
of_nodeattached, there will be another 'dev' created by regulator core functionregulator_register(), which is wrapped by 'regulator_dev'.Quoted 8 lines
Quoted 3 lines
So we have two 'dev'. One is created by DT core with
of_nodeattached, and used to retrieveregulator_init_datafrom device tree. Another one is created inregulator_register()and used by regulator core.But thats not something newly done now with DT. Thats how it was even in the non-DT world. There were always two devices with the
regulator_devdevice as the child.
Quoted 9 lines
Let's look at mc13892-regulator driver. There are 23 regulators defined in array
mc13892_regulators. Needless to say, there is a dev behind mc13892-regulator driver. And when getting probed, this driver will callregulator_register()to register those 23 regulators individually. That said, for non-dt world, we have 1 + 23 'dev' with that 1 as the parent of all other 23 'dev' (wrapped byregulator_dev). But with the current DT implementation, we will have at least 1 + 23 * 2 'dev'. These extra 23 'dev' is totally new with DT.
but thats only because the mc13892-regulator driver is implemeted in such a way that all the regulators on the platform are bundled in as *one* device. It would again depend on how you would pass these from the DT, if you indeed stick to the same way of bundling all regulators as one device from DT, the mc13892-regulator probe would just get called once and there would be one device associated, no?
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 10 lines · Rajendra Nayak
Quoted 9 lines
Let's look at mc13892-regulator driver. There are 23 regulators defined in array
mc13892_regulators. Needless to say, there is a dev behind mc13892-regulator driver. And when getting probed, this driver will callregulator_register()to register those 23 regulators individually. That said, for non-dt world, we have 1 + 23 'dev' with that 1 as the parent of all other 23 'dev' (wrapped byregulator_dev). But with the current DT implementation, we will have at least 1 + 23 * 2 'dev'. These extra 23 'dev' is totally new with DT.
Quoted 3 lines
but thats only because the mc13892-regulator driver is implemeted in such a way that all the regulators on the platform are bundled in as *one* device.
I did not look into too many regulator drivers, but I expect this is way that most regulator drivers are implemented in. Having mc13892-regulator being probed 23 times to register these 23 regulators just makes less sense to me.
Quoted 5 lines
It would again depend on how you would pass these from
the DT, if you indeed stick to the same way of bundling all regulators as one device from DT, the mc13892-regulator probe would just get called once and there would be one device associated, no?
Yes, I indeed would stick to the same way of bundling the registration of all regulators with mc13892-regulator being probed once. The problem I have with the current regulator core DT implementation is that it assumes the device_node of rdev->dev (dev wrapped in regulator_dev) is being attached to rdev->dev.parent rather than itself. Back to mc13892-regulator example, that said, it requires the dev of mc13892-regulator have the device_node of individual regulator attached to. IOW, the current implementation forces mc13892-regulator to be probed 23 times to register those 23 regulators. This is wrong to me.
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 25 lines · Shawn Guo
Quoted 10 lines · Rajendra Nayak
Quoted 9 lines
Let's look at mc13892-regulator driver. There are 23 regulators defined in array
mc13892_regulators. Needless to say, there is a dev behind mc13892-regulator driver. And when getting probed, this driver will callregulator_register()to register those 23 regulators individually. That said, for non-dt world, we have 1 + 23 'dev' with that 1 as the parent of all other 23 'dev' (wrapped byregulator_dev). But with the current DT implementation, we will have at least 1 + 23 * 2 'dev'. These extra 23 'dev' is totally new with DT.Quoted 3 lines
but thats only because the mc13892-regulator driver is implemeted in such a way that all the regulators on the platform are bundled in as *one* device.
I did not look into too many regulator drivers, but I expect this is way that most regulator drivers are implemented in. Having mc13892-regulator being probed 23 times to register these 23 regulators just makes less sense to me.
Quoted 5 lines
It would again depend on how you would pass these from
the DT, if you indeed stick to the same way of bundling all regulators as one device from DT, the mc13892-regulator probe would just get called once and there would be one device associated, no?
Quoted 9 lines
Yes, I indeed would stick to the same way of bundling the registration of all regulators with mc13892-regulator being probed once. The problem I have with the current regulator core DT implementation is that it assumes the
device_nodeofrdev->dev(dev wrapped inregulator_dev) is being attached tordev->dev.parentrather than itself. Back to mc13892-regulator example, that said, it requires the dev of mc13892-regulator have thedevice_nodeof individual regulator attached to. IOW, the current implementation forces mc13892-regulator to be probed 23 times to register those 23 regulators. This is wrong to me.
I think I now understand to some extent the problem that you seem to be reporting. It is mainly with drivers which bundle all regulators and pass them as one device and would want to do so with DT too.
however I am still not clear on how what you seem to suggest would solve this problem. Note that not all drivers do it this way, and there are drivers where each regulator is considered as one device and I suspect they would remain that way with DT too. And hence we need to support both.
Do you have any RFC patch/code which could explain better what you are suggesting we do here?
Quoted 1 line
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 40 lines · Rajendra Nayak
Quoted 25 lines · Shawn Guo
Quoted 10 lines · Rajendra Nayak
Quoted 9 lines
Let's look at mc13892-regulator driver. There are 23 regulators defined in array
mc13892_regulators. Needless to say, there is a dev behind mc13892-regulator driver. And when getting probed, this driver will callregulator_register()to register those 23 regulators individually. That said, for non-dt world, we have 1 + 23 'dev' with that 1 as the parent of all other 23 'dev' (wrapped byregulator_dev). But with the current DT implementation, we will have at least 1 + 23 * 2 'dev'. These extra 23 'dev' is totally new with DT.Quoted 3 lines
but thats only because the mc13892-regulator driver is implemeted in such a way that all the regulators on the platform are bundled in as *one* device.
I did not look into too many regulator drivers, but I expect this is way that most regulator drivers are implemented in. Having mc13892-regulator being probed 23 times to register these 23 regulators just makes less sense to me.
Quoted 5 lines
It would again depend on how you would pass these from
the DT, if you indeed stick to the same way of bundling all regulators as one device from DT, the mc13892-regulator probe would just get called once and there would be one device associated, no?Quoted 9 lines
Yes, I indeed would stick to the same way of bundling the registration of all regulators with mc13892-regulator being probed once. The problem I have with the current regulator core DT implementation is that it assumes the
device_nodeofrdev->dev(dev wrapped inregulator_dev) is being attached tordev->dev.parentrather than itself. Back to mc13892-regulator example, that said, it requires the dev of mc13892-regulator have thedevice_nodeof individual regulator attached to. IOW, the current implementation forces mc13892-regulator to be probed 23 times to register those 23 regulators. This is wrong to me.I think I now understand to some extent the problem that you seem to be reporting. It is mainly with drivers which bundle all regulators and pass them as one device and would want to do so with DT too.
Quoted 9 lines
however I am still not clear on how what you seem to suggest would solve this problem. Note that not all drivers do it this way, and there are drivers where each regulator is considered as one device and I suspect they would remain that way with DT too. And hence we need to support both.
Do you have any RFC patch/code which could explain better what you are suggesting we do here?
Quoted 1 line
Here is what I changed based on your patches. It only changes drivers/regulator/core.c.
---8<-------
drivers/regulator/core.c +18 -11
@@ -1211,7 +1211,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, node =of_get_regulator (dev, id);if (node)list_for_each_entry (rdev, ®ulator_list, list) -if (node == rdev->dev.parent->of_node) +if (node == rdev->dev.of_node) goto found; }list_for_each_entry (map, ®ulator_map_list, list) {
@@ -2642,9 +2642,6 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, regulator_desc->type != REGULATOR_CURRENT)return ERR_PTR (-EINVAL ); -if (!init_data) -return ERR_PTR (-EINVAL ); -/* Only one of each should be implemented */ WARN_ON (regulator_desc->ops->get_voltage && regulator_desc->ops->get_voltage_sel);
@@ -2675,12 +2672,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,INIT_LIST_HEAD (&rdev->list);BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier); -/* preform any regulator specific init */ -if (init_data->regulator_init) { - ret = init_data->regulator_init (rdev->reg_data); -if (ret <0 ) - goto clean; - } +/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);/* register with sysfs */ rdev->dev.class = ®ulator_class;
@@ -2693,6 +2686,20 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, goto clean; } +if (!init_data) { +/* try to get init_data from device tree */ + init_data =of_get_regulator_init_data (&rdev->dev); +if (!init_data) +return ERR_PTR (-EINVAL ); + } + +/* preform any regulator specific init */ +if (init_data->regulator_init) { + ret = init_data->regulator_init (rdev->reg_data); +if (ret <0 ) + goto clean; + } +dev_set_drvdata (&rdev->dev, rdev);/* set regulator constraints */
@@ -2719,7 +2726,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, node =of_get_regulator (dev, supply);if (node)list_for_each_entry (r, ®ulator_list, list) -if (node == r->dev.parent->of_node) +if (node == r->dev.of_node) goto found; }
------->8---
And my dts file looks like something below.
ecspi@70010000 { /* ECSPI1 */
fsl,spi-num-chipselects = <2>;
cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */
<&gpio3 25 0>; /* GPIO4_25 */
status = "okay";
pmic: mc13892@0 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "fsl,mc13892";
spi-max-frequency = <6000000>;
reg = <0>;
mc13xxx-irq-gpios = <&gpio0 8 0>; /* GPIO1_8 */
regulators {
sw1reg: mc13892_sw1 {
regulator-min-uV = <600000>;
regulator-max-uV = <1375000>;
regulator-change-voltage;
regulator-boot-on;
regulator-always-on;
};
sw2reg: mc13892_sw2 {
regulator-min-uV = <900000>;
regulator-max-uV = <1850000>;
regulator-change-voltage;
regulator-boot-on;
regulator-always-on;
};
......
};
leds {
......
};
buttons {
......
};
};
flash: at45db321d@1 {
......
};
};
};Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 33 lines
Quoted 4 lines
Do you have any RFC patch/code which could explain better what you are suggesting we do here?
Quoted 1 line
Here is what I changed based on your patches. It only changes
drivers/regulator/core.c.---8<-------
drivers/regulator/core.c +1
-4@@ -1211,7 +1211,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, node =of_get_regulator (dev, id);if (node)list_for_each_entry (rdev,®ulator_list, list) -if (node == rdev->dev.parent->of_node) +if (node == rdev->dev.of_node) goto found; }list_for_each_entry (map,®ulator_map_list, list) {@@ -2642,9 +2642,6 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, regulator_desc->type != REGULATOR_CURRENT)return ERR_PTR (-EINVAL ); -if (!init_data) -return ERR_PTR (-EINVAL ); -/* Only one of each should be implemented */ WARN_ON (regulator_desc->ops->get_voltage&& regulator_desc->ops->get_voltage_sel);@@ -2675,12 +2672,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,INIT_LIST_HEAD (&rdev->list);
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2676
Quoted 10 lines
drivers/regulator/core.c +2
-6BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier); -/* preform any regulator specific init */ -if (init_data->regulator_init) { - ret = init_data->regulator_init (rdev->reg_data); -if (ret<0 ) - goto clean; - } +/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);
so would this do a complete dt search for every regulator? we would also need the driver names and dt names to match for this to work, right?
The approach otherwise looks fine to me and should work for both cases of one device per regulator and one device for all regulators.
Quoted 86 lines
drivers/regulator/core.c +15
-2/* register with sysfs */ rdev->dev.class =®ulator_class;@@ -2693,6 +2686,20 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, goto clean; } +if (!init_data) { +/* try to get init_data from device tree */ + init_data =of_get_regulator_init_data (&rdev->dev); +if (!init_data) +return ERR_PTR (-EINVAL ); + } + +/* preform any regulator specific init */ +if (init_data->regulator_init) { + ret = init_data->regulator_init (rdev->reg_data); +if (ret<0 ) + goto clean; + } +dev_set_drvdata (&rdev->dev, rdev);/* set regulator constraints */ @@ -2719,7 +2726,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, node =of_get_regulator (dev, supply);if (node)list_for_each_entry (r,®ulator_list, list) -if (node == r->dev.parent->of_node) +if (node == r->dev.of_node) goto found; } ------->8---And my dts file looks like something below.
ecspi at 70010000 { /* ECSPI1 */ fsl,spi-num-chipselects =<2>; cs-gpios =<&gpio3 24 0>, /* GPIO4_24 */ <&gpio3 25 0>; /* GPIO4_25 */ status = "okay"; pmic: mc13892 at 0 { #address-cells =<1>; #size-cells =<0>; compatible = "fsl,mc13892"; spi-max-frequency =<6000000>; reg =<0>; mc13xxx-irq-gpios =<&gpio0 8 0>; /* GPIO1_8 */ regulators { sw1reg: mc13892_sw1 { regulator-min-uV =<600000>; regulator-max-uV =<1375000>; regulator-change-voltage; regulator-boot-on; regulator-always-on; }; sw2reg: mc13892_sw2 { regulator-min-uV =<900000>; regulator-max-uV =<1850000>; regulator-change-voltage; regulator-boot-on; regulator-always-on; }; ...... }; leds { ...... }; buttons { ...... }; }; flash: at45db321d at 1 { ...... }; }; };
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
On Fri, Oct 21, 2011 at 02:11:55PM +0530, Rajendra Nayak wrote:
[...]
Quoted 4 lines
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2676
Quoted 2 lines
drivers/regulator/core.c +2
-0+/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);so would this do a complete dt search for every regulator?
Yes, with the first param being NULL, tthe entire device tree will be searched.
Quoted 3 lines
we would also need the driver names and dt names to match for this to work, right?
Driver name does not matter. The key for this search to work is having regulator's name (regulator_desc->name) match device tree node's name, case ignored.
Quoted 3 lines
The approach otherwise looks fine to me and should work for both cases of one device per regulator and one device for all regulators.
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 10 lines · Shawn Guo
On Fri, Oct 21, 2011 at 02:11:55PM +0530, Rajendra Nayak wrote:
[...]Quoted 4 lines
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2676
Quoted 2 lines
drivers/regulator/core.c +2
-0+/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);so would this do a complete dt search for every regulator?
Yes, with the first param being NULL, tthe entire device tree will be searched.
Quoted 6 lines
Quoted 3 lines
we would also need the driver names and dt names to match for this to work, right?
Driver name does not matter. The key for this search to work is having regulator's name (
regulator_desc->name) match device tree node's name, case ignored.
Mark, whats your take on this? I am somehow not quite sure if we should have this limitation put in to match DT node names with whats in the driver structs (regulator_desc).
Quoted 5 lines
Quoted 4 lines
The approach otherwise looks fine to me and should work for both cases of one device per regulator and one device for all regulators.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 9 lines · Rajendra Nayak
Quoted 3 lines · Shawn Guo
Driver name does not matter. The key for this search to work is having regulator's name (
regulator_desc->name) match device tree node's name, case ignored.Mark, whats your take on this? I am somehow not quite sure if we should have this limitation put in to match DT node names with whats in the driver structs (
regulator_desc).
If we're matching the string in the regulator_desc I'd expect we're going to run into trouble with systems that have two of the same type of regulator in the system. Is that the case? Since my primary development system is such a system I care deeply about them :)
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Rajendra NayakQuoted 14 lines · Rajendra Nayak
Quoted 13 lines · Shawn Guo
On Fri, Oct 21, 2011 at 02:11:55PM +0530, Rajendra Nayak wrote:
[...]Quoted 4 lines
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2676
Quoted 2 lines
drivers/regulator/core.c +2
-0+/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);so would this do a complete dt search for every regulator?
Yes, with the first param being NULL, tthe entire device tree will be searched.
Quoted 3 lines
we would also need the driver names and dt names to match for this to work, right?
Quoted 7 lines
Quoted 3 lines
Driver name does not matter. The key for this search to work is having regulator's name (
regulator_desc->name) match device tree node's name, case ignored.Mark, whats your take on this? I am somehow not quite sure if we should have this limitation put in to match DT node names with whats in the driver structs (
regulator_desc).
This looks wrong to me. Matching based on node /name/, particularly when searching the entire tree, will cause problems.
g.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 19 lines · Grant Likely
Quoted 18 lines · Rajendra Nayak
Quoted 16 lines · Shawn Guo
On Fri, Oct 21, 2011 at 02:11:55PM +0530, Rajendra Nayak wrote:
[...]Quoted 4 lines
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2676
Quoted 2 lines
drivers/regulator/core.c +2
-0+/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);so would this do a complete dt search for every regulator?
Yes, with the first param being NULL, tthe entire device tree will be searched.
Quoted 3 lines
we would also need the driver names and dt names to match for this to work, right?
Driver name does not matter. The key for this search to work is having regulator's name (
regulator_desc->name) match device tree node's name, case ignored.
Quoted 7 lines
Quoted 3 lines
Mark, whats your take on this? I am somehow not quite sure if we should have this limitation put in to match DT node names with whats in the driver structs (
regulator_desc).This looks wrong to me. Matching based on node /name/, particularly when searching the entire tree, will cause problems.
Okay, it's wrong then since so many people say it's wrong :) I guess a quick fix would be adding one property in device tree node for matching some unique field in regulator_desc, id, maybe? Mark, any suggestion?
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 24 lines · Shawn Guo
Quoted 23 lines · Grant Likely
Quoted 21 lines · Rajendra Nayak
Quoted 10 lines · Shawn Guo
On Fri, Oct 21, 2011 at 02:11:55PM +0530, Rajendra Nayak wrote:
[...]Quoted 4 lines
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2676
Quoted 2 lines
drivers/regulator/core.c +2
-0+/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);so would this do a complete dt search for every regulator?
Yes, with the first param being NULL, tthe entire device tree will be searched.
Quoted 6 lines
Quoted 3 lines
we would also need the driver names and dt names to match for this to work, right?
Driver name does not matter. The key for this search to work is having regulator's name (
regulator_desc->name) match device tree node's name, case ignored.Mark, whats your take on this? I am somehow not quite sure if we should have this limitation put in to match DT node names with whats in the driver structs (
regulator_desc).
Quoted 7 lines
Quoted 3 lines
This looks wrong to me. Matching based on node /name/, particularly when searching the entire tree, will cause problems.
Okay, it's wrong then since so many people say it's wrong :) I guess a quick fix would be adding one property in device tree node for matching some unique field in
regulator_desc, id, maybe? Mark, any suggestion?
Thats basically what the DT compatible property is for :)
Quoted 1 line
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 7 lines · Rajendra Nayak
Quoted 4 lines · Shawn Guo
Okay, it's wrong then since so many people say it's wrong :) I guess a quick fix would be adding one property in device tree node for matching some unique field in
regulator_desc, id, maybe? Mark, any suggestion?Thats basically what the DT compatible property is for :)
But adding compatible property will get DT core create 'struct dev' for each regulator node, while we are trying to avoid that since regulator core has been doing this.
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 7 lines · Shawn Guo
Quoted 6 lines · Rajendra Nayak
Quoted 4 lines · Shawn Guo
Okay, it's wrong then since so many people say it's wrong :) I guess a quick fix would be adding one property in device tree node for matching some unique field in
regulator_desc, id, maybe? Mark, any suggestion?
Quoted 6 lines
Quoted 1 line
Thats basically what the DT compatible property is for :)
But adding compatible property will get DT core create 'struct dev' for each regulator node, while we are trying to avoid that since regulator core has been doing this.
No it won't.
So here's what I am suggesting.
Case 1:
One device per regulator:
DT nodes look something like this
reg1: reg at 1 {
...
...
};reg2: reg at 2 {
...
...
};The regulator driver probes 2 devices and each time the dev passed has a of_node associated which the regulator driver can then pass to the core.
Case 2:
One device for all regulators:
DT nodes look something like this
regulators {
reg1: reg at 1 {
...
...
};
reg2: reg at 2 {
...
...
};
};The regulator driver probes only one device and the dev->of_node points to the "regulators" node above.
The regulator driver then based on compatible property extracts and registers all the child nodes of "regulators" (for ex: reg1, reg2 above) with each call to regulator_register and passes the child nodes as of_node to be associated with the regulator device.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 17 lines · Rajendra Nayak
Case 2:
One device for all regulators:DT nodes look something like this
regulators { reg1: reg@1 { ... ... }; reg2: reg@2 { ... ... }; };
Quoted 2 lines
The regulator driver probes only one device and the
dev->of_nodepoints to the "regulators" node above.
The mc13892 example I put in the reply to Grant demonstrates that for some case, dev->of_node is NULL (devices are created by mfd core).
Quoted 5 lines
The regulator driver then based on compatible property extracts and registers all the child nodes of "regulators" (for ex: reg1, reg2 above) with each call to
regulator_registerand passes the child nodes asof_nodeto be associated with the regulator device.
I still think the discovery of all the child nodes of "regulators" does not necessarily need to be done in regulator driver. Instead, it can be done in regulator core.
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 18 lines · Shawn Guo
Quoted 17 lines · Rajendra Nayak
Case 2:
One device for all regulators:DT nodes look something like this
regulators { reg1: reg at 1 { ... ... }; reg2: reg at 2 { ... ... }; };
Quoted 5 lines
Quoted 2 lines
The regulator driver probes only one device and the
dev->of_nodepoints to the "regulators" node above.The mc13892 example I put in the reply to Grant demonstrates that for some case,
dev->of_nodeis NULL (devices are created by mfd core).
In that case should you not be first converting the mfd driver to register regulator devices using DT?
Thats what we did for OMAP, and hence we always have the of_node populated when the regulator devices are probed.
See this patch from Benoit on how thats done for twl devices..
http://marc.info/?l=linux-omap&m=131489864814428&w=2
Quoted 10 lines
Quoted 6 lines
The regulator driver then based on compatible property extracts and registers all the child nodes of "regulators" (for ex: reg1, reg2 above) with each call to
regulator_registerand passes the child nodes asof_nodeto be associated with the regulator device.I still think the discovery of all the child nodes of "regulators" does not necessarily need to be done in regulator driver. Instead, it can be done in regulator core.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 7 lines · Rajendra Nayak
In that case should you not be first converting the mfd driver to register regulator devices using DT?
Thats what we did for OMAP, and hence we always have theof_nodepopulated when the regulator devices are probed.
See this patch from Benoit on how thats done for twl devices..
http://marc.info/?l=linux-omap&m=131489864814428&w=2
Sorry, that was a link to an older version of the patch. Here's the latest one from Benoit which he did based on Arnd's suggestion of using of_platform_populate() directly.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Rajendra NayakQuoted 19 lines · Rajendra Nayak
Quoted 18 lines · Shawn Guo
Quoted 17 lines · Rajendra Nayak
Case 2:
One device for all regulators:DT nodes look something like this
regulators { reg1: reg@1 { ... ... }; reg2: reg@2 { ... ... }; };
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The regulator driver probes only one device and the
dev->of_nodepoints to the "regulators" node above.The mc13892 example I put in the reply to Grant demonstrates that for some case,
dev->of_nodeis NULL (devices are created by mfd core).In that case should you not be first converting the mfd driver to register regulator devices using DT?
The mc13892 mfd driver calls mfd_add_devices() to add device for mc13892 regulator driver. Are you suggesting that I should hack mfd_add_devices() to have device_node of 'regulators' attached? The mfd is not a bus like i2c and spi, so I'm not sure this is the right thing to do.
Quoted 5 lines
Thats what we did for OMAP, and hence we always have the
of_nodepopulated when the regulator devices are probed.
See this patch from Benoit on how thats done for twl devices..
http://marc.info/?l=linux-omap&m=131489864814428&w=2
OMAP is "Case 1", and we are talking about "Case 2".
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 35 lines · Shawn Guo
Quoted 19 lines · Rajendra Nayak
Quoted 18 lines · Shawn Guo
Quoted 17 lines · Rajendra Nayak
Case 2:
One device for all regulators:DT nodes look something like this
regulators { reg1: reg at 1 { ... ... }; reg2: reg at 2 { ... ... }; };Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The regulator driver probes only one device and the
dev->of_nodepoints to the "regulators" node above.The mc13892 example I put in the reply to Grant demonstrates that for some case,
dev->of_nodeis NULL (devices are created by mfd core).In that case should you not be first converting the mfd driver to register regulator devices using DT?
The mc13892 mfd driver calls
mfd_add_devices()to add device for mc13892 regulator driver. Are you suggesting that I should hackmfd_add_devices()to havedevice_nodeof 'regulators' attached? The mfd is not a bus like i2c and spi, so I'm not sure this is the right thing to do.
Quoted 6 lines
Quoted 5 lines
Thats what we did for OMAP, and hence we always have the
of_nodepopulated when the regulator devices are probed.
See this patch from Benoit on how thats done for twl devices..
http://marc.info/?l=linux-omap&m=131489864814428&w=2OMAP is "Case 1", and we are talking about "Case 2".
I don't see why it wouldn't work for "Case 2". The only difference is in case of "Case 1", the dev->of_node would already point to the right regulator node, like 'reg1', 'reg2' above.
In case of "Case 2", the dev->of_node would point to the 'regulators' node instead, and the driver could then do a for_each_child_of_node() to iterate over all its children to get 'reg1', 'reg2' etc.
Quoted 1 line
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 2 lines · Rajendra Nayak
Quoted 1 line · Shawn Guo
On Tue, Oct 25, 2011 at 11:30:19AM +0530, Rajendra Nayak wrote:
[...]
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Thats what we did for OMAP, and hence we always have the
of_nodepopulated when the regulator devices are probed.
See this patch from Benoit on how thats done for twl devices..
http://marc.info/?l=linux-omap&m=131489864814428&w=2OMAP is "Case 1", and we are talking about "Case 2".
I don't see why it wouldn't work for "Case 2".
I did not say it wouldn't work for "Case 2". I meant they work in different way.
Quoted 7 lines
The only difference
is in case of "Case 1", thedev->of_nodewould already point to the right regulator node, like 'reg1', 'reg2' above.
In case of "Case 2", thedev->of_nodewould point to the 'regulators' node instead, and the driver could then do afor_each_child_of_node()to iterate over all its children to get 'reg1', 'reg2' etc.
Yes, that's the difference. So you will need to distinguish these two cases in regulator_register()? How?
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 23 lines · Shawn Guo
Quoted 2 lines · Rajendra Nayak
Quoted 1 line · Shawn Guo
On Tue, Oct 25, 2011 at 11:30:19AM +0530, Rajendra Nayak wrote:
[...]
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Thats what we did for OMAP, and hence we always have the
of_nodepopulated when the regulator devices are probed.
See this patch from Benoit on how thats done for twl devices..
http://marc.info/?l=linux-omap&m=131489864814428&w=2OMAP is "Case 1", and we are talking about "Case 2".
I don't see why it wouldn't work for "Case 2".
I did not say it wouldn't work for "Case 2". I meant they work in different way.
Quoted 7 lines
The only difference
is in case of "Case 1", thedev->of_nodewould already point to the right regulator node, like 'reg1', 'reg2' above.
In case of "Case 2", thedev->of_nodewould point to the 'regulators' node instead, and the driver could then do afor_each_child_of_node()to iterate over all its children to get 'reg1', 'reg2' etc.
Quoted 2 lines
Yes, that's the difference. So you will need to distinguish these two cases in
regulator_register()? How?
You don't need to distinguish these cases in regulator_register(). The driver knows if its handling "Case 1" devices or "Case 2" devices and it needs to handle things accordingly and pass the right of_node which regulator_register() can then attach to regulator_dev->dev.
Quoted 1 line
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 24 lines · Rajendra Nayak
Quoted 23 lines · Shawn Guo
Quoted 2 lines · Rajendra Nayak
Quoted 1 line · Shawn Guo
On Tue, Oct 25, 2011 at 11:30:19AM +0530, Rajendra Nayak wrote:
[...]
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Thats what we did for OMAP, and hence we always have the
of_nodepopulated when the regulator devices are probed.
See this patch from Benoit on how thats done for twl devices..
http://marc.info/?l=linux-omap&m=131489864814428&w=2OMAP is "Case 1", and we are talking about "Case 2".
I don't see why it wouldn't work for "Case 2".
I did not say it wouldn't work for "Case 2". I meant they work in different way.
Quoted 7 lines
The only difference
is in case of "Case 1", thedev->of_nodewould already point to the right regulator node, like 'reg1', 'reg2' above.
In case of "Case 2", thedev->of_nodewould point to the 'regulators' node instead, and the driver could then do afor_each_child_of_node()to iterate over all its children to get 'reg1', 'reg2' etc.
Quoted 8 lines
Quoted 2 lines
Yes, that's the difference. So you will need to distinguish these two cases in
regulator_register()? How?You don't need to distinguish these cases in
regulator_register(). The driver knows if its handling "Case 1" devices or "Case 2" devices and it needs to handle things accordingly and pass the rightof_nodewhichregulator_register()can then attach toregulator_dev->dev.
Ah, you are thinking about (for Case 2) calling for_each_child_of_node() in regulator driver and passing the of_node found for each regulator to regulator core as a new parameter of regulator_register(). Yes, that would work, though my thought is to put the device_node discovery in regulator core and hide it from regulator driver.
Okay, I'm good with this solution. Grant, Mark, what about you?
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Shawn GuoQuoted 7 lines · Shawn Guo
Quoted 6 lines · Rajendra Nayak
Quoted 4 lines · Shawn Guo
Okay, it's wrong then since so many people say it's wrong :) I guess a quick fix would be adding one property in device tree node for matching some unique field in
regulator_desc, id, maybe? Mark, any suggestion?
Quoted 5 lines
Quoted 1 line
Thats basically what the DT compatible property is for :)
But adding compatible property will get DT core create 'struct dev' for each regulator node, while we are trying to avoid that since regulator core has been doing this.
By design, of_platform_populate() will only go one level deep except if it matches the passed in list of bus compatible properties. Having a compatible property does not necessarily create a struct dev.
That said, I agree with you that a compatible property isn't really needed in the child nodes **if it is defined as part of the parent node's binding**.
g.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Grant LikelyQuoted 6 lines · Grant Likely
Quoted 5 lines · Rajendra Nayak
Quoted 4 lines · Shawn Guo
On Fri, Oct 21, 2011 at 02:11:55PM +0530, Rajendra Nayak wrote:
[...]Quoted 2 lines
Quoted 2 lines
drivers/regulator/core.c +2
-0+/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);
Shawn/Mark,
How about the driver passing the of_node to be associated with the regulator, as part of regulator_desc, to the regulator core, instead of this complete DT search and the restriction of having to match DT node names with names in regulator_desc.
regards,
Rajendra
Quoted 21 lines
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
so would this do a complete dt search for every regulator?
Yes, with the first param being NULL, tthe entire device tree will be searched.
Quoted 3 lines
we would also need the driver names and dt names to match for this to work, right?
Quoted 7 lines
Quoted 3 lines
Driver name does not matter. The key for this search to work is having regulator's name (
regulator_desc->name) match device tree node's name, case ignored.Mark, whats your take on this? I am somehow not quite sure if we should have this limitation put in to match DT node names with whats in the driver structs (
regulator_desc).This looks wrong to me. Matching based on node /name/, particularly when searching the entire tree, will cause problems.
g.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 8 lines · Rajendra Nayak
Quoted 6 lines · Grant Likely
Quoted 5 lines · Rajendra Nayak
Quoted 4 lines · Shawn Guo
On Fri, Oct 21, 2011 at 02:11:55PM +0530, Rajendra Nayak wrote:
[...]Quoted 2 lines
Quoted 2 lines
drivers/regulator/core.c +2
-0+/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);
Quoted 7 lines
Shawn/Mark,
How about the driver passing the
of_nodeto be associated with the regulator, as part ofregulator_desc, to the regulator core, instead of this complete DT search and the restriction of having to match DT node names with names inregulator_desc.
If you agree that we should try to get DT core from creating 'struct dev' for each regulator, the of_node is not being attached to any 'struct dev' in regulator driver either, so there is no difference between finding the of_node in regulator driver and in regulator core.
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Rajendra NayakQuoted 4 lines · Rajendra Nayak
How about the driver passing the
of_nodeto be associated with the regulator, as part ofregulator_desc, to the regulator core, instead of this complete DT search and the restriction of having to match DT node names with names inregulator_desc.
regulator_desc should be const so that we handle multiple instances of the same device nicely. We could pass the information in as an argument I guess.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 10 lines · Mark Brown
Quoted 4 lines · Rajendra Nayak
How about the driver passing the
of_nodeto be associated with the regulator, as part ofregulator_desc, to the regulator core, instead of this complete DT search and the restriction of having to match DT node names with names inregulator_desc.
regulator_descshould be const so that we handle multiple instances of the same device nicely. We could pass the information in as an argument I guess.
Ok, will do. The only downside being that all existing users would need to be changed.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Shawn GuoQuoted 151 lines · Shawn Guo
Quoted 40 lines · Rajendra Nayak
Quoted 25 lines · Shawn Guo
Quoted 10 lines · Rajendra Nayak
Quoted 9 lines
Let's look at mc13892-regulator driver. There are 23 regulators defined in array
mc13892_regulators. Needless to say, there is a dev behind mc13892-regulator driver. And when getting probed, this driver will callregulator_register()to register those 23 regulators individually. That said, for non-dt world, we have 1 + 23 'dev' with that 1 as the parent of all other 23 'dev' (wrapped byregulator_dev). But with the current DT implementation, we will have at least 1 + 23 * 2 'dev'. These extra 23 'dev' is totally new with DT.Quoted 3 lines
but thats only because the mc13892-regulator driver is implemeted in such a way that all the regulators on the platform are bundled in as *one* device.
I did not look into too many regulator drivers, but I expect this is way that most regulator drivers are implemented in. Having mc13892-regulator being probed 23 times to register these 23 regulators just makes less sense to me.
Quoted 5 lines
It would again depend on how you would pass these from
the DT, if you indeed stick to the same way of bundling all regulators as one device from DT, the mc13892-regulator probe would just get called once and there would be one device associated, no?Quoted 9 lines
Yes, I indeed would stick to the same way of bundling the registration of all regulators with mc13892-regulator being probed once. The problem I have with the current regulator core DT implementation is that it assumes the
device_nodeofrdev->dev(dev wrapped inregulator_dev) is being attached tordev->dev.parentrather than itself. Back to mc13892-regulator example, that said, it requires the dev of mc13892-regulator have thedevice_nodeof individual regulator attached to. IOW, the current implementation forces mc13892-regulator to be probed 23 times to register those 23 regulators. This is wrong to me.I think I now understand to some extent the problem that you seem to be reporting. It is mainly with drivers which bundle all regulators and pass them as one device and would want to do so with DT too.
Quoted 9 lines
however I am still not clear on how what you seem to suggest would solve this problem. Note that not all drivers do it this way, and there are drivers where each regulator is considered as one device and I suspect they would remain that way with DT too. And hence we need to support both.
Do you have any RFC patch/code which could explain better what you are suggesting we do here?
Quoted 1 line
Here is what I changed based on your patches. It only changes
drivers/regulator/core.c.---8<-------
drivers/regulator/core.c +18
-12@@ -1211,7 +1211,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, node =of_get_regulator (dev, id);if (node)list_for_each_entry (rdev, ®ulator_list, list) -if (node == rdev->dev.parent->of_node) +if (node == rdev->dev.of_node) goto found; }list_for_each_entry (map, ®ulator_map_list, list) {@@ -2642,9 +2642,6 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, regulator_desc->type != REGULATOR_CURRENT)return ERR_PTR (-EINVAL ); -if (!init_data) -return ERR_PTR (-EINVAL ); -/* Only one of each should be implemented */ WARN_ON (regulator_desc->ops->get_voltage && regulator_desc->ops->get_voltage_sel);@@ -2675,12 +2672,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,INIT_LIST_HEAD (&rdev->list);BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier); -/* preform any regulator specific init */ -if (init_data->regulator_init) { - ret = init_data->regulator_init (rdev->reg_data); -if (ret <0 ) - goto clean; - } +/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);/* register with sysfs */ rdev->dev.class = ®ulator_class;@@ -2693,6 +2686,20 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, goto clean; } +if (!init_data) { +/* try to get init_data from device tree */ + init_data =of_get_regulator_init_data (&rdev->dev); +if (!init_data) +return ERR_PTR (-EINVAL ); + } + +/* preform any regulator specific init */ +if (init_data->regulator_init) { + ret = init_data->regulator_init (rdev->reg_data); +if (ret <0 ) + goto clean; + } +dev_set_drvdata (&rdev->dev, rdev);/* set regulator constraints */ @@ -2719,7 +2726,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, node =of_get_regulator (dev, supply);if (node)list_for_each_entry (r, ®ulator_list, list) -if (node == r->dev.parent->of_node) +if (node == r->dev.of_node) goto found; } ------->8---And my dts file looks like something below.
ecspi at 70010000 { /* ECSPI1 */ fsl,spi-num-chipselects = <2>; cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */ <&gpio3 25 0>; /* GPIO4_25 */ status = "okay"; pmic: mc13892 at 0 { #address-cells = <1>; #size-cells = <0>; compatible = "fsl,mc13892"; spi-max-frequency = <6000000>; reg = <0>; mc13xxx-irq-gpios = <&gpio0 8 0>; /* GPIO1_8 */ regulators { sw1reg: mc13892_sw1 { regulator-min-uV = <600000>; regulator-max-uV = <1375000>; regulator-change-voltage; regulator-boot-on; regulator-always-on; }; sw2reg: mc13892_sw2 { regulator-min-uV = <900000>;
Quoted 8 lines
regulator-max-uV = <1850000>; regulator-change-voltage; regulator-boot-on; regulator-always-on; }; ...... };
To follow up from my earlier comment, this .dts structure looks fine and reasonable to me, and it would also be fine for the mc13892 driver to use for_each_child_of_node() to find all the children of the regulators node. Even finding the 'regulators' node by name from the mc13892 driver is perfectly fine provided for_each_child_of_node is used to find it. All of this is okay because it is under the umbrella of the "fsl,mc13892" binding.
What isn't okay is doing a whole tree search for nodes by name because there is a high likelyhood of getting a conflict (and yes, I realized that this example has the device name encoded into the node name, but that doesn't change the fact that deep searches by name are bad practice).
g.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 7 lines · Grant Likely
To follow up from my earlier comment, this .dts structure looks fine and reasonable to me, and it would also be fine for the mc13892 driver to use
for_each_child_of_node()to find all the children of the regulators node. Even finding the 'regulators' node by name from the mc13892 driver is perfectly fine providedfor_each_child_of_nodeis used to find it. All of this is okay because it is under the umbrella of the "fsl,mc13892" binding.
Yes, a search of children of the device node that the driver is probing off seems like a sensible approach.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Grant LikelyQuoted 158 lines · Grant Likely
Quoted 157 lines · Shawn Guo
Quoted 40 lines · Rajendra Nayak
Quoted 25 lines · Shawn Guo
Quoted 10 lines · Rajendra Nayak
Quoted 9 lines
Let's look at mc13892-regulator driver. There are 23 regulators defined in array
mc13892_regulators. Needless to say, there is a dev behind mc13892-regulator driver. And when getting probed, this driver will callregulator_register()to register those 23 regulators individually. That said, for non-dt world, we have 1 + 23 'dev' with that 1 as the parent of all other 23 'dev' (wrapped byregulator_dev). But with the current DT implementation, we will have at least 1 + 23 * 2 'dev'. These extra 23 'dev' is totally new with DT.Quoted 3 lines
but thats only because the mc13892-regulator driver is implemeted in such a way that all the regulators on the platform are bundled in as *one* device.
I did not look into too many regulator drivers, but I expect this is way that most regulator drivers are implemented in. Having mc13892-regulator being probed 23 times to register these 23 regulators just makes less sense to me.
Quoted 5 lines
It would again depend on how you would pass these from
the DT, if you indeed stick to the same way of bundling all regulators as one device from DT, the mc13892-regulator probe would just get called once and there would be one device associated, no?Quoted 9 lines
Yes, I indeed would stick to the same way of bundling the registration of all regulators with mc13892-regulator being probed once. The problem I have with the current regulator core DT implementation is that it assumes the
device_nodeofrdev->dev(dev wrapped inregulator_dev) is being attached tordev->dev.parentrather than itself. Back to mc13892-regulator example, that said, it requires the dev of mc13892-regulator have thedevice_nodeof individual regulator attached to. IOW, the current implementation forces mc13892-regulator to be probed 23 times to register those 23 regulators. This is wrong to me.I think I now understand to some extent the problem that you seem to be reporting. It is mainly with drivers which bundle all regulators and pass them as one device and would want to do so with DT too.
Quoted 9 lines
however I am still not clear on how what you seem to suggest would solve this problem. Note that not all drivers do it this way, and there are drivers where each regulator is considered as one device and I suspect they would remain that way with DT too. And hence we need to support both.
Do you have any RFC patch/code which could explain better what you are suggesting we do here?
Quoted 1 line
Here is what I changed based on your patches. It only changes
drivers/regulator/core.c.---8<-------
drivers/regulator/core.c +18
-12@@ -1211,7 +1211,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, node =of_get_regulator (dev, id);if (node)list_for_each_entry (rdev, ®ulator_list, list) -if (node == rdev->dev.parent->of_node) +if (node == rdev->dev.of_node) goto found; }list_for_each_entry (map, ®ulator_map_list, list) {@@ -2642,9 +2642,6 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, regulator_desc->type != REGULATOR_CURRENT)return ERR_PTR (-EINVAL ); -if (!init_data) -return ERR_PTR (-EINVAL ); -/* Only one of each should be implemented */ WARN_ON (regulator_desc->ops->get_voltage && regulator_desc->ops->get_voltage_sel);@@ -2675,12 +2672,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,INIT_LIST_HEAD (&rdev->list);BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier); -/* preform any regulator specific init */ -if (init_data->regulator_init) { - ret = init_data->regulator_init (rdev->reg_data); -if (ret <0 ) - goto clean; - } +/* find device_node and attach it */ + rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name);/* register with sysfs */ rdev->dev.class = ®ulator_class;@@ -2693,6 +2686,20 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, goto clean; } +if (!init_data) { +/* try to get init_data from device tree */ + init_data =of_get_regulator_init_data (&rdev->dev); +if (!init_data) +return ERR_PTR (-EINVAL ); + } + +/* preform any regulator specific init */ +if (init_data->regulator_init) { + ret = init_data->regulator_init (rdev->reg_data); +if (ret <0 ) + goto clean; + } +dev_set_drvdata (&rdev->dev, rdev);/* set regulator constraints */ @@ -2719,7 +2726,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, node =of_get_regulator (dev, supply);if (node)list_for_each_entry (r, ®ulator_list, list) -if (node == r->dev.parent->of_node) +if (node == r->dev.of_node) goto found; } ------->8---And my dts file looks like something below.
ecspi@70010000 { /* ECSPI1 */ fsl,spi-num-chipselects = <2>; cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */ <&gpio3 25 0>; /* GPIO4_25 */ status = "okay"; pmic: mc13892@0 { #address-cells = <1>; #size-cells = <0>; compatible = "fsl,mc13892"; spi-max-frequency = <6000000>; reg = <0>; mc13xxx-irq-gpios = <&gpio0 8 0>; /* GPIO1_8 */ regulators { sw1reg: mc13892_sw1 { regulator-min-uV = <600000>; regulator-max-uV = <1375000>; regulator-change-voltage; regulator-boot-on; regulator-always-on; }; sw2reg: mc13892_sw2 { regulator-min-uV = <900000>; regulator-max-uV = <1850000>; regulator-change-voltage; regulator-boot-on; regulator-always-on; };
Quoted 11 lines
Quoted 2 lines
...... };To follow up from my earlier comment, this .dts structure looks fine and reasonable to me, and it would also be fine for the mc13892 driver to use
for_each_child_of_node()to find all the children of the regulators node. Even finding the 'regulators' node by name from the mc13892 driver is perfectly fine providedfor_each_child_of_nodeis used to find it. All of this is okay because it is under the umbrella of the "fsl,mc13892" binding.
For mc13892 regulator example, there are 3 levels 'struct dev'.
1. drivers/mfd/mc13xxx-core.c
The "fsl,mc13892" binding is used in this mfd driver to get mc13xxx-core device probed. And this mfd driver will in turn call mfd_add_devices() to add the second level device below.
2. drivers/regulator/mc13892-regulator.c
As this device is created by mfd_add_devices() above, there is no device_node attached to its of_node, though we would hope that node 'regulators' is attached there. And the driver will call regulator_register() to have each regulator device created and registered in regulator core below.
3. drivers/regulator/core.c
regulator_register() called above will create device (rdev->dev) for each regulator.
I am thinking about hiding the device_node discovering for each regulator from the second level (regulator driver) and make it internal to the third level (regulator core), as it seems to me that regulator driver does not need to necessarily know about this.
If we can attach the device_node of 'regulators' node to dev->of_node when calling regulator_register(regulator_desc, dev, ...) from regulator driver, the regulator core will be able to find all nodes under 'regulators' using for_each_child_of_node(dev->of_node, child).
Then the question would be how we attach the device_node of 'regulators' to dev->of_node where 'dev' is the second level device above. I somehow hesitate to hack this into mfd_add_devices(), so I would like to add compatible string "fsl,mc13892-regulators" to node 'regulators' and find the node using of_find_compatible_node(dev->parent, NULL, "fsl,mc13892-regulators").
I'm not sure this is exactly same as what your comment suggests above. So please let me know if it's appropriate.
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 4 lines · Shawn Guo
If we can attach the
device_nodeof 'regulators' node todev->of_nodewhen callingregulator_register(regulator_desc, dev, ...)from regulator driver, the regulator core will be able to find all nodes under 'regulators' usingfor_each_child_of_node(dev->of_node, child).
Please provide concrete examples of the bindings you're talking about, the really important thing here is how sane the bindings look and I've really got no idea what any of what you're talking about will look like or if they make sense.
Quoted 4 lines
hesitate to hack this into
mfd_add_devices(), so I would like to add compatible string "fsl,mc13892-regulators" to node 'regulators' and find the node usingof_find_compatible_node(dev->parent, NULL, "fsl,mc13892-regulators").
It's not immediately obvious to me that having a binding for the regulators separately makes sense, it's not a usefully distinct device.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 7 lines · Mark Brown
Quoted 4 lines · Shawn Guo
If we can attach the
device_nodeof 'regulators' node todev->of_nodewhen callingregulator_register(regulator_desc, dev, ...)from regulator driver, the regulator core will be able to find all nodes under 'regulators' usingfor_each_child_of_node(dev->of_node, child).
Quoted 5 lines
Please provide concrete examples of the bindings you're talking about, the really important thing here is how sane the bindings look and I've really got no idea what any of what you're talking about will look like or if they make sense.
The only thing different from what I attached last time is the compatible string added to 'regulators' node.
ecspi@70010000 { /* ECSPI1 */
fsl,spi-num-chipselects = <2>;
cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */
<&gpio3 25 0>; /* GPIO4_25 */
status = "okay";
pmic: mc13892@0 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "fsl,mc13892";
spi-max-frequency = <6000000>;
reg = <0>;
mc13xxx-irq-gpios = <&gpio0 8 0>; /* GPIO1_8 */
regulators {
compatible = "fsl,mc13892-regulator";
sw1reg: mc13892_sw1 {
regulator-min-uV = <600000>;
regulator-max-uV = <1375000>;
regulator-change-voltage;
regulator-boot-on;
regulator-always-on;
};
sw2reg: mc13892_sw2 {
regulator-min-uV = <900000>;
regulator-max-uV = <1850000>;
regulator-change-voltage;
regulator-boot-on;
regulator-always-on;
};
......
};
leds {
......
};
buttons {
......
};
};
flash: at45db321d@1 {
......
};
};Quoted 8 lines
Quoted 4 lines
hesitate to hack this into
mfd_add_devices(), so I would like to add compatible string "fsl,mc13892-regulators" to node 'regulators' and find the node usingof_find_compatible_node(dev->parent, NULL, "fsl,mc13892-regulators").It's not immediately obvious to me that having a binding for the regulators separately makes sense, it's not a usefully distinct device.
Fair point. Actually, I also hate to have the finding of node 'regulators' plugged into regulator driver. What about following change to address Grant's concern on global device tree search?
drivers/regulator/core.c +2 -1
@@ -2673,7 +2673,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);/* find device_node and attach it */ - rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name); + rdev->dev.of_node =of_find_node_by_name (dev->parent->of_node, + regulator_desc->name);/* register with sysfs */ rdev->dev.class = ®ulator_class;
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2678
Quoted 9 lines · Shawn Guo
+++
b/drivers/regulator/core.cdrivers/regulator/core.c +2
-1@@ -2673,7 +2673,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);/* find device_node and attach it */ - rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name); + rdev->dev.of_node =of_find_node_by_name (dev->parent->of_node, + regulator_desc->name);
Is that going to do the right thing if you've got a MFD which does register each regulator as a separate device? Might be best to just search within dev and get drivers to pass the "real" device in when registering the regulator rather than the virtual device.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 6 lines · Mark Brown
Quoted 4 lines · Shawn Guo
+++
b/drivers/regulator/core.cdrivers/regulator/core.c +0
-0@@ -2673,7 +2673,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);
Quoted 8 lines
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2678
Quoted 5 lines
drivers/regulator/core.c +2
-1/* find device_node and attach it */ - rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name); + rdev->dev.of_node =of_find_node_by_name (dev->parent->of_node, + regulator_desc->name);Is that going to do the right thing if you've got a MFD which does register each regulator as a separate device?
Based on my understanding, 1:1 is just a special case of N:1. I failed to see any problem having it work with registering each regulator as a separate device.
Quoted 4 lines
Might be best to just
search within dev and get drivers to pass the "real" device in when registering the regulator rather than the virtual device.
It should also work, but it will also change the API slightly for non-dt users. I'm not sure it's something we want.
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 8 lines · Shawn Guo
Quoted 3 lines · Mark Brown
Might be best to just
search within dev and get drivers to pass the "real" device in when registering the regulator rather than the virtual device.It should also work, but it will also change the API slightly for non-dt users. I'm not sure it's something we want.
I don't think that's an issue at all.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Shawn GuoQuoted 83 lines · Shawn Guo
Quoted 7 lines · Mark Brown
Quoted 4 lines · Shawn Guo
If we can attach the
device_nodeof 'regulators' node todev->of_nodewhen callingregulator_register(regulator_desc, dev, ...)from regulator driver, the regulator core will be able to find all nodes under 'regulators' usingfor_each_child_of_node(dev->of_node, child).Quoted 5 lines
Please provide concrete examples of the bindings you're talking about, the really important thing here is how sane the bindings look and I've really got no idea what any of what you're talking about will look like or if they make sense.
The only thing different from what I attached last time is the compatible string added to 'regulators' node.
ecspi at 70010000 { /* ECSPI1 */ fsl,spi-num-chipselects = <2>; cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */ <&gpio3 25 0>; /* GPIO4_25 */ status = "okay"; pmic: mc13892 at 0 { #address-cells = <1>; #size-cells = <0>; compatible = "fsl,mc13892"; spi-max-frequency = <6000000>; reg = <0>; mc13xxx-irq-gpios = <&gpio0 8 0>; /* GPIO1_8 */ regulators { compatible = "fsl,mc13892-regulator"; sw1reg: mc13892_sw1 { regulator-min-uV = <600000>; regulator-max-uV = <1375000>; regulator-change-voltage; regulator-boot-on; regulator-always-on; }; sw2reg: mc13892_sw2 { regulator-min-uV = <900000>; regulator-max-uV = <1850000>; regulator-change-voltage; regulator-boot-on; regulator-always-on; }; ...... }; leds { ...... }; buttons { ...... }; }; flash: at45db321d at 1 { ...... }; };Quoted 8 lines
Quoted 4 lines
hesitate to hack this into
mfd_add_devices(), so I would like to add compatible string "fsl,mc13892-regulators" to node 'regulators' and find the node usingof_find_compatible_node(dev->parent, NULL, "fsl,mc13892-regulators").It's not immediately obvious to me that having a binding for the regulators separately makes sense, it's not a usefully distinct device.
Fair point. Actually, I also hate to have the finding of node 'regulators' plugged into regulator driver. What about following change to address Grant's concern on global device tree search?
drivers/regulator/core.c +0
-0
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2677
Quoted 6 lines
drivers/regulator/core.c +2
-1@@ -2673,7 +2673,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);/* find device_node and attach it */ - rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name); + rdev->dev.of_node =of_find_node_by_name (dev->parent->of_node, + regulator_desc->name);
of_find_node_by_name() doesn't work that way. The first argument is a starting point, but it doesn't restrict the search to children of a node.
for_each_child_of_node() is what you want to use when iterating over the children which unfortunately changes the structure of this function.
g.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 95 lines · Grant Likely
Quoted 83 lines · Shawn Guo
Quoted 7 lines · Mark Brown
Quoted 4 lines · Shawn Guo
If we can attach the
device_nodeof 'regulators' node todev->of_nodewhen callingregulator_register(regulator_desc, dev, ...)from regulator driver, the regulator core will be able to find all nodes under 'regulators' usingfor_each_child_of_node(dev->of_node, child).Quoted 5 lines
Please provide concrete examples of the bindings you're talking about, the really important thing here is how sane the bindings look and I've really got no idea what any of what you're talking about will look like or if they make sense.
The only thing different from what I attached last time is the compatible string added to 'regulators' node.
ecspi@70010000 { /* ECSPI1 */ fsl,spi-num-chipselects = <2>; cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */ <&gpio3 25 0>; /* GPIO4_25 */ status = "okay"; pmic: mc13892@0 { #address-cells = <1>; #size-cells = <0>; compatible = "fsl,mc13892"; spi-max-frequency = <6000000>; reg = <0>; mc13xxx-irq-gpios = <&gpio0 8 0>; /* GPIO1_8 */ regulators { compatible = "fsl,mc13892-regulator"; sw1reg: mc13892_sw1 { regulator-min-uV = <600000>; regulator-max-uV = <1375000>; regulator-change-voltage; regulator-boot-on; regulator-always-on; }; sw2reg: mc13892_sw2 { regulator-min-uV = <900000>; regulator-max-uV = <1850000>; regulator-change-voltage; regulator-boot-on; regulator-always-on; }; ...... }; leds { ...... }; buttons { ...... }; }; flash: at45db321d@1 { ...... }; };Quoted 8 lines
Quoted 4 lines
hesitate to hack this into
mfd_add_devices(), so I would like to add compatible string "fsl,mc13892-regulators" to node 'regulators' and find the node usingof_find_compatible_node(dev->parent, NULL, "fsl,mc13892-regulators").It's not immediately obvious to me that having a binding for the regulators separately makes sense, it's not a usefully distinct device.
Fair point. Actually, I also hate to have the finding of node 'regulators' plugged into regulator driver. What about following change to address Grant's concern on global device tree search?
drivers/regulator/core.c +0
-0drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2677
Quoted 6 lines
drivers/regulator/core.c +2
-1@@ -2673,7 +2673,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);/* find device_node and attach it */ - rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name); + rdev->dev.of_node =of_find_node_by_name (dev->parent->of_node, + regulator_desc->name);
of_find_node_by_name()doesn't work that way. The first argument is a starting point, but it doesn't restrict the search to children of a node.
Quoted 4 lines
for_each_child_of_node()is what you want to use when iterating over the children which unfortunately changes the structure of this function.
The dev->parent->of_node is meant to point to node 'pmic: mc13892@0'. And the intention here is not to iterate over the children, but to start a search from a reasonable point rather than the top root node.
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 18 lines · Shawn Guo
Quoted 17 lines · Grant Likely
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2677
Quoted 11 lines · Shawn Guo
drivers/regulator/core.c +2
-1@@ -2673,7 +2673,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);/* find device_node and attach it */ - rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name); + rdev->dev.of_node =of_find_node_by_name (dev->parent->of_node, + regulator_desc->name);
of_find_node_by_name()doesn't work that way. The first argument is a starting point, but it doesn't restrict the search to children of a node.
Quoted 7 lines
Quoted 4 lines
for_each_child_of_node()is what you want to use when iterating over the children which unfortunately changes the structure of this function.The
dev->parent->of_nodeis meant to point to node 'pmic: mc13892 at 0'. And the intention here is not to iterate over the children, but to start a search from a reasonable point rather than the top root node.
It is always better to attach the of_node at struct device registration time instead of searching the tree in common code. The of_node should already be assigned by the time regulator_register() is called. The caller should already have access to all that information before the call anyway, especially since it is not strictly manditory for all regulators to use the common binding. It is entirely conceivable that the proposed binding won't work for some regulators.
g.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 23 lines · Grant Likely
Quoted 22 lines · Shawn Guo
Quoted 21 lines · Grant Likely
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2677
Quoted 11 lines · Shawn Guo
drivers/regulator/core.c +2
-1@@ -2673,7 +2673,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);/* find device_node and attach it */ - rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name); + rdev->dev.of_node =of_find_node_by_name (dev->parent->of_node, + regulator_desc->name);
of_find_node_by_name()doesn't work that way. The first argument is a starting point, but it doesn't restrict the search to children of a node.
for_each_child_of_node()is what you want to use when iterating over the children which unfortunately changes the structure of this function.
Quoted 8 lines
Quoted 3 lines
The
dev->parent->of_nodeis meant to point to node 'pmic: mc13892@0'. And the intention here is not to iterate over the children, but to start a search from a reasonable point rather than the top root node.It is always better to attach the
of_nodeat struct device registration time instead of searching the tree in common code. Theof_nodeshould already be assigned by the timeregulator_register()is called.
That's the problem we have. There is no 'struct dev' to attach of_node for each regulator by the time regulator_register() is called, because the 'struct dev' for each regulator is created inside regulator_register() as wrapped by 'struct regulator_dev'.
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 33 lines · Shawn Guo
Quoted 23 lines · Grant Likely
Quoted 22 lines · Shawn Guo
Quoted 21 lines · Grant Likely
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2677
Quoted 11 lines · Shawn Guo
drivers/regulator/core.c +2
-1@@ -2673,7 +2673,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);/* find device_node and attach it */ - rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name); + rdev->dev.of_node =of_find_node_by_name (dev->parent->of_node, + regulator_desc->name);
of_find_node_by_name()doesn't work that way. The first argument is a starting point, but it doesn't restrict the search to children of a node.
for_each_child_of_node()is what you want to use when iterating over the children which unfortunately changes the structure of this function.Quoted 8 lines
Quoted 3 lines
The
dev->parent->of_nodeis meant to point to node 'pmic: mc13892 at 0'. And the intention here is not to iterate over the children, but to start a search from a reasonable point rather than the top root node.It is always better to attach the
of_nodeat struct device registration time instead of searching the tree in common code. Theof_nodeshould already be assigned by the timeregulator_register()is called.
Quoted 4 lines
That's the problem we have. There is no 'struct dev' to attach
of_nodefor each regulator by the timeregulator_register()is called, because the 'struct dev' for each regulator is created insideregulator_register()as wrapped by 'structregulator_dev'.
Then regulator_register must be split in half. This is a common use case, and other libraries have had to do the same. One half to allocate the structure, and then a second half for registration, and regulator_register() becomes a simpler helper that calls both. That way a caller can insert extra initialization between the two steps.
g.
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
In reply to Shawn GuoQuoted 33 lines · Shawn Guo
Quoted 23 lines · Grant Likely
Quoted 22 lines · Shawn Guo
Quoted 21 lines · Grant Likely
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2677
Quoted 11 lines · Shawn Guo
drivers/regulator/core.c +2
-1@@ -2673,7 +2673,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);/* find device_node and attach it */ - rdev->dev.of_node =of_find_node_by_name (NULL , regulator_desc->name); + rdev->dev.of_node =of_find_node_by_name (dev->parent->of_node, + regulator_desc->name);
of_find_node_by_name()doesn't work that way. The first argument is a starting point, but it doesn't restrict the search to children of a node.
for_each_child_of_node()is what you want to use when iterating over the children which unfortunately changes the structure of this function.Quoted 8 lines
Quoted 3 lines
The
dev->parent->of_nodeis meant to point to node 'pmic: mc13892 at 0'. And the intention here is not to iterate over the children, but to start a search from a reasonable point rather than the top root node.It is always better to attach the
of_nodeat struct device registration time instead of searching the tree in common code. Theof_nodeshould already be assigned by the timeregulator_register()is called.
Quoted 4 lines
That's the problem we have. There is no 'struct dev' to attach
of_nodefor each regulator by the timeregulator_register()is called, because the 'struct dev' for each regulator is created insideregulator_register()as wrapped by 'structregulator_dev'.
The root of your problem seems to be that your pmic driver isn't registering regulator devices from DT, and if it did, you wouldn't need to do a search in dev->parent->of_node and instead the driver would have the right dev->of_node populated.
Quoted 1 line
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 2 lines · Rajendra Nayak
Quoted 1 line · Shawn Guo
On Mon, Oct 24, 2011 at 04:56:31PM +0200, Grant Likely wrote:
[...]
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
It is always better to attach the
of_nodeat struct device registration time instead of searching the tree in common code. Theof_nodeshould already be assigned by the timeregulator_register()is called.That's the problem we have. There is no 'struct dev' to attach
of_nodefor each regulator by the timeregulator_register()is called, because the 'struct dev' for each regulator is created insideregulator_register()as wrapped by 'structregulator_dev'.
Quoted 5 lines
The root of your problem seems to be that your pmic driver isn't registering regulator devices from DT, and if it did, you wouldn't need to do a search in
dev->parent->of_nodeand instead the driver would have the rightdev->of_nodepopulated.
No, it's not the root of my problem. Again, we are talking about 'Case 2', where multiple regulator devices are registered to regulator core with regulator driver being probed once, where each regulator node is taken as the child of 'regulators' node. Having device_node of 'regulators' attached to dev->of_node does not help at all. What we need is to have each child node attached to regulator_dev->dev.of_node.
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 19 lines · Shawn Guo
Quoted 2 lines · Rajendra Nayak
Quoted 1 line · Shawn Guo
On Mon, Oct 24, 2011 at 04:56:31PM +0200, Grant Likely wrote:
[...]
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
It is always better to attach the
of_nodeat struct device registration time instead of searching the tree in common code. Theof_nodeshould already be assigned by the timeregulator_register()is called.That's the problem we have. There is no 'struct dev' to attach
of_nodefor each regulator by the timeregulator_register()is called, because the 'struct dev' for each regulator is created insideregulator_register()as wrapped by 'structregulator_dev'.Quoted 5 lines
The root of your problem seems to be that your pmic driver isn't registering regulator devices from DT, and if it did, you wouldn't need to do a search in
dev->parent->of_nodeand instead the driver would have the rightdev->of_nodepopulated.
Quoted 7 lines
No, it's not the root of my problem. Again, we are talking about 'Case 2', where multiple regulator devices are registered to regulator core with regulator driver being probed once, where each regulator node is taken as the child of 'regulators' node. Having
device_nodeof 'regulators' attached todev->of_nodedoes not help at all. What we need is to have each child node attached toregulator_dev->dev.of_node.
It certainly helps if dev->of_node has the 'regulators' node attached. The driver can very easily then do a for_each_child_of_node() to extract and register individual regulators passing an additional of_node param.
Quoted 1 line
Re: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Quoted 28 lines · Rajendra Nayak
Quoted 19 lines · Shawn Guo
Quoted 2 lines · Rajendra Nayak
Quoted 1 line · Shawn Guo
On Mon, Oct 24, 2011 at 04:56:31PM +0200, Grant Likely wrote:
[...]
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
It is always better to attach the
of_nodeat struct device registration time instead of searching the tree in common code. Theof_nodeshould already be assigned by the timeregulator_register()is called.That's the problem we have. There is no 'struct dev' to attach
of_nodefor each regulator by the timeregulator_register()is called, because the 'struct dev' for each regulator is created insideregulator_register()as wrapped by 'structregulator_dev'.Quoted 5 lines
The root of your problem seems to be that your pmic driver isn't registering regulator devices from DT, and if it did, you wouldn't need to do a search in
dev->parent->of_nodeand instead the driver would have the rightdev->of_nodepopulated.Quoted 7 lines
No, it's not the root of my problem. Again, we are talking about 'Case 2', where multiple regulator devices are registered to regulator core with regulator driver being probed once, where each regulator node is taken as the child of 'regulators' node. Having
device_nodeof 'regulators' attached todev->of_nodedoes not help at all. What we need is to have each child node attached toregulator_dev->dev.of_node.
Quoted 4 lines
It certainly helps if
dev->of_nodehas the 'regulators' node attached. The driver can very easily then do afor_each_child_of_node()to extract and register individual regulators passing an additionalof_nodeparam.
Well, let's look at what Grant is asking for. He is asking for that each child node should be attached to regulator_dev->dev.of_node by the time regulator_register() is called. How can this be helping that?
Signature · 2 lines
Regards, Shawn
PATCH v2 4/5 regulator: adapt fixed regulator driver to dt
In reply to Rajendra NayakThe fixed regulator driver uses of_get_fixed_voltage_config() to extract fixed_voltage_config structure contents from device tree.
Also add documenation for additional bindings for fixed regulators that can be passed through dt.
--- .../bindings/regulator/fixed-regulator.txt | 25 +++++++++ drivers/regulator/fixed.c | 58 ++++++++++++++++++++ 2 files changed, 83 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/fixed-regulator.txt
Documentation/devicetree/bindings/regulator/fixed-regulator.txt new file +25 -0
@@ -0,0 +1,25 @@ +Fixed Voltage regulators + +Required properties: +- compatible: Must be "regulator-fixed"; + +Optional properties: +- regulator-fixed-supply: Name of the regulator supply +- regulator-fixed-microvolts: Output voltage of regulator +- regulator-fixed-gpio: gpio to use for enable control +- regulator-fixed-startup-delay: startup time in microseconds +- regulator-fixed-enable-high: Polarity of enable GPIO, + 1 = Active High, 0 = Active low +- regulator-fixed-enabled-at-boot: 1 = yes, 0 = no + +Example: + + abc: fixedregulator at 0 { + compatible = "regulator-fixed"; + regulator-fixed-supply = "fixed-supply"; + regulator-fixed-microvolts = <1800000>; + regulator-fixed-gpio = <43>; + regulator-fixed-startup-delay = <70000>; + regulator-fixed-enable-high; + regulator-fixed-enabled-at-boot; + };
drivers/regulator/fixed.c +58 -0
91 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH v2 4/5] regulator: adapt fixed regulator driver to dt
Quoted 76 lines · Rajendra Nayak
The fixed regulator driver uses
of_get_fixed_voltage_config()to extractfixed_voltage_configstructure contents from device tree.Also add documenation for additional bindings for fixed regulators that can be passed through dt.
Signed-off-by Rajendra Nayak <[email protected]>--- .../bindings/regulator/fixed-regulator.txt | 25 +++++++++ drivers/regulator/fixed.c | 58 ++++++++++++++++++++ 2 files changed, 83 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/fixed-regulator.txtDocumentation/devicetree/bindings/regulator/fixed-regulator.txt new file +25
-0@@ -0,0 +1,25 @@ +Fixed Voltage regulators + +Required properties: +- compatible: Must be "regulator-fixed"; + +Optional properties: +- regulator-fixed-supply: Name of the regulator supply +- regulator-fixed-microvolts: Output voltage of regulator +- regulator-fixed-gpio: gpio to use for enable control +- regulator-fixed-startup-delay: startup time in microseconds +- regulator-fixed-enable-high: Polarity of enable GPIO, + 1 = Active High, 0 = Active low +- regulator-fixed-enabled-at-boot: 1 = yes, 0 = no + +Example: + + abc: fixedregulator at 0 { + compatible = "regulator-fixed"; + regulator-fixed-supply = "fixed-supply"; + regulator-fixed-microvolts = <1800000>; + regulator-fixed-gpio = <43>; + regulator-fixed-startup-delay = <70000>; + regulator-fixed-enable-high; + regulator-fixed-enabled-at-boot; + };drivers/regulator/fixed.c +14
-0@@ -23,9 +23,12 @@#include <linux/platform_device.h> #include <linux/regulator/driver.h> #include <linux/regulator/fixed.h> +#include <linux/regulator/machine.h> #include <linux/gpio.h> #include <linux/delay.h> #include <linux/slab.h> +#include <linux/of.h> +#include <linux/regulator/of_regulator.h> struct fixed_voltage_data {struct regulator_desc desc;@@ -37,6 +40,47 @@ struct fixed_voltage_data {bool is_enabled; }; + +/** +* of_get_fixed_voltage_config - extract fixed_voltage_config structure info +* @dev: device requesting for fixed_voltage_config +* +* Populates fixed_voltage_config structure by extracting data from device +* tree node, returns a pointer to the populated structure of NULL if memory +* alloc fails. +*/ +struct fixed_voltage_config *of_get_fixed_voltage_config (struct device *dev) +{
drivers/regulator/fixed.c struct fixed_voltage_data { · line 63
Quoted 10 lines
drivers/regulator/fixed.c +10
-0+struct fixed_voltage_config *config; +struct device_node *np = dev->of_node; +const __be32 *microvolts, *gpio, *delay; + + config =devm_kzalloc (dev,sizeof (struct fixed_voltage_config ),GFP_KERNEL ); +if (!config) +return NULL ; + + config->supply_name = (char *)of_get_property (np, +"regulator-fixed-supply" ,NULL );
of_get_property() returns a (const void *). Casting drops the const and should not be used. Either make supply_name a (const char *), or copy the string into a (char *) buffer.
drivers/regulator/fixed.c struct fixed_voltage_data { · line 69
Quoted 6 lines
drivers/regulator/fixed.c +6
-0+ microvolts =of_get_property (np,"regulator-fixed-microvolts" ,NULL ); +if (microvolts) + config->microvolts =be32_to_cpu (*microvolts); + gpio =of_get_property (np,"regulator-fixed-gpio" ,NULL ); +if (gpio) + config->gpio =be32_to_cpu (*gpio);
of_property_read_u32() may help here.
Quoted 54 lines
drivers/regulator/fixed.c +28
-0+ delay =of_get_property (np,"regulator-fixed-startup-delay" ,NULL ); +if (delay) + config->startup_delay =be32_to_cpu (*delay); + +if (of_find_property (np,"regulator-fixed-enable-high" ,NULL )) + config->enable_high = true; +if (of_find_property (np,"regulator-fixed-enabled-at-boot" ,NULL )) + config->enabled_at_boot = true; + + config->init_data =of_get_regulator_init_data (dev); + +return config; +} +static int fixed_voltage_is_enabled (struct regulator_dev *dev) {struct fixed_voltage_data *data =rdev_get_drvdata (dev);@@ -108,6 +152,9 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)struct fixed_voltage_data *drvdata;int ret; +if (pdev->dev.of_node) + config =of_get_fixed_voltage_config (&pdev->dev); + drvdata =kzalloc (sizeof (struct fixed_voltage_data ),GFP_KERNEL );if (drvdata ==NULL ) {dev_err (&pdev->dev,"Failed to allocate device data\n" );@@ -216,12 +263,23 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev)return 0 ; } +#if defined(CONFIG_OF ) +static const struct of_device_id fixed_of_match[]__devinitconst = { + { .compatible ="regulator-fixed" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, fixed_of_match); +#else +#define fixed_of_match NULL +#endif +static struct platform_driver regulator_fixed_voltage_driver = { .probe = reg_fixed_voltage_probe, .remove =__devexit_p (reg_fixed_voltage_remove), .driver = { .name ="reg-fixed-voltage" , .owner =THIS_MODULE , + .of_match_table = fixed_of_match, }, };Signature · 1 line
1.7.1
PATCH v2 5/5 regulator: map consumer regulator based on device tree
In reply to Rajendra NayakDevice nodes in DT can associate themselves with one or more regulators/supply by providing a list of phandles (to regulator nodes) and corresponding supply names.
For Example:
devicenode: node at 0x0 {
...
...
vmmc-supply = <®ulator1>;
vpll-supply = <®ulator1>;
};The driver would then do a regulator_get(dev, "vmmc"); to get regulator1 and do a regulator_get(dev, "vpll"); to get regulator2.
of_get_regulator() extracts the regulator node for a given device, based on the supply name.
Use it to look up the regulator for a given consumer from device tree, during a regulator_get(). If not found fallback and lookup through
the regulator_map_list instead.
Also, since the regulator dt nodes can use the same binding to associate with a parent regulator/supply, allow the drivers to specify a supply_name, which can then be used to lookup dt to find the parent phandle.
--- drivers/regulator/core.c | 91 +++++++++++++++++++++++++++++++------ include/linux/regulator/driver.h | 2 + 2 files changed, 78 insertions(+), 15 deletions(-)
drivers/regulator/core.c +76 -15
@@ -25,9 +25,11 @@#include <linux/mutex.h> #include <linux/suspend.h> #include <linux/delay.h> +#include <linux/of.h> #include <linux/regulator/consumer.h> #include <linux/regulator/driver.h> #include <linux/regulator/machine.h> +#include <linux/regulator/of_regulator.h> #define CREATE_TRACE_POINTS #include <trace/events/regulator.h>
@@ -131,6 +133,33 @@ static struct regulator *get_device_regulator(struct device *dev)return NULL ; } +/** +* of_get_regulator - get a regulator device node based on supply name +* @dev: Device pointer for the consumer (of regulator) device +* @supply: regulator supply name +* +* Extract the regulator device node corresponding to the supply name. +* retruns the device node corresponding to the regulator if found, else +* returns NULL. +*/ +struct device_node *of_get_regulator (struct device *dev,const char *supply) +{ +struct device_node *regnode =NULL ; +char prop_name[32 ];/* 32 is max size of property name */ + +dev_dbg (dev,"Looking up %s-supply from device tree\n" , supply); + +snprintf (prop_name,32 ,"%s-supply" , supply); + regnode =of_parse_phandle (dev->of_node, prop_name,0 ); + +if (!regnode) { +pr_warn ("%s: %s property in node %s references invalid phandle" , + __func__, prop_name, dev->of_node->full_name); +return NULL ; + } +return regnode; +} +/* Platform voltage constraint check */ static int regulator_check_voltage (struct regulator_dev *rdev,int *min_uV,int *max_uV)
@@ -1155,6 +1184,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,struct regulator_map *map;struct regulator *regulator =ERR_PTR (-ENODEV );const char *devname =NULL ; +struct device_node *node;int ret;if (id ==NULL ) {
@@ -1167,6 +1197,23 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,mutex_lock (®ulator_list_mutex); +/* +* Lookup happens in 3 ways +* 1. If a dev and dev->of_node exist, look for a +* regulator mapping in dt node. +* 2. Check if a match can be found in regulator_map_list +* if regulator info is still passed in non-dt way +* 3. if !dev, then just look for a matching regulator name. +* Useful for dt builds using regulator_get() without specifying +* a device. +*/ +if (dev && dev->of_node) { + node =of_get_regulator (dev, id); +if (node) +list_for_each_entry (rdev, ®ulator_list, list) +if (node == rdev->dev.parent->of_node) + goto found; + }list_for_each_entry (map, ®ulator_map_list, list) {/* If the mapping has a device set up it must match */ if (map->dev_name &&
@@ -1178,6 +1225,10 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, goto found; } } +if (!dev) +list_for_each_entry (rdev, ®ulator_list, list) +if (strcmp (rdev_get_name (rdev), id)) + goto found;if (board_wants_dummy_regulator) { rdev = dummy_regulator_rdev;
@@ -2579,6 +2630,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,static atomic_t regulator_no =ATOMIC_INIT (0 );struct regulator_dev *rdev;int ret, i; +const char *supply;if (regulator_desc ==NULL )return ERR_PTR (-EINVAL );
@@ -2653,25 +2705,34 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,if (ret <0 ) goto scrub; -if (init_data->supply_regulator) { -struct regulator_dev *r; -int found =0 ; +if (init_data->supply_regulator) + supply = init_data->supply_regulator; +else if (regulator_desc->supply_name); + supply = regulator_desc->supply_name; -list_for_each_entry (r, ®ulator_list, list) { -if (strcmp (rdev_get_name (r), - init_data->supply_regulator) ==0 ) { - found =1 ; -break ; - } +if (supply) { +struct regulator_dev *r; +struct device_node *node; + +/* first do a dt based lookup */ +if (dev) { + node =of_get_regulator (dev, supply); +if (node) +list_for_each_entry (r, ®ulator_list, list) +if (node == r->dev.parent->of_node) + goto found; } -if (!found) { -dev_err (dev,"Failed to find supply %s\n" , - init_data->supply_regulator); - ret = -ENODEV ; - goto scrub; - } +/* next try doing it non-dt way */ +list_for_each_entry (r, ®ulator_list, list) +if (strcmp (rdev_get_name (r), supply) ==0 ) + goto found; +dev_err (dev,"Failed to find supply %s\n" , supply); + ret = -ENODEV ; + goto scrub; + +found: ret =set_supply (rdev, r);if (ret <0 ) goto scrub;
include/linux/regulator/driver.h +2 -0
@@ -153,6 +153,7 @@ enum regulator_type {* this type. * * @name: Identifying name for the regulator. +* @supply_name: Identifying the regulator supply * @id: Numerical identifier for the regulator. * @n_voltages: Number of selectors available for ops.list_voltage(). * @ops: Regulator operations table.
@@ -162,6 +163,7 @@ enum regulator_type {*/ struct regulator_desc {const char *name; +const char *supply_name;int id;unsigned n_voltages;struct regulator_ops *ops;
Signature · 1 line
1.7.1
Re: [PATCH v2 5/5] regulator: map consumer regulator based on device tree
Quoted 3 lines · Rajendra Nayak
Device nodes in DT can associate themselves with one or more regulators/supply by providing a list of phandles (to regulator nodes) and corresponding supply names.
Mostly looks good.
drivers/regulator/core.c static struct regulator *get_device_regulator(struct device *dev) · line 146
Quoted 11 lines
drivers/regulator/core.c +11
-0+/** +* of_get_regulator - get a regulator device node based on supply name +* @dev: Device pointer for the consumer (of regulator) device +* @supply: regulator supply name +* +* Extract the regulator device node corresponding to the supply name. +* retruns the device node corresponding to the regulator if found, else +* returns NULL. +*/ +struct device_node *of_get_regulator (struct device *dev,const char *supply) +{
Should be static.
drivers/regulator/core.c static struct regulator *_regulator_get(struct device *dev, const char *id, · line 1232
Quoted 9 lines
drivers/regulator/core.c +4
-0@@ -1178,6 +1225,10 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, goto found; } } +if (!dev) +list_for_each_entry (rdev, ®ulator_list, list) +if (strcmp (rdev_get_name (rdev), id)) + goto found;
This looks really strange, we didn't remove any old lookup code and the DT lookup jumps to found by iself so why are we adding code here?
Quoted 19 lines
drivers/regulator/core.c +11
-6+if (supply) { +struct regulator_dev *r; +struct device_node *node; + +/* first do a dt based lookup */ +if (dev) { + node =of_get_regulator (dev, supply); +if (node) +list_for_each_entry (r, ®ulator_list, list) +if (node == r->dev.parent->of_node) + goto found; } -if (!found) { -dev_err (dev,"Failed to find supply %s\n" , - init_data->supply_regulator); - ret = -ENODEV ; - goto scrub; - }
drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2735
Quoted 10 lines
drivers/regulator/core.c +9
-0+/* next try doing it non-dt way */ +list_for_each_entry (r, ®ulator_list, list) +if (strcmp (rdev_get_name (r), supply) ==0 ) + goto found; +dev_err (dev,"Failed to find supply %s\n" , supply); + ret = -ENODEV ; + goto scrub; + +found:
This is all getting *really* complicated and illegible. I'm not sure what the best way to structure is but erroring out early looks useful.
Re: [PATCH v2 5/5] regulator: map consumer regulator based on device tree
Quoted 14 lines
drivers/regulator/core.c static struct regulator *_regulator_get(struct device *dev, const char *id, · line 1232
Quoted 11 lines
drivers/regulator/core.c +4
-0@@ -1178,6 +1225,10 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, goto found; } } +if (!dev) +list_for_each_entry (rdev,®ulator_list, list) +if (strcmp (rdev_get_name (rdev), id)) + goto found;This looks really strange, we didn't remove any old lookup code and the DT lookup jumps to found by iself so why are we adding code here?
The old lookup code looks up using the regulator_map_list, and the dt lookup depends on a dev pointer to extract the of_node. This above code was needed for cases when a regulator_get() would be called on dt builds without specifying a device pointer, like the cpufreq implementations you mentioned.
This is what I tried putting in the comments above the lookup code.
/*
* Lookup happens in 3 ways
* 1. If a dev and dev->of_node exist, look for a
* regulator mapping in dt node.
* 2. Check if a match can be found in regulator_map_list
* if regulator info is still passed in non-dt way
* 3. if !dev, then just look for a matching regulator name.
* Useful for dt builds using regulator_get() without specifying
* a device.
*/
I know its quite complicated but thats because we need to support both the legacy and the dt based lookups.
Quoted 33 lines
Quoted 20 lines
drivers/regulator/core.c +11
-6+if (supply) { +struct regulator_dev *r; +struct device_node *node; + +/* first do a dt based lookup */ +if (dev) { + node =of_get_regulator (dev, supply); +if (node) +list_for_each_entry (r,®ulator_list, list) +if (node == r->dev.parent->of_node) + goto found; } -if (!found) { -dev_err (dev,"Failed to find supply %s\n" , - init_data->supply_regulator); - ret = -ENODEV ; - goto scrub; - }drivers/regulator/core.c struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, · line 2735
Quoted 10 lines
drivers/regulator/core.c +9
-0+/* next try doing it non-dt way */ +list_for_each_entry (r,®ulator_list, list) +if (strcmp (rdev_get_name (r), supply) ==0 ) + goto found; +dev_err (dev,"Failed to find supply %s\n" , supply); + ret = -ENODEV ; + goto scrub; + +found:This is all getting *really* complicated and illegible. I'm not sure what the best way to structure is but erroring out early looks useful.
Re: [PATCH v2 5/5] regulator: map consumer regulator based on device tree
In reply to Mark BrownQuoted 25 lines
Quoted 25 lines
+ ? ? if (supply) {
+ ? ? ? ? ? ? structregulator_dev*r;
+ ? ? ? ? ? ? structdevice_node*node;
+
+ ? ? ? ? ? ? /* first do a dt based lookup */
+ ? ? ? ? ? ? if (dev) {
+ ? ? ? ? ? ? ? ? ? ? node =of_get_regulator(dev, supply);
+ ? ? ? ? ? ? ? ? ? ? if (node)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ?list_for_each_entry(r, ®ulator_list, list)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (node ==r->dev.parent->of_node)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto found;
? ? ? ? ? ? ? }- ? ? ? ? ? ? if (!found) {
- ? ? ? ? ? ? ? ? ? ? dev_err(dev, "Failed to find supply %s\n",
- ? ? ? ? ? ? ? ? ? ? ? ? ? ?init_data->supply_regulator);
- ? ? ? ? ? ? ? ? ? ? ret =-ENODEV;
- ? ? ? ? ? ? ? ? ? ? goto scrub;
- ? ? ? ? ? ? }
+ ? ? ? ? ? ? /* next try doing it non-dt way */
+ ? ? ? ? ? ?list_for_each_entry(r, ®ulator_list, list)
+ ? ? ? ? ? ? ? ? ? ? if (strcmp(rdev_get_name(r), supply)== 0)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto found;
Quoted 9 lines
Review
Quoted 5 lines
+ ? ? ? ? ? ?
dev_err(dev, "Failed to find supply %s\n", supply);
+ ? ? ? ? ? ? ret =-ENODEV;
+ ? ? ? ? ? ? goto scrub;(quoted diff) +2
-0+ +found:This is all getting *really* complicated and illegible. ?I'm not sure what the best way to structure is but erroring out early looks useful.
How about this updated patch?
Re: [PATCH v2 5/5] regulator: map consumer regulator based on device tree
Quoted 1 line · Rajendra
How about this updated patch?
Yes, I think that looks broadly sensible.
Grant Likely
Acked-byRe: [PATCH v2 5/5] regulator: map consumer regulator based on device tree
In reply to Nayak, RajendraQuoted 65 lines · Rajendra
Quoted 25 lines
Quoted 25 lines
+ ? ? if (supply) {
+ ? ? ? ? ? ? structregulator_dev*r;
+ ? ? ? ? ? ? structdevice_node*node;
+
+ ? ? ? ? ? ? /* first do a dt based lookup */
+ ? ? ? ? ? ? if (dev) {
+ ? ? ? ? ? ? ? ? ? ? node =of_get_regulator(dev, supply);
+ ? ? ? ? ? ? ? ? ? ? if (node)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ?list_for_each_entry(r, ®ulator_list, list)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (node ==r->dev.parent->of_node)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto found;
? ? ? ? ? ? ? }- ? ? ? ? ? ? if (!found) {
- ? ? ? ? ? ? ? ? ? ? dev_err(dev, "Failed to find supply %s\n",
- ? ? ? ? ? ? ? ? ? ? ? ? ? ?init_data->supply_regulator);
- ? ? ? ? ? ? ? ? ? ? ret =-ENODEV;
- ? ? ? ? ? ? ? ? ? ? goto scrub;
- ? ? ? ? ? ? }
+ ? ? ? ? ? ? /* next try doing it non-dt way */
+ ? ? ? ? ? ?list_for_each_entry(r, ®ulator_list, list)
+ ? ? ? ? ? ? ? ? ? ? if (strcmp(rdev_get_name(r), supply)== 0)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto found;Quoted 9 lines
Review
Quoted 5 lines
+ ? ? ? ? ? ?
dev_err(dev, "Failed to find supply %s\n", supply);
+ ? ? ? ? ? ? ret =-ENODEV;
+ ? ? ? ? ? ? goto scrub;(quoted diff) +2
-0+ +found:This is all getting *really* complicated and illegible. ?I'm not sure what the best way to structure is but erroring out early looks useful.
How about this updated patch?
From
f4c7d2b283740382c272c7971665375067d26dbeMon Sep 17 00:00:00 2001
From: Rajendra Nayak <[email protected]>
Date: Thu, 22 Sep 2011 17:51:10 +0530
Subject: [PATCH 5/5] regulator: map consumer regulator based on device treeDevice nodes in DT can associate themselves with one or more regulators/supply by providing a list of phandles (to regulator nodes) and corresponding supply names.
For Example:
devicenode: node at 0x0 { ... ... vmmc-supply = <®ulator1>; vpll-supply = <®ulator1>; };The driver would then do a
regulator_get(dev, "vmmc"); to get regulator1 and do aregulator_get(dev, "vpll"); to get regulator2.
of_get_regulator()extracts the regulator node for a given device, based on the supply name.Use it to look up the regulator for a given consumer from device tree, during a
regulator_get(). If not found fallback and lookup through
theregulator_map_listinstead.
Quoted 6 lines
Also, since the regulator dt nodes can use the same binding to associate with a parent regulator/supply, allow the drivers to specify a
supply_name, which can then be used to lookup dt to find the parent phandle.Signed-off-by Rajendra Nayak <[email protected]>
Quoted 164 lines
--- drivers/regulator/core.c | 91 +++++++++++++++++++++++++++++++------ include/linux/regulator/driver.h | 2 + 2 files changed, 78 insertions(+), 15 deletions(-)Index:
linux/drivers/regulator/core.c
===================================================================drivers/regulator/core.c +29
-0@@ -25,9 +25,11 @@#include <linux/mutex.h> #include <linux/suspend.h> #include <linux/delay.h> +#include <linux/of.h> #include <linux/regulator/consumer.h> #include <linux/regulator/driver.h> #include <linux/regulator/machine.h> +#include <linux/regulator/of_regulator.h> #define CREATE_TRACE_POINTS #include <trace/events/regulator.h> @@ -131,6 +133,33 @@return NULL ; } +/** +* of_get_regulator - get a regulator device node based on supply name +* @dev: Device pointer for the consumer (of regulator) device +* @supply: regulator supply name +* +* Extract the regulator device node corresponding to the supply name. +* retruns the device node corresponding to the regulator if found, else +* returns NULL. +*/ +static struct device_node *of_get_regulator (struct device *dev,const char *supply) +{ +struct device_node *regnode =NULL ; +char prop_name[32 ];/* 32 is max size of property name */ + +dev_dbg (dev,"Looking up %s-supply from device tree\n" , supply); + +snprintf (prop_name,32 ,"%s-supply" , supply); + regnode =of_parse_phandle (dev->of_node, prop_name,0 ); + +if (!regnode) { +pr_warn ("%s: %s property in node %s references invalid phandle" , + __func__, prop_name, dev->of_node->full_name); +return NULL ; + } +return regnode; +} +/* Platform voltage constraint check */ static int regulator_check_voltage(struct regulator_dev *rdev,drivers/regulator/core.c +37
-12int *min_uV, int *max_uV)@@ -1147,6 +1176,28 @@return rdev->desc->ops->enable_time (rdev); } +static struct regulator_dev *regulator_dev_lookup (struct device *dev, +const char *supply) +{ +struct regulator_dev *r; +struct device_node *node; + +/* first do a dt based lookup */ +if (dev && dev->of_node) + node =of_get_regulator (dev, supply); +if (node) +list_for_each_entry (r, ®ulator_list, list) +if (node == r->dev.parent->of_node) +return r; + +/* if not found, try doing it non-dt way */ +list_for_each_entry (r, ®ulator_list, list) +if (strcmp (rdev_get_name (r), supply) ==0 ) +return r; + +return NULL ; +} +/* Internal regulator request function */ static struct regulator *_regulator_get (struct device *dev,const char *id,int exclusive)@@ -1155,6 +1206,7 @@struct regulator_map *map;struct regulator *regulator =ERR_PTR (-ENODEV );const char *devname =NULL ; +struct device_node *node;int ret;if (id ==NULL ) {@@ -1167,6 +1219,10 @@mutex_lock (®ulator_list_mutex); + rdev =regulator_dev_lookup (dev, id); +if (rdev) + goto found; +list_for_each_entry (map, ®ulator_map_list, list) {/* If the mapping has a device set up it must match */ if (map->dev_name &&@@ -2579,6 +2635,7 @@static atomic_t regulator_no =ATOMIC_INIT (0 );struct regulator_dev *rdev;int ret, i; +const char *supply;if (regulator_desc ==NULL )return ERR_PTR (-EINVAL );@@ -2653,21 +2710,18 @@if (ret <0 ) goto scrub; -if (init_data->supply_regulator) { +if (init_data->supply_regulator) + supply = init_data->supply_regulator; +else if (regulator_desc->supply_name); + supply = regulator_desc->supply_name; + +if (supply) {struct regulator_dev *r; -int found =0 ; -list_for_each_entry (r, ®ulator_list, list) { -if (strcmp (rdev_get_name (r), - init_data->supply_regulator) ==0 ) { - found =1 ; -break ; - } - } + r =regulator_dev_lookup (dev, supply); -if (!found) { -dev_err (dev,"Failed to find supply %s\n" , - init_data->supply_regulator); +if (!r) { +dev_err (dev,"Failed to find supply %s\n" , supply); ret = -ENODEV ; goto scrub; }Index:
linux/include/linux/regulator/driver.h
===================================================================
---linux.orig/include/linux/regulator/driver.h2011-10-11
11:43:27.936139476 +0530
+++linux/include/linux/regulator/driver.h2011-10-11 11:43:43.485351850 +0530drivers/regulator/core.c +2
-0@@ -153,6 +153,7 @@* this type. * * @name: Identifying name for the regulator. +* @supply_name: Identifying the regulator supply * @id: Numerical identifier for the regulator. * @n_voltages: Number of selectors available for ops.list_voltage(). * @ops: Regulator operations table. @@ -162,6 +163,7 @@*/ struct regulator_desc {const char *name; +const char *supply_name;int id;unsigned n_voltages;struct regulator_ops *ops;
Re: [PATCH v2 5/5] regulator: map consumer regulator based on device tree
In reply to Rajendra NayakQuoted 10 lines · Rajendra Nayak
Device nodes in DT can associate themselves with one or more regulators/supply by providing a list of phandles (to regulator nodes) and corresponding supply names.
For Example:
devicenode: node@0x0 { ... ... vmmc-supply = <®ulator1>; vpll-supply = <®ulator1>;
s/regulator1/regulator2
Quoted 91 lines
};The driver would then do a
regulator_get(dev, "vmmc"); to get regulator1 and do aregulator_get(dev, "vpll"); to get regulator2.
of_get_regulator()extracts the regulator node for a given device, based on the supply name.Use it to look up the regulator for a given consumer from device tree, during a
regulator_get(). If not found fallback and lookup through
theregulator_map_listinstead.Also, since the regulator dt nodes can use the same binding to associate with a parent regulator/supply, allow the drivers to specify a
supply_name, which can then be used to lookup dt to find the parent phandle.Signed-off-by Rajendra Nayak <[email protected]>--- drivers/regulator/core.c | 91 +++++++++++++++++++++++++++++++------ include/linux/regulator/driver.h | 2 + 2 files changed, 78 insertions(+), 15 deletions(-)drivers/regulator/core.c +35
-0@@ -25,9 +25,11 @@#include <linux/mutex.h> #include <linux/suspend.h> #include <linux/delay.h> +#include <linux/of.h> #include <linux/regulator/consumer.h> #include <linux/regulator/driver.h> #include <linux/regulator/machine.h> +#include <linux/regulator/of_regulator.h> #define CREATE_TRACE_POINTS #include <trace/events/regulator.h> @@ -131,6 +133,33 @@ static struct regulator *get_device_regulator(struct device *dev)return NULL ; } +/** +* of_get_regulator - get a regulator device node based on supply name +* @dev: Device pointer for the consumer (of regulator) device +* @supply: regulator supply name +* +* Extract the regulator device node corresponding to the supply name. +* retruns the device node corresponding to the regulator if found, else +* returns NULL. +*/ +struct device_node *of_get_regulator (struct device *dev,const char *supply) +{ +struct device_node *regnode =NULL ; +char prop_name[32 ];/* 32 is max size of property name */ + +dev_dbg (dev,"Looking up %s-supply from device tree\n" , supply); + +snprintf (prop_name,32 ,"%s-supply" , supply); + regnode =of_parse_phandle (dev->of_node, prop_name,0 ); + +if (!regnode) { +pr_warn ("%s: %s property in node %s references invalid phandle" , + __func__, prop_name, dev->of_node->full_name); +return NULL ; + } +return regnode; +} +/* Platform voltage constraint check */ static int regulator_check_voltage (struct regulator_dev *rdev,int *min_uV,int *max_uV)@@ -1155,6 +1184,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,struct regulator_map *map;struct regulator *regulator =ERR_PTR (-ENODEV );const char *devname =NULL ; +struct device_node *node;int ret;if (id ==NULL ) {@@ -1167,6 +1197,23 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,mutex_lock (®ulator_list_mutex); +/* +* Lookup happens in 3 ways +* 1. If a dev and dev->of_node exist, look for a +* regulator mapping in dt node. +* 2. Check if a match can be found in regulator_map_list
drivers/regulator/core.c static struct regulator *_regulator_get(struct device *dev, const char *id, · line 1214
Quoted 10 lines
drivers/regulator/core.c +10
-0+* if regulator info is still passed in non-dt way +* 3. if !dev, then just look for a matching regulator name. +* Useful for dt builds using regulator_get() without specifying +* a device. +*/ +if (dev && dev->of_node) { + node =of_get_regulator (dev, id); +if (node) +list_for_each_entry (rdev, ®ulator_list, list) +if (node == rdev->dev.parent->of_node)
If we move DT parsing procedure into regulator core, we will be able to find the of_node for given regulator and attach it to rdev->dev when regulator_register() gets called by regulator drivers. Then we will have 'if (node == rdev->dev.of_node)' here which makes more sense to me.
Regards,
Shawn
Quoted 102 lines
drivers/regulator/core.c +31
-15+ goto found; + }list_for_each_entry (map, ®ulator_map_list, list) {/* If the mapping has a device set up it must match */ if (map->dev_name &&@@ -1178,6 +1225,10 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, goto found; } } +if (!dev) +list_for_each_entry (rdev, ®ulator_list, list) +if (strcmp (rdev_get_name (rdev), id)) + goto found;if (board_wants_dummy_regulator) { rdev = dummy_regulator_rdev;@@ -2579,6 +2630,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,static atomic_t regulator_no =ATOMIC_INIT (0 );struct regulator_dev *rdev;int ret, i; +const char *supply;if (regulator_desc ==NULL )return ERR_PTR (-EINVAL );@@ -2653,25 +2705,34 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,if (ret <0 ) goto scrub; -if (init_data->supply_regulator) { -struct regulator_dev *r; -int found =0 ; +if (init_data->supply_regulator) + supply = init_data->supply_regulator; +else if (regulator_desc->supply_name); + supply = regulator_desc->supply_name; -list_for_each_entry (r, ®ulator_list, list) { -if (strcmp (rdev_get_name (r), - init_data->supply_regulator) ==0 ) { - found =1 ; -break ; - } +if (supply) { +struct regulator_dev *r; +struct device_node *node; + +/* first do a dt based lookup */ +if (dev) { + node =of_get_regulator (dev, supply); +if (node) +list_for_each_entry (r, ®ulator_list, list) +if (node == r->dev.parent->of_node) + goto found; } -if (!found) { -dev_err (dev,"Failed to find supply %s\n" , - init_data->supply_regulator); - ret = -ENODEV ; - goto scrub; - } +/* next try doing it non-dt way */ +list_for_each_entry (r, ®ulator_list, list) +if (strcmp (rdev_get_name (r), supply) ==0 ) + goto found; +dev_err (dev,"Failed to find supply %s\n" , supply); + ret = -ENODEV ; + goto scrub; + +found: ret =set_supply (rdev, r);if (ret <0 ) goto scrub;include/linux/regulator/driver.h +2
-0@@ -153,6 +153,7 @@ enum regulator_type {* this type. * * @name: Identifying name for the regulator. +* @supply_name: Identifying the regulator supply * @id: Numerical identifier for the regulator. * @n_voltages: Number of selectors available for ops.list_voltage(). * @ops: Regulator operations table. @@ -162,6 +163,7 @@ enum regulator_type {*/ struct regulator_desc {const char *name; +const char *supply_name;int id;unsigned n_voltages;struct regulator_ops *ops;Signature · 6 lines
1.7.1 _______________________________________________ devicetree-discuss mailing list [email protected] https://lists.ozlabs.org/listinfo/devicetree-discuss