blob: 10d206266ac27770ec25efa16e94f5eb658a891b [file] [log] [blame]
Jonghwa Lee133d4012012-06-01 13:17:14 +09001/*
2 * max77686.c - Regulator driver for the Maxim 77686
3 *
4 * Copyright (C) 2012 Samsung Electronics
5 * Chiwoong Byun <woong.byun@smasung.com>
6 * Jonghwa Lee <jonghwa3.lee@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * This driver is based on max8997.c
23 */
24
25#include <linux/kernel.h>
26#include <linux/bug.h>
Jonghwa Lee133d4012012-06-01 13:17:14 +090027#include <linux/err.h>
28#include <linux/gpio.h>
29#include <linux/slab.h>
30#include <linux/platform_device.h>
31#include <linux/regulator/driver.h>
32#include <linux/regulator/machine.h>
Yadwinder Singh Brar4706fca2012-07-05 09:28:25 +053033#include <linux/regulator/of_regulator.h>
Jonghwa Lee133d4012012-06-01 13:17:14 +090034#include <linux/mfd/max77686.h>
35#include <linux/mfd/max77686-private.h>
36
37#define MAX77686_LDO_MINUV 800000
38#define MAX77686_LDO_UVSTEP 50000
39#define MAX77686_LDO_LOW_MINUV 800000
40#define MAX77686_LDO_LOW_UVSTEP 25000
41#define MAX77686_BUCK_MINUV 750000
42#define MAX77686_BUCK_UVSTEP 50000
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +053043#define MAX77686_RAMP_DELAY 100000 /* uV/us */
44#define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */
Jonghwa Lee133d4012012-06-01 13:17:14 +090045#define MAX77686_DVS_MINUV 600000
46#define MAX77686_DVS_UVSTEP 12500
47
Krzysztof Kozlowski7636f192014-10-27 13:11:47 +010048/*
49 * Values used for configuring LDOs and bucks.
50 * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
51 */
52#define MAX77686_LDO_LOWPOWER 0x1
53/*
54 * On/off controlled by PWRREQ:
55 * - LDO2, 6-8, 10-12, 14-16
56 * - buck[1234]
57 */
58#define MAX77686_OFF_PWRREQ 0x1
59/* Low power mode controlled by PWRREQ: All LDOs */
60#define MAX77686_LDO_LOWPOWER_PWRREQ 0x2
61/* Forcing low power mode: buck[234] */
62#define MAX77686_BUCK_LOWPOWER 0x2
63#define MAX77686_NORMAL 0x3
64
Jonghwa Lee133d4012012-06-01 13:17:14 +090065#define MAX77686_OPMODE_SHIFT 6
66#define MAX77686_OPMODE_BUCK234_SHIFT 4
67#define MAX77686_OPMODE_MASK 0x3
68
69#define MAX77686_VSEL_MASK 0x3F
70#define MAX77686_DVS_VSEL_MASK 0xFF
71
72#define MAX77686_RAMP_RATE_MASK 0xC0
73
74#define MAX77686_REGULATORS MAX77686_REG_MAX
75#define MAX77686_LDOS 26
76
77enum max77686_ramp_rate {
78 RAMP_RATE_13P75MV,
79 RAMP_RATE_27P5MV,
80 RAMP_RATE_55MV,
81 RAMP_RATE_NO_CTRL, /* 100mV/us */
82};
83
84struct max77686_data {
Krzysztof Kozlowskieca29da2014-11-04 09:49:41 +010085 /* Array indexed by regulator id */
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +053086 unsigned int opmode[MAX77686_REGULATORS];
Jonghwa Lee133d4012012-06-01 13:17:14 +090087};
88
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +010089static unsigned int max77686_get_opmode_shift(int id)
90{
91 switch (id) {
92 case MAX77686_BUCK1:
93 case MAX77686_BUCK5 ... MAX77686_BUCK9:
94 return 0;
95 case MAX77686_BUCK2 ... MAX77686_BUCK4:
96 return MAX77686_OPMODE_BUCK234_SHIFT;
97 default:
98 /* all LDOs */
99 return MAX77686_OPMODE_SHIFT;
100 }
101}
102
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100103/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
104static int max77686_set_suspend_disable(struct regulator_dev *rdev)
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530105{
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100106 unsigned int val, shift;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530107 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Axel Lin3ecf1982013-04-27 16:18:16 +0800108 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530109
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100110 shift = max77686_get_opmode_shift(id);
111 val = MAX77686_OFF_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530112
Axel Lin3ecf1982013-04-27 16:18:16 +0800113 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100114 rdev->desc->enable_mask, val << shift);
Axel Lin3ecf1982013-04-27 16:18:16 +0800115 if (ret)
116 return ret;
117
Thiago Farina40e72142013-02-13 17:52:26 -0200118 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800119 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530120}
121
122/* Some LDOs supports [LPM/Normal]ON mode during suspend state */
123static int max77686_set_suspend_mode(struct regulator_dev *rdev,
124 unsigned int mode)
125{
126 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
127 unsigned int val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800128 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530129
130 /* BUCK[5-9] doesn't support this feature */
Thiago Farina40e72142013-02-13 17:52:26 -0200131 if (id >= MAX77686_BUCK5)
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530132 return 0;
133
134 switch (mode) {
135 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100136 val = MAX77686_LDO_LOWPOWER_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530137 break;
138 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100139 val = MAX77686_NORMAL;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530140 break;
141 default:
142 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
143 rdev->desc->name, mode);
144 return -EINVAL;
145 }
146
Axel Lin3ecf1982013-04-27 16:18:16 +0800147 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100148 rdev->desc->enable_mask,
149 val << MAX77686_OPMODE_SHIFT);
Axel Lin3ecf1982013-04-27 16:18:16 +0800150 if (ret)
151 return ret;
152
Thiago Farina40e72142013-02-13 17:52:26 -0200153 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800154 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530155}
156
157/* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */
158static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
159 unsigned int mode)
160{
161 unsigned int val;
162 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Axel Lin3ecf1982013-04-27 16:18:16 +0800163 int ret;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530164
165 switch (mode) {
166 case REGULATOR_MODE_STANDBY: /* switch off */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100167 val = MAX77686_OFF_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530168 break;
169 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100170 val = MAX77686_LDO_LOWPOWER_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530171 break;
172 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100173 val = MAX77686_NORMAL;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530174 break;
175 default:
176 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
177 rdev->desc->name, mode);
178 return -EINVAL;
179 }
180
Axel Lin3ecf1982013-04-27 16:18:16 +0800181 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100182 rdev->desc->enable_mask,
183 val << MAX77686_OPMODE_SHIFT);
Axel Lin3ecf1982013-04-27 16:18:16 +0800184 if (ret)
185 return ret;
186
Thiago Farina40e72142013-02-13 17:52:26 -0200187 max77686->opmode[rdev_get_id(rdev)] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800188 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530189}
190
Yadwinder Singh Brar38d34032012-10-22 09:39:28 +0530191static int max77686_enable(struct regulator_dev *rdev)
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530192{
193 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100194 unsigned int shift;
195 int id = rdev_get_id(rdev);
196
197 shift = max77686_get_opmode_shift(id);
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530198
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100199 if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
200 max77686->opmode[id] = MAX77686_NORMAL;
201
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530202 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
203 rdev->desc->enable_mask,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100204 max77686->opmode[id] << shift);
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530205}
206
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530207static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
208{
209 unsigned int ramp_value = RAMP_RATE_NO_CTRL;
210
211 switch (ramp_delay) {
212 case 1 ... 13750:
213 ramp_value = RAMP_RATE_13P75MV;
214 break;
215 case 13751 ... 27500:
216 ramp_value = RAMP_RATE_27P5MV;
217 break;
218 case 27501 ... 55000:
219 ramp_value = RAMP_RATE_55MV;
220 break;
221 case 55001 ... 100000:
222 break;
223 default:
224 pr_warn("%s: ramp_delay: %d not supported, setting 100000\n",
225 rdev->desc->name, ramp_delay);
226 }
227
228 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
229 MAX77686_RAMP_RATE_MASK, ramp_value << 6);
230}
231
Jonghwa Lee133d4012012-06-01 13:17:14 +0900232static struct regulator_ops max77686_ops = {
233 .list_voltage = regulator_list_voltage_linear,
Axel Lin2e3f7f22012-06-03 22:46:14 +0800234 .map_voltage = regulator_map_voltage_linear,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900235 .is_enabled = regulator_is_enabled_regmap,
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530236 .enable = max77686_enable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900237 .disable = regulator_disable_regmap,
238 .get_voltage_sel = regulator_get_voltage_sel_regmap,
239 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530240 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530241 .set_suspend_mode = max77686_set_suspend_mode,
242};
243
244static struct regulator_ops max77686_ldo_ops = {
245 .list_voltage = regulator_list_voltage_linear,
246 .map_voltage = regulator_map_voltage_linear,
247 .is_enabled = regulator_is_enabled_regmap,
248 .enable = max77686_enable,
249 .disable = regulator_disable_regmap,
250 .get_voltage_sel = regulator_get_voltage_sel_regmap,
251 .set_voltage_sel = regulator_set_voltage_sel_regmap,
252 .set_voltage_time_sel = regulator_set_voltage_time_sel,
253 .set_suspend_mode = max77686_ldo_set_suspend_mode,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100254 .set_suspend_disable = max77686_set_suspend_disable,
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530255};
256
257static struct regulator_ops max77686_buck1_ops = {
258 .list_voltage = regulator_list_voltage_linear,
259 .map_voltage = regulator_map_voltage_linear,
260 .is_enabled = regulator_is_enabled_regmap,
261 .enable = max77686_enable,
262 .disable = regulator_disable_regmap,
263 .get_voltage_sel = regulator_get_voltage_sel_regmap,
264 .set_voltage_sel = regulator_set_voltage_sel_regmap,
265 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100266 .set_suspend_disable = max77686_set_suspend_disable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900267};
268
269static struct regulator_ops max77686_buck_dvs_ops = {
270 .list_voltage = regulator_list_voltage_linear,
Axel Lin2e3f7f22012-06-03 22:46:14 +0800271 .map_voltage = regulator_map_voltage_linear,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900272 .is_enabled = regulator_is_enabled_regmap,
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530273 .enable = max77686_enable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900274 .disable = regulator_disable_regmap,
275 .get_voltage_sel = regulator_get_voltage_sel_regmap,
276 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530277 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530278 .set_ramp_delay = max77686_set_ramp_delay,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100279 .set_suspend_disable = max77686_set_suspend_disable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900280};
281
282#define regulator_desc_ldo(num) { \
283 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100284 .of_match = of_match_ptr("LDO"#num), \
285 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900286 .id = MAX77686_LDO##num, \
287 .ops = &max77686_ops, \
288 .type = REGULATOR_VOLTAGE, \
289 .owner = THIS_MODULE, \
290 .min_uV = MAX77686_LDO_MINUV, \
291 .uV_step = MAX77686_LDO_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530292 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900293 .n_voltages = MAX77686_VSEL_MASK + 1, \
294 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
295 .vsel_mask = MAX77686_VSEL_MASK, \
296 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
297 .enable_mask = MAX77686_OPMODE_MASK \
298 << MAX77686_OPMODE_SHIFT, \
299}
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530300#define regulator_desc_lpm_ldo(num) { \
301 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100302 .of_match = of_match_ptr("LDO"#num), \
303 .regulators_node = of_match_ptr("voltage-regulators"), \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530304 .id = MAX77686_LDO##num, \
305 .ops = &max77686_ldo_ops, \
306 .type = REGULATOR_VOLTAGE, \
307 .owner = THIS_MODULE, \
308 .min_uV = MAX77686_LDO_MINUV, \
309 .uV_step = MAX77686_LDO_UVSTEP, \
310 .ramp_delay = MAX77686_RAMP_DELAY, \
311 .n_voltages = MAX77686_VSEL_MASK + 1, \
312 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
313 .vsel_mask = MAX77686_VSEL_MASK, \
314 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
315 .enable_mask = MAX77686_OPMODE_MASK \
316 << MAX77686_OPMODE_SHIFT, \
317}
Jonghwa Lee133d4012012-06-01 13:17:14 +0900318#define regulator_desc_ldo_low(num) { \
319 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100320 .of_match = of_match_ptr("LDO"#num), \
321 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900322 .id = MAX77686_LDO##num, \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530323 .ops = &max77686_ldo_ops, \
324 .type = REGULATOR_VOLTAGE, \
325 .owner = THIS_MODULE, \
326 .min_uV = MAX77686_LDO_LOW_MINUV, \
327 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
328 .ramp_delay = MAX77686_RAMP_DELAY, \
329 .n_voltages = MAX77686_VSEL_MASK + 1, \
330 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
331 .vsel_mask = MAX77686_VSEL_MASK, \
332 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
333 .enable_mask = MAX77686_OPMODE_MASK \
334 << MAX77686_OPMODE_SHIFT, \
335}
336#define regulator_desc_ldo1_low(num) { \
337 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100338 .of_match = of_match_ptr("LDO"#num), \
339 .regulators_node = of_match_ptr("voltage-regulators"), \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530340 .id = MAX77686_LDO##num, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900341 .ops = &max77686_ops, \
342 .type = REGULATOR_VOLTAGE, \
343 .owner = THIS_MODULE, \
344 .min_uV = MAX77686_LDO_LOW_MINUV, \
345 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530346 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900347 .n_voltages = MAX77686_VSEL_MASK + 1, \
348 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
349 .vsel_mask = MAX77686_VSEL_MASK, \
350 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
351 .enable_mask = MAX77686_OPMODE_MASK \
352 << MAX77686_OPMODE_SHIFT, \
353}
354#define regulator_desc_buck(num) { \
355 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100356 .of_match = of_match_ptr("BUCK"#num), \
357 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900358 .id = MAX77686_BUCK##num, \
359 .ops = &max77686_ops, \
360 .type = REGULATOR_VOLTAGE, \
361 .owner = THIS_MODULE, \
362 .min_uV = MAX77686_BUCK_MINUV, \
363 .uV_step = MAX77686_BUCK_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530364 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900365 .n_voltages = MAX77686_VSEL_MASK + 1, \
366 .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \
367 .vsel_mask = MAX77686_VSEL_MASK, \
368 .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \
369 .enable_mask = MAX77686_OPMODE_MASK, \
370}
371#define regulator_desc_buck1(num) { \
372 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100373 .of_match = of_match_ptr("BUCK"#num), \
374 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900375 .id = MAX77686_BUCK##num, \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530376 .ops = &max77686_buck1_ops, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900377 .type = REGULATOR_VOLTAGE, \
378 .owner = THIS_MODULE, \
379 .min_uV = MAX77686_BUCK_MINUV, \
380 .uV_step = MAX77686_BUCK_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530381 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900382 .n_voltages = MAX77686_VSEL_MASK + 1, \
383 .vsel_reg = MAX77686_REG_BUCK1OUT, \
384 .vsel_mask = MAX77686_VSEL_MASK, \
385 .enable_reg = MAX77686_REG_BUCK1CTRL, \
386 .enable_mask = MAX77686_OPMODE_MASK, \
387}
388#define regulator_desc_buck_dvs(num) { \
389 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100390 .of_match = of_match_ptr("BUCK"#num), \
391 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900392 .id = MAX77686_BUCK##num, \
Axel Lin74adfee52012-06-04 10:19:18 +0800393 .ops = &max77686_buck_dvs_ops, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900394 .type = REGULATOR_VOLTAGE, \
395 .owner = THIS_MODULE, \
396 .min_uV = MAX77686_DVS_MINUV, \
397 .uV_step = MAX77686_DVS_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530398 .ramp_delay = MAX77686_DVS_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900399 .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \
400 .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \
401 .vsel_mask = MAX77686_DVS_VSEL_MASK, \
402 .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \
403 .enable_mask = MAX77686_OPMODE_MASK \
404 << MAX77686_OPMODE_BUCK234_SHIFT, \
405}
406
Krzysztof Kozlowski73dbdf82014-10-27 16:03:42 +0100407static const struct regulator_desc regulators[] = {
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530408 regulator_desc_ldo1_low(1),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900409 regulator_desc_ldo_low(2),
410 regulator_desc_ldo(3),
411 regulator_desc_ldo(4),
412 regulator_desc_ldo(5),
413 regulator_desc_ldo_low(6),
414 regulator_desc_ldo_low(7),
415 regulator_desc_ldo_low(8),
416 regulator_desc_ldo(9),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530417 regulator_desc_lpm_ldo(10),
418 regulator_desc_lpm_ldo(11),
419 regulator_desc_lpm_ldo(12),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900420 regulator_desc_ldo(13),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530421 regulator_desc_lpm_ldo(14),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900422 regulator_desc_ldo_low(15),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530423 regulator_desc_lpm_ldo(16),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900424 regulator_desc_ldo(17),
425 regulator_desc_ldo(18),
426 regulator_desc_ldo(19),
427 regulator_desc_ldo(20),
428 regulator_desc_ldo(21),
429 regulator_desc_ldo(22),
430 regulator_desc_ldo(23),
431 regulator_desc_ldo(24),
432 regulator_desc_ldo(25),
433 regulator_desc_ldo(26),
434 regulator_desc_buck1(1),
435 regulator_desc_buck_dvs(2),
436 regulator_desc_buck_dvs(3),
437 regulator_desc_buck_dvs(4),
438 regulator_desc_buck(5),
439 regulator_desc_buck(6),
440 regulator_desc_buck(7),
441 regulator_desc_buck(8),
442 regulator_desc_buck(9),
443};
444
Bill Pembertona5023572012-11-19 13:22:22 -0500445static int max77686_pmic_probe(struct platform_device *pdev)
Jonghwa Lee133d4012012-06-01 13:17:14 +0900446{
447 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
Jonghwa Lee133d4012012-06-01 13:17:14 +0900448 struct max77686_data *max77686;
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100449 int i;
Axel Linc59d2a62012-06-20 15:01:25 +0800450 struct regulator_config config = { };
Jonghwa Lee133d4012012-06-01 13:17:14 +0900451
452 dev_dbg(&pdev->dev, "%s\n", __func__);
453
454 max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
455 GFP_KERNEL);
456 if (!max77686)
457 return -ENOMEM;
458
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100459 config.dev = iodev->dev;
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530460 config.regmap = iodev->regmap;
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530461 config.driver_data = max77686;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900462 platform_set_drvdata(pdev, max77686);
463
Axel Linab0d1cb2012-06-08 12:03:04 +0800464 for (i = 0; i < MAX77686_REGULATORS; i++) {
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100465 struct regulator_dev *rdev;
Krzysztof Kozlowskieca29da2014-11-04 09:49:41 +0100466 int id = regulators[i].id;
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100467
Krzysztof Kozlowski4524df82014-11-04 09:49:42 +0100468 max77686->opmode[id] = MAX77686_NORMAL;
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100469 rdev = devm_regulator_register(&pdev->dev,
Sachin Kamat44815b42013-09-04 11:07:54 +0530470 &regulators[i], &config);
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100471 if (IS_ERR(rdev)) {
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100472 int ret = PTR_ERR(rdev);
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530473 dev_err(&pdev->dev,
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100474 "regulator init failed for %d: %d\n", i, ret);
475 return ret;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900476 }
Jonghwa Lee133d4012012-06-01 13:17:14 +0900477 }
Axel Linab0d1cb2012-06-08 12:03:04 +0800478
Jonghwa Lee133d4012012-06-01 13:17:14 +0900479 return 0;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900480}
481
482static const struct platform_device_id max77686_pmic_id[] = {
483 {"max77686-pmic", 0},
484 { },
485};
486MODULE_DEVICE_TABLE(platform, max77686_pmic_id);
487
488static struct platform_driver max77686_pmic_driver = {
489 .driver = {
490 .name = "max77686-pmic",
Jonghwa Lee133d4012012-06-01 13:17:14 +0900491 },
492 .probe = max77686_pmic_probe,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900493 .id_table = max77686_pmic_id,
494};
495
496static int __init max77686_pmic_init(void)
497{
498 return platform_driver_register(&max77686_pmic_driver);
499}
500subsys_initcall(max77686_pmic_init);
501
502static void __exit max77686_pmic_cleanup(void)
503{
504 platform_driver_unregister(&max77686_pmic_driver);
505}
506module_exit(max77686_pmic_cleanup);
507
508MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver");
509MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
510MODULE_LICENSE("GPL");