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