blob: a7ef70177de8423b60c959a633ffe2f4955aa342 [file] [log] [blame]
Svyatoslav Ryhel9c58dd62024-10-06 14:50:02 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright(C) 2024 Svyatoslav Ryhel <clamor95@gmail.com>
4 */
5
6#include <dm.h>
7#include <dm/lists.h>
8#include <power/pmic.h>
Svyatoslav Ryhel8df7d472024-10-06 14:59:54 +03009#include <power/max8907.h>
10
11static const struct pmic_child_info pmic_children_info[] = {
12 { .prefix = "ldo", .driver = MAX8907_LDO_DRIVER },
13 { .prefix = "sd", .driver = MAX8907_SD_DRIVER },
14 { },
15};
Svyatoslav Ryhel9c58dd62024-10-06 14:50:02 +030016
17static int max8907_write(struct udevice *dev, uint reg, const uint8_t *buff, int len)
18{
19 int ret;
20
21 ret = dm_i2c_write(dev, reg, buff, len);
22 if (ret) {
23 log_debug("%s: write error to device: %p register: %#x!\n",
24 __func__, dev, reg);
25 return ret;
26 }
27
28 return 0;
29}
30
31static int max8907_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
32{
33 int ret;
34
35 ret = dm_i2c_read(dev, reg, buff, len);
36 if (ret) {
37 log_debug("%s: read error from device: %p register: %#x!\n",
38 __func__, dev, reg);
39 return ret;
40 }
41
Svyatoslav Ryhel8df7d472024-10-06 14:59:54 +030042 return 0;
43}
44
45static int max8907_bind(struct udevice *dev)
46{
47 ofnode regulators_node;
Svyatoslav Ryhel9f8ea822024-10-06 16:51:21 +030048 int children, ret;
49
50 if (IS_ENABLED(CONFIG_SYSRESET_MAX8907) &&
51 dev_read_bool(dev, "maxim,system-power-controller")) {
52 ret = device_bind_driver_to_node(dev, MAX8907_RST_DRIVER,
53 "sysreset", dev_ofnode(dev),
54 NULL);
55 if (ret) {
56 log_debug("%s: cannot bind SYSRESET (ret = %d)\n",
57 __func__, ret);
58 return ret;
59 }
60 }
Svyatoslav Ryhel8df7d472024-10-06 14:59:54 +030061
62 regulators_node = dev_read_subnode(dev, "regulators");
63 if (!ofnode_valid(regulators_node)) {
64 log_err("%s regulators subnode not found!\n", dev->name);
65 return -ENXIO;
66 }
67
68 log_debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
69
70 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
71 if (!children)
72 log_err("%s - no child found\n", dev->name);
73
74 /* Always return success for this device */
Svyatoslav Ryhel9c58dd62024-10-06 14:50:02 +030075 return 0;
76}
77
78static struct dm_pmic_ops max8907_ops = {
79 .read = max8907_read,
80 .write = max8907_write,
81};
82
83static const struct udevice_id max8907_ids[] = {
84 { .compatible = "maxim,max8907" },
85 { }
86};
87
88U_BOOT_DRIVER(pmic_max8907) = {
89 .name = "max8907_pmic",
90 .id = UCLASS_PMIC,
91 .of_match = max8907_ids,
Svyatoslav Ryhel8df7d472024-10-06 14:59:54 +030092 .bind = max8907_bind,
Svyatoslav Ryhel9c58dd62024-10-06 14:50:02 +030093 .ops = &max8907_ops,
94};