blob: fac97ed221eac63304404cdefaba46fab7e48dba [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;
47 int children;
48
49 regulators_node = dev_read_subnode(dev, "regulators");
50 if (!ofnode_valid(regulators_node)) {
51 log_err("%s regulators subnode not found!\n", dev->name);
52 return -ENXIO;
53 }
54
55 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
56
57 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
58 if (!children)
59 log_err("%s - no child found\n", dev->name);
60
61 /* Always return success for this device */
62 return 0;
63}
64
65static struct dm_pmic_ops max77663_ops = {
66 .read = max77663_read,
67 .write = max77663_write,
68};
69
70static const struct udevice_id max77663_ids[] = {
71 { .compatible = "maxim,max77663" },
72 { }
73};
74
75U_BOOT_DRIVER(pmic_max77663) = {
76 .name = "max77663_pmic",
77 .id = UCLASS_PMIC,
78 .of_match = max77663_ids,
79 .bind = max77663_bind,
80 .ops = &max77663_ops,
81};