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 | |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <errno.h> |
| 9 | #include <fdtdec.h> |
| 10 | #include <i2c.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 12 | #include <linux/printk.h> |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 13 | #include <power/pmic.h> |
| 14 | #include <power/tps65090.h> |
| 15 | |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 16 | static const struct pmic_child_info pmic_children_info[] = { |
| 17 | { .prefix = "fet", .driver = TPS65090_FET_DRIVER }, |
| 18 | { }, |
| 19 | }; |
| 20 | |
| 21 | static int tps65090_reg_count(struct udevice *dev) |
| 22 | { |
| 23 | return TPS65090_NUM_REGS; |
| 24 | } |
| 25 | |
| 26 | static int tps65090_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 27 | int len) |
| 28 | { |
| 29 | if (dm_i2c_write(dev, reg, buff, len)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 30 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 31 | return -EIO; |
| 32 | } |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static int tps65090_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 38 | { |
| 39 | int ret; |
| 40 | |
| 41 | ret = dm_i2c_read(dev, reg, buff, len); |
| 42 | if (ret) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 43 | pr_err("read error %d from device: %p register: %#x!\n", ret, |
| 44 | dev, reg); |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 45 | return -EIO; |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int tps65090_bind(struct udevice *dev) |
| 52 | { |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 53 | ofnode regulators_node; |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 54 | int children; |
| 55 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 56 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 57 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 58 | debug("%s: %s regulators subnode not found!\n", __func__, |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 59 | dev->name); |
| 60 | return -ENXIO; |
| 61 | } |
| 62 | |
| 63 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 64 | |
| 65 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 66 | if (!children) |
| 67 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 68 | |
| 69 | /* Always return success for this device */ |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static struct dm_pmic_ops tps65090_ops = { |
| 74 | .reg_count = tps65090_reg_count, |
| 75 | .read = tps65090_read, |
| 76 | .write = tps65090_write, |
| 77 | }; |
| 78 | |
| 79 | static const struct udevice_id tps65090_ids[] = { |
| 80 | { .compatible = "ti,tps65090" }, |
| 81 | { } |
| 82 | }; |
| 83 | |
| 84 | U_BOOT_DRIVER(pmic_tps65090) = { |
| 85 | .name = "tps65090 pmic", |
| 86 | .id = UCLASS_PMIC, |
| 87 | .of_match = tps65090_ids, |
| 88 | .bind = tps65090_bind, |
| 89 | .ops = &tps65090_ops, |
| 90 | }; |