Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Keerthy | cdad57a | 2017-06-07 19:08:28 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2017 Texas Instruments Incorporated, <www.ti.com> |
| 4 | * Keerthy <j-keerthy@ti.com> |
Keerthy | cdad57a | 2017-06-07 19:08:28 +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/lp87565.h> |
| 15 | #include <dm/device.h> |
| 16 | |
Keerthy | cdad57a | 2017-06-07 19:08:28 +0530 | [diff] [blame] | 17 | static const struct pmic_child_info pmic_children_info[] = { |
| 18 | { .prefix = "buck", .driver = LP87565_BUCK_DRIVER }, |
| 19 | { }, |
| 20 | }; |
| 21 | |
| 22 | static int lp87565_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 23 | int len) |
| 24 | { |
| 25 | int ret; |
| 26 | |
| 27 | ret = dm_i2c_write(dev, reg, buff, len); |
| 28 | if (ret) |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 29 | pr_err("write error to device: %p register: %#x!", dev, reg); |
Keerthy | cdad57a | 2017-06-07 19:08:28 +0530 | [diff] [blame] | 30 | |
| 31 | return ret; |
| 32 | } |
| 33 | |
| 34 | static int lp87565_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 35 | { |
| 36 | int ret; |
| 37 | |
| 38 | ret = dm_i2c_read(dev, reg, buff, len); |
| 39 | if (ret) |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 40 | pr_err("read error from device: %p register: %#x!", dev, reg); |
Keerthy | cdad57a | 2017-06-07 19:08:28 +0530 | [diff] [blame] | 41 | |
| 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | static int lp87565_bind(struct udevice *dev) |
| 46 | { |
| 47 | ofnode regulators_node; |
| 48 | int children; |
| 49 | |
| 50 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 51 | if (!ofnode_valid(regulators_node)) { |
| 52 | debug("%s: %s regulators subnode not found!", __func__, |
| 53 | dev->name); |
| 54 | return -ENXIO; |
| 55 | } |
| 56 | |
| 57 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 58 | |
| 59 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 60 | if (!children) |
| 61 | printf("%s: %s - no child found\n", __func__, dev->name); |
| 62 | |
| 63 | /* Always return success for this device */ |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static struct dm_pmic_ops lp87565_ops = { |
| 68 | .read = lp87565_read, |
| 69 | .write = lp87565_write, |
| 70 | }; |
| 71 | |
| 72 | static const struct udevice_id lp87565_ids[] = { |
| 73 | { .compatible = "ti,lp87565", .data = LP87565 }, |
| 74 | { .compatible = "ti,lp87565-q1", .data = LP87565_Q1 }, |
| 75 | { } |
| 76 | }; |
| 77 | |
| 78 | U_BOOT_DRIVER(pmic_lp87565) = { |
| 79 | .name = "lp87565_pmic", |
| 80 | .id = UCLASS_PMIC, |
| 81 | .of_match = lp87565_ids, |
| 82 | .bind = lp87565_bind, |
| 83 | .ops = &lp87565_ops, |
| 84 | }; |