blob: 727b42747ab60ab811d74402372c229ba7dbc18a [file] [log] [blame]
Keerthy6b86dd02019-10-24 15:00:50 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2019 Texas Instruments Incorporated, <www.ti.com>
4 * Keerthy <j-keerthy@ti.com>
5 */
6
7#include <common.h>
8#include <fdtdec.h>
9#include <errno.h>
10#include <dm.h>
11#include <i2c.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Simon Glass1e94b462023-09-14 18:21:46 -060013#include <linux/printk.h>
Keerthy6b86dd02019-10-24 15:00:50 +053014#include <power/pmic.h>
15#include <power/regulator.h>
16#include <power/tps65941.h>
17#include <dm/device.h>
18
19static const struct pmic_child_info pmic_children_info[] = {
20 { .prefix = "ldo", .driver = TPS65941_LDO_DRIVER },
21 { .prefix = "buck", .driver = TPS65941_BUCK_DRIVER },
22 { },
23};
24
25static int tps65941_write(struct udevice *dev, uint reg, const uint8_t *buff,
26 int len)
27{
28 if (dm_i2c_write(dev, reg, buff, len)) {
29 pr_err("write error to device: %p register: %#x!\n", dev, reg);
30 return -EIO;
31 }
32
33 return 0;
34}
35
36static int tps65941_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
37{
38 if (dm_i2c_read(dev, reg, buff, len)) {
39 pr_err("read error from device: %p register: %#x!\n", dev, reg);
40 return -EIO;
41 }
42
43 return 0;
44}
45
46static int tps65941_bind(struct udevice *dev)
47{
48 ofnode regulators_node;
49 int children;
50
51 regulators_node = dev_read_subnode(dev, "regulators");
52 if (!ofnode_valid(regulators_node)) {
53 debug("%s: %s regulators subnode not found!\n", __func__,
54 dev->name);
55 return -ENXIO;
56 }
57
58 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
59
60 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
61 if (!children)
62 printf("%s: %s - no child found\n", __func__, dev->name);
63
Tero Kristo8cd10a42020-02-14 11:18:14 +020064 /* Probe all the child devices */
65 return dm_scan_fdt_dev(dev);
Keerthy6b86dd02019-10-24 15:00:50 +053066}
67
68static struct dm_pmic_ops tps65941_ops = {
69 .read = tps65941_read,
70 .write = tps65941_write,
71};
72
73static const struct udevice_id tps65941_ids[] = {
74 { .compatible = "ti,tps659411", .data = TPS659411 },
Sinthu Raja3d32ad42022-02-09 15:06:46 +053075 { .compatible = "ti,tps659412", .data = TPS659411 },
Keerthy6b86dd02019-10-24 15:00:50 +053076 { .compatible = "ti,tps659413", .data = TPS659413 },
Gowtham Tammana6fdbd2b2021-07-14 15:52:56 -050077 { .compatible = "ti,lp876441", .data = LP876441 },
Keerthy6b86dd02019-10-24 15:00:50 +053078 { }
79};
80
81U_BOOT_DRIVER(pmic_tps65941) = {
82 .name = "tps65941_pmic",
83 .id = UCLASS_PMIC,
84 .of_match = tps65941_ids,
85 .bind = tps65941_bind,
86 .ops = &tps65941_ops,
87};