tps6594-regulator.c (03c11eb3b16dc0058589751dfd91f254be2be613) tps6594-regulator.c (00c826525fbae0230f6c3e9879e56d50267deb42)
1// SPDX-License-Identifier: GPL-2.0
2//
3// Regulator driver for tps6594 PMIC
4//
5// Copyright (C) 2023 BayLibre Incorporated - https://www.baylibre.com/
6
7#include <linux/device.h>
8#include <linux/err.h>

--- 4 unchanged lines hidden (view full) ---

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>
18
19#include <linux/mfd/tps6594.h>
20
1// SPDX-License-Identifier: GPL-2.0
2//
3// Regulator driver for tps6594 PMIC
4//
5// Copyright (C) 2023 BayLibre Incorporated - https://www.baylibre.com/
6
7#include <linux/device.h>
8#include <linux/err.h>

--- 4 unchanged lines hidden (view full) ---

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>
18
19#include <linux/mfd/tps6594.h>
20
21#define BUCK_NB 5
22#define LDO_NB 4
23#define MULTI_PHASE_NB 4
24#define REGS_INT_NB 4
21#define BUCK_NB 5
22#define LDO_NB 4
23#define MULTI_PHASE_NB 4
24/* TPS6593 and LP8764 supports OV, UV, SC, ILIM */
25#define REGS_INT_NB 4
26/* TPS65224 supports OV or UV */
27#define TPS65224_REGS_INT_NB 1
25
26enum tps6594_regulator_id {
27 /* DCDC's */
28 TPS6594_BUCK_1,
29 TPS6594_BUCK_2,
30 TPS6594_BUCK_3,
31 TPS6594_BUCK_4,
32 TPS6594_BUCK_5,

--- 28 unchanged lines hidden (view full) ---

61 { TPS6594_IRQ_NAME_VMON1_RV, "VMON1", "residual voltage",
62 REGULATOR_EVENT_OVER_VOLTAGE_WARN },
63 { TPS6594_IRQ_NAME_VMON2_OV, "VMON2", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
64 { TPS6594_IRQ_NAME_VMON2_UV, "VMON2", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE },
65 { TPS6594_IRQ_NAME_VMON2_RV, "VMON2", "residual voltage",
66 REGULATOR_EVENT_OVER_VOLTAGE_WARN },
67};
68
28
29enum tps6594_regulator_id {
30 /* DCDC's */
31 TPS6594_BUCK_1,
32 TPS6594_BUCK_2,
33 TPS6594_BUCK_3,
34 TPS6594_BUCK_4,
35 TPS6594_BUCK_5,

--- 28 unchanged lines hidden (view full) ---

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 },
70};
71
72static 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 },
79};
80
69struct tps6594_regulator_irq_data {
70 struct device *dev;
71 struct tps6594_regulator_irq_type *type;
72 struct regulator_dev *rdev;
73};
74
75struct tps6594_ext_regulator_irq_data {
76 struct device *dev;

--- 40 unchanged lines hidden (view full) ---

117static const struct linear_range ldos_1_2_3_ranges[] = {
118 REGULATOR_LINEAR_RANGE(600000, 0x4, 0x3a, 50000),
119};
120
121static const struct linear_range ldos_4_ranges[] = {
122 REGULATOR_LINEAR_RANGE(1200000, 0x20, 0x74, 25000),
123};
124
81struct tps6594_regulator_irq_data {
82 struct device *dev;
83 struct tps6594_regulator_irq_type *type;
84 struct regulator_dev *rdev;
85};
86
87struct tps6594_ext_regulator_irq_data {
88 struct device *dev;

--- 40 unchanged lines hidden (view full) ---

129static const struct linear_range ldos_1_2_3_ranges[] = {
130 REGULATOR_LINEAR_RANGE(600000, 0x4, 0x3a, 50000),
131};
132
133static const struct linear_range ldos_4_ranges[] = {
134 REGULATOR_LINEAR_RANGE(1200000, 0x20, 0x74, 25000),
135};
136
137/* Voltage range for TPS65224 Bucks and LDOs */
138static 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),
143};
144
145static 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),
148};
149
150static const struct linear_range tps65224_ldos_1_ranges[] = {
151 REGULATOR_LINEAR_RANGE(1200000, 0xC, 0x36, 50000),
152};
153
154static const struct linear_range tps65224_ldos_2_3_ranges[] = {
155 REGULATOR_LINEAR_RANGE(600000, 0x0, 0x38, 50000),
156};
157
125/* Operations permitted on BUCK1/2/3/4/5 */
126static const struct regulator_ops tps6594_bucks_ops = {
127 .is_enabled = regulator_is_enabled_regmap,
128 .enable = regulator_enable_regmap,
129 .disable = regulator_disable_regmap,
130 .get_voltage_sel = regulator_get_voltage_sel_regmap,
131 .set_voltage_sel = regulator_set_voltage_sel_regmap,
132 .list_voltage = regulator_list_voltage_linear_range,

--- 59 unchanged lines hidden (view full) ---

192 REGULATOR_VOLTAGE, tps6594_bucks_ops, TPS6594_MASK_BUCKS_VSET,
193 TPS6594_REG_BUCKX_VOUT_1(4),
194 TPS6594_MASK_BUCKS_VSET,
195 TPS6594_REG_BUCKX_CTRL(4),
196 TPS6594_BIT_BUCK_EN, 0, 0, bucks_ranges,
197 4, 0, 0, NULL, 0, 0),
198};
199
158/* Operations permitted on BUCK1/2/3/4/5 */
159static 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,

--- 59 unchanged lines hidden (view full) ---

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),
231};
232
233/* Buck configuration for TPS65224 */
234static 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),
263};
264
200static struct tps6594_regulator_irq_type tps6594_buck1_irq_types[] = {
201 { TPS6594_IRQ_NAME_BUCK1_OV, "BUCK1", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
202 { TPS6594_IRQ_NAME_BUCK1_UV, "BUCK1", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE },
203 { TPS6594_IRQ_NAME_BUCK1_SC, "BUCK1", "short circuit", REGULATOR_EVENT_REGULATION_OUT },
204 { TPS6594_IRQ_NAME_BUCK1_ILIM, "BUCK1", "reach ilim, overcurrent",
205 REGULATOR_EVENT_OVER_CURRENT },
206};
207

--- 56 unchanged lines hidden (view full) ---

264static struct tps6594_regulator_irq_type tps6594_ldo4_irq_types[] = {
265 { TPS6594_IRQ_NAME_LDO4_OV, "LDO4", "overvoltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
266 { TPS6594_IRQ_NAME_LDO4_UV, "LDO4", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE },
267 { TPS6594_IRQ_NAME_LDO4_SC, "LDO4", "short circuit", REGULATOR_EVENT_REGULATION_OUT },
268 { TPS6594_IRQ_NAME_LDO4_ILIM, "LDO4", "reach ilim, overcurrent",
269 REGULATOR_EVENT_OVER_CURRENT },
270};
271
265static 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 },
271};
272

--- 56 unchanged lines hidden (view full) ---

329static 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 },
335};
336
337static 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 },
340};
341
342static 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 },
345};
346
347static 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 },
350};
351
352static 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 },
355};
356
357static 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 },
360};
361
362static 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 },
365};
366
367static 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 },
370};
371
272static struct tps6594_regulator_irq_type *tps6594_bucks_irq_types[] = {
273 tps6594_buck1_irq_types,
274 tps6594_buck2_irq_types,
275 tps6594_buck3_irq_types,
276 tps6594_buck4_irq_types,
277 tps6594_buck5_irq_types,
278};
279
280static struct tps6594_regulator_irq_type *tps6594_ldos_irq_types[] = {
281 tps6594_ldo1_irq_types,
282 tps6594_ldo2_irq_types,
283 tps6594_ldo3_irq_types,
284 tps6594_ldo4_irq_types,
285};
286
372static 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,
378};
379
380static 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,
385};
386
287static const struct regulator_desc multi_regs[] = {
387static 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,
392};
393
394static struct tps6594_regulator_irq_type *tps65224_ldos_irq_types[] = {
395 tps65224_ldo1_irq_types,
396 tps65224_ldo2_irq_types,
397 tps65224_ldo3_irq_types,
398};
399
400static const struct regulator_desc tps6594_multi_regs[] = {
288 TPS6594_REGULATOR("BUCK12", "buck12", TPS6594_BUCK_1,
289 REGULATOR_VOLTAGE, tps6594_bucks_ops, TPS6594_MASK_BUCKS_VSET,
290 TPS6594_REG_BUCKX_VOUT_1(1),
291 TPS6594_MASK_BUCKS_VSET,
292 TPS6594_REG_BUCKX_CTRL(1),
293 TPS6594_BIT_BUCK_EN, 0, 0, bucks_ranges,
294 4, 4000, 0, NULL, 0, 0),
295 TPS6594_REGULATOR("BUCK34", "buck34", TPS6594_BUCK_3,

--- 14 unchanged lines hidden (view full) ---

310 REGULATOR_VOLTAGE, tps6594_bucks_ops, TPS6594_MASK_BUCKS_VSET,
311 TPS6594_REG_BUCKX_VOUT_1(1),
312 TPS6594_MASK_BUCKS_VSET,
313 TPS6594_REG_BUCKX_CTRL(1),
314 TPS6594_BIT_BUCK_EN, 0, 0, bucks_ranges,
315 4, 4000, 0, NULL, 0, 0),
316};
317
401 TPS6594_REGULATOR("BUCK12", "buck12", TPS6594_BUCK_1,
402 REGULATOR_VOLTAGE, tps6594_bucks_ops, TPS6594_MASK_BUCKS_VSET,
403 TPS6594_REG_BUCKX_VOUT_1(1),
404 TPS6594_MASK_BUCKS_VSET,
405 TPS6594_REG_BUCKX_CTRL(1),
406 TPS6594_BIT_BUCK_EN, 0, 0, bucks_ranges,
407 4, 4000, 0, NULL, 0, 0),
408 TPS6594_REGULATOR("BUCK34", "buck34", TPS6594_BUCK_3,

--- 14 unchanged lines hidden (view full) ---

423 REGULATOR_VOLTAGE, tps6594_bucks_ops, TPS6594_MASK_BUCKS_VSET,
424 TPS6594_REG_BUCKX_VOUT_1(1),
425 TPS6594_MASK_BUCKS_VSET,
426 TPS6594_REG_BUCKX_CTRL(1),
427 TPS6594_BIT_BUCK_EN, 0, 0, bucks_ranges,
428 4, 4000, 0, NULL, 0, 0),
429};
430
318static const struct regulator_desc ldo_regs[] = {
431static 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),
439};
440
441static const struct regulator_desc tps6594_ldo_regs[] = {
319 TPS6594_REGULATOR("LDO1", "ldo1", TPS6594_LDO_1,
320 REGULATOR_VOLTAGE, tps6594_ldos_1_2_3_ops, TPS6594_MASK_LDO123_VSET,
321 TPS6594_REG_LDOX_VOUT(0),
322 TPS6594_MASK_LDO123_VSET,
323 TPS6594_REG_LDOX_CTRL(0),
324 TPS6594_BIT_LDO_EN, 0, 0, ldos_1_2_3_ranges,
325 1, 0, 0, NULL, 0, TPS6594_BIT_LDO_BYPASS),
326 TPS6594_REGULATOR("LDO2", "ldo2", TPS6594_LDO_2,

--- 14 unchanged lines hidden (view full) ---

341 REGULATOR_VOLTAGE, tps6594_ldos_4_ops, TPS6594_MASK_LDO4_VSET >> 1,
342 TPS6594_REG_LDOX_VOUT(3),
343 TPS6594_MASK_LDO4_VSET,
344 TPS6594_REG_LDOX_CTRL(3),
345 TPS6594_BIT_LDO_EN, 0, 0, ldos_4_ranges,
346 1, 0, 0, NULL, 0, 0),
347};
348
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,

--- 14 unchanged lines hidden (view full) ---

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),
470};
471
472static 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),
494};
495
349static irqreturn_t tps6594_regulator_irq_handler(int irq, void *data)
350{
351 struct tps6594_regulator_irq_data *irq_data = data;
352
353 if (irq_data->type->event_name[0] == '\0') {
354 /* This is the timeout interrupt no specific regulator */
355 dev_err(irq_data->dev,
356 "System was put in shutdown due to timeout during an active or standby transition.\n");

--- 7 unchanged lines hidden (view full) ---

364 irq_data->type->event, NULL);
365
366 return IRQ_HANDLED;
367}
368
369static int tps6594_request_reg_irqs(struct platform_device *pdev,
370 struct regulator_dev *rdev,
371 struct tps6594_regulator_irq_data *irq_data,
496static irqreturn_t tps6594_regulator_irq_handler(int irq, void *data)
497{
498 struct tps6594_regulator_irq_data *irq_data = data;
499
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");

--- 7 unchanged lines hidden (view full) ---

511 irq_data->type->event, NULL);
512
513 return IRQ_HANDLED;
514}
515
516static int tps6594_request_reg_irqs(struct platform_device *pdev,
517 struct regulator_dev *rdev,
518 struct tps6594_regulator_irq_data *irq_data,
372 struct tps6594_regulator_irq_type *tps6594_regs_irq_types,
519 struct tps6594_regulator_irq_type *regs_irq_types,
520 size_t interrupt_cnt,
373 int *irq_idx)
374{
375 struct tps6594_regulator_irq_type *irq_type;
376 struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent);
521 int *irq_idx)
522{
523 struct tps6594_regulator_irq_type *irq_type;
524 struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent);
377 int j;
525 size_t j;
378 int irq;
379 int error;
380
526 int irq;
527 int error;
528
381 for (j = 0; j < REGS_INT_NB; j++) {
382 irq_type = &tps6594_regs_irq_types[j];
529 for (j = 0; j < interrupt_cnt; j++) {
530 irq_type = &regs_irq_types[j];
383 irq = platform_get_irq_byname(pdev, irq_type->irq_name);
384 if (irq < 0)
385 return -EINVAL;
386
387 irq_data[*irq_idx].dev = tps->dev;
388 irq_data[*irq_idx].type = irq_type;
389 irq_data[*irq_idx].rdev = rdev;
390

--- 15 unchanged lines hidden (view full) ---

406 struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent);
407 struct regulator_dev *rdev;
408 struct device_node *np = NULL;
409 struct device_node *np_pmic_parent = NULL;
410 struct regulator_config config = {};
411 struct tps6594_regulator_irq_data *irq_data;
412 struct tps6594_ext_regulator_irq_data *irq_ext_reg_data;
413 struct tps6594_regulator_irq_type *irq_type;
531 irq = platform_get_irq_byname(pdev, irq_type->irq_name);
532 if (irq < 0)
533 return -EINVAL;
534
535 irq_data[*irq_idx].dev = tps->dev;
536 irq_data[*irq_idx].type = irq_type;
537 irq_data[*irq_idx].rdev = rdev;
538

--- 15 unchanged lines hidden (view full) ---

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;
414 u8 buck_configured[BUCK_NB] = { 0 };
415 u8 buck_multi[MULTI_PHASE_NB] = { 0 };
416 static const char * const multiphases[] = {"buck12", "buck123", "buck1234", "buck34"};
562 struct tps6594_regulator_irq_type *irq_types;
563 bool buck_configured[BUCK_NB] = { false };
564 bool buck_multi[MULTI_PHASE_NB] = { false };
565
417 static const char *npname;
566 static const char *npname;
418 int error, i, irq, multi, delta;
567 int error, i, irq, multi;
419 int irq_idx = 0;
420 int buck_idx = 0;
568 int irq_idx = 0;
569 int buck_idx = 0;
421 size_t ext_reg_irq_nb = 2;
570 int nr_ldo;
571 int nr_buck;
572 int nr_types;
573 unsigned int irq_count;
574 unsigned int multi_phase_cnt;
422 size_t reg_irq_nb;
575 size_t reg_irq_nb;
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;
581
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);
589 } else {
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);
596 }
597
423 enum {
424 MULTI_BUCK12,
598 enum {
599 MULTI_BUCK12,
600 MULTI_BUCK12_34,
425 MULTI_BUCK123,
426 MULTI_BUCK1234,
601 MULTI_BUCK123,
602 MULTI_BUCK1234,
427 MULTI_BUCK12_34,
428 MULTI_FIRST = MULTI_BUCK12,
429 MULTI_LAST = MULTI_BUCK12_34,
430 MULTI_NUM = MULTI_LAST - MULTI_FIRST + 1
431 };
432
433 config.dev = tps->dev;
434 config.driver_data = tps;
435 config.regmap = tps->regmap;
436
437 /*
438 * Switch case defines different possible multi phase config
439 * This is based on dts buck node name.
440 * Buck node name must be chosen accordingly.
441 * Default case is no Multiphase buck.
442 * In case of Multiphase configuration, value should be defined for
443 * buck_configured to avoid creating bucks for every buck in multiphase
444 */
603 };
604
605 config.dev = tps->dev;
606 config.driver_data = tps;
607 config.regmap = tps->regmap;
608
609 /*
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
616 */
445 for (multi = MULTI_FIRST; multi < MULTI_NUM; multi++) {
446 np = of_find_node_by_name(tps->dev->of_node, multiphases[multi]);
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);
447 npname = of_node_full_name(np);
448 np_pmic_parent = of_get_parent(of_get_parent(np));
449 if (of_node_cmp(of_node_full_name(np_pmic_parent), tps->dev->of_node->full_name))
450 continue;
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))
622 continue;
451 delta = strcmp(npname, multiphases[multi]);
452 if (!delta) {
623 if (strcmp(npname, multi_regs[multi].supply_name) == 0) {
453 switch (multi) {
454 case MULTI_BUCK12:
624 switch (multi) {
625 case MULTI_BUCK12:
455 buck_multi[0] = 1;
456 buck_configured[0] = 1;
457 buck_configured[1] = 1;
626 buck_multi[0] = true;
627 buck_configured[0] = true;
628 buck_configured[1] = true;
458 break;
459 /* multiphase buck34 is supported only with buck12 */
460 case MULTI_BUCK12_34:
629 break;
630 /* multiphase buck34 is supported only with buck12 */
631 case MULTI_BUCK12_34:
461 buck_multi[0] = 1;
462 buck_multi[1] = 1;
463 buck_configured[0] = 1;
464 buck_configured[1] = 1;
465 buck_configured[2] = 1;
466 buck_configured[3] = 1;
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;
467 break;
468 case MULTI_BUCK123:
638 break;
639 case MULTI_BUCK123:
469 buck_multi[2] = 1;
470 buck_configured[0] = 1;
471 buck_configured[1] = 1;
472 buck_configured[2] = 1;
640 buck_multi[2] = true;
641 buck_configured[0] = true;
642 buck_configured[1] = true;
643 buck_configured[2] = true;
473 break;
474 case MULTI_BUCK1234:
644 break;
645 case MULTI_BUCK1234:
475 buck_multi[3] = 1;
476 buck_configured[0] = 1;
477 buck_configured[1] = 1;
478 buck_configured[2] = 1;
479 buck_configured[3] = 1;
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;
480 break;
481 }
482 }
483 }
484
485 if (tps->chip_id == LP8764) {
651 break;
652 }
653 }
654 }
655
656 if (tps->chip_id == LP8764) {
486 /* There is only 4 buck on LP8764 */
487 buck_configured[4] = 1;
488 reg_irq_nb = size_mul(REGS_INT_NB, (BUCK_NB - 1));
657 nr_buck = ARRAY_SIZE(buck_regs);
658 nr_ldo = 0;
659 nr_types = REGS_INT_NB;
660 } else if (tps->chip_id == TPS65224) {
661 nr_buck = ARRAY_SIZE(tps65224_buck_regs);
662 nr_ldo = ARRAY_SIZE(tps65224_ldo_regs);
663 nr_types = REGS_INT_NB;
489 } else {
664 } else {
490 reg_irq_nb = size_mul(REGS_INT_NB, (size_add(BUCK_NB, LDO_NB)));
665 nr_buck = ARRAY_SIZE(buck_regs);
666 nr_ldo = ARRAY_SIZE(tps6594_ldo_regs);
667 nr_types = TPS65224_REGS_INT_NB;
491 }
492
668 }
669
670 reg_irq_nb = nr_types * (nr_buck + nr_ldo);
671
493 irq_data = devm_kmalloc_array(tps->dev, reg_irq_nb,
494 sizeof(struct tps6594_regulator_irq_data), GFP_KERNEL);
495 if (!irq_data)
496 return -ENOMEM;
497
672 irq_data = devm_kmalloc_array(tps->dev, reg_irq_nb,
673 sizeof(struct tps6594_regulator_irq_data), GFP_KERNEL);
674 if (!irq_data)
675 return -ENOMEM;
676
498 for (i = 0; i < MULTI_PHASE_NB; i++) {
499 if (buck_multi[i] == 0)
677 for (i = 0; i < multi_phase_cnt; i++) {
678 if (!buck_multi[i])
500 continue;
501
502 rdev = devm_regulator_register(&pdev->dev, &multi_regs[i], &config);
503 if (IS_ERR(rdev))
504 return dev_err_probe(tps->dev, PTR_ERR(rdev),
505 "failed to register %s regulator\n",
506 pdev->name);
507
508 /* config multiphase buck12+buck34 */
679 continue;
680
681 rdev = devm_regulator_register(&pdev->dev, &multi_regs[i], &config);
682 if (IS_ERR(rdev))
683 return dev_err_probe(tps->dev, PTR_ERR(rdev),
684 "failed to register %s regulator\n",
685 pdev->name);
686
687 /* config multiphase buck12+buck34 */
509 if (i == 1)
688 if (i == MULTI_BUCK12_34)
510 buck_idx = 2;
689 buck_idx = 2;
690
511 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
691 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
512 tps6594_bucks_irq_types[buck_idx], &irq_idx);
692 bucks_irq_types[buck_idx],
693 interrupt_count, &irq_idx);
513 if (error)
514 return error;
694 if (error)
695 return error;
696
515 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
697 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
516 tps6594_bucks_irq_types[buck_idx + 1], &irq_idx);
698 bucks_irq_types[buck_idx + 1],
699 interrupt_count, &irq_idx);
517 if (error)
518 return error;
519
700 if (error)
701 return error;
702
520 if (i == 2 || i == 3) {
703 if (i == MULTI_BUCK123 || i == MULTI_BUCK1234) {
521 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
522 tps6594_bucks_irq_types[buck_idx + 2],
704 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
705 tps6594_bucks_irq_types[buck_idx + 2],
706 interrupt_count,
523 &irq_idx);
524 if (error)
525 return error;
526 }
707 &irq_idx);
708 if (error)
709 return error;
710 }
527 if (i == 3) {
711 if (i == MULTI_BUCK1234) {
528 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
529 tps6594_bucks_irq_types[buck_idx + 3],
712 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
713 tps6594_bucks_irq_types[buck_idx + 3],
714 interrupt_count,
530 &irq_idx);
531 if (error)
532 return error;
533 }
534 }
535
715 &irq_idx);
716 if (error)
717 return error;
718 }
719 }
720
536 for (i = 0; i < BUCK_NB; i++) {
537 if (buck_configured[i] == 1)
721 for (i = 0; i < nr_buck; i++) {
722 if (buck_configured[i])
538 continue;
539
723 continue;
724
540 rdev = devm_regulator_register(&pdev->dev, &buck_regs[i], &config);
725 const struct regulator_desc *buck_cfg = (tps->chip_id == TPS65224) ?
726 tps65224_buck_regs : buck_regs;
727
728 rdev = devm_regulator_register(&pdev->dev, &buck_cfg[i], &config);
541 if (IS_ERR(rdev))
542 return dev_err_probe(tps->dev, PTR_ERR(rdev),
729 if (IS_ERR(rdev))
730 return dev_err_probe(tps->dev, PTR_ERR(rdev),
543 "failed to register %s regulator\n",
544 pdev->name);
731 "failed to register %s regulator\n", pdev->name);
545
546 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
732
733 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
547 tps6594_bucks_irq_types[i], &irq_idx);
734 bucks_irq_types[i], interrupt_count, &irq_idx);
548 if (error)
549 return error;
550 }
551
735 if (error)
736 return error;
737 }
738
552 /* LP8764 dosen't have LDO */
739 /* LP8764 doesn't have LDO */
553 if (tps->chip_id != LP8764) {
740 if (tps->chip_id != LP8764) {
554 for (i = 0; i < ARRAY_SIZE(ldo_regs); i++) {
741 for (i = 0; i < nr_ldo; i++) {
555 rdev = devm_regulator_register(&pdev->dev, &ldo_regs[i], &config);
556 if (IS_ERR(rdev))
557 return dev_err_probe(tps->dev, PTR_ERR(rdev),
558 "failed to register %s regulator\n",
559 pdev->name);
560
561 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
742 rdev = devm_regulator_register(&pdev->dev, &ldo_regs[i], &config);
743 if (IS_ERR(rdev))
744 return dev_err_probe(tps->dev, PTR_ERR(rdev),
745 "failed to register %s regulator\n",
746 pdev->name);
747
748 error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
562 tps6594_ldos_irq_types[i],
749 ldos_irq_types[i], interrupt_count,
563 &irq_idx);
564 if (error)
565 return error;
566 }
567 }
568
750 &irq_idx);
751 if (error)
752 return error;
753 }
754 }
755
569 if (tps->chip_id == LP8764)
570 ext_reg_irq_nb = ARRAY_SIZE(tps6594_ext_regulator_irq_types);
756 if (tps->chip_id == TPS65224) {
757 irq_types = tps65224_ext_regulator_irq_types;
758 irq_count = ARRAY_SIZE(tps65224_ext_regulator_irq_types);
759 } else {
760 irq_types = tps6594_ext_regulator_irq_types;
761 if (tps->chip_id == LP8764)
762 irq_count = ARRAY_SIZE(tps6594_ext_regulator_irq_types);
763 else
764 /* TPS6593 supports only VCCA OV and UV */
765 irq_count = 2;
766 }
571
572 irq_ext_reg_data = devm_kmalloc_array(tps->dev,
767
768 irq_ext_reg_data = devm_kmalloc_array(tps->dev,
573 ext_reg_irq_nb,
574 sizeof(struct tps6594_ext_regulator_irq_data),
575 GFP_KERNEL);
769 irq_count,
770 sizeof(struct tps6594_ext_regulator_irq_data),
771 GFP_KERNEL);
576 if (!irq_ext_reg_data)
577 return -ENOMEM;
578
772 if (!irq_ext_reg_data)
773 return -ENOMEM;
774
579 for (i = 0; i < ext_reg_irq_nb; ++i) {
580 irq_type = &tps6594_ext_regulator_irq_types[i];
581
775 for (i = 0; i < irq_count; ++i) {
776 irq_type = &irq_types[i];
582 irq = platform_get_irq_byname(pdev, irq_type->irq_name);
583 if (irq < 0)
584 return -EINVAL;
585
586 irq_ext_reg_data[i].dev = tps->dev;
587 irq_ext_reg_data[i].type = irq_type;
588
589 error = devm_request_threaded_irq(tps->dev, irq, NULL,

--- 15 unchanged lines hidden (view full) ---

605 },
606 .probe = tps6594_regulator_probe,
607};
608
609module_platform_driver(tps6594_regulator_driver);
610
611MODULE_ALIAS("platform:tps6594-regulator");
612MODULE_AUTHOR("Jerome Neanne <jneanne@baylibre.com>");
777 irq = platform_get_irq_byname(pdev, irq_type->irq_name);
778 if (irq < 0)
779 return -EINVAL;
780
781 irq_ext_reg_data[i].dev = tps->dev;
782 irq_ext_reg_data[i].type = irq_type;
783
784 error = devm_request_threaded_irq(tps->dev, irq, NULL,

--- 15 unchanged lines hidden (view full) ---

800 },
801 .probe = tps6594_regulator_probe,
802};
803
804module_platform_driver(tps6594_regulator_driver);
805
806MODULE_ALIAS("platform:tps6594-regulator");
807MODULE_AUTHOR("Jerome Neanne <jneanne@baylibre.com>");
808MODULE_AUTHOR("Nirmala Devi Mal Nadar <m.nirmaladevi@ltts.com>");
613MODULE_DESCRIPTION("TPS6594 voltage regulator driver");
614MODULE_LICENSE("GPL");
809MODULE_DESCRIPTION("TPS6594 voltage regulator driver");
810MODULE_LICENSE("GPL");