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