diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-07-24 20:51:44 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-08-28 14:00:25 -0400 |
commit | 7c7475c009260d02d56f940816bb7c86fce1542e (patch) | |
tree | 53fbba62db664206d8fe5f00be9e0cb54d3c78f9 /drivers/regulator/tps6586x-regulator.c | |
parent | 0f4c46d2e2150ef68d4c100d74f186ae93f00f3c (diff) |
regulator: tps6586x: Convert to regulator_[enable|disable|is_enabled|get_voltage_sel]_regmap
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/tps6586x-regulator.c')
-rw-r--r-- | drivers/regulator/tps6586x-regulator.c | 76 |
1 files changed, 11 insertions, 65 deletions
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c index 19241fc30050..c80f0ac05e2f 100644 --- a/drivers/regulator/tps6586x-regulator.c +++ b/drivers/regulator/tps6586x-regulator.c | |||
@@ -57,9 +57,6 @@ | |||
57 | struct tps6586x_regulator { | 57 | struct tps6586x_regulator { |
58 | struct regulator_desc desc; | 58 | struct regulator_desc desc; |
59 | 59 | ||
60 | int volt_reg; | ||
61 | int volt_shift; | ||
62 | int volt_nbits; | ||
63 | int enable_bit[2]; | 60 | int enable_bit[2]; |
64 | int enable_reg[2]; | 61 | int enable_reg[2]; |
65 | 62 | ||
@@ -81,10 +78,10 @@ static int tps6586x_set_voltage_sel(struct regulator_dev *rdev, | |||
81 | int ret, val, rid = rdev_get_id(rdev); | 78 | int ret, val, rid = rdev_get_id(rdev); |
82 | uint8_t mask; | 79 | uint8_t mask; |
83 | 80 | ||
84 | val = selector << ri->volt_shift; | 81 | val = selector << (ffs(rdev->desc->vsel_mask) - 1); |
85 | mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; | 82 | mask = rdev->desc->vsel_mask; |
86 | 83 | ||
87 | ret = tps6586x_update(parent, ri->volt_reg, val, mask); | 84 | ret = tps6586x_update(parent, rdev->desc->vsel_reg, val, mask); |
88 | if (ret) | 85 | if (ret) |
89 | return ret; | 86 | return ret; |
90 | 87 | ||
@@ -100,66 +97,14 @@ static int tps6586x_set_voltage_sel(struct regulator_dev *rdev, | |||
100 | return ret; | 97 | return ret; |
101 | } | 98 | } |
102 | 99 | ||
103 | static int tps6586x_get_voltage_sel(struct regulator_dev *rdev) | ||
104 | { | ||
105 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); | ||
106 | struct device *parent = to_tps6586x_dev(rdev); | ||
107 | uint8_t val, mask; | ||
108 | int ret; | ||
109 | |||
110 | ret = tps6586x_read(parent, ri->volt_reg, &val); | ||
111 | if (ret) | ||
112 | return ret; | ||
113 | |||
114 | mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; | ||
115 | val = (val & mask) >> ri->volt_shift; | ||
116 | |||
117 | if (val >= ri->desc.n_voltages) | ||
118 | BUG(); | ||
119 | |||
120 | return val; | ||
121 | } | ||
122 | |||
123 | static int tps6586x_regulator_enable(struct regulator_dev *rdev) | ||
124 | { | ||
125 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); | ||
126 | struct device *parent = to_tps6586x_dev(rdev); | ||
127 | |||
128 | return tps6586x_set_bits(parent, ri->enable_reg[0], | ||
129 | 1 << ri->enable_bit[0]); | ||
130 | } | ||
131 | |||
132 | static int tps6586x_regulator_disable(struct regulator_dev *rdev) | ||
133 | { | ||
134 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); | ||
135 | struct device *parent = to_tps6586x_dev(rdev); | ||
136 | |||
137 | return tps6586x_clr_bits(parent, ri->enable_reg[0], | ||
138 | 1 << ri->enable_bit[0]); | ||
139 | } | ||
140 | |||
141 | static int tps6586x_regulator_is_enabled(struct regulator_dev *rdev) | ||
142 | { | ||
143 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); | ||
144 | struct device *parent = to_tps6586x_dev(rdev); | ||
145 | uint8_t reg_val; | ||
146 | int ret; | ||
147 | |||
148 | ret = tps6586x_read(parent, ri->enable_reg[0], ®_val); | ||
149 | if (ret) | ||
150 | return ret; | ||
151 | |||
152 | return !!(reg_val & (1 << ri->enable_bit[0])); | ||
153 | } | ||
154 | |||
155 | static struct regulator_ops tps6586x_regulator_ops = { | 100 | static struct regulator_ops tps6586x_regulator_ops = { |
156 | .list_voltage = regulator_list_voltage_table, | 101 | .list_voltage = regulator_list_voltage_table, |
157 | .get_voltage_sel = tps6586x_get_voltage_sel, | 102 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
158 | .set_voltage_sel = tps6586x_set_voltage_sel, | 103 | .set_voltage_sel = tps6586x_set_voltage_sel, |
159 | 104 | ||
160 | .is_enabled = tps6586x_regulator_is_enabled, | 105 | .is_enabled = regulator_is_enabled_regmap, |
161 | .enable = tps6586x_regulator_enable, | 106 | .enable = regulator_enable_regmap, |
162 | .disable = tps6586x_regulator_disable, | 107 | .disable = regulator_disable_regmap, |
163 | }; | 108 | }; |
164 | 109 | ||
165 | static const unsigned int tps6586x_ldo0_voltages[] = { | 110 | static const unsigned int tps6586x_ldo0_voltages[] = { |
@@ -202,10 +147,11 @@ static const unsigned int tps6586x_dvm_voltages[] = { | |||
202 | .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ | 147 | .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ |
203 | .volt_table = tps6586x_##vdata##_voltages, \ | 148 | .volt_table = tps6586x_##vdata##_voltages, \ |
204 | .owner = THIS_MODULE, \ | 149 | .owner = THIS_MODULE, \ |
150 | .enable_reg = TPS6586X_SUPPLY##ereg0, \ | ||
151 | .enable_mask = 1 << (ebit0), \ | ||
152 | .vsel_reg = TPS6586X_##vreg, \ | ||
153 | .vsel_mask = ((1 << (nbits)) - 1) << (shift), \ | ||
205 | }, \ | 154 | }, \ |
206 | .volt_reg = TPS6586X_##vreg, \ | ||
207 | .volt_shift = (shift), \ | ||
208 | .volt_nbits = (nbits), \ | ||
209 | .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \ | 155 | .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \ |
210 | .enable_bit[0] = (ebit0), \ | 156 | .enable_bit[0] = (ebit0), \ |
211 | .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \ | 157 | .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \ |