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