Neil Armstrong | e422fbe | 2022-04-27 13:28:09 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2022 BayLibre, SAS |
| 4 | * Author: Neil Armstrong <narmstrong@baylibre.com> |
| 5 | */ |
| 6 | |
Neil Armstrong | e422fbe | 2022-04-27 13:28:09 +0200 | [diff] [blame] | 7 | #include <fdtdec.h> |
| 8 | #include <errno.h> |
| 9 | #include <dm.h> |
| 10 | #include <i2c.h> |
| 11 | #include <log.h> |
| 12 | #include <power/pmic.h> |
| 13 | #include <power/regulator.h> |
| 14 | #include <power/tps65219.h> |
| 15 | #include <dm/device.h> |
| 16 | |
| 17 | static const struct pmic_child_info pmic_children_info[] = { |
| 18 | { .prefix = "ldo", .driver = TPS65219_LDO_DRIVER }, |
| 19 | { .prefix = "buck", .driver = TPS65219_BUCK_DRIVER }, |
| 20 | { }, |
| 21 | }; |
| 22 | |
| 23 | static int tps65219_reg_count(struct udevice *dev) |
| 24 | { |
| 25 | return 0x41; |
| 26 | } |
| 27 | |
| 28 | static int tps65219_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 29 | int len) |
| 30 | { |
| 31 | if (dm_i2c_write(dev, reg, buff, len)) { |
| 32 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
| 33 | return -EIO; |
| 34 | } |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static int tps65219_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 40 | { |
| 41 | if (dm_i2c_read(dev, reg, buff, len)) { |
| 42 | pr_err("read error from device: %p register: %#x!\n", dev, reg); |
| 43 | return -EIO; |
| 44 | } |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int tps65219_bind(struct udevice *dev) |
| 50 | { |
| 51 | ofnode regulators_node; |
| 52 | int children; |
| 53 | |
| 54 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 55 | if (!ofnode_valid(regulators_node)) { |
| 56 | debug("%s: %s regulators subnode not found!\n", __func__, |
| 57 | dev->name); |
| 58 | } |
| 59 | |
| 60 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 61 | |
| 62 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 63 | if (!children) |
| 64 | printf("%s: %s - no child found\n", __func__, dev->name); |
| 65 | |
| 66 | /* Probe all the child devices */ |
| 67 | return dm_scan_fdt_dev(dev); |
| 68 | } |
| 69 | |
| 70 | static struct dm_pmic_ops tps65219_ops = { |
| 71 | .reg_count = tps65219_reg_count, |
| 72 | .read = tps65219_read, |
| 73 | .write = tps65219_write, |
| 74 | }; |
| 75 | |
| 76 | static const struct udevice_id tps65219_ids[] = { |
| 77 | { .compatible = "ti,tps65219" }, |
| 78 | { } |
| 79 | }; |
| 80 | |
| 81 | U_BOOT_DRIVER(pmic_tps65219) = { |
| 82 | .name = "tps65219_pmic", |
| 83 | .id = UCLASS_PMIC, |
| 84 | .of_match = tps65219_ids, |
| 85 | .bind = tps65219_bind, |
| 86 | .ops = &tps65219_ops, |
| 87 | }; |