xref: /openbmc/u-boot/drivers/power/pmic/s5m8767.c (revision 3ce88cd7)
1 /*
2  * Copyright (C) 2015 Google, Inc
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <fdtdec.h>
9 #include <errno.h>
10 #include <dm.h>
11 #include <i2c.h>
12 #include <power/pmic.h>
13 #include <power/regulator.h>
14 #include <power/s5m8767.h>
15 
16 static const struct pmic_child_info pmic_children_info[] = {
17 	{ .prefix = "LDO", .driver = S5M8767_LDO_DRIVER },
18 	{ .prefix = "BUCK", .driver = S5M8767_BUCK_DRIVER },
19 	{ },
20 };
21 
22 static int s5m8767_reg_count(struct udevice *dev)
23 {
24 	return S5M8767_NUM_OF_REGS;
25 }
26 
27 static int s5m8767_write(struct udevice *dev, uint reg, const uint8_t *buff,
28 			  int len)
29 {
30 	if (dm_i2c_write(dev, reg, buff, len)) {
31 		pr_err("write error to device: %p register: %#x!", dev, reg);
32 		return -EIO;
33 	}
34 
35 	return 0;
36 }
37 
38 static int s5m8767_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
39 {
40 	if (dm_i2c_read(dev, reg, buff, len)) {
41 		pr_err("read error from device: %p register: %#x!", dev, reg);
42 		return -EIO;
43 	}
44 
45 	return 0;
46 }
47 
48 int s5m8767_enable_32khz_cp(struct udevice *dev)
49 {
50 	return pmic_clrsetbits(dev, S5M8767_EN32KHZ_CP, 0, 1 << 1);
51 }
52 
53 static int s5m8767_bind(struct udevice *dev)
54 {
55 	int children;
56 	ofnode node;
57 
58 	node = dev_read_subnode(dev, "regulators");
59 	if (!ofnode_valid(node)) {
60 		debug("%s: %s regulators subnode not found!", __func__,
61 		      dev->name);
62 		return -ENXIO;
63 	}
64 
65 	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
66 
67 	children = pmic_bind_children(dev, node, pmic_children_info);
68 	if (!children)
69 		debug("%s: %s - no child found\n", __func__, dev->name);
70 
71 	/* Always return success for this device */
72 	return 0;
73 }
74 
75 static struct dm_pmic_ops s5m8767_ops = {
76 	.reg_count = s5m8767_reg_count,
77 	.read = s5m8767_read,
78 	.write = s5m8767_write,
79 };
80 
81 static const struct udevice_id s5m8767_ids[] = {
82 	{ .compatible = "samsung,s5m8767-pmic" },
83 	{ }
84 };
85 
86 U_BOOT_DRIVER(pmic_s5m8767) = {
87 	.name = "s5m8767_pmic",
88 	.id = UCLASS_PMIC,
89 	.of_match = s5m8767_ids,
90 	.bind = s5m8767_bind,
91 	.ops = &s5m8767_ops,
92 };
93