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