blob: 15fb1416bfbde99c9724644dd25bf106695fda97 [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>
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +010029#include <linux/of_gpio.h>
Jonghwa Lee133d4012012-06-01 13:17:14 +090030#include <linux/slab.h>
31#include <linux/platform_device.h>
32#include <linux/regulator/driver.h>
33#include <linux/regulator/machine.h>
Yadwinder Singh Brar4706fca2012-07-05 09:28:25 +053034#include <linux/regulator/of_regulator.h>
Jonghwa Lee133d4012012-06-01 13:17:14 +090035#include <linux/mfd/max77686.h>
36#include <linux/mfd/max77686-private.h>
37
38#define MAX77686_LDO_MINUV 800000
39#define MAX77686_LDO_UVSTEP 50000
40#define MAX77686_LDO_LOW_MINUV 800000
41#define MAX77686_LDO_LOW_UVSTEP 25000
42#define MAX77686_BUCK_MINUV 750000
43#define MAX77686_BUCK_UVSTEP 50000
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +053044#define MAX77686_RAMP_DELAY 100000 /* uV/us */
45#define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */
Jonghwa Lee133d4012012-06-01 13:17:14 +090046#define MAX77686_DVS_MINUV 600000
47#define MAX77686_DVS_UVSTEP 12500
48
Krzysztof Kozlowski7636f192014-10-27 13:11:47 +010049/*
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +010050 * Value for configuring buck[89] and LDO{20,21,22} as GPIO control.
51 * It is the same as 'off' for other regulators.
52 */
53#define MAX77686_GPIO_CONTROL 0x0
54/*
Krzysztof Kozlowski7636f192014-10-27 13:11:47 +010055 * Values used for configuring LDOs and bucks.
56 * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
57 */
58#define MAX77686_LDO_LOWPOWER 0x1
59/*
60 * On/off controlled by PWRREQ:
61 * - LDO2, 6-8, 10-12, 14-16
62 * - buck[1234]
63 */
64#define MAX77686_OFF_PWRREQ 0x1
65/* Low power mode controlled by PWRREQ: All LDOs */
66#define MAX77686_LDO_LOWPOWER_PWRREQ 0x2
67/* Forcing low power mode: buck[234] */
68#define MAX77686_BUCK_LOWPOWER 0x2
69#define MAX77686_NORMAL 0x3
70
Jonghwa Lee133d4012012-06-01 13:17:14 +090071#define MAX77686_OPMODE_SHIFT 6
72#define MAX77686_OPMODE_BUCK234_SHIFT 4
73#define MAX77686_OPMODE_MASK 0x3
74
75#define MAX77686_VSEL_MASK 0x3F
76#define MAX77686_DVS_VSEL_MASK 0xFF
77
78#define MAX77686_RAMP_RATE_MASK 0xC0
79
80#define MAX77686_REGULATORS MAX77686_REG_MAX
81#define MAX77686_LDOS 26
82
83enum max77686_ramp_rate {
84 RAMP_RATE_13P75MV,
85 RAMP_RATE_27P5MV,
86 RAMP_RATE_55MV,
87 RAMP_RATE_NO_CTRL, /* 100mV/us */
88};
89
90struct max77686_data {
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +010091 u64 gpio_enabled:MAX77686_REGULATORS;
92
Krzysztof Kozlowskieca29da2014-11-04 09:49:41 +010093 /* Array indexed by regulator id */
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +053094 unsigned int opmode[MAX77686_REGULATORS];
Jonghwa Lee133d4012012-06-01 13:17:14 +090095};
96
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +010097static unsigned int max77686_get_opmode_shift(int id)
98{
99 switch (id) {
100 case MAX77686_BUCK1:
101 case MAX77686_BUCK5 ... MAX77686_BUCK9:
102 return 0;
103 case MAX77686_BUCK2 ... MAX77686_BUCK4:
104 return MAX77686_OPMODE_BUCK234_SHIFT;
105 default:
106 /* all LDOs */
107 return MAX77686_OPMODE_SHIFT;
108 }
109}
110
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100111/*
112 * When regulator is configured for GPIO control then it
113 * replaces "normal" mode. Any change from low power mode to normal
114 * should actually change to GPIO control.
115 * Map normal mode to proper value for such regulators.
116 */
117static unsigned int max77686_map_normal_mode(struct max77686_data *max77686,
118 int id)
119{
120 switch (id) {
121 case MAX77686_BUCK8:
122 case MAX77686_BUCK9:
123 case MAX77686_LDO20 ... MAX77686_LDO22:
124 if (max77686->gpio_enabled & (1 << id))
125 return MAX77686_GPIO_CONTROL;
126 }
127
128 return MAX77686_NORMAL;
129}
130
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100131/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
132static int max77686_set_suspend_disable(struct regulator_dev *rdev)
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530133{
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100134 unsigned int val, shift;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530135 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Axel Lin3ecf1982013-04-27 16:18:16 +0800136 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530137
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100138 shift = max77686_get_opmode_shift(id);
139 val = MAX77686_OFF_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530140
Axel Lin3ecf1982013-04-27 16:18:16 +0800141 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100142 rdev->desc->enable_mask, val << shift);
Axel Lin3ecf1982013-04-27 16:18:16 +0800143 if (ret)
144 return ret;
145
Thiago Farina40e72142013-02-13 17:52:26 -0200146 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800147 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530148}
149
150/* Some LDOs supports [LPM/Normal]ON mode during suspend state */
151static int max77686_set_suspend_mode(struct regulator_dev *rdev,
152 unsigned int mode)
153{
154 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
155 unsigned int val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800156 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530157
158 /* BUCK[5-9] doesn't support this feature */
Thiago Farina40e72142013-02-13 17:52:26 -0200159 if (id >= MAX77686_BUCK5)
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530160 return 0;
161
162 switch (mode) {
163 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100164 val = MAX77686_LDO_LOWPOWER_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530165 break;
166 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100167 val = max77686_map_normal_mode(max77686, id);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530168 break;
169 default:
170 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
171 rdev->desc->name, mode);
172 return -EINVAL;
173 }
174
Axel Lin3ecf1982013-04-27 16:18:16 +0800175 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100176 rdev->desc->enable_mask,
177 val << MAX77686_OPMODE_SHIFT);
Axel Lin3ecf1982013-04-27 16:18:16 +0800178 if (ret)
179 return ret;
180
Thiago Farina40e72142013-02-13 17:52:26 -0200181 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800182 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530183}
184
185/* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */
186static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
187 unsigned int mode)
188{
189 unsigned int val;
190 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100191 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530192
193 switch (mode) {
194 case REGULATOR_MODE_STANDBY: /* switch off */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100195 val = MAX77686_OFF_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530196 break;
197 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100198 val = MAX77686_LDO_LOWPOWER_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530199 break;
200 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100201 val = max77686_map_normal_mode(max77686, id);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530202 break;
203 default:
204 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
205 rdev->desc->name, mode);
206 return -EINVAL;
207 }
208
Axel Lin3ecf1982013-04-27 16:18:16 +0800209 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100210 rdev->desc->enable_mask,
211 val << MAX77686_OPMODE_SHIFT);
Axel Lin3ecf1982013-04-27 16:18:16 +0800212 if (ret)
213 return ret;
214
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100215 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800216 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530217}
218
Yadwinder Singh Brar38d34032012-10-22 09:39:28 +0530219static int max77686_enable(struct regulator_dev *rdev)
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530220{
221 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100222 unsigned int shift;
223 int id = rdev_get_id(rdev);
224
225 shift = max77686_get_opmode_shift(id);
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530226
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100227 if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100228 max77686->opmode[id] = max77686_map_normal_mode(max77686, id);
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100229
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530230 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
231 rdev->desc->enable_mask,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100232 max77686->opmode[id] << shift);
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530233}
234
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530235static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
236{
237 unsigned int ramp_value = RAMP_RATE_NO_CTRL;
238
239 switch (ramp_delay) {
240 case 1 ... 13750:
241 ramp_value = RAMP_RATE_13P75MV;
242 break;
243 case 13751 ... 27500:
244 ramp_value = RAMP_RATE_27P5MV;
245 break;
246 case 27501 ... 55000:
247 ramp_value = RAMP_RATE_55MV;
248 break;
249 case 55001 ... 100000:
250 break;
251 default:
252 pr_warn("%s: ramp_delay: %d not supported, setting 100000\n",
253 rdev->desc->name, ramp_delay);
254 }
255
256 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
257 MAX77686_RAMP_RATE_MASK, ramp_value << 6);
258}
259
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100260static int max77686_of_parse_cb(struct device_node *np,
261 const struct regulator_desc *desc,
262 struct regulator_config *config)
263{
264 struct max77686_data *max77686 = config->driver_data;
265
266 switch (desc->id) {
267 case MAX77686_BUCK8:
268 case MAX77686_BUCK9:
269 case MAX77686_LDO20 ... MAX77686_LDO22:
270 config->ena_gpio = of_get_named_gpio(np,
271 "maxim,ena-gpios", 0);
272 config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
273 config->ena_gpio_initialized = true;
274 break;
275 default:
276 return 0;
277 }
278
279 if (gpio_is_valid(config->ena_gpio)) {
280 max77686->gpio_enabled |= (1 << desc->id);
281
282 return regmap_update_bits(config->regmap, desc->enable_reg,
283 desc->enable_mask,
284 MAX77686_GPIO_CONTROL);
285 }
286
287 return 0;
288}
289
Jonghwa Lee133d4012012-06-01 13:17:14 +0900290static struct regulator_ops max77686_ops = {
291 .list_voltage = regulator_list_voltage_linear,
Axel Lin2e3f7f22012-06-03 22:46:14 +0800292 .map_voltage = regulator_map_voltage_linear,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900293 .is_enabled = regulator_is_enabled_regmap,
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530294 .enable = max77686_enable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900295 .disable = regulator_disable_regmap,
296 .get_voltage_sel = regulator_get_voltage_sel_regmap,
297 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530298 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530299 .set_suspend_mode = max77686_set_suspend_mode,
300};
301
302static struct regulator_ops max77686_ldo_ops = {
303 .list_voltage = regulator_list_voltage_linear,
304 .map_voltage = regulator_map_voltage_linear,
305 .is_enabled = regulator_is_enabled_regmap,
306 .enable = max77686_enable,
307 .disable = regulator_disable_regmap,
308 .get_voltage_sel = regulator_get_voltage_sel_regmap,
309 .set_voltage_sel = regulator_set_voltage_sel_regmap,
310 .set_voltage_time_sel = regulator_set_voltage_time_sel,
311 .set_suspend_mode = max77686_ldo_set_suspend_mode,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100312 .set_suspend_disable = max77686_set_suspend_disable,
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530313};
314
315static struct regulator_ops max77686_buck1_ops = {
316 .list_voltage = regulator_list_voltage_linear,
317 .map_voltage = regulator_map_voltage_linear,
318 .is_enabled = regulator_is_enabled_regmap,
319 .enable = max77686_enable,
320 .disable = regulator_disable_regmap,
321 .get_voltage_sel = regulator_get_voltage_sel_regmap,
322 .set_voltage_sel = regulator_set_voltage_sel_regmap,
323 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100324 .set_suspend_disable = max77686_set_suspend_disable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900325};
326
327static struct regulator_ops max77686_buck_dvs_ops = {
328 .list_voltage = regulator_list_voltage_linear,
Axel Lin2e3f7f22012-06-03 22:46:14 +0800329 .map_voltage = regulator_map_voltage_linear,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900330 .is_enabled = regulator_is_enabled_regmap,
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530331 .enable = max77686_enable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900332 .disable = regulator_disable_regmap,
333 .get_voltage_sel = regulator_get_voltage_sel_regmap,
334 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530335 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530336 .set_ramp_delay = max77686_set_ramp_delay,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100337 .set_suspend_disable = max77686_set_suspend_disable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900338};
339
340#define regulator_desc_ldo(num) { \
341 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100342 .of_match = of_match_ptr("LDO"#num), \
343 .regulators_node = of_match_ptr("voltage-regulators"), \
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100344 .of_parse_cb = max77686_of_parse_cb, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900345 .id = MAX77686_LDO##num, \
346 .ops = &max77686_ops, \
347 .type = REGULATOR_VOLTAGE, \
348 .owner = THIS_MODULE, \
349 .min_uV = MAX77686_LDO_MINUV, \
350 .uV_step = MAX77686_LDO_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530351 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900352 .n_voltages = MAX77686_VSEL_MASK + 1, \
353 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
354 .vsel_mask = MAX77686_VSEL_MASK, \
355 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
356 .enable_mask = MAX77686_OPMODE_MASK \
357 << MAX77686_OPMODE_SHIFT, \
358}
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530359#define regulator_desc_lpm_ldo(num) { \
360 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100361 .of_match = of_match_ptr("LDO"#num), \
362 .regulators_node = of_match_ptr("voltage-regulators"), \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530363 .id = MAX77686_LDO##num, \
364 .ops = &max77686_ldo_ops, \
365 .type = REGULATOR_VOLTAGE, \
366 .owner = THIS_MODULE, \
367 .min_uV = MAX77686_LDO_MINUV, \
368 .uV_step = MAX77686_LDO_UVSTEP, \
369 .ramp_delay = MAX77686_RAMP_DELAY, \
370 .n_voltages = MAX77686_VSEL_MASK + 1, \
371 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
372 .vsel_mask = MAX77686_VSEL_MASK, \
373 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
374 .enable_mask = MAX77686_OPMODE_MASK \
375 << MAX77686_OPMODE_SHIFT, \
376}
Jonghwa Lee133d4012012-06-01 13:17:14 +0900377#define regulator_desc_ldo_low(num) { \
378 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100379 .of_match = of_match_ptr("LDO"#num), \
380 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900381 .id = MAX77686_LDO##num, \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530382 .ops = &max77686_ldo_ops, \
383 .type = REGULATOR_VOLTAGE, \
384 .owner = THIS_MODULE, \
385 .min_uV = MAX77686_LDO_LOW_MINUV, \
386 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
387 .ramp_delay = MAX77686_RAMP_DELAY, \
388 .n_voltages = MAX77686_VSEL_MASK + 1, \
389 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
390 .vsel_mask = MAX77686_VSEL_MASK, \
391 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
392 .enable_mask = MAX77686_OPMODE_MASK \
393 << MAX77686_OPMODE_SHIFT, \
394}
395#define regulator_desc_ldo1_low(num) { \
396 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100397 .of_match = of_match_ptr("LDO"#num), \
398 .regulators_node = of_match_ptr("voltage-regulators"), \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530399 .id = MAX77686_LDO##num, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900400 .ops = &max77686_ops, \
401 .type = REGULATOR_VOLTAGE, \
402 .owner = THIS_MODULE, \
403 .min_uV = MAX77686_LDO_LOW_MINUV, \
404 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530405 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900406 .n_voltages = MAX77686_VSEL_MASK + 1, \
407 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
408 .vsel_mask = MAX77686_VSEL_MASK, \
409 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
410 .enable_mask = MAX77686_OPMODE_MASK \
411 << MAX77686_OPMODE_SHIFT, \
412}
413#define regulator_desc_buck(num) { \
414 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100415 .of_match = of_match_ptr("BUCK"#num), \
416 .regulators_node = of_match_ptr("voltage-regulators"), \
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100417 .of_parse_cb = max77686_of_parse_cb, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900418 .id = MAX77686_BUCK##num, \
419 .ops = &max77686_ops, \
420 .type = REGULATOR_VOLTAGE, \
421 .owner = THIS_MODULE, \
422 .min_uV = MAX77686_BUCK_MINUV, \
423 .uV_step = MAX77686_BUCK_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530424 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900425 .n_voltages = MAX77686_VSEL_MASK + 1, \
426 .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \
427 .vsel_mask = MAX77686_VSEL_MASK, \
428 .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \
429 .enable_mask = MAX77686_OPMODE_MASK, \
430}
431#define regulator_desc_buck1(num) { \
432 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100433 .of_match = of_match_ptr("BUCK"#num), \
434 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900435 .id = MAX77686_BUCK##num, \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530436 .ops = &max77686_buck1_ops, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900437 .type = REGULATOR_VOLTAGE, \
438 .owner = THIS_MODULE, \
439 .min_uV = MAX77686_BUCK_MINUV, \
440 .uV_step = MAX77686_BUCK_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530441 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900442 .n_voltages = MAX77686_VSEL_MASK + 1, \
443 .vsel_reg = MAX77686_REG_BUCK1OUT, \
444 .vsel_mask = MAX77686_VSEL_MASK, \
445 .enable_reg = MAX77686_REG_BUCK1CTRL, \
446 .enable_mask = MAX77686_OPMODE_MASK, \
447}
448#define regulator_desc_buck_dvs(num) { \
449 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100450 .of_match = of_match_ptr("BUCK"#num), \
451 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900452 .id = MAX77686_BUCK##num, \
Axel Lin74adfee52012-06-04 10:19:18 +0800453 .ops = &max77686_buck_dvs_ops, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900454 .type = REGULATOR_VOLTAGE, \
455 .owner = THIS_MODULE, \
456 .min_uV = MAX77686_DVS_MINUV, \
457 .uV_step = MAX77686_DVS_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530458 .ramp_delay = MAX77686_DVS_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900459 .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \
460 .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \
461 .vsel_mask = MAX77686_DVS_VSEL_MASK, \
462 .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \
463 .enable_mask = MAX77686_OPMODE_MASK \
464 << MAX77686_OPMODE_BUCK234_SHIFT, \
465}
466
Krzysztof Kozlowski73dbdf82014-10-27 16:03:42 +0100467static const struct regulator_desc regulators[] = {
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530468 regulator_desc_ldo1_low(1),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900469 regulator_desc_ldo_low(2),
470 regulator_desc_ldo(3),
471 regulator_desc_ldo(4),
472 regulator_desc_ldo(5),
473 regulator_desc_ldo_low(6),
474 regulator_desc_ldo_low(7),
475 regulator_desc_ldo_low(8),
476 regulator_desc_ldo(9),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530477 regulator_desc_lpm_ldo(10),
478 regulator_desc_lpm_ldo(11),
479 regulator_desc_lpm_ldo(12),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900480 regulator_desc_ldo(13),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530481 regulator_desc_lpm_ldo(14),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900482 regulator_desc_ldo_low(15),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530483 regulator_desc_lpm_ldo(16),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900484 regulator_desc_ldo(17),
485 regulator_desc_ldo(18),
486 regulator_desc_ldo(19),
487 regulator_desc_ldo(20),
488 regulator_desc_ldo(21),
489 regulator_desc_ldo(22),
490 regulator_desc_ldo(23),
491 regulator_desc_ldo(24),
492 regulator_desc_ldo(25),
493 regulator_desc_ldo(26),
494 regulator_desc_buck1(1),
495 regulator_desc_buck_dvs(2),
496 regulator_desc_buck_dvs(3),
497 regulator_desc_buck_dvs(4),
498 regulator_desc_buck(5),
499 regulator_desc_buck(6),
500 regulator_desc_buck(7),
501 regulator_desc_buck(8),
502 regulator_desc_buck(9),
503};
504
Bill Pembertona5023572012-11-19 13:22:22 -0500505static int max77686_pmic_probe(struct platform_device *pdev)
Jonghwa Lee133d4012012-06-01 13:17:14 +0900506{
507 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
Jonghwa Lee133d4012012-06-01 13:17:14 +0900508 struct max77686_data *max77686;
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100509 int i;
Axel Linc59d2a62012-06-20 15:01:25 +0800510 struct regulator_config config = { };
Jonghwa Lee133d4012012-06-01 13:17:14 +0900511
512 dev_dbg(&pdev->dev, "%s\n", __func__);
513
514 max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
515 GFP_KERNEL);
516 if (!max77686)
517 return -ENOMEM;
518
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100519 config.dev = iodev->dev;
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530520 config.regmap = iodev->regmap;
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530521 config.driver_data = max77686;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900522 platform_set_drvdata(pdev, max77686);
523
Axel Linab0d1cb2012-06-08 12:03:04 +0800524 for (i = 0; i < MAX77686_REGULATORS; i++) {
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100525 struct regulator_dev *rdev;
Krzysztof Kozlowskieca29da2014-11-04 09:49:41 +0100526 int id = regulators[i].id;
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100527
Krzysztof Kozlowski4524df82014-11-04 09:49:42 +0100528 max77686->opmode[id] = MAX77686_NORMAL;
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100529 rdev = devm_regulator_register(&pdev->dev,
Sachin Kamat44815b42013-09-04 11:07:54 +0530530 &regulators[i], &config);
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100531 if (IS_ERR(rdev)) {
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100532 int ret = PTR_ERR(rdev);
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530533 dev_err(&pdev->dev,
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100534 "regulator init failed for %d: %d\n", i, ret);
535 return ret;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900536 }
Jonghwa Lee133d4012012-06-01 13:17:14 +0900537 }
Axel Linab0d1cb2012-06-08 12:03:04 +0800538
Jonghwa Lee133d4012012-06-01 13:17:14 +0900539 return 0;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900540}
541
542static const struct platform_device_id max77686_pmic_id[] = {
543 {"max77686-pmic", 0},
544 { },
545};
546MODULE_DEVICE_TABLE(platform, max77686_pmic_id);
547
548static struct platform_driver max77686_pmic_driver = {
549 .driver = {
550 .name = "max77686-pmic",
Jonghwa Lee133d4012012-06-01 13:17:14 +0900551 },
552 .probe = max77686_pmic_probe,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900553 .id_table = max77686_pmic_id,
554};
555
556static int __init max77686_pmic_init(void)
557{
558 return platform_driver_register(&max77686_pmic_driver);
559}
560subsys_initcall(max77686_pmic_init);
561
562static void __exit max77686_pmic_cleanup(void)
563{
564 platform_driver_unregister(&max77686_pmic_driver);
565}
566module_exit(max77686_pmic_cleanup);
567
568MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver");
569MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
570MODULE_LICENSE("GPL");