diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/regulator/tps65090-regulator.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/drivers/regulator/tps65090-regulator.c b/drivers/regulator/tps65090-regulator.c index 577fbf8ffd77..caa89867e833 100644 --- a/drivers/regulator/tps65090-regulator.c +++ b/drivers/regulator/tps65090-regulator.c @@ -27,7 +27,7 @@ #include <linux/mfd/tps65090.h> #include <linux/regulator/tps65090-regulator.h> -struct tps65090_regulator { +struct tps65090_regulator_info { int id; /* Regulator register address.*/ u8 reg_en_reg; @@ -35,9 +35,12 @@ struct tps65090_regulator { /* used by regulator core */ struct regulator_desc desc; +}; - /* Device */ - struct device *dev; +struct tps65090_regulator { + struct tps65090_regulator_info *rinfo; + struct device *dev; + struct regulator_dev *rdev; }; static inline struct device *to_tps65090_dev(struct regulator_dev *rdev) @@ -52,13 +55,13 @@ static int tps65090_reg_is_enabled(struct regulator_dev *rdev) uint8_t control; int ret; - ret = tps65090_read(parent, ri->reg_en_reg, &control); + ret = tps65090_read(parent, ri->rinfo->reg_en_reg, &control); if (ret < 0) { dev_err(&rdev->dev, "Error in reading reg 0x%x\n", - ri->reg_en_reg); + ri->rinfo->reg_en_reg); return ret; } - return (((control >> ri->en_bit) & 1) == 1); + return (((control >> ri->rinfo->en_bit) & 1) == 1); } static int tps65090_reg_enable(struct regulator_dev *rdev) @@ -67,10 +70,11 @@ static int tps65090_reg_enable(struct regulator_dev *rdev) struct device *parent = to_tps65090_dev(rdev); int ret; - ret = tps65090_set_bits(parent, ri->reg_en_reg, ri->en_bit); + ret = tps65090_set_bits(parent, ri->rinfo->reg_en_reg, + ri->rinfo->en_bit); if (ret < 0) dev_err(&rdev->dev, "Error in updating reg 0x%x\n", - ri->reg_en_reg); + ri->rinfo->reg_en_reg); return ret; } @@ -80,10 +84,11 @@ static int tps65090_reg_disable(struct regulator_dev *rdev) struct device *parent = to_tps65090_dev(rdev); int ret; - ret = tps65090_clr_bits(parent, ri->reg_en_reg, ri->en_bit); + ret = tps65090_clr_bits(parent, ri->rinfo->reg_en_reg, + ri->rinfo->en_bit); if (ret < 0) dev_err(&rdev->dev, "Error in updating reg 0x%x\n", - ri->reg_en_reg); + ri->rinfo->reg_en_reg); return ret; } @@ -108,7 +113,7 @@ static struct regulator_ops tps65090_ops = { }, \ } -static struct tps65090_regulator TPS65090_regulator[] = { +static struct tps65090_regulator_info TPS65090_regulator_info[] = { tps65090_REG(DCDC1, 12, 0, tps65090_ops), tps65090_REG(DCDC2, 13, 0, tps65090_ops), tps65090_REG(DCDC3, 14, 0, tps65090_ops), @@ -121,21 +126,22 @@ static struct tps65090_regulator TPS65090_regulator[] = { tps65090_REG(FET7, 21, 0, tps65090_ops), }; -static inline struct tps65090_regulator *find_regulator_info(int id) +static inline struct tps65090_regulator_info *find_regulator_info(int id) { - struct tps65090_regulator *ri; + struct tps65090_regulator_info *rinfo; int i; - for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) { - ri = &TPS65090_regulator[i]; - if (ri->desc.id == id) - return ri; + for (i = 0; i < ARRAY_SIZE(TPS65090_regulator_info); i++) { + rinfo = &TPS65090_regulator_info[i]; + if (rinfo->desc.id == id) + return rinfo; } return NULL; } static int __devinit tps65090_regulator_probe(struct platform_device *pdev) { + struct tps65090_regulator_info *rinfo = NULL; struct tps65090_regulator *ri = NULL; struct regulator_dev *rdev; struct tps65090_regulator_platform_data *tps_pdata; @@ -143,31 +149,40 @@ static int __devinit tps65090_regulator_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "Probing regulator %d\n", id); - ri = find_regulator_info(id); - if (ri == NULL) { + rinfo = find_regulator_info(id); + if (rinfo == NULL) { dev_err(&pdev->dev, "invalid regulator ID specified\n"); return -EINVAL; } tps_pdata = pdev->dev.platform_data; + + ri = devm_kzalloc(&pdev->dev, sizeof(*ri), GFP_KERNEL); + if (!ri) { + dev_err(&pdev->dev, "mem alloc for ri failed\n"); + return -ENOMEM; + } + ri->dev = &pdev->dev; + ri->rinfo = rinfo; - rdev = regulator_register(&ri->desc, &pdev->dev, + rdev = regulator_register(&ri->rinfo->desc, &pdev->dev, &tps_pdata->regulator, ri); if (IS_ERR(rdev)) { dev_err(&pdev->dev, "failed to register regulator %s\n", - ri->desc.name); + ri->rinfo->desc.name); return PTR_ERR(rdev); } + ri->rdev = rdev; - platform_set_drvdata(pdev, rdev); + platform_set_drvdata(pdev, ri); return 0; } static int __devexit tps65090_regulator_remove(struct platform_device *pdev) { - struct regulator_dev *rdev = platform_get_drvdata(pdev); + struct tps65090_regulator *ri = platform_get_drvdata(pdev); - regulator_unregister(rdev); + regulator_unregister(ri->rdev); return 0; } |