xref: /rk3399_rockchip-uboot/drivers/power/pmic/pmic_sy7636a.c (revision 49fa68b0dbd5e2cf48ddcd537cf74590eeefd48f)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2024 Rockchip Electronics Co., Ltd.
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <dm/lists.h>
9 #include <dm/device-internal.h>
10 #include <dm/of_access.h>
11 #include <dm/pinctrl.h>
12 #include <i2c.h>
13 #include <power/pmic.h>
14 #include <power/regulator.h>
15 #include <power/sy7636a.h>
16 
17 DECLARE_GLOBAL_DATA_PTR;
18 
19 static const struct pmic_child_info pmic_children_info[] = {
20 	{ .prefix = "vcom", .driver = SY7636A_REGULATOR_DRIVER_NAME },
21 	{ },
22 };
23 
24 static const struct pmic_child_info thermal_child_info[] = {
25 	{ .prefix = "sy7636a_thermal", .driver = SY7636A_THERMAL_COMTATIBLE_NAME },
26 	{ },
27 };
28 
29 static int sy7636a_reg_count(struct udevice *dev)
30 {
31         return SY7636A_REG_MAX;
32 }
33 
34 static int sy7636a_write(struct udevice *dev, uint reg, const uint8_t *buff, int len)
35 {
36 	int ret;
37 
38 	ret = dm_i2c_write(dev, reg, buff, len);
39 	if (ret) {
40 		pr_err("sy7636a failed to write register: %#x, ret:%d\n", reg, ret);
41 		return ret;
42 	}
43 
44 	return 0;
45 }
46 
47 static int sy7636a_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
48 {
49 	int ret;
50 
51 	ret = dm_i2c_read(dev, reg, buff, len);
52 	if (ret) {
53 		pr_err("sy7636a failed to write register: %#x, ret:%d\n", reg, ret);
54 		return ret;
55 	}
56 
57 	return 0;
58 }
59 
60 static int pmic_sy7636a_probe(struct udevice *dev)
61 {
62 	/* After setting pinctrl, SY7636A requires 2.5ms delay time to enter active mode */
63 	udelay(2500);
64 
65 	return 0;
66 }
67 
68 static int pmic_sy7636a_bind(struct udevice *dev)
69 {
70 	ofnode regulators_node;
71 	int children;
72 
73 	regulators_node = dev_read_subnode(dev, "regulators");
74 	if (!ofnode_valid(regulators_node)) {
75 		dev_err(dev, "Regulators subnode not found!");
76 		return -ENXIO;
77 	}
78 
79 	children = pmic_bind_children(dev, regulators_node, pmic_children_info);
80 	if (!children)
81 		dev_err(dev, "Failed to bind sy7636a regulator\n");
82 
83 	children = pmic_bind_children(dev, dev->node, thermal_child_info);
84 	if (!children)
85 		dev_err(dev, "Failed to bind sy7636a thermal\n");
86 
87         return 0;
88 }
89 
90 static struct dm_pmic_ops sy7636a_ops = {
91 	.reg_count = sy7636a_reg_count,
92 	.read = sy7636a_read,
93 	.write = sy7636a_write,
94 };
95 
96 static const struct udevice_id pmic_sy7636a_of_match[] = {
97 	{ .compatible = "silergy,sy7636a" },
98 	{ .compatible = "silergy,sy7636a-pmic" },
99 	{}
100 };
101 
102 U_BOOT_DRIVER(pmic_sy7636a) = {
103 	.name = "pmic_sy7636a",
104 	.id = UCLASS_PMIC,
105 	.of_match = pmic_sy7636a_of_match,
106 	.probe = pmic_sy7636a_probe,
107 	.ops = &sy7636a_ops,
108 	.bind = pmic_sy7636a_bind,
109 };
110