regulator: wm8994: Convert wm8994_ldo2_ops to use regulator_list_voltage_linear
PATCH 1/2 regulator: wm8994: Convert wm8994_ldo2_ops to use regulator_list_voltage_linear
Signed-off-by Axel Lin <[email protected]>
--- drivers/regulator/wm8994-regulator.c | 57 ++++++++++++++++------------------ 1 file changed, 26 insertions(+), 31 deletions(-)
drivers/regulator/wm8994-regulator.c +26 -31
@@ -27,7 +27,6 @@struct wm8994_ldo {struct regulator_dev *regulator; -struct wm8994 *wm8994; };#define WM8994_LDO1_MAX_SELECTOR 0x7
@@ -40,39 +39,14 @@ static struct regulator_ops wm8994_ldo1_ops = { .set_voltage_sel = regulator_set_voltage_sel_regmap, }; -static int wm8994_ldo2_list_voltage (struct regulator_dev *rdev, -unsigned int selector) -{ -struct wm8994_ldo *ldo =rdev_get_drvdata (rdev); - -if (selector >WM8994_LDO2_MAX_SELECTOR ) -return -EINVAL ; - -switch (ldo->wm8994->type) { -case WM8994 : -return (selector *100000 ) +900000 ; -case WM8958 : -return (selector *100000 ) +1000000 ; -case WM1811 : -switch (selector) { -case 0 : -return -EINVAL ; -default : -return (selector *100000 ) +950000 ; - } -break ; -default : -return -EINVAL ; - } -} -static struct regulator_ops wm8994_ldo2_ops = { - .list_voltage = wm8994_ldo2_list_voltage, + .list_voltage = regulator_list_voltage_linear, + .map_voltage = regulator_map_voltage_linear, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, }; -static const struct regulator_desc wm8994_ldo_desc[] = { +static struct regulator_desc wm8994_ldo_desc[] = { { .name ="LDO1" , .id =1 ,
@@ -116,8 +90,6 @@ static int wm8994_ldo_probe(struct platform_device *pdev)return -ENOMEM ; } - ldo->wm8994 = wm8994; - config.dev = wm8994->dev; config.driver_data = ldo; config.regmap = wm8994->regmap;
@@ -126,6 +98,29 @@ static int wm8994_ldo_probe(struct platform_device *pdev) config.ena_gpio = pdata->ldo[id].enable; } +/* LDO2, id starts from 0 */ +if (id ==1 ) { +switch (wm8994->type) { +case WM8994 : + wm8994_ldo_desc[id].min_uV =900000 ; + wm8994_ldo_desc[id].uV_step =100000 ; +break ; +case WM8958 : + wm8994_ldo_desc[id].min_uV =1000000 ; + wm8994_ldo_desc[id].uV_step =100000 ; +break ; +case WM1811 : + wm8994_ldo_desc[id].min_uV =1050000 ; + wm8994_ldo_desc[id].uV_step =100000 ; + wm8994_ldo_desc[id].linear_min_sel =1 ; +break ; +default : +dev_err (&pdev->dev,"Unknown wm8994 device type %d\n" , + wm8994->type); +return -EINVAL ; + } + } + ldo->regulator =regulator_register (&wm8994_ldo_desc[id], &config);if (IS_ERR (ldo->regulator)) { ret =PTR_ERR (ldo->regulator);
Signature · 1 line
1.7.9.5
PATCH 2/2 regulator: wm8994: Merge wm8994_ldo1_ops and wm8994_ldo2_ops
wm8994_ldo1_ops and wm8994_ldo2_ops are the same after converting wm8994_ldo2_ops to use regulator_list_voltage_linear, merge them.
Signed-off-by Axel Lin <[email protected]>
--- drivers/regulator/wm8994-regulator.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/regulator/wm8994-regulator.c +3 -10
@@ -32,14 +32,7 @@ struct wm8994_ldo {#define WM8994_LDO1_MAX_SELECTOR 0x7#define WM8994_LDO2_MAX_SELECTOR 0x3 -static struct regulator_ops wm8994_ldo1_ops = { - .list_voltage = regulator_list_voltage_linear, - .map_voltage = regulator_map_voltage_linear, - .get_voltage_sel = regulator_get_voltage_sel_regmap, - .set_voltage_sel = regulator_set_voltage_sel_regmap, -}; - -static struct regulator_ops wm8994_ldo2_ops = { +static struct regulator_ops wm8994_ldo_ops = { .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, .get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -54,7 +47,7 @@ static struct regulator_desc wm8994_ldo_desc[] = { .n_voltages = WM8994_LDO1_MAX_SELECTOR + 1, .vsel_reg = WM8994_LDO_1, .vsel_mask = WM8994_LDO1_VSEL_MASK, - .ops = &wm8994_ldo1_ops, + .ops = &wm8994_ldo_ops, .min_uV = 2400000, .uV_step = 100000, .enable_time = 3000,
@@ -67,7 +60,7 @@ static struct regulator_desc wm8994_ldo_desc[] = { .n_voltages = WM8994_LDO2_MAX_SELECTOR + 1, .vsel_reg = WM8994_LDO_2, .vsel_mask = WM8994_LDO2_VSEL_MASK, - .ops = &wm8994_ldo2_ops, + .ops = &wm8994_ldo_ops, .enable_time = 3000, .owner = THIS_MODULE, },
Signature · 1 line
1.7.9.5
drivers/regulator/wm8994-regulator.c static int wm8994_ldo_probe(struct platform_device *pdev) · line 107
Quoted 7 lines · Axel Lin
drivers/regulator/wm8994-regulator.c +7
-0+/* LDO2, id starts from 0 */ +if (id ==1 ) { +switch (wm8994->type) { +case WM8994 : + wm8994_ldo_desc[id].min_uV =900000 ; + wm8994_ldo_desc[id].uV_step =100000 ; +break ;
This isn't going to work in the (admittedly unlikely) case where we have two different devices using this driver in the system. We shouldn't be modifying static data like this.