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