blob: 337dd614695e4d14f0125841d0c7e7e02ed01a7e [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Graeme Gregorye5ce4202012-05-18 16:53:57 +01002/*
3 * Driver for Regulator part of Palmas PMIC Chips
4 *
Graeme Gregory7be859f2013-03-07 13:17:48 +00005 * Copyright 2011-2013 Texas Instruments Inc.
Graeme Gregorye5ce4202012-05-18 16:53:57 +01006 *
7 * Author: Graeme Gregory <gg@slimlogic.co.uk>
Graeme Gregorya7dddf22013-02-23 16:35:40 +00008 * Author: Ian Lartey <ian@slimlogic.co.uk>
Graeme Gregorye5ce4202012-05-18 16:53:57 +01009 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/err.h>
15#include <linux/platform_device.h>
16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h>
18#include <linux/slab.h>
19#include <linux/regmap.h>
20#include <linux/mfd/palmas.h>
Graeme Gregorya361cd92012-08-28 13:47:40 +020021#include <linux/of.h>
22#include <linux/of_platform.h>
23#include <linux/regulator/of_regulator.h>
Graeme Gregorye5ce4202012-05-18 16:53:57 +010024
Matti Vaittinen60ab7f42020-05-08 18:43:36 +030025static const struct linear_range smps_low_ranges[] = {
Nishanth Menon6b7f2d82014-06-04 14:34:31 -050026 REGULATOR_LINEAR_RANGE(0, 0x0, 0x0, 0),
Keerthydbabd622014-05-22 14:48:29 +053027 REGULATOR_LINEAR_RANGE(500000, 0x1, 0x6, 0),
28 REGULATOR_LINEAR_RANGE(510000, 0x7, 0x79, 10000),
29 REGULATOR_LINEAR_RANGE(1650000, 0x7A, 0x7f, 0),
30};
31
Matti Vaittinen60ab7f42020-05-08 18:43:36 +030032static const struct linear_range smps_high_ranges[] = {
Nishanth Menon6b7f2d82014-06-04 14:34:31 -050033 REGULATOR_LINEAR_RANGE(0, 0x0, 0x0, 0),
Keerthydbabd622014-05-22 14:48:29 +053034 REGULATOR_LINEAR_RANGE(1000000, 0x1, 0x6, 0),
35 REGULATOR_LINEAR_RANGE(1020000, 0x7, 0x79, 20000),
36 REGULATOR_LINEAR_RANGE(3300000, 0x7A, 0x7f, 0),
37};
38
Nishanth Menon6839cd62014-06-30 10:57:37 -050039static struct palmas_regs_info palmas_generic_regs_info[] = {
Graeme Gregorye5ce4202012-05-18 16:53:57 +010040 {
41 .name = "SMPS12",
Laxman Dewangan504382c2013-03-20 19:26:37 +053042 .sname = "smps1-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010043 .vsel_addr = PALMAS_SMPS12_VOLTAGE,
44 .ctrl_addr = PALMAS_SMPS12_CTRL,
45 .tstep_addr = PALMAS_SMPS12_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053046 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS12,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010047 },
48 {
49 .name = "SMPS123",
Laxman Dewangan504382c2013-03-20 19:26:37 +053050 .sname = "smps1-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010051 .vsel_addr = PALMAS_SMPS12_VOLTAGE,
52 .ctrl_addr = PALMAS_SMPS12_CTRL,
53 .tstep_addr = PALMAS_SMPS12_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053054 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS12,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010055 },
56 {
57 .name = "SMPS3",
Laxman Dewangan504382c2013-03-20 19:26:37 +053058 .sname = "smps3-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010059 .vsel_addr = PALMAS_SMPS3_VOLTAGE,
60 .ctrl_addr = PALMAS_SMPS3_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053061 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS3,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010062 },
63 {
64 .name = "SMPS45",
Laxman Dewangan504382c2013-03-20 19:26:37 +053065 .sname = "smps4-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010066 .vsel_addr = PALMAS_SMPS45_VOLTAGE,
67 .ctrl_addr = PALMAS_SMPS45_CTRL,
68 .tstep_addr = PALMAS_SMPS45_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053069 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS45,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010070 },
71 {
72 .name = "SMPS457",
Laxman Dewangan504382c2013-03-20 19:26:37 +053073 .sname = "smps4-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010074 .vsel_addr = PALMAS_SMPS45_VOLTAGE,
75 .ctrl_addr = PALMAS_SMPS45_CTRL,
76 .tstep_addr = PALMAS_SMPS45_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053077 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS45,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010078 },
79 {
80 .name = "SMPS6",
Laxman Dewangan504382c2013-03-20 19:26:37 +053081 .sname = "smps6-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010082 .vsel_addr = PALMAS_SMPS6_VOLTAGE,
83 .ctrl_addr = PALMAS_SMPS6_CTRL,
84 .tstep_addr = PALMAS_SMPS6_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053085 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS6,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010086 },
87 {
88 .name = "SMPS7",
Laxman Dewangan504382c2013-03-20 19:26:37 +053089 .sname = "smps7-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010090 .vsel_addr = PALMAS_SMPS7_VOLTAGE,
91 .ctrl_addr = PALMAS_SMPS7_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +053092 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS7,
Graeme Gregorye5ce4202012-05-18 16:53:57 +010093 },
94 {
95 .name = "SMPS8",
Laxman Dewangan504382c2013-03-20 19:26:37 +053096 .sname = "smps8-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +010097 .vsel_addr = PALMAS_SMPS8_VOLTAGE,
98 .ctrl_addr = PALMAS_SMPS8_CTRL,
99 .tstep_addr = PALMAS_SMPS8_TSTEP,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530100 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS8,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100101 },
102 {
103 .name = "SMPS9",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530104 .sname = "smps9-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100105 .vsel_addr = PALMAS_SMPS9_VOLTAGE,
106 .ctrl_addr = PALMAS_SMPS9_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530107 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS9,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100108 },
109 {
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530110 .name = "SMPS10_OUT2",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530111 .sname = "smps10-in",
Axel Line31089c2013-04-19 20:33:45 +0800112 .ctrl_addr = PALMAS_SMPS10_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530113 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS10,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100114 },
115 {
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530116 .name = "SMPS10_OUT1",
117 .sname = "smps10-out2",
118 .ctrl_addr = PALMAS_SMPS10_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530119 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS10,
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530120 },
121 {
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100122 .name = "LDO1",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530123 .sname = "ldo1-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100124 .vsel_addr = PALMAS_LDO1_VOLTAGE,
125 .ctrl_addr = PALMAS_LDO1_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530126 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO1,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100127 },
128 {
129 .name = "LDO2",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530130 .sname = "ldo2-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100131 .vsel_addr = PALMAS_LDO2_VOLTAGE,
132 .ctrl_addr = PALMAS_LDO2_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530133 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO2,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100134 },
135 {
136 .name = "LDO3",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530137 .sname = "ldo3-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100138 .vsel_addr = PALMAS_LDO3_VOLTAGE,
139 .ctrl_addr = PALMAS_LDO3_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530140 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO3,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100141 },
142 {
143 .name = "LDO4",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530144 .sname = "ldo4-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100145 .vsel_addr = PALMAS_LDO4_VOLTAGE,
146 .ctrl_addr = PALMAS_LDO4_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530147 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO4,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100148 },
149 {
150 .name = "LDO5",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530151 .sname = "ldo5-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100152 .vsel_addr = PALMAS_LDO5_VOLTAGE,
153 .ctrl_addr = PALMAS_LDO5_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530154 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO5,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100155 },
156 {
157 .name = "LDO6",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530158 .sname = "ldo6-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100159 .vsel_addr = PALMAS_LDO6_VOLTAGE,
160 .ctrl_addr = PALMAS_LDO6_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530161 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO6,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100162 },
163 {
164 .name = "LDO7",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530165 .sname = "ldo7-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100166 .vsel_addr = PALMAS_LDO7_VOLTAGE,
167 .ctrl_addr = PALMAS_LDO7_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530168 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO7,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100169 },
170 {
171 .name = "LDO8",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530172 .sname = "ldo8-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100173 .vsel_addr = PALMAS_LDO8_VOLTAGE,
174 .ctrl_addr = PALMAS_LDO8_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530175 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO8,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100176 },
177 {
178 .name = "LDO9",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530179 .sname = "ldo9-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100180 .vsel_addr = PALMAS_LDO9_VOLTAGE,
181 .ctrl_addr = PALMAS_LDO9_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530182 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO9,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100183 },
184 {
185 .name = "LDOLN",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530186 .sname = "ldoln-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100187 .vsel_addr = PALMAS_LDOLN_VOLTAGE,
188 .ctrl_addr = PALMAS_LDOLN_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530189 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDOLN,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100190 },
191 {
192 .name = "LDOUSB",
Laxman Dewangan504382c2013-03-20 19:26:37 +0530193 .sname = "ldousb-in",
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100194 .vsel_addr = PALMAS_LDOUSB_VOLTAGE,
195 .ctrl_addr = PALMAS_LDOUSB_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530196 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDOUSB,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100197 },
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530198 {
199 .name = "REGEN1",
200 .ctrl_addr = PALMAS_REGEN1_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530201 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN1,
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530202 },
203 {
204 .name = "REGEN2",
205 .ctrl_addr = PALMAS_REGEN2_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530206 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN2,
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530207 },
208 {
209 .name = "REGEN3",
210 .ctrl_addr = PALMAS_REGEN3_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530211 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN3,
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530212 },
213 {
214 .name = "SYSEN1",
215 .ctrl_addr = PALMAS_SYSEN1_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530216 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SYSEN1,
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530217 },
218 {
219 .name = "SYSEN2",
220 .ctrl_addr = PALMAS_SYSEN2_CTRL,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530221 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SYSEN2,
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530222 },
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100223};
224
Nishanth Menone7cf34e2014-06-30 10:57:35 -0500225static struct palmas_regs_info tps65917_regs_info[] = {
Keerthyd6f83372014-06-18 15:29:00 +0530226 {
227 .name = "SMPS1",
228 .sname = "smps1-in",
229 .vsel_addr = TPS65917_SMPS1_VOLTAGE,
230 .ctrl_addr = TPS65917_SMPS1_CTRL,
231 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS1,
232 },
233 {
234 .name = "SMPS2",
235 .sname = "smps2-in",
236 .vsel_addr = TPS65917_SMPS2_VOLTAGE,
237 .ctrl_addr = TPS65917_SMPS2_CTRL,
238 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS2,
239 },
240 {
241 .name = "SMPS3",
242 .sname = "smps3-in",
243 .vsel_addr = TPS65917_SMPS3_VOLTAGE,
244 .ctrl_addr = TPS65917_SMPS3_CTRL,
245 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS3,
246 },
247 {
248 .name = "SMPS4",
249 .sname = "smps4-in",
250 .vsel_addr = TPS65917_SMPS4_VOLTAGE,
251 .ctrl_addr = TPS65917_SMPS4_CTRL,
252 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS4,
253 },
254 {
255 .name = "SMPS5",
256 .sname = "smps5-in",
257 .vsel_addr = TPS65917_SMPS5_VOLTAGE,
258 .ctrl_addr = TPS65917_SMPS5_CTRL,
259 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS5,
260 },
261 {
Keerthybe035302017-05-23 17:46:56 +0530262 .name = "SMPS12",
263 .sname = "smps1-in",
264 .vsel_addr = TPS65917_SMPS1_VOLTAGE,
265 .ctrl_addr = TPS65917_SMPS1_CTRL,
266 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS12,
267 },
268 {
Keerthyd6f83372014-06-18 15:29:00 +0530269 .name = "LDO1",
270 .sname = "ldo1-in",
271 .vsel_addr = TPS65917_LDO1_VOLTAGE,
272 .ctrl_addr = TPS65917_LDO1_CTRL,
273 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_LDO1,
274 },
275 {
276 .name = "LDO2",
277 .sname = "ldo2-in",
278 .vsel_addr = TPS65917_LDO2_VOLTAGE,
279 .ctrl_addr = TPS65917_LDO2_CTRL,
280 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_LDO2,
281 },
282 {
283 .name = "LDO3",
284 .sname = "ldo3-in",
285 .vsel_addr = TPS65917_LDO3_VOLTAGE,
286 .ctrl_addr = TPS65917_LDO3_CTRL,
287 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_LDO3,
288 },
289 {
290 .name = "LDO4",
291 .sname = "ldo4-in",
292 .vsel_addr = TPS65917_LDO4_VOLTAGE,
293 .ctrl_addr = TPS65917_LDO4_CTRL,
294 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_LDO4,
295 },
296 {
297 .name = "LDO5",
298 .sname = "ldo5-in",
299 .vsel_addr = TPS65917_LDO5_VOLTAGE,
300 .ctrl_addr = TPS65917_LDO5_CTRL,
301 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_LDO5,
302 },
303 {
304 .name = "REGEN1",
305 .ctrl_addr = TPS65917_REGEN1_CTRL,
306 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_REGEN1,
307 },
308 {
309 .name = "REGEN2",
310 .ctrl_addr = TPS65917_REGEN2_CTRL,
311 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_REGEN2,
312 },
313 {
314 .name = "REGEN3",
315 .ctrl_addr = TPS65917_REGEN3_CTRL,
316 .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_REGEN3,
317 },
318};
319
Keerthycac9e912014-06-18 15:28:59 +0530320#define EXTERNAL_REQUESTOR(_id, _offset, _pos) \
321 [PALMAS_EXTERNAL_REQSTR_ID_##_id] = { \
322 .id = PALMAS_EXTERNAL_REQSTR_ID_##_id, \
323 .reg_offset = _offset, \
324 .bit_pos = _pos, \
325 }
326
Nishanth Menon4b09e172014-06-30 10:57:34 -0500327static struct palmas_sleep_requestor_info palma_sleep_req_info[] = {
Keerthycac9e912014-06-18 15:28:59 +0530328 EXTERNAL_REQUESTOR(REGEN1, 0, 0),
329 EXTERNAL_REQUESTOR(REGEN2, 0, 1),
330 EXTERNAL_REQUESTOR(SYSEN1, 0, 2),
331 EXTERNAL_REQUESTOR(SYSEN2, 0, 3),
332 EXTERNAL_REQUESTOR(CLK32KG, 0, 4),
333 EXTERNAL_REQUESTOR(CLK32KGAUDIO, 0, 5),
334 EXTERNAL_REQUESTOR(REGEN3, 0, 6),
335 EXTERNAL_REQUESTOR(SMPS12, 1, 0),
336 EXTERNAL_REQUESTOR(SMPS3, 1, 1),
337 EXTERNAL_REQUESTOR(SMPS45, 1, 2),
338 EXTERNAL_REQUESTOR(SMPS6, 1, 3),
339 EXTERNAL_REQUESTOR(SMPS7, 1, 4),
340 EXTERNAL_REQUESTOR(SMPS8, 1, 5),
341 EXTERNAL_REQUESTOR(SMPS9, 1, 6),
342 EXTERNAL_REQUESTOR(SMPS10, 1, 7),
343 EXTERNAL_REQUESTOR(LDO1, 2, 0),
344 EXTERNAL_REQUESTOR(LDO2, 2, 1),
345 EXTERNAL_REQUESTOR(LDO3, 2, 2),
346 EXTERNAL_REQUESTOR(LDO4, 2, 3),
347 EXTERNAL_REQUESTOR(LDO5, 2, 4),
348 EXTERNAL_REQUESTOR(LDO6, 2, 5),
349 EXTERNAL_REQUESTOR(LDO7, 2, 6),
350 EXTERNAL_REQUESTOR(LDO8, 2, 7),
351 EXTERNAL_REQUESTOR(LDO9, 3, 0),
352 EXTERNAL_REQUESTOR(LDOLN, 3, 1),
353 EXTERNAL_REQUESTOR(LDOUSB, 3, 2),
354};
355
Keerthyd6f83372014-06-18 15:29:00 +0530356#define EXTERNAL_REQUESTOR_TPS65917(_id, _offset, _pos) \
357 [TPS65917_EXTERNAL_REQSTR_ID_##_id] = { \
358 .id = TPS65917_EXTERNAL_REQSTR_ID_##_id, \
359 .reg_offset = _offset, \
360 .bit_pos = _pos, \
361 }
362
363static struct palmas_sleep_requestor_info tps65917_sleep_req_info[] = {
364 EXTERNAL_REQUESTOR_TPS65917(REGEN1, 0, 0),
365 EXTERNAL_REQUESTOR_TPS65917(REGEN2, 0, 1),
366 EXTERNAL_REQUESTOR_TPS65917(REGEN3, 0, 6),
367 EXTERNAL_REQUESTOR_TPS65917(SMPS1, 1, 0),
368 EXTERNAL_REQUESTOR_TPS65917(SMPS2, 1, 1),
369 EXTERNAL_REQUESTOR_TPS65917(SMPS3, 1, 2),
370 EXTERNAL_REQUESTOR_TPS65917(SMPS4, 1, 3),
371 EXTERNAL_REQUESTOR_TPS65917(SMPS5, 1, 4),
Keerthybe035302017-05-23 17:46:56 +0530372 EXTERNAL_REQUESTOR_TPS65917(SMPS12, 1, 5),
Keerthyd6f83372014-06-18 15:29:00 +0530373 EXTERNAL_REQUESTOR_TPS65917(LDO1, 2, 0),
374 EXTERNAL_REQUESTOR_TPS65917(LDO2, 2, 1),
375 EXTERNAL_REQUESTOR_TPS65917(LDO3, 2, 2),
376 EXTERNAL_REQUESTOR_TPS65917(LDO4, 2, 3),
377 EXTERNAL_REQUESTOR_TPS65917(LDO5, 2, 4),
378};
379
Axel Linad542a52019-03-01 22:20:16 +0800380static const unsigned int palmas_smps_ramp_delay[4] = {0, 10000, 5000, 2500};
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530381
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100382#define SMPS_CTRL_MODE_OFF 0x00
383#define SMPS_CTRL_MODE_ON 0x01
384#define SMPS_CTRL_MODE_ECO 0x02
385#define SMPS_CTRL_MODE_PWM 0x03
386
Laxman Dewangan0f45aa82013-09-04 15:20:06 +0530387#define PALMAS_SMPS_NUM_VOLTAGES 122
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100388#define PALMAS_SMPS10_NUM_VOLTAGES 2
389#define PALMAS_LDO_NUM_VOLTAGES 50
390
391#define SMPS10_VSEL (1<<3)
392#define SMPS10_BOOST_EN (1<<2)
393#define SMPS10_BYPASS_EN (1<<1)
394#define SMPS10_SWITCH_EN (1<<0)
395
396#define REGULATOR_SLAVE 0
397
398static int palmas_smps_read(struct palmas *palmas, unsigned int reg,
399 unsigned int *dest)
400{
401 unsigned int addr;
402
403 addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
404
405 return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
406}
407
408static int palmas_smps_write(struct palmas *palmas, unsigned int reg,
409 unsigned int value)
410{
411 unsigned int addr;
412
413 addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
414
415 return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
416}
417
418static int palmas_ldo_read(struct palmas *palmas, unsigned int reg,
419 unsigned int *dest)
420{
421 unsigned int addr;
422
423 addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
424
425 return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
426}
427
428static int palmas_ldo_write(struct palmas *palmas, unsigned int reg,
429 unsigned int value)
430{
431 unsigned int addr;
432
433 addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
434
435 return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
436}
437
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100438static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
439{
Nishanth Menoncf910b62014-06-30 10:57:36 -0500440 int id = rdev_get_id(dev);
Kangjie Lu966e9272018-12-18 23:04:13 -0600441 int ret;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100442 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
Keerthycac9e912014-06-18 15:28:59 +0530443 struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata;
Nishanth Menoncf910b62014-06-30 10:57:36 -0500444 struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100445 unsigned int reg;
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530446 bool rail_enable = true;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100447
Kangjie Lu966e9272018-12-18 23:04:13 -0600448 ret = palmas_smps_read(pmic->palmas, rinfo->ctrl_addr, &reg);
449 if (ret)
450 return ret;
Keerthycac9e912014-06-18 15:28:59 +0530451
Axel Lin999f0c72012-06-07 17:08:21 +0800452 reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100453
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530454 if (reg == SMPS_CTRL_MODE_OFF)
455 rail_enable = false;
456
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100457 switch (mode) {
458 case REGULATOR_MODE_NORMAL:
459 reg |= SMPS_CTRL_MODE_ON;
460 break;
461 case REGULATOR_MODE_IDLE:
462 reg |= SMPS_CTRL_MODE_ECO;
463 break;
464 case REGULATOR_MODE_FAST:
465 reg |= SMPS_CTRL_MODE_PWM;
466 break;
467 default:
468 return -EINVAL;
469 }
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100470
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530471 pmic->current_reg_mode[id] = reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
472 if (rail_enable)
Nishanth Menoncf910b62014-06-30 10:57:36 -0500473 palmas_smps_write(pmic->palmas, rinfo->ctrl_addr, reg);
Nishanth Menon318dbb02014-06-20 12:26:23 -0500474
475 /* Switch the enable value to ensure this is used for enable */
476 pmic->desc[id].enable_val = pmic->current_reg_mode[id];
477
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100478 return 0;
479}
480
481static unsigned int palmas_get_mode_smps(struct regulator_dev *dev)
482{
483 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
484 int id = rdev_get_id(dev);
485 unsigned int reg;
486
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +0530487 reg = pmic->current_reg_mode[id] & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100488
489 switch (reg) {
490 case SMPS_CTRL_MODE_ON:
491 return REGULATOR_MODE_NORMAL;
492 case SMPS_CTRL_MODE_ECO:
493 return REGULATOR_MODE_IDLE;
494 case SMPS_CTRL_MODE_PWM:
495 return REGULATOR_MODE_FAST;
496 }
497
498 return 0;
499}
500
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530501static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev,
502 int ramp_delay)
503{
Nishanth Menoncf910b62014-06-30 10:57:36 -0500504 int id = rdev_get_id(rdev);
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530505 struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
Keerthycac9e912014-06-18 15:28:59 +0530506 struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata;
Nishanth Menoncf910b62014-06-30 10:57:36 -0500507 struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530508 unsigned int reg = 0;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530509 int ret;
510
Axel Linf22c2ba2013-04-19 14:18:48 +0800511 /* SMPS3 and SMPS7 do not have tstep_addr setting */
512 switch (id) {
513 case PALMAS_REG_SMPS3:
514 case PALMAS_REG_SMPS7:
515 return 0;
516 }
517
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530518 if (ramp_delay <= 0)
519 reg = 0;
Axel Lin0ea34b52013-04-22 18:22:49 +0800520 else if (ramp_delay <= 2500)
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530521 reg = 3;
Axel Lin0ea34b52013-04-22 18:22:49 +0800522 else if (ramp_delay <= 5000)
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530523 reg = 2;
524 else
525 reg = 1;
526
Nishanth Menoncf910b62014-06-30 10:57:36 -0500527 ret = palmas_smps_write(pmic->palmas, rinfo->tstep_addr, reg);
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530528 if (ret < 0) {
529 dev_err(pmic->palmas->dev, "TSTEP write failed: %d\n", ret);
530 return ret;
531 }
532
533 pmic->ramp_delay[id] = palmas_smps_ramp_delay[reg];
534 return ret;
535}
536
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530537static const struct regulator_ops palmas_ops_smps = {
Keerthydbabd622014-05-22 14:48:29 +0530538 .is_enabled = regulator_is_enabled_regmap,
539 .enable = regulator_enable_regmap,
540 .disable = regulator_disable_regmap,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100541 .set_mode = palmas_set_mode_smps,
542 .get_mode = palmas_get_mode_smps,
Axel Linbdc4baa2012-11-29 10:01:44 +0800543 .get_voltage_sel = regulator_get_voltage_sel_regmap,
544 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Keerthydbabd622014-05-22 14:48:29 +0530545 .list_voltage = regulator_list_voltage_linear_range,
546 .map_voltage = regulator_map_voltage_linear_range,
547 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +0530548 .set_ramp_delay = palmas_smps_set_ramp_delay,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100549};
550
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530551static const struct regulator_ops palmas_ops_ext_control_smps = {
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530552 .set_mode = palmas_set_mode_smps,
553 .get_mode = palmas_get_mode_smps,
554 .get_voltage_sel = regulator_get_voltage_sel_regmap,
555 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Keerthydbabd622014-05-22 14:48:29 +0530556 .list_voltage = regulator_list_voltage_linear_range,
557 .map_voltage = regulator_map_voltage_linear_range,
558 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530559 .set_ramp_delay = palmas_smps_set_ramp_delay,
560};
561
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530562static const struct regulator_ops palmas_ops_smps10 = {
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100563 .is_enabled = regulator_is_enabled_regmap,
564 .enable = regulator_enable_regmap,
565 .disable = regulator_disable_regmap,
566 .get_voltage_sel = regulator_get_voltage_sel_regmap,
567 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Axel Lin8029a002012-05-22 12:26:42 +0800568 .list_voltage = regulator_list_voltage_linear,
569 .map_voltage = regulator_map_voltage_linear,
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530570 .set_bypass = regulator_set_bypass_regmap,
571 .get_bypass = regulator_get_bypass_regmap,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100572};
573
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530574static const struct regulator_ops tps65917_ops_smps = {
Keerthyd6f83372014-06-18 15:29:00 +0530575 .is_enabled = regulator_is_enabled_regmap,
576 .enable = regulator_enable_regmap,
577 .disable = regulator_disable_regmap,
578 .set_mode = palmas_set_mode_smps,
579 .get_mode = palmas_get_mode_smps,
580 .get_voltage_sel = regulator_get_voltage_sel_regmap,
581 .set_voltage_sel = regulator_set_voltage_sel_regmap,
582 .list_voltage = regulator_list_voltage_linear_range,
583 .map_voltage = regulator_map_voltage_linear_range,
584 .set_voltage_time_sel = regulator_set_voltage_time_sel,
585};
586
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530587static const struct regulator_ops tps65917_ops_ext_control_smps = {
Keerthyd6f83372014-06-18 15:29:00 +0530588 .set_mode = palmas_set_mode_smps,
589 .get_mode = palmas_get_mode_smps,
590 .get_voltage_sel = regulator_get_voltage_sel_regmap,
591 .set_voltage_sel = regulator_set_voltage_sel_regmap,
592 .list_voltage = regulator_list_voltage_linear_range,
593 .map_voltage = regulator_map_voltage_linear_range,
594};
595
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100596static int palmas_is_enabled_ldo(struct regulator_dev *dev)
597{
Nishanth Menoncf910b62014-06-30 10:57:36 -0500598 int id = rdev_get_id(dev);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100599 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
Keerthycac9e912014-06-18 15:28:59 +0530600 struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata;
Nishanth Menoncf910b62014-06-30 10:57:36 -0500601 struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100602 unsigned int reg;
603
Nishanth Menoncf910b62014-06-30 10:57:36 -0500604 palmas_ldo_read(pmic->palmas, rinfo->ctrl_addr, &reg);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100605
606 reg &= PALMAS_LDO1_CTRL_STATUS;
607
608 return !!(reg);
609}
610
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530611static const struct regulator_ops palmas_ops_ldo = {
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100612 .is_enabled = palmas_is_enabled_ldo,
613 .enable = regulator_enable_regmap,
614 .disable = regulator_disable_regmap,
Axel Lin4a247a92012-07-18 12:34:08 +0800615 .get_voltage_sel = regulator_get_voltage_sel_regmap,
616 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Axel Lin9119ff62012-11-27 10:27:34 +0800617 .list_voltage = regulator_list_voltage_linear,
618 .map_voltage = regulator_map_voltage_linear,
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100619};
620
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530621static const struct regulator_ops palmas_ops_ldo9 = {
Keerthyb554e142015-12-14 12:06:55 +0530622 .is_enabled = palmas_is_enabled_ldo,
623 .enable = regulator_enable_regmap,
624 .disable = regulator_disable_regmap,
625 .get_voltage_sel = regulator_get_voltage_sel_regmap,
626 .set_voltage_sel = regulator_set_voltage_sel_regmap,
627 .list_voltage = regulator_list_voltage_linear,
628 .map_voltage = regulator_map_voltage_linear,
629 .set_bypass = regulator_set_bypass_regmap,
630 .get_bypass = regulator_get_bypass_regmap,
631};
632
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530633static const struct regulator_ops palmas_ops_ext_control_ldo = {
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530634 .get_voltage_sel = regulator_get_voltage_sel_regmap,
635 .set_voltage_sel = regulator_set_voltage_sel_regmap,
636 .list_voltage = regulator_list_voltage_linear,
637 .map_voltage = regulator_map_voltage_linear,
638};
639
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530640static const struct regulator_ops palmas_ops_extreg = {
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530641 .is_enabled = regulator_is_enabled_regmap,
642 .enable = regulator_enable_regmap,
643 .disable = regulator_disable_regmap,
644};
645
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530646static const struct regulator_ops palmas_ops_ext_control_extreg = {
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530647};
648
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530649static const struct regulator_ops tps65917_ops_ldo = {
Keerthyd6f83372014-06-18 15:29:00 +0530650 .is_enabled = palmas_is_enabled_ldo,
651 .enable = regulator_enable_regmap,
652 .disable = regulator_disable_regmap,
653 .get_voltage_sel = regulator_get_voltage_sel_regmap,
654 .set_voltage_sel = regulator_set_voltage_sel_regmap,
655 .list_voltage = regulator_list_voltage_linear,
656 .map_voltage = regulator_map_voltage_linear,
657 .set_voltage_time_sel = regulator_set_voltage_time_sel,
658};
659
Bhumika Goyal0e5a768002017-01-28 20:23:55 +0530660static const struct regulator_ops tps65917_ops_ldo_1_2 = {
Keerthyb554e142015-12-14 12:06:55 +0530661 .is_enabled = palmas_is_enabled_ldo,
662 .enable = regulator_enable_regmap,
663 .disable = regulator_disable_regmap,
664 .get_voltage_sel = regulator_get_voltage_sel_regmap,
665 .set_voltage_sel = regulator_set_voltage_sel_regmap,
666 .list_voltage = regulator_list_voltage_linear,
667 .map_voltage = regulator_map_voltage_linear,
668 .set_voltage_time_sel = regulator_set_voltage_time_sel,
669 .set_bypass = regulator_set_bypass_regmap,
670 .get_bypass = regulator_get_bypass_regmap,
671};
672
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530673static int palmas_regulator_config_external(struct palmas *palmas, int id,
674 struct palmas_reg_init *reg_init)
675{
Nishanth Menoncf910b62014-06-30 10:57:36 -0500676 struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata;
677 struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530678 int ret;
679
Nishanth Menoncf910b62014-06-30 10:57:36 -0500680 ret = palmas_ext_control_req_config(palmas, rinfo->sleep_id,
681 reg_init->roof_floor, true);
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530682 if (ret < 0)
683 dev_err(palmas->dev,
684 "Ext control config for regulator %d failed %d\n",
685 id, ret);
686 return ret;
687}
688
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100689/*
690 * setup the hardware based sleep configuration of the SMPS/LDO regulators
691 * from the platform data. This is different to the software based control
692 * supported by the regulator framework as it is controlled by toggling
693 * pins on the PMIC such as PREQ, SYSEN, ...
694 */
695static int palmas_smps_init(struct palmas *palmas, int id,
696 struct palmas_reg_init *reg_init)
697{
698 unsigned int reg;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100699 int ret;
Keerthycac9e912014-06-18 15:28:59 +0530700 struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata;
Nishanth Menoncf910b62014-06-30 10:57:36 -0500701 struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
702 unsigned int addr = rinfo->ctrl_addr;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100703
704 ret = palmas_smps_read(palmas, addr, &reg);
705 if (ret)
706 return ret;
707
Axel Linfedd89b2012-06-06 20:01:38 +0800708 switch (id) {
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +0530709 case PALMAS_REG_SMPS10_OUT1:
710 case PALMAS_REG_SMPS10_OUT2:
Laxman Dewangan30590d02013-04-17 15:13:11 +0530711 reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
712 if (reg_init->mode_sleep)
Axel Linfedd89b2012-06-06 20:01:38 +0800713 reg |= reg_init->mode_sleep <<
714 PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
Axel Linfedd89b2012-06-06 20:01:38 +0800715 break;
716 default:
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100717 if (reg_init->warm_reset)
718 reg |= PALMAS_SMPS12_CTRL_WR_S;
Laxman Dewangan30590d02013-04-17 15:13:11 +0530719 else
720 reg &= ~PALMAS_SMPS12_CTRL_WR_S;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100721
722 if (reg_init->roof_floor)
723 reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN;
Laxman Dewangan30590d02013-04-17 15:13:11 +0530724 else
725 reg &= ~PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100726
Laxman Dewangan30590d02013-04-17 15:13:11 +0530727 reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK;
728 if (reg_init->mode_sleep)
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100729 reg |= reg_init->mode_sleep <<
730 PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100731 }
Axel Linfedd89b2012-06-06 20:01:38 +0800732
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100733 ret = palmas_smps_write(palmas, addr, reg);
734 if (ret)
735 return ret;
736
Nishanth Menoncf910b62014-06-30 10:57:36 -0500737 if (rinfo->vsel_addr && reg_init->vsel) {
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100738
739 reg = reg_init->vsel;
740
Nishanth Menoncf910b62014-06-30 10:57:36 -0500741 ret = palmas_smps_write(palmas, rinfo->vsel_addr, reg);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100742 if (ret)
743 return ret;
744 }
745
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530746 if (reg_init->roof_floor && (id != PALMAS_REG_SMPS10_OUT1) &&
747 (id != PALMAS_REG_SMPS10_OUT2)) {
748 /* Enable externally controlled regulator */
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530749 ret = palmas_smps_read(palmas, addr, &reg);
750 if (ret < 0)
751 return ret;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100752
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530753 if (!(reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK)) {
754 reg |= SMPS_CTRL_MODE_ON;
755 ret = palmas_smps_write(palmas, addr, reg);
756 if (ret < 0)
757 return ret;
758 }
759 return palmas_regulator_config_external(palmas, id, reg_init);
760 }
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100761 return 0;
762}
763
764static int palmas_ldo_init(struct palmas *palmas, int id,
765 struct palmas_reg_init *reg_init)
766{
767 unsigned int reg;
768 unsigned int addr;
769 int ret;
Keerthycac9e912014-06-18 15:28:59 +0530770 struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata;
Nishanth Menoncf910b62014-06-30 10:57:36 -0500771 struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
Keerthycac9e912014-06-18 15:28:59 +0530772
Nishanth Menoncf910b62014-06-30 10:57:36 -0500773 addr = rinfo->ctrl_addr;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100774
Axel Lin2735dae2012-07-18 12:31:59 +0800775 ret = palmas_ldo_read(palmas, addr, &reg);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100776 if (ret)
777 return ret;
778
779 if (reg_init->warm_reset)
780 reg |= PALMAS_LDO1_CTRL_WR_S;
Laxman Dewangan30590d02013-04-17 15:13:11 +0530781 else
782 reg &= ~PALMAS_LDO1_CTRL_WR_S;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100783
784 if (reg_init->mode_sleep)
785 reg |= PALMAS_LDO1_CTRL_MODE_SLEEP;
Laxman Dewangan30590d02013-04-17 15:13:11 +0530786 else
787 reg &= ~PALMAS_LDO1_CTRL_MODE_SLEEP;
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100788
Axel Lin2735dae2012-07-18 12:31:59 +0800789 ret = palmas_ldo_write(palmas, addr, reg);
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100790 if (ret)
791 return ret;
792
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530793 if (reg_init->roof_floor) {
794 /* Enable externally controlled regulator */
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530795 ret = palmas_update_bits(palmas, PALMAS_LDO_BASE,
796 addr, PALMAS_LDO1_CTRL_MODE_ACTIVE,
797 PALMAS_LDO1_CTRL_MODE_ACTIVE);
798 if (ret < 0) {
799 dev_err(palmas->dev,
800 "LDO Register 0x%02x update failed %d\n",
801 addr, ret);
802 return ret;
803 }
804 return palmas_regulator_config_external(palmas, id, reg_init);
805 }
Graeme Gregorye5ce4202012-05-18 16:53:57 +0100806 return 0;
807}
808
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530809static int palmas_extreg_init(struct palmas *palmas, int id,
810 struct palmas_reg_init *reg_init)
811{
812 unsigned int addr;
813 int ret;
814 unsigned int val = 0;
Keerthycac9e912014-06-18 15:28:59 +0530815 struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata;
Nishanth Menoncf910b62014-06-30 10:57:36 -0500816 struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
Keerthycac9e912014-06-18 15:28:59 +0530817
Nishanth Menoncf910b62014-06-30 10:57:36 -0500818 addr = rinfo->ctrl_addr;
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530819
820 if (reg_init->mode_sleep)
821 val = PALMAS_REGEN1_CTRL_MODE_SLEEP;
822
823 ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE,
824 addr, PALMAS_REGEN1_CTRL_MODE_SLEEP, val);
825 if (ret < 0) {
826 dev_err(palmas->dev, "Resource reg 0x%02x update failed %d\n",
827 addr, ret);
828 return ret;
829 }
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530830
831 if (reg_init->roof_floor) {
832 /* Enable externally controlled regulator */
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530833 ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE,
834 addr, PALMAS_REGEN1_CTRL_MODE_ACTIVE,
835 PALMAS_REGEN1_CTRL_MODE_ACTIVE);
836 if (ret < 0) {
837 dev_err(palmas->dev,
838 "Resource Register 0x%02x update failed %d\n",
839 addr, ret);
840 return ret;
841 }
842 return palmas_regulator_config_external(palmas, id, reg_init);
843 }
Laxman Dewanganaa07f022013-04-17 15:13:12 +0530844 return 0;
845}
846
Laxman Dewangan17c11a72013-04-17 15:13:13 +0530847static void palmas_enable_ldo8_track(struct palmas *palmas)
848{
849 unsigned int reg;
850 unsigned int addr;
851 int ret;
Keerthycac9e912014-06-18 15:28:59 +0530852 struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata;
Nishanth Menoncf910b62014-06-30 10:57:36 -0500853 struct palmas_regs_info *rinfo;
Keerthycac9e912014-06-18 15:28:59 +0530854
Nishanth Menoncf910b62014-06-30 10:57:36 -0500855 rinfo = &ddata->palmas_regs_info[PALMAS_REG_LDO8];
856 addr = rinfo->ctrl_addr;
Laxman Dewangan17c11a72013-04-17 15:13:13 +0530857
858 ret = palmas_ldo_read(palmas, addr, &reg);
859 if (ret) {
860 dev_err(palmas->dev, "Error in reading ldo8 control reg\n");
861 return;
862 }
863
864 reg |= PALMAS_LDO8_CTRL_LDO_TRACKING_EN;
865 ret = palmas_ldo_write(palmas, addr, reg);
866 if (ret < 0) {
867 dev_err(palmas->dev, "Error in enabling tracking mode\n");
868 return;
869 }
870 /*
871 * When SMPS45 is set to off and LDO8 tracking is enabled, the LDO8
872 * output is defined by the LDO8_VOLTAGE.VSEL register divided by two,
873 * and can be set from 0.45 to 1.65 V.
874 */
Nishanth Menoncf910b62014-06-30 10:57:36 -0500875 addr = rinfo->vsel_addr;
Laxman Dewangan17c11a72013-04-17 15:13:13 +0530876 ret = palmas_ldo_read(palmas, addr, &reg);
877 if (ret) {
878 dev_err(palmas->dev, "Error in reading ldo8 voltage reg\n");
879 return;
880 }
881
882 reg = (reg << 1) & PALMAS_LDO8_VOLTAGE_VSEL_MASK;
883 ret = palmas_ldo_write(palmas, addr, reg);
884 if (ret < 0)
885 dev_err(palmas->dev, "Error in setting ldo8 voltage reg\n");
886
887 return;
888}
889
Keerthycac9e912014-06-18 15:28:59 +0530890static int palmas_ldo_registration(struct palmas_pmic *pmic,
891 struct palmas_pmic_driver_data *ddata,
892 struct palmas_pmic_platform_data *pdata,
893 const char *pdev_name,
894 struct regulator_config config)
Graeme Gregorya361cd92012-08-28 13:47:40 +0200895{
Keerthycac9e912014-06-18 15:28:59 +0530896 int id, ret;
897 struct regulator_dev *rdev;
898 struct palmas_reg_init *reg_init;
Nishanth Menoncf910b62014-06-30 10:57:36 -0500899 struct palmas_regs_info *rinfo;
Nishanth Menon429222d2014-06-30 10:57:38 -0500900 struct regulator_desc *desc;
Graeme Gregorya361cd92012-08-28 13:47:40 +0200901
Keerthycac9e912014-06-18 15:28:59 +0530902 for (id = ddata->ldo_begin; id < ddata->max_reg; id++) {
903 if (pdata && pdata->reg_init[id])
904 reg_init = pdata->reg_init[id];
905 else
906 reg_init = NULL;
Graeme Gregorya361cd92012-08-28 13:47:40 +0200907
Nishanth Menoncf910b62014-06-30 10:57:36 -0500908 rinfo = &ddata->palmas_regs_info[id];
Keerthycac9e912014-06-18 15:28:59 +0530909 /* Miss out regulators which are not available due
910 * to alternate functions.
911 */
Graeme Gregorya361cd92012-08-28 13:47:40 +0200912
Keerthycac9e912014-06-18 15:28:59 +0530913 /* Register the regulators */
Nishanth Menon429222d2014-06-30 10:57:38 -0500914 desc = &pmic->desc[id];
915 desc->name = rinfo->name;
916 desc->id = id;
917 desc->type = REGULATOR_VOLTAGE;
918 desc->owner = THIS_MODULE;
Graeme Gregorya361cd92012-08-28 13:47:40 +0200919
Keerthycac9e912014-06-18 15:28:59 +0530920 if (id < PALMAS_REG_REGEN1) {
Nishanth Menon429222d2014-06-30 10:57:38 -0500921 desc->n_voltages = PALMAS_LDO_NUM_VOLTAGES;
Keerthycac9e912014-06-18 15:28:59 +0530922 if (reg_init && reg_init->roof_floor)
Nishanth Menon429222d2014-06-30 10:57:38 -0500923 desc->ops = &palmas_ops_ext_control_ldo;
Keerthycac9e912014-06-18 15:28:59 +0530924 else
Nishanth Menon429222d2014-06-30 10:57:38 -0500925 desc->ops = &palmas_ops_ldo;
926 desc->min_uV = 900000;
927 desc->uV_step = 50000;
928 desc->linear_min_sel = 1;
929 desc->enable_time = 500;
930 desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
931 rinfo->vsel_addr);
932 desc->vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK;
933 desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
934 rinfo->ctrl_addr);
935 desc->enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE;
Graeme Gregorya361cd92012-08-28 13:47:40 +0200936
Keerthycac9e912014-06-18 15:28:59 +0530937 /* Check if LDO8 is in tracking mode or not */
938 if (pdata && (id == PALMAS_REG_LDO8) &&
939 pdata->enable_ldo8_tracking) {
940 palmas_enable_ldo8_track(pmic->palmas);
Nishanth Menon429222d2014-06-30 10:57:38 -0500941 desc->min_uV = 450000;
942 desc->uV_step = 25000;
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530943 }
Keerthycac9e912014-06-18 15:28:59 +0530944
945 /* LOD6 in vibrator mode will have enable time 2000us */
946 if (pdata && pdata->ldo6_vibrator &&
947 (id == PALMAS_REG_LDO6))
Nishanth Menon429222d2014-06-30 10:57:38 -0500948 desc->enable_time = 2000;
Keerthyb554e142015-12-14 12:06:55 +0530949
950 if (id == PALMAS_REG_LDO9) {
951 desc->ops = &palmas_ops_ldo9;
952 desc->bypass_reg = desc->enable_reg;
Nishanth Menone0341f12016-04-26 11:36:42 -0500953 desc->bypass_val_on =
954 PALMAS_LDO9_CTRL_LDO_BYPASS_EN;
Keerthyb554e142015-12-14 12:06:55 +0530955 desc->bypass_mask =
956 PALMAS_LDO9_CTRL_LDO_BYPASS_EN;
957 }
Keerthycac9e912014-06-18 15:28:59 +0530958 } else {
Keerthye999c722015-03-17 15:56:05 +0530959 if (!ddata->has_regen3 && id == PALMAS_REG_REGEN3)
960 continue;
961
Nishanth Menon429222d2014-06-30 10:57:38 -0500962 desc->n_voltages = 1;
Keerthycac9e912014-06-18 15:28:59 +0530963 if (reg_init && reg_init->roof_floor)
Nishanth Menon429222d2014-06-30 10:57:38 -0500964 desc->ops = &palmas_ops_ext_control_extreg;
Keerthycac9e912014-06-18 15:28:59 +0530965 else
Nishanth Menon429222d2014-06-30 10:57:38 -0500966 desc->ops = &palmas_ops_extreg;
967 desc->enable_reg =
Keerthycac9e912014-06-18 15:28:59 +0530968 PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE,
Nishanth Menoncf910b62014-06-30 10:57:36 -0500969 rinfo->ctrl_addr);
Nishanth Menon429222d2014-06-30 10:57:38 -0500970 desc->enable_mask = PALMAS_REGEN1_CTRL_MODE_ACTIVE;
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +0530971 }
Graeme Gregorya361cd92012-08-28 13:47:40 +0200972
Keerthycac9e912014-06-18 15:28:59 +0530973 if (pdata)
974 config.init_data = pdata->reg_data[id];
975 else
976 config.init_data = NULL;
Graeme Gregorya361cd92012-08-28 13:47:40 +0200977
Nishanth Menon429222d2014-06-30 10:57:38 -0500978 desc->supply_name = rinfo->sname;
Keerthycac9e912014-06-18 15:28:59 +0530979 config.of_node = ddata->palmas_matches[id].of_node;
Graeme Gregorya361cd92012-08-28 13:47:40 +0200980
Nishanth Menon429222d2014-06-30 10:57:38 -0500981 rdev = devm_regulator_register(pmic->dev, desc, &config);
Keerthycac9e912014-06-18 15:28:59 +0530982 if (IS_ERR(rdev)) {
983 dev_err(pmic->dev,
984 "failed to register %s regulator\n",
985 pdev_name);
986 return PTR_ERR(rdev);
987 }
988
Keerthycac9e912014-06-18 15:28:59 +0530989 /* Initialise sleep/init values from platform data */
990 if (pdata) {
991 reg_init = pdata->reg_init[id];
992 if (reg_init) {
993 if (id <= ddata->ldo_end)
994 ret = palmas_ldo_init(pmic->palmas, id,
995 reg_init);
996 else
997 ret = palmas_extreg_init(pmic->palmas,
998 id, reg_init);
999 if (ret)
1000 return ret;
1001 }
1002 }
Graeme Gregorya361cd92012-08-28 13:47:40 +02001003 }
1004
Keerthycac9e912014-06-18 15:28:59 +05301005 return 0;
Graeme Gregorya361cd92012-08-28 13:47:40 +02001006}
1007
Keerthyd6f83372014-06-18 15:29:00 +05301008static int tps65917_ldo_registration(struct palmas_pmic *pmic,
1009 struct palmas_pmic_driver_data *ddata,
1010 struct palmas_pmic_platform_data *pdata,
1011 const char *pdev_name,
1012 struct regulator_config config)
1013{
1014 int id, ret;
1015 struct regulator_dev *rdev;
1016 struct palmas_reg_init *reg_init;
Nishanth Menoncf910b62014-06-30 10:57:36 -05001017 struct palmas_regs_info *rinfo;
Nishanth Menon429222d2014-06-30 10:57:38 -05001018 struct regulator_desc *desc;
Keerthyd6f83372014-06-18 15:29:00 +05301019
1020 for (id = ddata->ldo_begin; id < ddata->max_reg; id++) {
1021 if (pdata && pdata->reg_init[id])
1022 reg_init = pdata->reg_init[id];
1023 else
1024 reg_init = NULL;
1025
1026 /* Miss out regulators which are not available due
1027 * to alternate functions.
1028 */
Nishanth Menoncf910b62014-06-30 10:57:36 -05001029 rinfo = &ddata->palmas_regs_info[id];
Keerthyd6f83372014-06-18 15:29:00 +05301030
1031 /* Register the regulators */
Nishanth Menon429222d2014-06-30 10:57:38 -05001032 desc = &pmic->desc[id];
1033 desc->name = rinfo->name;
1034 desc->id = id;
1035 desc->type = REGULATOR_VOLTAGE;
1036 desc->owner = THIS_MODULE;
Keerthyd6f83372014-06-18 15:29:00 +05301037
1038 if (id < TPS65917_REG_REGEN1) {
Nishanth Menon429222d2014-06-30 10:57:38 -05001039 desc->n_voltages = PALMAS_LDO_NUM_VOLTAGES;
Keerthyd6f83372014-06-18 15:29:00 +05301040 if (reg_init && reg_init->roof_floor)
Nishanth Menon429222d2014-06-30 10:57:38 -05001041 desc->ops = &palmas_ops_ext_control_ldo;
Keerthyd6f83372014-06-18 15:29:00 +05301042 else
Nishanth Menon429222d2014-06-30 10:57:38 -05001043 desc->ops = &tps65917_ops_ldo;
1044 desc->min_uV = 900000;
1045 desc->uV_step = 50000;
1046 desc->linear_min_sel = 1;
1047 desc->enable_time = 500;
1048 desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
1049 rinfo->vsel_addr);
1050 desc->vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK;
1051 desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
1052 rinfo->ctrl_addr);
1053 desc->enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE;
Keerthyd6f83372014-06-18 15:29:00 +05301054 /*
1055 * To be confirmed. Discussion on going with PMIC Team.
1056 * It is of the order of ~60mV/uS.
1057 */
Nishanth Menon429222d2014-06-30 10:57:38 -05001058 desc->ramp_delay = 2500;
Keerthyb554e142015-12-14 12:06:55 +05301059 if (id == TPS65917_REG_LDO1 ||
1060 id == TPS65917_REG_LDO2) {
1061 desc->ops = &tps65917_ops_ldo_1_2;
1062 desc->bypass_reg = desc->enable_reg;
Nishanth Menone0341f12016-04-26 11:36:42 -05001063 desc->bypass_val_on =
1064 TPS65917_LDO1_CTRL_BYPASS_EN;
Keerthyb554e142015-12-14 12:06:55 +05301065 desc->bypass_mask =
1066 TPS65917_LDO1_CTRL_BYPASS_EN;
1067 }
Keerthyd6f83372014-06-18 15:29:00 +05301068 } else {
Nishanth Menon429222d2014-06-30 10:57:38 -05001069 desc->n_voltages = 1;
Keerthyd6f83372014-06-18 15:29:00 +05301070 if (reg_init && reg_init->roof_floor)
Nishanth Menon429222d2014-06-30 10:57:38 -05001071 desc->ops = &palmas_ops_ext_control_extreg;
Keerthyd6f83372014-06-18 15:29:00 +05301072 else
Nishanth Menon429222d2014-06-30 10:57:38 -05001073 desc->ops = &palmas_ops_extreg;
1074 desc->enable_reg =
Keerthyd6f83372014-06-18 15:29:00 +05301075 PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE,
Nishanth Menoncf910b62014-06-30 10:57:36 -05001076 rinfo->ctrl_addr);
Nishanth Menon429222d2014-06-30 10:57:38 -05001077 desc->enable_mask = PALMAS_REGEN1_CTRL_MODE_ACTIVE;
Keerthyd6f83372014-06-18 15:29:00 +05301078 }
1079
1080 if (pdata)
1081 config.init_data = pdata->reg_data[id];
1082 else
1083 config.init_data = NULL;
1084
Nishanth Menon429222d2014-06-30 10:57:38 -05001085 desc->supply_name = rinfo->sname;
Keerthyd6f83372014-06-18 15:29:00 +05301086 config.of_node = ddata->palmas_matches[id].of_node;
1087
Nishanth Menon429222d2014-06-30 10:57:38 -05001088 rdev = devm_regulator_register(pmic->dev, desc, &config);
Keerthyd6f83372014-06-18 15:29:00 +05301089 if (IS_ERR(rdev)) {
1090 dev_err(pmic->dev,
1091 "failed to register %s regulator\n",
1092 pdev_name);
1093 return PTR_ERR(rdev);
1094 }
1095
Keerthyd6f83372014-06-18 15:29:00 +05301096 /* Initialise sleep/init values from platform data */
1097 if (pdata) {
1098 reg_init = pdata->reg_init[id];
1099 if (reg_init) {
1100 if (id < TPS65917_REG_REGEN1)
1101 ret = palmas_ldo_init(pmic->palmas,
1102 id, reg_init);
1103 else
1104 ret = palmas_extreg_init(pmic->palmas,
1105 id, reg_init);
1106 if (ret)
1107 return ret;
1108 }
1109 }
1110 }
1111
1112 return 0;
1113}
1114
Keerthycac9e912014-06-18 15:28:59 +05301115static int palmas_smps_registration(struct palmas_pmic *pmic,
1116 struct palmas_pmic_driver_data *ddata,
1117 struct palmas_pmic_platform_data *pdata,
1118 const char *pdev_name,
1119 struct regulator_config config)
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001120{
Keerthycac9e912014-06-18 15:28:59 +05301121 int id, ret;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001122 unsigned int addr, reg;
Keerthycac9e912014-06-18 15:28:59 +05301123 struct regulator_dev *rdev;
1124 struct palmas_reg_init *reg_init;
Nishanth Menoncf910b62014-06-30 10:57:36 -05001125 struct palmas_regs_info *rinfo;
Nishanth Menon429222d2014-06-30 10:57:38 -05001126 struct regulator_desc *desc;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001127
Keerthycac9e912014-06-18 15:28:59 +05301128 for (id = ddata->smps_start; id <= ddata->smps_end; id++) {
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301129 bool ramp_delay_support = false;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001130
1131 /*
1132 * Miss out regulators which are not available due
1133 * to slaving configurations.
1134 */
1135 switch (id) {
1136 case PALMAS_REG_SMPS12:
1137 case PALMAS_REG_SMPS3:
1138 if (pmic->smps123)
1139 continue;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301140 if (id == PALMAS_REG_SMPS12)
1141 ramp_delay_support = true;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001142 break;
1143 case PALMAS_REG_SMPS123:
1144 if (!pmic->smps123)
1145 continue;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301146 ramp_delay_support = true;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001147 break;
1148 case PALMAS_REG_SMPS45:
1149 case PALMAS_REG_SMPS7:
1150 if (pmic->smps457)
1151 continue;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301152 if (id == PALMAS_REG_SMPS45)
1153 ramp_delay_support = true;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001154 break;
1155 case PALMAS_REG_SMPS457:
1156 if (!pmic->smps457)
1157 continue;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301158 ramp_delay_support = true;
1159 break;
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +05301160 case PALMAS_REG_SMPS10_OUT1:
1161 case PALMAS_REG_SMPS10_OUT2:
Keerthycac9e912014-06-18 15:28:59 +05301162 if (!PALMAS_PMIC_HAS(pmic->palmas, SMPS10_BOOST))
J Keerthy1ffb0be2013-06-19 11:27:48 +05301163 continue;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301164 }
Nishanth Menoncf910b62014-06-30 10:57:36 -05001165 rinfo = &ddata->palmas_regs_info[id];
Nishanth Menon429222d2014-06-30 10:57:38 -05001166 desc = &pmic->desc[id];
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301167
Sachin Kamat3f4d6362013-05-08 16:09:06 +05301168 if ((id == PALMAS_REG_SMPS6) || (id == PALMAS_REG_SMPS8))
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301169 ramp_delay_support = true;
1170
1171 if (ramp_delay_support) {
Nishanth Menoncf910b62014-06-30 10:57:36 -05001172 addr = rinfo->tstep_addr;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301173 ret = palmas_smps_read(pmic->palmas, addr, &reg);
1174 if (ret < 0) {
Keerthycac9e912014-06-18 15:28:59 +05301175 dev_err(pmic->dev,
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301176 "reading TSTEP reg failed: %d\n", ret);
Sachin Kamat51c86b32013-09-04 12:01:01 +05301177 return ret;
Laxman Dewangan28d1e8c2013-04-18 18:32:47 +05301178 }
Nishanth Menon429222d2014-06-30 10:57:38 -05001179 desc->ramp_delay = palmas_smps_ramp_delay[reg & 0x3];
1180 pmic->ramp_delay[id] = desc->ramp_delay;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001181 }
1182
Axel Linbdc4baa2012-11-29 10:01:44 +08001183 /* Initialise sleep/init values from platform data */
1184 if (pdata && pdata->reg_init[id]) {
1185 reg_init = pdata->reg_init[id];
Keerthycac9e912014-06-18 15:28:59 +05301186 ret = palmas_smps_init(pmic->palmas, id, reg_init);
Axel Linbdc4baa2012-11-29 10:01:44 +08001187 if (ret)
Sachin Kamat51c86b32013-09-04 12:01:01 +05301188 return ret;
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +05301189 } else {
1190 reg_init = NULL;
Axel Linbdc4baa2012-11-29 10:01:44 +08001191 }
1192
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001193 /* Register the regulators */
Nishanth Menon429222d2014-06-30 10:57:38 -05001194 desc->name = rinfo->name;
1195 desc->id = id;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001196
Axel Linfedd89b2012-06-06 20:01:38 +08001197 switch (id) {
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +05301198 case PALMAS_REG_SMPS10_OUT1:
1199 case PALMAS_REG_SMPS10_OUT2:
Nishanth Menon429222d2014-06-30 10:57:38 -05001200 desc->n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
1201 desc->ops = &palmas_ops_smps10;
1202 desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1203 PALMAS_SMPS10_CTRL);
1204 desc->vsel_mask = SMPS10_VSEL;
1205 desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1206 PALMAS_SMPS10_CTRL);
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +05301207 if (id == PALMAS_REG_SMPS10_OUT1)
Nishanth Menon429222d2014-06-30 10:57:38 -05001208 desc->enable_mask = SMPS10_SWITCH_EN;
Kishon Vijay Abraham I77409d92013-08-12 14:21:14 +05301209 else
Nishanth Menon429222d2014-06-30 10:57:38 -05001210 desc->enable_mask = SMPS10_BOOST_EN;
1211 desc->bypass_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1212 PALMAS_SMPS10_CTRL);
Nishanth Menone0341f12016-04-26 11:36:42 -05001213 desc->bypass_val_on = SMPS10_BYPASS_EN;
Nishanth Menon429222d2014-06-30 10:57:38 -05001214 desc->bypass_mask = SMPS10_BYPASS_EN;
1215 desc->min_uV = 3750000;
1216 desc->uV_step = 1250000;
Axel Linfedd89b2012-06-06 20:01:38 +08001217 break;
1218 default:
Axel Linbdc4baa2012-11-29 10:01:44 +08001219 /*
1220 * Read and store the RANGE bit for later use
1221 * This must be done before regulator is probed,
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +05301222 * otherwise we error in probe with unsupportable
1223 * ranges. Read the current smps mode for later use.
Axel Linbdc4baa2012-11-29 10:01:44 +08001224 */
Nishanth Menoncf910b62014-06-30 10:57:36 -05001225 addr = rinfo->vsel_addr;
Nishanth Menon429222d2014-06-30 10:57:38 -05001226 desc->n_linear_ranges = 3;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001227
1228 ret = palmas_smps_read(pmic->palmas, addr, &reg);
1229 if (ret)
Sachin Kamat51c86b32013-09-04 12:01:01 +05301230 return ret;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001231 if (reg & PALMAS_SMPS12_VOLTAGE_RANGE)
1232 pmic->range[id] = 1;
Keerthydbabd622014-05-22 14:48:29 +05301233 if (pmic->range[id])
Nishanth Menon429222d2014-06-30 10:57:38 -05001234 desc->linear_ranges = smps_high_ranges;
Keerthydbabd622014-05-22 14:48:29 +05301235 else
Nishanth Menon429222d2014-06-30 10:57:38 -05001236 desc->linear_ranges = smps_low_ranges;
Axel Linbdc4baa2012-11-29 10:01:44 +08001237
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +05301238 if (reg_init && reg_init->roof_floor)
Nishanth Menon429222d2014-06-30 10:57:38 -05001239 desc->ops = &palmas_ops_ext_control_smps;
Laxman Dewangan32b6d3f2013-08-21 16:18:16 +05301240 else
Nishanth Menon429222d2014-06-30 10:57:38 -05001241 desc->ops = &palmas_ops_smps;
1242 desc->n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
1243 desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1244 rinfo->vsel_addr);
1245 desc->vsel_mask = PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +05301246
1247 /* Read the smps mode for later use. */
Nishanth Menoncf910b62014-06-30 10:57:36 -05001248 addr = rinfo->ctrl_addr;
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +05301249 ret = palmas_smps_read(pmic->palmas, addr, &reg);
1250 if (ret)
Sachin Kamat51c86b32013-09-04 12:01:01 +05301251 return ret;
Laxman Dewangan51d3a0c2013-04-18 18:32:48 +05301252 pmic->current_reg_mode[id] = reg &
1253 PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
Nishanth Menon318dbb02014-06-20 12:26:23 -05001254
Nishanth Menon429222d2014-06-30 10:57:38 -05001255 desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1256 rinfo->ctrl_addr);
1257 desc->enable_mask = PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
Nishanth Menon318dbb02014-06-20 12:26:23 -05001258 /* set_mode overrides this value */
Nishanth Menon429222d2014-06-30 10:57:38 -05001259 desc->enable_val = SMPS_CTRL_MODE_ON;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001260 }
1261
Nishanth Menon429222d2014-06-30 10:57:38 -05001262 desc->type = REGULATOR_VOLTAGE;
1263 desc->owner = THIS_MODULE;
Axel Linbdc4baa2012-11-29 10:01:44 +08001264
Graeme Gregorya361cd92012-08-28 13:47:40 +02001265 if (pdata)
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001266 config.init_data = pdata->reg_data[id];
1267 else
1268 config.init_data = NULL;
1269
Nishanth Menon429222d2014-06-30 10:57:38 -05001270 desc->supply_name = rinfo->sname;
Keerthycac9e912014-06-18 15:28:59 +05301271 config.of_node = ddata->palmas_matches[id].of_node;
Graeme Gregorya361cd92012-08-28 13:47:40 +02001272
Nishanth Menon429222d2014-06-30 10:57:38 -05001273 rdev = devm_regulator_register(pmic->dev, desc, &config);
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001274 if (IS_ERR(rdev)) {
Keerthycac9e912014-06-18 15:28:59 +05301275 dev_err(pmic->dev,
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001276 "failed to register %s regulator\n",
Keerthycac9e912014-06-18 15:28:59 +05301277 pdev_name);
Sachin Kamat51c86b32013-09-04 12:01:01 +05301278 return PTR_ERR(rdev);
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001279 }
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001280 }
1281
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001282 return 0;
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001283}
1284
Keerthyd6f83372014-06-18 15:29:00 +05301285static int tps65917_smps_registration(struct palmas_pmic *pmic,
1286 struct palmas_pmic_driver_data *ddata,
1287 struct palmas_pmic_platform_data *pdata,
1288 const char *pdev_name,
1289 struct regulator_config config)
1290{
1291 int id, ret;
1292 unsigned int addr, reg;
1293 struct regulator_dev *rdev;
1294 struct palmas_reg_init *reg_init;
Nishanth Menoncf910b62014-06-30 10:57:36 -05001295 struct palmas_regs_info *rinfo;
Nishanth Menon429222d2014-06-30 10:57:38 -05001296 struct regulator_desc *desc;
Keerthyd6f83372014-06-18 15:29:00 +05301297
1298 for (id = ddata->smps_start; id <= ddata->smps_end; id++) {
1299 /*
1300 * Miss out regulators which are not available due
1301 * to slaving configurations.
1302 */
Nishanth Menon429222d2014-06-30 10:57:38 -05001303 desc = &pmic->desc[id];
1304 desc->n_linear_ranges = 3;
Keerthybe035302017-05-23 17:46:56 +05301305 if ((id == TPS65917_REG_SMPS2 || id == TPS65917_REG_SMPS1) &&
1306 pmic->smps12)
Keerthyd6f83372014-06-18 15:29:00 +05301307 continue;
1308
1309 /* Initialise sleep/init values from platform data */
1310 if (pdata && pdata->reg_init[id]) {
1311 reg_init = pdata->reg_init[id];
1312 ret = palmas_smps_init(pmic->palmas, id, reg_init);
1313 if (ret)
1314 return ret;
1315 } else {
1316 reg_init = NULL;
1317 }
Nishanth Menoncf910b62014-06-30 10:57:36 -05001318 rinfo = &ddata->palmas_regs_info[id];
Keerthyd6f83372014-06-18 15:29:00 +05301319
1320 /* Register the regulators */
Nishanth Menon429222d2014-06-30 10:57:38 -05001321 desc->name = rinfo->name;
1322 desc->id = id;
Keerthyd6f83372014-06-18 15:29:00 +05301323
1324 /*
1325 * Read and store the RANGE bit for later use
1326 * This must be done before regulator is probed,
1327 * otherwise we error in probe with unsupportable
1328 * ranges. Read the current smps mode for later use.
1329 */
Nishanth Menoncf910b62014-06-30 10:57:36 -05001330 addr = rinfo->vsel_addr;
Keerthyd6f83372014-06-18 15:29:00 +05301331
1332 ret = palmas_smps_read(pmic->palmas, addr, &reg);
1333 if (ret)
1334 return ret;
1335 if (reg & TPS65917_SMPS1_VOLTAGE_RANGE)
1336 pmic->range[id] = 1;
1337
1338 if (pmic->range[id])
Nishanth Menon429222d2014-06-30 10:57:38 -05001339 desc->linear_ranges = smps_high_ranges;
1340 else
1341 desc->linear_ranges = smps_low_ranges;
Keerthyd6f83372014-06-18 15:29:00 +05301342
1343 if (reg_init && reg_init->roof_floor)
Nishanth Menon429222d2014-06-30 10:57:38 -05001344 desc->ops = &tps65917_ops_ext_control_smps;
Keerthyd6f83372014-06-18 15:29:00 +05301345 else
Nishanth Menon429222d2014-06-30 10:57:38 -05001346 desc->ops = &tps65917_ops_smps;
1347 desc->n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
1348 desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1349 rinfo->vsel_addr);
1350 desc->vsel_mask = PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
1351 desc->ramp_delay = 2500;
Keerthyd6f83372014-06-18 15:29:00 +05301352
1353 /* Read the smps mode for later use. */
Nishanth Menoncf910b62014-06-30 10:57:36 -05001354 addr = rinfo->ctrl_addr;
Keerthyd6f83372014-06-18 15:29:00 +05301355 ret = palmas_smps_read(pmic->palmas, addr, &reg);
1356 if (ret)
1357 return ret;
1358 pmic->current_reg_mode[id] = reg &
1359 PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
Nishanth Menonb6328152014-06-30 10:57:39 -05001360 desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1361 rinfo->ctrl_addr);
1362 desc->enable_mask = PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
1363 /* set_mode overrides this value */
1364 desc->enable_val = SMPS_CTRL_MODE_ON;
Keerthyd6f83372014-06-18 15:29:00 +05301365
Nishanth Menon429222d2014-06-30 10:57:38 -05001366 desc->type = REGULATOR_VOLTAGE;
1367 desc->owner = THIS_MODULE;
Keerthyd6f83372014-06-18 15:29:00 +05301368
1369 if (pdata)
1370 config.init_data = pdata->reg_data[id];
1371 else
1372 config.init_data = NULL;
1373
Nishanth Menon429222d2014-06-30 10:57:38 -05001374 desc->supply_name = rinfo->sname;
Keerthyd6f83372014-06-18 15:29:00 +05301375 config.of_node = ddata->palmas_matches[id].of_node;
1376
Nishanth Menon429222d2014-06-30 10:57:38 -05001377 rdev = devm_regulator_register(pmic->dev, desc, &config);
Keerthyd6f83372014-06-18 15:29:00 +05301378 if (IS_ERR(rdev)) {
1379 dev_err(pmic->dev,
1380 "failed to register %s regulator\n",
1381 pdev_name);
1382 return PTR_ERR(rdev);
1383 }
Keerthyd6f83372014-06-18 15:29:00 +05301384 }
1385
1386 return 0;
1387}
1388
Keerthycac9e912014-06-18 15:28:59 +05301389static struct of_regulator_match palmas_matches[] = {
1390 { .name = "smps12", },
1391 { .name = "smps123", },
1392 { .name = "smps3", },
1393 { .name = "smps45", },
1394 { .name = "smps457", },
1395 { .name = "smps6", },
1396 { .name = "smps7", },
1397 { .name = "smps8", },
1398 { .name = "smps9", },
1399 { .name = "smps10_out2", },
1400 { .name = "smps10_out1", },
1401 { .name = "ldo1", },
1402 { .name = "ldo2", },
1403 { .name = "ldo3", },
1404 { .name = "ldo4", },
1405 { .name = "ldo5", },
1406 { .name = "ldo6", },
1407 { .name = "ldo7", },
1408 { .name = "ldo8", },
1409 { .name = "ldo9", },
1410 { .name = "ldoln", },
1411 { .name = "ldousb", },
1412 { .name = "regen1", },
1413 { .name = "regen2", },
1414 { .name = "regen3", },
1415 { .name = "sysen1", },
1416 { .name = "sysen2", },
1417};
1418
Keerthyd6f83372014-06-18 15:29:00 +05301419static struct of_regulator_match tps65917_matches[] = {
1420 { .name = "smps1", },
1421 { .name = "smps2", },
1422 { .name = "smps3", },
1423 { .name = "smps4", },
1424 { .name = "smps5", },
Keerthybe035302017-05-23 17:46:56 +05301425 { .name = "smps12",},
Keerthyd6f83372014-06-18 15:29:00 +05301426 { .name = "ldo1", },
1427 { .name = "ldo2", },
1428 { .name = "ldo3", },
1429 { .name = "ldo4", },
1430 { .name = "ldo5", },
1431 { .name = "regen1", },
1432 { .name = "regen2", },
1433 { .name = "regen3", },
1434 { .name = "sysen1", },
1435 { .name = "sysen2", },
1436};
1437
Nishanth Menon4b09e172014-06-30 10:57:34 -05001438static struct palmas_pmic_driver_data palmas_ddata = {
Keerthycac9e912014-06-18 15:28:59 +05301439 .smps_start = PALMAS_REG_SMPS12,
1440 .smps_end = PALMAS_REG_SMPS10_OUT1,
1441 .ldo_begin = PALMAS_REG_LDO1,
1442 .ldo_end = PALMAS_REG_LDOUSB,
1443 .max_reg = PALMAS_NUM_REGS,
Keerthye999c722015-03-17 15:56:05 +05301444 .has_regen3 = true,
Nishanth Menon6839cd62014-06-30 10:57:37 -05001445 .palmas_regs_info = palmas_generic_regs_info,
Keerthycac9e912014-06-18 15:28:59 +05301446 .palmas_matches = palmas_matches,
1447 .sleep_req_info = palma_sleep_req_info,
1448 .smps_register = palmas_smps_registration,
1449 .ldo_register = palmas_ldo_registration,
1450};
1451
Nishanth Menon4b09e172014-06-30 10:57:34 -05001452static struct palmas_pmic_driver_data tps65917_ddata = {
Keerthyd6f83372014-06-18 15:29:00 +05301453 .smps_start = TPS65917_REG_SMPS1,
Keerthybe035302017-05-23 17:46:56 +05301454 .smps_end = TPS65917_REG_SMPS12,
Keerthyd6f83372014-06-18 15:29:00 +05301455 .ldo_begin = TPS65917_REG_LDO1,
1456 .ldo_end = TPS65917_REG_LDO5,
1457 .max_reg = TPS65917_NUM_REGS,
Keerthye999c722015-03-17 15:56:05 +05301458 .has_regen3 = true,
Keerthyd6f83372014-06-18 15:29:00 +05301459 .palmas_regs_info = tps65917_regs_info,
1460 .palmas_matches = tps65917_matches,
1461 .sleep_req_info = tps65917_sleep_req_info,
1462 .smps_register = tps65917_smps_registration,
1463 .ldo_register = tps65917_ldo_registration,
1464};
1465
Nishanth Menon7f091e52016-05-05 19:29:51 -05001466static int palmas_dt_to_pdata(struct device *dev,
1467 struct device_node *node,
1468 struct palmas_pmic_platform_data *pdata,
1469 struct palmas_pmic_driver_data *ddata)
Keerthycac9e912014-06-18 15:28:59 +05301470{
1471 struct device_node *regulators;
1472 u32 prop;
1473 int idx, ret;
1474
Keerthycac9e912014-06-18 15:28:59 +05301475 regulators = of_get_child_by_name(node, "regulators");
1476 if (!regulators) {
1477 dev_info(dev, "regulator node not found\n");
Nishanth Menon7f091e52016-05-05 19:29:51 -05001478 return 0;
Keerthycac9e912014-06-18 15:28:59 +05301479 }
1480
1481 ret = of_regulator_match(dev, regulators, ddata->palmas_matches,
1482 ddata->max_reg);
1483 of_node_put(regulators);
1484 if (ret < 0) {
1485 dev_err(dev, "Error parsing regulator init data: %d\n", ret);
Nishanth Menon7f091e52016-05-05 19:29:51 -05001486 return 0;
Keerthycac9e912014-06-18 15:28:59 +05301487 }
1488
1489 for (idx = 0; idx < ddata->max_reg; idx++) {
Julia Lawall96e4f522017-05-04 22:10:51 +02001490 struct of_regulator_match *match;
Nishanth Menon1b424432016-05-05 19:29:50 -05001491 struct palmas_reg_init *rinit;
Nishanth Menon6c7d6142016-05-05 19:29:52 -05001492 struct device_node *np;
Nishanth Menon036d1932016-05-05 19:29:49 -05001493
1494 match = &ddata->palmas_matches[idx];
Nishanth Menon6c7d6142016-05-05 19:29:52 -05001495 np = match->of_node;
Nishanth Menon036d1932016-05-05 19:29:49 -05001496
Nishanth Menon6c7d6142016-05-05 19:29:52 -05001497 if (!match->init_data || !np)
Keerthycac9e912014-06-18 15:28:59 +05301498 continue;
1499
Nishanth Menon1b424432016-05-05 19:29:50 -05001500 rinit = devm_kzalloc(dev, sizeof(*rinit), GFP_KERNEL);
Nishanth Menon7f091e52016-05-05 19:29:51 -05001501 if (!rinit)
1502 return -ENOMEM;
1503
Nishanth Menon036d1932016-05-05 19:29:49 -05001504 pdata->reg_data[idx] = match->init_data;
Nishanth Menon1b424432016-05-05 19:29:50 -05001505 pdata->reg_init[idx] = rinit;
Keerthycac9e912014-06-18 15:28:59 +05301506
Nishanth Menon6c7d6142016-05-05 19:29:52 -05001507 rinit->warm_reset = of_property_read_bool(np, "ti,warm-reset");
1508 ret = of_property_read_u32(np, "ti,roof-floor", &prop);
Keerthycac9e912014-06-18 15:28:59 +05301509 /* EINVAL: Property not found */
1510 if (ret != -EINVAL) {
1511 int econtrol;
1512
1513 /* use default value, when no value is specified */
1514 econtrol = PALMAS_EXT_CONTROL_NSLEEP;
1515 if (!ret) {
1516 switch (prop) {
1517 case 1:
1518 econtrol = PALMAS_EXT_CONTROL_ENABLE1;
1519 break;
1520 case 2:
1521 econtrol = PALMAS_EXT_CONTROL_ENABLE2;
1522 break;
1523 case 3:
1524 econtrol = PALMAS_EXT_CONTROL_NSLEEP;
1525 break;
1526 default:
1527 WARN_ON(1);
1528 dev_warn(dev,
1529 "%s: Invalid roof-floor option: %u\n",
Nishanth Menon036d1932016-05-05 19:29:49 -05001530 match->name, prop);
Keerthycac9e912014-06-18 15:28:59 +05301531 break;
1532 }
1533 }
Nishanth Menon1b424432016-05-05 19:29:50 -05001534 rinit->roof_floor = econtrol;
Keerthycac9e912014-06-18 15:28:59 +05301535 }
1536
Nishanth Menon6c7d6142016-05-05 19:29:52 -05001537 ret = of_property_read_u32(np, "ti,mode-sleep", &prop);
Keerthycac9e912014-06-18 15:28:59 +05301538 if (!ret)
Nishanth Menon1b424432016-05-05 19:29:50 -05001539 rinit->mode_sleep = prop;
Keerthycac9e912014-06-18 15:28:59 +05301540
Nishanth Menon6c7d6142016-05-05 19:29:52 -05001541 ret = of_property_read_bool(np, "ti,smps-range");
Keerthycac9e912014-06-18 15:28:59 +05301542 if (ret)
Nishanth Menon1b424432016-05-05 19:29:50 -05001543 rinit->vsel = PALMAS_SMPS12_VOLTAGE_RANGE;
Keerthycac9e912014-06-18 15:28:59 +05301544
1545 if (idx == PALMAS_REG_LDO8)
1546 pdata->enable_ldo8_tracking = of_property_read_bool(
Nishanth Menon6c7d6142016-05-05 19:29:52 -05001547 np, "ti,enable-ldo8-tracking");
Keerthycac9e912014-06-18 15:28:59 +05301548 }
1549
1550 pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator");
Nishanth Menon7f091e52016-05-05 19:29:51 -05001551
1552 return 0;
Keerthycac9e912014-06-18 15:28:59 +05301553}
1554
Fabian Frederickcdbf6f02015-03-16 20:17:08 +01001555static const struct of_device_id of_palmas_match_tbl[] = {
Keerthycac9e912014-06-18 15:28:59 +05301556 {
1557 .compatible = "ti,palmas-pmic",
1558 .data = &palmas_ddata,
1559 },
1560 {
1561 .compatible = "ti,twl6035-pmic",
1562 .data = &palmas_ddata,
1563 },
1564 {
1565 .compatible = "ti,twl6036-pmic",
1566 .data = &palmas_ddata,
1567 },
1568 {
1569 .compatible = "ti,twl6037-pmic",
1570 .data = &palmas_ddata,
1571 },
1572 {
1573 .compatible = "ti,tps65913-pmic",
1574 .data = &palmas_ddata,
1575 },
1576 {
1577 .compatible = "ti,tps65914-pmic",
1578 .data = &palmas_ddata,
1579 },
1580 {
1581 .compatible = "ti,tps80036-pmic",
1582 .data = &palmas_ddata,
1583 },
1584 {
1585 .compatible = "ti,tps659038-pmic",
1586 .data = &palmas_ddata,
1587 },
Keerthyd6f83372014-06-18 15:29:00 +05301588 {
1589 .compatible = "ti,tps65917-pmic",
1590 .data = &tps65917_ddata,
1591 },
Graeme Gregorya361cd92012-08-28 13:47:40 +02001592 { /* end */ }
1593};
1594
Keerthycac9e912014-06-18 15:28:59 +05301595static int palmas_regulators_probe(struct platform_device *pdev)
1596{
1597 struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
1598 struct palmas_pmic_platform_data *pdata = dev_get_platdata(&pdev->dev);
1599 struct device_node *node = pdev->dev.of_node;
1600 struct palmas_pmic_driver_data *driver_data;
1601 struct regulator_config config = { };
1602 struct palmas_pmic *pmic;
1603 const char *pdev_name;
1604 const struct of_device_id *match;
1605 int ret = 0;
1606 unsigned int reg;
1607
1608 match = of_match_device(of_match_ptr(of_palmas_match_tbl), &pdev->dev);
1609
1610 if (!match)
1611 return -ENODATA;
1612
1613 driver_data = (struct palmas_pmic_driver_data *)match->data;
1614 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
1615 if (!pdata)
1616 return -ENOMEM;
1617
1618 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
1619 if (!pmic)
1620 return -ENOMEM;
1621
Keerthye999c722015-03-17 15:56:05 +05301622 if (of_device_is_compatible(node, "ti,tps659038-pmic")) {
Keerthye03826d2015-03-17 15:56:04 +05301623 palmas_generic_regs_info[PALMAS_REG_REGEN2].ctrl_addr =
1624 TPS659038_REGEN2_CTRL;
Keerthye999c722015-03-17 15:56:05 +05301625 palmas_ddata.has_regen3 = false;
1626 }
Keerthye03826d2015-03-17 15:56:04 +05301627
Keerthycac9e912014-06-18 15:28:59 +05301628 pmic->dev = &pdev->dev;
1629 pmic->palmas = palmas;
1630 palmas->pmic = pmic;
1631 platform_set_drvdata(pdev, pmic);
1632 pmic->palmas->pmic_ddata = driver_data;
1633
Nishanth Menon7f091e52016-05-05 19:29:51 -05001634 ret = palmas_dt_to_pdata(&pdev->dev, node, pdata, driver_data);
1635 if (ret)
1636 return ret;
Keerthycac9e912014-06-18 15:28:59 +05301637
1638 ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg);
1639 if (ret)
1640 return ret;
1641
Keerthybe035302017-05-23 17:46:56 +05301642 if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN) {
Keerthycac9e912014-06-18 15:28:59 +05301643 pmic->smps123 = 1;
Keerthybe035302017-05-23 17:46:56 +05301644 pmic->smps12 = 1;
1645 }
Keerthycac9e912014-06-18 15:28:59 +05301646
1647 if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN)
1648 pmic->smps457 = 1;
1649
1650 config.regmap = palmas->regmap[REGULATOR_SLAVE];
1651 config.dev = &pdev->dev;
1652 config.driver_data = pmic;
1653 pdev_name = pdev->name;
1654
1655 ret = driver_data->smps_register(pmic, driver_data, pdata, pdev_name,
1656 config);
1657 if (ret)
1658 return ret;
1659
1660 ret = driver_data->ldo_register(pmic, driver_data, pdata, pdev_name,
1661 config);
1662
1663 return ret;
1664}
1665
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001666static struct platform_driver palmas_driver = {
1667 .driver = {
1668 .name = "palmas-pmic",
Graeme Gregorya361cd92012-08-28 13:47:40 +02001669 .of_match_table = of_palmas_match_tbl,
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001670 },
Laxman Dewanganbbcf50b2013-03-18 14:59:49 +05301671 .probe = palmas_regulators_probe,
Graeme Gregorye5ce4202012-05-18 16:53:57 +01001672};
1673
1674static int __init palmas_init(void)
1675{
1676 return platform_driver_register(&palmas_driver);
1677}
1678subsys_initcall(palmas_init);
1679
1680static void __exit palmas_exit(void)
1681{
1682 platform_driver_unregister(&palmas_driver);
1683}
1684module_exit(palmas_exit);
1685
1686MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1687MODULE_DESCRIPTION("Palmas voltage regulator driver");
1688MODULE_LICENSE("GPL");
1689MODULE_ALIAS("platform:palmas-pmic");
Graeme Gregorya361cd92012-08-28 13:47:40 +02001690MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);