1 --- a/drivers/regulator/Kconfig
2 +++ b/drivers/regulator/Kconfig
3 @@ -300,6 +300,14 @@ config REGULATOR_PCF50633
4 Say Y here to support the voltage regulators and convertors
7 +config REGULATOR_PFUZE100
8 + tristate "Support regulators on Freescale PFUZE100 PMIC"
12 + Say y here to support the regulators found on the Freescale PFUZE100
15 config REGULATOR_RC5T583
16 tristate "RICOH RC5T583 Power regulators"
17 depends on MFD_RC5T583
18 --- a/drivers/regulator/Makefile
19 +++ b/drivers/regulator/Makefile
20 @@ -45,6 +45,7 @@ obj-$(CONFIG_REGULATOR_MC13783) += mc137
21 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
22 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o
23 obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o
24 +obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o
25 obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o
26 obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
27 obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
29 +++ b/drivers/regulator/pfuze100-regulator.c
32 + * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
34 + * This program is free software; you can redistribute it and/or modify
35 + * it under the terms of the GNU General Public License as published by
36 + * the Free Software Foundation; either version 2 of the License, or
37 + * (at your option) any later version.
39 + * This program is distributed in the hope that it will be useful,
40 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 + * GNU General Public License for more details.
44 + * You should have received a copy of the GNU General Public License
45 + * along with this program; if not, write to the Free Software
46 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48 +#include <linux/kernel.h>
49 +#include <linux/module.h>
50 +#include <linux/init.h>
51 +#include <linux/err.h>
52 +#include <linux/of.h>
53 +#include <linux/of_device.h>
54 +#include <linux/regulator/of_regulator.h>
55 +#include <linux/platform_device.h>
56 +#include <linux/regulator/driver.h>
57 +#include <linux/regulator/machine.h>
58 +#include <linux/regulator/pfuze100.h>
59 +#include <linux/i2c.h>
60 +#include <linux/slab.h>
61 +#include <linux/regmap.h>
63 +#define PFUZE_NUMREGS 128
64 +#define PFUZE100_VOL_OFFSET 0
65 +#define PFUZE100_STANDBY_OFFSET 1
66 +#define PFUZE100_MODE_OFFSET 3
67 +#define PFUZE100_CONF_OFFSET 4
69 +#define PFUZE100_DEVICEID 0x0
70 +#define PFUZE100_REVID 0x3
71 +#define PFUZE100_FABID 0x3
73 +#define PFUZE100_SW1ABVOL 0x20
74 +#define PFUZE100_SW1CVOL 0x2e
75 +#define PFUZE100_SW2VOL 0x35
76 +#define PFUZE100_SW3AVOL 0x3c
77 +#define PFUZE100_SW3BVOL 0x43
78 +#define PFUZE100_SW4VOL 0x4a
79 +#define PFUZE100_SWBSTCON1 0x66
80 +#define PFUZE100_VREFDDRCON 0x6a
81 +#define PFUZE100_VSNVSVOL 0x6b
82 +#define PFUZE100_VGEN1VOL 0x6c
83 +#define PFUZE100_VGEN2VOL 0x6d
84 +#define PFUZE100_VGEN3VOL 0x6e
85 +#define PFUZE100_VGEN4VOL 0x6f
86 +#define PFUZE100_VGEN5VOL 0x70
87 +#define PFUZE100_VGEN6VOL 0x71
89 +struct pfuze_regulator {
90 + struct regulator_desc desc;
91 + unsigned char stby_reg;
92 + unsigned char stby_mask;
96 + struct regmap *regmap;
98 + struct pfuze_regulator regulator_descs[PFUZE100_MAX_REGULATOR];
99 + struct regulator_dev *regulators[PFUZE100_MAX_REGULATOR];
102 +static const int pfuze100_swbst[] = {
103 + 5000000, 5050000, 5100000, 5150000,
106 +static const int pfuze100_vsnvs[] = {
107 + 1000000, 1100000, 1200000, 1300000, 1500000, 1800000, 3000000,
110 +static const struct i2c_device_id pfuze_device_id[] = {
111 + {.name = "pfuze100"},
114 +MODULE_DEVICE_TABLE(i2c, pfuze_device_id);
116 +static const struct of_device_id pfuze_dt_ids[] = {
117 + { .compatible = "fsl,pfuze100" },
120 +MODULE_DEVICE_TABLE(of, pfuze_dt_ids);
122 +static int pfuze100_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
124 + struct pfuze_chip *pfuze100 = rdev_get_drvdata(rdev);
125 + int id = rdev->desc->id;
126 + unsigned int ramp_bits;
129 + if (id < PFUZE100_SWBST) {
130 + ramp_delay = 12500 / ramp_delay;
131 + ramp_bits = (ramp_delay >> 1) - (ramp_delay >> 3);
132 + ret = regmap_update_bits(pfuze100->regmap,
133 + rdev->desc->vsel_reg + 4,
134 + 0xc0, ramp_bits << 6);
136 + dev_err(pfuze100->dev, "ramp failed, err %d\n", ret);
143 +static struct regulator_ops pfuze100_ldo_regulator_ops = {
144 + .enable = regulator_enable_regmap,
145 + .disable = regulator_disable_regmap,
146 + .is_enabled = regulator_is_enabled_regmap,
147 + .list_voltage = regulator_list_voltage_linear,
148 + .set_voltage_sel = regulator_set_voltage_sel_regmap,
149 + .get_voltage_sel = regulator_get_voltage_sel_regmap,
152 +static struct regulator_ops pfuze100_fixed_regulator_ops = {
153 + .list_voltage = regulator_list_voltage_linear,
156 +static struct regulator_ops pfuze100_sw_regulator_ops = {
157 + .list_voltage = regulator_list_voltage_linear,
158 + .set_voltage_sel = regulator_set_voltage_sel_regmap,
159 + .get_voltage_sel = regulator_get_voltage_sel_regmap,
160 + .set_voltage_time_sel = regulator_set_voltage_time_sel,
161 + .set_ramp_delay = pfuze100_set_ramp_delay,
164 +static struct regulator_ops pfuze100_swb_regulator_ops = {
165 + .list_voltage = regulator_list_voltage_table,
166 + .map_voltage = regulator_map_voltage_ascend,
167 + .set_voltage_sel = regulator_set_voltage_sel_regmap,
168 + .get_voltage_sel = regulator_get_voltage_sel_regmap,
172 +#define PFUZE100_FIXED_REG(_name, base, voltage) \
173 + [PFUZE100_ ## _name] = { \
177 + .ops = &pfuze100_fixed_regulator_ops, \
178 + .type = REGULATOR_VOLTAGE, \
179 + .id = PFUZE100_ ## _name, \
180 + .owner = THIS_MODULE, \
181 + .min_uV = (voltage), \
182 + .enable_reg = (base), \
183 + .enable_mask = 0x10, \
187 +#define PFUZE100_SW_REG(_name, base, min, max, step) \
188 + [PFUZE100_ ## _name] = { \
191 + .n_voltages = ((max) - (min)) / (step) + 1, \
192 + .ops = &pfuze100_sw_regulator_ops, \
193 + .type = REGULATOR_VOLTAGE, \
194 + .id = PFUZE100_ ## _name, \
195 + .owner = THIS_MODULE, \
197 + .uV_step = (step), \
198 + .vsel_reg = (base) + PFUZE100_VOL_OFFSET, \
199 + .vsel_mask = 0x3f, \
201 + .stby_reg = (base) + PFUZE100_STANDBY_OFFSET, \
202 + .stby_mask = 0x3f, \
205 +#define PFUZE100_SWB_REG(_name, base, mask, voltages) \
206 + [PFUZE100_ ## _name] = { \
209 + .n_voltages = ARRAY_SIZE(voltages), \
210 + .ops = &pfuze100_swb_regulator_ops, \
211 + .type = REGULATOR_VOLTAGE, \
212 + .id = PFUZE100_ ## _name, \
213 + .owner = THIS_MODULE, \
214 + .volt_table = voltages, \
215 + .vsel_reg = (base), \
216 + .vsel_mask = (mask), \
220 +#define PFUZE100_VGEN_REG(_name, base, min, max, step) \
221 + [PFUZE100_ ## _name] = { \
224 + .n_voltages = ((max) - (min)) / (step) + 1, \
225 + .ops = &pfuze100_ldo_regulator_ops, \
226 + .type = REGULATOR_VOLTAGE, \
227 + .id = PFUZE100_ ## _name, \
228 + .owner = THIS_MODULE, \
230 + .uV_step = (step), \
231 + .vsel_reg = (base), \
232 + .vsel_mask = 0xf, \
233 + .enable_reg = (base), \
234 + .enable_mask = 0x10, \
236 + .stby_reg = (base), \
237 + .stby_mask = 0x20, \
240 +static struct pfuze_regulator pfuze100_regulators[] = {
241 + PFUZE100_SW_REG(SW1AB, PFUZE100_SW1ABVOL, 300000, 1875000, 25000),
242 + PFUZE100_SW_REG(SW1C, PFUZE100_SW1CVOL, 300000, 1875000, 25000),
243 + PFUZE100_SW_REG(SW2, PFUZE100_SW2VOL, 400000, 1975000, 25000),
244 + PFUZE100_SW_REG(SW3A, PFUZE100_SW3AVOL, 400000, 1975000, 25000),
245 + PFUZE100_SW_REG(SW3B, PFUZE100_SW3BVOL, 400000, 1975000, 25000),
246 + PFUZE100_SW_REG(SW4, PFUZE100_SW4VOL, 400000, 1975000, 25000),
247 + PFUZE100_SWB_REG(SWBST, PFUZE100_SWBSTCON1, 0x3 , pfuze100_swbst),
248 + PFUZE100_SWB_REG(VSNVS, PFUZE100_VSNVSVOL, 0x7, pfuze100_vsnvs),
249 + PFUZE100_FIXED_REG(VREFDDR, PFUZE100_VREFDDRCON, 750000),
250 + PFUZE100_VGEN_REG(VGEN1, PFUZE100_VGEN1VOL, 800000, 1550000, 50000),
251 + PFUZE100_VGEN_REG(VGEN2, PFUZE100_VGEN2VOL, 800000, 1550000, 50000),
252 + PFUZE100_VGEN_REG(VGEN3, PFUZE100_VGEN3VOL, 1800000, 3300000, 100000),
253 + PFUZE100_VGEN_REG(VGEN4, PFUZE100_VGEN4VOL, 1800000, 3300000, 100000),
254 + PFUZE100_VGEN_REG(VGEN5, PFUZE100_VGEN5VOL, 1800000, 3300000, 100000),
255 + PFUZE100_VGEN_REG(VGEN6, PFUZE100_VGEN6VOL, 1800000, 3300000, 100000),
259 +static struct of_regulator_match pfuze100_matches[] = {
260 + { .name = "sw1ab", },
261 + { .name = "sw1c", },
262 + { .name = "sw2", },
263 + { .name = "sw3a", },
264 + { .name = "sw3b", },
265 + { .name = "sw4", },
266 + { .name = "swbst", },
267 + { .name = "vsnvs", },
268 + { .name = "vrefddr", },
269 + { .name = "vgen1", },
270 + { .name = "vgen2", },
271 + { .name = "vgen3", },
272 + { .name = "vgen4", },
273 + { .name = "vgen5", },
274 + { .name = "vgen6", },
277 +static int pfuze_parse_regulators_dt(struct pfuze_chip *chip)
279 + struct device *dev = chip->dev;
280 + struct device_node *np, *parent;
283 + np = of_node_get(dev->parent->of_node);
287 + parent = of_find_node_by_name(np, "regulators");
289 + dev_err(dev, "regulators node not found\n");
293 + ret = of_regulator_match(dev, parent, pfuze100_matches,
294 + ARRAY_SIZE(pfuze100_matches));
296 + of_node_put(parent);
298 + dev_err(dev, "Error parsing regulator init data: %d\n",
306 +static inline struct regulator_init_data *match_init_data(int index)
308 + return pfuze100_matches[index].init_data;
311 +static inline struct device_node *match_of_node(int index)
313 + return pfuze100_matches[index].of_node;
316 +static int pfuze_parse_regulators_dt(struct pfuze_chip *chip)
321 +static inline struct regulator_init_data *match_init_data(int index)
326 +static inline struct device_node *match_of_node(int index)
332 +static int pfuze_identify(struct pfuze_chip *pfuze_chip)
334 + unsigned int value;
337 + ret = regmap_read(pfuze_chip->regmap, PFUZE100_DEVICEID, &value);
341 + if (value & 0x0f) {
342 + dev_warn(pfuze_chip->dev, "Illegal ID: %x\n", value);
346 + ret = regmap_read(pfuze_chip->regmap, PFUZE100_REVID, &value);
349 + dev_info(pfuze_chip->dev,
350 + "Full lay: %x, Metal lay: %x\n",
351 + (value & 0xf0) >> 4, value & 0x0f);
353 + ret = regmap_read(pfuze_chip->regmap, PFUZE100_FABID, &value);
356 + dev_info(pfuze_chip->dev, "FAB: %x, FIN: %x\n",
357 + (value & 0xc) >> 2, value & 0x3);
362 +static const struct regmap_config pfuze_regmap_config = {
365 + .max_register = PFUZE_NUMREGS - 1,
366 + .cache_type = REGCACHE_RBTREE,
369 +static int pfuze100_regulator_probe(struct i2c_client *client,
370 + const struct i2c_device_id *id)
372 + struct pfuze_chip *pfuze_chip;
373 + struct pfuze_regulator_platform_data *pdata =
374 + dev_get_platdata(&client->dev);
375 + struct regulator_config config = { };
378 + pfuze_chip = devm_kzalloc(&client->dev, sizeof(*pfuze_chip),
383 + i2c_set_clientdata(client, pfuze_chip);
385 + memcpy(pfuze_chip->regulator_descs, pfuze100_regulators,
386 + sizeof(pfuze_chip->regulator_descs));
388 + pfuze_chip->dev = &client->dev;
390 + pfuze_chip->regmap = devm_regmap_init_i2c(client, &pfuze_regmap_config);
391 + if (IS_ERR(pfuze_chip->regmap)) {
392 + ret = PTR_ERR(pfuze_chip->regmap);
393 + dev_err(&client->dev,
394 + "regmap allocation failed with err %d\n", ret);
398 + ret = pfuze_identify(pfuze_chip);
400 + dev_err(&client->dev, "unrecognized pfuze chip ID!\n");
404 + ret = pfuze_parse_regulators_dt(pfuze_chip);
408 + for (i = 0; i < PFUZE100_MAX_REGULATOR; i++) {
409 + struct regulator_init_data *init_data;
410 + struct regulator_desc *desc;
413 + desc = &pfuze_chip->regulator_descs[i].desc;
416 + init_data = pdata->init_data[i];
418 + init_data = match_init_data(i);
420 + /* SW2~SW4 high bit check and modify the voltage value table */
421 + if (i > PFUZE100_SW1C && i < PFUZE100_SWBST) {
422 + regmap_read(pfuze_chip->regmap, desc->vsel_reg, &val);
424 + desc->min_uV = 800000;
425 + desc->uV_step = 50000;
426 + desc->n_voltages = 51;
430 + config.dev = &client->dev;
431 + config.init_data = init_data;
432 + config.driver_data = pfuze_chip;
433 + config.of_node = match_of_node(i);
435 + pfuze_chip->regulators[i] = regulator_register(desc, &config);
436 + if (IS_ERR(pfuze_chip->regulators[i])) {
437 + dev_err(&client->dev, "register regulator%s failed\n",
438 + pfuze100_regulators[i].desc.name);
439 + ret = PTR_ERR(pfuze_chip->regulators[i]);
441 + regulator_unregister(pfuze_chip->regulators[i]);
449 +static int pfuze100_regulator_remove(struct i2c_client *client)
452 + struct pfuze_chip *pfuze_chip = i2c_get_clientdata(client);
454 + for (i = 0; i < PFUZE100_MAX_REGULATOR; i++)
455 + regulator_unregister(pfuze_chip->regulators[i]);
460 +static struct i2c_driver pfuze_driver = {
461 + .id_table = pfuze_device_id,
463 + .name = "pfuze100-regulator",
464 + .owner = THIS_MODULE,
465 + .of_match_table = pfuze_dt_ids,
467 + .probe = pfuze100_regulator_probe,
468 + .remove = pfuze100_regulator_remove,
470 +module_i2c_driver(pfuze_driver);
472 +MODULE_AUTHOR("Robin Gong <b38343@freescale.com>");
473 +MODULE_DESCRIPTION("Regulator Driver for Freescale PFUZE100 PMIC");
474 +MODULE_LICENSE("GPL v2");
475 +MODULE_ALIAS("i2c:pfuze100-regulator");
477 +++ b/include/linux/regulator/pfuze100.h
480 + * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
482 + * This program is free software; you can redistribute it and/or modify
483 + * it under the terms of the GNU General Public License as published by
484 + * the Free Software Foundation; either version 2 of the License, or
485 + * (at your option) any later version.
487 + * This program is distributed in the hope that it will be useful,
488 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
489 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
490 + * GNU General Public License for more details.
492 + * You should have received a copy of the GNU General Public License along
493 + * with this program; if not, write to the Free Software Foundation, Inc.,
494 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
496 +#ifndef __LINUX_REG_PFUZE100_H
497 +#define __LINUX_REG_PFUZE100_H
499 +#define PFUZE100_SW1AB 0
500 +#define PFUZE100_SW1C 1
501 +#define PFUZE100_SW2 2
502 +#define PFUZE100_SW3A 3
503 +#define PFUZE100_SW3B 4
504 +#define PFUZE100_SW4 5
505 +#define PFUZE100_SWBST 6
506 +#define PFUZE100_VSNVS 7
507 +#define PFUZE100_VREFDDR 8
508 +#define PFUZE100_VGEN1 9
509 +#define PFUZE100_VGEN2 10
510 +#define PFUZE100_VGEN3 11
511 +#define PFUZE100_VGEN4 12
512 +#define PFUZE100_VGEN5 13
513 +#define PFUZE100_VGEN6 14
514 +#define PFUZE100_MAX_REGULATOR 15
516 +struct regulator_init_data;
518 +struct pfuze_regulator_platform_data {
519 + struct regulator_init_data *init_data[PFUZE100_MAX_REGULATOR];
522 +#endif /* __LINUX_REG_PFUZE100_H */