blob: 31c9139c646da487e9f5678d48490a7b84276c3c [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>
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030011#include <power/pmic.h>
12#include <power/regulator.h>
13#include <power/bd71837.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17static const struct pmic_child_info pmic_children_info[] = {
18 /* buck */
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030019 { .prefix = "b", .driver = BD718XX_REGULATOR_DRIVER},
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030020 /* ldo */
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030021 { .prefix = "l", .driver = BD718XX_REGULATOR_DRIVER},
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030022 { },
23};
24
25static int bd71837_reg_count(struct udevice *dev)
26{
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030027 return BD718XX_MAX_REGISTER - 1;
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030028}
29
30static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
31 int len)
32{
33 if (dm_i2c_write(dev, reg, buff, len)) {
34 pr_err("write error to device: %p register: %#x!", dev, reg);
35 return -EIO;
36 }
37
38 return 0;
39}
40
41static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
42{
43 if (dm_i2c_read(dev, reg, buff, len)) {
44 pr_err("read error from device: %p register: %#x!", dev, reg);
45 return -EIO;
46 }
47
48 return 0;
49}
50
51static int bd71837_bind(struct udevice *dev)
52{
53 int children;
54 ofnode regulators_node;
55
56 regulators_node = dev_read_subnode(dev, "regulators");
57 if (!ofnode_valid(regulators_node)) {
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030058 debug("%s: %s regulators subnode not found!\n", __func__,
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030059 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
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030073static int bd718x7_probe(struct udevice *dev)
74{
75 int ret;
76 uint8_t mask = BD718XX_REGLOCK_PWRSEQ | BD718XX_REGLOCK_VREG;
77
78 /* Unlock the PMIC regulator control before probing the children */
79 ret = pmic_clrsetbits(dev, BD718XX_REGLOCK, mask, 0);
80 if (ret) {
81 debug("%s: %s Failed to unlock regulator control\n", __func__,
82 dev->name);
83 return ret;
84 }
85 debug("%s: '%s' - BD718x7 PMIC registers unlocked\n", __func__,
86 dev->name);
87
88 return 0;
89}
90
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +030091static struct dm_pmic_ops bd71837_ops = {
92 .reg_count = bd71837_reg_count,
93 .read = bd71837_read,
94 .write = bd71837_write,
95};
96
97static const struct udevice_id bd71837_ids[] = {
Matti Vaittinen9d4ce302019-05-07 10:45:55 +030098 { .compatible = "rohm,bd71837", .data = ROHM_CHIP_TYPE_BD71837, },
99 { .compatible = "rohm,bd71847", .data = ROHM_CHIP_TYPE_BD71847, },
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +0300100 { }
101};
102
103U_BOOT_DRIVER(pmic_bd71837) = {
104 .name = "bd71837 pmic",
105 .id = UCLASS_PMIC,
106 .of_match = bd71837_ids,
107 .bind = bd71837_bind,
Matti Vaittinen9d4ce302019-05-07 10:45:55 +0300108 .probe = bd718x7_probe,
Matti Vaittinen1cf7f1d2019-05-07 10:43:39 +0300109 .ops = &bd71837_ops,
110};