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