Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com> |
| 4 | * Keerthy <j-keerthy@ti.com> |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <fdtdec.h> |
| 9 | #include <errno.h> |
| 10 | #include <dm.h> |
Svyatoslav Ryhel | eacea67 | 2023-10-24 10:49:08 +0300 | [diff] [blame] | 11 | #include <dm/lists.h> |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 12 | #include <i2c.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 14 | #include <linux/printk.h> |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 15 | #include <power/pmic.h> |
| 16 | #include <power/regulator.h> |
| 17 | #include <power/palmas.h> |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 18 | |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 19 | static const struct pmic_child_info pmic_children_info[] = { |
| 20 | { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER }, |
| 21 | { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER }, |
| 22 | { }, |
| 23 | }; |
| 24 | |
| 25 | static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 26 | int len) |
| 27 | { |
| 28 | if (dm_i2c_write(dev, reg, buff, len)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 29 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 30 | return -EIO; |
| 31 | } |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 37 | { |
| 38 | if (dm_i2c_read(dev, reg, buff, len)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 39 | pr_err("read error from device: %p register: %#x!\n", dev, reg); |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 40 | return -EIO; |
| 41 | } |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | static int palmas_bind(struct udevice *dev) |
| 47 | { |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 48 | ofnode pmic_node = ofnode_null(), regulators_node; |
| 49 | ofnode subnode; |
Svyatoslav Ryhel | eacea67 | 2023-10-24 10:49:08 +0300 | [diff] [blame] | 50 | int children, ret; |
| 51 | |
| 52 | if (IS_ENABLED(CONFIG_SYSRESET_PALMAS)) { |
| 53 | ret = device_bind_driver(dev, PALMAS_RST_DRIVER, |
| 54 | "sysreset", NULL); |
| 55 | if (ret) { |
| 56 | log_err("cannot bind SYSRESET (ret = %d)\n", ret); |
| 57 | return ret; |
| 58 | } |
| 59 | } |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 60 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 61 | dev_for_each_subnode(subnode, dev) { |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 62 | const char *name; |
| 63 | char *temp; |
| 64 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 65 | name = ofnode_get_name(subnode); |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 66 | temp = strstr(name, "pmic"); |
| 67 | if (temp) { |
| 68 | pmic_node = subnode; |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 73 | if (!ofnode_valid(pmic_node)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 74 | debug("%s: %s pmic subnode not found!\n", __func__, dev->name); |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 75 | return -ENXIO; |
| 76 | } |
| 77 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 78 | regulators_node = ofnode_find_subnode(pmic_node, "regulators"); |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 79 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 80 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 81 | debug("%s: %s reg subnode not found!\n", __func__, dev->name); |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 82 | return -ENXIO; |
| 83 | } |
| 84 | |
| 85 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 86 | if (!children) |
| 87 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 88 | |
| 89 | /* Always return success for this device */ |
| 90 | return 0; |
| 91 | } |
| 92 | |
Svyatoslav Ryhel | eacea67 | 2023-10-24 10:49:08 +0300 | [diff] [blame] | 93 | static int palmas_probe(struct udevice *dev) |
| 94 | { |
| 95 | struct dm_i2c_chip *chip = dev_get_parent_plat(dev); |
| 96 | struct palmas_priv *priv = dev_get_priv(dev); |
| 97 | struct udevice *bus = dev_get_parent(dev); |
| 98 | u32 chip2_addr = chip->chip_addr + 1; |
| 99 | int ret; |
| 100 | |
| 101 | /* Palmas PMIC is multi chip and chips are located in a row */ |
| 102 | ret = i2c_get_chip(bus, chip2_addr, 1, &priv->chip2); |
| 103 | if (ret) { |
| 104 | log_err("cannot get second PMIC I2C chip (err %d)\n", ret); |
| 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 111 | static struct dm_pmic_ops palmas_ops = { |
| 112 | .read = palmas_read, |
| 113 | .write = palmas_write, |
| 114 | }; |
| 115 | |
| 116 | static const struct udevice_id palmas_ids[] = { |
| 117 | { .compatible = "ti,tps659038", .data = TPS659038 }, |
Svyatoslav Ryhel | c6951c3 | 2023-10-27 11:26:08 +0300 | [diff] [blame] | 118 | { .compatible = "ti,tps65913" , .data = TPS659038 }, |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 119 | { .compatible = "ti,tps65917" , .data = TPS65917 }, |
| 120 | { } |
| 121 | }; |
| 122 | |
| 123 | U_BOOT_DRIVER(pmic_palmas) = { |
| 124 | .name = "palmas_pmic", |
| 125 | .id = UCLASS_PMIC, |
| 126 | .of_match = palmas_ids, |
| 127 | .bind = palmas_bind, |
Svyatoslav Ryhel | eacea67 | 2023-10-24 10:49:08 +0300 | [diff] [blame] | 128 | .probe = palmas_probe, |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 129 | .ops = &palmas_ops, |
Svyatoslav Ryhel | eacea67 | 2023-10-24 10:49:08 +0300 | [diff] [blame] | 130 | .priv_auto = sizeof(struct palmas_priv), |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 131 | }; |