blob: 83d0f83c64ae5d1b97859e35c39446721866ccf4 [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>
Keerthy6b86dd02019-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 Kristo8cd10a42020-02-14 11:18:14 +020063 /* Probe all the child devices */
64 return dm_scan_fdt_dev(dev);
Keerthy6b86dd02019-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 Raja3d32ad42022-02-09 15:06:46 +053074 { .compatible = "ti,tps659412", .data = TPS659411 },
Keerthy6b86dd02019-10-24 15:00:50 +053075 { .compatible = "ti,tps659413", .data = TPS659413 },
Gowtham Tammana6fdbd2b2021-07-14 15:52:56 -050076 { .compatible = "ti,lp876441", .data = LP876441 },
Keerthy6b86dd02019-10-24 15:00:50 +053077 { }
78};
79
80U_BOOT_DRIVER(pmic_tps65941) = {
81 .name = "tps65941_pmic",
82 .id = UCLASS_PMIC,
83 .of_match = tps65941_ids,
84 .bind = tps65941_bind,
85 .ops = &tps65941_ops,
86};