blob: ee5358bcedc8f82da8f70204f723d363e3fce7f2 [file] [log] [blame]
Simon Glass151b2232015-07-02 18:15:58 -06001/*
2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <errno.h>
11#include <fdtdec.h>
12#include <i2c.h>
13#include <power/pmic.h>
14#include <power/tps65090.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = "fet", .driver = TPS65090_FET_DRIVER },
20 { },
21};
22
23static int tps65090_reg_count(struct udevice *dev)
24{
25 return TPS65090_NUM_REGS;
26}
27
28static int tps65090_write(struct udevice *dev, uint reg, const uint8_t *buff,
29 int len)
30{
31 if (dm_i2c_write(dev, reg, buff, len)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090032 pr_err("write error to device: %p register: %#x!", dev, reg);
Simon Glass151b2232015-07-02 18:15:58 -060033 return -EIO;
34 }
35
36 return 0;
37}
38
39static int tps65090_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
40{
41 int ret;
42
43 ret = dm_i2c_read(dev, reg, buff, len);
44 if (ret) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090045 pr_err("read error %d from device: %p register: %#x!", ret, dev,
Simon Glass151b2232015-07-02 18:15:58 -060046 reg);
47 return -EIO;
48 }
49
50 return 0;
51}
52
53static int tps65090_bind(struct udevice *dev)
54{
Simon Glass7a869e62017-05-18 20:09:32 -060055 ofnode regulators_node;
Simon Glass151b2232015-07-02 18:15:58 -060056 int children;
57
Simon Glass7a869e62017-05-18 20:09:32 -060058 regulators_node = dev_read_subnode(dev, "regulators");
59 if (!ofnode_valid(regulators_node)) {
Simon Glass151b2232015-07-02 18:15:58 -060060 debug("%s: %s regulators subnode not found!", __func__,
61 dev->name);
62 return -ENXIO;
63 }
64
65 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
66
67 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
68 if (!children)
69 debug("%s: %s - no child found\n", __func__, dev->name);
70
71 /* Always return success for this device */
72 return 0;
73}
74
75static struct dm_pmic_ops tps65090_ops = {
76 .reg_count = tps65090_reg_count,
77 .read = tps65090_read,
78 .write = tps65090_write,
79};
80
81static const struct udevice_id tps65090_ids[] = {
82 { .compatible = "ti,tps65090" },
83 { }
84};
85
86U_BOOT_DRIVER(pmic_tps65090) = {
87 .name = "tps65090 pmic",
88 .id = UCLASS_PMIC,
89 .of_match = tps65090_ids,
90 .bind = tps65090_bind,
91 .ops = &tps65090_ops,
92};