blob: 9089ec608fccb6550b9fc7a9400c6e6bb1f3537f [file] [log] [blame]
Krzysztof Kozlowski5e9384c2018-08-07 18:18:25 +02001// SPDX-License-Identifier: GPL-2.0+
2//
3// max77686.c - Regulator driver for the Maxim 77686
4//
5// Copyright (C) 2012 Samsung Electronics
6// Chiwoong Byun <woong.byun@samsung.com>
7// Jonghwa Lee <jonghwa3.lee@samsung.com>
8//
9// This driver is based on max8997.c
Jonghwa Lee133d4012012-06-01 13:17:14 +090010
11#include <linux/kernel.h>
12#include <linux/bug.h>
Jonghwa Lee133d4012012-06-01 13:17:14 +090013#include <linux/err.h>
Linus Walleij96392c32018-11-15 09:01:19 +010014#include <linux/gpio/consumer.h>
Jonghwa Lee133d4012012-06-01 13:17:14 +090015#include <linux/slab.h>
16#include <linux/platform_device.h>
17#include <linux/regulator/driver.h>
18#include <linux/regulator/machine.h>
Yadwinder Singh Brar4706fca2012-07-05 09:28:25 +053019#include <linux/regulator/of_regulator.h>
Jonghwa Lee133d4012012-06-01 13:17:14 +090020#include <linux/mfd/max77686.h>
21#include <linux/mfd/max77686-private.h>
22
23#define MAX77686_LDO_MINUV 800000
24#define MAX77686_LDO_UVSTEP 50000
25#define MAX77686_LDO_LOW_MINUV 800000
26#define MAX77686_LDO_LOW_UVSTEP 25000
27#define MAX77686_BUCK_MINUV 750000
28#define MAX77686_BUCK_UVSTEP 50000
Krzysztof Kozlowskia9597302016-04-29 12:59:51 +020029#define MAX77686_BUCK_ENABLE_TIME 40 /* us */
30#define MAX77686_DVS_ENABLE_TIME 22 /* us */
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +053031#define MAX77686_RAMP_DELAY 100000 /* uV/us */
32#define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */
Jonghwa Lee133d4012012-06-01 13:17:14 +090033#define MAX77686_DVS_MINUV 600000
34#define MAX77686_DVS_UVSTEP 12500
35
Krzysztof Kozlowski7636f192014-10-27 13:11:47 +010036/*
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +010037 * Value for configuring buck[89] and LDO{20,21,22} as GPIO control.
38 * It is the same as 'off' for other regulators.
39 */
40#define MAX77686_GPIO_CONTROL 0x0
41/*
Krzysztof Kozlowski7636f192014-10-27 13:11:47 +010042 * Values used for configuring LDOs and bucks.
43 * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
44 */
45#define MAX77686_LDO_LOWPOWER 0x1
46/*
47 * On/off controlled by PWRREQ:
48 * - LDO2, 6-8, 10-12, 14-16
49 * - buck[1234]
50 */
51#define MAX77686_OFF_PWRREQ 0x1
52/* Low power mode controlled by PWRREQ: All LDOs */
53#define MAX77686_LDO_LOWPOWER_PWRREQ 0x2
54/* Forcing low power mode: buck[234] */
55#define MAX77686_BUCK_LOWPOWER 0x2
56#define MAX77686_NORMAL 0x3
57
Jonghwa Lee133d4012012-06-01 13:17:14 +090058#define MAX77686_OPMODE_SHIFT 6
59#define MAX77686_OPMODE_BUCK234_SHIFT 4
60#define MAX77686_OPMODE_MASK 0x3
61
62#define MAX77686_VSEL_MASK 0x3F
63#define MAX77686_DVS_VSEL_MASK 0xFF
64
65#define MAX77686_RAMP_RATE_MASK 0xC0
66
67#define MAX77686_REGULATORS MAX77686_REG_MAX
68#define MAX77686_LDOS 26
69
70enum max77686_ramp_rate {
71 RAMP_RATE_13P75MV,
72 RAMP_RATE_27P5MV,
73 RAMP_RATE_55MV,
74 RAMP_RATE_NO_CTRL, /* 100mV/us */
75};
76
77struct max77686_data {
Linus Walleij96392c32018-11-15 09:01:19 +010078 struct device *dev;
Joe Perchesc53403a2015-05-18 10:01:03 -070079 DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS);
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +010080
Krzysztof Kozlowskieca29da2014-11-04 09:49:41 +010081 /* Array indexed by regulator id */
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +053082 unsigned int opmode[MAX77686_REGULATORS];
Jonghwa Lee133d4012012-06-01 13:17:14 +090083};
84
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +010085static unsigned int max77686_get_opmode_shift(int id)
86{
87 switch (id) {
88 case MAX77686_BUCK1:
89 case MAX77686_BUCK5 ... MAX77686_BUCK9:
90 return 0;
91 case MAX77686_BUCK2 ... MAX77686_BUCK4:
92 return MAX77686_OPMODE_BUCK234_SHIFT;
93 default:
94 /* all LDOs */
95 return MAX77686_OPMODE_SHIFT;
96 }
97}
98
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +010099/*
100 * When regulator is configured for GPIO control then it
101 * replaces "normal" mode. Any change from low power mode to normal
102 * should actually change to GPIO control.
103 * Map normal mode to proper value for such regulators.
104 */
105static unsigned int max77686_map_normal_mode(struct max77686_data *max77686,
106 int id)
107{
108 switch (id) {
109 case MAX77686_BUCK8:
110 case MAX77686_BUCK9:
111 case MAX77686_LDO20 ... MAX77686_LDO22:
Joe Perchesc53403a2015-05-18 10:01:03 -0700112 if (test_bit(id, max77686->gpio_enabled))
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100113 return MAX77686_GPIO_CONTROL;
114 }
115
116 return MAX77686_NORMAL;
117}
118
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100119/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
120static int max77686_set_suspend_disable(struct regulator_dev *rdev)
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530121{
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100122 unsigned int val, shift;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530123 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Axel Lin3ecf1982013-04-27 16:18:16 +0800124 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530125
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100126 shift = max77686_get_opmode_shift(id);
127 val = MAX77686_OFF_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530128
Axel Lin3ecf1982013-04-27 16:18:16 +0800129 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100130 rdev->desc->enable_mask, val << shift);
Axel Lin3ecf1982013-04-27 16:18:16 +0800131 if (ret)
132 return ret;
133
Thiago Farina40e72142013-02-13 17:52:26 -0200134 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800135 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530136}
137
138/* Some LDOs supports [LPM/Normal]ON mode during suspend state */
139static int max77686_set_suspend_mode(struct regulator_dev *rdev,
140 unsigned int mode)
141{
142 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
143 unsigned int val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800144 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530145
146 /* BUCK[5-9] doesn't support this feature */
Thiago Farina40e72142013-02-13 17:52:26 -0200147 if (id >= MAX77686_BUCK5)
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530148 return 0;
149
150 switch (mode) {
151 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100152 val = MAX77686_LDO_LOWPOWER_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530153 break;
154 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100155 val = max77686_map_normal_mode(max77686, id);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530156 break;
157 default:
158 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
159 rdev->desc->name, mode);
160 return -EINVAL;
161 }
162
Axel Lin3ecf1982013-04-27 16:18:16 +0800163 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100164 rdev->desc->enable_mask,
165 val << MAX77686_OPMODE_SHIFT);
Axel Lin3ecf1982013-04-27 16:18:16 +0800166 if (ret)
167 return ret;
168
Thiago Farina40e72142013-02-13 17:52:26 -0200169 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800170 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530171}
172
173/* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */
174static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
175 unsigned int mode)
176{
177 unsigned int val;
178 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100179 int ret, id = rdev_get_id(rdev);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530180
181 switch (mode) {
182 case REGULATOR_MODE_STANDBY: /* switch off */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100183 val = MAX77686_OFF_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530184 break;
185 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100186 val = MAX77686_LDO_LOWPOWER_PWRREQ;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530187 break;
188 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100189 val = max77686_map_normal_mode(max77686, id);
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530190 break;
191 default:
192 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
193 rdev->desc->name, mode);
194 return -EINVAL;
195 }
196
Axel Lin3ecf1982013-04-27 16:18:16 +0800197 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100198 rdev->desc->enable_mask,
199 val << MAX77686_OPMODE_SHIFT);
Axel Lin3ecf1982013-04-27 16:18:16 +0800200 if (ret)
201 return ret;
202
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100203 max77686->opmode[id] = val;
Axel Lin3ecf1982013-04-27 16:18:16 +0800204 return 0;
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530205}
206
Yadwinder Singh Brar38d34032012-10-22 09:39:28 +0530207static int max77686_enable(struct regulator_dev *rdev)
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530208{
209 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100210 unsigned int shift;
211 int id = rdev_get_id(rdev);
212
213 shift = max77686_get_opmode_shift(id);
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530214
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100215 if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100216 max77686->opmode[id] = max77686_map_normal_mode(max77686, id);
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100217
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530218 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
219 rdev->desc->enable_mask,
Krzysztof Kozlowski68c5d182014-10-27 13:11:48 +0100220 max77686->opmode[id] << shift);
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530221}
222
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530223static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
224{
225 unsigned int ramp_value = RAMP_RATE_NO_CTRL;
226
227 switch (ramp_delay) {
228 case 1 ... 13750:
229 ramp_value = RAMP_RATE_13P75MV;
230 break;
231 case 13751 ... 27500:
232 ramp_value = RAMP_RATE_27P5MV;
233 break;
234 case 27501 ... 55000:
235 ramp_value = RAMP_RATE_55MV;
236 break;
237 case 55001 ... 100000:
238 break;
239 default:
240 pr_warn("%s: ramp_delay: %d not supported, setting 100000\n",
241 rdev->desc->name, ramp_delay);
242 }
243
244 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
245 MAX77686_RAMP_RATE_MASK, ramp_value << 6);
246}
247
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100248static int max77686_of_parse_cb(struct device_node *np,
249 const struct regulator_desc *desc,
250 struct regulator_config *config)
251{
252 struct max77686_data *max77686 = config->driver_data;
Linus Walleijd03c63d2018-12-06 13:43:43 +0100253 int ret;
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100254
255 switch (desc->id) {
256 case MAX77686_BUCK8:
257 case MAX77686_BUCK9:
258 case MAX77686_LDO20 ... MAX77686_LDO22:
Dmitry Torokhov0b2ba812019-10-04 16:10:17 -0700259 config->ena_gpiod = fwnode_gpiod_get_index(
260 of_fwnode_handle(np),
261 "maxim,ena",
Linus Walleij96392c32018-11-15 09:01:19 +0100262 0,
263 GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
264 "max77686-regulator");
265 if (IS_ERR(config->ena_gpiod))
266 config->ena_gpiod = NULL;
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100267 break;
268 default:
269 return 0;
270 }
271
Linus Walleij96392c32018-11-15 09:01:19 +0100272 if (config->ena_gpiod) {
Joe Perchesc53403a2015-05-18 10:01:03 -0700273 set_bit(desc->id, max77686->gpio_enabled);
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100274
Linus Walleijd03c63d2018-12-06 13:43:43 +0100275 ret = regmap_update_bits(config->regmap, desc->enable_reg,
276 desc->enable_mask,
277 MAX77686_GPIO_CONTROL);
278 if (ret) {
279 gpiod_put(config->ena_gpiod);
280 config->ena_gpiod = NULL;
281 }
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100282 }
283
284 return 0;
285}
286
Bhumika Goyal404826c2017-01-28 19:52:24 +0530287static const struct regulator_ops max77686_ops = {
Jonghwa Lee133d4012012-06-01 13:17:14 +0900288 .list_voltage = regulator_list_voltage_linear,
Axel Lin2e3f7f22012-06-03 22:46:14 +0800289 .map_voltage = regulator_map_voltage_linear,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900290 .is_enabled = regulator_is_enabled_regmap,
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530291 .enable = max77686_enable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900292 .disable = regulator_disable_regmap,
293 .get_voltage_sel = regulator_get_voltage_sel_regmap,
294 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530295 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530296 .set_suspend_mode = max77686_set_suspend_mode,
297};
298
Bhumika Goyal404826c2017-01-28 19:52:24 +0530299static const struct regulator_ops max77686_ldo_ops = {
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530300 .list_voltage = regulator_list_voltage_linear,
301 .map_voltage = regulator_map_voltage_linear,
302 .is_enabled = regulator_is_enabled_regmap,
303 .enable = max77686_enable,
304 .disable = regulator_disable_regmap,
305 .get_voltage_sel = regulator_get_voltage_sel_regmap,
306 .set_voltage_sel = regulator_set_voltage_sel_regmap,
307 .set_voltage_time_sel = regulator_set_voltage_time_sel,
308 .set_suspend_mode = max77686_ldo_set_suspend_mode,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100309 .set_suspend_disable = max77686_set_suspend_disable,
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530310};
311
Bhumika Goyal404826c2017-01-28 19:52:24 +0530312static const struct regulator_ops max77686_buck1_ops = {
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530313 .list_voltage = regulator_list_voltage_linear,
314 .map_voltage = regulator_map_voltage_linear,
315 .is_enabled = regulator_is_enabled_regmap,
316 .enable = max77686_enable,
317 .disable = regulator_disable_regmap,
318 .get_voltage_sel = regulator_get_voltage_sel_regmap,
319 .set_voltage_sel = regulator_set_voltage_sel_regmap,
320 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100321 .set_suspend_disable = max77686_set_suspend_disable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900322};
323
Bhumika Goyal404826c2017-01-28 19:52:24 +0530324static const struct regulator_ops max77686_buck_dvs_ops = {
Jonghwa Lee133d4012012-06-01 13:17:14 +0900325 .list_voltage = regulator_list_voltage_linear,
Axel Lin2e3f7f22012-06-03 22:46:14 +0800326 .map_voltage = regulator_map_voltage_linear,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900327 .is_enabled = regulator_is_enabled_regmap,
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530328 .enable = max77686_enable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900329 .disable = regulator_disable_regmap,
330 .get_voltage_sel = regulator_get_voltage_sel_regmap,
331 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530332 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530333 .set_ramp_delay = max77686_set_ramp_delay,
Krzysztof Kozlowski78ce6122014-10-29 12:14:52 +0100334 .set_suspend_disable = max77686_set_suspend_disable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900335};
336
337#define regulator_desc_ldo(num) { \
338 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100339 .of_match = of_match_ptr("LDO"#num), \
340 .regulators_node = of_match_ptr("voltage-regulators"), \
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100341 .of_parse_cb = max77686_of_parse_cb, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900342 .id = MAX77686_LDO##num, \
343 .ops = &max77686_ops, \
344 .type = REGULATOR_VOLTAGE, \
345 .owner = THIS_MODULE, \
346 .min_uV = MAX77686_LDO_MINUV, \
347 .uV_step = MAX77686_LDO_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530348 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900349 .n_voltages = MAX77686_VSEL_MASK + 1, \
350 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
351 .vsel_mask = MAX77686_VSEL_MASK, \
352 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
353 .enable_mask = MAX77686_OPMODE_MASK \
354 << MAX77686_OPMODE_SHIFT, \
355}
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530356#define regulator_desc_lpm_ldo(num) { \
357 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100358 .of_match = of_match_ptr("LDO"#num), \
359 .regulators_node = of_match_ptr("voltage-regulators"), \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530360 .id = MAX77686_LDO##num, \
361 .ops = &max77686_ldo_ops, \
362 .type = REGULATOR_VOLTAGE, \
363 .owner = THIS_MODULE, \
364 .min_uV = MAX77686_LDO_MINUV, \
365 .uV_step = MAX77686_LDO_UVSTEP, \
366 .ramp_delay = MAX77686_RAMP_DELAY, \
367 .n_voltages = MAX77686_VSEL_MASK + 1, \
368 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
369 .vsel_mask = MAX77686_VSEL_MASK, \
370 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
371 .enable_mask = MAX77686_OPMODE_MASK \
372 << MAX77686_OPMODE_SHIFT, \
373}
Jonghwa Lee133d4012012-06-01 13:17:14 +0900374#define regulator_desc_ldo_low(num) { \
375 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100376 .of_match = of_match_ptr("LDO"#num), \
377 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900378 .id = MAX77686_LDO##num, \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530379 .ops = &max77686_ldo_ops, \
380 .type = REGULATOR_VOLTAGE, \
381 .owner = THIS_MODULE, \
382 .min_uV = MAX77686_LDO_LOW_MINUV, \
383 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
384 .ramp_delay = MAX77686_RAMP_DELAY, \
385 .n_voltages = MAX77686_VSEL_MASK + 1, \
386 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
387 .vsel_mask = MAX77686_VSEL_MASK, \
388 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
389 .enable_mask = MAX77686_OPMODE_MASK \
390 << MAX77686_OPMODE_SHIFT, \
391}
392#define regulator_desc_ldo1_low(num) { \
393 .name = "LDO"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100394 .of_match = of_match_ptr("LDO"#num), \
395 .regulators_node = of_match_ptr("voltage-regulators"), \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530396 .id = MAX77686_LDO##num, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900397 .ops = &max77686_ops, \
398 .type = REGULATOR_VOLTAGE, \
399 .owner = THIS_MODULE, \
400 .min_uV = MAX77686_LDO_LOW_MINUV, \
401 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530402 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900403 .n_voltages = MAX77686_VSEL_MASK + 1, \
404 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
405 .vsel_mask = MAX77686_VSEL_MASK, \
406 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
407 .enable_mask = MAX77686_OPMODE_MASK \
408 << MAX77686_OPMODE_SHIFT, \
409}
410#define regulator_desc_buck(num) { \
411 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100412 .of_match = of_match_ptr("BUCK"#num), \
413 .regulators_node = of_match_ptr("voltage-regulators"), \
Krzysztof Kozlowski3307e902015-01-05 12:48:43 +0100414 .of_parse_cb = max77686_of_parse_cb, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900415 .id = MAX77686_BUCK##num, \
416 .ops = &max77686_ops, \
417 .type = REGULATOR_VOLTAGE, \
418 .owner = THIS_MODULE, \
419 .min_uV = MAX77686_BUCK_MINUV, \
420 .uV_step = MAX77686_BUCK_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530421 .ramp_delay = MAX77686_RAMP_DELAY, \
Krzysztof Kozlowskia9597302016-04-29 12:59:51 +0200422 .enable_time = MAX77686_BUCK_ENABLE_TIME, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900423 .n_voltages = MAX77686_VSEL_MASK + 1, \
424 .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \
425 .vsel_mask = MAX77686_VSEL_MASK, \
426 .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \
427 .enable_mask = MAX77686_OPMODE_MASK, \
428}
429#define regulator_desc_buck1(num) { \
430 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100431 .of_match = of_match_ptr("BUCK"#num), \
432 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900433 .id = MAX77686_BUCK##num, \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530434 .ops = &max77686_buck1_ops, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900435 .type = REGULATOR_VOLTAGE, \
436 .owner = THIS_MODULE, \
437 .min_uV = MAX77686_BUCK_MINUV, \
438 .uV_step = MAX77686_BUCK_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530439 .ramp_delay = MAX77686_RAMP_DELAY, \
Krzysztof Kozlowskia9597302016-04-29 12:59:51 +0200440 .enable_time = MAX77686_BUCK_ENABLE_TIME, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900441 .n_voltages = MAX77686_VSEL_MASK + 1, \
442 .vsel_reg = MAX77686_REG_BUCK1OUT, \
443 .vsel_mask = MAX77686_VSEL_MASK, \
444 .enable_reg = MAX77686_REG_BUCK1CTRL, \
445 .enable_mask = MAX77686_OPMODE_MASK, \
446}
447#define regulator_desc_buck_dvs(num) { \
448 .name = "BUCK"#num, \
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100449 .of_match = of_match_ptr("BUCK"#num), \
450 .regulators_node = of_match_ptr("voltage-regulators"), \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900451 .id = MAX77686_BUCK##num, \
Axel Lin74adfee52012-06-04 10:19:18 +0800452 .ops = &max77686_buck_dvs_ops, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900453 .type = REGULATOR_VOLTAGE, \
454 .owner = THIS_MODULE, \
455 .min_uV = MAX77686_DVS_MINUV, \
456 .uV_step = MAX77686_DVS_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530457 .ramp_delay = MAX77686_DVS_RAMP_DELAY, \
Krzysztof Kozlowskia9597302016-04-29 12:59:51 +0200458 .enable_time = MAX77686_DVS_ENABLE_TIME, \
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
Linus Walleij96392c32018-11-15 09:01:19 +0100519 max77686->dev = &pdev->dev;
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100520 config.dev = iodev->dev;
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530521 config.regmap = iodev->regmap;
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530522 config.driver_data = max77686;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900523 platform_set_drvdata(pdev, max77686);
524
Axel Linab0d1cb2012-06-08 12:03:04 +0800525 for (i = 0; i < MAX77686_REGULATORS; i++) {
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100526 struct regulator_dev *rdev;
Krzysztof Kozlowskieca29da2014-11-04 09:49:41 +0100527 int id = regulators[i].id;
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100528
Krzysztof Kozlowski4524df82014-11-04 09:49:42 +0100529 max77686->opmode[id] = MAX77686_NORMAL;
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100530 rdev = devm_regulator_register(&pdev->dev,
Sachin Kamat44815b42013-09-04 11:07:54 +0530531 &regulators[i], &config);
Krzysztof Kozlowskib0c13e82014-03-10 09:32:45 +0100532 if (IS_ERR(rdev)) {
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100533 int ret = PTR_ERR(rdev);
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530534 dev_err(&pdev->dev,
Krzysztof Kozlowski04803952014-11-05 10:47:50 +0100535 "regulator init failed for %d: %d\n", i, ret);
536 return ret;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900537 }
Jonghwa Lee133d4012012-06-01 13:17:14 +0900538 }
Axel Linab0d1cb2012-06-08 12:03:04 +0800539
Jonghwa Lee133d4012012-06-01 13:17:14 +0900540 return 0;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900541}
542
543static const struct platform_device_id max77686_pmic_id[] = {
544 {"max77686-pmic", 0},
545 { },
546};
547MODULE_DEVICE_TABLE(platform, max77686_pmic_id);
548
549static struct platform_driver max77686_pmic_driver = {
550 .driver = {
551 .name = "max77686-pmic",
Jonghwa Lee133d4012012-06-01 13:17:14 +0900552 },
553 .probe = max77686_pmic_probe,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900554 .id_table = max77686_pmic_id,
555};
556
Javier Martinez Canillas314a8202016-04-06 09:49:47 -0400557module_platform_driver(max77686_pmic_driver);
Jonghwa Lee133d4012012-06-01 13:17:14 +0900558
559MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver");
560MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
561MODULE_LICENSE("GPL");