Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Keerthy | ca1de0b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com> |
| 4 | * Keerthy <j-keerthy@ti.com> |
Keerthy | ca1de0b | 2016-09-30 09:34:02 +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/lp873x.h> |
| 15 | #include <dm/device.h> |
| 16 | |
Keerthy | ca1de0b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 17 | static const struct pmic_child_info pmic_children_info[] = { |
| 18 | { .prefix = "ldo", .driver = LP873X_LDO_DRIVER }, |
| 19 | { .prefix = "buck", .driver = LP873X_BUCK_DRIVER }, |
| 20 | { }, |
| 21 | }; |
| 22 | |
| 23 | static int lp873x_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 | ca1de0b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 28 | return -EIO; |
| 29 | } |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static int lp873x_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 | ca1de0b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 38 | return -EIO; |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static int lp873x_bind(struct udevice *dev) |
| 45 | { |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 46 | ofnode regulators_node; |
Keerthy | ca1de0b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 47 | int children; |
Keerthy | ca1de0b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 48 | |
Simon Glass | 7a869e6 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 49 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 50 | if (!ofnode_valid(regulators_node)) { |
| 51 | debug("%s: %s regulators subnode not found!", __func__, |
| 52 | dev->name); |
Keerthy | ca1de0b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 53 | return -ENXIO; |
| 54 | } |
| 55 | |
| 56 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 57 | if (!children) |
| 58 | printf("%s: %s - no child found\n", __func__, dev->name); |
| 59 | |
| 60 | /* Always return success for this device */ |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static struct dm_pmic_ops lp873x_ops = { |
| 65 | .read = lp873x_read, |
| 66 | .write = lp873x_write, |
| 67 | }; |
| 68 | |
| 69 | static const struct udevice_id lp873x_ids[] = { |
| 70 | { .compatible = "ti,lp8732", .data = LP8732 }, |
| 71 | { .compatible = "ti,lp8733" , .data = LP8733 }, |
| 72 | { } |
| 73 | }; |
| 74 | |
| 75 | U_BOOT_DRIVER(pmic_lp873x) = { |
| 76 | .name = "lp873x_pmic", |
| 77 | .id = UCLASS_PMIC, |
| 78 | .of_match = lp873x_ids, |
| 79 | .bind = lp873x_bind, |
| 80 | .ops = &lp873x_ops, |
| 81 | }; |