blob: 32f2a938b285e3f9ef21c9282e6431590397284d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Keerthy33621d22016-09-30 09:20:43 +05302/*
3 * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
4 * Keerthy <j-keerthy@ti.com>
Keerthy33621d22016-09-30 09:20:43 +05305 */
6
7#include <common.h>
8#include <fdtdec.h>
9#include <errno.h>
10#include <dm.h>
Svyatoslav Ryhel4afdc7a2023-10-24 10:49:08 +030011#include <dm/lists.h>
Keerthy33621d22016-09-30 09:20:43 +053012#include <i2c.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Simon Glass1e94b462023-09-14 18:21:46 -060014#include <linux/printk.h>
Keerthy33621d22016-09-30 09:20:43 +053015#include <power/pmic.h>
16#include <power/regulator.h>
17#include <power/palmas.h>
Keerthy33621d22016-09-30 09:20:43 +053018
Keerthy33621d22016-09-30 09:20:43 +053019static const struct pmic_child_info pmic_children_info[] = {
20 { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
21 { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
22 { },
23};
24
25static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff,
26 int len)
27{
28 if (dm_i2c_write(dev, reg, buff, len)) {
Simon Glassc83c4362018-11-18 08:14:28 -070029 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Keerthy33621d22016-09-30 09:20:43 +053030 return -EIO;
31 }
32
33 return 0;
34}
35
36static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
37{
38 if (dm_i2c_read(dev, reg, buff, len)) {
Simon Glassc83c4362018-11-18 08:14:28 -070039 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Keerthy33621d22016-09-30 09:20:43 +053040 return -EIO;
41 }
42
43 return 0;
44}
45
46static int palmas_bind(struct udevice *dev)
47{
Simon Glass7a869e62017-05-18 20:09:32 -060048 ofnode pmic_node = ofnode_null(), regulators_node;
49 ofnode subnode;
Svyatoslav Ryhel4afdc7a2023-10-24 10:49:08 +030050 int children, ret;
51
52 if (IS_ENABLED(CONFIG_SYSRESET_PALMAS)) {
53 ret = device_bind_driver(dev, PALMAS_RST_DRIVER,
54 "sysreset", NULL);
55 if (ret) {
56 log_err("cannot bind SYSRESET (ret = %d)\n", ret);
57 return ret;
58 }
59 }
Keerthy33621d22016-09-30 09:20:43 +053060
Simon Glass7a869e62017-05-18 20:09:32 -060061 dev_for_each_subnode(subnode, dev) {
Keerthy33621d22016-09-30 09:20:43 +053062 const char *name;
63 char *temp;
64
Simon Glass7a869e62017-05-18 20:09:32 -060065 name = ofnode_get_name(subnode);
Keerthy33621d22016-09-30 09:20:43 +053066 temp = strstr(name, "pmic");
67 if (temp) {
68 pmic_node = subnode;
69 break;
70 }
71 }
72
Simon Glass7a869e62017-05-18 20:09:32 -060073 if (!ofnode_valid(pmic_node)) {
Simon Glassc83c4362018-11-18 08:14:28 -070074 debug("%s: %s pmic subnode not found!\n", __func__, dev->name);
Keerthy33621d22016-09-30 09:20:43 +053075 return -ENXIO;
76 }
77
Simon Glass7a869e62017-05-18 20:09:32 -060078 regulators_node = ofnode_find_subnode(pmic_node, "regulators");
Keerthy33621d22016-09-30 09:20:43 +053079
Simon Glass7a869e62017-05-18 20:09:32 -060080 if (!ofnode_valid(regulators_node)) {
Simon Glassc83c4362018-11-18 08:14:28 -070081 debug("%s: %s reg subnode not found!\n", __func__, dev->name);
Keerthy33621d22016-09-30 09:20:43 +053082 return -ENXIO;
83 }
84
85 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
86 if (!children)
87 debug("%s: %s - no child found\n", __func__, dev->name);
88
89 /* Always return success for this device */
90 return 0;
91}
92
Svyatoslav Ryhel4afdc7a2023-10-24 10:49:08 +030093static int palmas_probe(struct udevice *dev)
94{
95 struct dm_i2c_chip *chip = dev_get_parent_plat(dev);
96 struct palmas_priv *priv = dev_get_priv(dev);
97 struct udevice *bus = dev_get_parent(dev);
98 u32 chip2_addr = chip->chip_addr + 1;
99 int ret;
100
101 /* Palmas PMIC is multi chip and chips are located in a row */
102 ret = i2c_get_chip(bus, chip2_addr, 1, &priv->chip2);
103 if (ret) {
104 log_err("cannot get second PMIC I2C chip (err %d)\n", ret);
105 return ret;
106 }
107
108 return 0;
109}
110
Keerthy33621d22016-09-30 09:20:43 +0530111static struct dm_pmic_ops palmas_ops = {
112 .read = palmas_read,
113 .write = palmas_write,
114};
115
116static const struct udevice_id palmas_ids[] = {
117 { .compatible = "ti,tps659038", .data = TPS659038 },
Svyatoslav Ryhel8ab09b92023-10-27 11:26:08 +0300118 { .compatible = "ti,tps65913" , .data = TPS659038 },
Keerthy33621d22016-09-30 09:20:43 +0530119 { .compatible = "ti,tps65917" , .data = TPS65917 },
120 { }
121};
122
123U_BOOT_DRIVER(pmic_palmas) = {
124 .name = "palmas_pmic",
125 .id = UCLASS_PMIC,
126 .of_match = palmas_ids,
127 .bind = palmas_bind,
Svyatoslav Ryhel4afdc7a2023-10-24 10:49:08 +0300128 .probe = palmas_probe,
Keerthy33621d22016-09-30 09:20:43 +0530129 .ops = &palmas_ops,
Svyatoslav Ryhel4afdc7a2023-10-24 10:49:08 +0300130 .priv_auto = sizeof(struct palmas_priv),
Keerthy33621d22016-09-30 09:20:43 +0530131};