diff options
Diffstat (limited to 'drivers/regulator/tps80031-regulator.c')
| -rw-r--r-- | drivers/regulator/tps80031-regulator.c | 83 |
1 files changed, 32 insertions, 51 deletions
diff --git a/drivers/regulator/tps80031-regulator.c b/drivers/regulator/tps80031-regulator.c index b15d711bc8c..26aa6d9c308 100644 --- a/drivers/regulator/tps80031-regulator.c +++ b/drivers/regulator/tps80031-regulator.c @@ -115,7 +115,7 @@ static int tps80031_reg_is_enabled(struct regulator_dev *rdev) ri->rinfo->state_reg, ret); return ret; } - return ((reg_val & TPS80031_STATE_MASK) == TPS80031_STATE_ON); + return (reg_val & TPS80031_STATE_MASK) == TPS80031_STATE_ON; } static int tps80031_reg_enable(struct regulator_dev *rdev) @@ -238,12 +238,11 @@ static int tps80031_dcdc_get_voltage_sel(struct regulator_dev *rdev) return vsel & SMPS_VSEL_MASK; } -static int tps80031_ldo_set_voltage_sel(struct regulator_dev *rdev, - unsigned sel) +static int tps80031_ldo_list_voltage(struct regulator_dev *rdev, + unsigned int sel) { struct tps80031_regulator *ri = rdev_get_drvdata(rdev); struct device *parent = to_tps80031_dev(rdev); - int ret; /* Check for valid setting for TPS80031 or TPS80032-ES1.0 */ if ((ri->rinfo->desc.id == TPS80031_REGULATOR_LDO2) && @@ -260,28 +259,27 @@ static int tps80031_ldo_set_voltage_sel(struct regulator_dev *rdev, } } - ret = tps80031_write(parent, ri->rinfo->volt_id, - ri->rinfo->volt_reg, sel); - if (ret < 0) - dev_err(ri->dev, "Error in writing reg 0x%02x, e = %d\n", - ri->rinfo->volt_reg, ret); - return ret; + return regulator_list_voltage_linear(rdev, sel); } -static int tps80031_ldo_get_voltage_sel(struct regulator_dev *rdev) +static int tps80031_ldo_map_voltage(struct regulator_dev *rdev, + int min_uV, int max_uV) { struct tps80031_regulator *ri = rdev_get_drvdata(rdev); struct device *parent = to_tps80031_dev(rdev); - uint8_t vsel; - int ret; - ret = tps80031_read(parent, ri->rinfo->volt_id, - ri->rinfo->volt_reg, &vsel); - if (ret < 0) { - dev_err(ri->dev, "Error in writing the Voltage register\n"); - return ret; + /* Check for valid setting for TPS80031 or TPS80032-ES1.0 */ + if ((ri->rinfo->desc.id == TPS80031_REGULATOR_LDO2) && + (ri->device_flags & TRACK_MODE_ENABLE)) { + if (((tps80031_get_chip_info(parent) == TPS80031) || + ((tps80031_get_chip_info(parent) == TPS80032) && + (tps80031_get_pmu_version(parent) == 0x0)))) { + return regulator_map_voltage_iterate(rdev, min_uV, + max_uV); + } } - return vsel & rdev->desc->vsel_mask; + + return regulator_map_voltage_linear(rdev, min_uV, max_uV); } static int tps80031_vbus_is_enabled(struct regulator_dev *rdev) @@ -390,9 +388,10 @@ static struct regulator_ops tps80031_dcdc_ops = { }; static struct regulator_ops tps80031_ldo_ops = { - .list_voltage = regulator_list_voltage_linear, - .set_voltage_sel = tps80031_ldo_set_voltage_sel, - .get_voltage_sel = tps80031_ldo_get_voltage_sel, + .list_voltage = tps80031_ldo_list_voltage, + .map_voltage = tps80031_ldo_map_voltage, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, .enable = tps80031_reg_enable, .disable = tps80031_reg_disable, .is_enabled = tps80031_reg_is_enabled, @@ -459,6 +458,7 @@ static struct regulator_ops tps80031_ext_reg_ops = { .uV_step = 100000, \ .linear_min_sel = 1, \ .n_voltages = 25, \ + .vsel_reg = TPS80031_##_id##_CFG_VOLTAGE, \ .vsel_mask = LDO_VSEL_MASK, \ .enable_time = 500, \ }, \ @@ -680,6 +680,7 @@ static int tps80031_regulator_probe(struct platform_device *pdev) struct tps80031_regulator *pmic; struct regulator_dev *rdev; struct regulator_config config = { }; + struct tps80031 *tps80031_mfd = dev_get_drvdata(pdev->dev.parent); int ret; int num; @@ -692,10 +693,8 @@ static int tps80031_regulator_probe(struct platform_device *pdev) pmic = devm_kzalloc(&pdev->dev, TPS80031_REGULATOR_MAX * sizeof(*pmic), GFP_KERNEL); - if (!pmic) { - dev_err(&pdev->dev, "mem alloc for pmic failed\n"); + if (!pmic) return -ENOMEM; - } for (num = 0; num < TPS80031_REGULATOR_MAX; ++num) { tps_pdata = pdata->regulator_pdata[num]; @@ -707,6 +706,8 @@ static int tps80031_regulator_probe(struct platform_device *pdev) config.dev = &pdev->dev; config.init_data = NULL; config.driver_data = ri; + config.regmap = tps80031_mfd->regmap[ri->rinfo->volt_id]; + if (tps_pdata) { config.init_data = tps_pdata->reg_init_data; ri->config_flags = tps_pdata->config_flags; @@ -716,7 +717,7 @@ static int tps80031_regulator_probe(struct platform_device *pdev) if (ret < 0) { dev_err(&pdev->dev, "regulator config failed, e %d\n", ret); - goto fail; + return ret; } ret = tps80031_power_req_config(pdev->dev.parent, @@ -724,41 +725,22 @@ static int tps80031_regulator_probe(struct platform_device *pdev) if (ret < 0) { dev_err(&pdev->dev, "pwr_req config failed, err %d\n", ret); - goto fail; + return ret; } } - rdev = regulator_register(&ri->rinfo->desc, &config); - if (IS_ERR_OR_NULL(rdev)) { + rdev = devm_regulator_register(&pdev->dev, &ri->rinfo->desc, + &config); + if (IS_ERR(rdev)) { dev_err(&pdev->dev, "register regulator failed %s\n", ri->rinfo->desc.name); - ret = PTR_ERR(rdev); - goto fail; + return PTR_ERR(rdev); } ri->rdev = rdev; } platform_set_drvdata(pdev, pmic); return 0; -fail: - while (--num >= 0) { - ri = &pmic[num]; - regulator_unregister(ri->rdev); - } - return ret; -} - -static int tps80031_regulator_remove(struct platform_device *pdev) -{ - struct tps80031_regulator *pmic = platform_get_drvdata(pdev); - struct tps80031_regulator *ri = NULL; - int num; - - for (num = 0; num < TPS80031_REGULATOR_MAX; ++num) { - ri = &pmic[num]; - regulator_unregister(ri->rdev); - } - return 0; } static struct platform_driver tps80031_regulator_driver = { @@ -767,7 +749,6 @@ static struct platform_driver tps80031_regulator_driver = { .owner = THIS_MODULE, }, .probe = tps80031_regulator_probe, - .remove = tps80031_regulator_remove, }; static int __init tps80031_regulator_init(void) |
