• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  Copyright (C) 2015 Samsung Electronics
4  *  Przemyslaw Marczak  <p.marczak@samsung.com>
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/sandbox_pmic.h>
15 
16 static const struct pmic_child_info pmic_children_info[] = {
17 	{ .prefix = SANDBOX_OF_LDO_PREFIX, .driver = SANDBOX_LDO_DRIVER },
18 	{ .prefix = SANDBOX_OF_BUCK_PREFIX, .driver = SANDBOX_BUCK_DRIVER },
19 	{ },
20 };
21 
sandbox_pmic_reg_count(struct udevice * dev)22 static int sandbox_pmic_reg_count(struct udevice *dev)
23 {
24 	return SANDBOX_PMIC_REG_COUNT;
25 }
26 
sandbox_pmic_write(struct udevice * dev,uint reg,const uint8_t * buff,int len)27 static int sandbox_pmic_write(struct udevice *dev, uint reg,
28 			      const uint8_t *buff, int len)
29 {
30 	if (dm_i2c_write(dev, reg, buff, len)) {
31 		pr_err("write error to device: %p register: %#x!\n", dev, reg);
32 		return -EIO;
33 	}
34 
35 	return 0;
36 }
37 
sandbox_pmic_read(struct udevice * dev,uint reg,uint8_t * buff,int len)38 static int sandbox_pmic_read(struct udevice *dev, uint reg,
39 			     uint8_t *buff, int len)
40 {
41 	if (dm_i2c_read(dev, reg, buff, len)) {
42 		pr_err("read error from device: %p register: %#x!\n", dev, reg);
43 		return -EIO;
44 	}
45 
46 	return 0;
47 }
48 
sandbox_pmic_bind(struct udevice * dev)49 static int sandbox_pmic_bind(struct udevice *dev)
50 {
51 	if (!pmic_bind_children(dev, dev_ofnode(dev), pmic_children_info))
52 		pr_err("%s:%d PMIC: %s - no child found!", __func__, __LINE__,
53 							  dev->name);
54 
55 	/* Always return success for this device - allows for PMIC I/O */
56 	return 0;
57 }
58 
59 static struct dm_pmic_ops sandbox_pmic_ops = {
60 	.reg_count = sandbox_pmic_reg_count,
61 	.read = sandbox_pmic_read,
62 	.write = sandbox_pmic_write,
63 };
64 
65 static const struct udevice_id sandbox_pmic_ids[] = {
66 	{ .compatible = "sandbox,pmic" },
67 	{ }
68 };
69 
70 U_BOOT_DRIVER(sandbox_pmic) = {
71 	.name = "sandbox_pmic",
72 	.id = UCLASS_PMIC,
73 	.of_match = sandbox_pmic_ids,
74 	.bind = sandbox_pmic_bind,
75 	.ops = &sandbox_pmic_ops,
76 };
77