blob: 6b36ebbf7db4ef188f190839acd65c05cfabd7e3 [file] [log] [blame]
Svyatoslav Ryhel8f0fa2b2023-10-27 11:26:12 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright(C) 2023 Svyatoslav Ryhel <clamor95@gmail.com>
4 */
5
6#include <dm.h>
7#include <dm/lists.h>
8#include <power/pmic.h>
9#include <power/tps80031.h>
10
11static const struct pmic_child_info pmic_children_info[] = {
12 { .prefix = "ldo", .driver = TPS80031_LDO_DRIVER },
13 { .prefix = "smps", .driver = TPS80031_SMPS_DRIVER },
14 { },
15};
16
17static int tps80031_write(struct udevice *dev, uint reg, const uint8_t *buff,
18 int len)
19{
20 int ret;
21
22 ret = dm_i2c_write(dev, reg, buff, len);
23 if (ret) {
24 log_debug("write error to device: %p register: %#x!\n", dev, reg);
25 return ret;
26 }
27
28 return 0;
29}
30
31static int tps80031_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
32{
33 int ret;
34
35 ret = dm_i2c_read(dev, reg, buff, len);
36 if (ret) {
37 log_debug("read error from device: %p register: %#x!\n", dev, reg);
38 return ret;
39 }
40
41 return 0;
42}
43
44static int tps80031_bind(struct udevice *dev)
45{
46 ofnode regulators_node;
47 int children;
48
49 regulators_node = dev_read_subnode(dev, "regulators");
50 if (!ofnode_valid(regulators_node)) {
51 log_err("%s regulators subnode not found!\n", dev->name);
52 return -ENXIO;
53 }
54
55 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
56
57 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
58 if (!children)
59 log_err("%s - no child found\n", dev->name);
60
61 /* Always return success for this device */
62 return 0;
63}
64
65static struct dm_pmic_ops tps80031_ops = {
66 .read = tps80031_read,
67 .write = tps80031_write,
68};
69
70static const struct udevice_id tps80031_ids[] = {
71 { .compatible = "ti,tps80031" },
72 { .compatible = "ti,tps80032" },
73 { }
74};
75
76U_BOOT_DRIVER(pmic_tps80031) = {
77 .name = "tps80031_pmic",
78 .id = UCLASS_PMIC,
79 .of_match = tps80031_ids,
80 .bind = tps80031_bind,
81 .ops = &tps80031_ops,
82};