Device tree support for regulators
cover Device tree support for regulators
Hi Mark, Grant,
This is a respin of my RFC series I posted sometime back and is now based on top of the latest omap i2c-twl support series posted by Benoitgit://gitorious.org/omap-pm/linux.git for_3.2/4_omap_dt_i2c_twl
some changes done since the RFC:
1. twl driver fixed to remove hardcoded board params
2. regulator helpers moved from drivers/of to drivers/regulator
3. Better compatible definitions for specific device type
4. twl regulator driver doing internal table lookup based on compatible rather then pdev->id
5. Seperate fixed voltage regulator bindings defined
6. Changed the way devices associate with regulators i.e using <name>-supply = <®ulator-phandle>;
regards,
Rajendra
Rajendra Nayak (9):
regulator: twl: Remove hardcoded board constraints from driver
regulator: helper routine to extract regulator_init_data
omap4: sdp: Pass regulator data from dt
regulator: twl: Make twl-regulator driver extract data from DT
regulator: helper routine to extract fixed_voltage_config
regulator: make fixed regulator driver extract data from dt
omap4: panda: Pass regulator data from DT
regulator: helper to extract regulator node based on supply name
regulator: map consumer regulator based on device tree
.../bindings/regulator/fixed-regulator.txt | 24 ++++ .../devicetree/bindings/regulator/regulator.txt | 42 +++++++ .../bindings/regulator/twl-regulator.txt | 60 +++++++++ arch/arm/boot/dts/omap4-panda.dts | 54 ++++++++ arch/arm/boot/dts/omap4-sdp.dts | 64 ++++++++++ drivers/regulator/Kconfig | 7 + drivers/regulator/Makefile | 1 + drivers/regulator/core.c | 14 ++ drivers/regulator/fixed.c | 54 ++++++++- drivers/regulator/of_regulator.c | 127 ++++++++++++++++++++ drivers/regulator/twl-regulator.c | 125 ++++++++++++-------- include/linux/regulator/driver.h | 3 + include/linux/regulator/fixed.h | 6 +- include/linux/regulator/machine.h | 12 +- include/linux/regulator/of_regulator.h | 28 +++++ 15 files changed, 562 insertions(+), 59 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/fixed-regulator.txt create mode 100644 Documentation/devicetree/bindings/regulator/regulator.txt create mode 100644 Documentation/devicetree/bindings/regulator/twl-regulator.txt create mode 100644 drivers/regulator/of_regulator.c create mode 100644 include/linux/regulator/of_regulator.h
PATCH 1/9 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
PATCH 1/9 regulator: twl: Remove hardcoded board constraints from driver
Quoted 6 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]>
drivers/regulator/twl-regulator.c static int __devinit twlreg_probe(struct platform_device *pdev) · line 1037
Quoted 8 lines
drivers/regulator/twl-regulator.c +0
-8-/* 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 ;
This isn't actually hard coding constraints, this is restricting the constraints passed in further rather than adding new ones.
However should be fine:
PATCH 1/9 regulator: twl: Remove hardcoded board constraints from driver
Quoted 19 lines · Mark Brown
Quoted 6 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]>drivers/regulator/twl-regulator.c static int __devinit twlreg_probe(struct platform_device *pdev) · line 1037
Quoted 8 lines
drivers/regulator/twl-regulator.c +0
-8-/* 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 ;This isn't actually hard coding constraints, this is restricting the constraints passed in further rather than adding new ones.
Quoted 3 lines
However should be fine:
Acked-by Mark Brown<[email protected]>
Thanks.
PATCH 2/9 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.
Also add documentation for regulator bindings to be used to pass regulator_init_data struct information from device tree.
--- .../devicetree/bindings/regulator/regulator.txt | 42 +++++++++ drivers/regulator/Kconfig | 7 ++ drivers/regulator/Makefile | 1 + drivers/regulator/of_regulator.c | 88 ++++++++++++++++++++ include/linux/regulator/machine.h | 12 ++-- include/linux/regulator/of_regulator.h | 21 +++++ 6 files changed, 165 insertions(+), 6 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 +42 -0
@@ -0,0 +1,42 @@ +Voltage/Current Regulators + +Optional properties: +- regulator-supplies: Names of the regulator supplies +- 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 + +Example: + + xyzreg: regulator at 0 { + regulator-min-uV = <1000000>; + regulator-max-uV = <2500000>; + regulator-mode-fast; + regulator-change-voltage; + regulator-always-on; + }; + +Example of a device node referencing a regulator node: + + devicenode: node at 0x0 { + ... + ... + <name>-supply = <&xyzreg>; + }; + + where <name> is the supply name or regulator id passed + as part of regulator_get(dev, <name>);
drivers/regulator/Kconfig +7 -0
@@ -64,6 +64,13 @@ config REGULATOR_USERSPACE_CONSUMER If unsure, say no. +config OF_REGULATOR + tristate "OF regulator helpers" + depends on 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 +88 -0
88 lines not on this page · raw message
include/linux/regulator/machine.h +6 -6
@@ -98,14 +98,14 @@ struct regulation_constraints {char *name;/* voltage output range (inclusive) - for voltage control */ -int min_uV; -int max_uV; +u32 min_uV; +u32 max_uV; -int uV_offset; +u32 uV_offset;/* current output range (inclusive) - for current control */ -int min_uA; -int max_uA; +u32 min_uA; +u32 max_uA;/* valid regulator operating modes for this machine */ unsigned int valid_modes_mask;
@@ -114,7 +114,7 @@ struct regulation_constraints {unsigned int valid_ops_mask;/* regulator input voltage - only if supply is another regulator */ -int input_uV; +u32 input_uV;/* regulator suspend states for global PMIC STANDBY/HIBERNATE */ struct regulator_state state_disk;
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_node *np) +{ +return NULL ; +} +#endif /* CONFIG_OF_REGULATOR */ + +#endif /* __LINUX_OF_REG_H */ +
Signature · 1 line
1.7.1
PATCH 2/9 regulator: helper routine to extract regulator_init_data
drivers/regulator/of_regulator.c line 82
Quoted 4 lines · Rajendra Nayak
drivers/regulator/of_regulator.c new file +4
-0+ init_data =devm_kzalloc (dev,sizeof (struct regulator_init_data ), +GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */
This means that the init data will be kept around for the entire lifetime of the device rather than being discarded.
drivers/regulator/of_regulator.c line 85
Quoted 2 lines
drivers/regulator/of_regulator.c new file +2
-0+ init_data->supply_regulator = (char *)of_get_property (dev->of_node, +"regulator-supplies" ,NULL );
I'd expect that in the device tree world the supply regulator would reference the node for that regulator.
Quoted 4 lines
include/linux/regulator/machine.h +1
-2/* voltage output range (inclusive) - for voltage control */ -int min_uV; -int max_uV; +u32 min_uV;
include/linux/regulator/machine.h struct regulation_constraints { · line 108
Quoted 10 lines
include/linux/regulator/machine.h +4
-3+u32 max_uV; -int uV_offset; +u32 uV_offset;/* current output range (inclusive) - for current control */ -int min_uA; -int max_uA; +u32 min_uA; +u32 max_uA;
Hrm, I think loosing the signs here is bad karma - negative voltages do exist after all.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 9 lines · Mark Brown
drivers/regulator/of_regulator.c line 82
Quoted 4 lines · Rajendra Nayak
drivers/regulator/of_regulator.c new file +4
-0+ init_data =devm_kzalloc (dev,sizeof (struct regulator_init_data ), +GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ This means that the init data will be kept around for the entire lifetime of the device rather than being discarded.
Wasn't it the same while this was passed around as platform_data?
Quoted 6 lines
drivers/regulator/of_regulator.c line 85
Quoted 3 lines
drivers/regulator/of_regulator.c new file +2
-0+ init_data->supply_regulator = (char *)of_get_property (dev->of_node, +"regulator-supplies" ,NULL );I'd expect that in the device tree world the supply regulator would reference the node for that regulator.
You mean using phandles? Thats what Grant proposed too but I thought you instead had an inclination towards names? Or maybe I misunderstood.
Quoted 10 lines
Quoted 10 lines
/* voltage output range (inclusive) - for voltage control */
include/linux/regulator/machine.h +3
-3-int min_uV; -int max_uV; +u32 min_uV; +u32 max_uV; -int uV_offset; +u32 uV_offset;
Quoted 8 lines
include/linux/regulator/machine.h struct regulation_constraints { · line 108
Quoted 5 lines
/* current output range (inclusive) - for current control */
include/linux/regulator/machine.h +2
-2-int min_uA; -int max_uA; +u32 min_uA; +u32 max_uA;Hrm, I think loosing the signs here is bad karma - negative voltages do exist after all.
Oops.. they do? didn't know about that.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 11 lines · Rajendra Nayak
Quoted 9 lines · Mark Brown
drivers/regulator/of_regulator.c line 82
Quoted 4 lines · Rajendra Nayak
drivers/regulator/of_regulator.c new file +4
-0+ init_data =devm_kzalloc (dev,sizeof (struct regulator_init_data ), +GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ This means that the init data will be kept around for the entire lifetime of the device rather than being discarded.
Quoted 1 line
Wasn't it the same while this was passed around as
platform_data?
It was in the past but I remember fixing it at some point. Perhaps I'm imagining things.
Quoted 9 lines
Quoted 5 lines
drivers/regulator/of_regulator.c line 85
Quoted 2 lines
drivers/regulator/of_regulator.c new file +2
-0+ init_data->supply_regulator = (char *)of_get_property (dev->of_node, +"regulator-supplies" ,NULL );I'd expect that in the device tree world the supply regulator would reference the node for that regulator.
You mean using phandles? Thats what Grant proposed too but I thought you instead had an inclination towards names? Or maybe I misunderstood.
They need both. We need to reference the device that provides the supply and use a name to say which of the potentially multiple supplies on the consumer device is which.
Quoted 4 lines
Quoted 2 lines
Hrm, I think loosing the signs here is bad karma - negative voltages do exist after all.
Oops.. they do? didn't know about that.
Yup, ground is just a reference point.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 31 lines · Mark Brown
Quoted 11 lines · Rajendra Nayak
Quoted 9 lines · Mark Brown
drivers/regulator/of_regulator.c line 82
Quoted 4 lines · Rajendra Nayak
drivers/regulator/of_regulator.c new file +4
-0+ init_data =devm_kzalloc (dev,sizeof (struct regulator_init_data ), +GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ This means that the init data will be kept around for the entire lifetime of the device rather than being discarded.
Quoted 1 line
Wasn't it the same while this was passed around as
platform_data?It was in the past but I remember fixing it at some point. Perhaps I'm imagining things.
Quoted 9 lines
Quoted 5 lines
drivers/regulator/of_regulator.c line 85
Quoted 2 lines
drivers/regulator/of_regulator.c new file +2
-0+ init_data->supply_regulator = (char *)of_get_property (dev->of_node, +"regulator-supplies" ,NULL );I'd expect that in the device tree world the supply regulator would reference the node for that regulator.
You mean using phandles? Thats what Grant proposed too but I thought you instead had an inclination towards names? Or maybe I misunderstood.
They need both. We need to reference the device that provides the supply and use a name to say which of the potentially multiple supplies on the consumer device is which.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Hrm, I think loosing the signs here is bad karma - negative voltages do exist after all.
Oops.. they do? didn't know about that.
Yup, ground is just a reference point.
Yep, we do have a negative charge pump to generate -1.9v from 3.8v to supply the audio power amplifier part in twl6040 for example.
Benoit
PATCH 2/9 regulator: helper routine to extract regulator_init_data
In reply to Mark Brown[]...
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
drivers/regulator/of_regulator.c line 85
Quoted 3 lines
drivers/regulator/of_regulator.c new file +2
-0+ init_data->supply_regulator = (char *)of_get_property (dev->of_node, +"regulator-supplies" ,NULL );I'd expect that in the device tree world the supply regulator would reference the node for that regulator.
Quoted 7 lines
Quoted 3 lines
You mean using phandles? Thats what Grant proposed too but I thought you instead had an inclination towards names? Or maybe I misunderstood.
They need both. We need to reference the device that provides the supply and use a name to say which of the potentially multiple supplies on the consumer device is which.
Mark, I still seem to be a little confused with this one as to why we would need a phandle *and* a supply-name to reference a parent regulator/supply.
The phandle would point to a regulator dt node and that node internally would have just one name associated with it.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Hrm, I think loosing the signs here is bad karma - negative voltages do exist after all.
Oops.. they do? didn't know about that.
Yup, ground is just a reference point.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
On 9/30/2011 6:27 AM, Nayak, Rajendra wrote:
[...]
Quoted 9 lines
Quoted 3 lines
They need both. We need to reference the device that provides the supply and use a name to say which of the potentially multiple supplies on the consumer device is which.
Mark, I still seem to be a little confused with this one as to why we would need a phandle *and* a supply-name to reference a parent regulator/supply.
The phandle would point to a regulator dt node and that node internally would have just one name associated with it.
I think as well that we should avoid considering a regulator with several outputs. I saw the same pattern used for the clock binding in DT as well.
A clock node like a regulator node should output only one signal. These nodes should provide atomic functionality. And if extra functionality are needed we might consider adding some intermediate nodes. Except for a regulator that will output several lines at the same voltage to spread the current load, assuming it does exist, I'm not sure to understand the need.
Mark,
What usage do you have in mind for such supply node with several outputs?
Regards,
Benoit
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 3 lines · Benoit
I think as well that we should avoid considering a regulator with several outputs. I saw the same pattern used for the clock binding in DT as well.
This binding is for the consumer side, not the producer side. A binding which restricted us to a single consumer per regulator would obviously not work for real systems.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
In reply to Rajendra NayakQuoted 5 lines · Rajendra Nayak
Mark, I still seem to be a little confused with this one as to why we would need a phandle *and* a supply-name to reference a parent regulator/supply.
The phandle would point to a regulator dt node and that node internally would have just one name associated with it.
To repeat: the supply name is for the consumer. It is needed so that the consumer can tell which supply is provided by which regulator. Almost all devices have more than one supply and if the device does anything more complicated than just turning on all the supplies when the device is active it's going to need to figure out which supply is which.
Also, please do remember to keep linux-kernel in the loop on all regulator API discussion - you should always keep the relevant mailing lists in the loop for any subsystem you're changing.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 11 lines · Mark Brown
Quoted 8 lines · Rajendra Nayak
Quoted 2 lines
drivers/regulator/of_regulator.c line 85
Quoted 2 lines
drivers/regulator/of_regulator.c new file +2
-0+ init_data->supply_regulator = (char *)of_get_property (dev->of_node, +"regulator-supplies" ,NULL );Mark, I still seem to be a little confused with this one as to why we would need a phandle *and* a supply-name to reference a parent regulator/supply.
The phandle would point to a regulator dt node and that node internally would have just one name associated with it.
Quoted 5 lines
To repeat: the supply name is for the consumer. It is needed so that the consumer can tell which supply is provided by which regulator. Almost all devices have more than one supply and if the device does anything more complicated than just turning on all the supplies when the device is active it's going to need to figure out which supply is which.
Hang on, I now have no idea what this is supposed to be doing. Later on in the series you had examples in your commit logs with perfectly sensible bindings for supplies:
vmmc-supply = <®ulator1>;
vpll-supply = <®ulator1>;which have both a unique name and a direct reference to the supplying regulator. What are these "regulator-supplies" properties supposed to be?
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 22 lines · Mark Brown
Quoted 11 lines · Mark Brown
Quoted 8 lines · Rajendra Nayak
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ init_data->supply_regulator = (char *)of_get_property(dev->of_node, + "regulator-supplies", NULL);Mark, I still seem to be a little confused with this one as to why we would need a phandle *and* a supply-name to reference a parent regulator/supply.
The phandle would point to a regulator dt node and that node internally would have just one name associated with it.Quoted 5 lines
To repeat: the supply name is for the consumer. It is needed so that the consumer can tell which supply is provided by which regulator. Almost all devices have more than one supply and if the device does anything more complicated than just turning on all the supplies when the device is active it's going to need to figure out which supply is which.
Hang on, I now have no idea what this is supposed to be doing. Later on in the series you had examples in your commit logs with perfectly sensible bindings for supplies:
Quoted 6 lines
vmmc-supply =<®ulator1>; vpll-supply =<®ulator1>;which have both a unique name and a direct reference to the supplying regulator. What are these "regulator-supplies" properties supposed to be?
:-), yes, I was confused for a while as well after reading your response.
The "regulator-supplies" is used to specific the regulator *parent*. Same as what was earlier passed by using the "supply_regulator" field of regulator_init_data structure. Grant wanted the bindings to support specifying multiple parents and hence I was thinking of either a list of names *or*
a list of phandles to specify multiple parents to a regulator.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 30 lines · Rajendra
Quoted 22 lines · Mark Brown
Quoted 11 lines · Mark Brown
Quoted 8 lines · Rajendra Nayak
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ init_data->supply_regulator = (char *)of_get_property(dev->of_node, + "regulator-supplies", NULL);Mark, I still seem to be a little confused with this one as to why we would need a phandle *and* a supply-name to reference a parent regulator/supply.
The phandle would point to a regulator dt node and that node internally would have just one name associated with it.Quoted 5 lines
To repeat: the supply name is for the consumer. It is needed so that the consumer can tell which supply is provided by which regulator. Almost all devices have more than one supply and if the device does anything more complicated than just turning on all the supplies when the device is active it's going to need to figure out which supply is which.
Hang on, I now have no idea what this is supposed to be doing. Later on in the series you had examples in your commit logs with perfectly sensible bindings for supplies:
Quoted 6 lines
vmmc-supply =<®ulator1>; vpll-supply =<®ulator1>;which have both a unique name and a direct reference to the supplying regulator. What are these "regulator-supplies" properties supposed to be?
Quoted 8 lines
:-), yes, I was confused for a while as well after reading your response.
The "regulator-supplies" is used to specific the regulator *parent*. Same as what was earlier passed by using the "
supply_regulator" field ofregulator_init_datastructure. Grant wanted the bindings to support specifying multiple parents and hence I was thinking of either a list of names *or*
a list of phandles to specify multiple parents to a regulator.
I'm confused too now :-)
You can not have multiple to one kind of connection from a power supply to a single power rail of an IP (vmmc, vpll...).
So I do not see the need for more any other binding that the one you did:
vmmc-supply = <®ulator1>;
That kind of binding does not really exist in the real world:
vmmc-supply = <®ulator1 ®ulator2>;
At least not without a power switch in between.
Regards,
Benoit
PATCH 2/9 regulator: helper routine to extract regulator_init_data
In reply to Rajendra NayakQuoted 6 lines · Rajendra Nayak
The "regulator-supplies" is used to specific the regulator *parent*. Same as what was earlier passed by using the "
supply_regulator" field ofregulator_init_datastructure. Grant wanted the bindings to support specifying multiple parents and hence I was thinking of either a list of names *or*
a list of phandles to specify multiple parents to a regulator.
So, as I'm fairly sure I said last time these are just standard supplies. It just happens to be that the consumer is a regulator. The fact that Linux chooses to have core framework handling for this is an implementation detail of Linux (and indeed many devices ignore this for their on board regulators).
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 9 lines · Mark Brown
Quoted 6 lines · Rajendra Nayak
The "regulator-supplies" is used to specific the regulator *parent*. Same as what was earlier passed by using the "
supply_regulator" field ofregulator_init_datastructure. Grant wanted the bindings to support specifying multiple parents and hence I was thinking of either a list of names *or*
a list of phandles to specify multiple parents to a regulator.
Quoted 5 lines
So, as I'm fairly sure I said last time these are just standard supplies. It just happens to be that the consumer is a regulator. The fact that Linux chooses to have core framework handling for this is an implementation detail of Linux (and indeed many devices ignore this for their on board regulators).
Yes, the implementation details of linux is what is making me using these bindings difficult, and maybe you can help me how I can work around the framework. The binding themselves, I agree should not care if the consumer is a device/IP or a regulator itself.
So here's my problem:
I use the <name-supply> = <®_phandle> binding to define a device/IP using one/more regulators on one/more rails.
device mmc {
...
...
vmmc-supply = <&vmmc>;
vpll-supply = <&vpll>;
};The parsing of the "vmmc-supply" or the "vpll-supply" property happens only when a mmc drivers makes a call to regulator_get() passing the supply-name as "vmmc" or "vpll". For ex:regulator_get(dev, "vmmc"); or regulator_get(dev, "vpll");
Its easy to just append the "-supply" to a "vmmc" or "vpll" and derive a property name like "vmm-supply" or "vpll-supply".
Now lets take the case of a regulator as a consumer:
regulator vmmc {
...
...
vin-supply = <&vin>;
};Now I need to parse the "vin-supply" property during a regulator_register(), so I could do a set_supply() and create the parent/child relationship between a vin and vmmc.
The problem is I don't know if the property in the regulator dt node is called "vin-supply" or "vxyz-supply" and hence I can parse the property based on a substring alone, which is "-supply" because all I know is the property name is expected to end with a "-supply".
I can always add a new of_find_property_substr() which finds me property based on a substring value passed rather than the exact property-name string.
However I don;t know if this is the best way to handle it. Any thoughts?
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 5 lines · Rajendra Nayak
The problem is I don't know if the property in the regulator dt node is called "vin-supply" or "vxyz-supply" and hence I can parse the property based on a substring alone, which is "-supply" because all I know is the property name is expected to end with a "-supply".
This seems fairly straightforward though it will require some changes within Linux, all we have to do is have the regulators name their supplies.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 11 lines · Mark Brown
Quoted 5 lines · Rajendra Nayak
The problem is I don't know if the property in the regulator dt node is called "vin-supply" or "vxyz-supply" and hence I can parse the property based on a substring alone, which is "-supply" because all I know is the property name is expected to end with a "-supply".
This seems fairly straightforward though it will require some changes within Linux, all we have to do is have the regulators name their supplies.
through dt? thats what the original bindings was doing.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 7 lines · Rajendra Nayak
Quoted 3 lines · Mark Brown
This seems fairly straightforward though it will require some changes within Linux, all we have to do is have the regulators name their supplies.
through dt? thats what the original bindings was doing.
I wouldn't expect it done through DT (except for things like the fixed voltage regulator) - the driver should just know.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 11 lines · Mark Brown
Quoted 7 lines · Rajendra Nayak
Quoted 3 lines · Mark Brown
This seems fairly straightforward though it will require some changes within Linux, all we have to do is have the regulators name their supplies.
through dt? thats what the original bindings was doing.
I wouldn't expect it done through DT (except for things like the fixed voltage regulator) - the driver should just know.
something like a
int regulator_set_supply(struct regulator_dev *rdev, char *supply_name); to be called from drivers makes sense?
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 8 lines · Rajendra Nayak
Quoted 2 lines · Mark Brown
I wouldn't expect it done through DT (except for things like the fixed voltage regulator) - the driver should just know.
something like a
intregulator_set_supply(struct regulator_dev *rdev, char *supply_name); to be called from drivers makes sense?
Just put a member in the driver struct, much simpler that way, no code in the individual drivers.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 7 lines · Mark Brown
Quoted 4 lines · Rajendra Nayak
Quoted 2 lines · Mark Brown
I wouldn't expect it done through DT (except for things like the fixed voltage regulator) - the driver should just know.
Quoted 6 lines
Quoted 3 lines
something like a
intregulator_set_supply(struct regulator_dev *rdev, char *supply_name); to be called from drivers makes sense?Just put a member in the driver struct, much simpler that way, no code in the individual drivers.
okay, makes sense. I will add it to struct regulator_desc. Thanks.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
In reply to Mark BrownQuoted 10 lines · Mark Brown
drivers/regulator/of_regulator.c line 82
Quoted 4 lines · Rajendra Nayak
drivers/regulator/of_regulator.c new file +4
-0+ init_data =devm_kzalloc (dev,sizeof (struct regulator_init_data ), +GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ This means that the init data will be kept around for the entire lifetime of the device rather than being discarded.
Quoted 5 lines
drivers/regulator/of_regulator.c line 85
Quoted 2 lines
drivers/regulator/of_regulator.c new file +2
-0+ init_data->supply_regulator = (char *)of_get_property (dev->of_node, +"regulator-supplies" ,NULL );I'd expect that in the device tree world the supply regulator would reference the node for that regulator.
Yes, I would expect the same.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
In reply to Mark BrownQuoted 9 lines · Mark Brown
drivers/regulator/of_regulator.c line 82
Quoted 4 lines · Rajendra Nayak
drivers/regulator/of_regulator.c new file +4
-0+ init_data =devm_kzalloc (dev,sizeof (struct regulator_init_data ), +GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ This means that the init data will be kept around for the entire lifetime of the device rather than being discarded.
May I remind you that devm_* lifetime expires whenever the associated driver is unbound, which can be much shorter than the lifetime of the struct device.
It expires when any of the following occurs:
1. userspace asks the associated driver to be unbound
2. the driver is removed
3. any driver probe for this struct device fails
4. the struct device is unregistered.
So: don't use devm_* for anything other than stuff inside a driver being associated with the struct device itself. Other uses are a bug waiting to happen.
PATCH 2/9 regulator: helper routine to extract regulator_init_data
Quoted 21 lines · Russell King - ARM Linux
Quoted 9 lines · Mark Brown
drivers/regulator/of_regulator.c line 82
Quoted 4 lines · Rajendra Nayak
drivers/regulator/of_regulator.c new file +4
-0+ init_data =devm_kzalloc (dev,sizeof (struct regulator_init_data ), +GFP_KERNEL ); +if (!init_data) +return NULL ;/* Out of memory? */ This means that the init data will be kept around for the entire lifetime of the device rather than being discarded.
May I remind you that devm_* lifetime expires whenever the associated driver is unbound, which can be much shorter than the lifetime of the struct device.
It expires when any of the following occurs:
1. userspace asks the associated driver to be unbound
2. the driver is removed
3. any driver probe for this struct device fails
4. the struct device is unregistered.
Quoted 3 lines
So: don't use devm_* for anything other than stuff inside a driver being associated with the struct device itself. Other uses are a bug waiting to happen.
Yes, Russell is right. There were a number of places where I suggested using devm_* in entirely the wrong places. Double check anyplace where you've added devm_ calls.
g.
PATCH 3/9 omap4: sdp: Pass regulator data from dt
In reply to Rajendra NayakPass adjustable regulator information for omap4sdp from device tree so the regulator driver can then use the regulator helper
routine to extract and use them during the driver probe().
Also add documentation for TWL regulator specific bindings.
--- .../bindings/regulator/twl-regulator.txt | 60 ++++++++++++++++++ arch/arm/boot/dts/omap4-sdp.dts | 64 ++++++++++++++++++++ 2 files changed, 124 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/twl-regulator.txt
Documentation/devicetree/bindings/regulator/twl-regulator.txt new file +60 -0
@@ -0,0 +1,60 @@ +TWL family of regulators + +Required properties: +- compatible: + - "ti,twl4030" for twl4030 regulators + - "ti,twl6025" for twl6025 regulators + - "ti,twl6030" for twl6030 regulators + +Additionally compatible can be used to specify the +exact regulator/ldo instance like +For twl6030 regulators/LDO's +- compatible: + - "ti,twl6030-vaux1" for VAUX1 LDO + - "ti,twl6030-vaux2" for VAUX2 LDO + - "ti,twl6030-vaux3" for VAUX3 LDO + - "ti,twl6030-vmmc" for VMMC LDO + - "ti,twl6030-vpp" for VPP LDO + - "ti,twl6030-vusim" for VUSIM LDO +For twl6025 regulators/LDO's +- compatible: + - "ti,twl6025-ldo1" for LDO1 LDO + - "ti,twl6025-ldo2" for LDO2 LDO + - "ti,twl6025-ldo3" for LDO3 LDO + - "ti,twl6025-ldo4" for LDO4 LDO + - "ti,twl6025-ldo5" for LDO5 LDO + - "ti,twl6025-ldo6" for LDO6 LDO + - "ti,twl6025-ldo7" for LDO7 LDO + - "ti,twl6025-ldoln" for LDOLN LDO + - "ti,twl6025-ldousb" for LDOUSB LDO +For twl4030 regulators/LDO's +- compatible: + - "ti,twl4030-vaux1" for VAUX1 LDO + - "ti,twl4030-vaux2" for VAUX2 LDO + - "ti,twl5030-vaux2" for VAUX2 LDO + - "ti,twl4030-vaux3" for VAUX3 LDO + - "ti,twl4030-vaux4" for VAUX4 LDO + - "ti,twl4030-vmmc1" for VMMC1 LDO + - "ti,twl4030-vmmc2" for VMMC2 LDO + - "ti,twl4030-vpll1" for VPLL1 LDO + - "ti,twl4030-vpll2" for VPLL2 LDO + - "ti,twl4030-vsim" for VSIM LDO + - "ti,twl4030-vdac" for VDAC LDO + - "ti,twl4030-vintana2" for VINTANA2 LDO + - "ti,twl4030-vio" for VIO LDO + - "ti,twl4030-vdd1" for VDD1 LDO + - "ti,twl4030-vdd2" for VDD2 LDO + +Optional properties: +- Any optional property defined in bindings/regulator/regulator.txt + +Example: + + xyz: regulator at 0 { + compatible = "ti,twl6030-vaux1","ti,twl6030"; + regulator-min_uV = <1000000>; + regulator-max_uV = <3000000>; + regulator-more-normal; + regulator-mode-standby; + regulator-change-voltage; + };
arch/arm/boot/dts/omap4-sdp.dts +64 -0
70 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 4/9 regulator: twl: Make twl-regulator driver extract data from DT
In reply to Rajendra NayakModify the twl regulator driver to extract the regulator_init_data from device tree when passed, instead of getting it through platform_data structures (on non-DT builds)
--- drivers/regulator/twl-regulator.c | 117 ++++++++++++++++++++++++------------- 1 files changed, 76 insertions(+), 41 deletions(-)
drivers/regulator/twl-regulator.c +76 -41
@@ -14,8 +14,10 @@#include <linux/err.h> #include <linux/delay.h> #include <linux/platform_device.h> +#include <linux/of.h> #include <linux/regulator/driver.h> #include <linux/regulator/machine.h> +#include <linux/regulator/of_regulator.h> #include <linux/i2c/twl.h>
@@ -58,6 +60,9 @@ struct twlreg_info {/* chip specific features */ unsigned long features; +#ifdef CONFIG_OF +char compatible[128 ]; +#endif };
@@ -839,13 +844,14 @@ static struct regulator_ops twlsmps_ops = {TWL_FIXED_LDO (label, offset, mVolts,0x0 , turnon_delay, \ 0x0, TWL6030, twl6030fixed_ops) -#define TWL4030_ADJUSTABLE_LDO (label, offset, num, turnon_delay, remap_conf) { \ +#define TWL4030_ADJUSTABLE_LDO (label, offset, num, turnon_delay, remap_conf, comp) { \ .base = offset, \ .id = num, \ .table_len = ARRAY_SIZE(label##_VSEL_table), \ .table = label##_VSEL_table, \ .delay = turnon_delay, \ .remap = remap_conf, \ + .compatible = comp, \ .desc = { \ .name = #label, \ .id = TWL4030_REG_##label, \
@@ -856,10 +862,11 @@ static struct regulator_ops twlsmps_ops = { }, \ } -#define TWL6030_ADJUSTABLE_LDO (label, offset, min_mVolts, max_mVolts) { \ +#define TWL6030_ADJUSTABLE_LDO (label, offset, min_mVolts, max_mVolts, comp) { \ .base = offset, \ .min_mV = min_mVolts, \ .max_mV = max_mVolts, \ + .compatible = comp, \ .desc = { \ .name = #label, \ .id = TWL6030_REG_##label, \
@@ -870,10 +877,11 @@ static struct regulator_ops twlsmps_ops = { }, \ } -#define TWL6025_ADJUSTABLE_LDO (label, offset, min_mVolts, max_mVolts) { \ +#define TWL6025_ADJUSTABLE_LDO (label, offset, min_mVolts, max_mVolts, comp) { \ .base = offset, \ .min_mV = min_mVolts, \ .max_mV = max_mVolts, \ + .compatible = comp, \ .desc = { \ .name = #label, \ .id = TWL6025_REG_##label, \
@@ -932,23 +940,23 @@ static struct regulator_ops twlsmps_ops = {* software control over them after boot. */ static struct twlreg_info twl_regs[] = { -TWL4030_ADJUSTABLE_LDO (VAUX1 ,0x17 ,1 ,100 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VAUX2_4030 ,0x1b ,2 ,100 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VAUX2 ,0x1b ,2 ,100 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VAUX3 ,0x1f ,3 ,100 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VAUX4 ,0x23 ,4 ,100 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VMMC1 ,0x27 ,5 ,100 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VMMC2 ,0x2b ,6 ,100 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VPLL1 ,0x2f ,7 ,100 ,0x00 ), -TWL4030_ADJUSTABLE_LDO (VPLL2 ,0x33 ,8 ,100 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VSIM ,0x37 ,9 ,100 ,0x00 ), -TWL4030_ADJUSTABLE_LDO (VDAC ,0x3b ,10 ,100 ,0x08 ), +TWL4030_ADJUSTABLE_LDO (VAUX1 ,0x17 ,1 ,100 ,0x08 ,"ti,twl4030-vaux1" ), +TWL4030_ADJUSTABLE_LDO (VAUX2_4030 ,0x1b ,2 ,100 ,0x08 ,"ti,twl4030-vaux2" ), +TWL4030_ADJUSTABLE_LDO (VAUX2 ,0x1b ,2 ,100 ,0x08 ,"ti,twl5030-vaux2" ), +TWL4030_ADJUSTABLE_LDO (VAUX3 ,0x1f ,3 ,100 ,0x08 ,"ti,twl4030-vaux3" ), +TWL4030_ADJUSTABLE_LDO (VAUX4 ,0x23 ,4 ,100 ,0x08 ,"ti,twl4030-vaux4" ), +TWL4030_ADJUSTABLE_LDO (VMMC1 ,0x27 ,5 ,100 ,0x08 ,"ti,twl4030-vmmc1" ), +TWL4030_ADJUSTABLE_LDO (VMMC2 ,0x2b ,6 ,100 ,0x08 ,"ti,twl4030-vmmc2" ), +TWL4030_ADJUSTABLE_LDO (VPLL1 ,0x2f ,7 ,100 ,0x00 ,"ti,twl4030-vpll1" ), +TWL4030_ADJUSTABLE_LDO (VPLL2 ,0x33 ,8 ,100 ,0x08 ,"ti,twl4030-vpll2" ), +TWL4030_ADJUSTABLE_LDO (VSIM ,0x37 ,9 ,100 ,0x00 ,"ti,twl4030-vsim" ), +TWL4030_ADJUSTABLE_LDO (VDAC ,0x3b ,10 ,100 ,0x08 ,"ti,twl4030-vdac" ),TWL4030_FIXED_LDO (VINTANA1 ,0x3f ,1500 ,11 ,100 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VINTANA2 ,0x43 ,12 ,100 ,0x08 ), +TWL4030_ADJUSTABLE_LDO (VINTANA2 ,0x43 ,12 ,100 ,0x08 ,"ti,twl4030-vintana2" ),TWL4030_FIXED_LDO (VINTDIG ,0x47 ,1500 ,13 ,100 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VIO ,0x4b ,14 ,1000 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VDD1 ,0x55 ,15 ,1000 ,0x08 ), -TWL4030_ADJUSTABLE_LDO (VDD2 ,0x63 ,16 ,1000 ,0x08 ), +TWL4030_ADJUSTABLE_LDO (VIO ,0x4b ,14 ,1000 ,0x08 ,"ti,twl4030-vio" ), +TWL4030_ADJUSTABLE_LDO (VDD1 ,0x55 ,15 ,1000 ,0x08 ,"ti,twl4030-vdd1" ), +TWL4030_ADJUSTABLE_LDO (VDD2 ,0x63 ,16 ,1000 ,0x08 ,"ti,twl4030-vdd2" ),TWL4030_FIXED_LDO (VUSB1V5 ,0x71 ,1500 ,17 ,100 ,0x08 ),TWL4030_FIXED_LDO (VUSB1V8 ,0x74 ,1800 ,18 ,100 ,0x08 ),TWL4030_FIXED_LDO (VUSB3V1 ,0x77 ,3100 ,19 ,150 ,0x08 ),
@@ -957,12 +965,12 @@ static struct twlreg_info twl_regs[] = {/* 6030 REG with base as PMC Slave Misc : 0x0030 */ /* Turnon-delay and remap configuration values for 6030 are not verified since the specification is not public */ -TWL6030_ADJUSTABLE_LDO (VAUX1_6030 ,0x54 ,1000 ,3300 ), -TWL6030_ADJUSTABLE_LDO (VAUX2_6030 ,0x58 ,1000 ,3300 ), -TWL6030_ADJUSTABLE_LDO (VAUX3_6030 ,0x5c ,1000 ,3300 ), -TWL6030_ADJUSTABLE_LDO (VMMC ,0x68 ,1000 ,3300 ), -TWL6030_ADJUSTABLE_LDO (VPP ,0x6c ,1000 ,3300 ), -TWL6030_ADJUSTABLE_LDO (VUSIM ,0x74 ,1000 ,3300 ), +TWL6030_ADJUSTABLE_LDO (VAUX1_6030 ,0x54 ,1000 ,3300 ,"ti,twl6030-vaux1" ), +TWL6030_ADJUSTABLE_LDO (VAUX2_6030 ,0x58 ,1000 ,3300 ,"ti,twl6030-vaux2" ), +TWL6030_ADJUSTABLE_LDO (VAUX3_6030 ,0x5c ,1000 ,3300 ,"ti,twl6030-vaux3" ), +TWL6030_ADJUSTABLE_LDO (VMMC ,0x68 ,1000 ,3300 ,"ti,twl6030-vmmc" ), +TWL6030_ADJUSTABLE_LDO (VPP ,0x6c ,1000 ,3300 ,"ti,twl6030-vpp" ), +TWL6030_ADJUSTABLE_LDO (VUSIM ,0x74 ,1000 ,3300 ,"ti,twl6030-vusim" ),TWL6030_FIXED_LDO (VANA ,0x50 ,2100 ,0 ),TWL6030_FIXED_LDO (VCXIO ,0x60 ,1800 ,0 ), TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0),
@@ -970,15 +978,15 @@ static struct twlreg_info twl_regs[] = {TWL6030_FIXED_RESOURCE (CLK32KG ,0x8C ,0 ),/* 6025 are renamed compared to 6030 versions */ -TWL6025_ADJUSTABLE_LDO (LDO2 ,0x54 ,1000 ,3300 ), -TWL6025_ADJUSTABLE_LDO (LDO4 ,0x58 ,1000 ,3300 ), -TWL6025_ADJUSTABLE_LDO (LDO3 ,0x5c ,1000 ,3300 ), -TWL6025_ADJUSTABLE_LDO (LDO5 ,0x68 ,1000 ,3300 ), -TWL6025_ADJUSTABLE_LDO (LDO1 ,0x6c ,1000 ,3300 ), -TWL6025_ADJUSTABLE_LDO (LDO7 ,0x74 ,1000 ,3300 ), -TWL6025_ADJUSTABLE_LDO (LDO6 ,0x60 ,1000 ,3300 ), -TWL6025_ADJUSTABLE_LDO (LDOLN ,0x64 ,1000 ,3300 ), -TWL6025_ADJUSTABLE_LDO (LDOUSB ,0x70 ,1000 ,3300 ), +TWL6025_ADJUSTABLE_LDO (LDO2 ,0x54 ,1000 ,3300 ,"ti,twl6025-ldo2" ), +TWL6025_ADJUSTABLE_LDO (LDO4 ,0x58 ,1000 ,3300 ,"ti,twl6025-ldo4" ), +TWL6025_ADJUSTABLE_LDO (LDO3 ,0x5c ,1000 ,3300 ,"ti,twl6025-ldo3" ), +TWL6025_ADJUSTABLE_LDO (LDO5 ,0x68 ,1000 ,3300 ,"ti,twl6025-ldo5" ), +TWL6025_ADJUSTABLE_LDO (LDO1 ,0x6c ,1000 ,3300 ,"ti,twl6025-ldo1" ), +TWL6025_ADJUSTABLE_LDO (LDO7 ,0x74 ,1000 ,3300 ,"ti,twl6025-ldo7" ), +TWL6025_ADJUSTABLE_LDO (LDO6 ,0x60 ,1000 ,3300 ,"ti,twl6025-ldo6" ), +TWL6025_ADJUSTABLE_LDO (LDOLN ,0x64 ,1000 ,3300 ,"ti,twl6025-ldoln" ), +TWL6025_ADJUSTABLE_LDO (LDOUSB ,0x70 ,1000 ,3300 ,"ti,twl6025-ldousb" ),TWL6025_ADJUSTABLE_SMPS (SMPS3 ,0x34 ), TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10),
@@ -1011,16 +1019,27 @@ static int __devinit twlreg_probe(struct platform_device *pdev)struct regulation_constraints *c;struct regulator_dev *rdev; -for (i =0 , info =NULL ; i <ARRAY_SIZE (twl_regs); i++) { -if (twl_regs[i].desc.id != pdev->id) -continue ; - info = twl_regs + i; -break ; +if (pdev->dev.of_node) {/* dt based lookup */ +for (i =0 , info =NULL ; i <ARRAY_SIZE (twl_regs); i++) { +if (!of_device_is_compatible (pdev->dev.of_node, + twl_regs[i].compatible)) +continue ; + info = twl_regs + i; +break ; + } + initdata =of_get_regulator_init_data (&pdev->dev); + }else {/* pdev->id based lookup */ +for (i =0 , info =NULL ; i <ARRAY_SIZE (twl_regs); i++) { +if (twl_regs[i].desc.id != pdev->id) +continue ; + info = twl_regs + i; +break ; + } + initdata = pdev->dev.platform_data; }if (!info)return -ENODEV ; - initdata = pdev->dev.platform_data;if (!initdata)return -EINVAL ;
@@ -1093,14 +1112,30 @@ static int __devexit twlreg_remove(struct platform_device *pdev)MODULE_ALIAS ("platform:twl_reg" ); +#if defined(CONFIG_OF ) +static const struct of_device_id twl_of_match[]__devinitconst = { + { .compatible ="ti,twl6030" }, + { .compatible ="ti,twl6025" }, + { .compatible ="ti,twl5030" }, + { .compatible ="ti,twl4030" }, + {}, +}; +MODULE_DEVICE_TABLE (of, twl_of_match); +#else +#define twl_of_match NULL +#endif +static struct platform_driver twlreg_driver = { .probe = twlreg_probe, .remove =__devexit_p (twlreg_remove),/* NOTE: short name, to work around driver model truncation of * "twl_regulator.12" (and friends) to "twl_regulator.1". */ - .driver.name ="twl_reg" , - .driver.owner =THIS_MODULE , + .driver = { + .name ="twl_reg" , + .owner =THIS_MODULE , + .of_match_table = twl_of_match, + }, };static int __init twlreg_init (void )
Signature · 1 line
1.7.1
PATCH 4/9 regulator: twl: Make twl-regulator driver extract data from DT
drivers/regulator/twl-regulator.c struct twlreg_info { · line 65
Quoted 3 lines · Rajendra Nayak
drivers/regulator/twl-regulator.c +3
-0+#ifdef CONFIG_OF +char compatible[128 ]; +#endif
Might it not be better to just make this a pointer to const char?
PATCH 4/9 regulator: twl: Make twl-regulator driver extract data from DT
Quoted 7 lines · Mark Brown
drivers/regulator/twl-regulator.c struct twlreg_info { · line 65
Quoted 3 lines · Rajendra Nayak
drivers/regulator/twl-regulator.c +3
-0+#ifdef CONFIG_OF +char compatible[128 ]; +#endif Might it not be better to just make this a pointer to const char?
Yes, my bad.
PATCH 5/9 regulator: helper routine to extract fixed_voltage_config
In reply to Rajendra NayakThe helper routine of_get_fixed_voltage_config() extracts 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 | 24 +++++++++++++ drivers/regulator/fixed.c | 36 ++++++++++++++++++++ include/linux/regulator/fixed.h | 6 ++-- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/fixed-regulator.txt
Documentation/devicetree/bindings/regulator/fixed-regulator.txt new file +24 -0
@@ -0,0 +1,24 @@ +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 +36 -0
@@ -26,6 +26,8 @@#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 +39,40 @@ 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) +{ +struct fixed_voltage_config *config; +struct device_node *np = dev->of_node; + + 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_property_read_u32 (np,"regulator-fixed-microvolts" , + &config->microvolts); +of_property_read_u32 (np,"regulator-fixed-gpio" , &config->gpio); +of_property_read_u32 (np,"regulator-fixed-startup-delay" , + &config->startup_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);
include/linux/regulator/fixed.h +3 -3
@@ -40,9 +40,9 @@ struct regulator_init_data;*/ struct fixed_voltage_config {const char *supply_name; -int microvolts; -int gpio; -unsigned startup_delay; +u32 microvolts; +u32 gpio; +u32 startup_delay;unsigned enable_high:1 ;unsigned enabled_at_boot:1 ;struct regulator_init_data *init_data;
Signature · 1 line
1.7.1
PATCH 5/9 regulator: helper routine to extract fixed_voltage_config
Quoted 5 lines · Rajendra Nayak
The helper routine
of_get_fixed_voltage_config()extractsfixed_voltage_configstructure contents from device tree.Also add documenation for additional bindings for fixed regulators that can be passed through dt.
Why not just add device tree support into the driver directly?
Quoted 2 lines
+Optional properties:
+- regulator-fixed-supply: Name of the regulator supply
This is going to be confusing with respect to the generic regulator supply property.
Quoted 1 line
+- regulator-fixed-enable-high: Polarity of enable GPIO, 1 = Active High, 0 = Active low
Word wrap for legibility please.
PATCH 5/9 regulator: helper routine to extract fixed_voltage_config
Quoted 8 lines · Mark Brown
Quoted 5 lines · Rajendra Nayak
The helper routine
of_get_fixed_voltage_config()extractsfixed_voltage_configstructure contents from device tree.Also add documenation for additional bindings for fixed regulators that can be passed through dt.
Why not just add device tree support into the driver directly?
Ok, will do.
Quoted 6 lines
Quoted 3 lines
+Optional properties:
+- regulator-fixed-supply: Name of the regulator supplyThis is going to be confusing with respect to the generic regulator supply property.
Yes, I guess. Any suggestions on how to make it less confusing? :-)
Quoted 4 lines
Quoted 2 lines
+- regulator-fixed-enable-high: Polarity of enable GPIO, 1 = Active High, 0 = Active low
Word wrap for legibility please.
Ok.
PATCH 5/9 regulator: helper routine to extract fixed_voltage_config
Quoted 11 lines · Rajendra Nayak
Quoted 7 lines · Mark Brown
Quoted 2 lines · Rajendra Nayak
+Optional properties:
+- regulator-fixed-supply: Name of the regulator supplyThis is going to be confusing with respect to the generic regulator supply property.
Yes, I guess. Any suggestions on how to make it less confusing? :-)
Call it display-name or something?
PATCH 5/9 regulator: helper routine to extract fixed_voltage_config
In reply to Rajendra NayakQuoted 66 lines · Rajendra Nayak
The helper routine
of_get_fixed_voltage_config()extractsfixed_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 | 24 +++++++++++++ drivers/regulator/fixed.c | 36 ++++++++++++++++++++ include/linux/regulator/fixed.h | 6 ++-- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/fixed-regulator.txtDocumentation/devicetree/bindings/regulator/fixed-regulator.txt new file +24
-0@@ -0,0 +1,24 @@ +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 +7
-0@@ -26,6 +26,8 @@#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 +39,40 @@ 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 +*
drivers/regulator/fixed.c struct fixed_voltage_data { · line 56
Quoted 10 lines
drivers/regulator/fixed.c +10
-0+* 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) +{ +struct fixed_voltage_config *config; +struct device_node *np = dev->of_node; + + config =devm_kzalloc (dev,sizeof (struct fixed_voltage_config ),GFP_KERNEL );
Nit: config = devm_kzalloc(dev, *config, GFP_KERNEL);
g.
PATCH 6/9 regulator: make fixed regulator driver extract data from dt
In reply to Rajendra NayakModify the fixed regulator driver to extract fixed_voltage_config from device tree when passed, instead of getting it through platform_data structures (on non-DT builds)
--- drivers/regulator/fixed.c | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-)
drivers/regulator/fixed.c +17 -1
@@ -140,10 +140,15 @@ static struct regulator_ops fixed_voltage_ops = {static int __devinit reg_fixed_voltage_probe (struct platform_device *pdev) { -struct fixed_voltage_config *config = pdev->dev.platform_data; +struct fixed_voltage_config *config;struct fixed_voltage_data *drvdata;int ret; +if (pdev->dev.of_node) + config =of_get_fixed_voltage_config (&pdev->dev); +else + config = pdev->dev.platform_data; + drvdata =kzalloc (sizeof (struct fixed_voltage_data ),GFP_KERNEL );if (drvdata ==NULL ) {dev_err (&pdev->dev,"Failed to allocate device data\n" );
@@ -252,12 +257,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 6/9 regulator: make fixed regulator driver extract data from dt
Quoted 14 lines · Rajendra Nayak
Modify the fixed regulator driver to extract
fixed_voltage_configfrom device tree when passed, instead of getting it throughplatform_datastructures (on non-DT builds)Signed-off-by Rajendra Nayak <[email protected]>--- drivers/regulator/fixed.c | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-)drivers/regulator/fixed.c +0
-0
drivers/regulator/fixed.c static struct regulator_ops fixed_voltage_ops = { · line 143
Quoted 5 lines
drivers/regulator/fixed.c +1
-1@@ -140,10 +140,15 @@ static struct regulator_ops fixed_voltage_ops = {static int __devinit reg_fixed_voltage_probe (struct platform_device *pdev) { -struct fixed_voltage_config *config = pdev->dev.platform_data; +struct fixed_voltage_config *config;
This line doesn't actually need to change; just override it below if the of_node is present.
Quoted 40 lines
drivers/regulator/fixed.c +16
-0struct fixed_voltage_data *drvdata;int ret; +if (pdev->dev.of_node) + config =of_get_fixed_voltage_config (&pdev->dev); +else + config = pdev->dev.platform_data; + drvdata =kzalloc (sizeof (struct fixed_voltage_data ),GFP_KERNEL );if (drvdata ==NULL ) {dev_err (&pdev->dev,"Failed to allocate device data\n" );@@ -252,12 +257,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 7/9 omap4: panda: Pass regulator data from DT
In reply to Rajendra NayakPass the fixed and adjustable voltage regulator information for omap4panda board from device tree.
--- arch/arm/boot/dts/omap4-panda.dts | 54 +++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-)
arch/arm/boot/dts/omap4-panda.dts +54 -0
@@ -48,6 +48,60 @@ compatible = "ti,twl4030-rtc"; interrupts = <11>; }; + + vwl1271: fixedregulator at 0 { + compatible = "regulator-fixed"; + regulator-fixed-supply = "vwl1271"; + regulator-fixed-microvolts = <1800000>; + regulator-fixed-gpio = <43>; + regulator-fixed-startup-delay = <70000>; + regulator-fixed-enable-high; + regulator-fixed-enabled-at-boot; + }; + + vaux2: regulator at 0 { + compatible = "ti,twl6030-vaux2","ti,twl6030"; + regulator-min-uV = <1200000>; + regulator-max-uV = <2800000>; + regulator-mode-normal; + regulator-mode-standby; + regulator-change-mode; + regulator-change-status; + regulator-change-voltage; + }; + + vaux3: regulator at 1 { + compatible = "ti,twl6030-vaux3","ti,twl6030"; + regulator-min-uV = <1000000>; + regulator-max-uV = <3000000>; + regulator-mode-normal; + regulator-mode-standby; + regulator-change-mode; + regulator-change-status; + regulator-change-voltage; + }; + + vmmc: regulator at 2 { + compatible = "ti,twl6030-vmmc","ti,twl6030"; + regulator-min-uV = <1200000>; + regulator-max-uV = <3000000>; + regulator-mode-normal; + regulator-mode-standby; + regulator-change-mode; + regulator-change-status; + regulator-change-voltage; + }; + + vpp: regulator at 3 { + compatible = "ti,twl6030-vpp","ti,twl6030"; + regulator-min-uV = <1800000>; + regulator-max-uV = <2500000>; + regulator-mode-normal; + regulator-mode-standby; + regulator-change-mode; + regulator-change-status; + regulator-change-voltage; + }; }; };
Signature · 1 line
1.7.1
PATCH 8/9 regulator: helper to extract regulator node based on supply name
In reply to Rajendra NayakDevice nodes in DT can associate themselves with one or more regulators 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.
--- drivers/regulator/of_regulator.c | 39 ++++++++++++++++++++++++++++++++ include/linux/regulator/of_regulator.h | 7 +++++ 2 files changed, 46 insertions(+), 0 deletions(-)
drivers/regulator/of_regulator.c +39 -0
@@ -14,6 +14,45 @@#include <linux/of.h> #include <linux/regulator/machine.h> + +/** +* 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 ; +u32 reghandle; +char prop_name[32 ];/* 32 is max size of property name */ +const void *prop; +int sz; + +if (!dev) +return NULL ; + +dev_dbg (dev,"Looking up %s-supply from device tree\n" , supply); + +snprintf (prop_name,32 ,"%s-supply" , supply); + + prop =of_get_property (dev->of_node, prop_name, &sz); +if (!prop || sz <4 ) +return NULL ; + + reghandle =be32_to_cpup (prop); + regnode =of_find_node_by_phandle (reghandle); +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; +} +static void of_get_regulation_constraints (struct device_node *np,struct regulator_init_data **init_data) {
include/linux/regulator/of_regulator.h +7 -0
@@ -9,12 +9,19 @@#if defined(CONFIG_OF_REGULATOR )extern struct regulator_init_data *of_get_regulator_init_data (struct device *dev); +extern struct device_node *of_get_regulator (struct device *dev, +const char *supply);#else static inline struct regulator_init_data *of_get_regulator_init_data (struct device_node *np) {return NULL ; } +static inline struct device_node *of_get_regulator (struct device *dev, +const char *id) +{ +return NULL ; +}#endif /* CONFIG_OF_REGULATOR */ #endif /* __LINUX_OF_REG_H */
Signature · 1 line
1.7.1
PATCH 8/9 regulator: helper to extract regulator node based on supply name
Review
Quoted 2 lines · Rajendra Nayak
(quoted diff) +2
-0+ if (!dev) + return NULL;
So how do we handle CPUs? cpufreq is one of the most active users of regulators...
drivers/regulator/of_regulator.c line 44
Quoted 5 lines
drivers/regulator/of_regulator.c +5
-0+snprintf (prop_name,32 ,"%s-supply" , supply); + + prop =of_get_property (dev->of_node, prop_name, &sz); +if (!prop || sz <4 ) +return NULL ;
sz < 4? Magic! :)
include/linux/regulator/of_regulator.h line 13
Quoted 2 lines
include/linux/regulator/of_regulator.h +2
-0+extern struct device_node *of_get_regulator (struct device *dev, +const char *supply);
This shouldn't be part of the public API, it should be transparently handled within the core.
PATCH 8/9 regulator: helper to extract regulator node based on supply name
Quoted 7 lines · Mark Brown
Review
Quoted 2 lines · Rajendra Nayak
(quoted diff) +2
-0+ if (!dev) + return NULL;So how do we handle CPUs? cpufreq is one of the most active users of regulators...
Hmm, never thought of it :(
Maybe I should associate a supply name with all regulators and then lookup from the global registered list.
Quoted 8 lines
drivers/regulator/of_regulator.c line 44
Quoted 6 lines
drivers/regulator/of_regulator.c +5
-0+snprintf (prop_name,32 ,"%s-supply" , supply); + + prop =of_get_property (dev->of_node, prop_name,&sz); +if (!prop || sz<4 ) +return NULL ;sz< 4? Magic! :)
Its the valid phandle size.
I guess I need a sz != 4
Quoted 6 lines
include/linux/regulator/of_regulator.h line 13
Quoted 3 lines
include/linux/regulator/of_regulator.h +2
-0+extern struct device_node *of_get_regulator (struct device *dev, +const char *supply);This shouldn't be part of the public API, it should be transparently handled within the core.
agreed.
PATCH 8/9 regulator: helper to extract regulator node based on supply name
Quoted 9 lines · Rajendra Nayak
Quoted 7 lines · Mark Brown
Review
Quoted 2 lines · Rajendra Nayak
(quoted diff) +2
-0+ if (!dev) + return NULL;So how do we handle CPUs? cpufreq is one of the most active users of regulators...
Quoted 4 lines
Hmm, never thought of it :(
Maybe I should associate a supply name with all regulators and then lookup from the global registered list.
I'm not sure how this should work in a device tree world, I'd *hope* we'd get a device tree node for the CPU and could then just make this a regular consumer thing but then the cpufreq drivers would need to be updated to make use of it. The only reason we allow null devices right now is the fact that cpufreq doesn't have a struct device it can use.
Quoted 10 lines
Quoted 7 lines
drivers/regulator/of_regulator.c line 44
Quoted 5 lines
drivers/regulator/of_regulator.c +5
-0+snprintf (prop_name,32 ,"%s-supply" , supply); + + prop =of_get_property (dev->of_node, prop_name,&sz); +if (!prop || sz<4 ) +return NULL ;sz< 4? Magic! :)
Its the valid phandle size.
I guess I need a sz != 4
I think we need an of_get_phandle(), it'd be clearer what the check is, more type safe and would avoid needing to replicate the check.
PATCH 8/9 regulator: helper to extract regulator node based on supply name
Quoted 15 lines · Mark Brown
Quoted 9 lines · Rajendra Nayak
Quoted 7 lines · Mark Brown
Review
Quoted 2 lines · Rajendra Nayak
(quoted diff) +2
-0+ if (!dev) + return NULL;So how do we handle CPUs? cpufreq is one of the most active users of regulators...
Quoted 4 lines
Hmm, never thought of it :(
Maybe I should associate a supply name with all regulators and then lookup from the global registered list.
Quoted 5 lines
I'm not sure how this should work in a device tree world, I'd *hope* we'd get a device tree node for the CPU and could then just make this a regular consumer thing but then the cpufreq drivers would need to be updated to make use of it. The only reason we allow null devices right now is the fact that cpufreq doesn't have a struct device it can use.
That's why we do have a MPU node in OMAP dts, in order to build an omap_device that will be mainly used for the DVFS on the MPU.
And even before DT migration, we used to build statically some omap_device to represent the various processors in the system (MPU, DSP, CortexM3...).
Regards,
Benoit
PATCH 8/9 regulator: helper to extract regulator node based on supply name
Quoted 22 lines · Benoit
Quoted 15 lines · Mark Brown
Quoted 6 lines · Rajendra Nayak
Quoted 4 lines · Mark Brown
Quoted 2 lines · Rajendra Nayak
+ if (!dev)
+ return NULL;Quoted 7 lines
Quoted 2 lines
So how do we handle CPUs? cpufreq is one of the most active users of regulators...
Hmm, never thought of it :(
Maybe I should associate a supply name with all regulators and then lookup from the global registered list.Quoted 5 lines
I'm not sure how this should work in a device tree world, I'd *hope* we'd get a device tree node for the CPU and could then just make this a regular consumer thing but then the cpufreq drivers would need to be updated to make use of it. The only reason we allow null devices right now is the fact that cpufreq doesn't have a struct device it can use.
Quoted 6 lines
That's why we do have a MPU node in OMAP dts, in order to build an
omap_devicethat will be mainly used for the DVFS on the MPU.And even before DT migration, we used to build statically some
omap_deviceto represent the various processors in the system (MPU, DSP, CortexM3...).
yes, but clearly not everyone seems to do this. and then there are also these instances of board files requesting regulators without associating them with any device :(
Quoted 3 lines
Regards,
Benoit
PATCH 8/9 regulator: helper to extract regulator node based on supply name
In reply to Cousson, BenoitQuoted 8 lines · Benoit
Quoted 5 lines · Mark Brown
I'm not sure how this should work in a device tree world, I'd *hope* we'd get a device tree node for the CPU and could then just make this a regular consumer thing but then the cpufreq drivers would need to be updated to make use of it. The only reason we allow null devices right now is the fact that cpufreq doesn't have a struct device it can use.
Quoted 6 lines
That's why we do have a MPU node in OMAP dts, in order to build an
omap_devicethat will be mainly used for the DVFS on the MPU.And even before DT migration, we used to build statically some
omap_deviceto represent the various processors in the system (MPU, DSP, CortexM3...).
Yeah, but that's very OMAP specific - we don't have that in general (in fact it's the only Linux platform I'm aware of that has a device for the CPU).
PATCH 8/9 regulator: helper to extract regulator node based on supply name
Quoted 12 lines · Mark Brown
Quoted 10 lines · Benoit
Quoted 5 lines · Mark Brown
I'm not sure how this should work in a device tree world, I'd *hope* we'd get a device tree node for the CPU and could then just make this a regular consumer thing but then the cpufreq drivers would need to be updated to make use of it. The only reason we allow null devices right now is the fact that cpufreq doesn't have a struct device it can use.
That's why we do have a MPU node in OMAP dts, in order to build an
omap_devicethat will be mainly used for the DVFS on the MPU.
Quoted 7 lines
Quoted 3 lines
And even before DT migration, we used to build statically some
omap_deviceto represent the various processors in the system (MPU, DSP, CortexM3...).Yeah, but that's very OMAP specific - we don't have that in general (in fact it's the only Linux platform I'm aware of that has a device for the CPU).
But isn't this the right thing to do for everyone else too?
PATCH 8/9 regulator: helper to extract regulator node based on supply name
Quoted 7 lines · Rajendra Nayak
Quoted 5 lines · Mark Brown
Quoted 3 lines · Benoit
And even before DT migration, we used to build statically some
omap_deviceto represent the various processors in the system (MPU, DSP, CortexM3...).
Quoted 5 lines
Quoted 3 lines
Yeah, but that's very OMAP specific - we don't have that in general (in fact it's the only Linux platform I'm aware of that has a device for the CPU).
But isn't this the right thing to do for everyone else too?
That doesn't really matter so long as nobody else is actually doing it; you can't make a decision like this in an OMAP-specific fashion, you need to make sure everyone else is on board with the decision and make sure we've got at least at a high level way of representing the CPUs and SoCs in the device tree that people can buy into.
PATCH 8/9 regulator: helper to extract regulator node based on supply name
In reply to Rajendra NayakQuoted 17 lines · Rajendra Nayak
Quoted 16 lines · Mark Brown
Quoted 14 lines · Benoit
Quoted 5 lines · Mark Brown
I'm not sure how this should work in a device tree world, I'd *hope* we'd get a device tree node for the CPU and could then just make this a regular consumer thing but then the cpufreq drivers would need to be updated to make use of it. The only reason we allow null devices right now is the fact that cpufreq doesn't have a struct device it can use.
That's why we do have a MPU node in OMAP dts, in order to build an
omap_devicethat will be mainly used for the DVFS on the MPU.And even before DT migration, we used to build statically some
omap_deviceto represent the various processors in the system (MPU, DSP, CortexM3...).
Quoted 6 lines
Quoted 3 lines
Yeah, but that's very OMAP specific - we don't have that in general (in fact it's the only Linux platform I'm aware of that has a device for the CPU).
But isn't this the right thing to do for everyone else too?
It is normal to have nodes for each CPU. The /cpus/ node normally contains cpu@* nodes for each logical cpu core, and I would expect nodes for each additional DSP and MPU core. Whether or not they belong in the /cpus/ node is a matter of design (we don't have any patterns for that yet).
g.
PATCH 8/9 regulator: helper to extract regulator node based on supply name
In reply to Mark BrownQuoted 29 lines · Mark Brown
Quoted 9 lines · Rajendra Nayak
Quoted 7 lines · Mark Brown
Review
Quoted 2 lines · Rajendra Nayak
(quoted diff) +2
-0+ if (!dev) + return NULL;So how do we handle CPUs? cpufreq is one of the most active users of regulators...
Quoted 4 lines
Hmm, never thought of it :(
Maybe I should associate a supply name with all regulators and then lookup from the global registered list.I'm not sure how this should work in a device tree world, I'd *hope* we'd get a device tree node for the CPU and could then just make this a regular consumer thing but then the cpufreq drivers would need to be updated to make use of it. The only reason we allow null devices right now is the fact that cpufreq doesn't have a struct device it can use.
Quoted 7 lines
Quoted 7 lines
drivers/regulator/of_regulator.c line 44
Quoted 5 lines
drivers/regulator/of_regulator.c +5
-0+snprintf (prop_name,32 ,"%s-supply" , supply); + + prop =of_get_property (dev->of_node, prop_name,&sz); +if (!prop || sz<4 ) +return NULL ;sz< 4? Magic! :)
Quoted 5 lines
Quoted 2 lines
Its the valid phandle size.
I guess I need a sz != 4I think we need an
of_get_phandle(), it'd be clearer what the check is, more type safe and would avoid needing to replicate the check.
Yes, there already seems to be one, of_parse_phandle() which I should have used. thanks.
PATCH 8/9 regulator: helper to extract regulator node based on supply name
In reply to Rajendra NayakQuoted 54 lines · Rajendra Nayak
Device nodes in DT can associate themselves with one or more regulators 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.Signed-off-by Rajendra Nayak <[email protected]>--- drivers/regulator/of_regulator.c | 39 ++++++++++++++++++++++++++++++++ include/linux/regulator/of_regulator.h | 7 +++++ 2 files changed, 46 insertions(+), 0 deletions(-)drivers/regulator/of_regulator.c +21
-0@@ -14,6 +14,45 @@#include <linux/of.h> #include <linux/regulator/machine.h> + +/** +* 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 ; +u32 reghandle; +char prop_name[32 ];/* 32 is max size of property name */ +const void *prop; +int sz; + +if (!dev) +return NULL ; +
drivers/regulator/of_regulator.c line 47
Quoted 10 lines
drivers/regulator/of_regulator.c +10
-0+dev_dbg (dev,"Looking up %s-supply from device tree\n" , supply); + +snprintf (prop_name,32 ,"%s-supply" , supply); + + prop =of_get_property (dev->of_node, prop_name, &sz); +if (!prop || sz <4 ) +return NULL ; + + reghandle =be32_to_cpup (prop); + regnode =of_find_node_by_phandle (reghandle);
of_parse_phandle()
Quoted 38 lines
drivers/regulator/of_regulator.c +8
-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; +} +static void of_get_regulation_constraints (struct device_node *np,struct regulator_init_data **init_data) {include/linux/regulator/of_regulator.h +7
-0@@ -9,12 +9,19 @@#if defined(CONFIG_OF_REGULATOR )extern struct regulator_init_data *of_get_regulator_init_data (struct device *dev); +extern struct device_node *of_get_regulator (struct device *dev, +const char *supply);#else static inline struct regulator_init_data *of_get_regulator_init_data (struct device_node *np) {return NULL ; } +static inline struct device_node *of_get_regulator (struct device *dev, +const char *id) +{ +return NULL ; +}#endif /* CONFIG_OF_REGULATOR */ #endif /* __LINUX_OF_REG_H */ Signature · 1 line
1.7.1
PATCH 9/9 regulator: map consumer regulator based on device tree
In reply to Rajendra NayakLook 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.
Devices can associate with one or more regulators by providing a list of phandles and supply names.
For Example:
devicenode: node at 0x0 {
...
...
vmmc-supply = <®ulator1>;
vpll-supply = <®ulator2>;
};When a device driver calls a regulator_get, specifying the supply name, the phandle and eventually the regulator node is extracted from the device node.
--- drivers/regulator/core.c | 14 ++++++++++++++ include/linux/regulator/driver.h | 3 +++ 2 files changed, 17 insertions(+), 0 deletions(-)
drivers/regulator/core.c +14 -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>
@@ -1155,6 +1157,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 +1170,15 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,mutex_lock (®ulator_list_mutex); +if (dev->of_node) { + node =of_get_regulator (dev, id); +if (!node) + goto retry;/* fallback and chk regulator_map_list */ +list_for_each_entry (rdev, ®ulator_list, list) +if (node == rdev->node) + goto found; + } +retry:list_for_each_entry (map, ®ulator_map_list, list) {/* If the mapping has a device set up it must match */ if (map->dev_name &&
@@ -2619,6 +2631,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, rdev->reg_data = driver_data; rdev->owner = regulator_desc->owner; rdev->desc = regulator_desc; +if (dev && dev->of_node) + rdev->node = dev->of_node;INIT_LIST_HEAD (&rdev->consumer_list);INIT_LIST_HEAD (&rdev->list);BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);
include/linux/regulator/driver.h +3 -0
@@ -196,6 +196,9 @@ struct regulator_dev {struct mutex mutex;/* consumer lock */ struct module *owner;struct device dev; +#ifdef CONFIG_OF +struct device_node *node; +#endif struct regulation_constraints *constraints;struct regulator *supply;/* for tree */
Signature · 1 line
1.7.1
PATCH 9/9 regulator: map consumer regulator based on device tree
Quoted 3 lines · Rajendra Nayak
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.
As with the fixed voltage regulator patch just use the code along with adding it, no need to split it just makes it harder to review.
drivers/regulator/core.c static struct regulator *_regulator_get(struct device *dev, const char *id, · line 1181
Quoted 9 lines
drivers/regulator/core.c +9
-0+if (dev->of_node) { + node =of_get_regulator (dev, id); +if (!node) + goto retry;/* fallback and chk regulator_map_list */ +list_for_each_entry (rdev, ®ulator_list, list) +if (node == rdev->node) + goto found; + } +retry:
retry is a confusing name for the target, we don't ever actually retry using it. Given the simplicity of the code I'd be inclined to just intert the if (!node) check.
PATCH 9/9 regulator: map consumer regulator based on device tree
Quoted 7 lines · Mark Brown
Quoted 3 lines · Rajendra Nayak
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.As with the fixed voltage regulator patch just use the code along with adding it, no need to split it just makes it harder to review.
Ok.
Quoted 14 lines
drivers/regulator/core.c static struct regulator *_regulator_get(struct device *dev, const char *id, · line 1181
Quoted 10 lines
drivers/regulator/core.c +9
-0+if (dev->of_node) { + node =of_get_regulator (dev, id); +if (!node) + goto retry;/* fallback and chk regulator_map_list */ +list_for_each_entry (rdev,®ulator_list, list) +if (node == rdev->node) + goto found; + } +retry:retry is a confusing name for the target, we don't ever actually retry using it. Given the simplicity of the code I'd be inclined to just intert the if (!node) check.
Ok.
PATCH 9/9 regulator: map consumer regulator based on device tree
In reply to Rajendra NayakQuoted 79 lines · Rajendra Nayak
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.Devices can associate with one or more regulators by providing a list of phandles and supply names.
For Example:
devicenode: node at 0x0 { ... ... vmmc-supply = <®ulator1>; vpll-supply = <®ulator2>; };When a device driver calls a
regulator_get, specifying the supply name, the phandle and eventually the regulator node is extracted from the device node.Signed-off-by Rajendra Nayak <[email protected]>--- drivers/regulator/core.c | 14 ++++++++++++++ include/linux/regulator/driver.h | 3 +++ 2 files changed, 17 insertions(+), 0 deletions(-)drivers/regulator/core.c +14
-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> @@ -1155,6 +1157,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 +1170,15 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,mutex_lock (®ulator_list_mutex); +if (dev->of_node) { + node =of_get_regulator (dev, id); +if (!node) + goto retry;/* fallback and chk regulator_map_list */ +list_for_each_entry (rdev, ®ulator_list, list) +if (node == rdev->node) + goto found; + } +retry:list_for_each_entry (map, ®ulator_map_list, list) {/* If the mapping has a device set up it must match */ if (map->dev_name &&@@ -2619,6 +2631,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, rdev->reg_data = driver_data; rdev->owner = regulator_desc->owner; rdev->desc = regulator_desc; +if (dev && dev->of_node) + rdev->node = dev->of_node;INIT_LIST_HEAD (&rdev->consumer_list);INIT_LIST_HEAD (&rdev->list);BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);include/linux/regulator/driver.h +0
-0
include/linux/regulator/driver.h struct regulator_dev { · line 201
Quoted 6 lines
include/linux/regulator/driver.h +3
-0@@ -196,6 +196,9 @@ struct regulator_dev {struct mutex mutex;/* consumer lock */ struct module *owner;struct device dev; +#ifdef CONFIG_OF +struct device_node *node; +#endif
There is already an of_node pointer in regulator_dev->dev.of_node. Why does another need to be added here?
g.
PATCH 9/9 regulator: map consumer regulator based on device tree
Quoted 81 lines · Grant Likely
Quoted 80 lines · Rajendra Nayak
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.Devices can associate with one or more regulators by providing a list of phandles and supply names.
For Example:
devicenode: node at 0x0 { ... ... vmmc-supply =<®ulator1>; vpll-supply =<®ulator2>; };When a device driver calls a
regulator_get, specifying the supply name, the phandle and eventually the regulator node is extracted from the device node.Signed-off-by Rajendra Nayak<[email protected]>--- drivers/regulator/core.c | 14 ++++++++++++++ include/linux/regulator/driver.h | 3 +++ 2 files changed, 17 insertions(+), 0 deletions(-)drivers/regulator/core.c +14
-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> @@ -1155,6 +1157,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 +1170,15 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,mutex_lock (®ulator_list_mutex); +if (dev->of_node) { + node =of_get_regulator (dev, id); +if (!node) + goto retry;/* fallback and chk regulator_map_list */ +list_for_each_entry (rdev,®ulator_list, list) +if (node == rdev->node) + goto found; + } +retry:list_for_each_entry (map,®ulator_map_list, list) {/* If the mapping has a device set up it must match */ if (map->dev_name&&@@ -2619,6 +2631,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, rdev->reg_data = driver_data; rdev->owner = regulator_desc->owner; rdev->desc = regulator_desc; +if (dev&& dev->of_node) + rdev->node = dev->of_node;INIT_LIST_HEAD (&rdev->consumer_list);INIT_LIST_HEAD (&rdev->list);BLOCKING_INIT_NOTIFIER_HEAD (&rdev->notifier);include/linux/regulator/driver.h +0
-0@@ -196,6 +196,9 @@ struct regulator_dev {struct mutex mutex;/* consumer lock */
Quoted 8 lines
include/linux/regulator/driver.h struct regulator_dev { · line 201
Quoted 5 lines
include/linux/regulator/driver.h +3
-0struct module *owner;struct device dev; +#ifdef CONFIG_OF +struct device_node *node; +#endif There is already an
of_nodepointer inregulator_dev->dev.of_node. Why does another need to be added here?
Yes, I guess it doesn't. Will remove it.
Thanks.
Quoted 3 lines
g.
cover Device tree support for regulators
In reply to Rajendra NayakQuoted 7 lines · Rajendra Nayak
Hi Mark, Grant,
This is a respin of my RFC series I posted sometime back and is now based on top of the latest omap i2c-twl support series posted by Benoit
git://gitorious.org/omap-pm/linux.gitfor_3.2/4_omap_dt_i2c_twl
Quoted 9 lines
some changes done since the RFC:
1. twl driver fixed to remove hardcoded board params
2. regulator helpers moved fromdrivers/oftodrivers/regulator
3. Better compatible definitions for specific device type
4. twl regulator driver doing internal table lookup based on compatible rather thenpdev->id
5. Seperate fixed voltage regulator bindings defined
6. Changed the way devices associate with regulators i.e using <name>-supply = <®ulator-phandle>;
Overall looks fairly good other than the comments made by Mark and myself.
g.