blob: c7f8b8095407736e2cfb8660907002b4ad71f374 [file] [log] [blame]
Ye Li22172f62019-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 Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Ye Li22172f62019-10-15 02:15:18 -070012#include <power/pmic.h>
13#include <power/regulator.h>
14#include <power/pca9450.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18static const struct pmic_child_info pmic_children_info[] = {
19 /* buck */
20 { .prefix = "b", .driver = PCA9450_REGULATOR_DRIVER},
21 /* ldo */
22 { .prefix = "l", .driver = PCA9450_REGULATOR_DRIVER},
23 { },
24};
25
26static int pca9450_reg_count(struct udevice *dev)
27{
28 return PCA9450_REG_NUM;
29}
30
31static int pca9450_write(struct udevice *dev, uint reg, const uint8_t *buff,
32 int len)
33{
34 if (dm_i2c_write(dev, reg, buff, len)) {
35 pr_err("write error to device: %p register: %#x!", dev, reg);
36 return -EIO;
37 }
38
39 return 0;
40}
41
42static int pca9450_read(struct udevice *dev, uint reg, uint8_t *buff,
43 int len)
44{
45 if (dm_i2c_read(dev, reg, buff, len)) {
46 pr_err("read error from device: %p register: %#x!", dev, reg);
47 return -EIO;
48 }
49
50 return 0;
51}
52
53static int pca9450_bind(struct udevice *dev)
54{
55 int children;
56 ofnode regulators_node;
57
58 regulators_node = dev_read_subnode(dev, "regulators");
59 if (!ofnode_valid(regulators_node)) {
60 debug("%s: %s regulators subnode not found!", __func__,
61 dev->name);
62 return -ENXIO;
63 }
64
65 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
66
67 children = pmic_bind_children(dev, regulators_node,
68 pmic_children_info);
69 if (!children)
70 debug("%s: %s - no child found\n", __func__, dev->name);
71
72 /* Always return success for this device */
73 return 0;
74}
75
76static struct dm_pmic_ops pca9450_ops = {
77 .reg_count = pca9450_reg_count,
78 .read = pca9450_read,
79 .write = pca9450_write,
80};
81
82static const struct udevice_id pca9450_ids[] = {
Max Krummenacher5d89afe2020-10-28 11:58:09 +020083 { .compatible = "nxp,pca9450a", .data = 0x25, },
Ye Li22172f62019-10-15 02:15:18 -070084 { .compatible = "nxp,pca9450b", .data = 0x25, },
85 { }
86};
87
88U_BOOT_DRIVER(pmic_pca9450) = {
89 .name = "pca9450 pmic",
90 .id = UCLASS_PMIC,
91 .of_match = pca9450_ids,
92 .bind = pca9450_bind,
93 .ops = &pca9450_ops,
94};