Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
ade7515f KM |
2 | /* |
3 | * TI LP8788 MFD - buck regulator driver | |
4 | * | |
5 | * Copyright 2012 Texas Instruments | |
6 | * | |
7 | * Author: Milo(Woogyom) Kim <milo.kim@ti.com> | |
ade7515f KM |
8 | */ |
9 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/slab.h> | |
12 | #include <linux/err.h> | |
13 | #include <linux/platform_device.h> | |
14 | #include <linux/regulator/driver.h> | |
15 | #include <linux/mfd/lp8788.h> | |
95daa868 | 16 | #include <linux/gpio/consumer.h> |
ade7515f KM |
17 | |
18 | /* register address */ | |
19 | #define LP8788_EN_BUCK 0x0C | |
20 | #define LP8788_BUCK_DVS_SEL 0x1D | |
21 | #define LP8788_BUCK1_VOUT0 0x1E | |
22 | #define LP8788_BUCK1_VOUT1 0x1F | |
23 | #define LP8788_BUCK1_VOUT2 0x20 | |
24 | #define LP8788_BUCK1_VOUT3 0x21 | |
25 | #define LP8788_BUCK2_VOUT0 0x22 | |
26 | #define LP8788_BUCK2_VOUT1 0x23 | |
27 | #define LP8788_BUCK2_VOUT2 0x24 | |
28 | #define LP8788_BUCK2_VOUT3 0x25 | |
29 | #define LP8788_BUCK3_VOUT 0x26 | |
30 | #define LP8788_BUCK4_VOUT 0x27 | |
31 | #define LP8788_BUCK1_TIMESTEP 0x28 | |
32 | #define LP8788_BUCK_PWM 0x2D | |
33 | ||
34 | /* mask/shift bits */ | |
35 | #define LP8788_EN_BUCK1_M BIT(0) /* Addr 0Ch */ | |
36 | #define LP8788_EN_BUCK2_M BIT(1) | |
37 | #define LP8788_EN_BUCK3_M BIT(2) | |
38 | #define LP8788_EN_BUCK4_M BIT(3) | |
39 | #define LP8788_BUCK1_DVS_SEL_M 0x04 /* Addr 1Dh */ | |
40 | #define LP8788_BUCK1_DVS_M 0x03 | |
41 | #define LP8788_BUCK1_DVS_S 0 | |
42 | #define LP8788_BUCK2_DVS_SEL_M 0x40 | |
43 | #define LP8788_BUCK2_DVS_M 0x30 | |
44 | #define LP8788_BUCK2_DVS_S 4 | |
45 | #define LP8788_BUCK1_DVS_I2C BIT(2) | |
46 | #define LP8788_BUCK2_DVS_I2C BIT(6) | |
47 | #define LP8788_BUCK1_DVS_PIN (0 << 2) | |
48 | #define LP8788_BUCK2_DVS_PIN (0 << 6) | |
49 | #define LP8788_VOUT_M 0x1F /* Addr 1Eh ~ 27h */ | |
50 | #define LP8788_STARTUP_TIME_M 0xF8 /* Addr 28h ~ 2Bh */ | |
51 | #define LP8788_STARTUP_TIME_S 3 | |
52 | #define LP8788_FPWM_BUCK1_M BIT(0) /* Addr 2Dh */ | |
53 | #define LP8788_FPWM_BUCK1_S 0 | |
54 | #define LP8788_FPWM_BUCK2_M BIT(1) | |
55 | #define LP8788_FPWM_BUCK2_S 1 | |
56 | #define LP8788_FPWM_BUCK3_M BIT(2) | |
57 | #define LP8788_FPWM_BUCK3_S 2 | |
58 | #define LP8788_FPWM_BUCK4_M BIT(3) | |
59 | #define LP8788_FPWM_BUCK4_S 3 | |
60 | ||
61 | #define INVALID_ADDR 0xFF | |
62 | #define LP8788_FORCE_PWM 1 | |
63 | #define LP8788_AUTO_PWM 0 | |
64 | #define PIN_LOW 0 | |
65 | #define PIN_HIGH 1 | |
66 | #define ENABLE_TIME_USEC 32 | |
67 | ||
0f4c46d2 AL |
68 | #define BUCK_FPWM_MASK(x) (1 << (x)) |
69 | #define BUCK_FPWM_SHIFT(x) (x) | |
70 | ||
ade7515f | 71 | enum lp8788_dvs_state { |
95daa868 LW |
72 | DVS_LOW = 0, |
73 | DVS_HIGH = 1, | |
ade7515f KM |
74 | }; |
75 | ||
76 | enum lp8788_dvs_mode { | |
77 | REGISTER, | |
78 | EXTPIN, | |
79 | }; | |
80 | ||
81 | enum lp8788_buck_id { | |
82 | BUCK1, | |
83 | BUCK2, | |
84 | BUCK3, | |
85 | BUCK4, | |
86 | }; | |
87 | ||
ade7515f KM |
88 | struct lp8788_buck { |
89 | struct lp8788 *lp; | |
90 | struct regulator_dev *regulator; | |
ade7515f | 91 | void *dvs; |
95daa868 LW |
92 | struct gpio_desc *gpio1; |
93 | struct gpio_desc *gpio2; /* Only used on BUCK2 */ | |
ade7515f KM |
94 | }; |
95 | ||
7932a880 | 96 | /* BUCK 1 ~ 4 voltage ranges */ |
60ab7f41 | 97 | static const struct linear_range buck_volt_ranges[] = { |
7932a880 AL |
98 | REGULATOR_LINEAR_RANGE(500000, 0, 0, 0), |
99 | REGULATOR_LINEAR_RANGE(800000, 1, 25, 50000), | |
ade7515f KM |
100 | }; |
101 | ||
ade7515f KM |
102 | static void lp8788_buck1_set_dvs(struct lp8788_buck *buck) |
103 | { | |
104 | struct lp8788_buck1_dvs *dvs = (struct lp8788_buck1_dvs *)buck->dvs; | |
105 | enum lp8788_dvs_state pinstate; | |
106 | ||
107 | if (!dvs) | |
108 | return; | |
109 | ||
110 | pinstate = dvs->vsel == DVS_SEL_V0 ? DVS_LOW : DVS_HIGH; | |
95daa868 | 111 | gpiod_set_value(buck->gpio1, pinstate); |
ade7515f KM |
112 | } |
113 | ||
114 | static void lp8788_buck2_set_dvs(struct lp8788_buck *buck) | |
115 | { | |
116 | struct lp8788_buck2_dvs *dvs = (struct lp8788_buck2_dvs *)buck->dvs; | |
117 | enum lp8788_dvs_state pin1, pin2; | |
118 | ||
119 | if (!dvs) | |
120 | return; | |
121 | ||
122 | switch (dvs->vsel) { | |
123 | case DVS_SEL_V0: | |
124 | pin1 = DVS_LOW; | |
125 | pin2 = DVS_LOW; | |
126 | break; | |
127 | case DVS_SEL_V1: | |
128 | pin1 = DVS_HIGH; | |
129 | pin2 = DVS_LOW; | |
130 | break; | |
131 | case DVS_SEL_V2: | |
132 | pin1 = DVS_LOW; | |
133 | pin2 = DVS_HIGH; | |
134 | break; | |
135 | case DVS_SEL_V3: | |
136 | pin1 = DVS_HIGH; | |
137 | pin2 = DVS_HIGH; | |
138 | break; | |
139 | default: | |
140 | return; | |
141 | } | |
142 | ||
95daa868 LW |
143 | gpiod_set_value(buck->gpio1, pin1); |
144 | gpiod_set_value(buck->gpio2, pin2); | |
ade7515f KM |
145 | } |
146 | ||
147 | static void lp8788_set_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id) | |
148 | { | |
149 | switch (id) { | |
150 | case BUCK1: | |
151 | lp8788_buck1_set_dvs(buck); | |
152 | break; | |
153 | case BUCK2: | |
154 | lp8788_buck2_set_dvs(buck); | |
155 | break; | |
156 | default: | |
157 | break; | |
158 | } | |
159 | } | |
160 | ||
161 | static enum lp8788_dvs_mode | |
162 | lp8788_get_buck_dvs_ctrl_mode(struct lp8788_buck *buck, enum lp8788_buck_id id) | |
163 | { | |
164 | u8 val, mask; | |
165 | ||
166 | switch (id) { | |
167 | case BUCK1: | |
168 | mask = LP8788_BUCK1_DVS_SEL_M; | |
169 | break; | |
170 | case BUCK2: | |
171 | mask = LP8788_BUCK2_DVS_SEL_M; | |
172 | break; | |
173 | default: | |
174 | return REGISTER; | |
175 | } | |
176 | ||
177 | lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); | |
178 | ||
179 | return val & mask ? REGISTER : EXTPIN; | |
180 | } | |
181 | ||
182 | static bool lp8788_is_valid_buck_addr(u8 addr) | |
183 | { | |
184 | switch (addr) { | |
185 | case LP8788_BUCK1_VOUT0: | |
186 | case LP8788_BUCK1_VOUT1: | |
187 | case LP8788_BUCK1_VOUT2: | |
188 | case LP8788_BUCK1_VOUT3: | |
189 | case LP8788_BUCK2_VOUT0: | |
190 | case LP8788_BUCK2_VOUT1: | |
191 | case LP8788_BUCK2_VOUT2: | |
192 | case LP8788_BUCK2_VOUT3: | |
193 | return true; | |
194 | default: | |
195 | return false; | |
196 | } | |
197 | } | |
198 | ||
199 | static u8 lp8788_select_buck_vout_addr(struct lp8788_buck *buck, | |
200 | enum lp8788_buck_id id) | |
201 | { | |
202 | enum lp8788_dvs_mode mode = lp8788_get_buck_dvs_ctrl_mode(buck, id); | |
ade7515f KM |
203 | u8 val, idx, addr; |
204 | int pin1, pin2; | |
205 | ||
206 | switch (id) { | |
207 | case BUCK1: | |
208 | if (mode == EXTPIN) { | |
95daa868 | 209 | idx = gpiod_get_value(buck->gpio1); |
ade7515f KM |
210 | } else { |
211 | lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); | |
212 | idx = (val & LP8788_BUCK1_DVS_M) >> LP8788_BUCK1_DVS_S; | |
213 | } | |
e69995d3 | 214 | addr = LP8788_BUCK1_VOUT0 + idx; |
ade7515f KM |
215 | break; |
216 | case BUCK2: | |
217 | if (mode == EXTPIN) { | |
95daa868 LW |
218 | pin1 = gpiod_get_value(buck->gpio1); |
219 | pin2 = gpiod_get_value(buck->gpio2); | |
ade7515f KM |
220 | |
221 | if (pin1 == PIN_LOW && pin2 == PIN_LOW) | |
222 | idx = 0; | |
223 | else if (pin1 == PIN_LOW && pin2 == PIN_HIGH) | |
224 | idx = 2; | |
225 | else if (pin1 == PIN_HIGH && pin2 == PIN_LOW) | |
226 | idx = 1; | |
227 | else | |
228 | idx = 3; | |
229 | } else { | |
230 | lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); | |
231 | idx = (val & LP8788_BUCK2_DVS_M) >> LP8788_BUCK2_DVS_S; | |
232 | } | |
e69995d3 | 233 | addr = LP8788_BUCK2_VOUT0 + idx; |
ade7515f KM |
234 | break; |
235 | default: | |
236 | goto err; | |
237 | } | |
238 | ||
239 | return addr; | |
240 | err: | |
241 | return INVALID_ADDR; | |
242 | } | |
243 | ||
244 | static int lp8788_buck12_set_voltage_sel(struct regulator_dev *rdev, | |
245 | unsigned selector) | |
246 | { | |
247 | struct lp8788_buck *buck = rdev_get_drvdata(rdev); | |
248 | enum lp8788_buck_id id = rdev_get_id(rdev); | |
249 | u8 addr; | |
250 | ||
251 | if (buck->dvs) | |
252 | lp8788_set_dvs(buck, id); | |
253 | ||
254 | addr = lp8788_select_buck_vout_addr(buck, id); | |
255 | if (!lp8788_is_valid_buck_addr(addr)) | |
256 | return -EINVAL; | |
257 | ||
258 | return lp8788_update_bits(buck->lp, addr, LP8788_VOUT_M, selector); | |
259 | } | |
260 | ||
261 | static int lp8788_buck12_get_voltage_sel(struct regulator_dev *rdev) | |
262 | { | |
263 | struct lp8788_buck *buck = rdev_get_drvdata(rdev); | |
264 | enum lp8788_buck_id id = rdev_get_id(rdev); | |
265 | int ret; | |
266 | u8 val, addr; | |
267 | ||
268 | addr = lp8788_select_buck_vout_addr(buck, id); | |
269 | if (!lp8788_is_valid_buck_addr(addr)) | |
270 | return -EINVAL; | |
271 | ||
272 | ret = lp8788_read_byte(buck->lp, addr, &val); | |
273 | if (ret) | |
274 | return ret; | |
275 | ||
276 | return val & LP8788_VOUT_M; | |
277 | } | |
278 | ||
279 | static int lp8788_buck_enable_time(struct regulator_dev *rdev) | |
280 | { | |
281 | struct lp8788_buck *buck = rdev_get_drvdata(rdev); | |
282 | enum lp8788_buck_id id = rdev_get_id(rdev); | |
283 | u8 val, addr = LP8788_BUCK1_TIMESTEP + id; | |
284 | ||
285 | if (lp8788_read_byte(buck->lp, addr, &val)) | |
286 | return -EINVAL; | |
287 | ||
288 | val = (val & LP8788_STARTUP_TIME_M) >> LP8788_STARTUP_TIME_S; | |
289 | ||
290 | return ENABLE_TIME_USEC * val; | |
291 | } | |
292 | ||
293 | static int lp8788_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) | |
294 | { | |
295 | struct lp8788_buck *buck = rdev_get_drvdata(rdev); | |
0f4c46d2 AL |
296 | enum lp8788_buck_id id = rdev_get_id(rdev); |
297 | u8 mask, val; | |
ade7515f | 298 | |
0f4c46d2 | 299 | mask = BUCK_FPWM_MASK(id); |
ade7515f KM |
300 | switch (mode) { |
301 | case REGULATOR_MODE_FAST: | |
0f4c46d2 | 302 | val = LP8788_FORCE_PWM << BUCK_FPWM_SHIFT(id); |
ade7515f KM |
303 | break; |
304 | case REGULATOR_MODE_NORMAL: | |
0f4c46d2 | 305 | val = LP8788_AUTO_PWM << BUCK_FPWM_SHIFT(id); |
ade7515f KM |
306 | break; |
307 | default: | |
308 | return -EINVAL; | |
309 | } | |
310 | ||
0f4c46d2 | 311 | return lp8788_update_bits(buck->lp, LP8788_BUCK_PWM, mask, val); |
ade7515f KM |
312 | } |
313 | ||
314 | static unsigned int lp8788_buck_get_mode(struct regulator_dev *rdev) | |
315 | { | |
316 | struct lp8788_buck *buck = rdev_get_drvdata(rdev); | |
0f4c46d2 | 317 | enum lp8788_buck_id id = rdev_get_id(rdev); |
ade7515f KM |
318 | u8 val; |
319 | int ret; | |
320 | ||
ade7515f KM |
321 | ret = lp8788_read_byte(buck->lp, LP8788_BUCK_PWM, &val); |
322 | if (ret) | |
323 | return ret; | |
324 | ||
0f4c46d2 AL |
325 | return val & BUCK_FPWM_MASK(id) ? |
326 | REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; | |
ade7515f KM |
327 | } |
328 | ||
95dfead1 | 329 | static const struct regulator_ops lp8788_buck12_ops = { |
7932a880 AL |
330 | .list_voltage = regulator_list_voltage_linear_range, |
331 | .map_voltage = regulator_map_voltage_linear_range, | |
ade7515f KM |
332 | .set_voltage_sel = lp8788_buck12_set_voltage_sel, |
333 | .get_voltage_sel = lp8788_buck12_get_voltage_sel, | |
334 | .enable = regulator_enable_regmap, | |
335 | .disable = regulator_disable_regmap, | |
336 | .is_enabled = regulator_is_enabled_regmap, | |
337 | .enable_time = lp8788_buck_enable_time, | |
338 | .set_mode = lp8788_buck_set_mode, | |
339 | .get_mode = lp8788_buck_get_mode, | |
340 | }; | |
341 | ||
95dfead1 | 342 | static const struct regulator_ops lp8788_buck34_ops = { |
7932a880 AL |
343 | .list_voltage = regulator_list_voltage_linear_range, |
344 | .map_voltage = regulator_map_voltage_linear_range, | |
ade7515f KM |
345 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
346 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
347 | .enable = regulator_enable_regmap, | |
348 | .disable = regulator_disable_regmap, | |
349 | .is_enabled = regulator_is_enabled_regmap, | |
350 | .enable_time = lp8788_buck_enable_time, | |
351 | .set_mode = lp8788_buck_set_mode, | |
352 | .get_mode = lp8788_buck_get_mode, | |
353 | }; | |
354 | ||
b133305c | 355 | static const struct regulator_desc lp8788_buck_desc[] = { |
ade7515f KM |
356 | { |
357 | .name = "buck1", | |
358 | .id = BUCK1, | |
359 | .ops = &lp8788_buck12_ops, | |
7932a880 AL |
360 | .n_voltages = 26, |
361 | .linear_ranges = buck_volt_ranges, | |
362 | .n_linear_ranges = ARRAY_SIZE(buck_volt_ranges), | |
ade7515f KM |
363 | .type = REGULATOR_VOLTAGE, |
364 | .owner = THIS_MODULE, | |
365 | .enable_reg = LP8788_EN_BUCK, | |
366 | .enable_mask = LP8788_EN_BUCK1_M, | |
367 | }, | |
368 | { | |
369 | .name = "buck2", | |
370 | .id = BUCK2, | |
371 | .ops = &lp8788_buck12_ops, | |
7932a880 AL |
372 | .n_voltages = 26, |
373 | .linear_ranges = buck_volt_ranges, | |
374 | .n_linear_ranges = ARRAY_SIZE(buck_volt_ranges), | |
ade7515f KM |
375 | .type = REGULATOR_VOLTAGE, |
376 | .owner = THIS_MODULE, | |
377 | .enable_reg = LP8788_EN_BUCK, | |
378 | .enable_mask = LP8788_EN_BUCK2_M, | |
379 | }, | |
380 | { | |
381 | .name = "buck3", | |
382 | .id = BUCK3, | |
383 | .ops = &lp8788_buck34_ops, | |
7932a880 AL |
384 | .n_voltages = 26, |
385 | .linear_ranges = buck_volt_ranges, | |
386 | .n_linear_ranges = ARRAY_SIZE(buck_volt_ranges), | |
ade7515f KM |
387 | .type = REGULATOR_VOLTAGE, |
388 | .owner = THIS_MODULE, | |
389 | .vsel_reg = LP8788_BUCK3_VOUT, | |
390 | .vsel_mask = LP8788_VOUT_M, | |
391 | .enable_reg = LP8788_EN_BUCK, | |
392 | .enable_mask = LP8788_EN_BUCK3_M, | |
393 | }, | |
394 | { | |
395 | .name = "buck4", | |
396 | .id = BUCK4, | |
397 | .ops = &lp8788_buck34_ops, | |
7932a880 AL |
398 | .n_voltages = 26, |
399 | .linear_ranges = buck_volt_ranges, | |
400 | .n_linear_ranges = ARRAY_SIZE(buck_volt_ranges), | |
ade7515f KM |
401 | .type = REGULATOR_VOLTAGE, |
402 | .owner = THIS_MODULE, | |
403 | .vsel_reg = LP8788_BUCK4_VOUT, | |
404 | .vsel_mask = LP8788_VOUT_M, | |
405 | .enable_reg = LP8788_EN_BUCK, | |
406 | .enable_mask = LP8788_EN_BUCK4_M, | |
407 | }, | |
408 | }; | |
409 | ||
38d8f67c KM |
410 | static int lp8788_dvs_gpio_request(struct platform_device *pdev, |
411 | struct lp8788_buck *buck, | |
ade7515f KM |
412 | enum lp8788_buck_id id) |
413 | { | |
414 | struct lp8788_platform_data *pdata = buck->lp->pdata; | |
95daa868 | 415 | struct device *dev = &pdev->dev; |
ade7515f KM |
416 | |
417 | switch (id) { | |
418 | case BUCK1: | |
95daa868 LW |
419 | buck->gpio1 = devm_gpiod_get(dev, "dvs", GPIOD_OUT_LOW); |
420 | if (IS_ERR(buck->gpio1)) | |
421 | return PTR_ERR(buck->gpio1); | |
422 | gpiod_set_consumer_name(buck->gpio1, "LP8788_B1_DVS"); | |
ade7515f KM |
423 | |
424 | buck->dvs = pdata->buck1_dvs; | |
425 | break; | |
426 | case BUCK2: | |
95daa868 LW |
427 | buck->gpio1 = devm_gpiod_get_index(dev, "dvs", 0, GPIOD_OUT_LOW); |
428 | if (IS_ERR(buck->gpio1)) | |
429 | return PTR_ERR(buck->gpio1); | |
430 | gpiod_set_consumer_name(buck->gpio1, "LP8788_B2_DVS1"); | |
431 | ||
432 | buck->gpio2 = devm_gpiod_get_index(dev, "dvs", 1, GPIOD_OUT_LOW); | |
e6f0b08a DC |
433 | if (IS_ERR(buck->gpio2)) |
434 | return PTR_ERR(buck->gpio2); | |
435 | gpiod_set_consumer_name(buck->gpio2, "LP8788_B2_DVS2"); | |
95daa868 | 436 | |
ade7515f KM |
437 | buck->dvs = pdata->buck2_dvs; |
438 | break; | |
439 | default: | |
440 | break; | |
441 | } | |
442 | ||
443 | return 0; | |
444 | } | |
445 | ||
38d8f67c KM |
446 | static int lp8788_init_dvs(struct platform_device *pdev, |
447 | struct lp8788_buck *buck, enum lp8788_buck_id id) | |
ade7515f KM |
448 | { |
449 | struct lp8788_platform_data *pdata = buck->lp->pdata; | |
450 | u8 mask[] = { LP8788_BUCK1_DVS_SEL_M, LP8788_BUCK2_DVS_SEL_M }; | |
451 | u8 val[] = { LP8788_BUCK1_DVS_PIN, LP8788_BUCK2_DVS_PIN }; | |
c42ea5cd | 452 | u8 default_dvs_mode[] = { LP8788_BUCK1_DVS_I2C, LP8788_BUCK2_DVS_I2C }; |
ade7515f KM |
453 | |
454 | /* no dvs for buck3, 4 */ | |
eb758de6 | 455 | if (id > BUCK2) |
ade7515f KM |
456 | return 0; |
457 | ||
458 | /* no dvs platform data, then dvs will be selected by I2C registers */ | |
459 | if (!pdata) | |
460 | goto set_default_dvs_mode; | |
461 | ||
462 | if ((id == BUCK1 && !pdata->buck1_dvs) || | |
463 | (id == BUCK2 && !pdata->buck2_dvs)) | |
464 | goto set_default_dvs_mode; | |
465 | ||
38d8f67c | 466 | if (lp8788_dvs_gpio_request(pdev, buck, id)) |
ade7515f KM |
467 | goto set_default_dvs_mode; |
468 | ||
469 | return lp8788_update_bits(buck->lp, LP8788_BUCK_DVS_SEL, mask[id], | |
470 | val[id]); | |
471 | ||
472 | set_default_dvs_mode: | |
c42ea5cd AL |
473 | return lp8788_update_bits(buck->lp, LP8788_BUCK_DVS_SEL, mask[id], |
474 | default_dvs_mode[id]); | |
ade7515f KM |
475 | } |
476 | ||
a5023574 | 477 | static int lp8788_buck_probe(struct platform_device *pdev) |
ade7515f KM |
478 | { |
479 | struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); | |
480 | int id = pdev->id; | |
481 | struct lp8788_buck *buck; | |
482 | struct regulator_config cfg = { }; | |
483 | struct regulator_dev *rdev; | |
484 | int ret; | |
485 | ||
eb758de6 AL |
486 | if (id >= LP8788_NUM_BUCKS) |
487 | return -EINVAL; | |
488 | ||
3b0e8f12 | 489 | buck = devm_kzalloc(&pdev->dev, sizeof(struct lp8788_buck), GFP_KERNEL); |
ade7515f KM |
490 | if (!buck) |
491 | return -ENOMEM; | |
492 | ||
493 | buck->lp = lp; | |
ade7515f | 494 | |
38d8f67c | 495 | ret = lp8788_init_dvs(pdev, buck, id); |
ade7515f KM |
496 | if (ret) |
497 | return ret; | |
498 | ||
3b0e8f12 | 499 | cfg.dev = pdev->dev.parent; |
ade7515f KM |
500 | cfg.init_data = lp->pdata ? lp->pdata->buck_data[id] : NULL; |
501 | cfg.driver_data = buck; | |
502 | cfg.regmap = lp->regmap; | |
503 | ||
3343fa17 | 504 | rdev = devm_regulator_register(&pdev->dev, &lp8788_buck_desc[id], &cfg); |
ade7515f KM |
505 | if (IS_ERR(rdev)) { |
506 | ret = PTR_ERR(rdev); | |
3b0e8f12 | 507 | dev_err(&pdev->dev, "BUCK%d regulator register err = %d\n", |
ade7515f KM |
508 | id + 1, ret); |
509 | return ret; | |
510 | } | |
511 | ||
512 | buck->regulator = rdev; | |
513 | platform_set_drvdata(pdev, buck); | |
514 | ||
515 | return 0; | |
516 | } | |
517 | ||
ade7515f KM |
518 | static struct platform_driver lp8788_buck_driver = { |
519 | .probe = lp8788_buck_probe, | |
ade7515f KM |
520 | .driver = { |
521 | .name = LP8788_DEV_BUCK, | |
259b93b2 | 522 | .probe_type = PROBE_PREFER_ASYNCHRONOUS, |
ade7515f KM |
523 | }, |
524 | }; | |
525 | ||
526 | static int __init lp8788_buck_init(void) | |
527 | { | |
528 | return platform_driver_register(&lp8788_buck_driver); | |
529 | } | |
530 | subsys_initcall(lp8788_buck_init); | |
531 | ||
532 | static void __exit lp8788_buck_exit(void) | |
533 | { | |
534 | platform_driver_unregister(&lp8788_buck_driver); | |
535 | } | |
536 | module_exit(lp8788_buck_exit); | |
537 | ||
538 | MODULE_DESCRIPTION("TI LP8788 BUCK Driver"); | |
539 | MODULE_AUTHOR("Milo Kim"); | |
540 | MODULE_LICENSE("GPL"); | |
541 | MODULE_ALIAS("platform:lp8788-buck"); |