imx6: update 3.10 patches
[openwrt.git] / target / linux / imx6 / patches-3.10 / 0019-regulator-pfuze100-add-pfuze100-regulator-driver.patch
1 From 3784b6d64dc52ed3fbebad61a85ab9b7a687a167 Mon Sep 17 00:00:00 2001
2 From: Robin Gong <b38343@freescale.com>
3 Date: Thu, 25 Jul 2013 11:33:18 +0800
4 Subject: [PATCH] regulator: pfuze100: add pfuze100 regulator driver
5
6 Add pfuze100 regulator driver.
7
8 Signed-off-by: Robin Gong <b38343@freescale.com>
9 Tested-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
10 Signed-off-by: Mark Brown <broonie@linaro.org>
11 ---
12  .../devicetree/bindings/regulator/pfuze100.txt     | 113 +++++
13  drivers/regulator/Kconfig                          |   7 +
14  drivers/regulator/Makefile                         |   1 +
15  drivers/regulator/pfuze100-regulator.c             | 454 +++++++++++++++++++++
16  include/linux/regulator/pfuze100.h                 |  44 ++
17  5 files changed, 619 insertions(+)
18  create mode 100644 Documentation/devicetree/bindings/regulator/pfuze100.txt
19  create mode 100644 drivers/regulator/pfuze100-regulator.c
20  create mode 100644 include/linux/regulator/pfuze100.h
21
22 --- /dev/null
23 +++ b/Documentation/devicetree/bindings/regulator/pfuze100.txt
24 @@ -0,0 +1,113 @@
25 +PFUZE100 family of regulators
26 +
27 +Required properties:
28 +- compatible: "fsl,pfuze100"
29 +- reg: I2C slave address
30 +- regulators: This is the list of child nodes that specify the regulator
31 +  initialization data for defined regulators. Please refer to below doc
32 +  Documentation/devicetree/bindings/regulator/regulator.txt.
33 +
34 +  The valid names for regulators are:
35 +  sw1ab,sw1c,sw2,sw3a,sw3b,sw4,swbst,vsnvs,vrefddr,vgen1~vgen6
36 +
37 +Each regulator is defined using the standard binding for regulators.
38 +
39 +Example:
40 +
41 +       pmic: pfuze100@08 {
42 +               compatible = "fsl,pfuze100";
43 +               reg = <0x08>;
44 +
45 +               regulators {
46 +                       sw1a_reg: sw1ab {
47 +                               regulator-min-microvolt = <300000>;
48 +                               regulator-max-microvolt = <1875000>;
49 +                               regulator-boot-on;
50 +                               regulator-always-on;
51 +                               regulator-ramp-delay = <6250>;
52 +                       };
53 +
54 +                       sw1c_reg: sw1c {
55 +                               regulator-min-microvolt = <300000>;
56 +                               regulator-max-microvolt = <1875000>;
57 +                               regulator-boot-on;
58 +                               regulator-always-on;
59 +                       };
60 +
61 +                       sw2_reg: sw2 {
62 +                               regulator-min-microvolt = <800000>;
63 +                               regulator-max-microvolt = <3300000>;
64 +                               regulator-boot-on;
65 +                               regulator-always-on;
66 +                       };
67 +
68 +                       sw3a_reg: sw3a {
69 +                               regulator-min-microvolt = <400000>;
70 +                               regulator-max-microvolt = <1975000>;
71 +                               regulator-boot-on;
72 +                               regulator-always-on;
73 +                       };
74 +
75 +                       sw3b_reg: sw3b {
76 +                               regulator-min-microvolt = <400000>;
77 +                               regulator-max-microvolt = <1975000>;
78 +                               regulator-boot-on;
79 +                               regulator-always-on;
80 +                       };
81 +
82 +                       sw4_reg: sw4 {
83 +                               regulator-min-microvolt = <800000>;
84 +                               regulator-max-microvolt = <3300000>;
85 +                       };
86 +
87 +                       swbst_reg: swbst {
88 +                               regulator-min-microvolt = <5000000>;
89 +                               regulator-max-microvolt = <5150000>;
90 +                       };
91 +
92 +                       snvs_reg: vsnvs {
93 +                               regulator-min-microvolt = <1000000>;
94 +                               regulator-max-microvolt = <3000000>;
95 +                               regulator-boot-on;
96 +                               regulator-always-on;
97 +                       };
98 +
99 +                       vref_reg: vrefddr {
100 +                               regulator-boot-on;
101 +                               regulator-always-on;
102 +                       };
103 +
104 +                       vgen1_reg: vgen1 {
105 +                               regulator-min-microvolt = <800000>;
106 +                               regulator-max-microvolt = <1550000>;
107 +                       };
108 +
109 +                       vgen2_reg: vgen2 {
110 +                               regulator-min-microvolt = <800000>;
111 +                               regulator-max-microvolt = <1550000>;
112 +                       };
113 +
114 +                       vgen3_reg: vgen3 {
115 +                               regulator-min-microvolt = <1800000>;
116 +                               regulator-max-microvolt = <3300000>;
117 +                       };
118 +
119 +                       vgen4_reg: vgen4 {
120 +                               regulator-min-microvolt = <1800000>;
121 +                               regulator-max-microvolt = <3300000>;
122 +                               regulator-always-on;
123 +                       };
124 +
125 +                       vgen5_reg: vgen5 {
126 +                               regulator-min-microvolt = <1800000>;
127 +                               regulator-max-microvolt = <3300000>;
128 +                               regulator-always-on;
129 +                       };
130 +
131 +                       vgen6_reg: vgen6 {
132 +                               regulator-min-microvolt = <1800000>;
133 +                               regulator-max-microvolt = <3300000>;
134 +                               regulator-always-on;
135 +                       };
136 +               };
137 +       };
138 --- a/drivers/regulator/Kconfig
139 +++ b/drivers/regulator/Kconfig
140 @@ -300,6 +300,13 @@ config REGULATOR_PCF50633
141          Say Y here to support the voltage regulators and convertors
142          on PCF50633
143  
144 +config REGULATOR_PFUZE100
145 +       tristate "Support regulators on Freescale PFUZE100 PMIC"
146 +       depends on I2C
147 +       help
148 +         Say y here to support the regulators found on the Freescale PFUZE100
149 +         PMIC.
150 +
151  config REGULATOR_RC5T583
152         tristate "RICOH RC5T583 Power regulators"
153         depends on MFD_RC5T583
154 --- a/drivers/regulator/Makefile
155 +++ b/drivers/regulator/Makefile
156 @@ -45,6 +45,7 @@ obj-$(CONFIG_REGULATOR_MC13783) += mc137
157  obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
158  obj-$(CONFIG_REGULATOR_MC13XXX_CORE) +=  mc13xxx-regulator-core.o
159  obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o
160 +obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o
161  obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o
162  obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
163  obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
164 --- /dev/null
165 +++ b/drivers/regulator/pfuze100-regulator.c
166 @@ -0,0 +1,454 @@
167 +/*
168 + * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
169 + *
170 + * This program is free software; you can redistribute it and/or modify
171 + * it under the terms of the GNU General Public License as published by
172 + * the Free Software Foundation; either version 2 of the License, or
173 + * (at your option) any later version.
174 + *
175 + * This program is distributed in the hope that it will be useful,
176 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
177 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
178 + * GNU General Public License for more details.
179 + *
180 + * You should have received a copy of the GNU General Public License
181 + * along with this program; if not, write to the Free Software
182 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
183 + */
184 +#include <linux/kernel.h>
185 +#include <linux/module.h>
186 +#include <linux/init.h>
187 +#include <linux/err.h>
188 +#include <linux/of.h>
189 +#include <linux/of_device.h>
190 +#include <linux/regulator/of_regulator.h>
191 +#include <linux/platform_device.h>
192 +#include <linux/regulator/driver.h>
193 +#include <linux/regulator/machine.h>
194 +#include <linux/regulator/pfuze100.h>
195 +#include <linux/i2c.h>
196 +#include <linux/slab.h>
197 +#include <linux/regmap.h>
198 +
199 +#define PFUZE_NUMREGS          128
200 +#define PFUZE100_VOL_OFFSET    0
201 +#define PFUZE100_STANDBY_OFFSET        1
202 +#define PFUZE100_MODE_OFFSET   3
203 +#define PFUZE100_CONF_OFFSET   4
204 +
205 +#define PFUZE100_DEVICEID      0x0
206 +#define PFUZE100_REVID         0x3
207 +#define PFUZE100_FABID         0x3
208 +
209 +#define PFUZE100_SW1ABVOL      0x20
210 +#define PFUZE100_SW1CVOL       0x2e
211 +#define PFUZE100_SW2VOL                0x35
212 +#define PFUZE100_SW3AVOL       0x3c
213 +#define PFUZE100_SW3BVOL       0x43
214 +#define PFUZE100_SW4VOL                0x4a
215 +#define PFUZE100_SWBSTCON1     0x66
216 +#define PFUZE100_VREFDDRCON    0x6a
217 +#define PFUZE100_VSNVSVOL      0x6b
218 +#define PFUZE100_VGEN1VOL      0x6c
219 +#define PFUZE100_VGEN2VOL      0x6d
220 +#define PFUZE100_VGEN3VOL      0x6e
221 +#define PFUZE100_VGEN4VOL      0x6f
222 +#define PFUZE100_VGEN5VOL      0x70
223 +#define PFUZE100_VGEN6VOL      0x71
224 +
225 +struct pfuze_regulator {
226 +       struct regulator_desc desc;
227 +       unsigned char stby_reg;
228 +       unsigned char stby_mask;
229 +};
230 +
231 +struct pfuze_chip {
232 +       struct regmap *regmap;
233 +       struct device *dev;
234 +       struct pfuze_regulator regulator_descs[PFUZE100_MAX_REGULATOR];
235 +       struct regulator_dev *regulators[PFUZE100_MAX_REGULATOR];
236 +};
237 +
238 +static const int pfuze100_swbst[] = {
239 +       5000000, 5050000, 5100000, 5150000,
240 +};
241 +
242 +static const int pfuze100_vsnvs[] = {
243 +       1000000, 1100000, 1200000, 1300000, 1500000, 1800000, 3000000,
244 +};
245 +
246 +static const struct i2c_device_id pfuze_device_id[] = {
247 +       {.name = "pfuze100"},
248 +       {},
249 +};
250 +MODULE_DEVICE_TABLE(i2c, pfuze_device_id);
251 +
252 +static const struct of_device_id pfuze_dt_ids[] = {
253 +       { .compatible = "fsl,pfuze100" },
254 +       {},
255 +};
256 +MODULE_DEVICE_TABLE(of, pfuze_dt_ids);
257 +
258 +static int pfuze100_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
259 +{
260 +       struct pfuze_chip *pfuze100 = rdev_get_drvdata(rdev);
261 +       int id = rdev->desc->id;
262 +       unsigned int val, ramp_bits, reg;
263 +       int ret;
264 +
265 +       if (id < PFUZE100_SWBST) {
266 +               if (id == PFUZE100_SW1AB)
267 +                       reg = PFUZE100_SW1ABVOL;
268 +               else
269 +                       reg = PFUZE100_SW1CVOL + (id - PFUZE100_SW1C) * 7;
270 +               regmap_read(pfuze100->regmap, reg, &val);
271 +
272 +               if (id <= PFUZE100_SW1C)
273 +                       ramp_delay = 25000 / (2 * ramp_delay);
274 +               else if (val & 0x40)
275 +                       ramp_delay = 50000 / (4 * ramp_delay);
276 +               else
277 +                       ramp_delay = 25000 / (2 * ramp_delay);
278 +
279 +               ramp_bits = (ramp_delay >> 1) - (ramp_delay >> 3);
280 +               ret = regmap_update_bits(pfuze100->regmap, reg + 4 , 0xc0,
281 +                               ramp_bits << 6);
282 +               if (ret < 0)
283 +                       dev_err(pfuze100->dev, "ramp failed, err %d\n", ret);
284 +       } else
285 +               ret = -EACCES;
286 +
287 +       return ret;
288 +}
289 +
290 +static struct regulator_ops pfuze100_ldo_regulator_ops = {
291 +       .enable = regulator_enable_regmap,
292 +       .disable = regulator_disable_regmap,
293 +       .is_enabled = regulator_is_enabled_regmap,
294 +       .list_voltage = regulator_list_voltage_linear,
295 +       .set_voltage_sel = regulator_set_voltage_sel_regmap,
296 +       .get_voltage_sel = regulator_get_voltage_sel_regmap,
297 +};
298 +
299 +static struct regulator_ops pfuze100_fixed_regulator_ops = {
300 +       .list_voltage = regulator_list_voltage_linear,
301 +};
302 +
303 +static struct regulator_ops pfuze100_sw_regulator_ops = {
304 +       .list_voltage = regulator_list_voltage_linear,
305 +       .set_voltage_sel = regulator_set_voltage_sel_regmap,
306 +       .get_voltage_sel = regulator_get_voltage_sel_regmap,
307 +       .set_voltage_time_sel = regulator_set_voltage_time_sel,
308 +       .set_ramp_delay = pfuze100_set_ramp_delay,
309 +};
310 +
311 +static struct regulator_ops pfuze100_swb_regulator_ops = {
312 +       .list_voltage = regulator_list_voltage_table,
313 +       .set_voltage_sel = regulator_set_voltage_sel_regmap,
314 +       .get_voltage_sel = regulator_get_voltage_sel_regmap,
315 +
316 +};
317 +
318 +#define PFUZE100_FIXED_REG(_name, base, voltage)       \
319 +       [PFUZE100_ ## _name] = {        \
320 +               .desc = {       \
321 +                       .name = #_name, \
322 +                       .n_voltages = 1,        \
323 +                       .ops = &pfuze100_fixed_regulator_ops,   \
324 +                       .type = REGULATOR_VOLTAGE,      \
325 +                       .id = PFUZE100_ ## _name,       \
326 +                       .owner = THIS_MODULE,   \
327 +                       .min_uV = (voltage),    \
328 +                       .enable_reg = (base),   \
329 +                       .enable_mask = 0x10,    \
330 +               },      \
331 +       }
332 +
333 +#define PFUZE100_SW_REG(_name, base, min, max, step)   \
334 +       [PFUZE100_ ## _name] = {        \
335 +               .desc = {       \
336 +                       .name = #_name,\
337 +                       .n_voltages = ((max) - (min)) / (step) + 1,     \
338 +                       .ops = &pfuze100_sw_regulator_ops,      \
339 +                       .type = REGULATOR_VOLTAGE,      \
340 +                       .id = PFUZE100_ ## _name,       \
341 +                       .owner = THIS_MODULE,   \
342 +                       .min_uV = (min),        \
343 +                       .uV_step = (step),      \
344 +                       .vsel_reg = (base) + PFUZE100_VOL_OFFSET,       \
345 +                       .vsel_mask = 0x3f,      \
346 +               },      \
347 +               .stby_reg = (base) + PFUZE100_STANDBY_OFFSET,   \
348 +               .stby_mask = 0x3f,      \
349 +       }
350 +
351 +#define PFUZE100_SWB_REG(_name, base, mask, voltages)  \
352 +       [PFUZE100_ ## _name] = {        \
353 +               .desc = {       \
354 +                       .name = #_name, \
355 +                       .n_voltages = ARRAY_SIZE(voltages),     \
356 +                       .ops = &pfuze100_swb_regulator_ops,     \
357 +                       .type = REGULATOR_VOLTAGE,      \
358 +                       .id = PFUZE100_ ## _name,       \
359 +                       .owner = THIS_MODULE,   \
360 +                       .volt_table = voltages, \
361 +                       .vsel_reg = (base),     \
362 +                       .vsel_mask = (mask),    \
363 +               },      \
364 +       }
365 +
366 +#define PFUZE100_VGEN_REG(_name, base, min, max, step) \
367 +       [PFUZE100_ ## _name] = {        \
368 +               .desc = {       \
369 +                       .name = #_name, \
370 +                       .n_voltages = ((max) - (min)) / (step) + 1,     \
371 +                       .ops = &pfuze100_ldo_regulator_ops,     \
372 +                       .type = REGULATOR_VOLTAGE,      \
373 +                       .id = PFUZE100_ ## _name,       \
374 +                       .owner = THIS_MODULE,   \
375 +                       .min_uV = (min),        \
376 +                       .uV_step = (step),      \
377 +                       .vsel_reg = (base),     \
378 +                       .vsel_mask = 0xf,       \
379 +                       .enable_reg = (base),   \
380 +                       .enable_mask = 0x10,    \
381 +               },      \
382 +               .stby_reg = (base),     \
383 +               .stby_mask = 0x20,      \
384 +       }
385 +
386 +static struct pfuze_regulator pfuze100_regulators[] = {
387 +       PFUZE100_SW_REG(SW1AB, PFUZE100_SW1ABVOL, 300000, 1875000, 25000),
388 +       PFUZE100_SW_REG(SW1C, PFUZE100_SW1CVOL, 300000, 1875000, 25000),
389 +       PFUZE100_SW_REG(SW2, PFUZE100_SW2VOL, 400000, 1975000, 25000),
390 +       PFUZE100_SW_REG(SW3A, PFUZE100_SW3AVOL, 400000, 1975000, 25000),
391 +       PFUZE100_SW_REG(SW3B, PFUZE100_SW3BVOL, 400000, 1975000, 25000),
392 +       PFUZE100_SW_REG(SW4, PFUZE100_SW4VOL, 400000, 1975000, 25000),
393 +       PFUZE100_SWB_REG(SWBST, PFUZE100_SWBSTCON1, 0x3 , pfuze100_swbst),
394 +       PFUZE100_SWB_REG(VSNVS, PFUZE100_VSNVSVOL, 0x7, pfuze100_vsnvs),
395 +       PFUZE100_FIXED_REG(VREFDDR, PFUZE100_VREFDDRCON, 750000),
396 +       PFUZE100_VGEN_REG(VGEN1, PFUZE100_VGEN1VOL, 800000, 1550000, 50000),
397 +       PFUZE100_VGEN_REG(VGEN2, PFUZE100_VGEN2VOL, 800000, 1550000, 50000),
398 +       PFUZE100_VGEN_REG(VGEN3, PFUZE100_VGEN3VOL, 1800000, 3300000, 100000),
399 +       PFUZE100_VGEN_REG(VGEN4, PFUZE100_VGEN4VOL, 1800000, 3300000, 100000),
400 +       PFUZE100_VGEN_REG(VGEN5, PFUZE100_VGEN5VOL, 1800000, 3300000, 100000),
401 +       PFUZE100_VGEN_REG(VGEN6, PFUZE100_VGEN6VOL, 1800000, 3300000, 100000),
402 +};
403 +
404 +#ifdef CONFIG_OF
405 +static struct of_regulator_match pfuze100_matches[] = {
406 +       { .name = "sw1ab",      },
407 +       { .name = "sw1c",       },
408 +       { .name = "sw2",        },
409 +       { .name = "sw3a",       },
410 +       { .name = "sw3b",       },
411 +       { .name = "sw4",        },
412 +       { .name = "swbst",      },
413 +       { .name = "vsnvs",      },
414 +       { .name = "vrefddr",    },
415 +       { .name = "vgen1",      },
416 +       { .name = "vgen2",      },
417 +       { .name = "vgen3",      },
418 +       { .name = "vgen4",      },
419 +       { .name = "vgen5",      },
420 +       { .name = "vgen6",      },
421 +};
422 +
423 +static int pfuze_parse_regulators_dt(struct pfuze_chip *chip)
424 +{
425 +       struct device *dev = chip->dev;
426 +       struct device_node *np, *parent;
427 +       int ret;
428 +
429 +       np = of_node_get(dev->parent->of_node);
430 +       if (!np)
431 +               return 0;
432 +
433 +       parent = of_find_node_by_name(np, "regulators");
434 +       if (!parent) {
435 +               dev_err(dev, "regulators node not found\n");
436 +               return -EINVAL;
437 +       }
438 +
439 +       ret = of_regulator_match(dev, parent, pfuze100_matches,
440 +                                ARRAY_SIZE(pfuze100_matches));
441 +
442 +       of_node_put(parent);
443 +       if (ret < 0) {
444 +               dev_err(dev, "Error parsing regulator init data: %d\n",
445 +                       ret);
446 +               return ret;
447 +       }
448 +
449 +       return 0;
450 +}
451 +
452 +static inline struct regulator_init_data *match_init_data(int index)
453 +{
454 +       return pfuze100_matches[index].init_data;
455 +}
456 +
457 +static inline struct device_node *match_of_node(int index)
458 +{
459 +       return pfuze100_matches[index].of_node;
460 +}
461 +#else
462 +static int pfuze_parse_regulators_dt(struct pfuze_chip *chip)
463 +{
464 +       return NULL;
465 +}
466 +
467 +static inline struct regulator_init_data *match_init_data(int index)
468 +{
469 +       return NULL;
470 +}
471 +
472 +static inline struct device_node *match_of_node(int index)
473 +{
474 +       return NULL;
475 +}
476 +#endif
477 +
478 +static int pfuze_identify(struct pfuze_chip *pfuze_chip)
479 +{
480 +       unsigned int value;
481 +       int ret;
482 +
483 +       ret = regmap_read(pfuze_chip->regmap, PFUZE100_DEVICEID, &value);
484 +       if (ret)
485 +               return ret;
486 +
487 +       if (value & 0x0f) {
488 +               dev_warn(pfuze_chip->dev, "Illegal ID: %x\n", value);
489 +               return -ENODEV;
490 +       }
491 +
492 +       ret = regmap_read(pfuze_chip->regmap, PFUZE100_REVID, &value);
493 +       if (ret)
494 +               return ret;
495 +       dev_info(pfuze_chip->dev,
496 +                "Full lay: %x, Metal lay: %x\n",
497 +                (value & 0xf0) >> 4, value & 0x0f);
498 +
499 +       ret = regmap_read(pfuze_chip->regmap, PFUZE100_FABID, &value);
500 +       if (ret)
501 +               return ret;
502 +       dev_info(pfuze_chip->dev, "FAB: %x, FIN: %x\n",
503 +                (value & 0xc) >> 2, value & 0x3);
504 +
505 +       return 0;
506 +}
507 +
508 +static const struct regmap_config pfuze_regmap_config = {
509 +       .reg_bits = 8,
510 +       .val_bits = 8,
511 +       .max_register = PFUZE_NUMREGS,
512 +       .cache_type = REGCACHE_RBTREE,
513 +};
514 +
515 +static int pfuze100_regulator_probe(struct i2c_client *client,
516 +                                   const struct i2c_device_id *id)
517 +{
518 +       struct pfuze_chip *pfuze_chip;
519 +       struct pfuze_regulator_platform_data *pdata =
520 +           dev_get_platdata(&client->dev);
521 +       struct regulator_config config = { };
522 +       int i, ret;
523 +
524 +       pfuze_chip = devm_kzalloc(&client->dev, sizeof(*pfuze_chip),
525 +                       GFP_KERNEL);
526 +       if (!pfuze_chip)
527 +               return -ENOMEM;
528 +
529 +       dev_set_drvdata(&client->dev, pfuze_chip);
530 +
531 +       memcpy(pfuze_chip->regulator_descs, pfuze100_regulators,
532 +               sizeof(pfuze_chip->regulator_descs));
533 +
534 +       pfuze_chip->dev = &client->dev;
535 +
536 +       pfuze_chip->regmap = devm_regmap_init_i2c(client, &pfuze_regmap_config);
537 +       if (IS_ERR(pfuze_chip->regmap)) {
538 +               ret = PTR_ERR(pfuze_chip->regmap);
539 +               dev_err(&client->dev,
540 +                       "regmap allocation failed with err %d\n", ret);
541 +               return ret;
542 +       }
543 +
544 +       ret = pfuze_identify(pfuze_chip);
545 +       if (ret) {
546 +               dev_err(&client->dev, "unrecognized pfuze chip ID!\n");
547 +               return ret;
548 +       }
549 +
550 +       ret = pfuze_parse_regulators_dt(pfuze_chip);
551 +       if (ret)
552 +               return ret;
553 +
554 +       for (i = 0; i < PFUZE100_MAX_REGULATOR; i++) {
555 +               struct regulator_init_data *init_data;
556 +               int val;
557 +
558 +               if (pdata)
559 +                       init_data = pdata->init_data[i];
560 +               else
561 +                       init_data = match_init_data(i);
562 +
563 +               /* SW2~SW4 high bit check and modify the voltage value table */
564 +               if (i > PFUZE100_SW1C && i < PFUZE100_SWBST) {
565 +                       regmap_read(pfuze_chip->regmap, PFUZE100_SW2VOL +
566 +                                       (i - PFUZE100_SW2) * 7, &val);
567 +                       if (val & 0x40) {
568 +                               pfuze_chip->regulator_descs[i].desc.min_uV
569 +                               = 800000;
570 +                               pfuze_chip->regulator_descs[i].desc.uV_step
571 +                               = 50000;
572 +                       }
573 +               }
574 +
575 +               config.dev = &client->dev;
576 +               config.init_data = init_data;
577 +               config.driver_data = pfuze_chip;
578 +               config.of_node = match_of_node(i);
579 +
580 +               pfuze_chip->regulators[i] = regulator_register(&pfuze_chip
581 +                       ->regulator_descs[i].desc, &config);
582 +               if (IS_ERR(pfuze_chip->regulators[i])) {
583 +                       dev_err(&client->dev, "register regulator%s failed\n",
584 +                               pfuze100_regulators[i].desc.name);
585 +                       ret = PTR_ERR(pfuze_chip->regulators[i]);
586 +                       while (--i >= 0)
587 +                               regulator_unregister(pfuze_chip->regulators[i]);
588 +                       return ret;
589 +               }
590 +       }
591 +
592 +       return 0;
593 +}
594 +
595 +static int pfuze100_regulator_remove(struct i2c_client *client)
596 +{
597 +       int i;
598 +       struct pfuze_chip *pfuze_chip = dev_get_drvdata(&client->dev);
599 +
600 +       for (i = 0; i < PFUZE100_MAX_REGULATOR; i++)
601 +               regulator_unregister(pfuze_chip->regulators[i]);
602 +
603 +       return 0;
604 +}
605 +
606 +static struct i2c_driver pfuze_driver = {
607 +       .id_table = pfuze_device_id,
608 +       .driver = {
609 +               .name = "pfuze100-regulator",
610 +               .owner = THIS_MODULE,
611 +               .of_match_table = pfuze_dt_ids,
612 +       },
613 +       .probe = pfuze100_regulator_probe,
614 +       .remove = pfuze100_regulator_remove,
615 +};
616 +module_i2c_driver(pfuze_driver);
617 +
618 +MODULE_AUTHOR("Robin Gong <b38343@freescale.com>");
619 +MODULE_DESCRIPTION("Regulator Driver for Freescale PFUZE100 PMIC");
620 +MODULE_ALIAS("pfuze100-regulator");
621 --- /dev/null
622 +++ b/include/linux/regulator/pfuze100.h
623 @@ -0,0 +1,44 @@
624 +/*
625 + * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
626 + *
627 + * This program is free software; you can redistribute it and/or modify
628 + * it under the terms of the GNU General Public License as published by
629 + * the Free Software Foundation; either version 2 of the License, or
630 + * (at your option) any later version.
631 + *
632 + * This program is distributed in the hope that it will be useful,
633 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
634 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
635 + * GNU General Public License for more details.
636 + *
637 + * You should have received a copy of the GNU General Public License along
638 + * with this program; if not, write to the Free Software Foundation, Inc.,
639 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
640 + */
641 +#ifndef __LINUX_REG_PFUZE100_H
642 +#define __LINUX_REG_PFUZE100_H
643 +
644 +#define PFUZE100_SW1AB         0
645 +#define PFUZE100_SW1C          1
646 +#define PFUZE100_SW2           2
647 +#define PFUZE100_SW3A          3
648 +#define PFUZE100_SW3B          4
649 +#define PFUZE100_SW4           5
650 +#define PFUZE100_SWBST         6
651 +#define PFUZE100_VSNVS         7
652 +#define PFUZE100_VREFDDR       8
653 +#define PFUZE100_VGEN1         9
654 +#define PFUZE100_VGEN2         10
655 +#define PFUZE100_VGEN3         11
656 +#define PFUZE100_VGEN4         12
657 +#define PFUZE100_VGEN5         13
658 +#define PFUZE100_VGEN6         14
659 +#define PFUZE100_MAX_REGULATOR 15
660 +
661 +struct regulator_init_data;
662 +
663 +struct pfuze_regulator_platform_data {
664 +       struct regulator_init_data *init_data[PFUZE100_MAX_REGULATOR];
665 +};
666 +
667 +#endif /* __LINUX_REG_PFUZE100_H */