blob: 347043a5a9a7df999722fd73870cda070123abbd [file] [log] [blame]
Thomas Gleixner873e65b2019-05-27 08:55:15 +02001// SPDX-License-Identifier: GPL-2.0-only
Wolfram Sang27f37e42009-09-25 09:39:26 +02002/*
3 * max8660.c -- Voltage regulation for the Maxim 8660/8661
4 *
5 * based on max1586.c and wm8400-regulator.c
6 *
7 * Copyright (C) 2009 Wolfram Sang, Pengutronix e.K.
8 *
Wolfram Sang27f37e42009-09-25 09:39:26 +02009 * Some info:
10 *
11 * Datasheet: http://datasheets.maxim-ic.com/en/ds/MAX8660-MAX8661.pdf
12 *
13 * This chip is a bit nasty because it is a write-only device. Thus, the driver
14 * uses shadow registers to keep track of its values. The main problem appears
15 * to be the initialization: When Linux boots up, we cannot know if the chip is
16 * in the default state or not, so we would have to pass such information in
17 * platform_data. As this adds a bit of complexity to the driver, this is left
18 * out for now until it is really needed.
19 *
20 * [A|S|M]DTV1 registers are currently not used, but [A|S|M]DTV2.
21 *
22 * If the driver is feature complete, it might be worth to check if one set of
23 * functions for V3-V7 is sufficient. For maximum flexibility during
24 * development, they are separated for now.
Wolfram Sang27f37e42009-09-25 09:39:26 +020025 */
26
27#include <linux/module.h>
28#include <linux/err.h>
29#include <linux/i2c.h>
30#include <linux/platform_device.h>
31#include <linux/regulator/driver.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Wolfram Sang27f37e42009-09-25 09:39:26 +020033#include <linux/regulator/max8660.h>
Daniel Mackabe4c512013-08-02 12:59:44 +020034#include <linux/of.h>
35#include <linux/of_device.h>
36#include <linux/regulator/of_regulator.h>
Wolfram Sang27f37e42009-09-25 09:39:26 +020037
38#define MAX8660_DCDC_MIN_UV 725000
39#define MAX8660_DCDC_MAX_UV 1800000
40#define MAX8660_DCDC_STEP 25000
41#define MAX8660_DCDC_MAX_SEL 0x2b
42
43#define MAX8660_LDO5_MIN_UV 1700000
44#define MAX8660_LDO5_MAX_UV 2000000
45#define MAX8660_LDO5_STEP 25000
46#define MAX8660_LDO5_MAX_SEL 0x0c
47
48#define MAX8660_LDO67_MIN_UV 1800000
49#define MAX8660_LDO67_MAX_UV 3300000
50#define MAX8660_LDO67_STEP 100000
51#define MAX8660_LDO67_MAX_SEL 0x0f
52
53enum {
54 MAX8660_OVER1,
55 MAX8660_OVER2,
56 MAX8660_VCC1,
57 MAX8660_ADTV1,
58 MAX8660_ADTV2,
59 MAX8660_SDTV1,
60 MAX8660_SDTV2,
61 MAX8660_MDTV1,
62 MAX8660_MDTV2,
63 MAX8660_L12VCR,
64 MAX8660_FPWM,
65 MAX8660_N_REGS, /* not a real register */
66};
67
68struct max8660 {
69 struct i2c_client *client;
70 u8 shadow_regs[MAX8660_N_REGS]; /* as chip is write only */
Wolfram Sang27f37e42009-09-25 09:39:26 +020071};
72
73static int max8660_write(struct max8660 *max8660, u8 reg, u8 mask, u8 val)
74{
Sachin Kamatf920ec72014-03-18 15:53:02 +053075 static const u8 max8660_addresses[MAX8660_N_REGS] = {
Sachin Kamatdda5e362014-03-19 18:02:58 +053076 0x10, 0x12, 0x20, 0x23, 0x24, 0x29, 0x2a, 0x32, 0x33, 0x39, 0x80
77 };
Wolfram Sang27f37e42009-09-25 09:39:26 +020078
79 int ret;
80 u8 reg_val = (max8660->shadow_regs[reg] & mask) | val;
Sachin Kamatf920ec72014-03-18 15:53:02 +053081
Wolfram Sang27f37e42009-09-25 09:39:26 +020082 dev_vdbg(&max8660->client->dev, "Writing reg %02x with %02x\n",
83 max8660_addresses[reg], reg_val);
84
85 ret = i2c_smbus_write_byte_data(max8660->client,
86 max8660_addresses[reg], reg_val);
87 if (ret == 0)
88 max8660->shadow_regs[reg] = reg_val;
89
90 return ret;
91}
92
93
94/*
95 * DCDC functions
96 */
97
98static int max8660_dcdc_is_enabled(struct regulator_dev *rdev)
99{
100 struct max8660 *max8660 = rdev_get_drvdata(rdev);
101 u8 val = max8660->shadow_regs[MAX8660_OVER1];
102 u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? 1 : 4;
Sachin Kamatf920ec72014-03-18 15:53:02 +0530103
Wolfram Sang27f37e42009-09-25 09:39:26 +0200104 return !!(val & mask);
105}
106
107static int max8660_dcdc_enable(struct regulator_dev *rdev)
108{
109 struct max8660 *max8660 = rdev_get_drvdata(rdev);
110 u8 bit = (rdev_get_id(rdev) == MAX8660_V3) ? 1 : 4;
Sachin Kamatf920ec72014-03-18 15:53:02 +0530111
Wolfram Sang27f37e42009-09-25 09:39:26 +0200112 return max8660_write(max8660, MAX8660_OVER1, 0xff, bit);
113}
114
115static int max8660_dcdc_disable(struct regulator_dev *rdev)
116{
117 struct max8660 *max8660 = rdev_get_drvdata(rdev);
118 u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? ~1 : ~4;
Sachin Kamatf920ec72014-03-18 15:53:02 +0530119
Wolfram Sang27f37e42009-09-25 09:39:26 +0200120 return max8660_write(max8660, MAX8660_OVER1, mask, 0);
121}
122
Axel Lin9392c4f2012-05-15 21:42:12 +0800123static int max8660_dcdc_get_voltage_sel(struct regulator_dev *rdev)
Wolfram Sang27f37e42009-09-25 09:39:26 +0200124{
125 struct max8660 *max8660 = rdev_get_drvdata(rdev);
126 u8 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2;
127 u8 selector = max8660->shadow_regs[reg];
Sachin Kamatf920ec72014-03-18 15:53:02 +0530128
Axel Lin9392c4f2012-05-15 21:42:12 +0800129 return selector;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200130}
131
Axel Lin5eb33942012-05-15 21:43:29 +0800132static int max8660_dcdc_set_voltage_sel(struct regulator_dev *rdev,
133 unsigned int selector)
Wolfram Sang27f37e42009-09-25 09:39:26 +0200134{
135 struct max8660 *max8660 = rdev_get_drvdata(rdev);
Axel Lin5eb33942012-05-15 21:43:29 +0800136 u8 reg, bits;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200137 int ret;
138
Wolfram Sang27f37e42009-09-25 09:39:26 +0200139 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2;
140 ret = max8660_write(max8660, reg, 0, selector);
141 if (ret)
142 return ret;
143
144 /* Select target voltage register and activate regulation */
145 bits = (rdev_get_id(rdev) == MAX8660_V3) ? 0x03 : 0x30;
146 return max8660_write(max8660, MAX8660_VCC1, 0xff, bits);
147}
148
149static struct regulator_ops max8660_dcdc_ops = {
150 .is_enabled = max8660_dcdc_is_enabled,
Axel Lin134d34a2012-05-15 21:41:18 +0800151 .list_voltage = regulator_list_voltage_linear,
Axel Lin5eb33942012-05-15 21:43:29 +0800152 .map_voltage = regulator_map_voltage_linear,
153 .set_voltage_sel = max8660_dcdc_set_voltage_sel,
Axel Lin9392c4f2012-05-15 21:42:12 +0800154 .get_voltage_sel = max8660_dcdc_get_voltage_sel,
Wolfram Sang27f37e42009-09-25 09:39:26 +0200155};
156
157
158/*
159 * LDO5 functions
160 */
161
Axel Lin9392c4f2012-05-15 21:42:12 +0800162static int max8660_ldo5_get_voltage_sel(struct regulator_dev *rdev)
Wolfram Sang27f37e42009-09-25 09:39:26 +0200163{
164 struct max8660 *max8660 = rdev_get_drvdata(rdev);
Wolfram Sang27f37e42009-09-25 09:39:26 +0200165
Axel Lin9392c4f2012-05-15 21:42:12 +0800166 u8 selector = max8660->shadow_regs[MAX8660_MDTV2];
167 return selector;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200168}
169
Axel Lin5eb33942012-05-15 21:43:29 +0800170static int max8660_ldo5_set_voltage_sel(struct regulator_dev *rdev,
171 unsigned int selector)
Wolfram Sang27f37e42009-09-25 09:39:26 +0200172{
173 struct max8660 *max8660 = rdev_get_drvdata(rdev);
Wolfram Sang27f37e42009-09-25 09:39:26 +0200174 int ret;
175
Wolfram Sang27f37e42009-09-25 09:39:26 +0200176 ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector);
177 if (ret)
178 return ret;
179
180 /* Select target voltage register and activate regulation */
181 return max8660_write(max8660, MAX8660_VCC1, 0xff, 0xc0);
182}
183
Krzysztof Kozlowski8c2cd462017-03-11 21:01:20 +0200184static const struct regulator_ops max8660_ldo5_ops = {
Axel Lin134d34a2012-05-15 21:41:18 +0800185 .list_voltage = regulator_list_voltage_linear,
Axel Lin5eb33942012-05-15 21:43:29 +0800186 .map_voltage = regulator_map_voltage_linear,
187 .set_voltage_sel = max8660_ldo5_set_voltage_sel,
Axel Lin9392c4f2012-05-15 21:42:12 +0800188 .get_voltage_sel = max8660_ldo5_get_voltage_sel,
Wolfram Sang27f37e42009-09-25 09:39:26 +0200189};
190
191
192/*
193 * LDO67 functions
194 */
195
196static int max8660_ldo67_is_enabled(struct regulator_dev *rdev)
197{
198 struct max8660 *max8660 = rdev_get_drvdata(rdev);
199 u8 val = max8660->shadow_regs[MAX8660_OVER2];
200 u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? 2 : 4;
Sachin Kamatf920ec72014-03-18 15:53:02 +0530201
Wolfram Sang27f37e42009-09-25 09:39:26 +0200202 return !!(val & mask);
203}
204
205static int max8660_ldo67_enable(struct regulator_dev *rdev)
206{
207 struct max8660 *max8660 = rdev_get_drvdata(rdev);
208 u8 bit = (rdev_get_id(rdev) == MAX8660_V6) ? 2 : 4;
Sachin Kamatf920ec72014-03-18 15:53:02 +0530209
Wolfram Sang27f37e42009-09-25 09:39:26 +0200210 return max8660_write(max8660, MAX8660_OVER2, 0xff, bit);
211}
212
213static int max8660_ldo67_disable(struct regulator_dev *rdev)
214{
215 struct max8660 *max8660 = rdev_get_drvdata(rdev);
216 u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? ~2 : ~4;
Sachin Kamatf920ec72014-03-18 15:53:02 +0530217
Wolfram Sang27f37e42009-09-25 09:39:26 +0200218 return max8660_write(max8660, MAX8660_OVER2, mask, 0);
219}
220
Axel Lin9392c4f2012-05-15 21:42:12 +0800221static int max8660_ldo67_get_voltage_sel(struct regulator_dev *rdev)
Wolfram Sang27f37e42009-09-25 09:39:26 +0200222{
223 struct max8660 *max8660 = rdev_get_drvdata(rdev);
224 u8 shift = (rdev_get_id(rdev) == MAX8660_V6) ? 0 : 4;
225 u8 selector = (max8660->shadow_regs[MAX8660_L12VCR] >> shift) & 0xf;
Sachin Kamatf920ec72014-03-18 15:53:02 +0530226
Axel Lin9392c4f2012-05-15 21:42:12 +0800227 return selector;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200228}
229
Axel Lin5eb33942012-05-15 21:43:29 +0800230static int max8660_ldo67_set_voltage_sel(struct regulator_dev *rdev,
231 unsigned int selector)
Wolfram Sang27f37e42009-09-25 09:39:26 +0200232{
233 struct max8660 *max8660 = rdev_get_drvdata(rdev);
Mark Brown3a93f2a2010-11-10 14:38:29 +0000234
Wolfram Sang27f37e42009-09-25 09:39:26 +0200235 if (rdev_get_id(rdev) == MAX8660_V6)
236 return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector);
237 else
Axel Lin5eb33942012-05-15 21:43:29 +0800238 return max8660_write(max8660, MAX8660_L12VCR, 0x0f,
239 selector << 4);
Wolfram Sang27f37e42009-09-25 09:39:26 +0200240}
241
Krzysztof Kozlowski8c2cd462017-03-11 21:01:20 +0200242static const struct regulator_ops max8660_ldo67_ops = {
Wolfram Sang27f37e42009-09-25 09:39:26 +0200243 .is_enabled = max8660_ldo67_is_enabled,
244 .enable = max8660_ldo67_enable,
245 .disable = max8660_ldo67_disable,
Axel Lin134d34a2012-05-15 21:41:18 +0800246 .list_voltage = regulator_list_voltage_linear,
Axel Lin5eb33942012-05-15 21:43:29 +0800247 .map_voltage = regulator_map_voltage_linear,
Axel Lin9392c4f2012-05-15 21:42:12 +0800248 .get_voltage_sel = max8660_ldo67_get_voltage_sel,
Axel Lin5eb33942012-05-15 21:43:29 +0800249 .set_voltage_sel = max8660_ldo67_set_voltage_sel,
Wolfram Sang27f37e42009-09-25 09:39:26 +0200250};
251
Axel Lin621adb32012-04-06 08:26:59 +0800252static const struct regulator_desc max8660_reg[] = {
Wolfram Sang27f37e42009-09-25 09:39:26 +0200253 {
254 .name = "V3(DCDC)",
255 .id = MAX8660_V3,
256 .ops = &max8660_dcdc_ops,
257 .type = REGULATOR_VOLTAGE,
258 .n_voltages = MAX8660_DCDC_MAX_SEL + 1,
259 .owner = THIS_MODULE,
Axel Lin134d34a2012-05-15 21:41:18 +0800260 .min_uV = MAX8660_DCDC_MIN_UV,
261 .uV_step = MAX8660_DCDC_STEP,
Wolfram Sang27f37e42009-09-25 09:39:26 +0200262 },
263 {
264 .name = "V4(DCDC)",
265 .id = MAX8660_V4,
266 .ops = &max8660_dcdc_ops,
267 .type = REGULATOR_VOLTAGE,
268 .n_voltages = MAX8660_DCDC_MAX_SEL + 1,
269 .owner = THIS_MODULE,
Axel Lin134d34a2012-05-15 21:41:18 +0800270 .min_uV = MAX8660_DCDC_MIN_UV,
271 .uV_step = MAX8660_DCDC_STEP,
Wolfram Sang27f37e42009-09-25 09:39:26 +0200272 },
273 {
274 .name = "V5(LDO)",
275 .id = MAX8660_V5,
276 .ops = &max8660_ldo5_ops,
277 .type = REGULATOR_VOLTAGE,
278 .n_voltages = MAX8660_LDO5_MAX_SEL + 1,
279 .owner = THIS_MODULE,
Axel Lin134d34a2012-05-15 21:41:18 +0800280 .min_uV = MAX8660_LDO5_MIN_UV,
281 .uV_step = MAX8660_LDO5_STEP,
Wolfram Sang27f37e42009-09-25 09:39:26 +0200282 },
283 {
284 .name = "V6(LDO)",
285 .id = MAX8660_V6,
286 .ops = &max8660_ldo67_ops,
287 .type = REGULATOR_VOLTAGE,
288 .n_voltages = MAX8660_LDO67_MAX_SEL + 1,
289 .owner = THIS_MODULE,
Axel Lin134d34a2012-05-15 21:41:18 +0800290 .min_uV = MAX8660_LDO67_MIN_UV,
291 .uV_step = MAX8660_LDO67_STEP,
Wolfram Sang27f37e42009-09-25 09:39:26 +0200292 },
293 {
294 .name = "V7(LDO)",
295 .id = MAX8660_V7,
296 .ops = &max8660_ldo67_ops,
297 .type = REGULATOR_VOLTAGE,
298 .n_voltages = MAX8660_LDO67_MAX_SEL + 1,
299 .owner = THIS_MODULE,
Axel Lin134d34a2012-05-15 21:41:18 +0800300 .min_uV = MAX8660_LDO67_MIN_UV,
301 .uV_step = MAX8660_LDO67_STEP,
Wolfram Sang27f37e42009-09-25 09:39:26 +0200302 },
303};
304
Daniel Mack4a678f02013-08-02 10:19:15 +0200305enum {
306 MAX8660 = 0,
307 MAX8661 = 1,
308};
309
Daniel Mackabe4c512013-08-02 12:59:44 +0200310#ifdef CONFIG_OF
311static const struct of_device_id max8660_dt_ids[] = {
312 { .compatible = "maxim,max8660", .data = (void *) MAX8660 },
313 { .compatible = "maxim,max8661", .data = (void *) MAX8661 },
314 { }
315};
316MODULE_DEVICE_TABLE(of, max8660_dt_ids);
317
318static int max8660_pdata_from_dt(struct device *dev,
319 struct device_node **of_node,
320 struct max8660_platform_data *pdata)
321{
322 int matched, i;
323 struct device_node *np;
324 struct max8660_subdev_data *sub;
Javier Martinez Canillasc9889802014-11-03 15:40:43 +0100325 struct of_regulator_match rmatch[ARRAY_SIZE(max8660_reg)] = { };
Daniel Mackabe4c512013-08-02 12:59:44 +0200326
Sachin Kamat826adb42014-02-14 17:19:49 +0530327 np = of_get_child_by_name(dev->of_node, "regulators");
Daniel Mackabe4c512013-08-02 12:59:44 +0200328 if (!np) {
329 dev_err(dev, "missing 'regulators' subnode in DT\n");
330 return -EINVAL;
331 }
332
333 for (i = 0; i < ARRAY_SIZE(rmatch); i++)
334 rmatch[i].name = max8660_reg[i].name;
335
336 matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(rmatch));
Sachin Kamatcde248f2014-02-17 14:33:34 +0530337 of_node_put(np);
Daniel Mackabe4c512013-08-02 12:59:44 +0200338 if (matched <= 0)
339 return matched;
340
Kees Cooka86854d2018-06-12 14:07:58 -0700341 pdata->subdevs = devm_kcalloc(dev,
342 matched,
343 sizeof(struct max8660_subdev_data),
344 GFP_KERNEL);
Daniel Mackabe4c512013-08-02 12:59:44 +0200345 if (!pdata->subdevs)
346 return -ENOMEM;
347
348 pdata->num_subdevs = matched;
349 sub = pdata->subdevs;
350
351 for (i = 0; i < matched; i++) {
352 sub->id = i;
353 sub->name = rmatch[i].name;
354 sub->platform_data = rmatch[i].init_data;
355 of_node[i] = rmatch[i].of_node;
356 sub++;
357 }
358
359 return 0;
360}
361#else
362static inline int max8660_pdata_from_dt(struct device *dev,
363 struct device_node **of_node,
Daniel Mackd6c7e112013-08-08 12:02:18 +0200364 struct max8660_platform_data *pdata)
Daniel Mackabe4c512013-08-02 12:59:44 +0200365{
366 return 0;
367}
368#endif
369
Bill Pembertona5023572012-11-19 13:22:22 -0500370static int max8660_probe(struct i2c_client *client,
Dmitry Torokhov308f1002010-02-23 23:38:28 -0800371 const struct i2c_device_id *i2c_id)
Wolfram Sang27f37e42009-09-25 09:39:26 +0200372{
Daniel Mackde492e82013-08-02 10:19:16 +0200373 struct device *dev = &client->dev;
Colin Ian Kingdfb85ba2015-04-07 23:06:46 +0100374 struct max8660_platform_data pdata_of, *pdata = dev_get_platdata(dev);
Mark Brownc172708d2012-04-04 00:50:22 +0100375 struct regulator_config config = { };
Wolfram Sang27f37e42009-09-25 09:39:26 +0200376 struct max8660 *max8660;
377 int boot_on, i, id, ret = -EINVAL;
Daniel Mackabe4c512013-08-02 12:59:44 +0200378 struct device_node *of_node[MAX8660_V_END];
Daniel Mackd6c7e112013-08-08 12:02:18 +0200379 unsigned long type;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200380
Daniel Mackabe4c512013-08-02 12:59:44 +0200381 if (dev->of_node && !pdata) {
382 const struct of_device_id *id;
Daniel Mackabe4c512013-08-02 12:59:44 +0200383
384 id = of_match_device(of_match_ptr(max8660_dt_ids), dev);
385 if (!id)
386 return -ENODEV;
387
388 ret = max8660_pdata_from_dt(dev, of_node, &pdata_of);
389 if (ret < 0)
390 return ret;
391
392 pdata = &pdata_of;
Daniel Mackd6c7e112013-08-08 12:02:18 +0200393 type = (unsigned long) id->data;
Daniel Mackabe4c512013-08-02 12:59:44 +0200394 } else {
395 type = i2c_id->driver_data;
396 memset(of_node, 0, sizeof(of_node));
397 }
398
Wolfram Sang27f37e42009-09-25 09:39:26 +0200399 if (pdata->num_subdevs > MAX8660_V_END) {
Daniel Mackde492e82013-08-02 10:19:16 +0200400 dev_err(dev, "Too many regulators found!\n");
Axel Lin4d26f7d2012-04-11 23:08:27 +0800401 return -EINVAL;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200402 }
403
Krzysztof Kozlowski67f76a92014-03-10 10:37:19 +0100404 max8660 = devm_kzalloc(dev, sizeof(struct max8660), GFP_KERNEL);
Axel Lin4d26f7d2012-04-11 23:08:27 +0800405 if (!max8660)
406 return -ENOMEM;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200407
408 max8660->client = client;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200409
410 if (pdata->en34_is_high) {
411 /* Simulate always on */
412 max8660->shadow_regs[MAX8660_OVER1] = 5;
413 } else {
414 /* Otherwise devices can be toggled via software */
415 max8660_dcdc_ops.enable = max8660_dcdc_enable;
416 max8660_dcdc_ops.disable = max8660_dcdc_disable;
417 }
418
419 /*
420 * First, set up shadow registers to prevent glitches. As some
421 * registers are shared between regulators, everything must be properly
422 * set up for all regulators in advance.
423 */
424 max8660->shadow_regs[MAX8660_ADTV1] =
425 max8660->shadow_regs[MAX8660_ADTV2] =
426 max8660->shadow_regs[MAX8660_SDTV1] =
427 max8660->shadow_regs[MAX8660_SDTV2] = 0x1b;
428 max8660->shadow_regs[MAX8660_MDTV1] =
429 max8660->shadow_regs[MAX8660_MDTV2] = 0x04;
430
431 for (i = 0; i < pdata->num_subdevs; i++) {
432
433 if (!pdata->subdevs[i].platform_data)
Markus Pargmannc0cf5a592015-04-10 15:23:42 +0200434 boot_on = false;
435 else
436 boot_on = pdata->subdevs[i].platform_data->constraints.boot_on;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200437
438 switch (pdata->subdevs[i].id) {
439 case MAX8660_V3:
440 if (boot_on)
441 max8660->shadow_regs[MAX8660_OVER1] |= 1;
442 break;
443
444 case MAX8660_V4:
445 if (boot_on)
446 max8660->shadow_regs[MAX8660_OVER1] |= 4;
447 break;
448
449 case MAX8660_V5:
450 break;
451
452 case MAX8660_V6:
453 if (boot_on)
454 max8660->shadow_regs[MAX8660_OVER2] |= 2;
455 break;
456
457 case MAX8660_V7:
Daniel Mack4a678f02013-08-02 10:19:15 +0200458 if (type == MAX8661) {
Daniel Mackde492e82013-08-02 10:19:16 +0200459 dev_err(dev, "Regulator not on this chip!\n");
Sachin Kamatdcfb6b52013-09-04 11:07:58 +0530460 return -EINVAL;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200461 }
462
463 if (boot_on)
464 max8660->shadow_regs[MAX8660_OVER2] |= 4;
465 break;
466
467 default:
Daniel Mackde492e82013-08-02 10:19:16 +0200468 dev_err(dev, "invalid regulator %s\n",
Wolfram Sang27f37e42009-09-25 09:39:26 +0200469 pdata->subdevs[i].name);
Sachin Kamatdcfb6b52013-09-04 11:07:58 +0530470 return ret;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200471 }
472 }
473
474 /* Finally register devices */
475 for (i = 0; i < pdata->num_subdevs; i++) {
Krzysztof Kozlowski67f76a92014-03-10 10:37:19 +0100476 struct regulator_dev *rdev;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200477
478 id = pdata->subdevs[i].id;
479
Daniel Mackde492e82013-08-02 10:19:16 +0200480 config.dev = dev;
Mark Brownc172708d2012-04-04 00:50:22 +0100481 config.init_data = pdata->subdevs[i].platform_data;
Daniel Mackabe4c512013-08-02 12:59:44 +0200482 config.of_node = of_node[i];
Mark Brownc172708d2012-04-04 00:50:22 +0100483 config.driver_data = max8660;
484
Krzysztof Kozlowski67f76a92014-03-10 10:37:19 +0100485 rdev = devm_regulator_register(&client->dev,
Sachin Kamatdcfb6b52013-09-04 11:07:58 +0530486 &max8660_reg[id], &config);
Krzysztof Kozlowski67f76a92014-03-10 10:37:19 +0100487 if (IS_ERR(rdev)) {
Sachin Kamatdcfb6b52013-09-04 11:07:58 +0530488 dev_err(&client->dev, "failed to register %s\n",
Wolfram Sang27f37e42009-09-25 09:39:26 +0200489 max8660_reg[id].name);
Krzysztof Kozlowski67f76a92014-03-10 10:37:19 +0100490 return PTR_ERR(rdev);
Wolfram Sang27f37e42009-09-25 09:39:26 +0200491 }
492 }
493
Axel Lin53a4bef2010-08-06 13:35:27 +0800494 i2c_set_clientdata(client, max8660);
Wolfram Sang27f37e42009-09-25 09:39:26 +0200495 return 0;
Wolfram Sang27f37e42009-09-25 09:39:26 +0200496}
497
498static const struct i2c_device_id max8660_id[] = {
Daniel Mack4a678f02013-08-02 10:19:15 +0200499 { .name = "max8660", .driver_data = MAX8660 },
500 { .name = "max8661", .driver_data = MAX8661 },
Wolfram Sang27f37e42009-09-25 09:39:26 +0200501 { }
502};
503MODULE_DEVICE_TABLE(i2c, max8660_id);
504
505static struct i2c_driver max8660_driver = {
506 .probe = max8660_probe,
Wolfram Sang27f37e42009-09-25 09:39:26 +0200507 .driver = {
508 .name = "max8660",
Wolfram Sang27f37e42009-09-25 09:39:26 +0200509 },
510 .id_table = max8660_id,
511};
512
513static int __init max8660_init(void)
514{
515 return i2c_add_driver(&max8660_driver);
516}
517subsys_initcall(max8660_init);
518
519static void __exit max8660_exit(void)
520{
521 i2c_del_driver(&max8660_driver);
522}
523module_exit(max8660_exit);
524
525/* Module information */
526MODULE_DESCRIPTION("MAXIM 8660/8661 voltage regulator driver");
527MODULE_AUTHOR("Wolfram Sang");
528MODULE_LICENSE("GPL v2");