lp872x: remove platform_data based probing and adjustments

Svyatoslav Ryhel <clamor95@gmail.com> says:

Upgrade schema. Consolidate driver file, remove platform_data based
probing and add missing regulator/chip supplies.

Link: https://patch.msgid.link/20261013181417.492252-1-clamor95@gmail.com
This commit is contained in:
Mark Brown 2026-10-13 20:17:58 +01:00
commit 98a375660b
No known key found for this signature in database
GPG Key ID: 2FEF73B0B3D03889
3 changed files with 229 additions and 547 deletions

View File

@ -47,10 +47,12 @@ properties:
ti,update-config:
type: boolean
deprecated: true
description: define it when LP872X_GENERAL_CFG register should be set
ti,dvs-gpio:
maxItems: 1
deprecated: true
description: GPIO specifier for external DVS pin control of LP872x devices.
ti,dvs-vsel:
@ -67,6 +69,10 @@ properties:
maxItems: 1
description: GPIO specifier for EN pin control of LP872x devices.
dvs-gpios:
description: GPIO specifier for external DVS pin control.
maxItems: 1
buck:
type: object
$ref: regulator.yaml#
@ -75,6 +81,16 @@ properties:
Single BUCK regulator for LP8720.
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[1-2]?|ldo[1-5]|lilo[1-2])$":
type: object
$ref: regulator.yaml#
@ -95,6 +111,7 @@ allOf:
reg:
const: 0x7d
patternProperties:
"^(vin(3|lilo[1-2]))-supply$": false
"^(buck[1-2]|lilo[1-2])$": false
- if:
@ -106,6 +123,7 @@ allOf:
properties:
reg:
const: 0x7a
vbatt-supply: false
buck: false
additionalProperties: false

View File

@ -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/property.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/of_regulator.h>
/* Registers : LP8720/8725 shared */
@ -92,17 +92,58 @@
/* dump registers in regmap-debugfs */
#define MAX_REGISTERS 0x0F
#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_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;
};
@ -152,36 +193,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;
enum lp872x_id chip = lp->info->chipid;
u32 val, mask, shift;
int *time_usec, size, ret;
int lp8720_time_usec[] = { 25, 50 };
int lp8725_time_usec[] = { 32, 64, 128, 256 };
@ -203,7 +218,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;
@ -220,7 +235,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;
@ -239,7 +254,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;
@ -261,9 +276,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) {
@ -272,7 +287,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 ?
@ -317,31 +332,30 @@ 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;
struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL;
u32 addr, mask = LP872X_VOUT_M;
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))
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;
@ -352,7 +366,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:
@ -381,14 +395,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) {
@ -408,7 +422,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;
@ -454,79 +468,62 @@ 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",
.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",
.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",
.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",
.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",
.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",
.of_match = of_match_ptr("buck"),
.id = LP8720_ID_BUCK,
.ops = &lp8720_buck_ops,
@ -540,244 +537,60 @@ static const struct regulator_desc lp8720_regulator_desc[] = {
};
static const struct regulator_desc lp8725_regulator_desc[] = {
{
.name = "ldo1",
.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",
.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",
.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",
.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",
.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",
.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",
.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",
.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",
.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)
{
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 };
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 state = 1;
u8 vsel = SEL_V1;
if (!dvs)
goto set_default_dvs_mode;
device_property_read_u8(dev, "ti,dvs-vsel", &vsel);
lp->vsel = vsel;
if (!dvs->gpio)
goto set_default_dvs_mode;
device_property_read_u8(dev, "ti,dvs-state", &state);
lp->dvs_pin = state ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
pinstate = dvs->init_state;
dvs->gpio = devm_gpiod_get_optional(lp->dev, "ti,dvs", pinstate);
lp->dvs_gpio = devm_gpiod_get_optional(dev, "dvs", lp->dvs_pin);
if (IS_ERR(lp->dvs_gpio))
return dev_err_probe(dev, PTR_ERR(lp->dvs_gpio),
"Failed to request DVS GPIO\n");
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;
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;
set_default_dvs_mode:
return lp872x_update_bits(lp, 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;
/* 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);
}
/* 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);
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 = lp872x_write_byte(lp, 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 = dev;
cfg.driver_data = lp;
cfg.regmap = lp->regmap;
cfg.dev = lp->dev;
cfg.init_data = lp872x_find_regulator_init_data(desc->id, lp);
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);
}
}
@ -791,152 +604,89 @@ 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;
const char *in_supply_name;
struct lp872x *lp;
struct lp872x_platform_data *pdata;
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;
/* 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);
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");
ret = lp872x_config(lp);
/* 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);
if (device_property_present(dev, "ti,general-config")) {
u8 general_config;
ret = device_property_read_u8(dev, "ti,general-config",
&general_config);
if (ret)
return dev_err_probe(dev, ret, "Failed to read general config\n");
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);
@ -945,7 +695,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,

View File

@ -1,86 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright 2012 Texas Instruments
*
* Author: Milo(Woogyom) Kim <milo.kim@ti.com>
*/
#ifndef __LP872X_REGULATOR_H__
#define __LP872X_REGULATOR_H__
#include <linux/regulator/machine.h>
#include <linux/platform_device.h>
#include <linux/gpio/consumer.h>
#define LP872X_MAX_REGULATORS 9
#define LP8720_ENABLE_DELAY 200
#define LP8725_ENABLE_DELAY 30000
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,
};
/**
* lp872x_dvs
* @gpio : gpio descriptor for dvs control
* @vsel : dvs selector for buck v1 or buck v2 register
* @init_state : initial dvs pin state
*/
struct lp872x_dvs {
struct gpio_desc *gpio;
enum lp872x_dvs_sel vsel;
enum gpiod_flags init_state;
};
/**
* lp872x_regdata
* @id : regulator id
* @init_data : init data for each regulator
*/
struct lp872x_regulator_data {
enum lp872x_regulator_id id;
struct regulator_init_data *init_data;
};
/**
* lp872x_platform_data
* @general_config : the value of LP872X_GENERAL_CFG register
* @update_config : if LP872X_GENERAL_CFG register is updated, set true
* @regulator_data : platform regulator id and init data
* @dvs : dvs data for buck voltage control
* @enable_gpio : gpio descriptor for enable control
*/
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;
};
#endif