1 // SPDX-License-Identifier: GPL-2.0
4 * NXP PCA9450 pmic driver
8 #include <linux/gpio/consumer.h>
10 #include <linux/interrupt.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/regulator/driver.h>
16 #include <linux/regulator/machine.h>
17 #include <linux/regulator/of_regulator.h>
18 #include <linux/regulator/pca9450.h>
20 struct pc9450_dvs_config
{
21 unsigned int run_reg
; /* dvs0 */
22 unsigned int run_mask
;
23 unsigned int standby_reg
; /* dvs1 */
24 unsigned int standby_mask
;
27 struct pca9450_regulator_desc
{
28 struct regulator_desc desc
;
29 const struct pc9450_dvs_config dvs
;
34 struct regmap
*regmap
;
35 struct gpio_desc
*sd_vsel_gpio
;
36 enum pca9450_chip_type type
;
41 static const struct regmap_range pca9450_status_range
= {
42 .range_min
= PCA9450_REG_INT1
,
43 .range_max
= PCA9450_REG_PWRON_STAT
,
46 static const struct regmap_access_table pca9450_volatile_regs
= {
47 .yes_ranges
= &pca9450_status_range
,
51 static const struct regmap_config pca9450_regmap_config
= {
54 .volatile_table
= &pca9450_volatile_regs
,
55 .max_register
= PCA9450_MAX_REGISTER
- 1,
56 .cache_type
= REGCACHE_MAPLE
,
61 * BUCK1RAM[1:0] BUCK1 DVS ramp rate setting
67 static const unsigned int pca9450_dvs_buck_ramp_table
[] = {
68 25000, 12500, 6250, 3125
71 static const struct regulator_ops pca9450_dvs_buck_regulator_ops
= {
72 .enable
= regulator_enable_regmap
,
73 .disable
= regulator_disable_regmap
,
74 .is_enabled
= regulator_is_enabled_regmap
,
75 .list_voltage
= regulator_list_voltage_linear_range
,
76 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
77 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
78 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
79 .set_ramp_delay
= regulator_set_ramp_delay_regmap
,
82 static const struct regulator_ops pca9450_buck_regulator_ops
= {
83 .enable
= regulator_enable_regmap
,
84 .disable
= regulator_disable_regmap
,
85 .is_enabled
= regulator_is_enabled_regmap
,
86 .list_voltage
= regulator_list_voltage_linear_range
,
87 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
88 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
89 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
92 static const struct regulator_ops pca9450_ldo_regulator_ops
= {
93 .enable
= regulator_enable_regmap
,
94 .disable
= regulator_disable_regmap
,
95 .is_enabled
= regulator_is_enabled_regmap
,
96 .list_voltage
= regulator_list_voltage_linear_range
,
97 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
98 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
103 * 0.60 to 2.1875V (12.5mV step)
105 static const struct linear_range pca9450_dvs_buck_volts
[] = {
106 REGULATOR_LINEAR_RANGE(600000, 0x00, 0x7F, 12500),
111 * 0.65 to 2.2375V (12.5mV step)
113 static const struct linear_range pca9451a_dvs_buck_volts
[] = {
114 REGULATOR_LINEAR_RANGE(650000, 0x00, 0x7F, 12500),
119 * 0.6V to 3.4V (25mV step)
121 static const struct linear_range pca9450_buck_volts
[] = {
122 REGULATOR_LINEAR_RANGE(600000, 0x00, 0x70, 25000),
123 REGULATOR_LINEAR_RANGE(3400000, 0x71, 0x7F, 0),
130 static const struct linear_range pca9450_ldo1_volts
[] = {
131 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
132 REGULATOR_LINEAR_RANGE(3000000, 0x04, 0x07, 100000),
137 * 0.8 to 1.15V (50mV step)
139 static const struct linear_range pca9450_ldo2_volts
[] = {
140 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x07, 50000),
145 * 0.8 to 3.3V (100mV step)
147 static const struct linear_range pca9450_ldo34_volts
[] = {
148 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x19, 100000),
149 REGULATOR_LINEAR_RANGE(3300000, 0x1A, 0x1F, 0),
154 * 1.8 to 3.3V (100mV step)
156 static const struct linear_range pca9450_ldo5_volts
[] = {
157 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
160 static int buck_set_dvs(const struct regulator_desc
*desc
,
161 struct device_node
*np
, struct regmap
*regmap
,
162 char *prop
, unsigned int reg
, unsigned int mask
)
167 ret
= of_property_read_u32(np
, prop
, &uv
);
173 for (i
= 0; i
< desc
->n_voltages
; i
++) {
174 ret
= regulator_desc_list_voltage_linear_range(desc
, i
);
178 i
<<= ffs(desc
->vsel_mask
) - 1;
179 ret
= regmap_update_bits(regmap
, reg
, mask
, i
);
185 struct pca9450_regulator_desc
*regulator
= container_of(desc
,
186 struct pca9450_regulator_desc
, desc
);
188 /* Enable DVS control through PMIC_STBY_REQ for this BUCK */
189 ret
= regmap_update_bits(regmap
, regulator
->desc
.enable_reg
,
190 BUCK1_DVS_CTRL
, BUCK1_DVS_CTRL
);
195 static int pca9450_set_dvs_levels(struct device_node
*np
,
196 const struct regulator_desc
*desc
,
197 struct regulator_config
*cfg
)
199 struct pca9450_regulator_desc
*data
= container_of(desc
,
200 struct pca9450_regulator_desc
, desc
);
201 const struct pc9450_dvs_config
*dvs
= &data
->dvs
;
202 unsigned int reg
, mask
;
206 for (i
= 0; i
< PCA9450_DVS_LEVEL_MAX
; i
++) {
208 case PCA9450_DVS_LEVEL_RUN
:
209 prop
= "nxp,dvs-run-voltage";
211 mask
= dvs
->run_mask
;
213 case PCA9450_DVS_LEVEL_STANDBY
:
214 prop
= "nxp,dvs-standby-voltage";
215 reg
= dvs
->standby_reg
;
216 mask
= dvs
->standby_mask
;
222 ret
= buck_set_dvs(desc
, np
, cfg
->regmap
, prop
, reg
, mask
);
230 static const struct pca9450_regulator_desc pca9450a_regulators
[] = {
234 .of_match
= of_match_ptr("BUCK1"),
235 .regulators_node
= of_match_ptr("regulators"),
237 .ops
= &pca9450_dvs_buck_regulator_ops
,
238 .type
= REGULATOR_VOLTAGE
,
239 .n_voltages
= PCA9450_BUCK1_VOLTAGE_NUM
,
240 .linear_ranges
= pca9450_dvs_buck_volts
,
241 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
242 .vsel_reg
= PCA9450_REG_BUCK1OUT_DVS0
,
243 .vsel_mask
= BUCK1OUT_DVS0_MASK
,
244 .enable_reg
= PCA9450_REG_BUCK1CTRL
,
245 .enable_mask
= BUCK1_ENMODE_MASK
,
246 .ramp_reg
= PCA9450_REG_BUCK1CTRL
,
247 .ramp_mask
= BUCK1_RAMP_MASK
,
248 .ramp_delay_table
= pca9450_dvs_buck_ramp_table
,
249 .n_ramp_values
= ARRAY_SIZE(pca9450_dvs_buck_ramp_table
),
250 .owner
= THIS_MODULE
,
251 .of_parse_cb
= pca9450_set_dvs_levels
,
254 .run_reg
= PCA9450_REG_BUCK1OUT_DVS0
,
255 .run_mask
= BUCK1OUT_DVS0_MASK
,
256 .standby_reg
= PCA9450_REG_BUCK1OUT_DVS1
,
257 .standby_mask
= BUCK1OUT_DVS1_MASK
,
263 .of_match
= of_match_ptr("BUCK2"),
264 .regulators_node
= of_match_ptr("regulators"),
266 .ops
= &pca9450_dvs_buck_regulator_ops
,
267 .type
= REGULATOR_VOLTAGE
,
268 .n_voltages
= PCA9450_BUCK2_VOLTAGE_NUM
,
269 .linear_ranges
= pca9450_dvs_buck_volts
,
270 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
271 .vsel_reg
= PCA9450_REG_BUCK2OUT_DVS0
,
272 .vsel_mask
= BUCK2OUT_DVS0_MASK
,
273 .enable_reg
= PCA9450_REG_BUCK2CTRL
,
274 .enable_mask
= BUCK2_ENMODE_MASK
,
275 .ramp_reg
= PCA9450_REG_BUCK2CTRL
,
276 .ramp_mask
= BUCK2_RAMP_MASK
,
277 .ramp_delay_table
= pca9450_dvs_buck_ramp_table
,
278 .n_ramp_values
= ARRAY_SIZE(pca9450_dvs_buck_ramp_table
),
279 .owner
= THIS_MODULE
,
280 .of_parse_cb
= pca9450_set_dvs_levels
,
283 .run_reg
= PCA9450_REG_BUCK2OUT_DVS0
,
284 .run_mask
= BUCK2OUT_DVS0_MASK
,
285 .standby_reg
= PCA9450_REG_BUCK2OUT_DVS1
,
286 .standby_mask
= BUCK2OUT_DVS1_MASK
,
292 .of_match
= of_match_ptr("BUCK3"),
293 .regulators_node
= of_match_ptr("regulators"),
295 .ops
= &pca9450_dvs_buck_regulator_ops
,
296 .type
= REGULATOR_VOLTAGE
,
297 .n_voltages
= PCA9450_BUCK3_VOLTAGE_NUM
,
298 .linear_ranges
= pca9450_dvs_buck_volts
,
299 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
300 .vsel_reg
= PCA9450_REG_BUCK3OUT_DVS0
,
301 .vsel_mask
= BUCK3OUT_DVS0_MASK
,
302 .enable_reg
= PCA9450_REG_BUCK3CTRL
,
303 .enable_mask
= BUCK3_ENMODE_MASK
,
304 .ramp_reg
= PCA9450_REG_BUCK3CTRL
,
305 .ramp_mask
= BUCK3_RAMP_MASK
,
306 .ramp_delay_table
= pca9450_dvs_buck_ramp_table
,
307 .n_ramp_values
= ARRAY_SIZE(pca9450_dvs_buck_ramp_table
),
308 .owner
= THIS_MODULE
,
309 .of_parse_cb
= pca9450_set_dvs_levels
,
312 .run_reg
= PCA9450_REG_BUCK3OUT_DVS0
,
313 .run_mask
= BUCK3OUT_DVS0_MASK
,
314 .standby_reg
= PCA9450_REG_BUCK3OUT_DVS1
,
315 .standby_mask
= BUCK3OUT_DVS1_MASK
,
321 .of_match
= of_match_ptr("BUCK4"),
322 .regulators_node
= of_match_ptr("regulators"),
324 .ops
= &pca9450_buck_regulator_ops
,
325 .type
= REGULATOR_VOLTAGE
,
326 .n_voltages
= PCA9450_BUCK4_VOLTAGE_NUM
,
327 .linear_ranges
= pca9450_buck_volts
,
328 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
329 .vsel_reg
= PCA9450_REG_BUCK4OUT
,
330 .vsel_mask
= BUCK4OUT_MASK
,
331 .enable_reg
= PCA9450_REG_BUCK4CTRL
,
332 .enable_mask
= BUCK4_ENMODE_MASK
,
333 .owner
= THIS_MODULE
,
339 .of_match
= of_match_ptr("BUCK5"),
340 .regulators_node
= of_match_ptr("regulators"),
342 .ops
= &pca9450_buck_regulator_ops
,
343 .type
= REGULATOR_VOLTAGE
,
344 .n_voltages
= PCA9450_BUCK5_VOLTAGE_NUM
,
345 .linear_ranges
= pca9450_buck_volts
,
346 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
347 .vsel_reg
= PCA9450_REG_BUCK5OUT
,
348 .vsel_mask
= BUCK5OUT_MASK
,
349 .enable_reg
= PCA9450_REG_BUCK5CTRL
,
350 .enable_mask
= BUCK5_ENMODE_MASK
,
351 .owner
= THIS_MODULE
,
357 .of_match
= of_match_ptr("BUCK6"),
358 .regulators_node
= of_match_ptr("regulators"),
360 .ops
= &pca9450_buck_regulator_ops
,
361 .type
= REGULATOR_VOLTAGE
,
362 .n_voltages
= PCA9450_BUCK6_VOLTAGE_NUM
,
363 .linear_ranges
= pca9450_buck_volts
,
364 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
365 .vsel_reg
= PCA9450_REG_BUCK6OUT
,
366 .vsel_mask
= BUCK6OUT_MASK
,
367 .enable_reg
= PCA9450_REG_BUCK6CTRL
,
368 .enable_mask
= BUCK6_ENMODE_MASK
,
369 .owner
= THIS_MODULE
,
375 .of_match
= of_match_ptr("LDO1"),
376 .regulators_node
= of_match_ptr("regulators"),
378 .ops
= &pca9450_ldo_regulator_ops
,
379 .type
= REGULATOR_VOLTAGE
,
380 .n_voltages
= PCA9450_LDO1_VOLTAGE_NUM
,
381 .linear_ranges
= pca9450_ldo1_volts
,
382 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo1_volts
),
383 .vsel_reg
= PCA9450_REG_LDO1CTRL
,
384 .vsel_mask
= LDO1OUT_MASK
,
385 .enable_reg
= PCA9450_REG_LDO1CTRL
,
386 .enable_mask
= LDO1_EN_MASK
,
387 .owner
= THIS_MODULE
,
393 .of_match
= of_match_ptr("LDO2"),
394 .regulators_node
= of_match_ptr("regulators"),
396 .ops
= &pca9450_ldo_regulator_ops
,
397 .type
= REGULATOR_VOLTAGE
,
398 .n_voltages
= PCA9450_LDO2_VOLTAGE_NUM
,
399 .linear_ranges
= pca9450_ldo2_volts
,
400 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo2_volts
),
401 .vsel_reg
= PCA9450_REG_LDO2CTRL
,
402 .vsel_mask
= LDO2OUT_MASK
,
403 .enable_reg
= PCA9450_REG_LDO2CTRL
,
404 .enable_mask
= LDO2_EN_MASK
,
405 .owner
= THIS_MODULE
,
411 .of_match
= of_match_ptr("LDO3"),
412 .regulators_node
= of_match_ptr("regulators"),
414 .ops
= &pca9450_ldo_regulator_ops
,
415 .type
= REGULATOR_VOLTAGE
,
416 .n_voltages
= PCA9450_LDO3_VOLTAGE_NUM
,
417 .linear_ranges
= pca9450_ldo34_volts
,
418 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo34_volts
),
419 .vsel_reg
= PCA9450_REG_LDO3CTRL
,
420 .vsel_mask
= LDO3OUT_MASK
,
421 .enable_reg
= PCA9450_REG_LDO3CTRL
,
422 .enable_mask
= LDO3_EN_MASK
,
423 .owner
= THIS_MODULE
,
429 .of_match
= of_match_ptr("LDO4"),
430 .regulators_node
= of_match_ptr("regulators"),
432 .ops
= &pca9450_ldo_regulator_ops
,
433 .type
= REGULATOR_VOLTAGE
,
434 .n_voltages
= PCA9450_LDO4_VOLTAGE_NUM
,
435 .linear_ranges
= pca9450_ldo34_volts
,
436 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo34_volts
),
437 .vsel_reg
= PCA9450_REG_LDO4CTRL
,
438 .vsel_mask
= LDO4OUT_MASK
,
439 .enable_reg
= PCA9450_REG_LDO4CTRL
,
440 .enable_mask
= LDO4_EN_MASK
,
441 .owner
= THIS_MODULE
,
447 .of_match
= of_match_ptr("LDO5"),
448 .regulators_node
= of_match_ptr("regulators"),
450 .ops
= &pca9450_ldo_regulator_ops
,
451 .type
= REGULATOR_VOLTAGE
,
452 .n_voltages
= PCA9450_LDO5_VOLTAGE_NUM
,
453 .linear_ranges
= pca9450_ldo5_volts
,
454 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo5_volts
),
455 .vsel_reg
= PCA9450_REG_LDO5CTRL_H
,
456 .vsel_mask
= LDO5HOUT_MASK
,
457 .enable_reg
= PCA9450_REG_LDO5CTRL_H
,
458 .enable_mask
= LDO5H_EN_MASK
,
459 .owner
= THIS_MODULE
,
465 * Buck3 removed on PCA9450B and connected with Buck1 internal for dual phase
466 * on PCA9450C as no Buck3.
468 static const struct pca9450_regulator_desc pca9450bc_regulators
[] = {
472 .of_match
= of_match_ptr("BUCK1"),
473 .regulators_node
= of_match_ptr("regulators"),
475 .ops
= &pca9450_dvs_buck_regulator_ops
,
476 .type
= REGULATOR_VOLTAGE
,
477 .n_voltages
= PCA9450_BUCK1_VOLTAGE_NUM
,
478 .linear_ranges
= pca9450_dvs_buck_volts
,
479 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
480 .vsel_reg
= PCA9450_REG_BUCK1OUT_DVS0
,
481 .vsel_mask
= BUCK1OUT_DVS0_MASK
,
482 .enable_reg
= PCA9450_REG_BUCK1CTRL
,
483 .enable_mask
= BUCK1_ENMODE_MASK
,
484 .ramp_reg
= PCA9450_REG_BUCK1CTRL
,
485 .ramp_mask
= BUCK1_RAMP_MASK
,
486 .ramp_delay_table
= pca9450_dvs_buck_ramp_table
,
487 .n_ramp_values
= ARRAY_SIZE(pca9450_dvs_buck_ramp_table
),
488 .owner
= THIS_MODULE
,
489 .of_parse_cb
= pca9450_set_dvs_levels
,
492 .run_reg
= PCA9450_REG_BUCK1OUT_DVS0
,
493 .run_mask
= BUCK1OUT_DVS0_MASK
,
494 .standby_reg
= PCA9450_REG_BUCK1OUT_DVS1
,
495 .standby_mask
= BUCK1OUT_DVS1_MASK
,
501 .of_match
= of_match_ptr("BUCK2"),
502 .regulators_node
= of_match_ptr("regulators"),
504 .ops
= &pca9450_dvs_buck_regulator_ops
,
505 .type
= REGULATOR_VOLTAGE
,
506 .n_voltages
= PCA9450_BUCK2_VOLTAGE_NUM
,
507 .linear_ranges
= pca9450_dvs_buck_volts
,
508 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
509 .vsel_reg
= PCA9450_REG_BUCK2OUT_DVS0
,
510 .vsel_mask
= BUCK2OUT_DVS0_MASK
,
511 .enable_reg
= PCA9450_REG_BUCK2CTRL
,
512 .enable_mask
= BUCK2_ENMODE_MASK
,
513 .ramp_reg
= PCA9450_REG_BUCK2CTRL
,
514 .ramp_mask
= BUCK2_RAMP_MASK
,
515 .ramp_delay_table
= pca9450_dvs_buck_ramp_table
,
516 .n_ramp_values
= ARRAY_SIZE(pca9450_dvs_buck_ramp_table
),
517 .owner
= THIS_MODULE
,
518 .of_parse_cb
= pca9450_set_dvs_levels
,
521 .run_reg
= PCA9450_REG_BUCK2OUT_DVS0
,
522 .run_mask
= BUCK2OUT_DVS0_MASK
,
523 .standby_reg
= PCA9450_REG_BUCK2OUT_DVS1
,
524 .standby_mask
= BUCK2OUT_DVS1_MASK
,
530 .of_match
= of_match_ptr("BUCK4"),
531 .regulators_node
= of_match_ptr("regulators"),
533 .ops
= &pca9450_buck_regulator_ops
,
534 .type
= REGULATOR_VOLTAGE
,
535 .n_voltages
= PCA9450_BUCK4_VOLTAGE_NUM
,
536 .linear_ranges
= pca9450_buck_volts
,
537 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
538 .vsel_reg
= PCA9450_REG_BUCK4OUT
,
539 .vsel_mask
= BUCK4OUT_MASK
,
540 .enable_reg
= PCA9450_REG_BUCK4CTRL
,
541 .enable_mask
= BUCK4_ENMODE_MASK
,
542 .owner
= THIS_MODULE
,
548 .of_match
= of_match_ptr("BUCK5"),
549 .regulators_node
= of_match_ptr("regulators"),
551 .ops
= &pca9450_buck_regulator_ops
,
552 .type
= REGULATOR_VOLTAGE
,
553 .n_voltages
= PCA9450_BUCK5_VOLTAGE_NUM
,
554 .linear_ranges
= pca9450_buck_volts
,
555 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
556 .vsel_reg
= PCA9450_REG_BUCK5OUT
,
557 .vsel_mask
= BUCK5OUT_MASK
,
558 .enable_reg
= PCA9450_REG_BUCK5CTRL
,
559 .enable_mask
= BUCK5_ENMODE_MASK
,
560 .owner
= THIS_MODULE
,
566 .of_match
= of_match_ptr("BUCK6"),
567 .regulators_node
= of_match_ptr("regulators"),
569 .ops
= &pca9450_buck_regulator_ops
,
570 .type
= REGULATOR_VOLTAGE
,
571 .n_voltages
= PCA9450_BUCK6_VOLTAGE_NUM
,
572 .linear_ranges
= pca9450_buck_volts
,
573 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
574 .vsel_reg
= PCA9450_REG_BUCK6OUT
,
575 .vsel_mask
= BUCK6OUT_MASK
,
576 .enable_reg
= PCA9450_REG_BUCK6CTRL
,
577 .enable_mask
= BUCK6_ENMODE_MASK
,
578 .owner
= THIS_MODULE
,
584 .of_match
= of_match_ptr("LDO1"),
585 .regulators_node
= of_match_ptr("regulators"),
587 .ops
= &pca9450_ldo_regulator_ops
,
588 .type
= REGULATOR_VOLTAGE
,
589 .n_voltages
= PCA9450_LDO1_VOLTAGE_NUM
,
590 .linear_ranges
= pca9450_ldo1_volts
,
591 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo1_volts
),
592 .vsel_reg
= PCA9450_REG_LDO1CTRL
,
593 .vsel_mask
= LDO1OUT_MASK
,
594 .enable_reg
= PCA9450_REG_LDO1CTRL
,
595 .enable_mask
= LDO1_EN_MASK
,
596 .owner
= THIS_MODULE
,
602 .of_match
= of_match_ptr("LDO2"),
603 .regulators_node
= of_match_ptr("regulators"),
605 .ops
= &pca9450_ldo_regulator_ops
,
606 .type
= REGULATOR_VOLTAGE
,
607 .n_voltages
= PCA9450_LDO2_VOLTAGE_NUM
,
608 .linear_ranges
= pca9450_ldo2_volts
,
609 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo2_volts
),
610 .vsel_reg
= PCA9450_REG_LDO2CTRL
,
611 .vsel_mask
= LDO2OUT_MASK
,
612 .enable_reg
= PCA9450_REG_LDO2CTRL
,
613 .enable_mask
= LDO2_EN_MASK
,
614 .owner
= THIS_MODULE
,
620 .of_match
= of_match_ptr("LDO3"),
621 .regulators_node
= of_match_ptr("regulators"),
623 .ops
= &pca9450_ldo_regulator_ops
,
624 .type
= REGULATOR_VOLTAGE
,
625 .n_voltages
= PCA9450_LDO3_VOLTAGE_NUM
,
626 .linear_ranges
= pca9450_ldo34_volts
,
627 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo34_volts
),
628 .vsel_reg
= PCA9450_REG_LDO3CTRL
,
629 .vsel_mask
= LDO3OUT_MASK
,
630 .enable_reg
= PCA9450_REG_LDO3CTRL
,
631 .enable_mask
= LDO3_EN_MASK
,
632 .owner
= THIS_MODULE
,
638 .of_match
= of_match_ptr("LDO4"),
639 .regulators_node
= of_match_ptr("regulators"),
641 .ops
= &pca9450_ldo_regulator_ops
,
642 .type
= REGULATOR_VOLTAGE
,
643 .n_voltages
= PCA9450_LDO4_VOLTAGE_NUM
,
644 .linear_ranges
= pca9450_ldo34_volts
,
645 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo34_volts
),
646 .vsel_reg
= PCA9450_REG_LDO4CTRL
,
647 .vsel_mask
= LDO4OUT_MASK
,
648 .enable_reg
= PCA9450_REG_LDO4CTRL
,
649 .enable_mask
= LDO4_EN_MASK
,
650 .owner
= THIS_MODULE
,
656 .of_match
= of_match_ptr("LDO5"),
657 .regulators_node
= of_match_ptr("regulators"),
659 .ops
= &pca9450_ldo_regulator_ops
,
660 .type
= REGULATOR_VOLTAGE
,
661 .n_voltages
= PCA9450_LDO5_VOLTAGE_NUM
,
662 .linear_ranges
= pca9450_ldo5_volts
,
663 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo5_volts
),
664 .vsel_reg
= PCA9450_REG_LDO5CTRL_H
,
665 .vsel_mask
= LDO5HOUT_MASK
,
666 .enable_reg
= PCA9450_REG_LDO5CTRL_H
,
667 .enable_mask
= LDO5H_EN_MASK
,
668 .owner
= THIS_MODULE
,
673 static const struct pca9450_regulator_desc pca9451a_regulators
[] = {
677 .of_match
= of_match_ptr("BUCK1"),
678 .regulators_node
= of_match_ptr("regulators"),
680 .ops
= &pca9450_dvs_buck_regulator_ops
,
681 .type
= REGULATOR_VOLTAGE
,
682 .n_voltages
= PCA9450_BUCK1_VOLTAGE_NUM
,
683 .linear_ranges
= pca9451a_dvs_buck_volts
,
684 .n_linear_ranges
= ARRAY_SIZE(pca9451a_dvs_buck_volts
),
685 .vsel_reg
= PCA9450_REG_BUCK1OUT_DVS0
,
686 .vsel_mask
= BUCK1OUT_DVS0_MASK
,
687 .enable_reg
= PCA9450_REG_BUCK1CTRL
,
688 .enable_mask
= BUCK1_ENMODE_MASK
,
689 .enable_val
= BUCK_ENMODE_ONREQ
,
690 .ramp_mask
= BUCK1_RAMP_MASK
,
691 .ramp_delay_table
= pca9450_dvs_buck_ramp_table
,
692 .n_ramp_values
= ARRAY_SIZE(pca9450_dvs_buck_ramp_table
),
693 .owner
= THIS_MODULE
,
694 .of_parse_cb
= pca9450_set_dvs_levels
,
697 .run_reg
= PCA9450_REG_BUCK1OUT_DVS0
,
698 .run_mask
= BUCK1OUT_DVS0_MASK
,
699 .standby_reg
= PCA9450_REG_BUCK1OUT_DVS1
,
700 .standby_mask
= BUCK1OUT_DVS1_MASK
,
706 .of_match
= of_match_ptr("BUCK2"),
707 .regulators_node
= of_match_ptr("regulators"),
709 .ops
= &pca9450_dvs_buck_regulator_ops
,
710 .type
= REGULATOR_VOLTAGE
,
711 .n_voltages
= PCA9450_BUCK2_VOLTAGE_NUM
,
712 .linear_ranges
= pca9450_dvs_buck_volts
,
713 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
714 .vsel_reg
= PCA9450_REG_BUCK2OUT_DVS0
,
715 .vsel_mask
= BUCK2OUT_DVS0_MASK
,
716 .enable_reg
= PCA9450_REG_BUCK2CTRL
,
717 .enable_mask
= BUCK2_ENMODE_MASK
,
718 .enable_val
= BUCK_ENMODE_ONREQ_STBYREQ
,
719 .ramp_mask
= BUCK2_RAMP_MASK
,
720 .ramp_delay_table
= pca9450_dvs_buck_ramp_table
,
721 .n_ramp_values
= ARRAY_SIZE(pca9450_dvs_buck_ramp_table
),
722 .owner
= THIS_MODULE
,
723 .of_parse_cb
= pca9450_set_dvs_levels
,
726 .run_reg
= PCA9450_REG_BUCK2OUT_DVS0
,
727 .run_mask
= BUCK2OUT_DVS0_MASK
,
728 .standby_reg
= PCA9450_REG_BUCK2OUT_DVS1
,
729 .standby_mask
= BUCK2OUT_DVS1_MASK
,
735 .of_match
= of_match_ptr("BUCK4"),
736 .regulators_node
= of_match_ptr("regulators"),
738 .ops
= &pca9450_buck_regulator_ops
,
739 .type
= REGULATOR_VOLTAGE
,
740 .n_voltages
= PCA9450_BUCK4_VOLTAGE_NUM
,
741 .linear_ranges
= pca9450_buck_volts
,
742 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
743 .vsel_reg
= PCA9450_REG_BUCK4OUT
,
744 .vsel_mask
= BUCK4OUT_MASK
,
745 .enable_reg
= PCA9450_REG_BUCK4CTRL
,
746 .enable_mask
= BUCK4_ENMODE_MASK
,
747 .enable_val
= BUCK_ENMODE_ONREQ
,
748 .owner
= THIS_MODULE
,
754 .of_match
= of_match_ptr("BUCK5"),
755 .regulators_node
= of_match_ptr("regulators"),
757 .ops
= &pca9450_buck_regulator_ops
,
758 .type
= REGULATOR_VOLTAGE
,
759 .n_voltages
= PCA9450_BUCK5_VOLTAGE_NUM
,
760 .linear_ranges
= pca9450_buck_volts
,
761 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
762 .vsel_reg
= PCA9450_REG_BUCK5OUT
,
763 .vsel_mask
= BUCK5OUT_MASK
,
764 .enable_reg
= PCA9450_REG_BUCK5CTRL
,
765 .enable_mask
= BUCK5_ENMODE_MASK
,
766 .enable_val
= BUCK_ENMODE_ONREQ
,
767 .owner
= THIS_MODULE
,
773 .of_match
= of_match_ptr("BUCK6"),
774 .regulators_node
= of_match_ptr("regulators"),
776 .ops
= &pca9450_buck_regulator_ops
,
777 .type
= REGULATOR_VOLTAGE
,
778 .n_voltages
= PCA9450_BUCK6_VOLTAGE_NUM
,
779 .linear_ranges
= pca9450_buck_volts
,
780 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
781 .vsel_reg
= PCA9450_REG_BUCK6OUT
,
782 .vsel_mask
= BUCK6OUT_MASK
,
783 .enable_reg
= PCA9450_REG_BUCK6CTRL
,
784 .enable_mask
= BUCK6_ENMODE_MASK
,
785 .enable_val
= BUCK_ENMODE_ONREQ
,
786 .owner
= THIS_MODULE
,
792 .of_match
= of_match_ptr("LDO1"),
793 .regulators_node
= of_match_ptr("regulators"),
795 .ops
= &pca9450_ldo_regulator_ops
,
796 .type
= REGULATOR_VOLTAGE
,
797 .n_voltages
= PCA9450_LDO1_VOLTAGE_NUM
,
798 .linear_ranges
= pca9450_ldo1_volts
,
799 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo1_volts
),
800 .vsel_reg
= PCA9450_REG_LDO1CTRL
,
801 .vsel_mask
= LDO1OUT_MASK
,
802 .enable_reg
= PCA9450_REG_LDO1CTRL
,
803 .enable_mask
= LDO1_EN_MASK
,
804 .owner
= THIS_MODULE
,
810 .of_match
= of_match_ptr("LDO4"),
811 .regulators_node
= of_match_ptr("regulators"),
813 .ops
= &pca9450_ldo_regulator_ops
,
814 .type
= REGULATOR_VOLTAGE
,
815 .n_voltages
= PCA9450_LDO4_VOLTAGE_NUM
,
816 .linear_ranges
= pca9450_ldo34_volts
,
817 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo34_volts
),
818 .vsel_reg
= PCA9450_REG_LDO4CTRL
,
819 .vsel_mask
= LDO4OUT_MASK
,
820 .enable_reg
= PCA9450_REG_LDO4CTRL
,
821 .enable_mask
= LDO4_EN_MASK
,
822 .owner
= THIS_MODULE
,
828 .of_match
= of_match_ptr("LDO5"),
829 .regulators_node
= of_match_ptr("regulators"),
831 .ops
= &pca9450_ldo_regulator_ops
,
832 .type
= REGULATOR_VOLTAGE
,
833 .n_voltages
= PCA9450_LDO5_VOLTAGE_NUM
,
834 .linear_ranges
= pca9450_ldo5_volts
,
835 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo5_volts
),
836 .vsel_reg
= PCA9450_REG_LDO5CTRL_H
,
837 .vsel_mask
= LDO5HOUT_MASK
,
838 .enable_reg
= PCA9450_REG_LDO5CTRL_H
,
839 .enable_mask
= LDO5H_EN_MASK
,
840 .owner
= THIS_MODULE
,
845 static irqreturn_t
pca9450_irq_handler(int irq
, void *data
)
847 struct pca9450
*pca9450
= data
;
848 struct regmap
*regmap
= pca9450
->regmap
;
852 ret
= regmap_read(regmap
, PCA9450_REG_INT1
, &status
);
854 dev_err(pca9450
->dev
,
855 "Failed to read INT1(%d)\n", ret
);
859 if (status
& IRQ_PWRON
)
860 dev_warn(pca9450
->dev
, "PWRON interrupt.\n");
862 if (status
& IRQ_WDOGB
)
863 dev_warn(pca9450
->dev
, "WDOGB interrupt.\n");
865 if (status
& IRQ_VR_FLT1
)
866 dev_warn(pca9450
->dev
, "VRFLT1 interrupt.\n");
868 if (status
& IRQ_VR_FLT2
)
869 dev_warn(pca9450
->dev
, "VRFLT2 interrupt.\n");
871 if (status
& IRQ_LOWVSYS
)
872 dev_warn(pca9450
->dev
, "LOWVSYS interrupt.\n");
874 if (status
& IRQ_THERM_105
)
875 dev_warn(pca9450
->dev
, "IRQ_THERM_105 interrupt.\n");
877 if (status
& IRQ_THERM_125
)
878 dev_warn(pca9450
->dev
, "IRQ_THERM_125 interrupt.\n");
883 static int pca9450_i2c_probe(struct i2c_client
*i2c
)
885 enum pca9450_chip_type type
= (unsigned int)(uintptr_t)
886 of_device_get_match_data(&i2c
->dev
);
887 const struct pca9450_regulator_desc
*regulator_desc
;
888 struct regulator_config config
= { };
889 struct pca9450
*pca9450
;
890 unsigned int device_id
, i
;
891 unsigned int reset_ctrl
;
894 pca9450
= devm_kzalloc(&i2c
->dev
, sizeof(struct pca9450
), GFP_KERNEL
);
899 case PCA9450_TYPE_PCA9450A
:
900 regulator_desc
= pca9450a_regulators
;
901 pca9450
->rcnt
= ARRAY_SIZE(pca9450a_regulators
);
903 case PCA9450_TYPE_PCA9450BC
:
904 regulator_desc
= pca9450bc_regulators
;
905 pca9450
->rcnt
= ARRAY_SIZE(pca9450bc_regulators
);
907 case PCA9450_TYPE_PCA9451A
:
908 regulator_desc
= pca9451a_regulators
;
909 pca9450
->rcnt
= ARRAY_SIZE(pca9451a_regulators
);
912 dev_err(&i2c
->dev
, "Unknown device type");
916 pca9450
->irq
= i2c
->irq
;
917 pca9450
->type
= type
;
918 pca9450
->dev
= &i2c
->dev
;
920 dev_set_drvdata(&i2c
->dev
, pca9450
);
922 pca9450
->regmap
= devm_regmap_init_i2c(i2c
,
923 &pca9450_regmap_config
);
924 if (IS_ERR(pca9450
->regmap
)) {
925 dev_err(&i2c
->dev
, "regmap initialization failed\n");
926 return PTR_ERR(pca9450
->regmap
);
929 ret
= regmap_read(pca9450
->regmap
, PCA9450_REG_DEV_ID
, &device_id
);
931 dev_err(&i2c
->dev
, "Read device id error\n");
935 /* Check your board and dts for match the right pmic */
936 if (((device_id
>> 4) != 0x1 && type
== PCA9450_TYPE_PCA9450A
) ||
937 ((device_id
>> 4) != 0x3 && type
== PCA9450_TYPE_PCA9450BC
) ||
938 ((device_id
>> 4) != 0x9 && type
== PCA9450_TYPE_PCA9451A
)) {
939 dev_err(&i2c
->dev
, "Device id(%x) mismatched\n",
944 for (i
= 0; i
< pca9450
->rcnt
; i
++) {
945 const struct regulator_desc
*desc
;
946 struct regulator_dev
*rdev
;
947 const struct pca9450_regulator_desc
*r
;
949 r
= ®ulator_desc
[i
];
952 config
.regmap
= pca9450
->regmap
;
953 config
.dev
= pca9450
->dev
;
955 rdev
= devm_regulator_register(pca9450
->dev
, desc
, &config
);
958 dev_err(pca9450
->dev
,
959 "Failed to register regulator(%s): %d\n",
966 ret
= devm_request_threaded_irq(pca9450
->dev
, pca9450
->irq
, NULL
,
968 (IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
),
969 "pca9450-irq", pca9450
);
971 dev_err(pca9450
->dev
, "Failed to request IRQ: %d\n",
975 /* Unmask all interrupt except PWRON/WDOG/RSVD */
976 ret
= regmap_update_bits(pca9450
->regmap
, PCA9450_REG_INT1_MSK
,
977 IRQ_VR_FLT1
| IRQ_VR_FLT2
| IRQ_LOWVSYS
|
978 IRQ_THERM_105
| IRQ_THERM_125
,
979 IRQ_PWRON
| IRQ_WDOGB
| IRQ_RSVD
);
981 dev_err(&i2c
->dev
, "Unmask irq error\n");
986 /* Clear PRESET_EN bit in BUCK123_DVS to use DVS registers */
987 ret
= regmap_clear_bits(pca9450
->regmap
, PCA9450_REG_BUCK123_DVS
,
990 dev_err(&i2c
->dev
, "Failed to clear PRESET_EN bit: %d\n", ret
);
994 if (of_property_read_bool(i2c
->dev
.of_node
, "nxp,wdog_b-warm-reset"))
995 reset_ctrl
= WDOG_B_CFG_WARM
;
997 reset_ctrl
= WDOG_B_CFG_COLD_LDO12
;
999 /* Set reset behavior on assertion of WDOG_B signal */
1000 ret
= regmap_update_bits(pca9450
->regmap
, PCA9450_REG_RESET_CTRL
,
1001 WDOG_B_CFG_MASK
, reset_ctrl
);
1003 dev_err(&i2c
->dev
, "Failed to set WDOG_B reset behavior\n");
1007 if (of_property_read_bool(i2c
->dev
.of_node
, "nxp,i2c-lt-enable")) {
1008 /* Enable I2C Level Translator */
1009 ret
= regmap_update_bits(pca9450
->regmap
, PCA9450_REG_CONFIG2
,
1010 I2C_LT_MASK
, I2C_LT_ON_STANDBY_RUN
);
1013 "Failed to enable I2C level translator\n");
1019 * The driver uses the LDO5CTRL_H register to control the LDO5 regulator.
1020 * This is only valid if the SD_VSEL input of the PMIC is high. Let's
1021 * check if the pin is available as GPIO and set it to high.
1023 pca9450
->sd_vsel_gpio
= gpiod_get_optional(pca9450
->dev
, "sd-vsel", GPIOD_OUT_HIGH
);
1025 if (IS_ERR(pca9450
->sd_vsel_gpio
)) {
1026 dev_err(&i2c
->dev
, "Failed to get SD_VSEL GPIO\n");
1027 return PTR_ERR(pca9450
->sd_vsel_gpio
);
1030 dev_info(&i2c
->dev
, "%s probed.\n",
1031 type
== PCA9450_TYPE_PCA9450A
? "pca9450a" :
1032 (type
== PCA9450_TYPE_PCA9451A
? "pca9451a" : "pca9450bc"));
1037 static const struct of_device_id pca9450_of_match
[] = {
1039 .compatible
= "nxp,pca9450a",
1040 .data
= (void *)PCA9450_TYPE_PCA9450A
,
1043 .compatible
= "nxp,pca9450b",
1044 .data
= (void *)PCA9450_TYPE_PCA9450BC
,
1047 .compatible
= "nxp,pca9450c",
1048 .data
= (void *)PCA9450_TYPE_PCA9450BC
,
1051 .compatible
= "nxp,pca9451a",
1052 .data
= (void *)PCA9450_TYPE_PCA9451A
,
1056 MODULE_DEVICE_TABLE(of
, pca9450_of_match
);
1058 static struct i2c_driver pca9450_i2c_driver
= {
1060 .name
= "nxp-pca9450",
1061 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
1062 .of_match_table
= pca9450_of_match
,
1064 .probe
= pca9450_i2c_probe
,
1067 module_i2c_driver(pca9450_i2c_driver
);
1069 MODULE_AUTHOR("Robin Gong <yibin.gong@nxp.com>");
1070 MODULE_DESCRIPTION("NXP PCA9450 Power Management IC driver");
1071 MODULE_LICENSE("GPL");