blob: e84be29533f49df306417a54d8594e257676afa6 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Kim, Miloaf8b5fc2012-06-19 07:08:22 +00002/*
3 * Copyright 2012 Texas Instruments
4 *
5 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
Kim, Miloaf8b5fc2012-06-19 07:08:22 +00006 */
7
8#include <linux/module.h>
9#include <linux/slab.h>
10#include <linux/i2c.h>
11#include <linux/regmap.h>
12#include <linux/err.h>
13#include <linux/gpio.h>
Paul Kocialkowski7e6213f2016-02-05 19:42:19 +010014#include <linux/delay.h>
Kim, Miloaf8b5fc2012-06-19 07:08:22 +000015#include <linux/regulator/lp872x.h>
16#include <linux/regulator/driver.h>
17#include <linux/platform_device.h>
Kim, Milo00fd6e62013-05-20 12:36:07 +000018#include <linux/of.h>
19#include <linux/of_gpio.h>
20#include <linux/regulator/of_regulator.h>
Kim, Miloaf8b5fc2012-06-19 07:08:22 +000021
22/* Registers : LP8720/8725 shared */
23#define LP872X_GENERAL_CFG 0x00
24#define LP872X_LDO1_VOUT 0x01
25#define LP872X_LDO2_VOUT 0x02
26#define LP872X_LDO3_VOUT 0x03
27#define LP872X_LDO4_VOUT 0x04
28#define LP872X_LDO5_VOUT 0x05
29
30/* Registers : LP8720 */
31#define LP8720_BUCK_VOUT1 0x06
32#define LP8720_BUCK_VOUT2 0x07
33#define LP8720_ENABLE 0x08
34
35/* Registers : LP8725 */
36#define LP8725_LILO1_VOUT 0x06
37#define LP8725_LILO2_VOUT 0x07
38#define LP8725_BUCK1_VOUT1 0x08
39#define LP8725_BUCK1_VOUT2 0x09
40#define LP8725_BUCK2_VOUT1 0x0A
41#define LP8725_BUCK2_VOUT2 0x0B
42#define LP8725_BUCK_CTRL 0x0C
43#define LP8725_LDO_CTRL 0x0D
44
45/* Mask/shift : LP8720/LP8725 shared */
46#define LP872X_VOUT_M 0x1F
47#define LP872X_START_DELAY_M 0xE0
48#define LP872X_START_DELAY_S 5
49#define LP872X_EN_LDO1_M BIT(0)
50#define LP872X_EN_LDO2_M BIT(1)
51#define LP872X_EN_LDO3_M BIT(2)
52#define LP872X_EN_LDO4_M BIT(3)
53#define LP872X_EN_LDO5_M BIT(4)
54
55/* Mask/shift : LP8720 */
56#define LP8720_TIMESTEP_S 0 /* Addr 00h */
57#define LP8720_TIMESTEP_M BIT(0)
58#define LP8720_EXT_DVS_M BIT(2)
59#define LP8720_BUCK_FPWM_S 5 /* Addr 07h */
60#define LP8720_BUCK_FPWM_M BIT(5)
61#define LP8720_EN_BUCK_M BIT(5) /* Addr 08h */
62#define LP8720_DVS_SEL_M BIT(7)
63
64/* Mask/shift : LP8725 */
65#define LP8725_TIMESTEP_M 0xC0 /* Addr 00h */
66#define LP8725_TIMESTEP_S 6
67#define LP8725_BUCK1_EN_M BIT(0)
68#define LP8725_DVS1_M BIT(2)
69#define LP8725_DVS2_M BIT(3)
70#define LP8725_BUCK2_EN_M BIT(4)
71#define LP8725_BUCK_CL_M 0xC0 /* Addr 09h, 0Bh */
72#define LP8725_BUCK_CL_S 6
73#define LP8725_BUCK1_FPWM_S 1 /* Addr 0Ch */
74#define LP8725_BUCK1_FPWM_M BIT(1)
75#define LP8725_BUCK2_FPWM_S 5
76#define LP8725_BUCK2_FPWM_M BIT(5)
77#define LP8725_EN_LILO1_M BIT(5) /* Addr 0Dh */
78#define LP8725_EN_LILO2_M BIT(6)
79
80/* PWM mode */
81#define LP872X_FORCE_PWM 1
82#define LP872X_AUTO_PWM 0
83
84#define LP8720_NUM_REGULATORS 6
85#define LP8725_NUM_REGULATORS 9
86#define EXTERN_DVS_USED 0
87#define MAX_DELAY 6
88
Kim, Milob158fba2012-09-05 04:39:16 +000089/* Default DVS Mode */
90#define LP8720_DEFAULT_DVS 0
91#define LP8725_DEFAULT_DVS BIT(2)
92
Kim, Miloaf8b5fc2012-06-19 07:08:22 +000093/* dump registers in regmap-debugfs */
94#define MAX_REGISTERS 0x0F
95
96enum lp872x_id {
97 LP8720,
98 LP8725,
99};
100
101struct lp872x {
102 struct regmap *regmap;
103 struct device *dev;
104 enum lp872x_id chipid;
105 struct lp872x_platform_data *pdata;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000106 int num_regulators;
107 enum lp872x_dvs_state dvs_pin;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000108};
109
110/* LP8720/LP8725 shared voltage table for LDOs */
111static const unsigned int lp872x_ldo_vtbl[] = {
112 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, 1550000,
113 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000, 2000000,
114 2100000, 2200000, 2300000, 2400000, 2500000, 2600000, 2650000, 2700000,
115 2750000, 2800000, 2850000, 2900000, 2950000, 3000000, 3100000, 3300000,
116};
117
118/* LP8720 LDO4 voltage table */
119static const unsigned int lp8720_ldo4_vtbl[] = {
120 800000, 850000, 900000, 1000000, 1100000, 1200000, 1250000, 1300000,
121 1350000, 1400000, 1450000, 1500000, 1550000, 1600000, 1650000, 1700000,
122 1750000, 1800000, 1850000, 1900000, 2000000, 2100000, 2200000, 2300000,
123 2400000, 2500000, 2600000, 2650000, 2700000, 2750000, 2800000, 2850000,
124};
125
126/* LP8725 LILO(Low Input Low Output) voltage table */
127static const unsigned int lp8725_lilo_vtbl[] = {
128 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, 1150000,
129 1200000, 1250000, 1300000, 1350000, 1400000, 1500000, 1600000, 1700000,
130 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
131 2600000, 2700000, 2800000, 2850000, 2900000, 3000000, 3100000, 3300000,
132};
133
134/* LP8720 BUCK voltage table */
135#define EXT_R 0 /* external resistor divider */
136static const unsigned int lp8720_buck_vtbl[] = {
137 EXT_R, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000,
138 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000,
139 1550000, 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000,
140 1950000, 2000000, 2050000, 2100000, 2150000, 2200000, 2250000, 2300000,
141};
142
143/* LP8725 BUCK voltage table */
144static const unsigned int lp8725_buck_vtbl[] = {
145 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, 1150000,
146 1200000, 1250000, 1300000, 1350000, 1400000, 1500000, 1600000, 1700000,
147 1750000, 1800000, 1850000, 1900000, 2000000, 2100000, 2200000, 2300000,
148 2400000, 2500000, 2600000, 2700000, 2800000, 2850000, 2900000, 3000000,
149};
150
151/* LP8725 BUCK current limit */
152static const unsigned int lp8725_buck_uA[] = {
153 460000, 780000, 1050000, 1370000,
154};
155
156static int lp872x_read_byte(struct lp872x *lp, u8 addr, u8 *data)
157{
158 int ret;
159 unsigned int val;
160
161 ret = regmap_read(lp->regmap, addr, &val);
162 if (ret < 0) {
163 dev_err(lp->dev, "failed to read 0x%.2x\n", addr);
164 return ret;
165 }
166
167 *data = (u8)val;
168 return 0;
169}
170
171static inline int lp872x_write_byte(struct lp872x *lp, u8 addr, u8 data)
172{
173 return regmap_write(lp->regmap, addr, data);
174}
175
176static inline int lp872x_update_bits(struct lp872x *lp, u8 addr,
177 unsigned int mask, u8 data)
178{
179 return regmap_update_bits(lp->regmap, addr, mask, data);
180}
181
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000182static int lp872x_get_timestep_usec(struct lp872x *lp)
183{
184 enum lp872x_id chip = lp->chipid;
185 u8 val, mask, shift;
186 int *time_usec, size, ret;
187 int lp8720_time_usec[] = { 25, 50 };
188 int lp8725_time_usec[] = { 32, 64, 128, 256 };
189
190 switch (chip) {
191 case LP8720:
192 mask = LP8720_TIMESTEP_M;
193 shift = LP8720_TIMESTEP_S;
194 time_usec = &lp8720_time_usec[0];
195 size = ARRAY_SIZE(lp8720_time_usec);
196 break;
197 case LP8725:
198 mask = LP8725_TIMESTEP_M;
199 shift = LP8725_TIMESTEP_S;
200 time_usec = &lp8725_time_usec[0];
201 size = ARRAY_SIZE(lp8725_time_usec);
202 break;
203 default:
204 return -EINVAL;
205 }
206
207 ret = lp872x_read_byte(lp, LP872X_GENERAL_CFG, &val);
208 if (ret)
Sachin Kamatad5ec6c2014-02-18 16:11:02 +0530209 return ret;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000210
211 val = (val & mask) >> shift;
212 if (val >= size)
213 return -EINVAL;
214
215 return *(time_usec + val);
216}
217
218static int lp872x_regulator_enable_time(struct regulator_dev *rdev)
219{
220 struct lp872x *lp = rdev_get_drvdata(rdev);
Axel Lin2c129922012-12-08 09:56:48 +0800221 enum lp872x_regulator_id rid = rdev_get_id(rdev);
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000222 int time_step_us = lp872x_get_timestep_usec(lp);
Axel Lin2c129922012-12-08 09:56:48 +0800223 int ret;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000224 u8 addr, val;
225
226 if (time_step_us < 0)
Sachin Kamatad5ec6c2014-02-18 16:11:02 +0530227 return time_step_us;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000228
Axel Lin2c129922012-12-08 09:56:48 +0800229 switch (rid) {
230 case LP8720_ID_LDO1 ... LP8720_ID_BUCK:
231 addr = LP872X_LDO1_VOUT + rid;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000232 break;
Axel Lin2c129922012-12-08 09:56:48 +0800233 case LP8725_ID_LDO1 ... LP8725_ID_BUCK1:
234 addr = LP872X_LDO1_VOUT + rid - LP8725_ID_BASE;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000235 break;
236 case LP8725_ID_BUCK2:
237 addr = LP8725_BUCK2_VOUT1;
238 break;
239 default:
240 return -EINVAL;
241 }
242
243 ret = lp872x_read_byte(lp, addr, &val);
244 if (ret)
245 return ret;
246
247 val = (val & LP872X_START_DELAY_M) >> LP872X_START_DELAY_S;
248
249 return val > MAX_DELAY ? 0 : val * time_step_us;
250}
251
Kim, Milo9d6da6f2012-09-05 04:39:33 +0000252static void lp872x_set_dvs(struct lp872x *lp, enum lp872x_dvs_sel dvs_sel,
253 int gpio)
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000254{
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000255 enum lp872x_dvs_state state;
256
257 state = dvs_sel == SEL_V1 ? DVS_HIGH : DVS_LOW;
258 gpio_set_value(gpio, state);
259 lp->dvs_pin = state;
260}
261
262static u8 lp872x_select_buck_vout_addr(struct lp872x *lp,
263 enum lp872x_regulator_id buck)
264{
265 u8 val, addr;
266
267 if (lp872x_read_byte(lp, LP872X_GENERAL_CFG, &val))
268 return 0;
269
270 switch (buck) {
271 case LP8720_ID_BUCK:
272 if (val & LP8720_EXT_DVS_M) {
273 addr = (lp->dvs_pin == DVS_HIGH) ?
274 LP8720_BUCK_VOUT1 : LP8720_BUCK_VOUT2;
275 } else {
276 if (lp872x_read_byte(lp, LP8720_ENABLE, &val))
277 return 0;
278
279 addr = val & LP8720_DVS_SEL_M ?
280 LP8720_BUCK_VOUT1 : LP8720_BUCK_VOUT2;
281 }
282 break;
283 case LP8725_ID_BUCK1:
284 if (val & LP8725_DVS1_M)
285 addr = LP8725_BUCK1_VOUT1;
286 else
287 addr = (lp->dvs_pin == DVS_HIGH) ?
288 LP8725_BUCK1_VOUT1 : LP8725_BUCK1_VOUT2;
289 break;
290 case LP8725_ID_BUCK2:
291 addr = val & LP8725_DVS2_M ?
292 LP8725_BUCK2_VOUT1 : LP8725_BUCK2_VOUT2;
293 break;
294 default:
295 return 0;
296 }
297
298 return addr;
299}
300
301static bool lp872x_is_valid_buck_addr(u8 addr)
302{
303 switch (addr) {
304 case LP8720_BUCK_VOUT1:
305 case LP8720_BUCK_VOUT2:
306 case LP8725_BUCK1_VOUT1:
307 case LP8725_BUCK1_VOUT2:
308 case LP8725_BUCK2_VOUT1:
309 case LP8725_BUCK2_VOUT2:
310 return true;
311 default:
312 return false;
313 }
314}
315
316static int lp872x_buck_set_voltage_sel(struct regulator_dev *rdev,
317 unsigned selector)
318{
319 struct lp872x *lp = rdev_get_drvdata(rdev);
320 enum lp872x_regulator_id buck = rdev_get_id(rdev);
321 u8 addr, mask = LP872X_VOUT_M;
Kim, Milo9d6da6f2012-09-05 04:39:33 +0000322 struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000323
324 if (dvs && gpio_is_valid(dvs->gpio))
Kim, Milo9d6da6f2012-09-05 04:39:33 +0000325 lp872x_set_dvs(lp, dvs->vsel, dvs->gpio);
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000326
327 addr = lp872x_select_buck_vout_addr(lp, buck);
328 if (!lp872x_is_valid_buck_addr(addr))
329 return -EINVAL;
330
331 return lp872x_update_bits(lp, addr, mask, selector);
332}
333
334static int lp872x_buck_get_voltage_sel(struct regulator_dev *rdev)
335{
336 struct lp872x *lp = rdev_get_drvdata(rdev);
337 enum lp872x_regulator_id buck = rdev_get_id(rdev);
338 u8 addr, val;
339 int ret;
340
341 addr = lp872x_select_buck_vout_addr(lp, buck);
342 if (!lp872x_is_valid_buck_addr(addr))
343 return -EINVAL;
344
345 ret = lp872x_read_byte(lp, addr, &val);
346 if (ret)
347 return ret;
348
349 return val & LP872X_VOUT_M;
350}
351
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000352static int lp872x_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
353{
354 struct lp872x *lp = rdev_get_drvdata(rdev);
355 enum lp872x_regulator_id buck = rdev_get_id(rdev);
356 u8 addr, mask, shift, val;
357
358 switch (buck) {
359 case LP8720_ID_BUCK:
360 addr = LP8720_BUCK_VOUT2;
361 mask = LP8720_BUCK_FPWM_M;
362 shift = LP8720_BUCK_FPWM_S;
363 break;
364 case LP8725_ID_BUCK1:
365 addr = LP8725_BUCK_CTRL;
366 mask = LP8725_BUCK1_FPWM_M;
367 shift = LP8725_BUCK1_FPWM_S;
368 break;
369 case LP8725_ID_BUCK2:
370 addr = LP8725_BUCK_CTRL;
371 mask = LP8725_BUCK2_FPWM_M;
372 shift = LP8725_BUCK2_FPWM_S;
373 break;
374 default:
375 return -EINVAL;
376 }
377
378 if (mode == REGULATOR_MODE_FAST)
379 val = LP872X_FORCE_PWM << shift;
380 else if (mode == REGULATOR_MODE_NORMAL)
381 val = LP872X_AUTO_PWM << shift;
382 else
383 return -EINVAL;
384
385 return lp872x_update_bits(lp, addr, mask, val);
386}
387
388static unsigned int lp872x_buck_get_mode(struct regulator_dev *rdev)
389{
390 struct lp872x *lp = rdev_get_drvdata(rdev);
391 enum lp872x_regulator_id buck = rdev_get_id(rdev);
392 u8 addr, mask, val;
393 int ret;
394
395 switch (buck) {
396 case LP8720_ID_BUCK:
397 addr = LP8720_BUCK_VOUT2;
398 mask = LP8720_BUCK_FPWM_M;
399 break;
400 case LP8725_ID_BUCK1:
401 addr = LP8725_BUCK_CTRL;
402 mask = LP8725_BUCK1_FPWM_M;
403 break;
404 case LP8725_ID_BUCK2:
405 addr = LP8725_BUCK_CTRL;
406 mask = LP8725_BUCK2_FPWM_M;
407 break;
408 default:
409 return -EINVAL;
410 }
411
412 ret = lp872x_read_byte(lp, addr, &val);
413 if (ret)
414 return ret;
415
416 return val & mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
417}
418
Axel Linf9664042019-01-26 11:39:02 +0800419static const struct regulator_ops lp872x_ldo_ops = {
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000420 .list_voltage = regulator_list_voltage_table,
Axel Lina32f9e02013-04-24 20:44:47 +0800421 .map_voltage = regulator_map_voltage_ascend,
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000422 .set_voltage_sel = regulator_set_voltage_sel_regmap,
423 .get_voltage_sel = regulator_get_voltage_sel_regmap,
424 .enable = regulator_enable_regmap,
425 .disable = regulator_disable_regmap,
426 .is_enabled = regulator_is_enabled_regmap,
427 .enable_time = lp872x_regulator_enable_time,
428};
429
Axel Linf9664042019-01-26 11:39:02 +0800430static const struct regulator_ops lp8720_buck_ops = {
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000431 .list_voltage = regulator_list_voltage_table,
Axel Lina32f9e02013-04-24 20:44:47 +0800432 .map_voltage = regulator_map_voltage_ascend,
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000433 .set_voltage_sel = lp872x_buck_set_voltage_sel,
434 .get_voltage_sel = lp872x_buck_get_voltage_sel,
435 .enable = regulator_enable_regmap,
436 .disable = regulator_disable_regmap,
437 .is_enabled = regulator_is_enabled_regmap,
438 .enable_time = lp872x_regulator_enable_time,
439 .set_mode = lp872x_buck_set_mode,
440 .get_mode = lp872x_buck_get_mode,
441};
442
Axel Linf9664042019-01-26 11:39:02 +0800443static const struct regulator_ops lp8725_buck_ops = {
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000444 .list_voltage = regulator_list_voltage_table,
Axel Lina32f9e02013-04-24 20:44:47 +0800445 .map_voltage = regulator_map_voltage_ascend,
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000446 .set_voltage_sel = lp872x_buck_set_voltage_sel,
447 .get_voltage_sel = lp872x_buck_get_voltage_sel,
448 .enable = regulator_enable_regmap,
449 .disable = regulator_disable_regmap,
450 .is_enabled = regulator_is_enabled_regmap,
451 .enable_time = lp872x_regulator_enable_time,
452 .set_mode = lp872x_buck_set_mode,
453 .get_mode = lp872x_buck_get_mode,
Axel Lin8918f062019-02-28 21:40:16 +0800454 .set_current_limit = regulator_set_current_limit_regmap,
455 .get_current_limit = regulator_get_current_limit_regmap,
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000456};
457
Axel Linf9664042019-01-26 11:39:02 +0800458static const struct regulator_desc lp8720_regulator_desc[] = {
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000459 {
460 .name = "ldo1",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100461 .of_match = of_match_ptr("ldo1"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000462 .id = LP8720_ID_LDO1,
463 .ops = &lp872x_ldo_ops,
464 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
465 .volt_table = lp872x_ldo_vtbl,
466 .type = REGULATOR_VOLTAGE,
467 .owner = THIS_MODULE,
468 .vsel_reg = LP872X_LDO1_VOUT,
469 .vsel_mask = LP872X_VOUT_M,
470 .enable_reg = LP8720_ENABLE,
471 .enable_mask = LP872X_EN_LDO1_M,
472 },
473 {
474 .name = "ldo2",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100475 .of_match = of_match_ptr("ldo2"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000476 .id = LP8720_ID_LDO2,
477 .ops = &lp872x_ldo_ops,
478 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
479 .volt_table = lp872x_ldo_vtbl,
480 .type = REGULATOR_VOLTAGE,
481 .owner = THIS_MODULE,
482 .vsel_reg = LP872X_LDO2_VOUT,
483 .vsel_mask = LP872X_VOUT_M,
484 .enable_reg = LP8720_ENABLE,
485 .enable_mask = LP872X_EN_LDO2_M,
486 },
487 {
488 .name = "ldo3",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100489 .of_match = of_match_ptr("ldo3"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000490 .id = LP8720_ID_LDO3,
491 .ops = &lp872x_ldo_ops,
492 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
493 .volt_table = lp872x_ldo_vtbl,
494 .type = REGULATOR_VOLTAGE,
495 .owner = THIS_MODULE,
496 .vsel_reg = LP872X_LDO3_VOUT,
497 .vsel_mask = LP872X_VOUT_M,
498 .enable_reg = LP8720_ENABLE,
499 .enable_mask = LP872X_EN_LDO3_M,
500 },
501 {
502 .name = "ldo4",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100503 .of_match = of_match_ptr("ldo4"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000504 .id = LP8720_ID_LDO4,
505 .ops = &lp872x_ldo_ops,
506 .n_voltages = ARRAY_SIZE(lp8720_ldo4_vtbl),
507 .volt_table = lp8720_ldo4_vtbl,
508 .type = REGULATOR_VOLTAGE,
509 .owner = THIS_MODULE,
510 .vsel_reg = LP872X_LDO4_VOUT,
511 .vsel_mask = LP872X_VOUT_M,
512 .enable_reg = LP8720_ENABLE,
513 .enable_mask = LP872X_EN_LDO4_M,
514 },
515 {
516 .name = "ldo5",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100517 .of_match = of_match_ptr("ldo5"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000518 .id = LP8720_ID_LDO5,
519 .ops = &lp872x_ldo_ops,
520 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
521 .volt_table = lp872x_ldo_vtbl,
522 .type = REGULATOR_VOLTAGE,
523 .owner = THIS_MODULE,
524 .vsel_reg = LP872X_LDO5_VOUT,
525 .vsel_mask = LP872X_VOUT_M,
526 .enable_reg = LP8720_ENABLE,
527 .enable_mask = LP872X_EN_LDO5_M,
528 },
529 {
530 .name = "buck",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100531 .of_match = of_match_ptr("buck"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000532 .id = LP8720_ID_BUCK,
533 .ops = &lp8720_buck_ops,
534 .n_voltages = ARRAY_SIZE(lp8720_buck_vtbl),
535 .volt_table = lp8720_buck_vtbl,
536 .type = REGULATOR_VOLTAGE,
537 .owner = THIS_MODULE,
538 .enable_reg = LP8720_ENABLE,
539 .enable_mask = LP8720_EN_BUCK_M,
540 },
541};
542
Axel Linf9664042019-01-26 11:39:02 +0800543static const struct regulator_desc lp8725_regulator_desc[] = {
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000544 {
545 .name = "ldo1",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100546 .of_match = of_match_ptr("ldo1"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000547 .id = LP8725_ID_LDO1,
548 .ops = &lp872x_ldo_ops,
549 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
550 .volt_table = lp872x_ldo_vtbl,
551 .type = REGULATOR_VOLTAGE,
552 .owner = THIS_MODULE,
553 .vsel_reg = LP872X_LDO1_VOUT,
554 .vsel_mask = LP872X_VOUT_M,
555 .enable_reg = LP8725_LDO_CTRL,
556 .enable_mask = LP872X_EN_LDO1_M,
557 },
558 {
559 .name = "ldo2",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100560 .of_match = of_match_ptr("ldo2"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000561 .id = LP8725_ID_LDO2,
562 .ops = &lp872x_ldo_ops,
563 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
564 .volt_table = lp872x_ldo_vtbl,
565 .type = REGULATOR_VOLTAGE,
566 .owner = THIS_MODULE,
567 .vsel_reg = LP872X_LDO2_VOUT,
568 .vsel_mask = LP872X_VOUT_M,
569 .enable_reg = LP8725_LDO_CTRL,
570 .enable_mask = LP872X_EN_LDO2_M,
571 },
572 {
573 .name = "ldo3",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100574 .of_match = of_match_ptr("ldo3"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000575 .id = LP8725_ID_LDO3,
576 .ops = &lp872x_ldo_ops,
577 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
578 .volt_table = lp872x_ldo_vtbl,
579 .type = REGULATOR_VOLTAGE,
580 .owner = THIS_MODULE,
581 .vsel_reg = LP872X_LDO3_VOUT,
582 .vsel_mask = LP872X_VOUT_M,
583 .enable_reg = LP8725_LDO_CTRL,
584 .enable_mask = LP872X_EN_LDO3_M,
585 },
586 {
587 .name = "ldo4",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100588 .of_match = of_match_ptr("ldo4"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000589 .id = LP8725_ID_LDO4,
590 .ops = &lp872x_ldo_ops,
591 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
592 .volt_table = lp872x_ldo_vtbl,
593 .type = REGULATOR_VOLTAGE,
594 .owner = THIS_MODULE,
595 .vsel_reg = LP872X_LDO4_VOUT,
596 .vsel_mask = LP872X_VOUT_M,
597 .enable_reg = LP8725_LDO_CTRL,
598 .enable_mask = LP872X_EN_LDO4_M,
599 },
600 {
601 .name = "ldo5",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100602 .of_match = of_match_ptr("ldo5"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000603 .id = LP8725_ID_LDO5,
604 .ops = &lp872x_ldo_ops,
605 .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl),
606 .volt_table = lp872x_ldo_vtbl,
607 .type = REGULATOR_VOLTAGE,
608 .owner = THIS_MODULE,
609 .vsel_reg = LP872X_LDO5_VOUT,
610 .vsel_mask = LP872X_VOUT_M,
611 .enable_reg = LP8725_LDO_CTRL,
612 .enable_mask = LP872X_EN_LDO5_M,
613 },
614 {
615 .name = "lilo1",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100616 .of_match = of_match_ptr("lilo1"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000617 .id = LP8725_ID_LILO1,
618 .ops = &lp872x_ldo_ops,
619 .n_voltages = ARRAY_SIZE(lp8725_lilo_vtbl),
620 .volt_table = lp8725_lilo_vtbl,
621 .type = REGULATOR_VOLTAGE,
622 .owner = THIS_MODULE,
623 .vsel_reg = LP8725_LILO1_VOUT,
624 .vsel_mask = LP872X_VOUT_M,
625 .enable_reg = LP8725_LDO_CTRL,
626 .enable_mask = LP8725_EN_LILO1_M,
627 },
628 {
629 .name = "lilo2",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100630 .of_match = of_match_ptr("lilo2"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000631 .id = LP8725_ID_LILO2,
632 .ops = &lp872x_ldo_ops,
633 .n_voltages = ARRAY_SIZE(lp8725_lilo_vtbl),
634 .volt_table = lp8725_lilo_vtbl,
635 .type = REGULATOR_VOLTAGE,
636 .owner = THIS_MODULE,
637 .vsel_reg = LP8725_LILO2_VOUT,
638 .vsel_mask = LP872X_VOUT_M,
639 .enable_reg = LP8725_LDO_CTRL,
640 .enable_mask = LP8725_EN_LILO2_M,
641 },
642 {
643 .name = "buck1",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100644 .of_match = of_match_ptr("buck1"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000645 .id = LP8725_ID_BUCK1,
646 .ops = &lp8725_buck_ops,
647 .n_voltages = ARRAY_SIZE(lp8725_buck_vtbl),
648 .volt_table = lp8725_buck_vtbl,
649 .type = REGULATOR_VOLTAGE,
650 .owner = THIS_MODULE,
651 .enable_reg = LP872X_GENERAL_CFG,
652 .enable_mask = LP8725_BUCK1_EN_M,
Axel Lin8918f062019-02-28 21:40:16 +0800653 .curr_table = lp8725_buck_uA,
654 .n_current_limits = ARRAY_SIZE(lp8725_buck_uA),
655 .csel_reg = LP8725_BUCK1_VOUT2,
656 .csel_mask = LP8725_BUCK_CL_M,
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000657 },
658 {
659 .name = "buck2",
Paul Kocialkowski1f97fe42015-12-23 11:58:34 +0100660 .of_match = of_match_ptr("buck2"),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000661 .id = LP8725_ID_BUCK2,
662 .ops = &lp8725_buck_ops,
663 .n_voltages = ARRAY_SIZE(lp8725_buck_vtbl),
664 .volt_table = lp8725_buck_vtbl,
665 .type = REGULATOR_VOLTAGE,
666 .owner = THIS_MODULE,
667 .enable_reg = LP872X_GENERAL_CFG,
668 .enable_mask = LP8725_BUCK2_EN_M,
Axel Lin8918f062019-02-28 21:40:16 +0800669 .curr_table = lp8725_buck_uA,
670 .n_current_limits = ARRAY_SIZE(lp8725_buck_uA),
671 .csel_reg = LP8725_BUCK2_VOUT2,
672 .csel_mask = LP8725_BUCK_CL_M,
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000673 },
674};
675
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000676static int lp872x_init_dvs(struct lp872x *lp)
677{
678 int ret, gpio;
Kim, Milob158fba2012-09-05 04:39:16 +0000679 struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000680 enum lp872x_dvs_state pinstate;
Kim, Milob158fba2012-09-05 04:39:16 +0000681 u8 mask[] = { LP8720_EXT_DVS_M, LP8725_DVS1_M | LP8725_DVS2_M };
682 u8 default_dvs_mode[] = { LP8720_DEFAULT_DVS, LP8725_DEFAULT_DVS };
683
684 if (!dvs)
685 goto set_default_dvs_mode;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000686
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000687 gpio = dvs->gpio;
Paul Kocialkowski690f44b2016-02-05 19:42:18 +0100688 if (!gpio_is_valid(gpio))
Kim, Milo00fd6e62013-05-20 12:36:07 +0000689 goto set_default_dvs_mode;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000690
691 pinstate = dvs->init_state;
692 ret = devm_gpio_request_one(lp->dev, gpio, pinstate, "LP872X DVS");
693 if (ret) {
694 dev_err(lp->dev, "gpio request err: %d\n", ret);
695 return ret;
696 }
697
698 lp->dvs_pin = pinstate;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000699
700 return 0;
Kim, Milob158fba2012-09-05 04:39:16 +0000701
702set_default_dvs_mode:
703 return lp872x_update_bits(lp, LP872X_GENERAL_CFG, mask[lp->chipid],
704 default_dvs_mode[lp->chipid]);
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000705}
706
Paul Kocialkowski7e6213f2016-02-05 19:42:19 +0100707static int lp872x_hw_enable(struct lp872x *lp)
708{
709 int ret, gpio;
710
711 if (!lp->pdata)
712 return -EINVAL;
713
714 gpio = lp->pdata->enable_gpio;
715 if (!gpio_is_valid(gpio))
716 return 0;
717
718 /* Always set enable GPIO high. */
719 ret = devm_gpio_request_one(lp->dev, gpio, GPIOF_OUT_INIT_HIGH, "LP872X EN");
720 if (ret) {
721 dev_err(lp->dev, "gpio request err: %d\n", ret);
722 return ret;
723 }
724
725 /* Each chip has a different enable delay. */
726 if (lp->chipid == LP8720)
727 usleep_range(LP8720_ENABLE_DELAY, 1.5 * LP8720_ENABLE_DELAY);
728 else
729 usleep_range(LP8725_ENABLE_DELAY, 1.5 * LP8725_ENABLE_DELAY);
730
731 return 0;
732}
733
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000734static int lp872x_config(struct lp872x *lp)
735{
736 struct lp872x_platform_data *pdata = lp->pdata;
737 int ret;
738
Kim, Milo86b3fef2012-09-05 04:39:23 +0000739 if (!pdata || !pdata->update_config)
740 goto init_dvs;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000741
742 ret = lp872x_write_byte(lp, LP872X_GENERAL_CFG, pdata->general_config);
743 if (ret)
744 return ret;
745
Kim, Milo86b3fef2012-09-05 04:39:23 +0000746init_dvs:
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000747 return lp872x_init_dvs(lp);
748}
749
750static struct regulator_init_data
Axel Lin5bae0622012-07-15 16:57:12 +0800751*lp872x_find_regulator_init_data(int id, struct lp872x *lp)
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000752{
Kim, Milo9ffaa862012-09-05 04:39:11 +0000753 struct lp872x_platform_data *pdata = lp->pdata;
Axel Lin5bae0622012-07-15 16:57:12 +0800754 int i;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000755
Kim, Milo9ffaa862012-09-05 04:39:11 +0000756 if (!pdata)
757 return NULL;
758
Axel Lin5bae0622012-07-15 16:57:12 +0800759 for (i = 0; i < lp->num_regulators; i++) {
Kim, Milo9ffaa862012-09-05 04:39:11 +0000760 if (pdata->regulator_data[i].id == id)
761 return pdata->regulator_data[i].init_data;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000762 }
763
Axel Lin5bae0622012-07-15 16:57:12 +0800764 return NULL;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000765}
766
767static int lp872x_regulator_register(struct lp872x *lp)
768{
Axel Linf9664042019-01-26 11:39:02 +0800769 const struct regulator_desc *desc;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000770 struct regulator_config cfg = { };
771 struct regulator_dev *rdev;
Jingoo Haned6025342013-09-30 09:54:34 +0900772 int i;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000773
Milo Kim37a6f432013-07-03 10:30:57 +0900774 for (i = 0; i < lp->num_regulators; i++) {
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000775 desc = (lp->chipid == LP8720) ? &lp8720_regulator_desc[i] :
776 &lp8725_regulator_desc[i];
777
778 cfg.dev = lp->dev;
Axel Lin5bae0622012-07-15 16:57:12 +0800779 cfg.init_data = lp872x_find_regulator_init_data(desc->id, lp);
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000780 cfg.driver_data = lp;
781 cfg.regmap = lp->regmap;
782
Jingoo Haned6025342013-09-30 09:54:34 +0900783 rdev = devm_regulator_register(lp->dev, desc, &cfg);
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000784 if (IS_ERR(rdev)) {
785 dev_err(lp->dev, "regulator register err");
Jingoo Haned6025342013-09-30 09:54:34 +0900786 return PTR_ERR(rdev);
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000787 }
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000788 }
789
790 return 0;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000791}
792
793static const struct regmap_config lp872x_regmap_config = {
794 .reg_bits = 8,
795 .val_bits = 8,
796 .max_register = MAX_REGISTERS,
797};
798
Kim, Milo00fd6e62013-05-20 12:36:07 +0000799#ifdef CONFIG_OF
800
801#define LP872X_VALID_OPMODE (REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL)
802
803static struct of_regulator_match lp8720_matches[] = {
804 { .name = "ldo1", .driver_data = (void *)LP8720_ID_LDO1, },
805 { .name = "ldo2", .driver_data = (void *)LP8720_ID_LDO2, },
806 { .name = "ldo3", .driver_data = (void *)LP8720_ID_LDO3, },
807 { .name = "ldo4", .driver_data = (void *)LP8720_ID_LDO4, },
808 { .name = "ldo5", .driver_data = (void *)LP8720_ID_LDO5, },
809 { .name = "buck", .driver_data = (void *)LP8720_ID_BUCK, },
810};
811
812static struct of_regulator_match lp8725_matches[] = {
813 { .name = "ldo1", .driver_data = (void *)LP8725_ID_LDO1, },
814 { .name = "ldo2", .driver_data = (void *)LP8725_ID_LDO2, },
815 { .name = "ldo3", .driver_data = (void *)LP8725_ID_LDO3, },
816 { .name = "ldo4", .driver_data = (void *)LP8725_ID_LDO4, },
817 { .name = "ldo5", .driver_data = (void *)LP8725_ID_LDO5, },
818 { .name = "lilo1", .driver_data = (void *)LP8725_ID_LILO1, },
819 { .name = "lilo2", .driver_data = (void *)LP8725_ID_LILO2, },
820 { .name = "buck1", .driver_data = (void *)LP8725_ID_BUCK1, },
821 { .name = "buck2", .driver_data = (void *)LP8725_ID_BUCK2, },
822};
823
824static struct lp872x_platform_data
825*lp872x_populate_pdata_from_dt(struct device *dev, enum lp872x_id which)
826{
827 struct device_node *np = dev->of_node;
828 struct lp872x_platform_data *pdata;
829 struct of_regulator_match *match;
Kim, Milo00fd6e62013-05-20 12:36:07 +0000830 int num_matches;
831 int count;
832 int i;
833 u8 dvs_state;
834
835 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
836 if (!pdata)
Milo Kim804486b2015-08-25 14:54:12 +0900837 return ERR_PTR(-ENOMEM);
Kim, Milo00fd6e62013-05-20 12:36:07 +0000838
839 of_property_read_u8(np, "ti,general-config", &pdata->general_config);
840 if (of_find_property(np, "ti,update-config", NULL))
841 pdata->update_config = true;
842
843 pdata->dvs = devm_kzalloc(dev, sizeof(struct lp872x_dvs), GFP_KERNEL);
844 if (!pdata->dvs)
Milo Kim804486b2015-08-25 14:54:12 +0900845 return ERR_PTR(-ENOMEM);
Kim, Milo00fd6e62013-05-20 12:36:07 +0000846
847 pdata->dvs->gpio = of_get_named_gpio(np, "ti,dvs-gpio", 0);
848 of_property_read_u8(np, "ti,dvs-vsel", (u8 *)&pdata->dvs->vsel);
849 of_property_read_u8(np, "ti,dvs-state", &dvs_state);
850 pdata->dvs->init_state = dvs_state ? DVS_HIGH : DVS_LOW;
851
Paul Kocialkowski7e6213f2016-02-05 19:42:19 +0100852 pdata->enable_gpio = of_get_named_gpio(np, "enable-gpios", 0);
853
Kim, Milo00fd6e62013-05-20 12:36:07 +0000854 if (of_get_child_count(np) == 0)
855 goto out;
856
857 switch (which) {
858 case LP8720:
859 match = lp8720_matches;
860 num_matches = ARRAY_SIZE(lp8720_matches);
861 break;
862 case LP8725:
863 match = lp8725_matches;
864 num_matches = ARRAY_SIZE(lp8725_matches);
865 break;
866 default:
867 goto out;
868 }
869
870 count = of_regulator_match(dev, np, match, num_matches);
871 if (count <= 0)
872 goto out;
873
874 for (i = 0; i < num_matches; i++) {
Milo Kim37a6f432013-07-03 10:30:57 +0900875 pdata->regulator_data[i].id =
876 (enum lp872x_regulator_id)match[i].driver_data;
Kim, Milo00fd6e62013-05-20 12:36:07 +0000877 pdata->regulator_data[i].init_data = match[i].init_data;
Kim, Milo00fd6e62013-05-20 12:36:07 +0000878 }
879out:
880 return pdata;
881}
882#else
883static struct lp872x_platform_data
884*lp872x_populate_pdata_from_dt(struct device *dev, enum lp872x_id which)
885{
886 return NULL;
887}
888#endif
889
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000890static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
891{
892 struct lp872x *lp;
Milo Kimd9ffae12015-08-25 14:54:11 +0900893 struct lp872x_platform_data *pdata;
Axel Lin8538c402015-01-26 10:25:13 +0800894 int ret;
Colin Ian King390d8282020-10-16 23:22:35 +0100895 static const int lp872x_num_regulators[] = {
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000896 [LP8720] = LP8720_NUM_REGULATORS,
897 [LP8725] = LP8725_NUM_REGULATORS,
898 };
899
Milo Kim804486b2015-08-25 14:54:12 +0900900 if (cl->dev.of_node) {
Milo Kimd9ffae12015-08-25 14:54:11 +0900901 pdata = lp872x_populate_pdata_from_dt(&cl->dev,
Kim, Milo00fd6e62013-05-20 12:36:07 +0000902 (enum lp872x_id)id->driver_data);
Milo Kim804486b2015-08-25 14:54:12 +0900903 if (IS_ERR(pdata))
904 return PTR_ERR(pdata);
905 } else {
Milo Kimd9ffae12015-08-25 14:54:11 +0900906 pdata = dev_get_platdata(&cl->dev);
Milo Kim804486b2015-08-25 14:54:12 +0900907 }
Kim, Milo00fd6e62013-05-20 12:36:07 +0000908
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000909 lp = devm_kzalloc(&cl->dev, sizeof(struct lp872x), GFP_KERNEL);
910 if (!lp)
Axel Lin8538c402015-01-26 10:25:13 +0800911 return -ENOMEM;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000912
Axel Lin8538c402015-01-26 10:25:13 +0800913 lp->num_regulators = lp872x_num_regulators[id->driver_data];
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000914
915 lp->regmap = devm_regmap_init_i2c(cl, &lp872x_regmap_config);
916 if (IS_ERR(lp->regmap)) {
917 ret = PTR_ERR(lp->regmap);
918 dev_err(&cl->dev, "regmap init i2c err: %d\n", ret);
Axel Lin8538c402015-01-26 10:25:13 +0800919 return ret;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000920 }
921
922 lp->dev = &cl->dev;
Milo Kimd9ffae12015-08-25 14:54:11 +0900923 lp->pdata = pdata;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000924 lp->chipid = id->driver_data;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000925 i2c_set_clientdata(cl, lp);
926
Paul Kocialkowski7e6213f2016-02-05 19:42:19 +0100927 ret = lp872x_hw_enable(lp);
928 if (ret)
929 return ret;
930
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000931 ret = lp872x_config(lp);
932 if (ret)
Axel Lin8538c402015-01-26 10:25:13 +0800933 return ret;
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000934
935 return lp872x_regulator_register(lp);
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000936}
937
Kim, Milo00fd6e62013-05-20 12:36:07 +0000938static const struct of_device_id lp872x_dt_ids[] = {
939 { .compatible = "ti,lp8720", },
940 { .compatible = "ti,lp8725", },
941 { }
942};
943MODULE_DEVICE_TABLE(of, lp872x_dt_ids);
944
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000945static const struct i2c_device_id lp872x_ids[] = {
946 {"lp8720", LP8720},
947 {"lp8725", LP8725},
948 { }
949};
950MODULE_DEVICE_TABLE(i2c, lp872x_ids);
951
952static struct i2c_driver lp872x_driver = {
953 .driver = {
954 .name = "lp872x",
Kim, Milo00fd6e62013-05-20 12:36:07 +0000955 .of_match_table = of_match_ptr(lp872x_dt_ids),
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000956 },
957 .probe = lp872x_probe,
Kim, Miloaf8b5fc2012-06-19 07:08:22 +0000958 .id_table = lp872x_ids,
959};
960
961module_i2c_driver(lp872x_driver);
962
963MODULE_DESCRIPTION("TI/National Semiconductor LP872x PMU Regulator Driver");
964MODULE_AUTHOR("Milo Kim");
965MODULE_LICENSE("GPL");