1 // SPDX-License-Identifier: GPL-2.0
4 * NXP PCA9450 pmic driver
9 #include <linux/interrupt.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
13 #include <linux/of_device.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 enum pca9450_chip_type type
;
40 static const struct regmap_range pca9450_status_range
= {
41 .range_min
= PCA9450_REG_INT1
,
42 .range_max
= PCA9450_REG_PWRON_STAT
,
45 static const struct regmap_access_table pca9450_volatile_regs
= {
46 .yes_ranges
= &pca9450_status_range
,
50 static const struct regmap_config pca9450_regmap_config
= {
53 .volatile_table
= &pca9450_volatile_regs
,
54 .max_register
= PCA9450_MAX_REGISTER
- 1,
55 .cache_type
= REGCACHE_RBTREE
,
60 * BUCK1RAM[1:0] BUCK1 DVS ramp rate setting
66 static int pca9450_dvs_set_ramp_delay(struct regulator_dev
*rdev
,
69 int id
= rdev_get_id(rdev
);
70 unsigned int ramp_value
;
74 ramp_value
= BUCK1_RAMP_3P125MV
;
77 ramp_value
= BUCK1_RAMP_6P25MV
;
80 ramp_value
= BUCK1_RAMP_12P5MV
;
83 ramp_value
= BUCK1_RAMP_25MV
;
86 ramp_value
= BUCK1_RAMP_25MV
;
89 return regmap_update_bits(rdev
->regmap
, PCA9450_REG_BUCK1CTRL
+ id
* 3,
90 BUCK1_RAMP_MASK
, ramp_value
<< 6);
93 static const struct regulator_ops pca9450_dvs_buck_regulator_ops
= {
94 .enable
= regulator_enable_regmap
,
95 .disable
= regulator_disable_regmap
,
96 .is_enabled
= regulator_is_enabled_regmap
,
97 .list_voltage
= regulator_list_voltage_linear_range
,
98 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
99 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
100 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
101 .set_ramp_delay
= pca9450_dvs_set_ramp_delay
,
104 static const struct regulator_ops pca9450_buck_regulator_ops
= {
105 .enable
= regulator_enable_regmap
,
106 .disable
= regulator_disable_regmap
,
107 .is_enabled
= regulator_is_enabled_regmap
,
108 .list_voltage
= regulator_list_voltage_linear_range
,
109 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
110 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
111 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
114 static const struct regulator_ops pca9450_ldo_regulator_ops
= {
115 .enable
= regulator_enable_regmap
,
116 .disable
= regulator_disable_regmap
,
117 .is_enabled
= regulator_is_enabled_regmap
,
118 .list_voltage
= regulator_list_voltage_linear_range
,
119 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
120 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
125 * 0.60 to 2.1875V (12.5mV step)
127 static const struct linear_range pca9450_dvs_buck_volts
[] = {
128 REGULATOR_LINEAR_RANGE(600000, 0x00, 0x7F, 12500),
133 * 0.6V to 3.4V (25mV step)
135 static const struct linear_range pca9450_buck_volts
[] = {
136 REGULATOR_LINEAR_RANGE(600000, 0x00, 0x70, 25000),
137 REGULATOR_LINEAR_RANGE(3400000, 0x71, 0x7F, 0),
144 static const struct linear_range pca9450_ldo1_volts
[] = {
145 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
146 REGULATOR_LINEAR_RANGE(3000000, 0x04, 0x07, 100000),
151 * 0.8 to 1.15V (50mV step)
153 static const struct linear_range pca9450_ldo2_volts
[] = {
154 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x07, 50000),
159 * 0.8 to 3.3V (100mV step)
161 static const struct linear_range pca9450_ldo34_volts
[] = {
162 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x19, 100000),
163 REGULATOR_LINEAR_RANGE(3300000, 0x1A, 0x1F, 0),
168 * 1.8 to 3.3V (100mV step)
170 static const struct linear_range pca9450_ldo5_volts
[] = {
171 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
174 static int buck_set_dvs(const struct regulator_desc
*desc
,
175 struct device_node
*np
, struct regmap
*regmap
,
176 char *prop
, unsigned int reg
, unsigned int mask
)
181 ret
= of_property_read_u32(np
, prop
, &uv
);
187 for (i
= 0; i
< desc
->n_voltages
; i
++) {
188 ret
= regulator_desc_list_voltage_linear_range(desc
, i
);
192 i
<<= ffs(desc
->vsel_mask
) - 1;
193 ret
= regmap_update_bits(regmap
, reg
, mask
, i
);
201 static int pca9450_set_dvs_levels(struct device_node
*np
,
202 const struct regulator_desc
*desc
,
203 struct regulator_config
*cfg
)
205 struct pca9450_regulator_desc
*data
= container_of(desc
,
206 struct pca9450_regulator_desc
, desc
);
207 const struct pc9450_dvs_config
*dvs
= &data
->dvs
;
208 unsigned int reg
, mask
;
212 for (i
= 0; i
< PCA9450_DVS_LEVEL_MAX
; i
++) {
214 case PCA9450_DVS_LEVEL_RUN
:
215 prop
= "nxp,dvs-run-voltage";
217 mask
= dvs
->run_mask
;
219 case PCA9450_DVS_LEVEL_STANDBY
:
220 prop
= "nxp,dvs-standby-voltage";
221 reg
= dvs
->standby_reg
;
222 mask
= dvs
->standby_mask
;
228 ret
= buck_set_dvs(desc
, np
, cfg
->regmap
, prop
, reg
, mask
);
236 static const struct pca9450_regulator_desc pca9450a_regulators
[] = {
240 .of_match
= of_match_ptr("BUCK1"),
241 .regulators_node
= of_match_ptr("regulators"),
243 .ops
= &pca9450_dvs_buck_regulator_ops
,
244 .type
= REGULATOR_VOLTAGE
,
245 .n_voltages
= PCA9450_BUCK1_VOLTAGE_NUM
,
246 .linear_ranges
= pca9450_dvs_buck_volts
,
247 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
248 .vsel_reg
= PCA9450_REG_BUCK1OUT_DVS0
,
249 .vsel_mask
= BUCK1OUT_DVS0_MASK
,
250 .enable_reg
= PCA9450_REG_BUCK1CTRL
,
251 .enable_mask
= BUCK1_ENMODE_MASK
,
252 .owner
= THIS_MODULE
,
253 .of_parse_cb
= pca9450_set_dvs_levels
,
256 .run_reg
= PCA9450_REG_BUCK1OUT_DVS0
,
257 .run_mask
= BUCK1OUT_DVS0_MASK
,
258 .standby_reg
= PCA9450_REG_BUCK1OUT_DVS1
,
259 .standby_mask
= BUCK1OUT_DVS1_MASK
,
265 .of_match
= of_match_ptr("BUCK2"),
266 .regulators_node
= of_match_ptr("regulators"),
268 .ops
= &pca9450_dvs_buck_regulator_ops
,
269 .type
= REGULATOR_VOLTAGE
,
270 .n_voltages
= PCA9450_BUCK2_VOLTAGE_NUM
,
271 .linear_ranges
= pca9450_dvs_buck_volts
,
272 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
273 .vsel_reg
= PCA9450_REG_BUCK2OUT_DVS0
,
274 .vsel_mask
= BUCK2OUT_DVS0_MASK
,
275 .enable_reg
= PCA9450_REG_BUCK2CTRL
,
276 .enable_mask
= BUCK1_ENMODE_MASK
,
277 .owner
= THIS_MODULE
,
278 .of_parse_cb
= pca9450_set_dvs_levels
,
281 .run_reg
= PCA9450_REG_BUCK2OUT_DVS0
,
282 .run_mask
= BUCK2OUT_DVS0_MASK
,
283 .standby_reg
= PCA9450_REG_BUCK2OUT_DVS1
,
284 .standby_mask
= BUCK2OUT_DVS1_MASK
,
290 .of_match
= of_match_ptr("BUCK3"),
291 .regulators_node
= of_match_ptr("regulators"),
293 .ops
= &pca9450_dvs_buck_regulator_ops
,
294 .type
= REGULATOR_VOLTAGE
,
295 .n_voltages
= PCA9450_BUCK3_VOLTAGE_NUM
,
296 .linear_ranges
= pca9450_dvs_buck_volts
,
297 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
298 .vsel_reg
= PCA9450_REG_BUCK3OUT_DVS0
,
299 .vsel_mask
= BUCK3OUT_DVS0_MASK
,
300 .enable_reg
= PCA9450_REG_BUCK3CTRL
,
301 .enable_mask
= BUCK3_ENMODE_MASK
,
302 .owner
= THIS_MODULE
,
303 .of_parse_cb
= pca9450_set_dvs_levels
,
306 .run_reg
= PCA9450_REG_BUCK3OUT_DVS0
,
307 .run_mask
= BUCK3OUT_DVS0_MASK
,
308 .standby_reg
= PCA9450_REG_BUCK3OUT_DVS1
,
309 .standby_mask
= BUCK3OUT_DVS1_MASK
,
315 .of_match
= of_match_ptr("BUCK4"),
316 .regulators_node
= of_match_ptr("regulators"),
318 .ops
= &pca9450_buck_regulator_ops
,
319 .type
= REGULATOR_VOLTAGE
,
320 .n_voltages
= PCA9450_BUCK4_VOLTAGE_NUM
,
321 .linear_ranges
= pca9450_buck_volts
,
322 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
323 .vsel_reg
= PCA9450_REG_BUCK4OUT
,
324 .vsel_mask
= BUCK4OUT_MASK
,
325 .enable_reg
= PCA9450_REG_BUCK4CTRL
,
326 .enable_mask
= BUCK4_ENMODE_MASK
,
327 .owner
= THIS_MODULE
,
333 .of_match
= of_match_ptr("BUCK5"),
334 .regulators_node
= of_match_ptr("regulators"),
336 .ops
= &pca9450_buck_regulator_ops
,
337 .type
= REGULATOR_VOLTAGE
,
338 .n_voltages
= PCA9450_BUCK5_VOLTAGE_NUM
,
339 .linear_ranges
= pca9450_buck_volts
,
340 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
341 .vsel_reg
= PCA9450_REG_BUCK5OUT
,
342 .vsel_mask
= BUCK5OUT_MASK
,
343 .enable_reg
= PCA9450_REG_BUCK5CTRL
,
344 .enable_mask
= BUCK5_ENMODE_MASK
,
345 .owner
= THIS_MODULE
,
351 .of_match
= of_match_ptr("BUCK6"),
352 .regulators_node
= of_match_ptr("regulators"),
354 .ops
= &pca9450_buck_regulator_ops
,
355 .type
= REGULATOR_VOLTAGE
,
356 .n_voltages
= PCA9450_BUCK6_VOLTAGE_NUM
,
357 .linear_ranges
= pca9450_buck_volts
,
358 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
359 .vsel_reg
= PCA9450_REG_BUCK6OUT
,
360 .vsel_mask
= BUCK6OUT_MASK
,
361 .enable_reg
= PCA9450_REG_BUCK6CTRL
,
362 .enable_mask
= BUCK6_ENMODE_MASK
,
363 .owner
= THIS_MODULE
,
369 .of_match
= of_match_ptr("LDO1"),
370 .regulators_node
= of_match_ptr("regulators"),
372 .ops
= &pca9450_ldo_regulator_ops
,
373 .type
= REGULATOR_VOLTAGE
,
374 .n_voltages
= PCA9450_LDO1_VOLTAGE_NUM
,
375 .linear_ranges
= pca9450_ldo1_volts
,
376 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo1_volts
),
377 .vsel_reg
= PCA9450_REG_LDO1CTRL
,
378 .vsel_mask
= LDO1OUT_MASK
,
379 .enable_reg
= PCA9450_REG_LDO1CTRL
,
380 .enable_mask
= LDO1_EN_MASK
,
381 .owner
= THIS_MODULE
,
387 .of_match
= of_match_ptr("LDO2"),
388 .regulators_node
= of_match_ptr("regulators"),
390 .ops
= &pca9450_ldo_regulator_ops
,
391 .type
= REGULATOR_VOLTAGE
,
392 .n_voltages
= PCA9450_LDO2_VOLTAGE_NUM
,
393 .linear_ranges
= pca9450_ldo2_volts
,
394 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo2_volts
),
395 .vsel_reg
= PCA9450_REG_LDO2CTRL
,
396 .vsel_mask
= LDO2OUT_MASK
,
397 .enable_reg
= PCA9450_REG_LDO2CTRL
,
398 .enable_mask
= LDO2_EN_MASK
,
399 .owner
= THIS_MODULE
,
405 .of_match
= of_match_ptr("LDO3"),
406 .regulators_node
= of_match_ptr("regulators"),
408 .ops
= &pca9450_ldo_regulator_ops
,
409 .type
= REGULATOR_VOLTAGE
,
410 .n_voltages
= PCA9450_LDO3_VOLTAGE_NUM
,
411 .linear_ranges
= pca9450_ldo34_volts
,
412 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo34_volts
),
413 .vsel_reg
= PCA9450_REG_LDO3CTRL
,
414 .vsel_mask
= LDO3OUT_MASK
,
415 .enable_reg
= PCA9450_REG_LDO3CTRL
,
416 .enable_mask
= LDO3_EN_MASK
,
417 .owner
= THIS_MODULE
,
423 .of_match
= of_match_ptr("LDO4"),
424 .regulators_node
= of_match_ptr("regulators"),
426 .ops
= &pca9450_ldo_regulator_ops
,
427 .type
= REGULATOR_VOLTAGE
,
428 .n_voltages
= PCA9450_LDO4_VOLTAGE_NUM
,
429 .linear_ranges
= pca9450_ldo34_volts
,
430 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo34_volts
),
431 .vsel_reg
= PCA9450_REG_LDO4CTRL
,
432 .vsel_mask
= LDO4OUT_MASK
,
433 .enable_reg
= PCA9450_REG_LDO4CTRL
,
434 .enable_mask
= LDO4_EN_MASK
,
435 .owner
= THIS_MODULE
,
441 .of_match
= of_match_ptr("LDO5"),
442 .regulators_node
= of_match_ptr("regulators"),
444 .ops
= &pca9450_ldo_regulator_ops
,
445 .type
= REGULATOR_VOLTAGE
,
446 .n_voltages
= PCA9450_LDO5_VOLTAGE_NUM
,
447 .linear_ranges
= pca9450_ldo5_volts
,
448 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo5_volts
),
449 .vsel_reg
= PCA9450_REG_LDO5CTRL_H
,
450 .vsel_mask
= LDO5HOUT_MASK
,
451 .enable_reg
= PCA9450_REG_LDO5CTRL_H
,
452 .enable_mask
= LDO5H_EN_MASK
,
453 .owner
= THIS_MODULE
,
459 * Buck3 removed on PCA9450B and connected with Buck1 internal for dual phase
460 * on PCA9450C as no Buck3.
462 static const struct pca9450_regulator_desc pca9450bc_regulators
[] = {
466 .of_match
= of_match_ptr("BUCK1"),
467 .regulators_node
= of_match_ptr("regulators"),
469 .ops
= &pca9450_dvs_buck_regulator_ops
,
470 .type
= REGULATOR_VOLTAGE
,
471 .n_voltages
= PCA9450_BUCK1_VOLTAGE_NUM
,
472 .linear_ranges
= pca9450_dvs_buck_volts
,
473 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
474 .vsel_reg
= PCA9450_REG_BUCK1OUT_DVS0
,
475 .vsel_mask
= BUCK1OUT_DVS0_MASK
,
476 .enable_reg
= PCA9450_REG_BUCK1CTRL
,
477 .enable_mask
= BUCK1_ENMODE_MASK
,
478 .owner
= THIS_MODULE
,
479 .of_parse_cb
= pca9450_set_dvs_levels
,
482 .run_reg
= PCA9450_REG_BUCK1OUT_DVS0
,
483 .run_mask
= BUCK1OUT_DVS0_MASK
,
484 .standby_reg
= PCA9450_REG_BUCK1OUT_DVS1
,
485 .standby_mask
= BUCK1OUT_DVS1_MASK
,
491 .of_match
= of_match_ptr("BUCK2"),
492 .regulators_node
= of_match_ptr("regulators"),
494 .ops
= &pca9450_dvs_buck_regulator_ops
,
495 .type
= REGULATOR_VOLTAGE
,
496 .n_voltages
= PCA9450_BUCK2_VOLTAGE_NUM
,
497 .linear_ranges
= pca9450_dvs_buck_volts
,
498 .n_linear_ranges
= ARRAY_SIZE(pca9450_dvs_buck_volts
),
499 .vsel_reg
= PCA9450_REG_BUCK2OUT_DVS0
,
500 .vsel_mask
= BUCK2OUT_DVS0_MASK
,
501 .enable_reg
= PCA9450_REG_BUCK2CTRL
,
502 .enable_mask
= BUCK1_ENMODE_MASK
,
503 .owner
= THIS_MODULE
,
504 .of_parse_cb
= pca9450_set_dvs_levels
,
507 .run_reg
= PCA9450_REG_BUCK2OUT_DVS0
,
508 .run_mask
= BUCK2OUT_DVS0_MASK
,
509 .standby_reg
= PCA9450_REG_BUCK2OUT_DVS1
,
510 .standby_mask
= BUCK2OUT_DVS1_MASK
,
516 .of_match
= of_match_ptr("BUCK4"),
517 .regulators_node
= of_match_ptr("regulators"),
519 .ops
= &pca9450_buck_regulator_ops
,
520 .type
= REGULATOR_VOLTAGE
,
521 .n_voltages
= PCA9450_BUCK4_VOLTAGE_NUM
,
522 .linear_ranges
= pca9450_buck_volts
,
523 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
524 .vsel_reg
= PCA9450_REG_BUCK4OUT
,
525 .vsel_mask
= BUCK4OUT_MASK
,
526 .enable_reg
= PCA9450_REG_BUCK4CTRL
,
527 .enable_mask
= BUCK4_ENMODE_MASK
,
528 .owner
= THIS_MODULE
,
534 .of_match
= of_match_ptr("BUCK5"),
535 .regulators_node
= of_match_ptr("regulators"),
537 .ops
= &pca9450_buck_regulator_ops
,
538 .type
= REGULATOR_VOLTAGE
,
539 .n_voltages
= PCA9450_BUCK5_VOLTAGE_NUM
,
540 .linear_ranges
= pca9450_buck_volts
,
541 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
542 .vsel_reg
= PCA9450_REG_BUCK5OUT
,
543 .vsel_mask
= BUCK5OUT_MASK
,
544 .enable_reg
= PCA9450_REG_BUCK5CTRL
,
545 .enable_mask
= BUCK5_ENMODE_MASK
,
546 .owner
= THIS_MODULE
,
552 .of_match
= of_match_ptr("BUCK6"),
553 .regulators_node
= of_match_ptr("regulators"),
555 .ops
= &pca9450_buck_regulator_ops
,
556 .type
= REGULATOR_VOLTAGE
,
557 .n_voltages
= PCA9450_BUCK6_VOLTAGE_NUM
,
558 .linear_ranges
= pca9450_buck_volts
,
559 .n_linear_ranges
= ARRAY_SIZE(pca9450_buck_volts
),
560 .vsel_reg
= PCA9450_REG_BUCK6OUT
,
561 .vsel_mask
= BUCK6OUT_MASK
,
562 .enable_reg
= PCA9450_REG_BUCK6CTRL
,
563 .enable_mask
= BUCK6_ENMODE_MASK
,
564 .owner
= THIS_MODULE
,
570 .of_match
= of_match_ptr("LDO1"),
571 .regulators_node
= of_match_ptr("regulators"),
573 .ops
= &pca9450_ldo_regulator_ops
,
574 .type
= REGULATOR_VOLTAGE
,
575 .n_voltages
= PCA9450_LDO1_VOLTAGE_NUM
,
576 .linear_ranges
= pca9450_ldo1_volts
,
577 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo1_volts
),
578 .vsel_reg
= PCA9450_REG_LDO1CTRL
,
579 .vsel_mask
= LDO1OUT_MASK
,
580 .enable_reg
= PCA9450_REG_LDO1CTRL
,
581 .enable_mask
= LDO1_EN_MASK
,
582 .owner
= THIS_MODULE
,
588 .of_match
= of_match_ptr("LDO2"),
589 .regulators_node
= of_match_ptr("regulators"),
591 .ops
= &pca9450_ldo_regulator_ops
,
592 .type
= REGULATOR_VOLTAGE
,
593 .n_voltages
= PCA9450_LDO2_VOLTAGE_NUM
,
594 .linear_ranges
= pca9450_ldo2_volts
,
595 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo2_volts
),
596 .vsel_reg
= PCA9450_REG_LDO2CTRL
,
597 .vsel_mask
= LDO2OUT_MASK
,
598 .enable_reg
= PCA9450_REG_LDO2CTRL
,
599 .enable_mask
= LDO2_EN_MASK
,
600 .owner
= THIS_MODULE
,
606 .of_match
= of_match_ptr("LDO3"),
607 .regulators_node
= of_match_ptr("regulators"),
609 .ops
= &pca9450_ldo_regulator_ops
,
610 .type
= REGULATOR_VOLTAGE
,
611 .n_voltages
= PCA9450_LDO3_VOLTAGE_NUM
,
612 .linear_ranges
= pca9450_ldo34_volts
,
613 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo34_volts
),
614 .vsel_reg
= PCA9450_REG_LDO3CTRL
,
615 .vsel_mask
= LDO3OUT_MASK
,
616 .enable_reg
= PCA9450_REG_LDO3CTRL
,
617 .enable_mask
= LDO3_EN_MASK
,
618 .owner
= THIS_MODULE
,
624 .of_match
= of_match_ptr("LDO4"),
625 .regulators_node
= of_match_ptr("regulators"),
627 .ops
= &pca9450_ldo_regulator_ops
,
628 .type
= REGULATOR_VOLTAGE
,
629 .n_voltages
= PCA9450_LDO4_VOLTAGE_NUM
,
630 .linear_ranges
= pca9450_ldo34_volts
,
631 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo34_volts
),
632 .vsel_reg
= PCA9450_REG_LDO4CTRL
,
633 .vsel_mask
= LDO4OUT_MASK
,
634 .enable_reg
= PCA9450_REG_LDO4CTRL
,
635 .enable_mask
= LDO4_EN_MASK
,
636 .owner
= THIS_MODULE
,
642 .of_match
= of_match_ptr("LDO5"),
643 .regulators_node
= of_match_ptr("regulators"),
645 .ops
= &pca9450_ldo_regulator_ops
,
646 .type
= REGULATOR_VOLTAGE
,
647 .n_voltages
= PCA9450_LDO5_VOLTAGE_NUM
,
648 .linear_ranges
= pca9450_ldo5_volts
,
649 .n_linear_ranges
= ARRAY_SIZE(pca9450_ldo5_volts
),
650 .vsel_reg
= PCA9450_REG_LDO5CTRL_H
,
651 .vsel_mask
= LDO5HOUT_MASK
,
652 .enable_reg
= PCA9450_REG_LDO5CTRL_H
,
653 .enable_mask
= LDO5H_EN_MASK
,
654 .owner
= THIS_MODULE
,
659 static irqreturn_t
pca9450_irq_handler(int irq
, void *data
)
661 struct pca9450
*pca9450
= data
;
662 struct regmap
*regmap
= pca9450
->regmap
;
666 ret
= regmap_read(regmap
, PCA9450_REG_INT1
, &status
);
668 dev_err(pca9450
->dev
,
669 "Failed to read INT1(%d)\n", ret
);
673 if (status
& IRQ_PWRON
)
674 dev_warn(pca9450
->dev
, "PWRON interrupt.\n");
676 if (status
& IRQ_WDOGB
)
677 dev_warn(pca9450
->dev
, "WDOGB interrupt.\n");
679 if (status
& IRQ_VR_FLT1
)
680 dev_warn(pca9450
->dev
, "VRFLT1 interrupt.\n");
682 if (status
& IRQ_VR_FLT2
)
683 dev_warn(pca9450
->dev
, "VRFLT2 interrupt.\n");
685 if (status
& IRQ_LOWVSYS
)
686 dev_warn(pca9450
->dev
, "LOWVSYS interrupt.\n");
688 if (status
& IRQ_THERM_105
)
689 dev_warn(pca9450
->dev
, "IRQ_THERM_105 interrupt.\n");
691 if (status
& IRQ_THERM_125
)
692 dev_warn(pca9450
->dev
, "IRQ_THERM_125 interrupt.\n");
697 static int pca9450_i2c_probe(struct i2c_client
*i2c
,
698 const struct i2c_device_id
*id
)
700 enum pca9450_chip_type type
= (unsigned int)(uintptr_t)
701 of_device_get_match_data(&i2c
->dev
);
702 const struct pca9450_regulator_desc
*regulator_desc
;
703 struct regulator_config config
= { };
704 struct pca9450
*pca9450
;
705 unsigned int device_id
, i
;
709 dev_err(&i2c
->dev
, "No IRQ configured?\n");
713 pca9450
= devm_kzalloc(&i2c
->dev
, sizeof(struct pca9450
), GFP_KERNEL
);
718 case PCA9450_TYPE_PCA9450A
:
719 regulator_desc
= pca9450a_regulators
;
720 pca9450
->rcnt
= ARRAY_SIZE(pca9450a_regulators
);
722 case PCA9450_TYPE_PCA9450BC
:
723 regulator_desc
= pca9450bc_regulators
;
724 pca9450
->rcnt
= ARRAY_SIZE(pca9450bc_regulators
);
727 dev_err(&i2c
->dev
, "Unknown device type");
731 pca9450
->irq
= i2c
->irq
;
732 pca9450
->type
= type
;
733 pca9450
->dev
= &i2c
->dev
;
735 dev_set_drvdata(&i2c
->dev
, pca9450
);
737 pca9450
->regmap
= devm_regmap_init_i2c(i2c
,
738 &pca9450_regmap_config
);
739 if (IS_ERR(pca9450
->regmap
)) {
740 dev_err(&i2c
->dev
, "regmap initialization failed\n");
741 return PTR_ERR(pca9450
->regmap
);
744 ret
= regmap_read(pca9450
->regmap
, PCA9450_REG_DEV_ID
, &device_id
);
746 dev_err(&i2c
->dev
, "Read device id error\n");
750 /* Check your board and dts for match the right pmic */
751 if (((device_id
>> 4) != 0x1 && type
== PCA9450_TYPE_PCA9450A
) ||
752 ((device_id
>> 4) != 0x3 && type
== PCA9450_TYPE_PCA9450BC
)) {
753 dev_err(&i2c
->dev
, "Device id(%x) mismatched\n",
758 for (i
= 0; i
< pca9450
->rcnt
; i
++) {
759 const struct regulator_desc
*desc
;
760 struct regulator_dev
*rdev
;
761 const struct pca9450_regulator_desc
*r
;
763 r
= ®ulator_desc
[i
];
766 config
.regmap
= pca9450
->regmap
;
767 config
.dev
= pca9450
->dev
;
769 rdev
= devm_regulator_register(pca9450
->dev
, desc
, &config
);
772 dev_err(pca9450
->dev
,
773 "Failed to register regulator(%s): %d\n",
779 ret
= devm_request_threaded_irq(pca9450
->dev
, pca9450
->irq
, NULL
,
781 (IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
),
782 "pca9450-irq", pca9450
);
784 dev_err(pca9450
->dev
, "Failed to request IRQ: %d\n",
788 /* Unmask all interrupt except PWRON/WDOG/RSVD */
789 ret
= regmap_update_bits(pca9450
->regmap
, PCA9450_REG_INT1_MSK
,
790 IRQ_VR_FLT1
| IRQ_VR_FLT2
| IRQ_LOWVSYS
|
791 IRQ_THERM_105
| IRQ_THERM_125
,
792 IRQ_PWRON
| IRQ_WDOGB
| IRQ_RSVD
);
794 dev_err(&i2c
->dev
, "Unmask irq error\n");
798 dev_info(&i2c
->dev
, "%s probed.\n",
799 type
== PCA9450_TYPE_PCA9450A
? "pca9450a" : "pca9450bc");
804 static const struct of_device_id pca9450_of_match
[] = {
806 .compatible
= "nxp,pca9450a",
807 .data
= (void *)PCA9450_TYPE_PCA9450A
,
810 .compatible
= "nxp,pca9450b",
811 .data
= (void *)PCA9450_TYPE_PCA9450BC
,
814 .compatible
= "nxp,pca9450c",
815 .data
= (void *)PCA9450_TYPE_PCA9450BC
,
819 MODULE_DEVICE_TABLE(of
, pca9450_of_match
);
821 static struct i2c_driver pca9450_i2c_driver
= {
823 .name
= "nxp-pca9450",
824 .of_match_table
= pca9450_of_match
,
826 .probe
= pca9450_i2c_probe
,
829 module_i2c_driver(pca9450_i2c_driver
);
831 MODULE_AUTHOR("Robin Gong <yibin.gong@nxp.com>");
832 MODULE_DESCRIPTION("NXP PCA9450 Power Management IC driver");
833 MODULE_LICENSE("GPL");