blob: 116ac49a8db669adb0dbde24173f4fdca14a1db7 [file] [log] [blame]
Ye Lic3ee9092019-10-15 02:15:18 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 NXP
4 */
5
6#include <common.h>
7#include <fdtdec.h>
8#include <errno.h>
9#include <dm.h>
10#include <i2c.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Ye Lic3ee9092019-10-15 02:15:18 -070013#include <power/pmic.h>
14#include <power/regulator.h>
15#include <power/pca9450.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
19static const struct pmic_child_info pmic_children_info[] = {
20 /* buck */
21 { .prefix = "b", .driver = PCA9450_REGULATOR_DRIVER},
Marek Vasut1d6dd082022-05-20 05:10:16 +020022 { .prefix = "B", .driver = PCA9450_REGULATOR_DRIVER},
Ye Lic3ee9092019-10-15 02:15:18 -070023 /* ldo */
24 { .prefix = "l", .driver = PCA9450_REGULATOR_DRIVER},
Marek Vasut1d6dd082022-05-20 05:10:16 +020025 { .prefix = "L", .driver = PCA9450_REGULATOR_DRIVER},
Ye Lic3ee9092019-10-15 02:15:18 -070026 { },
27};
28
29static int pca9450_reg_count(struct udevice *dev)
30{
31 return PCA9450_REG_NUM;
32}
33
34static int pca9450_write(struct udevice *dev, uint reg, const uint8_t *buff,
35 int len)
36{
37 if (dm_i2c_write(dev, reg, buff, len)) {
38 pr_err("write error to device: %p register: %#x!", dev, reg);
39 return -EIO;
40 }
41
42 return 0;
43}
44
45static int pca9450_read(struct udevice *dev, uint reg, uint8_t *buff,
46 int len)
47{
48 if (dm_i2c_read(dev, reg, buff, len)) {
49 pr_err("read error from device: %p register: %#x!", dev, reg);
50 return -EIO;
51 }
52
53 return 0;
54}
55
56static int pca9450_bind(struct udevice *dev)
57{
58 int children;
59 ofnode regulators_node;
60
61 regulators_node = dev_read_subnode(dev, "regulators");
62 if (!ofnode_valid(regulators_node)) {
63 debug("%s: %s regulators subnode not found!", __func__,
64 dev->name);
65 return -ENXIO;
66 }
67
68 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
69
70 children = pmic_bind_children(dev, regulators_node,
71 pmic_children_info);
72 if (!children)
73 debug("%s: %s - no child found\n", __func__, dev->name);
74
75 /* Always return success for this device */
76 return 0;
77}
78
79static struct dm_pmic_ops pca9450_ops = {
80 .reg_count = pca9450_reg_count,
81 .read = pca9450_read,
82 .write = pca9450_write,
83};
84
85static const struct udevice_id pca9450_ids[] = {
Marek Vasut5d9b83d2022-05-20 05:10:17 +020086 { .compatible = "nxp,pca9450a", .data = NXP_CHIP_TYPE_PCA9450A, },
87 { .compatible = "nxp,pca9450b", .data = NXP_CHIP_TYPE_PCA9450BC, },
88 { .compatible = "nxp,pca9450c", .data = NXP_CHIP_TYPE_PCA9450BC, },
Ye Lic3ee9092019-10-15 02:15:18 -070089 { }
90};
91
92U_BOOT_DRIVER(pmic_pca9450) = {
93 .name = "pca9450 pmic",
94 .id = UCLASS_PMIC,
95 .of_match = pca9450_ids,
96 .bind = pca9450_bind,
97 .ops = &pca9450_ops,
98};