lp872x: remove platform_data based probing and adjustments
Subsystems (2)
cover lp872x: remove platform_data based probing and adjustments
Convert and upgrade schema. Consolidate driver file, remove platform_data based probing and add missing regulator/chip supplies.
Svyatoslav Ryhel (7):
regulator: dt-bindings: ti,lp872x: Convert to DT schema
regulator: dt-bindings: ti,lp872x: Document input supplies
regulator: lp872x: Fold driver header into driver file
regulator: lp872x: Remove redundant regmap wrappers
regulator: lp872x: Remove platform_data based probing
regulator: lp872x: Add support for input and regulator power supplies
regulator: lp872x: Use macro to fill regulator descriptor
.../devicetree/bindings/regulator/lp872x.txt | 161 ----- .../bindings/regulator/ti,lp8720.yaml | 244 +++++++ drivers/regulator/lp872x.c | 665 ++++++------------ include/linux/regulator/lp872x.h | 86 --- 4 files changed, 448 insertions(+), 708 deletions(-) delete mode 100644 Documentation/devicetree/bindings/regulator/lp872x.txt create mode 100644 Documentation/devicetree/bindings/regulator/ti,lp8720.yaml delete mode 100644 include/linux/regulator/lp872x.h
Signature · 1 line
2.53.0
PATCH 1/7 regulator: dt-bindings: ti,lp872x: Convert to DT schema
Convert TI LP872x regulator binding from text to DT schema.
--- .../devicetree/bindings/regulator/lp872x.txt | 161 ------------ .../bindings/regulator/ti,lp8720.yaml | 232 ++++++++++++++++++ 2 files changed, 232 insertions(+), 161 deletions(-) delete mode 100644 Documentation/devicetree/bindings/regulator/lp872x.txt create mode 100644 Documentation/devicetree/bindings/regulator/ti,lp8720.yaml
Documentation/devicetree/bindings/regulator/lp872x.txt deleted +0 -161
@@ -1,161 +0,0 @@ -Binding for TI/National Semiconductor LP872x Driver - -Required properties: - - compatible: "ti,lp8720" or "ti,lp8725" - - reg: I2C slave address. 0x7d = LP8720, 0x7a = LP8725 - -Optional properties: - - ti,general-config: the value of LP872X_GENERAL_CFG register (u8) - (LP8720) - bit[2]: BUCK output voltage control by external DVS pin or register - 1 = external pin, 0 = bit7 of register 08h - bit[1]: sleep control by external DVS pin or register - 1 = external pin, 0 = bit6 of register 08h - bit[0]: time step unit(usec). 1 = 25, 0 = 50 - - (LP8725) - bit[7:6]: time step unit(usec). 00 = 32, 01 = 64, 10 = 128, 11 = 256 - bit[4]: BUCK2 enable control. 1 = enable, 0 = disable - bit[3]: BUCK2 output voltage register address. 1 = 0Ah, 0 = 0Bh - bit[2]: BUCK1 output voltage control by external DVS pin or register - 1 = register 08h, 0 = DVS - bit[1]: LDO sleep control. 1 = sleep mode, 0 = normal - bit[0]: BUCK1 enable control, 1 = enable, 0 = disable - - For more details, please see the datasheet. - - - ti,update-config: define it when LP872X_GENERAL_CFG register should be set - - ti,dvs-gpio: GPIO specifier for external DVS pin control of LP872x devices. - - ti,dvs-vsel: DVS selector. 0 = SEL_V1, 1 = SEL_V2. - - ti,dvs-state: initial DVS pin state. 0 = DVS_LOW, 1 = DVS_HIGH. - - enable-gpios: GPIO specifier for EN pin control of LP872x devices. - - Sub nodes for regulator_init_data - LP8720 has maximum 6 nodes. (child name: ldo1 ~ 5 and buck) - LP8725 has maximum 9 nodes. (child name: ldo1 ~ 5, lilo1,2 and buck1,2) - For more details, please see the following binding document. - (Documentation/devicetree/bindings/regulator/regulator.txt) - -Datasheet - - LP8720: https://www.ti.com/lit/ds/symlink/lp8720.pdf - - LP8725: https://www.ti.com/lit/ds/symlink/lp8725.pdf - -Example 1) LP8720 - -lp8720@7d { - compatible = "ti,lp8720"; - reg = <0x7d>; - - /* external DVS pin used, timestep is 25usec */ - ti,general-config = /bits/ 8 <0x03>; - ti,update-config; - - /* - * The dvs-gpio depends on the processor environment. - * For example, following GPIO specifier means GPIO134 in OMAP4. - */ - ti,dvs-gpio = <&gpio5 6 0>; - ti,dvs-vsel = /bits/ 8 <1>; /* SEL_V2 */ - ti,dvs-state = /bits/ 8 <1>; /* DVS_HIGH */ - - vaf: ldo1 { - regulator-min-microvolt = <1200000>; - regulator-max-microvolt = <3300000>; - }; - - vmmc: ldo2 { - regulator-min-microvolt = <1200000>; - regulator-max-microvolt = <3300000>; - }; - - vcam_io: ldo3 { - regulator-min-microvolt = <1200000>; - regulator-max-microvolt = <3300000>; - regulator-boot-on; - }; - - vcam_core: ldo4 { - regulator-min-microvolt = <800000>; - regulator-max-microvolt = <2850000>; - regulator-boot-on; - }; - - vcam: ldo5 { - regulator-min-microvolt = <1200000>; - regulator-max-microvolt = <3300000>; - }; - - vcc: buck { - regulator-name = "VBUCK"; - regulator-min-microvolt = <800000>; - regulator-max-microvolt = <2300000>; - }; -}; - -Example 2) LP8725 - -lp8725@7a { - compatible = "ti,lp8725"; - reg = <0x7a>; - - /* Enable BUCK1,2, no DVS, normal LDO mode, timestep is 256usec */ - ti,general-config = /bits/ 8 <0xdd>; - ti,update-config; - - vcam_io: ldo1 { - regulator-min-microvolt = <1200000>; - regulator-max-microvolt = <3300000>; - }; - - vcam_core: ldo2 { - regulator-min-microvolt = <1200000>; - regulator-max-microvolt = <3300000>; - }; - - vcam: ldo3 { - regulator-min-microvolt = <1200000>; - regulator-max-microvolt = <3300000>; - }; - - vcmmb_io: ldo4 { - regulator-min-microvolt = <1200000>; - regulator-max-microvolt = <3300000>; - regulator-boot-on; - }; - - vcmmb_core: ldo5 { - regulator-min-microvolt = <1200000>; - regulator-max-microvolt = <3300000>; - regulator-boot-on; - }; - - vaux1: lilo1 { - regulator-name = "VAUX1"; - regulator-min-microvolt = <800000>; - regulator-max-microvolt = <3300000>; - }; - - vaux2: lilo2 { - regulator-name = "VAUX2"; - regulator-min-microvolt = <800000>; - regulator-max-microvolt = <3300000>; - }; - - vcc1: buck1 { - regulator-name = "VBUCK1"; - regulator-min-microvolt = <800000>; - regulator-max-microvolt = <3000000>; - regulator-min-microamp = <460000>; - regulator-max-microamp = <1370000>; - regulator-boot-on; - }; - - vcc2: buck2 { - regulator-name = "VBUCK2"; - regulator-min-microvolt = <800000>; - regulator-max-microvolt = <3000000>; - regulator-min-microamp = <460000>; - regulator-max-microamp = <1370000>; - regulator-boot-on; - }; -};
Documentation/devicetree/bindings/regulator/ti,lp8720.yaml new file +232 -0
232 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v1 1/7] regulator: dt-bindings: ti,lp872x: Convert to DT schema
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] dt-bindings: ti,lp872x: ABI breakage by renaming ti,dvs-gpio --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] dt-bindings: ti,lp872x: ABI breakage by renaming ti,dvs-gpio --
commit c03dfe1db500df8cb1f0e6fb4b50fc47567114c6
Author: Svyatoslav Ryhel <[email protected]>
regulator: dt-bindings: ti,lp872x: Convert to DT schema
Convert TI LP872x regulator binding from text to DT schema.
Quoted 6 lines
Documentation/devicetree/bindings/regulator/lp872x.txt deleted +0
-0@@ -1,161 +0,0 @@
[ ... ]
Quoted 2 lines
Documentation/devicetree/bindings/regulator/lp872x.txt deleted +0
-2-Optional properties: - - ti,general-config: the value of LP872X_GENERAL_CFG register (u8)
[ ... ]
Quoted 4 lines
Documentation/devicetree/bindings/regulator/lp872x.txt deleted +0
-4- - ti,update-config: define it when LP872X_GENERAL_CFG register should be set - - ti,dvs-gpio: GPIO specifier for external DVS pin control of LP872x devices. - - ti,dvs-vsel: DVS selector. 0 = SEL_V1, 1 = SEL_V2. - - ti,dvs-state: initial DVS pin state. 0 = DVS_LOW, 1 = DVS_HIGH.
[ ... ]
Quoted 6 lines
Documentation/devicetree/bindings/regulator/ti,lp8720.yaml new file +0
-0@@ -0,0 +1,232 @@
[ ... ]
Documentation/devicetree/bindings/regulator/ti,lp8720.yaml line 38
Quoted 6 lines
Documentation/devicetree/bindings/regulator/ti,lp8720.yaml new file +6
-0+ enable-gpios: + description: GPIO specifier for EN pin control. + maxItems: 1 + + dvs-gpios: + description: GPIO specifier for external DVS pin control.
[Severity: Critical]
Does renaming ti,dvs-gpio to dvs-gpios cause a regression for existing device trees?
The original text binding specifies ti,dvs-gpio for DVS pin control, but the new YAML schema renames it to dvs-gpios and uses additionalProperties: false. Existing valid device trees using ti,dvs-gpio will fail schema validation.
Furthermore, looking at lp872x_init_dvs() in drivers/regulator/lp872x.c, when the driver is updated to use devm_gpiod_get_optional(dev, "dvs", ...) instead of the legacy ti,dvs connection ID, it will only look for dvs-gpios or dvs-gpio. The driver will silently ignore the legacy ti,dvs-gpio property, breaking DVS functionality for existing hardware unless explicit fallback logic is provided.
Should the schema retain ti,dvs-gpio as a deprecated property or support both names to maintain backward compatibility?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/7 regulator: dt-bindings: ti,lp872x: Document input supplies
In reply to Svyatoslav RyhelDocument input supplies of TI LP8720 and LP8725.
--- .../devicetree/bindings/regulator/ti,lp8720.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/regulator/ti,lp8720.yaml +12 -0
@@ -74,6 +74,16 @@ properties: description: Initial DVS pin state. 0 = DVS_LOW, 1 = DVS_HIGH. patternProperties: + "^(vbatt|vin([1-3]|b|lilo[1-2]))-supply$": + $ref: /schemas/types.yaml#/definitions/phandle + description: | + vbatt - input supply for ldo1 and all internal circuitry (lp8720 only). + vin1 - input supply for ldo2 - ldo3 (lp8720) or ldo1 (lp8725). + vin2 - input supply for ldo4 - ldo5 (lp8720) or ldo2 - ldo3 (lp8725). + vin3 - input supply for ldo4 - ldo5 (lp8725). + vinb - input supply for buck. + vinlilo1 and vinlilo2 - input supply for lilo1 and lilo2. + "^(buck|buck[1-2]|ldo[1-5]|lilo[1-2])$": $ref: /schemas/regulator/regulator.yaml# unevaluatedProperties: false
@@ -86,6 +96,7 @@ allOf: const: ti,lp8720 then: patternProperties: + "^(vin(3|lilo[1-2]))-supply$": false "^(buck[1-2]|lilo[1-2])$": false - if:
@@ -95,6 +106,7 @@ allOf: const: ti,lp8725 then: properties: + vbatt-supply: false buck: false required:
Signature · 1 line
2.53.0
PATCH 3/7 regulator: lp872x: Fold driver header into driver file
In reply to Svyatoslav RyhelRemove need in header file in preparation for pdata probing removal.
--- drivers/regulator/lp872x.c | 54 +++++++++++++++++++- include/linux/regulator/lp872x.h | 86 -------------------------------- 2 files changed, 53 insertions(+), 87 deletions(-) delete mode 100644 include/linux/regulator/lp872x.h
drivers/regulator/lp872x.c +53 -1
@@ -12,10 +12,10 @@#include <linux/err.h> #include <linux/gpio/consumer.h> #include <linux/delay.h> -#include <linux/regulator/lp872x.h> #include <linux/regulator/driver.h> #include <linux/platform_device.h> #include <linux/of.h> +#include <linux/regulator/machine.h> #include <linux/regulator/of_regulator.h> /* Registers : LP8720/8725 shared */
@@ -92,11 +92,63 @@/* dump registers in regmap-debugfs */ #define MAX_REGISTERS 0x0F +#define LP872X_MAX_REGULATORS 9 + +#define LP8720_ENABLE_DELAY 200 +#define LP8725_ENABLE_DELAY 30000 +enum lp872x_id {LP8720 ,LP8725 , }; +enum lp872x_regulator_id { +LP8720_ID_BASE , +LP8720_ID_LDO1 =LP8720_ID_BASE , +LP8720_ID_LDO2 , +LP8720_ID_LDO3 , +LP8720_ID_LDO4 , +LP8720_ID_LDO5 , +LP8720_ID_BUCK , + +LP8725_ID_BASE , +LP8725_ID_LDO1 =LP8725_ID_BASE , +LP8725_ID_LDO2 , +LP8725_ID_LDO3 , +LP8725_ID_LDO4 , +LP8725_ID_LDO5 , +LP8725_ID_LILO1 , +LP8725_ID_LILO2 , +LP8725_ID_BUCK1 , +LP8725_ID_BUCK2 , + +LP872X_ID_MAX , +}; + +enum lp872x_dvs_sel { +SEL_V1 , +SEL_V2 , +}; + +struct lp872x_dvs { +struct gpio_desc *gpio; +enum lp872x_dvs_sel vsel; +enum gpiod_flags init_state; +}; + +struct lp872x_regulator_data { +enum lp872x_regulator_id id; +struct regulator_init_data *init_data; +}; + +struct lp872x_platform_data { +u8 general_config; +bool update_config; +struct lp872x_regulator_data regulator_data[LP872X_MAX_REGULATORS ]; +struct lp872x_dvs *dvs; +struct gpio_desc *enable_gpio; +}; +struct lp872x {struct regmap *regmap;struct device *dev;
include/linux/regulator/lp872x.h deleted +0 -86
86 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 4/7 regulator: lp872x: Remove redundant regmap wrappers
In reply to Svyatoslav RyhelRemove lp872x_read_byte(), lp872x_write_byte(), and lp872x_update_bits() helpers which are just wrappers around the same regmap helpers.
--- drivers/regulator/lp872x.c | 66 ++++++++++++-------------------------- 1 file changed, 20 insertions(+), 46 deletions(-)
drivers/regulator/lp872x.c +20 -46
@@ -204,36 +204,10 @@ static const unsigned int lp8725_buck_uA[] = { 460000, 780000, 1050000, 1370000, }; -static int lp872x_read_byte (struct lp872x *lp,u8 addr,u8 *data) -{ -int ret; -unsigned int val; - - ret =regmap_read (lp->regmap, addr, &val); -if (ret <0 ) { -dev_err (lp->dev,"failed to read 0x%.2x\n" , addr); -return ret; - } - - *data = (u8 )val; -return 0 ; -} - -static inline int lp872x_write_byte (struct lp872x *lp,u8 addr,u8 data) -{ -return regmap_write (lp->regmap, addr, data); -} - -static inline int lp872x_update_bits (struct lp872x *lp,u8 addr, -unsigned int mask,u8 data) -{ -return regmap_update_bits (lp->regmap, addr, mask, data); -} -static int lp872x_get_timestep_usec (struct lp872x *lp) {enum lp872x_id chip = lp->chipid; -u8 val, mask, shift; +u32 val, mask, shift;int *time_usec, size, ret;int lp8720_time_usec[] = {25 ,50 };int lp8725_time_usec[] = {32 ,64 ,128 ,256 };
@@ -255,7 +229,7 @@ static int lp872x_get_timestep_usec(struct lp872x *lp)return -EINVAL ; } - ret =lp872x_read_byte (lp,LP872X_GENERAL_CFG , &val); + ret =regmap_read (lp->regmap,LP872X_GENERAL_CFG , &val);if (ret)return ret;
@@ -272,7 +246,7 @@ static int lp872x_regulator_enable_time(struct regulator_dev *rdev)enum lp872x_regulator_id rid =rdev_get_id (rdev);int time_step_us =lp872x_get_timestep_usec (lp);int ret; -u8 addr, val; +u32 addr, val;if (time_step_us <0 )return time_step_us;
@@ -291,7 +265,7 @@ static int lp872x_regulator_enable_time(struct regulator_dev *rdev)return -EINVAL ; } - ret =lp872x_read_byte (lp, addr, &val); + ret =regmap_read (lp->regmap, addr, &val);if (ret)return ret;
@@ -313,9 +287,9 @@ static void lp872x_set_dvs(struct lp872x *lp, enum lp872x_dvs_sel dvs_sel,static u8 lp872x_select_buck_vout_addr (struct lp872x *lp,enum lp872x_regulator_id buck) { -u8 val, addr; +u32 val, addr; -if (lp872x_read_byte (lp,LP872X_GENERAL_CFG , &val)) +if (regmap_read (lp->regmap,LP872X_GENERAL_CFG , &val))return 0 ;switch (buck) {
@@ -324,7 +298,7 @@ static u8 lp872x_select_buck_vout_addr(struct lp872x *lp, addr = (lp->dvs_pin ==GPIOD_OUT_HIGH ) ?LP8720_BUCK_VOUT1 :LP8720_BUCK_VOUT2 ; }else { -if (lp872x_read_byte (lp,LP8720_ENABLE , &val)) +if (regmap_read (lp->regmap,LP8720_ENABLE , &val))return 0 ; addr = val & LP8720_DVS_SEL_M ?
@@ -369,7 +343,7 @@ static int lp872x_buck_set_voltage_sel(struct regulator_dev *rdev, {struct lp872x *lp =rdev_get_drvdata (rdev);enum lp872x_regulator_id buck =rdev_get_id (rdev); -u8 addr, mask =LP872X_VOUT_M ; +u32 addr, mask =LP872X_VOUT_M ;struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs :NULL ;if (dvs && dvs->gpio)
@@ -379,21 +353,21 @@ static int lp872x_buck_set_voltage_sel(struct regulator_dev *rdev,if (!lp872x_is_valid_buck_addr (addr))return -EINVAL ; -return lp872x_update_bits (lp, addr, mask, selector); +return regmap_update_bits (lp->regmap, addr, mask, selector); }static int lp872x_buck_get_voltage_sel (struct regulator_dev *rdev) {struct lp872x *lp =rdev_get_drvdata (rdev);enum lp872x_regulator_id buck =rdev_get_id (rdev); -u8 addr, val; +u32 addr, val;int ret; addr =lp872x_select_buck_vout_addr (lp, buck);if (!lp872x_is_valid_buck_addr (addr))return -EINVAL ; - ret =lp872x_read_byte (lp, addr, &val); + ret =regmap_read (lp->regmap, addr, &val);if (ret)return ret;
@@ -404,7 +378,7 @@ static int lp872x_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) {struct lp872x *lp =rdev_get_drvdata (rdev);enum lp872x_regulator_id buck =rdev_get_id (rdev); -u8 addr, mask, shift, val; +u32 addr, mask, shift, val;switch (buck) {case LP8720_ID_BUCK :
@@ -433,14 +407,14 @@ static int lp872x_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)else return -EINVAL ; -return lp872x_update_bits (lp, addr, mask, val); +return regmap_update_bits (lp->regmap, addr, mask, val); }static unsigned int lp872x_buck_get_mode (struct regulator_dev *rdev) {struct lp872x *lp =rdev_get_drvdata (rdev);enum lp872x_regulator_id buck =rdev_get_id (rdev); -u8 addr, mask, val; +u32 addr, mask, val;int ret;switch (buck) {
@@ -460,7 +434,7 @@ static unsigned int lp872x_buck_get_mode(struct regulator_dev *rdev)return -EINVAL ; } - ret =lp872x_read_byte (lp, addr, &val); + ret =regmap_read (lp->regmap, addr, &val);if (ret)return ret;
@@ -728,8 +702,8 @@ static int lp872x_init_dvs(struct lp872x *lp) {struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs :NULL ;enum gpiod_flags pinstate; -u8 mask[] = {LP8720_EXT_DVS_M ,LP8725_DVS1_M |LP8725_DVS2_M }; -u8 default_dvs_mode[] = {LP8720_DEFAULT_DVS ,LP8725_DEFAULT_DVS }; +u32 mask[] = {LP8720_EXT_DVS_M ,LP8725_DVS1_M |LP8725_DVS2_M }; +u32 default_dvs_mode[] = {LP8720_DEFAULT_DVS ,LP8725_DEFAULT_DVS };if (!dvs) goto set_default_dvs_mode;
@@ -750,8 +724,8 @@ static int lp872x_init_dvs(struct lp872x *lp)return 0 ; set_default_dvs_mode: -return lp872x_update_bits (lp,LP872X_GENERAL_CFG , mask[lp->chipid], - default_dvs_mode[lp->chipid]); +return regmap_update_bits (lp->regmap,LP872X_GENERAL_CFG , mask[lp->chipid], + default_dvs_mode[lp->chipid]); }static int lp872x_hw_enable (struct lp872x *lp)
@@ -786,7 +760,7 @@ static int lp872x_config(struct lp872x *lp)if (!pdata || !pdata->update_config) goto init_dvs; - ret =lp872x_write_byte (lp,LP872X_GENERAL_CFG , pdata->general_config); + ret =regmap_write (lp->regmap,LP872X_GENERAL_CFG , pdata->general_config);if (ret)return ret;
Signature · 1 line
2.53.0
PATCH 5/7 regulator: lp872x: Remove platform_data based probing
In reply to Svyatoslav RyhelThe platform_data-based probing is tightly integrated into the lp872x driver structure itself; removing just the platform data support is impossible without remodeling major parts of the probe sequence.
The lp872x_platform_data structure was removed, and its contents were incorporated into the driver private structure and lp872x_chip_info (which holds differences between the LP8720 and LP8725). The lp872x_populate_pdata_from_dt() helper was removed: general Device Tree parsing code was integrated directly into the probe function, and DVS-related code was consolidated into lp872x_init_dvs(). lp872x_hw_enable() and lp872x_config() helpers were folded into probe(). i2c_client_get_device_id() was switched to i2c_get_match_data(). Finally, of_regulator_match structures were dropped, and lp872x_regulator_register() was upgraded to rely on the core regulator registration framework.
--- drivers/regulator/lp872x.c | 320 ++++++++++--------------------------- 1 file changed, 84 insertions(+), 236 deletions(-)
drivers/regulator/lp872x.c +84 -236
@@ -14,7 +14,7 @@#include <linux/delay.h> #include <linux/regulator/driver.h> #include <linux/platform_device.h> -#include <linux/of.h> +#include <linux/property.h> #include <linux/regulator/machine.h> #include <linux/regulator/of_regulator.h>
@@ -92,8 +92,6 @@/* dump registers in regmap-debugfs */ #define MAX_REGISTERS 0x0F -#define LP872X_MAX_REGULATORS 9 -#define LP8720_ENABLE_DELAY 200#define LP8725_ENABLE_DELAY 30000
@@ -130,31 +128,22 @@ enum lp872x_dvs_sel { SEL_V2, }; -struct lp872x_dvs { -struct gpio_desc *gpio; -enum lp872x_dvs_sel vsel; -enum gpiod_flags init_state; -}; - -struct lp872x_regulator_data { -enum lp872x_regulator_id id; -struct regulator_init_data *init_data; -}; - -struct lp872x_platform_data { -u8 general_config; -bool update_config; -struct lp872x_regulator_data regulator_data[LP872X_MAX_REGULATORS ]; -struct lp872x_dvs *dvs; -struct gpio_desc *enable_gpio; +struct lp872x_chip_info { +const struct regulator_desc *rdesc; +int num_regulators; +enum lp872x_id chipid; };struct lp872x {struct regmap *regmap;struct device *dev; -enum lp872x_id chipid; -struct lp872x_platform_data *pdata; -int num_regulators; + +struct gpio_desc *enable_gpio; +struct gpio_desc *dvs_gpio; + +const struct lp872x_chip_info *info; + +enum lp872x_dvs_sel vsel;enum gpiod_flags dvs_pin; };
@@ -206,7 +195,7 @@ static const unsigned int lp8725_buck_uA[] = {static int lp872x_get_timestep_usec (struct lp872x *lp) { -enum lp872x_id chip = lp->chipid; +enum lp872x_id chip = lp->info->chipid;u32 val, mask, shift;int *time_usec, size, ret;int lp8720_time_usec[] = {25 ,50 };
@@ -344,10 +333,9 @@ static int lp872x_buck_set_voltage_sel(struct regulator_dev *rdev,struct lp872x *lp =rdev_get_drvdata (rdev);enum lp872x_regulator_id buck =rdev_get_id (rdev);u32 addr, mask =LP872X_VOUT_M ; -struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs :NULL ; -if (dvs && dvs->gpio) -lp872x_set_dvs (lp, dvs->vsel, dvs->gpio); +if (lp->dvs_gpio) +lp872x_set_dvs (lp, lp->vsel, lp->dvs_gpio); addr =lp872x_select_buck_vout_addr (lp, buck);if (!lp872x_is_valid_buck_addr (addr))
@@ -700,110 +688,45 @@ static const struct regulator_desc lp8725_regulator_desc[] = {static int lp872x_init_dvs (struct lp872x *lp) { -struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs :NULL ; -enum gpiod_flags pinstate; +struct device *dev = lp->dev;u32 mask[] = {LP8720_EXT_DVS_M ,LP8725_DVS1_M |LP8725_DVS2_M };u32 default_dvs_mode[] = {LP8720_DEFAULT_DVS ,LP8725_DEFAULT_DVS }; +u8 dvs_state; -if (!dvs) - goto set_default_dvs_mode; - -if (!dvs->gpio) - goto set_default_dvs_mode; - - pinstate = dvs->init_state; - dvs->gpio =devm_gpiod_get_optional (lp->dev,"ti,dvs" , pinstate); - -if (IS_ERR (dvs->gpio)) { -dev_err (lp->dev,"gpio request err: %ld\n" ,PTR_ERR (dvs->gpio)); -return PTR_ERR (dvs->gpio); - } - - lp->dvs_pin = pinstate; - -return 0 ; - -set_default_dvs_mode: -return regmap_update_bits (lp->regmap,LP872X_GENERAL_CFG , mask[lp->chipid], - default_dvs_mode[lp->chipid]); -} - -static int lp872x_hw_enable (struct lp872x *lp) -{ -if (!lp->pdata) -return -EINVAL ; - -if (!lp->pdata->enable_gpio) -return 0 ; +device_property_read_u8 (dev,"ti,dvs-vsel" , (u8 *)&lp->vsel); +device_property_read_u8 (dev,"ti,dvs-state" , &dvs_state); + lp->dvs_pin = dvs_state ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; -/* Always set enable GPIO high. */ - lp->pdata->enable_gpio =devm_gpiod_get_optional (lp->dev,"enable" ,GPIOD_OUT_HIGH ); -if (IS_ERR (lp->pdata->enable_gpio)) { -dev_err (lp->dev,"gpio request err: %ld\n" ,PTR_ERR (lp->pdata->enable_gpio)); -return PTR_ERR (lp->pdata->enable_gpio); + lp->dvs_gpio =devm_gpiod_get_optional (dev,"dvs" , lp->dvs_pin); +if (IS_ERR (lp->dvs_gpio)) { +dev_err (dev,"gpio request err: %ld\n" ,PTR_ERR (lp->dvs_gpio)); +return PTR_ERR (lp->dvs_gpio); } -/* Each chip has a different enable delay. */ -if (lp->chipid ==LP8720 ) -usleep_range (LP8720_ENABLE_DELAY ,1.5 *LP8720_ENABLE_DELAY ); -else -usleep_range (LP8725_ENABLE_DELAY ,1.5 *LP8725_ENABLE_DELAY ); +if (!lp->dvs_gpio) +return regmap_update_bits (lp->regmap,LP872X_GENERAL_CFG , + mask[lp->info->chipid], + default_dvs_mode[lp->info->chipid]);return 0 ; } -static int lp872x_config (struct lp872x *lp) -{ -struct lp872x_platform_data *pdata = lp->pdata; -int ret; - -if (!pdata || !pdata->update_config) - goto init_dvs; - - ret =regmap_write (lp->regmap,LP872X_GENERAL_CFG , pdata->general_config); -if (ret) -return ret; - -init_dvs: -return lp872x_init_dvs (lp); -} - -static struct regulator_init_data -*lp872x_find_regulator_init_data (int id,struct lp872x *lp) -{ -struct lp872x_platform_data *pdata = lp->pdata; -int i; - -if (!pdata) -return NULL ; - -for (i =0 ; i < lp->num_regulators; i++) { -if (pdata->regulator_data[i].id == id) -return pdata->regulator_data[i].init_data; - } - -return NULL ; -} -static int lp872x_regulator_register (struct lp872x *lp) { -const struct regulator_desc *desc; +const struct regulator_desc *desc = lp->info->rdesc; +int num_regulators = lp->info->num_regulators;struct regulator_config cfg = { }; +struct device *dev = lp->dev;struct regulator_dev *rdev; -int i; - -for (i =0 ; i < lp->num_regulators; i++) { - desc = (lp->chipid ==LP8720 ) ? &lp8720_regulator_desc[i] : - &lp8725_regulator_desc[i]; - cfg.dev = lp->dev; - cfg.init_data =lp872x_find_regulator_init_data (desc->id, lp); - cfg.driver_data = lp; - cfg.regmap = lp->regmap; + cfg.dev = dev; + cfg.driver_data = lp; + cfg.regmap = lp->regmap; - rdev =devm_regulator_register (lp->dev, desc, &cfg); +for (int i =0 ; i < num_regulators; i++) { + rdev =devm_regulator_register (dev, &desc[i], &cfg);if (IS_ERR (rdev)) { -dev_err (lp->dev,"regulator register err" ); +dev_err (dev,"regulator register err" );return PTR_ERR (rdev); } }
@@ -817,152 +740,77 @@ static const struct regmap_config lp872x_regmap_config = { .max_register = MAX_REGISTERS, }; -#ifdef CONFIG_OF - -#define LP872X_VALID_OPMODE (REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL) - -static struct of_regulator_match lp8720_matches[] = { - { .name ="ldo1" , .driver_data = (void *)LP8720_ID_LDO1 , }, - { .name ="ldo2" , .driver_data = (void *)LP8720_ID_LDO2 , }, - { .name ="ldo3" , .driver_data = (void *)LP8720_ID_LDO3 , }, - { .name ="ldo4" , .driver_data = (void *)LP8720_ID_LDO4 , }, - { .name ="ldo5" , .driver_data = (void *)LP8720_ID_LDO5 , }, - { .name ="buck" , .driver_data = (void *)LP8720_ID_BUCK , }, -}; - -static struct of_regulator_match lp8725_matches[] = { - { .name ="ldo1" , .driver_data = (void *)LP8725_ID_LDO1 , }, - { .name ="ldo2" , .driver_data = (void *)LP8725_ID_LDO2 , }, - { .name ="ldo3" , .driver_data = (void *)LP8725_ID_LDO3 , }, - { .name ="ldo4" , .driver_data = (void *)LP8725_ID_LDO4 , }, - { .name ="ldo5" , .driver_data = (void *)LP8725_ID_LDO5 , }, - { .name ="lilo1" , .driver_data = (void *)LP8725_ID_LILO1 , }, - { .name ="lilo2" , .driver_data = (void *)LP8725_ID_LILO2 , }, - { .name ="buck1" , .driver_data = (void *)LP8725_ID_BUCK1 , }, - { .name ="buck2" , .driver_data = (void *)LP8725_ID_BUCK2 , }, -}; - -static struct lp872x_platform_data -*lp872x_populate_pdata_from_dt (struct device *dev,enum lp872x_id which) -{ -struct device_node *np = dev->of_node; -struct lp872x_platform_data *pdata; -struct of_regulator_match *match; -int num_matches; -int count; -int i; -u8 dvs_state; - - pdata =devm_kzalloc (dev,sizeof (*pdata),GFP_KERNEL ); -if (!pdata) -return ERR_PTR (-ENOMEM ); - -of_property_read_u8 (np,"ti,general-config" , &pdata->general_config); - pdata->update_config =of_property_read_bool (np,"ti,update-config" ); - - pdata->dvs =devm_kzalloc (dev,sizeof (struct lp872x_dvs ),GFP_KERNEL ); -if (!pdata->dvs) -return ERR_PTR (-ENOMEM ); - -of_property_read_u8 (np,"ti,dvs-vsel" , (u8 *)&pdata->dvs->vsel); -of_property_read_u8 (np,"ti,dvs-state" , &dvs_state); - pdata->dvs->init_state = dvs_state ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; - -if (of_get_child_count (np) ==0 ) - goto out; - -switch (which) { -case LP8720 : - match = lp8720_matches; - num_matches =ARRAY_SIZE (lp8720_matches); -break ; -case LP8725 : - match = lp8725_matches; - num_matches =ARRAY_SIZE (lp8725_matches); -break ; -default : - goto out; - } - - count =of_regulator_match (dev, np, match, num_matches); -if (count <=0 ) - goto out; - -for (i =0 ; i < num_matches; i++) { - pdata->regulator_data[i].id = - (uintptr_t )match[i].driver_data; - pdata->regulator_data[i].init_data = match[i].init_data; - } -out: -return pdata; -} -#else -static struct lp872x_platform_data -*lp872x_populate_pdata_from_dt (struct device *dev,enum lp872x_id which) -{ -return NULL ; -} -#endif -static int lp872x_probe (struct i2c_client *cl) { -const struct i2c_device_id *id =i2c_client_get_device_id (cl); +struct device *dev = &cl->dev;struct lp872x *lp; -struct lp872x_platform_data *pdata; +u8 general_config;int ret; -static const int lp872x_num_regulators[] = { - [LP8720 ] =LP8720_NUM_REGULATORS , - [LP8725 ] =LP8725_NUM_REGULATORS , - }; - -if (cl->dev.of_node) { - pdata =lp872x_populate_pdata_from_dt (&cl->dev, - (enum lp872x_id )id->driver_data); -if (IS_ERR (pdata)) -return PTR_ERR (pdata); - }else { - pdata =dev_get_platdata (&cl->dev); - } - lp =devm_kzalloc (&cl->dev,sizeof (struct lp872x ),GFP_KERNEL ); + lp =devm_kzalloc (dev,sizeof (*lp),GFP_KERNEL );if (!lp)return -ENOMEM ; - lp->num_regulators = lp872x_num_regulators[id->driver_data]; + lp->info =i2c_get_match_data (cl); +if (!lp->info) +return -ENODEV ; lp->regmap =devm_regmap_init_i2c (cl, &lp872x_regmap_config); -if (IS_ERR (lp->regmap)) { - ret =PTR_ERR (lp->regmap); -dev_err (&cl->dev,"regmap init i2c err: %d\n" , ret); -return ret; - } +if (IS_ERR (lp->regmap)) +return dev_err_probe (dev,PTR_ERR (lp->regmap), +"Failed to init regmap\n" ); - lp->dev = &cl->dev; - lp->pdata = pdata; - lp->chipid = id->driver_data; + lp->dev = dev;i2c_set_clientdata (cl, lp); - ret =lp872x_hw_enable (lp); -if (ret) -return ret; +/* Always set enable GPIO high. */ + lp->enable_gpio =devm_gpiod_get_optional (dev,"enable" ,GPIOD_OUT_HIGH ); +if (IS_ERR (lp->enable_gpio)) +return dev_err_probe (dev,PTR_ERR (lp->enable_gpio), +"Failed to request gpio\n" ); + +/* Each chip has a different enable delay. */ +if (lp->info->chipid ==LP8720 ) +usleep_range (LP8720_ENABLE_DELAY ,1.5 *LP8720_ENABLE_DELAY ); +else +usleep_range (LP8725_ENABLE_DELAY ,1.5 *LP8725_ENABLE_DELAY ); - ret =lp872x_config (lp); +device_property_read_u8 (dev,"ti,general-config" , &general_config); +if (device_property_read_bool (dev,"ti,update-config" )) { + ret =regmap_write (lp->regmap,LP872X_GENERAL_CFG , general_config); +if (ret) +return ret; + } + + ret =lp872x_init_dvs (lp);if (ret)return ret;return lp872x_regulator_register (lp); } -static const struct of_device_id lp872x_dt_ids[]__maybe_unused = { - { .compatible ="ti,lp8720" , }, - { .compatible ="ti,lp8725" , }, +static const struct lp872x_chip_info lp8720_data = { + .rdesc = lp8720_regulator_desc, + .num_regulators =LP8720_NUM_REGULATORS , + .chipid =LP8720 , +}; + +static const struct lp872x_chip_info lp8725_data = { + .rdesc = lp8725_regulator_desc, + .num_regulators =LP8725_NUM_REGULATORS , + .chipid =LP8725 , +}; + +static const struct of_device_id lp872x_dt_ids[] = { + { .compatible ="ti,lp8720" , .data = &lp8720_data }, + { .compatible ="ti,lp8725" , .data = &lp8725_data }, { } };MODULE_DEVICE_TABLE (of, lp872x_dt_ids);static const struct i2c_device_id lp872x_ids[] = { - { .name ="lp8720" , .driver_data =LP8720 }, - { .name ="lp8725" , .driver_data =LP8725 }, + { .name ="lp8720" , .driver_data = (kernel_ulong_t)&lp8720_data }, + { .name ="lp8725" , .driver_data = (kernel_ulong_t)&lp8725_data }, { } };MODULE_DEVICE_TABLE (i2c, lp872x_ids);
@@ -971,7 +819,7 @@ static struct i2c_driver lp872x_driver = { .driver = { .name = "lp872x", .probe_type = PROBE_PREFER_ASYNCHRONOUS, - .of_match_table = of_match_ptr(lp872x_dt_ids), + .of_match_table = lp872x_dt_ids, }, .probe = lp872x_probe, .id_table = lp872x_ids,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v1 5/7] regulator: lp872x: Remove platform_data based probing
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] regulator: lp872x: uninitialized stack variable general_config write - [High] regulator: lp872x…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] regulator: lp872x: uninitialized stack variable general_config write
- [High] regulator: lp872x: ABI breakage due to changed GPIO connection ID
- [Medium] regulator: lp872x: unconditional 30ms sleep in probe path
--
commit ffba7b7b46bbae180cc6ce91332a272bc6093ec2
Author: Svyatoslav Ryhel <[email protected]>
Subject: regulator: lp872x: Remove platform_data based probing
This commit removes platform_data-based probing from the lp872x regulator driver, transitioning fully to Device Tree parsing directly in the probe function. It also consolidates DVS initialization and drops the use of of_regulator_match in favor of the core registration framework.
Quoted 4 lines
drivers/regulator/lp872x.c +0
-0
[ ... ]
Quoted 4 lines
drivers/regulator/lp872x.c +0
-0@@ -700,110 +688,45 @@ static const struct regulator_desc lp8725_regulator_desc[] = {static int lp872x_init_dvs (struct lp872x *lp) {
[ ... ]
Quoted 1 line
drivers/regulator/lp872x.c +0
-1- dvs->gpio =devm_gpiod_get_optional (lp->dev,"ti,dvs" , pinstate);
[ ... ]
drivers/regulator/lp872x.c static const struct regulator_desc lp8725_regulator_desc[] = { · line 700
Quoted 1 line
drivers/regulator/lp872x.c +1
-0+ lp->dvs_gpio =devm_gpiod_get_optional (dev,"dvs" , lp->dvs_pin);
[Severity: High]
Does this change in connection ID break compatibility with existing Device Trees?
The original code searched for ti,dvs-gpios by using the ti,dvs connection ID. Changing this to dvs causes the GPIO framework to search for dvs-gpios instead. Existing device trees using the documented ti,dvs-gpios property will fail to find the GPIO, causing a fallback to register-based DVS.
[ ... ]
Quoted 1 line
drivers/regulator/lp872x.c +0
-0@@ -817,152 +740,77 @@ static const struct regmap_config lp872x_regmap_config = {
[ ... ]
Quoted 2 lines
static int
lp872x_probe(struct i2c_client *cl)
{
[ ... ]
Quoted 2 lines
drivers/regulator/lp872x.c +1
-0+u8 general_config;int ret;
[ ... ]
drivers/regulator/lp872x.c static const struct regmap_config lp872x_regmap_config = { · line 776
Quoted 11 lines
drivers/regulator/lp872x.c +11
-0+/* Always set enable GPIO high. */ + lp->enable_gpio =devm_gpiod_get_optional (dev,"enable" ,GPIOD_OUT_HIGH ); +if (IS_ERR (lp->enable_gpio)) +return dev_err_probe (dev,PTR_ERR (lp->enable_gpio), +"Failed to request gpio\n" ); + +/* Each chip has a different enable delay. */ +if (lp->info->chipid ==LP8720 ) +usleep_range (LP8720_ENABLE_DELAY ,1.5 *LP8720_ENABLE_DELAY ); +else +usleep_range (LP8725_ENABLE_DELAY ,1.5 *LP8725_ENABLE_DELAY );
[Severity: Medium]
Should this delay be conditional on whether an enable GPIO was actually found?
In the previous implementation, if there was no enable GPIO, it returned early and skipped the delay. Now, devm_gpiod_get_optional() returns NULL if no GPIO is configured, but the delay runs unconditionally. This adds an unnecessary 30ms sleep during boot for LP8725 platforms without an enable GPIO.
drivers/regulator/lp872x.c static const struct regmap_config lp872x_regmap_config = { · line 780
Quoted 5 lines
drivers/regulator/lp872x.c +3
-1- ret =lp872x_config (lp); +device_property_read_u8 (dev,"ti,general-config" , &general_config); +if (device_property_read_bool (dev,"ti,update-config" )) { + ret =regmap_write (lp->regmap,LP872X_GENERAL_CFG , general_config);
[Severity: High]
Can uninitialized stack memory be written to the hardware here?
If a device tree specifies ti,update-config but omits ti,general-config, device_property_read_u8() will fail and leave general_config untouched. Because general_config is declared on the stack without initialization, this leads to uninitialized memory being written to the LP872X_GENERAL_CFG register.
Quoted 6 lines
drivers/regulator/lp872x.c +3
-1+if (ret)return ret; + } - ret =lp872x_init_dvs (lp); + ret =lp872x_init_dvs (lp);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Mark Brown
maintainerRe: [PATCH v1 5/7] regulator: lp872x: Remove platform_data based probing
In reply to Svyatoslav RyhelQuoted 6 lines · Svyatoslav Ryhel
The platform_data-based probing is tightly integrated into the lp872x driver structure itself; removing just the platform data support is impossible without remodeling major parts of the probe sequence.
static int
lp872x_init_dvs(struct lp872x *lp)
{
drivers/regulator/lp872x.c static const struct regulator_desc lp8725_regulator_desc[] = { · line 696
Quoted 8 lines
drivers/regulator/lp872x.c +3
-2-struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs :NULL ; -enum gpiod_flags pinstate; +struct device *dev = lp->dev;u32 mask[] = {LP8720_EXT_DVS_M ,LP8725_DVS1_M |LP8725_DVS2_M };u32 default_dvs_mode[] = {LP8720_DEFAULT_DVS ,LP8725_DEFAULT_DVS }; +u8 dvs_state; +device_property_read_u8 (dev,"ti,dvs-vsel" , (u8 *)&lp->vsel);
Since you're updating this we should fix to read into a local u8 and assign the value - the cast won't work on big endian.
drivers/regulator/lp872x.c static const struct regulator_desc lp8725_regulator_desc[] = { · line 697
Quoted 1 line
drivers/regulator/lp872x.c +1
-0+device_property_read_u8 (dev,"ti,dvs-state" , &dvs_state);
If these properties are absent then dvs_state won't be updated...
drivers/regulator/lp872x.c static const struct regulator_desc lp8725_regulator_desc[] = { · line 698
Quoted 1 line
drivers/regulator/lp872x.c +1
-0+ lp->dvs_pin = dvs_state ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ;
...so this will be random.
drivers/regulator/lp872x.c static const struct regulator_desc lp8725_regulator_desc[] = { · line 704
Quoted 5 lines
drivers/regulator/lp872x.c +4
-0+ lp->dvs_gpio =devm_gpiod_get_optional (dev,"dvs" , lp->dvs_pin); +if (IS_ERR (lp->dvs_gpio)) { +dev_err (dev,"gpio request err: %ld\n" ,PTR_ERR (lp->dvs_gpio)); +return PTR_ERR (lp->dvs_gpio); }
dev_err_probe()
drivers/regulator/lp872x.c static const struct regmap_config lp872x_regmap_config = { · line 780
Quoted 11 lines
static int
lp872x_probe(struct i2c_client *cl)
{drivers/regulator/lp872x.c +5
-2-const struct i2c_device_id *id =i2c_client_get_device_id (cl); +struct device *dev = &cl->dev;struct lp872x *lp; -struct lp872x_platform_data *pdata; +u8 general_config; +device_property_read_u8 (dev,"ti,general-config" , &general_config); +if (device_property_read_bool (dev,"ti,update-config" )) { + ret =regmap_write (lp->regmap,LP872X_GENERAL_CFG , general_config);
Same issue here with general_config being uninitialised if absent; this is a buggy DT but we should still handle it better.
Re: [PATCH v1 5/7] regulator: lp872x: Remove platform_data based probing
ср, 7 жовт. 2026 р. о 11:39 Mark Brown <[email protected]> пише:
Quoted 16 lines · Svyatoslav Ryhel
Quoted 13 lines
The platform_data-based probing is tightly integrated into the lp872x driver structure itself; removing just the platform data support is impossible without remodeling major parts of the probe sequence.
static int
lp872x_init_dvs(struct lp872x *lp)
{drivers/regulator/lp872x.c +2
-2-struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs :NULL ; -enum gpiod_flags pinstate; +struct device *dev = lp->dev;u32 mask[] = {LP8720_EXT_DVS_M ,LP8725_DVS1_M |LP8725_DVS2_M };u32 default_dvs_mode[] = {LP8720_DEFAULT_DVS ,LP8725_DEFAULT_DVS }; +u8 dvs_state;
Quoted 5 lines
Quoted 1 line
+
device_property_read_u8(dev, "ti,dvs-vsel", (u8 *)&lp->vsel);Since you're updating this we should fix to read into a local u8 and assign the value - the cast won't work on big endian.
Noted
Quoted 4 lines
Quoted 1 line
+
device_property_read_u8(dev, "ti,dvs-state", &dvs_state);If these properties are absent then
dvs_statewon't be updated...
I will init dvs_state above then.
Quoted 4 lines
Quoted 1 line
+
lp->dvs_pin=dvs_state?GPIOD_OUT_HIGH:GPIOD_OUT_LOW;...so this will be random.
Quoted 8 lines
drivers/regulator/lp872x.c static const struct regulator_desc lp8725_regulator_desc[] = { · line 704
Quoted 5 lines
drivers/regulator/lp872x.c +4
-0+ lp->dvs_gpio =devm_gpiod_get_optional (dev,"dvs" , lp->dvs_pin); +if (IS_ERR (lp->dvs_gpio)) { +dev_err (dev,"gpio request err: %ld\n" ,PTR_ERR (lp->dvs_gpio)); +return PTR_ERR (lp->dvs_gpio); }
dev_err_probe()
Noted
Quoted 8 lines
Quoted 7 lines
static int
lp872x_probe(struct i2c_client *cl)
{drivers/regulator/lp872x.c +2
-2-const struct i2c_device_id *id =i2c_client_get_device_id (cl); +struct device *dev = &cl->dev;struct lp872x *lp; -struct lp872x_platform_data *pdata; +u8 general_config;
Quoted 6 lines
drivers/regulator/lp872x.c static const struct regmap_config lp872x_regmap_config = { · line 780
Quoted 3 lines
drivers/regulator/lp872x.c +3
-0+device_property_read_u8 (dev,"ti,general-config" , &general_config); +if (device_property_read_bool (dev,"ti,update-config" )) { + ret =regmap_write (lp->regmap,LP872X_GENERAL_CFG , general_config);Same issue here with
general_configbeing uninitialised if absent; this is a buggy DT but we should still handle it better.
Noted, I will check default values in datasheet then, thanks.
PATCH 6/7 regulator: lp872x: Add support for input and regulator power supplies
In reply to Svyatoslav RyhelThe LP872x support dedicated main power supply input usually shared with parent power supply for one of internal regulators (ldo1).
Add support for retrieving and managing these supply regulators using the regulator framework to ensure proper power supply dependencies and power-up sequencing.
--- drivers/regulator/lp872x.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/regulator/lp872x.c +22 -0
@@ -471,6 +471,7 @@ static const struct regulator_ops lp8725_buck_ops = {static const struct regulator_desc lp8720_regulator_desc[] = { { .name ="ldo1" , + .supply_name ="vbatt" , .of_match =of_match_ptr ("ldo1" ), .id =LP8720_ID_LDO1 , .ops = &lp872x_ldo_ops,
@@ -485,6 +486,7 @@ static const struct regulator_desc lp8720_regulator_desc[] = { }, { .name = "ldo2", + .supply_name = "vin1", .of_match = of_match_ptr("ldo2"), .id = LP8720_ID_LDO2, .ops = &lp872x_ldo_ops,
@@ -499,6 +501,7 @@ static const struct regulator_desc lp8720_regulator_desc[] = { }, { .name = "ldo3", + .supply_name = "vin1", .of_match = of_match_ptr("ldo3"), .id = LP8720_ID_LDO3, .ops = &lp872x_ldo_ops,
@@ -513,6 +516,7 @@ static const struct regulator_desc lp8720_regulator_desc[] = { }, { .name = "ldo4", + .supply_name = "vin2", .of_match = of_match_ptr("ldo4"), .id = LP8720_ID_LDO4, .ops = &lp872x_ldo_ops,
@@ -527,6 +531,7 @@ static const struct regulator_desc lp8720_regulator_desc[] = { }, { .name = "ldo5", + .supply_name = "vin2", .of_match = of_match_ptr("ldo5"), .id = LP8720_ID_LDO5, .ops = &lp872x_ldo_ops,
@@ -541,6 +546,7 @@ static const struct regulator_desc lp8720_regulator_desc[] = { }, { .name = "buck", + .supply_name = "vinb", .of_match = of_match_ptr("buck"), .id = LP8720_ID_BUCK, .ops = &lp8720_buck_ops,
@@ -556,6 +562,7 @@ static const struct regulator_desc lp8720_regulator_desc[] = {static const struct regulator_desc lp8725_regulator_desc[] = { { .name ="ldo1" , + .supply_name ="vin1" , .of_match =of_match_ptr ("ldo1" ), .id =LP8725_ID_LDO1 , .ops = &lp872x_ldo_ops,
@@ -570,6 +577,7 @@ static const struct regulator_desc lp8725_regulator_desc[] = { }, { .name = "ldo2", + .supply_name = "vin2", .of_match = of_match_ptr("ldo2"), .id = LP8725_ID_LDO2, .ops = &lp872x_ldo_ops,
@@ -584,6 +592,7 @@ static const struct regulator_desc lp8725_regulator_desc[] = { }, { .name = "ldo3", + .supply_name = "vin2", .of_match = of_match_ptr("ldo3"), .id = LP8725_ID_LDO3, .ops = &lp872x_ldo_ops,
@@ -598,6 +607,7 @@ static const struct regulator_desc lp8725_regulator_desc[] = { }, { .name = "ldo4", + .supply_name = "vin3", .of_match = of_match_ptr("ldo4"), .id = LP8725_ID_LDO4, .ops = &lp872x_ldo_ops,
@@ -612,6 +622,7 @@ static const struct regulator_desc lp8725_regulator_desc[] = { }, { .name = "ldo5", + .supply_name = "vin3", .of_match = of_match_ptr("ldo5"), .id = LP8725_ID_LDO5, .ops = &lp872x_ldo_ops,
@@ -626,6 +637,7 @@ static const struct regulator_desc lp8725_regulator_desc[] = { }, { .name = "lilo1", + .supply_name = "vinlilo1", .of_match = of_match_ptr("lilo1"), .id = LP8725_ID_LILO1, .ops = &lp872x_ldo_ops,
@@ -640,6 +652,7 @@ static const struct regulator_desc lp8725_regulator_desc[] = { }, { .name = "lilo2", + .supply_name = "vinlilo2", .of_match = of_match_ptr("lilo2"), .id = LP8725_ID_LILO2, .ops = &lp872x_ldo_ops,
@@ -654,6 +667,7 @@ static const struct regulator_desc lp8725_regulator_desc[] = { }, { .name = "buck1", + .supply_name = "vinb", .of_match = of_match_ptr("buck1"), .id = LP8725_ID_BUCK1, .ops = &lp8725_buck_ops,
@@ -670,6 +684,7 @@ static const struct regulator_desc lp8725_regulator_desc[] = { }, { .name = "buck2", + .supply_name = "vinb", .of_match = of_match_ptr("buck2"), .id = LP8725_ID_BUCK2, .ops = &lp8725_buck_ops,
@@ -743,6 +758,7 @@ static const struct regmap_config lp872x_regmap_config = {static int lp872x_probe (struct i2c_client *cl) {struct device *dev = &cl->dev; +const char *in_supply_name;struct lp872x *lp;u8 general_config;int ret;
@@ -760,6 +776,12 @@ static int lp872x_probe(struct i2c_client *cl)return dev_err_probe (dev,PTR_ERR (lp->regmap),"Failed to init regmap\n" ); +/* LDO0 parent supplies chip itself */ + in_supply_name = lp->info->rdesc[0 ].supply_name; + ret =devm_regulator_get_enable (dev, in_supply_name); +if (ret) +return dev_err_probe (dev, ret,"Failed to enable supply regulator\n" ); + lp->dev = dev;i2c_set_clientdata (cl, lp);
Signature · 1 line
2.53.0
PATCH 7/7 regulator: lp872x: Use macro to fill regulator descriptor
In reply to Svyatoslav RyhelSwitch to using the macro for filling the LP872x regulator descriptor to improve readability.
--- drivers/regulator/lp872x.c | 275 ++++++++----------------------------- 1 file changed, 61 insertions(+), 214 deletions(-)
drivers/regulator/lp872x.c +61 -214
@@ -468,82 +468,59 @@ static const struct regulator_ops lp8725_buck_ops = { .get_current_limit = regulator_get_current_limit_regmap, }; +#define LP872X_LDO (_id, match, supply, _volt_table, _vsel_reg, \ + _enable_reg, _enable_mask) { \ + .name = (match), \ + .supply_name = (supply), \ + .of_match = (match), \ + .id = _id, \ + .ops = &lp872x_ldo_ops, \ + .n_voltages = ARRAY_SIZE(_volt_table), \ + .volt_table = _volt_table, \ + .type = REGULATOR_VOLTAGE, \ + .owner = THIS_MODULE, \ + .vsel_reg = _vsel_reg, \ + .vsel_mask = LP872X_VOUT_M, \ + .enable_reg = _enable_reg, \ + .enable_mask = _enable_mask, \ +} + +#define LP8720_LDO (ids, match, supply, _volt_table) \ + LP872X_LDO(LP8720_ID_##ids, match, supply, _volt_table, \ + LP872X_##ids##_VOUT, LP8720_ENABLE, LP872X_EN_##ids##_M) + +#define LP8725_LDO (ids, match, supply) \ + LP872X_LDO(LP8725_ID_##ids, match, supply, lp872x_ldo_vtbl, \ + LP872X_##ids##_VOUT, LP8725_LDO_CTRL, LP872X_EN_##ids##_M) + +#define LP8725_LILO (ids, match, supply) \ + LP872X_LDO(LP8725_ID_##ids, match, supply, lp8725_lilo_vtbl, \ + LP8725_##ids##_VOUT, LP8725_LDO_CTRL, LP8725_EN_##ids##_M) + +#define LP8725_BUCK (ids, match) { \ + .name = (match), \ + .supply_name = "vinb", \ + .of_match = (match), \ + .id = LP8725_ID_##ids, \ + .ops = &lp8725_buck_ops, \ + .n_voltages = ARRAY_SIZE(lp8725_buck_vtbl), \ + .volt_table = lp8725_buck_vtbl, \ + .type = REGULATOR_VOLTAGE, \ + .owner = THIS_MODULE, \ + .enable_reg = LP872X_GENERAL_CFG, \ + .enable_mask = LP8725_##ids##_EN_M, \ + .curr_table = lp8725_buck_uA, \ + .n_current_limits = ARRAY_SIZE(lp8725_buck_uA), \ + .csel_reg = LP8725_##ids##_VOUT2, \ + .csel_mask = LP8725_BUCK_CL_M, \ +} +static const struct regulator_desc lp8720_regulator_desc[] = { - { - .name ="ldo1" , - .supply_name ="vbatt" , - .of_match =of_match_ptr ("ldo1" ), - .id =LP8720_ID_LDO1 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp872x_ldo_vtbl), - .volt_table = lp872x_ldo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP872X_LDO1_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8720_ENABLE , - .enable_mask =LP872X_EN_LDO1_M , - }, - { - .name ="ldo2" , - .supply_name ="vin1" , - .of_match =of_match_ptr ("ldo2" ), - .id =LP8720_ID_LDO2 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp872x_ldo_vtbl), - .volt_table = lp872x_ldo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP872X_LDO2_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8720_ENABLE , - .enable_mask =LP872X_EN_LDO2_M , - }, - { - .name ="ldo3" , - .supply_name ="vin1" , - .of_match =of_match_ptr ("ldo3" ), - .id =LP8720_ID_LDO3 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp872x_ldo_vtbl), - .volt_table = lp872x_ldo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP872X_LDO3_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8720_ENABLE , - .enable_mask =LP872X_EN_LDO3_M , - }, - { - .name ="ldo4" , - .supply_name ="vin2" , - .of_match =of_match_ptr ("ldo4" ), - .id =LP8720_ID_LDO4 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp8720_ldo4_vtbl), - .volt_table = lp8720_ldo4_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP872X_LDO4_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8720_ENABLE , - .enable_mask =LP872X_EN_LDO4_M , - }, - { - .name ="ldo5" , - .supply_name ="vin2" , - .of_match =of_match_ptr ("ldo5" ), - .id =LP8720_ID_LDO5 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp872x_ldo_vtbl), - .volt_table = lp872x_ldo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP872X_LDO5_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8720_ENABLE , - .enable_mask =LP872X_EN_LDO5_M , - }, +LP8720_LDO (LDO1 ,"ldo1" ,"vbatt" , lp872x_ldo_vtbl), +LP8720_LDO (LDO2 ,"ldo2" ,"vin1" , lp872x_ldo_vtbl), +LP8720_LDO (LDO3 ,"ldo3" ,"vin1" , lp872x_ldo_vtbl), +LP8720_LDO (LDO4 ,"ldo4" ,"vin2" , lp8720_ldo4_vtbl), +LP8720_LDO (LDO5 ,"ldo5" ,"vin2" , lp872x_ldo_vtbl), { .name ="buck" , .supply_name ="vinb" ,
@@ -560,145 +537,15 @@ static const struct regulator_desc lp8720_regulator_desc[] = { };static const struct regulator_desc lp8725_regulator_desc[] = { - { - .name ="ldo1" , - .supply_name ="vin1" , - .of_match =of_match_ptr ("ldo1" ), - .id =LP8725_ID_LDO1 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp872x_ldo_vtbl), - .volt_table = lp872x_ldo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP872X_LDO1_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8725_LDO_CTRL , - .enable_mask =LP872X_EN_LDO1_M , - }, - { - .name ="ldo2" , - .supply_name ="vin2" , - .of_match =of_match_ptr ("ldo2" ), - .id =LP8725_ID_LDO2 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp872x_ldo_vtbl), - .volt_table = lp872x_ldo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP872X_LDO2_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8725_LDO_CTRL , - .enable_mask =LP872X_EN_LDO2_M , - }, - { - .name ="ldo3" , - .supply_name ="vin2" , - .of_match =of_match_ptr ("ldo3" ), - .id =LP8725_ID_LDO3 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp872x_ldo_vtbl), - .volt_table = lp872x_ldo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP872X_LDO3_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8725_LDO_CTRL , - .enable_mask =LP872X_EN_LDO3_M , - }, - { - .name ="ldo4" , - .supply_name ="vin3" , - .of_match =of_match_ptr ("ldo4" ), - .id =LP8725_ID_LDO4 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp872x_ldo_vtbl), - .volt_table = lp872x_ldo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP872X_LDO4_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8725_LDO_CTRL , - .enable_mask =LP872X_EN_LDO4_M , - }, - { - .name ="ldo5" , - .supply_name ="vin3" , - .of_match =of_match_ptr ("ldo5" ), - .id =LP8725_ID_LDO5 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp872x_ldo_vtbl), - .volt_table = lp872x_ldo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP872X_LDO5_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8725_LDO_CTRL , - .enable_mask =LP872X_EN_LDO5_M , - }, - { - .name ="lilo1" , - .supply_name ="vinlilo1" , - .of_match =of_match_ptr ("lilo1" ), - .id =LP8725_ID_LILO1 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp8725_lilo_vtbl), - .volt_table = lp8725_lilo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP8725_LILO1_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8725_LDO_CTRL , - .enable_mask =LP8725_EN_LILO1_M , - }, - { - .name ="lilo2" , - .supply_name ="vinlilo2" , - .of_match =of_match_ptr ("lilo2" ), - .id =LP8725_ID_LILO2 , - .ops = &lp872x_ldo_ops, - .n_voltages =ARRAY_SIZE (lp8725_lilo_vtbl), - .volt_table = lp8725_lilo_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .vsel_reg =LP8725_LILO2_VOUT , - .vsel_mask =LP872X_VOUT_M , - .enable_reg =LP8725_LDO_CTRL , - .enable_mask =LP8725_EN_LILO2_M , - }, - { - .name ="buck1" , - .supply_name ="vinb" , - .of_match =of_match_ptr ("buck1" ), - .id =LP8725_ID_BUCK1 , - .ops = &lp8725_buck_ops, - .n_voltages =ARRAY_SIZE (lp8725_buck_vtbl), - .volt_table = lp8725_buck_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .enable_reg =LP872X_GENERAL_CFG , - .enable_mask =LP8725_BUCK1_EN_M , - .curr_table = lp8725_buck_uA, - .n_current_limits =ARRAY_SIZE (lp8725_buck_uA), - .csel_reg =LP8725_BUCK1_VOUT2 , - .csel_mask =LP8725_BUCK_CL_M , - }, - { - .name ="buck2" , - .supply_name ="vinb" , - .of_match =of_match_ptr ("buck2" ), - .id =LP8725_ID_BUCK2 , - .ops = &lp8725_buck_ops, - .n_voltages =ARRAY_SIZE (lp8725_buck_vtbl), - .volt_table = lp8725_buck_vtbl, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , - .enable_reg =LP872X_GENERAL_CFG , - .enable_mask =LP8725_BUCK2_EN_M , - .curr_table = lp8725_buck_uA, - .n_current_limits =ARRAY_SIZE (lp8725_buck_uA), - .csel_reg =LP8725_BUCK2_VOUT2 , - .csel_mask =LP8725_BUCK_CL_M , - }, +LP8725_LDO (LDO1 ,"ldo1" ,"vin1" ), +LP8725_LDO (LDO2 ,"ldo2" ,"vin2" ), +LP8725_LDO (LDO3 ,"ldo3" ,"vin2" ), +LP8725_LDO (LDO4 ,"ldo4" ,"vin3" ), +LP8725_LDO (LDO5 ,"ldo5" ,"vin3" ), +LP8725_LILO (LILO1 ,"lilo1" ,"vinlilo1" ), +LP8725_LILO (LILO2 ,"lilo2" ,"vinlilo2" ), +LP8725_BUCK (BUCK1 ,"buck1" ), +LP8725_BUCK (BUCK2 ,"buck2" ), };static int lp872x_init_dvs (struct lp872x *lp)
Signature · 1 line
2.53.0