diff options
| author | Axel Lin <axel.lin@ingics.com> | 2014-03-07 22:56:47 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@linaro.org> | 2014-04-14 17:16:25 -0400 |
| commit | 60e8c1e34d3ab74556fb9b25f26fa34b9879ee30 (patch) | |
| tree | 9379aa09403612f3f2ae5e5fa5d91f328c6adfc6 | |
| parent | 1cb7b43f6796ad0bc62669fa52d1005916911d27 (diff) | |
regulator: pbias: Convert to use regmap helper functions
This patch converts this driver to use the regmap helper functions provided by
regulator core.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Balaji T K <balajitk@ti.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
| -rw-r--r-- | drivers/regulator/pbias-regulator.c | 74 |
1 files changed, 19 insertions, 55 deletions
diff --git a/drivers/regulator/pbias-regulator.c b/drivers/regulator/pbias-regulator.c index d89a1d8615c7..6d38be3d970c 100644 --- a/drivers/regulator/pbias-regulator.c +++ b/drivers/regulator/pbias-regulator.c | |||
| @@ -38,66 +38,24 @@ struct pbias_reg_info { | |||
| 38 | struct pbias_regulator_data { | 38 | struct pbias_regulator_data { |
| 39 | struct regulator_desc desc; | 39 | struct regulator_desc desc; |
| 40 | void __iomem *pbias_addr; | 40 | void __iomem *pbias_addr; |
| 41 | unsigned int pbias_reg; | ||
| 42 | struct regulator_dev *dev; | 41 | struct regulator_dev *dev; |
| 43 | struct regmap *syscon; | 42 | struct regmap *syscon; |
| 44 | const struct pbias_reg_info *info; | 43 | const struct pbias_reg_info *info; |
| 45 | int voltage; | 44 | int voltage; |
| 46 | }; | 45 | }; |
| 47 | 46 | ||
| 48 | static int pbias_regulator_set_voltage(struct regulator_dev *dev, | 47 | static const unsigned int pbias_volt_table[] = { |
| 49 | int min_uV, int max_uV, unsigned *selector) | 48 | 1800000, |
| 50 | { | 49 | 3000000 |
| 51 | struct pbias_regulator_data *data = rdev_get_drvdata(dev); | 50 | }; |
| 52 | const struct pbias_reg_info *info = data->info; | ||
| 53 | int ret, vmode; | ||
| 54 | |||
| 55 | if (min_uV <= 1800000) | ||
| 56 | vmode = 0; | ||
| 57 | else if (min_uV > 1800000) | ||
| 58 | vmode = info->vmode; | ||
| 59 | |||
| 60 | ret = regmap_update_bits(data->syscon, data->pbias_reg, | ||
| 61 | info->vmode, vmode); | ||
| 62 | |||
| 63 | return ret; | ||
| 64 | } | ||
| 65 | |||
| 66 | static int pbias_regulator_get_voltage(struct regulator_dev *rdev) | ||
| 67 | { | ||
| 68 | struct pbias_regulator_data *data = rdev_get_drvdata(rdev); | ||
| 69 | const struct pbias_reg_info *info = data->info; | ||
| 70 | int value, voltage; | ||
| 71 | |||
| 72 | regmap_read(data->syscon, data->pbias_reg, &value); | ||
| 73 | value &= info->vmode; | ||
| 74 | |||
| 75 | voltage = value ? 3000000 : 1800000; | ||
| 76 | |||
| 77 | return voltage; | ||
| 78 | } | ||
| 79 | 51 | ||
| 80 | static int pbias_regulator_enable(struct regulator_dev *rdev) | 52 | static int pbias_regulator_enable(struct regulator_dev *rdev) |
| 81 | { | 53 | { |
| 82 | struct pbias_regulator_data *data = rdev_get_drvdata(rdev); | 54 | struct pbias_regulator_data *data = rdev_get_drvdata(rdev); |
| 83 | const struct pbias_reg_info *info = data->info; | 55 | const struct pbias_reg_info *info = data->info; |
| 84 | int ret; | ||
| 85 | |||
| 86 | ret = regmap_update_bits(data->syscon, data->pbias_reg, | ||
| 87 | info->enable_mask, info->enable); | ||
| 88 | |||
| 89 | return ret; | ||
| 90 | } | ||
| 91 | |||
| 92 | static int pbias_regulator_disable(struct regulator_dev *rdev) | ||
| 93 | { | ||
| 94 | struct pbias_regulator_data *data = rdev_get_drvdata(rdev); | ||
| 95 | const struct pbias_reg_info *info = data->info; | ||
| 96 | int ret; | ||
| 97 | 56 | ||
| 98 | ret = regmap_update_bits(data->syscon, data->pbias_reg, | 57 | return regmap_update_bits(data->syscon, rdev->desc->enable_reg, |
| 99 | info->enable_mask, 0); | 58 | info->enable_mask, info->enable); |
| 100 | return ret; | ||
| 101 | } | 59 | } |
| 102 | 60 | ||
| 103 | static int pbias_regulator_is_enable(struct regulator_dev *rdev) | 61 | static int pbias_regulator_is_enable(struct regulator_dev *rdev) |
| @@ -106,17 +64,18 @@ static int pbias_regulator_is_enable(struct regulator_dev *rdev) | |||
| 106 | const struct pbias_reg_info *info = data->info; | 64 | const struct pbias_reg_info *info = data->info; |
| 107 | int value; | 65 | int value; |
| 108 | 66 | ||
| 109 | regmap_read(data->syscon, data->pbias_reg, &value); | 67 | regmap_read(data->syscon, rdev->desc->enable_reg, &value); |
| 110 | 68 | ||
| 111 | return (value & info->enable_mask) == info->enable; | 69 | return (value & info->enable_mask) == info->enable; |
| 112 | } | 70 | } |
| 113 | 71 | ||
| 114 | static struct regulator_ops pbias_regulator_voltage_ops = { | 72 | static struct regulator_ops pbias_regulator_voltage_ops = { |
| 115 | .set_voltage = pbias_regulator_set_voltage, | 73 | .list_voltage = regulator_list_voltage_table, |
| 116 | .get_voltage = pbias_regulator_get_voltage, | 74 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 117 | .enable = pbias_regulator_enable, | 75 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 118 | .disable = pbias_regulator_disable, | 76 | .enable = pbias_regulator_enable, |
| 119 | .is_enabled = pbias_regulator_is_enable, | 77 | .disable = regulator_disable_regmap, |
| 78 | .is_enabled = pbias_regulator_is_enable, | ||
| 120 | }; | 79 | }; |
| 121 | 80 | ||
| 122 | static const struct pbias_reg_info pbias_mmc_omap2430 = { | 81 | static const struct pbias_reg_info pbias_mmc_omap2430 = { |
| @@ -192,6 +151,7 @@ static int pbias_regulator_probe(struct platform_device *pdev) | |||
| 192 | if (IS_ERR(syscon)) | 151 | if (IS_ERR(syscon)) |
| 193 | return PTR_ERR(syscon); | 152 | return PTR_ERR(syscon); |
| 194 | 153 | ||
| 154 | cfg.regmap = syscon; | ||
| 195 | cfg.dev = &pdev->dev; | 155 | cfg.dev = &pdev->dev; |
| 196 | 156 | ||
| 197 | for (idx = 0; idx < PBIAS_NUM_REGS && data_idx < count; idx++) { | 157 | for (idx = 0; idx < PBIAS_NUM_REGS && data_idx < count; idx++) { |
| @@ -207,15 +167,19 @@ static int pbias_regulator_probe(struct platform_device *pdev) | |||
| 207 | if (!res) | 167 | if (!res) |
| 208 | return -EINVAL; | 168 | return -EINVAL; |
| 209 | 169 | ||
| 210 | drvdata[data_idx].pbias_reg = res->start; | ||
| 211 | drvdata[data_idx].syscon = syscon; | 170 | drvdata[data_idx].syscon = syscon; |
| 212 | drvdata[data_idx].info = info; | 171 | drvdata[data_idx].info = info; |
| 213 | drvdata[data_idx].desc.name = info->name; | 172 | drvdata[data_idx].desc.name = info->name; |
| 214 | drvdata[data_idx].desc.owner = THIS_MODULE; | 173 | drvdata[data_idx].desc.owner = THIS_MODULE; |
| 215 | drvdata[data_idx].desc.type = REGULATOR_VOLTAGE; | 174 | drvdata[data_idx].desc.type = REGULATOR_VOLTAGE; |
| 216 | drvdata[data_idx].desc.ops = &pbias_regulator_voltage_ops; | 175 | drvdata[data_idx].desc.ops = &pbias_regulator_voltage_ops; |
| 176 | drvdata[data_idx].desc.volt_table = pbias_volt_table; | ||
| 217 | drvdata[data_idx].desc.n_voltages = 2; | 177 | drvdata[data_idx].desc.n_voltages = 2; |
| 218 | drvdata[data_idx].desc.enable_time = info->enable_time; | 178 | drvdata[data_idx].desc.enable_time = info->enable_time; |
| 179 | drvdata[data_idx].desc.vsel_reg = res->start; | ||
| 180 | drvdata[data_idx].desc.vsel_mask = info->vmode; | ||
| 181 | drvdata[data_idx].desc.enable_reg = res->start; | ||
| 182 | drvdata[data_idx].desc.enable_mask = info->enable_mask; | ||
| 219 | 183 | ||
| 220 | cfg.init_data = pbias_matches[idx].init_data; | 184 | cfg.init_data = pbias_matches[idx].init_data; |
| 221 | cfg.driver_data = &drvdata[data_idx]; | 185 | cfg.driver_data = &drvdata[data_idx]; |
