blob: ecf836eb0e659002ad64f5f0696ed6f69758eda7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Felix Brack9493f0e2017-11-30 13:52:37 +01002/*
3 * Copyright (C) EETS GmbH, 2017, Felix Brack <f.brack@eets.ch>
Felix Brack9493f0e2017-11-30 13:52:37 +01004 */
5
6#include <common.h>
7#include <dm.h>
Svyatoslav Ryhelab97ca22023-10-24 10:49:07 +03008#include <dm/lists.h>
Felix Brack9493f0e2017-11-30 13:52:37 +01009#include <i2c.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060011#include <linux/printk.h>
Felix Brack9493f0e2017-11-30 13:52:37 +010012#include <power/pmic.h>
13#include <power/regulator.h>
14#include <power/tps65910_pmic.h>
15
Svyatoslav Ryhel04081b52023-10-27 11:26:14 +030016static const struct pmic_child_info tps65910_children_info[] = {
Felix Brack9493f0e2017-11-30 13:52:37 +010017 { .prefix = "ldo_", .driver = TPS65910_LDO_DRIVER },
18 { .prefix = "buck_", .driver = TPS65910_BUCK_DRIVER },
19 { .prefix = "boost_", .driver = TPS65910_BOOST_DRIVER },
20 { },
21};
22
Svyatoslav Ryhel04081b52023-10-27 11:26:14 +030023static const struct pmic_child_info tps65911_children_info[] = {
24 { .prefix = "ldo", .driver = TPS65911_LDO_DRIVER },
25 { .prefix = "vdd", .driver = TPS65911_VDD_DRIVER },
26 { },
27};
28
Felix Brack9493f0e2017-11-30 13:52:37 +010029static int pmic_tps65910_reg_count(struct udevice *dev)
30{
31 return TPS65910_NUM_REGS;
32}
33
34static int pmic_tps65910_write(struct udevice *dev, uint reg, const u8 *buffer,
35 int len)
36{
37 int ret;
38
39 ret = dm_i2c_write(dev, reg, buffer, len);
40 if (ret)
Felix Brackabdd51d2017-12-18 15:38:28 +010041 pr_err("%s write error on register %02x\n", dev->name, reg);
Felix Brack9493f0e2017-11-30 13:52:37 +010042
43 return ret;
44}
45
46static int pmic_tps65910_read(struct udevice *dev, uint reg, u8 *buffer,
47 int len)
48{
49 int ret;
50
51 ret = dm_i2c_read(dev, reg, buffer, len);
52 if (ret)
Felix Brackabdd51d2017-12-18 15:38:28 +010053 pr_err("%s read error on register %02x\n", dev->name, reg);
Felix Brack9493f0e2017-11-30 13:52:37 +010054
55 return ret;
56}
57
58static int pmic_tps65910_bind(struct udevice *dev)
59{
Svyatoslav Ryhel04081b52023-10-27 11:26:14 +030060 const struct pmic_child_info *tps6591x_children_info =
61 (struct pmic_child_info *)dev_get_driver_data(dev);
Felix Brack9493f0e2017-11-30 13:52:37 +010062 ofnode regulators_node;
Svyatoslav Ryhelab97ca22023-10-24 10:49:07 +030063 int children, ret;
64
65 if (IS_ENABLED(CONFIG_SYSRESET_TPS65910)) {
66 ret = device_bind_driver(dev, TPS65910_RST_DRIVER,
67 "sysreset", NULL);
68 if (ret) {
69 log_err("cannot bind SYSRESET (ret = %d)\n", ret);
70 return ret;
71 }
72 }
Felix Brack9493f0e2017-11-30 13:52:37 +010073
74 regulators_node = dev_read_subnode(dev, "regulators");
75 if (!ofnode_valid(regulators_node)) {
76 debug("%s regulators subnode not found\n", dev->name);
77 return -EINVAL;
78 }
79
Svyatoslav Ryhel04081b52023-10-27 11:26:14 +030080 children = pmic_bind_children(dev, regulators_node, tps6591x_children_info);
Felix Brack9493f0e2017-11-30 13:52:37 +010081 if (!children)
82 debug("%s has no children (regulators)\n", dev->name);
83
84 return 0;
85}
86
87static int pmic_tps65910_probe(struct udevice *dev)
88{
89 /* use I2C control interface instead of I2C smartreflex interface to
90 * access smartrefelex registers VDD1_OP_REG, VDD1_SR_REG, VDD2_OP_REG
91 * and VDD2_SR_REG
92 */
93 return pmic_clrsetbits(dev, TPS65910_REG_DEVICE_CTRL, 0,
94 TPS65910_I2C_SEL_MASK);
95}
96
97static struct dm_pmic_ops pmic_tps65910_ops = {
98 .reg_count = pmic_tps65910_reg_count,
99 .read = pmic_tps65910_read,
100 .write = pmic_tps65910_write,
101};
102
103static const struct udevice_id pmic_tps65910_match[] = {
Svyatoslav Ryhel04081b52023-10-27 11:26:14 +0300104 { .compatible = "ti,tps65910", .data = (ulong)&tps65910_children_info },
105 { .compatible = "ti,tps65911", .data = (ulong)&tps65911_children_info },
Felix Brack9493f0e2017-11-30 13:52:37 +0100106 { /* sentinel */ }
107};
108
109U_BOOT_DRIVER(pmic_tps65910) = {
110 .name = "pmic_tps65910",
111 .id = UCLASS_PMIC,
112 .of_match = pmic_tps65910_match,
113 .bind = pmic_tps65910_bind,
114 .probe = pmic_tps65910_probe,
115 .ops = &pmic_tps65910_ops,
116};