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