Tim Harvey | 338588e | 2020-12-21 08:19:39 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2020 Gateworks Corporation |
| 4 | */ |
Tim Harvey | 338588e | 2020-12-21 08:19:39 -0800 | [diff] [blame] | 5 | #include <errno.h> |
| 6 | #include <dm.h> |
| 7 | #include <i2c.h> |
| 8 | #include <log.h> |
| 9 | #include <power/pmic.h> |
| 10 | #include <power/regulator.h> |
| 11 | #include <power/mp5416.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Tim Harvey | 338588e | 2020-12-21 08:19:39 -0800 | [diff] [blame] | 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
| 16 | static const struct pmic_child_info pmic_children_info[] = { |
| 17 | /* buck */ |
| 18 | { .prefix = "b", .driver = MP6416_REGULATOR_DRIVER }, |
| 19 | /* ldo */ |
| 20 | { .prefix = "l", .driver = MP6416_REGULATOR_DRIVER }, |
| 21 | { }, |
| 22 | }; |
| 23 | |
| 24 | static int mp5416_reg_count(struct udevice *dev) |
| 25 | { |
| 26 | return MP5416_NUM_OF_REGS - 1; |
| 27 | } |
| 28 | |
| 29 | static int mp5416_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 30 | int len) |
| 31 | { |
| 32 | if (dm_i2c_write(dev, reg, buff, len)) { |
| 33 | pr_err("write error to device: %p register: %#x!", dev, reg); |
| 34 | return -EIO; |
| 35 | } |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static int mp5416_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 41 | { |
| 42 | if (dm_i2c_read(dev, reg, buff, len)) { |
| 43 | pr_err("read error from device: %p register: %#x!", dev, reg); |
| 44 | return -EIO; |
| 45 | } |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int mp5416_bind(struct udevice *dev) |
| 51 | { |
| 52 | int children; |
| 53 | ofnode regulators_node; |
| 54 | |
| 55 | debug("%s %s\n", __func__, dev->name); |
| 56 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 57 | if (!ofnode_valid(regulators_node)) { |
| 58 | debug("%s: %s regulators subnode not found!\n", __func__, |
| 59 | dev->name); |
| 60 | return -ENXIO; |
| 61 | } |
| 62 | |
| 63 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 64 | |
| 65 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 66 | if (!children) |
| 67 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 68 | |
| 69 | /* Always return success for this device */ |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static int mp5416_probe(struct udevice *dev) |
| 74 | { |
| 75 | debug("%s %s\n", __func__, dev->name); |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static struct dm_pmic_ops mp5416_ops = { |
| 81 | .reg_count = mp5416_reg_count, |
| 82 | .read = mp5416_read, |
| 83 | .write = mp5416_write, |
| 84 | }; |
| 85 | |
| 86 | static const struct udevice_id mp5416_ids[] = { |
| 87 | { .compatible = "mps,mp5416", }, |
| 88 | { } |
| 89 | }; |
| 90 | |
| 91 | U_BOOT_DRIVER(pmic_mp5416) = { |
| 92 | .name = "mp5416 pmic", |
| 93 | .id = UCLASS_PMIC, |
| 94 | .of_match = mp5416_ids, |
| 95 | .bind = mp5416_bind, |
| 96 | .probe = mp5416_probe, |
| 97 | .ops = &mp5416_ops, |
| 98 | }; |