Matti Vaittinen | 1023c87 | 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> |
| 10 | #include <power/pmic.h> |
| 11 | #include <power/regulator.h> |
| 12 | #include <power/bd71837.h> |
| 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
| 16 | static const struct pmic_child_info pmic_children_info[] = { |
| 17 | /* buck */ |
Matti Vaittinen | 21b0241 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 18 | { .prefix = "b", .driver = BD718XX_REGULATOR_DRIVER}, |
Matti Vaittinen | 1023c87 | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 19 | /* ldo */ |
Matti Vaittinen | 21b0241 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 20 | { .prefix = "l", .driver = BD718XX_REGULATOR_DRIVER}, |
Matti Vaittinen | 1023c87 | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 21 | { }, |
| 22 | }; |
| 23 | |
| 24 | static int bd71837_reg_count(struct udevice *dev) |
| 25 | { |
Matti Vaittinen | 21b0241 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 26 | return BD718XX_MAX_REGISTER - 1; |
Matti Vaittinen | 1023c87 | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | static int bd71837_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 bd71837_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 bd71837_bind(struct udevice *dev) |
| 51 | { |
| 52 | int children; |
| 53 | ofnode regulators_node; |
| 54 | |
| 55 | regulators_node = dev_read_subnode(dev, "regulators"); |
| 56 | if (!ofnode_valid(regulators_node)) { |
Matti Vaittinen | 21b0241 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 57 | debug("%s: %s regulators subnode not found!\n", __func__, |
Matti Vaittinen | 1023c87 | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 58 | dev->name); |
| 59 | return -ENXIO; |
| 60 | } |
| 61 | |
| 62 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); |
| 63 | |
| 64 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); |
| 65 | if (!children) |
| 66 | debug("%s: %s - no child found\n", __func__, dev->name); |
| 67 | |
| 68 | /* Always return success for this device */ |
| 69 | return 0; |
| 70 | } |
| 71 | |
Matti Vaittinen | 21b0241 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 72 | static int bd718x7_probe(struct udevice *dev) |
| 73 | { |
| 74 | int ret; |
| 75 | uint8_t mask = BD718XX_REGLOCK_PWRSEQ | BD718XX_REGLOCK_VREG; |
| 76 | |
| 77 | /* Unlock the PMIC regulator control before probing the children */ |
| 78 | ret = pmic_clrsetbits(dev, BD718XX_REGLOCK, mask, 0); |
| 79 | if (ret) { |
| 80 | debug("%s: %s Failed to unlock regulator control\n", __func__, |
| 81 | dev->name); |
| 82 | return ret; |
| 83 | } |
| 84 | debug("%s: '%s' - BD718x7 PMIC registers unlocked\n", __func__, |
| 85 | dev->name); |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
Matti Vaittinen | 1023c87 | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 90 | static struct dm_pmic_ops bd71837_ops = { |
| 91 | .reg_count = bd71837_reg_count, |
| 92 | .read = bd71837_read, |
| 93 | .write = bd71837_write, |
| 94 | }; |
| 95 | |
| 96 | static const struct udevice_id bd71837_ids[] = { |
Matti Vaittinen | 21b0241 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 97 | { .compatible = "rohm,bd71837", .data = ROHM_CHIP_TYPE_BD71837, }, |
| 98 | { .compatible = "rohm,bd71847", .data = ROHM_CHIP_TYPE_BD71847, }, |
Matti Vaittinen | 1023c87 | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 99 | { } |
| 100 | }; |
| 101 | |
| 102 | U_BOOT_DRIVER(pmic_bd71837) = { |
| 103 | .name = "bd71837 pmic", |
| 104 | .id = UCLASS_PMIC, |
| 105 | .of_match = bd71837_ids, |
| 106 | .bind = bd71837_bind, |
Matti Vaittinen | 21b0241 | 2019-05-07 10:45:55 +0300 | [diff] [blame] | 107 | .probe = bd718x7_probe, |
Matti Vaittinen | 1023c87 | 2019-05-07 10:43:39 +0300 | [diff] [blame] | 108 | .ops = &bd71837_ops, |
| 109 | }; |