1// SPDX-License-Identifier: GPL-2.0+
2//
3// max77802.c - Regulator driver for the Maxim 77802
4//
5// Copyright (C) 2013-2014 Google, Inc
6// Simon Glass <sjg@chromium.org>
7//
8// Copyright (C) 2012 Samsung Electronics
9// Chiwoong Byun <woong.byun@samsung.com>
10// Jonghwa Lee <jonghwa3.lee@samsung.com>
11//
12// This driver is based on max8997.c
13
14#include <linux/kernel.h>
15#include <linux/bug.h>
16#include <linux/err.h>
17#include <linux/gpio.h>
18#include <linux/slab.h>
19#include <linux/gpio/consumer.h>
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/regulator/driver.h>
23#include <linux/regulator/machine.h>
24#include <linux/regulator/of_regulator.h>
25#include <linux/mfd/max77686.h>
26#include <linux/mfd/max77686-private.h>
27#include <dt-bindings/regulator/maxim,max77802.h>
28
29/* Default ramp delay in case it is not manually set */
30#define MAX77802_RAMP_DELAY 100000 /* uV/us */
31
32#define MAX77802_OPMODE_SHIFT_LDO 6
33#define MAX77802_OPMODE_BUCK234_SHIFT 4
34#define MAX77802_OPMODE_MASK 0x3
35
36#define MAX77802_VSEL_MASK 0x3F
37#define MAX77802_DVS_VSEL_MASK 0xFF
38
39#define MAX77802_RAMP_RATE_MASK_2BIT 0xC0
40#define MAX77802_RAMP_RATE_SHIFT_2BIT 6
41#define MAX77802_RAMP_RATE_MASK_4BIT 0xF0
42#define MAX77802_RAMP_RATE_SHIFT_4BIT 4
43
44#define MAX77802_STATUS_OFF 0x0
45#define MAX77802_OFF_PWRREQ 0x1
46#define MAX77802_LP_PWRREQ 0x2
47
48/* MAX77802 has two register formats: 2-bit and 4-bit */
49static const unsigned int ramp_table_77802_2bit[] = {
50 12500,
51 25000,
52 50000,
53 100000,
54};
55
56static unsigned int ramp_table_77802_4bit[] = {
57 1000, 2000, 3030, 4000,
58 5000, 5880, 7140, 8330,
59 9090, 10000, 11110, 12500,
60 16670, 25000, 50000, 100000,
61};
62
63struct max77802_regulator_prv {
64 /* Array indexed by regulator id */
65 unsigned int opmode[MAX77802_REG_MAX];
66};
67
68static inline unsigned int max77802_map_mode(unsigned int mode)
69{
70 return mode == MAX77802_OPMODE_NORMAL ?
71 REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY;
72}
73
74static int max77802_get_opmode_shift(int id)
75{
76 if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 &&
77 id <= MAX77802_BUCK10))
78 return 0;
79
80 if (id >= MAX77802_BUCK2 && id <= MAX77802_BUCK4)
81 return MAX77802_OPMODE_BUCK234_SHIFT;
82
83 if (id >= MAX77802_LDO1 && id <= MAX77802_LDO35)
84 return MAX77802_OPMODE_SHIFT_LDO;
85
86 return -EINVAL;
87}
88
89/**
90 * max77802_set_suspend_disable - Disable the regulator during system suspend
91 * @rdev: regulator to mark as disabled
92 *
93 * All regulators expect LDO 1, 3, 20 and 21 support OFF by PWRREQ.
94 * Configure the regulator so the PMIC will turn it OFF during system suspend.
95 */
96static int max77802_set_suspend_disable(struct regulator_dev *rdev)
97{
98 unsigned int val = MAX77802_OFF_PWRREQ;
99 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
100 int id = rdev_get_id(rdev);
101 int shift = max77802_get_opmode_shift(id);
102
103 max77802->opmode[id] = val;
104 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
105 rdev->desc->enable_mask, val << shift);
106}
107
108/*
109 * Some LDOs support Low Power Mode while the system is running.
110 *
111 * LDOs 1, 3, 20, 21.
112 */
113static int max77802_set_mode(struct regulator_dev *rdev, unsigned int mode)
114{
115 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
116 int id = rdev_get_id(rdev);
117 unsigned int val;
118 int shift = max77802_get_opmode_shift(id);
119
120 switch (mode) {
121 case REGULATOR_MODE_STANDBY:
122 val = MAX77802_OPMODE_LP; /* ON in Low Power Mode */
123 break;
124 case REGULATOR_MODE_NORMAL:
125 val = MAX77802_OPMODE_NORMAL; /* ON in Normal Mode */
126 break;
127 default:
128 dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
129 rdev->desc->name, mode);
130 return -EINVAL;
131 }
132
133 max77802->opmode[id] = val;
134 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
135 rdev->desc->enable_mask, val << shift);
136}
137
138static unsigned max77802_get_mode(struct regulator_dev *rdev)
139{
140 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
141 int id = rdev_get_id(rdev);
142
143 return max77802_map_mode(max77802->opmode[id]);
144}
145
146/**
147 * max77802_set_suspend_mode - set regulator opmode when the system is suspended
148 * @rdev: regulator to change mode
149 * @mode: operating mode to be set
150 *
151 * Will set the operating mode for the regulators during system suspend.
152 * This function is valid for the three different enable control logics:
153 *
154 * Enable Control Logic1 by PWRREQ (BUCK 2-4 and LDOs 2, 4-19, 22-35)
155 * Enable Control Logic2 by PWRREQ (LDOs 1, 20, 21)
156 * Enable Control Logic3 by PWRREQ (LDO 3)
157 *
158 * If setting the regulator mode fails, the function only warns but does
159 * not return an error code to avoid the regulator core to stop setting
160 * the operating mode for the remaining regulators.
161 */
162static int max77802_set_suspend_mode(struct regulator_dev *rdev,
163 unsigned int mode)
164{
165 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
166 int id = rdev_get_id(rdev);
167 unsigned int val;
168 int shift = max77802_get_opmode_shift(id);
169
170 /*
171 * If the regulator has been disabled for suspend
172 * then is invalid to try setting a suspend mode.
173 */
174 if (max77802->opmode[id] == MAX77802_OFF_PWRREQ) {
175 dev_warn(&rdev->dev, "%s: is disabled, mode: 0x%x not set\n",
176 rdev->desc->name, mode);
177 return 0;
178 }
179
180 switch (mode) {
181 case REGULATOR_MODE_STANDBY:
182 /*
183 * If the regulator opmode is normal then enable
184 * ON in Low Power Mode by PWRREQ. If the mode is
185 * already Low Power then no action is required.
186 */
187 if (max77802->opmode[id] == MAX77802_OPMODE_NORMAL)
188 val = MAX77802_LP_PWRREQ;
189 else
190 return 0;
191 break;
192 case REGULATOR_MODE_NORMAL:
193 /*
194 * If the regulator operating mode is Low Power then
195 * normal is not a valid opmode in suspend. If the
196 * mode is already normal then no action is required.
197 */
198 if (max77802->opmode[id] == MAX77802_OPMODE_LP)
199 dev_warn(&rdev->dev, "%s: in Low Power: 0x%x invalid\n",
200 rdev->desc->name, mode);
201 return 0;
202 default:
203 dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
204 rdev->desc->name, mode);
205 return -EINVAL;
206 }
207
208 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
209 rdev->desc->enable_mask, val << shift);
210}
211
212static int max77802_enable(struct regulator_dev *rdev)
213{
214 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
215 int id = rdev_get_id(rdev);
216 int shift = max77802_get_opmode_shift(id);
217
218 if (max77802->opmode[id] == MAX77802_OFF_PWRREQ)
219 max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
220
221 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
222 rdev->desc->enable_mask,
223 max77802->opmode[id] << shift);
224}
225
226static int max77802_find_ramp_value(struct regulator_dev *rdev,
227 const unsigned int limits[], int size,
228 unsigned int ramp_delay)
229{
230 int i;
231
232 for (i = 0; i < size; i++) {
233 if (ramp_delay <= limits[i])
234 return i;
235 }
236
237 /* Use maximum value for no ramp control */
238 dev_warn(&rdev->dev, "%s: ramp_delay: %d not supported, setting 100000\n",
239 rdev->desc->name, ramp_delay);
240 return size - 1;
241}
242
243/* Used for BUCKs 2-4 */
244static int max77802_set_ramp_delay_2bit(struct regulator_dev *rdev,
245 int ramp_delay)
246{
247 int id = rdev_get_id(rdev);
248 unsigned int ramp_value;
249
250 if (id > MAX77802_BUCK4) {
251 dev_warn(&rdev->dev,
252 "%s: regulator: ramp delay not supported\n",
253 rdev->desc->name);
254 return -EINVAL;
255 }
256 ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_2bit,
257 ARRAY_SIZE(ramp_table_77802_2bit), ramp_delay);
258
259 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
260 MAX77802_RAMP_RATE_MASK_2BIT,
261 ramp_value << MAX77802_RAMP_RATE_SHIFT_2BIT);
262}
263
264/* For BUCK1, 6 */
265static int max77802_set_ramp_delay_4bit(struct regulator_dev *rdev,
266 int ramp_delay)
267{
268 unsigned int ramp_value;
269
270 ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_4bit,
271 ARRAY_SIZE(ramp_table_77802_4bit), ramp_delay);
272
273 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
274 MAX77802_RAMP_RATE_MASK_4BIT,
275 ramp_value << MAX77802_RAMP_RATE_SHIFT_4BIT);
276}
277
278/*
279 * LDOs 2, 4-19, 22-35
280 */
281static const struct regulator_ops max77802_ldo_ops_logic1 = {
282 .list_voltage = regulator_list_voltage_linear,
283 .map_voltage = regulator_map_voltage_linear,
284 .is_enabled = regulator_is_enabled_regmap,
285 .enable = max77802_enable,
286 .disable = regulator_disable_regmap,
287 .get_voltage_sel = regulator_get_voltage_sel_regmap,
288 .set_voltage_sel = regulator_set_voltage_sel_regmap,
289 .set_voltage_time_sel = regulator_set_voltage_time_sel,
290 .set_suspend_disable = max77802_set_suspend_disable,
291 .set_suspend_mode = max77802_set_suspend_mode,
292};
293
294/*
295 * LDOs 1, 20, 21, 3
296 */
297static const struct regulator_ops max77802_ldo_ops_logic2 = {
298 .list_voltage = regulator_list_voltage_linear,
299 .map_voltage = regulator_map_voltage_linear,
300 .is_enabled = regulator_is_enabled_regmap,
301 .enable = max77802_enable,
302 .disable = regulator_disable_regmap,
303 .get_voltage_sel = regulator_get_voltage_sel_regmap,
304 .set_voltage_sel = regulator_set_voltage_sel_regmap,
305 .set_voltage_time_sel = regulator_set_voltage_time_sel,
306 .set_mode = max77802_set_mode,
307 .get_mode = max77802_get_mode,
308 .set_suspend_mode = max77802_set_suspend_mode,
309};
310
311/* BUCKS 1, 6 */
312static const struct regulator_ops max77802_buck_16_dvs_ops = {
313 .list_voltage = regulator_list_voltage_linear,
314 .map_voltage = regulator_map_voltage_linear,
315 .is_enabled = regulator_is_enabled_regmap,
316 .enable = max77802_enable,
317 .disable = regulator_disable_regmap,
318 .get_voltage_sel = regulator_get_voltage_sel_regmap,
319 .set_voltage_sel = regulator_set_voltage_sel_regmap,
320 .set_voltage_time_sel = regulator_set_voltage_time_sel,
321 .set_ramp_delay = max77802_set_ramp_delay_4bit,
322 .set_suspend_disable = max77802_set_suspend_disable,
323};
324
325/* BUCKs 2-4 */
326static const struct regulator_ops max77802_buck_234_ops = {
327 .list_voltage = regulator_list_voltage_linear,
328 .map_voltage = regulator_map_voltage_linear,
329 .is_enabled = regulator_is_enabled_regmap,
330 .enable = max77802_enable,
331 .disable = regulator_disable_regmap,
332 .get_voltage_sel = regulator_get_voltage_sel_regmap,
333 .set_voltage_sel = regulator_set_voltage_sel_regmap,
334 .set_voltage_time_sel = regulator_set_voltage_time_sel,
335 .set_ramp_delay = max77802_set_ramp_delay_2bit,
336 .set_suspend_disable = max77802_set_suspend_disable,
337 .set_suspend_mode = max77802_set_suspend_mode,
338};
339
340/* BUCKs 5, 7-10 */
341static const struct regulator_ops max77802_buck_dvs_ops = {
342 .list_voltage = regulator_list_voltage_linear,
343 .map_voltage = regulator_map_voltage_linear,
344 .is_enabled = regulator_is_enabled_regmap,
345 .enable = max77802_enable,
346 .disable = regulator_disable_regmap,
347 .get_voltage_sel = regulator_get_voltage_sel_regmap,
348 .set_voltage_sel = regulator_set_voltage_sel_regmap,
349 .set_voltage_time_sel = regulator_set_voltage_time_sel,
350 .set_ramp_delay = max77802_set_ramp_delay_2bit,
351 .set_suspend_disable = max77802_set_suspend_disable,
352};
353
354/* LDOs 3-7, 9-14, 18-26, 28, 29, 32-34 */
355#define regulator_77802_desc_p_ldo(num, supply, log) { \
356 .name = "LDO"#num, \
357 .of_match = of_match_ptr("LDO"#num), \
358 .regulators_node = of_match_ptr("regulators"), \
359 .id = MAX77802_LDO##num, \
360 .supply_name = "inl"#supply, \
361 .ops = &max77802_ldo_ops_logic##log, \
362 .type = REGULATOR_VOLTAGE, \
363 .owner = THIS_MODULE, \
364 .min_uV = 800000, \
365 .uV_step = 50000, \
366 .ramp_delay = MAX77802_RAMP_DELAY, \
367 .n_voltages = 1 << 6, \
368 .vsel_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \
369 .vsel_mask = MAX77802_VSEL_MASK, \
370 .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \
371 .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \
372 .of_map_mode = max77802_map_mode, \
373}
374
375/* LDOs 1, 2, 8, 15, 17, 27, 30, 35 */
376#define regulator_77802_desc_n_ldo(num, supply, log) { \
377 .name = "LDO"#num, \
378 .of_match = of_match_ptr("LDO"#num), \
379 .regulators_node = of_match_ptr("regulators"), \
380 .id = MAX77802_LDO##num, \
381 .supply_name = "inl"#supply, \
382 .ops = &max77802_ldo_ops_logic##log, \
383 .type = REGULATOR_VOLTAGE, \
384 .owner = THIS_MODULE, \
385 .min_uV = 800000, \
386 .uV_step = 25000, \
387 .ramp_delay = MAX77802_RAMP_DELAY, \
388 .n_voltages = 1 << 6, \
389 .vsel_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \
390 .vsel_mask = MAX77802_VSEL_MASK, \
391 .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \
392 .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \
393 .of_map_mode = max77802_map_mode, \
394}
395
396/* BUCKs 1, 6 */
397#define regulator_77802_desc_16_buck(num) { \
398 .name = "BUCK"#num, \
399 .of_match = of_match_ptr("BUCK"#num), \
400 .regulators_node = of_match_ptr("regulators"), \
401 .id = MAX77802_BUCK##num, \
402 .supply_name = "inb"#num, \
403 .ops = &max77802_buck_16_dvs_ops, \
404 .type = REGULATOR_VOLTAGE, \
405 .owner = THIS_MODULE, \
406 .min_uV = 612500, \
407 .uV_step = 6250, \
408 .ramp_delay = MAX77802_RAMP_DELAY, \
409 .n_voltages = 1 << 8, \
410 .vsel_reg = MAX77802_REG_BUCK ## num ## DVS1, \
411 .vsel_mask = MAX77802_DVS_VSEL_MASK, \
412 .enable_reg = MAX77802_REG_BUCK ## num ## CTRL, \
413 .enable_mask = MAX77802_OPMODE_MASK, \
414 .of_map_mode = max77802_map_mode, \
415}
416
417/* BUCKS 2-4 */
418#define regulator_77802_desc_234_buck(num) { \
419 .name = "BUCK"#num, \
420 .of_match = of_match_ptr("BUCK"#num), \
421 .regulators_node = of_match_ptr("regulators"), \
422 .id = MAX77802_BUCK##num, \
423 .supply_name = "inb"#num, \
424 .ops = &max77802_buck_234_ops, \
425 .type = REGULATOR_VOLTAGE, \
426 .owner = THIS_MODULE, \
427 .min_uV = 600000, \
428 .uV_step = 6250, \
429 .ramp_delay = MAX77802_RAMP_DELAY, \
430 .n_voltages = 0x91, \
431 .vsel_reg = MAX77802_REG_BUCK ## num ## DVS1, \
432 .vsel_mask = MAX77802_DVS_VSEL_MASK, \
433 .enable_reg = MAX77802_REG_BUCK ## num ## CTRL1, \
434 .enable_mask = MAX77802_OPMODE_MASK << \
435 MAX77802_OPMODE_BUCK234_SHIFT, \
436 .of_map_mode = max77802_map_mode, \
437}
438
439/* BUCK 5 */
440#define regulator_77802_desc_buck5(num) { \
441 .name = "BUCK"#num, \
442 .of_match = of_match_ptr("BUCK"#num), \
443 .regulators_node = of_match_ptr("regulators"), \
444 .id = MAX77802_BUCK##num, \
445 .supply_name = "inb"#num, \
446 .ops = &max77802_buck_dvs_ops, \
447 .type = REGULATOR_VOLTAGE, \
448 .owner = THIS_MODULE, \
449 .min_uV = 750000, \
450 .uV_step = 50000, \
451 .ramp_delay = MAX77802_RAMP_DELAY, \
452 .n_voltages = 1 << 6, \
453 .vsel_reg = MAX77802_REG_BUCK5OUT, \
454 .vsel_mask = MAX77802_VSEL_MASK, \
455 .enable_reg = MAX77802_REG_BUCK5CTRL, \
456 .enable_mask = MAX77802_OPMODE_MASK, \
457 .of_map_mode = max77802_map_mode, \
458}
459
460/* BUCKs 7-10 */
461#define regulator_77802_desc_buck7_10(num) { \
462 .name = "BUCK"#num, \
463 .of_match = of_match_ptr("BUCK"#num), \
464 .regulators_node = of_match_ptr("regulators"), \
465 .id = MAX77802_BUCK##num, \
466 .supply_name = "inb"#num, \
467 .ops = &max77802_buck_dvs_ops, \
468 .type = REGULATOR_VOLTAGE, \
469 .owner = THIS_MODULE, \
470 .min_uV = 750000, \
471 .uV_step = 50000, \
472 .ramp_delay = MAX77802_RAMP_DELAY, \
473 .n_voltages = 1 << 6, \
474 .vsel_reg = MAX77802_REG_BUCK7OUT + (num - 7) * 3, \
475 .vsel_mask = MAX77802_VSEL_MASK, \
476 .enable_reg = MAX77802_REG_BUCK7CTRL + (num - 7) * 3, \
477 .enable_mask = MAX77802_OPMODE_MASK, \
478 .of_map_mode = max77802_map_mode, \
479}
480
481static const struct regulator_desc regulators[] = {
482 regulator_77802_desc_16_buck(1),
483 regulator_77802_desc_234_buck(2),
484 regulator_77802_desc_234_buck(3),
485 regulator_77802_desc_234_buck(4),
486 regulator_77802_desc_buck5(5),
487 regulator_77802_desc_16_buck(6),
488 regulator_77802_desc_buck7_10(7),
489 regulator_77802_desc_buck7_10(8),
490 regulator_77802_desc_buck7_10(9),
491 regulator_77802_desc_buck7_10(10),
492 regulator_77802_desc_n_ldo(1, 10, 2),
493 regulator_77802_desc_n_ldo(2, 10, 1),
494 regulator_77802_desc_p_ldo(3, 3, 2),
495 regulator_77802_desc_p_ldo(4, 6, 1),
496 regulator_77802_desc_p_ldo(5, 3, 1),
497 regulator_77802_desc_p_ldo(6, 3, 1),
498 regulator_77802_desc_p_ldo(7, 3, 1),
499 regulator_77802_desc_n_ldo(8, 1, 1),
500 regulator_77802_desc_p_ldo(9, 5, 1),
501 regulator_77802_desc_p_ldo(10, 4, 1),
502 regulator_77802_desc_p_ldo(11, 4, 1),
503 regulator_77802_desc_p_ldo(12, 9, 1),
504 regulator_77802_desc_p_ldo(13, 4, 1),
505 regulator_77802_desc_p_ldo(14, 4, 1),
506 regulator_77802_desc_n_ldo(15, 1, 1),
507 regulator_77802_desc_n_ldo(17, 2, 1),
508 regulator_77802_desc_p_ldo(18, 7, 1),
509 regulator_77802_desc_p_ldo(19, 5, 1),
510 regulator_77802_desc_p_ldo(20, 7, 2),
511 regulator_77802_desc_p_ldo(21, 6, 2),
512 regulator_77802_desc_p_ldo(23, 9, 1),
513 regulator_77802_desc_p_ldo(24, 6, 1),
514 regulator_77802_desc_p_ldo(25, 9, 1),
515 regulator_77802_desc_p_ldo(26, 9, 1),
516 regulator_77802_desc_n_ldo(27, 2, 1),
517 regulator_77802_desc_p_ldo(28, 7, 1),
518 regulator_77802_desc_p_ldo(29, 7, 1),
519 regulator_77802_desc_n_ldo(30, 2, 1),
520 regulator_77802_desc_p_ldo(32, 9, 1),
521 regulator_77802_desc_p_ldo(33, 6, 1),
522 regulator_77802_desc_p_ldo(34, 9, 1),
523 regulator_77802_desc_n_ldo(35, 2, 1),
524};
525
526static int max77802_pmic_probe(struct platform_device *pdev)
527{
528 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
529 struct max77802_regulator_prv *max77802;
530 int i, val;
531 struct regulator_config config = { };
532
533 max77802 = devm_kzalloc(&pdev->dev,
534 sizeof(struct max77802_regulator_prv),
535 GFP_KERNEL);
536 if (!max77802)
537 return -ENOMEM;
538
539 config.dev = iodev->dev;
540 config.regmap = iodev->regmap;
541 config.driver_data = max77802;
542 platform_set_drvdata(pdev, max77802);
543
544 for (i = 0; i < MAX77802_REG_MAX; i++) {
545 struct regulator_dev *rdev;
546 int id = regulators[i].id;
547 int shift = max77802_get_opmode_shift(id);
548 int ret;
549
550 ret = regmap_read(iodev->regmap, regulators[i].enable_reg, &val);
551 if (ret < 0) {
552 dev_warn(&pdev->dev,
553 "cannot read current mode for %d\n", i);
554 val = MAX77802_OPMODE_NORMAL;
555 } else {
556 val = val >> shift & MAX77802_OPMODE_MASK;
557 }
558
559 /*
560 * If the regulator is disabled and the system warm rebooted,
561 * the hardware reports OFF as the regulator operating mode.
562 * Default to operating mode NORMAL in that case.
563 */
564 if (val == MAX77802_STATUS_OFF)
565 max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
566 else
567 max77802->opmode[id] = val;
568
569 rdev = devm_regulator_register(&pdev->dev,
570 &regulators[i], &config);
571 if (IS_ERR(rdev)) {
572 ret = PTR_ERR(rdev);
573 dev_err(&pdev->dev,
574 "regulator init failed for %d: %d\n", i, ret);
575 return ret;
576 }
577 }
578
579 return 0;
580}
581
582static const struct platform_device_id max77802_pmic_id[] = {
583 {"max77802-pmic", 0},
584 { },
585};
586MODULE_DEVICE_TABLE(platform, max77802_pmic_id);
587
588static struct platform_driver max77802_pmic_driver = {
589 .driver = {
590 .name = "max77802-pmic",
591 },
592 .probe = max77802_pmic_probe,
593 .id_table = max77802_pmic_id,
594};
595
596module_platform_driver(max77802_pmic_driver);
597
598MODULE_DESCRIPTION("MAXIM 77802 Regulator Driver");
599MODULE_AUTHOR("Simon Glass <sjg@chromium.org>");
600MODULE_LICENSE("GPL");
601