GNU Linux-libre 5.4.241-gnu1
[releases.git] / include / linux / mfd / rohm-bd70528.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Copyright (C) 2018 ROHM Semiconductors */
3
4 #ifndef __LINUX_MFD_BD70528_H__
5 #define __LINUX_MFD_BD70528_H__
6
7 #include <linux/bits.h>
8 #include <linux/device.h>
9 #include <linux/mfd/rohm-generic.h>
10 #include <linux/regmap.h>
11
12 enum {
13         BD70528_BUCK1,
14         BD70528_BUCK2,
15         BD70528_BUCK3,
16         BD70528_LDO1,
17         BD70528_LDO2,
18         BD70528_LDO3,
19         BD70528_LED1,
20         BD70528_LED2,
21 };
22
23 struct bd70528_data {
24         struct rohm_regmap_dev chip;
25         struct mutex rtc_timer_lock;
26 };
27
28 #define BD70528_BUCK_VOLTS 0x10
29 #define BD70528_LDO_VOLTS 0x20
30
31 #define BD70528_REG_BUCK1_EN    0x0F
32 #define BD70528_REG_BUCK1_VOLT  0x15
33 #define BD70528_REG_BUCK2_EN    0x10
34 #define BD70528_REG_BUCK2_VOLT  0x16
35 #define BD70528_REG_BUCK3_EN    0x11
36 #define BD70528_REG_BUCK3_VOLT  0x17
37 #define BD70528_REG_LDO1_EN     0x1b
38 #define BD70528_REG_LDO1_VOLT   0x1e
39 #define BD70528_REG_LDO2_EN     0x1c
40 #define BD70528_REG_LDO2_VOLT   0x1f
41 #define BD70528_REG_LDO3_EN     0x1d
42 #define BD70528_REG_LDO3_VOLT   0x20
43 #define BD70528_REG_LED_CTRL    0x2b
44 #define BD70528_REG_LED_VOLT    0x29
45 #define BD70528_REG_LED_EN      0x2a
46
47 /* main irq registers */
48 #define BD70528_REG_INT_MAIN    0x7E
49 #define BD70528_REG_INT_MAIN_MASK 0x74
50
51 /* 'sub irq' registers */
52 #define BD70528_REG_INT_SHDN    0x7F
53 #define BD70528_REG_INT_PWR_FLT 0x80
54 #define BD70528_REG_INT_VR_FLT  0x81
55 #define BD70528_REG_INT_MISC    0x82
56 #define BD70528_REG_INT_BAT1    0x83
57 #define BD70528_REG_INT_BAT2    0x84
58 #define BD70528_REG_INT_RTC     0x85
59 #define BD70528_REG_INT_GPIO    0x86
60 #define BD70528_REG_INT_OP_FAIL 0x87
61
62 #define BD70528_REG_INT_SHDN_MASK       0x75
63 #define BD70528_REG_INT_PWR_FLT_MASK    0x76
64 #define BD70528_REG_INT_VR_FLT_MASK     0x77
65 #define BD70528_REG_INT_MISC_MASK       0x78
66 #define BD70528_REG_INT_BAT1_MASK       0x79
67 #define BD70528_REG_INT_BAT2_MASK       0x7a
68 #define BD70528_REG_INT_RTC_MASK        0x7b
69 #define BD70528_REG_INT_GPIO_MASK       0x7c
70 #define BD70528_REG_INT_OP_FAIL_MASK    0x7d
71
72 /* Reset related 'magic' registers */
73 #define BD70528_REG_SHIPMODE    0x03
74 #define BD70528_REG_HWRESET     0x04
75 #define BD70528_REG_WARMRESET   0x05
76 #define BD70528_REG_STANDBY     0x06
77
78 /* GPIO registers */
79 #define BD70528_REG_GPIO_STATE  0x8F
80
81 #define BD70528_REG_GPIO1_IN    0x4d
82 #define BD70528_REG_GPIO2_IN    0x4f
83 #define BD70528_REG_GPIO3_IN    0x51
84 #define BD70528_REG_GPIO4_IN    0x53
85 #define BD70528_REG_GPIO1_OUT   0x4e
86 #define BD70528_REG_GPIO2_OUT   0x50
87 #define BD70528_REG_GPIO3_OUT   0x52
88 #define BD70528_REG_GPIO4_OUT   0x54
89
90 /* clk control */
91
92 #define BD70528_REG_CLK_OUT     0x2c
93
94 /* RTC */
95
96 #define BD70528_REG_RTC_COUNT_H         0x2d
97 #define BD70528_REG_RTC_COUNT_L         0x2e
98 #define BD70528_REG_RTC_SEC             0x2f
99 #define BD70528_REG_RTC_MINUTE          0x30
100 #define BD70528_REG_RTC_HOUR            0x31
101 #define BD70528_REG_RTC_WEEK            0x32
102 #define BD70528_REG_RTC_DAY             0x33
103 #define BD70528_REG_RTC_MONTH           0x34
104 #define BD70528_REG_RTC_YEAR            0x35
105
106 #define BD70528_REG_RTC_ALM_SEC         0x36
107 #define BD70528_REG_RTC_ALM_START       BD70528_REG_RTC_ALM_SEC
108 #define BD70528_REG_RTC_ALM_MINUTE      0x37
109 #define BD70528_REG_RTC_ALM_HOUR        0x38
110 #define BD70528_REG_RTC_ALM_WEEK        0x39
111 #define BD70528_REG_RTC_ALM_DAY         0x3a
112 #define BD70528_REG_RTC_ALM_MONTH       0x3b
113 #define BD70528_REG_RTC_ALM_YEAR        0x3c
114 #define BD70528_REG_RTC_ALM_MASK        0x3d
115 #define BD70528_REG_RTC_ALM_REPEAT      0x3e
116 #define BD70528_REG_RTC_START           BD70528_REG_RTC_SEC
117
118 #define BD70528_REG_RTC_WAKE_SEC        0x43
119 #define BD70528_REG_RTC_WAKE_START      BD70528_REG_RTC_WAKE_SEC
120 #define BD70528_REG_RTC_WAKE_MIN        0x44
121 #define BD70528_REG_RTC_WAKE_HOUR       0x45
122 #define BD70528_REG_RTC_WAKE_CTRL       0x46
123
124 #define BD70528_REG_ELAPSED_TIMER_EN    0x42
125 #define BD70528_REG_WAKE_EN             0x46
126
127 /* WDT registers */
128 #define BD70528_REG_WDT_CTRL            0x4A
129 #define BD70528_REG_WDT_HOUR            0x49
130 #define BD70528_REG_WDT_MINUTE          0x48
131 #define BD70528_REG_WDT_SEC             0x47
132
133 /* Charger / Battery */
134 #define BD70528_REG_CHG_CURR_STAT       0x59
135 #define BD70528_REG_CHG_BAT_STAT        0x57
136 #define BD70528_REG_CHG_BAT_TEMP        0x58
137 #define BD70528_REG_CHG_IN_STAT         0x56
138 #define BD70528_REG_CHG_DCIN_ILIM       0x5d
139 #define BD70528_REG_CHG_CHG_CURR_WARM   0x61
140 #define BD70528_REG_CHG_CHG_CURR_COLD   0x62
141
142 /* Masks for main IRQ register bits */
143 enum {
144         BD70528_INT_SHDN,
145 #define BD70528_INT_SHDN_MASK BIT(BD70528_INT_SHDN)
146         BD70528_INT_PWR_FLT,
147 #define BD70528_INT_PWR_FLT_MASK BIT(BD70528_INT_PWR_FLT)
148         BD70528_INT_VR_FLT,
149 #define BD70528_INT_VR_FLT_MASK BIT(BD70528_INT_VR_FLT)
150         BD70528_INT_MISC,
151 #define BD70528_INT_MISC_MASK BIT(BD70528_INT_MISC)
152         BD70528_INT_BAT1,
153 #define BD70528_INT_BAT1_MASK BIT(BD70528_INT_BAT1)
154         BD70528_INT_RTC,
155 #define BD70528_INT_RTC_MASK BIT(BD70528_INT_RTC)
156         BD70528_INT_GPIO,
157 #define BD70528_INT_GPIO_MASK BIT(BD70528_INT_GPIO)
158         BD70528_INT_OP_FAIL,
159 #define BD70528_INT_OP_FAIL_MASK BIT(BD70528_INT_OP_FAIL)
160 };
161
162 /* IRQs */
163 enum {
164         /* Shutdown register IRQs */
165         BD70528_INT_LONGPUSH,
166         BD70528_INT_WDT,
167         BD70528_INT_HWRESET,
168         BD70528_INT_RSTB_FAULT,
169         BD70528_INT_VBAT_UVLO,
170         BD70528_INT_TSD,
171         BD70528_INT_RSTIN,
172         /* Power failure register IRQs */
173         BD70528_INT_BUCK1_FAULT,
174         BD70528_INT_BUCK2_FAULT,
175         BD70528_INT_BUCK3_FAULT,
176         BD70528_INT_LDO1_FAULT,
177         BD70528_INT_LDO2_FAULT,
178         BD70528_INT_LDO3_FAULT,
179         BD70528_INT_LED1_FAULT,
180         BD70528_INT_LED2_FAULT,
181         /* VR FAULT register IRQs */
182         BD70528_INT_BUCK1_OCP,
183         BD70528_INT_BUCK2_OCP,
184         BD70528_INT_BUCK3_OCP,
185         BD70528_INT_LED1_OCP,
186         BD70528_INT_LED2_OCP,
187         BD70528_INT_BUCK1_FULLON,
188         BD70528_INT_BUCK2_FULLON,
189         /* PMU register interrupts */
190         BD70528_INT_SHORTPUSH,
191         BD70528_INT_AUTO_WAKEUP,
192         BD70528_INT_STATE_CHANGE,
193         /* Charger 1 register IRQs */
194         BD70528_INT_BAT_OV_RES,
195         BD70528_INT_BAT_OV_DET,
196         BD70528_INT_DBAT_DET,
197         BD70528_INT_BATTSD_COLD_RES,
198         BD70528_INT_BATTSD_COLD_DET,
199         BD70528_INT_BATTSD_HOT_RES,
200         BD70528_INT_BATTSD_HOT_DET,
201         BD70528_INT_CHG_TSD,
202         /* Charger 2 register IRQs */
203         BD70528_INT_BAT_RMV,
204         BD70528_INT_BAT_DET,
205         BD70528_INT_DCIN2_OV_RES,
206         BD70528_INT_DCIN2_OV_DET,
207         BD70528_INT_DCIN2_RMV,
208         BD70528_INT_DCIN2_DET,
209         BD70528_INT_DCIN1_RMV,
210         BD70528_INT_DCIN1_DET,
211         /* RTC register IRQs */
212         BD70528_INT_RTC_ALARM,
213         BD70528_INT_ELPS_TIM,
214         /* GPIO register IRQs */
215         BD70528_INT_GPIO0,
216         BD70528_INT_GPIO1,
217         BD70528_INT_GPIO2,
218         BD70528_INT_GPIO3,
219         /* Invalid operation register IRQs */
220         BD70528_INT_BUCK1_DVS_OPFAIL,
221         BD70528_INT_BUCK2_DVS_OPFAIL,
222         BD70528_INT_BUCK3_DVS_OPFAIL,
223         BD70528_INT_LED1_VOLT_OPFAIL,
224         BD70528_INT_LED2_VOLT_OPFAIL,
225 };
226
227 /* Masks */
228 #define BD70528_INT_LONGPUSH_MASK 0x1
229 #define BD70528_INT_WDT_MASK 0x2
230 #define BD70528_INT_HWRESET_MASK 0x4
231 #define BD70528_INT_RSTB_FAULT_MASK 0x8
232 #define BD70528_INT_VBAT_UVLO_MASK 0x10
233 #define BD70528_INT_TSD_MASK 0x20
234 #define BD70528_INT_RSTIN_MASK 0x40
235
236 #define BD70528_INT_BUCK1_FAULT_MASK 0x1
237 #define BD70528_INT_BUCK2_FAULT_MASK 0x2
238 #define BD70528_INT_BUCK3_FAULT_MASK 0x4
239 #define BD70528_INT_LDO1_FAULT_MASK 0x8
240 #define BD70528_INT_LDO2_FAULT_MASK 0x10
241 #define BD70528_INT_LDO3_FAULT_MASK 0x20
242 #define BD70528_INT_LED1_FAULT_MASK 0x40
243 #define BD70528_INT_LED2_FAULT_MASK 0x80
244
245 #define BD70528_INT_BUCK1_OCP_MASK 0x1
246 #define BD70528_INT_BUCK2_OCP_MASK 0x2
247 #define BD70528_INT_BUCK3_OCP_MASK 0x4
248 #define BD70528_INT_LED1_OCP_MASK 0x8
249 #define BD70528_INT_LED2_OCP_MASK 0x10
250 #define BD70528_INT_BUCK1_FULLON_MASK 0x20
251 #define BD70528_INT_BUCK2_FULLON_MASK 0x40
252
253 #define BD70528_INT_SHORTPUSH_MASK 0x1
254 #define BD70528_INT_AUTO_WAKEUP_MASK 0x2
255 #define BD70528_INT_STATE_CHANGE_MASK 0x10
256
257 #define BD70528_INT_BAT_OV_RES_MASK 0x1
258 #define BD70528_INT_BAT_OV_DET_MASK 0x2
259 #define BD70528_INT_DBAT_DET_MASK 0x4
260 #define BD70528_INT_BATTSD_COLD_RES_MASK 0x8
261 #define BD70528_INT_BATTSD_COLD_DET_MASK 0x10
262 #define BD70528_INT_BATTSD_HOT_RES_MASK 0x20
263 #define BD70528_INT_BATTSD_HOT_DET_MASK 0x40
264 #define BD70528_INT_CHG_TSD_MASK 0x80
265
266 #define BD70528_INT_BAT_RMV_MASK 0x1
267 #define BD70528_INT_BAT_DET_MASK 0x2
268 #define BD70528_INT_DCIN2_OV_RES_MASK 0x4
269 #define BD70528_INT_DCIN2_OV_DET_MASK 0x8
270 #define BD70528_INT_DCIN2_RMV_MASK 0x10
271 #define BD70528_INT_DCIN2_DET_MASK 0x20
272 #define BD70528_INT_DCIN1_RMV_MASK 0x40
273 #define BD70528_INT_DCIN1_DET_MASK 0x80
274
275 #define BD70528_INT_RTC_ALARM_MASK 0x1
276 #define BD70528_INT_ELPS_TIM_MASK 0x2
277
278 #define BD70528_INT_GPIO0_MASK 0x1
279 #define BD70528_INT_GPIO1_MASK 0x2
280 #define BD70528_INT_GPIO2_MASK 0x4
281 #define BD70528_INT_GPIO3_MASK 0x8
282
283 #define BD70528_INT_BUCK1_DVS_OPFAIL_MASK 0x1
284 #define BD70528_INT_BUCK2_DVS_OPFAIL_MASK 0x2
285 #define BD70528_INT_BUCK3_DVS_OPFAIL_MASK 0x4
286 #define BD70528_INT_LED1_VOLT_OPFAIL_MASK 0x10
287 #define BD70528_INT_LED2_VOLT_OPFAIL_MASK 0x20
288
289 #define BD70528_DEBOUNCE_MASK 0x3
290
291 #define BD70528_DEBOUNCE_DISABLE 0
292 #define BD70528_DEBOUNCE_15MS 1
293 #define BD70528_DEBOUNCE_30MS 2
294 #define BD70528_DEBOUNCE_50MS 3
295
296 #define BD70528_GPIO_DRIVE_MASK 0x2
297 #define BD70528_GPIO_PUSH_PULL 0x0
298 #define BD70528_GPIO_OPEN_DRAIN 0x2
299
300 #define BD70528_GPIO_OUT_EN_MASK 0x80
301 #define BD70528_GPIO_OUT_ENABLE 0x80
302 #define BD70528_GPIO_OUT_DISABLE 0x0
303
304 #define BD70528_GPIO_OUT_HI 0x1
305 #define BD70528_GPIO_OUT_LO 0x0
306 #define BD70528_GPIO_OUT_MASK 0x1
307
308 #define BD70528_GPIO_IN_STATE_BASE 1
309
310 #define BD70528_CLK_OUT_EN_MASK 0x1
311
312 /* RTC masks to mask out reserved bits */
313
314 #define BD70528_MASK_RTC_SEC            0x7f
315 #define BD70528_MASK_RTC_MINUTE         0x7f
316 #define BD70528_MASK_RTC_HOUR_24H       0x80
317 #define BD70528_MASK_RTC_HOUR_PM        0x20
318 #define BD70528_MASK_RTC_HOUR           0x3f
319 #define BD70528_MASK_RTC_DAY            0x3f
320 #define BD70528_MASK_RTC_WEEK           0x07
321 #define BD70528_MASK_RTC_MONTH          0x1f
322 #define BD70528_MASK_RTC_YEAR           0xff
323 #define BD70528_MASK_RTC_COUNT_L        0x7f
324
325 #define BD70528_MASK_ELAPSED_TIMER_EN   0x1
326 /* Mask second, min and hour fields
327  * HW would support ALM irq for over 24h
328  * (by setting day, month and year too)
329  * but as we wish to keep this same as for
330  * wake-up we limit ALM to 24H and only
331  * unmask sec, min and hour
332  */
333 #define BD70528_MASK_ALM_EN             0x7
334 #define BD70528_MASK_WAKE_EN            0x1
335
336 /* WDT masks */
337 #define BD70528_MASK_WDT_EN             0x1
338 #define BD70528_MASK_WDT_HOUR           0x1
339 #define BD70528_MASK_WDT_MINUTE         0x7f
340 #define BD70528_MASK_WDT_SEC            0x7f
341
342 #define BD70528_WDT_STATE_BIT           0x1
343 #define BD70528_ELAPSED_STATE_BIT       0x2
344 #define BD70528_WAKE_STATE_BIT          0x4
345
346 /* Charger masks */
347 #define BD70528_MASK_CHG_STAT           0x7f
348 #define BD70528_MASK_CHG_BAT_TIMER      0x20
349 #define BD70528_MASK_CHG_BAT_OVERVOLT   0x10
350 #define BD70528_MASK_CHG_BAT_DETECT     0x1
351 #define BD70528_MASK_CHG_DCIN1_UVLO     0x1
352 #define BD70528_MASK_CHG_DCIN_ILIM      0x3f
353 #define BD70528_MASK_CHG_CHG_CURR       0x1f
354 #define BD70528_MASK_CHG_TRICKLE_CURR   0x10
355
356 /*
357  * Note, external battery register is the lonely rider at
358  * address 0xc5. See how to stuff that in the regmap
359  */
360 #define BD70528_MAX_REGISTER 0x94
361
362 /* Buck control masks */
363 #define BD70528_MASK_RUN_EN     0x4
364 #define BD70528_MASK_STBY_EN    0x2
365 #define BD70528_MASK_IDLE_EN    0x1
366 #define BD70528_MASK_LED1_EN    0x1
367 #define BD70528_MASK_LED2_EN    0x10
368
369 #define BD70528_MASK_BUCK_VOLT  0xf
370 #define BD70528_MASK_LDO_VOLT   0x1f
371 #define BD70528_MASK_LED1_VOLT  0x1
372 #define BD70528_MASK_LED2_VOLT  0x10
373
374 /* Misc irq masks */
375 #define BD70528_INT_MASK_SHORT_PUSH     1
376 #define BD70528_INT_MASK_AUTO_WAKE      2
377 #define BD70528_INT_MASK_POWER_STATE    4
378
379 #define BD70528_MASK_BUCK_RAMP 0x10
380 #define BD70528_SIFT_BUCK_RAMP 4
381
382 #if IS_ENABLED(CONFIG_BD70528_WATCHDOG)
383
384 int bd70528_wdt_set(struct rohm_regmap_dev *data, int enable, int *old_state);
385 void bd70528_wdt_lock(struct rohm_regmap_dev *data);
386 void bd70528_wdt_unlock(struct rohm_regmap_dev *data);
387
388 #else /* CONFIG_BD70528_WATCHDOG */
389
390 static inline int bd70528_wdt_set(struct rohm_regmap_dev *data, int enable,
391                                   int *old_state)
392 {
393         return 0;
394 }
395
396 static inline void bd70528_wdt_lock(struct rohm_regmap_dev *data)
397 {
398 }
399
400 static inline void bd70528_wdt_unlock(struct rohm_regmap_dev *data)
401 {
402 }
403
404 #endif /* CONFIG_BD70528_WATCHDOG */
405
406 #endif /* __LINUX_MFD_BD70528_H__ */