blob: ac4fa581e0a5eaa60f1afd4179778883d3919561 [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
Fabio Estevame4e8ccc2015-04-20 16:19:01 -03005 * Chiwoong Byun <woong.byun@samsung.com>
Jonghwa Lee133d4012012-06-01 13:17:14 +09006 * 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
Krzysztof Kozlowskia9597302016-04-29 12:59:51 +020044#define MAX77686_BUCK_ENABLE_TIME 40 /* us */
45#define MAX77686_DVS_ENABLE_TIME 22 /* us */
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +053046#define MAX77686_RAMP_DELAY 100000 /* uV/us */
47#define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */
Jonghwa Lee133d4012012-06-01 13:17:14 +090048#define MAX77686_DVS_MINUV 600000
49#define MAX77686_DVS_UVSTEP 12500
50
Krzysztof Kozlowski7636f192014-10-27 13:11:47 +010051/*
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +010052 * Value for configuring buck[89] and LDO{20,21,22} as GPIO control.
53 * It is the same as 'off' for other regulators.
54 */
55#define MAX77686_GPIO_CONTROL 0x0
56/*
Krzysztof Kozlowski7636f192014-10-27 13:11:47 +010057 * Values used for configuring LDOs and bucks.
58 * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
59 */
60#define MAX77686_LDO_LOWPOWER 0x1
61/*
62 * On/off controlled by PWRREQ:
63 * - LDO2, 6-8, 10-12, 14-16
64 * - buck[1234]
65 */
66#define MAX77686_OFF_PWRREQ 0x1
67/* Low power mode controlled by PWRREQ: All LDOs */
68#define MAX77686_LDO_LOWPOWER_PWRREQ 0x2
69/* Forcing low power mode: buck[234] */
70#define MAX77686_BUCK_LOWPOWER 0x2
71#define MAX77686_NORMAL 0x3
72
Jonghwa Lee133d4012012-06-01 13:17:14 +090073#define MAX77686_OPMODE_SHIFT 6
74#define MAX77686_OPMODE_BUCK234_SHIFT 4
75#define MAX77686_OPMODE_MASK 0x3
76
77#define MAX77686_VSEL_MASK 0x3F
78#define MAX77686_DVS_VSEL_MASK 0xFF
79
80#define MAX77686_RAMP_RATE_MASK 0xC0
81
82#define MAX77686_REGULATORS MAX77686_REG_MAX
83#define MAX77686_LDOS 26
84
85enum max77686_ramp_rate {
86 RAMP_RATE_13P75MV,
87 RAMP_RATE_27P5MV,
88 RAMP_RATE_55MV,
89 RAMP_RATE_NO_CTRL, /* 100mV/us */
90};
91
92struct max77686_data {
Joe Perchesc53403a2015-05-18 10:01:03 -070093 DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS);
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +010094
Krzysztof Kozlowskieca29da2014-11-04 09:49:41 +010095 /* Array indexed by regulator id */
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +053096 unsigned int opmode[MAX77686_REGULATORS];
Jonghwa Lee133d4012012-06-01 13:17:14 +090097};
98
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +010099static unsigned int max77686_get_opmode_shift(int id)
100{
101 switch (id) {
102 case MAX77686_BUCK1:
103 case MAX77686_BUCK5 ... MAX77686_BUCK9:
104 return 0;
105 case MAX77686_BUCK2 ... MAX77686_BUCK4:
106 return MAX77686_OPMODE_BUCK234_SHIFT;
107 default:
108 /* all LDOs */
109 return MAX77686_OPMODE_SHIFT;
110 }
111}
112
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100113/*
114 * When regulator is configured for GPIO control then it
115 * replaces "normal" mode. Any change from low power mode to normal
116 * should actually change to GPIO control.
117 * Map normal mode to proper value for such regulators.
118 */
119static unsigned int max77686_map_normal_mode(struct max77686_data *max77686,
120 int id)
121{
122 switch (id) {
123 case MAX77686_BUCK8:
124 case MAX77686_BUCK9:
125 case MAX77686_LDO20 ... MAX77686_LDO22:
Joe Perchesc53403a2015-05-18 10:01:03 -0700126 if (test_bit(id, max77686->gpio_enabled))
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100127 return MAX77686_GPIO_CONTROL;
128 }
129
130 return MAX77686_NORMAL;
131}
132
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100133/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
134static int max77686_set_suspend_disable(struct regulator_dev *rdev)
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530135{
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100136 unsigned int val, shift;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530137 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Axel Lin3ecf1982013-04-27 16:18:16 +0800138 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530139
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100140 shift = max77686_get_opmode_shift(id);
141 val = MAX77686_OFF_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530142
Axel Lin3ecf1982013-04-27 16:18:16 +0800143 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100144 rdev->desc->enable_mask, val << shift);
Axel Lin3ecf1982013-04-27 16:18:16 +0800145 if (ret)
146 return ret;
147
Thiago Farina40e72142013-02-13 17:52:26 -0200148 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800149 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530150}
151
152/* Some LDOs supports [LPM/Normal]ON mode during suspend state */
153static int max77686_set_suspend_mode(struct regulator_dev *rdev,
154 unsigned int mode)
155{
156 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
157 unsigned int val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800158 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530159
160 /* BUCK[5-9] doesn't support this feature */
Thiago Farina40e72142013-02-13 17:52:26 -0200161 if (id >= MAX77686_BUCK5)
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530162 return 0;
163
164 switch (mode) {
165 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100166 val = MAX77686_LDO_LOWPOWER_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530167 break;
168 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100169 val = max77686_map_normal_mode(max77686, id);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530170 break;
171 default:
172 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
173 rdev->desc->name, mode);
174 return -EINVAL;
175 }
176
Axel Lin3ecf1982013-04-27 16:18:16 +0800177 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100178 rdev->desc->enable_mask,
179 val << MAX77686_OPMODE_SHIFT);
Axel Lin3ecf1982013-04-27 16:18:16 +0800180 if (ret)
181 return ret;
182
Thiago Farina40e72142013-02-13 17:52:26 -0200183 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800184 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530185}
186
187/* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */
188static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
189 unsigned int mode)
190{
191 unsigned int val;
192 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100193 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530194
195 switch (mode) {
196 case REGULATOR_MODE_STANDBY: /* switch off */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100197 val = MAX77686_OFF_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530198 break;
199 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100200 val = MAX77686_LDO_LOWPOWER_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530201 break;
202 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100203 val = max77686_map_normal_mode(max77686, id);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530204 break;
205 default:
206 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
207 rdev->desc->name, mode);
208 return -EINVAL;
209 }
210
Axel Lin3ecf1982013-04-27 16:18:16 +0800211 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100212 rdev->desc->enable_mask,
213 val << MAX77686_OPMODE_SHIFT);
Axel Lin3ecf1982013-04-27 16:18:16 +0800214 if (ret)
215 return ret;
216
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100217 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800218 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530219}
220
Yadwinder Singh Brar38d34032012-10-22 09:39:28 +0530221static int max77686_enable(struct regulator_dev *rdev)
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530222{
223 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100224 unsigned int shift;
225 int id = rdev_get_id(rdev);
226
227 shift = max77686_get_opmode_shift(id);
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530228
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100229 if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100230 max77686->opmode[id] = max77686_map_normal_mode(max77686, id);
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100231
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530232 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
233 rdev->desc->enable_mask,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100234 max77686->opmode[id] << shift);
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530235}
236
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530237static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
238{
239 unsigned int ramp_value = RAMP_RATE_NO_CTRL;
240
241 switch (ramp_delay) {
242 case 1 ... 13750:
243 ramp_value = RAMP_RATE_13P75MV;
244 break;
245 case 13751 ... 27500:
246 ramp_value = RAMP_RATE_27P5MV;
247 break;
248 case 27501 ... 55000:
249 ramp_value = RAMP_RATE_55MV;
250 break;
251 case 55001 ... 100000:
252 break;
253 default:
254 pr_warn("%s: ramp_delay: %d not supported, setting 100000\n",
255 rdev->desc->name, ramp_delay);
256 }
257
258 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
259 MAX77686_RAMP_RATE_MASK, ramp_value << 6);
260}
261
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100262static int max77686_of_parse_cb(struct device_node *np,
263 const struct regulator_desc *desc,
264 struct regulator_config *config)
265{
266 struct max77686_data *max77686 = config->driver_data;
267
268 switch (desc->id) {
269 case MAX77686_BUCK8:
270 case MAX77686_BUCK9:
271 case MAX77686_LDO20 ... MAX77686_LDO22:
272 config->ena_gpio = of_get_named_gpio(np,
273 "maxim,ena-gpios", 0);
274 config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
275 config->ena_gpio_initialized = true;
276 break;
277 default:
278 return 0;
279 }
280
281 if (gpio_is_valid(config->ena_gpio)) {
Joe Perchesc53403a2015-05-18 10:01:03 -0700282 set_bit(desc->id, max77686->gpio_enabled);
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100283
284 return regmap_update_bits(config->regmap, desc->enable_reg,
285 desc->enable_mask,
286 MAX77686_GPIO_CONTROL);
287 }
288
289 return 0;
290}
291
Jonghwa Lee133d4012012-06-01 13:17:14 +0900292static struct regulator_ops max77686_ops = {
293 .list_voltage = regulator_list_voltage_linear,
Axel Lin2e3f7f22012-06-03 22:46:14 +0800294 .map_voltage = regulator_map_voltage_linear,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900295 .is_enabled = regulator_is_enabled_regmap,
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530296 .enable = max77686_enable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900297 .disable = regulator_disable_regmap,
298 .get_voltage_sel = regulator_get_voltage_sel_regmap,
299 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530300 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530301 .set_suspend_mode = max77686_set_suspend_mode,
302};
303
304static struct regulator_ops max77686_ldo_ops = {
305 .list_voltage = regulator_list_voltage_linear,
306 .map_voltage = regulator_map_voltage_linear,
307 .is_enabled = regulator_is_enabled_regmap,
308 .enable = max77686_enable,
309 .disable = regulator_disable_regmap,
310 .get_voltage_sel = regulator_get_voltage_sel_regmap,
311 .set_voltage_sel = regulator_set_voltage_sel_regmap,
312 .set_voltage_time_sel = regulator_set_voltage_time_sel,
313 .set_suspend_mode = max77686_ldo_set_suspend_mode,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100314 .set_suspend_disable = max77686_set_suspend_disable,
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530315};
316
317static struct regulator_ops max77686_buck1_ops = {
318 .list_voltage = regulator_list_voltage_linear,
319 .map_voltage = regulator_map_voltage_linear,
320 .is_enabled = regulator_is_enabled_regmap,
321 .enable = max77686_enable,
322 .disable = regulator_disable_regmap,
323 .get_voltage_sel = regulator_get_voltage_sel_regmap,
324 .set_voltage_sel = regulator_set_voltage_sel_regmap,
325 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100326 .set_suspend_disable = max77686_set_suspend_disable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900327};
328
329static struct regulator_ops max77686_buck_dvs_ops = {
330 .list_voltage = regulator_list_voltage_linear,
Axel Lin2e3f7f22012-06-03 22:46:14 +0800331 .map_voltage = regulator_map_voltage_linear,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900332 .is_enabled = regulator_is_enabled_regmap,
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530333 .enable = max77686_enable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900334 .disable = regulator_disable_regmap,
335 .get_voltage_sel = regulator_get_voltage_sel_regmap,
336 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530337 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530338 .set_ramp_delay = max77686_set_ramp_delay,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100339 .set_suspend_disable = max77686_set_suspend_disable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900340};
341
342#define regulator_desc_ldo(num) { \
343 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100344 .of_match = of_match_ptr("LDO"#num), \
345 .regulators_node = of_match_ptr("voltage-regulators"), \
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100346 .of_parse_cb = max77686_of_parse_cb, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900347 .id = MAX77686_LDO##num, \
348 .ops = &max77686_ops, \
349 .type = REGULATOR_VOLTAGE, \
350 .owner = THIS_MODULE, \
351 .min_uV = MAX77686_LDO_MINUV, \
352 .uV_step = MAX77686_LDO_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530353 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900354 .n_voltages = MAX77686_VSEL_MASK + 1, \
355 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
356 .vsel_mask = MAX77686_VSEL_MASK, \
357 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
358 .enable_mask = MAX77686_OPMODE_MASK \
359 << MAX77686_OPMODE_SHIFT, \
360}
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530361#define regulator_desc_lpm_ldo(num) { \
362 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100363 .of_match = of_match_ptr("LDO"#num), \
364 .regulators_node = of_match_ptr("voltage-regulators"), \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530365 .id = MAX77686_LDO##num, \
366 .ops = &max77686_ldo_ops, \
367 .type = REGULATOR_VOLTAGE, \
368 .owner = THIS_MODULE, \
369 .min_uV = MAX77686_LDO_MINUV, \
370 .uV_step = MAX77686_LDO_UVSTEP, \
371 .ramp_delay = MAX77686_RAMP_DELAY, \
372 .n_voltages = MAX77686_VSEL_MASK + 1, \
373 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
374 .vsel_mask = MAX77686_VSEL_MASK, \
375 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
376 .enable_mask = MAX77686_OPMODE_MASK \
377 << MAX77686_OPMODE_SHIFT, \
378}
Jonghwa Lee133d4012012-06-01 13:17:14 +0900379#define regulator_desc_ldo_low(num) { \
380 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100381 .of_match = of_match_ptr("LDO"#num), \
382 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900383 .id = MAX77686_LDO##num, \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530384 .ops = &max77686_ldo_ops, \
385 .type = REGULATOR_VOLTAGE, \
386 .owner = THIS_MODULE, \
387 .min_uV = MAX77686_LDO_LOW_MINUV, \
388 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
389 .ramp_delay = MAX77686_RAMP_DELAY, \
390 .n_voltages = MAX77686_VSEL_MASK + 1, \
391 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
392 .vsel_mask = MAX77686_VSEL_MASK, \
393 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
394 .enable_mask = MAX77686_OPMODE_MASK \
395 << MAX77686_OPMODE_SHIFT, \
396}
397#define regulator_desc_ldo1_low(num) { \
398 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100399 .of_match = of_match_ptr("LDO"#num), \
400 .regulators_node = of_match_ptr("voltage-regulators"), \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530401 .id = MAX77686_LDO##num, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900402 .ops = &max77686_ops, \
403 .type = REGULATOR_VOLTAGE, \
404 .owner = THIS_MODULE, \
405 .min_uV = MAX77686_LDO_LOW_MINUV, \
406 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530407 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900408 .n_voltages = MAX77686_VSEL_MASK + 1, \
409 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
410 .vsel_mask = MAX77686_VSEL_MASK, \
411 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
412 .enable_mask = MAX77686_OPMODE_MASK \
413 << MAX77686_OPMODE_SHIFT, \
414}
415#define regulator_desc_buck(num) { \
416 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100417 .of_match = of_match_ptr("BUCK"#num), \
418 .regulators_node = of_match_ptr("voltage-regulators"), \
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100419 .of_parse_cb = max77686_of_parse_cb, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900420 .id = MAX77686_BUCK##num, \
421 .ops = &max77686_ops, \
422 .type = REGULATOR_VOLTAGE, \
423 .owner = THIS_MODULE, \
424 .min_uV = MAX77686_BUCK_MINUV, \
425 .uV_step = MAX77686_BUCK_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530426 .ramp_delay = MAX77686_RAMP_DELAY, \
Krzysztof Kozlowskia9597302016-04-29 12:59:51 +0200427 .enable_time = MAX77686_BUCK_ENABLE_TIME, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900428 .n_voltages = MAX77686_VSEL_MASK + 1, \
429 .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \
430 .vsel_mask = MAX77686_VSEL_MASK, \
431 .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \
432 .enable_mask = MAX77686_OPMODE_MASK, \
433}
434#define regulator_desc_buck1(num) { \
435 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100436 .of_match = of_match_ptr("BUCK"#num), \
437 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900438 .id = MAX77686_BUCK##num, \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530439 .ops = &max77686_buck1_ops, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900440 .type = REGULATOR_VOLTAGE, \
441 .owner = THIS_MODULE, \
442 .min_uV = MAX77686_BUCK_MINUV, \
443 .uV_step = MAX77686_BUCK_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530444 .ramp_delay = MAX77686_RAMP_DELAY, \
Krzysztof Kozlowskia9597302016-04-29 12:59:51 +0200445 .enable_time = MAX77686_BUCK_ENABLE_TIME, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900446 .n_voltages = MAX77686_VSEL_MASK + 1, \
447 .vsel_reg = MAX77686_REG_BUCK1OUT, \
448 .vsel_mask = MAX77686_VSEL_MASK, \
449 .enable_reg = MAX77686_REG_BUCK1CTRL, \
450 .enable_mask = MAX77686_OPMODE_MASK, \
451}
452#define regulator_desc_buck_dvs(num) { \
453 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100454 .of_match = of_match_ptr("BUCK"#num), \
455 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900456 .id = MAX77686_BUCK##num, \
Axel Lin74adfee52012-06-04 10:19:18 +0800457 .ops = &max77686_buck_dvs_ops, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900458 .type = REGULATOR_VOLTAGE, \
459 .owner = THIS_MODULE, \
460 .min_uV = MAX77686_DVS_MINUV, \
461 .uV_step = MAX77686_DVS_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530462 .ramp_delay = MAX77686_DVS_RAMP_DELAY, \
Krzysztof Kozlowskia9597302016-04-29 12:59:51 +0200463 .enable_time = MAX77686_DVS_ENABLE_TIME, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900464 .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \
465 .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \
466 .vsel_mask = MAX77686_DVS_VSEL_MASK, \
467 .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \
468 .enable_mask = MAX77686_OPMODE_MASK \
469 << MAX77686_OPMODE_BUCK234_SHIFT, \
470}
471
Krzysztof Kozlowski73dbdf82014-10-27 16:03:42 +0100472static const struct regulator_desc regulators[] = {
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530473 regulator_desc_ldo1_low(1),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900474 regulator_desc_ldo_low(2),
475 regulator_desc_ldo(3),
476 regulator_desc_ldo(4),
477 regulator_desc_ldo(5),
478 regulator_desc_ldo_low(6),
479 regulator_desc_ldo_low(7),
480 regulator_desc_ldo_low(8),
481 regulator_desc_ldo(9),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530482 regulator_desc_lpm_ldo(10),
483 regulator_desc_lpm_ldo(11),
484 regulator_desc_lpm_ldo(12),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900485 regulator_desc_ldo(13),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530486 regulator_desc_lpm_ldo(14),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900487 regulator_desc_ldo_low(15),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530488 regulator_desc_lpm_ldo(16),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900489 regulator_desc_ldo(17),
490 regulator_desc_ldo(18),
491 regulator_desc_ldo(19),
492 regulator_desc_ldo(20),
493 regulator_desc_ldo(21),
494 regulator_desc_ldo(22),
495 regulator_desc_ldo(23),
496 regulator_desc_ldo(24),
497 regulator_desc_ldo(25),
498 regulator_desc_ldo(26),
499 regulator_desc_buck1(1),
500 regulator_desc_buck_dvs(2),
501 regulator_desc_buck_dvs(3),
502 regulator_desc_buck_dvs(4),
503 regulator_desc_buck(5),
504 regulator_desc_buck(6),
505 regulator_desc_buck(7),
506 regulator_desc_buck(8),
507 regulator_desc_buck(9),
508};
509
Bill Pembertona5023572012-11-19 13:22:22 -0500510static int max77686_pmic_probe(struct platform_device *pdev)
Jonghwa Lee133d4012012-06-01 13:17:14 +0900511{
512 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
Jonghwa Lee133d4012012-06-01 13:17:14 +0900513 struct max77686_data *max77686;
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100514 int i;
Axel Linc59d2a62012-06-20 15:01:25 +0800515 struct regulator_config config = { };
Jonghwa Lee133d4012012-06-01 13:17:14 +0900516
517 dev_dbg(&pdev->dev, "%s\n", __func__);
518
519 max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
520 GFP_KERNEL);
521 if (!max77686)
522 return -ENOMEM;
523
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100524 config.dev = iodev->dev;
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530525 config.regmap = iodev->regmap;
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530526 config.driver_data = max77686;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900527 platform_set_drvdata(pdev, max77686);
528
Axel Linab0d1cb2012-06-08 12:03:04 +0800529 for (i = 0; i < MAX77686_REGULATORS; i++) {
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100530 struct regulator_dev *rdev;
Krzysztof Kozlowskieca29da2014-11-04 09:49:41 +0100531 int id = regulators[i].id;
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100532
Krzysztof Kozlowski4524df82014-11-04 09:49:42 +0100533 max77686->opmode[id] = MAX77686_NORMAL;
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100534 rdev = devm_regulator_register(&pdev->dev,
Sachin Kamat44815b42013-09-04 11:07:54 +0530535 &regulators[i], &config);
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100536 if (IS_ERR(rdev)) {
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100537 int ret = PTR_ERR(rdev);
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530538 dev_err(&pdev->dev,
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100539 "regulator init failed for %d: %d\n", i, ret);
540 return ret;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900541 }
Jonghwa Lee133d4012012-06-01 13:17:14 +0900542 }
Axel Linab0d1cb2012-06-08 12:03:04 +0800543
Jonghwa Lee133d4012012-06-01 13:17:14 +0900544 return 0;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900545}
546
547static const struct platform_device_id max77686_pmic_id[] = {
548 {"max77686-pmic", 0},
549 { },
550};
551MODULE_DEVICE_TABLE(platform, max77686_pmic_id);
552
553static struct platform_driver max77686_pmic_driver = {
554 .driver = {
555 .name = "max77686-pmic",
Jonghwa Lee133d4012012-06-01 13:17:14 +0900556 },
557 .probe = max77686_pmic_probe,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900558 .id_table = max77686_pmic_id,
559};
560
Javier Martinez Canillas314a8202016-04-06 09:49:47 -0400561module_platform_driver(max77686_pmic_driver);
Jonghwa Lee133d4012012-06-01 13:17:14 +0900562
563MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver");
564MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
565MODULE_LICENSE("GPL");