Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 5 | */ |
| 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 Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 15 | static const struct pmic_child_info pmic_children_info[] = { |
| 16 | { .prefix = "fet", .driver = TPS65090_FET_DRIVER }, |
| 17 | { }, |
| 18 | }; |
| 19 | |
| 20 | static int tps65090_reg_count(struct udevice *dev) |
| 21 | { |
| 22 | return TPS65090_NUM_REGS; |
| 23 | } |
| 24 | |
| 25 | static 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)) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 29 | pr_err("write error to device: %p register: %#x!", dev, reg); |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 30 | return -EIO; |
| 31 | } |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static 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) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 42 | pr_err("read error %d from device: %p register: %#x!", ret, dev, |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 43 | reg); |
| 44 | return -EIO; |
| 45 | } |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int tps65090_bind(struct udevice *dev) |
| 51 | { |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 52 | ofnode regulators_node; |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 53 | int children; |
| 54 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 55 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 56 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 57 | debug("%s: %s regulators subnode not found!", __func__, |
| 58 | 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 | |
| 72 | static struct dm_pmic_ops tps65090_ops = { |
| 73 | .reg_count = tps65090_reg_count, |
| 74 | .read = tps65090_read, |
| 75 | .write = tps65090_write, |
| 76 | }; |
| 77 | |
| 78 | static const struct udevice_id tps65090_ids[] = { |
| 79 | { .compatible = "ti,tps65090" }, |
| 80 | { } |
| 81 | }; |
| 82 | |
| 83 | U_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 | }; |