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_RBTREE,
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.6V to 3.4V (25mV step)
113 static const struct linear_range pca9450_buck_volts[] = {
114 REGULATOR_LINEAR_RANGE(600000, 0x00, 0x70, 25000),
115 REGULATOR_LINEAR_RANGE(3400000, 0x71, 0x7F, 0),
122 static const struct linear_range pca9450_ldo1_volts[] = {
123 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
124 REGULATOR_LINEAR_RANGE(3000000, 0x04, 0x07, 100000),
129 * 0.8 to 1.15V (50mV step)
131 static const struct linear_range pca9450_ldo2_volts[] = {
132 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x07, 50000),
137 * 0.8 to 3.3V (100mV step)
139 static const struct linear_range pca9450_ldo34_volts[] = {
140 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x19, 100000),
141 REGULATOR_LINEAR_RANGE(3300000, 0x1A, 0x1F, 0),
146 * 1.8 to 3.3V (100mV step)
148 static const struct linear_range pca9450_ldo5_volts[] = {
149 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
152 static int buck_set_dvs(const struct regulator_desc *desc,
153 struct device_node *np, struct regmap *regmap,
154 char *prop, unsigned int reg, unsigned int mask)
159 ret = of_property_read_u32(np, prop, &uv);
165 for (i = 0; i < desc->n_voltages; i++) {
166 ret = regulator_desc_list_voltage_linear_range(desc, i);
170 i <<= ffs(desc->vsel_mask) - 1;
171 ret = regmap_update_bits(regmap, reg, mask, i);
177 struct pca9450_regulator_desc *regulator = container_of(desc,
178 struct pca9450_regulator_desc, desc);
180 /* Enable DVS control through PMIC_STBY_REQ for this BUCK */
181 ret = regmap_update_bits(regmap, regulator->desc.enable_reg,
182 BUCK1_DVS_CTRL, BUCK1_DVS_CTRL);
187 static int pca9450_set_dvs_levels(struct device_node *np,
188 const struct regulator_desc *desc,
189 struct regulator_config *cfg)
191 struct pca9450_regulator_desc *data = container_of(desc,
192 struct pca9450_regulator_desc, desc);
193 const struct pc9450_dvs_config *dvs = &data->dvs;
194 unsigned int reg, mask;
198 for (i = 0; i < PCA9450_DVS_LEVEL_MAX; i++) {
200 case PCA9450_DVS_LEVEL_RUN:
201 prop = "nxp,dvs-run-voltage";
203 mask = dvs->run_mask;
205 case PCA9450_DVS_LEVEL_STANDBY:
206 prop = "nxp,dvs-standby-voltage";
207 reg = dvs->standby_reg;
208 mask = dvs->standby_mask;
214 ret = buck_set_dvs(desc, np, cfg->regmap, prop, reg, mask);
222 static const struct pca9450_regulator_desc pca9450a_regulators[] = {
226 .of_match = of_match_ptr("BUCK1"),
227 .regulators_node = of_match_ptr("regulators"),
229 .ops = &pca9450_dvs_buck_regulator_ops,
230 .type = REGULATOR_VOLTAGE,
231 .n_voltages = PCA9450_BUCK1_VOLTAGE_NUM,
232 .linear_ranges = pca9450_dvs_buck_volts,
233 .n_linear_ranges = ARRAY_SIZE(pca9450_dvs_buck_volts),
234 .vsel_reg = PCA9450_REG_BUCK1OUT_DVS0,
235 .vsel_mask = BUCK1OUT_DVS0_MASK,
236 .enable_reg = PCA9450_REG_BUCK1CTRL,
237 .enable_mask = BUCK1_ENMODE_MASK,
238 .ramp_reg = PCA9450_REG_BUCK1CTRL,
239 .ramp_mask = BUCK1_RAMP_MASK,
240 .ramp_delay_table = pca9450_dvs_buck_ramp_table,
241 .n_ramp_values = ARRAY_SIZE(pca9450_dvs_buck_ramp_table),
242 .owner = THIS_MODULE,
243 .of_parse_cb = pca9450_set_dvs_levels,
246 .run_reg = PCA9450_REG_BUCK1OUT_DVS0,
247 .run_mask = BUCK1OUT_DVS0_MASK,
248 .standby_reg = PCA9450_REG_BUCK1OUT_DVS1,
249 .standby_mask = BUCK1OUT_DVS1_MASK,
255 .of_match = of_match_ptr("BUCK2"),
256 .regulators_node = of_match_ptr("regulators"),
258 .ops = &pca9450_dvs_buck_regulator_ops,
259 .type = REGULATOR_VOLTAGE,
260 .n_voltages = PCA9450_BUCK2_VOLTAGE_NUM,
261 .linear_ranges = pca9450_dvs_buck_volts,
262 .n_linear_ranges = ARRAY_SIZE(pca9450_dvs_buck_volts),
263 .vsel_reg = PCA9450_REG_BUCK2OUT_DVS0,
264 .vsel_mask = BUCK2OUT_DVS0_MASK,
265 .enable_reg = PCA9450_REG_BUCK2CTRL,
266 .enable_mask = BUCK2_ENMODE_MASK,
267 .ramp_reg = PCA9450_REG_BUCK2CTRL,
268 .ramp_mask = BUCK2_RAMP_MASK,
269 .ramp_delay_table = pca9450_dvs_buck_ramp_table,
270 .n_ramp_values = ARRAY_SIZE(pca9450_dvs_buck_ramp_table),
271 .owner = THIS_MODULE,
272 .of_parse_cb = pca9450_set_dvs_levels,
275 .run_reg = PCA9450_REG_BUCK2OUT_DVS0,
276 .run_mask = BUCK2OUT_DVS0_MASK,
277 .standby_reg = PCA9450_REG_BUCK2OUT_DVS1,
278 .standby_mask = BUCK2OUT_DVS1_MASK,
284 .of_match = of_match_ptr("BUCK3"),
285 .regulators_node = of_match_ptr("regulators"),
287 .ops = &pca9450_dvs_buck_regulator_ops,
288 .type = REGULATOR_VOLTAGE,
289 .n_voltages = PCA9450_BUCK3_VOLTAGE_NUM,
290 .linear_ranges = pca9450_dvs_buck_volts,
291 .n_linear_ranges = ARRAY_SIZE(pca9450_dvs_buck_volts),
292 .vsel_reg = PCA9450_REG_BUCK3OUT_DVS0,
293 .vsel_mask = BUCK3OUT_DVS0_MASK,
294 .enable_reg = PCA9450_REG_BUCK3CTRL,
295 .enable_mask = BUCK3_ENMODE_MASK,
296 .ramp_reg = PCA9450_REG_BUCK3CTRL,
297 .ramp_mask = BUCK3_RAMP_MASK,
298 .ramp_delay_table = pca9450_dvs_buck_ramp_table,
299 .n_ramp_values = ARRAY_SIZE(pca9450_dvs_buck_ramp_table),
300 .owner = THIS_MODULE,
301 .of_parse_cb = pca9450_set_dvs_levels,
304 .run_reg = PCA9450_REG_BUCK3OUT_DVS0,
305 .run_mask = BUCK3OUT_DVS0_MASK,
306 .standby_reg = PCA9450_REG_BUCK3OUT_DVS1,
307 .standby_mask = BUCK3OUT_DVS1_MASK,
313 .of_match = of_match_ptr("BUCK4"),
314 .regulators_node = of_match_ptr("regulators"),
316 .ops = &pca9450_buck_regulator_ops,
317 .type = REGULATOR_VOLTAGE,
318 .n_voltages = PCA9450_BUCK4_VOLTAGE_NUM,
319 .linear_ranges = pca9450_buck_volts,
320 .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
321 .vsel_reg = PCA9450_REG_BUCK4OUT,
322 .vsel_mask = BUCK4OUT_MASK,
323 .enable_reg = PCA9450_REG_BUCK4CTRL,
324 .enable_mask = BUCK4_ENMODE_MASK,
325 .owner = THIS_MODULE,
331 .of_match = of_match_ptr("BUCK5"),
332 .regulators_node = of_match_ptr("regulators"),
334 .ops = &pca9450_buck_regulator_ops,
335 .type = REGULATOR_VOLTAGE,
336 .n_voltages = PCA9450_BUCK5_VOLTAGE_NUM,
337 .linear_ranges = pca9450_buck_volts,
338 .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
339 .vsel_reg = PCA9450_REG_BUCK5OUT,
340 .vsel_mask = BUCK5OUT_MASK,
341 .enable_reg = PCA9450_REG_BUCK5CTRL,
342 .enable_mask = BUCK5_ENMODE_MASK,
343 .owner = THIS_MODULE,
349 .of_match = of_match_ptr("BUCK6"),
350 .regulators_node = of_match_ptr("regulators"),
352 .ops = &pca9450_buck_regulator_ops,
353 .type = REGULATOR_VOLTAGE,
354 .n_voltages = PCA9450_BUCK6_VOLTAGE_NUM,
355 .linear_ranges = pca9450_buck_volts,
356 .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
357 .vsel_reg = PCA9450_REG_BUCK6OUT,
358 .vsel_mask = BUCK6OUT_MASK,
359 .enable_reg = PCA9450_REG_BUCK6CTRL,
360 .enable_mask = BUCK6_ENMODE_MASK,
361 .owner = THIS_MODULE,
367 .of_match = of_match_ptr("LDO1"),
368 .regulators_node = of_match_ptr("regulators"),
370 .ops = &pca9450_ldo_regulator_ops,
371 .type = REGULATOR_VOLTAGE,
372 .n_voltages = PCA9450_LDO1_VOLTAGE_NUM,
373 .linear_ranges = pca9450_ldo1_volts,
374 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo1_volts),
375 .vsel_reg = PCA9450_REG_LDO1CTRL,
376 .vsel_mask = LDO1OUT_MASK,
377 .enable_reg = PCA9450_REG_LDO1CTRL,
378 .enable_mask = LDO1_EN_MASK,
379 .owner = THIS_MODULE,
385 .of_match = of_match_ptr("LDO2"),
386 .regulators_node = of_match_ptr("regulators"),
388 .ops = &pca9450_ldo_regulator_ops,
389 .type = REGULATOR_VOLTAGE,
390 .n_voltages = PCA9450_LDO2_VOLTAGE_NUM,
391 .linear_ranges = pca9450_ldo2_volts,
392 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo2_volts),
393 .vsel_reg = PCA9450_REG_LDO2CTRL,
394 .vsel_mask = LDO2OUT_MASK,
395 .enable_reg = PCA9450_REG_LDO2CTRL,
396 .enable_mask = LDO2_EN_MASK,
397 .owner = THIS_MODULE,
403 .of_match = of_match_ptr("LDO3"),
404 .regulators_node = of_match_ptr("regulators"),
406 .ops = &pca9450_ldo_regulator_ops,
407 .type = REGULATOR_VOLTAGE,
408 .n_voltages = PCA9450_LDO3_VOLTAGE_NUM,
409 .linear_ranges = pca9450_ldo34_volts,
410 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo34_volts),
411 .vsel_reg = PCA9450_REG_LDO3CTRL,
412 .vsel_mask = LDO3OUT_MASK,
413 .enable_reg = PCA9450_REG_LDO3CTRL,
414 .enable_mask = LDO3_EN_MASK,
415 .owner = THIS_MODULE,
421 .of_match = of_match_ptr("LDO4"),
422 .regulators_node = of_match_ptr("regulators"),
424 .ops = &pca9450_ldo_regulator_ops,
425 .type = REGULATOR_VOLTAGE,
426 .n_voltages = PCA9450_LDO4_VOLTAGE_NUM,
427 .linear_ranges = pca9450_ldo34_volts,
428 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo34_volts),
429 .vsel_reg = PCA9450_REG_LDO4CTRL,
430 .vsel_mask = LDO4OUT_MASK,
431 .enable_reg = PCA9450_REG_LDO4CTRL,
432 .enable_mask = LDO4_EN_MASK,
433 .owner = THIS_MODULE,
439 .of_match = of_match_ptr("LDO5"),
440 .regulators_node = of_match_ptr("regulators"),
442 .ops = &pca9450_ldo_regulator_ops,
443 .type = REGULATOR_VOLTAGE,
444 .n_voltages = PCA9450_LDO5_VOLTAGE_NUM,
445 .linear_ranges = pca9450_ldo5_volts,
446 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo5_volts),
447 .vsel_reg = PCA9450_REG_LDO5CTRL_H,
448 .vsel_mask = LDO5HOUT_MASK,
449 .enable_reg = PCA9450_REG_LDO5CTRL_H,
450 .enable_mask = LDO5H_EN_MASK,
451 .owner = THIS_MODULE,
457 * Buck3 removed on PCA9450B and connected with Buck1 internal for dual phase
458 * on PCA9450C as no Buck3.
460 static const struct pca9450_regulator_desc pca9450bc_regulators[] = {
464 .of_match = of_match_ptr("BUCK1"),
465 .regulators_node = of_match_ptr("regulators"),
467 .ops = &pca9450_dvs_buck_regulator_ops,
468 .type = REGULATOR_VOLTAGE,
469 .n_voltages = PCA9450_BUCK1_VOLTAGE_NUM,
470 .linear_ranges = pca9450_dvs_buck_volts,
471 .n_linear_ranges = ARRAY_SIZE(pca9450_dvs_buck_volts),
472 .vsel_reg = PCA9450_REG_BUCK1OUT_DVS0,
473 .vsel_mask = BUCK1OUT_DVS0_MASK,
474 .enable_reg = PCA9450_REG_BUCK1CTRL,
475 .enable_mask = BUCK1_ENMODE_MASK,
476 .ramp_reg = PCA9450_REG_BUCK1CTRL,
477 .ramp_mask = BUCK1_RAMP_MASK,
478 .ramp_delay_table = pca9450_dvs_buck_ramp_table,
479 .n_ramp_values = ARRAY_SIZE(pca9450_dvs_buck_ramp_table),
480 .owner = THIS_MODULE,
481 .of_parse_cb = pca9450_set_dvs_levels,
484 .run_reg = PCA9450_REG_BUCK1OUT_DVS0,
485 .run_mask = BUCK1OUT_DVS0_MASK,
486 .standby_reg = PCA9450_REG_BUCK1OUT_DVS1,
487 .standby_mask = BUCK1OUT_DVS1_MASK,
493 .of_match = of_match_ptr("BUCK2"),
494 .regulators_node = of_match_ptr("regulators"),
496 .ops = &pca9450_dvs_buck_regulator_ops,
497 .type = REGULATOR_VOLTAGE,
498 .n_voltages = PCA9450_BUCK2_VOLTAGE_NUM,
499 .linear_ranges = pca9450_dvs_buck_volts,
500 .n_linear_ranges = ARRAY_SIZE(pca9450_dvs_buck_volts),
501 .vsel_reg = PCA9450_REG_BUCK2OUT_DVS0,
502 .vsel_mask = BUCK2OUT_DVS0_MASK,
503 .enable_reg = PCA9450_REG_BUCK2CTRL,
504 .enable_mask = BUCK2_ENMODE_MASK,
505 .ramp_reg = PCA9450_REG_BUCK2CTRL,
506 .ramp_mask = BUCK2_RAMP_MASK,
507 .ramp_delay_table = pca9450_dvs_buck_ramp_table,
508 .n_ramp_values = ARRAY_SIZE(pca9450_dvs_buck_ramp_table),
509 .owner = THIS_MODULE,
510 .of_parse_cb = pca9450_set_dvs_levels,
513 .run_reg = PCA9450_REG_BUCK2OUT_DVS0,
514 .run_mask = BUCK2OUT_DVS0_MASK,
515 .standby_reg = PCA9450_REG_BUCK2OUT_DVS1,
516 .standby_mask = BUCK2OUT_DVS1_MASK,
522 .of_match = of_match_ptr("BUCK4"),
523 .regulators_node = of_match_ptr("regulators"),
525 .ops = &pca9450_buck_regulator_ops,
526 .type = REGULATOR_VOLTAGE,
527 .n_voltages = PCA9450_BUCK4_VOLTAGE_NUM,
528 .linear_ranges = pca9450_buck_volts,
529 .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
530 .vsel_reg = PCA9450_REG_BUCK4OUT,
531 .vsel_mask = BUCK4OUT_MASK,
532 .enable_reg = PCA9450_REG_BUCK4CTRL,
533 .enable_mask = BUCK4_ENMODE_MASK,
534 .owner = THIS_MODULE,
540 .of_match = of_match_ptr("BUCK5"),
541 .regulators_node = of_match_ptr("regulators"),
543 .ops = &pca9450_buck_regulator_ops,
544 .type = REGULATOR_VOLTAGE,
545 .n_voltages = PCA9450_BUCK5_VOLTAGE_NUM,
546 .linear_ranges = pca9450_buck_volts,
547 .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
548 .vsel_reg = PCA9450_REG_BUCK5OUT,
549 .vsel_mask = BUCK5OUT_MASK,
550 .enable_reg = PCA9450_REG_BUCK5CTRL,
551 .enable_mask = BUCK5_ENMODE_MASK,
552 .owner = THIS_MODULE,
558 .of_match = of_match_ptr("BUCK6"),
559 .regulators_node = of_match_ptr("regulators"),
561 .ops = &pca9450_buck_regulator_ops,
562 .type = REGULATOR_VOLTAGE,
563 .n_voltages = PCA9450_BUCK6_VOLTAGE_NUM,
564 .linear_ranges = pca9450_buck_volts,
565 .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
566 .vsel_reg = PCA9450_REG_BUCK6OUT,
567 .vsel_mask = BUCK6OUT_MASK,
568 .enable_reg = PCA9450_REG_BUCK6CTRL,
569 .enable_mask = BUCK6_ENMODE_MASK,
570 .owner = THIS_MODULE,
576 .of_match = of_match_ptr("LDO1"),
577 .regulators_node = of_match_ptr("regulators"),
579 .ops = &pca9450_ldo_regulator_ops,
580 .type = REGULATOR_VOLTAGE,
581 .n_voltages = PCA9450_LDO1_VOLTAGE_NUM,
582 .linear_ranges = pca9450_ldo1_volts,
583 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo1_volts),
584 .vsel_reg = PCA9450_REG_LDO1CTRL,
585 .vsel_mask = LDO1OUT_MASK,
586 .enable_reg = PCA9450_REG_LDO1CTRL,
587 .enable_mask = LDO1_EN_MASK,
588 .owner = THIS_MODULE,
594 .of_match = of_match_ptr("LDO2"),
595 .regulators_node = of_match_ptr("regulators"),
597 .ops = &pca9450_ldo_regulator_ops,
598 .type = REGULATOR_VOLTAGE,
599 .n_voltages = PCA9450_LDO2_VOLTAGE_NUM,
600 .linear_ranges = pca9450_ldo2_volts,
601 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo2_volts),
602 .vsel_reg = PCA9450_REG_LDO2CTRL,
603 .vsel_mask = LDO2OUT_MASK,
604 .enable_reg = PCA9450_REG_LDO2CTRL,
605 .enable_mask = LDO2_EN_MASK,
606 .owner = THIS_MODULE,
612 .of_match = of_match_ptr("LDO3"),
613 .regulators_node = of_match_ptr("regulators"),
615 .ops = &pca9450_ldo_regulator_ops,
616 .type = REGULATOR_VOLTAGE,
617 .n_voltages = PCA9450_LDO3_VOLTAGE_NUM,
618 .linear_ranges = pca9450_ldo34_volts,
619 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo34_volts),
620 .vsel_reg = PCA9450_REG_LDO3CTRL,
621 .vsel_mask = LDO3OUT_MASK,
622 .enable_reg = PCA9450_REG_LDO3CTRL,
623 .enable_mask = LDO3_EN_MASK,
624 .owner = THIS_MODULE,
630 .of_match = of_match_ptr("LDO4"),
631 .regulators_node = of_match_ptr("regulators"),
633 .ops = &pca9450_ldo_regulator_ops,
634 .type = REGULATOR_VOLTAGE,
635 .n_voltages = PCA9450_LDO4_VOLTAGE_NUM,
636 .linear_ranges = pca9450_ldo34_volts,
637 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo34_volts),
638 .vsel_reg = PCA9450_REG_LDO4CTRL,
639 .vsel_mask = LDO4OUT_MASK,
640 .enable_reg = PCA9450_REG_LDO4CTRL,
641 .enable_mask = LDO4_EN_MASK,
642 .owner = THIS_MODULE,
648 .of_match = of_match_ptr("LDO5"),
649 .regulators_node = of_match_ptr("regulators"),
651 .ops = &pca9450_ldo_regulator_ops,
652 .type = REGULATOR_VOLTAGE,
653 .n_voltages = PCA9450_LDO5_VOLTAGE_NUM,
654 .linear_ranges = pca9450_ldo5_volts,
655 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo5_volts),
656 .vsel_reg = PCA9450_REG_LDO5CTRL_H,
657 .vsel_mask = LDO5HOUT_MASK,
658 .enable_reg = PCA9450_REG_LDO5CTRL_H,
659 .enable_mask = LDO5H_EN_MASK,
660 .owner = THIS_MODULE,
665 static irqreturn_t pca9450_irq_handler(int irq, void *data)
667 struct pca9450 *pca9450 = data;
668 struct regmap *regmap = pca9450->regmap;
672 ret = regmap_read(regmap, PCA9450_REG_INT1, &status);
674 dev_err(pca9450->dev,
675 "Failed to read INT1(%d)\n", ret);
679 if (status & IRQ_PWRON)
680 dev_warn(pca9450->dev, "PWRON interrupt.\n");
682 if (status & IRQ_WDOGB)
683 dev_warn(pca9450->dev, "WDOGB interrupt.\n");
685 if (status & IRQ_VR_FLT1)
686 dev_warn(pca9450->dev, "VRFLT1 interrupt.\n");
688 if (status & IRQ_VR_FLT2)
689 dev_warn(pca9450->dev, "VRFLT2 interrupt.\n");
691 if (status & IRQ_LOWVSYS)
692 dev_warn(pca9450->dev, "LOWVSYS interrupt.\n");
694 if (status & IRQ_THERM_105)
695 dev_warn(pca9450->dev, "IRQ_THERM_105 interrupt.\n");
697 if (status & IRQ_THERM_125)
698 dev_warn(pca9450->dev, "IRQ_THERM_125 interrupt.\n");
703 static int pca9450_i2c_probe(struct i2c_client *i2c)
705 enum pca9450_chip_type type = (unsigned int)(uintptr_t)
706 of_device_get_match_data(&i2c->dev);
707 const struct pca9450_regulator_desc *regulator_desc;
708 struct regulator_config config = { };
709 struct pca9450 *pca9450;
710 unsigned int device_id, i;
711 unsigned int reset_ctrl;
715 dev_err(&i2c->dev, "No IRQ configured?\n");
719 pca9450 = devm_kzalloc(&i2c->dev, sizeof(struct pca9450), GFP_KERNEL);
724 case PCA9450_TYPE_PCA9450A:
725 regulator_desc = pca9450a_regulators;
726 pca9450->rcnt = ARRAY_SIZE(pca9450a_regulators);
728 case PCA9450_TYPE_PCA9450BC:
729 regulator_desc = pca9450bc_regulators;
730 pca9450->rcnt = ARRAY_SIZE(pca9450bc_regulators);
733 dev_err(&i2c->dev, "Unknown device type");
737 pca9450->irq = i2c->irq;
738 pca9450->type = type;
739 pca9450->dev = &i2c->dev;
741 dev_set_drvdata(&i2c->dev, pca9450);
743 pca9450->regmap = devm_regmap_init_i2c(i2c,
744 &pca9450_regmap_config);
745 if (IS_ERR(pca9450->regmap)) {
746 dev_err(&i2c->dev, "regmap initialization failed\n");
747 return PTR_ERR(pca9450->regmap);
750 ret = regmap_read(pca9450->regmap, PCA9450_REG_DEV_ID, &device_id);
752 dev_err(&i2c->dev, "Read device id error\n");
756 /* Check your board and dts for match the right pmic */
757 if (((device_id >> 4) != 0x1 && type == PCA9450_TYPE_PCA9450A) ||
758 ((device_id >> 4) != 0x3 && type == PCA9450_TYPE_PCA9450BC)) {
759 dev_err(&i2c->dev, "Device id(%x) mismatched\n",
764 for (i = 0; i < pca9450->rcnt; i++) {
765 const struct regulator_desc *desc;
766 struct regulator_dev *rdev;
767 const struct pca9450_regulator_desc *r;
769 r = ®ulator_desc[i];
772 config.regmap = pca9450->regmap;
773 config.dev = pca9450->dev;
775 rdev = devm_regulator_register(pca9450->dev, desc, &config);
778 dev_err(pca9450->dev,
779 "Failed to register regulator(%s): %d\n",
785 ret = devm_request_threaded_irq(pca9450->dev, pca9450->irq, NULL,
787 (IRQF_TRIGGER_FALLING | IRQF_ONESHOT),
788 "pca9450-irq", pca9450);
790 dev_err(pca9450->dev, "Failed to request IRQ: %d\n",
794 /* Unmask all interrupt except PWRON/WDOG/RSVD */
795 ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_INT1_MSK,
796 IRQ_VR_FLT1 | IRQ_VR_FLT2 | IRQ_LOWVSYS |
797 IRQ_THERM_105 | IRQ_THERM_125,
798 IRQ_PWRON | IRQ_WDOGB | IRQ_RSVD);
800 dev_err(&i2c->dev, "Unmask irq error\n");
804 /* Clear PRESET_EN bit in BUCK123_DVS to use DVS registers */
805 ret = regmap_clear_bits(pca9450->regmap, PCA9450_REG_BUCK123_DVS,
808 dev_err(&i2c->dev, "Failed to clear PRESET_EN bit: %d\n", ret);
812 if (of_property_read_bool(i2c->dev.of_node, "nxp,wdog_b-warm-reset"))
813 reset_ctrl = WDOG_B_CFG_WARM;
815 reset_ctrl = WDOG_B_CFG_COLD_LDO12;
817 /* Set reset behavior on assertion of WDOG_B signal */
818 ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_RESET_CTRL,
819 WDOG_B_CFG_MASK, reset_ctrl);
821 dev_err(&i2c->dev, "Failed to set WDOG_B reset behavior\n");
825 if (of_property_read_bool(i2c->dev.of_node, "nxp,i2c-lt-enable")) {
826 /* Enable I2C Level Translator */
827 ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_CONFIG2,
828 I2C_LT_MASK, I2C_LT_ON_STANDBY_RUN);
831 "Failed to enable I2C level translator\n");
837 * The driver uses the LDO5CTRL_H register to control the LDO5 regulator.
838 * This is only valid if the SD_VSEL input of the PMIC is high. Let's
839 * check if the pin is available as GPIO and set it to high.
841 pca9450->sd_vsel_gpio = gpiod_get_optional(pca9450->dev, "sd-vsel", GPIOD_OUT_HIGH);
843 if (IS_ERR(pca9450->sd_vsel_gpio)) {
844 dev_err(&i2c->dev, "Failed to get SD_VSEL GPIO\n");
845 return PTR_ERR(pca9450->sd_vsel_gpio);
848 dev_info(&i2c->dev, "%s probed.\n",
849 type == PCA9450_TYPE_PCA9450A ? "pca9450a" : "pca9450bc");
854 static const struct of_device_id pca9450_of_match[] = {
856 .compatible = "nxp,pca9450a",
857 .data = (void *)PCA9450_TYPE_PCA9450A,
860 .compatible = "nxp,pca9450b",
861 .data = (void *)PCA9450_TYPE_PCA9450BC,
864 .compatible = "nxp,pca9450c",
865 .data = (void *)PCA9450_TYPE_PCA9450BC,
869 MODULE_DEVICE_TABLE(of, pca9450_of_match);
871 static struct i2c_driver pca9450_i2c_driver = {
873 .name = "nxp-pca9450",
874 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
875 .of_match_table = pca9450_of_match,
877 .probe = pca9450_i2c_probe,
880 module_i2c_driver(pca9450_i2c_driver);
882 MODULE_AUTHOR("Robin Gong <yibin.gong@nxp.com>");
883 MODULE_DESCRIPTION("NXP PCA9450 Power Management IC driver");
884 MODULE_LICENSE("GPL");