blob: eb83c88d5641c272be33ccbac3fed0368c6ccd14 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Keerthyf0df1b12016-09-30 09:20:43 +05302/*
3 * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
4 * Keerthy <j-keerthy@ti.com>
Keerthyf0df1b12016-09-30 09:20:43 +05305 */
6
7#include <common.h>
8#include <fdtdec.h>
9#include <errno.h>
10#include <dm.h>
11#include <i2c.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060013#include <linux/printk.h>
Keerthyf0df1b12016-09-30 09:20:43 +053014#include <power/pmic.h>
15#include <power/regulator.h>
16#include <power/palmas.h>
17#include <dm/device.h>
18
Keerthyf0df1b12016-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 Glass73126ac2018-11-18 08:14:28 -070029 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Keerthyf0df1b12016-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 Glass73126ac2018-11-18 08:14:28 -070039 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Keerthyf0df1b12016-09-30 09:20:43 +053040 return -EIO;
41 }
42
43 return 0;
44}
45
46static int palmas_bind(struct udevice *dev)
47{
Simon Glass2c2d2c22017-05-18 20:09:32 -060048 ofnode pmic_node = ofnode_null(), regulators_node;
49 ofnode subnode;
Keerthyf0df1b12016-09-30 09:20:43 +053050 int children;
Keerthyf0df1b12016-09-30 09:20:43 +053051
Simon Glass2c2d2c22017-05-18 20:09:32 -060052 dev_for_each_subnode(subnode, dev) {
Keerthyf0df1b12016-09-30 09:20:43 +053053 const char *name;
54 char *temp;
55
Simon Glass2c2d2c22017-05-18 20:09:32 -060056 name = ofnode_get_name(subnode);
Keerthyf0df1b12016-09-30 09:20:43 +053057 temp = strstr(name, "pmic");
58 if (temp) {
59 pmic_node = subnode;
60 break;
61 }
62 }
63
Simon Glass2c2d2c22017-05-18 20:09:32 -060064 if (!ofnode_valid(pmic_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070065 debug("%s: %s pmic subnode not found!\n", __func__, dev->name);
Keerthyf0df1b12016-09-30 09:20:43 +053066 return -ENXIO;
67 }
68
Simon Glass2c2d2c22017-05-18 20:09:32 -060069 regulators_node = ofnode_find_subnode(pmic_node, "regulators");
Keerthyf0df1b12016-09-30 09:20:43 +053070
Simon Glass2c2d2c22017-05-18 20:09:32 -060071 if (!ofnode_valid(regulators_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070072 debug("%s: %s reg subnode not found!\n", __func__, dev->name);
Keerthyf0df1b12016-09-30 09:20:43 +053073 return -ENXIO;
74 }
75
76 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
77 if (!children)
78 debug("%s: %s - no child found\n", __func__, dev->name);
79
80 /* Always return success for this device */
81 return 0;
82}
83
84static struct dm_pmic_ops palmas_ops = {
85 .read = palmas_read,
86 .write = palmas_write,
87};
88
89static const struct udevice_id palmas_ids[] = {
90 { .compatible = "ti,tps659038", .data = TPS659038 },
91 { .compatible = "ti,tps65917" , .data = TPS65917 },
92 { }
93};
94
95U_BOOT_DRIVER(pmic_palmas) = {
96 .name = "palmas_pmic",
97 .id = UCLASS_PMIC,
98 .of_match = palmas_ids,
99 .bind = palmas_bind,
100 .ops = &palmas_ops,
101};