2 * Voltage regulator support for AMS AS3722 PMIC
4 * Copyright (C) 2013 ams
6 * Author: Florian Lobmaier <florian.lobmaier@ams.com>
7 * Author: Laxman Dewangan <ldewangan@nvidia.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/err.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/mfd/as3722.h>
30 #include <linux/of_platform.h>
31 #include <linux/platform_device.h>
32 #include <linux/regulator/driver.h>
33 #include <linux/regulator/machine.h>
34 #include <linux/regulator/of_regulator.h>
35 #include <linux/slab.h>
38 enum as3722_regulators_id {
39 AS3722_REGULATOR_ID_SD0,
40 AS3722_REGULATOR_ID_SD1,
41 AS3722_REGULATOR_ID_SD2,
42 AS3722_REGULATOR_ID_SD3,
43 AS3722_REGULATOR_ID_SD4,
44 AS3722_REGULATOR_ID_SD5,
45 AS3722_REGULATOR_ID_SD6,
46 AS3722_REGULATOR_ID_LDO0,
47 AS3722_REGULATOR_ID_LDO1,
48 AS3722_REGULATOR_ID_LDO2,
49 AS3722_REGULATOR_ID_LDO3,
50 AS3722_REGULATOR_ID_LDO4,
51 AS3722_REGULATOR_ID_LDO5,
52 AS3722_REGULATOR_ID_LDO6,
53 AS3722_REGULATOR_ID_LDO7,
54 AS3722_REGULATOR_ID_LDO9,
55 AS3722_REGULATOR_ID_LDO10,
56 AS3722_REGULATOR_ID_LDO11,
57 AS3722_REGULATOR_ID_MAX,
60 struct as3722_register_mapping {
75 struct as3722_regulator_config_data {
76 struct regulator_init_data *reg_init;
81 struct as3722_regulators {
83 struct as3722 *as3722;
84 struct regulator_dev *rdevs[AS3722_REGULATOR_ID_MAX];
85 struct regulator_desc desc[AS3722_REGULATOR_ID_MAX];
86 struct as3722_regulator_config_data
87 reg_config_data[AS3722_REGULATOR_ID_MAX];
90 static const struct as3722_register_mapping as3722_reg_lookup[] = {
92 .regulator_id = AS3722_REGULATOR_ID_SD0,
94 .vsel_reg = AS3722_SD0_VOLTAGE_REG,
95 .vsel_mask = AS3722_SD_VSEL_MASK,
96 .enable_reg = AS3722_SD_CONTROL_REG,
97 .enable_mask = AS3722_SDn_CTRL(0),
98 .sleep_ctrl_reg = AS3722_ENABLE_CTRL1_REG,
99 .sleep_ctrl_mask = AS3722_SD0_EXT_ENABLE_MASK,
100 .control_reg = AS3722_SD0_CONTROL_REG,
101 .mode_mask = AS3722_SD0_MODE_FAST,
104 .regulator_id = AS3722_REGULATOR_ID_SD1,
105 .name = "as3722-sd1",
106 .vsel_reg = AS3722_SD1_VOLTAGE_REG,
107 .vsel_mask = AS3722_SD_VSEL_MASK,
108 .enable_reg = AS3722_SD_CONTROL_REG,
109 .enable_mask = AS3722_SDn_CTRL(1),
110 .sleep_ctrl_reg = AS3722_ENABLE_CTRL1_REG,
111 .sleep_ctrl_mask = AS3722_SD1_EXT_ENABLE_MASK,
112 .control_reg = AS3722_SD1_CONTROL_REG,
113 .mode_mask = AS3722_SD1_MODE_FAST,
116 .regulator_id = AS3722_REGULATOR_ID_SD2,
117 .name = "as3722-sd2",
119 .vsel_reg = AS3722_SD2_VOLTAGE_REG,
120 .vsel_mask = AS3722_SD_VSEL_MASK,
121 .enable_reg = AS3722_SD_CONTROL_REG,
122 .enable_mask = AS3722_SDn_CTRL(2),
123 .sleep_ctrl_reg = AS3722_ENABLE_CTRL1_REG,
124 .sleep_ctrl_mask = AS3722_SD2_EXT_ENABLE_MASK,
125 .control_reg = AS3722_SD23_CONTROL_REG,
126 .mode_mask = AS3722_SD2_MODE_FAST,
127 .n_voltages = AS3722_SD2_VSEL_MAX + 1,
130 .regulator_id = AS3722_REGULATOR_ID_SD3,
131 .name = "as3722-sd3",
133 .vsel_reg = AS3722_SD3_VOLTAGE_REG,
134 .vsel_mask = AS3722_SD_VSEL_MASK,
135 .enable_reg = AS3722_SD_CONTROL_REG,
136 .enable_mask = AS3722_SDn_CTRL(3),
137 .sleep_ctrl_reg = AS3722_ENABLE_CTRL1_REG,
138 .sleep_ctrl_mask = AS3722_SD3_EXT_ENABLE_MASK,
139 .control_reg = AS3722_SD23_CONTROL_REG,
140 .mode_mask = AS3722_SD3_MODE_FAST,
141 .n_voltages = AS3722_SD2_VSEL_MAX + 1,
144 .regulator_id = AS3722_REGULATOR_ID_SD4,
145 .name = "as3722-sd4",
147 .vsel_reg = AS3722_SD4_VOLTAGE_REG,
148 .vsel_mask = AS3722_SD_VSEL_MASK,
149 .enable_reg = AS3722_SD_CONTROL_REG,
150 .enable_mask = AS3722_SDn_CTRL(4),
151 .sleep_ctrl_reg = AS3722_ENABLE_CTRL2_REG,
152 .sleep_ctrl_mask = AS3722_SD4_EXT_ENABLE_MASK,
153 .control_reg = AS3722_SD4_CONTROL_REG,
154 .mode_mask = AS3722_SD4_MODE_FAST,
155 .n_voltages = AS3722_SD2_VSEL_MAX + 1,
158 .regulator_id = AS3722_REGULATOR_ID_SD5,
159 .name = "as3722-sd5",
161 .vsel_reg = AS3722_SD5_VOLTAGE_REG,
162 .vsel_mask = AS3722_SD_VSEL_MASK,
163 .enable_reg = AS3722_SD_CONTROL_REG,
164 .enable_mask = AS3722_SDn_CTRL(5),
165 .sleep_ctrl_reg = AS3722_ENABLE_CTRL2_REG,
166 .sleep_ctrl_mask = AS3722_SD5_EXT_ENABLE_MASK,
167 .control_reg = AS3722_SD5_CONTROL_REG,
168 .mode_mask = AS3722_SD5_MODE_FAST,
169 .n_voltages = AS3722_SD2_VSEL_MAX + 1,
172 .regulator_id = AS3722_REGULATOR_ID_SD6,
173 .name = "as3722-sd6",
174 .vsel_reg = AS3722_SD6_VOLTAGE_REG,
175 .vsel_mask = AS3722_SD_VSEL_MASK,
176 .enable_reg = AS3722_SD_CONTROL_REG,
177 .enable_mask = AS3722_SDn_CTRL(6),
178 .sleep_ctrl_reg = AS3722_ENABLE_CTRL2_REG,
179 .sleep_ctrl_mask = AS3722_SD6_EXT_ENABLE_MASK,
180 .control_reg = AS3722_SD6_CONTROL_REG,
181 .mode_mask = AS3722_SD6_MODE_FAST,
184 .regulator_id = AS3722_REGULATOR_ID_LDO0,
185 .name = "as3722-ldo0",
187 .vsel_reg = AS3722_LDO0_VOLTAGE_REG,
188 .vsel_mask = AS3722_LDO0_VSEL_MASK,
189 .enable_reg = AS3722_LDOCONTROL0_REG,
190 .enable_mask = AS3722_LDO0_CTRL,
191 .sleep_ctrl_reg = AS3722_ENABLE_CTRL3_REG,
192 .sleep_ctrl_mask = AS3722_LDO0_EXT_ENABLE_MASK,
193 .n_voltages = AS3722_LDO0_NUM_VOLT,
196 .regulator_id = AS3722_REGULATOR_ID_LDO1,
197 .name = "as3722-ldo1",
198 .sname = "vin-ldo1-6",
199 .vsel_reg = AS3722_LDO1_VOLTAGE_REG,
200 .vsel_mask = AS3722_LDO_VSEL_MASK,
201 .enable_reg = AS3722_LDOCONTROL0_REG,
202 .enable_mask = AS3722_LDO1_CTRL,
203 .sleep_ctrl_reg = AS3722_ENABLE_CTRL3_REG,
204 .sleep_ctrl_mask = AS3722_LDO1_EXT_ENABLE_MASK,
205 .n_voltages = AS3722_LDO_NUM_VOLT,
208 .regulator_id = AS3722_REGULATOR_ID_LDO2,
209 .name = "as3722-ldo2",
210 .sname = "vin-ldo2-5-7",
211 .vsel_reg = AS3722_LDO2_VOLTAGE_REG,
212 .vsel_mask = AS3722_LDO_VSEL_MASK,
213 .enable_reg = AS3722_LDOCONTROL0_REG,
214 .enable_mask = AS3722_LDO2_CTRL,
215 .sleep_ctrl_reg = AS3722_ENABLE_CTRL3_REG,
216 .sleep_ctrl_mask = AS3722_LDO2_EXT_ENABLE_MASK,
217 .n_voltages = AS3722_LDO_NUM_VOLT,
220 .regulator_id = AS3722_REGULATOR_ID_LDO3,
221 .name = "as3722-ldo3",
222 .name = "vin-ldo3-4",
223 .vsel_reg = AS3722_LDO3_VOLTAGE_REG,
224 .vsel_mask = AS3722_LDO3_VSEL_MASK,
225 .enable_reg = AS3722_LDOCONTROL0_REG,
226 .enable_mask = AS3722_LDO3_CTRL,
227 .sleep_ctrl_reg = AS3722_ENABLE_CTRL3_REG,
228 .sleep_ctrl_mask = AS3722_LDO3_EXT_ENABLE_MASK,
229 .n_voltages = AS3722_LDO3_NUM_VOLT,
232 .regulator_id = AS3722_REGULATOR_ID_LDO4,
233 .name = "as3722-ldo4",
234 .name = "vin-ldo3-4",
235 .vsel_reg = AS3722_LDO4_VOLTAGE_REG,
236 .vsel_mask = AS3722_LDO_VSEL_MASK,
237 .enable_reg = AS3722_LDOCONTROL0_REG,
238 .enable_mask = AS3722_LDO4_CTRL,
239 .sleep_ctrl_reg = AS3722_ENABLE_CTRL4_REG,
240 .sleep_ctrl_mask = AS3722_LDO4_EXT_ENABLE_MASK,
241 .n_voltages = AS3722_LDO_NUM_VOLT,
244 .regulator_id = AS3722_REGULATOR_ID_LDO5,
245 .name = "as3722-ldo5",
246 .sname = "vin-ldo2-5-7",
247 .vsel_reg = AS3722_LDO5_VOLTAGE_REG,
248 .vsel_mask = AS3722_LDO_VSEL_MASK,
249 .enable_reg = AS3722_LDOCONTROL0_REG,
250 .enable_mask = AS3722_LDO5_CTRL,
251 .sleep_ctrl_reg = AS3722_ENABLE_CTRL4_REG,
252 .sleep_ctrl_mask = AS3722_LDO5_EXT_ENABLE_MASK,
253 .n_voltages = AS3722_LDO_NUM_VOLT,
256 .regulator_id = AS3722_REGULATOR_ID_LDO6,
257 .name = "as3722-ldo6",
258 .sname = "vin-ldo1-6",
259 .vsel_reg = AS3722_LDO6_VOLTAGE_REG,
260 .vsel_mask = AS3722_LDO_VSEL_MASK,
261 .enable_reg = AS3722_LDOCONTROL0_REG,
262 .enable_mask = AS3722_LDO6_CTRL,
263 .sleep_ctrl_reg = AS3722_ENABLE_CTRL4_REG,
264 .sleep_ctrl_mask = AS3722_LDO6_EXT_ENABLE_MASK,
265 .n_voltages = AS3722_LDO_NUM_VOLT,
268 .regulator_id = AS3722_REGULATOR_ID_LDO7,
269 .name = "as3722-ldo7",
270 .sname = "vin-ldo2-5-7",
271 .vsel_reg = AS3722_LDO7_VOLTAGE_REG,
272 .vsel_mask = AS3722_LDO_VSEL_MASK,
273 .enable_reg = AS3722_LDOCONTROL0_REG,
274 .enable_mask = AS3722_LDO7_CTRL,
275 .sleep_ctrl_reg = AS3722_ENABLE_CTRL4_REG,
276 .sleep_ctrl_mask = AS3722_LDO7_EXT_ENABLE_MASK,
277 .n_voltages = AS3722_LDO_NUM_VOLT,
280 .regulator_id = AS3722_REGULATOR_ID_LDO9,
281 .name = "as3722-ldo9",
282 .sname = "vin-ldo9-10",
283 .vsel_reg = AS3722_LDO9_VOLTAGE_REG,
284 .vsel_mask = AS3722_LDO_VSEL_MASK,
285 .enable_reg = AS3722_LDOCONTROL1_REG,
286 .enable_mask = AS3722_LDO9_CTRL,
287 .sleep_ctrl_reg = AS3722_ENABLE_CTRL5_REG,
288 .sleep_ctrl_mask = AS3722_LDO9_EXT_ENABLE_MASK,
289 .n_voltages = AS3722_LDO_NUM_VOLT,
292 .regulator_id = AS3722_REGULATOR_ID_LDO10,
293 .name = "as3722-ldo10",
294 .sname = "vin-ldo9-10",
295 .vsel_reg = AS3722_LDO10_VOLTAGE_REG,
296 .vsel_mask = AS3722_LDO_VSEL_MASK,
297 .enable_reg = AS3722_LDOCONTROL1_REG,
298 .enable_mask = AS3722_LDO10_CTRL,
299 .sleep_ctrl_reg = AS3722_ENABLE_CTRL5_REG,
300 .sleep_ctrl_mask = AS3722_LDO10_EXT_ENABLE_MASK,
301 .n_voltages = AS3722_LDO_NUM_VOLT,
304 .regulator_id = AS3722_REGULATOR_ID_LDO11,
305 .name = "as3722-ldo11",
306 .sname = "vin-ldo11",
307 .vsel_reg = AS3722_LDO11_VOLTAGE_REG,
308 .vsel_mask = AS3722_LDO_VSEL_MASK,
309 .enable_reg = AS3722_LDOCONTROL1_REG,
310 .enable_mask = AS3722_LDO11_CTRL,
311 .sleep_ctrl_reg = AS3722_ENABLE_CTRL5_REG,
312 .sleep_ctrl_mask = AS3722_LDO11_EXT_ENABLE_MASK,
313 .n_voltages = AS3722_LDO_NUM_VOLT,
318 static const int as3722_ldo_current[] = { 150000, 300000 };
319 static const int as3722_sd016_current[] = { 2500000, 3000000, 3500000 };
321 static int as3722_current_to_index(int min_uA, int max_uA,
322 const int *curr_table, int n_currents)
326 for (i = n_currents - 1; i >= 0; i--) {
327 if ((min_uA <= curr_table[i]) && (curr_table[i] <= max_uA))
333 static int as3722_ldo_get_current_limit(struct regulator_dev *rdev)
335 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
336 struct as3722 *as3722 = as3722_regs->as3722;
337 int id = rdev_get_id(rdev);
341 ret = as3722_read(as3722, as3722_reg_lookup[id].vsel_reg, &val);
343 dev_err(as3722_regs->dev, "Reg 0x%02x read failed: %d\n",
344 as3722_reg_lookup[id].vsel_reg, ret);
347 if (val & AS3722_LDO_ILIMIT_MASK)
352 static int as3722_ldo_set_current_limit(struct regulator_dev *rdev,
353 int min_uA, int max_uA)
355 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
356 struct as3722 *as3722 = as3722_regs->as3722;
357 int id = rdev_get_id(rdev);
361 ret = as3722_current_to_index(min_uA, max_uA, as3722_ldo_current,
362 ARRAY_SIZE(as3722_ldo_current));
364 dev_err(as3722_regs->dev,
365 "Current range min:max = %d:%d does not support\n",
370 reg = AS3722_LDO_ILIMIT_BIT;
371 return as3722_update_bits(as3722, as3722_reg_lookup[id].vsel_reg,
372 AS3722_LDO_ILIMIT_MASK, reg);
375 static struct regulator_ops as3722_ldo0_ops = {
376 .is_enabled = regulator_is_enabled_regmap,
377 .enable = regulator_enable_regmap,
378 .disable = regulator_disable_regmap,
379 .list_voltage = regulator_list_voltage_linear,
380 .get_voltage_sel = regulator_get_voltage_sel_regmap,
381 .set_voltage_sel = regulator_set_voltage_sel_regmap,
382 .get_current_limit = as3722_ldo_get_current_limit,
383 .set_current_limit = as3722_ldo_set_current_limit,
386 static struct regulator_ops as3722_ldo0_extcntrl_ops = {
387 .list_voltage = regulator_list_voltage_linear,
388 .get_voltage_sel = regulator_get_voltage_sel_regmap,
389 .set_voltage_sel = regulator_set_voltage_sel_regmap,
390 .get_current_limit = as3722_ldo_get_current_limit,
391 .set_current_limit = as3722_ldo_set_current_limit,
394 static int as3722_ldo3_set_tracking_mode(struct as3722_regulators *as3722_reg,
397 struct as3722 *as3722 = as3722_reg->as3722;
400 case AS3722_LDO3_MODE_PMOS:
401 case AS3722_LDO3_MODE_PMOS_TRACKING:
402 case AS3722_LDO3_MODE_NMOS:
403 case AS3722_LDO3_MODE_SWITCH:
404 return as3722_update_bits(as3722,
405 as3722_reg_lookup[id].vsel_reg,
406 AS3722_LDO3_MODE_MASK, mode);
413 static int as3722_ldo3_get_current_limit(struct regulator_dev *rdev)
418 static struct regulator_ops as3722_ldo3_ops = {
419 .is_enabled = regulator_is_enabled_regmap,
420 .enable = regulator_enable_regmap,
421 .disable = regulator_disable_regmap,
422 .list_voltage = regulator_list_voltage_linear,
423 .get_voltage_sel = regulator_get_voltage_sel_regmap,
424 .set_voltage_sel = regulator_set_voltage_sel_regmap,
425 .get_current_limit = as3722_ldo3_get_current_limit,
428 static struct regulator_ops as3722_ldo3_extcntrl_ops = {
429 .list_voltage = regulator_list_voltage_linear,
430 .get_voltage_sel = regulator_get_voltage_sel_regmap,
431 .set_voltage_sel = regulator_set_voltage_sel_regmap,
432 .get_current_limit = as3722_ldo3_get_current_limit,
435 static const struct regulator_linear_range as3722_ldo_ranges[] = {
436 REGULATOR_LINEAR_RANGE(825000, 0x01, 0x24, 25000),
437 REGULATOR_LINEAR_RANGE(1725000, 0x40, 0x7F, 25000),
440 static struct regulator_ops as3722_ldo_ops = {
441 .is_enabled = regulator_is_enabled_regmap,
442 .enable = regulator_enable_regmap,
443 .disable = regulator_disable_regmap,
444 .map_voltage = regulator_map_voltage_linear_range,
445 .set_voltage_sel = regulator_set_voltage_sel_regmap,
446 .get_voltage_sel = regulator_get_voltage_sel_regmap,
447 .list_voltage = regulator_list_voltage_linear_range,
448 .get_current_limit = as3722_ldo_get_current_limit,
449 .set_current_limit = as3722_ldo_set_current_limit,
452 static struct regulator_ops as3722_ldo_extcntrl_ops = {
453 .map_voltage = regulator_map_voltage_linear_range,
454 .set_voltage_sel = regulator_set_voltage_sel_regmap,
455 .get_voltage_sel = regulator_get_voltage_sel_regmap,
456 .list_voltage = regulator_list_voltage_linear_range,
457 .get_current_limit = as3722_ldo_get_current_limit,
458 .set_current_limit = as3722_ldo_set_current_limit,
461 static unsigned int as3722_sd_get_mode(struct regulator_dev *rdev)
463 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
464 struct as3722 *as3722 = as3722_regs->as3722;
465 int id = rdev_get_id(rdev);
469 if (!as3722_reg_lookup[id].control_reg)
472 ret = as3722_read(as3722, as3722_reg_lookup[id].control_reg, &val);
474 dev_err(as3722_regs->dev, "Reg 0x%02x read failed: %d\n",
475 as3722_reg_lookup[id].control_reg, ret);
479 if (val & as3722_reg_lookup[id].mode_mask)
480 return REGULATOR_MODE_FAST;
482 return REGULATOR_MODE_NORMAL;
485 static int as3722_sd_set_mode(struct regulator_dev *rdev,
488 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
489 struct as3722 *as3722 = as3722_regs->as3722;
490 u8 id = rdev_get_id(rdev);
494 if (!as3722_reg_lookup[id].control_reg)
498 case REGULATOR_MODE_FAST:
499 val = as3722_reg_lookup[id].mode_mask;
500 case REGULATOR_MODE_NORMAL: /* fall down */
506 ret = as3722_update_bits(as3722, as3722_reg_lookup[id].control_reg,
507 as3722_reg_lookup[id].mode_mask, val);
509 dev_err(as3722_regs->dev, "Reg 0x%02x update failed: %d\n",
510 as3722_reg_lookup[id].control_reg, ret);
516 static int as3722_sd016_get_current_limit(struct regulator_dev *rdev)
518 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
519 struct as3722 *as3722 = as3722_regs->as3722;
520 int id = rdev_get_id(rdev);
526 case AS3722_REGULATOR_ID_SD0:
527 reg = AS3722_OVCURRENT_REG;
528 mask = AS3722_OVCURRENT_SD0_TRIP_MASK;
530 case AS3722_REGULATOR_ID_SD1:
531 reg = AS3722_OVCURRENT_REG;
532 mask = AS3722_OVCURRENT_SD1_TRIP_MASK;
534 case AS3722_REGULATOR_ID_SD6:
535 reg = AS3722_OVCURRENT_DEB_REG;
536 mask = AS3722_OVCURRENT_SD6_TRIP_MASK;
541 ret = as3722_read(as3722, reg, &val);
543 dev_err(as3722_regs->dev, "Reg 0x%02x read failed: %d\n",
548 val >>= ffs(mask) - 1;
551 return as3722_sd016_current[val];
554 static int as3722_sd016_set_current_limit(struct regulator_dev *rdev,
555 int min_uA, int max_uA)
557 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
558 struct as3722 *as3722 = as3722_regs->as3722;
559 int id = rdev_get_id(rdev);
565 ret = as3722_current_to_index(min_uA, max_uA, as3722_sd016_current,
566 ARRAY_SIZE(as3722_sd016_current));
568 dev_err(as3722_regs->dev,
569 "Current range min:max = %d:%d does not support\n",
575 case AS3722_REGULATOR_ID_SD0:
576 reg = AS3722_OVCURRENT_REG;
577 mask = AS3722_OVCURRENT_SD0_TRIP_MASK;
579 case AS3722_REGULATOR_ID_SD1:
580 reg = AS3722_OVCURRENT_REG;
581 mask = AS3722_OVCURRENT_SD1_TRIP_MASK;
583 case AS3722_REGULATOR_ID_SD6:
584 reg = AS3722_OVCURRENT_DEB_REG;
585 mask = AS3722_OVCURRENT_SD6_TRIP_MASK;
590 ret <<= ffs(mask) - 1;
592 return as3722_update_bits(as3722, reg, mask, val);
595 static bool as3722_sd0_is_low_voltage(struct as3722_regulators *as3722_regs)
600 err = as3722_read(as3722_regs->as3722, AS3722_FUSE7_REG, &val);
602 dev_err(as3722_regs->dev, "Reg 0x%02x read failed: %d\n",
603 AS3722_FUSE7_REG, err);
606 if (val & AS3722_FUSE7_SD0_LOW_VOLTAGE)
611 static const struct regulator_linear_range as3722_sd2345_ranges[] = {
612 REGULATOR_LINEAR_RANGE(612500, 0x01, 0x40, 12500),
613 REGULATOR_LINEAR_RANGE(1425000, 0x41, 0x70, 25000),
614 REGULATOR_LINEAR_RANGE(2650000, 0x71, 0x7F, 50000),
617 static struct regulator_ops as3722_sd016_ops = {
618 .is_enabled = regulator_is_enabled_regmap,
619 .enable = regulator_enable_regmap,
620 .disable = regulator_disable_regmap,
621 .list_voltage = regulator_list_voltage_linear,
622 .map_voltage = regulator_map_voltage_linear,
623 .get_voltage_sel = regulator_get_voltage_sel_regmap,
624 .set_voltage_sel = regulator_set_voltage_sel_regmap,
625 .get_current_limit = as3722_sd016_get_current_limit,
626 .set_current_limit = as3722_sd016_set_current_limit,
627 .get_mode = as3722_sd_get_mode,
628 .set_mode = as3722_sd_set_mode,
631 static struct regulator_ops as3722_sd016_extcntrl_ops = {
632 .list_voltage = regulator_list_voltage_linear,
633 .map_voltage = regulator_map_voltage_linear,
634 .get_voltage_sel = regulator_get_voltage_sel_regmap,
635 .set_voltage_sel = regulator_set_voltage_sel_regmap,
636 .get_current_limit = as3722_sd016_get_current_limit,
637 .set_current_limit = as3722_sd016_set_current_limit,
638 .get_mode = as3722_sd_get_mode,
639 .set_mode = as3722_sd_set_mode,
642 static struct regulator_ops as3722_sd2345_ops = {
643 .is_enabled = regulator_is_enabled_regmap,
644 .enable = regulator_enable_regmap,
645 .disable = regulator_disable_regmap,
646 .list_voltage = regulator_list_voltage_linear_range,
647 .map_voltage = regulator_map_voltage_linear_range,
648 .set_voltage_sel = regulator_set_voltage_sel_regmap,
649 .get_voltage_sel = regulator_get_voltage_sel_regmap,
650 .get_mode = as3722_sd_get_mode,
651 .set_mode = as3722_sd_set_mode,
654 static struct regulator_ops as3722_sd2345_extcntrl_ops = {
655 .list_voltage = regulator_list_voltage_linear_range,
656 .map_voltage = regulator_map_voltage_linear_range,
657 .set_voltage_sel = regulator_set_voltage_sel_regmap,
658 .get_voltage_sel = regulator_get_voltage_sel_regmap,
659 .get_mode = as3722_sd_get_mode,
660 .set_mode = as3722_sd_set_mode,
663 static int as3722_extreg_init(struct as3722_regulators *as3722_regs, int id,
669 if ((ext_pwr_ctrl < AS3722_EXT_CONTROL_ENABLE1) ||
670 (ext_pwr_ctrl > AS3722_EXT_CONTROL_ENABLE3))
673 val = ext_pwr_ctrl << (ffs(as3722_reg_lookup[id].sleep_ctrl_mask) - 1);
674 ret = as3722_update_bits(as3722_regs->as3722,
675 as3722_reg_lookup[id].sleep_ctrl_reg,
676 as3722_reg_lookup[id].sleep_ctrl_mask, val);
678 dev_err(as3722_regs->dev, "Reg 0x%02x update failed: %d\n",
679 as3722_reg_lookup[id].sleep_ctrl_reg, ret);
683 static struct of_regulator_match as3722_regulator_matches[] = {
700 { .name = "ldo10", },
701 { .name = "ldo11", },
704 static int as3722_get_regulator_dt_data(struct platform_device *pdev,
705 struct as3722_regulators *as3722_regs)
707 struct device_node *np;
708 struct as3722_regulator_config_data *reg_config;
713 np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
715 dev_err(&pdev->dev, "Device is not having regulators node\n");
718 pdev->dev.of_node = np;
720 ret = of_regulator_match(&pdev->dev, np, as3722_regulator_matches,
721 ARRAY_SIZE(as3722_regulator_matches));
723 dev_err(&pdev->dev, "Parsing of regulator node failed: %d\n",
728 for (id = 0; id < ARRAY_SIZE(as3722_regulator_matches); ++id) {
729 struct device_node *reg_node;
731 reg_config = &as3722_regs->reg_config_data[id];
732 reg_config->reg_init = as3722_regulator_matches[id].init_data;
733 reg_node = as3722_regulator_matches[id].of_node;
735 if (!reg_config->reg_init || !reg_node)
738 ret = of_property_read_u32(reg_node, "ams,ext-control", &prop);
741 reg_config->ext_control = prop;
744 "ext-control have invalid option: %u\n",
747 reg_config->enable_tracking =
748 of_property_read_bool(reg_node, "ams,enable-tracking");
753 static int as3722_regulator_probe(struct platform_device *pdev)
755 struct as3722 *as3722 = dev_get_drvdata(pdev->dev.parent);
756 struct as3722_regulators *as3722_regs;
757 struct as3722_regulator_config_data *reg_config;
758 struct regulator_dev *rdev;
759 struct regulator_config config = { };
760 struct regulator_ops *ops;
764 as3722_regs = devm_kzalloc(&pdev->dev, sizeof(*as3722_regs),
769 as3722_regs->dev = &pdev->dev;
770 as3722_regs->as3722 = as3722;
771 platform_set_drvdata(pdev, as3722_regs);
773 ret = as3722_get_regulator_dt_data(pdev, as3722_regs);
777 config.dev = &pdev->dev;
778 config.driver_data = as3722_regs;
779 config.regmap = as3722->regmap;
781 for (id = 0; id < AS3722_REGULATOR_ID_MAX; id++) {
782 reg_config = &as3722_regs->reg_config_data[id];
784 as3722_regs->desc[id].name = as3722_reg_lookup[id].name;
785 as3722_regs->desc[id].supply_name = as3722_reg_lookup[id].sname;
786 as3722_regs->desc[id].id = as3722_reg_lookup[id].regulator_id;
787 as3722_regs->desc[id].n_voltages =
788 as3722_reg_lookup[id].n_voltages;
789 as3722_regs->desc[id].type = REGULATOR_VOLTAGE;
790 as3722_regs->desc[id].owner = THIS_MODULE;
791 as3722_regs->desc[id].enable_reg =
792 as3722_reg_lookup[id].enable_reg;
793 as3722_regs->desc[id].enable_mask =
794 as3722_reg_lookup[id].enable_mask;
795 as3722_regs->desc[id].vsel_reg = as3722_reg_lookup[id].vsel_reg;
796 as3722_regs->desc[id].vsel_mask =
797 as3722_reg_lookup[id].vsel_mask;
799 case AS3722_REGULATOR_ID_LDO0:
800 if (reg_config->ext_control)
801 ops = &as3722_ldo0_extcntrl_ops;
803 ops = &as3722_ldo0_ops;
804 as3722_regs->desc[id].min_uV = 825000;
805 as3722_regs->desc[id].uV_step = 25000;
806 as3722_regs->desc[id].linear_min_sel = 1;
807 as3722_regs->desc[id].enable_time = 500;
809 case AS3722_REGULATOR_ID_LDO3:
810 if (reg_config->ext_control)
811 ops = &as3722_ldo3_extcntrl_ops;
813 ops = &as3722_ldo3_ops;
814 as3722_regs->desc[id].min_uV = 620000;
815 as3722_regs->desc[id].uV_step = 20000;
816 as3722_regs->desc[id].linear_min_sel = 1;
817 as3722_regs->desc[id].enable_time = 500;
818 if (reg_config->enable_tracking) {
819 ret = as3722_ldo3_set_tracking_mode(as3722_regs,
820 id, AS3722_LDO3_MODE_PMOS_TRACKING);
823 "LDO3 tracking failed: %d\n",
829 case AS3722_REGULATOR_ID_SD0:
830 case AS3722_REGULATOR_ID_SD1:
831 case AS3722_REGULATOR_ID_SD6:
832 if (reg_config->ext_control)
833 ops = &as3722_sd016_extcntrl_ops;
835 ops = &as3722_sd016_ops;
836 if (id == AS3722_REGULATOR_ID_SD0 &&
837 as3722_sd0_is_low_voltage(as3722_regs)) {
838 as3722_regs->desc[id].n_voltages =
839 AS3722_SD0_VSEL_LOW_VOL_MAX + 1;
840 as3722_regs->desc[id].min_uV = 410000;
842 as3722_regs->desc[id].n_voltages =
843 AS3722_SD0_VSEL_MAX + 1,
844 as3722_regs->desc[id].min_uV = 610000;
846 as3722_regs->desc[id].uV_step = 10000;
847 as3722_regs->desc[id].linear_min_sel = 1;
848 as3722_regs->desc[id].enable_time = 600;
850 case AS3722_REGULATOR_ID_SD2:
851 case AS3722_REGULATOR_ID_SD3:
852 case AS3722_REGULATOR_ID_SD4:
853 case AS3722_REGULATOR_ID_SD5:
854 if (reg_config->ext_control)
855 ops = &as3722_sd2345_extcntrl_ops;
857 ops = &as3722_sd2345_ops;
858 as3722_regs->desc[id].linear_ranges =
859 as3722_sd2345_ranges;
860 as3722_regs->desc[id].n_linear_ranges =
861 ARRAY_SIZE(as3722_sd2345_ranges);
864 if (reg_config->ext_control)
865 ops = &as3722_ldo_extcntrl_ops;
867 ops = &as3722_ldo_ops;
868 as3722_regs->desc[id].enable_time = 500;
869 as3722_regs->desc[id].linear_ranges = as3722_ldo_ranges;
870 as3722_regs->desc[id].n_linear_ranges =
871 ARRAY_SIZE(as3722_ldo_ranges);
874 as3722_regs->desc[id].ops = ops;
875 config.init_data = reg_config->reg_init;
876 config.of_node = as3722_regulator_matches[id].of_node;
877 rdev = devm_regulator_register(&pdev->dev,
878 &as3722_regs->desc[id], &config);
881 dev_err(&pdev->dev, "regulator %d register failed %d\n",
886 as3722_regs->rdevs[id] = rdev;
887 if (reg_config->ext_control) {
888 ret = regulator_enable_regmap(rdev);
891 "Regulator %d enable failed: %d\n",
895 ret = as3722_extreg_init(as3722_regs, id,
896 reg_config->ext_control);
899 "AS3722 ext control failed: %d", ret);
907 static const struct of_device_id of_as3722_regulator_match[] = {
908 { .compatible = "ams,as3722-regulator", },
911 MODULE_DEVICE_TABLE(of, of_as3722_regulator_match);
913 static struct platform_driver as3722_regulator_driver = {
915 .name = "as3722-regulator",
916 .owner = THIS_MODULE,
917 .of_match_table = of_as3722_regulator_match,
919 .probe = as3722_regulator_probe,
922 module_platform_driver(as3722_regulator_driver);
924 MODULE_ALIAS("platform:as3722-regulator");
925 MODULE_DESCRIPTION("AS3722 regulator driver");
926 MODULE_AUTHOR("Florian Lobmaier <florian.lobmaier@ams.com>");
927 MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
928 MODULE_LICENSE("GPL");