UPSTREAM: regulator: rk808: remove unused rk808_reg_ops_ranges
[firefly-linux-kernel-4.4.55.git] / drivers / regulator / rk808-regulator.c
1 /*
2  * Regulator driver for Rockchip RK808
3  *
4  * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
5  *
6  * Author: Chris Zhong <zyw@rock-chips.com>
7  * Author: Zhang Qing <zhangqing@rock-chips.com>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms and conditions of the GNU General Public License,
11  * version 2, as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  * more details.
17  */
18
19 #include <linux/delay.h>
20 #include <linux/gpio.h>
21 #include <linux/i2c.h>
22 #include <linux/module.h>
23 #include <linux/of_device.h>
24 #include <linux/of_gpio.h>
25 #include <linux/mfd/rk808.h>
26 #include <linux/regulator/driver.h>
27 #include <linux/regulator/of_regulator.h>
28 #include <linux/gpio/consumer.h>
29
30 /* Field Definitions */
31 #define RK808_BUCK_VSEL_MASK    0x3f
32 #define RK808_BUCK4_VSEL_MASK   0xf
33 #define RK808_LDO_VSEL_MASK     0x1f
34
35 /* Ramp rate definitions for buck1 / buck2 only */
36 #define RK808_RAMP_RATE_OFFSET          3
37 #define RK808_RAMP_RATE_MASK            (3 << RK808_RAMP_RATE_OFFSET)
38 #define RK808_RAMP_RATE_2MV_PER_US      (0 << RK808_RAMP_RATE_OFFSET)
39 #define RK808_RAMP_RATE_4MV_PER_US      (1 << RK808_RAMP_RATE_OFFSET)
40 #define RK808_RAMP_RATE_6MV_PER_US      (2 << RK808_RAMP_RATE_OFFSET)
41 #define RK808_RAMP_RATE_10MV_PER_US     (3 << RK808_RAMP_RATE_OFFSET)
42
43 #define RK808_DVS2_POL          BIT(2)
44 #define RK808_DVS1_POL          BIT(1)
45
46 /* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */
47 #define RK808_SLP_REG_OFFSET 1
48
49 /* Offset from XXX_ON_VSEL to XXX_DVS_VSEL */
50 #define RK808_DVS_REG_OFFSET 2
51
52 /* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */
53 #define RK808_SLP_SET_OFF_REG_OFFSET 2
54
55 /* max steps for increase voltage of Buck1/2, equal 100mv*/
56 #define MAX_STEPS_ONE_TIME 8
57
58 struct rk808_regulator_data {
59         struct gpio_desc *dvs_gpio[2];
60 };
61
62 static const int rk808_buck_config_regs[] = {
63         RK808_BUCK1_CONFIG_REG,
64         RK808_BUCK2_CONFIG_REG,
65         RK808_BUCK3_CONFIG_REG,
66         RK808_BUCK4_CONFIG_REG,
67 };
68
69 static const struct regulator_linear_range rk808_ldo3_voltage_ranges[] = {
70         REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000),
71         REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0),
72 };
73
74 static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev)
75 {
76         struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
77         int id = rdev->desc->id - RK808_ID_DCDC1;
78         struct gpio_desc *gpio = pdata->dvs_gpio[id];
79         unsigned int val;
80         int ret;
81
82         if (!gpio || gpiod_get_value(gpio) == 0)
83                 return regulator_get_voltage_sel_regmap(rdev);
84
85         ret = regmap_read(rdev->regmap,
86                           rdev->desc->vsel_reg + RK808_DVS_REG_OFFSET,
87                           &val);
88         if (ret != 0)
89                 return ret;
90
91         val &= rdev->desc->vsel_mask;
92         val >>= ffs(rdev->desc->vsel_mask) - 1;
93
94         return val;
95 }
96
97 static int rk808_buck1_2_i2c_set_voltage_sel(struct regulator_dev *rdev,
98                                              unsigned sel)
99 {
100         int ret, delta_sel;
101         unsigned int old_sel, tmp, val, mask = rdev->desc->vsel_mask;
102
103         ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
104         if (ret != 0)
105                 return ret;
106
107         tmp = val & ~mask;
108         old_sel = val & mask;
109         old_sel >>= ffs(mask) - 1;
110         delta_sel = sel - old_sel;
111
112         /*
113          * If directly modify the register to change the voltage, we will face
114          * the risk of overshoot. Put it into a multi-step, can effectively
115          * avoid this problem, a step is 100mv here.
116          */
117         while (delta_sel > MAX_STEPS_ONE_TIME) {
118                 old_sel += MAX_STEPS_ONE_TIME;
119                 val = old_sel << (ffs(mask) - 1);
120                 val |= tmp;
121
122                 /*
123                  * i2c is 400kHz (2.5us per bit) and we must transmit _at least_
124                  * 3 bytes (24 bits) plus start and stop so 26 bits.  So we've
125                  * got more than 65 us between each voltage change and thus
126                  * won't ramp faster than ~1500 uV / us.
127                  */
128                 ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val);
129                 delta_sel = sel - old_sel;
130         }
131
132         sel <<= ffs(mask) - 1;
133         val = tmp | sel;
134         ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val);
135
136         /*
137          * When we change the voltage register directly, the ramp rate is about
138          * 100000uv/us, wait 1us to make sure the target voltage to be stable,
139          * so we needn't wait extra time after that.
140          */
141         udelay(1);
142
143         return ret;
144 }
145
146 static int rk808_buck1_2_set_voltage_sel(struct regulator_dev *rdev,
147                                          unsigned sel)
148 {
149         struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
150         int id = rdev->desc->id - RK808_ID_DCDC1;
151         struct gpio_desc *gpio = pdata->dvs_gpio[id];
152         unsigned int reg = rdev->desc->vsel_reg;
153         unsigned old_sel;
154         int ret, gpio_level;
155
156         if (!gpio)
157                 return rk808_buck1_2_i2c_set_voltage_sel(rdev, sel);
158
159         gpio_level = gpiod_get_value(gpio);
160         if (gpio_level == 0) {
161                 reg += RK808_DVS_REG_OFFSET;
162                 ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &old_sel);
163         } else {
164                 ret = regmap_read(rdev->regmap,
165                                   reg + RK808_DVS_REG_OFFSET,
166                                   &old_sel);
167         }
168
169         if (ret != 0)
170                 return ret;
171
172         sel <<= ffs(rdev->desc->vsel_mask) - 1;
173         sel |= old_sel & ~rdev->desc->vsel_mask;
174
175         ret = regmap_write(rdev->regmap, reg, sel);
176         if (ret)
177                 return ret;
178
179         gpiod_set_value(gpio, !gpio_level);
180
181         return ret;
182 }
183
184 static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev,
185                                        unsigned int old_selector,
186                                        unsigned int new_selector)
187 {
188         struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
189         int id = rdev->desc->id - RK808_ID_DCDC1;
190         struct gpio_desc *gpio = pdata->dvs_gpio[id];
191
192         /* if there is no dvs1/2 pin, we don't need wait extra time here. */
193         if (!gpio)
194                 return 0;
195
196         return regulator_set_voltage_time_sel(rdev, old_selector, new_selector);
197 }
198
199 static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
200 {
201         unsigned int ramp_value = RK808_RAMP_RATE_10MV_PER_US;
202         unsigned int reg = rk808_buck_config_regs[rdev->desc->id -
203                                                   RK808_ID_DCDC1];
204
205         switch (ramp_delay) {
206         case 1 ... 2000:
207                 ramp_value = RK808_RAMP_RATE_2MV_PER_US;
208                 break;
209         case 2001 ... 4000:
210                 ramp_value = RK808_RAMP_RATE_4MV_PER_US;
211                 break;
212         case 4001 ... 6000:
213                 ramp_value = RK808_RAMP_RATE_6MV_PER_US;
214                 break;
215         case 6001 ... 10000:
216                 break;
217         default:
218                 pr_warn("%s ramp_delay: %d not supported, setting 10000\n",
219                         rdev->desc->name, ramp_delay);
220         }
221
222         return regmap_update_bits(rdev->regmap, reg,
223                                   RK808_RAMP_RATE_MASK, ramp_value);
224 }
225
226 static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
227 {
228         unsigned int reg;
229         int sel = regulator_map_voltage_linear(rdev, uv, uv);
230
231         if (sel < 0)
232                 return -EINVAL;
233
234         reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
235
236         return regmap_update_bits(rdev->regmap, reg,
237                                   rdev->desc->vsel_mask,
238                                   sel);
239 }
240
241 static int rk808_set_suspend_enable(struct regulator_dev *rdev)
242 {
243         unsigned int reg;
244
245         reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
246
247         return regmap_update_bits(rdev->regmap, reg,
248                                   rdev->desc->enable_mask,
249                                   0);
250 }
251
252 static int rk808_set_suspend_disable(struct regulator_dev *rdev)
253 {
254         unsigned int reg;
255
256         reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
257
258         return regmap_update_bits(rdev->regmap, reg,
259                                   rdev->desc->enable_mask,
260                                   rdev->desc->enable_mask);
261 }
262
263 static struct regulator_ops rk808_buck1_2_ops = {
264         .list_voltage           = regulator_list_voltage_linear,
265         .map_voltage            = regulator_map_voltage_linear,
266         .get_voltage_sel        = rk808_buck1_2_get_voltage_sel_regmap,
267         .set_voltage_sel        = rk808_buck1_2_set_voltage_sel,
268         .set_voltage_time_sel   = rk808_buck1_2_set_voltage_time_sel,
269         .enable                 = regulator_enable_regmap,
270         .disable                = regulator_disable_regmap,
271         .is_enabled             = regulator_is_enabled_regmap,
272         .set_ramp_delay         = rk808_set_ramp_delay,
273         .set_suspend_voltage    = rk808_set_suspend_voltage,
274         .set_suspend_enable     = rk808_set_suspend_enable,
275         .set_suspend_disable    = rk808_set_suspend_disable,
276 };
277
278 static struct regulator_ops rk808_reg_ops = {
279         .list_voltage           = regulator_list_voltage_linear,
280         .map_voltage            = regulator_map_voltage_linear,
281         .get_voltage_sel        = regulator_get_voltage_sel_regmap,
282         .set_voltage_sel        = regulator_set_voltage_sel_regmap,
283         .enable                 = regulator_enable_regmap,
284         .disable                = regulator_disable_regmap,
285         .is_enabled             = regulator_is_enabled_regmap,
286         .set_suspend_voltage    = rk808_set_suspend_voltage,
287         .set_suspend_enable     = rk808_set_suspend_enable,
288         .set_suspend_disable    = rk808_set_suspend_disable,
289 };
290
291 static struct regulator_ops rk808_switch_ops = {
292         .enable                 = regulator_enable_regmap,
293         .disable                = regulator_disable_regmap,
294         .is_enabled             = regulator_is_enabled_regmap,
295         .set_suspend_enable     = rk808_set_suspend_enable,
296         .set_suspend_disable    = rk808_set_suspend_disable,
297 };
298
299 static const struct regulator_desc rk808_reg[] = {
300         {
301                 .name = "DCDC_REG1",
302                 .supply_name = "vcc1",
303                 .id = RK808_ID_DCDC1,
304                 .ops = &rk808_buck1_2_ops,
305                 .type = REGULATOR_VOLTAGE,
306                 .min_uV = 712500,
307                 .uV_step = 12500,
308                 .n_voltages = 64,
309                 .vsel_reg = RK808_BUCK1_ON_VSEL_REG,
310                 .vsel_mask = RK808_BUCK_VSEL_MASK,
311                 .enable_reg = RK808_DCDC_EN_REG,
312                 .enable_mask = BIT(0),
313                 .owner = THIS_MODULE,
314         }, {
315                 .name = "DCDC_REG2",
316                 .supply_name = "vcc2",
317                 .id = RK808_ID_DCDC2,
318                 .ops = &rk808_buck1_2_ops,
319                 .type = REGULATOR_VOLTAGE,
320                 .min_uV = 712500,
321                 .uV_step = 12500,
322                 .n_voltages = 64,
323                 .vsel_reg = RK808_BUCK2_ON_VSEL_REG,
324                 .vsel_mask = RK808_BUCK_VSEL_MASK,
325                 .enable_reg = RK808_DCDC_EN_REG,
326                 .enable_mask = BIT(1),
327                 .owner = THIS_MODULE,
328         }, {
329                 .name = "DCDC_REG3",
330                 .supply_name = "vcc3",
331                 .id = RK808_ID_DCDC3,
332                 .ops = &rk808_switch_ops,
333                 .type = REGULATOR_VOLTAGE,
334                 .n_voltages = 1,
335                 .enable_reg = RK808_DCDC_EN_REG,
336                 .enable_mask = BIT(2),
337                 .owner = THIS_MODULE,
338         }, {
339                 .name = "DCDC_REG4",
340                 .supply_name = "vcc4",
341                 .id = RK808_ID_DCDC4,
342                 .ops = &rk808_reg_ops,
343                 .type = REGULATOR_VOLTAGE,
344                 .min_uV = 1800000,
345                 .uV_step = 100000,
346                 .n_voltages = 16,
347                 .vsel_reg = RK808_BUCK4_ON_VSEL_REG,
348                 .vsel_mask = RK808_BUCK4_VSEL_MASK,
349                 .enable_reg = RK808_DCDC_EN_REG,
350                 .enable_mask = BIT(3),
351                 .owner = THIS_MODULE,
352         }, {
353                 .name = "LDO_REG1",
354                 .supply_name = "vcc6",
355                 .id = RK808_ID_LDO1,
356                 .ops = &rk808_reg_ops,
357                 .type = REGULATOR_VOLTAGE,
358                 .min_uV = 1800000,
359                 .uV_step = 100000,
360                 .n_voltages = 17,
361                 .vsel_reg = RK808_LDO1_ON_VSEL_REG,
362                 .vsel_mask = RK808_LDO_VSEL_MASK,
363                 .enable_reg = RK808_LDO_EN_REG,
364                 .enable_mask = BIT(0),
365                 .enable_time = 400,
366                 .owner = THIS_MODULE,
367         }, {
368                 .name = "LDO_REG2",
369                 .supply_name = "vcc6",
370                 .id = RK808_ID_LDO2,
371                 .ops = &rk808_reg_ops,
372                 .type = REGULATOR_VOLTAGE,
373                 .min_uV = 1800000,
374                 .uV_step = 100000,
375                 .n_voltages = 17,
376                 .vsel_reg = RK808_LDO2_ON_VSEL_REG,
377                 .vsel_mask = RK808_LDO_VSEL_MASK,
378                 .enable_reg = RK808_LDO_EN_REG,
379                 .enable_mask = BIT(1),
380                 .enable_time = 400,
381                 .owner = THIS_MODULE,
382         }, {
383                 .name = "LDO_REG3",
384                 .supply_name = "vcc7",
385                 .id = RK808_ID_LDO3,
386                 .ops = &rk808_reg_ops,
387                 .type = REGULATOR_VOLTAGE,
388                 .n_voltages = 16,
389                 .linear_ranges = rk808_ldo3_voltage_ranges,
390                 .n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges),
391                 .vsel_reg = RK808_LDO3_ON_VSEL_REG,
392                 .vsel_mask = RK808_BUCK4_VSEL_MASK,
393                 .enable_reg = RK808_LDO_EN_REG,
394                 .enable_mask = BIT(2),
395                 .enable_time = 400,
396                 .owner = THIS_MODULE,
397         }, {
398                 .name = "LDO_REG4",
399                 .supply_name = "vcc9",
400                 .id = RK808_ID_LDO4,
401                 .ops = &rk808_reg_ops,
402                 .type = REGULATOR_VOLTAGE,
403                 .min_uV = 1800000,
404                 .uV_step = 100000,
405                 .n_voltages = 17,
406                 .vsel_reg = RK808_LDO4_ON_VSEL_REG,
407                 .vsel_mask = RK808_LDO_VSEL_MASK,
408                 .enable_reg = RK808_LDO_EN_REG,
409                 .enable_mask = BIT(3),
410                 .enable_time = 400,
411                 .owner = THIS_MODULE,
412         }, {
413                 .name = "LDO_REG5",
414                 .supply_name = "vcc9",
415                 .id = RK808_ID_LDO5,
416                 .ops = &rk808_reg_ops,
417                 .type = REGULATOR_VOLTAGE,
418                 .min_uV = 1800000,
419                 .uV_step = 100000,
420                 .n_voltages = 17,
421                 .vsel_reg = RK808_LDO5_ON_VSEL_REG,
422                 .vsel_mask = RK808_LDO_VSEL_MASK,
423                 .enable_reg = RK808_LDO_EN_REG,
424                 .enable_mask = BIT(4),
425                 .enable_time = 400,
426                 .owner = THIS_MODULE,
427         }, {
428                 .name = "LDO_REG6",
429                 .supply_name = "vcc10",
430                 .id = RK808_ID_LDO6,
431                 .ops = &rk808_reg_ops,
432                 .type = REGULATOR_VOLTAGE,
433                 .min_uV = 800000,
434                 .uV_step = 100000,
435                 .n_voltages = 18,
436                 .vsel_reg = RK808_LDO6_ON_VSEL_REG,
437                 .vsel_mask = RK808_LDO_VSEL_MASK,
438                 .enable_reg = RK808_LDO_EN_REG,
439                 .enable_mask = BIT(5),
440                 .enable_time = 400,
441                 .owner = THIS_MODULE,
442         }, {
443                 .name = "LDO_REG7",
444                 .supply_name = "vcc7",
445                 .id = RK808_ID_LDO7,
446                 .ops = &rk808_reg_ops,
447                 .type = REGULATOR_VOLTAGE,
448                 .min_uV = 800000,
449                 .uV_step = 100000,
450                 .n_voltages = 18,
451                 .vsel_reg = RK808_LDO7_ON_VSEL_REG,
452                 .vsel_mask = RK808_LDO_VSEL_MASK,
453                 .enable_reg = RK808_LDO_EN_REG,
454                 .enable_mask = BIT(6),
455                 .enable_time = 400,
456                 .owner = THIS_MODULE,
457         }, {
458                 .name = "LDO_REG8",
459                 .supply_name = "vcc11",
460                 .id = RK808_ID_LDO8,
461                 .ops = &rk808_reg_ops,
462                 .type = REGULATOR_VOLTAGE,
463                 .min_uV = 1800000,
464                 .uV_step = 100000,
465                 .n_voltages = 17,
466                 .vsel_reg = RK808_LDO8_ON_VSEL_REG,
467                 .vsel_mask = RK808_LDO_VSEL_MASK,
468                 .enable_reg = RK808_LDO_EN_REG,
469                 .enable_mask = BIT(7),
470                 .enable_time = 400,
471                 .owner = THIS_MODULE,
472         }, {
473                 .name = "SWITCH_REG1",
474                 .supply_name = "vcc8",
475                 .id = RK808_ID_SWITCH1,
476                 .ops = &rk808_switch_ops,
477                 .type = REGULATOR_VOLTAGE,
478                 .enable_reg = RK808_DCDC_EN_REG,
479                 .enable_mask = BIT(5),
480                 .owner = THIS_MODULE,
481         }, {
482                 .name = "SWITCH_REG2",
483                 .supply_name = "vcc12",
484                 .id = RK808_ID_SWITCH2,
485                 .ops = &rk808_switch_ops,
486                 .type = REGULATOR_VOLTAGE,
487                 .enable_reg = RK808_DCDC_EN_REG,
488                 .enable_mask = BIT(6),
489                 .owner = THIS_MODULE,
490         },
491 };
492
493 static struct of_regulator_match rk808_reg_matches[] = {
494         [RK808_ID_DCDC1]        = { .name = "DCDC_REG1" },
495         [RK808_ID_DCDC2]        = { .name = "DCDC_REG2" },
496         [RK808_ID_DCDC3]        = { .name = "DCDC_REG3" },
497         [RK808_ID_DCDC4]        = { .name = "DCDC_REG4" },
498         [RK808_ID_LDO1]         = { .name = "LDO_REG1" },
499         [RK808_ID_LDO2]         = { .name = "LDO_REG2" },
500         [RK808_ID_LDO3]         = { .name = "LDO_REG3" },
501         [RK808_ID_LDO4]         = { .name = "LDO_REG4" },
502         [RK808_ID_LDO5]         = { .name = "LDO_REG5" },
503         [RK808_ID_LDO6]         = { .name = "LDO_REG6" },
504         [RK808_ID_LDO7]         = { .name = "LDO_REG7" },
505         [RK808_ID_LDO8]         = { .name = "LDO_REG8" },
506         [RK808_ID_SWITCH1]      = { .name = "SWITCH_REG1" },
507         [RK808_ID_SWITCH2]      = { .name = "SWITCH_REG2" },
508 };
509
510 static int rk808_regulator_dt_parse_pdata(struct device *dev,
511                                    struct device *client_dev,
512                                    struct regmap *map,
513                                    struct rk808_regulator_data *pdata)
514 {
515         struct device_node *np;
516         int tmp, ret, i;
517
518         np = of_get_child_by_name(client_dev->of_node, "regulators");
519         if (!np)
520                 return -ENXIO;
521
522         ret = of_regulator_match(dev, np, rk808_reg_matches,
523                                  RK808_NUM_REGULATORS);
524         if (ret < 0)
525                 goto dt_parse_end;
526
527         for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) {
528                 pdata->dvs_gpio[i] =
529                         devm_gpiod_get_index_optional(client_dev, "dvs", i,
530                                                       GPIOD_OUT_LOW);
531                 if (IS_ERR(pdata->dvs_gpio[i])) {
532                         ret = PTR_ERR(pdata->dvs_gpio[i]);
533                         dev_err(dev, "failed to get dvs%d gpio (%d)\n", i, ret);
534                         goto dt_parse_end;
535                 }
536
537                 if (!pdata->dvs_gpio[i]) {
538                         dev_warn(dev, "there is no dvs%d gpio\n", i);
539                         continue;
540                 }
541
542                 tmp = i ? RK808_DVS2_POL : RK808_DVS1_POL;
543                 ret = regmap_update_bits(map, RK808_IO_POL_REG, tmp,
544                                 gpiod_is_active_low(pdata->dvs_gpio[i]) ?
545                                 0 : tmp);
546         }
547
548 dt_parse_end:
549         of_node_put(np);
550         return ret;
551 }
552
553 static int rk808_regulator_probe(struct platform_device *pdev)
554 {
555         struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
556         struct i2c_client *client = rk808->i2c;
557         struct regulator_config config = {};
558         struct regulator_dev *rk808_rdev;
559         struct rk808_regulator_data *pdata;
560         int ret, i;
561
562         pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
563         if (!pdata)
564                 return -ENOMEM;
565
566         ret = rk808_regulator_dt_parse_pdata(&pdev->dev, &client->dev,
567                                              rk808->regmap, pdata);
568         if (ret < 0)
569                 return ret;
570
571         platform_set_drvdata(pdev, pdata);
572
573         /* Instantiate the regulators */
574         for (i = 0; i < RK808_NUM_REGULATORS; i++) {
575                 if (!rk808_reg_matches[i].init_data ||
576                     !rk808_reg_matches[i].of_node)
577                         continue;
578
579                 config.dev = &client->dev;
580                 config.driver_data = pdata;
581                 config.regmap = rk808->regmap;
582                 config.of_node = rk808_reg_matches[i].of_node;
583                 config.init_data = rk808_reg_matches[i].init_data;
584
585                 rk808_rdev = devm_regulator_register(&pdev->dev,
586                                                      &rk808_reg[i], &config);
587                 if (IS_ERR(rk808_rdev)) {
588                         dev_err(&client->dev,
589                                 "failed to register %d regulator\n", i);
590                         return PTR_ERR(rk808_rdev);
591                 }
592         }
593
594         return 0;
595 }
596
597 static struct platform_driver rk808_regulator_driver = {
598         .probe = rk808_regulator_probe,
599         .driver = {
600                 .name = "rk808-regulator",
601                 .owner = THIS_MODULE,
602         },
603 };
604
605 module_platform_driver(rk808_regulator_driver);
606
607 MODULE_DESCRIPTION("regulator driver for the rk808 series PMICs");
608 MODULE_AUTHOR("Chris Zhong<zyw@rock-chips.com>");
609 MODULE_AUTHOR("Zhang Qing<zhangqing@rock-chips.com>");
610 MODULE_LICENSE("GPL");
611 MODULE_ALIAS("platform:rk808-regulator");