183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2cdad57a7SKeerthy /*
3cdad57a7SKeerthy * (C) Copyright 2017 Texas Instruments Incorporated, <www.ti.com>
4cdad57a7SKeerthy * Keerthy <j-keerthy@ti.com>
5cdad57a7SKeerthy */
6cdad57a7SKeerthy
7cdad57a7SKeerthy #include <common.h>
8cdad57a7SKeerthy #include <fdtdec.h>
9cdad57a7SKeerthy #include <errno.h>
10cdad57a7SKeerthy #include <dm.h>
11cdad57a7SKeerthy #include <i2c.h>
12cdad57a7SKeerthy #include <power/pmic.h>
13cdad57a7SKeerthy #include <power/regulator.h>
14cdad57a7SKeerthy #include <power/lp87565.h>
15cdad57a7SKeerthy #include <dm/device.h>
16cdad57a7SKeerthy
17cdad57a7SKeerthy static const struct pmic_child_info pmic_children_info[] = {
18cdad57a7SKeerthy { .prefix = "buck", .driver = LP87565_BUCK_DRIVER },
19cdad57a7SKeerthy { },
20cdad57a7SKeerthy };
21cdad57a7SKeerthy
lp87565_write(struct udevice * dev,uint reg,const uint8_t * buff,int len)22cdad57a7SKeerthy static int lp87565_write(struct udevice *dev, uint reg, const uint8_t *buff,
23cdad57a7SKeerthy int len)
24cdad57a7SKeerthy {
25cdad57a7SKeerthy int ret;
26cdad57a7SKeerthy
27cdad57a7SKeerthy ret = dm_i2c_write(dev, reg, buff, len);
28cdad57a7SKeerthy if (ret)
29*c83c436dSSimon Glass pr_err("write error to device: %p register: %#x!\n", dev, reg);
30cdad57a7SKeerthy
31cdad57a7SKeerthy return ret;
32cdad57a7SKeerthy }
33cdad57a7SKeerthy
lp87565_read(struct udevice * dev,uint reg,uint8_t * buff,int len)34cdad57a7SKeerthy static int lp87565_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
35cdad57a7SKeerthy {
36cdad57a7SKeerthy int ret;
37cdad57a7SKeerthy
38cdad57a7SKeerthy ret = dm_i2c_read(dev, reg, buff, len);
39cdad57a7SKeerthy if (ret)
40*c83c436dSSimon Glass pr_err("read error from device: %p register: %#x!\n", dev, reg);
41cdad57a7SKeerthy
42cdad57a7SKeerthy return ret;
43cdad57a7SKeerthy }
44cdad57a7SKeerthy
lp87565_bind(struct udevice * dev)45cdad57a7SKeerthy static int lp87565_bind(struct udevice *dev)
46cdad57a7SKeerthy {
47cdad57a7SKeerthy ofnode regulators_node;
48cdad57a7SKeerthy int children;
49cdad57a7SKeerthy
50cdad57a7SKeerthy regulators_node = dev_read_subnode(dev, "regulators");
51cdad57a7SKeerthy if (!ofnode_valid(regulators_node)) {
52*c83c436dSSimon Glass debug("%s: %s regulators subnode not found!\n", __func__,
53cdad57a7SKeerthy dev->name);
54cdad57a7SKeerthy return -ENXIO;
55cdad57a7SKeerthy }
56cdad57a7SKeerthy
57cdad57a7SKeerthy debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
58cdad57a7SKeerthy
59cdad57a7SKeerthy children = pmic_bind_children(dev, regulators_node, pmic_children_info);
60cdad57a7SKeerthy if (!children)
61cdad57a7SKeerthy printf("%s: %s - no child found\n", __func__, dev->name);
62cdad57a7SKeerthy
63cdad57a7SKeerthy /* Always return success for this device */
64cdad57a7SKeerthy return 0;
65cdad57a7SKeerthy }
66cdad57a7SKeerthy
67cdad57a7SKeerthy static struct dm_pmic_ops lp87565_ops = {
68cdad57a7SKeerthy .read = lp87565_read,
69cdad57a7SKeerthy .write = lp87565_write,
70cdad57a7SKeerthy };
71cdad57a7SKeerthy
72cdad57a7SKeerthy static const struct udevice_id lp87565_ids[] = {
73cdad57a7SKeerthy { .compatible = "ti,lp87565", .data = LP87565 },
74cdad57a7SKeerthy { .compatible = "ti,lp87565-q1", .data = LP87565_Q1 },
75cdad57a7SKeerthy { }
76cdad57a7SKeerthy };
77cdad57a7SKeerthy
78cdad57a7SKeerthy U_BOOT_DRIVER(pmic_lp87565) = {
79cdad57a7SKeerthy .name = "lp87565_pmic",
80cdad57a7SKeerthy .id = UCLASS_PMIC,
81cdad57a7SKeerthy .of_match = lp87565_ids,
82cdad57a7SKeerthy .bind = lp87565_bind,
83cdad57a7SKeerthy .ops = &lp87565_ops,
84cdad57a7SKeerthy };
85