Matti Vaittinen | 1cf7f1d | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2018 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <errno.h> |
| 8 | #include <dm.h> |
| 9 | #include <i2c.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Matti Vaittinen | 1cf7f1d | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 12 | #include <power/pmic.h> |
| 13 | #include <power/regulator.h> |
| 14 | #include <power/bd71837.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | static const struct pmic_child_info pmic_children_info[] = { |
| 19 | /* buck */ |
Matti Vaittinen | 9d4ce30 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 20 | { .prefix = "b", .driver = BD718XX_REGULATOR_DRIVER}, |
Matti Vaittinen | 1cf7f1d | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 21 | /* ldo */ |
Matti Vaittinen | 9d4ce30 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 22 | { .prefix = "l", .driver = BD718XX_REGULATOR_DRIVER}, |
Matti Vaittinen | 1cf7f1d | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 23 | { }, |
| 24 | }; |
| 25 | |
| 26 | static int bd71837_reg_count(struct udevice *dev) |
| 27 | { |
Matti Vaittinen | 9d4ce30 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 28 | return BD718XX_MAX_REGISTER - 1; |
Matti Vaittinen | 1cf7f1d | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff, |
| 32 | int len) |
| 33 | { |
| 34 | if (dm_i2c_write(dev, reg, buff, len)) { |
| 35 | pr_err("write error to device: %p register: %#x!", dev, reg); |
| 36 | return -EIO; |
| 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
| 43 | { |
| 44 | if (dm_i2c_read(dev, reg, buff, len)) { |
| 45 | pr_err("read error from device: %p register: %#x!", dev, reg); |
| 46 | return -EIO; |
| 47 | } |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static int bd71837_bind(struct udevice *dev) |
| 53 | { |
| 54 | int children; |
| 55 | ofnode regulators_node; |
| 56 | |
| 57 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 58 | if (!ofnode_valid(regulators_node)) { |
Matti Vaittinen | 9d4ce30 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 59 | debug("%s: %s regulators subnode not found!\n", __func__, |
Matti Vaittinen | 1cf7f1d | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 60 | dev->name); |
| 61 | return -ENXIO; |
| 62 | } |
| 63 | |
| 64 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 65 | |
Adam Ford | 2ce0c44 | 2022-10-22 08:43:42 -0500 | [diff] [blame] | 66 | if (CONFIG_IS_ENABLED(PMIC_CHILDREN)) { |
| 67 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 68 | if (!children) |
| 69 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 70 | } |
Matti Vaittinen | 1cf7f1d | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 71 | /* Always return success for this device */ |
| 72 | return 0; |
| 73 | } |
| 74 | |
Matti Vaittinen | 9d4ce30 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 75 | static int bd718x7_probe(struct udevice *dev) |
| 76 | { |
| 77 | int ret; |
| 78 | uint8_t mask = BD718XX_REGLOCK_PWRSEQ | BD718XX_REGLOCK_VREG; |
| 79 | |
| 80 | /* Unlock the PMIC regulator control before probing the children */ |
| 81 | ret = pmic_clrsetbits(dev, BD718XX_REGLOCK, mask, 0); |
| 82 | if (ret) { |
| 83 | debug("%s: %s Failed to unlock regulator control\n", __func__, |
| 84 | dev->name); |
| 85 | return ret; |
| 86 | } |
| 87 | debug("%s: '%s' - BD718x7 PMIC registers unlocked\n", __func__, |
| 88 | dev->name); |
| 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
Matti Vaittinen | 1cf7f1d | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 93 | static struct dm_pmic_ops bd71837_ops = { |
| 94 | .reg_count = bd71837_reg_count, |
| 95 | .read = bd71837_read, |
| 96 | .write = bd71837_write, |
| 97 | }; |
| 98 | |
| 99 | static const struct udevice_id bd71837_ids[] = { |
Matti Vaittinen | 9d4ce30 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 100 | { .compatible = "rohm,bd71837", .data = ROHM_CHIP_TYPE_BD71837, }, |
| 101 | { .compatible = "rohm,bd71847", .data = ROHM_CHIP_TYPE_BD71847, }, |
Matti Vaittinen | 1cf7f1d | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 102 | { } |
| 103 | }; |
| 104 | |
| 105 | U_BOOT_DRIVER(pmic_bd71837) = { |
| 106 | .name = "bd71837 pmic", |
| 107 | .id = UCLASS_PMIC, |
| 108 | .of_match = bd71837_ids, |
| 109 | .bind = bd71837_bind, |
Matti Vaittinen | 9d4ce30 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 110 | .probe = bd718x7_probe, |
Matti Vaittinen | 1cf7f1d | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 111 | .ops = &bd71837_ops, |
| 112 | }; |