Ye Li | c3ee909 | 2019-10-15 02:15:18 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2019 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <fdtdec.h> |
| 8 | #include <errno.h> |
| 9 | #include <dm.h> |
| 10 | #include <i2c.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Ye Li | c3ee909 | 2019-10-15 02:15:18 -0700 | [diff] [blame] | 13 | #include <power/pmic.h> |
| 14 | #include <power/regulator.h> |
| 15 | #include <power/pca9450.h> |
| 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
| 19 | static const struct pmic_child_info pmic_children_info[] = { |
| 20 | /* buck */ |
| 21 | { .prefix = "b", .driver = PCA9450_REGULATOR_DRIVER}, |
Marek Vasut | 1d6dd08 | 2022-05-20 05:10:16 +0200 | [diff] [blame] | 22 | { .prefix = "B", .driver = PCA9450_REGULATOR_DRIVER}, |
Ye Li | c3ee909 | 2019-10-15 02:15:18 -0700 | [diff] [blame] | 23 | /* ldo */ |
| 24 | { .prefix = "l", .driver = PCA9450_REGULATOR_DRIVER}, |
Marek Vasut | 1d6dd08 | 2022-05-20 05:10:16 +0200 | [diff] [blame] | 25 | { .prefix = "L", .driver = PCA9450_REGULATOR_DRIVER}, |
Ye Li | c3ee909 | 2019-10-15 02:15:18 -0700 | [diff] [blame] | 26 | { }, |
| 27 | }; |
| 28 | |
| 29 | static int pca9450_reg_count(struct udevice *dev) |
| 30 | { |
| 31 | return PCA9450_REG_NUM; |
| 32 | } |
| 33 | |
| 34 | static int pca9450_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 35 | int len) |
| 36 | { |
| 37 | if (dm_i2c_write(dev, reg, buff, len)) { |
| 38 | pr_err("write error to device: %p register: %#x!", dev, reg); |
| 39 | return -EIO; |
| 40 | } |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int pca9450_read(struct udevice *dev, uint reg, uint8_t *buff, |
| 46 | int len) |
| 47 | { |
| 48 | if (dm_i2c_read(dev, reg, buff, len)) { |
| 49 | pr_err("read error from device: %p register: %#x!", dev, reg); |
| 50 | return -EIO; |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static int pca9450_bind(struct udevice *dev) |
| 57 | { |
| 58 | int children; |
| 59 | ofnode regulators_node; |
| 60 | |
| 61 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 62 | if (!ofnode_valid(regulators_node)) { |
| 63 | debug("%s: %s regulators subnode not found!", __func__, |
| 64 | dev->name); |
| 65 | return -ENXIO; |
| 66 | } |
| 67 | |
| 68 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 69 | |
| 70 | children = pmic_bind_children(dev, regulators_node, |
| 71 | pmic_children_info); |
| 72 | if (!children) |
| 73 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 74 | |
| 75 | /* Always return success for this device */ |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | static struct dm_pmic_ops pca9450_ops = { |
| 80 | .reg_count = pca9450_reg_count, |
| 81 | .read = pca9450_read, |
| 82 | .write = pca9450_write, |
| 83 | }; |
| 84 | |
| 85 | static const struct udevice_id pca9450_ids[] = { |
Marek Vasut | 5d9b83d | 2022-05-20 05:10:17 +0200 | [diff] [blame] | 86 | { .compatible = "nxp,pca9450a", .data = NXP_CHIP_TYPE_PCA9450A, }, |
| 87 | { .compatible = "nxp,pca9450b", .data = NXP_CHIP_TYPE_PCA9450BC, }, |
| 88 | { .compatible = "nxp,pca9450c", .data = NXP_CHIP_TYPE_PCA9450BC, }, |
Ye Li | c3ee909 | 2019-10-15 02:15:18 -0700 | [diff] [blame] | 89 | { } |
| 90 | }; |
| 91 | |
| 92 | U_BOOT_DRIVER(pmic_pca9450) = { |
| 93 | .name = "pca9450 pmic", |
| 94 | .id = UCLASS_PMIC, |
| 95 | .of_match = pca9450_ids, |
| 96 | .bind = pca9450_bind, |
| 97 | .ops = &pca9450_ops, |
| 98 | }; |