blob: 9462afee77fd6e9a3099ab19964634e74aa31fc8 [file] [log] [blame]
Neil Armstronge422fbe2022-04-27 13:28:09 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2022 BayLibre, SAS
4 * Author: Neil Armstrong <narmstrong@baylibre.com>
5 */
6
7#include <common.h>
8#include <fdtdec.h>
9#include <errno.h>
10#include <dm.h>
11#include <i2c.h>
12#include <log.h>
13#include <power/pmic.h>
14#include <power/regulator.h>
15#include <power/tps65219.h>
16#include <dm/device.h>
17
18static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = "ldo", .driver = TPS65219_LDO_DRIVER },
20 { .prefix = "buck", .driver = TPS65219_BUCK_DRIVER },
21 { },
22};
23
24static int tps65219_reg_count(struct udevice *dev)
25{
26 return 0x41;
27}
28
29static int tps65219_write(struct udevice *dev, uint reg, const uint8_t *buff,
30 int len)
31{
32 if (dm_i2c_write(dev, reg, buff, len)) {
33 pr_err("write error to device: %p register: %#x!\n", dev, reg);
34 return -EIO;
35 }
36
37 return 0;
38}
39
40static int tps65219_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
41{
42 if (dm_i2c_read(dev, reg, buff, len)) {
43 pr_err("read error from device: %p register: %#x!\n", dev, reg);
44 return -EIO;
45 }
46
47 return 0;
48}
49
50static int tps65219_bind(struct udevice *dev)
51{
52 ofnode regulators_node;
53 int children;
54
55 regulators_node = dev_read_subnode(dev, "regulators");
56 if (!ofnode_valid(regulators_node)) {
57 debug("%s: %s regulators subnode not found!\n", __func__,
58 dev->name);
59 }
60
61 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
62
63 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
64 if (!children)
65 printf("%s: %s - no child found\n", __func__, dev->name);
66
67 /* Probe all the child devices */
68 return dm_scan_fdt_dev(dev);
69}
70
71static struct dm_pmic_ops tps65219_ops = {
72 .reg_count = tps65219_reg_count,
73 .read = tps65219_read,
74 .write = tps65219_write,
75};
76
77static const struct udevice_id tps65219_ids[] = {
78 { .compatible = "ti,tps65219" },
79 { }
80};
81
82U_BOOT_DRIVER(pmic_tps65219) = {
83 .name = "tps65219_pmic",
84 .id = UCLASS_PMIC,
85 .of_match = tps65219_ids,
86 .bind = tps65219_bind,
87 .ops = &tps65219_ops,
88};