diff options
-rw-r--r-- | arch/arm/mach-tegra/board-enterprise-power.c | 143 | ||||
-rw-r--r-- | drivers/regulator/tps80031-regulator.c | 132 | ||||
-rw-r--r-- | include/linux/mfd/tps80031.h | 2 | ||||
-rw-r--r-- | include/linux/regulator/tps80031-regulator.h | 2 |
4 files changed, 167 insertions, 112 deletions
diff --git a/arch/arm/mach-tegra/board-enterprise-power.c b/arch/arm/mach-tegra/board-enterprise-power.c index b457cda6ace0..f07e61c95287 100644 --- a/arch/arm/mach-tegra/board-enterprise-power.c +++ b/arch/arm/mach-tegra/board-enterprise-power.c @@ -233,7 +233,7 @@ static struct regulator_consumer_supply tps80031_battery_charge_supply[] = { REGULATOR_SUPPLY("usb_bat_chg", NULL), }; -#define TPS_PDATA_INIT(_id, _sname, _minmv, _maxmv, _supply_reg, _always_on, \ +#define TPS_PDATA_INIT(_reg_id, _id, _sname, _minmv, _maxmv, _supply_reg, _always_on, \ _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply, \ _flags, _ectrl, _delay) \ static struct regulator_init_data reg_idata_##_id##_##_sname = { \ @@ -256,6 +256,7 @@ static struct regulator_consumer_supply tps80031_battery_charge_supply[] = { }; \ static struct tps80031_regulator_platform_data pdata_##_id##_##_sname = { \ .reg_init_data = ®_idata_##_id##_##_sname, \ + .regulator_id = TPS80031_REGULATOR_##_reg_id, \ .init_uV = _init_uV * 1000, \ .init_enable = _init_enable, \ .init_apply = _init_apply, \ @@ -264,31 +265,31 @@ static struct regulator_consumer_supply tps80031_battery_charge_supply[] = { .delay_us = _delay, \ } -TPS_PDATA_INIT(vio, a02, 600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0); -TPS_PDATA_INIT(vio, a03, 600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0); -TPS_PDATA_INIT(smps1, common, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ2 | PWR_OFF_ON_SLEEP, 0); -TPS_PDATA_INIT(smps2, common, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(smps3, common, 600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0); -TPS_PDATA_INIT(smps4, a02, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(smps4, a03, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(ldo1, a02, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, 0, 0); -TPS_PDATA_INIT(ldo1, a03, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(ldo2, common, 1000, 1000, 0, 1, 1, 1, -1, 0, 0, 0, 0, 0); -TPS_PDATA_INIT(ldo3, common, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_OFF_ON_SLEEP, 0); -TPS_PDATA_INIT(ldo4, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0); -TPS_PDATA_INIT(ldo4, a03, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(ldo5, common, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0); -TPS_PDATA_INIT(ldo6, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(ldo6, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(ldo7, a02, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(ldo7, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(ldoln, a02, 1000, 3300, tps80031_rails(smps3), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(ldoln, a03, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(ldousb, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, USBLDO_INPUT_VSYS, PWR_OFF_ON_SLEEP, 0); -TPS_PDATA_INIT(ldousb, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, USBLDO_INPUT_VSYS, PWR_REQ_INPUT_PREQ1, 0); -TPS_PDATA_INIT(vana, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0); -TPS_PDATA_INIT(vana, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_OFF_ON_SLEEP, 0); -TPS_PDATA_INIT(vbus, common, 0, 5000, 0, 0, 0, 0, -1, 0, 0, (VBUS_SW_ONLY | VBUS_DISCHRG_EN_PDN), 0, 100000); +TPS_PDATA_INIT(VIO, vio, a02, 600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0); +TPS_PDATA_INIT(VIO, vio, a03, 600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0); +TPS_PDATA_INIT(SMPS1, smps1, common, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ2 | PWR_OFF_ON_SLEEP, 0); +TPS_PDATA_INIT(SMPS2, smps2, common, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(SMPS3, smps3, common, 600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0); +TPS_PDATA_INIT(SMPS4, smps4, a02, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(SMPS4, smps4, a03, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(LDO1, ldo1, a02, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, 0, 0); +TPS_PDATA_INIT(LDO1, ldo1, a03, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(LDO2, ldo2, common, 1000, 1000, 0, 1, 1, 1, -1, 0, 0, 0, 0, 0); +TPS_PDATA_INIT(LDO3, ldo3, common, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_OFF_ON_SLEEP, 0); +TPS_PDATA_INIT(LDO4, ldo4, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0); +TPS_PDATA_INIT(LDO4, ldo4, a03, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(LDO5, ldo5, common, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0); +TPS_PDATA_INIT(LDO6, ldo6, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(LDO6, ldo6, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(LDO7, ldo7, a02, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(LDO7, ldo7, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(LDOLN, ldoln, a02, 1000, 3300, tps80031_rails(smps3), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(LDOLN, ldoln, a03, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(LDOUSB, ldousb, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, USBLDO_INPUT_VSYS, PWR_OFF_ON_SLEEP, 0); +TPS_PDATA_INIT(LDOUSB, ldousb, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, USBLDO_INPUT_VSYS, PWR_REQ_INPUT_PREQ1, 0); +TPS_PDATA_INIT(VANA, vana, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0); +TPS_PDATA_INIT(VANA, vana, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_OFF_ON_SLEEP, 0); +TPS_PDATA_INIT(VBUS, vbus, common, 0, 5000, 0, 0, 0, 0, -1, 0, 0, (VBUS_SW_ONLY | VBUS_DISCHRG_EN_PDN), 0, 100000); static struct tps80031_rtc_platform_data rtc_data = { .irq = ENT_TPS80031_IRQ_BASE + TPS80031_INT_RTC_ALARM, @@ -339,12 +340,6 @@ static struct tps80031_bg_platform_data battery_gauge_data = { .platform_data = &rtc_data, \ } -#define TPS_REG(_id, _data, _sname) \ - { \ - .id = TPS80031_REGULATOR_##_id, \ - .name = "tps80031-regulator", \ - .platform_data = &pdata_##_data##_##_sname, \ - } #define TPS_BATTERY() \ { \ .name = "tps80031-charger", \ @@ -361,45 +356,56 @@ static struct tps80031_bg_platform_data battery_gauge_data = { } #define TPS80031_DEVS_COMMON \ - TPS_REG(SMPS1, smps1, common), \ - TPS_REG(SMPS2, smps2, common), \ - TPS_REG(SMPS3, smps3, common), \ - TPS_REG(LDO2, ldo2, common), \ - TPS_REG(LDO3, ldo3, common), \ - TPS_REG(LDO5, ldo5, common), \ - TPS_REG(VBUS, vbus, common), \ TPS_RTC(), \ TPS_BATTERY(), \ TPS_BATTERY_GAUGE(), \ TPS_GPADC() -static struct tps80031_subdev_info tps80031_devs_a02[] = { - TPS_REG(VIO, vio, a02), - TPS80031_DEVS_COMMON, - TPS_REG(SMPS4, smps4, a02), - TPS_REG(LDO1, ldo1, a02), - TPS_REG(LDO4, ldo4, a02), - TPS_REG(LDO6, ldo6, a02), - TPS_REG(LDO7, ldo7, a02), - TPS_REG(LDOLN, ldoln, a02), - TPS_REG(LDOUSB, ldousb, a02), - TPS_REG(VANA, vana, a02), - +static struct tps80031_subdev_info tps80031_devs[] = { + TPS_RTC(), + TPS_BATTERY(), + TPS_BATTERY_GAUGE(), + TPS_GPADC() }; -static struct tps80031_subdev_info tps80031_devs_a03[] = { - TPS_REG(VIO, vio, a03), - TPS80031_DEVS_COMMON, - TPS_REG(SMPS4, smps4, a03), - TPS_REG(LDO1, ldo1, a03), - TPS_REG(LDO4, ldo4, a03), - TPS_REG(LDO6, ldo6, a03), - TPS_REG(LDO7, ldo7, a03), - TPS_REG(LDOLN, ldoln, a03), - TPS_REG(LDOUSB, ldousb, a03), - TPS_REG(VANA, vana, a03), - +#define TPS_REG_PDATA(_id, _sname) &pdata_##_id##_##_sname +static struct tps80031_regulator_platform_data *tps80031_reg_pdata_a02[] = { + TPS_REG_PDATA(vio, a02), + TPS_REG_PDATA(smps1, common), + TPS_REG_PDATA(smps2, common), + TPS_REG_PDATA(smps3, common), + TPS_REG_PDATA(ldo2, common), + TPS_REG_PDATA(ldo3, common), + TPS_REG_PDATA(ldo5, common), + TPS_REG_PDATA(vbus, common), + TPS_REG_PDATA(smps4, a02), + TPS_REG_PDATA(ldo1, a02), + TPS_REG_PDATA(ldo4, a02), + TPS_REG_PDATA(ldo6, a02), + TPS_REG_PDATA(ldo7, a02), + TPS_REG_PDATA(ldoln, a02), + TPS_REG_PDATA(ldousb, a02), + TPS_REG_PDATA(vana, a02), +}; + +static struct tps80031_regulator_platform_data *tps80031_reg_pdata_a03[] = { + TPS_REG_PDATA(vio, a03), + TPS_REG_PDATA(smps1, common), + TPS_REG_PDATA(smps2, common), + TPS_REG_PDATA(smps3, common), + TPS_REG_PDATA(ldo2, common), + TPS_REG_PDATA(ldo3, common), + TPS_REG_PDATA(ldo5, common), + TPS_REG_PDATA(vbus, common), + TPS_REG_PDATA(smps4, a03), + TPS_REG_PDATA(ldo1, a03), + TPS_REG_PDATA(ldo4, a03), + TPS_REG_PDATA(ldo6, a03), + TPS_REG_PDATA(ldo7, a03), + TPS_REG_PDATA(ldoln, a03), + TPS_REG_PDATA(ldousb, a03), + TPS_REG_PDATA(vana, a03), }; static struct tps80031_clk32k_init_data clk32k_idata[] = { @@ -752,12 +758,15 @@ int __init enterprise_regulator_init(void) battery_gauge_data.battery_present = 0; } + tps_platform.num_subdevs = ARRAY_SIZE(tps80031_devs); + tps_platform.subdevs = tps80031_devs; + if (board_info.fab < BOARD_FAB_A03) { - tps_platform.num_subdevs = ARRAY_SIZE(tps80031_devs_a02); - tps_platform.subdevs = tps80031_devs_a02; + tps_platform.num_regulator_pdata = ARRAY_SIZE(tps80031_reg_pdata_a02); + tps_platform.regulator_pdata = tps80031_reg_pdata_a02; } else { - tps_platform.num_subdevs = ARRAY_SIZE(tps80031_devs_a03); - tps_platform.subdevs = tps80031_devs_a03; + tps_platform.num_regulator_pdata = ARRAY_SIZE(tps80031_reg_pdata_a03); + tps_platform.regulator_pdata = tps80031_reg_pdata_a03; tps_platform.pupd_init_data = pupd_idata; tps_platform.pupd_init_data_size = ARRAY_SIZE(pupd_idata); tps_platform.gpio_init_data = gpio_idata_a03; diff --git a/drivers/regulator/tps80031-regulator.c b/drivers/regulator/tps80031-regulator.c index 570a178bbfaf..6995ea2884e5 100644 --- a/drivers/regulator/tps80031-regulator.c +++ b/drivers/regulator/tps80031-regulator.c @@ -1026,78 +1026,120 @@ static inline int tps80031_cache_regulator_register(struct device *parent, static int __devinit tps80031_regulator_probe(struct platform_device *pdev) { + struct tps80031_platform_data *pdata = dev_get_platdata(pdev->dev.parent); + struct tps80031_regulator_platform_data *tps_pdata; struct tps80031_regulator_info *rinfo; - struct tps80031_regulator *ri = NULL; + struct tps80031_regulator *ri; + struct tps80031_regulator *pmic; struct regulator_dev *rdev; - struct tps80031_regulator_platform_data *tps_pdata; - int id = pdev->id; - int err; - - dev_dbg(&pdev->dev, "Probing reulator %d\n", id); + int id; + int ret; + int num; - rinfo = find_regulator_info(id); - if (!rinfo) { - dev_err(&pdev->dev, "invalid regulator ID specified\n"); + if (!pdata || !pdata->num_regulator_pdata) { + dev_err(&pdev->dev, "Number of regulator is 0\n"); return -EINVAL; } - ri = devm_kzalloc(&pdev->dev, sizeof(*ri), GFP_KERNEL); - if (!ri) { - dev_err(&pdev->dev, "mem alloc for ri failed\n"); + pmic = devm_kzalloc(&pdev->dev, + pdata->num_regulator_pdata * sizeof(*pmic), GFP_KERNEL); + if (!pmic) { + dev_err(&pdev->dev, "mem alloc for pmic failed\n"); return -ENOMEM; } - ri->rinfo = rinfo; - tps_pdata = pdev->dev.platform_data; - ri->dev = &pdev->dev; - if (tps_pdata->delay_us > 0) - ri->delay = tps_pdata->delay_us; - else - ri->delay = rinfo->delay; - ri->tolerance_uv = tps_pdata->tolerance_uv; + for (num = 0; num < pdata->num_regulator_pdata; ++num) { + tps_pdata = pdata->regulator_pdata[num]; + if (!tps_pdata->reg_init_data) { + dev_err(&pdev->dev, + "No regulator init data for index %d\n", num); + ret = -EINVAL; + goto fail; + } - check_smps_mode_mult(pdev->dev.parent, ri); - ri->platform_flags = tps_pdata->flags; - ri->ext_ctrl_flag = tps_pdata->ext_ctrl_flag; + id = tps_pdata->regulator_id; + rinfo = find_regulator_info(id); + if (!rinfo) { + dev_err(&pdev->dev, "invalid regulator ID specified\n"); + ret = -EINVAL; + goto fail; + } - err = tps80031_cache_regulator_register(pdev->dev.parent, ri); - if (err) { - dev_err(&pdev->dev, "Register access for caching is failed\n"); - return err; - } - err = tps80031_regulator_preinit(pdev->dev.parent, ri, tps_pdata); - if (err) - return err; + ri = &pmic[num]; + ri->rinfo = rinfo; + ri->dev = &pdev->dev; + if (tps_pdata->delay_us) + ri->delay = tps_pdata->delay_us; + else + ri->delay = rinfo->delay; + ri->tolerance_uv = tps_pdata->tolerance_uv; + + check_smps_mode_mult(pdev->dev.parent, ri); + ri->platform_flags = tps_pdata->flags; + ri->ext_ctrl_flag = tps_pdata->ext_ctrl_flag; + + ret = tps80031_cache_regulator_register(pdev->dev.parent, ri); + if (ret < 0) { + dev_err(&pdev->dev, + "Register cache failed, err %d\n", ret); + goto fail; + } + ret = tps80031_regulator_preinit(pdev->dev.parent, ri, tps_pdata); + if (ret < 0) { + dev_err(&pdev->dev, + "regulator preinit failed, err %d\n", ret); + goto fail; + } - err = tps80031_power_req_config(pdev->dev.parent, ri, tps_pdata); - if (err) - return err; + ret = tps80031_power_req_config(pdev->dev.parent, ri, tps_pdata); + if (ret < 0) { + dev_err(&pdev->dev, + "power req config failed, err %d\n", ret); + goto fail; + } - rdev = regulator_register(&ri->rinfo->desc, &pdev->dev, + rdev = regulator_register(&ri->rinfo->desc, &pdev->dev, tps_pdata->reg_init_data, ri); - if (IS_ERR_OR_NULL(rdev)) { - dev_err(&pdev->dev, "failed to register regulator %s\n", - ri->rinfo->desc.name); - return PTR_ERR(rdev); + if (IS_ERR_OR_NULL(rdev)) { + dev_err(&pdev->dev, + "register regulator failed %s\n", + ri->rinfo->desc.name); + ret = PTR_ERR(rdev); + goto fail; + } + ri->rdev = rdev; } - ri->rdev = rdev; - - platform_set_drvdata(pdev, ri); + platform_set_drvdata(pdev, pmic); return 0; +fail: + while(--num >= 0) { + ri = &pmic[num]; + regulator_unregister(ri->rdev); + } + return ret; } static int __devexit tps80031_regulator_remove(struct platform_device *pdev) { - struct tps80031_regulator *ri = platform_get_drvdata(pdev); + struct tps80031_platform_data *pdata = pdev->dev.parent->platform_data; + struct tps80031_regulator *pmic = platform_get_drvdata(pdev); + struct tps80031_regulator *ri = NULL; + int num; - regulator_unregister(ri->rdev); + if (!pdata || !pdata->num_regulator_pdata) + return 0; + + for (num = 0; num < pdata->num_regulator_pdata; ++num) { + ri = &pmic[num]; + regulator_unregister(ri->rdev); + } return 0; } static struct platform_driver tps80031_regulator_driver = { .driver = { - .name = "tps80031-regulator", + .name = "tps80031-regulators", .owner = THIS_MODULE, }, .probe = tps80031_regulator_probe, diff --git a/include/linux/mfd/tps80031.h b/include/linux/mfd/tps80031.h index b3b9480ce596..974fc0db0ff2 100644 --- a/include/linux/mfd/tps80031.h +++ b/include/linux/mfd/tps80031.h @@ -197,6 +197,8 @@ struct tps80031_platform_data { bool use_power_off; struct tps80031_pupd_init_data *pupd_init_data; int pupd_init_data_size; + struct tps80031_regulator_platform_data **regulator_pdata; + int num_regulator_pdata; }; struct tps80031_bg_platform_data { diff --git a/include/linux/regulator/tps80031-regulator.h b/include/linux/regulator/tps80031-regulator.h index 4058f7cfa27a..97fdf34c1b6e 100644 --- a/include/linux/regulator/tps80031-regulator.h +++ b/include/linux/regulator/tps80031-regulator.h @@ -66,6 +66,7 @@ enum { /* * struct tps80031_regulator_platform_data - tps80031 regulator platform data. * + * @regulator_id" Regulator ID. * @reg_init_data: The regulator init data. * @init_uV: initial micro volts which need to be set. * @init_enable: Enable or do not enable the rails during initialization. @@ -80,6 +81,7 @@ enum { */ struct tps80031_regulator_platform_data { + int regulator_id; struct regulator_init_data *reg_init_data; int init_uV; unsigned init_enable:1; |