diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-21 21:34:56 +0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-21 21:34:56 +0400 |
commit | d15d76448bb58c7832e954b6a8f1e301720b7866 (patch) | |
tree | 7891c9e0779f5df33840be9cdba1f0331459e97c /drivers/regulator/tps6507x-regulator.c | |
parent | 0c2fe82a9b106f1c03719783134360586d718a69 (diff) | |
parent | 4992fa1fd425f1934f503ffa96b68e235b89db9a (diff) | |
download | linux-d15d76448bb58c7832e954b6a8f1e301720b7866.tar.xz |
Merge tag 'regulator-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
Pull regulator updates for 3.4 from Mark Brown:
"This has been a fairly quiet release from a regulator point of view,
the only real framework features added were devm support and a
convenience helper for setting up fixed voltage regulators.
We also added a couple of drivers (but will drop the BQ240022 driver
via the arm-soc tree as it's been replaced by the more generic
gpio-regulator driver) and Axel Lin continued his relentless and
generally awesome stream of fixes and cleanups."
* tag 'regulator-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (93 commits)
regulator: Fix up a confusing dev_warn when DT lookup fails
regulator: Convert tps6507x to set_voltage_sel
regulator: Refactor tps6507x to use one tps6507x_pmic_ops for all LDOs and DCDCs
regulator: Make s5m8767_get_voltage_register always return correct register
regulator: s5m8767: Check pdata->buck[2|3|4]_gpiodvs earlier
regulator: tps65910: Provide settling time for DCDC voltage change
regulator: Add Anatop regulator driver
regulator: Simplify implementation of tps65912_get_voltage_dcdc
regulator: Use tps65912_set_voltage_sel for both DCDCx and LDOx
regulator: tps65910: Provide settling time for enabling rails
regulator: max8925: Use DIV_ROUND_UP macro
regulator: tps65912: Use simple equations to get register address
regulator: Fix the logic of tps65910_get_mode
regulator: Merge tps65217_pmic_ldo234_ops and tps65217_pmic_dcdc_ops to tps65217_pmic_ops
regulator: Use DIV_ROUND_CLOSEST in wm8350_isink_get_current
regulator: Use array to store dcdc_range settings for tps65912
regulator: Rename s5m8767_convert_voltage to s5m8767_convert_voltage_to_sel
regulator: tps6524x: Remove unneeded comment for N_REGULATORS
regulator: Rename set_voltage_sel callback function name to *_sel
regulator: Fix s5m8767_set_voltage_time_sel calculation value
...
Diffstat (limited to 'drivers/regulator/tps6507x-regulator.c')
-rw-r--r-- | drivers/regulator/tps6507x-regulator.c | 283 |
1 files changed, 64 insertions, 219 deletions
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c index 0b63ef71a5fe..832833fe8aad 100644 --- a/drivers/regulator/tps6507x-regulator.c +++ b/drivers/regulator/tps6507x-regulator.c @@ -238,16 +238,16 @@ static int tps6507x_pmic_reg_write(struct tps6507x_pmic *tps, u8 reg, u8 val) return err; } -static int tps6507x_pmic_dcdc_is_enabled(struct regulator_dev *dev) +static int tps6507x_pmic_is_enabled(struct regulator_dev *dev) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, dcdc = rdev_get_id(dev); + int data, rid = rdev_get_id(dev); u8 shift; - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) return -EINVAL; - shift = TPS6507X_MAX_REG_ID - dcdc; + shift = TPS6507X_MAX_REG_ID - rid; data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1); if (data < 0) @@ -256,99 +256,65 @@ static int tps6507x_pmic_dcdc_is_enabled(struct regulator_dev *dev) return (data & 1<<shift) ? 1 : 0; } -static int tps6507x_pmic_ldo_is_enabled(struct regulator_dev *dev) +static int tps6507x_pmic_enable(struct regulator_dev *dev) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, ldo = rdev_get_id(dev); + int rid = rdev_get_id(dev); u8 shift; - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) return -EINVAL; - shift = TPS6507X_MAX_REG_ID - ldo; - data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1); - - if (data < 0) - return data; - else - return (data & 1<<shift) ? 1 : 0; -} - -static int tps6507x_pmic_dcdc_enable(struct regulator_dev *dev) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int dcdc = rdev_get_id(dev); - u8 shift; - - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) - return -EINVAL; - - shift = TPS6507X_MAX_REG_ID - dcdc; - return tps6507x_pmic_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); -} - -static int tps6507x_pmic_dcdc_disable(struct regulator_dev *dev) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int dcdc = rdev_get_id(dev); - u8 shift; - - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) - return -EINVAL; - - shift = TPS6507X_MAX_REG_ID - dcdc; - return tps6507x_pmic_clear_bits(tps, TPS6507X_REG_CON_CTRL1, - 1 << shift); -} - -static int tps6507x_pmic_ldo_enable(struct regulator_dev *dev) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int ldo = rdev_get_id(dev); - u8 shift; - - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) - return -EINVAL; - - shift = TPS6507X_MAX_REG_ID - ldo; + shift = TPS6507X_MAX_REG_ID - rid; return tps6507x_pmic_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); } -static int tps6507x_pmic_ldo_disable(struct regulator_dev *dev) +static int tps6507x_pmic_disable(struct regulator_dev *dev) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int ldo = rdev_get_id(dev); + int rid = rdev_get_id(dev); u8 shift; - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) return -EINVAL; - shift = TPS6507X_MAX_REG_ID - ldo; + shift = TPS6507X_MAX_REG_ID - rid; return tps6507x_pmic_clear_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); } -static int tps6507x_pmic_dcdc_get_voltage(struct regulator_dev *dev) +static int tps6507x_pmic_get_voltage(struct regulator_dev *dev) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, dcdc = rdev_get_id(dev); - u8 reg; + int data, rid = rdev_get_id(dev); + u8 reg, mask; - switch (dcdc) { + switch (rid) { case TPS6507X_DCDC_1: reg = TPS6507X_REG_DEFDCDC1; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; break; case TPS6507X_DCDC_2: - if (tps->info[dcdc]->defdcdc_default) + if (tps->info[rid]->defdcdc_default) reg = TPS6507X_REG_DEFDCDC2_HIGH; else reg = TPS6507X_REG_DEFDCDC2_LOW; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; break; case TPS6507X_DCDC_3: - if (tps->info[dcdc]->defdcdc_default) + if (tps->info[rid]->defdcdc_default) reg = TPS6507X_REG_DEFDCDC3_HIGH; else reg = TPS6507X_REG_DEFDCDC3_LOW; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; + break; + case TPS6507X_LDO_1: + reg = TPS6507X_REG_LDO_CTRL1; + mask = TPS6507X_REG_LDO_CTRL1_LDO1_MASK; + break; + case TPS6507X_LDO_2: + reg = TPS6507X_REG_DEFLDO2; + mask = TPS6507X_REG_DEFLDO2_LDO2_MASK; break; default: return -EINVAL; @@ -358,193 +324,83 @@ static int tps6507x_pmic_dcdc_get_voltage(struct regulator_dev *dev) if (data < 0) return data; - data &= TPS6507X_DEFDCDCX_DCDC_MASK; - return tps->info[dcdc]->table[data] * 1000; + data &= mask; + return tps->info[rid]->table[data] * 1000; } -static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev, - int min_uV, int max_uV, - unsigned *selector) +static int tps6507x_pmic_set_voltage_sel(struct regulator_dev *dev, + unsigned selector) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, vsel, dcdc = rdev_get_id(dev); - u8 reg; + int data, rid = rdev_get_id(dev); + u8 reg, mask; - switch (dcdc) { + switch (rid) { case TPS6507X_DCDC_1: reg = TPS6507X_REG_DEFDCDC1; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; break; case TPS6507X_DCDC_2: - if (tps->info[dcdc]->defdcdc_default) + if (tps->info[rid]->defdcdc_default) reg = TPS6507X_REG_DEFDCDC2_HIGH; else reg = TPS6507X_REG_DEFDCDC2_LOW; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; break; case TPS6507X_DCDC_3: - if (tps->info[dcdc]->defdcdc_default) + if (tps->info[rid]->defdcdc_default) reg = TPS6507X_REG_DEFDCDC3_HIGH; else reg = TPS6507X_REG_DEFDCDC3_LOW; + mask = TPS6507X_DEFDCDCX_DCDC_MASK; + break; + case TPS6507X_LDO_1: + reg = TPS6507X_REG_LDO_CTRL1; + mask = TPS6507X_REG_LDO_CTRL1_LDO1_MASK; + break; + case TPS6507X_LDO_2: + reg = TPS6507X_REG_DEFLDO2; + mask = TPS6507X_REG_DEFLDO2_LDO2_MASK; break; default: return -EINVAL; } - if (min_uV < tps->info[dcdc]->min_uV - || min_uV > tps->info[dcdc]->max_uV) - return -EINVAL; - if (max_uV < tps->info[dcdc]->min_uV - || max_uV > tps->info[dcdc]->max_uV) - return -EINVAL; - - for (vsel = 0; vsel < tps->info[dcdc]->table_len; vsel++) { - int mV = tps->info[dcdc]->table[vsel]; - int uV = mV * 1000; - - /* Break at the first in-range value */ - if (min_uV <= uV && uV <= max_uV) - break; - } - - /* write to the register in case we found a match */ - if (vsel == tps->info[dcdc]->table_len) - return -EINVAL; - - *selector = vsel; - - data = tps6507x_pmic_reg_read(tps, reg); - if (data < 0) - return data; - - data &= ~TPS6507X_DEFDCDCX_DCDC_MASK; - data |= vsel; - - return tps6507x_pmic_reg_write(tps, reg, data); -} - -static int tps6507x_pmic_ldo_get_voltage(struct regulator_dev *dev) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, ldo = rdev_get_id(dev); - u8 reg, mask; - - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) - return -EINVAL; - else { - reg = (ldo == TPS6507X_LDO_1 ? - TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2); - mask = (ldo == TPS6507X_LDO_1 ? - TPS6507X_REG_LDO_CTRL1_LDO1_MASK : - TPS6507X_REG_DEFLDO2_LDO2_MASK); - } - - data = tps6507x_pmic_reg_read(tps, reg); - if (data < 0) - return data; - - data &= mask; - return tps->info[ldo]->table[data] * 1000; -} - -static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev, - int min_uV, int max_uV, - unsigned *selector) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int data, vsel, ldo = rdev_get_id(dev); - u8 reg, mask; - - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) - return -EINVAL; - else { - reg = (ldo == TPS6507X_LDO_1 ? - TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2); - mask = (ldo == TPS6507X_LDO_1 ? - TPS6507X_REG_LDO_CTRL1_LDO1_MASK : - TPS6507X_REG_DEFLDO2_LDO2_MASK); - } - - if (min_uV < tps->info[ldo]->min_uV || min_uV > tps->info[ldo]->max_uV) - return -EINVAL; - if (max_uV < tps->info[ldo]->min_uV || max_uV > tps->info[ldo]->max_uV) - return -EINVAL; - - for (vsel = 0; vsel < tps->info[ldo]->table_len; vsel++) { - int mV = tps->info[ldo]->table[vsel]; - int uV = mV * 1000; - - /* Break at the first in-range value */ - if (min_uV <= uV && uV <= max_uV) - break; - } - - if (vsel == tps->info[ldo]->table_len) - return -EINVAL; - - *selector = vsel; - data = tps6507x_pmic_reg_read(tps, reg); if (data < 0) return data; data &= ~mask; - data |= vsel; + data |= selector; return tps6507x_pmic_reg_write(tps, reg, data); } -static int tps6507x_pmic_dcdc_list_voltage(struct regulator_dev *dev, +static int tps6507x_pmic_list_voltage(struct regulator_dev *dev, unsigned selector) { struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int dcdc = rdev_get_id(dev); + int rid = rdev_get_id(dev); - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) return -EINVAL; - if (selector >= tps->info[dcdc]->table_len) + if (selector >= tps->info[rid]->table_len) return -EINVAL; else - return tps->info[dcdc]->table[selector] * 1000; + return tps->info[rid]->table[selector] * 1000; } -static int tps6507x_pmic_ldo_list_voltage(struct regulator_dev *dev, - unsigned selector) -{ - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); - int ldo = rdev_get_id(dev); - - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) - return -EINVAL; - - if (selector >= tps->info[ldo]->table_len) - return -EINVAL; - else - return tps->info[ldo]->table[selector] * 1000; -} - -/* Operations permitted on VDCDCx */ -static struct regulator_ops tps6507x_pmic_dcdc_ops = { - .is_enabled = tps6507x_pmic_dcdc_is_enabled, - .enable = tps6507x_pmic_dcdc_enable, - .disable = tps6507x_pmic_dcdc_disable, - .get_voltage = tps6507x_pmic_dcdc_get_voltage, - .set_voltage = tps6507x_pmic_dcdc_set_voltage, - .list_voltage = tps6507x_pmic_dcdc_list_voltage, +static struct regulator_ops tps6507x_pmic_ops = { + .is_enabled = tps6507x_pmic_is_enabled, + .enable = tps6507x_pmic_enable, + .disable = tps6507x_pmic_disable, + .get_voltage = tps6507x_pmic_get_voltage, + .set_voltage_sel = tps6507x_pmic_set_voltage_sel, + .list_voltage = tps6507x_pmic_list_voltage, }; -/* Operations permitted on LDOx */ -static struct regulator_ops tps6507x_pmic_ldo_ops = { - .is_enabled = tps6507x_pmic_ldo_is_enabled, - .enable = tps6507x_pmic_ldo_enable, - .disable = tps6507x_pmic_ldo_disable, - .get_voltage = tps6507x_pmic_ldo_get_voltage, - .set_voltage = tps6507x_pmic_ldo_set_voltage, - .list_voltage = tps6507x_pmic_ldo_list_voltage, -}; - -static __devinit -int tps6507x_pmic_probe(struct platform_device *pdev) +static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) { struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent); struct tps_info *info = &tps6507x_pmic_regs[0]; @@ -593,8 +449,7 @@ int tps6507x_pmic_probe(struct platform_device *pdev) tps->desc[i].name = info->name; tps->desc[i].id = i; tps->desc[i].n_voltages = info->table_len; - tps->desc[i].ops = (i > TPS6507X_DCDC_3 ? - &tps6507x_pmic_ldo_ops : &tps6507x_pmic_dcdc_ops); + tps->desc[i].ops = &tps6507x_pmic_ops; tps->desc[i].type = REGULATOR_VOLTAGE; tps->desc[i].owner = THIS_MODULE; @@ -648,22 +503,12 @@ static struct platform_driver tps6507x_pmic_driver = { .remove = __devexit_p(tps6507x_pmic_remove), }; -/** - * tps6507x_pmic_init - * - * Module init function - */ static int __init tps6507x_pmic_init(void) { return platform_driver_register(&tps6507x_pmic_driver); } subsys_initcall(tps6507x_pmic_init); -/** - * tps6507x_pmic_cleanup - * - * Module exit function - */ static void __exit tps6507x_pmic_cleanup(void) { platform_driver_unregister(&tps6507x_pmic_driver); |