blob: 2a04d5948a5e4d407c399f068743ba383d3b1edc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassc0871112015-07-02 18:15:58 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glassc0871112015-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>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060013#include <linux/printk.h>
Simon Glassc0871112015-07-02 18:15:58 -060014#include <power/pmic.h>
15#include <power/tps65090.h>
16
Simon Glassc0871112015-07-02 18:15:58 -060017static const struct pmic_child_info pmic_children_info[] = {
18 { .prefix = "fet", .driver = TPS65090_FET_DRIVER },
19 { },
20};
21
22static int tps65090_reg_count(struct udevice *dev)
23{
24 return TPS65090_NUM_REGS;
25}
26
27static int tps65090_write(struct udevice *dev, uint reg, const uint8_t *buff,
28 int len)
29{
30 if (dm_i2c_write(dev, reg, buff, len)) {
Simon Glass73126ac2018-11-18 08:14:28 -070031 pr_err("write error to device: %p register: %#x!\n", dev, reg);
Simon Glassc0871112015-07-02 18:15:58 -060032 return -EIO;
33 }
34
35 return 0;
36}
37
38static int tps65090_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
39{
40 int ret;
41
42 ret = dm_i2c_read(dev, reg, buff, len);
43 if (ret) {
Simon Glass73126ac2018-11-18 08:14:28 -070044 pr_err("read error %d from device: %p register: %#x!\n", ret,
45 dev, reg);
Simon Glassc0871112015-07-02 18:15:58 -060046 return -EIO;
47 }
48
49 return 0;
50}
51
52static int tps65090_bind(struct udevice *dev)
53{
Simon Glass2c2d2c22017-05-18 20:09:32 -060054 ofnode regulators_node;
Simon Glassc0871112015-07-02 18:15:58 -060055 int children;
56
Simon Glass2c2d2c22017-05-18 20:09:32 -060057 regulators_node = dev_read_subnode(dev, "regulators");
58 if (!ofnode_valid(regulators_node)) {
Simon Glass73126ac2018-11-18 08:14:28 -070059 debug("%s: %s regulators subnode not found!\n", __func__,
Simon Glassc0871112015-07-02 18:15:58 -060060 dev->name);
61 return -ENXIO;
62 }
63
64 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
65
66 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
67 if (!children)
68 debug("%s: %s - no child found\n", __func__, dev->name);
69
70 /* Always return success for this device */
71 return 0;
72}
73
74static struct dm_pmic_ops tps65090_ops = {
75 .reg_count = tps65090_reg_count,
76 .read = tps65090_read,
77 .write = tps65090_write,
78};
79
80static const struct udevice_id tps65090_ids[] = {
81 { .compatible = "ti,tps65090" },
82 { }
83};
84
85U_BOOT_DRIVER(pmic_tps65090) = {
86 .name = "tps65090 pmic",
87 .id = UCLASS_PMIC,
88 .of_match = tps65090_ids,
89 .bind = tps65090_bind,
90 .ops = &tps65090_ops,
91};