Commit c54a155d authored by Mark Brown's avatar Mark Brown

regulator: wm8400: Modernise driver

Update the driver to use all the regmap based helpers, saving a nice chunk
of code (especially for the DCDCs).
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent d31e954e
...@@ -19,31 +19,6 @@ ...@@ -19,31 +19,6 @@
#include <linux/regulator/driver.h> #include <linux/regulator/driver.h>
#include <linux/mfd/wm8400-private.h> #include <linux/mfd/wm8400-private.h>
static int wm8400_ldo_is_enabled(struct regulator_dev *dev)
{
struct wm8400 *wm8400 = rdev_get_drvdata(dev);
u16 val;
val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev));
return (val & WM8400_LDO1_ENA) != 0;
}
static int wm8400_ldo_enable(struct regulator_dev *dev)
{
struct wm8400 *wm8400 = rdev_get_drvdata(dev);
return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
WM8400_LDO1_ENA, WM8400_LDO1_ENA);
}
static int wm8400_ldo_disable(struct regulator_dev *dev)
{
struct wm8400 *wm8400 = rdev_get_drvdata(dev);
return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
WM8400_LDO1_ENA, 0);
}
static int wm8400_ldo_list_voltage(struct regulator_dev *dev, static int wm8400_ldo_list_voltage(struct regulator_dev *dev,
unsigned selector) unsigned selector)
{ {
...@@ -56,21 +31,9 @@ static int wm8400_ldo_list_voltage(struct regulator_dev *dev, ...@@ -56,21 +31,9 @@ static int wm8400_ldo_list_voltage(struct regulator_dev *dev,
return 1600000 + ((selector - 14) * 100000); return 1600000 + ((selector - 14) * 100000);
} }
static int wm8400_ldo_get_voltage_sel(struct regulator_dev *dev) static int wm8400_ldo_map_voltage(struct regulator_dev *dev,
int min_uV, int max_uV)
{ {
struct wm8400 *wm8400 = rdev_get_drvdata(dev);
u16 val;
val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev));
val &= WM8400_LDO1_VSEL_MASK;
return val;
}
static int wm8400_ldo_set_voltage(struct regulator_dev *dev,
int min_uV, int max_uV, unsigned *selector)
{
struct wm8400 *wm8400 = rdev_get_drvdata(dev);
u16 val; u16 val;
if (min_uV < 900000 || min_uV > 3300000) if (min_uV < 900000 || min_uV > 3300000)
...@@ -94,92 +57,19 @@ static int wm8400_ldo_set_voltage(struct regulator_dev *dev, ...@@ -94,92 +57,19 @@ static int wm8400_ldo_set_voltage(struct regulator_dev *dev,
val += 0xf; val += 0xf;
} }
*selector = val; return val;
return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
WM8400_LDO1_VSEL_MASK, val);
} }
static struct regulator_ops wm8400_ldo_ops = { static struct regulator_ops wm8400_ldo_ops = {
.is_enabled = wm8400_ldo_is_enabled, .is_enabled = regulator_is_enabled_regmap,
.enable = wm8400_ldo_enable, .enable = regulator_enable_regmap,
.disable = wm8400_ldo_disable, .disable = regulator_disable_regmap,
.list_voltage = wm8400_ldo_list_voltage, .list_voltage = wm8400_ldo_list_voltage,
.get_voltage_sel = wm8400_ldo_get_voltage_sel, .get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage = wm8400_ldo_set_voltage, .set_voltage_sel = regulator_set_voltage_sel_regmap,
.map_voltage = wm8400_ldo_map_voltage,
}; };
static int wm8400_dcdc_is_enabled(struct regulator_dev *dev)
{
struct wm8400 *wm8400 = rdev_get_drvdata(dev);
int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
u16 val;
val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset);
return (val & WM8400_DC1_ENA) != 0;
}
static int wm8400_dcdc_enable(struct regulator_dev *dev)
{
struct wm8400 *wm8400 = rdev_get_drvdata(dev);
int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
WM8400_DC1_ENA, WM8400_DC1_ENA);
}
static int wm8400_dcdc_disable(struct regulator_dev *dev)
{
struct wm8400 *wm8400 = rdev_get_drvdata(dev);
int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
WM8400_DC1_ENA, 0);
}
static int wm8400_dcdc_list_voltage(struct regulator_dev *dev,
unsigned selector)
{
if (selector > WM8400_DC1_VSEL_MASK)
return -EINVAL;
return 850000 + (selector * 25000);
}
static int wm8400_dcdc_get_voltage_sel(struct regulator_dev *dev)
{
struct wm8400 *wm8400 = rdev_get_drvdata(dev);
u16 val;
int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset);
val &= WM8400_DC1_VSEL_MASK;
return val;
}
static int wm8400_dcdc_set_voltage(struct regulator_dev *dev,
int min_uV, int max_uV, unsigned *selector)
{
struct wm8400 *wm8400 = rdev_get_drvdata(dev);
u16 val;
int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
if (min_uV < 850000)
return -EINVAL;
val = DIV_ROUND_UP(min_uV - 850000, 25000);
if (850000 + (25000 * val) > max_uV)
return -EINVAL;
BUG_ON(850000 + (25000 * val) < min_uV);
*selector = val;
return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
WM8400_DC1_VSEL_MASK, val);
}
static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev)
{ {
struct wm8400 *wm8400 = rdev_get_drvdata(dev); struct wm8400 *wm8400 = rdev_get_drvdata(dev);
...@@ -258,12 +148,12 @@ static unsigned int wm8400_dcdc_get_optimum_mode(struct regulator_dev *dev, ...@@ -258,12 +148,12 @@ static unsigned int wm8400_dcdc_get_optimum_mode(struct regulator_dev *dev,
} }
static struct regulator_ops wm8400_dcdc_ops = { static struct regulator_ops wm8400_dcdc_ops = {
.is_enabled = wm8400_dcdc_is_enabled, .is_enabled = regulator_is_enabled_regmap,
.enable = wm8400_dcdc_enable, .enable = regulator_enable_regmap,
.disable = wm8400_dcdc_disable, .disable = regulator_disable_regmap,
.list_voltage = wm8400_dcdc_list_voltage, .list_voltage = regulator_list_voltage_linear,
.get_voltage_sel = wm8400_dcdc_get_voltage_sel, .get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage = wm8400_dcdc_set_voltage, .set_voltage_sel = regulator_set_voltage_sel_regmap,
.get_mode = wm8400_dcdc_get_mode, .get_mode = wm8400_dcdc_get_mode,
.set_mode = wm8400_dcdc_set_mode, .set_mode = wm8400_dcdc_set_mode,
.get_optimum_mode = wm8400_dcdc_get_optimum_mode, .get_optimum_mode = wm8400_dcdc_get_optimum_mode,
...@@ -274,7 +164,11 @@ static struct regulator_desc regulators[] = { ...@@ -274,7 +164,11 @@ static struct regulator_desc regulators[] = {
.name = "LDO1", .name = "LDO1",
.id = WM8400_LDO1, .id = WM8400_LDO1,
.ops = &wm8400_ldo_ops, .ops = &wm8400_ldo_ops,
.enable_reg = WM8400_LDO1_CONTROL,
.enable_mask = WM8400_LDO1_ENA,
.n_voltages = WM8400_LDO1_VSEL_MASK + 1, .n_voltages = WM8400_LDO1_VSEL_MASK + 1,
.vsel_reg = WM8400_LDO1_CONTROL,
.vsel_mask = WM8400_LDO1_VSEL_MASK,
.type = REGULATOR_VOLTAGE, .type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
...@@ -282,15 +176,23 @@ static struct regulator_desc regulators[] = { ...@@ -282,15 +176,23 @@ static struct regulator_desc regulators[] = {
.name = "LDO2", .name = "LDO2",
.id = WM8400_LDO2, .id = WM8400_LDO2,
.ops = &wm8400_ldo_ops, .ops = &wm8400_ldo_ops,
.enable_reg = WM8400_LDO2_CONTROL,
.enable_mask = WM8400_LDO2_ENA,
.n_voltages = WM8400_LDO2_VSEL_MASK + 1, .n_voltages = WM8400_LDO2_VSEL_MASK + 1,
.type = REGULATOR_VOLTAGE, .type = REGULATOR_VOLTAGE,
.vsel_reg = WM8400_LDO2_CONTROL,
.vsel_mask = WM8400_LDO2_VSEL_MASK,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
{ {
.name = "LDO3", .name = "LDO3",
.id = WM8400_LDO3, .id = WM8400_LDO3,
.ops = &wm8400_ldo_ops, .ops = &wm8400_ldo_ops,
.enable_reg = WM8400_LDO3_CONTROL,
.enable_mask = WM8400_LDO3_ENA,
.n_voltages = WM8400_LDO3_VSEL_MASK + 1, .n_voltages = WM8400_LDO3_VSEL_MASK + 1,
.vsel_reg = WM8400_LDO3_CONTROL,
.vsel_mask = WM8400_LDO3_VSEL_MASK,
.type = REGULATOR_VOLTAGE, .type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
...@@ -298,7 +200,11 @@ static struct regulator_desc regulators[] = { ...@@ -298,7 +200,11 @@ static struct regulator_desc regulators[] = {
.name = "LDO4", .name = "LDO4",
.id = WM8400_LDO4, .id = WM8400_LDO4,
.ops = &wm8400_ldo_ops, .ops = &wm8400_ldo_ops,
.enable_reg = WM8400_LDO4_CONTROL,
.enable_mask = WM8400_LDO4_ENA,
.n_voltages = WM8400_LDO4_VSEL_MASK + 1, .n_voltages = WM8400_LDO4_VSEL_MASK + 1,
.vsel_reg = WM8400_LDO4_CONTROL,
.vsel_mask = WM8400_LDO4_VSEL_MASK,
.type = REGULATOR_VOLTAGE, .type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
...@@ -306,7 +212,13 @@ static struct regulator_desc regulators[] = { ...@@ -306,7 +212,13 @@ static struct regulator_desc regulators[] = {
.name = "DCDC1", .name = "DCDC1",
.id = WM8400_DCDC1, .id = WM8400_DCDC1,
.ops = &wm8400_dcdc_ops, .ops = &wm8400_dcdc_ops,
.enable_reg = WM8400_DCDC1_CONTROL_1,
.enable_mask = WM8400_DC1_ENA_MASK,
.n_voltages = WM8400_DC1_VSEL_MASK + 1, .n_voltages = WM8400_DC1_VSEL_MASK + 1,
.vsel_reg = WM8400_DCDC1_CONTROL_1,
.vsel_mask = WM8400_DC1_VSEL_MASK,
.min_uV = 850000,
.uV_step = 25000,
.type = REGULATOR_VOLTAGE, .type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
...@@ -314,7 +226,13 @@ static struct regulator_desc regulators[] = { ...@@ -314,7 +226,13 @@ static struct regulator_desc regulators[] = {
.name = "DCDC2", .name = "DCDC2",
.id = WM8400_DCDC2, .id = WM8400_DCDC2,
.ops = &wm8400_dcdc_ops, .ops = &wm8400_dcdc_ops,
.enable_reg = WM8400_DCDC2_CONTROL_1,
.enable_mask = WM8400_DC1_ENA_MASK,
.n_voltages = WM8400_DC2_VSEL_MASK + 1, .n_voltages = WM8400_DC2_VSEL_MASK + 1,
.vsel_reg = WM8400_DCDC2_CONTROL_1,
.vsel_mask = WM8400_DC2_VSEL_MASK,
.min_uV = 850000,
.uV_step = 25000,
.type = REGULATOR_VOLTAGE, .type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
...@@ -329,6 +247,7 @@ static int __devinit wm8400_regulator_probe(struct platform_device *pdev) ...@@ -329,6 +247,7 @@ static int __devinit wm8400_regulator_probe(struct platform_device *pdev)
config.dev = &pdev->dev; config.dev = &pdev->dev;
config.init_data = pdev->dev.platform_data; config.init_data = pdev->dev.platform_data;
config.driver_data = wm8400; config.driver_data = wm8400;
config.regmap = wm8400->regmap;
rdev = regulator_register(&regulators[pdev->id], &config); rdev = regulator_register(&regulators[pdev->id], &config);
if (IS_ERR(rdev)) if (IS_ERR(rdev))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment