xref: /openbmc/u-boot/drivers/power/pmic/stpmu1.c (revision 9d466f2f)
1 /*
2  * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
3  *
4  * SPDX-License-Identifier:	GPL-2.0+	BSD-3-Clause
5  */
6 
7 #include <common.h>
8 #include <dm.h>
9 #include <errno.h>
10 #include <i2c.h>
11 #include <power/pmic.h>
12 #include <power/stpmu1.h>
13 
14 #define STMPU1_NUM_OF_REGS 0x100
15 
16 static int stpmu1_reg_count(struct udevice *dev)
17 {
18 	return STMPU1_NUM_OF_REGS;
19 }
20 
21 static int stpmu1_write(struct udevice *dev, uint reg, const uint8_t *buff,
22 			int len)
23 {
24 	int ret;
25 
26 	ret = dm_i2c_write(dev, reg, buff, len);
27 	if (ret)
28 		dev_err(dev, "%s: failed to write register %#x :%d",
29 			__func__, reg, ret);
30 
31 	return ret;
32 }
33 
34 static int stpmu1_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
35 {
36 	int ret;
37 
38 	ret = dm_i2c_read(dev, reg, buff, len);
39 	if (ret)
40 		dev_err(dev, "%s: failed to read register %#x : %d",
41 			__func__, reg, ret);
42 
43 	return ret;
44 }
45 
46 static struct dm_pmic_ops stpmu1_ops = {
47 	.reg_count = stpmu1_reg_count,
48 	.read = stpmu1_read,
49 	.write = stpmu1_write,
50 };
51 
52 static const struct udevice_id stpmu1_ids[] = {
53 	{ .compatible = "st,stpmu1" },
54 	{ }
55 };
56 
57 U_BOOT_DRIVER(pmic_stpmu1) = {
58 	.name = "stpmu1_pmic",
59 	.id = UCLASS_PMIC,
60 	.of_match = stpmu1_ids,
61 	.ops = &stpmu1_ops,
62 };
63