1 // SPDX-License-Identifier: GPL-2.0
3 // Regulator driver for tps6594 PMIC
5 // Copyright (C) 2023 BayLibre Incorporated - https://www.baylibre.com/
7 #include <linux/device.h>
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/regmap.h>
15 #include <linux/regulator/driver.h>
16 #include <linux/regulator/machine.h>
17 #include <linux/regulator/of_regulator.h>
19 #include <linux/mfd/tps6594.h>
23 #define MULTI_PHASE_NB 4
24 /* TPS6593 and LP8764 supports OV, UV, SC, ILIM */
26 /* TPS65224 supports OV or UV */
27 #define TPS65224_REGS_INT_NB 1
29 enum tps6594_regulator_id
{
44 enum tps6594_multi_regulator_id
{
45 /* Multi-phase DCDC's */
52 struct tps6594_regulator_irq_type
{
54 const char *regulator_name
;
55 const char *event_name
;
59 static struct tps6594_regulator_irq_type tps6594_ext_regulator_irq_types
[] = {
60 { TPS6594_IRQ_NAME_VCCA_OV
, "VCCA", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
61 { TPS6594_IRQ_NAME_VCCA_UV
, "VCCA", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
62 { TPS6594_IRQ_NAME_VMON1_OV
, "VMON1", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
63 { TPS6594_IRQ_NAME_VMON1_UV
, "VMON1", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
64 { TPS6594_IRQ_NAME_VMON1_RV
, "VMON1", "residual voltage",
65 REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
66 { TPS6594_IRQ_NAME_VMON2_OV
, "VMON2", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
67 { TPS6594_IRQ_NAME_VMON2_UV
, "VMON2", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
68 { TPS6594_IRQ_NAME_VMON2_RV
, "VMON2", "residual voltage",
69 REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
72 static struct tps6594_regulator_irq_type tps65224_ext_regulator_irq_types
[] = {
73 { TPS65224_IRQ_NAME_VCCA_UVOV
, "VCCA", "voltage out of range",
74 REGULATOR_EVENT_REGULATION_OUT
},
75 { TPS65224_IRQ_NAME_VMON1_UVOV
, "VMON1", "voltage out of range",
76 REGULATOR_EVENT_REGULATION_OUT
},
77 { TPS65224_IRQ_NAME_VMON2_UVOV
, "VMON2", "voltage out of range",
78 REGULATOR_EVENT_REGULATION_OUT
},
81 struct tps6594_regulator_irq_data
{
83 struct tps6594_regulator_irq_type
*type
;
84 struct regulator_dev
*rdev
;
87 struct tps6594_ext_regulator_irq_data
{
89 struct tps6594_regulator_irq_type
*type
;
92 #define TPS6594_REGULATOR(_name, _of, _id, _type, _ops, _n, _vr, _vm, _er, \
93 _em, _cr, _cm, _lr, _nlr, _delay, _fuv, \
98 .regulators_node = of_match_ptr("regulators"), \
104 .owner = THIS_MODULE, \
110 .n_current_limits = _ncl, \
112 .enable_mask = _em, \
113 .volt_table = NULL, \
114 .linear_ranges = _lr, \
115 .n_linear_ranges = _nlr, \
116 .ramp_delay = _delay, \
119 .bypass_mask = _bpm, \
122 static const struct linear_range bucks_ranges[] = {
123 REGULATOR_LINEAR_RANGE(300000, 0x0, 0xe, 20000),
124 REGULATOR_LINEAR_RANGE(600000, 0xf, 0x72, 5000),
125 REGULATOR_LINEAR_RANGE(1100000, 0x73, 0xaa, 10000),
126 REGULATOR_LINEAR_RANGE(1660000, 0xab, 0xff, 20000),
129 static const struct linear_range ldos_1_2_3_ranges
[] = {
130 REGULATOR_LINEAR_RANGE(600000, 0x4, 0x3a, 50000),
133 static const struct linear_range ldos_4_ranges
[] = {
134 REGULATOR_LINEAR_RANGE(1200000, 0x20, 0x74, 25000),
137 /* Voltage range for TPS65224 Bucks and LDOs */
138 static const struct linear_range tps65224_bucks_1_ranges
[] = {
139 REGULATOR_LINEAR_RANGE(500000, 0x0a, 0x0e, 20000),
140 REGULATOR_LINEAR_RANGE(600000, 0x0f, 0x72, 5000),
141 REGULATOR_LINEAR_RANGE(1100000, 0x73, 0xaa, 10000),
142 REGULATOR_LINEAR_RANGE(1660000, 0xab, 0xfd, 20000),
145 static const struct linear_range tps65224_bucks_2_3_4_ranges
[] = {
146 REGULATOR_LINEAR_RANGE(500000, 0x0, 0x1a, 25000),
147 REGULATOR_LINEAR_RANGE(1200000, 0x1b, 0x45, 50000),
150 static const struct linear_range tps65224_ldos_1_ranges
[] = {
151 REGULATOR_LINEAR_RANGE(1200000, 0xC, 0x36, 50000),
154 static const struct linear_range tps65224_ldos_2_3_ranges
[] = {
155 REGULATOR_LINEAR_RANGE(600000, 0x0, 0x38, 50000),
158 /* Operations permitted on BUCK1/2/3/4/5 */
159 static const struct regulator_ops tps6594_bucks_ops
= {
160 .is_enabled
= regulator_is_enabled_regmap
,
161 .enable
= regulator_enable_regmap
,
162 .disable
= regulator_disable_regmap
,
163 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
164 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
165 .list_voltage
= regulator_list_voltage_linear_range
,
166 .map_voltage
= regulator_map_voltage_linear_range
,
167 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
171 /* Operations permitted on LDO1/2/3 */
172 static const struct regulator_ops tps6594_ldos_1_2_3_ops
= {
173 .is_enabled
= regulator_is_enabled_regmap
,
174 .enable
= regulator_enable_regmap
,
175 .disable
= regulator_disable_regmap
,
176 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
177 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
178 .list_voltage
= regulator_list_voltage_linear_range
,
179 .map_voltage
= regulator_map_voltage_linear_range
,
180 .set_bypass
= regulator_set_bypass_regmap
,
181 .get_bypass
= regulator_get_bypass_regmap
,
184 /* Operations permitted on LDO4 */
185 static const struct regulator_ops tps6594_ldos_4_ops
= {
186 .is_enabled
= regulator_is_enabled_regmap
,
187 .enable
= regulator_enable_regmap
,
188 .disable
= regulator_disable_regmap
,
189 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
190 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
191 .list_voltage
= regulator_list_voltage_linear_range
,
192 .map_voltage
= regulator_map_voltage_linear_range
,
195 static const struct regulator_desc buck_regs
[] = {
196 TPS6594_REGULATOR("BUCK1", "buck1", TPS6594_BUCK_1
,
197 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS6594_MASK_BUCKS_VSET
,
198 TPS6594_REG_BUCKX_VOUT_1(0),
199 TPS6594_MASK_BUCKS_VSET
,
200 TPS6594_REG_BUCKX_CTRL(0),
201 TPS6594_BIT_BUCK_EN
, 0, 0, bucks_ranges
,
202 4, 0, 0, NULL
, 0, 0),
203 TPS6594_REGULATOR("BUCK2", "buck2", TPS6594_BUCK_2
,
204 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS6594_MASK_BUCKS_VSET
,
205 TPS6594_REG_BUCKX_VOUT_1(1),
206 TPS6594_MASK_BUCKS_VSET
,
207 TPS6594_REG_BUCKX_CTRL(1),
208 TPS6594_BIT_BUCK_EN
, 0, 0, bucks_ranges
,
209 4, 0, 0, NULL
, 0, 0),
210 TPS6594_REGULATOR("BUCK3", "buck3", TPS6594_BUCK_3
,
211 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS6594_MASK_BUCKS_VSET
,
212 TPS6594_REG_BUCKX_VOUT_1(2),
213 TPS6594_MASK_BUCKS_VSET
,
214 TPS6594_REG_BUCKX_CTRL(2),
215 TPS6594_BIT_BUCK_EN
, 0, 0, bucks_ranges
,
216 4, 0, 0, NULL
, 0, 0),
217 TPS6594_REGULATOR("BUCK4", "buck4", TPS6594_BUCK_4
,
218 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS6594_MASK_BUCKS_VSET
,
219 TPS6594_REG_BUCKX_VOUT_1(3),
220 TPS6594_MASK_BUCKS_VSET
,
221 TPS6594_REG_BUCKX_CTRL(3),
222 TPS6594_BIT_BUCK_EN
, 0, 0, bucks_ranges
,
223 4, 0, 0, NULL
, 0, 0),
224 TPS6594_REGULATOR("BUCK5", "buck5", TPS6594_BUCK_5
,
225 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS6594_MASK_BUCKS_VSET
,
226 TPS6594_REG_BUCKX_VOUT_1(4),
227 TPS6594_MASK_BUCKS_VSET
,
228 TPS6594_REG_BUCKX_CTRL(4),
229 TPS6594_BIT_BUCK_EN
, 0, 0, bucks_ranges
,
230 4, 0, 0, NULL
, 0, 0),
233 /* Buck configuration for TPS65224 */
234 static const struct regulator_desc tps65224_buck_regs
[] = {
235 TPS6594_REGULATOR("BUCK1", "buck1", TPS6594_BUCK_1
,
236 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS65224_MASK_BUCK1_VSET
,
237 TPS6594_REG_BUCKX_VOUT_1(0),
238 TPS65224_MASK_BUCK1_VSET
,
239 TPS6594_REG_BUCKX_CTRL(0),
240 TPS6594_BIT_BUCK_EN
, 0, 0, tps65224_bucks_1_ranges
,
241 4, 0, 0, NULL
, 0, 0),
242 TPS6594_REGULATOR("BUCK2", "buck2", TPS6594_BUCK_2
,
243 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS65224_MASK_BUCKS_VSET
,
244 TPS6594_REG_BUCKX_VOUT_1(1),
245 TPS65224_MASK_BUCKS_VSET
,
246 TPS6594_REG_BUCKX_CTRL(1),
247 TPS6594_BIT_BUCK_EN
, 0, 0, tps65224_bucks_2_3_4_ranges
,
248 4, 0, 0, NULL
, 0, 0),
249 TPS6594_REGULATOR("BUCK3", "buck3", TPS6594_BUCK_3
,
250 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS65224_MASK_BUCKS_VSET
,
251 TPS6594_REG_BUCKX_VOUT_1(2),
252 TPS65224_MASK_BUCKS_VSET
,
253 TPS6594_REG_BUCKX_CTRL(2),
254 TPS6594_BIT_BUCK_EN
, 0, 0, tps65224_bucks_2_3_4_ranges
,
255 4, 0, 0, NULL
, 0, 0),
256 TPS6594_REGULATOR("BUCK4", "buck4", TPS6594_BUCK_4
,
257 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS65224_MASK_BUCKS_VSET
,
258 TPS6594_REG_BUCKX_VOUT_1(3),
259 TPS65224_MASK_BUCKS_VSET
,
260 TPS6594_REG_BUCKX_CTRL(3),
261 TPS6594_BIT_BUCK_EN
, 0, 0, tps65224_bucks_2_3_4_ranges
,
262 4, 0, 0, NULL
, 0, 0),
265 static struct tps6594_regulator_irq_type tps6594_buck1_irq_types
[] = {
266 { TPS6594_IRQ_NAME_BUCK1_OV
, "BUCK1", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
267 { TPS6594_IRQ_NAME_BUCK1_UV
, "BUCK1", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
268 { TPS6594_IRQ_NAME_BUCK1_SC
, "BUCK1", "short circuit", REGULATOR_EVENT_REGULATION_OUT
},
269 { TPS6594_IRQ_NAME_BUCK1_ILIM
, "BUCK1", "reach ilim, overcurrent",
270 REGULATOR_EVENT_OVER_CURRENT
},
273 static struct tps6594_regulator_irq_type tps6594_buck2_irq_types
[] = {
274 { TPS6594_IRQ_NAME_BUCK2_OV
, "BUCK2", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
275 { TPS6594_IRQ_NAME_BUCK2_UV
, "BUCK2", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
276 { TPS6594_IRQ_NAME_BUCK2_SC
, "BUCK2", "short circuit", REGULATOR_EVENT_REGULATION_OUT
},
277 { TPS6594_IRQ_NAME_BUCK2_ILIM
, "BUCK2", "reach ilim, overcurrent",
278 REGULATOR_EVENT_OVER_CURRENT
},
281 static struct tps6594_regulator_irq_type tps6594_buck3_irq_types
[] = {
282 { TPS6594_IRQ_NAME_BUCK3_OV
, "BUCK3", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
283 { TPS6594_IRQ_NAME_BUCK3_UV
, "BUCK3", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
284 { TPS6594_IRQ_NAME_BUCK3_SC
, "BUCK3", "short circuit", REGULATOR_EVENT_REGULATION_OUT
},
285 { TPS6594_IRQ_NAME_BUCK3_ILIM
, "BUCK3", "reach ilim, overcurrent",
286 REGULATOR_EVENT_OVER_CURRENT
},
289 static struct tps6594_regulator_irq_type tps6594_buck4_irq_types
[] = {
290 { TPS6594_IRQ_NAME_BUCK4_OV
, "BUCK4", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
291 { TPS6594_IRQ_NAME_BUCK4_UV
, "BUCK4", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
292 { TPS6594_IRQ_NAME_BUCK4_SC
, "BUCK4", "short circuit", REGULATOR_EVENT_REGULATION_OUT
},
293 { TPS6594_IRQ_NAME_BUCK4_ILIM
, "BUCK4", "reach ilim, overcurrent",
294 REGULATOR_EVENT_OVER_CURRENT
},
297 static struct tps6594_regulator_irq_type tps6594_buck5_irq_types
[] = {
298 { TPS6594_IRQ_NAME_BUCK5_OV
, "BUCK5", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
299 { TPS6594_IRQ_NAME_BUCK5_UV
, "BUCK5", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
300 { TPS6594_IRQ_NAME_BUCK5_SC
, "BUCK5", "short circuit", REGULATOR_EVENT_REGULATION_OUT
},
301 { TPS6594_IRQ_NAME_BUCK5_ILIM
, "BUCK5", "reach ilim, overcurrent",
302 REGULATOR_EVENT_OVER_CURRENT
},
305 static struct tps6594_regulator_irq_type tps6594_ldo1_irq_types
[] = {
306 { TPS6594_IRQ_NAME_LDO1_OV
, "LDO1", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
307 { TPS6594_IRQ_NAME_LDO1_UV
, "LDO1", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
308 { TPS6594_IRQ_NAME_LDO1_SC
, "LDO1", "short circuit", REGULATOR_EVENT_REGULATION_OUT
},
309 { TPS6594_IRQ_NAME_LDO1_ILIM
, "LDO1", "reach ilim, overcurrent",
310 REGULATOR_EVENT_OVER_CURRENT
},
313 static struct tps6594_regulator_irq_type tps6594_ldo2_irq_types
[] = {
314 { TPS6594_IRQ_NAME_LDO2_OV
, "LDO2", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
315 { TPS6594_IRQ_NAME_LDO2_UV
, "LDO2", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
316 { TPS6594_IRQ_NAME_LDO2_SC
, "LDO2", "short circuit", REGULATOR_EVENT_REGULATION_OUT
},
317 { TPS6594_IRQ_NAME_LDO2_ILIM
, "LDO2", "reach ilim, overcurrent",
318 REGULATOR_EVENT_OVER_CURRENT
},
321 static struct tps6594_regulator_irq_type tps6594_ldo3_irq_types
[] = {
322 { TPS6594_IRQ_NAME_LDO3_OV
, "LDO3", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
323 { TPS6594_IRQ_NAME_LDO3_UV
, "LDO3", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
324 { TPS6594_IRQ_NAME_LDO3_SC
, "LDO3", "short circuit", REGULATOR_EVENT_REGULATION_OUT
},
325 { TPS6594_IRQ_NAME_LDO3_ILIM
, "LDO3", "reach ilim, overcurrent",
326 REGULATOR_EVENT_OVER_CURRENT
},
329 static struct tps6594_regulator_irq_type tps6594_ldo4_irq_types
[] = {
330 { TPS6594_IRQ_NAME_LDO4_OV
, "LDO4", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN
},
331 { TPS6594_IRQ_NAME_LDO4_UV
, "LDO4", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE
},
332 { TPS6594_IRQ_NAME_LDO4_SC
, "LDO4", "short circuit", REGULATOR_EVENT_REGULATION_OUT
},
333 { TPS6594_IRQ_NAME_LDO4_ILIM
, "LDO4", "reach ilim, overcurrent",
334 REGULATOR_EVENT_OVER_CURRENT
},
337 static struct tps6594_regulator_irq_type tps65224_buck1_irq_types
[] = {
338 { TPS65224_IRQ_NAME_BUCK1_UVOV
, "BUCK1", "voltage out of range",
339 REGULATOR_EVENT_REGULATION_OUT
},
342 static struct tps6594_regulator_irq_type tps65224_buck2_irq_types
[] = {
343 { TPS65224_IRQ_NAME_BUCK2_UVOV
, "BUCK2", "voltage out of range",
344 REGULATOR_EVENT_REGULATION_OUT
},
347 static struct tps6594_regulator_irq_type tps65224_buck3_irq_types
[] = {
348 { TPS65224_IRQ_NAME_BUCK3_UVOV
, "BUCK3", "voltage out of range",
349 REGULATOR_EVENT_REGULATION_OUT
},
352 static struct tps6594_regulator_irq_type tps65224_buck4_irq_types
[] = {
353 { TPS65224_IRQ_NAME_BUCK4_UVOV
, "BUCK4", "voltage out of range",
354 REGULATOR_EVENT_REGULATION_OUT
},
357 static struct tps6594_regulator_irq_type tps65224_ldo1_irq_types
[] = {
358 { TPS65224_IRQ_NAME_LDO1_UVOV
, "LDO1", "voltage out of range",
359 REGULATOR_EVENT_REGULATION_OUT
},
362 static struct tps6594_regulator_irq_type tps65224_ldo2_irq_types
[] = {
363 { TPS65224_IRQ_NAME_LDO2_UVOV
, "LDO2", "voltage out of range",
364 REGULATOR_EVENT_REGULATION_OUT
},
367 static struct tps6594_regulator_irq_type tps65224_ldo3_irq_types
[] = {
368 { TPS65224_IRQ_NAME_LDO3_UVOV
, "LDO3", "voltage out of range",
369 REGULATOR_EVENT_REGULATION_OUT
},
372 static struct tps6594_regulator_irq_type
*tps6594_bucks_irq_types
[] = {
373 tps6594_buck1_irq_types
,
374 tps6594_buck2_irq_types
,
375 tps6594_buck3_irq_types
,
376 tps6594_buck4_irq_types
,
377 tps6594_buck5_irq_types
,
380 static struct tps6594_regulator_irq_type
*tps6594_ldos_irq_types
[] = {
381 tps6594_ldo1_irq_types
,
382 tps6594_ldo2_irq_types
,
383 tps6594_ldo3_irq_types
,
384 tps6594_ldo4_irq_types
,
387 static struct tps6594_regulator_irq_type
*tps65224_bucks_irq_types
[] = {
388 tps65224_buck1_irq_types
,
389 tps65224_buck2_irq_types
,
390 tps65224_buck3_irq_types
,
391 tps65224_buck4_irq_types
,
394 static struct tps6594_regulator_irq_type
*tps65224_ldos_irq_types
[] = {
395 tps65224_ldo1_irq_types
,
396 tps65224_ldo2_irq_types
,
397 tps65224_ldo3_irq_types
,
400 static const struct regulator_desc tps6594_multi_regs
[] = {
401 TPS6594_REGULATOR("BUCK12", "buck12", TPS6594_BUCK_1
,
402 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS6594_MASK_BUCKS_VSET
,
403 TPS6594_REG_BUCKX_VOUT_1(0),
404 TPS6594_MASK_BUCKS_VSET
,
405 TPS6594_REG_BUCKX_CTRL(0),
406 TPS6594_BIT_BUCK_EN
, 0, 0, bucks_ranges
,
407 4, 4000, 0, NULL
, 0, 0),
408 TPS6594_REGULATOR("BUCK34", "buck34", TPS6594_BUCK_3
,
409 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS6594_MASK_BUCKS_VSET
,
410 TPS6594_REG_BUCKX_VOUT_1(2),
411 TPS6594_MASK_BUCKS_VSET
,
412 TPS6594_REG_BUCKX_CTRL(2),
413 TPS6594_BIT_BUCK_EN
, 0, 0, bucks_ranges
,
414 4, 0, 0, NULL
, 0, 0),
415 TPS6594_REGULATOR("BUCK123", "buck123", TPS6594_BUCK_1
,
416 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS6594_MASK_BUCKS_VSET
,
417 TPS6594_REG_BUCKX_VOUT_1(0),
418 TPS6594_MASK_BUCKS_VSET
,
419 TPS6594_REG_BUCKX_CTRL(0),
420 TPS6594_BIT_BUCK_EN
, 0, 0, bucks_ranges
,
421 4, 4000, 0, NULL
, 0, 0),
422 TPS6594_REGULATOR("BUCK1234", "buck1234", TPS6594_BUCK_1
,
423 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS6594_MASK_BUCKS_VSET
,
424 TPS6594_REG_BUCKX_VOUT_1(0),
425 TPS6594_MASK_BUCKS_VSET
,
426 TPS6594_REG_BUCKX_CTRL(0),
427 TPS6594_BIT_BUCK_EN
, 0, 0, bucks_ranges
,
428 4, 4000, 0, NULL
, 0, 0),
431 static const struct regulator_desc tps65224_multi_regs
[] = {
432 TPS6594_REGULATOR("BUCK12", "buck12", TPS6594_BUCK_1
,
433 REGULATOR_VOLTAGE
, tps6594_bucks_ops
, TPS65224_MASK_BUCK1_VSET
,
434 TPS6594_REG_BUCKX_VOUT_1(0),
435 TPS65224_MASK_BUCK1_VSET
,
436 TPS6594_REG_BUCKX_CTRL(0),
437 TPS6594_BIT_BUCK_EN
, 0, 0, tps65224_bucks_1_ranges
,
438 4, 4000, 0, NULL
, 0, 0),
441 static const struct regulator_desc tps6594_ldo_regs
[] = {
442 TPS6594_REGULATOR("LDO1", "ldo1", TPS6594_LDO_1
,
443 REGULATOR_VOLTAGE
, tps6594_ldos_1_2_3_ops
, TPS6594_MASK_LDO123_VSET
,
444 TPS6594_REG_LDOX_VOUT(0),
445 TPS6594_MASK_LDO123_VSET
,
446 TPS6594_REG_LDOX_CTRL(0),
447 TPS6594_BIT_LDO_EN
, 0, 0, ldos_1_2_3_ranges
,
448 1, 0, 0, NULL
, 0, TPS6594_BIT_LDO_BYPASS
),
449 TPS6594_REGULATOR("LDO2", "ldo2", TPS6594_LDO_2
,
450 REGULATOR_VOLTAGE
, tps6594_ldos_1_2_3_ops
, TPS6594_MASK_LDO123_VSET
,
451 TPS6594_REG_LDOX_VOUT(1),
452 TPS6594_MASK_LDO123_VSET
,
453 TPS6594_REG_LDOX_CTRL(1),
454 TPS6594_BIT_LDO_EN
, 0, 0, ldos_1_2_3_ranges
,
455 1, 0, 0, NULL
, 0, TPS6594_BIT_LDO_BYPASS
),
456 TPS6594_REGULATOR("LDO3", "ldo3", TPS6594_LDO_3
,
457 REGULATOR_VOLTAGE
, tps6594_ldos_1_2_3_ops
, TPS6594_MASK_LDO123_VSET
,
458 TPS6594_REG_LDOX_VOUT(2),
459 TPS6594_MASK_LDO123_VSET
,
460 TPS6594_REG_LDOX_CTRL(2),
461 TPS6594_BIT_LDO_EN
, 0, 0, ldos_1_2_3_ranges
,
462 1, 0, 0, NULL
, 0, TPS6594_BIT_LDO_BYPASS
),
463 TPS6594_REGULATOR("LDO4", "ldo4", TPS6594_LDO_4
,
464 REGULATOR_VOLTAGE
, tps6594_ldos_4_ops
, TPS6594_MASK_LDO4_VSET
>> 1,
465 TPS6594_REG_LDOX_VOUT(3),
466 TPS6594_MASK_LDO4_VSET
,
467 TPS6594_REG_LDOX_CTRL(3),
468 TPS6594_BIT_LDO_EN
, 0, 0, ldos_4_ranges
,
469 1, 0, 0, NULL
, 0, 0),
472 static const struct regulator_desc tps65224_ldo_regs
[] = {
473 TPS6594_REGULATOR("LDO1", "ldo1", TPS6594_LDO_1
,
474 REGULATOR_VOLTAGE
, tps6594_ldos_1_2_3_ops
, TPS6594_MASK_LDO123_VSET
,
475 TPS6594_REG_LDOX_VOUT(0),
476 TPS6594_MASK_LDO123_VSET
,
477 TPS6594_REG_LDOX_CTRL(0),
478 TPS6594_BIT_LDO_EN
, 0, 0, tps65224_ldos_1_ranges
,
479 1, 0, 0, NULL
, 0, TPS6594_BIT_LDO_BYPASS
),
480 TPS6594_REGULATOR("LDO2", "ldo2", TPS6594_LDO_2
,
481 REGULATOR_VOLTAGE
, tps6594_ldos_1_2_3_ops
, TPS6594_MASK_LDO123_VSET
,
482 TPS6594_REG_LDOX_VOUT(1),
483 TPS6594_MASK_LDO123_VSET
,
484 TPS6594_REG_LDOX_CTRL(1),
485 TPS6594_BIT_LDO_EN
, 0, 0, tps65224_ldos_2_3_ranges
,
486 1, 0, 0, NULL
, 0, TPS6594_BIT_LDO_BYPASS
),
487 TPS6594_REGULATOR("LDO3", "ldo3", TPS6594_LDO_3
,
488 REGULATOR_VOLTAGE
, tps6594_ldos_1_2_3_ops
, TPS6594_MASK_LDO123_VSET
,
489 TPS6594_REG_LDOX_VOUT(2),
490 TPS6594_MASK_LDO123_VSET
,
491 TPS6594_REG_LDOX_CTRL(2),
492 TPS6594_BIT_LDO_EN
, 0, 0, tps65224_ldos_2_3_ranges
,
493 1, 0, 0, NULL
, 0, TPS6594_BIT_LDO_BYPASS
),
496 static irqreturn_t
tps6594_regulator_irq_handler(int irq
, void *data
)
498 struct tps6594_regulator_irq_data
*irq_data
= data
;
500 if (irq_data
->type
->event_name
[0] == '\0') {
501 /* This is the timeout interrupt no specific regulator */
502 dev_err(irq_data
->dev
,
503 "System was put in shutdown due to timeout during an active or standby transition.\n");
507 dev_err(irq_data
->dev
, "Error IRQ trap %s for %s\n",
508 irq_data
->type
->event_name
, irq_data
->type
->regulator_name
);
510 regulator_notifier_call_chain(irq_data
->rdev
,
511 irq_data
->type
->event
, NULL
);
516 static int tps6594_request_reg_irqs(struct platform_device
*pdev
,
517 struct regulator_dev
*rdev
,
518 struct tps6594_regulator_irq_data
*irq_data
,
519 struct tps6594_regulator_irq_type
*regs_irq_types
,
520 size_t interrupt_cnt
,
523 struct tps6594_regulator_irq_type
*irq_type
;
524 struct tps6594
*tps
= dev_get_drvdata(pdev
->dev
.parent
);
529 for (j
= 0; j
< interrupt_cnt
; j
++) {
530 irq_type
= ®s_irq_types
[j
];
531 irq
= platform_get_irq_byname(pdev
, irq_type
->irq_name
);
535 irq_data
[*irq_idx
].dev
= tps
->dev
;
536 irq_data
[*irq_idx
].type
= irq_type
;
537 irq_data
[*irq_idx
].rdev
= rdev
;
539 error
= devm_request_threaded_irq(tps
->dev
, irq
, NULL
,
540 tps6594_regulator_irq_handler
, IRQF_ONESHOT
,
541 irq_type
->irq_name
, &irq_data
[*irq_idx
]);
543 dev_err(tps
->dev
, "tps6594 failed to request %s IRQ %d: %d\n",
544 irq_type
->irq_name
, irq
, error
);
552 static int tps6594_regulator_probe(struct platform_device
*pdev
)
554 struct tps6594
*tps
= dev_get_drvdata(pdev
->dev
.parent
);
555 struct regulator_dev
*rdev
;
556 struct device_node
*np
= NULL
;
557 struct device_node
*np_pmic_parent
= NULL
;
558 struct regulator_config config
= {};
559 struct tps6594_regulator_irq_data
*irq_data
;
560 struct tps6594_ext_regulator_irq_data
*irq_ext_reg_data
;
561 struct tps6594_regulator_irq_type
*irq_type
;
562 struct tps6594_regulator_irq_type
*irq_types
;
563 bool buck_configured
[BUCK_NB
] = { false };
564 bool buck_multi
[MULTI_PHASE_NB
] = { false };
566 static const char *npname
;
567 int error
, i
, irq
, multi
;
573 unsigned int irq_count
;
574 unsigned int multi_phase_cnt
;
576 struct tps6594_regulator_irq_type
**bucks_irq_types
;
577 const struct regulator_desc
*multi_regs
;
578 struct tps6594_regulator_irq_type
**ldos_irq_types
;
579 const struct regulator_desc
*ldo_regs
;
580 size_t interrupt_count
;
582 if (tps
->chip_id
== TPS65224
) {
583 bucks_irq_types
= tps65224_bucks_irq_types
;
584 interrupt_count
= ARRAY_SIZE(tps65224_buck1_irq_types
);
585 multi_regs
= tps65224_multi_regs
;
586 ldos_irq_types
= tps65224_ldos_irq_types
;
587 ldo_regs
= tps65224_ldo_regs
;
588 multi_phase_cnt
= ARRAY_SIZE(tps65224_multi_regs
);
590 bucks_irq_types
= tps6594_bucks_irq_types
;
591 interrupt_count
= ARRAY_SIZE(tps6594_buck1_irq_types
);
592 multi_regs
= tps6594_multi_regs
;
593 ldos_irq_types
= tps6594_ldos_irq_types
;
594 ldo_regs
= tps6594_ldo_regs
;
595 multi_phase_cnt
= ARRAY_SIZE(tps6594_multi_regs
);
605 config
.dev
= tps
->dev
;
606 config
.driver_data
= tps
;
607 config
.regmap
= tps
->regmap
;
610 * Switch case defines different possible multi phase config
611 * This is based on dts buck node name.
612 * Buck node name must be chosen accordingly.
613 * Default case is no Multiphase buck.
614 * In case of Multiphase configuration, value should be defined for
615 * buck_configured to avoid creating bucks for every buck in multiphase
617 for (multi
= 0; multi
< multi_phase_cnt
; multi
++) {
618 np
= of_find_node_by_name(tps
->dev
->of_node
, multi_regs
[multi
].supply_name
);
619 npname
= of_node_full_name(np
);
620 np_pmic_parent
= of_get_parent(of_get_parent(np
));
621 if (of_node_cmp(of_node_full_name(np_pmic_parent
), tps
->dev
->of_node
->full_name
))
623 if (strcmp(npname
, multi_regs
[multi
].supply_name
) == 0) {
626 buck_multi
[0] = true;
627 buck_configured
[0] = true;
628 buck_configured
[1] = true;
630 /* multiphase buck34 is supported only with buck12 */
631 case MULTI_BUCK12_34
:
632 buck_multi
[0] = true;
633 buck_multi
[1] = true;
634 buck_configured
[0] = true;
635 buck_configured
[1] = true;
636 buck_configured
[2] = true;
637 buck_configured
[3] = true;
640 buck_multi
[2] = true;
641 buck_configured
[0] = true;
642 buck_configured
[1] = true;
643 buck_configured
[2] = true;
646 buck_multi
[3] = true;
647 buck_configured
[0] = true;
648 buck_configured
[1] = true;
649 buck_configured
[2] = true;
650 buck_configured
[3] = true;
656 if (tps
->chip_id
== TPS65224
) {
657 nr_buck
= ARRAY_SIZE(tps65224_buck_regs
);
658 nr_ldo
= ARRAY_SIZE(tps65224_ldo_regs
);
659 nr_types
= TPS65224_REGS_INT_NB
;
661 nr_buck
= ARRAY_SIZE(buck_regs
);
662 nr_ldo
= (tps
->chip_id
== LP8764
) ? 0 : ARRAY_SIZE(tps6594_ldo_regs
);
663 nr_types
= REGS_INT_NB
;
666 reg_irq_nb
= nr_types
* (nr_buck
+ nr_ldo
);
668 irq_data
= devm_kmalloc_array(tps
->dev
, reg_irq_nb
,
669 sizeof(struct tps6594_regulator_irq_data
), GFP_KERNEL
);
673 for (i
= 0; i
< multi_phase_cnt
; i
++) {
677 rdev
= devm_regulator_register(&pdev
->dev
, &multi_regs
[i
], &config
);
679 return dev_err_probe(tps
->dev
, PTR_ERR(rdev
),
680 "failed to register %s regulator\n",
683 /* config multiphase buck12+buck34 */
684 if (i
== MULTI_BUCK12_34
)
687 error
= tps6594_request_reg_irqs(pdev
, rdev
, irq_data
,
688 bucks_irq_types
[buck_idx
],
689 interrupt_count
, &irq_idx
);
693 error
= tps6594_request_reg_irqs(pdev
, rdev
, irq_data
,
694 bucks_irq_types
[buck_idx
+ 1],
695 interrupt_count
, &irq_idx
);
699 if (i
== MULTI_BUCK123
|| i
== MULTI_BUCK1234
) {
700 error
= tps6594_request_reg_irqs(pdev
, rdev
, irq_data
,
701 tps6594_bucks_irq_types
[buck_idx
+ 2],
707 if (i
== MULTI_BUCK1234
) {
708 error
= tps6594_request_reg_irqs(pdev
, rdev
, irq_data
,
709 tps6594_bucks_irq_types
[buck_idx
+ 3],
717 for (i
= 0; i
< nr_buck
; i
++) {
718 if (buck_configured
[i
])
721 const struct regulator_desc
*buck_cfg
= (tps
->chip_id
== TPS65224
) ?
722 tps65224_buck_regs
: buck_regs
;
724 rdev
= devm_regulator_register(&pdev
->dev
, &buck_cfg
[i
], &config
);
726 return dev_err_probe(tps
->dev
, PTR_ERR(rdev
),
727 "failed to register %s regulator\n", pdev
->name
);
729 error
= tps6594_request_reg_irqs(pdev
, rdev
, irq_data
,
730 bucks_irq_types
[i
], interrupt_count
, &irq_idx
);
735 /* LP8764 doesn't have LDO */
736 if (tps
->chip_id
!= LP8764
) {
737 for (i
= 0; i
< nr_ldo
; i
++) {
738 rdev
= devm_regulator_register(&pdev
->dev
, &ldo_regs
[i
], &config
);
740 return dev_err_probe(tps
->dev
, PTR_ERR(rdev
),
741 "failed to register %s regulator\n",
744 error
= tps6594_request_reg_irqs(pdev
, rdev
, irq_data
,
745 ldos_irq_types
[i
], interrupt_count
,
752 if (tps
->chip_id
== TPS65224
) {
753 irq_types
= tps65224_ext_regulator_irq_types
;
754 irq_count
= ARRAY_SIZE(tps65224_ext_regulator_irq_types
);
756 irq_types
= tps6594_ext_regulator_irq_types
;
757 if (tps
->chip_id
== LP8764
)
758 irq_count
= ARRAY_SIZE(tps6594_ext_regulator_irq_types
);
760 /* TPS6593 supports only VCCA OV and UV */
764 irq_ext_reg_data
= devm_kmalloc_array(tps
->dev
,
766 sizeof(struct tps6594_ext_regulator_irq_data
),
768 if (!irq_ext_reg_data
)
771 for (i
= 0; i
< irq_count
; ++i
) {
772 irq_type
= &irq_types
[i
];
773 irq
= platform_get_irq_byname(pdev
, irq_type
->irq_name
);
777 irq_ext_reg_data
[i
].dev
= tps
->dev
;
778 irq_ext_reg_data
[i
].type
= irq_type
;
780 error
= devm_request_threaded_irq(tps
->dev
, irq
, NULL
,
781 tps6594_regulator_irq_handler
,
784 &irq_ext_reg_data
[i
]);
786 return dev_err_probe(tps
->dev
, error
,
787 "failed to request %s IRQ %d\n",
788 irq_type
->irq_name
, irq
);
793 static struct platform_driver tps6594_regulator_driver
= {
795 .name
= "tps6594-regulator",
797 .probe
= tps6594_regulator_probe
,
800 module_platform_driver(tps6594_regulator_driver
);
802 MODULE_ALIAS("platform:tps6594-regulator");
803 MODULE_AUTHOR("Jerome Neanne <jneanne@baylibre.com>");
804 MODULE_AUTHOR("Nirmala Devi Mal Nadar <m.nirmaladevi@ltts.com>");
805 MODULE_DESCRIPTION("TPS6594 voltage regulator driver");
806 MODULE_LICENSE("GPL");