blob: ee6ae78e5c4c91e371de48d3ce8f423aae8274f8 [file] [log] [blame]
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +03001// 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 Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060012#include <linux/printk.h>
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030013#include <power/pmic.h>
14#include <power/regulator.h>
15#include <power/bd71837.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
19static const struct pmic_child_info pmic_children_info[] = {
20 /* buck */
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030021 { .prefix = "b", .driver = BD718XX_REGULATOR_DRIVER},
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030022 /* ldo */
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030023 { .prefix = "l", .driver = BD718XX_REGULATOR_DRIVER},
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030024 { },
25};
26
27static int bd71837_reg_count(struct udevice *dev)
28{
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030029 return BD718XX_MAX_REGISTER - 1;
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030030}
31
32static int bd71837_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
43static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
44{
45 if (dm_i2c_read(dev, reg, buff, len)) {
46 pr_err("read error from device: %p register: %#x!", dev, reg);
47 return -EIO;
48 }
49
50 return 0;
51}
52
53static int bd71837_bind(struct udevice *dev)
54{
55 int children;
56 ofnode regulators_node;
57
58 regulators_node = dev_read_subnode(dev, "regulators");
59 if (!ofnode_valid(regulators_node)) {
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030060 debug("%s: %s regulators subnode not found!\n", __func__,
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030061 dev->name);
62 return -ENXIO;
63 }
64
65 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
66
Adam Ford2ce0c442022-10-22 08:43:42 -050067 if (CONFIG_IS_ENABLED(PMIC_CHILDREN)) {
68 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
69 if (!children)
70 debug("%s: %s - no child found\n", __func__, dev->name);
71 }
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030072 /* Always return success for this device */
73 return 0;
74}
75
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030076static int bd718x7_probe(struct udevice *dev)
77{
78 int ret;
79 uint8_t mask = BD718XX_REGLOCK_PWRSEQ | BD718XX_REGLOCK_VREG;
80
81 /* Unlock the PMIC regulator control before probing the children */
82 ret = pmic_clrsetbits(dev, BD718XX_REGLOCK, mask, 0);
83 if (ret) {
84 debug("%s: %s Failed to unlock regulator control\n", __func__,
85 dev->name);
86 return ret;
87 }
88 debug("%s: '%s' - BD718x7 PMIC registers unlocked\n", __func__,
89 dev->name);
90
91 return 0;
92}
93
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030094static struct dm_pmic_ops bd71837_ops = {
95 .reg_count = bd71837_reg_count,
96 .read = bd71837_read,
97 .write = bd71837_write,
98};
99
100static const struct udevice_id bd71837_ids[] = {
Matti Vaittinen9d4ce302019-05-07 10:45:55 +0300101 { .compatible = "rohm,bd71837", .data = ROHM_CHIP_TYPE_BD71837, },
102 { .compatible = "rohm,bd71847", .data = ROHM_CHIP_TYPE_BD71847, },
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +0300103 { }
104};
105
106U_BOOT_DRIVER(pmic_bd71837) = {
107 .name = "bd71837 pmic",
108 .id = UCLASS_PMIC,
109 .of_match = bd71837_ids,
110 .bind = bd71837_bind,
Matti Vaittinen9d4ce302019-05-07 10:45:55 +0300111 .probe = bd718x7_probe,
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +0300112 .ops = &bd71837_ops,
113};