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> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame^] | 13 | #include <linux/printk.h> |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 14 | #include <power/pmic.h> |
| 15 | #include <power/tps65090.h> |
| 16 | |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 17 | static const struct pmic_child_info pmic_children_info[] = { |
| 18 | { .prefix = "fet", .driver = TPS65090_FET_DRIVER }, |
| 19 | { }, |
| 20 | }; |
| 21 | |
| 22 | static int tps65090_reg_count(struct udevice *dev) |
| 23 | { |
| 24 | return TPS65090_NUM_REGS; |
| 25 | } |
| 26 | |
| 27 | static 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 Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 31 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 32 | return -EIO; |
| 33 | } |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static 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 Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 44 | pr_err("read error %d from device: %p register: %#x!\n", ret, |
| 45 | dev, reg); |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 46 | return -EIO; |
| 47 | } |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static int tps65090_bind(struct udevice *dev) |
| 53 | { |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 54 | ofnode regulators_node; |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 55 | int children; |
| 56 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 57 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 58 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 59 | debug("%s: %s regulators subnode not found!\n", __func__, |
Simon Glass | c087111 | 2015-07-02 18:15:58 -0600 | [diff] [blame] | 60 | 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 | |
| 74 | static struct dm_pmic_ops tps65090_ops = { |
| 75 | .reg_count = tps65090_reg_count, |
| 76 | .read = tps65090_read, |
| 77 | .write = tps65090_write, |
| 78 | }; |
| 79 | |
| 80 | static const struct udevice_id tps65090_ids[] = { |
| 81 | { .compatible = "ti,tps65090" }, |
| 82 | { } |
| 83 | }; |
| 84 | |
| 85 | U_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 | }; |