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