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> |
| 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> |
| 17 | #include <dm/device.h> |
| 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; |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 50 | int children; |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 51 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 52 | dev_for_each_subnode(subnode, dev) { |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 53 | const char *name; |
| 54 | char *temp; |
| 55 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 56 | name = ofnode_get_name(subnode); |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 57 | temp = strstr(name, "pmic"); |
| 58 | if (temp) { |
| 59 | pmic_node = subnode; |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 64 | if (!ofnode_valid(pmic_node)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 65 | debug("%s: %s pmic subnode not found!\n", __func__, dev->name); |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 66 | return -ENXIO; |
| 67 | } |
| 68 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 69 | regulators_node = ofnode_find_subnode(pmic_node, "regulators"); |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 70 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 71 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 72 | debug("%s: %s reg subnode not found!\n", __func__, dev->name); |
Keerthy | f0df1b1 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 73 | return -ENXIO; |
| 74 | } |
| 75 | |
| 76 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 77 | if (!children) |
| 78 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 79 | |
| 80 | /* Always return success for this device */ |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static struct dm_pmic_ops palmas_ops = { |
| 85 | .read = palmas_read, |
| 86 | .write = palmas_write, |
| 87 | }; |
| 88 | |
| 89 | static const struct udevice_id palmas_ids[] = { |
| 90 | { .compatible = "ti,tps659038", .data = TPS659038 }, |
| 91 | { .compatible = "ti,tps65917" , .data = TPS65917 }, |
| 92 | { } |
| 93 | }; |
| 94 | |
| 95 | U_BOOT_DRIVER(pmic_palmas) = { |
| 96 | .name = "palmas_pmic", |
| 97 | .id = UCLASS_PMIC, |
| 98 | .of_match = palmas_ids, |
| 99 | .bind = palmas_bind, |
| 100 | .ops = &palmas_ops, |
| 101 | }; |