diff options
-rw-r--r-- | Documentation/devicetree/bindings/regulator/act8865-regulator.txt | 7 | ||||
-rw-r--r-- | drivers/regulator/act8865-regulator.c | 329 | ||||
-rw-r--r-- | include/linux/regulator/act8865.h | 23 |
3 files changed, 216 insertions, 143 deletions
diff --git a/Documentation/devicetree/bindings/regulator/act8865-regulator.txt b/Documentation/devicetree/bindings/regulator/act8865-regulator.txt index bef1fbb647ca..865614b34d6f 100644 --- a/Documentation/devicetree/bindings/regulator/act8865-regulator.txt +++ b/Documentation/devicetree/bindings/regulator/act8865-regulator.txt | |||
@@ -1,13 +1,16 @@ | |||
1 | ACT8865 regulator | 1 | ACT88xx regulators |
2 | ------------------- | 2 | ------------------- |
3 | 3 | ||
4 | Required properties: | 4 | Required properties: |
5 | - compatible: "active-semi,act8865" | 5 | - compatible: "active-semi,act8846" or "active-semi,act8865" |
6 | - reg: I2C slave address | 6 | - reg: I2C slave address |
7 | 7 | ||
8 | Any standard regulator properties can be used to configure the single regulator. | 8 | Any standard regulator properties can be used to configure the single regulator. |
9 | 9 | ||
10 | The valid names for regulators are: | 10 | The valid names for regulators are: |
11 | - for act8846: | ||
12 | REG1, REG2, REG3, REG4, REG5, REG6, REG7, REG8, REG9, REG10, REG11, REG12 | ||
13 | - for act8865: | ||
11 | DCDC_REG1, DCDC_REG2, DCDC_REG3, LDO_REG1, LDO_REG2, LDO_REG3, LDO_REG4. | 14 | DCDC_REG1, DCDC_REG2, DCDC_REG3, LDO_REG1, LDO_REG2, LDO_REG3, LDO_REG4. |
12 | 15 | ||
13 | Example: | 16 | Example: |
diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index 89f9f0c0f64d..afd06f92dfdf 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * act8865-regulator.c - Voltage regulation for the active-semi ACT8865 | 2 | * act8865-regulator.c - Voltage regulation for active-semi ACT88xx PMUs |
3 | * http://www.active-semi.com/sheets/ACT8865_Datasheet.pdf | 3 | * |
4 | * http://www.active-semi.com/products/power-management-units/act88xx/ | ||
4 | * | 5 | * |
5 | * Copyright (C) 2013 Atmel Corporation | 6 | * Copyright (C) 2013 Atmel Corporation |
6 | * | 7 | * |
@@ -28,6 +29,40 @@ | |||
28 | #include <linux/regmap.h> | 29 | #include <linux/regmap.h> |
29 | 30 | ||
30 | /* | 31 | /* |
32 | * ACT8846 Global Register Map. | ||
33 | */ | ||
34 | #define ACT8846_SYS0 0x00 | ||
35 | #define ACT8846_SYS1 0x01 | ||
36 | #define ACT8846_REG1_VSET 0x10 | ||
37 | #define ACT8846_REG1_CTRL 0x12 | ||
38 | #define ACT8846_REG2_VSET0 0x20 | ||
39 | #define ACT8846_REG2_VSET1 0x21 | ||
40 | #define ACT8846_REG2_CTRL 0x22 | ||
41 | #define ACT8846_REG3_VSET0 0x30 | ||
42 | #define ACT8846_REG3_VSET1 0x31 | ||
43 | #define ACT8846_REG3_CTRL 0x32 | ||
44 | #define ACT8846_REG4_VSET0 0x40 | ||
45 | #define ACT8846_REG4_VSET1 0x41 | ||
46 | #define ACT8846_REG4_CTRL 0x42 | ||
47 | #define ACT8846_REG5_VSET 0x50 | ||
48 | #define ACT8846_REG5_CTRL 0x51 | ||
49 | #define ACT8846_REG6_VSET 0x58 | ||
50 | #define ACT8846_REG6_CTRL 0x59 | ||
51 | #define ACT8846_REG7_VSET 0x60 | ||
52 | #define ACT8846_REG7_CTRL 0x61 | ||
53 | #define ACT8846_REG8_VSET 0x68 | ||
54 | #define ACT8846_REG8_CTRL 0x69 | ||
55 | #define ACT8846_REG9_VSET 0x70 | ||
56 | #define ACT8846_REG9_CTRL 0x71 | ||
57 | #define ACT8846_REG10_VSET 0x80 | ||
58 | #define ACT8846_REG10_CTRL 0x81 | ||
59 | #define ACT8846_REG11_VSET 0x90 | ||
60 | #define ACT8846_REG11_CTRL 0x91 | ||
61 | #define ACT8846_REG12_VSET 0xa0 | ||
62 | #define ACT8846_REG12_CTRL 0xa1 | ||
63 | #define ACT8846_REG13_CTRL 0xb1 | ||
64 | |||
65 | /* | ||
31 | * ACT8865 Global Register Map. | 66 | * ACT8865 Global Register Map. |
32 | */ | 67 | */ |
33 | #define ACT8865_SYS_MODE 0x00 | 68 | #define ACT8865_SYS_MODE 0x00 |
@@ -70,7 +105,7 @@ static const struct regmap_config act8865_regmap_config = { | |||
70 | .val_bits = 8, | 105 | .val_bits = 8, |
71 | }; | 106 | }; |
72 | 107 | ||
73 | static const struct regulator_linear_range act8865_volatge_ranges[] = { | 108 | static const struct regulator_linear_range act8865_voltage_ranges[] = { |
74 | REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000), | 109 | REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000), |
75 | REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000), | 110 | REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000), |
76 | REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000), | 111 | REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000), |
@@ -86,114 +121,70 @@ static struct regulator_ops act8865_ops = { | |||
86 | .is_enabled = regulator_is_enabled_regmap, | 121 | .is_enabled = regulator_is_enabled_regmap, |
87 | }; | 122 | }; |
88 | 123 | ||
89 | static const struct regulator_desc act8865_reg[] = { | 124 | #define ACT88xx_REG(_name, _family, _id, _vsel_reg) \ |
90 | { | 125 | [_family##_ID_##_id] = { \ |
91 | .name = "DCDC_REG1", | 126 | .name = _name, \ |
92 | .id = ACT8865_ID_DCDC1, | 127 | .id = _family##_ID_##_id, \ |
93 | .ops = &act8865_ops, | 128 | .type = REGULATOR_VOLTAGE, \ |
94 | .type = REGULATOR_VOLTAGE, | 129 | .ops = &act8865_ops, \ |
95 | .n_voltages = ACT8865_VOLTAGE_NUM, | 130 | .n_voltages = ACT8865_VOLTAGE_NUM, \ |
96 | .linear_ranges = act8865_volatge_ranges, | 131 | .linear_ranges = act8865_voltage_ranges, \ |
97 | .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), | 132 | .n_linear_ranges = ARRAY_SIZE(act8865_voltage_ranges), \ |
98 | .vsel_reg = ACT8865_DCDC1_VSET1, | 133 | .vsel_reg = _family##_##_id##_##_vsel_reg, \ |
99 | .vsel_mask = ACT8865_VSEL_MASK, | 134 | .vsel_mask = ACT8865_VSEL_MASK, \ |
100 | .enable_reg = ACT8865_DCDC1_CTRL, | 135 | .enable_reg = _family##_##_id##_CTRL, \ |
101 | .enable_mask = ACT8865_ENA, | 136 | .enable_mask = ACT8865_ENA, \ |
102 | .owner = THIS_MODULE, | 137 | .owner = THIS_MODULE, \ |
103 | }, | 138 | } |
104 | { | 139 | |
105 | .name = "DCDC_REG2", | 140 | static const struct regulator_desc act8846_regulators[] = { |
106 | .id = ACT8865_ID_DCDC2, | 141 | ACT88xx_REG("REG1", ACT8846, REG1, VSET), |
107 | .ops = &act8865_ops, | 142 | ACT88xx_REG("REG2", ACT8846, REG2, VSET0), |
108 | .type = REGULATOR_VOLTAGE, | 143 | ACT88xx_REG("REG3", ACT8846, REG3, VSET0), |
109 | .n_voltages = ACT8865_VOLTAGE_NUM, | 144 | ACT88xx_REG("REG4", ACT8846, REG4, VSET0), |
110 | .linear_ranges = act8865_volatge_ranges, | 145 | ACT88xx_REG("REG5", ACT8846, REG5, VSET), |
111 | .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), | 146 | ACT88xx_REG("REG6", ACT8846, REG6, VSET), |
112 | .vsel_reg = ACT8865_DCDC2_VSET1, | 147 | ACT88xx_REG("REG7", ACT8846, REG7, VSET), |
113 | .vsel_mask = ACT8865_VSEL_MASK, | 148 | ACT88xx_REG("REG8", ACT8846, REG8, VSET), |
114 | .enable_reg = ACT8865_DCDC2_CTRL, | 149 | ACT88xx_REG("REG9", ACT8846, REG9, VSET), |
115 | .enable_mask = ACT8865_ENA, | 150 | ACT88xx_REG("REG10", ACT8846, REG10, VSET), |
116 | .owner = THIS_MODULE, | 151 | ACT88xx_REG("REG11", ACT8846, REG11, VSET), |
117 | }, | 152 | ACT88xx_REG("REG12", ACT8846, REG12, VSET), |
118 | { | 153 | }; |
119 | .name = "DCDC_REG3", | 154 | |
120 | .id = ACT8865_ID_DCDC3, | 155 | static const struct regulator_desc act8865_regulators[] = { |
121 | .ops = &act8865_ops, | 156 | ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET1), |
122 | .type = REGULATOR_VOLTAGE, | 157 | ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET1), |
123 | .n_voltages = ACT8865_VOLTAGE_NUM, | 158 | ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET1), |
124 | .linear_ranges = act8865_volatge_ranges, | 159 | ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET), |
125 | .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), | 160 | ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET), |
126 | .vsel_reg = ACT8865_DCDC3_VSET1, | 161 | ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET), |
127 | .vsel_mask = ACT8865_VSEL_MASK, | 162 | ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET), |
128 | .enable_reg = ACT8865_DCDC3_CTRL, | ||
129 | .enable_mask = ACT8865_ENA, | ||
130 | .owner = THIS_MODULE, | ||
131 | }, | ||
132 | { | ||
133 | .name = "LDO_REG1", | ||
134 | .id = ACT8865_ID_LDO1, | ||
135 | .ops = &act8865_ops, | ||
136 | .type = REGULATOR_VOLTAGE, | ||
137 | .n_voltages = ACT8865_VOLTAGE_NUM, | ||
138 | .linear_ranges = act8865_volatge_ranges, | ||
139 | .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), | ||
140 | .vsel_reg = ACT8865_LDO1_VSET, | ||
141 | .vsel_mask = ACT8865_VSEL_MASK, | ||
142 | .enable_reg = ACT8865_LDO1_CTRL, | ||
143 | .enable_mask = ACT8865_ENA, | ||
144 | .owner = THIS_MODULE, | ||
145 | }, | ||
146 | { | ||
147 | .name = "LDO_REG2", | ||
148 | .id = ACT8865_ID_LDO2, | ||
149 | .ops = &act8865_ops, | ||
150 | .type = REGULATOR_VOLTAGE, | ||
151 | .n_voltages = ACT8865_VOLTAGE_NUM, | ||
152 | .linear_ranges = act8865_volatge_ranges, | ||
153 | .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), | ||
154 | .vsel_reg = ACT8865_LDO2_VSET, | ||
155 | .vsel_mask = ACT8865_VSEL_MASK, | ||
156 | .enable_reg = ACT8865_LDO2_CTRL, | ||
157 | .enable_mask = ACT8865_ENA, | ||
158 | .owner = THIS_MODULE, | ||
159 | }, | ||
160 | { | ||
161 | .name = "LDO_REG3", | ||
162 | .id = ACT8865_ID_LDO3, | ||
163 | .ops = &act8865_ops, | ||
164 | .type = REGULATOR_VOLTAGE, | ||
165 | .n_voltages = ACT8865_VOLTAGE_NUM, | ||
166 | .linear_ranges = act8865_volatge_ranges, | ||
167 | .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), | ||
168 | .vsel_reg = ACT8865_LDO3_VSET, | ||
169 | .vsel_mask = ACT8865_VSEL_MASK, | ||
170 | .enable_reg = ACT8865_LDO3_CTRL, | ||
171 | .enable_mask = ACT8865_ENA, | ||
172 | .owner = THIS_MODULE, | ||
173 | }, | ||
174 | { | ||
175 | .name = "LDO_REG4", | ||
176 | .id = ACT8865_ID_LDO4, | ||
177 | .ops = &act8865_ops, | ||
178 | .type = REGULATOR_VOLTAGE, | ||
179 | .n_voltages = ACT8865_VOLTAGE_NUM, | ||
180 | .linear_ranges = act8865_volatge_ranges, | ||
181 | .n_linear_ranges = ARRAY_SIZE(act8865_volatge_ranges), | ||
182 | .vsel_reg = ACT8865_LDO4_VSET, | ||
183 | .vsel_mask = ACT8865_VSEL_MASK, | ||
184 | .enable_reg = ACT8865_LDO4_CTRL, | ||
185 | .enable_mask = ACT8865_ENA, | ||
186 | .owner = THIS_MODULE, | ||
187 | }, | ||
188 | }; | 163 | }; |
189 | 164 | ||
190 | #ifdef CONFIG_OF | 165 | #ifdef CONFIG_OF |
191 | static const struct of_device_id act8865_dt_ids[] = { | 166 | static const struct of_device_id act8865_dt_ids[] = { |
192 | { .compatible = "active-semi,act8865" }, | 167 | { .compatible = "active-semi,act8846", .data = (void *)ACT8846 }, |
168 | { .compatible = "active-semi,act8865", .data = (void *)ACT8865 }, | ||
193 | { } | 169 | { } |
194 | }; | 170 | }; |
195 | MODULE_DEVICE_TABLE(of, act8865_dt_ids); | 171 | MODULE_DEVICE_TABLE(of, act8865_dt_ids); |
196 | 172 | ||
173 | static struct of_regulator_match act8846_matches[] = { | ||
174 | [ACT8846_ID_REG1] = { .name = "REG1" }, | ||
175 | [ACT8846_ID_REG2] = { .name = "REG2" }, | ||
176 | [ACT8846_ID_REG3] = { .name = "REG3" }, | ||
177 | [ACT8846_ID_REG4] = { .name = "REG4" }, | ||
178 | [ACT8846_ID_REG5] = { .name = "REG5" }, | ||
179 | [ACT8846_ID_REG6] = { .name = "REG6" }, | ||
180 | [ACT8846_ID_REG7] = { .name = "REG7" }, | ||
181 | [ACT8846_ID_REG8] = { .name = "REG8" }, | ||
182 | [ACT8846_ID_REG9] = { .name = "REG9" }, | ||
183 | [ACT8846_ID_REG10] = { .name = "REG10" }, | ||
184 | [ACT8846_ID_REG11] = { .name = "REG11" }, | ||
185 | [ACT8846_ID_REG12] = { .name = "REG12" }, | ||
186 | }; | ||
187 | |||
197 | static struct of_regulator_match act8865_matches[] = { | 188 | static struct of_regulator_match act8865_matches[] = { |
198 | [ACT8865_ID_DCDC1] = { .name = "DCDC_REG1"}, | 189 | [ACT8865_ID_DCDC1] = { .name = "DCDC_REG1"}, |
199 | [ACT8865_ID_DCDC2] = { .name = "DCDC_REG2"}, | 190 | [ACT8865_ID_DCDC2] = { .name = "DCDC_REG2"}, |
@@ -206,11 +197,13 @@ static struct of_regulator_match act8865_matches[] = { | |||
206 | 197 | ||
207 | static int act8865_pdata_from_dt(struct device *dev, | 198 | static int act8865_pdata_from_dt(struct device *dev, |
208 | struct device_node **of_node, | 199 | struct device_node **of_node, |
209 | struct act8865_platform_data *pdata) | 200 | struct act8865_platform_data *pdata, |
201 | unsigned long type) | ||
210 | { | 202 | { |
211 | int matched, i; | 203 | int matched, i, num_matches; |
212 | struct device_node *np; | 204 | struct device_node *np; |
213 | struct act8865_regulator_data *regulator; | 205 | struct act8865_regulator_data *regulator; |
206 | struct of_regulator_match *matches; | ||
214 | 207 | ||
215 | np = of_get_child_by_name(dev->of_node, "regulators"); | 208 | np = of_get_child_by_name(dev->of_node, "regulators"); |
216 | if (!np) { | 209 | if (!np) { |
@@ -218,26 +211,39 @@ static int act8865_pdata_from_dt(struct device *dev, | |||
218 | return -EINVAL; | 211 | return -EINVAL; |
219 | } | 212 | } |
220 | 213 | ||
221 | matched = of_regulator_match(dev, np, | 214 | switch (type) { |
222 | act8865_matches, ARRAY_SIZE(act8865_matches)); | 215 | case ACT8846: |
216 | matches = act8846_matches; | ||
217 | num_matches = ARRAY_SIZE(act8846_matches); | ||
218 | break; | ||
219 | case ACT8865: | ||
220 | matches = act8865_matches; | ||
221 | num_matches = ARRAY_SIZE(act8865_matches); | ||
222 | break; | ||
223 | default: | ||
224 | dev_err(dev, "invalid device id %lu\n", type); | ||
225 | return -EINVAL; | ||
226 | } | ||
227 | |||
228 | matched = of_regulator_match(dev, np, matches, num_matches); | ||
223 | of_node_put(np); | 229 | of_node_put(np); |
224 | if (matched <= 0) | 230 | if (matched <= 0) |
225 | return matched; | 231 | return matched; |
226 | 232 | ||
227 | pdata->regulators = devm_kzalloc(dev, | 233 | pdata->regulators = devm_kzalloc(dev, |
228 | sizeof(struct act8865_regulator_data) * | 234 | sizeof(struct act8865_regulator_data) * |
229 | ARRAY_SIZE(act8865_matches), GFP_KERNEL); | 235 | num_matches, GFP_KERNEL); |
230 | if (!pdata->regulators) | 236 | if (!pdata->regulators) |
231 | return -ENOMEM; | 237 | return -ENOMEM; |
232 | 238 | ||
233 | pdata->num_regulators = ARRAY_SIZE(act8865_matches); | 239 | pdata->num_regulators = num_matches; |
234 | regulator = pdata->regulators; | 240 | regulator = pdata->regulators; |
235 | 241 | ||
236 | for (i = 0; i < ARRAY_SIZE(act8865_matches); i++) { | 242 | for (i = 0; i < num_matches; i++) { |
237 | regulator->id = i; | 243 | regulator->id = i; |
238 | regulator->name = act8865_matches[i].name; | 244 | regulator->name = matches[i].name; |
239 | regulator->platform_data = act8865_matches[i].init_data; | 245 | regulator->platform_data = matches[i].init_data; |
240 | of_node[i] = act8865_matches[i].of_node; | 246 | of_node[i] = matches[i].of_node; |
241 | regulator++; | 247 | regulator++; |
242 | } | 248 | } |
243 | 249 | ||
@@ -246,42 +252,84 @@ static int act8865_pdata_from_dt(struct device *dev, | |||
246 | #else | 252 | #else |
247 | static inline int act8865_pdata_from_dt(struct device *dev, | 253 | static inline int act8865_pdata_from_dt(struct device *dev, |
248 | struct device_node **of_node, | 254 | struct device_node **of_node, |
249 | struct act8865_platform_data *pdata) | 255 | struct act8865_platform_data *pdata, |
256 | unsigned long type) | ||
250 | { | 257 | { |
251 | return 0; | 258 | return 0; |
252 | } | 259 | } |
253 | #endif | 260 | #endif |
254 | 261 | ||
262 | static struct regulator_init_data | ||
263 | *act8865_get_init_data(int id, struct act8865_platform_data *pdata) | ||
264 | { | ||
265 | int i; | ||
266 | |||
267 | if (!pdata) | ||
268 | return NULL; | ||
269 | |||
270 | for (i = 0; i < pdata->num_regulators; i++) { | ||
271 | if (pdata->regulators[i].id == id) | ||
272 | return pdata->regulators[i].platform_data; | ||
273 | } | ||
274 | |||
275 | return NULL; | ||
276 | } | ||
277 | |||
255 | static int act8865_pmic_probe(struct i2c_client *client, | 278 | static int act8865_pmic_probe(struct i2c_client *client, |
256 | const struct i2c_device_id *i2c_id) | 279 | const struct i2c_device_id *i2c_id) |
257 | { | 280 | { |
258 | struct regulator_dev *rdev; | 281 | static const struct regulator_desc *regulators; |
282 | struct act8865_platform_data pdata_of, *pdata; | ||
259 | struct device *dev = &client->dev; | 283 | struct device *dev = &client->dev; |
260 | struct act8865_platform_data *pdata = dev_get_platdata(dev); | 284 | struct device_node **of_node; |
261 | struct regulator_config config = { }; | 285 | int i, ret, num_regulators; |
262 | struct act8865 *act8865; | 286 | struct act8865 *act8865; |
263 | struct device_node *of_node[ACT8865_REG_NUM]; | 287 | unsigned long type; |
264 | int i, id; | 288 | |
265 | int ret = -EINVAL; | 289 | pdata = dev_get_platdata(dev); |
266 | int error; | ||
267 | 290 | ||
268 | if (dev->of_node && !pdata) { | 291 | if (dev->of_node && !pdata) { |
269 | const struct of_device_id *id; | 292 | const struct of_device_id *id; |
270 | struct act8865_platform_data pdata_of; | ||
271 | 293 | ||
272 | id = of_match_device(of_match_ptr(act8865_dt_ids), dev); | 294 | id = of_match_device(of_match_ptr(act8865_dt_ids), dev); |
273 | if (!id) | 295 | if (!id) |
274 | return -ENODEV; | 296 | return -ENODEV; |
275 | 297 | ||
276 | ret = act8865_pdata_from_dt(dev, of_node, &pdata_of); | 298 | type = (unsigned long) id->data; |
299 | } else { | ||
300 | type = i2c_id->driver_data; | ||
301 | } | ||
302 | |||
303 | switch (type) { | ||
304 | case ACT8846: | ||
305 | regulators = act8846_regulators; | ||
306 | num_regulators = ARRAY_SIZE(act8846_regulators); | ||
307 | break; | ||
308 | case ACT8865: | ||
309 | regulators = act8865_regulators; | ||
310 | num_regulators = ARRAY_SIZE(act8865_regulators); | ||
311 | break; | ||
312 | default: | ||
313 | dev_err(dev, "invalid device id %lu\n", type); | ||
314 | return -EINVAL; | ||
315 | } | ||
316 | |||
317 | of_node = devm_kzalloc(dev, sizeof(struct device_node *) * | ||
318 | num_regulators, GFP_KERNEL); | ||
319 | if (!of_node) | ||
320 | return -ENOMEM; | ||
321 | |||
322 | if (dev->of_node && !pdata) { | ||
323 | ret = act8865_pdata_from_dt(dev, of_node, &pdata_of, type); | ||
277 | if (ret < 0) | 324 | if (ret < 0) |
278 | return ret; | 325 | return ret; |
279 | 326 | ||
280 | pdata = &pdata_of; | 327 | pdata = &pdata_of; |
281 | } | 328 | } |
282 | 329 | ||
283 | if (pdata->num_regulators > ACT8865_REG_NUM) { | 330 | if (pdata->num_regulators > num_regulators) { |
284 | dev_err(dev, "Too many regulators found!\n"); | 331 | dev_err(dev, "too many regulators: %d\n", |
332 | pdata->num_regulators); | ||
285 | return -EINVAL; | 333 | return -EINVAL; |
286 | } | 334 | } |
287 | 335 | ||
@@ -291,39 +339,40 @@ static int act8865_pmic_probe(struct i2c_client *client, | |||
291 | 339 | ||
292 | act8865->regmap = devm_regmap_init_i2c(client, &act8865_regmap_config); | 340 | act8865->regmap = devm_regmap_init_i2c(client, &act8865_regmap_config); |
293 | if (IS_ERR(act8865->regmap)) { | 341 | if (IS_ERR(act8865->regmap)) { |
294 | error = PTR_ERR(act8865->regmap); | 342 | ret = PTR_ERR(act8865->regmap); |
295 | dev_err(&client->dev, "Failed to allocate register map: %d\n", | 343 | dev_err(&client->dev, "Failed to allocate register map: %d\n", |
296 | error); | 344 | ret); |
297 | return error; | 345 | return ret; |
298 | } | 346 | } |
299 | 347 | ||
300 | /* Finally register devices */ | 348 | /* Finally register devices */ |
301 | for (i = 0; i < ACT8865_REG_NUM; i++) { | 349 | for (i = 0; i < num_regulators; i++) { |
302 | 350 | const struct regulator_desc *desc = ®ulators[i]; | |
303 | id = pdata->regulators[i].id; | 351 | struct regulator_config config = { }; |
352 | struct regulator_dev *rdev; | ||
304 | 353 | ||
305 | config.dev = dev; | 354 | config.dev = dev; |
306 | config.init_data = pdata->regulators[i].platform_data; | 355 | config.init_data = act8865_get_init_data(desc->id, pdata); |
307 | config.of_node = of_node[i]; | 356 | config.of_node = of_node[i]; |
308 | config.driver_data = act8865; | 357 | config.driver_data = act8865; |
309 | config.regmap = act8865->regmap; | 358 | config.regmap = act8865->regmap; |
310 | 359 | ||
311 | rdev = devm_regulator_register(&client->dev, &act8865_reg[i], | 360 | rdev = devm_regulator_register(&client->dev, desc, &config); |
312 | &config); | ||
313 | if (IS_ERR(rdev)) { | 361 | if (IS_ERR(rdev)) { |
314 | dev_err(dev, "failed to register %s\n", | 362 | dev_err(dev, "failed to register %s\n", desc->name); |
315 | act8865_reg[id].name); | ||
316 | return PTR_ERR(rdev); | 363 | return PTR_ERR(rdev); |
317 | } | 364 | } |
318 | } | 365 | } |
319 | 366 | ||
320 | i2c_set_clientdata(client, act8865); | 367 | i2c_set_clientdata(client, act8865); |
368 | devm_kfree(dev, of_node); | ||
321 | 369 | ||
322 | return 0; | 370 | return 0; |
323 | } | 371 | } |
324 | 372 | ||
325 | static const struct i2c_device_id act8865_ids[] = { | 373 | static const struct i2c_device_id act8865_ids[] = { |
326 | { "act8865", 0 }, | 374 | { .name = "act8846", .driver_data = ACT8846 }, |
375 | { .name = "act8865", .driver_data = ACT8865 }, | ||
327 | { }, | 376 | { }, |
328 | }; | 377 | }; |
329 | MODULE_DEVICE_TABLE(i2c, act8865_ids); | 378 | MODULE_DEVICE_TABLE(i2c, act8865_ids); |
@@ -339,6 +388,6 @@ static struct i2c_driver act8865_pmic_driver = { | |||
339 | 388 | ||
340 | module_i2c_driver(act8865_pmic_driver); | 389 | module_i2c_driver(act8865_pmic_driver); |
341 | 390 | ||
342 | MODULE_DESCRIPTION("active-semi act8865 voltage regulator driver"); | 391 | MODULE_DESCRIPTION("active-semi act88xx voltage regulator driver"); |
343 | MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>"); | 392 | MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>"); |
344 | MODULE_LICENSE("GPL v2"); | 393 | MODULE_LICENSE("GPL v2"); |
diff --git a/include/linux/regulator/act8865.h b/include/linux/regulator/act8865.h index 49206c1b4905..b6c4909b33af 100644 --- a/include/linux/regulator/act8865.h +++ b/include/linux/regulator/act8865.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * act8865.h -- Voltage regulation for the active-semi act8865 | 2 | * act8865.h -- Voltage regulation for active-semi act88xx PMUs |
3 | * | 3 | * |
4 | * Copyright (C) 2013 Atmel Corporation. | 4 | * Copyright (C) 2013 Atmel Corporation. |
5 | * | 5 | * |
@@ -29,6 +29,27 @@ enum { | |||
29 | ACT8865_REG_NUM, | 29 | ACT8865_REG_NUM, |
30 | }; | 30 | }; |
31 | 31 | ||
32 | enum { | ||
33 | ACT8846_ID_REG1, | ||
34 | ACT8846_ID_REG2, | ||
35 | ACT8846_ID_REG3, | ||
36 | ACT8846_ID_REG4, | ||
37 | ACT8846_ID_REG5, | ||
38 | ACT8846_ID_REG6, | ||
39 | ACT8846_ID_REG7, | ||
40 | ACT8846_ID_REG8, | ||
41 | ACT8846_ID_REG9, | ||
42 | ACT8846_ID_REG10, | ||
43 | ACT8846_ID_REG11, | ||
44 | ACT8846_ID_REG12, | ||
45 | ACT8846_REG_NUM, | ||
46 | }; | ||
47 | |||
48 | enum { | ||
49 | ACT8865, | ||
50 | ACT8846, | ||
51 | }; | ||
52 | |||
32 | /** | 53 | /** |
33 | * act8865_regulator_data - regulator data | 54 | * act8865_regulator_data - regulator data |
34 | * @id: regulator id | 55 | * @id: regulator id |