mfd: rk8xx: add pm_shutdown callback in rk8xx_power_data
[firefly-linux-kernel-4.4.55.git] / include / linux / mfd / rk808.h
1 /*
2  * rk808.h for Rockchip RK808
3  *
4  * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
5  *
6  * Author: Chris Zhong <zyw@rock-chips.com>
7  * Author: Zhang Qing <zhangqing@rock-chips.com>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms and conditions of the GNU General Public License,
11  * version 2, as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  * more details.
17  */
18
19 #ifndef __LINUX_REGULATOR_rk808_H
20 #define __LINUX_REGULATOR_rk808_H
21
22 #include <linux/regulator/machine.h>
23 #include <linux/regmap.h>
24
25 /*
26  * rk808 Global Register Map.
27  */
28
29 #define RK808_DCDC1     0 /* (0+RK808_START) */
30 #define RK808_LDO1      4 /* (4+RK808_START) */
31 #define RK808_NUM_REGULATORS   14
32
33 enum rk808_reg {
34         RK808_ID_DCDC1,
35         RK808_ID_DCDC2,
36         RK808_ID_DCDC3,
37         RK808_ID_DCDC4,
38         RK808_ID_LDO1,
39         RK808_ID_LDO2,
40         RK808_ID_LDO3,
41         RK808_ID_LDO4,
42         RK808_ID_LDO5,
43         RK808_ID_LDO6,
44         RK808_ID_LDO7,
45         RK808_ID_LDO8,
46         RK808_ID_SWITCH1,
47         RK808_ID_SWITCH2,
48 };
49
50 enum rk818_reg {
51         RK818_ID_DCDC1,
52         RK818_ID_DCDC2,
53         RK818_ID_DCDC3,
54         RK818_ID_DCDC4,
55         RK818_ID_LDO1,
56         RK818_ID_LDO2,
57         RK818_ID_LDO3,
58         RK818_ID_LDO4,
59         RK818_ID_LDO5,
60         RK818_ID_LDO6,
61         RK818_ID_LDO7,
62         RK818_ID_LDO8,
63         RK818_ID_LDO9,
64         RK818_ID_SWITCH,
65 };
66
67 #define RK808_SECONDS_REG       0x00
68 #define RK808_MINUTES_REG       0x01
69 #define RK808_HOURS_REG         0x02
70 #define RK808_DAYS_REG          0x03
71 #define RK808_MONTHS_REG        0x04
72 #define RK808_YEARS_REG         0x05
73 #define RK808_WEEKS_REG         0x06
74 #define RK808_ALARM_SECONDS_REG 0x08
75 #define RK808_ALARM_MINUTES_REG 0x09
76 #define RK808_ALARM_HOURS_REG   0x0a
77 #define RK808_ALARM_DAYS_REG    0x0b
78 #define RK808_ALARM_MONTHS_REG  0x0c
79 #define RK808_ALARM_YEARS_REG   0x0d
80 #define RK808_RTC_CTRL_REG      0x10
81 #define RK808_RTC_STATUS_REG    0x11
82 #define RK808_RTC_INT_REG       0x12
83 #define RK808_RTC_COMP_LSB_REG  0x13
84 #define RK808_RTC_COMP_MSB_REG  0x14
85 #define RK808_CLK32OUT_REG      0x20
86 #define RK808_VB_MON_REG        0x21
87 #define RK808_THERMAL_REG       0x22
88 #define RK808_DCDC_EN_REG       0x23
89 #define RK808_LDO_EN_REG        0x24
90 #define RK808_SLEEP_SET_OFF_REG1        0x25
91 #define RK808_SLEEP_SET_OFF_REG2        0x26
92 #define RK808_DCDC_UV_STS_REG   0x27
93 #define RK808_DCDC_UV_ACT_REG   0x28
94 #define RK808_LDO_UV_STS_REG    0x29
95 #define RK808_LDO_UV_ACT_REG    0x2a
96 #define RK808_DCDC_PG_REG       0x2b
97 #define RK808_LDO_PG_REG        0x2c
98 #define RK808_VOUT_MON_TDB_REG  0x2d
99 #define RK808_BUCK1_CONFIG_REG          0x2e
100 #define RK808_BUCK1_ON_VSEL_REG         0x2f
101 #define RK808_BUCK1_SLP_VSEL_REG        0x30
102 #define RK808_BUCK1_DVS_VSEL_REG        0x31
103 #define RK808_BUCK2_CONFIG_REG          0x32
104 #define RK808_BUCK2_ON_VSEL_REG         0x33
105 #define RK808_BUCK2_SLP_VSEL_REG        0x34
106 #define RK808_BUCK2_DVS_VSEL_REG        0x35
107 #define RK808_BUCK3_CONFIG_REG          0x36
108 #define RK808_BUCK4_CONFIG_REG          0x37
109 #define RK808_BUCK4_ON_VSEL_REG         0x38
110 #define RK808_BUCK4_SLP_VSEL_REG        0x39
111 #define RK808_BOOST_CONFIG_REG          0x3a
112 #define RK808_LDO1_ON_VSEL_REG          0x3b
113 #define RK808_LDO1_SLP_VSEL_REG         0x3c
114 #define RK808_LDO2_ON_VSEL_REG          0x3d
115 #define RK808_LDO2_SLP_VSEL_REG         0x3e
116 #define RK808_LDO3_ON_VSEL_REG          0x3f
117 #define RK808_LDO3_SLP_VSEL_REG         0x40
118 #define RK808_LDO4_ON_VSEL_REG          0x41
119 #define RK808_LDO4_SLP_VSEL_REG         0x42
120 #define RK808_LDO5_ON_VSEL_REG          0x43
121 #define RK808_LDO5_SLP_VSEL_REG         0x44
122 #define RK808_LDO6_ON_VSEL_REG          0x45
123 #define RK808_LDO6_SLP_VSEL_REG         0x46
124 #define RK808_LDO7_ON_VSEL_REG          0x47
125 #define RK808_LDO7_SLP_VSEL_REG         0x48
126 #define RK808_LDO8_ON_VSEL_REG          0x49
127 #define RK808_LDO8_SLP_VSEL_REG         0x4a
128 #define RK808_DEVCTRL_REG       0x4b
129 #define RK808_INT_STS_REG1      0x4c
130 #define RK808_INT_STS_MSK_REG1  0x4d
131 #define RK808_INT_STS_REG2      0x4e
132 #define RK808_INT_STS_MSK_REG2  0x4f
133 #define RK808_IO_POL_REG        0x50
134
135 #define RK818_VB_MON_REG                0x21
136 #define RK818_THERMAL_REG               0x22
137 #define RK818_DCDC_EN_REG               0x23
138 #define RK818_LDO_EN_REG                0x24
139 #define RK818_SLEEP_SET_OFF_REG1        0x25
140 #define RK818_SLEEP_SET_OFF_REG2        0x26
141 #define RK818_DCDC_UV_STS_REG           0x27
142 #define RK818_DCDC_UV_ACT_REG           0x28
143 #define RK818_LDO_UV_STS_REG            0x29
144 #define RK818_LDO_UV_ACT_REG            0x2a
145 #define RK818_DCDC_PG_REG               0x2b
146 #define RK818_LDO_PG_REG                0x2c
147 #define RK818_VOUT_MON_TDB_REG          0x2d
148 #define RK818_BUCK1_CONFIG_REG          0x2e
149 #define RK818_BUCK1_ON_VSEL_REG         0x2f
150 #define RK818_BUCK1_SLP_VSEL_REG        0x30
151 #define RK818_BUCK2_CONFIG_REG          0x32
152 #define RK818_BUCK2_ON_VSEL_REG         0x33
153 #define RK818_BUCK2_SLP_VSEL_REG        0x34
154 #define RK818_BUCK3_CONFIG_REG          0x36
155 #define RK818_BUCK4_CONFIG_REG          0x37
156 #define RK818_BUCK4_ON_VSEL_REG         0x38
157 #define RK818_BUCK4_SLP_VSEL_REG        0x39
158 #define RK818_BOOST_CONFIG_REG          0x3a
159 #define RK818_LDO1_ON_VSEL_REG          0x3b
160 #define RK818_LDO1_SLP_VSEL_REG         0x3c
161 #define RK818_LDO2_ON_VSEL_REG          0x3d
162 #define RK818_LDO2_SLP_VSEL_REG         0x3e
163 #define RK818_LDO3_ON_VSEL_REG          0x3f
164 #define RK818_LDO3_SLP_VSEL_REG         0x40
165 #define RK818_LDO4_ON_VSEL_REG          0x41
166 #define RK818_LDO4_SLP_VSEL_REG         0x42
167 #define RK818_LDO5_ON_VSEL_REG          0x43
168 #define RK818_LDO5_SLP_VSEL_REG         0x44
169 #define RK818_LDO6_ON_VSEL_REG          0x45
170 #define RK818_LDO6_SLP_VSEL_REG         0x46
171 #define RK818_LDO7_ON_VSEL_REG          0x47
172 #define RK818_LDO7_SLP_VSEL_REG         0x48
173 #define RK818_LDO8_ON_VSEL_REG          0x49
174 #define RK818_LDO8_SLP_VSEL_REG         0x4a
175 #define RK818_DEVCTRL_REG               0x4b
176 #define RK818_INT_STS_REG1              0X4c
177 #define RK818_INT_STS_MSK_REG1          0X4d
178 #define RK818_INT_STS_REG2              0X4e
179 #define RK818_INT_STS_MSK_REG2          0X4f
180 #define RK818_IO_POL_REG                0X50
181 #define RK818_OTP_VDD_EN_REG            0x51
182 #define RK818_H5V_EN_REG                0x52
183 #define RK818_SLEEP_SET_OFF_REG3        0x53
184 #define RK818_BOOST_LDO9_ON_VSEL_REG    0x54
185 #define RK818_BOOST_LDO9_SLP_VSEL_REG   0x55
186 #define RK818_BOOST_CTRL_REG            0x56
187 #define RK818_DCDC_ILMAX_REG            0x90
188 #define RK818_CHRG_COMP_REG             0x9a
189 #define RK818_SUP_STS_REG               0xa0
190 #define RK818_USB_CTRL_REG              0xa1
191
192 #define RK818_SAVE_DATA19               0xF2
193 #define RK818_NUM_REGULATORS            14
194
195 /* IRQ Definitions */
196 #define RK808_IRQ_VOUT_LO       0
197 #define RK808_IRQ_VB_LO         1
198 #define RK808_IRQ_PWRON         2
199 #define RK808_IRQ_PWRON_LP      3
200 #define RK808_IRQ_HOTDIE        4
201 #define RK808_IRQ_RTC_ALARM     5
202 #define RK808_IRQ_RTC_PERIOD    6
203 #define RK808_IRQ_PLUG_IN_INT   7
204 #define RK808_IRQ_PLUG_OUT_INT  8
205 #define RK808_NUM_IRQ           9
206
207 #define RK808_IRQ_VOUT_LO_MSK           BIT(0)
208 #define RK808_IRQ_VB_LO_MSK             BIT(1)
209 #define RK808_IRQ_PWRON_MSK             BIT(2)
210 #define RK808_IRQ_PWRON_LP_MSK          BIT(3)
211 #define RK808_IRQ_HOTDIE_MSK            BIT(4)
212 #define RK808_IRQ_RTC_ALARM_MSK         BIT(5)
213 #define RK808_IRQ_RTC_PERIOD_MSK        BIT(6)
214 #define RK808_IRQ_PLUG_IN_INT_MSK       BIT(0)
215 #define RK808_IRQ_PLUG_OUT_INT_MSK      BIT(1)
216
217 #define RK808_VBAT_LOW_2V8      0x00
218 #define RK808_VBAT_LOW_2V9      0x01
219 #define RK808_VBAT_LOW_3V0      0x02
220 #define RK808_VBAT_LOW_3V1      0x03
221 #define RK808_VBAT_LOW_3V2      0x04
222 #define RK808_VBAT_LOW_3V3      0x05
223 #define RK808_VBAT_LOW_3V4      0x06
224 #define RK808_VBAT_LOW_3V5      0x07
225 #define VBAT_LOW_VOL_MASK       (0x07 << 0)
226 #define EN_VABT_LOW_SHUT_DOWN   (0x00 << 4)
227 #define EN_VBAT_LOW_IRQ         (0x1 << 4)
228 #define VBAT_LOW_ACT_MASK       (0x1 << 4)
229
230 #define BUCK_ILMIN_MASK         (7 << 0)
231 #define BOOST_ILMIN_MASK        (7 << 0)
232 #define BUCK1_RATE_MASK         (3 << 3)
233 #define BUCK2_RATE_MASK         (3 << 3)
234 #define MASK_ALL        0xff
235
236 #define BUCK_UV_ACT_MASK        0x0f
237 #define BUCK_UV_ACT_DISABLE     0
238
239 #define SWITCH2_EN      BIT(6)
240 #define SWITCH1_EN      BIT(5)
241 #define DEV_OFF_RST     BIT(3)
242 #define DEV_OFF         BIT(0)
243
244 #define VB_LO_ACT               BIT(4)
245 #define VB_LO_SEL_3500MV        (7 << 0)
246
247 #define VOUT_LO_INT     BIT(0)
248 #define CLK32KOUT2_EN   BIT(0)
249 #define H5V_EN_MASK             BIT(0)
250 #define H5V_EN_ENABLE           BIT(0)
251 #define REF_RDY_CTRL_MASK       BIT(1)
252 #define REF_RDY_CTRL_ENABLE     BIT(1)
253
254 /*RK818_DCDC_EN_REG*/
255 #define BUCK1_EN_MASK           BIT(0)
256 #define BUCK2_EN_MASK           BIT(1)
257 #define BUCK3_EN_MASK           BIT(2)
258 #define BUCK4_EN_MASK           BIT(3)
259 #define BOOST_EN_MASK           BIT(4)
260 #define LDO9_EN_MASK            BIT(5)
261 #define SWITCH_EN_MASK          BIT(6)
262 #define OTG_EN_MASK             BIT(7)
263
264 #define BUCK1_EN_ENABLE         BIT(0)
265 #define BUCK2_EN_ENABLE         BIT(1)
266 #define BUCK3_EN_ENABLE         BIT(2)
267 #define BUCK4_EN_ENABLE         BIT(3)
268 #define BOOST_EN_ENABLE         BIT(4)
269 #define LDO9_EN_ENABLE          BIT(5)
270 #define SWITCH_EN_ENABLE        BIT(6)
271 #define OTG_EN_ENABLE           BIT(7)
272
273 /* IRQ Definitions */
274 #define RK818_IRQ_VOUT_LO       0
275 #define RK818_IRQ_VB_LO         1
276 #define RK818_IRQ_PWRON         2
277 #define RK818_IRQ_PWRON_LP      3
278 #define RK818_IRQ_HOTDIE        4
279 #define RK818_IRQ_RTC_ALARM     5
280 #define RK818_IRQ_RTC_PERIOD    6
281 #define RK818_IRQ_USB_OV        7
282 #define RK818_IRQ_PLUG_IN       8
283 #define RK818_IRQ_PLUG_OUT      9
284 #define RK818_IRQ_CHG_OK        10
285 #define RK818_IRQ_CHG_TE        11
286 #define RK818_IRQ_CHG_TS1       12
287 #define RK818_IRQ_TS2           13
288 #define RK818_IRQ_CHG_CVTLIM    14
289 #define RK818_IRQ_DISCHG_ILIM   15
290
291 #define BUCK1_SLP_SET_MASK      BIT(0)
292 #define BUCK2_SLP_SET_MASK      BIT(1)
293 #define BUCK3_SLP_SET_MASK      BIT(2)
294 #define BUCK4_SLP_SET_MASK      BIT(3)
295 #define BOOST_SLP_SET_MASK      BIT(4)
296 #define LDO9_SLP_SET_MASK       BIT(5)
297 #define SWITCH_SLP_SET_MASK     BIT(6)
298 #define OTG_SLP_SET_MASK        BIT(7)
299
300 #define BUCK1_SLP_SET_OFF       BIT(0)
301 #define BUCK2_SLP_SET_OFF       BIT(1)
302 #define BUCK3_SLP_SET_OFF       BIT(2)
303 #define BUCK4_SLP_SET_OFF       BIT(3)
304 #define BOOST_SLP_SET_OFF       BIT(4)
305 #define LDO9_SLP_SET_OFF        BIT(5)
306 #define SWITCH_SLP_SET_OFF      BIT(6)
307 #define OTG_SLP_SET_OFF         BIT(7)
308
309 #define BUCK1_SLP_SET_ON        BIT(0)
310 #define BUCK2_SLP_SET_ON        BIT(1)
311 #define BUCK3_SLP_SET_ON        BIT(2)
312 #define BUCK4_SLP_SET_ON        BIT(3)
313 #define BOOST_SLP_SET_ON        BIT(4)
314 #define LDO9_SLP_SET_ON         BIT(5)
315 #define SWITCH_SLP_SET_ON       BIT(6)
316 #define OTG_SLP_SET_ON          BIT(7)
317
318 #define VOUT_LO_MASK            BIT(0)
319 #define VB_LO_MASK              BIT(1)
320 #define PWRON_MASK              BIT(2)
321 #define PWRON_LP_MASK           BIT(3)
322 #define HOTDIE_MASK             BIT(4)
323 #define RTC_ALARM_MASK          BIT(5)
324 #define RTC_PERIOD_MASK         BIT(6)
325 #define USB_OV_MASK             BIT(7)
326
327 #define VOUT_LO_DISABLE         BIT(0)
328 #define VB_LO_DISABLE           BIT(1)
329 #define PWRON_DISABLE           BIT(2)
330 #define PWRON_LP_DISABLE        BIT(3)
331 #define HOTDIE_DISABLE          BIT(4)
332 #define RTC_ALARM_DISABLE       BIT(5)
333 #define RTC_PERIOD_DISABLE      BIT(6)
334 #define USB_OV_INT_DISABLE      BIT(7)
335
336 #define VOUT_LO_ENABLE          (0 << 0)
337 #define VB_LO_ENABLE            (0 << 1)
338 #define PWRON_ENABLE            (0 << 2)
339 #define PWRON_LP_ENABLE         (0 << 3)
340 #define HOTDIE_ENABLE           (0 << 4)
341 #define RTC_ALARM_ENABLE        (0 << 5)
342 #define RTC_PERIOD_ENABLE       (0 << 6)
343 #define USB_OV_INT_ENABLE       (0 << 7)
344
345 #define PLUG_IN_MASK            BIT(0)
346 #define PLUG_OUT_MASK           BIT(1)
347 #define CHGOK_MASK              BIT(2)
348 #define CHGTE_MASK              BIT(3)
349 #define CHGTS1_MASK             BIT(4)
350 #define TS2_MASK                BIT(5)
351 #define CHG_CVTLIM_MASK         BIT(6)
352 #define DISCHG_ILIM_MASK        BIT(7)
353
354 #define PLUG_IN_DISABLE         BIT(0)
355 #define PLUG_OUT_DISABLE        BIT(1)
356 #define CHGOK_DISABLE           BIT(2)
357 #define CHGTE_DISABLE           BIT(3)
358 #define CHGTS1_DISABLE          BIT(4)
359 #define TS2_DISABLE             BIT(5)
360 #define CHG_CVTLIM_DISABLE      BIT(6)
361 #define DISCHG_ILIM_DISABLE     BIT(7)
362
363 #define PLUG_IN_ENABLE          BIT(0)
364 #define PLUG_OUT_ENABLE         BIT(1)
365 #define CHGOK_ENABLE            BIT(2)
366 #define CHGTE_ENABLE            BIT(3)
367 #define CHGTS1_ENABLE           BIT(4)
368 #define TS2_ENABLE              BIT(5)
369 #define CHG_CVTLIM_ENABLE       BIT(6)
370 #define DISCHG_ILIM_ENABLE      BIT(7)
371
372 enum {
373         BUCK_ILMIN_50MA,
374         BUCK_ILMIN_100MA,
375         BUCK_ILMIN_150MA,
376         BUCK_ILMIN_200MA,
377         BUCK_ILMIN_250MA,
378         BUCK_ILMIN_300MA,
379         BUCK_ILMIN_350MA,
380         BUCK_ILMIN_400MA,
381 };
382
383 enum {
384         BOOST_ILMIN_75MA,
385         BOOST_ILMIN_100MA,
386         BOOST_ILMIN_125MA,
387         BOOST_ILMIN_150MA,
388         BOOST_ILMIN_175MA,
389         BOOST_ILMIN_200MA,
390         BOOST_ILMIN_225MA,
391         BOOST_ILMIN_250MA,
392 };
393
394 struct rk808 {
395         struct i2c_client *i2c;
396         struct regmap_irq_chip_data *irq_data;
397         struct regmap *regmap;
398 };
399 #endif /* __LINUX_REGULATOR_rk808_H */