Blame view

drivers/regulator/palmas-regulator.c 44.3 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
e5ce4208f   Graeme Gregory   regulator: regula...
2
3
4
  /*
   * Driver for Regulator part of Palmas PMIC Chips
   *
7be859f74   Graeme Gregory   regulator: palmas...
5
   * Copyright 2011-2013 Texas Instruments Inc.
e5ce4208f   Graeme Gregory   regulator: regula...
6
7
   *
   * Author: Graeme Gregory <gg@slimlogic.co.uk>
a7dddf275   Graeme Gregory   regulator: palmas...
8
   * Author: Ian Lartey <ian@slimlogic.co.uk>
e5ce4208f   Graeme Gregory   regulator: regula...
9
10
11
12
13
14
15
16
17
18
19
20
   */
  
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/err.h>
  #include <linux/platform_device.h>
  #include <linux/regulator/driver.h>
  #include <linux/regulator/machine.h>
  #include <linux/slab.h>
  #include <linux/regmap.h>
  #include <linux/mfd/palmas.h>
a361cd9f2   Graeme Gregory   regulator: palmas...
21
22
23
  #include <linux/of.h>
  #include <linux/of_platform.h>
  #include <linux/regulator/of_regulator.h>
e5ce4208f   Graeme Gregory   regulator: regula...
24

dbabd624d   Keerthy   regulator: palmas...
25
  static const struct regulator_linear_range smps_low_ranges[] = {
6b7f2d82d   Nishanth Menon   regulator: palmas...
26
  	REGULATOR_LINEAR_RANGE(0, 0x0, 0x0, 0),
dbabd624d   Keerthy   regulator: palmas...
27
28
29
30
31
32
  	REGULATOR_LINEAR_RANGE(500000, 0x1, 0x6, 0),
  	REGULATOR_LINEAR_RANGE(510000, 0x7, 0x79, 10000),
  	REGULATOR_LINEAR_RANGE(1650000, 0x7A, 0x7f, 0),
  };
  
  static const struct regulator_linear_range smps_high_ranges[] = {
6b7f2d82d   Nishanth Menon   regulator: palmas...
33
  	REGULATOR_LINEAR_RANGE(0, 0x0, 0x0, 0),
dbabd624d   Keerthy   regulator: palmas...
34
35
36
37
  	REGULATOR_LINEAR_RANGE(1000000, 0x1, 0x6, 0),
  	REGULATOR_LINEAR_RANGE(1020000, 0x7, 0x79, 20000),
  	REGULATOR_LINEAR_RANGE(3300000, 0x7A, 0x7f, 0),
  };
6839cd6f6   Nishanth Menon   regulator: palmas...
38
  static struct palmas_regs_info palmas_generic_regs_info[] = {
e5ce4208f   Graeme Gregory   regulator: regula...
39
40
  	{
  		.name		= "SMPS12",
504382c99   Laxman Dewangan   regulator: palmas...
41
  		.sname		= "smps1-in",
e5ce4208f   Graeme Gregory   regulator: regula...
42
43
44
  		.vsel_addr	= PALMAS_SMPS12_VOLTAGE,
  		.ctrl_addr	= PALMAS_SMPS12_CTRL,
  		.tstep_addr	= PALMAS_SMPS12_TSTEP,
32b6d3f60   Laxman Dewangan   regulator: palmas...
45
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS12,
e5ce4208f   Graeme Gregory   regulator: regula...
46
47
48
  	},
  	{
  		.name		= "SMPS123",
504382c99   Laxman Dewangan   regulator: palmas...
49
  		.sname		= "smps1-in",
e5ce4208f   Graeme Gregory   regulator: regula...
50
51
52
  		.vsel_addr	= PALMAS_SMPS12_VOLTAGE,
  		.ctrl_addr	= PALMAS_SMPS12_CTRL,
  		.tstep_addr	= PALMAS_SMPS12_TSTEP,
32b6d3f60   Laxman Dewangan   regulator: palmas...
53
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS12,
e5ce4208f   Graeme Gregory   regulator: regula...
54
55
56
  	},
  	{
  		.name		= "SMPS3",
504382c99   Laxman Dewangan   regulator: palmas...
57
  		.sname		= "smps3-in",
e5ce4208f   Graeme Gregory   regulator: regula...
58
59
  		.vsel_addr	= PALMAS_SMPS3_VOLTAGE,
  		.ctrl_addr	= PALMAS_SMPS3_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
60
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS3,
e5ce4208f   Graeme Gregory   regulator: regula...
61
62
63
  	},
  	{
  		.name		= "SMPS45",
504382c99   Laxman Dewangan   regulator: palmas...
64
  		.sname		= "smps4-in",
e5ce4208f   Graeme Gregory   regulator: regula...
65
66
67
  		.vsel_addr	= PALMAS_SMPS45_VOLTAGE,
  		.ctrl_addr	= PALMAS_SMPS45_CTRL,
  		.tstep_addr	= PALMAS_SMPS45_TSTEP,
32b6d3f60   Laxman Dewangan   regulator: palmas...
68
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS45,
e5ce4208f   Graeme Gregory   regulator: regula...
69
70
71
  	},
  	{
  		.name		= "SMPS457",
504382c99   Laxman Dewangan   regulator: palmas...
72
  		.sname		= "smps4-in",
e5ce4208f   Graeme Gregory   regulator: regula...
73
74
75
  		.vsel_addr	= PALMAS_SMPS45_VOLTAGE,
  		.ctrl_addr	= PALMAS_SMPS45_CTRL,
  		.tstep_addr	= PALMAS_SMPS45_TSTEP,
32b6d3f60   Laxman Dewangan   regulator: palmas...
76
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS45,
e5ce4208f   Graeme Gregory   regulator: regula...
77
78
79
  	},
  	{
  		.name		= "SMPS6",
504382c99   Laxman Dewangan   regulator: palmas...
80
  		.sname		= "smps6-in",
e5ce4208f   Graeme Gregory   regulator: regula...
81
82
83
  		.vsel_addr	= PALMAS_SMPS6_VOLTAGE,
  		.ctrl_addr	= PALMAS_SMPS6_CTRL,
  		.tstep_addr	= PALMAS_SMPS6_TSTEP,
32b6d3f60   Laxman Dewangan   regulator: palmas...
84
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS6,
e5ce4208f   Graeme Gregory   regulator: regula...
85
86
87
  	},
  	{
  		.name		= "SMPS7",
504382c99   Laxman Dewangan   regulator: palmas...
88
  		.sname		= "smps7-in",
e5ce4208f   Graeme Gregory   regulator: regula...
89
90
  		.vsel_addr	= PALMAS_SMPS7_VOLTAGE,
  		.ctrl_addr	= PALMAS_SMPS7_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
91
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS7,
e5ce4208f   Graeme Gregory   regulator: regula...
92
93
94
  	},
  	{
  		.name		= "SMPS8",
504382c99   Laxman Dewangan   regulator: palmas...
95
  		.sname		= "smps8-in",
e5ce4208f   Graeme Gregory   regulator: regula...
96
97
98
  		.vsel_addr	= PALMAS_SMPS8_VOLTAGE,
  		.ctrl_addr	= PALMAS_SMPS8_CTRL,
  		.tstep_addr	= PALMAS_SMPS8_TSTEP,
32b6d3f60   Laxman Dewangan   regulator: palmas...
99
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS8,
e5ce4208f   Graeme Gregory   regulator: regula...
100
101
102
  	},
  	{
  		.name		= "SMPS9",
504382c99   Laxman Dewangan   regulator: palmas...
103
  		.sname		= "smps9-in",
e5ce4208f   Graeme Gregory   regulator: regula...
104
105
  		.vsel_addr	= PALMAS_SMPS9_VOLTAGE,
  		.ctrl_addr	= PALMAS_SMPS9_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
106
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS9,
e5ce4208f   Graeme Gregory   regulator: regula...
107
108
  	},
  	{
77409d9bc   Kishon Vijay Abraham I   regulator: palmas...
109
  		.name		= "SMPS10_OUT2",
504382c99   Laxman Dewangan   regulator: palmas...
110
  		.sname		= "smps10-in",
e31089c60   Axel Lin   regulator: palmas...
111
  		.ctrl_addr	= PALMAS_SMPS10_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
112
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS10,
e5ce4208f   Graeme Gregory   regulator: regula...
113
114
  	},
  	{
77409d9bc   Kishon Vijay Abraham I   regulator: palmas...
115
116
117
  		.name		= "SMPS10_OUT1",
  		.sname		= "smps10-out2",
  		.ctrl_addr	= PALMAS_SMPS10_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
118
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SMPS10,
77409d9bc   Kishon Vijay Abraham I   regulator: palmas...
119
120
  	},
  	{
e5ce4208f   Graeme Gregory   regulator: regula...
121
  		.name		= "LDO1",
504382c99   Laxman Dewangan   regulator: palmas...
122
  		.sname		= "ldo1-in",
e5ce4208f   Graeme Gregory   regulator: regula...
123
124
  		.vsel_addr	= PALMAS_LDO1_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDO1_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
125
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDO1,
e5ce4208f   Graeme Gregory   regulator: regula...
126
127
128
  	},
  	{
  		.name		= "LDO2",
504382c99   Laxman Dewangan   regulator: palmas...
129
  		.sname		= "ldo2-in",
e5ce4208f   Graeme Gregory   regulator: regula...
130
131
  		.vsel_addr	= PALMAS_LDO2_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDO2_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
132
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDO2,
e5ce4208f   Graeme Gregory   regulator: regula...
133
134
135
  	},
  	{
  		.name		= "LDO3",
504382c99   Laxman Dewangan   regulator: palmas...
136
  		.sname		= "ldo3-in",
e5ce4208f   Graeme Gregory   regulator: regula...
137
138
  		.vsel_addr	= PALMAS_LDO3_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDO3_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
139
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDO3,
e5ce4208f   Graeme Gregory   regulator: regula...
140
141
142
  	},
  	{
  		.name		= "LDO4",
504382c99   Laxman Dewangan   regulator: palmas...
143
  		.sname		= "ldo4-in",
e5ce4208f   Graeme Gregory   regulator: regula...
144
145
  		.vsel_addr	= PALMAS_LDO4_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDO4_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
146
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDO4,
e5ce4208f   Graeme Gregory   regulator: regula...
147
148
149
  	},
  	{
  		.name		= "LDO5",
504382c99   Laxman Dewangan   regulator: palmas...
150
  		.sname		= "ldo5-in",
e5ce4208f   Graeme Gregory   regulator: regula...
151
152
  		.vsel_addr	= PALMAS_LDO5_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDO5_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
153
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDO5,
e5ce4208f   Graeme Gregory   regulator: regula...
154
155
156
  	},
  	{
  		.name		= "LDO6",
504382c99   Laxman Dewangan   regulator: palmas...
157
  		.sname		= "ldo6-in",
e5ce4208f   Graeme Gregory   regulator: regula...
158
159
  		.vsel_addr	= PALMAS_LDO6_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDO6_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
160
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDO6,
e5ce4208f   Graeme Gregory   regulator: regula...
161
162
163
  	},
  	{
  		.name		= "LDO7",
504382c99   Laxman Dewangan   regulator: palmas...
164
  		.sname		= "ldo7-in",
e5ce4208f   Graeme Gregory   regulator: regula...
165
166
  		.vsel_addr	= PALMAS_LDO7_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDO7_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
167
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDO7,
e5ce4208f   Graeme Gregory   regulator: regula...
168
169
170
  	},
  	{
  		.name		= "LDO8",
504382c99   Laxman Dewangan   regulator: palmas...
171
  		.sname		= "ldo8-in",
e5ce4208f   Graeme Gregory   regulator: regula...
172
173
  		.vsel_addr	= PALMAS_LDO8_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDO8_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
174
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDO8,
e5ce4208f   Graeme Gregory   regulator: regula...
175
176
177
  	},
  	{
  		.name		= "LDO9",
504382c99   Laxman Dewangan   regulator: palmas...
178
  		.sname		= "ldo9-in",
e5ce4208f   Graeme Gregory   regulator: regula...
179
180
  		.vsel_addr	= PALMAS_LDO9_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDO9_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
181
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDO9,
e5ce4208f   Graeme Gregory   regulator: regula...
182
183
184
  	},
  	{
  		.name		= "LDOLN",
504382c99   Laxman Dewangan   regulator: palmas...
185
  		.sname		= "ldoln-in",
e5ce4208f   Graeme Gregory   regulator: regula...
186
187
  		.vsel_addr	= PALMAS_LDOLN_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDOLN_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
188
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDOLN,
e5ce4208f   Graeme Gregory   regulator: regula...
189
190
191
  	},
  	{
  		.name		= "LDOUSB",
504382c99   Laxman Dewangan   regulator: palmas...
192
  		.sname		= "ldousb-in",
e5ce4208f   Graeme Gregory   regulator: regula...
193
194
  		.vsel_addr	= PALMAS_LDOUSB_VOLTAGE,
  		.ctrl_addr	= PALMAS_LDOUSB_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
195
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_LDOUSB,
e5ce4208f   Graeme Gregory   regulator: regula...
196
  	},
aa07f0279   Laxman Dewangan   regulator: palmas...
197
198
199
  	{
  		.name		= "REGEN1",
  		.ctrl_addr	= PALMAS_REGEN1_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
200
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_REGEN1,
aa07f0279   Laxman Dewangan   regulator: palmas...
201
202
203
204
  	},
  	{
  		.name		= "REGEN2",
  		.ctrl_addr	= PALMAS_REGEN2_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
205
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_REGEN2,
aa07f0279   Laxman Dewangan   regulator: palmas...
206
207
208
209
  	},
  	{
  		.name		= "REGEN3",
  		.ctrl_addr	= PALMAS_REGEN3_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
210
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_REGEN3,
aa07f0279   Laxman Dewangan   regulator: palmas...
211
212
213
214
  	},
  	{
  		.name		= "SYSEN1",
  		.ctrl_addr	= PALMAS_SYSEN1_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
215
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SYSEN1,
aa07f0279   Laxman Dewangan   regulator: palmas...
216
217
218
219
  	},
  	{
  		.name		= "SYSEN2",
  		.ctrl_addr	= PALMAS_SYSEN2_CTRL,
32b6d3f60   Laxman Dewangan   regulator: palmas...
220
  		.sleep_id	= PALMAS_EXTERNAL_REQSTR_ID_SYSEN2,
aa07f0279   Laxman Dewangan   regulator: palmas...
221
  	},
e5ce4208f   Graeme Gregory   regulator: regula...
222
  };
e7cf34ef3   Nishanth Menon   regulator: palmas...
223
  static struct palmas_regs_info tps65917_regs_info[] = {
d6f83370e   Keerthy   regulator: palmas...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
  	{
  		.name		= "SMPS1",
  		.sname		= "smps1-in",
  		.vsel_addr	= TPS65917_SMPS1_VOLTAGE,
  		.ctrl_addr	= TPS65917_SMPS1_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_SMPS1,
  	},
  	{
  		.name		= "SMPS2",
  		.sname		= "smps2-in",
  		.vsel_addr	= TPS65917_SMPS2_VOLTAGE,
  		.ctrl_addr	= TPS65917_SMPS2_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_SMPS2,
  	},
  	{
  		.name		= "SMPS3",
  		.sname		= "smps3-in",
  		.vsel_addr	= TPS65917_SMPS3_VOLTAGE,
  		.ctrl_addr	= TPS65917_SMPS3_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_SMPS3,
  	},
  	{
  		.name		= "SMPS4",
  		.sname		= "smps4-in",
  		.vsel_addr	= TPS65917_SMPS4_VOLTAGE,
  		.ctrl_addr	= TPS65917_SMPS4_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_SMPS4,
  	},
  	{
  		.name		= "SMPS5",
  		.sname		= "smps5-in",
  		.vsel_addr	= TPS65917_SMPS5_VOLTAGE,
  		.ctrl_addr	= TPS65917_SMPS5_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_SMPS5,
  	},
  	{
be0353031   Keerthy   regulator: tps659...
260
261
262
263
264
265
266
  		.name		= "SMPS12",
  		.sname		= "smps1-in",
  		.vsel_addr	= TPS65917_SMPS1_VOLTAGE,
  		.ctrl_addr	= TPS65917_SMPS1_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_SMPS12,
  	},
  	{
d6f83370e   Keerthy   regulator: palmas...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
  		.name		= "LDO1",
  		.sname		= "ldo1-in",
  		.vsel_addr	= TPS65917_LDO1_VOLTAGE,
  		.ctrl_addr	= TPS65917_LDO1_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_LDO1,
  	},
  	{
  		.name		= "LDO2",
  		.sname		= "ldo2-in",
  		.vsel_addr	= TPS65917_LDO2_VOLTAGE,
  		.ctrl_addr	= TPS65917_LDO2_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_LDO2,
  	},
  	{
  		.name		= "LDO3",
  		.sname		= "ldo3-in",
  		.vsel_addr	= TPS65917_LDO3_VOLTAGE,
  		.ctrl_addr	= TPS65917_LDO3_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_LDO3,
  	},
  	{
  		.name		= "LDO4",
  		.sname		= "ldo4-in",
  		.vsel_addr	= TPS65917_LDO4_VOLTAGE,
  		.ctrl_addr	= TPS65917_LDO4_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_LDO4,
  	},
  	{
  		.name		= "LDO5",
  		.sname		= "ldo5-in",
  		.vsel_addr	= TPS65917_LDO5_VOLTAGE,
  		.ctrl_addr	= TPS65917_LDO5_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_LDO5,
  	},
  	{
  		.name		= "REGEN1",
  		.ctrl_addr	= TPS65917_REGEN1_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_REGEN1,
  	},
  	{
  		.name		= "REGEN2",
  		.ctrl_addr	= TPS65917_REGEN2_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_REGEN2,
  	},
  	{
  		.name		= "REGEN3",
  		.ctrl_addr	= TPS65917_REGEN3_CTRL,
  		.sleep_id	= TPS65917_EXTERNAL_REQSTR_ID_REGEN3,
  	},
  };
cac9e9162   Keerthy   regulator: palmas...
317
318
319
320
321
322
  #define EXTERNAL_REQUESTOR(_id, _offset, _pos)		\
  	[PALMAS_EXTERNAL_REQSTR_ID_##_id] = {		\
  		.id = PALMAS_EXTERNAL_REQSTR_ID_##_id,	\
  		.reg_offset = _offset,			\
  		.bit_pos = _pos,			\
  	}
4b09e17b6   Nishanth Menon   regulator: palmas...
323
  static struct palmas_sleep_requestor_info palma_sleep_req_info[] = {
cac9e9162   Keerthy   regulator: palmas...
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
  	EXTERNAL_REQUESTOR(REGEN1, 0, 0),
  	EXTERNAL_REQUESTOR(REGEN2, 0, 1),
  	EXTERNAL_REQUESTOR(SYSEN1, 0, 2),
  	EXTERNAL_REQUESTOR(SYSEN2, 0, 3),
  	EXTERNAL_REQUESTOR(CLK32KG, 0, 4),
  	EXTERNAL_REQUESTOR(CLK32KGAUDIO, 0, 5),
  	EXTERNAL_REQUESTOR(REGEN3, 0, 6),
  	EXTERNAL_REQUESTOR(SMPS12, 1, 0),
  	EXTERNAL_REQUESTOR(SMPS3, 1, 1),
  	EXTERNAL_REQUESTOR(SMPS45, 1, 2),
  	EXTERNAL_REQUESTOR(SMPS6, 1, 3),
  	EXTERNAL_REQUESTOR(SMPS7, 1, 4),
  	EXTERNAL_REQUESTOR(SMPS8, 1, 5),
  	EXTERNAL_REQUESTOR(SMPS9, 1, 6),
  	EXTERNAL_REQUESTOR(SMPS10, 1, 7),
  	EXTERNAL_REQUESTOR(LDO1, 2, 0),
  	EXTERNAL_REQUESTOR(LDO2, 2, 1),
  	EXTERNAL_REQUESTOR(LDO3, 2, 2),
  	EXTERNAL_REQUESTOR(LDO4, 2, 3),
  	EXTERNAL_REQUESTOR(LDO5, 2, 4),
  	EXTERNAL_REQUESTOR(LDO6, 2, 5),
  	EXTERNAL_REQUESTOR(LDO7, 2, 6),
  	EXTERNAL_REQUESTOR(LDO8, 2, 7),
  	EXTERNAL_REQUESTOR(LDO9, 3, 0),
  	EXTERNAL_REQUESTOR(LDOLN, 3, 1),
  	EXTERNAL_REQUESTOR(LDOUSB, 3, 2),
  };
d6f83370e   Keerthy   regulator: palmas...
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
  #define EXTERNAL_REQUESTOR_TPS65917(_id, _offset, _pos)		\
  	[TPS65917_EXTERNAL_REQSTR_ID_##_id] = {		\
  		.id = TPS65917_EXTERNAL_REQSTR_ID_##_id,	\
  		.reg_offset = _offset,			\
  		.bit_pos = _pos,			\
  	}
  
  static struct palmas_sleep_requestor_info tps65917_sleep_req_info[] = {
  	EXTERNAL_REQUESTOR_TPS65917(REGEN1, 0, 0),
  	EXTERNAL_REQUESTOR_TPS65917(REGEN2, 0, 1),
  	EXTERNAL_REQUESTOR_TPS65917(REGEN3, 0, 6),
  	EXTERNAL_REQUESTOR_TPS65917(SMPS1, 1, 0),
  	EXTERNAL_REQUESTOR_TPS65917(SMPS2, 1, 1),
  	EXTERNAL_REQUESTOR_TPS65917(SMPS3, 1, 2),
  	EXTERNAL_REQUESTOR_TPS65917(SMPS4, 1, 3),
  	EXTERNAL_REQUESTOR_TPS65917(SMPS5, 1, 4),
be0353031   Keerthy   regulator: tps659...
367
  	EXTERNAL_REQUESTOR_TPS65917(SMPS12, 1, 5),
d6f83370e   Keerthy   regulator: palmas...
368
369
370
371
372
373
  	EXTERNAL_REQUESTOR_TPS65917(LDO1, 2, 0),
  	EXTERNAL_REQUESTOR_TPS65917(LDO2, 2, 1),
  	EXTERNAL_REQUESTOR_TPS65917(LDO3, 2, 2),
  	EXTERNAL_REQUESTOR_TPS65917(LDO4, 2, 3),
  	EXTERNAL_REQUESTOR_TPS65917(LDO5, 2, 4),
  };
ad542a527   Axel Lin   regulator: palmas...
374
  static const unsigned int palmas_smps_ramp_delay[4] = {0, 10000, 5000, 2500};
28d1e8cd6   Laxman Dewangan   regulator: palma:...
375

e5ce4208f   Graeme Gregory   regulator: regula...
376
377
378
379
  #define SMPS_CTRL_MODE_OFF		0x00
  #define SMPS_CTRL_MODE_ON		0x01
  #define SMPS_CTRL_MODE_ECO		0x02
  #define SMPS_CTRL_MODE_PWM		0x03
0f45aa84b   Laxman Dewangan   regulator: palmas...
380
  #define PALMAS_SMPS_NUM_VOLTAGES	122
e5ce4208f   Graeme Gregory   regulator: regula...
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
  #define PALMAS_SMPS10_NUM_VOLTAGES	2
  #define PALMAS_LDO_NUM_VOLTAGES		50
  
  #define SMPS10_VSEL			(1<<3)
  #define SMPS10_BOOST_EN			(1<<2)
  #define SMPS10_BYPASS_EN		(1<<1)
  #define SMPS10_SWITCH_EN		(1<<0)
  
  #define REGULATOR_SLAVE			0
  
  static int palmas_smps_read(struct palmas *palmas, unsigned int reg,
  		unsigned int *dest)
  {
  	unsigned int addr;
  
  	addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
  
  	return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
  }
  
  static int palmas_smps_write(struct palmas *palmas, unsigned int reg,
  		unsigned int value)
  {
  	unsigned int addr;
  
  	addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
  
  	return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
  }
  
  static int palmas_ldo_read(struct palmas *palmas, unsigned int reg,
  		unsigned int *dest)
  {
  	unsigned int addr;
  
  	addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
  
  	return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
  }
  
  static int palmas_ldo_write(struct palmas *palmas, unsigned int reg,
  		unsigned int value)
  {
  	unsigned int addr;
  
  	addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
  
  	return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
  }
e5ce4208f   Graeme Gregory   regulator: regula...
430
431
  static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
  {
cf910b6b7   Nishanth Menon   regulator: palmas...
432
  	int id = rdev_get_id(dev);
966e927bf   Kangjie Lu   drivers/regulator...
433
  	int ret;
e5ce4208f   Graeme Gregory   regulator: regula...
434
  	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
cac9e9162   Keerthy   regulator: palmas...
435
  	struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata;
cf910b6b7   Nishanth Menon   regulator: palmas...
436
  	struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
e5ce4208f   Graeme Gregory   regulator: regula...
437
  	unsigned int reg;
51d3a0c99   Laxman Dewangan   regulator: palmas...
438
  	bool rail_enable = true;
e5ce4208f   Graeme Gregory   regulator: regula...
439

966e927bf   Kangjie Lu   drivers/regulator...
440
441
442
  	ret = palmas_smps_read(pmic->palmas, rinfo->ctrl_addr, &reg);
  	if (ret)
  		return ret;
cac9e9162   Keerthy   regulator: palmas...
443

999f0c7cb   Axel Lin   regulator: palmas...
444
  	reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
e5ce4208f   Graeme Gregory   regulator: regula...
445

51d3a0c99   Laxman Dewangan   regulator: palmas...
446
447
  	if (reg == SMPS_CTRL_MODE_OFF)
  		rail_enable = false;
e5ce4208f   Graeme Gregory   regulator: regula...
448
449
450
451
452
453
454
455
456
457
458
459
460
  	switch (mode) {
  	case REGULATOR_MODE_NORMAL:
  		reg |= SMPS_CTRL_MODE_ON;
  		break;
  	case REGULATOR_MODE_IDLE:
  		reg |= SMPS_CTRL_MODE_ECO;
  		break;
  	case REGULATOR_MODE_FAST:
  		reg |= SMPS_CTRL_MODE_PWM;
  		break;
  	default:
  		return -EINVAL;
  	}
e5ce4208f   Graeme Gregory   regulator: regula...
461

51d3a0c99   Laxman Dewangan   regulator: palmas...
462
463
  	pmic->current_reg_mode[id] = reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
  	if (rail_enable)
cf910b6b7   Nishanth Menon   regulator: palmas...
464
  		palmas_smps_write(pmic->palmas, rinfo->ctrl_addr, reg);
318dbb02b   Nishanth Menon   regulator: palmas...
465
466
467
  
  	/* Switch the enable value to ensure this is used for enable */
  	pmic->desc[id].enable_val = pmic->current_reg_mode[id];
e5ce4208f   Graeme Gregory   regulator: regula...
468
469
470
471
472
473
474
475
  	return 0;
  }
  
  static unsigned int palmas_get_mode_smps(struct regulator_dev *dev)
  {
  	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
  	int id = rdev_get_id(dev);
  	unsigned int reg;
51d3a0c99   Laxman Dewangan   regulator: palmas...
476
  	reg = pmic->current_reg_mode[id] & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
e5ce4208f   Graeme Gregory   regulator: regula...
477
478
479
480
481
482
483
484
485
486
487
488
  
  	switch (reg) {
  	case SMPS_CTRL_MODE_ON:
  		return REGULATOR_MODE_NORMAL;
  	case SMPS_CTRL_MODE_ECO:
  		return REGULATOR_MODE_IDLE;
  	case SMPS_CTRL_MODE_PWM:
  		return REGULATOR_MODE_FAST;
  	}
  
  	return 0;
  }
28d1e8cd6   Laxman Dewangan   regulator: palma:...
489
490
491
  static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev,
  		 int ramp_delay)
  {
cf910b6b7   Nishanth Menon   regulator: palmas...
492
  	int id = rdev_get_id(rdev);
28d1e8cd6   Laxman Dewangan   regulator: palma:...
493
  	struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
cac9e9162   Keerthy   regulator: palmas...
494
  	struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata;
cf910b6b7   Nishanth Menon   regulator: palmas...
495
  	struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
28d1e8cd6   Laxman Dewangan   regulator: palma:...
496
  	unsigned int reg = 0;
28d1e8cd6   Laxman Dewangan   regulator: palma:...
497
  	int ret;
f22c2bae2   Axel Lin   regulator: palmas...
498
499
500
501
502
503
  	/* SMPS3 and SMPS7 do not have tstep_addr setting */
  	switch (id) {
  	case PALMAS_REG_SMPS3:
  	case PALMAS_REG_SMPS7:
  		return 0;
  	}
28d1e8cd6   Laxman Dewangan   regulator: palma:...
504
505
  	if (ramp_delay <= 0)
  		reg = 0;
0ea34b578   Axel Lin   regulator: palmas...
506
  	else if (ramp_delay <= 2500)
28d1e8cd6   Laxman Dewangan   regulator: palma:...
507
  		reg = 3;
0ea34b578   Axel Lin   regulator: palmas...
508
  	else if (ramp_delay <= 5000)
28d1e8cd6   Laxman Dewangan   regulator: palma:...
509
510
511
  		reg = 2;
  	else
  		reg = 1;
cf910b6b7   Nishanth Menon   regulator: palmas...
512
  	ret = palmas_smps_write(pmic->palmas, rinfo->tstep_addr, reg);
28d1e8cd6   Laxman Dewangan   regulator: palma:...
513
514
515
516
517
518
519
520
521
  	if (ret < 0) {
  		dev_err(pmic->palmas->dev, "TSTEP write failed: %d
  ", ret);
  		return ret;
  	}
  
  	pmic->ramp_delay[id] = palmas_smps_ramp_delay[reg];
  	return ret;
  }
0e5a76800   Bhumika Goyal   regulator: palmas...
522
  static const struct regulator_ops palmas_ops_smps = {
dbabd624d   Keerthy   regulator: palmas...
523
524
525
  	.is_enabled		= regulator_is_enabled_regmap,
  	.enable			= regulator_enable_regmap,
  	.disable		= regulator_disable_regmap,
e5ce4208f   Graeme Gregory   regulator: regula...
526
527
  	.set_mode		= palmas_set_mode_smps,
  	.get_mode		= palmas_get_mode_smps,
bdc4baace   Axel Lin   regulator: palmas...
528
529
  	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
dbabd624d   Keerthy   regulator: palmas...
530
531
532
  	.list_voltage		= regulator_list_voltage_linear_range,
  	.map_voltage		= regulator_map_voltage_linear_range,
  	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
28d1e8cd6   Laxman Dewangan   regulator: palma:...
533
  	.set_ramp_delay		= palmas_smps_set_ramp_delay,
e5ce4208f   Graeme Gregory   regulator: regula...
534
  };
0e5a76800   Bhumika Goyal   regulator: palmas...
535
  static const struct regulator_ops palmas_ops_ext_control_smps = {
32b6d3f60   Laxman Dewangan   regulator: palmas...
536
537
538
539
  	.set_mode		= palmas_set_mode_smps,
  	.get_mode		= palmas_get_mode_smps,
  	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
dbabd624d   Keerthy   regulator: palmas...
540
541
542
  	.list_voltage		= regulator_list_voltage_linear_range,
  	.map_voltage		= regulator_map_voltage_linear_range,
  	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
32b6d3f60   Laxman Dewangan   regulator: palmas...
543
544
  	.set_ramp_delay		= palmas_smps_set_ramp_delay,
  };
0e5a76800   Bhumika Goyal   regulator: palmas...
545
  static const struct regulator_ops palmas_ops_smps10 = {
e5ce4208f   Graeme Gregory   regulator: regula...
546
547
548
549
550
  	.is_enabled		= regulator_is_enabled_regmap,
  	.enable			= regulator_enable_regmap,
  	.disable		= regulator_disable_regmap,
  	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
8029a0068   Axel Lin   regulator: palmas...
551
552
  	.list_voltage		= regulator_list_voltage_linear,
  	.map_voltage		= regulator_map_voltage_linear,
77409d9bc   Kishon Vijay Abraham I   regulator: palmas...
553
554
  	.set_bypass		= regulator_set_bypass_regmap,
  	.get_bypass		= regulator_get_bypass_regmap,
e5ce4208f   Graeme Gregory   regulator: regula...
555
  };
0e5a76800   Bhumika Goyal   regulator: palmas...
556
  static const struct regulator_ops tps65917_ops_smps = {
d6f83370e   Keerthy   regulator: palmas...
557
558
559
560
561
562
563
564
565
566
567
  	.is_enabled		= regulator_is_enabled_regmap,
  	.enable			= regulator_enable_regmap,
  	.disable		= regulator_disable_regmap,
  	.set_mode		= palmas_set_mode_smps,
  	.get_mode		= palmas_get_mode_smps,
  	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
  	.list_voltage		= regulator_list_voltage_linear_range,
  	.map_voltage		= regulator_map_voltage_linear_range,
  	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
  };
0e5a76800   Bhumika Goyal   regulator: palmas...
568
  static const struct regulator_ops tps65917_ops_ext_control_smps = {
d6f83370e   Keerthy   regulator: palmas...
569
570
571
572
573
574
575
  	.set_mode		= palmas_set_mode_smps,
  	.get_mode		= palmas_get_mode_smps,
  	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
  	.list_voltage		= regulator_list_voltage_linear_range,
  	.map_voltage		= regulator_map_voltage_linear_range,
  };
e5ce4208f   Graeme Gregory   regulator: regula...
576
577
  static int palmas_is_enabled_ldo(struct regulator_dev *dev)
  {
cf910b6b7   Nishanth Menon   regulator: palmas...
578
  	int id = rdev_get_id(dev);
e5ce4208f   Graeme Gregory   regulator: regula...
579
  	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
cac9e9162   Keerthy   regulator: palmas...
580
  	struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata;
cf910b6b7   Nishanth Menon   regulator: palmas...
581
  	struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
e5ce4208f   Graeme Gregory   regulator: regula...
582
  	unsigned int reg;
cf910b6b7   Nishanth Menon   regulator: palmas...
583
  	palmas_ldo_read(pmic->palmas, rinfo->ctrl_addr, &reg);
e5ce4208f   Graeme Gregory   regulator: regula...
584
585
586
587
588
  
  	reg &= PALMAS_LDO1_CTRL_STATUS;
  
  	return !!(reg);
  }
0e5a76800   Bhumika Goyal   regulator: palmas...
589
  static const struct regulator_ops palmas_ops_ldo = {
e5ce4208f   Graeme Gregory   regulator: regula...
590
591
592
  	.is_enabled		= palmas_is_enabled_ldo,
  	.enable			= regulator_enable_regmap,
  	.disable		= regulator_disable_regmap,
4a247a961   Axel Lin   regulator: palmas...
593
594
  	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
9119ff6af   Axel Lin   regulator: palmas...
595
596
  	.list_voltage		= regulator_list_voltage_linear,
  	.map_voltage		= regulator_map_voltage_linear,
e5ce4208f   Graeme Gregory   regulator: regula...
597
  };
0e5a76800   Bhumika Goyal   regulator: palmas...
598
  static const struct regulator_ops palmas_ops_ldo9 = {
b554e1450   Keerthy   regulator: tps659...
599
600
601
602
603
604
605
606
607
608
  	.is_enabled		= palmas_is_enabled_ldo,
  	.enable			= regulator_enable_regmap,
  	.disable		= regulator_disable_regmap,
  	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
  	.list_voltage		= regulator_list_voltage_linear,
  	.map_voltage		= regulator_map_voltage_linear,
  	.set_bypass		= regulator_set_bypass_regmap,
  	.get_bypass		= regulator_get_bypass_regmap,
  };
0e5a76800   Bhumika Goyal   regulator: palmas...
609
  static const struct regulator_ops palmas_ops_ext_control_ldo = {
32b6d3f60   Laxman Dewangan   regulator: palmas...
610
611
612
613
614
  	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
  	.list_voltage		= regulator_list_voltage_linear,
  	.map_voltage		= regulator_map_voltage_linear,
  };
0e5a76800   Bhumika Goyal   regulator: palmas...
615
  static const struct regulator_ops palmas_ops_extreg = {
aa07f0279   Laxman Dewangan   regulator: palmas...
616
617
618
619
  	.is_enabled		= regulator_is_enabled_regmap,
  	.enable			= regulator_enable_regmap,
  	.disable		= regulator_disable_regmap,
  };
0e5a76800   Bhumika Goyal   regulator: palmas...
620
  static const struct regulator_ops palmas_ops_ext_control_extreg = {
32b6d3f60   Laxman Dewangan   regulator: palmas...
621
  };
0e5a76800   Bhumika Goyal   regulator: palmas...
622
  static const struct regulator_ops tps65917_ops_ldo = {
d6f83370e   Keerthy   regulator: palmas...
623
624
625
626
627
628
629
630
631
  	.is_enabled		= palmas_is_enabled_ldo,
  	.enable			= regulator_enable_regmap,
  	.disable		= regulator_disable_regmap,
  	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
  	.list_voltage		= regulator_list_voltage_linear,
  	.map_voltage		= regulator_map_voltage_linear,
  	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
  };
0e5a76800   Bhumika Goyal   regulator: palmas...
632
  static const struct regulator_ops tps65917_ops_ldo_1_2 = {
b554e1450   Keerthy   regulator: tps659...
633
634
635
636
637
638
639
640
641
642
643
  	.is_enabled		= palmas_is_enabled_ldo,
  	.enable			= regulator_enable_regmap,
  	.disable		= regulator_disable_regmap,
  	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
  	.list_voltage		= regulator_list_voltage_linear,
  	.map_voltage		= regulator_map_voltage_linear,
  	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
  	.set_bypass		= regulator_set_bypass_regmap,
  	.get_bypass		= regulator_get_bypass_regmap,
  };
32b6d3f60   Laxman Dewangan   regulator: palmas...
644
645
646
  static int palmas_regulator_config_external(struct palmas *palmas, int id,
  		struct palmas_reg_init *reg_init)
  {
cf910b6b7   Nishanth Menon   regulator: palmas...
647
648
  	struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata;
  	struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
32b6d3f60   Laxman Dewangan   regulator: palmas...
649
  	int ret;
cf910b6b7   Nishanth Menon   regulator: palmas...
650
651
  	ret = palmas_ext_control_req_config(palmas, rinfo->sleep_id,
  					    reg_init->roof_floor, true);
32b6d3f60   Laxman Dewangan   regulator: palmas...
652
653
654
655
656
657
658
  	if (ret < 0)
  		dev_err(palmas->dev,
  			"Ext control config for regulator %d failed %d
  ",
  			id, ret);
  	return ret;
  }
e5ce4208f   Graeme Gregory   regulator: regula...
659
660
661
662
663
664
665
666
667
668
  /*
   * setup the hardware based sleep configuration of the SMPS/LDO regulators
   * from the platform data. This is different to the software based control
   * supported by the regulator framework as it is controlled by toggling
   * pins on the PMIC such as PREQ, SYSEN, ...
   */
  static int palmas_smps_init(struct palmas *palmas, int id,
  		struct palmas_reg_init *reg_init)
  {
  	unsigned int reg;
e5ce4208f   Graeme Gregory   regulator: regula...
669
  	int ret;
cac9e9162   Keerthy   regulator: palmas...
670
  	struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata;
cf910b6b7   Nishanth Menon   regulator: palmas...
671
672
  	struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
  	unsigned int addr = rinfo->ctrl_addr;
e5ce4208f   Graeme Gregory   regulator: regula...
673
674
675
676
  
  	ret = palmas_smps_read(palmas, addr, &reg);
  	if (ret)
  		return ret;
fedd89b1a   Axel Lin   regulator: palmas...
677
  	switch (id) {
77409d9bc   Kishon Vijay Abraham I   regulator: palmas...
678
679
  	case PALMAS_REG_SMPS10_OUT1:
  	case PALMAS_REG_SMPS10_OUT2:
30590d048   Laxman Dewangan   regulator: palmas...
680
681
  		reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
  		if (reg_init->mode_sleep)
fedd89b1a   Axel Lin   regulator: palmas...
682
683
  			reg |= reg_init->mode_sleep <<
  					PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
fedd89b1a   Axel Lin   regulator: palmas...
684
685
  		break;
  	default:
e5ce4208f   Graeme Gregory   regulator: regula...
686
687
  		if (reg_init->warm_reset)
  			reg |= PALMAS_SMPS12_CTRL_WR_S;
30590d048   Laxman Dewangan   regulator: palmas...
688
689
  		else
  			reg &= ~PALMAS_SMPS12_CTRL_WR_S;
e5ce4208f   Graeme Gregory   regulator: regula...
690
691
692
  
  		if (reg_init->roof_floor)
  			reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN;
30590d048   Laxman Dewangan   regulator: palmas...
693
694
  		else
  			reg &= ~PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN;
e5ce4208f   Graeme Gregory   regulator: regula...
695

30590d048   Laxman Dewangan   regulator: palmas...
696
697
  		reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK;
  		if (reg_init->mode_sleep)
e5ce4208f   Graeme Gregory   regulator: regula...
698
699
  			reg |= reg_init->mode_sleep <<
  					PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT;
e5ce4208f   Graeme Gregory   regulator: regula...
700
  	}
fedd89b1a   Axel Lin   regulator: palmas...
701

e5ce4208f   Graeme Gregory   regulator: regula...
702
703
704
  	ret = palmas_smps_write(palmas, addr, reg);
  	if (ret)
  		return ret;
cf910b6b7   Nishanth Menon   regulator: palmas...
705
  	if (rinfo->vsel_addr && reg_init->vsel) {
e5ce4208f   Graeme Gregory   regulator: regula...
706
707
  
  		reg = reg_init->vsel;
cf910b6b7   Nishanth Menon   regulator: palmas...
708
  		ret = palmas_smps_write(palmas, rinfo->vsel_addr, reg);
e5ce4208f   Graeme Gregory   regulator: regula...
709
710
711
  		if (ret)
  			return ret;
  	}
32b6d3f60   Laxman Dewangan   regulator: palmas...
712
713
714
  	if (reg_init->roof_floor && (id != PALMAS_REG_SMPS10_OUT1) &&
  			(id != PALMAS_REG_SMPS10_OUT2)) {
  		/* Enable externally controlled regulator */
32b6d3f60   Laxman Dewangan   regulator: palmas...
715
716
717
  		ret = palmas_smps_read(palmas, addr, &reg);
  		if (ret < 0)
  			return ret;
e5ce4208f   Graeme Gregory   regulator: regula...
718

32b6d3f60   Laxman Dewangan   regulator: palmas...
719
720
721
722
723
724
725
726
  		if (!(reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK)) {
  			reg |= SMPS_CTRL_MODE_ON;
  			ret = palmas_smps_write(palmas, addr, reg);
  			if (ret < 0)
  				return ret;
  		}
  		return palmas_regulator_config_external(palmas, id, reg_init);
  	}
e5ce4208f   Graeme Gregory   regulator: regula...
727
728
729
730
731
732
733
734
735
  	return 0;
  }
  
  static int palmas_ldo_init(struct palmas *palmas, int id,
  		struct palmas_reg_init *reg_init)
  {
  	unsigned int reg;
  	unsigned int addr;
  	int ret;
cac9e9162   Keerthy   regulator: palmas...
736
  	struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata;
cf910b6b7   Nishanth Menon   regulator: palmas...
737
  	struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
cac9e9162   Keerthy   regulator: palmas...
738

cf910b6b7   Nishanth Menon   regulator: palmas...
739
  	addr = rinfo->ctrl_addr;
e5ce4208f   Graeme Gregory   regulator: regula...
740

2735daeb1   Axel Lin   regulator: palmas...
741
  	ret = palmas_ldo_read(palmas, addr, &reg);
e5ce4208f   Graeme Gregory   regulator: regula...
742
743
744
745
746
  	if (ret)
  		return ret;
  
  	if (reg_init->warm_reset)
  		reg |= PALMAS_LDO1_CTRL_WR_S;
30590d048   Laxman Dewangan   regulator: palmas...
747
748
  	else
  		reg &= ~PALMAS_LDO1_CTRL_WR_S;
e5ce4208f   Graeme Gregory   regulator: regula...
749
750
751
  
  	if (reg_init->mode_sleep)
  		reg |= PALMAS_LDO1_CTRL_MODE_SLEEP;
30590d048   Laxman Dewangan   regulator: palmas...
752
753
  	else
  		reg &= ~PALMAS_LDO1_CTRL_MODE_SLEEP;
e5ce4208f   Graeme Gregory   regulator: regula...
754

2735daeb1   Axel Lin   regulator: palmas...
755
  	ret = palmas_ldo_write(palmas, addr, reg);
e5ce4208f   Graeme Gregory   regulator: regula...
756
757
  	if (ret)
  		return ret;
32b6d3f60   Laxman Dewangan   regulator: palmas...
758
759
  	if (reg_init->roof_floor) {
  		/* Enable externally controlled regulator */
32b6d3f60   Laxman Dewangan   regulator: palmas...
760
761
762
763
764
765
766
767
768
769
770
771
  		ret = palmas_update_bits(palmas, PALMAS_LDO_BASE,
  				addr, PALMAS_LDO1_CTRL_MODE_ACTIVE,
  				PALMAS_LDO1_CTRL_MODE_ACTIVE);
  		if (ret < 0) {
  			dev_err(palmas->dev,
  				"LDO Register 0x%02x update failed %d
  ",
  				addr, ret);
  			return ret;
  		}
  		return palmas_regulator_config_external(palmas, id, reg_init);
  	}
e5ce4208f   Graeme Gregory   regulator: regula...
772
773
  	return 0;
  }
aa07f0279   Laxman Dewangan   regulator: palmas...
774
775
776
777
778
779
  static int palmas_extreg_init(struct palmas *palmas, int id,
  		struct palmas_reg_init *reg_init)
  {
  	unsigned int addr;
  	int ret;
  	unsigned int val = 0;
cac9e9162   Keerthy   regulator: palmas...
780
  	struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata;
cf910b6b7   Nishanth Menon   regulator: palmas...
781
  	struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
cac9e9162   Keerthy   regulator: palmas...
782

cf910b6b7   Nishanth Menon   regulator: palmas...
783
  	addr = rinfo->ctrl_addr;
aa07f0279   Laxman Dewangan   regulator: palmas...
784
785
786
787
788
789
790
791
792
793
794
795
  
  	if (reg_init->mode_sleep)
  		val = PALMAS_REGEN1_CTRL_MODE_SLEEP;
  
  	ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE,
  			addr, PALMAS_REGEN1_CTRL_MODE_SLEEP, val);
  	if (ret < 0) {
  		dev_err(palmas->dev, "Resource reg 0x%02x update failed %d
  ",
  			addr, ret);
  		return ret;
  	}
32b6d3f60   Laxman Dewangan   regulator: palmas...
796
797
798
  
  	if (reg_init->roof_floor) {
  		/* Enable externally controlled regulator */
32b6d3f60   Laxman Dewangan   regulator: palmas...
799
800
801
802
803
804
805
806
807
808
809
810
  		ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE,
  				addr, PALMAS_REGEN1_CTRL_MODE_ACTIVE,
  				PALMAS_REGEN1_CTRL_MODE_ACTIVE);
  		if (ret < 0) {
  			dev_err(palmas->dev,
  				"Resource Register 0x%02x update failed %d
  ",
  				addr, ret);
  			return ret;
  		}
  		return palmas_regulator_config_external(palmas, id, reg_init);
  	}
aa07f0279   Laxman Dewangan   regulator: palmas...
811
812
  	return 0;
  }
17c11a760   Laxman Dewangan   regulator: palmas...
813
814
815
816
817
  static void palmas_enable_ldo8_track(struct palmas *palmas)
  {
  	unsigned int reg;
  	unsigned int addr;
  	int ret;
cac9e9162   Keerthy   regulator: palmas...
818
  	struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata;
cf910b6b7   Nishanth Menon   regulator: palmas...
819
  	struct palmas_regs_info *rinfo;
cac9e9162   Keerthy   regulator: palmas...
820

cf910b6b7   Nishanth Menon   regulator: palmas...
821
822
  	rinfo = &ddata->palmas_regs_info[PALMAS_REG_LDO8];
  	addr = rinfo->ctrl_addr;
17c11a760   Laxman Dewangan   regulator: palmas...
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
  
  	ret = palmas_ldo_read(palmas, addr, &reg);
  	if (ret) {
  		dev_err(palmas->dev, "Error in reading ldo8 control reg
  ");
  		return;
  	}
  
  	reg |= PALMAS_LDO8_CTRL_LDO_TRACKING_EN;
  	ret = palmas_ldo_write(palmas, addr, reg);
  	if (ret < 0) {
  		dev_err(palmas->dev, "Error in enabling tracking mode
  ");
  		return;
  	}
  	/*
  	 * When SMPS45 is set to off and LDO8 tracking is enabled, the LDO8
  	 * output is defined by the LDO8_VOLTAGE.VSEL register divided by two,
  	 * and can be set from 0.45 to 1.65 V.
  	 */
cf910b6b7   Nishanth Menon   regulator: palmas...
843
  	addr = rinfo->vsel_addr;
17c11a760   Laxman Dewangan   regulator: palmas...
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
  	ret = palmas_ldo_read(palmas, addr, &reg);
  	if (ret) {
  		dev_err(palmas->dev, "Error in reading ldo8 voltage reg
  ");
  		return;
  	}
  
  	reg = (reg << 1) & PALMAS_LDO8_VOLTAGE_VSEL_MASK;
  	ret = palmas_ldo_write(palmas, addr, reg);
  	if (ret < 0)
  		dev_err(palmas->dev, "Error in setting ldo8 voltage reg
  ");
  
  	return;
  }
cac9e9162   Keerthy   regulator: palmas...
859
860
861
862
863
  static int palmas_ldo_registration(struct palmas_pmic *pmic,
  				   struct palmas_pmic_driver_data *ddata,
  				   struct palmas_pmic_platform_data *pdata,
  				   const char *pdev_name,
  				   struct regulator_config config)
a361cd9f2   Graeme Gregory   regulator: palmas...
864
  {
cac9e9162   Keerthy   regulator: palmas...
865
866
867
  	int id, ret;
  	struct regulator_dev *rdev;
  	struct palmas_reg_init *reg_init;
cf910b6b7   Nishanth Menon   regulator: palmas...
868
  	struct palmas_regs_info *rinfo;
429222d00   Nishanth Menon   regulator: palmas...
869
  	struct regulator_desc *desc;
a361cd9f2   Graeme Gregory   regulator: palmas...
870

cac9e9162   Keerthy   regulator: palmas...
871
872
873
874
875
  	for (id = ddata->ldo_begin; id < ddata->max_reg; id++) {
  		if (pdata && pdata->reg_init[id])
  			reg_init = pdata->reg_init[id];
  		else
  			reg_init = NULL;
a361cd9f2   Graeme Gregory   regulator: palmas...
876

cf910b6b7   Nishanth Menon   regulator: palmas...
877
  		rinfo = &ddata->palmas_regs_info[id];
cac9e9162   Keerthy   regulator: palmas...
878
879
880
  		/* Miss out regulators which are not available due
  		 * to alternate functions.
  		 */
a361cd9f2   Graeme Gregory   regulator: palmas...
881

cac9e9162   Keerthy   regulator: palmas...
882
  		/* Register the regulators */
429222d00   Nishanth Menon   regulator: palmas...
883
884
885
886
887
  		desc = &pmic->desc[id];
  		desc->name = rinfo->name;
  		desc->id = id;
  		desc->type = REGULATOR_VOLTAGE;
  		desc->owner = THIS_MODULE;
a361cd9f2   Graeme Gregory   regulator: palmas...
888

cac9e9162   Keerthy   regulator: palmas...
889
  		if (id < PALMAS_REG_REGEN1) {
429222d00   Nishanth Menon   regulator: palmas...
890
  			desc->n_voltages = PALMAS_LDO_NUM_VOLTAGES;
cac9e9162   Keerthy   regulator: palmas...
891
  			if (reg_init && reg_init->roof_floor)
429222d00   Nishanth Menon   regulator: palmas...
892
  				desc->ops = &palmas_ops_ext_control_ldo;
cac9e9162   Keerthy   regulator: palmas...
893
  			else
429222d00   Nishanth Menon   regulator: palmas...
894
895
896
897
898
899
900
901
902
903
904
  				desc->ops = &palmas_ops_ldo;
  			desc->min_uV = 900000;
  			desc->uV_step = 50000;
  			desc->linear_min_sel = 1;
  			desc->enable_time = 500;
  			desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
  							    rinfo->vsel_addr);
  			desc->vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK;
  			desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
  							      rinfo->ctrl_addr);
  			desc->enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE;
a361cd9f2   Graeme Gregory   regulator: palmas...
905

cac9e9162   Keerthy   regulator: palmas...
906
907
908
909
  			/* Check if LDO8 is in tracking mode or not */
  			if (pdata && (id == PALMAS_REG_LDO8) &&
  			    pdata->enable_ldo8_tracking) {
  				palmas_enable_ldo8_track(pmic->palmas);
429222d00   Nishanth Menon   regulator: palmas...
910
911
  				desc->min_uV = 450000;
  				desc->uV_step = 25000;
cac9e9162   Keerthy   regulator: palmas...
912
  			}
a361cd9f2   Graeme Gregory   regulator: palmas...
913

cac9e9162   Keerthy   regulator: palmas...
914
915
916
  			/* LOD6 in vibrator mode will have enable time 2000us */
  			if (pdata && pdata->ldo6_vibrator &&
  			    (id == PALMAS_REG_LDO6))
429222d00   Nishanth Menon   regulator: palmas...
917
  				desc->enable_time = 2000;
b554e1450   Keerthy   regulator: tps659...
918
919
920
921
  
  			if (id == PALMAS_REG_LDO9) {
  				desc->ops = &palmas_ops_ldo9;
  				desc->bypass_reg = desc->enable_reg;
e0341f173   Nishanth Menon   regulator: tps659...
922
923
  				desc->bypass_val_on =
  						PALMAS_LDO9_CTRL_LDO_BYPASS_EN;
b554e1450   Keerthy   regulator: tps659...
924
925
926
  				desc->bypass_mask =
  						PALMAS_LDO9_CTRL_LDO_BYPASS_EN;
  			}
cac9e9162   Keerthy   regulator: palmas...
927
  		} else {
e999c7289   Keerthy   regulator: palmas...
928
929
  			if (!ddata->has_regen3 && id == PALMAS_REG_REGEN3)
  				continue;
429222d00   Nishanth Menon   regulator: palmas...
930
  			desc->n_voltages = 1;
cac9e9162   Keerthy   regulator: palmas...
931
  			if (reg_init && reg_init->roof_floor)
429222d00   Nishanth Menon   regulator: palmas...
932
  				desc->ops = &palmas_ops_ext_control_extreg;
cac9e9162   Keerthy   regulator: palmas...
933
  			else
429222d00   Nishanth Menon   regulator: palmas...
934
935
  				desc->ops = &palmas_ops_extreg;
  			desc->enable_reg =
cac9e9162   Keerthy   regulator: palmas...
936
  					PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE,
cf910b6b7   Nishanth Menon   regulator: palmas...
937
  							   rinfo->ctrl_addr);
429222d00   Nishanth Menon   regulator: palmas...
938
  			desc->enable_mask = PALMAS_REGEN1_CTRL_MODE_ACTIVE;
cac9e9162   Keerthy   regulator: palmas...
939
  		}
a361cd9f2   Graeme Gregory   regulator: palmas...
940

cac9e9162   Keerthy   regulator: palmas...
941
942
943
944
  		if (pdata)
  			config.init_data = pdata->reg_data[id];
  		else
  			config.init_data = NULL;
32b6d3f60   Laxman Dewangan   regulator: palmas...
945

429222d00   Nishanth Menon   regulator: palmas...
946
  		desc->supply_name = rinfo->sname;
cac9e9162   Keerthy   regulator: palmas...
947
  		config.of_node = ddata->palmas_matches[id].of_node;
a361cd9f2   Graeme Gregory   regulator: palmas...
948

429222d00   Nishanth Menon   regulator: palmas...
949
  		rdev = devm_regulator_register(pmic->dev, desc, &config);
cac9e9162   Keerthy   regulator: palmas...
950
951
952
953
954
955
956
  		if (IS_ERR(rdev)) {
  			dev_err(pmic->dev,
  				"failed to register %s regulator
  ",
  				pdev_name);
  			return PTR_ERR(rdev);
  		}
a361cd9f2   Graeme Gregory   regulator: palmas...
957

cac9e9162   Keerthy   regulator: palmas...
958
959
960
961
962
963
964
965
966
967
968
969
970
971
  		/* Initialise sleep/init values from platform data */
  		if (pdata) {
  			reg_init = pdata->reg_init[id];
  			if (reg_init) {
  				if (id <= ddata->ldo_end)
  					ret = palmas_ldo_init(pmic->palmas, id,
  							      reg_init);
  				else
  					ret = palmas_extreg_init(pmic->palmas,
  								 id, reg_init);
  				if (ret)
  					return ret;
  			}
  		}
a361cd9f2   Graeme Gregory   regulator: palmas...
972
  	}
cac9e9162   Keerthy   regulator: palmas...
973
  	return 0;
a361cd9f2   Graeme Gregory   regulator: palmas...
974
  }
d6f83370e   Keerthy   regulator: palmas...
975
976
977
978
979
980
981
982
983
  static int tps65917_ldo_registration(struct palmas_pmic *pmic,
  				     struct palmas_pmic_driver_data *ddata,
  				     struct palmas_pmic_platform_data *pdata,
  				     const char *pdev_name,
  				     struct regulator_config config)
  {
  	int id, ret;
  	struct regulator_dev *rdev;
  	struct palmas_reg_init *reg_init;
cf910b6b7   Nishanth Menon   regulator: palmas...
984
  	struct palmas_regs_info *rinfo;
429222d00   Nishanth Menon   regulator: palmas...
985
  	struct regulator_desc *desc;
d6f83370e   Keerthy   regulator: palmas...
986
987
988
989
990
991
992
993
994
995
  
  	for (id = ddata->ldo_begin; id < ddata->max_reg; id++) {
  		if (pdata && pdata->reg_init[id])
  			reg_init = pdata->reg_init[id];
  		else
  			reg_init = NULL;
  
  		/* Miss out regulators which are not available due
  		 * to alternate functions.
  		 */
cf910b6b7   Nishanth Menon   regulator: palmas...
996
  		rinfo = &ddata->palmas_regs_info[id];
d6f83370e   Keerthy   regulator: palmas...
997
998
  
  		/* Register the regulators */
429222d00   Nishanth Menon   regulator: palmas...
999
1000
1001
1002
1003
  		desc = &pmic->desc[id];
  		desc->name = rinfo->name;
  		desc->id = id;
  		desc->type = REGULATOR_VOLTAGE;
  		desc->owner = THIS_MODULE;
d6f83370e   Keerthy   regulator: palmas...
1004
1005
  
  		if (id < TPS65917_REG_REGEN1) {
429222d00   Nishanth Menon   regulator: palmas...
1006
  			desc->n_voltages = PALMAS_LDO_NUM_VOLTAGES;
d6f83370e   Keerthy   regulator: palmas...
1007
  			if (reg_init && reg_init->roof_floor)
429222d00   Nishanth Menon   regulator: palmas...
1008
  				desc->ops = &palmas_ops_ext_control_ldo;
d6f83370e   Keerthy   regulator: palmas...
1009
  			else
429222d00   Nishanth Menon   regulator: palmas...
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
  				desc->ops = &tps65917_ops_ldo;
  			desc->min_uV = 900000;
  			desc->uV_step = 50000;
  			desc->linear_min_sel = 1;
  			desc->enable_time = 500;
  			desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
  							    rinfo->vsel_addr);
  			desc->vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK;
  			desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
  							      rinfo->ctrl_addr);
  			desc->enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE;
d6f83370e   Keerthy   regulator: palmas...
1021
1022
1023
1024
  			/*
  			 * To be confirmed. Discussion on going with PMIC Team.
  			 * It is of the order of ~60mV/uS.
  			 */
429222d00   Nishanth Menon   regulator: palmas...
1025
  			desc->ramp_delay = 2500;
b554e1450   Keerthy   regulator: tps659...
1026
1027
1028
1029
  			if (id == TPS65917_REG_LDO1 ||
  			    id == TPS65917_REG_LDO2) {
  				desc->ops = &tps65917_ops_ldo_1_2;
  				desc->bypass_reg = desc->enable_reg;
e0341f173   Nishanth Menon   regulator: tps659...
1030
1031
  				desc->bypass_val_on =
  						TPS65917_LDO1_CTRL_BYPASS_EN;
b554e1450   Keerthy   regulator: tps659...
1032
1033
1034
  				desc->bypass_mask =
  						TPS65917_LDO1_CTRL_BYPASS_EN;
  			}
d6f83370e   Keerthy   regulator: palmas...
1035
  		} else {
429222d00   Nishanth Menon   regulator: palmas...
1036
  			desc->n_voltages = 1;
d6f83370e   Keerthy   regulator: palmas...
1037
  			if (reg_init && reg_init->roof_floor)
429222d00   Nishanth Menon   regulator: palmas...
1038
  				desc->ops = &palmas_ops_ext_control_extreg;
d6f83370e   Keerthy   regulator: palmas...
1039
  			else
429222d00   Nishanth Menon   regulator: palmas...
1040
1041
  				desc->ops = &palmas_ops_extreg;
  			desc->enable_reg =
d6f83370e   Keerthy   regulator: palmas...
1042
  					PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE,
cf910b6b7   Nishanth Menon   regulator: palmas...
1043
  							   rinfo->ctrl_addr);
429222d00   Nishanth Menon   regulator: palmas...
1044
  			desc->enable_mask = PALMAS_REGEN1_CTRL_MODE_ACTIVE;
d6f83370e   Keerthy   regulator: palmas...
1045
1046
1047
1048
1049
1050
  		}
  
  		if (pdata)
  			config.init_data = pdata->reg_data[id];
  		else
  			config.init_data = NULL;
429222d00   Nishanth Menon   regulator: palmas...
1051
  		desc->supply_name = rinfo->sname;
d6f83370e   Keerthy   regulator: palmas...
1052
  		config.of_node = ddata->palmas_matches[id].of_node;
429222d00   Nishanth Menon   regulator: palmas...
1053
  		rdev = devm_regulator_register(pmic->dev, desc, &config);
d6f83370e   Keerthy   regulator: palmas...
1054
1055
1056
1057
1058
1059
1060
  		if (IS_ERR(rdev)) {
  			dev_err(pmic->dev,
  				"failed to register %s regulator
  ",
  				pdev_name);
  			return PTR_ERR(rdev);
  		}
d6f83370e   Keerthy   regulator: palmas...
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
  		/* Initialise sleep/init values from platform data */
  		if (pdata) {
  			reg_init = pdata->reg_init[id];
  			if (reg_init) {
  				if (id < TPS65917_REG_REGEN1)
  					ret = palmas_ldo_init(pmic->palmas,
  							      id, reg_init);
  				else
  					ret = palmas_extreg_init(pmic->palmas,
  								 id, reg_init);
  				if (ret)
  					return ret;
  			}
  		}
  	}
  
  	return 0;
  }
cac9e9162   Keerthy   regulator: palmas...
1079
1080
1081
1082
1083
  static int palmas_smps_registration(struct palmas_pmic *pmic,
  				    struct palmas_pmic_driver_data *ddata,
  				    struct palmas_pmic_platform_data *pdata,
  				    const char *pdev_name,
  				    struct regulator_config config)
e5ce4208f   Graeme Gregory   regulator: regula...
1084
  {
cac9e9162   Keerthy   regulator: palmas...
1085
1086
  	int id, ret;
  	unsigned int addr, reg;
e5ce4208f   Graeme Gregory   regulator: regula...
1087
  	struct regulator_dev *rdev;
e5ce4208f   Graeme Gregory   regulator: regula...
1088
  	struct palmas_reg_init *reg_init;
cf910b6b7   Nishanth Menon   regulator: palmas...
1089
  	struct palmas_regs_info *rinfo;
429222d00   Nishanth Menon   regulator: palmas...
1090
  	struct regulator_desc *desc;
e5ce4208f   Graeme Gregory   regulator: regula...
1091

cac9e9162   Keerthy   regulator: palmas...
1092
  	for (id = ddata->smps_start; id <= ddata->smps_end; id++) {
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1093
  		bool ramp_delay_support = false;
e5ce4208f   Graeme Gregory   regulator: regula...
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
  
  		/*
  		 * Miss out regulators which are not available due
  		 * to slaving configurations.
  		 */
  		switch (id) {
  		case PALMAS_REG_SMPS12:
  		case PALMAS_REG_SMPS3:
  			if (pmic->smps123)
  				continue;
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1104
1105
  			if (id == PALMAS_REG_SMPS12)
  				ramp_delay_support = true;
e5ce4208f   Graeme Gregory   regulator: regula...
1106
1107
1108
1109
  			break;
  		case PALMAS_REG_SMPS123:
  			if (!pmic->smps123)
  				continue;
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1110
  			ramp_delay_support = true;
e5ce4208f   Graeme Gregory   regulator: regula...
1111
1112
1113
1114
1115
  			break;
  		case PALMAS_REG_SMPS45:
  		case PALMAS_REG_SMPS7:
  			if (pmic->smps457)
  				continue;
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1116
1117
  			if (id == PALMAS_REG_SMPS45)
  				ramp_delay_support = true;
e5ce4208f   Graeme Gregory   regulator: regula...
1118
1119
1120
1121
  			break;
  		case PALMAS_REG_SMPS457:
  			if (!pmic->smps457)
  				continue;
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1122
1123
  			ramp_delay_support = true;
  			break;
77409d9bc   Kishon Vijay Abraham I   regulator: palmas...
1124
1125
  		case PALMAS_REG_SMPS10_OUT1:
  		case PALMAS_REG_SMPS10_OUT2:
cac9e9162   Keerthy   regulator: palmas...
1126
  			if (!PALMAS_PMIC_HAS(pmic->palmas, SMPS10_BOOST))
1ffb0be3a   J Keerthy   mfd: palmas: Add ...
1127
  				continue;
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1128
  		}
cf910b6b7   Nishanth Menon   regulator: palmas...
1129
  		rinfo = &ddata->palmas_regs_info[id];
429222d00   Nishanth Menon   regulator: palmas...
1130
  		desc = &pmic->desc[id];
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1131

3f4d63640   Sachin Kamat   regulator: palmas...
1132
  		if ((id == PALMAS_REG_SMPS6) || (id == PALMAS_REG_SMPS8))
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1133
1134
1135
  			ramp_delay_support = true;
  
  		if (ramp_delay_support) {
cf910b6b7   Nishanth Menon   regulator: palmas...
1136
  			addr = rinfo->tstep_addr;
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1137
1138
  			ret = palmas_smps_read(pmic->palmas, addr, &reg);
  			if (ret < 0) {
cac9e9162   Keerthy   regulator: palmas...
1139
  				dev_err(pmic->dev,
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1140
1141
  					"reading TSTEP reg failed: %d
  ", ret);
51c86b3eb   Sachin Kamat   regulator: palmas...
1142
  				return ret;
28d1e8cd6   Laxman Dewangan   regulator: palma:...
1143
  			}
429222d00   Nishanth Menon   regulator: palmas...
1144
1145
  			desc->ramp_delay = palmas_smps_ramp_delay[reg & 0x3];
  			pmic->ramp_delay[id] = desc->ramp_delay;
e5ce4208f   Graeme Gregory   regulator: regula...
1146
  		}
bdc4baace   Axel Lin   regulator: palmas...
1147
1148
1149
  		/* Initialise sleep/init values from platform data */
  		if (pdata && pdata->reg_init[id]) {
  			reg_init = pdata->reg_init[id];
cac9e9162   Keerthy   regulator: palmas...
1150
  			ret = palmas_smps_init(pmic->palmas, id, reg_init);
bdc4baace   Axel Lin   regulator: palmas...
1151
  			if (ret)
51c86b3eb   Sachin Kamat   regulator: palmas...
1152
  				return ret;
32b6d3f60   Laxman Dewangan   regulator: palmas...
1153
1154
  		} else {
  			reg_init = NULL;
bdc4baace   Axel Lin   regulator: palmas...
1155
  		}
e5ce4208f   Graeme Gregory   regulator: regula...
1156
  		/* Register the regulators */
429222d00   Nishanth Menon   regulator: palmas...
1157
1158
  		desc->name = rinfo->name;
  		desc->id = id;
e5ce4208f   Graeme Gregory   regulator: regula...
1159

fedd89b1a   Axel Lin   regulator: palmas...
1160
  		switch (id) {
77409d9bc   Kishon Vijay Abraham I   regulator: palmas...
1161
1162
  		case PALMAS_REG_SMPS10_OUT1:
  		case PALMAS_REG_SMPS10_OUT2:
429222d00   Nishanth Menon   regulator: palmas...
1163
1164
1165
1166
1167
1168
1169
  			desc->n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
  			desc->ops = &palmas_ops_smps10;
  			desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
  							    PALMAS_SMPS10_CTRL);
  			desc->vsel_mask = SMPS10_VSEL;
  			desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
  							    PALMAS_SMPS10_CTRL);
77409d9bc   Kishon Vijay Abraham I   regulator: palmas...
1170
  			if (id == PALMAS_REG_SMPS10_OUT1)
429222d00   Nishanth Menon   regulator: palmas...
1171
  				desc->enable_mask = SMPS10_SWITCH_EN;
77409d9bc   Kishon Vijay Abraham I   regulator: palmas...
1172
  			else
429222d00   Nishanth Menon   regulator: palmas...
1173
1174
1175
  				desc->enable_mask = SMPS10_BOOST_EN;
  			desc->bypass_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
  							    PALMAS_SMPS10_CTRL);
e0341f173   Nishanth Menon   regulator: tps659...
1176
  			desc->bypass_val_on = SMPS10_BYPASS_EN;
429222d00   Nishanth Menon   regulator: palmas...
1177
1178
1179
  			desc->bypass_mask = SMPS10_BYPASS_EN;
  			desc->min_uV = 3750000;
  			desc->uV_step = 1250000;
fedd89b1a   Axel Lin   regulator: palmas...
1180
1181
  			break;
  		default:
bdc4baace   Axel Lin   regulator: palmas...
1182
1183
1184
  			/*
  			 * Read and store the RANGE bit for later use
  			 * This must be done before regulator is probed,
51d3a0c99   Laxman Dewangan   regulator: palmas...
1185
1186
  			 * otherwise we error in probe with unsupportable
  			 * ranges. Read the current smps mode for later use.
bdc4baace   Axel Lin   regulator: palmas...
1187
  			 */
cf910b6b7   Nishanth Menon   regulator: palmas...
1188
  			addr = rinfo->vsel_addr;
429222d00   Nishanth Menon   regulator: palmas...
1189
  			desc->n_linear_ranges = 3;
e5ce4208f   Graeme Gregory   regulator: regula...
1190
1191
1192
  
  			ret = palmas_smps_read(pmic->palmas, addr, &reg);
  			if (ret)
51c86b3eb   Sachin Kamat   regulator: palmas...
1193
  				return ret;
e5ce4208f   Graeme Gregory   regulator: regula...
1194
1195
  			if (reg & PALMAS_SMPS12_VOLTAGE_RANGE)
  				pmic->range[id] = 1;
dbabd624d   Keerthy   regulator: palmas...
1196
  			if (pmic->range[id])
429222d00   Nishanth Menon   regulator: palmas...
1197
  				desc->linear_ranges = smps_high_ranges;
dbabd624d   Keerthy   regulator: palmas...
1198
  			else
429222d00   Nishanth Menon   regulator: palmas...
1199
  				desc->linear_ranges = smps_low_ranges;
bdc4baace   Axel Lin   regulator: palmas...
1200

32b6d3f60   Laxman Dewangan   regulator: palmas...
1201
  			if (reg_init && reg_init->roof_floor)
429222d00   Nishanth Menon   regulator: palmas...
1202
  				desc->ops = &palmas_ops_ext_control_smps;
32b6d3f60   Laxman Dewangan   regulator: palmas...
1203
  			else
429222d00   Nishanth Menon   regulator: palmas...
1204
1205
1206
1207
1208
  				desc->ops = &palmas_ops_smps;
  			desc->n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
  			desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
  							    rinfo->vsel_addr);
  			desc->vsel_mask = PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
51d3a0c99   Laxman Dewangan   regulator: palmas...
1209
1210
  
  			/* Read the smps mode for later use. */
cf910b6b7   Nishanth Menon   regulator: palmas...
1211
  			addr = rinfo->ctrl_addr;
51d3a0c99   Laxman Dewangan   regulator: palmas...
1212
1213
  			ret = palmas_smps_read(pmic->palmas, addr, &reg);
  			if (ret)
51c86b3eb   Sachin Kamat   regulator: palmas...
1214
  				return ret;
51d3a0c99   Laxman Dewangan   regulator: palmas...
1215
1216
  			pmic->current_reg_mode[id] = reg &
  					PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
318dbb02b   Nishanth Menon   regulator: palmas...
1217

429222d00   Nishanth Menon   regulator: palmas...
1218
1219
1220
  			desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
  							      rinfo->ctrl_addr);
  			desc->enable_mask = PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
318dbb02b   Nishanth Menon   regulator: palmas...
1221
  			/* set_mode overrides this value */
429222d00   Nishanth Menon   regulator: palmas...
1222
  			desc->enable_val = SMPS_CTRL_MODE_ON;
e5ce4208f   Graeme Gregory   regulator: regula...
1223
  		}
429222d00   Nishanth Menon   regulator: palmas...
1224
1225
  		desc->type = REGULATOR_VOLTAGE;
  		desc->owner = THIS_MODULE;
bdc4baace   Axel Lin   regulator: palmas...
1226

a361cd9f2   Graeme Gregory   regulator: palmas...
1227
  		if (pdata)
e5ce4208f   Graeme Gregory   regulator: regula...
1228
1229
1230
  			config.init_data = pdata->reg_data[id];
  		else
  			config.init_data = NULL;
429222d00   Nishanth Menon   regulator: palmas...
1231
  		desc->supply_name = rinfo->sname;
cac9e9162   Keerthy   regulator: palmas...
1232
  		config.of_node = ddata->palmas_matches[id].of_node;
a361cd9f2   Graeme Gregory   regulator: palmas...
1233

429222d00   Nishanth Menon   regulator: palmas...
1234
  		rdev = devm_regulator_register(pmic->dev, desc, &config);
e5ce4208f   Graeme Gregory   regulator: regula...
1235
  		if (IS_ERR(rdev)) {
cac9e9162   Keerthy   regulator: palmas...
1236
  			dev_err(pmic->dev,
e5ce4208f   Graeme Gregory   regulator: regula...
1237
1238
  				"failed to register %s regulator
  ",
cac9e9162   Keerthy   regulator: palmas...
1239
  				pdev_name);
51c86b3eb   Sachin Kamat   regulator: palmas...
1240
  			return PTR_ERR(rdev);
e5ce4208f   Graeme Gregory   regulator: regula...
1241
  		}
e5ce4208f   Graeme Gregory   regulator: regula...
1242
  	}
cac9e9162   Keerthy   regulator: palmas...
1243
1244
  	return 0;
  }
e5ce4208f   Graeme Gregory   regulator: regula...
1245

d6f83370e   Keerthy   regulator: palmas...
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
  static int tps65917_smps_registration(struct palmas_pmic *pmic,
  				      struct palmas_pmic_driver_data *ddata,
  				      struct palmas_pmic_platform_data *pdata,
  				      const char *pdev_name,
  				      struct regulator_config config)
  {
  	int id, ret;
  	unsigned int addr, reg;
  	struct regulator_dev *rdev;
  	struct palmas_reg_init *reg_init;
cf910b6b7   Nishanth Menon   regulator: palmas...
1256
  	struct palmas_regs_info *rinfo;
429222d00   Nishanth Menon   regulator: palmas...
1257
  	struct regulator_desc *desc;
d6f83370e   Keerthy   regulator: palmas...
1258
1259
1260
1261
1262
1263
  
  	for (id = ddata->smps_start; id <= ddata->smps_end; id++) {
  		/*
  		 * Miss out regulators which are not available due
  		 * to slaving configurations.
  		 */
429222d00   Nishanth Menon   regulator: palmas...
1264
1265
  		desc = &pmic->desc[id];
  		desc->n_linear_ranges = 3;
be0353031   Keerthy   regulator: tps659...
1266
1267
  		if ((id == TPS65917_REG_SMPS2 || id == TPS65917_REG_SMPS1) &&
  		    pmic->smps12)
d6f83370e   Keerthy   regulator: palmas...
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
  			continue;
  
  		/* Initialise sleep/init values from platform data */
  		if (pdata && pdata->reg_init[id]) {
  			reg_init = pdata->reg_init[id];
  			ret = palmas_smps_init(pmic->palmas, id, reg_init);
  			if (ret)
  				return ret;
  		} else {
  			reg_init = NULL;
  		}
cf910b6b7   Nishanth Menon   regulator: palmas...
1279
  		rinfo = &ddata->palmas_regs_info[id];
d6f83370e   Keerthy   regulator: palmas...
1280
1281
  
  		/* Register the regulators */
429222d00   Nishanth Menon   regulator: palmas...
1282
1283
  		desc->name = rinfo->name;
  		desc->id = id;
d6f83370e   Keerthy   regulator: palmas...
1284
1285
1286
1287
1288
1289
1290
  
  		/*
  		 * Read and store the RANGE bit for later use
  		 * This must be done before regulator is probed,
  		 * otherwise we error in probe with unsupportable
  		 * ranges. Read the current smps mode for later use.
  		 */
cf910b6b7   Nishanth Menon   regulator: palmas...
1291
  		addr = rinfo->vsel_addr;
d6f83370e   Keerthy   regulator: palmas...
1292
1293
1294
1295
1296
1297
1298
1299
  
  		ret = palmas_smps_read(pmic->palmas, addr, &reg);
  		if (ret)
  			return ret;
  		if (reg & TPS65917_SMPS1_VOLTAGE_RANGE)
  			pmic->range[id] = 1;
  
  		if (pmic->range[id])
429222d00   Nishanth Menon   regulator: palmas...
1300
1301
1302
  			desc->linear_ranges = smps_high_ranges;
  		else
  			desc->linear_ranges = smps_low_ranges;
d6f83370e   Keerthy   regulator: palmas...
1303
1304
  
  		if (reg_init && reg_init->roof_floor)
429222d00   Nishanth Menon   regulator: palmas...
1305
  			desc->ops = &tps65917_ops_ext_control_smps;
d6f83370e   Keerthy   regulator: palmas...
1306
  		else
429222d00   Nishanth Menon   regulator: palmas...
1307
1308
1309
1310
1311
1312
  			desc->ops = &tps65917_ops_smps;
  		desc->n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
  		desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
  						    rinfo->vsel_addr);
  		desc->vsel_mask = PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
  		desc->ramp_delay = 2500;
d6f83370e   Keerthy   regulator: palmas...
1313
1314
  
  		/* Read the smps mode for later use. */
cf910b6b7   Nishanth Menon   regulator: palmas...
1315
  		addr = rinfo->ctrl_addr;
d6f83370e   Keerthy   regulator: palmas...
1316
1317
1318
1319
1320
  		ret = palmas_smps_read(pmic->palmas, addr, &reg);
  		if (ret)
  			return ret;
  		pmic->current_reg_mode[id] = reg &
  				PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
b632815e9   Nishanth Menon   regulator: palmas...
1321
1322
1323
1324
1325
  		desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
  						      rinfo->ctrl_addr);
  		desc->enable_mask = PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
  		/* set_mode overrides this value */
  		desc->enable_val = SMPS_CTRL_MODE_ON;
d6f83370e   Keerthy   regulator: palmas...
1326

429222d00   Nishanth Menon   regulator: palmas...
1327
1328
  		desc->type = REGULATOR_VOLTAGE;
  		desc->owner = THIS_MODULE;
d6f83370e   Keerthy   regulator: palmas...
1329
1330
1331
1332
1333
  
  		if (pdata)
  			config.init_data = pdata->reg_data[id];
  		else
  			config.init_data = NULL;
429222d00   Nishanth Menon   regulator: palmas...
1334
  		desc->supply_name = rinfo->sname;
d6f83370e   Keerthy   regulator: palmas...
1335
  		config.of_node = ddata->palmas_matches[id].of_node;
429222d00   Nishanth Menon   regulator: palmas...
1336
  		rdev = devm_regulator_register(pmic->dev, desc, &config);
d6f83370e   Keerthy   regulator: palmas...
1337
1338
1339
1340
1341
1342
1343
  		if (IS_ERR(rdev)) {
  			dev_err(pmic->dev,
  				"failed to register %s regulator
  ",
  				pdev_name);
  			return PTR_ERR(rdev);
  		}
d6f83370e   Keerthy   regulator: palmas...
1344
1345
1346
1347
  	}
  
  	return 0;
  }
cac9e9162   Keerthy   regulator: palmas...
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
  static struct of_regulator_match palmas_matches[] = {
  	{ .name = "smps12", },
  	{ .name = "smps123", },
  	{ .name = "smps3", },
  	{ .name = "smps45", },
  	{ .name = "smps457", },
  	{ .name = "smps6", },
  	{ .name = "smps7", },
  	{ .name = "smps8", },
  	{ .name = "smps9", },
  	{ .name = "smps10_out2", },
  	{ .name = "smps10_out1", },
  	{ .name = "ldo1", },
  	{ .name = "ldo2", },
  	{ .name = "ldo3", },
  	{ .name = "ldo4", },
  	{ .name = "ldo5", },
  	{ .name = "ldo6", },
  	{ .name = "ldo7", },
  	{ .name = "ldo8", },
  	{ .name = "ldo9", },
  	{ .name = "ldoln", },
  	{ .name = "ldousb", },
  	{ .name = "regen1", },
  	{ .name = "regen2", },
  	{ .name = "regen3", },
  	{ .name = "sysen1", },
  	{ .name = "sysen2", },
  };
e5ce4208f   Graeme Gregory   regulator: regula...
1377

d6f83370e   Keerthy   regulator: palmas...
1378
1379
1380
1381
1382
1383
  static struct of_regulator_match tps65917_matches[] = {
  	{ .name = "smps1", },
  	{ .name = "smps2", },
  	{ .name = "smps3", },
  	{ .name = "smps4", },
  	{ .name = "smps5", },
be0353031   Keerthy   regulator: tps659...
1384
  	{ .name = "smps12",},
d6f83370e   Keerthy   regulator: palmas...
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
  	{ .name = "ldo1", },
  	{ .name = "ldo2", },
  	{ .name = "ldo3", },
  	{ .name = "ldo4", },
  	{ .name = "ldo5", },
  	{ .name = "regen1", },
  	{ .name = "regen2", },
  	{ .name = "regen3", },
  	{ .name = "sysen1", },
  	{ .name = "sysen2", },
  };
4b09e17b6   Nishanth Menon   regulator: palmas...
1396
  static struct palmas_pmic_driver_data palmas_ddata = {
cac9e9162   Keerthy   regulator: palmas...
1397
1398
1399
1400
1401
  	.smps_start = PALMAS_REG_SMPS12,
  	.smps_end = PALMAS_REG_SMPS10_OUT1,
  	.ldo_begin = PALMAS_REG_LDO1,
  	.ldo_end = PALMAS_REG_LDOUSB,
  	.max_reg = PALMAS_NUM_REGS,
e999c7289   Keerthy   regulator: palmas...
1402
  	.has_regen3 = true,
6839cd6f6   Nishanth Menon   regulator: palmas...
1403
  	.palmas_regs_info = palmas_generic_regs_info,
cac9e9162   Keerthy   regulator: palmas...
1404
1405
1406
1407
1408
  	.palmas_matches = palmas_matches,
  	.sleep_req_info = palma_sleep_req_info,
  	.smps_register = palmas_smps_registration,
  	.ldo_register = palmas_ldo_registration,
  };
aa07f0279   Laxman Dewangan   regulator: palmas...
1409

4b09e17b6   Nishanth Menon   regulator: palmas...
1410
  static struct palmas_pmic_driver_data tps65917_ddata = {
d6f83370e   Keerthy   regulator: palmas...
1411
  	.smps_start = TPS65917_REG_SMPS1,
be0353031   Keerthy   regulator: tps659...
1412
  	.smps_end = TPS65917_REG_SMPS12,
d6f83370e   Keerthy   regulator: palmas...
1413
1414
1415
  	.ldo_begin = TPS65917_REG_LDO1,
  	.ldo_end = TPS65917_REG_LDO5,
  	.max_reg = TPS65917_NUM_REGS,
e999c7289   Keerthy   regulator: palmas...
1416
  	.has_regen3 = true,
d6f83370e   Keerthy   regulator: palmas...
1417
1418
1419
1420
1421
1422
  	.palmas_regs_info = tps65917_regs_info,
  	.palmas_matches = tps65917_matches,
  	.sleep_req_info = tps65917_sleep_req_info,
  	.smps_register = tps65917_smps_registration,
  	.ldo_register = tps65917_ldo_registration,
  };
7f091e53c   Nishanth Menon   regulator: tps659...
1423
1424
1425
1426
  static int palmas_dt_to_pdata(struct device *dev,
  			      struct device_node *node,
  			      struct palmas_pmic_platform_data *pdata,
  			      struct palmas_pmic_driver_data *ddata)
cac9e9162   Keerthy   regulator: palmas...
1427
1428
1429
1430
  {
  	struct device_node *regulators;
  	u32 prop;
  	int idx, ret;
17c11a760   Laxman Dewangan   regulator: palmas...
1431

cac9e9162   Keerthy   regulator: palmas...
1432
1433
1434
1435
  	regulators = of_get_child_by_name(node, "regulators");
  	if (!regulators) {
  		dev_info(dev, "regulator node not found
  ");
7f091e53c   Nishanth Menon   regulator: tps659...
1436
  		return 0;
cac9e9162   Keerthy   regulator: palmas...
1437
  	}
087d30e30   Laxman Dewangan   regulator: palmas...
1438

cac9e9162   Keerthy   regulator: palmas...
1439
1440
1441
1442
1443
1444
  	ret = of_regulator_match(dev, regulators, ddata->palmas_matches,
  				 ddata->max_reg);
  	of_node_put(regulators);
  	if (ret < 0) {
  		dev_err(dev, "Error parsing regulator init data: %d
  ", ret);
7f091e53c   Nishanth Menon   regulator: tps659...
1445
  		return 0;
cac9e9162   Keerthy   regulator: palmas...
1446
  	}
e5ce4208f   Graeme Gregory   regulator: regula...
1447

cac9e9162   Keerthy   regulator: palmas...
1448
  	for (idx = 0; idx < ddata->max_reg; idx++) {
96e4f5232   Julia Lawall   regulator: palmas...
1449
  		struct of_regulator_match *match;
1b42443db   Nishanth Menon   regulator: tps659...
1450
  		struct palmas_reg_init *rinit;
6c7d614fa   Nishanth Menon   regulator: tps659...
1451
  		struct device_node *np;
036d193d3   Nishanth Menon   regulator: tps659...
1452
1453
  
  		match = &ddata->palmas_matches[idx];
6c7d614fa   Nishanth Menon   regulator: tps659...
1454
  		np = match->of_node;
036d193d3   Nishanth Menon   regulator: tps659...
1455

6c7d614fa   Nishanth Menon   regulator: tps659...
1456
  		if (!match->init_data || !np)
cac9e9162   Keerthy   regulator: palmas...
1457
  			continue;
e5ce4208f   Graeme Gregory   regulator: regula...
1458

1b42443db   Nishanth Menon   regulator: tps659...
1459
  		rinit = devm_kzalloc(dev, sizeof(*rinit), GFP_KERNEL);
7f091e53c   Nishanth Menon   regulator: tps659...
1460
1461
  		if (!rinit)
  			return -ENOMEM;
036d193d3   Nishanth Menon   regulator: tps659...
1462
  		pdata->reg_data[idx] = match->init_data;
1b42443db   Nishanth Menon   regulator: tps659...
1463
  		pdata->reg_init[idx] = rinit;
a361cd9f2   Graeme Gregory   regulator: palmas...
1464

6c7d614fa   Nishanth Menon   regulator: tps659...
1465
1466
  		rinit->warm_reset = of_property_read_bool(np, "ti,warm-reset");
  		ret = of_property_read_u32(np, "ti,roof-floor", &prop);
cac9e9162   Keerthy   regulator: palmas...
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
  		/* EINVAL: Property not found */
  		if (ret != -EINVAL) {
  			int econtrol;
  
  			/* use default value, when no value is specified */
  			econtrol = PALMAS_EXT_CONTROL_NSLEEP;
  			if (!ret) {
  				switch (prop) {
  				case 1:
  					econtrol = PALMAS_EXT_CONTROL_ENABLE1;
  					break;
  				case 2:
  					econtrol = PALMAS_EXT_CONTROL_ENABLE2;
  					break;
  				case 3:
  					econtrol = PALMAS_EXT_CONTROL_NSLEEP;
  					break;
  				default:
  					WARN_ON(1);
  					dev_warn(dev,
  						 "%s: Invalid roof-floor option: %u
  ",
036d193d3   Nishanth Menon   regulator: tps659...
1489
  						 match->name, prop);
cac9e9162   Keerthy   regulator: palmas...
1490
1491
  					break;
  				}
e5ce4208f   Graeme Gregory   regulator: regula...
1492
  			}
1b42443db   Nishanth Menon   regulator: tps659...
1493
  			rinit->roof_floor = econtrol;
e5ce4208f   Graeme Gregory   regulator: regula...
1494
  		}
e5ce4208f   Graeme Gregory   regulator: regula...
1495

6c7d614fa   Nishanth Menon   regulator: tps659...
1496
  		ret = of_property_read_u32(np, "ti,mode-sleep", &prop);
cac9e9162   Keerthy   regulator: palmas...
1497
  		if (!ret)
1b42443db   Nishanth Menon   regulator: tps659...
1498
  			rinit->mode_sleep = prop;
17c11a760   Laxman Dewangan   regulator: palmas...
1499

6c7d614fa   Nishanth Menon   regulator: tps659...
1500
  		ret = of_property_read_bool(np, "ti,smps-range");
cac9e9162   Keerthy   regulator: palmas...
1501
  		if (ret)
1b42443db   Nishanth Menon   regulator: tps659...
1502
  			rinit->vsel = PALMAS_SMPS12_VOLTAGE_RANGE;
cac9e9162   Keerthy   regulator: palmas...
1503
1504
1505
  
  		if (idx == PALMAS_REG_LDO8)
  			pdata->enable_ldo8_tracking = of_property_read_bool(
6c7d614fa   Nishanth Menon   regulator: tps659...
1506
  						np, "ti,enable-ldo8-tracking");
cac9e9162   Keerthy   regulator: palmas...
1507
1508
1509
  	}
  
  	pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator");
7f091e53c   Nishanth Menon   regulator: tps659...
1510
1511
  
  	return 0;
e5ce4208f   Graeme Gregory   regulator: regula...
1512
  }
cdbf6f0e8   Fabian Frederick   regulator: consti...
1513
  static const struct of_device_id of_palmas_match_tbl[] = {
cac9e9162   Keerthy   regulator: palmas...
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
  	{
  		.compatible = "ti,palmas-pmic",
  		.data = &palmas_ddata,
  	},
  	{
  		.compatible = "ti,twl6035-pmic",
  		.data = &palmas_ddata,
  	},
  	{
  		.compatible = "ti,twl6036-pmic",
  		.data = &palmas_ddata,
  	},
  	{
  		.compatible = "ti,twl6037-pmic",
  		.data = &palmas_ddata,
  	},
  	{
  		.compatible = "ti,tps65913-pmic",
  		.data = &palmas_ddata,
  	},
  	{
  		.compatible = "ti,tps65914-pmic",
  		.data = &palmas_ddata,
  	},
  	{
  		.compatible = "ti,tps80036-pmic",
  		.data = &palmas_ddata,
  	},
  	{
  		.compatible = "ti,tps659038-pmic",
  		.data = &palmas_ddata,
  	},
d6f83370e   Keerthy   regulator: palmas...
1546
1547
1548
1549
  	 {
  		.compatible = "ti,tps65917-pmic",
  		.data = &tps65917_ddata,
  	},
a361cd9f2   Graeme Gregory   regulator: palmas...
1550
1551
  	{ /* end */ }
  };
cac9e9162   Keerthy   regulator: palmas...
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
  static int palmas_regulators_probe(struct platform_device *pdev)
  {
  	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
  	struct palmas_pmic_platform_data *pdata = dev_get_platdata(&pdev->dev);
  	struct device_node *node = pdev->dev.of_node;
  	struct palmas_pmic_driver_data *driver_data;
  	struct regulator_config config = { };
  	struct palmas_pmic *pmic;
  	const char *pdev_name;
  	const struct of_device_id *match;
  	int ret = 0;
  	unsigned int reg;
  
  	match = of_match_device(of_match_ptr(of_palmas_match_tbl), &pdev->dev);
  
  	if (!match)
  		return -ENODATA;
  
  	driver_data = (struct palmas_pmic_driver_data *)match->data;
  	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  	if (!pdata)
  		return -ENOMEM;
  
  	pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
  	if (!pmic)
  		return -ENOMEM;
e999c7289   Keerthy   regulator: palmas...
1578
  	if (of_device_is_compatible(node, "ti,tps659038-pmic")) {
e03826d50   Keerthy   regulator: palmas...
1579
1580
  		palmas_generic_regs_info[PALMAS_REG_REGEN2].ctrl_addr =
  							TPS659038_REGEN2_CTRL;
e999c7289   Keerthy   regulator: palmas...
1581
1582
  		palmas_ddata.has_regen3 = false;
  	}
e03826d50   Keerthy   regulator: palmas...
1583

cac9e9162   Keerthy   regulator: palmas...
1584
1585
1586
1587
1588
  	pmic->dev = &pdev->dev;
  	pmic->palmas = palmas;
  	palmas->pmic = pmic;
  	platform_set_drvdata(pdev, pmic);
  	pmic->palmas->pmic_ddata = driver_data;
7f091e53c   Nishanth Menon   regulator: tps659...
1589
1590
1591
  	ret = palmas_dt_to_pdata(&pdev->dev, node, pdata, driver_data);
  	if (ret)
  		return ret;
cac9e9162   Keerthy   regulator: palmas...
1592
1593
1594
1595
  
  	ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg);
  	if (ret)
  		return ret;
be0353031   Keerthy   regulator: tps659...
1596
  	if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN) {
cac9e9162   Keerthy   regulator: palmas...
1597
  		pmic->smps123 = 1;
be0353031   Keerthy   regulator: tps659...
1598
1599
  		pmic->smps12 = 1;
  	}
cac9e9162   Keerthy   regulator: palmas...
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
  
  	if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN)
  		pmic->smps457 = 1;
  
  	config.regmap = palmas->regmap[REGULATOR_SLAVE];
  	config.dev = &pdev->dev;
  	config.driver_data = pmic;
  	pdev_name = pdev->name;
  
  	ret = driver_data->smps_register(pmic, driver_data, pdata, pdev_name,
  					 config);
  	if (ret)
  		return ret;
  
  	ret = driver_data->ldo_register(pmic, driver_data, pdata, pdev_name,
  					config);
  
  	return ret;
  }
e5ce4208f   Graeme Gregory   regulator: regula...
1619
1620
1621
  static struct platform_driver palmas_driver = {
  	.driver = {
  		.name = "palmas-pmic",
a361cd9f2   Graeme Gregory   regulator: palmas...
1622
  		.of_match_table = of_palmas_match_tbl,
e5ce4208f   Graeme Gregory   regulator: regula...
1623
  	},
bbcf50b1d   Laxman Dewangan   regulator: palmas...
1624
  	.probe = palmas_regulators_probe,
e5ce4208f   Graeme Gregory   regulator: regula...
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
  };
  
  static int __init palmas_init(void)
  {
  	return platform_driver_register(&palmas_driver);
  }
  subsys_initcall(palmas_init);
  
  static void __exit palmas_exit(void)
  {
  	platform_driver_unregister(&palmas_driver);
  }
  module_exit(palmas_exit);
  
  MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
  MODULE_DESCRIPTION("Palmas voltage regulator driver");
  MODULE_LICENSE("GPL");
  MODULE_ALIAS("platform:palmas-pmic");
a361cd9f2   Graeme Gregory   regulator: palmas...
1643
  MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);