Ye Li | 22172f6 | 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 | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Ye Li | 22172f6 | 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}, |
| 22 | /* ldo */ |
| 23 | { .prefix = "l", .driver = PCA9450_REGULATOR_DRIVER}, |
| 24 | { }, |
| 25 | }; |
| 26 | |
| 27 | static int pca9450_reg_count(struct udevice *dev) |
| 28 | { |
| 29 | return PCA9450_REG_NUM; |
| 30 | } |
| 31 | |
| 32 | static int pca9450_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 33 | int len) |
| 34 | { |
| 35 | if (dm_i2c_write(dev, reg, buff, len)) { |
| 36 | pr_err("write error to device: %p register: %#x!", dev, reg); |
| 37 | return -EIO; |
| 38 | } |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int pca9450_read(struct udevice *dev, uint reg, uint8_t *buff, |
| 44 | int len) |
| 45 | { |
| 46 | if (dm_i2c_read(dev, reg, buff, len)) { |
| 47 | pr_err("read error from device: %p register: %#x!", dev, reg); |
| 48 | return -EIO; |
| 49 | } |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static int pca9450_bind(struct udevice *dev) |
| 55 | { |
| 56 | int children; |
| 57 | ofnode regulators_node; |
| 58 | |
| 59 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 60 | if (!ofnode_valid(regulators_node)) { |
| 61 | debug("%s: %s regulators subnode not found!", __func__, |
| 62 | dev->name); |
| 63 | return -ENXIO; |
| 64 | } |
| 65 | |
| 66 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 67 | |
| 68 | children = pmic_bind_children(dev, regulators_node, |
| 69 | pmic_children_info); |
| 70 | if (!children) |
| 71 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 72 | |
| 73 | /* Always return success for this device */ |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static struct dm_pmic_ops pca9450_ops = { |
| 78 | .reg_count = pca9450_reg_count, |
| 79 | .read = pca9450_read, |
| 80 | .write = pca9450_write, |
| 81 | }; |
| 82 | |
| 83 | static const struct udevice_id pca9450_ids[] = { |
Max Krummenacher | 5d89afe | 2020-10-28 11:58:09 +0200 | [diff] [blame] | 84 | { .compatible = "nxp,pca9450a", .data = 0x25, }, |
Ye Li | 22172f6 | 2019-10-15 02:15:18 -0700 | [diff] [blame] | 85 | { .compatible = "nxp,pca9450b", .data = 0x25, }, |
| 86 | { } |
| 87 | }; |
| 88 | |
| 89 | U_BOOT_DRIVER(pmic_pca9450) = { |
| 90 | .name = "pca9450 pmic", |
| 91 | .id = UCLASS_PMIC, |
| 92 | .of_match = pca9450_ids, |
| 93 | .bind = pca9450_bind, |
| 94 | .ops = &pca9450_ops, |
| 95 | }; |