blob: 68c3cbbc646967912a4b43f343387717d97c2ac2 [file] [log] [blame]
Svyatoslav Ryhelaba052b2023-10-27 11:26:10 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright(C) 2023 Svyatoslav Ryhel <clamor95@gmail.com>
4 */
5
6#include <dm.h>
7#include <dm/lists.h>
8#include <power/pmic.h>
9#include <power/max77663.h>
10
11static const struct pmic_child_info pmic_children_info[] = {
12 { .prefix = "ldo", .driver = MAX77663_LDO_DRIVER },
13 { .prefix = "sd", .driver = MAX77663_SD_DRIVER },
14 { },
15};
16
17static int max77663_write(struct udevice *dev, uint reg, const uint8_t *buff,
18 int len)
19{
20 int ret;
21
22 ret = dm_i2c_write(dev, reg, buff, len);
23 if (ret) {
24 log_debug("write error to device: %p register: %#x!\n", dev, reg);
25 return ret;
26 }
27
28 return 0;
29}
30
31static int max77663_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("read error from device: %p register: %#x!\n", dev, reg);
38 return ret;
39 }
40
41 return 0;
42}
43
44static int max77663_bind(struct udevice *dev)
45{
46 ofnode regulators_node;
Svyatoslav Ryhel52914ea2023-10-24 10:49:05 +030047 int children, ret;
48
49 if (IS_ENABLED(CONFIG_SYSRESET_MAX77663)) {
50 ret = device_bind_driver(dev, MAX77663_RST_DRIVER,
51 "sysreset", NULL);
52 if (ret) {
53 log_err("cannot bind SYSRESET (ret = %d)\n", ret);
54 return ret;
55 }
56 }
Svyatoslav Ryhelaba052b2023-10-27 11:26:10 +030057
58 regulators_node = dev_read_subnode(dev, "regulators");
59 if (!ofnode_valid(regulators_node)) {
60 log_err("%s regulators subnode not found!\n", dev->name);
61 return -ENXIO;
62 }
63
64 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
65
66 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
67 if (!children)
68 log_err("%s - no child found\n", dev->name);
69
70 /* Always return success for this device */
71 return 0;
72}
73
74static struct dm_pmic_ops max77663_ops = {
75 .read = max77663_read,
76 .write = max77663_write,
77};
78
79static const struct udevice_id max77663_ids[] = {
80 { .compatible = "maxim,max77663" },
81 { }
82};
83
84U_BOOT_DRIVER(pmic_max77663) = {
85 .name = "max77663_pmic",
86 .id = UCLASS_PMIC,
87 .of_match = max77663_ids,
88 .bind = max77663_bind,
89 .ops = &max77663_ops,
90};