Commit | Line | Data |
---|---|---|
30e6599d AA |
1 | /* |
2 | * tps65023-regulator.c | |
3 | * | |
4 | * Supports TPS65023 Regulator | |
5 | * | |
6 | * Copyright (C) 2009 Texas Instrument Incorporated - http://www.ti.com/ | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License as | |
10 | * published by the Free Software Foundation version 2. | |
11 | * | |
12 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, | |
13 | * whether express or implied; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | */ | |
17 | ||
18 | #include <linux/kernel.h> | |
19 | #include <linux/module.h> | |
20 | #include <linux/init.h> | |
21 | #include <linux/err.h> | |
22 | #include <linux/platform_device.h> | |
23 | #include <linux/regulator/driver.h> | |
24 | #include <linux/regulator/machine.h> | |
25 | #include <linux/i2c.h> | |
26 | #include <linux/delay.h> | |
5a0e3ad6 | 27 | #include <linux/slab.h> |
90923351 | 28 | #include <linux/regmap.h> |
30e6599d AA |
29 | |
30 | /* Register definitions */ | |
31 | #define TPS65023_REG_VERSION 0 | |
32 | #define TPS65023_REG_PGOODZ 1 | |
33 | #define TPS65023_REG_MASK 2 | |
34 | #define TPS65023_REG_REG_CTRL 3 | |
35 | #define TPS65023_REG_CON_CTRL 4 | |
36 | #define TPS65023_REG_CON_CTRL2 5 | |
37 | #define TPS65023_REG_DEF_CORE 6 | |
38 | #define TPS65023_REG_DEFSLEW 7 | |
39 | #define TPS65023_REG_LDO_CTRL 8 | |
40 | ||
41 | /* PGOODZ bitfields */ | |
42 | #define TPS65023_PGOODZ_PWRFAILZ BIT(7) | |
43 | #define TPS65023_PGOODZ_LOWBATTZ BIT(6) | |
44 | #define TPS65023_PGOODZ_VDCDC1 BIT(5) | |
45 | #define TPS65023_PGOODZ_VDCDC2 BIT(4) | |
46 | #define TPS65023_PGOODZ_VDCDC3 BIT(3) | |
47 | #define TPS65023_PGOODZ_LDO2 BIT(2) | |
48 | #define TPS65023_PGOODZ_LDO1 BIT(1) | |
49 | ||
50 | /* MASK bitfields */ | |
51 | #define TPS65023_MASK_PWRFAILZ BIT(7) | |
52 | #define TPS65023_MASK_LOWBATTZ BIT(6) | |
53 | #define TPS65023_MASK_VDCDC1 BIT(5) | |
54 | #define TPS65023_MASK_VDCDC2 BIT(4) | |
55 | #define TPS65023_MASK_VDCDC3 BIT(3) | |
56 | #define TPS65023_MASK_LDO2 BIT(2) | |
57 | #define TPS65023_MASK_LDO1 BIT(1) | |
58 | ||
59 | /* REG_CTRL bitfields */ | |
60 | #define TPS65023_REG_CTRL_VDCDC1_EN BIT(5) | |
61 | #define TPS65023_REG_CTRL_VDCDC2_EN BIT(4) | |
62 | #define TPS65023_REG_CTRL_VDCDC3_EN BIT(3) | |
63 | #define TPS65023_REG_CTRL_LDO2_EN BIT(2) | |
64 | #define TPS65023_REG_CTRL_LDO1_EN BIT(1) | |
65 | ||
fc999b83 MF |
66 | /* REG_CTRL2 bitfields */ |
67 | #define TPS65023_REG_CTRL2_GO BIT(7) | |
68 | #define TPS65023_REG_CTRL2_CORE_ADJ BIT(6) | |
69 | #define TPS65023_REG_CTRL2_DCDC2 BIT(2) | |
70 | #define TPS65023_REG_CTRL2_DCDC1 BIT(2) | |
71 | #define TPS65023_REG_CTRL2_DCDC3 BIT(0) | |
72 | ||
f068ad8c MF |
73 | /* REG_CTRL2 bitfields */ |
74 | #define TPS65023_REG_CTRL2_GO BIT(7) | |
75 | #define TPS65023_REG_CTRL2_CORE_ADJ BIT(6) | |
76 | #define TPS65023_REG_CTRL2_DCDC2 BIT(2) | |
77 | #define TPS65023_REG_CTRL2_DCDC1 BIT(1) | |
78 | #define TPS65023_REG_CTRL2_DCDC3 BIT(0) | |
79 | ||
30e6599d AA |
80 | /* LDO_CTRL bitfields */ |
81 | #define TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_id) ((ldo_id)*4) | |
82 | #define TPS65023_LDO_CTRL_LDOx_MASK(ldo_id) (0xF0 >> ((ldo_id)*4)) | |
83 | ||
84 | /* Number of step-down converters available */ | |
85 | #define TPS65023_NUM_DCDC 3 | |
86 | /* Number of LDO voltage regulators available */ | |
87 | #define TPS65023_NUM_LDO 2 | |
88 | /* Number of total regulators available */ | |
89 | #define TPS65023_NUM_REGULATOR (TPS65023_NUM_DCDC + TPS65023_NUM_LDO) | |
90 | ||
91 | /* DCDCs */ | |
92 | #define TPS65023_DCDC_1 0 | |
93 | #define TPS65023_DCDC_2 1 | |
94 | #define TPS65023_DCDC_3 2 | |
95 | /* LDOs */ | |
96 | #define TPS65023_LDO_1 3 | |
97 | #define TPS65023_LDO_2 4 | |
98 | ||
99 | #define TPS65023_MAX_REG_ID TPS65023_LDO_2 | |
100 | ||
101 | /* Supported voltage values for regulators */ | |
1c3ede05 | 102 | static const u16 VCORE_VSEL_table[] = { |
30e6599d AA |
103 | 800, 825, 850, 875, |
104 | 900, 925, 950, 975, | |
105 | 1000, 1025, 1050, 1075, | |
106 | 1100, 1125, 1150, 1175, | |
107 | 1200, 1225, 1250, 1275, | |
108 | 1300, 1325, 1350, 1375, | |
109 | 1400, 1425, 1450, 1475, | |
110 | 1500, 1525, 1550, 1600, | |
111 | }; | |
112 | ||
1c3ede05 MF |
113 | |
114 | ||
115 | /* Supported voltage values for LDO regulators | |
116 | * for tps65021 and tps65023 */ | |
117 | static const u16 TPS65023_LDO1_VSEL_table[] = { | |
30e6599d AA |
118 | 1000, 1100, 1300, 1800, |
119 | 2200, 2600, 2800, 3150, | |
120 | }; | |
121 | ||
1c3ede05 | 122 | static const u16 TPS65023_LDO2_VSEL_table[] = { |
30e6599d AA |
123 | 1050, 1200, 1300, 1800, |
124 | 2500, 2800, 3000, 3300, | |
125 | }; | |
126 | ||
30e6599d AA |
127 | /* Regulator specific details */ |
128 | struct tps_info { | |
129 | const char *name; | |
130 | unsigned min_uV; | |
131 | unsigned max_uV; | |
132 | bool fixed; | |
133 | u8 table_len; | |
134 | const u16 *table; | |
135 | }; | |
136 | ||
137 | /* PMIC details */ | |
138 | struct tps_pmic { | |
139 | struct regulator_desc desc[TPS65023_NUM_REGULATOR]; | |
140 | struct i2c_client *client; | |
141 | struct regulator_dev *rdev[TPS65023_NUM_REGULATOR]; | |
142 | const struct tps_info *info[TPS65023_NUM_REGULATOR]; | |
90923351 | 143 | struct regmap *regmap; |
1c3ede05 MF |
144 | u8 core_regulator; |
145 | }; | |
146 | ||
147 | /* Struct passed as driver data */ | |
148 | struct tps_driver_data { | |
149 | const struct tps_info *info; | |
150 | u8 core_regulator; | |
30e6599d AA |
151 | }; |
152 | ||
30e6599d AA |
153 | static int tps_65023_set_bits(struct tps_pmic *tps, u8 reg, u8 mask) |
154 | { | |
90923351 | 155 | return regmap_update_bits(tps->regmap, reg, mask, mask); |
30e6599d AA |
156 | } |
157 | ||
158 | static int tps_65023_clear_bits(struct tps_pmic *tps, u8 reg, u8 mask) | |
159 | { | |
90923351 | 160 | return regmap_update_bits(tps->regmap, reg, mask, 0); |
30e6599d AA |
161 | } |
162 | ||
163 | static int tps_65023_reg_read(struct tps_pmic *tps, u8 reg) | |
164 | { | |
90923351 MB |
165 | unsigned int val; |
166 | int ret; | |
30e6599d | 167 | |
90923351 | 168 | ret = regmap_read(tps->regmap, reg, &val); |
30e6599d | 169 | |
90923351 MB |
170 | if (ret != 0) |
171 | return ret; | |
172 | else | |
173 | return val; | |
30e6599d AA |
174 | } |
175 | ||
176 | static int tps_65023_reg_write(struct tps_pmic *tps, u8 reg, u8 val) | |
177 | { | |
90923351 | 178 | return regmap_write(tps->regmap, reg, val); |
30e6599d AA |
179 | } |
180 | ||
181 | static int tps65023_dcdc_is_enabled(struct regulator_dev *dev) | |
182 | { | |
183 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
184 | int data, dcdc = rdev_get_id(dev); | |
185 | u8 shift; | |
186 | ||
187 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) | |
188 | return -EINVAL; | |
189 | ||
190 | shift = TPS65023_NUM_REGULATOR - dcdc; | |
191 | data = tps_65023_reg_read(tps, TPS65023_REG_REG_CTRL); | |
192 | ||
193 | if (data < 0) | |
194 | return data; | |
195 | else | |
196 | return (data & 1<<shift) ? 1 : 0; | |
197 | } | |
198 | ||
199 | static int tps65023_ldo_is_enabled(struct regulator_dev *dev) | |
200 | { | |
201 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
202 | int data, ldo = rdev_get_id(dev); | |
203 | u8 shift; | |
204 | ||
205 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | |
206 | return -EINVAL; | |
207 | ||
208 | shift = (ldo == TPS65023_LDO_1 ? 1 : 2); | |
209 | data = tps_65023_reg_read(tps, TPS65023_REG_REG_CTRL); | |
210 | ||
211 | if (data < 0) | |
212 | return data; | |
213 | else | |
214 | return (data & 1<<shift) ? 1 : 0; | |
215 | } | |
216 | ||
217 | static int tps65023_dcdc_enable(struct regulator_dev *dev) | |
218 | { | |
219 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
220 | int dcdc = rdev_get_id(dev); | |
221 | u8 shift; | |
222 | ||
223 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) | |
224 | return -EINVAL; | |
225 | ||
226 | shift = TPS65023_NUM_REGULATOR - dcdc; | |
227 | return tps_65023_set_bits(tps, TPS65023_REG_REG_CTRL, 1 << shift); | |
228 | } | |
229 | ||
230 | static int tps65023_dcdc_disable(struct regulator_dev *dev) | |
231 | { | |
232 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
233 | int dcdc = rdev_get_id(dev); | |
234 | u8 shift; | |
235 | ||
236 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) | |
237 | return -EINVAL; | |
238 | ||
239 | shift = TPS65023_NUM_REGULATOR - dcdc; | |
240 | return tps_65023_clear_bits(tps, TPS65023_REG_REG_CTRL, 1 << shift); | |
241 | } | |
242 | ||
243 | static int tps65023_ldo_enable(struct regulator_dev *dev) | |
244 | { | |
245 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
246 | int ldo = rdev_get_id(dev); | |
247 | u8 shift; | |
248 | ||
249 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | |
250 | return -EINVAL; | |
251 | ||
252 | shift = (ldo == TPS65023_LDO_1 ? 1 : 2); | |
253 | return tps_65023_set_bits(tps, TPS65023_REG_REG_CTRL, 1 << shift); | |
254 | } | |
255 | ||
256 | static int tps65023_ldo_disable(struct regulator_dev *dev) | |
257 | { | |
258 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
259 | int ldo = rdev_get_id(dev); | |
260 | u8 shift; | |
261 | ||
262 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | |
263 | return -EINVAL; | |
264 | ||
265 | shift = (ldo == TPS65023_LDO_1 ? 1 : 2); | |
266 | return tps_65023_clear_bits(tps, TPS65023_REG_REG_CTRL, 1 << shift); | |
267 | } | |
268 | ||
269 | static int tps65023_dcdc_get_voltage(struct regulator_dev *dev) | |
270 | { | |
271 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
272 | int data, dcdc = rdev_get_id(dev); | |
273 | ||
274 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) | |
275 | return -EINVAL; | |
276 | ||
1c3ede05 | 277 | if (dcdc == tps->core_regulator) { |
30e6599d AA |
278 | data = tps_65023_reg_read(tps, TPS65023_REG_DEF_CORE); |
279 | if (data < 0) | |
280 | return data; | |
281 | data &= (tps->info[dcdc]->table_len - 1); | |
282 | return tps->info[dcdc]->table[data] * 1000; | |
283 | } else | |
284 | return tps->info[dcdc]->min_uV; | |
285 | } | |
286 | ||
287 | static int tps65023_dcdc_set_voltage(struct regulator_dev *dev, | |
3a93f2a9 MB |
288 | int min_uV, int max_uV, |
289 | unsigned *selector) | |
30e6599d AA |
290 | { |
291 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
292 | int dcdc = rdev_get_id(dev); | |
293 | int vsel; | |
cc17ef3f | 294 | int ret; |
30e6599d | 295 | |
1c3ede05 | 296 | if (dcdc != tps->core_regulator) |
30e6599d | 297 | return -EINVAL; |
30e6599d AA |
298 | if (min_uV < tps->info[dcdc]->min_uV |
299 | || min_uV > tps->info[dcdc]->max_uV) | |
300 | return -EINVAL; | |
301 | if (max_uV < tps->info[dcdc]->min_uV | |
302 | || max_uV > tps->info[dcdc]->max_uV) | |
303 | return -EINVAL; | |
304 | ||
305 | for (vsel = 0; vsel < tps->info[dcdc]->table_len; vsel++) { | |
306 | int mV = tps->info[dcdc]->table[vsel]; | |
307 | int uV = mV * 1000; | |
308 | ||
309 | /* Break at the first in-range value */ | |
310 | if (min_uV <= uV && uV <= max_uV) | |
311 | break; | |
312 | } | |
313 | ||
3a93f2a9 MB |
314 | *selector = vsel; |
315 | ||
30e6599d | 316 | if (vsel == tps->info[dcdc]->table_len) |
cc17ef3f MF |
317 | goto failed; |
318 | ||
319 | ret = tps_65023_reg_write(tps, TPS65023_REG_DEF_CORE, vsel); | |
320 | ||
321 | /* Tell the chip that we have changed the value in DEFCORE | |
322 | * and its time to update the core voltage | |
323 | */ | |
324 | tps_65023_set_bits(tps, TPS65023_REG_CON_CTRL2, | |
325 | TPS65023_REG_CTRL2_GO); | |
326 | ||
327 | return ret; | |
328 | ||
329 | failed: | |
330 | return -EINVAL; | |
30e6599d AA |
331 | } |
332 | ||
333 | static int tps65023_ldo_get_voltage(struct regulator_dev *dev) | |
334 | { | |
335 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
336 | int data, ldo = rdev_get_id(dev); | |
337 | ||
338 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | |
339 | return -EINVAL; | |
340 | ||
341 | data = tps_65023_reg_read(tps, TPS65023_REG_LDO_CTRL); | |
342 | if (data < 0) | |
343 | return data; | |
344 | ||
345 | data >>= (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1)); | |
346 | data &= (tps->info[ldo]->table_len - 1); | |
347 | return tps->info[ldo]->table[data] * 1000; | |
348 | } | |
349 | ||
350 | static int tps65023_ldo_set_voltage(struct regulator_dev *dev, | |
3a93f2a9 | 351 | int min_uV, int max_uV, unsigned *selector) |
30e6599d AA |
352 | { |
353 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
354 | int data, vsel, ldo = rdev_get_id(dev); | |
355 | ||
356 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | |
357 | return -EINVAL; | |
358 | ||
359 | if (min_uV < tps->info[ldo]->min_uV || min_uV > tps->info[ldo]->max_uV) | |
360 | return -EINVAL; | |
361 | if (max_uV < tps->info[ldo]->min_uV || max_uV > tps->info[ldo]->max_uV) | |
362 | return -EINVAL; | |
363 | ||
364 | for (vsel = 0; vsel < tps->info[ldo]->table_len; vsel++) { | |
365 | int mV = tps->info[ldo]->table[vsel]; | |
366 | int uV = mV * 1000; | |
367 | ||
368 | /* Break at the first in-range value */ | |
369 | if (min_uV <= uV && uV <= max_uV) | |
370 | break; | |
371 | } | |
372 | ||
373 | if (vsel == tps->info[ldo]->table_len) | |
374 | return -EINVAL; | |
375 | ||
3a93f2a9 MB |
376 | *selector = vsel; |
377 | ||
30e6599d AA |
378 | data = tps_65023_reg_read(tps, TPS65023_REG_LDO_CTRL); |
379 | if (data < 0) | |
380 | return data; | |
381 | ||
382 | data &= TPS65023_LDO_CTRL_LDOx_MASK(ldo - TPS65023_LDO_1); | |
383 | data |= (vsel << (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1))); | |
384 | return tps_65023_reg_write(tps, TPS65023_REG_LDO_CTRL, data); | |
385 | } | |
386 | ||
387 | static int tps65023_dcdc_list_voltage(struct regulator_dev *dev, | |
388 | unsigned selector) | |
389 | { | |
390 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
391 | int dcdc = rdev_get_id(dev); | |
392 | ||
393 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) | |
394 | return -EINVAL; | |
395 | ||
1c3ede05 | 396 | if (dcdc == tps->core_regulator) { |
30e6599d AA |
397 | if (selector >= tps->info[dcdc]->table_len) |
398 | return -EINVAL; | |
399 | else | |
400 | return tps->info[dcdc]->table[selector] * 1000; | |
401 | } else | |
402 | return tps->info[dcdc]->min_uV; | |
403 | } | |
404 | ||
405 | static int tps65023_ldo_list_voltage(struct regulator_dev *dev, | |
406 | unsigned selector) | |
407 | { | |
408 | struct tps_pmic *tps = rdev_get_drvdata(dev); | |
409 | int ldo = rdev_get_id(dev); | |
410 | ||
411 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | |
412 | return -EINVAL; | |
413 | ||
414 | if (selector >= tps->info[ldo]->table_len) | |
415 | return -EINVAL; | |
416 | else | |
417 | return tps->info[ldo]->table[selector] * 1000; | |
418 | } | |
419 | ||
420 | /* Operations permitted on VDCDCx */ | |
421 | static struct regulator_ops tps65023_dcdc_ops = { | |
422 | .is_enabled = tps65023_dcdc_is_enabled, | |
423 | .enable = tps65023_dcdc_enable, | |
424 | .disable = tps65023_dcdc_disable, | |
425 | .get_voltage = tps65023_dcdc_get_voltage, | |
426 | .set_voltage = tps65023_dcdc_set_voltage, | |
427 | .list_voltage = tps65023_dcdc_list_voltage, | |
428 | }; | |
429 | ||
430 | /* Operations permitted on LDOx */ | |
431 | static struct regulator_ops tps65023_ldo_ops = { | |
432 | .is_enabled = tps65023_ldo_is_enabled, | |
433 | .enable = tps65023_ldo_enable, | |
434 | .disable = tps65023_ldo_disable, | |
435 | .get_voltage = tps65023_ldo_get_voltage, | |
436 | .set_voltage = tps65023_ldo_set_voltage, | |
437 | .list_voltage = tps65023_ldo_list_voltage, | |
438 | }; | |
439 | ||
90923351 MB |
440 | static struct regmap_config tps65023_regmap_config = { |
441 | .reg_bits = 8, | |
442 | .val_bits = 8, | |
443 | }; | |
444 | ||
54d13ab1 DT |
445 | static int __devinit tps_65023_probe(struct i2c_client *client, |
446 | const struct i2c_device_id *id) | |
30e6599d | 447 | { |
1c3ede05 MF |
448 | const struct tps_driver_data *drv_data = (void *)id->driver_data; |
449 | const struct tps_info *info = drv_data->info; | |
30e6599d AA |
450 | struct regulator_init_data *init_data; |
451 | struct regulator_dev *rdev; | |
452 | struct tps_pmic *tps; | |
453 | int i; | |
54d13ab1 | 454 | int error; |
30e6599d AA |
455 | |
456 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | |
457 | return -EIO; | |
458 | ||
459 | /** | |
460 | * init_data points to array of regulator_init structures | |
461 | * coming from the board-evm file. | |
462 | */ | |
463 | init_data = client->dev.platform_data; | |
30e6599d AA |
464 | if (!init_data) |
465 | return -EIO; | |
466 | ||
467 | tps = kzalloc(sizeof(*tps), GFP_KERNEL); | |
468 | if (!tps) | |
469 | return -ENOMEM; | |
470 | ||
90923351 MB |
471 | tps->regmap = regmap_init_i2c(client, &tps65023_regmap_config); |
472 | if (IS_ERR(tps->regmap)) { | |
473 | error = PTR_ERR(tps->regmap); | |
474 | dev_err(&client->dev, "Failed to allocate register map: %d\n", | |
475 | error); | |
476 | goto fail_alloc; | |
477 | } | |
30e6599d AA |
478 | |
479 | /* common for all regulators */ | |
480 | tps->client = client; | |
1c3ede05 | 481 | tps->core_regulator = drv_data->core_regulator; |
30e6599d AA |
482 | |
483 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++, info++, init_data++) { | |
484 | /* Store regulator specific information */ | |
485 | tps->info[i] = info; | |
486 | ||
487 | tps->desc[i].name = info->name; | |
77fa44d0 | 488 | tps->desc[i].id = i; |
1c3ede05 | 489 | tps->desc[i].n_voltages = info->table_len; |
30e6599d AA |
490 | tps->desc[i].ops = (i > TPS65023_DCDC_3 ? |
491 | &tps65023_ldo_ops : &tps65023_dcdc_ops); | |
492 | tps->desc[i].type = REGULATOR_VOLTAGE; | |
493 | tps->desc[i].owner = THIS_MODULE; | |
494 | ||
495 | /* Register the regulators */ | |
496 | rdev = regulator_register(&tps->desc[i], &client->dev, | |
54d13ab1 | 497 | init_data, tps); |
30e6599d AA |
498 | if (IS_ERR(rdev)) { |
499 | dev_err(&client->dev, "failed to register %s\n", | |
500 | id->name); | |
54d13ab1 DT |
501 | error = PTR_ERR(rdev); |
502 | goto fail; | |
30e6599d AA |
503 | } |
504 | ||
505 | /* Save regulator for cleanup */ | |
506 | tps->rdev[i] = rdev; | |
507 | } | |
508 | ||
509 | i2c_set_clientdata(client, tps); | |
510 | ||
f068ad8c MF |
511 | /* Enable setting output voltage by I2C */ |
512 | tps_65023_clear_bits(tps, TPS65023_REG_CON_CTRL2, | |
513 | TPS65023_REG_CTRL2_CORE_ADJ); | |
514 | ||
fc999b83 MF |
515 | /* Enable setting output voltage by I2C */ |
516 | tps_65023_clear_bits(tps, TPS65023_REG_CON_CTRL2, | |
517 | TPS65023_REG_CTRL2_CORE_ADJ); | |
518 | ||
30e6599d | 519 | return 0; |
54d13ab1 DT |
520 | |
521 | fail: | |
522 | while (--i >= 0) | |
523 | regulator_unregister(tps->rdev[i]); | |
524 | ||
90923351 MB |
525 | regmap_exit(tps->regmap); |
526 | fail_alloc: | |
54d13ab1 DT |
527 | kfree(tps); |
528 | return error; | |
30e6599d AA |
529 | } |
530 | ||
531 | /** | |
532 | * tps_65023_remove - TPS65023 driver i2c remove handler | |
533 | * @client: i2c driver client device structure | |
534 | * | |
535 | * Unregister TPS driver as an i2c client device driver | |
536 | */ | |
537 | static int __devexit tps_65023_remove(struct i2c_client *client) | |
538 | { | |
539 | struct tps_pmic *tps = i2c_get_clientdata(client); | |
540 | int i; | |
541 | ||
542 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++) | |
543 | regulator_unregister(tps->rdev[i]); | |
544 | ||
90923351 | 545 | regmap_exit(tps->regmap); |
30e6599d AA |
546 | kfree(tps); |
547 | ||
548 | return 0; | |
549 | } | |
550 | ||
1c3ede05 MF |
551 | static const struct tps_info tps65021_regs[] = { |
552 | { | |
553 | .name = "VDCDC1", | |
554 | .min_uV = 3300000, | |
555 | .max_uV = 3300000, | |
556 | .fixed = 1, | |
557 | }, | |
558 | { | |
559 | .name = "VDCDC2", | |
560 | .min_uV = 1800000, | |
561 | .max_uV = 1800000, | |
562 | .fixed = 1, | |
563 | }, | |
564 | { | |
565 | .name = "VDCDC3", | |
566 | .min_uV = 800000, | |
567 | .max_uV = 1600000, | |
568 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), | |
569 | .table = VCORE_VSEL_table, | |
570 | }, | |
571 | { | |
572 | .name = "LDO1", | |
573 | .min_uV = 1000000, | |
574 | .max_uV = 3150000, | |
575 | .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), | |
576 | .table = TPS65023_LDO1_VSEL_table, | |
577 | }, | |
578 | { | |
579 | .name = "LDO2", | |
580 | .min_uV = 1050000, | |
581 | .max_uV = 3300000, | |
582 | .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), | |
583 | .table = TPS65023_LDO2_VSEL_table, | |
584 | }, | |
585 | }; | |
586 | ||
30e6599d AA |
587 | static const struct tps_info tps65023_regs[] = { |
588 | { | |
589 | .name = "VDCDC1", | |
590 | .min_uV = 800000, | |
591 | .max_uV = 1600000, | |
1c3ede05 MF |
592 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), |
593 | .table = VCORE_VSEL_table, | |
30e6599d AA |
594 | }, |
595 | { | |
596 | .name = "VDCDC2", | |
597 | .min_uV = 3300000, | |
598 | .max_uV = 3300000, | |
599 | .fixed = 1, | |
600 | }, | |
601 | { | |
602 | .name = "VDCDC3", | |
603 | .min_uV = 1800000, | |
604 | .max_uV = 1800000, | |
605 | .fixed = 1, | |
606 | }, | |
607 | { | |
608 | .name = "LDO1", | |
609 | .min_uV = 1000000, | |
610 | .max_uV = 3150000, | |
1c3ede05 MF |
611 | .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), |
612 | .table = TPS65023_LDO1_VSEL_table, | |
30e6599d AA |
613 | }, |
614 | { | |
615 | .name = "LDO2", | |
616 | .min_uV = 1050000, | |
617 | .max_uV = 3300000, | |
1c3ede05 MF |
618 | .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), |
619 | .table = TPS65023_LDO2_VSEL_table, | |
30e6599d AA |
620 | }, |
621 | }; | |
622 | ||
1c3ede05 MF |
623 | static struct tps_driver_data tps65021_drv_data = { |
624 | .info = tps65021_regs, | |
625 | .core_regulator = TPS65023_DCDC_3, | |
626 | }; | |
627 | ||
628 | static struct tps_driver_data tps65023_drv_data = { | |
629 | .info = tps65023_regs, | |
630 | .core_regulator = TPS65023_DCDC_1, | |
631 | }; | |
632 | ||
9e108d33 LG |
633 | static const struct i2c_device_id tps_65023_id[] = { |
634 | {.name = "tps65023", | |
1c3ede05 | 635 | .driver_data = (unsigned long) &tps65023_drv_data}, |
1880a2fc | 636 | {.name = "tps65021", |
1c3ede05 | 637 | .driver_data = (unsigned long) &tps65021_drv_data,}, |
9e108d33 | 638 | { }, |
30e6599d AA |
639 | }; |
640 | ||
641 | MODULE_DEVICE_TABLE(i2c, tps_65023_id); | |
642 | ||
643 | static struct i2c_driver tps_65023_i2c_driver = { | |
644 | .driver = { | |
645 | .name = "tps65023", | |
646 | .owner = THIS_MODULE, | |
647 | }, | |
648 | .probe = tps_65023_probe, | |
649 | .remove = __devexit_p(tps_65023_remove), | |
9e108d33 | 650 | .id_table = tps_65023_id, |
30e6599d AA |
651 | }; |
652 | ||
653 | /** | |
654 | * tps_65023_init | |
655 | * | |
656 | * Module init function | |
657 | */ | |
658 | static int __init tps_65023_init(void) | |
659 | { | |
660 | return i2c_add_driver(&tps_65023_i2c_driver); | |
661 | } | |
662 | subsys_initcall(tps_65023_init); | |
663 | ||
664 | /** | |
665 | * tps_65023_cleanup | |
666 | * | |
667 | * Module exit function | |
668 | */ | |
669 | static void __exit tps_65023_cleanup(void) | |
670 | { | |
671 | i2c_del_driver(&tps_65023_i2c_driver); | |
672 | } | |
673 | module_exit(tps_65023_cleanup); | |
674 | ||
675 | MODULE_AUTHOR("Texas Instruments"); | |
676 | MODULE_DESCRIPTION("TPS65023 voltage regulator driver"); | |
9e108d33 | 677 | MODULE_LICENSE("GPL v2"); |