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