xref: /openbmc/linux/include/linux/mfd/da9055/core.h (revision 74ba9207)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * da9055 declarations for DA9055 PMICs.
4  *
5  * Copyright(c) 2012 Dialog Semiconductor Ltd.
6  *
7  * Author: David Dajun Chen <dchen@diasemi.com>
8  */
9 
10 #ifndef __DA9055_CORE_H
11 #define __DA9055_CORE_H
12 
13 #include <linux/interrupt.h>
14 #include <linux/regmap.h>
15 
16 /*
17  * PMIC IRQ
18  */
19 #define DA9055_IRQ_ALARM	0x01
20 #define DA9055_IRQ_TICK		0x02
21 #define DA9055_IRQ_NONKEY	0x00
22 #define DA9055_IRQ_REGULATOR	0x0B
23 #define DA9055_IRQ_HWMON	0x03
24 
25 struct da9055_pdata;
26 
27 struct da9055 {
28 	struct regmap *regmap;
29 	struct regmap_irq_chip_data *irq_data;
30 	struct device *dev;
31 	struct i2c_client *i2c_client;
32 
33 	int irq_base;
34 	int chip_irq;
35 };
36 
37 /* Device I/O */
da9055_reg_read(struct da9055 * da9055,unsigned char reg)38 static inline int da9055_reg_read(struct da9055 *da9055, unsigned char reg)
39 {
40 	int val, ret;
41 
42 	ret = regmap_read(da9055->regmap, reg, &val);
43 	if (ret < 0)
44 		return ret;
45 
46 	return val;
47 }
48 
da9055_reg_write(struct da9055 * da9055,unsigned char reg,unsigned char val)49 static inline int da9055_reg_write(struct da9055 *da9055, unsigned char reg,
50 				    unsigned char val)
51 {
52 	return regmap_write(da9055->regmap, reg, val);
53 }
54 
da9055_group_read(struct da9055 * da9055,unsigned char reg,unsigned reg_cnt,unsigned char * val)55 static inline int da9055_group_read(struct da9055 *da9055, unsigned char reg,
56 				     unsigned reg_cnt, unsigned char *val)
57 {
58 	return regmap_bulk_read(da9055->regmap, reg, val, reg_cnt);
59 }
60 
da9055_group_write(struct da9055 * da9055,unsigned char reg,unsigned reg_cnt,unsigned char * val)61 static inline int da9055_group_write(struct da9055 *da9055, unsigned char reg,
62 				      unsigned reg_cnt, unsigned char *val)
63 {
64 	return regmap_raw_write(da9055->regmap, reg, val, reg_cnt);
65 }
66 
da9055_reg_update(struct da9055 * da9055,unsigned char reg,unsigned char bit_mask,unsigned char reg_val)67 static inline int da9055_reg_update(struct da9055 *da9055, unsigned char reg,
68 				     unsigned char bit_mask,
69 				     unsigned char reg_val)
70 {
71 	return regmap_update_bits(da9055->regmap, reg, bit_mask, reg_val);
72 }
73 
74 /* Generic Device API */
75 int da9055_device_init(struct da9055 *da9055);
76 void da9055_device_exit(struct da9055 *da9055);
77 
78 extern const struct regmap_config da9055_regmap_config;
79 
80 #endif /* __DA9055_CORE_H */
81