Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Keerthy | 662797b | 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 | 662797b | 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> |
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 | 662797b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 14 | #include <power/pmic.h> |
| 15 | #include <power/regulator.h> |
| 16 | #include <power/lp873x.h> |
| 17 | #include <dm/device.h> |
| 18 | |
Keerthy | 662797b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 19 | static const struct pmic_child_info pmic_children_info[] = { |
| 20 | { .prefix = "ldo", .driver = LP873X_LDO_DRIVER }, |
| 21 | { .prefix = "buck", .driver = LP873X_BUCK_DRIVER }, |
| 22 | { }, |
| 23 | }; |
| 24 | |
| 25 | static int lp873x_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 26 | int len) |
| 27 | { |
| 28 | if (dm_i2c_write(dev, reg, buff, len)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 29 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
Keerthy | 662797b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 30 | return -EIO; |
| 31 | } |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static int lp873x_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 37 | { |
| 38 | if (dm_i2c_read(dev, reg, buff, len)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 39 | pr_err("read error from device: %p register: %#x!\n", dev, reg); |
Keerthy | 662797b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 40 | return -EIO; |
| 41 | } |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | static int lp873x_bind(struct udevice *dev) |
| 47 | { |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 48 | ofnode regulators_node; |
Keerthy | 662797b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 49 | int children; |
Keerthy | 662797b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 50 | |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 51 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 52 | if (!ofnode_valid(regulators_node)) { |
Simon Glass | 73126ac | 2018-11-18 08:14:28 -0700 | [diff] [blame] | 53 | debug("%s: %s regulators subnode not found!\n", __func__, |
Simon Glass | 2c2d2c2 | 2017-05-18 20:09:32 -0600 | [diff] [blame] | 54 | dev->name); |
Keerthy | 662797b | 2016-09-30 09:34:02 +0530 | [diff] [blame] | 55 | return -ENXIO; |
| 56 | } |
| 57 | |
| 58 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 59 | if (!children) |
| 60 | printf("%s: %s - no child found\n", __func__, dev->name); |
| 61 | |
| 62 | /* Always return success for this device */ |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static struct dm_pmic_ops lp873x_ops = { |
| 67 | .read = lp873x_read, |
| 68 | .write = lp873x_write, |
| 69 | }; |
| 70 | |
| 71 | static const struct udevice_id lp873x_ids[] = { |
| 72 | { .compatible = "ti,lp8732", .data = LP8732 }, |
| 73 | { .compatible = "ti,lp8733" , .data = LP8733 }, |
| 74 | { } |
| 75 | }; |
| 76 | |
| 77 | U_BOOT_DRIVER(pmic_lp873x) = { |
| 78 | .name = "lp873x_pmic", |
| 79 | .id = UCLASS_PMIC, |
| 80 | .of_match = lp873x_ids, |
| 81 | .bind = lp873x_bind, |
| 82 | .ops = &lp873x_ops, |
| 83 | }; |