Simon Glass | 151b223 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 1 | /* |
| 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 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | static const struct pmic_child_info pmic_children_info[] = { |
| 19 | { .prefix = "fet", .driver = TPS65090_FET_DRIVER }, |
| 20 | { }, |
| 21 | }; |
| 22 | |
| 23 | static int tps65090_reg_count(struct udevice *dev) |
| 24 | { |
| 25 | return TPS65090_NUM_REGS; |
| 26 | } |
| 27 | |
| 28 | static 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)) { |
| 32 | error("write error to device: %p register: %#x!", dev, reg); |
| 33 | return -EIO; |
| 34 | } |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static 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) { |
| 45 | error("read error %d from device: %p register: %#x!", ret, dev, |
| 46 | reg); |
| 47 | return -EIO; |
| 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int tps65090_bind(struct udevice *dev) |
| 54 | { |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame^] | 55 | ofnode regulators_node; |
Simon Glass | 151b223 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 56 | int children; |
| 57 | |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame^] | 58 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 59 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | 151b223 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 60 | 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 | |
| 75 | static struct dm_pmic_ops tps65090_ops = { |
| 76 | .reg_count = tps65090_reg_count, |
| 77 | .read = tps65090_read, |
| 78 | .write = tps65090_write, |
| 79 | }; |
| 80 | |
| 81 | static const struct udevice_id tps65090_ids[] = { |
| 82 | { .compatible = "ti,tps65090" }, |
| 83 | { } |
| 84 | }; |
| 85 | |
| 86 | U_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 | }; |