Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Keerthy | 33621d2 | 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 | 33621d2 | 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> |
| 12 | #include <power/pmic.h> |
| 13 | #include <power/regulator.h> |
| 14 | #include <power/palmas.h> |
| 15 | #include <dm/device.h> |
| 16 | |
Keerthy | 33621d2 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 17 | static const struct pmic_child_info pmic_children_info[] = { |
| 18 | { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER }, |
| 19 | { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER }, |
| 20 | { }, |
| 21 | }; |
| 22 | |
| 23 | static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 24 | int len) |
| 25 | { |
| 26 | if (dm_i2c_write(dev, reg, buff, len)) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 27 | pr_err("write error to device: %p register: %#x!", dev, reg); |
Keerthy | 33621d2 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 28 | return -EIO; |
| 29 | } |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 35 | { |
| 36 | if (dm_i2c_read(dev, reg, buff, len)) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 37 | pr_err("read error from device: %p register: %#x!", dev, reg); |
Keerthy | 33621d2 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 38 | return -EIO; |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static int palmas_bind(struct udevice *dev) |
| 45 | { |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 46 | ofnode pmic_node = ofnode_null(), regulators_node; |
| 47 | ofnode subnode; |
Keerthy | 33621d2 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 48 | int children; |
Keerthy | 33621d2 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 49 | |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 50 | dev_for_each_subnode(subnode, dev) { |
Keerthy | 33621d2 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 51 | const char *name; |
| 52 | char *temp; |
| 53 | |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 54 | name = ofnode_get_name(subnode); |
Keerthy | 33621d2 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 55 | temp = strstr(name, "pmic"); |
| 56 | if (temp) { |
| 57 | pmic_node = subnode; |
| 58 | break; |
| 59 | } |
| 60 | } |
| 61 | |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 62 | if (!ofnode_valid(pmic_node)) { |
Keerthy | 33621d2 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 63 | debug("%s: %s pmic subnode not found!", __func__, dev->name); |
| 64 | return -ENXIO; |
| 65 | } |
| 66 | |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 67 | regulators_node = ofnode_find_subnode(pmic_node, "regulators"); |
Keerthy | 33621d2 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 68 | |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 69 | if (!ofnode_valid(regulators_node)) { |
Keerthy | 33621d2 | 2016-09-30 09:20:43 +0530 | [diff] [blame] | 70 | debug("%s: %s reg subnode not found!", __func__, dev->name); |
| 71 | return -ENXIO; |
| 72 | } |
| 73 | |
| 74 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 75 | if (!children) |
| 76 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 77 | |
| 78 | /* Always return success for this device */ |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static struct dm_pmic_ops palmas_ops = { |
| 83 | .read = palmas_read, |
| 84 | .write = palmas_write, |
| 85 | }; |
| 86 | |
| 87 | static const struct udevice_id palmas_ids[] = { |
| 88 | { .compatible = "ti,tps659038", .data = TPS659038 }, |
| 89 | { .compatible = "ti,tps65917" , .data = TPS65917 }, |
| 90 | { } |
| 91 | }; |
| 92 | |
| 93 | U_BOOT_DRIVER(pmic_palmas) = { |
| 94 | .name = "palmas_pmic", |
| 95 | .id = UCLASS_PMIC, |
| 96 | .of_match = palmas_ids, |
| 97 | .bind = palmas_bind, |
| 98 | .ops = &palmas_ops, |
| 99 | }; |