Svyatoslav Ryhel | 8f0fa2b | 2023-10-27 11:26:12 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright(C) 2023 Svyatoslav Ryhel <clamor95@gmail.com> |
| 4 | */ |
| 5 | |
| 6 | #include <dm.h> |
| 7 | #include <dm/lists.h> |
| 8 | #include <power/pmic.h> |
| 9 | #include <power/tps80031.h> |
| 10 | |
| 11 | static const struct pmic_child_info pmic_children_info[] = { |
| 12 | { .prefix = "ldo", .driver = TPS80031_LDO_DRIVER }, |
| 13 | { .prefix = "smps", .driver = TPS80031_SMPS_DRIVER }, |
| 14 | { }, |
| 15 | }; |
| 16 | |
| 17 | static int tps80031_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 18 | int len) |
| 19 | { |
| 20 | int ret; |
| 21 | |
| 22 | ret = dm_i2c_write(dev, reg, buff, len); |
| 23 | if (ret) { |
| 24 | log_debug("write error to device: %p register: %#x!\n", dev, reg); |
| 25 | return ret; |
| 26 | } |
| 27 | |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | static int tps80031_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 32 | { |
| 33 | int ret; |
| 34 | |
| 35 | ret = dm_i2c_read(dev, reg, buff, len); |
| 36 | if (ret) { |
| 37 | log_debug("read error from device: %p register: %#x!\n", dev, reg); |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static int tps80031_bind(struct udevice *dev) |
| 45 | { |
| 46 | ofnode regulators_node; |
Svyatoslav Ryhel | b72803f | 2023-10-24 10:49:06 +0300 | [diff] [blame] | 47 | int children, ret; |
| 48 | |
| 49 | if (IS_ENABLED(CONFIG_SYSRESET_TPS80031)) { |
| 50 | ret = device_bind_driver(dev, TPS80031_RST_DRIVER, |
| 51 | "sysreset", NULL); |
| 52 | if (ret) { |
| 53 | log_err("cannot bind SYSRESET (ret = %d)\n", ret); |
| 54 | return ret; |
| 55 | } |
| 56 | } |
Svyatoslav Ryhel | 8f0fa2b | 2023-10-27 11:26:12 +0300 | [diff] [blame] | 57 | |
| 58 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 59 | if (!ofnode_valid(regulators_node)) { |
| 60 | log_err("%s regulators subnode not found!\n", 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 | log_err("%s - no child found\n", dev->name); |
| 69 | |
| 70 | /* Always return success for this device */ |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static struct dm_pmic_ops tps80031_ops = { |
| 75 | .read = tps80031_read, |
| 76 | .write = tps80031_write, |
| 77 | }; |
| 78 | |
| 79 | static const struct udevice_id tps80031_ids[] = { |
| 80 | { .compatible = "ti,tps80031" }, |
| 81 | { .compatible = "ti,tps80032" }, |
| 82 | { } |
| 83 | }; |
| 84 | |
| 85 | U_BOOT_DRIVER(pmic_tps80031) = { |
| 86 | .name = "tps80031_pmic", |
| 87 | .id = UCLASS_PMIC, |
| 88 | .of_match = tps80031_ids, |
| 89 | .bind = tps80031_bind, |
| 90 | .ops = &tps80031_ops, |
| 91 | }; |