1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Driver for Realtek PCI-Express card reader
3 *
4 * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
5 *
6 * Author:
7 * Wei WANG <wei_wang@realsil.com.cn>
8 */
9
10 #ifndef __RTSX_PCI_H
11 #define __RTSX_PCI_H
12
13 #include <linux/sched.h>
14 #include <linux/pci.h>
15 #include <linux/rtsx_common.h>
16
17 #define MAX_RW_REG_CNT 1024
18
19 #define RTSX_HCBAR 0x00
20 #define RTSX_HCBCTLR 0x04
21 #define STOP_CMD (0x01 << 28)
22 #define READ_REG_CMD 0
23 #define WRITE_REG_CMD 1
24 #define CHECK_REG_CMD 2
25
26 #define RTSX_HDBAR 0x08
27 #define RTSX_SG_INT 0x04
28 #define RTSX_SG_END 0x02
29 #define RTSX_SG_VALID 0x01
30 #define RTSX_SG_NO_OP 0x00
31 #define RTSX_SG_TRANS_DATA (0x02 << 4)
32 #define RTSX_SG_LINK_DESC (0x03 << 4)
33 #define RTSX_HDBCTLR 0x0C
34 #define SDMA_MODE 0x00
35 #define ADMA_MODE (0x02 << 26)
36 #define STOP_DMA (0x01 << 28)
37 #define TRIG_DMA (0x01 << 31)
38
39 #define RTSX_HAIMR 0x10
40 #define HAIMR_TRANS_START (0x01 << 31)
41 #define HAIMR_READ 0x00
42 #define HAIMR_WRITE (0x01 << 30)
43 #define HAIMR_READ_START (HAIMR_TRANS_START | HAIMR_READ)
44 #define HAIMR_WRITE_START (HAIMR_TRANS_START | HAIMR_WRITE)
45 #define HAIMR_TRANS_END (HAIMR_TRANS_START)
46
47 #define RTSX_BIPR 0x14
48 #define CMD_DONE_INT (1 << 31)
49 #define DATA_DONE_INT (1 << 30)
50 #define TRANS_OK_INT (1 << 29)
51 #define TRANS_FAIL_INT (1 << 28)
52 #define XD_INT (1 << 27)
53 #define MS_INT (1 << 26)
54 #define SD_INT (1 << 25)
55 #define GPIO0_INT (1 << 24)
56 #define OC_INT (1 << 23)
57 #define SD_WRITE_PROTECT (1 << 19)
58 #define XD_EXIST (1 << 18)
59 #define MS_EXIST (1 << 17)
60 #define SD_EXIST (1 << 16)
61 #define DELINK_INT GPIO0_INT
62 #define MS_OC_INT (1 << 23)
63 #define SD_OC_INT (1 << 22)
64
65 #define CARD_INT (XD_INT | MS_INT | SD_INT)
66 #define NEED_COMPLETE_INT (DATA_DONE_INT | TRANS_OK_INT | TRANS_FAIL_INT)
67 #define RTSX_INT (CMD_DONE_INT | NEED_COMPLETE_INT | \
68 CARD_INT | GPIO0_INT | OC_INT)
69 #define CARD_EXIST (XD_EXIST | MS_EXIST | SD_EXIST)
70
71 #define RTSX_BIER 0x18
72 #define CMD_DONE_INT_EN (1 << 31)
73 #define DATA_DONE_INT_EN (1 << 30)
74 #define TRANS_OK_INT_EN (1 << 29)
75 #define TRANS_FAIL_INT_EN (1 << 28)
76 #define XD_INT_EN (1 << 27)
77 #define MS_INT_EN (1 << 26)
78 #define SD_INT_EN (1 << 25)
79 #define GPIO0_INT_EN (1 << 24)
80 #define OC_INT_EN (1 << 23)
81 #define DELINK_INT_EN GPIO0_INT_EN
82 #define MS_OC_INT_EN (1 << 23)
83 #define SD_OC_INT_EN (1 << 22)
84
85
86 /*
87 * macros for easy use
88 */
89 #define rtsx_pci_writel(pcr, reg, value) \
90 iowrite32(value, (pcr)->remap_addr + reg)
91 #define rtsx_pci_readl(pcr, reg) \
92 ioread32((pcr)->remap_addr + reg)
93 #define rtsx_pci_writew(pcr, reg, value) \
94 iowrite16(value, (pcr)->remap_addr + reg)
95 #define rtsx_pci_readw(pcr, reg) \
96 ioread16((pcr)->remap_addr + reg)
97 #define rtsx_pci_writeb(pcr, reg, value) \
98 iowrite8(value, (pcr)->remap_addr + reg)
99 #define rtsx_pci_readb(pcr, reg) \
100 ioread8((pcr)->remap_addr + reg)
101
102 #define STATE_TRANS_NONE 0
103 #define STATE_TRANS_CMD 1
104 #define STATE_TRANS_BUF 2
105 #define STATE_TRANS_SG 3
106
107 #define TRANS_NOT_READY 0
108 #define TRANS_RESULT_OK 1
109 #define TRANS_RESULT_FAIL 2
110 #define TRANS_NO_DEVICE 3
111
112 #define RTSX_RESV_BUF_LEN 4096
113 #define HOST_CMDS_BUF_LEN 1024
114 #define HOST_SG_TBL_BUF_LEN (RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
115 #define HOST_SG_TBL_ITEMS (HOST_SG_TBL_BUF_LEN / 8)
116 #define MAX_SG_ITEM_LEN 0x80000
117 #define HOST_TO_DEVICE 0
118 #define DEVICE_TO_HOST 1
119
120 #define OUTPUT_3V3 0
121 #define OUTPUT_1V8 1
122
123 #define RTSX_PHASE_MAX 32
124 #define RX_TUNING_CNT 3
125
126 #define MS_CFG 0xFD40
127 #define SAMPLE_TIME_RISING 0x00
128 #define SAMPLE_TIME_FALLING 0x80
129 #define PUSH_TIME_DEFAULT 0x00
130 #define PUSH_TIME_ODD 0x40
131 #define NO_EXTEND_TOGGLE 0x00
132 #define EXTEND_TOGGLE_CHK 0x20
133 #define MS_BUS_WIDTH_1 0x00
134 #define MS_BUS_WIDTH_4 0x10
135 #define MS_BUS_WIDTH_8 0x18
136 #define MS_2K_SECTOR_MODE 0x04
137 #define MS_512_SECTOR_MODE 0x00
138 #define MS_TOGGLE_TIMEOUT_EN 0x00
139 #define MS_TOGGLE_TIMEOUT_DISEN 0x01
140 #define MS_NO_CHECK_INT 0x02
141 #define MS_TPC 0xFD41
142 #define MS_TRANS_CFG 0xFD42
143 #define WAIT_INT 0x80
144 #define NO_WAIT_INT 0x00
145 #define NO_AUTO_READ_INT_REG 0x00
146 #define AUTO_READ_INT_REG 0x40
147 #define MS_CRC16_ERR 0x20
148 #define MS_RDY_TIMEOUT 0x10
149 #define MS_INT_CMDNK 0x08
150 #define MS_INT_BREQ 0x04
151 #define MS_INT_ERR 0x02
152 #define MS_INT_CED 0x01
153 #define MS_TRANSFER 0xFD43
154 #define MS_TRANSFER_START 0x80
155 #define MS_TRANSFER_END 0x40
156 #define MS_TRANSFER_ERR 0x20
157 #define MS_BS_STATE 0x10
158 #define MS_TM_READ_BYTES 0x00
159 #define MS_TM_NORMAL_READ 0x01
160 #define MS_TM_WRITE_BYTES 0x04
161 #define MS_TM_NORMAL_WRITE 0x05
162 #define MS_TM_AUTO_READ 0x08
163 #define MS_TM_AUTO_WRITE 0x0C
164 #define MS_INT_REG 0xFD44
165 #define MS_BYTE_CNT 0xFD45
166 #define MS_SECTOR_CNT_L 0xFD46
167 #define MS_SECTOR_CNT_H 0xFD47
168 #define MS_DBUS_H 0xFD48
169
170 #define SD_CFG1 0xFDA0
171 #define SD_CLK_DIVIDE_0 0x00
172 #define SD_CLK_DIVIDE_256 0xC0
173 #define SD_CLK_DIVIDE_128 0x80
174 #define SD_BUS_WIDTH_1BIT 0x00
175 #define SD_BUS_WIDTH_4BIT 0x01
176 #define SD_BUS_WIDTH_8BIT 0x02
177 #define SD_ASYNC_FIFO_NOT_RST 0x10
178 #define SD_20_MODE 0x00
179 #define SD_DDR_MODE 0x04
180 #define SD_30_MODE 0x08
181 #define SD_CLK_DIVIDE_MASK 0xC0
182 #define SD_MODE_SELECT_MASK 0x0C
183 #define SD_CFG2 0xFDA1
184 #define SD_CALCULATE_CRC7 0x00
185 #define SD_NO_CALCULATE_CRC7 0x80
186 #define SD_CHECK_CRC16 0x00
187 #define SD_NO_CHECK_CRC16 0x40
188 #define SD_NO_CHECK_WAIT_CRC_TO 0x20
189 #define SD_WAIT_BUSY_END 0x08
190 #define SD_NO_WAIT_BUSY_END 0x00
191 #define SD_CHECK_CRC7 0x00
192 #define SD_NO_CHECK_CRC7 0x04
193 #define SD_RSP_LEN_0 0x00
194 #define SD_RSP_LEN_6 0x01
195 #define SD_RSP_LEN_17 0x02
196 #define SD_RSP_TYPE_R0 0x04
197 #define SD_RSP_TYPE_R1 0x01
198 #define SD_RSP_TYPE_R1b 0x09
199 #define SD_RSP_TYPE_R2 0x02
200 #define SD_RSP_TYPE_R3 0x05
201 #define SD_RSP_TYPE_R4 0x05
202 #define SD_RSP_TYPE_R5 0x01
203 #define SD_RSP_TYPE_R6 0x01
204 #define SD_RSP_TYPE_R7 0x01
205 #define SD_CFG3 0xFDA2
206 #define SD30_CLK_END_EN 0x10
207 #define SD_RSP_80CLK_TIMEOUT_EN 0x01
208
209 #define SD_STAT1 0xFDA3
210 #define SD_CRC7_ERR 0x80
211 #define SD_CRC16_ERR 0x40
212 #define SD_CRC_WRITE_ERR 0x20
213 #define SD_CRC_WRITE_ERR_MASK 0x1C
214 #define GET_CRC_TIME_OUT 0x02
215 #define SD_TUNING_COMPARE_ERR 0x01
216 #define SD_STAT2 0xFDA4
217 #define SD_RSP_80CLK_TIMEOUT 0x01
218
219 #define SD_BUS_STAT 0xFDA5
220 #define SD_CLK_TOGGLE_EN 0x80
221 #define SD_CLK_FORCE_STOP 0x40
222 #define SD_DAT3_STATUS 0x10
223 #define SD_DAT2_STATUS 0x08
224 #define SD_DAT1_STATUS 0x04
225 #define SD_DAT0_STATUS 0x02
226 #define SD_CMD_STATUS 0x01
227 #define SD_PAD_CTL 0xFDA6
228 #define SD_IO_USING_1V8 0x80
229 #define SD_IO_USING_3V3 0x7F
230 #define TYPE_A_DRIVING 0x00
231 #define TYPE_B_DRIVING 0x01
232 #define TYPE_C_DRIVING 0x02
233 #define TYPE_D_DRIVING 0x03
234 #define SD_SAMPLE_POINT_CTL 0xFDA7
235 #define DDR_FIX_RX_DAT 0x00
236 #define DDR_VAR_RX_DAT 0x80
237 #define DDR_FIX_RX_DAT_EDGE 0x00
238 #define DDR_FIX_RX_DAT_14_DELAY 0x40
239 #define DDR_FIX_RX_CMD 0x00
240 #define DDR_VAR_RX_CMD 0x20
241 #define DDR_FIX_RX_CMD_POS_EDGE 0x00
242 #define DDR_FIX_RX_CMD_14_DELAY 0x10
243 #define SD20_RX_POS_EDGE 0x00
244 #define SD20_RX_14_DELAY 0x08
245 #define SD20_RX_SEL_MASK 0x08
246 #define SD_PUSH_POINT_CTL 0xFDA8
247 #define DDR_FIX_TX_CMD_DAT 0x00
248 #define DDR_VAR_TX_CMD_DAT 0x80
249 #define DDR_FIX_TX_DAT_14_TSU 0x00
250 #define DDR_FIX_TX_DAT_12_TSU 0x40
251 #define DDR_FIX_TX_CMD_NEG_EDGE 0x00
252 #define DDR_FIX_TX_CMD_14_AHEAD 0x20
253 #define SD20_TX_NEG_EDGE 0x00
254 #define SD20_TX_14_AHEAD 0x10
255 #define SD20_TX_SEL_MASK 0x10
256 #define DDR_VAR_SDCLK_POL_SWAP 0x01
257 #define SD_CMD0 0xFDA9
258 #define SD_CMD_START 0x40
259 #define SD_CMD1 0xFDAA
260 #define SD_CMD2 0xFDAB
261 #define SD_CMD3 0xFDAC
262 #define SD_CMD4 0xFDAD
263 #define SD_CMD5 0xFDAE
264 #define SD_BYTE_CNT_L 0xFDAF
265 #define SD_BYTE_CNT_H 0xFDB0
266 #define SD_BLOCK_CNT_L 0xFDB1
267 #define SD_BLOCK_CNT_H 0xFDB2
268 #define SD_TRANSFER 0xFDB3
269 #define SD_TRANSFER_START 0x80
270 #define SD_TRANSFER_END 0x40
271 #define SD_STAT_IDLE 0x20
272 #define SD_TRANSFER_ERR 0x10
273 #define SD_TM_NORMAL_WRITE 0x00
274 #define SD_TM_AUTO_WRITE_3 0x01
275 #define SD_TM_AUTO_WRITE_4 0x02
276 #define SD_TM_AUTO_READ_3 0x05
277 #define SD_TM_AUTO_READ_4 0x06
278 #define SD_TM_CMD_RSP 0x08
279 #define SD_TM_AUTO_WRITE_1 0x09
280 #define SD_TM_AUTO_WRITE_2 0x0A
281 #define SD_TM_NORMAL_READ 0x0C
282 #define SD_TM_AUTO_READ_1 0x0D
283 #define SD_TM_AUTO_READ_2 0x0E
284 #define SD_TM_AUTO_TUNING 0x0F
285 #define SD_CMD_STATE 0xFDB5
286 #define SD_CMD_IDLE 0x80
287
288 #define SD_DATA_STATE 0xFDB6
289 #define SD_DATA_IDLE 0x80
290 #define REG_SD_STOP_SDCLK_CFG 0xFDB8
291 #define SD30_CLK_STOP_CFG_EN 0x04
292 #define SD30_CLK_STOP_CFG1 0x02
293 #define SD30_CLK_STOP_CFG0 0x01
294 #define REG_PRE_RW_MODE 0xFD70
295 #define EN_INFINITE_MODE 0x01
296 #define REG_CRC_DUMMY_0 0xFD71
297 #define CFG_SD_POW_AUTO_PD (1<<0)
298
299 #define SRCTL 0xFC13
300
301 #define DCM_DRP_CTL 0xFC23
302 #define DCM_RESET 0x08
303 #define DCM_LOCKED 0x04
304 #define DCM_208M 0x00
305 #define DCM_TX 0x01
306 #define DCM_RX 0x02
307 #define DCM_DRP_TRIG 0xFC24
308 #define DRP_START 0x80
309 #define DRP_DONE 0x40
310 #define DCM_DRP_CFG 0xFC25
311 #define DRP_WRITE 0x80
312 #define DRP_READ 0x00
313 #define DCM_WRITE_ADDRESS_50 0x50
314 #define DCM_WRITE_ADDRESS_51 0x51
315 #define DCM_READ_ADDRESS_00 0x00
316 #define DCM_READ_ADDRESS_51 0x51
317 #define DCM_DRP_WR_DATA_L 0xFC26
318 #define DCM_DRP_WR_DATA_H 0xFC27
319 #define DCM_DRP_RD_DATA_L 0xFC28
320 #define DCM_DRP_RD_DATA_H 0xFC29
321 #define SD_VPCLK0_CTL 0xFC2A
322 #define SD_VPCLK1_CTL 0xFC2B
323 #define PHASE_SELECT_MASK 0x1F
324 #define SD_DCMPS0_CTL 0xFC2C
325 #define SD_DCMPS1_CTL 0xFC2D
326 #define SD_VPTX_CTL SD_VPCLK0_CTL
327 #define SD_VPRX_CTL SD_VPCLK1_CTL
328 #define PHASE_CHANGE 0x80
329 #define PHASE_NOT_RESET 0x40
330 #define SD_DCMPS_TX_CTL SD_DCMPS0_CTL
331 #define SD_DCMPS_RX_CTL SD_DCMPS1_CTL
332 #define DCMPS_CHANGE 0x80
333 #define DCMPS_CHANGE_DONE 0x40
334 #define DCMPS_ERROR 0x20
335 #define DCMPS_CURRENT_PHASE 0x1F
336 #define CARD_CLK_SOURCE 0xFC2E
337 #define CRC_FIX_CLK (0x00 << 0)
338 #define CRC_VAR_CLK0 (0x01 << 0)
339 #define CRC_VAR_CLK1 (0x02 << 0)
340 #define SD30_FIX_CLK (0x00 << 2)
341 #define SD30_VAR_CLK0 (0x01 << 2)
342 #define SD30_VAR_CLK1 (0x02 << 2)
343 #define SAMPLE_FIX_CLK (0x00 << 4)
344 #define SAMPLE_VAR_CLK0 (0x01 << 4)
345 #define SAMPLE_VAR_CLK1 (0x02 << 4)
346 #define CARD_PWR_CTL 0xFD50
347 #define PMOS_STRG_MASK 0x10
348 #define PMOS_STRG_800mA 0x10
349 #define PMOS_STRG_400mA 0x00
350 #define SD_POWER_OFF 0x03
351 #define SD_PARTIAL_POWER_ON 0x01
352 #define SD_POWER_ON 0x00
353 #define SD_POWER_MASK 0x03
354 #define MS_POWER_OFF 0x0C
355 #define MS_PARTIAL_POWER_ON 0x04
356 #define MS_POWER_ON 0x00
357 #define MS_POWER_MASK 0x0C
358 #define BPP_POWER_OFF 0x0F
359 #define BPP_POWER_5_PERCENT_ON 0x0E
360 #define BPP_POWER_10_PERCENT_ON 0x0C
361 #define BPP_POWER_15_PERCENT_ON 0x08
362 #define BPP_POWER_ON 0x00
363 #define BPP_POWER_MASK 0x0F
364 #define SD_VCC_PARTIAL_POWER_ON 0x02
365 #define SD_VCC_POWER_ON 0x00
366 #define CARD_CLK_SWITCH 0xFD51
367 #define RTL8411B_PACKAGE_MODE 0xFD51
368 #define CARD_SHARE_MODE 0xFD52
369 #define CARD_SHARE_MASK 0x0F
370 #define CARD_SHARE_MULTI_LUN 0x00
371 #define CARD_SHARE_NORMAL 0x00
372 #define CARD_SHARE_48_SD 0x04
373 #define CARD_SHARE_48_MS 0x08
374 #define CARD_SHARE_BAROSSA_SD 0x01
375 #define CARD_SHARE_BAROSSA_MS 0x02
376 #define CARD_DRIVE_SEL 0xFD53
377 #define MS_DRIVE_8mA (0x01 << 6)
378 #define MMC_DRIVE_8mA (0x01 << 4)
379 #define XD_DRIVE_8mA (0x01 << 2)
380 #define GPIO_DRIVE_8mA 0x01
381 #define RTS5209_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
382 XD_DRIVE_8mA | GPIO_DRIVE_8mA)
383 #define RTL8411_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
384 XD_DRIVE_8mA)
385 #define RTSX_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | GPIO_DRIVE_8mA)
386
387 #define CARD_STOP 0xFD54
388 #define SPI_STOP 0x01
389 #define XD_STOP 0x02
390 #define SD_STOP 0x04
391 #define MS_STOP 0x08
392 #define SPI_CLR_ERR 0x10
393 #define XD_CLR_ERR 0x20
394 #define SD_CLR_ERR 0x40
395 #define MS_CLR_ERR 0x80
396 #define CARD_OE 0xFD55
397 #define SD_OUTPUT_EN 0x04
398 #define MS_OUTPUT_EN 0x08
399 #define CARD_AUTO_BLINK 0xFD56
400 #define CARD_GPIO_DIR 0xFD57
401 #define CARD_GPIO 0xFD58
402 #define CARD_DATA_SOURCE 0xFD5B
403 #define PINGPONG_BUFFER 0x01
404 #define RING_BUFFER 0x00
405 #define SD30_CLK_DRIVE_SEL 0xFD5A
406 #define DRIVER_TYPE_A 0x05
407 #define DRIVER_TYPE_B 0x03
408 #define DRIVER_TYPE_C 0x02
409 #define DRIVER_TYPE_D 0x01
410 #define CARD_SELECT 0xFD5C
411 #define SD_MOD_SEL 2
412 #define MS_MOD_SEL 3
413 #define SD30_DRIVE_SEL 0xFD5E
414 #define CFG_DRIVER_TYPE_A 0x02
415 #define CFG_DRIVER_TYPE_B 0x03
416 #define CFG_DRIVER_TYPE_C 0x01
417 #define CFG_DRIVER_TYPE_D 0x00
418 #define SD30_CMD_DRIVE_SEL 0xFD5E
419 #define SD30_DAT_DRIVE_SEL 0xFD5F
420 #define CARD_CLK_EN 0xFD69
421 #define SD_CLK_EN 0x04
422 #define MS_CLK_EN 0x08
423 #define SD40_CLK_EN 0x10
424 #define SDIO_CTRL 0xFD6B
425 #define CD_PAD_CTL 0xFD73
426 #define CD_DISABLE_MASK 0x07
427 #define MS_CD_DISABLE 0x04
428 #define SD_CD_DISABLE 0x02
429 #define XD_CD_DISABLE 0x01
430 #define CD_DISABLE 0x07
431 #define CD_ENABLE 0x00
432 #define MS_CD_EN_ONLY 0x03
433 #define SD_CD_EN_ONLY 0x05
434 #define XD_CD_EN_ONLY 0x06
435 #define FORCE_CD_LOW_MASK 0x38
436 #define FORCE_CD_XD_LOW 0x08
437 #define FORCE_CD_SD_LOW 0x10
438 #define FORCE_CD_MS_LOW 0x20
439 #define CD_AUTO_DISABLE 0x40
440 #define FPDCTL 0xFC00
441 #define SSC_POWER_DOWN 0x01
442 #define SD_OC_POWER_DOWN 0x02
443 #define ALL_POWER_DOWN 0x03
444 #define OC_POWER_DOWN 0x02
445 #define PDINFO 0xFC01
446
447 #define CLK_CTL 0xFC02
448 #define CHANGE_CLK 0x01
449 #define CLK_LOW_FREQ 0x01
450
451 #define CLK_DIV 0xFC03
452 #define CLK_DIV_1 0x01
453 #define CLK_DIV_2 0x02
454 #define CLK_DIV_4 0x03
455 #define CLK_DIV_8 0x04
456 #define CLK_SEL 0xFC04
457
458 #define SSC_DIV_N_0 0xFC0F
459 #define SSC_DIV_N_1 0xFC10
460 #define SSC_CTL1 0xFC11
461 #define SSC_RSTB 0x80
462 #define SSC_8X_EN 0x40
463 #define SSC_FIX_FRAC 0x20
464 #define SSC_SEL_1M 0x00
465 #define SSC_SEL_2M 0x08
466 #define SSC_SEL_4M 0x10
467 #define SSC_SEL_8M 0x18
468 #define SSC_CTL2 0xFC12
469 #define SSC_DEPTH_MASK 0x07
470 #define SSC_DEPTH_DISALBE 0x00
471 #define SSC_DEPTH_4M 0x01
472 #define SSC_DEPTH_2M 0x02
473 #define SSC_DEPTH_1M 0x03
474 #define SSC_DEPTH_500K 0x04
475 #define SSC_DEPTH_250K 0x05
476 #define RCCTL 0xFC14
477
478 #define FPGA_PULL_CTL 0xFC1D
479 #define OLT_LED_CTL 0xFC1E
480 #define LED_SHINE_MASK 0x08
481 #define LED_SHINE_EN 0x08
482 #define LED_SHINE_DISABLE 0x00
483 #define GPIO_CTL 0xFC1F
484
485 #define LDO_CTL 0xFC1E
486 #define BPP_ASIC_1V7 0x00
487 #define BPP_ASIC_1V8 0x01
488 #define BPP_ASIC_1V9 0x02
489 #define BPP_ASIC_2V0 0x03
490 #define BPP_ASIC_2V7 0x04
491 #define BPP_ASIC_2V8 0x05
492 #define BPP_ASIC_3V2 0x06
493 #define BPP_ASIC_3V3 0x07
494 #define BPP_REG_TUNED18 0x07
495 #define BPP_TUNED18_SHIFT_8402 5
496 #define BPP_TUNED18_SHIFT_8411 4
497 #define BPP_PAD_MASK 0x04
498 #define BPP_PAD_3V3 0x04
499 #define BPP_PAD_1V8 0x00
500 #define BPP_LDO_POWB 0x03
501 #define BPP_LDO_ON 0x00
502 #define BPP_LDO_SUSPEND 0x02
503 #define BPP_LDO_OFF 0x03
504 #define EFUSE_CTL 0xFC30
505 #define EFUSE_ADD 0xFC31
506 #define SYS_VER 0xFC32
507 #define EFUSE_DATAL 0xFC34
508 #define EFUSE_DATAH 0xFC35
509
510 #define CARD_PULL_CTL1 0xFD60
511 #define CARD_PULL_CTL2 0xFD61
512 #define CARD_PULL_CTL3 0xFD62
513 #define CARD_PULL_CTL4 0xFD63
514 #define CARD_PULL_CTL5 0xFD64
515 #define CARD_PULL_CTL6 0xFD65
516
517 /* PCI Express Related Registers */
518 #define IRQEN0 0xFE20
519 #define IRQSTAT0 0xFE21
520 #define DMA_DONE_INT 0x80
521 #define SUSPEND_INT 0x40
522 #define LINK_RDY_INT 0x20
523 #define LINK_DOWN_INT 0x10
524 #define IRQEN1 0xFE22
525 #define IRQSTAT1 0xFE23
526 #define TLPRIEN 0xFE24
527 #define TLPRISTAT 0xFE25
528 #define TLPTIEN 0xFE26
529 #define TLPTISTAT 0xFE27
530 #define DMATC0 0xFE28
531 #define DMATC1 0xFE29
532 #define DMATC2 0xFE2A
533 #define DMATC3 0xFE2B
534 #define DMACTL 0xFE2C
535 #define DMA_RST 0x80
536 #define DMA_BUSY 0x04
537 #define DMA_DIR_TO_CARD 0x00
538 #define DMA_DIR_FROM_CARD 0x02
539 #define DMA_EN 0x01
540 #define DMA_128 (0 << 4)
541 #define DMA_256 (1 << 4)
542 #define DMA_512 (2 << 4)
543 #define DMA_1024 (3 << 4)
544 #define DMA_PACK_SIZE_MASK 0x30
545 #define BCTL 0xFE2D
546 #define RBBC0 0xFE2E
547 #define RBBC1 0xFE2F
548 #define RBDAT 0xFE30
549 #define RBCTL 0xFE34
550 #define U_AUTO_DMA_EN_MASK 0x20
551 #define U_AUTO_DMA_DISABLE 0x00
552 #define RB_FLUSH 0x80
553 #define CFGADDR0 0xFE35
554 #define CFGADDR1 0xFE36
555 #define CFGDATA0 0xFE37
556 #define CFGDATA1 0xFE38
557 #define CFGDATA2 0xFE39
558 #define CFGDATA3 0xFE3A
559 #define CFGRWCTL 0xFE3B
560 #define PHYRWCTL 0xFE3C
561 #define PHYDATA0 0xFE3D
562 #define PHYDATA1 0xFE3E
563 #define PHYADDR 0xFE3F
564 #define MSGRXDATA0 0xFE40
565 #define MSGRXDATA1 0xFE41
566 #define MSGRXDATA2 0xFE42
567 #define MSGRXDATA3 0xFE43
568 #define MSGTXDATA0 0xFE44
569 #define MSGTXDATA1 0xFE45
570 #define MSGTXDATA2 0xFE46
571 #define MSGTXDATA3 0xFE47
572 #define MSGTXCTL 0xFE48
573 #define LTR_CTL 0xFE4A
574 #define LTR_TX_EN_MASK BIT(7)
575 #define LTR_TX_EN_1 BIT(7)
576 #define LTR_TX_EN_0 0
577 #define LTR_LATENCY_MODE_MASK BIT(6)
578 #define LTR_LATENCY_MODE_HW 0
579 #define LTR_LATENCY_MODE_SW BIT(6)
580 #define OBFF_CFG 0xFE4C
581 #define OBFF_EN_MASK 0x03
582 #define OBFF_DISABLE 0x00
583
584 #define CDRESUMECTL 0xFE52
585 #define WAKE_SEL_CTL 0xFE54
586 #define PCLK_CTL 0xFE55
587 #define PCLK_MODE_SEL 0x20
588 #define PME_FORCE_CTL 0xFE56
589
590 #define ASPM_FORCE_CTL 0xFE57
591 #define FORCE_ASPM_CTL0 0x10
592 #define FORCE_ASPM_CTL1 0x20
593 #define FORCE_ASPM_VAL_MASK 0x03
594 #define FORCE_ASPM_L1_EN 0x02
595 #define FORCE_ASPM_L0_EN 0x01
596 #define FORCE_ASPM_NO_ASPM 0x00
597 #define PM_CLK_FORCE_CTL 0xFE58
598 #define CLK_PM_EN 0x01
599 #define FUNC_FORCE_CTL 0xFE59
600 #define FUNC_FORCE_UPME_XMT_DBG 0x02
601 #define PERST_GLITCH_WIDTH 0xFE5C
602 #define CHANGE_LINK_STATE 0xFE5B
603 #define RESET_LOAD_REG 0xFE5E
604 #define EFUSE_CONTENT 0xFE5F
605 #define HOST_SLEEP_STATE 0xFE60
606 #define HOST_ENTER_S1 1
607 #define HOST_ENTER_S3 2
608
609 #define SDIO_CFG 0xFE70
610 #define PM_EVENT_DEBUG 0xFE71
611 #define PME_DEBUG_0 0x08
612 #define NFTS_TX_CTRL 0xFE72
613
614 #define PWR_GATE_CTRL 0xFE75
615 #define PWR_GATE_EN 0x01
616 #define LDO3318_PWR_MASK 0x06
617 #define LDO_ON 0x00
618 #define LDO_SUSPEND 0x04
619 #define LDO_OFF 0x06
620 #define PWD_SUSPEND_EN 0xFE76
621 #define LDO_PWR_SEL 0xFE78
622
623 #define L1SUB_CONFIG1 0xFE8D
624 #define AUX_CLK_ACTIVE_SEL_MASK 0x01
625 #define MAC_CKSW_DONE 0x00
626 #define L1SUB_CONFIG2 0xFE8E
627 #define L1SUB_AUTO_CFG 0x02
628 #define L1SUB_CONFIG3 0xFE8F
629 #define L1OFF_MBIAS2_EN_5250 BIT(7)
630
631 #define DUMMY_REG_RESET_0 0xFE90
632 #define IC_VERSION_MASK 0x0F
633
634 #define REG_VREF 0xFE97
635 #define PWD_SUSPND_EN 0x10
636 #define RTS5260_DMA_RST_CTL_0 0xFEBF
637 #define RTS5260_DMA_RST 0x80
638 #define RTS5260_ADMA3_RST 0x40
639 #define AUTOLOAD_CFG_BASE 0xFF00
640 #define RELINK_TIME_MASK 0x01
641 #define PETXCFG 0xFF03
642 #define FORCE_CLKREQ_DELINK_MASK BIT(7)
643 #define FORCE_CLKREQ_LOW 0x80
644 #define FORCE_CLKREQ_HIGH 0x00
645
646 #define PM_CTRL1 0xFF44
647 #define CD_RESUME_EN_MASK 0xF0
648
649 #define PM_CTRL2 0xFF45
650 #define PM_CTRL3 0xFF46
651 #define SDIO_SEND_PME_EN 0x80
652 #define FORCE_RC_MODE_ON 0x40
653 #define FORCE_RX50_LINK_ON 0x20
654 #define D3_DELINK_MODE_EN 0x10
655 #define USE_PESRTB_CTL_DELINK 0x08
656 #define DELAY_PIN_WAKE 0x04
657 #define RESET_PIN_WAKE 0x02
658 #define PM_WAKE_EN 0x01
659 #define PM_CTRL4 0xFF47
660
661 #define REG_CFG_OOBS_OFF_TIMER 0xFEA6
662 #define REG_CFG_OOBS_ON_TIMER 0xFEA7
663 #define REG_CFG_VCM_ON_TIMER 0xFEA8
664 #define REG_CFG_OOBS_POLLING 0xFEA9
665
666 /* Memory mapping */
667 #define SRAM_BASE 0xE600
668 #define RBUF_BASE 0xF400
669 #define PPBUF_BASE1 0xF800
670 #define PPBUF_BASE2 0xFA00
671 #define IMAGE_FLAG_ADDR0 0xCE80
672 #define IMAGE_FLAG_ADDR1 0xCE81
673
674 #define RREF_CFG 0xFF6C
675 #define RREF_VBGSEL_MASK 0x38
676 #define RREF_VBGSEL_1V25 0x28
677
678 #define OOBS_CONFIG 0xFF6E
679 #define OOBS_AUTOK_DIS 0x80
680 #define OOBS_VAL_MASK 0x1F
681
682 #define LDO_DV18_CFG 0xFF70
683 #define LDO_DV18_SR_MASK 0xC0
684 #define LDO_DV18_SR_DF 0x40
685 #define DV331812_MASK 0x70
686 #define DV331812_33 0x70
687 #define DV331812_17 0x30
688
689 #define LDO_CONFIG2 0xFF71
690 #define LDO_D3318_MASK 0x07
691 #define LDO_D3318_33V 0x07
692 #define LDO_D3318_18V 0x02
693 #define DV331812_VDD1 0x04
694 #define DV331812_POWERON 0x08
695 #define DV331812_POWEROFF 0x00
696
697 #define LDO_VCC_CFG0 0xFF72
698 #define LDO_VCC_LMTVTH_MASK 0x30
699 #define LDO_VCC_LMTVTH_2A 0x10
700 /*RTS5260*/
701 #define RTS5260_DVCC_TUNE_MASK 0x70
702 #define RTS5260_DVCC_33 0x70
703
704 #define LDO_VCC_CFG1 0xFF73
705 #define LDO_VCC_REF_TUNE_MASK 0x30
706 #define LDO_VCC_REF_1V2 0x20
707 #define LDO_VCC_TUNE_MASK 0x07
708 #define LDO_VCC_1V8 0x04
709 #define LDO_VCC_3V3 0x07
710 #define LDO_VCC_LMT_EN 0x08
711 /*RTS5260*/
712 #define LDO_POW_SDVDD1_MASK 0x08
713 #define LDO_POW_SDVDD1_ON 0x08
714 #define LDO_POW_SDVDD1_OFF 0x00
715
716 #define LDO_VIO_CFG 0xFF75
717 #define LDO_VIO_SR_MASK 0xC0
718 #define LDO_VIO_SR_DF 0x40
719 #define LDO_VIO_REF_TUNE_MASK 0x30
720 #define LDO_VIO_REF_1V2 0x20
721 #define LDO_VIO_TUNE_MASK 0x07
722 #define LDO_VIO_1V7 0x03
723 #define LDO_VIO_1V8 0x04
724 #define LDO_VIO_3V3 0x07
725
726 #define LDO_DV12S_CFG 0xFF76
727 #define LDO_REF12_TUNE_MASK 0x18
728 #define LDO_REF12_TUNE_DF 0x10
729 #define LDO_D12_TUNE_MASK 0x07
730 #define LDO_D12_TUNE_DF 0x04
731
732 #define LDO_AV12S_CFG 0xFF77
733 #define LDO_AV12S_TUNE_MASK 0x07
734 #define LDO_AV12S_TUNE_DF 0x04
735
736 #define SD40_LDO_CTL1 0xFE7D
737 #define SD40_VIO_TUNE_MASK 0x70
738 #define SD40_VIO_TUNE_1V7 0x30
739 #define SD_VIO_LDO_1V8 0x40
740 #define SD_VIO_LDO_3V3 0x70
741
742 #define RTS5260_AUTOLOAD_CFG4 0xFF7F
743 #define RTS5260_MIMO_DISABLE 0x8A
744
745 #define RTS5260_REG_GPIO_CTL0 0xFC1A
746 #define RTS5260_REG_GPIO_MASK 0x01
747 #define RTS5260_REG_GPIO_ON 0x01
748 #define RTS5260_REG_GPIO_OFF 0x00
749
750 #define PWR_GLOBAL_CTRL 0xF200
751 #define PCIE_L1_2_EN 0x0C
752 #define PCIE_L1_1_EN 0x0A
753 #define PCIE_L1_0_EN 0x09
754 #define PWR_FE_CTL 0xF201
755 #define PCIE_L1_2_PD_FE_EN 0x0C
756 #define PCIE_L1_1_PD_FE_EN 0x0A
757 #define PCIE_L1_0_PD_FE_EN 0x09
758 #define CFG_PCIE_APHY_OFF_0 0xF204
759 #define CFG_PCIE_APHY_OFF_0_DEFAULT 0xBF
760 #define CFG_PCIE_APHY_OFF_1 0xF205
761 #define CFG_PCIE_APHY_OFF_1_DEFAULT 0xFF
762 #define CFG_PCIE_APHY_OFF_2 0xF206
763 #define CFG_PCIE_APHY_OFF_2_DEFAULT 0x01
764 #define CFG_PCIE_APHY_OFF_3 0xF207
765 #define CFG_PCIE_APHY_OFF_3_DEFAULT 0x00
766 #define CFG_L1_0_PCIE_MAC_RET_VALUE 0xF20C
767 #define CFG_L1_0_PCIE_DPHY_RET_VALUE 0xF20E
768 #define CFG_L1_0_SYS_RET_VALUE 0xF210
769 #define CFG_L1_0_CRC_MISC_RET_VALUE 0xF212
770 #define CFG_L1_0_CRC_SD30_RET_VALUE 0xF214
771 #define CFG_L1_0_CRC_SD40_RET_VALUE 0xF216
772 #define CFG_LP_FPWM_VALUE 0xF219
773 #define CFG_LP_FPWM_VALUE_DEFAULT 0x18
774 #define PWC_CDR 0xF253
775 #define PWC_CDR_DEFAULT 0x03
776 #define CFG_L1_0_RET_VALUE_DEFAULT 0x1B
777 #define CFG_L1_0_CRC_MISC_RET_VALUE_DEFAULT 0x0C
778
779 /* OCPCTL */
780 #define SD_DETECT_EN 0x08
781 #define SD_OCP_INT_EN 0x04
782 #define SD_OCP_INT_CLR 0x02
783 #define SD_OC_CLR 0x01
784
785 #define SDVIO_DETECT_EN (1 << 7)
786 #define SDVIO_OCP_INT_EN (1 << 6)
787 #define SDVIO_OCP_INT_CLR (1 << 5)
788 #define SDVIO_OC_CLR (1 << 4)
789
790 /* OCPSTAT */
791 #define SD_OCP_DETECT 0x08
792 #define SD_OC_NOW 0x04
793 #define SD_OC_EVER 0x02
794
795 #define SDVIO_OC_NOW (1 << 6)
796 #define SDVIO_OC_EVER (1 << 5)
797
798 #define REG_OCPCTL 0xFD6A
799 #define REG_OCPSTAT 0xFD6E
800 #define REG_OCPGLITCH 0xFD6C
801 #define REG_OCPPARA1 0xFD6B
802 #define REG_OCPPARA2 0xFD6D
803
804 /* rts5260 DV3318 OCP-related registers */
805 #define REG_DV3318_OCPCTL 0xFD89
806 #define DV3318_OCP_TIME_MASK 0xF0
807 #define DV3318_DETECT_EN 0x08
808 #define DV3318_OCP_INT_EN 0x04
809 #define DV3318_OCP_INT_CLR 0x02
810 #define DV3318_OCP_CLR 0x01
811
812 #define REG_DV3318_OCPSTAT 0xFD8A
813 #define DV3318_OCP_GlITCH_TIME_MASK 0xF0
814 #define DV3318_OCP_DETECT 0x08
815 #define DV3318_OCP_NOW 0x04
816 #define DV3318_OCP_EVER 0x02
817
818 #define SD_OCP_GLITCH_MASK 0x0F
819
820 /* OCPPARA1 */
821 #define SDVIO_OCP_TIME_60 0x00
822 #define SDVIO_OCP_TIME_100 0x10
823 #define SDVIO_OCP_TIME_200 0x20
824 #define SDVIO_OCP_TIME_400 0x30
825 #define SDVIO_OCP_TIME_600 0x40
826 #define SDVIO_OCP_TIME_800 0x50
827 #define SDVIO_OCP_TIME_1100 0x60
828 #define SDVIO_OCP_TIME_MASK 0x70
829
830 #define SD_OCP_TIME_60 0x00
831 #define SD_OCP_TIME_100 0x01
832 #define SD_OCP_TIME_200 0x02
833 #define SD_OCP_TIME_400 0x03
834 #define SD_OCP_TIME_600 0x04
835 #define SD_OCP_TIME_800 0x05
836 #define SD_OCP_TIME_1100 0x06
837 #define SD_OCP_TIME_MASK 0x07
838
839 /* OCPPARA2 */
840 #define SDVIO_OCP_THD_190 0x00
841 #define SDVIO_OCP_THD_250 0x10
842 #define SDVIO_OCP_THD_320 0x20
843 #define SDVIO_OCP_THD_380 0x30
844 #define SDVIO_OCP_THD_440 0x40
845 #define SDVIO_OCP_THD_500 0x50
846 #define SDVIO_OCP_THD_570 0x60
847 #define SDVIO_OCP_THD_630 0x70
848 #define SDVIO_OCP_THD_MASK 0x70
849
850 #define SD_OCP_THD_450 0x00
851 #define SD_OCP_THD_550 0x01
852 #define SD_OCP_THD_650 0x02
853 #define SD_OCP_THD_750 0x03
854 #define SD_OCP_THD_850 0x04
855 #define SD_OCP_THD_950 0x05
856 #define SD_OCP_THD_1050 0x06
857 #define SD_OCP_THD_1150 0x07
858 #define SD_OCP_THD_MASK 0x07
859
860 #define SDVIO_OCP_GLITCH_MASK 0xF0
861 #define SDVIO_OCP_GLITCH_NONE 0x00
862 #define SDVIO_OCP_GLITCH_50U 0x10
863 #define SDVIO_OCP_GLITCH_100U 0x20
864 #define SDVIO_OCP_GLITCH_200U 0x30
865 #define SDVIO_OCP_GLITCH_600U 0x40
866 #define SDVIO_OCP_GLITCH_800U 0x50
867 #define SDVIO_OCP_GLITCH_1M 0x60
868 #define SDVIO_OCP_GLITCH_2M 0x70
869 #define SDVIO_OCP_GLITCH_3M 0x80
870 #define SDVIO_OCP_GLITCH_4M 0x90
871 #define SDVIO_OCP_GLIVCH_5M 0xA0
872 #define SDVIO_OCP_GLITCH_6M 0xB0
873 #define SDVIO_OCP_GLITCH_7M 0xC0
874 #define SDVIO_OCP_GLITCH_8M 0xD0
875 #define SDVIO_OCP_GLITCH_9M 0xE0
876 #define SDVIO_OCP_GLITCH_10M 0xF0
877
878 #define SD_OCP_GLITCH_MASK 0x0F
879 #define SD_OCP_GLITCH_NONE 0x00
880 #define SD_OCP_GLITCH_50U 0x01
881 #define SD_OCP_GLITCH_100U 0x02
882 #define SD_OCP_GLITCH_200U 0x03
883 #define SD_OCP_GLITCH_600U 0x04
884 #define SD_OCP_GLITCH_800U 0x05
885 #define SD_OCP_GLITCH_1M 0x06
886 #define SD_OCP_GLITCH_2M 0x07
887 #define SD_OCP_GLITCH_3M 0x08
888 #define SD_OCP_GLITCH_4M 0x09
889 #define SD_OCP_GLIVCH_5M 0x0A
890 #define SD_OCP_GLITCH_6M 0x0B
891 #define SD_OCP_GLITCH_7M 0x0C
892 #define SD_OCP_GLITCH_8M 0x0D
893 #define SD_OCP_GLITCH_9M 0x0E
894 #define SD_OCP_GLITCH_10M 0x0F
895
896 /* Phy register */
897 #define PHY_PCR 0x00
898 #define PHY_PCR_FORCE_CODE 0xB000
899 #define PHY_PCR_OOBS_CALI_50 0x0800
900 #define PHY_PCR_OOBS_VCM_08 0x0200
901 #define PHY_PCR_OOBS_SEN_90 0x0040
902 #define PHY_PCR_RSSI_EN 0x0002
903 #define PHY_PCR_RX10K 0x0001
904
905 #define PHY_RCR0 0x01
906 #define PHY_RCR1 0x02
907 #define PHY_RCR1_ADP_TIME_4 0x0400
908 #define PHY_RCR1_VCO_COARSE 0x001F
909 #define PHY_RCR1_INIT_27S 0x0A1F
910 #define PHY_SSCCR2 0x02
911 #define PHY_SSCCR2_PLL_NCODE 0x0A00
912 #define PHY_SSCCR2_TIME0 0x001C
913 #define PHY_SSCCR2_TIME2_WIDTH 0x0003
914
915 #define PHY_RCR2 0x03
916 #define PHY_RCR2_EMPHASE_EN 0x8000
917 #define PHY_RCR2_NADJR 0x4000
918 #define PHY_RCR2_CDR_SR_2 0x0100
919 #define PHY_RCR2_FREQSEL_12 0x0040
920 #define PHY_RCR2_CDR_SC_12P 0x0010
921 #define PHY_RCR2_CALIB_LATE 0x0002
922 #define PHY_RCR2_INIT_27S 0xC152
923 #define PHY_SSCCR3 0x03
924 #define PHY_SSCCR3_STEP_IN 0x2740
925 #define PHY_SSCCR3_CHECK_DELAY 0x0008
926 #define _PHY_ANA03 0x03
927 #define _PHY_ANA03_TIMER_MAX 0x2700
928 #define _PHY_ANA03_OOBS_DEB_EN 0x0040
929 #define _PHY_CMU_DEBUG_EN 0x0008
930
931 #define PHY_RTCR 0x04
932 #define PHY_RDR 0x05
933 #define PHY_RDR_RXDSEL_1_9 0x4000
934 #define PHY_SSC_AUTO_PWD 0x0600
935 #define PHY_TCR0 0x06
936 #define PHY_TCR1 0x07
937 #define PHY_TUNE 0x08
938 #define PHY_TUNE_TUNEREF_1_0 0x4000
939 #define PHY_TUNE_VBGSEL_1252 0x0C00
940 #define PHY_TUNE_SDBUS_33 0x0200
941 #define PHY_TUNE_TUNED18 0x01C0
942 #define PHY_TUNE_TUNED12 0X0020
943 #define PHY_TUNE_TUNEA12 0x0004
944 #define PHY_TUNE_VOLTAGE_MASK 0xFC3F
945 #define PHY_TUNE_VOLTAGE_3V3 0x03C0
946 #define PHY_TUNE_D18_1V8 0x0100
947 #define PHY_TUNE_D18_1V7 0x0080
948 #define PHY_ANA08 0x08
949 #define PHY_ANA08_RX_EQ_DCGAIN 0x5000
950 #define PHY_ANA08_SEL_RX_EN 0x0400
951 #define PHY_ANA08_RX_EQ_VAL 0x03C0
952 #define PHY_ANA08_SCP 0x0020
953 #define PHY_ANA08_SEL_IPI 0x0004
954
955 #define PHY_IMR 0x09
956 #define PHY_BPCR 0x0A
957 #define PHY_BPCR_IBRXSEL 0x0400
958 #define PHY_BPCR_IBTXSEL 0x0100
959 #define PHY_BPCR_IB_FILTER 0x0080
960 #define PHY_BPCR_CMIRROR_EN 0x0040
961
962 #define PHY_BIST 0x0B
963 #define PHY_RAW_L 0x0C
964 #define PHY_RAW_H 0x0D
965 #define PHY_RAW_DATA 0x0E
966 #define PHY_HOST_CLK_CTRL 0x0F
967 #define PHY_DMR 0x10
968 #define PHY_BACR 0x11
969 #define PHY_BACR_BASIC_MASK 0xFFF3
970 #define PHY_IER 0x12
971 #define PHY_BCSR 0x13
972 #define PHY_BPR 0x14
973 #define PHY_BPNR2 0x15
974 #define PHY_BPNR 0x16
975 #define PHY_BRNR2 0x17
976 #define PHY_BENR 0x18
977 #define PHY_REV 0x19
978 #define PHY_REV_RESV 0xE000
979 #define PHY_REV_RXIDLE_LATCHED 0x1000
980 #define PHY_REV_P1_EN 0x0800
981 #define PHY_REV_RXIDLE_EN 0x0400
982 #define PHY_REV_CLKREQ_TX_EN 0x0200
983 #define PHY_REV_CLKREQ_RX_EN 0x0100
984 #define PHY_REV_CLKREQ_DT_1_0 0x0040
985 #define PHY_REV_STOP_CLKRD 0x0020
986 #define PHY_REV_RX_PWST 0x0008
987 #define PHY_REV_STOP_CLKWR 0x0004
988 #define _PHY_REV0 0x19
989 #define _PHY_REV0_FILTER_OUT 0x3800
990 #define _PHY_REV0_CDR_BYPASS_PFD 0x0100
991 #define _PHY_REV0_CDR_RX_IDLE_BYPASS 0x0002
992
993 #define PHY_FLD0 0x1A
994 #define PHY_ANA1A 0x1A
995 #define PHY_ANA1A_TXR_LOOPBACK 0x2000
996 #define PHY_ANA1A_RXT_BIST 0x0500
997 #define PHY_ANA1A_TXR_BIST 0x0040
998 #define PHY_ANA1A_REV 0x0006
999 #define PHY_FLD0_INIT_27S 0x2546
1000 #define PHY_FLD1 0x1B
1001 #define PHY_FLD2 0x1C
1002 #define PHY_FLD3 0x1D
1003 #define PHY_FLD3_TIMER_4 0x0800
1004 #define PHY_FLD3_TIMER_6 0x0020
1005 #define PHY_FLD3_RXDELINK 0x0004
1006 #define PHY_FLD3_INIT_27S 0x0004
1007 #define PHY_ANA1D 0x1D
1008 #define PHY_ANA1D_DEBUG_ADDR 0x0004
1009 #define _PHY_FLD0 0x1D
1010 #define _PHY_FLD0_CLK_REQ_20C 0x8000
1011 #define _PHY_FLD0_RX_IDLE_EN 0x1000
1012 #define _PHY_FLD0_BIT_ERR_RSTN 0x0800
1013 #define _PHY_FLD0_BER_COUNT 0x01E0
1014 #define _PHY_FLD0_BER_TIMER 0x001E
1015 #define _PHY_FLD0_CHECK_EN 0x0001
1016
1017 #define PHY_FLD4 0x1E
1018 #define PHY_FLD4_FLDEN_SEL 0x4000
1019 #define PHY_FLD4_REQ_REF 0x2000
1020 #define PHY_FLD4_RXAMP_OFF 0x1000
1021 #define PHY_FLD4_REQ_ADDA 0x0800
1022 #define PHY_FLD4_BER_COUNT 0x00E0
1023 #define PHY_FLD4_BER_TIMER 0x000A
1024 #define PHY_FLD4_BER_CHK_EN 0x0001
1025 #define PHY_FLD4_INIT_27S 0x5C7F
1026 #define PHY_DIG1E 0x1E
1027 #define PHY_DIG1E_REV 0x4000
1028 #define PHY_DIG1E_D0_X_D1 0x1000
1029 #define PHY_DIG1E_RX_ON_HOST 0x0800
1030 #define PHY_DIG1E_RCLK_REF_HOST 0x0400
1031 #define PHY_DIG1E_RCLK_TX_EN_KEEP 0x0040
1032 #define PHY_DIG1E_RCLK_TX_TERM_KEEP 0x0020
1033 #define PHY_DIG1E_RCLK_RX_EIDLE_ON 0x0010
1034 #define PHY_DIG1E_TX_TERM_KEEP 0x0008
1035 #define PHY_DIG1E_RX_TERM_KEEP 0x0004
1036 #define PHY_DIG1E_TX_EN_KEEP 0x0002
1037 #define PHY_DIG1E_RX_EN_KEEP 0x0001
1038 #define PHY_DUM_REG 0x1F
1039
1040 #define PCR_SETTING_REG1 0x724
1041 #define PCR_SETTING_REG2 0x814
1042 #define PCR_SETTING_REG3 0x747
1043
1044 #define rtsx_pci_init_cmd(pcr) ((pcr)->ci = 0)
1045
1046 #define RTS5227_DEVICE_ID 0x5227
1047 #define RTS_MAX_TIMES_FREQ_REDUCTION 8
1048
1049 struct rtsx_pcr;
1050
1051 struct pcr_handle {
1052 struct rtsx_pcr *pcr;
1053 };
1054
1055 struct pcr_ops {
1056 int (*write_phy)(struct rtsx_pcr *pcr, u8 addr, u16 val);
1057 int (*read_phy)(struct rtsx_pcr *pcr, u8 addr, u16 *val);
1058 int (*extra_init_hw)(struct rtsx_pcr *pcr);
1059 int (*optimize_phy)(struct rtsx_pcr *pcr);
1060 int (*turn_on_led)(struct rtsx_pcr *pcr);
1061 int (*turn_off_led)(struct rtsx_pcr *pcr);
1062 int (*enable_auto_blink)(struct rtsx_pcr *pcr);
1063 int (*disable_auto_blink)(struct rtsx_pcr *pcr);
1064 int (*card_power_on)(struct rtsx_pcr *pcr, int card);
1065 int (*card_power_off)(struct rtsx_pcr *pcr, int card);
1066 int (*switch_output_voltage)(struct rtsx_pcr *pcr,
1067 u8 voltage);
1068 unsigned int (*cd_deglitch)(struct rtsx_pcr *pcr);
1069 int (*conv_clk_and_div_n)(int clk, int dir);
1070 void (*fetch_vendor_settings)(struct rtsx_pcr *pcr);
1071 void (*force_power_down)(struct rtsx_pcr *pcr, u8 pm_state);
1072 void (*stop_cmd)(struct rtsx_pcr *pcr);
1073
1074 void (*set_aspm)(struct rtsx_pcr *pcr, bool enable);
1075 void (*set_l1off_cfg_sub_d0)(struct rtsx_pcr *pcr, int active);
1076 void (*enable_ocp)(struct rtsx_pcr *pcr);
1077 void (*disable_ocp)(struct rtsx_pcr *pcr);
1078 void (*init_ocp)(struct rtsx_pcr *pcr);
1079 void (*process_ocp)(struct rtsx_pcr *pcr);
1080 int (*get_ocpstat)(struct rtsx_pcr *pcr, u8 *val);
1081 void (*clear_ocpstat)(struct rtsx_pcr *pcr);
1082 };
1083
1084 enum PDEV_STAT {PDEV_STAT_IDLE, PDEV_STAT_RUN};
1085
1086 #define ASPM_L1_1_EN BIT(0)
1087 #define ASPM_L1_2_EN BIT(1)
1088 #define PM_L1_1_EN BIT(2)
1089 #define PM_L1_2_EN BIT(3)
1090 #define LTR_L1SS_PWR_GATE_EN BIT(4)
1091 #define L1_SNOOZE_TEST_EN BIT(5)
1092 #define LTR_L1SS_PWR_GATE_CHECK_CARD_EN BIT(6)
1093
1094 /*
1095 * struct rtsx_cr_option - card reader option
1096 * @dev_flags: device flags
1097 * @force_clkreq_0: force clock request
1098 * @ltr_en: enable ltr mode flag
1099 * @ltr_enabled: ltr mode in configure space flag
1100 * @ltr_active: ltr mode status
1101 * @ltr_active_latency: ltr mode active latency
1102 * @ltr_idle_latency: ltr mode idle latency
1103 * @ltr_l1off_latency: ltr mode l1off latency
1104 * @l1_snooze_delay: l1 snooze delay
1105 * @ltr_l1off_sspwrgate: ltr l1off sspwrgate
1106 * @ltr_l1off_snooze_sspwrgate: ltr l1off snooze sspwrgate
1107 * @ocp_en: enable ocp flag
1108 * @sd_400mA_ocp_thd: 400mA ocp thd
1109 * @sd_800mA_ocp_thd: 800mA ocp thd
1110 */
1111 struct rtsx_cr_option {
1112 u32 dev_flags;
1113 bool force_clkreq_0;
1114 bool ltr_en;
1115 bool ltr_enabled;
1116 bool ltr_active;
1117 u32 ltr_active_latency;
1118 u32 ltr_idle_latency;
1119 u32 ltr_l1off_latency;
1120 u32 l1_snooze_delay;
1121 u8 ltr_l1off_sspwrgate;
1122 u8 ltr_l1off_snooze_sspwrgate;
1123 bool ocp_en;
1124 u8 sd_400mA_ocp_thd;
1125 u8 sd_800mA_ocp_thd;
1126 };
1127
1128 /*
1129 * struct rtsx_hw_param - card reader hardware param
1130 * @interrupt_en: indicate which interrutp enable
1131 * @ocp_glitch: ocp glitch time
1132 */
1133 struct rtsx_hw_param {
1134 u32 interrupt_en;
1135 u8 ocp_glitch;
1136 };
1137
1138 #define rtsx_set_dev_flag(cr, flag) \
1139 ((cr)->option.dev_flags |= (flag))
1140 #define rtsx_clear_dev_flag(cr, flag) \
1141 ((cr)->option.dev_flags &= ~(flag))
1142 #define rtsx_check_dev_flag(cr, flag) \
1143 ((cr)->option.dev_flags & (flag))
1144
1145 struct rtsx_pcr {
1146 struct pci_dev *pci;
1147 unsigned int id;
1148 struct rtsx_cr_option option;
1149 struct rtsx_hw_param hw_param;
1150
1151 /* pci resources */
1152 unsigned long addr;
1153 void __iomem *remap_addr;
1154 int irq;
1155
1156 /* host reserved buffer */
1157 void *rtsx_resv_buf;
1158 dma_addr_t rtsx_resv_buf_addr;
1159
1160 void *host_cmds_ptr;
1161 dma_addr_t host_cmds_addr;
1162 int ci;
1163
1164 void *host_sg_tbl_ptr;
1165 dma_addr_t host_sg_tbl_addr;
1166 int sgi;
1167
1168 u32 bier;
1169 char trans_result;
1170
1171 unsigned int card_inserted;
1172 unsigned int card_removed;
1173 unsigned int card_exist;
1174
1175 struct delayed_work carddet_work;
1176 struct delayed_work idle_work;
1177
1178 spinlock_t lock;
1179 struct mutex pcr_mutex;
1180 struct completion *done;
1181 struct completion *finish_me;
1182
1183 unsigned int cur_clock;
1184 bool remove_pci;
1185 bool msi_en;
1186
1187 #define EXTRA_CAPS_SD_SDR50 (1 << 0)
1188 #define EXTRA_CAPS_SD_SDR104 (1 << 1)
1189 #define EXTRA_CAPS_SD_DDR50 (1 << 2)
1190 #define EXTRA_CAPS_MMC_HSDDR (1 << 3)
1191 #define EXTRA_CAPS_MMC_HS200 (1 << 4)
1192 #define EXTRA_CAPS_MMC_8BIT (1 << 5)
1193 #define EXTRA_CAPS_NO_MMC (1 << 7)
1194 u32 extra_caps;
1195
1196 #define IC_VER_A 0
1197 #define IC_VER_B 1
1198 #define IC_VER_C 2
1199 #define IC_VER_D 3
1200 u8 ic_version;
1201
1202 u8 sd30_drive_sel_1v8;
1203 u8 sd30_drive_sel_3v3;
1204 u8 card_drive_sel;
1205 #define ASPM_L1_EN 0x02
1206 u8 aspm_en;
1207 bool aspm_enabled;
1208
1209 #define PCR_MS_PMOS (1 << 0)
1210 #define PCR_REVERSE_SOCKET (1 << 1)
1211 u32 flags;
1212
1213 u32 tx_initial_phase;
1214 u32 rx_initial_phase;
1215
1216 const u32 *sd_pull_ctl_enable_tbl;
1217 const u32 *sd_pull_ctl_disable_tbl;
1218 const u32 *ms_pull_ctl_enable_tbl;
1219 const u32 *ms_pull_ctl_disable_tbl;
1220
1221 const struct pcr_ops *ops;
1222 enum PDEV_STAT state;
1223
1224 u16 reg_pm_ctrl3;
1225
1226 int num_slots;
1227 struct rtsx_slot *slots;
1228
1229 u8 dma_error_count;
1230 u8 ocp_stat;
1231 u8 ocp_stat2;
1232 u8 rtd3_en;
1233 };
1234
1235 #define PID_524A 0x524A
1236 #define PID_5249 0x5249
1237 #define PID_5250 0x5250
1238 #define PID_525A 0x525A
1239 #define PID_5260 0x5260
1240 #define PID_5261 0x5261
1241 #define PID_5228 0x5228
1242
1243 #define CHK_PCI_PID(pcr, pid) ((pcr)->pci->device == (pid))
1244 #define PCI_VID(pcr) ((pcr)->pci->vendor)
1245 #define PCI_PID(pcr) ((pcr)->pci->device)
1246 #define is_version(pcr, pid, ver) \
1247 (CHK_PCI_PID(pcr, pid) && (pcr)->ic_version == (ver))
1248 #define pcr_dbg(pcr, fmt, arg...) \
1249 dev_dbg(&(pcr)->pci->dev, fmt, ##arg)
1250
1251 #define SDR104_PHASE(val) ((val) & 0xFF)
1252 #define SDR50_PHASE(val) (((val) >> 8) & 0xFF)
1253 #define DDR50_PHASE(val) (((val) >> 16) & 0xFF)
1254 #define SDR104_TX_PHASE(pcr) SDR104_PHASE((pcr)->tx_initial_phase)
1255 #define SDR50_TX_PHASE(pcr) SDR50_PHASE((pcr)->tx_initial_phase)
1256 #define DDR50_TX_PHASE(pcr) DDR50_PHASE((pcr)->tx_initial_phase)
1257 #define SDR104_RX_PHASE(pcr) SDR104_PHASE((pcr)->rx_initial_phase)
1258 #define SDR50_RX_PHASE(pcr) SDR50_PHASE((pcr)->rx_initial_phase)
1259 #define DDR50_RX_PHASE(pcr) DDR50_PHASE((pcr)->rx_initial_phase)
1260 #define SET_CLOCK_PHASE(sdr104, sdr50, ddr50) \
1261 (((ddr50) << 16) | ((sdr50) << 8) | (sdr104))
1262
1263 void rtsx_pci_start_run(struct rtsx_pcr *pcr);
1264 int rtsx_pci_write_register(struct rtsx_pcr *pcr, u16 addr, u8 mask, u8 data);
1265 int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data);
1266 int rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val);
1267 int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val);
1268 void rtsx_pci_stop_cmd(struct rtsx_pcr *pcr);
1269 void rtsx_pci_add_cmd(struct rtsx_pcr *pcr,
1270 u8 cmd_type, u16 reg_addr, u8 mask, u8 data);
1271 void rtsx_pci_send_cmd_no_wait(struct rtsx_pcr *pcr);
1272 int rtsx_pci_send_cmd(struct rtsx_pcr *pcr, int timeout);
1273 int rtsx_pci_transfer_data(struct rtsx_pcr *pcr, struct scatterlist *sglist,
1274 int num_sg, bool read, int timeout);
1275 int rtsx_pci_dma_map_sg(struct rtsx_pcr *pcr, struct scatterlist *sglist,
1276 int num_sg, bool read);
1277 void rtsx_pci_dma_unmap_sg(struct rtsx_pcr *pcr, struct scatterlist *sglist,
1278 int num_sg, bool read);
1279 int rtsx_pci_dma_transfer(struct rtsx_pcr *pcr, struct scatterlist *sglist,
1280 int count, bool read, int timeout);
1281 int rtsx_pci_read_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
1282 int rtsx_pci_write_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
1283 int rtsx_pci_card_pull_ctl_enable(struct rtsx_pcr *pcr, int card);
1284 int rtsx_pci_card_pull_ctl_disable(struct rtsx_pcr *pcr, int card);
1285 int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
1286 u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk);
1287 int rtsx_pci_card_power_on(struct rtsx_pcr *pcr, int card);
1288 int rtsx_pci_card_power_off(struct rtsx_pcr *pcr, int card);
1289 int rtsx_pci_card_exclusive_check(struct rtsx_pcr *pcr, int card);
1290 int rtsx_pci_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage);
1291 unsigned int rtsx_pci_card_exist(struct rtsx_pcr *pcr);
1292 void rtsx_pci_complete_unfinished_transfer(struct rtsx_pcr *pcr);
1293
rtsx_pci_get_cmd_data(struct rtsx_pcr * pcr)1294 static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr)
1295 {
1296 return (u8 *)(pcr->host_cmds_ptr);
1297 }
1298
rtsx_pci_write_be32(struct rtsx_pcr * pcr,u16 reg,u32 val)1299 static inline void rtsx_pci_write_be32(struct rtsx_pcr *pcr, u16 reg, u32 val)
1300 {
1301 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg, 0xFF, val >> 24);
1302 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 1, 0xFF, val >> 16);
1303 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 2, 0xFF, val >> 8);
1304 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 3, 0xFF, val);
1305 }
1306
rtsx_pci_update_phy(struct rtsx_pcr * pcr,u8 addr,u16 mask,u16 append)1307 static inline int rtsx_pci_update_phy(struct rtsx_pcr *pcr, u8 addr,
1308 u16 mask, u16 append)
1309 {
1310 int err;
1311 u16 val;
1312
1313 err = rtsx_pci_read_phy_register(pcr, addr, &val);
1314 if (err < 0)
1315 return err;
1316
1317 return rtsx_pci_write_phy_register(pcr, addr, (val & mask) | append);
1318 }
1319
1320 #endif
1321