blob: b982f0ff4e01585114530a2514b0e7203b307b40 [file] [log] [blame]
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001/*
2 * Driver for Regulator part of Palmas PMIC Chips
3 *
Graeme Gregory7be859f2013-03-07 13:17:48 +00004 * Copyright 2011-2013 Texas Instruments Inc.
Graeme Gregorye5ce4202012-05-18 16:53:57 +01005 *
6 * Author: Graeme Gregory <gg@slimlogic.co.uk>
Graeme Gregorya7dddf22013-02-23 16:35:40 +00007 * Author: Ian Lartey <ian@slimlogic.co.uk>
Graeme Gregorye5ce4202012-05-18 16:53:57 +01008 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/err.h>
20#include <linux/platform_device.h>
21#include <linux/regulator/driver.h>
22#include <linux/regulator/machine.h>
23#include <linux/slab.h>
24#include <linux/regmap.h>
25#include <linux/mfd/palmas.h>
Graeme Gregorya361cd92012-08-28 13:47:40 +020026#include <linux/of.h>
27#include <linux/of_platform.h>
28#include <linux/regulator/of_regulator.h>
Graeme Gregorye5ce4202012-05-18 16:53:57 +010029
30struct regs_info {
31 char *name;
Laxman Dewangan504382c2013-03-20 19:26:37 +053032 char *sname;
Graeme Gregorye5ce4202012-05-18 16:53:57 +010033 u8 vsel_addr;
34 u8 ctrl_addr;
35 u8 tstep_addr;
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053036 int sleep_id;
Graeme Gregorye5ce4202012-05-18 16:53:57 +010037};
38
Keerthydbabd622014-05-22 14:48:29 +053039static const struct regulator_linear_range smps_low_ranges[] = {
Nishanth Menon6b7f2d82014-06-04 14:34:31 -050040 REGULATOR_LINEAR_RANGE(0, 0x0, 0x0, 0),
Keerthydbabd622014-05-22 14:48:29 +053041 REGULATOR_LINEAR_RANGE(500000, 0x1, 0x6, 0),
42 REGULATOR_LINEAR_RANGE(510000, 0x7, 0x79, 10000),
43 REGULATOR_LINEAR_RANGE(1650000, 0x7A, 0x7f, 0),
44};
45
46static const struct regulator_linear_range smps_high_ranges[] = {
Nishanth Menon6b7f2d82014-06-04 14:34:31 -050047 REGULATOR_LINEAR_RANGE(0, 0x0, 0x0, 0),
Keerthydbabd622014-05-22 14:48:29 +053048 REGULATOR_LINEAR_RANGE(1000000, 0x1, 0x6, 0),
49 REGULATOR_LINEAR_RANGE(1020000, 0x7, 0x79, 20000),
50 REGULATOR_LINEAR_RANGE(3300000, 0x7A, 0x7f, 0),
51};
52
Graeme Gregorye5ce4202012-05-18 16:53:57 +010053static const struct regs_info palmas_regs_info[] = {
54 {
55 .name = "SMPS12",
Laxman Dewangan504382c2013-03-20 19:26:37 +053056 .sname = "smps1-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010057 .vsel_addr = PALMAS_SMPS12_VOLTAGE,
58 .ctrl_addr = PALMAS_SMPS12_CTRL,
59 .tstep_addr = PALMAS_SMPS12_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053060 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS12,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010061 },
62 {
63 .name = "SMPS123",
Laxman Dewangan504382c2013-03-20 19:26:37 +053064 .sname = "smps1-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010065 .vsel_addr = PALMAS_SMPS12_VOLTAGE,
66 .ctrl_addr = PALMAS_SMPS12_CTRL,
67 .tstep_addr = PALMAS_SMPS12_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053068 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS12,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010069 },
70 {
71 .name = "SMPS3",
Laxman Dewangan504382c2013-03-20 19:26:37 +053072 .sname = "smps3-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010073 .vsel_addr = PALMAS_SMPS3_VOLTAGE,
74 .ctrl_addr = PALMAS_SMPS3_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053075 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS3,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010076 },
77 {
78 .name = "SMPS45",
Laxman Dewangan504382c2013-03-20 19:26:37 +053079 .sname = "smps4-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010080 .vsel_addr = PALMAS_SMPS45_VOLTAGE,
81 .ctrl_addr = PALMAS_SMPS45_CTRL,
82 .tstep_addr = PALMAS_SMPS45_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053083 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS45,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010084 },
85 {
86 .name = "SMPS457",
Laxman Dewangan504382c2013-03-20 19:26:37 +053087 .sname = "smps4-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010088 .vsel_addr = PALMAS_SMPS45_VOLTAGE,
89 .ctrl_addr = PALMAS_SMPS45_CTRL,
90 .tstep_addr = PALMAS_SMPS45_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053091 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS45,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010092 },
93 {
94 .name = "SMPS6",
Laxman Dewangan504382c2013-03-20 19:26:37 +053095 .sname = "smps6-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010096 .vsel_addr = PALMAS_SMPS6_VOLTAGE,
97 .ctrl_addr = PALMAS_SMPS6_CTRL,
98 .tstep_addr = PALMAS_SMPS6_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053099 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS6,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100100 },
101 {
102 .name = "SMPS7",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530103 .sname = "smps7-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100104 .vsel_addr = PALMAS_SMPS7_VOLTAGE,
105 .ctrl_addr = PALMAS_SMPS7_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530106 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS7,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100107 },
108 {
109 .name = "SMPS8",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530110 .sname = "smps8-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100111 .vsel_addr = PALMAS_SMPS8_VOLTAGE,
112 .ctrl_addr = PALMAS_SMPS8_CTRL,
113 .tstep_addr = PALMAS_SMPS8_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530114 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS8,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100115 },
116 {
117 .name = "SMPS9",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530118 .sname = "smps9-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100119 .vsel_addr = PALMAS_SMPS9_VOLTAGE,
120 .ctrl_addr = PALMAS_SMPS9_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530121 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS9,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100122 },
123 {
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530124 .name = "SMPS10_OUT2",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530125 .sname = "smps10-in",
Axel Line31089c2013-04-19 20:33:45 +0800126 .ctrl_addr = PALMAS_SMPS10_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530127 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS10,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100128 },
129 {
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530130 .name = "SMPS10_OUT1",
131 .sname = "smps10-out2",
132 .ctrl_addr = PALMAS_SMPS10_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530133 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS10,
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530134 },
135 {
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100136 .name = "LDO1",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530137 .sname = "ldo1-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100138 .vsel_addr = PALMAS_LDO1_VOLTAGE,
139 .ctrl_addr = PALMAS_LDO1_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530140 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO1,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100141 },
142 {
143 .name = "LDO2",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530144 .sname = "ldo2-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100145 .vsel_addr = PALMAS_LDO2_VOLTAGE,
146 .ctrl_addr = PALMAS_LDO2_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530147 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO2,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100148 },
149 {
150 .name = "LDO3",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530151 .sname = "ldo3-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100152 .vsel_addr = PALMAS_LDO3_VOLTAGE,
153 .ctrl_addr = PALMAS_LDO3_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530154 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO3,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100155 },
156 {
157 .name = "LDO4",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530158 .sname = "ldo4-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100159 .vsel_addr = PALMAS_LDO4_VOLTAGE,
160 .ctrl_addr = PALMAS_LDO4_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530161 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO4,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100162 },
163 {
164 .name = "LDO5",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530165 .sname = "ldo5-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100166 .vsel_addr = PALMAS_LDO5_VOLTAGE,
167 .ctrl_addr = PALMAS_LDO5_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530168 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO5,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100169 },
170 {
171 .name = "LDO6",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530172 .sname = "ldo6-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100173 .vsel_addr = PALMAS_LDO6_VOLTAGE,
174 .ctrl_addr = PALMAS_LDO6_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530175 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO6,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100176 },
177 {
178 .name = "LDO7",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530179 .sname = "ldo7-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100180 .vsel_addr = PALMAS_LDO7_VOLTAGE,
181 .ctrl_addr = PALMAS_LDO7_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530182 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO7,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100183 },
184 {
185 .name = "LDO8",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530186 .sname = "ldo8-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100187 .vsel_addr = PALMAS_LDO8_VOLTAGE,
188 .ctrl_addr = PALMAS_LDO8_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530189 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO8,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100190 },
191 {
192 .name = "LDO9",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530193 .sname = "ldo9-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100194 .vsel_addr = PALMAS_LDO9_VOLTAGE,
195 .ctrl_addr = PALMAS_LDO9_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530196 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO9,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100197 },
198 {
199 .name = "LDOLN",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530200 .sname = "ldoln-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100201 .vsel_addr = PALMAS_LDOLN_VOLTAGE,
202 .ctrl_addr = PALMAS_LDOLN_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530203 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDOLN,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100204 },
205 {
206 .name = "LDOUSB",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530207 .sname = "ldousb-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100208 .vsel_addr = PALMAS_LDOUSB_VOLTAGE,
209 .ctrl_addr = PALMAS_LDOUSB_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530210 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDOUSB,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100211 },
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530212 {
213 .name = "REGEN1",
214 .ctrl_addr = PALMAS_REGEN1_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530215 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN1,
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530216 },
217 {
218 .name = "REGEN2",
219 .ctrl_addr = PALMAS_REGEN2_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530220 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN2,
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530221 },
222 {
223 .name = "REGEN3",
224 .ctrl_addr = PALMAS_REGEN3_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530225 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN3,
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530226 },
227 {
228 .name = "SYSEN1",
229 .ctrl_addr = PALMAS_SYSEN1_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530230 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SYSEN1,
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530231 },
232 {
233 .name = "SYSEN2",
234 .ctrl_addr = PALMAS_SYSEN2_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530235 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SYSEN2,
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530236 },
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100237};
238
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530239static unsigned int palmas_smps_ramp_delay[4] = {0, 10000, 5000, 2500};
240
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100241#define SMPS_CTRL_MODE_OFF 0x00
242#define SMPS_CTRL_MODE_ON 0x01
243#define SMPS_CTRL_MODE_ECO 0x02
244#define SMPS_CTRL_MODE_PWM 0x03
245
Laxman Dewangan0f45aa82013-09-04 15:20:06 +0530246#define PALMAS_SMPS_NUM_VOLTAGES 122
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100247#define PALMAS_SMPS10_NUM_VOLTAGES 2
248#define PALMAS_LDO_NUM_VOLTAGES 50
249
250#define SMPS10_VSEL (1<<3)
251#define SMPS10_BOOST_EN (1<<2)
252#define SMPS10_BYPASS_EN (1<<1)
253#define SMPS10_SWITCH_EN (1<<0)
254
255#define REGULATOR_SLAVE 0
256
257static int palmas_smps_read(struct palmas *palmas, unsigned int reg,
258 unsigned int *dest)
259{
260 unsigned int addr;
261
262 addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
263
264 return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
265}
266
267static int palmas_smps_write(struct palmas *palmas, unsigned int reg,
268 unsigned int value)
269{
270 unsigned int addr;
271
272 addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
273
274 return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
275}
276
277static int palmas_ldo_read(struct palmas *palmas, unsigned int reg,
278 unsigned int *dest)
279{
280 unsigned int addr;
281
282 addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
283
284 return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
285}
286
287static int palmas_ldo_write(struct palmas *palmas, unsigned int reg,
288 unsigned int value)
289{
290 unsigned int addr;
291
292 addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
293
294 return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
295}
296
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100297static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
298{
299 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
300 int id = rdev_get_id(dev);
301 unsigned int reg;
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530302 bool rail_enable = true;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100303
304 palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
Axel Lin999f0c72012-06-07 17:08:21 +0800305 reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100306
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530307 if (reg == SMPS_CTRL_MODE_OFF)
308 rail_enable = false;
309
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100310 switch (mode) {
311 case REGULATOR_MODE_NORMAL:
312 reg |= SMPS_CTRL_MODE_ON;
313 break;
314 case REGULATOR_MODE_IDLE:
315 reg |= SMPS_CTRL_MODE_ECO;
316 break;
317 case REGULATOR_MODE_FAST:
318 reg |= SMPS_CTRL_MODE_PWM;
319 break;
320 default:
321 return -EINVAL;
322 }
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100323
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530324 pmic->current_reg_mode[id] = reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
325 if (rail_enable)
326 palmas_smps_write(pmic->palmas,
327 palmas_regs_info[id].ctrl_addr, reg);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100328 return 0;
329}
330
331static unsigned int palmas_get_mode_smps(struct regulator_dev *dev)
332{
333 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
334 int id = rdev_get_id(dev);
335 unsigned int reg;
336
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530337 reg = pmic->current_reg_mode[id] & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100338
339 switch (reg) {
340 case SMPS_CTRL_MODE_ON:
341 return REGULATOR_MODE_NORMAL;
342 case SMPS_CTRL_MODE_ECO:
343 return REGULATOR_MODE_IDLE;
344 case SMPS_CTRL_MODE_PWM:
345 return REGULATOR_MODE_FAST;
346 }
347
348 return 0;
349}
350
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530351static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev,
352 int ramp_delay)
353{
354 struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
355 int id = rdev_get_id(rdev);
356 unsigned int reg = 0;
357 unsigned int addr = palmas_regs_info[id].tstep_addr;
358 int ret;
359
Axel Linf22c2ba2013-04-19 14:18:48 +0800360 /* SMPS3 and SMPS7 do not have tstep_addr setting */
361 switch (id) {
362 case PALMAS_REG_SMPS3:
363 case PALMAS_REG_SMPS7:
364 return 0;
365 }
366
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530367 if (ramp_delay <= 0)
368 reg = 0;
Axel Lin0ea34b52013-04-22 18:22:49 +0800369 else if (ramp_delay <= 2500)
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530370 reg = 3;
Axel Lin0ea34b52013-04-22 18:22:49 +0800371 else if (ramp_delay <= 5000)
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530372 reg = 2;
373 else
374 reg = 1;
375
376 ret = palmas_smps_write(pmic->palmas, addr, reg);
377 if (ret < 0) {
378 dev_err(pmic->palmas->dev, "TSTEP write failed: %d\n", ret);
379 return ret;
380 }
381
382 pmic->ramp_delay[id] = palmas_smps_ramp_delay[reg];
383 return ret;
384}
385
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100386static struct regulator_ops palmas_ops_smps = {
Keerthydbabd622014-05-22 14:48:29 +0530387 .is_enabled = regulator_is_enabled_regmap,
388 .enable = regulator_enable_regmap,
389 .disable = regulator_disable_regmap,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100390 .set_mode = palmas_set_mode_smps,
391 .get_mode = palmas_get_mode_smps,
Axel Linbdc4baa2012-11-29 10:01:44 +0800392 .get_voltage_sel = regulator_get_voltage_sel_regmap,
393 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Keerthydbabd622014-05-22 14:48:29 +0530394 .list_voltage = regulator_list_voltage_linear_range,
395 .map_voltage = regulator_map_voltage_linear_range,
396 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530397 .set_ramp_delay = palmas_smps_set_ramp_delay,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100398};
399
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530400static struct regulator_ops palmas_ops_ext_control_smps = {
401 .set_mode = palmas_set_mode_smps,
402 .get_mode = palmas_get_mode_smps,
403 .get_voltage_sel = regulator_get_voltage_sel_regmap,
404 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Keerthydbabd622014-05-22 14:48:29 +0530405 .list_voltage = regulator_list_voltage_linear_range,
406 .map_voltage = regulator_map_voltage_linear_range,
407 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530408 .set_ramp_delay = palmas_smps_set_ramp_delay,
409};
410
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100411static struct regulator_ops palmas_ops_smps10 = {
412 .is_enabled = regulator_is_enabled_regmap,
413 .enable = regulator_enable_regmap,
414 .disable = regulator_disable_regmap,
415 .get_voltage_sel = regulator_get_voltage_sel_regmap,
416 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Axel Lin8029a002012-05-22 12:26:42 +0800417 .list_voltage = regulator_list_voltage_linear,
418 .map_voltage = regulator_map_voltage_linear,
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530419 .set_bypass = regulator_set_bypass_regmap,
420 .get_bypass = regulator_get_bypass_regmap,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100421};
422
423static int palmas_is_enabled_ldo(struct regulator_dev *dev)
424{
425 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
426 int id = rdev_get_id(dev);
427 unsigned int reg;
428
429 palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
430
431 reg &= PALMAS_LDO1_CTRL_STATUS;
432
433 return !!(reg);
434}
435
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100436static struct regulator_ops palmas_ops_ldo = {
437 .is_enabled = palmas_is_enabled_ldo,
438 .enable = regulator_enable_regmap,
439 .disable = regulator_disable_regmap,
Axel Lin4a247a92012-07-18 12:34:08 +0800440 .get_voltage_sel = regulator_get_voltage_sel_regmap,
441 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Axel Lin9119ff62012-11-27 10:27:34 +0800442 .list_voltage = regulator_list_voltage_linear,
443 .map_voltage = regulator_map_voltage_linear,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100444};
445
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530446static struct regulator_ops palmas_ops_ext_control_ldo = {
447 .get_voltage_sel = regulator_get_voltage_sel_regmap,
448 .set_voltage_sel = regulator_set_voltage_sel_regmap,
449 .list_voltage = regulator_list_voltage_linear,
450 .map_voltage = regulator_map_voltage_linear,
451};
452
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530453static struct regulator_ops palmas_ops_extreg = {
454 .is_enabled = regulator_is_enabled_regmap,
455 .enable = regulator_enable_regmap,
456 .disable = regulator_disable_regmap,
457};
458
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530459static struct regulator_ops palmas_ops_ext_control_extreg = {
460};
461
462static int palmas_regulator_config_external(struct palmas *palmas, int id,
463 struct palmas_reg_init *reg_init)
464{
465 int sleep_id = palmas_regs_info[id].sleep_id;
466 int ret;
467
468 ret = palmas_ext_control_req_config(palmas, sleep_id,
469 reg_init->roof_floor, true);
470 if (ret < 0)
471 dev_err(palmas->dev,
472 "Ext control config for regulator %d failed %d\n",
473 id, ret);
474 return ret;
475}
476
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100477/*
478 * setup the hardware based sleep configuration of the SMPS/LDO regulators
479 * from the platform data. This is different to the software based control
480 * supported by the regulator framework as it is controlled by toggling
481 * pins on the PMIC such as PREQ, SYSEN, ...
482 */
483static int palmas_smps_init(struct palmas *palmas, int id,
484 struct palmas_reg_init *reg_init)
485{
486 unsigned int reg;
487 unsigned int addr;
488 int ret;
489
490 addr = palmas_regs_info[id].ctrl_addr;
491
492 ret = palmas_smps_read(palmas, addr, &reg);
493 if (ret)
494 return ret;
495
Axel Linfedd89b2012-06-06 20:01:38 +0800496 switch (id) {
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530497 case PALMAS_REG_SMPS10_OUT1:
498 case PALMAS_REG_SMPS10_OUT2:
Laxman Dewangan30590d02013-04-17 15:13:11 +0530499 reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
500 if (reg_init->mode_sleep)
Axel Linfedd89b2012-06-06 20:01:38 +0800501 reg |= reg_init->mode_sleep <<
502 PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
Axel Linfedd89b2012-06-06 20:01:38 +0800503 break;
504 default:
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100505 if (reg_init->warm_reset)
506 reg |= PALMAS_SMPS12_CTRL_WR_S;
Laxman Dewangan30590d02013-04-17 15:13:11 +0530507 else
508 reg &= ~PALMAS_SMPS12_CTRL_WR_S;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100509
510 if (reg_init->roof_floor)
511 reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN;
Laxman Dewangan30590d02013-04-17 15:13:11 +0530512 else
513 reg &= ~PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100514
Laxman Dewangan30590d02013-04-17 15:13:11 +0530515 reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK;
516 if (reg_init->mode_sleep)
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100517 reg |= reg_init->mode_sleep <<
518 PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100519 }
Axel Linfedd89b2012-06-06 20:01:38 +0800520
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100521 ret = palmas_smps_write(palmas, addr, reg);
522 if (ret)
523 return ret;
524
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100525 if (palmas_regs_info[id].vsel_addr && reg_init->vsel) {
526 addr = palmas_regs_info[id].vsel_addr;
527
528 reg = reg_init->vsel;
529
530 ret = palmas_smps_write(palmas, addr, reg);
531 if (ret)
532 return ret;
533 }
534
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530535 if (reg_init->roof_floor && (id != PALMAS_REG_SMPS10_OUT1) &&
536 (id != PALMAS_REG_SMPS10_OUT2)) {
537 /* Enable externally controlled regulator */
538 addr = palmas_regs_info[id].ctrl_addr;
539 ret = palmas_smps_read(palmas, addr, &reg);
540 if (ret < 0)
541 return ret;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100542
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530543 if (!(reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK)) {
544 reg |= SMPS_CTRL_MODE_ON;
545 ret = palmas_smps_write(palmas, addr, reg);
546 if (ret < 0)
547 return ret;
548 }
549 return palmas_regulator_config_external(palmas, id, reg_init);
550 }
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100551 return 0;
552}
553
554static int palmas_ldo_init(struct palmas *palmas, int id,
555 struct palmas_reg_init *reg_init)
556{
557 unsigned int reg;
558 unsigned int addr;
559 int ret;
560
561 addr = palmas_regs_info[id].ctrl_addr;
562
Axel Lin2735dae2012-07-18 12:31:59 +0800563 ret = palmas_ldo_read(palmas, addr, &reg);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100564 if (ret)
565 return ret;
566
567 if (reg_init->warm_reset)
568 reg |= PALMAS_LDO1_CTRL_WR_S;
Laxman Dewangan30590d02013-04-17 15:13:11 +0530569 else
570 reg &= ~PALMAS_LDO1_CTRL_WR_S;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100571
572 if (reg_init->mode_sleep)
573 reg |= PALMAS_LDO1_CTRL_MODE_SLEEP;
Laxman Dewangan30590d02013-04-17 15:13:11 +0530574 else
575 reg &= ~PALMAS_LDO1_CTRL_MODE_SLEEP;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100576
Axel Lin2735dae2012-07-18 12:31:59 +0800577 ret = palmas_ldo_write(palmas, addr, reg);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100578 if (ret)
579 return ret;
580
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530581 if (reg_init->roof_floor) {
582 /* Enable externally controlled regulator */
583 addr = palmas_regs_info[id].ctrl_addr;
584 ret = palmas_update_bits(palmas, PALMAS_LDO_BASE,
585 addr, PALMAS_LDO1_CTRL_MODE_ACTIVE,
586 PALMAS_LDO1_CTRL_MODE_ACTIVE);
587 if (ret < 0) {
588 dev_err(palmas->dev,
589 "LDO Register 0x%02x update failed %d\n",
590 addr, ret);
591 return ret;
592 }
593 return palmas_regulator_config_external(palmas, id, reg_init);
594 }
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100595 return 0;
596}
597
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530598static int palmas_extreg_init(struct palmas *palmas, int id,
599 struct palmas_reg_init *reg_init)
600{
601 unsigned int addr;
602 int ret;
603 unsigned int val = 0;
604
605 addr = palmas_regs_info[id].ctrl_addr;
606
607 if (reg_init->mode_sleep)
608 val = PALMAS_REGEN1_CTRL_MODE_SLEEP;
609
610 ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE,
611 addr, PALMAS_REGEN1_CTRL_MODE_SLEEP, val);
612 if (ret < 0) {
613 dev_err(palmas->dev, "Resource reg 0x%02x update failed %d\n",
614 addr, ret);
615 return ret;
616 }
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530617
618 if (reg_init->roof_floor) {
619 /* Enable externally controlled regulator */
620 addr = palmas_regs_info[id].ctrl_addr;
621 ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE,
622 addr, PALMAS_REGEN1_CTRL_MODE_ACTIVE,
623 PALMAS_REGEN1_CTRL_MODE_ACTIVE);
624 if (ret < 0) {
625 dev_err(palmas->dev,
626 "Resource Register 0x%02x update failed %d\n",
627 addr, ret);
628 return ret;
629 }
630 return palmas_regulator_config_external(palmas, id, reg_init);
631 }
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530632 return 0;
633}
634
Laxman Dewangan17c11a72013-04-17 15:13:13 +0530635static void palmas_enable_ldo8_track(struct palmas *palmas)
636{
637 unsigned int reg;
638 unsigned int addr;
639 int ret;
640
641 addr = palmas_regs_info[PALMAS_REG_LDO8].ctrl_addr;
642
643 ret = palmas_ldo_read(palmas, addr, &reg);
644 if (ret) {
645 dev_err(palmas->dev, "Error in reading ldo8 control reg\n");
646 return;
647 }
648
649 reg |= PALMAS_LDO8_CTRL_LDO_TRACKING_EN;
650 ret = palmas_ldo_write(palmas, addr, reg);
651 if (ret < 0) {
652 dev_err(palmas->dev, "Error in enabling tracking mode\n");
653 return;
654 }
655 /*
656 * When SMPS45 is set to off and LDO8 tracking is enabled, the LDO8
657 * output is defined by the LDO8_VOLTAGE.VSEL register divided by two,
658 * and can be set from 0.45 to 1.65 V.
659 */
660 addr = palmas_regs_info[PALMAS_REG_LDO8].vsel_addr;
661 ret = palmas_ldo_read(palmas, addr, &reg);
662 if (ret) {
663 dev_err(palmas->dev, "Error in reading ldo8 voltage reg\n");
664 return;
665 }
666
667 reg = (reg << 1) & PALMAS_LDO8_VOLTAGE_VSEL_MASK;
668 ret = palmas_ldo_write(palmas, addr, reg);
669 if (ret < 0)
670 dev_err(palmas->dev, "Error in setting ldo8 voltage reg\n");
671
672 return;
673}
674
Graeme Gregorya361cd92012-08-28 13:47:40 +0200675static struct of_regulator_match palmas_matches[] = {
676 { .name = "smps12", },
677 { .name = "smps123", },
678 { .name = "smps3", },
679 { .name = "smps45", },
680 { .name = "smps457", },
681 { .name = "smps6", },
682 { .name = "smps7", },
683 { .name = "smps8", },
684 { .name = "smps9", },
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530685 { .name = "smps10_out2", },
686 { .name = "smps10_out1", },
Graeme Gregorya361cd92012-08-28 13:47:40 +0200687 { .name = "ldo1", },
688 { .name = "ldo2", },
689 { .name = "ldo3", },
690 { .name = "ldo4", },
691 { .name = "ldo5", },
692 { .name = "ldo6", },
693 { .name = "ldo7", },
694 { .name = "ldo8", },
695 { .name = "ldo9", },
696 { .name = "ldoln", },
697 { .name = "ldousb", },
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530698 { .name = "regen1", },
699 { .name = "regen2", },
700 { .name = "regen3", },
701 { .name = "sysen1", },
702 { .name = "sysen2", },
Graeme Gregorya361cd92012-08-28 13:47:40 +0200703};
704
Bill Pembertona5023572012-11-19 13:22:22 -0500705static void palmas_dt_to_pdata(struct device *dev,
Graeme Gregorya361cd92012-08-28 13:47:40 +0200706 struct device_node *node,
707 struct palmas_pmic_platform_data *pdata)
708{
709 struct device_node *regulators;
710 u32 prop;
711 int idx, ret;
712
Axel Linc92f5dd2013-01-27 21:16:56 +0800713 node = of_node_get(node);
Laxman Dewanganacc1cca2013-10-03 19:36:37 +0530714 regulators = of_get_child_by_name(node, "regulators");
Graeme Gregorya361cd92012-08-28 13:47:40 +0200715 if (!regulators) {
716 dev_info(dev, "regulator node not found\n");
717 return;
718 }
719
720 ret = of_regulator_match(dev, regulators, palmas_matches,
721 PALMAS_NUM_REGS);
Axel Linc92f5dd2013-01-27 21:16:56 +0800722 of_node_put(regulators);
Graeme Gregorya361cd92012-08-28 13:47:40 +0200723 if (ret < 0) {
724 dev_err(dev, "Error parsing regulator init data: %d\n", ret);
725 return;
726 }
727
728 for (idx = 0; idx < PALMAS_NUM_REGS; idx++) {
729 if (!palmas_matches[idx].init_data ||
730 !palmas_matches[idx].of_node)
731 continue;
732
733 pdata->reg_data[idx] = palmas_matches[idx].init_data;
734
735 pdata->reg_init[idx] = devm_kzalloc(dev,
736 sizeof(struct palmas_reg_init), GFP_KERNEL);
737
Graeme Gregory7be859f2013-03-07 13:17:48 +0000738 pdata->reg_init[idx]->warm_reset =
Axel Lin71f21462013-03-12 23:40:19 +0800739 of_property_read_bool(palmas_matches[idx].of_node,
740 "ti,warm-reset");
Graeme Gregorya361cd92012-08-28 13:47:40 +0200741
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530742 ret = of_property_read_u32(palmas_matches[idx].of_node,
743 "ti,roof-floor", &prop);
744 /* EINVAL: Property not found */
745 if (ret != -EINVAL) {
746 int econtrol;
747
748 /* use default value, when no value is specified */
749 econtrol = PALMAS_EXT_CONTROL_NSLEEP;
750 if (!ret) {
751 switch (prop) {
752 case 1:
753 econtrol = PALMAS_EXT_CONTROL_ENABLE1;
754 break;
755 case 2:
756 econtrol = PALMAS_EXT_CONTROL_ENABLE2;
757 break;
758 case 3:
759 econtrol = PALMAS_EXT_CONTROL_NSLEEP;
760 break;
761 default:
762 WARN_ON(1);
763 dev_warn(dev,
764 "%s: Invalid roof-floor option: %u\n",
765 palmas_matches[idx].name, prop);
766 break;
767 }
768 }
769 pdata->reg_init[idx]->roof_floor = econtrol;
770 }
Graeme Gregorya361cd92012-08-28 13:47:40 +0200771
772 ret = of_property_read_u32(palmas_matches[idx].of_node,
J Keerthy3c870e32013-02-18 10:44:20 +0530773 "ti,mode-sleep", &prop);
Graeme Gregorya361cd92012-08-28 13:47:40 +0200774 if (!ret)
775 pdata->reg_init[idx]->mode_sleep = prop;
776
Graeme Gregory7be859f2013-03-07 13:17:48 +0000777 ret = of_property_read_bool(palmas_matches[idx].of_node,
778 "ti,smps-range");
779 if (ret)
780 pdata->reg_init[idx]->vsel =
781 PALMAS_SMPS12_VOLTAGE_RANGE;
Graeme Gregorya361cd92012-08-28 13:47:40 +0200782
Laxman Dewangan17c11a72013-04-17 15:13:13 +0530783 if (idx == PALMAS_REG_LDO8)
784 pdata->enable_ldo8_tracking = of_property_read_bool(
785 palmas_matches[idx].of_node,
786 "ti,enable-ldo8-tracking");
Graeme Gregorya361cd92012-08-28 13:47:40 +0200787 }
788
Graeme Gregory7be859f2013-03-07 13:17:48 +0000789 pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator");
Graeme Gregorya361cd92012-08-28 13:47:40 +0200790}
791
792
Laxman Dewanganbbcf50b2013-03-18 14:59:49 +0530793static int palmas_regulators_probe(struct platform_device *pdev)
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100794{
795 struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
Jingoo Handff91d02013-07-30 17:20:47 +0900796 struct palmas_pmic_platform_data *pdata = dev_get_platdata(&pdev->dev);
Graeme Gregorya361cd92012-08-28 13:47:40 +0200797 struct device_node *node = pdev->dev.of_node;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100798 struct regulator_dev *rdev;
799 struct regulator_config config = { };
800 struct palmas_pmic *pmic;
801 struct palmas_reg_init *reg_init;
802 int id = 0, ret;
803 unsigned int addr, reg;
804
Graeme Gregorya361cd92012-08-28 13:47:40 +0200805 if (node && !pdata) {
806 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
807
808 if (!pdata)
809 return -ENOMEM;
810
811 palmas_dt_to_pdata(&pdev->dev, node, pdata);
812 }
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100813
814 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
815 if (!pmic)
816 return -ENOMEM;
817
818 pmic->dev = &pdev->dev;
819 pmic->palmas = palmas;
820 palmas->pmic = pmic;
821 platform_set_drvdata(pdev, pmic);
822
823 ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg);
824 if (ret)
Axel Lin1c9d2d72012-07-18 12:33:20 +0800825 return ret;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100826
827 if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN)
828 pmic->smps123 = 1;
829
830 if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN)
831 pmic->smps457 = 1;
832
833 config.regmap = palmas->regmap[REGULATOR_SLAVE];
834 config.dev = &pdev->dev;
835 config.driver_data = pmic;
836
837 for (id = 0; id < PALMAS_REG_LDO1; id++) {
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530838 bool ramp_delay_support = false;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100839
840 /*
841 * Miss out regulators which are not available due
842 * to slaving configurations.
843 */
844 switch (id) {
845 case PALMAS_REG_SMPS12:
846 case PALMAS_REG_SMPS3:
847 if (pmic->smps123)
848 continue;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530849 if (id == PALMAS_REG_SMPS12)
850 ramp_delay_support = true;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100851 break;
852 case PALMAS_REG_SMPS123:
853 if (!pmic->smps123)
854 continue;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530855 ramp_delay_support = true;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100856 break;
857 case PALMAS_REG_SMPS45:
858 case PALMAS_REG_SMPS7:
859 if (pmic->smps457)
860 continue;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530861 if (id == PALMAS_REG_SMPS45)
862 ramp_delay_support = true;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100863 break;
864 case PALMAS_REG_SMPS457:
865 if (!pmic->smps457)
866 continue;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530867 ramp_delay_support = true;
868 break;
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530869 case PALMAS_REG_SMPS10_OUT1:
870 case PALMAS_REG_SMPS10_OUT2:
J Keerthy1ffb0be2013-06-19 11:27:48 +0530871 if (!PALMAS_PMIC_HAS(palmas, SMPS10_BOOST))
872 continue;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530873 }
874
Sachin Kamat3f4d6362013-05-08 16:09:06 +0530875 if ((id == PALMAS_REG_SMPS6) || (id == PALMAS_REG_SMPS8))
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530876 ramp_delay_support = true;
877
878 if (ramp_delay_support) {
879 addr = palmas_regs_info[id].tstep_addr;
880 ret = palmas_smps_read(pmic->palmas, addr, &reg);
881 if (ret < 0) {
882 dev_err(&pdev->dev,
883 "reading TSTEP reg failed: %d\n", ret);
Sachin Kamat51c86b32013-09-04 12:01:01 +0530884 return ret;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530885 }
886 pmic->desc[id].ramp_delay =
887 palmas_smps_ramp_delay[reg & 0x3];
888 pmic->ramp_delay[id] = pmic->desc[id].ramp_delay;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100889 }
890
Axel Linbdc4baa2012-11-29 10:01:44 +0800891 /* Initialise sleep/init values from platform data */
892 if (pdata && pdata->reg_init[id]) {
893 reg_init = pdata->reg_init[id];
894 ret = palmas_smps_init(palmas, id, reg_init);
895 if (ret)
Sachin Kamat51c86b32013-09-04 12:01:01 +0530896 return ret;
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530897 } else {
898 reg_init = NULL;
Axel Linbdc4baa2012-11-29 10:01:44 +0800899 }
900
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100901 /* Register the regulators */
902 pmic->desc[id].name = palmas_regs_info[id].name;
903 pmic->desc[id].id = id;
904
Axel Linfedd89b2012-06-06 20:01:38 +0800905 switch (id) {
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530906 case PALMAS_REG_SMPS10_OUT1:
907 case PALMAS_REG_SMPS10_OUT2:
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100908 pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
909 pmic->desc[id].ops = &palmas_ops_smps10;
Axel Lin12565b12012-07-18 12:31:03 +0800910 pmic->desc[id].vsel_reg =
911 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
912 PALMAS_SMPS10_CTRL);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100913 pmic->desc[id].vsel_mask = SMPS10_VSEL;
Graeme Gregorya68de072012-06-22 13:36:20 +0100914 pmic->desc[id].enable_reg =
915 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
Kishon Vijay Abraham If2321682013-05-30 15:55:09 +0530916 PALMAS_SMPS10_CTRL);
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530917 if (id == PALMAS_REG_SMPS10_OUT1)
918 pmic->desc[id].enable_mask = SMPS10_SWITCH_EN;
919 else
920 pmic->desc[id].enable_mask = SMPS10_BOOST_EN;
921 pmic->desc[id].bypass_reg =
922 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
923 PALMAS_SMPS10_CTRL);
924 pmic->desc[id].bypass_mask = SMPS10_BYPASS_EN;
Axel Lin8029a002012-05-22 12:26:42 +0800925 pmic->desc[id].min_uV = 3750000;
926 pmic->desc[id].uV_step = 1250000;
Axel Linfedd89b2012-06-06 20:01:38 +0800927 break;
928 default:
Axel Linbdc4baa2012-11-29 10:01:44 +0800929 /*
930 * Read and store the RANGE bit for later use
931 * This must be done before regulator is probed,
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530932 * otherwise we error in probe with unsupportable
933 * ranges. Read the current smps mode for later use.
Axel Linbdc4baa2012-11-29 10:01:44 +0800934 */
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100935 addr = palmas_regs_info[id].vsel_addr;
Keerthydbabd622014-05-22 14:48:29 +0530936 pmic->desc[id].n_linear_ranges = 3;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100937
938 ret = palmas_smps_read(pmic->palmas, addr, &reg);
939 if (ret)
Sachin Kamat51c86b32013-09-04 12:01:01 +0530940 return ret;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100941 if (reg & PALMAS_SMPS12_VOLTAGE_RANGE)
942 pmic->range[id] = 1;
Keerthydbabd622014-05-22 14:48:29 +0530943 if (pmic->range[id])
944 pmic->desc[id].linear_ranges = smps_high_ranges;
945 else
946 pmic->desc[id].linear_ranges = smps_low_ranges;
Axel Linbdc4baa2012-11-29 10:01:44 +0800947
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530948 if (reg_init && reg_init->roof_floor)
949 pmic->desc[id].ops =
950 &palmas_ops_ext_control_smps;
951 else
952 pmic->desc[id].ops = &palmas_ops_smps;
Axel Linbdc4baa2012-11-29 10:01:44 +0800953 pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
954 pmic->desc[id].vsel_reg =
955 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
956 palmas_regs_info[id].vsel_addr);
957 pmic->desc[id].vsel_mask =
958 PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530959
960 /* Read the smps mode for later use. */
961 addr = palmas_regs_info[id].ctrl_addr;
962 ret = palmas_smps_read(pmic->palmas, addr, &reg);
963 if (ret)
Sachin Kamat51c86b32013-09-04 12:01:01 +0530964 return ret;
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530965 pmic->current_reg_mode[id] = reg &
966 PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100967 }
968
Axel Linbdc4baa2012-11-29 10:01:44 +0800969 pmic->desc[id].type = REGULATOR_VOLTAGE;
970 pmic->desc[id].owner = THIS_MODULE;
971
Graeme Gregorya361cd92012-08-28 13:47:40 +0200972 if (pdata)
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100973 config.init_data = pdata->reg_data[id];
974 else
975 config.init_data = NULL;
976
Laxman Dewangan504382c2013-03-20 19:26:37 +0530977 pmic->desc[id].supply_name = palmas_regs_info[id].sname;
Graeme Gregorya361cd92012-08-28 13:47:40 +0200978 config.of_node = palmas_matches[id].of_node;
979
Sachin Kamat51c86b32013-09-04 12:01:01 +0530980 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[id],
981 &config);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100982 if (IS_ERR(rdev)) {
983 dev_err(&pdev->dev,
984 "failed to register %s regulator\n",
985 pdev->name);
Sachin Kamat51c86b32013-09-04 12:01:01 +0530986 return PTR_ERR(rdev);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100987 }
988
989 /* Save regulator for cleanup */
990 pmic->rdev[id] = rdev;
991 }
992
993 /* Start this loop from the id left from previous loop */
994 for (; id < PALMAS_NUM_REGS; id++) {
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530995 if (pdata && pdata->reg_init[id])
996 reg_init = pdata->reg_init[id];
997 else
998 reg_init = NULL;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100999
1000 /* Miss out regulators which are not available due
1001 * to alternate functions.
1002 */
1003
1004 /* Register the regulators */
1005 pmic->desc[id].name = palmas_regs_info[id].name;
1006 pmic->desc[id].id = id;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001007 pmic->desc[id].type = REGULATOR_VOLTAGE;
1008 pmic->desc[id].owner = THIS_MODULE;
Laxman Dewanganaa07f022013-04-17 15:13:12 +05301009
1010 if (id < PALMAS_REG_REGEN1) {
1011 pmic->desc[id].n_voltages = PALMAS_LDO_NUM_VOLTAGES;
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +05301012 if (reg_init && reg_init->roof_floor)
1013 pmic->desc[id].ops =
1014 &palmas_ops_ext_control_ldo;
1015 else
1016 pmic->desc[id].ops = &palmas_ops_ldo;
Laxman Dewanganaa07f022013-04-17 15:13:12 +05301017 pmic->desc[id].min_uV = 900000;
1018 pmic->desc[id].uV_step = 50000;
1019 pmic->desc[id].linear_min_sel = 1;
Laxman Dewangan087d30e2013-09-10 16:48:07 +05301020 pmic->desc[id].enable_time = 500;
Laxman Dewanganaa07f022013-04-17 15:13:12 +05301021 pmic->desc[id].vsel_reg =
1022 PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
Axel Lin4a247a92012-07-18 12:34:08 +08001023 palmas_regs_info[id].vsel_addr);
Laxman Dewanganaa07f022013-04-17 15:13:12 +05301024 pmic->desc[id].vsel_mask =
1025 PALMAS_LDO1_VOLTAGE_VSEL_MASK;
1026 pmic->desc[id].enable_reg =
1027 PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
Graeme Gregorya68de072012-06-22 13:36:20 +01001028 palmas_regs_info[id].ctrl_addr);
Laxman Dewanganaa07f022013-04-17 15:13:12 +05301029 pmic->desc[id].enable_mask =
1030 PALMAS_LDO1_CTRL_MODE_ACTIVE;
Laxman Dewangan17c11a72013-04-17 15:13:13 +05301031
1032 /* Check if LDO8 is in tracking mode or not */
1033 if (pdata && (id == PALMAS_REG_LDO8) &&
1034 pdata->enable_ldo8_tracking) {
1035 palmas_enable_ldo8_track(palmas);
Axel Lin3df4a812013-04-19 00:53:52 +08001036 pmic->desc[id].min_uV = 450000;
Laxman Dewangan17c11a72013-04-17 15:13:13 +05301037 pmic->desc[id].uV_step = 25000;
1038 }
Laxman Dewangan087d30e2013-09-10 16:48:07 +05301039
1040 /* LOD6 in vibrator mode will have enable time 2000us */
1041 if (pdata && pdata->ldo6_vibrator &&
1042 (id == PALMAS_REG_LDO6))
1043 pmic->desc[id].enable_time = 2000;
Laxman Dewanganaa07f022013-04-17 15:13:12 +05301044 } else {
1045 pmic->desc[id].n_voltages = 1;
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +05301046 if (reg_init && reg_init->roof_floor)
1047 pmic->desc[id].ops =
1048 &palmas_ops_ext_control_extreg;
1049 else
1050 pmic->desc[id].ops = &palmas_ops_extreg;
Laxman Dewanganaa07f022013-04-17 15:13:12 +05301051 pmic->desc[id].enable_reg =
1052 PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE,
1053 palmas_regs_info[id].ctrl_addr);
1054 pmic->desc[id].enable_mask =
1055 PALMAS_REGEN1_CTRL_MODE_ACTIVE;
1056 }
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001057
Graeme Gregorya361cd92012-08-28 13:47:40 +02001058 if (pdata)
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001059 config.init_data = pdata->reg_data[id];
1060 else
1061 config.init_data = NULL;
1062
Laxman Dewangan504382c2013-03-20 19:26:37 +05301063 pmic->desc[id].supply_name = palmas_regs_info[id].sname;
Graeme Gregorya361cd92012-08-28 13:47:40 +02001064 config.of_node = palmas_matches[id].of_node;
1065
Sachin Kamat51c86b32013-09-04 12:01:01 +05301066 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[id],
1067 &config);
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001068 if (IS_ERR(rdev)) {
1069 dev_err(&pdev->dev,
1070 "failed to register %s regulator\n",
1071 pdev->name);
Sachin Kamat51c86b32013-09-04 12:01:01 +05301072 return PTR_ERR(rdev);
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001073 }
1074
1075 /* Save regulator for cleanup */
1076 pmic->rdev[id] = rdev;
1077
1078 /* Initialise sleep/init values from platform data */
Graeme Gregorya361cd92012-08-28 13:47:40 +02001079 if (pdata) {
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001080 reg_init = pdata->reg_init[id];
1081 if (reg_init) {
Laxman Dewanganaa07f022013-04-17 15:13:12 +05301082 if (id < PALMAS_REG_REGEN1)
1083 ret = palmas_ldo_init(palmas,
1084 id, reg_init);
1085 else
1086 ret = palmas_extreg_init(palmas,
1087 id, reg_init);
Axel Lincb2e45e2013-09-05 11:31:25 +08001088 if (ret)
Sachin Kamat51c86b32013-09-04 12:01:01 +05301089 return ret;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001090 }
1091 }
1092 }
1093
Laxman Dewangan17c11a72013-04-17 15:13:13 +05301094
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001095 return 0;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001096}
1097
Jingoo Han2449df92014-05-07 17:07:54 +09001098static const struct of_device_id of_palmas_match_tbl[] = {
Graeme Gregorya361cd92012-08-28 13:47:40 +02001099 { .compatible = "ti,palmas-pmic", },
Graeme Gregory7be859f2013-03-07 13:17:48 +00001100 { .compatible = "ti,twl6035-pmic", },
1101 { .compatible = "ti,twl6036-pmic", },
1102 { .compatible = "ti,twl6037-pmic", },
1103 { .compatible = "ti,tps65913-pmic", },
1104 { .compatible = "ti,tps65914-pmic", },
1105 { .compatible = "ti,tps80036-pmic", },
J Keerthyb5c46782013-06-20 16:32:15 +05301106 { .compatible = "ti,tps659038-pmic", },
Graeme Gregorya361cd92012-08-28 13:47:40 +02001107 { /* end */ }
1108};
1109
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001110static struct platform_driver palmas_driver = {
1111 .driver = {
1112 .name = "palmas-pmic",
Graeme Gregorya361cd92012-08-28 13:47:40 +02001113 .of_match_table = of_palmas_match_tbl,
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001114 .owner = THIS_MODULE,
1115 },
Laxman Dewanganbbcf50b2013-03-18 14:59:49 +05301116 .probe = palmas_regulators_probe,
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001117};
1118
1119static int __init palmas_init(void)
1120{
1121 return platform_driver_register(&palmas_driver);
1122}
1123subsys_initcall(palmas_init);
1124
1125static void __exit palmas_exit(void)
1126{
1127 platform_driver_unregister(&palmas_driver);
1128}
1129module_exit(palmas_exit);
1130
1131MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1132MODULE_DESCRIPTION("Palmas voltage regulator driver");
1133MODULE_LICENSE("GPL");
1134MODULE_ALIAS("platform:palmas-pmic");
Graeme Gregorya361cd92012-08-28 13:47:40 +02001135MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);