Keerthy | a36bb3c | 2019-10-24 15:00:50 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2019 Texas Instruments Incorporated, <www.ti.com> |
| 4 | * Keerthy <j-keerthy@ti.com> |
| 5 | */ |
| 6 | |
Keerthy | a36bb3c | 2019-10-24 15:00:50 +0530 | [diff] [blame] | 7 | #include <fdtdec.h> |
| 8 | #include <errno.h> |
| 9 | #include <dm.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> |
Keerthy | a36bb3c | 2019-10-24 15:00:50 +0530 | [diff] [blame] | 13 | #include <power/pmic.h> |
| 14 | #include <power/regulator.h> |
| 15 | #include <power/tps65941.h> |
| 16 | #include <dm/device.h> |
| 17 | |
| 18 | static const struct pmic_child_info pmic_children_info[] = { |
| 19 | { .prefix = "ldo", .driver = TPS65941_LDO_DRIVER }, |
| 20 | { .prefix = "buck", .driver = TPS65941_BUCK_DRIVER }, |
| 21 | { }, |
| 22 | }; |
| 23 | |
| 24 | static int tps65941_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 25 | int len) |
| 26 | { |
| 27 | if (dm_i2c_write(dev, reg, buff, len)) { |
| 28 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
| 29 | return -EIO; |
| 30 | } |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | static int tps65941_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 36 | { |
| 37 | if (dm_i2c_read(dev, reg, buff, len)) { |
| 38 | pr_err("read error from device: %p register: %#x!\n", dev, reg); |
| 39 | return -EIO; |
| 40 | } |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int tps65941_bind(struct udevice *dev) |
| 46 | { |
| 47 | ofnode regulators_node; |
| 48 | int children; |
| 49 | |
| 50 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 51 | if (!ofnode_valid(regulators_node)) { |
| 52 | debug("%s: %s regulators subnode not found!\n", __func__, |
| 53 | dev->name); |
| 54 | return -ENXIO; |
| 55 | } |
| 56 | |
| 57 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 58 | |
| 59 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 60 | if (!children) |
| 61 | printf("%s: %s - no child found\n", __func__, dev->name); |
| 62 | |
Tero Kristo | b74e774 | 2020-02-14 11:18:14 +0200 | [diff] [blame] | 63 | /* Probe all the child devices */ |
| 64 | return dm_scan_fdt_dev(dev); |
Keerthy | a36bb3c | 2019-10-24 15:00:50 +0530 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static struct dm_pmic_ops tps65941_ops = { |
| 68 | .read = tps65941_read, |
| 69 | .write = tps65941_write, |
| 70 | }; |
| 71 | |
| 72 | static const struct udevice_id tps65941_ids[] = { |
| 73 | { .compatible = "ti,tps659411", .data = TPS659411 }, |
Sinthu Raja | e8146ea | 2022-02-09 15:06:46 +0530 | [diff] [blame] | 74 | { .compatible = "ti,tps659412", .data = TPS659411 }, |
Keerthy | a36bb3c | 2019-10-24 15:00:50 +0530 | [diff] [blame] | 75 | { .compatible = "ti,tps659413", .data = TPS659413 }, |
Gowtham Tammana | 48a90fa | 2021-07-14 15:52:56 -0500 | [diff] [blame] | 76 | { .compatible = "ti,lp876441", .data = LP876441 }, |
Bhargav Raviprakash | fdb39e0 | 2024-04-22 09:48:46 +0000 | [diff] [blame] | 77 | { .compatible = "ti,tps65224", .data = TPS65224 }, |
Udit Kumar | 2675c9f | 2024-04-19 11:30:16 +0530 | [diff] [blame] | 78 | { .compatible = "ti,tps6594-q1", .data = TPS659411 }, |
| 79 | { .compatible = "ti,tps6593-q1", .data = TPS659413 }, |
| 80 | { .compatible = "ti,lp8764-q1", .data = LP876441 }, |
Keerthy | a36bb3c | 2019-10-24 15:00:50 +0530 | [diff] [blame] | 81 | { } |
| 82 | }; |
| 83 | |
| 84 | U_BOOT_DRIVER(pmic_tps65941) = { |
| 85 | .name = "tps65941_pmic", |
| 86 | .id = UCLASS_PMIC, |
| 87 | .of_match = tps65941_ids, |
| 88 | .bind = tps65941_bind, |
| 89 | .ops = &tps65941_ops, |
| 90 | }; |