blob: 36be119b6cff84e030b4066d073984a03305ac11 [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>
11#include <i2c.h>
12#include <power/pmic.h>
13#include <power/regulator.h>
14#include <power/palmas.h>
15#include <dm/device.h>
16
Keerthy33621d22016-09-30 09:20:43 +053017static const struct pmic_child_info pmic_children_info[] = {
18 { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
19 { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
20 { },
21};
22
23static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff,
24 int len)
25{
26 if (dm_i2c_write(dev, reg, buff, len)) {
Simon Glassc83c4362018-11-18 08:14:28 -070027 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Keerthy33621d22016-09-30 09:20:43 +053028 return -EIO;
29 }
30
31 return 0;
32}
33
34static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
35{
36 if (dm_i2c_read(dev, reg, buff, len)) {
Simon Glassc83c4362018-11-18 08:14:28 -070037 pr_err("read error from device: %p register: %#x!\n", dev, reg);
Keerthy33621d22016-09-30 09:20:43 +053038 return -EIO;
39 }
40
41 return 0;
42}
43
44static int palmas_bind(struct udevice *dev)
45{
Simon Glass7a869e62017-05-18 20:09:32 -060046 ofnode pmic_node = ofnode_null(), regulators_node;
47 ofnode subnode;
Keerthy33621d22016-09-30 09:20:43 +053048 int children;
Keerthy33621d22016-09-30 09:20:43 +053049
Simon Glass7a869e62017-05-18 20:09:32 -060050 dev_for_each_subnode(subnode, dev) {
Keerthy33621d22016-09-30 09:20:43 +053051 const char *name;
52 char *temp;
53
Simon Glass7a869e62017-05-18 20:09:32 -060054 name = ofnode_get_name(subnode);
Keerthy33621d22016-09-30 09:20:43 +053055 temp = strstr(name, "pmic");
56 if (temp) {
57 pmic_node = subnode;
58 break;
59 }
60 }
61
Simon Glass7a869e62017-05-18 20:09:32 -060062 if (!ofnode_valid(pmic_node)) {
Simon Glassc83c4362018-11-18 08:14:28 -070063 debug("%s: %s pmic subnode not found!\n", __func__, dev->name);
Keerthy33621d22016-09-30 09:20:43 +053064 return -ENXIO;
65 }
66
Simon Glass7a869e62017-05-18 20:09:32 -060067 regulators_node = ofnode_find_subnode(pmic_node, "regulators");
Keerthy33621d22016-09-30 09:20:43 +053068
Simon Glass7a869e62017-05-18 20:09:32 -060069 if (!ofnode_valid(regulators_node)) {
Simon Glassc83c4362018-11-18 08:14:28 -070070 debug("%s: %s reg subnode not found!\n", __func__, dev->name);
Keerthy33621d22016-09-30 09:20:43 +053071 return -ENXIO;
72 }
73
74 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
75 if (!children)
76 debug("%s: %s - no child found\n", __func__, dev->name);
77
78 /* Always return success for this device */
79 return 0;
80}
81
82static struct dm_pmic_ops palmas_ops = {
83 .read = palmas_read,
84 .write = palmas_write,
85};
86
87static const struct udevice_id palmas_ids[] = {
88 { .compatible = "ti,tps659038", .data = TPS659038 },
89 { .compatible = "ti,tps65917" , .data = TPS65917 },
90 { }
91};
92
93U_BOOT_DRIVER(pmic_palmas) = {
94 .name = "palmas_pmic",
95 .id = UCLASS_PMIC,
96 .of_match = palmas_ids,
97 .bind = palmas_bind,
98 .ops = &palmas_ops,
99};