xref: /openbmc/linux/include/linux/mfd/da903x.h (revision b2441318)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_PMIC_DA903X_H
3 #define __LINUX_PMIC_DA903X_H
4 
5 /* Unified sub device IDs for DA9030/DA9034/DA9035 */
6 enum {
7 	DA9030_ID_LED_1,
8 	DA9030_ID_LED_2,
9 	DA9030_ID_LED_3,
10 	DA9030_ID_LED_4,
11 	DA9030_ID_LED_PC,
12 	DA9030_ID_VIBRA,
13 	DA9030_ID_WLED,
14 	DA9030_ID_BUCK1,
15 	DA9030_ID_BUCK2,
16 	DA9030_ID_LDO1,
17 	DA9030_ID_LDO2,
18 	DA9030_ID_LDO3,
19 	DA9030_ID_LDO4,
20 	DA9030_ID_LDO5,
21 	DA9030_ID_LDO6,
22 	DA9030_ID_LDO7,
23 	DA9030_ID_LDO8,
24 	DA9030_ID_LDO9,
25 	DA9030_ID_LDO10,
26 	DA9030_ID_LDO11,
27 	DA9030_ID_LDO12,
28 	DA9030_ID_LDO13,
29 	DA9030_ID_LDO14,
30 	DA9030_ID_LDO15,
31 	DA9030_ID_LDO16,
32 	DA9030_ID_LDO17,
33 	DA9030_ID_LDO18,
34 	DA9030_ID_LDO19,
35 	DA9030_ID_LDO_INT,	/* LDO Internal */
36 	DA9030_ID_BAT,		/* battery charger */
37 
38 	DA9034_ID_LED_1,
39 	DA9034_ID_LED_2,
40 	DA9034_ID_VIBRA,
41 	DA9034_ID_WLED,
42 	DA9034_ID_TOUCH,
43 
44 	DA9034_ID_BUCK1,
45 	DA9034_ID_BUCK2,
46 	DA9034_ID_LDO1,
47 	DA9034_ID_LDO2,
48 	DA9034_ID_LDO3,
49 	DA9034_ID_LDO4,
50 	DA9034_ID_LDO5,
51 	DA9034_ID_LDO6,
52 	DA9034_ID_LDO7,
53 	DA9034_ID_LDO8,
54 	DA9034_ID_LDO9,
55 	DA9034_ID_LDO10,
56 	DA9034_ID_LDO11,
57 	DA9034_ID_LDO12,
58 	DA9034_ID_LDO13,
59 	DA9034_ID_LDO14,
60 	DA9034_ID_LDO15,
61 
62 	DA9035_ID_BUCK3,
63 };
64 
65 /*
66  * DA9030/DA9034 LEDs sub-devices uses generic "struct led_info"
67  * as the platform_data
68  */
69 
70 /* DA9030 flags for "struct led_info"
71  */
72 #define DA9030_LED_RATE_ON	(0 << 5)
73 #define DA9030_LED_RATE_052S	(1 << 5)
74 #define DA9030_LED_DUTY_1_16	(0 << 3)
75 #define DA9030_LED_DUTY_1_8	(1 << 3)
76 #define DA9030_LED_DUTY_1_4	(2 << 3)
77 #define DA9030_LED_DUTY_1_2	(3 << 3)
78 
79 #define DA9030_VIBRA_MODE_1P3V	(0 << 1)
80 #define DA9030_VIBRA_MODE_2P7V	(1 << 1)
81 #define DA9030_VIBRA_FREQ_1HZ	(0 << 2)
82 #define DA9030_VIBRA_FREQ_2HZ	(1 << 2)
83 #define DA9030_VIBRA_FREQ_4HZ	(2 << 2)
84 #define DA9030_VIBRA_FREQ_8HZ	(3 << 2)
85 #define DA9030_VIBRA_DUTY_ON	(0 << 4)
86 #define DA9030_VIBRA_DUTY_75P	(1 << 4)
87 #define DA9030_VIBRA_DUTY_50P	(2 << 4)
88 #define DA9030_VIBRA_DUTY_25P	(3 << 4)
89 
90 /* DA9034 flags for "struct led_info" */
91 #define DA9034_LED_RAMP		(1 << 7)
92 
93 /* DA9034 touch screen platform data */
94 struct da9034_touch_pdata {
95 	int	interval_ms;	/* sampling interval while pen down */
96 	int	x_inverted;
97 	int	y_inverted;
98 };
99 
100 struct da9034_backlight_pdata {
101 	int	output_current;	/* output current of WLED, from 0-31 (in mA) */
102 };
103 
104 /* DA9030 battery charger data */
105 struct power_supply_info;
106 
107 struct da9030_battery_info {
108 	/* battery parameters */
109 	struct power_supply_info *battery_info;
110 
111 	/* current and voltage to use for battery charging */
112 	unsigned int charge_milliamp;
113 	unsigned int charge_millivolt;
114 
115 	/* voltage thresholds (in millivolts) */
116 	int vbat_low;
117 	int vbat_crit;
118 	int vbat_charge_start;
119 	int vbat_charge_stop;
120 	int vbat_charge_restart;
121 
122 	/* battery nominal minimal and maximal voltages in millivolts */
123 	int vcharge_min;
124 	int vcharge_max;
125 
126 	/* Temperature thresholds. These are DA9030 register values
127 	   "as is" and should be measured for each battery type */
128 	int tbat_low;
129 	int tbat_high;
130 	int tbat_restart;
131 
132 
133 	/* battery monitor interval (seconds) */
134 	unsigned int batmon_interval;
135 
136 	/* platform callbacks for battery low and critical events */
137 	void (*battery_low)(void);
138 	void (*battery_critical)(void);
139 };
140 
141 struct da903x_subdev_info {
142 	int		id;
143 	const char	*name;
144 	void		*platform_data;
145 };
146 
147 struct da903x_platform_data {
148 	int num_subdevs;
149 	struct da903x_subdev_info *subdevs;
150 };
151 
152 /* bit definitions for DA9030 events */
153 #define DA9030_EVENT_ONKEY		(1 << 0)
154 #define	DA9030_EVENT_PWREN		(1 << 1)
155 #define	DA9030_EVENT_EXTON		(1 << 2)
156 #define	DA9030_EVENT_CHDET		(1 << 3)
157 #define	DA9030_EVENT_TBAT		(1 << 4)
158 #define	DA9030_EVENT_VBATMON		(1 << 5)
159 #define	DA9030_EVENT_VBATMON_TXON	(1 << 6)
160 #define	DA9030_EVENT_CHIOVER		(1 << 7)
161 #define	DA9030_EVENT_TCTO		(1 << 8)
162 #define	DA9030_EVENT_CCTO		(1 << 9)
163 #define	DA9030_EVENT_ADC_READY		(1 << 10)
164 #define	DA9030_EVENT_VBUS_4P4		(1 << 11)
165 #define	DA9030_EVENT_VBUS_4P0		(1 << 12)
166 #define	DA9030_EVENT_SESS_VALID		(1 << 13)
167 #define	DA9030_EVENT_SRP_DETECT		(1 << 14)
168 #define	DA9030_EVENT_WATCHDOG		(1 << 15)
169 #define	DA9030_EVENT_LDO15		(1 << 16)
170 #define	DA9030_EVENT_LDO16		(1 << 17)
171 #define	DA9030_EVENT_LDO17		(1 << 18)
172 #define	DA9030_EVENT_LDO18		(1 << 19)
173 #define	DA9030_EVENT_LDO19		(1 << 20)
174 #define	DA9030_EVENT_BUCK2		(1 << 21)
175 
176 /* bit definitions for DA9034 events */
177 #define DA9034_EVENT_ONKEY		(1 << 0)
178 #define DA9034_EVENT_EXTON		(1 << 2)
179 #define DA9034_EVENT_CHDET		(1 << 3)
180 #define DA9034_EVENT_TBAT		(1 << 4)
181 #define DA9034_EVENT_VBATMON		(1 << 5)
182 #define DA9034_EVENT_REV_IOVER		(1 << 6)
183 #define DA9034_EVENT_CH_IOVER		(1 << 7)
184 #define DA9034_EVENT_CH_TCTO		(1 << 8)
185 #define DA9034_EVENT_CH_CCTO		(1 << 9)
186 #define DA9034_EVENT_USB_DEV		(1 << 10)
187 #define DA9034_EVENT_OTGCP_IOVER	(1 << 11)
188 #define DA9034_EVENT_VBUS_4P55		(1 << 12)
189 #define DA9034_EVENT_VBUS_3P8		(1 << 13)
190 #define DA9034_EVENT_SESS_1P8		(1 << 14)
191 #define DA9034_EVENT_SRP_READY		(1 << 15)
192 #define DA9034_EVENT_ADC_MAN		(1 << 16)
193 #define DA9034_EVENT_ADC_AUTO4		(1 << 17)
194 #define DA9034_EVENT_ADC_AUTO5		(1 << 18)
195 #define DA9034_EVENT_ADC_AUTO6		(1 << 19)
196 #define DA9034_EVENT_PEN_DOWN		(1 << 20)
197 #define DA9034_EVENT_TSI_READY		(1 << 21)
198 #define DA9034_EVENT_UART_TX		(1 << 22)
199 #define DA9034_EVENT_UART_RX		(1 << 23)
200 #define DA9034_EVENT_HEADSET		(1 << 25)
201 #define DA9034_EVENT_HOOKSWITCH		(1 << 26)
202 #define DA9034_EVENT_WATCHDOG		(1 << 27)
203 
204 extern int da903x_register_notifier(struct device *dev,
205 		struct notifier_block *nb, unsigned int events);
206 extern int da903x_unregister_notifier(struct device *dev,
207 		struct notifier_block *nb, unsigned int events);
208 
209 /* Status Query Interface */
210 #define DA9030_STATUS_ONKEY		(1 << 0)
211 #define DA9030_STATUS_PWREN1		(1 << 1)
212 #define DA9030_STATUS_EXTON		(1 << 2)
213 #define DA9030_STATUS_CHDET		(1 << 3)
214 #define DA9030_STATUS_TBAT		(1 << 4)
215 #define DA9030_STATUS_VBATMON		(1 << 5)
216 #define DA9030_STATUS_VBATMON_TXON	(1 << 6)
217 #define DA9030_STATUS_MCLKDET		(1 << 7)
218 
219 #define DA9034_STATUS_ONKEY		(1 << 0)
220 #define DA9034_STATUS_EXTON		(1 << 2)
221 #define DA9034_STATUS_CHDET		(1 << 3)
222 #define DA9034_STATUS_TBAT		(1 << 4)
223 #define DA9034_STATUS_VBATMON		(1 << 5)
224 #define DA9034_STATUS_PEN_DOWN		(1 << 6)
225 #define DA9034_STATUS_MCLKDET		(1 << 7)
226 #define DA9034_STATUS_USB_DEV		(1 << 8)
227 #define DA9034_STATUS_HEADSET		(1 << 9)
228 #define DA9034_STATUS_HOOKSWITCH	(1 << 10)
229 #define DA9034_STATUS_REMCON		(1 << 11)
230 #define DA9034_STATUS_VBUS_VALID_4P55	(1 << 12)
231 #define DA9034_STATUS_VBUS_VALID_3P8	(1 << 13)
232 #define DA9034_STATUS_SESS_VALID_1P8	(1 << 14)
233 #define DA9034_STATUS_SRP_READY		(1 << 15)
234 
235 extern int da903x_query_status(struct device *dev, unsigned int status);
236 
237 
238 /* NOTE: the functions below are not intended for use outside
239  * of the DA903x sub-device drivers
240  */
241 extern int da903x_write(struct device *dev, int reg, uint8_t val);
242 extern int da903x_writes(struct device *dev, int reg, int len, uint8_t *val);
243 extern int da903x_read(struct device *dev, int reg, uint8_t *val);
244 extern int da903x_reads(struct device *dev, int reg, int len, uint8_t *val);
245 extern int da903x_update(struct device *dev, int reg, uint8_t val, uint8_t mask);
246 extern int da903x_set_bits(struct device *dev, int reg, uint8_t bit_mask);
247 extern int da903x_clr_bits(struct device *dev, int reg, uint8_t bit_mask);
248 #endif /* __LINUX_PMIC_DA903X_H */
249