blob: 6080cbff0beee21d9d479a611b251caa4b5add46 [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>
Keerthyf0df1b12016-09-30 09:20:43 +053013#include <power/pmic.h>
14#include <power/regulator.h>
15#include <power/palmas.h>
16#include <dm/device.h>
17
Keerthyf0df1b12016-09-30 09:20:43 +053018static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
20 { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
21 { },
22};
23
24static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff,
25 int len)
26{
27 if (dm_i2c_write(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070028 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Keerthyf0df1b12016-09-30 09:20:43 +053029 return -EIO;
30 }
31
32 return 0;
33}
34
35static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
36{
37 if (dm_i2c_read(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070038 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Keerthyf0df1b12016-09-30 09:20:43 +053039 return -EIO;
40 }
41
42 return 0;
43}
44
45static int palmas_bind(struct udevice *dev)
46{
Simon Glass2c2d2c22017-05-18 20:09:32 -060047 ofnode pmic_node = ofnode_null(), regulators_node;
48 ofnode subnode;
Keerthyf0df1b12016-09-30 09:20:43 +053049 int children;
Keerthyf0df1b12016-09-30 09:20:43 +053050
Simon Glass2c2d2c22017-05-18 20:09:32 -060051 dev_for_each_subnode(subnode, dev) {
Keerthyf0df1b12016-09-30 09:20:43 +053052 const char *name;
53 char *temp;
54
Simon Glass2c2d2c22017-05-18 20:09:32 -060055 name = ofnode_get_name(subnode);
Keerthyf0df1b12016-09-30 09:20:43 +053056 temp = strstr(name, "pmic");
57 if (temp) {
58 pmic_node = subnode;
59 break;
60 }
61 }
62
Simon Glass2c2d2c22017-05-18 20:09:32 -060063 if (!ofnode_valid(pmic_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070064 debug("%s: %s pmic subnode not found!\n", __func__, dev->name);
Keerthyf0df1b12016-09-30 09:20:43 +053065 return -ENXIO;
66 }
67
Simon Glass2c2d2c22017-05-18 20:09:32 -060068 regulators_node = ofnode_find_subnode(pmic_node, "regulators");
Keerthyf0df1b12016-09-30 09:20:43 +053069
Simon Glass2c2d2c22017-05-18 20:09:32 -060070 if (!ofnode_valid(regulators_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070071 debug("%s: %s reg subnode not found!\n", __func__, dev->name);
Keerthyf0df1b12016-09-30 09:20:43 +053072 return -ENXIO;
73 }
74
75 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
76 if (!children)
77 debug("%s: %s - no child found\n", __func__, dev->name);
78
79 /* Always return success for this device */
80 return 0;
81}
82
83static struct dm_pmic_ops palmas_ops = {
84 .read = palmas_read,
85 .write = palmas_write,
86};
87
88static const struct udevice_id palmas_ids[] = {
89 { .compatible = "ti,tps659038", .data = TPS659038 },
90 { .compatible = "ti,tps65917" , .data = TPS65917 },
91 { }
92};
93
94U_BOOT_DRIVER(pmic_palmas) = {
95 .name = "palmas_pmic",
96 .id = UCLASS_PMIC,
97 .of_match = palmas_ids,
98 .bind = palmas_bind,
99 .ops = &palmas_ops,
100};