blob: cf08b6a7e1df9059bd8eb02d60fb8de0a5303369 [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
Svyatoslav Ryhel16360b82023-07-15 22:25:03 +030058 if (IS_ENABLED(CONFIG_MAX77663_GPIO)) {
59 ret = device_bind_driver(dev, MAX77663_GPIO_DRIVER,
60 "gpio", NULL);
61 if (ret) {
62 log_err("cannot bind GPIOs (ret = %d)\n", ret);
63 return ret;
64 }
65 }
66
Svyatoslav Ryhelaba052b2023-10-27 11:26:10 +030067 regulators_node = dev_read_subnode(dev, "regulators");
68 if (!ofnode_valid(regulators_node)) {
69 log_err("%s regulators subnode not found!\n", dev->name);
70 return -ENXIO;
71 }
72
73 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
74
75 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
76 if (!children)
77 log_err("%s - no child found\n", dev->name);
78
79 /* Always return success for this device */
80 return 0;
81}
82
83static struct dm_pmic_ops max77663_ops = {
84 .read = max77663_read,
85 .write = max77663_write,
86};
87
88static const struct udevice_id max77663_ids[] = {
89 { .compatible = "maxim,max77663" },
90 { }
91};
92
93U_BOOT_DRIVER(pmic_max77663) = {
94 .name = "max77663_pmic",
95 .id = UCLASS_PMIC,
96 .of_match = max77663_ids,
97 .bind = max77663_bind,
98 .ops = &max77663_ops,
99};