regulator: palmas: add DT support
[linux-3.10.git] / drivers / regulator / palmas-regulator.c
1 /*
2  * Driver for Regulator part of Palmas PMIC Chips
3  *
4  * Copyright 2011-2013 Texas Instruments Inc.
5  * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
6  *
7  * Author: Graeme Gregory <gg@slimlogic.co.uk>
8  * Author: Ian Lartey <ian@slimlogic.co.uk>
9  *
10  *  This program is free software; you can redistribute it and/or modify it
11  *  under  the terms of the GNU General  Public License as published by the
12  *  Free Software Foundation;  either version 2 of the License, or (at your
13  *  option) any later version.
14  *
15  */
16
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/err.h>
21 #include <linux/gpio.h>
22 #include <linux/platform_device.h>
23 #include <linux/regulator/driver.h>
24 #include <linux/regulator/machine.h>
25 #include <linux/slab.h>
26 #include <linux/regmap.h>
27 #include <linux/mfd/palmas.h>
28 #include <linux/of.h>
29 #include <linux/of_platform.h>
30 #include <linux/regulator/of_regulator.h>
31
32 #define EXT_PWR_REQ (PALMAS_EXT_CONTROL_ENABLE1 |       \
33                      PALMAS_EXT_CONTROL_ENABLE2 |       \
34                      PALMAS_EXT_CONTROL_NSLEEP)
35
36 struct regs_info {
37         char    *name;
38         char    *sname;
39         u8      vsel_addr;
40         u8      ctrl_addr;
41         u8      tstep_addr;
42         u8      fvsel_addr;
43         int     sleep_id;
44 };
45
46 static const struct regs_info palmas_regs_info[] = {
47         {
48                 .name           = "SMPS12",
49                 .sname          = "smps1-in",
50                 .vsel_addr      = PALMAS_SMPS12_VOLTAGE,
51                 .ctrl_addr      = PALMAS_SMPS12_CTRL,
52                 .tstep_addr     = PALMAS_SMPS12_TSTEP,
53                 .fvsel_addr     = PALMAS_SMPS12_FORCE,
54                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS12,
55         },
56         {
57                 .name           = "SMPS123",
58                 .sname          = "smps1-in",
59                 .vsel_addr      = PALMAS_SMPS12_VOLTAGE,
60                 .ctrl_addr      = PALMAS_SMPS12_CTRL,
61                 .tstep_addr     = PALMAS_SMPS12_TSTEP,
62                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS12,
63         },
64         {
65                 .name           = "SMPS3",
66                 .sname          = "smps3-in",
67                 .vsel_addr      = PALMAS_SMPS3_VOLTAGE,
68                 .ctrl_addr      = PALMAS_SMPS3_CTRL,
69                 .tstep_addr     = PALMAS_SMPS3_TSTEP,
70                 .fvsel_addr     = PALMAS_SMPS3_FORCE,
71                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS3,
72         },
73         {
74                 .name           = "SMPS45",
75                 .sname          = "smps4-in",
76                 .vsel_addr      = PALMAS_SMPS45_VOLTAGE,
77                 .ctrl_addr      = PALMAS_SMPS45_CTRL,
78                 .tstep_addr     = PALMAS_SMPS45_TSTEP,
79                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS45,
80         },
81         {
82                 .name           = "SMPS457",
83                 .sname          = "smps4-in",
84                 .vsel_addr      = PALMAS_SMPS45_VOLTAGE,
85                 .ctrl_addr      = PALMAS_SMPS45_CTRL,
86                 .tstep_addr     = PALMAS_SMPS45_TSTEP,
87                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS45,
88         },
89         {
90                 .name           = "SMPS6",
91                 .sname          = "smps6-in",
92                 .vsel_addr      = PALMAS_SMPS6_VOLTAGE,
93                 .ctrl_addr      = PALMAS_SMPS6_CTRL,
94                 .tstep_addr     = PALMAS_SMPS6_TSTEP,
95                 .fvsel_addr     = PALMAS_SMPS6_FORCE,
96                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS6,
97         },
98         {
99                 .name           = "SMPS7",
100                 .sname          = "smps7-in",
101                 .vsel_addr      = PALMAS_SMPS7_VOLTAGE,
102                 .ctrl_addr      = PALMAS_SMPS7_CTRL,
103                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS7,
104         },
105         {
106                 .name           = "SMPS8",
107                 .sname          = "smps8-in",
108                 .vsel_addr      = PALMAS_SMPS8_VOLTAGE,
109                 .ctrl_addr      = PALMAS_SMPS8_CTRL,
110                 .tstep_addr     = PALMAS_SMPS8_TSTEP,
111                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS8,
112         },
113         {
114                 .name           = "SMPS9",
115                 .sname          = "smps9-in",
116                 .vsel_addr      = PALMAS_SMPS9_VOLTAGE,
117                 .ctrl_addr      = PALMAS_SMPS9_CTRL,
118                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS9,
119         },
120         {
121                 .name           = "SMPS10_OUT2",
122                 .sname          = "smps10-in",
123                 .ctrl_addr      = PALMAS_SMPS10_CTRL,
124                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS10,
125         },
126         {
127                 .name           = "SMPS10_OUT1",
128                 .sname          = "smps10-out2",
129                 .ctrl_addr      = PALMAS_SMPS10_CTRL,
130                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SMPS10,
131         },
132         {
133                 .name           = "LDO1",
134                 .sname          = "ldo1-in",
135                 .vsel_addr      = PALMAS_LDO1_VOLTAGE,
136                 .ctrl_addr      = PALMAS_LDO1_CTRL,
137                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO1,
138         },
139         {
140                 .name           = "LDO2",
141                 .sname          = "ldo2-in",
142                 .vsel_addr      = PALMAS_LDO2_VOLTAGE,
143                 .ctrl_addr      = PALMAS_LDO2_CTRL,
144                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO2,
145         },
146         {
147                 .name           = "LDO3",
148                 .sname          = "ldo3-in",
149                 .vsel_addr      = PALMAS_LDO3_VOLTAGE,
150                 .ctrl_addr      = PALMAS_LDO3_CTRL,
151                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO3,
152         },
153         {
154                 .name           = "LDO4",
155                 .sname          = "ldo4-in",
156                 .vsel_addr      = PALMAS_LDO4_VOLTAGE,
157                 .ctrl_addr      = PALMAS_LDO4_CTRL,
158                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO4,
159         },
160         {
161                 .name           = "LDO5",
162                 .sname          = "ldo5-in",
163                 .vsel_addr      = PALMAS_LDO5_VOLTAGE,
164                 .ctrl_addr      = PALMAS_LDO5_CTRL,
165                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO5,
166         },
167         {
168                 .name           = "LDO6",
169                 .sname          = "ldo6-in",
170                 .vsel_addr      = PALMAS_LDO6_VOLTAGE,
171                 .ctrl_addr      = PALMAS_LDO6_CTRL,
172                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO6,
173         },
174         {
175                 .name           = "LDO7",
176                 .sname          = "ldo7-in",
177                 .vsel_addr      = PALMAS_LDO7_VOLTAGE,
178                 .ctrl_addr      = PALMAS_LDO7_CTRL,
179                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO7,
180         },
181         {
182                 .name           = "LDO8",
183                 .sname          = "ldo8-in",
184                 .vsel_addr      = PALMAS_LDO8_VOLTAGE,
185                 .ctrl_addr      = PALMAS_LDO8_CTRL,
186                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO8,
187         },
188         {
189                 .name           = "LDO9",
190                 .sname          = "ldo9-in",
191                 .vsel_addr      = PALMAS_LDO9_VOLTAGE,
192                 .ctrl_addr      = PALMAS_LDO9_CTRL,
193                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO9,
194         },
195         {
196                 .name           = "LDO10",
197                 .sname          = "ldo10-in",
198                 .vsel_addr      = PALMAS_LDO10_VOLTAGE,
199                 .ctrl_addr      = PALMAS_LDO10_CTRL,
200                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO10,
201         },
202         {
203                 .name           = "LDO11",
204                 .sname          = "ldo11-in",
205                 .vsel_addr      = PALMAS_LDO11_VOLTAGE,
206                 .ctrl_addr      = PALMAS_LDO11_CTRL,
207                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO11,
208         },
209         {
210                 .name           = "LDO12",
211                 .sname          = "ldo12-in",
212                 .vsel_addr      = PALMAS_LDO12_VOLTAGE,
213                 .ctrl_addr      = PALMAS_LDO12_CTRL,
214                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO12,
215         },
216         {
217                 .name           = "LDO13",
218                 .sname          = "ldo13-in",
219                 .vsel_addr      = PALMAS_LDO13_VOLTAGE,
220                 .ctrl_addr      = PALMAS_LDO13_CTRL,
221                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO13,
222         },
223         {
224                 .name           = "LDO14",
225                 .sname          = "ldo14-in",
226                 .vsel_addr      = PALMAS_LDO14_VOLTAGE,
227                 .ctrl_addr      = PALMAS_LDO14_CTRL,
228                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDO14,
229         },
230         {
231                 .name           = "LDOLN",
232                 .sname          = "ldoln-in",
233                 .vsel_addr      = PALMAS_LDOLN_VOLTAGE,
234                 .ctrl_addr      = PALMAS_LDOLN_CTRL,
235                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDOLN,
236         },
237         {
238                 .name           = "LDOUSB",
239                 .sname          = "ldousb-in",
240                 .vsel_addr      = PALMAS_LDOUSB_VOLTAGE,
241                 .ctrl_addr      = PALMAS_LDOUSB_CTRL,
242                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_LDOUSB,
243         },
244         {
245                 .name           = "REGEN1",
246                 .ctrl_addr      = PALMAS_REGEN1_CTRL,
247                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_REGEN1,
248         },
249         {
250                 .name           = "REGEN2",
251                 .ctrl_addr      = PALMAS_REGEN2_CTRL,
252                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_REGEN2,
253         },
254         {
255                 .name           = "REGEN3",
256                 .ctrl_addr      = PALMAS_REGEN3_CTRL,
257                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_REGEN3,
258         },
259         {
260                 .name           = "REGEN4",
261                 .ctrl_addr      = PALMAS_REGEN4_CTRL,
262                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_REGEN4,
263         },
264         {
265                 .name           = "REGEN5",
266                 .ctrl_addr      = PALMAS_REGEN5_CTRL,
267                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_REGEN5,
268         },
269         {
270                 .name           = "REGEN7",
271                 .ctrl_addr      = PALMAS_REGEN7_CTRL,
272                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_REGEN7,
273         },
274         {
275                 .name           = "SYSEN1",
276                 .ctrl_addr      = PALMAS_SYSEN1_CTRL,
277                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SYSEN1,
278         },
279         {
280                 .name           = "SYSEN2",
281                 .ctrl_addr      = PALMAS_SYSEN2_CTRL,
282                 .sleep_id       = PALMAS_SLEEP_REQSTR_ID_SYSEN2,
283         },
284         {
285                 .name           = "CHARGERPUMP",
286                 .ctrl_addr      = PALMAS_CHARGE_PUMP_CTRL,
287         },
288 };
289
290 static unsigned int palmas_smps_ramp_delay[4] = {0, 10000, 5000, 2500};
291
292 #define SMPS_CTRL_MODE_OFF              0x00
293 #define SMPS_CTRL_MODE_ON               0x01
294 #define SMPS_CTRL_MODE_ECO              0x02
295 #define SMPS_CTRL_MODE_PWM              0x03
296
297 #define SMPS_CTRL_SLEEP_MODE_OFF        0x00
298 #define SMPS_CTRL_SLEEP_MODE_ON         0x04
299 #define SMPS_CTRL_SLEEP_MODE_ECO        0x08
300 #define SMPS_CTRL_SLEEP_MODE_PWM        0x0C
301
302 /* These values are derived from the data sheet. And are the number of steps
303  * where there is a voltage change, the ranges at beginning and end of register
304  * max/min values where there are no change are ommitted.
305  *
306  * So they are basically (maxV-minV)/stepV
307  */
308 #define PALMAS_SMPS_NUM_VOLTAGES        122
309 #define PALMAS_SMPS10_NUM_VOLTAGES      2
310 #define PALMAS_LDO_NUM_VOLTAGES         50
311
312 #define SMPS10_VSEL                     (1<<3)
313 #define SMPS10_BOOST_EN                 (1<<2)
314 #define SMPS10_BYPASS_EN                (1<<1)
315 #define SMPS10_SWITCH_EN                (1<<0)
316
317 #define REGULATOR_SLAVE                 0
318
319 static int palmas_smps_read(struct palmas *palmas, unsigned int reg,
320                 unsigned int *dest)
321 {
322         unsigned int addr;
323
324         addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
325
326         return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
327 }
328
329 static int palmas_smps_write(struct palmas *palmas, unsigned int reg,
330                 unsigned int value)
331 {
332         unsigned int addr;
333
334         addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
335
336         return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
337 }
338
339 static int palmas_ldo_read(struct palmas *palmas, unsigned int reg,
340                 unsigned int *dest)
341 {
342         unsigned int addr;
343
344         addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
345
346         return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
347 }
348
349 static int palmas_ldo_write(struct palmas *palmas, unsigned int reg,
350                 unsigned int value)
351 {
352         unsigned int addr;
353
354         addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
355
356         return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
357 }
358
359 static int palmas_is_enabled_smps(struct regulator_dev *dev)
360 {
361         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
362         int id = rdev_get_id(dev);
363         unsigned int reg;
364
365         palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
366
367         reg &= PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
368         reg >>= PALMAS_SMPS12_CTRL_MODE_ACTIVE_SHIFT;
369
370         return !!(reg);
371 }
372
373 static int palmas_enable_smps(struct regulator_dev *dev)
374 {
375         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
376         int id = rdev_get_id(dev);
377         unsigned int reg;
378
379         palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
380
381         reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
382         if (pmic->current_reg_mode[id])
383                 reg |= pmic->current_reg_mode[id];
384         else
385                 reg |= SMPS_CTRL_MODE_ON;
386
387         palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
388
389         return 0;
390 }
391
392 static int palmas_disable_smps(struct regulator_dev *dev)
393 {
394         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
395         int id = rdev_get_id(dev);
396         unsigned int reg;
397
398         palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
399
400         reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
401
402         palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
403
404         return 0;
405 }
406
407 static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
408 {
409         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
410         int id = rdev_get_id(dev);
411         unsigned int reg;
412         bool rail_enable = true;
413
414         palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
415         reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
416
417         if (reg == SMPS_CTRL_MODE_OFF)
418                 rail_enable = false;
419
420         switch (mode) {
421         case REGULATOR_MODE_NORMAL:
422                 reg |= SMPS_CTRL_MODE_ON;
423                 break;
424         case REGULATOR_MODE_IDLE:
425                 reg |= SMPS_CTRL_MODE_ECO;
426                 break;
427         case REGULATOR_MODE_FAST:
428                 reg |= SMPS_CTRL_MODE_PWM;
429                 break;
430         default:
431                 return -EINVAL;
432         }
433
434         pmic->current_reg_mode[id] = reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
435         if (rail_enable)
436                 palmas_smps_write(pmic->palmas,
437                         palmas_regs_info[id].ctrl_addr, reg);
438         return 0;
439 }
440
441 static unsigned int palmas_get_mode_smps(struct regulator_dev *dev)
442 {
443         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
444         int id = rdev_get_id(dev);
445         unsigned int reg;
446
447         reg = pmic->current_reg_mode[id] & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
448
449         switch (reg) {
450         case SMPS_CTRL_MODE_ON:
451                 return REGULATOR_MODE_NORMAL;
452         case SMPS_CTRL_MODE_ECO:
453                 return REGULATOR_MODE_IDLE;
454         case SMPS_CTRL_MODE_PWM:
455                 return REGULATOR_MODE_FAST;
456         }
457
458         return 0;
459 }
460
461 static int palmas_set_sleep_mode_smps(struct regulator_dev *dev,
462         unsigned int mode)
463 {
464         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
465         int id = rdev_get_id(dev);
466         unsigned int reg;
467
468         palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
469         reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK;
470
471         switch (mode) {
472         case REGULATOR_MODE_NORMAL:
473                 reg |= SMPS_CTRL_SLEEP_MODE_ON;
474                 break;
475         case REGULATOR_MODE_IDLE:
476                 reg |= SMPS_CTRL_SLEEP_MODE_ECO;
477                 break;
478         case REGULATOR_MODE_FAST:
479                 reg |= SMPS_CTRL_SLEEP_MODE_PWM;
480                 break;
481         case REGULATOR_MODE_STANDBY:
482         case REGULATOR_MODE_OFF:
483                 reg |= SMPS_CTRL_SLEEP_MODE_OFF;
484                 break;
485         default:
486                 return -EINVAL;
487         }
488         palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
489         return 0;
490 }
491
492 static int palmas_list_voltage_smps(struct regulator_dev *dev,
493                                         unsigned selector)
494 {
495         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
496         int id = rdev_get_id(dev);
497         int mult = 1;
498
499         /* Read the multiplier set in VSEL register to return
500          * the correct voltage.
501          */
502         if (pmic->range[id])
503                 mult = 2;
504
505         if (selector == 0)
506                 return 0;
507         else if (selector < 6)
508                 return 500000 * mult;
509         else
510                 /* Voltage is linear mapping starting from selector 6,
511                  * volt = (0.49V + ((selector - 5) * 0.01V)) * RANGE
512                  * RANGE is either x1 or x2
513                  */
514                 return (490000 + ((selector - 5) * 10000)) * mult;
515 }
516
517 static int palmas_map_voltage_smps(struct regulator_dev *rdev,
518                 int min_uV, int max_uV)
519 {
520         struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
521         int id = rdev_get_id(rdev);
522         int ret, voltage;
523
524         if (min_uV == 0)
525                 return 0;
526
527         if (pmic->range[id]) { /* RANGE is x2 */
528                 if (min_uV < 1000000)
529                         min_uV = 1000000;
530                 ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 6;
531         } else {                /* RANGE is x1 */
532                 if (min_uV < 500000)
533                         min_uV = 500000;
534                 ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 6;
535         }
536
537         /* Map back into a voltage to verify we're still in bounds */
538         voltage = palmas_list_voltage_smps(rdev, ret);
539         if (voltage < min_uV || voltage > max_uV)
540                 return -EINVAL;
541
542         return ret;
543 }
544
545 static int palma_smps_set_voltage_smps_time_sel(struct regulator_dev *rdev,
546         unsigned int old_selector, unsigned int new_selector)
547 {
548         struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
549         int id = rdev_get_id(rdev);
550         int old_uv, new_uv;
551         unsigned int ramp_delay = pmic->ramp_delay[id];
552
553         if (!pmic->ramp_delay_support[id])
554                 return 0;
555
556         /* ES2.1, have the 1.5X slower slew rate than configured */
557         if (palmas_is_es_version_or_less(pmic->palmas, 2, 1))
558                 ramp_delay = (ramp_delay * 10)/15;
559
560         if (!ramp_delay)
561                 return 0;
562
563         old_uv = palmas_list_voltage_smps(rdev, old_selector);
564         if (old_uv < 0)
565                 return old_uv;
566
567         new_uv = palmas_list_voltage_smps(rdev, new_selector);
568         if (new_uv < 0)
569                 return new_uv;
570
571         return DIV_ROUND_UP(abs(old_uv - new_uv), ramp_delay);
572 }
573
574 static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev,
575                  int ramp_delay)
576 {
577         struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
578         int id = rdev_get_id(rdev);
579         unsigned int reg = 0;
580         unsigned int addr = palmas_regs_info[id].tstep_addr;
581         int ret;
582
583         if (!pmic->ramp_delay_support[id])
584                 return 0;
585
586         if (ramp_delay <= 0)
587                 reg = 0;
588         else if (ramp_delay <= 2500)
589                 reg = 3;
590         else if (ramp_delay <= 5000)
591                 reg = 2;
592         else
593                 reg = 1;
594
595         ret = palmas_smps_write(pmic->palmas, addr, reg);
596         if (ret < 0) {
597                 dev_err(pmic->palmas->dev, "TSTEP write failed: %d\n", ret);
598                 return ret;
599         }
600
601         pmic->ramp_delay[id] = palmas_smps_ramp_delay[reg];
602         return ret;
603 }
604
605 static struct regulator_ops palmas_ops_smps = {
606         .is_enabled             = palmas_is_enabled_smps,
607         .enable                 = palmas_enable_smps,
608         .disable                = palmas_disable_smps,
609         .set_mode               = palmas_set_mode_smps,
610         .get_mode               = palmas_get_mode_smps,
611         .set_sleep_mode         = palmas_set_sleep_mode_smps,
612         .get_voltage_sel        = regulator_get_voltage_sel_regmap,
613         .set_voltage_sel        = regulator_set_voltage_sel_regmap,
614         .list_voltage           = palmas_list_voltage_smps,
615         .map_voltage            = palmas_map_voltage_smps,
616         .set_voltage_time_sel   = palma_smps_set_voltage_smps_time_sel,
617         .set_ramp_delay         = palmas_smps_set_ramp_delay,
618 };
619
620 static struct regulator_ops palmas_ops_smps_extctrl = {
621         .set_mode               = palmas_set_mode_smps,
622         .get_mode               = palmas_get_mode_smps,
623         .set_sleep_mode         = palmas_set_sleep_mode_smps,
624         .get_voltage_sel        = regulator_get_voltage_sel_regmap,
625         .set_voltage_sel        = regulator_set_voltage_sel_regmap,
626         .list_voltage           = palmas_list_voltage_smps,
627         .map_voltage            = palmas_map_voltage_smps,
628         .set_voltage_time_sel   = palma_smps_set_voltage_smps_time_sel,
629         .set_ramp_delay         = palmas_smps_set_ramp_delay,
630 };
631
632 static struct regulator_ops palmas_ops_smps10 = {
633         .is_enabled             = regulator_is_enabled_regmap,
634         .enable                 = regulator_enable_regmap,
635         .disable                = regulator_disable_regmap,
636         .get_voltage_sel        = regulator_get_voltage_sel_regmap,
637         .set_voltage_sel        = regulator_set_voltage_sel_regmap,
638         .list_voltage           = regulator_list_voltage_linear,
639         .map_voltage            = regulator_map_voltage_linear,
640         .set_bypass             = regulator_set_bypass_regmap,
641         .get_bypass             = regulator_get_bypass_regmap,
642 };
643
644 static int palmas_ldo_enable_time(struct regulator_dev *dev)
645 {
646         return 500;
647 }
648
649 static int palmas_list_voltage_ldo(struct regulator_dev *dev,
650                                         unsigned selector)
651 {
652         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
653         int id = rdev_get_id(dev);
654
655         if (!selector)
656                 return 0;
657
658         if (pmic->palmas->id == TPS80036) {
659                 if (id == PALMAS_REG_LDO4 || id == PALMAS_REG_LDO5 ||
660                                 id == PALMAS_REG_LDO9)
661                         if (pmic->ldo_vref0p425)
662                                 return  (850000 + (selector * 50000)) / 2;
663
664         }
665
666         /* voltage is 0.85V + (selector * 0.05v) */
667         return  850000 + (selector * 50000);
668 }
669
670 static int palmas_map_voltage_ldo(struct regulator_dev *rdev,
671                 int min_uV, int max_uV)
672 {
673         int ret, voltage;
674
675         if (min_uV == 0)
676                 return 0;
677
678         if (min_uV < 900000)
679                 min_uV = 900000;
680         ret = DIV_ROUND_UP(min_uV - 900000, 50000) + 1;
681
682         /* Map back into a voltage to verify we're still in bounds */
683         voltage = palmas_list_voltage_ldo(rdev, ret);
684         if (voltage < min_uV || voltage > max_uV)
685                 return -EINVAL;
686
687         return ret;
688 }
689
690 static struct regulator_ops palmas_ops_ldo = {
691         .enable_time            = palmas_ldo_enable_time,
692         .is_enabled             = regulator_is_enabled_regmap,
693         .enable                 = regulator_enable_regmap,
694         .disable                = regulator_disable_regmap,
695         .get_voltage_sel        = regulator_get_voltage_sel_regmap,
696         .set_voltage_sel        = regulator_set_voltage_sel_regmap,
697         .list_voltage           = palmas_list_voltage_ldo,
698         .map_voltage            = palmas_map_voltage_ldo,
699 };
700
701 static struct regulator_ops palmas_ops_ldo_extctrl = {
702         .get_voltage_sel        = regulator_get_voltage_sel_regmap,
703         .set_voltage_sel        = regulator_set_voltage_sel_regmap,
704         .list_voltage           = palmas_list_voltage_ldo,
705         .map_voltage            = palmas_map_voltage_ldo,
706 };
707
708 static int palmas_getvoltage_chargepump(struct regulator_dev *rdev)
709 {
710         return 5000;
711 }
712
713 static int palmas_getvoltage_extreg(struct regulator_dev *rdev)
714 {
715         return 4300 * 1000;
716 }
717
718 static struct regulator_ops palmas_ops_extreg = {
719         .is_enabled             = regulator_is_enabled_regmap,
720         .enable                 = regulator_enable_regmap,
721         .disable                = regulator_disable_regmap,
722 };
723
724 static struct regulator_ops palmas_ops_extreg_extctrl = {
725         .get_voltage            = palmas_getvoltage_extreg,
726 };
727
728 static struct regulator_ops palmas_ops_chargepump = {
729         .is_enabled             = regulator_is_enabled_regmap,
730         .enable                 = regulator_enable_regmap,
731         .disable                = regulator_disable_regmap,
732         .get_voltage            = palmas_getvoltage_chargepump,
733 };
734
735 static int palmas_ldo5_tracking_init(struct palmas *palmas,
736                 struct palmas_reg_init *reg_init,
737                 struct regulator_dev *rdev)
738 {
739         unsigned int reg;
740         int ret;
741
742         ret = palmas_ldo_read(palmas, PALMAS_LDO_CTRL, &reg);
743         if (ret < 0)
744                 return ret;
745         reg = reg & ~PALMAS_LDO_CTRL_LDO5_BYPASS_SRC_SEL_MASK;
746         if (reg_init->config_flags & PALMAS_REGULATOR_CONFIG_TRACKING_ENABLE) {
747                 if (reg_init->tracking_regulator == PALMAS_REG_SMPS12)
748                         reg |= PALMAS_LDO_CTRL_LDO5_BYPASS_SRC_SEL_SMPS12;
749                 else if (reg_init->tracking_regulator == PALMAS_REG_SMPS3)
750                         reg |= PALMAS_LDO_CTRL_LDO5_BYPASS_SRC_SEL_SMPS3;
751                 else if (reg_init->tracking_regulator == PALMAS_REG_SMPS6)
752                         reg |= PALMAS_LDO_CTRL_LDO5_BYPASS_SRC_SEL_SMPS6;
753         }
754         ret = palmas_ldo_write(palmas, PALMAS_LDO_CTRL, reg);
755         if (ret < 0)
756                 return ret;
757
758         if (reg_init->config_flags & PALMAS_REGULATOR_CONFIG_TRACKING_ENABLE) {
759                 ret = regulator_disable_regmap(rdev);
760                 if (ret < 0)
761                 return ret;
762         }
763         return 0;
764 }
765
766 static void palmas_enable_ldo8_track(struct palmas *palmas)
767 {
768         unsigned int reg;
769         unsigned int addr;
770         int ret;
771
772         addr = palmas_regs_info[PALMAS_REG_LDO8].ctrl_addr;
773
774         ret = palmas_ldo_read(palmas, addr, &reg);
775         if (ret) {
776                 dev_err(palmas->dev, "Error in reading ldo8 control reg\n");
777                 return;
778         }
779
780         reg |= PALMAS_LDO8_CTRL_LDO_TRACKING_EN;
781         ret = palmas_ldo_write(palmas, addr, reg);
782         if (ret < 0) {
783                 dev_err(palmas->dev, "Error in enabling tracking mode\n");
784                 return;
785         }
786         /*
787          * When SMPS45 is set to off and LDO8 tracking is enabled, the LDO8
788          * output is defined by the LDO8_VOLTAGE.VSEL register divided by two,
789          * and can be set from 0.45 to 1.65 V.
790          */
791         addr = palmas_regs_info[PALMAS_REG_LDO8].vsel_addr;
792         ret = palmas_ldo_read(palmas, addr, &reg);
793         if (ret) {
794                 dev_err(palmas->dev, "Error in reading ldo8 voltage reg\n");
795                 return;
796         }
797
798         reg = (reg << 1) & PALMAS_LDO8_VOLTAGE_VSEL_MASK;
799         ret = palmas_ldo_write(palmas, addr, reg);
800         if (ret < 0) {
801                 dev_err(palmas->dev, "Error in setting ldo8 voltage reg\n");
802                 return;
803         }
804
805         /*
806          * Errata ES1.0, 2,0 and 2.1
807          * When Tracking is enbled, it need to disable Pull-Down for LDO8 and
808          * when tracking is disabled, SW has to enabe Pull-Down.
809          */
810         if (palmas_is_es_version_or_less(palmas, 2, 1)) {
811                 addr = PALMAS_LDO_PD_CTRL1;
812                 ret = palmas_ldo_read(palmas, addr, &reg);
813                 if (ret < 0) {
814                         dev_err(palmas->dev,
815                                 "Error in reading pulldown control reg\n");
816                         return;
817                 }
818                 reg &= ~PALMAS_LDO_PD_CTRL1_LDO8;
819                 ret = palmas_ldo_write(palmas, addr, reg);
820                 if (ret < 0) {
821                         dev_err(palmas->dev,
822                                 "Error in setting pulldown control reg\n");
823                         return;
824                 }
825         }
826
827         return;
828 }
829
830 static void palmas_disable_ldo8_track(struct palmas *palmas)
831 {
832         unsigned int reg;
833         unsigned int addr;
834         int ret;
835
836         /*
837          * When SMPS4&5 is set to off and LDO8 tracking is enabled, the LDO8
838          * output is defined by the LDO8_VOLTAGE.VSEL register divided by two,
839          * and can be set from 0.45 to 1.65 V.
840          */
841         addr = palmas_regs_info[PALMAS_REG_LDO8].vsel_addr;
842         ret = palmas_ldo_read(palmas, addr, &reg);
843         if (ret) {
844                 dev_err(palmas->dev, "Error in reading ldo8 voltage reg\n");
845                 return;
846         }
847
848         reg = (reg >> 1) & PALMAS_LDO8_VOLTAGE_VSEL_MASK;
849         ret = palmas_ldo_write(palmas, addr, reg);
850         if (ret < 0) {
851                 dev_err(palmas->dev, "Error in setting ldo8 voltage reg\n");
852                 return;
853         }
854
855         /* Disable the tracking mode */
856         addr = palmas_regs_info[PALMAS_REG_LDO8].ctrl_addr;
857         ret = palmas_ldo_read(palmas, addr, &reg);
858         if (ret) {
859                 dev_err(palmas->dev, "Error in reading ldo8 control reg\n");
860                 return;
861         }
862         reg &= ~PALMAS_LDO8_CTRL_LDO_TRACKING_EN;
863         ret = palmas_ldo_write(palmas, addr, reg);
864         if (ret < 0) {
865                 dev_err(palmas->dev, "Error in disabling tracking mode\n");
866                 return;
867         }
868
869         /*
870          * Errata ES1.0, 2,0 and 2.1
871          * When Tracking is enbled, it need to disable Pull-Down for LDO8 and
872          * when tracking is disabled, SW has to enabe Pull-Down.
873          */
874         if (palmas_is_es_version_or_less(palmas, 2, 1)) {
875                 addr = PALMAS_LDO_PD_CTRL1;
876                 ret = palmas_ldo_read(palmas, addr, &reg);
877                 if (ret < 0) {
878                         dev_err(palmas->dev,
879                                 "Error in reading pulldown control reg\n");
880                         return;
881                 }
882                 reg |= PALMAS_LDO_PD_CTRL1_LDO8;
883                 ret = palmas_ldo_write(palmas, addr, reg);
884                 if (ret < 0) {
885                         dev_err(palmas->dev,
886                                 "Error in setting pulldown control reg\n");
887                         return;
888                 }
889         }
890
891         return;
892 }
893
894 /*
895  * setup the hardware based sleep configuration of the SMPS/LDO regulators
896  * from the platform data. This is different to the software based control
897  * supported by the regulator framework as it is controlled by toggling
898  * pins on the PMIC such as PREQ, SYSEN, ...
899  */
900 static int palmas_smps_init(struct regulator_dev *rdev,
901                 struct palmas *palmas, int id,
902                 struct palmas_reg_init *reg_init)
903 {
904         unsigned int reg;
905         unsigned int addr;
906         int ret;
907
908         addr = palmas_regs_info[id].ctrl_addr;
909
910         ret = palmas_smps_read(palmas, addr, &reg);
911         if (ret)
912                 return ret;
913
914         switch (id) {
915         case PALMAS_REG_SMPS10_OUT1:
916         case PALMAS_REG_SMPS10_OUT2:
917                 reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
918                 if (reg_init->mode_sleep)
919                         reg |= reg_init->mode_sleep <<
920                                         PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
921                 break;
922         default:
923                 if (reg_init->warm_reset)
924                         reg |= PALMAS_SMPS12_CTRL_WR_S;
925                 else
926                         reg &= ~PALMAS_SMPS12_CTRL_WR_S;
927
928                 if (reg_init->roof_floor)
929                         reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN;
930                 else
931                         reg &= ~PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN;
932
933                 reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK;
934                 if (reg_init->mode_sleep)
935                         reg |= reg_init->mode_sleep <<
936                                         PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT;
937                 break;
938         }
939
940         ret = palmas_smps_write(palmas, addr, reg);
941         if (ret)
942                 return ret;
943
944         if ((id != PALMAS_REG_SMPS10_OUT1) &&
945                         (id != PALMAS_REG_SMPS10_OUT2) &&
946                         reg_init->roof_floor) {
947                 int sleep_id = palmas_regs_info[id].sleep_id;
948
949                 ret = palmas_enable_smps(rdev);
950                 if (ret < 0) {
951                         dev_err(palmas->dev, "SMPS enable failed %d\n", ret);
952                         return ret;
953                 }
954
955                 ret = palmas_ext_power_req_config(palmas, sleep_id,
956                                         reg_init->roof_floor, true);
957                 if (ret < 0) {
958                         dev_err(palmas->dev,
959                                 "Error in configuring external control\n");
960                         return ret;
961                 }
962
963                 if (id == PALMAS_REG_SMPS123) {
964                         ret = palmas_ext_power_req_config(palmas,
965                                         PALMAS_SLEEP_REQSTR_ID_SMPS3,
966                                         reg_init->roof_floor, true);
967                         if (ret < 0) {
968                                 dev_err(palmas->dev,
969                                         "Error in configuring ext control\n");
970                                 return ret;
971                         }
972                 }
973         }
974
975         if (palmas_regs_info[id].vsel_addr && reg_init->vsel) {
976                 addr = palmas_regs_info[id].vsel_addr;
977
978                 reg = reg_init->vsel;
979
980                 ret = palmas_smps_write(palmas, addr, reg);
981                 if (ret)
982                         return ret;
983         }
984
985
986         return 0;
987 }
988
989 static int palmas_ldo_init(struct regulator_dev *rdev,
990                 struct palmas *palmas, int id,
991                 struct palmas_reg_init *reg_init)
992 {
993         unsigned int reg;
994         unsigned int addr;
995         int ret;
996
997         addr = palmas_regs_info[id].ctrl_addr;
998
999         ret = palmas_ldo_read(palmas, addr, &reg);
1000         if (ret)
1001                 return ret;
1002
1003         if (reg_init->warm_reset)
1004                 reg |= PALMAS_LDO1_CTRL_WR_S;
1005         else
1006                 reg &= ~PALMAS_LDO1_CTRL_WR_S;
1007
1008         if (reg_init->mode_sleep)
1009                 reg |= PALMAS_LDO1_CTRL_MODE_SLEEP;
1010         else
1011                 reg &= ~PALMAS_LDO1_CTRL_MODE_SLEEP;
1012
1013         ret = palmas_ldo_write(palmas, addr, reg);
1014         if (ret)
1015                 return ret;
1016
1017         if (reg_init->roof_floor) {
1018                 int sleep_id = palmas_regs_info[id].sleep_id;
1019
1020                 /* Always enable if externally controlled */
1021                 ret = regulator_enable_regmap(rdev);
1022                 if (ret < 0) {
1023                         dev_err(palmas->dev,
1024                                 "Error in enabling LOD regulator %d\n", id);
1025                         return ret;
1026                 }
1027
1028                 ret = palmas_ext_power_req_config(palmas, sleep_id,
1029                         reg_init->roof_floor, true);
1030                 if (ret < 0) {
1031                         dev_err(palmas->dev,
1032                                 "Error in configuring external control\n");
1033                         return ret;
1034                 }
1035         }
1036
1037         /* Rail specific configuration */
1038         switch (id) {
1039         case PALMAS_REG_LDO5:
1040                 ret = palmas_ldo5_tracking_init(palmas, reg_init,
1041                                         palmas->pmic->rdev[id]);
1042                 if (ret < 0) {
1043                         dev_err(palmas->dev,
1044                                 "tracking mode init for rail %d failed: %d\n",
1045                                 id, ret);
1046                         return ret;
1047                 }
1048                 break;
1049
1050         case PALMAS_REG_LDO8:
1051                 if (reg_init->config_flags &
1052                         PALMAS_REGULATOR_CONFIG_TRACKING_ENABLE)
1053                         palmas_enable_ldo8_track(palmas);
1054                 break;
1055
1056         default:
1057                 break;
1058         }
1059         return 0;
1060 }
1061
1062 static int palmas_extreg_init(struct regulator_dev *rdev,
1063                 struct palmas *palmas, int id,
1064                 struct palmas_reg_init *reg_init)
1065 {
1066         unsigned int addr;
1067         int ret;
1068         unsigned int val = 0;
1069
1070         addr = palmas_regs_info[id].ctrl_addr;
1071
1072         if (reg_init->mode_sleep)
1073                 val = PALMAS_REGEN1_CTRL_MODE_SLEEP;
1074
1075         ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE,
1076                         addr, PALMAS_REGEN1_CTRL_MODE_SLEEP, val);
1077         if (ret < 0) {
1078                 dev_err(palmas->dev, "Resource reg 0x%02x update failed %d\n",
1079                         addr, ret);
1080                 return ret;
1081         }
1082
1083         if (reg_init->roof_floor) {
1084                 int sleep_id = palmas_regs_info[id].sleep_id;
1085
1086                 /* Always enable if externally controlled */
1087                 ret = regulator_enable_regmap(rdev);
1088                 if (ret < 0) {
1089                         dev_err(palmas->dev,
1090                                 "Error in enabling regulator %d\n", id);
1091                         return ret;
1092                 }
1093
1094                 ret = palmas_ext_power_req_config(palmas, sleep_id,
1095                         reg_init->roof_floor, true);
1096                 if (ret < 0) {
1097                         dev_err(palmas->dev,
1098                                 "Error in configuring external control\n");
1099                         return ret;
1100                 }
1101         }
1102         return 0;
1103 }
1104
1105 static ssize_t palmas_show_dvfs_data(struct device *dev,
1106                         struct device_attribute *attr, char *buf)
1107 {
1108         struct palmas_pmic_platform_data *pdata = dev_get_platdata(dev);
1109         struct palmas_dvfs_init_data *dvfs_idata = pdata->dvfs_init_data;
1110         int data_size = pdata->dvfs_init_data_size;
1111         int i;
1112         int count = 0;
1113
1114         if (!dvfs_idata || !data_size)
1115                 return 0;
1116
1117         for (i = 0; i < data_size; i++) {
1118                 struct palmas_dvfs_init_data *dvfs_pd =  &dvfs_idata[i];
1119                 if (!dvfs_pd->en_pwm)
1120                         continue;
1121
1122                 count += sprintf(buf+count, "base_voltage:%d\n",
1123                                 dvfs_pd->base_voltage_uV);
1124                 count += sprintf(buf+count, "step_size:%d\n",
1125                                 dvfs_pd->step_20mV ? 20000 : 10000);
1126                 count += sprintf(buf+count, "max_voltage:%d\n",
1127                                 dvfs_pd->max_voltage_uV);
1128         }
1129
1130         return count;
1131 }
1132 static DEVICE_ATTR(dvfs_data, 0444, palmas_show_dvfs_data, NULL);
1133
1134 static void palmas_dvfs_init(struct palmas *palmas,
1135                         struct palmas_pmic_platform_data *pdata)
1136 {
1137         int slave;
1138         struct palmas_dvfs_init_data *dvfs_idata = pdata->dvfs_init_data;
1139         int data_size = pdata->dvfs_init_data_size;
1140         unsigned int reg, addr;
1141         int ret;
1142         int sleep_id;
1143         int i;
1144
1145         if (!dvfs_idata || !data_size)
1146                 return;
1147
1148         slave = PALMAS_BASE_TO_SLAVE(PALMAS_DVFS_BASE);
1149         for (i = 0; i < data_size; i++) {
1150                 struct palmas_dvfs_init_data *dvfs_pd =  &dvfs_idata[i];
1151
1152                 sleep_id = palmas_regs_info[dvfs_pd->reg_id].sleep_id;
1153                 if (!dvfs_pd->en_pwm)
1154                         continue;
1155
1156                 ret = palmas_ext_power_req_config(palmas, sleep_id,
1157                                 dvfs_pd->ext_ctrl, true);
1158                 if (ret < 0) {
1159                         dev_err(palmas->dev,
1160                                         "Error in configuring external control\n");
1161                         goto err;
1162                 }
1163
1164                 addr = PALMAS_BASE_TO_REG(PALMAS_DVFS_BASE,
1165                                 (PALMAS_SMPS_DVFS1_CTRL) + i*3);
1166                 reg =  (1 << PALMAS_SMPS_DVFS1_ENABLE_SHIFT);
1167                 if (dvfs_pd->step_20mV)
1168                         reg |= (1 << PALMAS_SMPS_DVFS1_OFFSET_STEP_SHIFT);
1169                 /* only DVFS1_CTRL register contains smps select bit */
1170                 if (dvfs_pd->smps3_ctrl && (i == 0))
1171                         reg |= (1 << PALMAS_SMPS_DVFS1_SMPS_SELECT_SHIFT);
1172
1173                 ret = regmap_write(palmas->regmap[slave], addr, reg);
1174                 if (ret)
1175                         goto err;
1176
1177                 addr = PALMAS_BASE_TO_REG(PALMAS_DVFS_BASE,
1178                                 (PALMAS_SMPS_DVFS1_VOLTAGE_MAX) + i*3);
1179                 if (!(dvfs_pd->max_voltage_uV >= DVFS_BASE_VOLTAGE_UV &&
1180                         dvfs_pd->max_voltage_uV <= DVFS_MAX_VOLTAGE_UV))
1181                         goto err;
1182
1183                 reg = DIV_ROUND_UP((dvfs_pd->max_voltage_uV -
1184                         DVFS_BASE_VOLTAGE_UV), DVFS_VOLTAGE_STEP_UV) + 6;
1185                 ret = regmap_write(palmas->regmap[slave], addr, reg);
1186                 if (ret)
1187                         goto err;
1188
1189                 addr = palmas_regs_info[dvfs_pd->reg_id].ctrl_addr;
1190                 ret = palmas_update_bits(palmas, PALMAS_SMPS_BASE, addr,
1191                         PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN, 0);
1192                 if (ret)
1193                         goto err;
1194
1195                 addr = palmas_regs_info[dvfs_pd->reg_id].fvsel_addr;
1196                 reg = (1 << PALMAS_SMPS12_FORCE_CMD_SHIFT);
1197                 reg |= DIV_ROUND_UP((dvfs_pd->base_voltage_uV -
1198                         DVFS_BASE_VOLTAGE_UV), DVFS_VOLTAGE_STEP_UV) + 6;
1199                 ret = palmas_smps_write(palmas, addr, reg);
1200                 if (ret)
1201                         goto  err;
1202
1203         }
1204
1205         ret = device_create_file(palmas->pmic->dev, &dev_attr_dvfs_data);
1206         if (ret)
1207                 dev_warn(palmas->pmic->dev,
1208                                 "Can't register dvfs sysfs attribute\n");
1209
1210         ret = sysfs_create_link(kernel_kobj, &(palmas->pmic->dev->kobj),
1211                                 "pmic");
1212         if (ret)
1213                 dev_warn(palmas->pmic->dev, "Can't create sysfs link\n");
1214
1215         return;
1216 err:
1217         dev_err(palmas->dev, "Failed to initilize cl dvfs(%d)", i);
1218         return;
1219 }
1220
1221 static struct of_regulator_match palmas_matches[] = {
1222         { .name = "smps12", },
1223         { .name = "smps123", },
1224         { .name = "smps3", },
1225         { .name = "smps45", },
1226         { .name = "smps457", },
1227         { .name = "smps6", },
1228         { .name = "smps7", },
1229         { .name = "smps8", },
1230         { .name = "smps9", },
1231         { .name = "smps10_out2", },
1232         { .name = "smps10_out1", },
1233         { .name = "ldo1", },
1234         { .name = "ldo2", },
1235         { .name = "ldo3", },
1236         { .name = "ldo4", },
1237         { .name = "ldo5", },
1238         { .name = "ldo6", },
1239         { .name = "ldo7", },
1240         { .name = "ldo8", },
1241         { .name = "ldo9", },
1242         { .name = "ldo10", },
1243         { .name = "ldo11", },
1244         { .name = "ldo12", },
1245         { .name = "ldo13", },
1246         { .name = "ldo14", },
1247         { .name = "ldoln", },
1248         { .name = "ldousb", },
1249         { .name = "regen1", },
1250         { .name = "regen2", },
1251         { .name = "regen3", },
1252         { .name = "regen4", },
1253         { .name = "regen5", },
1254         { .name = "regen7", },
1255         { .name = "sysen1", },
1256         { .name = "sysen2", },
1257         { .name = "charger_pump", },
1258 };
1259
1260 static void palmas_dt_to_pdata(struct device *dev,
1261                 struct device_node *node,
1262                 struct palmas_pmic_platform_data *pdata)
1263 {
1264         struct device_node *regulators;
1265         u32 prop;
1266         int idx, ret;
1267
1268         node = of_node_get(node);
1269         regulators = of_find_node_by_name(node, "regulators");
1270         if (!regulators) {
1271                 dev_info(dev, "regulator node not found\n");
1272                 return;
1273         }
1274
1275         ret = of_regulator_match(dev, regulators, palmas_matches,
1276                         PALMAS_NUM_REGS);
1277         of_node_put(regulators);
1278         if (ret < 0) {
1279                 dev_err(dev, "Error parsing regulator init data: %d\n", ret);
1280                 return;
1281         }
1282
1283         for (idx = 0; idx < PALMAS_NUM_REGS; idx++) {
1284                 if (!palmas_matches[idx].init_data ||
1285                                 !palmas_matches[idx].of_node)
1286                         continue;
1287
1288                 pdata->reg_data[idx] = palmas_matches[idx].init_data;
1289
1290                 pdata->reg_init[idx] = devm_kzalloc(dev,
1291                                 sizeof(struct palmas_reg_init), GFP_KERNEL);
1292
1293                 pdata->reg_init[idx]->warm_reset =
1294                         of_property_read_bool(palmas_matches[idx].of_node,
1295                                              "ti,warm-reset");
1296
1297                 ret = of_property_read_u32(palmas_matches[idx].of_node,
1298                                               "ti,roof-floor", &prop);
1299                 /* EINVAL: Property not found */
1300                 if (ret != -EINVAL) {
1301                         int econtrol;
1302
1303                         /* use default value, when no value is specified */
1304                         econtrol = PALMAS_EXT_CONTROL_NSLEEP;
1305                         if (!ret) {
1306                                 switch (prop) {
1307                                 case 1:
1308                                         econtrol = PALMAS_EXT_CONTROL_ENABLE1;
1309                                         break;
1310                                 case 2:
1311                                         econtrol = PALMAS_EXT_CONTROL_ENABLE2;
1312                                         break;
1313                                 case 3:
1314                                         econtrol = PALMAS_EXT_CONTROL_NSLEEP;
1315                                         break;
1316                                 default:
1317                                         WARN_ON(1);
1318                                         dev_warn(dev,
1319                                         "%s: Invalid roof-floor option: %u\n",
1320                                              palmas_matches[idx].name, prop);
1321                                         break;
1322                                 }
1323                         }
1324                         pdata->reg_init[idx]->roof_floor = econtrol;
1325                 }
1326
1327                 ret = of_property_read_u32(palmas_matches[idx].of_node,
1328                                 "ti,mode-sleep", &prop);
1329                 if (!ret)
1330                         pdata->reg_init[idx]->mode_sleep = prop;
1331
1332                 ret = of_property_read_bool(palmas_matches[idx].of_node,
1333                                             "ti,smps-range");
1334                 if (ret)
1335                         pdata->reg_init[idx]->vsel =
1336                                 PALMAS_SMPS12_VOLTAGE_RANGE;
1337
1338                 if (idx == PALMAS_REG_LDO8) {
1339                         if (of_property_read_bool(palmas_matches[idx].of_node,
1340                                                 "ti,enable-ldo8-tracking")) {
1341                                 pdata->reg_init[idx]->config_flags =
1342                                         PALMAS_REGULATOR_CONFIG_TRACKING_ENABLE;
1343                         }
1344                 }
1345
1346                 ret = of_property_read_u32(palmas_matches[idx].of_node,
1347                                 "ti,config-flags", &prop);
1348                 if (!ret)
1349                         pdata->reg_init[idx]->config_flags = prop;
1350         }
1351
1352         pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator");
1353 }
1354
1355
1356 static int palmas_regulators_probe(struct platform_device *pdev)
1357 {
1358         struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
1359         struct palmas_pmic_platform_data *pdata = dev_get_platdata(&pdev->dev);
1360         struct device_node *node = pdev->dev.of_node;
1361         struct regulator_dev *rdev;
1362         struct regulator_config config = { };
1363         struct palmas_pmic *pmic;
1364         struct palmas_reg_init *reg_init;
1365         int id = 0, ret;
1366         unsigned int addr, reg;
1367         int roof_floor;
1368
1369         if (node && !pdata) {
1370                 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
1371
1372                 if (!pdata)
1373                         return -ENOMEM;
1374
1375                 palmas_dt_to_pdata(&pdev->dev, node, pdata);
1376         }
1377
1378         pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
1379         if (!pmic)
1380                 return -ENOMEM;
1381
1382         pmic->dev = &pdev->dev;
1383         pmic->palmas = palmas;
1384         palmas->pmic = pmic;
1385         platform_set_drvdata(pdev, pmic);
1386
1387         /* Read VREF0P425 of LDO_CTRL register for TPS80036 */
1388         if (palmas->id == TPS80036) {
1389                 ret = palmas_read(palmas, PALMAS_LDO_BASE,
1390                         PALMAS_LDO_CTRL, &reg);
1391                 if (ret)
1392                         goto err_unregister_regulator;
1393
1394                 palmas->pmic->ldo_vref0p425 = (reg & PALMAS_LDO_CTRL_VREF_425)
1395                                                 ? 1 : 0;
1396         }
1397
1398         ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg);
1399         if (ret)
1400                 return ret;
1401
1402         if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN)
1403                 pmic->smps123 = 1;
1404
1405         if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN)
1406                 pmic->smps457 = 1;
1407
1408         config.regmap = palmas->regmap[REGULATOR_SLAVE];
1409         config.dev = &pdev->dev;
1410         config.driver_data = pmic;
1411
1412         for (id = 0; id < PALMAS_REG_LDO1; id++) {
1413                 bool ramp_delay_support = false;
1414
1415                 reg_init = pdata->reg_init[id];
1416                 roof_floor = 0;
1417                 if (reg_init)
1418                         roof_floor = reg_init->roof_floor;
1419
1420                 /*
1421                  * Miss out regulators which are not available due
1422                  * to slaving configurations.
1423                  */
1424                 switch (id) {
1425                 case PALMAS_REG_SMPS12:
1426                 case PALMAS_REG_SMPS3:
1427                         if (pmic->smps123)
1428                                 continue;
1429                         if (id == PALMAS_REG_SMPS12)
1430                                 ramp_delay_support = true;
1431
1432                         /* TPS80036 suports ramp delay on SMPS3 also */
1433                         if (palmas->id == TPS80036)
1434                                 ramp_delay_support = true;
1435
1436                         break;
1437                 case PALMAS_REG_SMPS123:
1438                         if (!pmic->smps123)
1439                                 continue;
1440                         ramp_delay_support = true;
1441                         break;
1442                 case PALMAS_REG_SMPS45:
1443                 case PALMAS_REG_SMPS7:
1444                         if (pmic->smps457)
1445                                 continue;
1446                         if (id == PALMAS_REG_SMPS45)
1447                                 ramp_delay_support = true;
1448                         break;
1449                 case PALMAS_REG_SMPS457:
1450                         if (!pmic->smps457)
1451                                 continue;
1452                         ramp_delay_support = true;
1453                         break;
1454                 }
1455
1456                 if ((id == PALMAS_REG_SMPS6) || (id == PALMAS_REG_SMPS8))
1457                         ramp_delay_support = true;
1458
1459                 pmic->ramp_delay_support[id] = ramp_delay_support;
1460                 if (ramp_delay_support) {
1461                         addr = palmas_regs_info[id].tstep_addr;
1462                         ret = palmas_smps_read(pmic->palmas, addr, &reg);
1463                         if (ret < 0) {
1464                                 dev_err(&pdev->dev,
1465                                         "reading TSTEP reg failed: %d\n", ret);
1466                                 goto err_unregister_regulator;
1467                         }
1468                         pmic->desc[id].ramp_delay =
1469                                         palmas_smps_ramp_delay[reg & 0x3];
1470                         pmic->ramp_delay[id] = pmic->desc[id].ramp_delay;
1471                 }
1472
1473                 /* Register the regulators */
1474                 pmic->desc[id].name = palmas_regs_info[id].name;
1475                 pmic->desc[id].id = id;
1476
1477                 switch (id) {
1478                 case PALMAS_REG_SMPS10_OUT1:
1479                 case PALMAS_REG_SMPS10_OUT2:
1480                         pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
1481                         pmic->desc[id].ops = &palmas_ops_smps10;
1482                         pmic->desc[id].vsel_reg =
1483                                         PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1484                                                         PALMAS_SMPS10_CTRL);
1485                         pmic->desc[id].vsel_mask = SMPS10_VSEL;
1486                         pmic->desc[id].enable_reg =
1487                                         PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1488                                                         PALMAS_SMPS10_CTRL);
1489                         if (id == PALMAS_REG_SMPS10_OUT1)
1490                                 pmic->desc[id].enable_mask = SMPS10_SWITCH_EN;
1491                         else
1492                                 pmic->desc[id].enable_mask = SMPS10_BOOST_EN;
1493                         pmic->desc[id].bypass_reg =
1494                                         PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1495                                                         PALMAS_SMPS10_CTRL);
1496                         pmic->desc[id].bypass_mask = SMPS10_BYPASS_EN;
1497                         pmic->desc[id].min_uV = 3750000;
1498                         pmic->desc[id].uV_step = 1250000;
1499                         break;
1500                 default:
1501                         /*
1502                          * Read and store the RANGE bit for later use
1503                          * This must be done before regulator is probed,
1504                          * otherwise we error in probe with unsupportable
1505                          * ranges. Read the current smps mode for later use.
1506                          */
1507                         addr = palmas_regs_info[id].vsel_addr;
1508
1509                         ret = palmas_smps_read(pmic->palmas, addr, &reg);
1510                         if (ret)
1511                                 goto err_unregister_regulator;
1512                         if (reg & PALMAS_SMPS12_VOLTAGE_RANGE)
1513                                 pmic->range[id] = 1;
1514
1515                         if (roof_floor)
1516                                 pmic->desc[id].ops = &palmas_ops_smps_extctrl;
1517                         else
1518                                 pmic->desc[id].ops = &palmas_ops_smps;
1519                         pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
1520                         pmic->desc[id].vsel_reg =
1521                                         PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1522                                                 palmas_regs_info[id].vsel_addr);
1523                         pmic->desc[id].vsel_mask =
1524                                         PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
1525
1526                         /* Read the smps mode for later use. */
1527                         addr = palmas_regs_info[id].ctrl_addr;
1528                         ret = palmas_smps_read(pmic->palmas, addr, &reg);
1529                         if (ret)
1530                                 goto err_unregister_regulator;
1531                         pmic->current_reg_mode[id] = reg &
1532                                         PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
1533                         break;
1534                 }
1535
1536                 pmic->desc[id].type = REGULATOR_VOLTAGE;
1537                 pmic->desc[id].owner = THIS_MODULE;
1538                 pmic->desc[id].supply_name = palmas_regs_info[id].sname;
1539
1540                 if (pdata)
1541                         config.init_data = pdata->reg_data[id];
1542                 else
1543                         config.init_data = NULL;
1544
1545                 pmic->desc[id].supply_name = palmas_regs_info[id].sname;
1546                 config.of_node = palmas_matches[id].of_node;
1547                 if (roof_floor & EXT_PWR_REQ) {
1548                         config.ena_gpio = reg_init->enable_gpio;
1549                         config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
1550                 } else {
1551                         config.ena_gpio = -EINVAL;
1552                         config.ena_gpio_flags = 0;
1553                 }
1554
1555                 rdev = regulator_register(&pmic->desc[id], &config);
1556                 if (IS_ERR(rdev)) {
1557                         dev_err(&pdev->dev,
1558                                 "failed to register %s regulator\n",
1559                                 pdev->name);
1560                         ret = PTR_ERR(rdev);
1561                         goto err_unregister_regulator;
1562                 }
1563
1564                 /* Save regulator for cleanup */
1565                 pmic->rdev[id] = rdev;
1566
1567                 /* Initialise sleep/init values from platform data */
1568                 if (reg_init) {
1569                         pmic->config_flags[id] = reg_init->config_flags;
1570                         ret = palmas_smps_init(rdev, palmas, id, reg_init);
1571                         if (ret)
1572                                 goto err_unregister_regulator;
1573                 }
1574         }
1575
1576         /* Start this loop from the id left from previous loop */
1577         for (; id < PALMAS_NUM_REGS; id++) {
1578
1579                 if (palmas->id != TPS80036) {
1580                         if (id > PALMAS_REG_LDO9 && id < PALMAS_REG_LDOLN)
1581                                 continue;
1582                         if (id > PALMAS_REG_REGEN3 && id < PALMAS_REG_SYSEN1)
1583                                 continue;
1584                 } else {
1585                         if (id == PALMAS_REG_REGEN3)
1586                                 continue;
1587                 }
1588
1589                 reg_init = pdata->reg_init[id];
1590                 roof_floor = 0;
1591                 if (reg_init)
1592                         roof_floor = reg_init->roof_floor;
1593
1594                 /* Miss out regulators which are not available due
1595                  * to alternate functions.
1596                  */
1597
1598                 /* Register the regulators */
1599                 pmic->desc[id].name = palmas_regs_info[id].name;
1600                 pmic->desc[id].id = id;
1601                 pmic->desc[id].type = REGULATOR_VOLTAGE;
1602                 pmic->desc[id].owner = THIS_MODULE;
1603                 pmic->desc[id].supply_name = palmas_regs_info[id].sname;
1604
1605                 if (id < PALMAS_REG_REGEN1) {
1606                         pmic->desc[id].n_voltages = PALMAS_LDO_NUM_VOLTAGES;
1607                         if (roof_floor)
1608                                 pmic->desc[id].ops = &palmas_ops_ldo_extctrl;
1609                         else
1610                                 pmic->desc[id].ops = &palmas_ops_ldo;
1611                         pmic->desc[id].vsel_reg =
1612                                         PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
1613                                                 palmas_regs_info[id].vsel_addr);
1614                         pmic->desc[id].vsel_mask =
1615                                         PALMAS_LDO1_VOLTAGE_VSEL_MASK;
1616                         pmic->desc[id].enable_reg =
1617                                         PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
1618                                                 palmas_regs_info[id].ctrl_addr);
1619                         pmic->desc[id].enable_mask =
1620                                         PALMAS_LDO1_CTRL_MODE_ACTIVE;
1621
1622                         /* Check if LDO8 is in tracking mode or not */
1623                         if (pdata && (id == PALMAS_REG_LDO8) &&
1624                                         (pdata->reg_init[id]->config_flags &
1625                                         PALMAS_REGULATOR_CONFIG_TRACKING_ENABLE)) {
1626                                 pmic->desc[id].min_uV = 450000;
1627                                 pmic->desc[id].uV_step = 25000;
1628                         }
1629                 } else if (id == PALMAS_REG_CHARGER_PUMP) {
1630                         pmic->desc[id].enable_reg =
1631                                         palmas_regs_info[id].ctrl_addr;
1632                         pmic->desc[id].enable_mask =
1633                                         PALMAS_CHARGE_PUMP_CTRL_MODE_ACTIVE;
1634                         pmic->desc[id].ops = &palmas_ops_chargepump;
1635                 } else {
1636                         pmic->desc[id].n_voltages = 1;
1637                         if (roof_floor)
1638                                 pmic->desc[id].ops = &palmas_ops_extreg_extctrl;
1639                         else
1640                                 pmic->desc[id].ops = &palmas_ops_extreg;
1641                         pmic->desc[id].enable_reg =
1642                                         PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE,
1643                                                 palmas_regs_info[id].ctrl_addr);
1644                         pmic->desc[id].enable_mask =
1645                                         PALMAS_REGEN1_CTRL_MODE_ACTIVE;
1646                 }
1647
1648                 if (pdata)
1649                         config.init_data = pdata->reg_data[id];
1650                 else
1651                         config.init_data = NULL;
1652
1653                 pmic->desc[id].supply_name = palmas_regs_info[id].sname;
1654                 config.of_node = palmas_matches[id].of_node;
1655                 if (roof_floor) {
1656                         config.ena_gpio = reg_init->enable_gpio;
1657                         config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
1658                 }
1659
1660                 rdev = regulator_register(&pmic->desc[id], &config);
1661                 if (IS_ERR(rdev)) {
1662                         dev_err(&pdev->dev,
1663                                 "failed to register %s regulator\n",
1664                                 pdev->name);
1665                         ret = PTR_ERR(rdev);
1666                         goto err_unregister_regulator;
1667                 }
1668
1669                 /* Save regulator for cleanup */
1670                 pmic->rdev[id] = rdev;
1671
1672                 /* Initialise sleep/init values from platform data */
1673                 if (pdata && reg_init && (id != PALMAS_REG_CHARGER_PUMP)) {
1674                         pmic->config_flags[id] = reg_init->config_flags;
1675                         if (id < PALMAS_REG_REGEN1)
1676                                 ret = palmas_ldo_init(rdev, palmas, id,
1677                                                         reg_init);
1678                         else
1679                                 ret = palmas_extreg_init(rdev, palmas,
1680                                                 id, reg_init);
1681                         if (ret) {
1682                                 regulator_unregister(pmic->rdev[id]);
1683                                 goto err_unregister_regulator;
1684                         }
1685                 }
1686         }
1687
1688         palmas_dvfs_init(palmas, pdata);
1689         return 0;
1690
1691 err_unregister_regulator:
1692         while (--id >= 0)
1693                 regulator_unregister(pmic->rdev[id]);
1694         return ret;
1695 }
1696
1697 static int palmas_regulators_remove(struct platform_device *pdev)
1698 {
1699         struct palmas_pmic *pmic = platform_get_drvdata(pdev);
1700         int id;
1701
1702         for (id = 0; id < PALMAS_NUM_REGS; id++)
1703                 regulator_unregister(pmic->rdev[id]);
1704         return 0;
1705 }
1706
1707 static struct of_device_id of_palmas_match_tbl[] = {
1708         { .compatible = "ti,palmas-pmic", },
1709         { .compatible = "ti,twl6035-pmic", },
1710         { .compatible = "ti,twl6036-pmic", },
1711         { .compatible = "ti,twl6037-pmic", },
1712         { .compatible = "ti,tps65913-pmic", },
1713         { .compatible = "ti,tps65914-pmic", },
1714         { .compatible = "ti,tps80036-pmic", },
1715         { .compatible = "ti,tps659038-pmic", },
1716         { /* end */ }
1717 };
1718
1719 #ifdef CONFIG_PM_SLEEP
1720 static int palmas_suspend(struct device *dev)
1721 {
1722         struct palmas *palmas = dev_get_drvdata(dev->parent);
1723         struct palmas_pmic *pmic = dev_get_drvdata(dev);
1724         int id;
1725
1726         for (id = 0; id < PALMAS_NUM_REGS; id++) {
1727                 unsigned int cf = pmic->config_flags[id];
1728
1729                 if ((cf & PALMAS_REGULATOR_CONFIG_SUSPEND_TRACKING_DISABLE) &&
1730                         (cf & PALMAS_REGULATOR_CONFIG_TRACKING_ENABLE)) {
1731                         if (id == PALMAS_REG_LDO8)
1732                                 palmas_disable_ldo8_track(palmas);
1733                 }
1734
1735                 if (pmic->config_flags[id] &
1736                         PALMAS_REGULATOR_CONFIG_SUSPEND_FORCE_OFF) {
1737                         if (pmic->desc[id].ops->disable)
1738                                 pmic->desc[id].ops->disable(pmic->rdev[id]);
1739                 }
1740         }
1741         return 0;
1742 }
1743
1744 static int palmas_resume(struct device *dev)
1745 {
1746         struct palmas *palmas = dev_get_drvdata(dev->parent);
1747         struct palmas_pmic *pmic = dev_get_drvdata(dev);
1748         int id;
1749
1750         for (id = 0; id < PALMAS_NUM_REGS; id++) {
1751                 unsigned int cf = pmic->config_flags[id];
1752
1753                 if ((cf & PALMAS_REGULATOR_CONFIG_SUSPEND_TRACKING_DISABLE) &&
1754                         (cf & PALMAS_REGULATOR_CONFIG_TRACKING_ENABLE)) {
1755                         if (id == PALMAS_REG_LDO8)
1756                                 palmas_enable_ldo8_track(palmas);
1757                 }
1758
1759                 if (pmic->config_flags[id] &
1760                         PALMAS_REGULATOR_CONFIG_SUSPEND_FORCE_OFF) {
1761                         if (pmic->desc[id].ops->enable)
1762                                 pmic->desc[id].ops->enable(pmic->rdev[id]);
1763                 }
1764         }
1765         return 0;
1766 }
1767 #endif
1768 static const struct dev_pm_ops palmas_pm_ops = {
1769         SET_SYSTEM_SLEEP_PM_OPS(palmas_suspend, palmas_resume)
1770 };
1771
1772 static struct platform_driver palmas_driver = {
1773         .driver = {
1774                 .name = "palmas-pmic",
1775                 .of_match_table = of_palmas_match_tbl,
1776                 .owner = THIS_MODULE,
1777                 .pm     = &palmas_pm_ops,
1778         },
1779         .probe = palmas_regulators_probe,
1780         .remove = palmas_regulators_remove,
1781 };
1782
1783 static int __init palmas_init(void)
1784 {
1785         return platform_driver_register(&palmas_driver);
1786 }
1787 subsys_initcall(palmas_init);
1788
1789 static void __exit palmas_exit(void)
1790 {
1791         platform_driver_unregister(&palmas_driver);
1792 }
1793 module_exit(palmas_exit);
1794
1795 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1796 MODULE_DESCRIPTION("Palmas voltage regulator driver");
1797 MODULE_LICENSE("GPL");
1798 MODULE_ALIAS("platform:palmas-pmic");
1799 MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);