regulator: ab8500: Prepare the driver for additional platforms

More platforms are to be supported by the AB8500 regulator driver,
so in this patch we prepare for their arrival. Instead of using
the AB8500 settings blindly, we provide an infrastructure where
adding a new platform is as easy as providing a couple of platform
specific data structures.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
Lee Jones 2013-03-28 16:11:10 +00:00 committed by Mark Brown
parent 742a73259d
commit b54969ac40
1 changed files with 49 additions and 27 deletions

View File

@ -774,46 +774,47 @@ static struct ab8500_reg_init ab8500_reg_init[] = {
}; };
static int ab8500_regulator_init_registers(struct platform_device *pdev, static int ab8500_regulator_init_registers(struct platform_device *pdev,
struct ab8500_reg_init *reg_init,
int id, int mask, int value) int id, int mask, int value)
{ {
int err; int err;
BUG_ON(value & ~mask); BUG_ON(value & ~mask);
BUG_ON(mask & ~ab8500_reg_init[id].mask); BUG_ON(mask & ~reg_init[id].mask);
/* initialize register */ /* initialize register */
err = abx500_mask_and_set_register_interruptible( err = abx500_mask_and_set_register_interruptible(
&pdev->dev, &pdev->dev,
ab8500_reg_init[id].bank, reg_init[id].bank,
ab8500_reg_init[id].addr, reg_init[id].addr,
mask, value); mask, value);
if (err < 0) { if (err < 0) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"Failed to initialize 0x%02x, 0x%02x.\n", "Failed to initialize 0x%02x, 0x%02x.\n",
ab8500_reg_init[id].bank, reg_init[id].bank,
ab8500_reg_init[id].addr); reg_init[id].addr);
return err; return err;
} }
dev_vdbg(&pdev->dev, dev_vdbg(&pdev->dev,
" init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", " init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
ab8500_reg_init[id].bank, reg_init[id].bank,
ab8500_reg_init[id].addr, reg_init[id].addr,
mask, value); mask, value);
return 0; return 0;
} }
static int ab8500_regulator_register(struct platform_device *pdev, static int ab8500_regulator_register(struct platform_device *pdev,
struct regulator_init_data *init_data, struct regulator_init_data *init_data,
int id, struct ab8500_regulator_info *regulator_info,
struct device_node *np) int id, struct device_node *np)
{ {
struct ab8500_regulator_info *info = NULL; struct ab8500_regulator_info *info = NULL;
struct regulator_config config = { }; struct regulator_config config = { };
int err; int err;
/* assign per-regulator data */ /* assign per-regulator data */
info = &ab8500_regulator_info[id]; info = &regulator_info[id];
info->dev = &pdev->dev; info->dev = &pdev->dev;
config.dev = &pdev->dev; config.dev = &pdev->dev;
@ -839,7 +840,7 @@ static int ab8500_regulator_register(struct platform_device *pdev,
info->desc.name); info->desc.name);
/* when we fail, un-register all earlier regulators */ /* when we fail, un-register all earlier regulators */
while (--id >= 0) { while (--id >= 0) {
info = &ab8500_regulator_info[id]; info = &regulator_info[id];
regulator_unregister(info->regulator); regulator_unregister(info->regulator);
} }
return err; return err;
@ -848,7 +849,7 @@ static int ab8500_regulator_register(struct platform_device *pdev,
return 0; return 0;
} }
static struct of_regulator_match ab8500_regulator_matches[] = { static struct of_regulator_match ab8500_regulator_match[] = {
{ .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, }, { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
{ .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, }, { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
{ .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, }, { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
@ -862,14 +863,18 @@ static struct of_regulator_match ab8500_regulator_matches[] = {
}; };
static int static int
ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np) ab8500_regulator_of_probe(struct platform_device *pdev,
struct ab8500_regulator_info *regulator_info,
int regulator_info_size,
struct of_regulator_match *match,
struct device_node *np)
{ {
int err, i; int err, i;
for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { for (i = 0; i < regulator_info_size; i++) {
err = ab8500_regulator_register( err = ab8500_regulator_register(
pdev, ab8500_regulator_matches[i].init_data, pdev, match[i].init_data, regulator_info,
i, ab8500_regulator_matches[i].of_node); i, match[i].of_node);
if (err) if (err)
return err; return err;
} }
@ -881,21 +886,32 @@ static int ab8500_regulator_probe(struct platform_device *pdev)
{ {
struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct of_regulator_match *match;
struct ab8500_platform_data *ppdata; struct ab8500_platform_data *ppdata;
struct ab8500_regulator_platform_data *pdata; struct ab8500_regulator_platform_data *pdata;
int i, err; int i, err;
struct ab8500_regulator_info *regulator_info;
int regulator_info_size;
struct ab8500_reg_init *reg_init;
int reg_init_size;
regulator_info = ab8500_regulator_info;
regulator_info_size = ARRAY_SIZE(ab8500_regulator_info);
reg_init = ab8500_reg_init;
reg_init_size = AB8500_NUM_REGULATOR_REGISTERS;
match = ab8500_regulator_match;
match_size = ARRAY_SIZE(ab8500_regulator_match)
if (np) { if (np) {
err = of_regulator_match(&pdev->dev, np, err = of_regulator_match(&pdev->dev, np, match, match_size);
ab8500_regulator_matches,
ARRAY_SIZE(ab8500_regulator_matches));
if (err < 0) { if (err < 0) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"Error parsing regulator init data: %d\n", err); "Error parsing regulator init data: %d\n", err);
return err; return err;
} }
err = ab8500_regulator_of_probe(pdev, np); err = ab8500_regulator_of_probe(pdev, regulator_info,
regulator_info_size, match, np);
return err; return err;
} }
@ -917,7 +933,7 @@ static int ab8500_regulator_probe(struct platform_device *pdev)
} }
/* make sure the platform data has the correct size */ /* make sure the platform data has the correct size */
if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) { if (pdata->num_regulator != regulator_info_size) {
dev_err(&pdev->dev, "Configuration error: size mismatch.\n"); dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
return -EINVAL; return -EINVAL;
} }
@ -938,7 +954,7 @@ static int ab8500_regulator_probe(struct platform_device *pdev)
/* check for configuration errors */ /* check for configuration errors */
BUG_ON(id >= AB8500_NUM_REGULATOR_REGISTERS); BUG_ON(id >= AB8500_NUM_REGULATOR_REGISTERS);
err = ab8500_regulator_init_registers(pdev, id, mask, value); err = ab8500_regulator_init_registers(pdev, reg_init, id, mask, value);
if (err < 0) if (err < 0)
return err; return err;
} }
@ -949,8 +965,9 @@ static int ab8500_regulator_probe(struct platform_device *pdev)
return err; return err;
/* register all regulators */ /* register all regulators */
for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { for (i = 0; i < regulator_info_size; i++) {
err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL); err = ab8500_regulator_register(pdev, &pdata->regulator[i],
regulator_info, i, NULL);
if (err < 0) if (err < 0)
return err; return err;
} }
@ -961,10 +978,15 @@ static int ab8500_regulator_probe(struct platform_device *pdev)
static int ab8500_regulator_remove(struct platform_device *pdev) static int ab8500_regulator_remove(struct platform_device *pdev)
{ {
int i, err; int i, err;
struct ab8500_regulator_info *regulator_info;
int regulator_info_size;
for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { regulator_info = ab8500_regulator_info;
regulator_info_size = ARRAY_SIZE(ab8500_regulator_info);
for (i = 0; i < regulator_info_size; i++) {
struct ab8500_regulator_info *info = NULL; struct ab8500_regulator_info *info = NULL;
info = &ab8500_regulator_info[i]; info = &regulator_info[i];
dev_vdbg(rdev_get_dev(info->regulator), dev_vdbg(rdev_get_dev(info->regulator),
"%s-remove\n", info->desc.name); "%s-remove\n", info->desc.name);