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>
};
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 err;
BUG_ON(value & ~mask);
int id, int mask, int value)
{
int err;
BUG_ON(value & ~mask);
- BUG_ON(mask & ~ab8500_reg_init[id].mask);
+ BUG_ON(mask & ~reg_init[id].mask);
/* initialize register */
err = abx500_mask_and_set_register_interruptible(
&pdev->dev,
/* initialize register */
err = abx500_mask_and_set_register_interruptible(
&pdev->dev,
- ab8500_reg_init[id].bank,
- ab8500_reg_init[id].addr,
+ reg_init[id].bank,
+ reg_init[id].addr,
mask, value);
if (err < 0) {
dev_err(&pdev->dev,
"Failed to initialize 0x%02x, 0x%02x.\n",
mask, value);
if (err < 0) {
dev_err(&pdev->dev,
"Failed to initialize 0x%02x, 0x%02x.\n",
- ab8500_reg_init[id].bank,
- ab8500_reg_init[id].addr);
+ reg_init[id].bank,
+ reg_init[id].addr);
return err;
}
dev_vdbg(&pdev->dev,
" init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
return err;
}
dev_vdbg(&pdev->dev,
" init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
- ab8500_reg_init[id].bank,
- ab8500_reg_init[id].addr,
+ reg_init[id].bank,
+ reg_init[id].addr,
mask, value);
return 0;
}
static int ab8500_regulator_register(struct platform_device *pdev,
mask, value);
return 0;
}
static int ab8500_regulator_register(struct platform_device *pdev,
- struct regulator_init_data *init_data,
- int id,
- struct device_node *np)
+ struct regulator_init_data *init_data,
+ struct ab8500_regulator_info *regulator_info,
+ int id, struct device_node *np)
{
struct ab8500_regulator_info *info = NULL;
struct regulator_config config = { };
int err;
/* assign per-regulator data */
{
struct ab8500_regulator_info *info = NULL;
struct regulator_config config = { };
int err;
/* assign per-regulator data */
- info = &ab8500_regulator_info[id];
+ info = ®ulator_info[id];
info->dev = &pdev->dev;
config.dev = &pdev->dev;
info->dev = &pdev->dev;
config.dev = &pdev->dev;
info->desc.name);
/* when we fail, un-register all earlier regulators */
while (--id >= 0) {
info->desc.name);
/* when we fail, un-register all earlier regulators */
while (--id >= 0) {
- info = &ab8500_regulator_info[id];
+ info = ®ulator_info[id];
regulator_unregister(info->regulator);
}
return err;
regulator_unregister(info->regulator);
}
return err;
-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_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
{ .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
{ .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
{ .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
{ .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
-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)
- 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,
- i, ab8500_regulator_matches[i].of_node);
+ pdev, match[i].init_data, regulator_info,
+ i, match[i].of_node);
{
struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
struct device_node *np = pdev->dev.of_node;
{
struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
struct device_node *np = pdev->dev.of_node;
+ struct of_regulator_match *match;
struct ab8500_platform_data *ppdata;
struct ab8500_regulator_platform_data *pdata;
int i, err;
struct ab8500_platform_data *ppdata;
struct ab8500_regulator_platform_data *pdata;
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)
- err = of_regulator_match(&pdev->dev, np,
- ab8500_regulator_matches,
- ARRAY_SIZE(ab8500_regulator_matches));
+ err = of_regulator_match(&pdev->dev, np, match, match_size);
if (err < 0) {
dev_err(&pdev->dev,
"Error parsing regulator init data: %d\n", err);
return err;
}
if (err < 0) {
dev_err(&pdev->dev,
"Error parsing regulator init data: %d\n", err);
return err;
}
- err = ab8500_regulator_of_probe(pdev, np);
+ err = ab8500_regulator_of_probe(pdev, regulator_info,
+ regulator_info_size, match, np);
}
/* 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");
return -EINVAL;
}
dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
return -EINVAL;
}
/* check for configuration errors */
BUG_ON(id >= AB8500_NUM_REGULATOR_REGISTERS);
/* check for configuration errors */
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)
return err;
}
if (err < 0)
return err;
}
return err;
/* register all regulators */
return err;
/* register all regulators */
- for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
- err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL);
+ for (i = 0; i < regulator_info_size; i++) {
+ err = ab8500_regulator_register(pdev, &pdata->regulator[i],
+ regulator_info, i, NULL);
if (err < 0)
return err;
}
if (err < 0)
return err;
}
static int ab8500_regulator_remove(struct platform_device *pdev)
{
int i, err;
static int ab8500_regulator_remove(struct platform_device *pdev)
{
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 = ®ulator_info[i];
dev_vdbg(rdev_get_dev(info->regulator),
"%s-remove\n", info->desc.name);
dev_vdbg(rdev_get_dev(info->regulator),
"%s-remove\n", info->desc.name);