blob: c3490db2a089850db40cf205fe52cb32a26a6bab [file] [log] [blame]
Keerthya36bb3c2019-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
Keerthya36bb3c2019-10-24 15:00:50 +05307#include <fdtdec.h>
8#include <errno.h>
9#include <dm.h>
10#include <i2c.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060012#include <linux/printk.h>
Keerthya36bb3c2019-10-24 15:00:50 +053013#include <power/pmic.h>
14#include <power/regulator.h>
15#include <power/tps65941.h>
16#include <dm/device.h>
17
18static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = "ldo", .driver = TPS65941_LDO_DRIVER },
20 { .prefix = "buck", .driver = TPS65941_BUCK_DRIVER },
21 { },
22};
23
24static int tps65941_write(struct udevice *dev, uint reg, const uint8_t *buff,
25 int len)
26{
27 if (dm_i2c_write(dev, reg, buff, len)) {
28 pr_err("write error to device: %p register: %#x!\n", dev, reg);
29 return -EIO;
30 }
31
32 return 0;
33}
34
35static int tps65941_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
36{
37 if (dm_i2c_read(dev, reg, buff, len)) {
38 pr_err("read error from device: %p register: %#x!\n", dev, reg);
39 return -EIO;
40 }
41
42 return 0;
43}
44
45static int tps65941_bind(struct udevice *dev)
46{
47 ofnode regulators_node;
48 int children;
49
50 regulators_node = dev_read_subnode(dev, "regulators");
51 if (!ofnode_valid(regulators_node)) {
52 debug("%s: %s regulators subnode not found!\n", __func__,
53 dev->name);
54 return -ENXIO;
55 }
56
57 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
58
59 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
60 if (!children)
61 printf("%s: %s - no child found\n", __func__, dev->name);
62
Tero Kristob74e7742020-02-14 11:18:14 +020063 /* Probe all the child devices */
64 return dm_scan_fdt_dev(dev);
Keerthya36bb3c2019-10-24 15:00:50 +053065}
66
67static struct dm_pmic_ops tps65941_ops = {
68 .read = tps65941_read,
69 .write = tps65941_write,
70};
71
72static const struct udevice_id tps65941_ids[] = {
73 { .compatible = "ti,tps659411", .data = TPS659411 },
Sinthu Rajae8146ea2022-02-09 15:06:46 +053074 { .compatible = "ti,tps659412", .data = TPS659411 },
Keerthya36bb3c2019-10-24 15:00:50 +053075 { .compatible = "ti,tps659413", .data = TPS659413 },
Gowtham Tammana48a90fa2021-07-14 15:52:56 -050076 { .compatible = "ti,lp876441", .data = LP876441 },
Bhargav Raviprakashfdb39e02024-04-22 09:48:46 +000077 { .compatible = "ti,tps65224", .data = TPS65224 },
Udit Kumar2675c9f2024-04-19 11:30:16 +053078 { .compatible = "ti,tps6594-q1", .data = TPS659411 },
79 { .compatible = "ti,tps6593-q1", .data = TPS659413 },
80 { .compatible = "ti,lp8764-q1", .data = LP876441 },
Keerthya36bb3c2019-10-24 15:00:50 +053081 { }
82};
83
84U_BOOT_DRIVER(pmic_tps65941) = {
85 .name = "tps65941_pmic",
86 .id = UCLASS_PMIC,
87 .of_match = tps65941_ids,
88 .bind = tps65941_bind,
89 .ops = &tps65941_ops,
90};