blob: 9cba73703704cb49c4d9a991a1414926087d41a7 [file] [log] [blame]
Wei WANG67d16a42012-11-09 20:53:33 +08001/* Driver for Realtek PCI-Express card reader
2 *
3 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
8 * later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author:
19 * Wei WANG <wei_wang@realsil.com.cn>
20 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
21 */
22
23#ifndef __RTSX_PCI_H
24#define __RTSX_PCI_H
25
26#include <linux/sched.h>
27#include <linux/pci.h>
28
29#include "rtsx_common.h"
30
31#define MAX_RW_REG_CNT 1024
32
33/* PCI Operation Register Address */
34#define RTSX_HCBAR 0x00
35#define RTSX_HCBCTLR 0x04
36#define RTSX_HDBAR 0x08
37#define RTSX_HDBCTLR 0x0C
38#define RTSX_HAIMR 0x10
39#define RTSX_BIPR 0x14
40#define RTSX_BIER 0x18
41
42/* Host command buffer control register */
43#define STOP_CMD (0x01 << 28)
44
45/* Host data buffer control register */
46#define SDMA_MODE 0x00
47#define ADMA_MODE (0x02 << 26)
48#define STOP_DMA (0x01 << 28)
49#define TRIG_DMA (0x01 << 31)
50
51/* Host access internal memory register */
52#define HAIMR_TRANS_START (0x01 << 31)
53#define HAIMR_READ 0x00
54#define HAIMR_WRITE (0x01 << 30)
55#define HAIMR_READ_START (HAIMR_TRANS_START | HAIMR_READ)
56#define HAIMR_WRITE_START (HAIMR_TRANS_START | HAIMR_WRITE)
57#define HAIMR_TRANS_END (HAIMR_TRANS_START)
58
59/* Bus interrupt pending register */
60#define CMD_DONE_INT (1 << 31)
61#define DATA_DONE_INT (1 << 30)
62#define TRANS_OK_INT (1 << 29)
63#define TRANS_FAIL_INT (1 << 28)
64#define XD_INT (1 << 27)
65#define MS_INT (1 << 26)
66#define SD_INT (1 << 25)
67#define GPIO0_INT (1 << 24)
68#define OC_INT (1 << 23)
69#define SD_WRITE_PROTECT (1 << 19)
70#define XD_EXIST (1 << 18)
71#define MS_EXIST (1 << 17)
72#define SD_EXIST (1 << 16)
73#define DELINK_INT GPIO0_INT
74#define MS_OC_INT (1 << 23)
75#define SD_OC_INT (1 << 22)
76
77#define CARD_INT (XD_INT | MS_INT | SD_INT)
78#define NEED_COMPLETE_INT (DATA_DONE_INT | TRANS_OK_INT | TRANS_FAIL_INT)
79#define RTSX_INT (CMD_DONE_INT | NEED_COMPLETE_INT | \
80 CARD_INT | GPIO0_INT | OC_INT)
81
82#define CARD_EXIST (XD_EXIST | MS_EXIST | SD_EXIST)
83
84/* Bus interrupt enable register */
85#define CMD_DONE_INT_EN (1 << 31)
86#define DATA_DONE_INT_EN (1 << 30)
87#define TRANS_OK_INT_EN (1 << 29)
88#define TRANS_FAIL_INT_EN (1 << 28)
89#define XD_INT_EN (1 << 27)
90#define MS_INT_EN (1 << 26)
91#define SD_INT_EN (1 << 25)
92#define GPIO0_INT_EN (1 << 24)
93#define OC_INT_EN (1 << 23)
94#define DELINK_INT_EN GPIO0_INT_EN
95#define MS_OC_INT_EN (1 << 23)
96#define SD_OC_INT_EN (1 << 22)
97
98#define READ_REG_CMD 0
99#define WRITE_REG_CMD 1
100#define CHECK_REG_CMD 2
101
102/*
103 * macros for easy use
104 */
105#define rtsx_pci_writel(pcr, reg, value) \
106 iowrite32(value, (pcr)->remap_addr + reg)
107#define rtsx_pci_readl(pcr, reg) \
108 ioread32((pcr)->remap_addr + reg)
109#define rtsx_pci_writew(pcr, reg, value) \
110 iowrite16(value, (pcr)->remap_addr + reg)
111#define rtsx_pci_readw(pcr, reg) \
112 ioread16((pcr)->remap_addr + reg)
113#define rtsx_pci_writeb(pcr, reg, value) \
114 iowrite8(value, (pcr)->remap_addr + reg)
115#define rtsx_pci_readb(pcr, reg) \
116 ioread8((pcr)->remap_addr + reg)
117
118#define rtsx_pci_read_config_byte(pcr, where, val) \
119 pci_read_config_byte((pcr)->pci, where, val)
120
121#define rtsx_pci_write_config_byte(pcr, where, val) \
122 pci_write_config_byte((pcr)->pci, where, val)
123
124#define rtsx_pci_read_config_dword(pcr, where, val) \
125 pci_read_config_dword((pcr)->pci, where, val)
126
127#define rtsx_pci_write_config_dword(pcr, where, val) \
128 pci_write_config_dword((pcr)->pci, where, val)
129
130#define STATE_TRANS_NONE 0
131#define STATE_TRANS_CMD 1
132#define STATE_TRANS_BUF 2
133#define STATE_TRANS_SG 3
134
135#define TRANS_NOT_READY 0
136#define TRANS_RESULT_OK 1
137#define TRANS_RESULT_FAIL 2
138#define TRANS_NO_DEVICE 3
139
140#define RTSX_RESV_BUF_LEN 4096
141#define HOST_CMDS_BUF_LEN 1024
142#define HOST_SG_TBL_BUF_LEN (RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
143#define HOST_SG_TBL_ITEMS (HOST_SG_TBL_BUF_LEN / 8)
144#define MAX_SG_ITEM_LEN 0x80000
145
146#define HOST_TO_DEVICE 0
147#define DEVICE_TO_HOST 1
148
149#define MAX_PHASE 31
150#define RX_TUNING_CNT 3
151
152/* SG descriptor */
153#define SG_INT 0x04
154#define SG_END 0x02
155#define SG_VALID 0x01
156
157#define SG_NO_OP 0x00
158#define SG_TRANS_DATA (0x02 << 4)
159#define SG_LINK_DESC (0x03 << 4)
160
Wei WANGd817ac42013-01-23 09:51:04 +0800161/* Output voltage */
162#define OUTPUT_3V3 0
163#define OUTPUT_1V8 1
Wei WANG67d16a42012-11-09 20:53:33 +0800164
165/* Card Clock Enable Register */
166#define SD_CLK_EN 0x04
167#define MS_CLK_EN 0x08
168
169/* Card Select Register */
170#define SD_MOD_SEL 2
171#define MS_MOD_SEL 3
172
173/* Card Output Enable Register */
174#define SD_OUTPUT_EN 0x04
175#define MS_OUTPUT_EN 0x08
176
177/* CARD_SHARE_MODE */
178#define CARD_SHARE_MASK 0x0F
179#define CARD_SHARE_MULTI_LUN 0x00
180#define CARD_SHARE_NORMAL 0x00
181#define CARD_SHARE_48_SD 0x04
182#define CARD_SHARE_48_MS 0x08
183/* CARD_SHARE_MODE for barossa */
184#define CARD_SHARE_BAROSSA_SD 0x01
185#define CARD_SHARE_BAROSSA_MS 0x02
186
Wei WANG773ccdf2013-08-20 14:18:51 +0800187/* CARD_DRIVE_SEL */
188#define MS_DRIVE_8mA (0x01 << 6)
189#define MMC_DRIVE_8mA (0x01 << 4)
190#define XD_DRIVE_8mA (0x01 << 2)
191#define GPIO_DRIVE_8mA 0x01
192#define RTS5209_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
193 XD_DRIVE_8mA | GPIO_DRIVE_8mA)
194#define RTL8411_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | MMC_DRIVE_8mA |\
195 XD_DRIVE_8mA)
196#define RTSX_CARD_DRIVE_DEFAULT (MS_DRIVE_8mA | GPIO_DRIVE_8mA)
197
Wei WANG67d16a42012-11-09 20:53:33 +0800198/* SD30_DRIVE_SEL */
199#define DRIVER_TYPE_A 0x05
200#define DRIVER_TYPE_B 0x03
201#define DRIVER_TYPE_C 0x02
202#define DRIVER_TYPE_D 0x01
Wei WANG773ccdf2013-08-20 14:18:51 +0800203#define CFG_DRIVER_TYPE_A 0x02
204#define CFG_DRIVER_TYPE_B 0x03
205#define CFG_DRIVER_TYPE_C 0x01
206#define CFG_DRIVER_TYPE_D 0x00
Wei WANG67d16a42012-11-09 20:53:33 +0800207
208/* FPDCTL */
209#define SSC_POWER_DOWN 0x01
210#define SD_OC_POWER_DOWN 0x02
211#define ALL_POWER_DOWN 0x07
212#define OC_POWER_DOWN 0x06
213
214/* CLK_CTL */
215#define CHANGE_CLK 0x01
216
217/* LDO_CTL */
Wei WANGd817ac42013-01-23 09:51:04 +0800218#define BPP_ASIC_1V7 0x00
219#define BPP_ASIC_1V8 0x01
220#define BPP_ASIC_1V9 0x02
221#define BPP_ASIC_2V0 0x03
222#define BPP_ASIC_2V7 0x04
223#define BPP_ASIC_2V8 0x05
224#define BPP_ASIC_3V2 0x06
225#define BPP_ASIC_3V3 0x07
226#define BPP_REG_TUNED18 0x07
227#define BPP_TUNED18_SHIFT_8402 5
228#define BPP_TUNED18_SHIFT_8411 4
229#define BPP_PAD_MASK 0x04
230#define BPP_PAD_3V3 0x04
231#define BPP_PAD_1V8 0x00
Wei WANG67d16a42012-11-09 20:53:33 +0800232#define BPP_LDO_POWB 0x03
233#define BPP_LDO_ON 0x00
234#define BPP_LDO_SUSPEND 0x02
235#define BPP_LDO_OFF 0x03
236
237/* CD_PAD_CTL */
238#define CD_DISABLE_MASK 0x07
239#define MS_CD_DISABLE 0x04
240#define SD_CD_DISABLE 0x02
241#define XD_CD_DISABLE 0x01
242#define CD_DISABLE 0x07
243#define CD_ENABLE 0x00
244#define MS_CD_EN_ONLY 0x03
245#define SD_CD_EN_ONLY 0x05
246#define XD_CD_EN_ONLY 0x06
247#define FORCE_CD_LOW_MASK 0x38
248#define FORCE_CD_XD_LOW 0x08
249#define FORCE_CD_SD_LOW 0x10
250#define FORCE_CD_MS_LOW 0x20
251#define CD_AUTO_DISABLE 0x40
252
253/* SD_STAT1 */
254#define SD_CRC7_ERR 0x80
255#define SD_CRC16_ERR 0x40
256#define SD_CRC_WRITE_ERR 0x20
257#define SD_CRC_WRITE_ERR_MASK 0x1C
258#define GET_CRC_TIME_OUT 0x02
259#define SD_TUNING_COMPARE_ERR 0x01
260
261/* SD_STAT2 */
262#define SD_RSP_80CLK_TIMEOUT 0x01
263
264/* SD_BUS_STAT */
265#define SD_CLK_TOGGLE_EN 0x80
266#define SD_CLK_FORCE_STOP 0x40
267#define SD_DAT3_STATUS 0x10
268#define SD_DAT2_STATUS 0x08
269#define SD_DAT1_STATUS 0x04
270#define SD_DAT0_STATUS 0x02
271#define SD_CMD_STATUS 0x01
272
273/* SD_PAD_CTL */
274#define SD_IO_USING_1V8 0x80
275#define SD_IO_USING_3V3 0x7F
276#define TYPE_A_DRIVING 0x00
277#define TYPE_B_DRIVING 0x01
278#define TYPE_C_DRIVING 0x02
279#define TYPE_D_DRIVING 0x03
280
281/* SD_SAMPLE_POINT_CTL */
282#define DDR_FIX_RX_DAT 0x00
283#define DDR_VAR_RX_DAT 0x80
284#define DDR_FIX_RX_DAT_EDGE 0x00
285#define DDR_FIX_RX_DAT_14_DELAY 0x40
286#define DDR_FIX_RX_CMD 0x00
287#define DDR_VAR_RX_CMD 0x20
288#define DDR_FIX_RX_CMD_POS_EDGE 0x00
289#define DDR_FIX_RX_CMD_14_DELAY 0x10
290#define SD20_RX_POS_EDGE 0x00
291#define SD20_RX_14_DELAY 0x08
292#define SD20_RX_SEL_MASK 0x08
293
294/* SD_PUSH_POINT_CTL */
295#define DDR_FIX_TX_CMD_DAT 0x00
296#define DDR_VAR_TX_CMD_DAT 0x80
297#define DDR_FIX_TX_DAT_14_TSU 0x00
298#define DDR_FIX_TX_DAT_12_TSU 0x40
299#define DDR_FIX_TX_CMD_NEG_EDGE 0x00
300#define DDR_FIX_TX_CMD_14_AHEAD 0x20
301#define SD20_TX_NEG_EDGE 0x00
302#define SD20_TX_14_AHEAD 0x10
303#define SD20_TX_SEL_MASK 0x10
304#define DDR_VAR_SDCLK_POL_SWAP 0x01
305
306/* SD_TRANSFER */
307#define SD_TRANSFER_START 0x80
308#define SD_TRANSFER_END 0x40
309#define SD_STAT_IDLE 0x20
310#define SD_TRANSFER_ERR 0x10
311/* SD Transfer Mode definition */
312#define SD_TM_NORMAL_WRITE 0x00
313#define SD_TM_AUTO_WRITE_3 0x01
314#define SD_TM_AUTO_WRITE_4 0x02
315#define SD_TM_AUTO_READ_3 0x05
316#define SD_TM_AUTO_READ_4 0x06
317#define SD_TM_CMD_RSP 0x08
318#define SD_TM_AUTO_WRITE_1 0x09
319#define SD_TM_AUTO_WRITE_2 0x0A
320#define SD_TM_NORMAL_READ 0x0C
321#define SD_TM_AUTO_READ_1 0x0D
322#define SD_TM_AUTO_READ_2 0x0E
323#define SD_TM_AUTO_TUNING 0x0F
324
325/* SD_VPTX_CTL / SD_VPRX_CTL */
326#define PHASE_CHANGE 0x80
327#define PHASE_NOT_RESET 0x40
328
329/* SD_DCMPS_TX_CTL / SD_DCMPS_RX_CTL */
330#define DCMPS_CHANGE 0x80
331#define DCMPS_CHANGE_DONE 0x40
332#define DCMPS_ERROR 0x20
333#define DCMPS_CURRENT_PHASE 0x1F
334
335/* SD Configure 1 Register */
336#define SD_CLK_DIVIDE_0 0x00
337#define SD_CLK_DIVIDE_256 0xC0
338#define SD_CLK_DIVIDE_128 0x80
339#define SD_BUS_WIDTH_1BIT 0x00
340#define SD_BUS_WIDTH_4BIT 0x01
341#define SD_BUS_WIDTH_8BIT 0x02
342#define SD_ASYNC_FIFO_NOT_RST 0x10
343#define SD_20_MODE 0x00
344#define SD_DDR_MODE 0x04
345#define SD_30_MODE 0x08
346
347#define SD_CLK_DIVIDE_MASK 0xC0
348
349/* SD_CMD_STATE */
350#define SD_CMD_IDLE 0x80
351
352/* SD_DATA_STATE */
353#define SD_DATA_IDLE 0x80
354
355/* DCM_DRP_CTL */
356#define DCM_RESET 0x08
357#define DCM_LOCKED 0x04
358#define DCM_208M 0x00
359#define DCM_TX 0x01
360#define DCM_RX 0x02
361
362/* DCM_DRP_TRIG */
363#define DRP_START 0x80
364#define DRP_DONE 0x40
365
366/* DCM_DRP_CFG */
367#define DRP_WRITE 0x80
368#define DRP_READ 0x00
369#define DCM_WRITE_ADDRESS_50 0x50
370#define DCM_WRITE_ADDRESS_51 0x51
371#define DCM_READ_ADDRESS_00 0x00
372#define DCM_READ_ADDRESS_51 0x51
373
374/* IRQSTAT0 */
375#define DMA_DONE_INT 0x80
376#define SUSPEND_INT 0x40
377#define LINK_RDY_INT 0x20
378#define LINK_DOWN_INT 0x10
379
380/* DMACTL */
381#define DMA_RST 0x80
382#define DMA_BUSY 0x04
383#define DMA_DIR_TO_CARD 0x00
384#define DMA_DIR_FROM_CARD 0x02
385#define DMA_EN 0x01
386#define DMA_128 (0 << 4)
387#define DMA_256 (1 << 4)
388#define DMA_512 (2 << 4)
389#define DMA_1024 (3 << 4)
390#define DMA_PACK_SIZE_MASK 0x30
391
392/* SSC_CTL1 */
393#define SSC_RSTB 0x80
394#define SSC_8X_EN 0x40
395#define SSC_FIX_FRAC 0x20
396#define SSC_SEL_1M 0x00
397#define SSC_SEL_2M 0x08
398#define SSC_SEL_4M 0x10
399#define SSC_SEL_8M 0x18
400
401/* SSC_CTL2 */
402#define SSC_DEPTH_MASK 0x07
403#define SSC_DEPTH_DISALBE 0x00
404#define SSC_DEPTH_4M 0x01
405#define SSC_DEPTH_2M 0x02
406#define SSC_DEPTH_1M 0x03
407#define SSC_DEPTH_500K 0x04
408#define SSC_DEPTH_250K 0x05
409
410/* System Clock Control Register */
411#define CLK_LOW_FREQ 0x01
412
413/* System Clock Divider Register */
414#define CLK_DIV_1 0x01
415#define CLK_DIV_2 0x02
416#define CLK_DIV_4 0x03
417#define CLK_DIV_8 0x04
418
419/* MS_CFG */
420#define SAMPLE_TIME_RISING 0x00
421#define SAMPLE_TIME_FALLING 0x80
422#define PUSH_TIME_DEFAULT 0x00
423#define PUSH_TIME_ODD 0x40
424#define NO_EXTEND_TOGGLE 0x00
425#define EXTEND_TOGGLE_CHK 0x20
426#define MS_BUS_WIDTH_1 0x00
427#define MS_BUS_WIDTH_4 0x10
428#define MS_BUS_WIDTH_8 0x18
429#define MS_2K_SECTOR_MODE 0x04
430#define MS_512_SECTOR_MODE 0x00
431#define MS_TOGGLE_TIMEOUT_EN 0x00
432#define MS_TOGGLE_TIMEOUT_DISEN 0x01
433#define MS_NO_CHECK_INT 0x02
434
435/* MS_TRANS_CFG */
436#define WAIT_INT 0x80
437#define NO_WAIT_INT 0x00
438#define NO_AUTO_READ_INT_REG 0x00
439#define AUTO_READ_INT_REG 0x40
440#define MS_CRC16_ERR 0x20
441#define MS_RDY_TIMEOUT 0x10
442#define MS_INT_CMDNK 0x08
443#define MS_INT_BREQ 0x04
444#define MS_INT_ERR 0x02
445#define MS_INT_CED 0x01
446
447/* MS_TRANSFER */
448#define MS_TRANSFER_START 0x80
449#define MS_TRANSFER_END 0x40
450#define MS_TRANSFER_ERR 0x20
451#define MS_BS_STATE 0x10
452#define MS_TM_READ_BYTES 0x00
453#define MS_TM_NORMAL_READ 0x01
454#define MS_TM_WRITE_BYTES 0x04
455#define MS_TM_NORMAL_WRITE 0x05
456#define MS_TM_AUTO_READ 0x08
457#define MS_TM_AUTO_WRITE 0x0C
458
459/* SD Configure 2 Register */
460#define SD_CALCULATE_CRC7 0x00
461#define SD_NO_CALCULATE_CRC7 0x80
462#define SD_CHECK_CRC16 0x00
463#define SD_NO_CHECK_CRC16 0x40
464#define SD_NO_CHECK_WAIT_CRC_TO 0x20
465#define SD_WAIT_BUSY_END 0x08
466#define SD_NO_WAIT_BUSY_END 0x00
467#define SD_CHECK_CRC7 0x00
468#define SD_NO_CHECK_CRC7 0x04
469#define SD_RSP_LEN_0 0x00
470#define SD_RSP_LEN_6 0x01
471#define SD_RSP_LEN_17 0x02
472/* SD/MMC Response Type Definition */
473#define SD_RSP_TYPE_R0 0x04
474#define SD_RSP_TYPE_R1 0x01
475#define SD_RSP_TYPE_R1b 0x09
476#define SD_RSP_TYPE_R2 0x02
477#define SD_RSP_TYPE_R3 0x05
478#define SD_RSP_TYPE_R4 0x05
479#define SD_RSP_TYPE_R5 0x01
480#define SD_RSP_TYPE_R6 0x01
481#define SD_RSP_TYPE_R7 0x01
482
Wei WANG3730bb82013-01-29 15:21:32 +0800483/* SD_CONFIGURE3 */
Wei WANG67d16a42012-11-09 20:53:33 +0800484#define SD_RSP_80CLK_TIMEOUT_EN 0x01
485
486/* Card Transfer Reset Register */
487#define SPI_STOP 0x01
488#define XD_STOP 0x02
489#define SD_STOP 0x04
490#define MS_STOP 0x08
491#define SPI_CLR_ERR 0x10
492#define XD_CLR_ERR 0x20
493#define SD_CLR_ERR 0x40
494#define MS_CLR_ERR 0x80
495
496/* Card Data Source Register */
497#define PINGPONG_BUFFER 0x01
498#define RING_BUFFER 0x00
499
500/* Card Power Control Register */
501#define PMOS_STRG_MASK 0x10
502#define PMOS_STRG_800mA 0x10
503#define PMOS_STRG_400mA 0x00
504#define SD_POWER_OFF 0x03
505#define SD_PARTIAL_POWER_ON 0x01
506#define SD_POWER_ON 0x00
507#define SD_POWER_MASK 0x03
508#define MS_POWER_OFF 0x0C
509#define MS_PARTIAL_POWER_ON 0x04
510#define MS_POWER_ON 0x00
511#define MS_POWER_MASK 0x0C
512#define BPP_POWER_OFF 0x0F
513#define BPP_POWER_5_PERCENT_ON 0x0E
514#define BPP_POWER_10_PERCENT_ON 0x0C
515#define BPP_POWER_15_PERCENT_ON 0x08
516#define BPP_POWER_ON 0x00
517#define BPP_POWER_MASK 0x0F
Wei WANG4c4b8c12013-04-11 10:43:40 +0800518#define SD_VCC_PARTIAL_POWER_ON 0x02
519#define SD_VCC_POWER_ON 0x00
Wei WANG67d16a42012-11-09 20:53:33 +0800520
521/* PWR_GATE_CTRL */
522#define PWR_GATE_EN 0x01
523#define LDO3318_PWR_MASK 0x06
524#define LDO_ON 0x00
525#define LDO_SUSPEND 0x04
526#define LDO_OFF 0x06
527
528/* CARD_CLK_SOURCE */
529#define CRC_FIX_CLK (0x00 << 0)
530#define CRC_VAR_CLK0 (0x01 << 0)
531#define CRC_VAR_CLK1 (0x02 << 0)
532#define SD30_FIX_CLK (0x00 << 2)
533#define SD30_VAR_CLK0 (0x01 << 2)
534#define SD30_VAR_CLK1 (0x02 << 2)
535#define SAMPLE_FIX_CLK (0x00 << 4)
536#define SAMPLE_VAR_CLK0 (0x01 << 4)
537#define SAMPLE_VAR_CLK1 (0x02 << 4)
538
539#define MS_CFG 0xFD40
540#define MS_TPC 0xFD41
541#define MS_TRANS_CFG 0xFD42
542#define MS_TRANSFER 0xFD43
543#define MS_INT_REG 0xFD44
544#define MS_BYTE_CNT 0xFD45
545#define MS_SECTOR_CNT_L 0xFD46
546#define MS_SECTOR_CNT_H 0xFD47
547#define MS_DBUS_H 0xFD48
548
549#define SD_CFG1 0xFDA0
550#define SD_CFG2 0xFDA1
551#define SD_CFG3 0xFDA2
552#define SD_STAT1 0xFDA3
553#define SD_STAT2 0xFDA4
554#define SD_BUS_STAT 0xFDA5
555#define SD_PAD_CTL 0xFDA6
556#define SD_SAMPLE_POINT_CTL 0xFDA7
557#define SD_PUSH_POINT_CTL 0xFDA8
558#define SD_CMD0 0xFDA9
559#define SD_CMD1 0xFDAA
560#define SD_CMD2 0xFDAB
561#define SD_CMD3 0xFDAC
562#define SD_CMD4 0xFDAD
563#define SD_CMD5 0xFDAE
564#define SD_BYTE_CNT_L 0xFDAF
565#define SD_BYTE_CNT_H 0xFDB0
566#define SD_BLOCK_CNT_L 0xFDB1
567#define SD_BLOCK_CNT_H 0xFDB2
568#define SD_TRANSFER 0xFDB3
569#define SD_CMD_STATE 0xFDB5
570#define SD_DATA_STATE 0xFDB6
571
572#define SRCTL 0xFC13
573
574#define DCM_DRP_CTL 0xFC23
575#define DCM_DRP_TRIG 0xFC24
576#define DCM_DRP_CFG 0xFC25
577#define DCM_DRP_WR_DATA_L 0xFC26
578#define DCM_DRP_WR_DATA_H 0xFC27
579#define DCM_DRP_RD_DATA_L 0xFC28
580#define DCM_DRP_RD_DATA_H 0xFC29
581#define SD_VPCLK0_CTL 0xFC2A
582#define SD_VPCLK1_CTL 0xFC2B
583#define SD_DCMPS0_CTL 0xFC2C
584#define SD_DCMPS1_CTL 0xFC2D
585#define SD_VPTX_CTL SD_VPCLK0_CTL
586#define SD_VPRX_CTL SD_VPCLK1_CTL
587#define SD_DCMPS_TX_CTL SD_DCMPS0_CTL
588#define SD_DCMPS_RX_CTL SD_DCMPS1_CTL
589#define CARD_CLK_SOURCE 0xFC2E
590
591#define CARD_PWR_CTL 0xFD50
592#define CARD_CLK_SWITCH 0xFD51
Roger Tseng9032eab2013-04-19 21:52:42 +0800593#define RTL8411B_PACKAGE_MODE 0xFD51
Wei WANG67d16a42012-11-09 20:53:33 +0800594#define CARD_SHARE_MODE 0xFD52
595#define CARD_DRIVE_SEL 0xFD53
596#define CARD_STOP 0xFD54
597#define CARD_OE 0xFD55
598#define CARD_AUTO_BLINK 0xFD56
599#define CARD_GPIO_DIR 0xFD57
600#define CARD_GPIO 0xFD58
601#define CARD_DATA_SOURCE 0xFD5B
Roger Tsenge1237932013-02-04 15:45:59 +0800602#define SD30_CLK_DRIVE_SEL 0xFD5A
Wei WANG67d16a42012-11-09 20:53:33 +0800603#define CARD_SELECT 0xFD5C
604#define SD30_DRIVE_SEL 0xFD5E
Roger Tsenge1237932013-02-04 15:45:59 +0800605#define SD30_CMD_DRIVE_SEL 0xFD5E
606#define SD30_DAT_DRIVE_SEL 0xFD5F
Wei WANG67d16a42012-11-09 20:53:33 +0800607#define CARD_CLK_EN 0xFD69
608#define SDIO_CTRL 0xFD6B
609#define CD_PAD_CTL 0xFD73
610
611#define FPDCTL 0xFC00
612#define PDINFO 0xFC01
613
614#define CLK_CTL 0xFC02
615#define CLK_DIV 0xFC03
616#define CLK_SEL 0xFC04
617
618#define SSC_DIV_N_0 0xFC0F
619#define SSC_DIV_N_1 0xFC10
620#define SSC_CTL1 0xFC11
621#define SSC_CTL2 0xFC12
622
623#define RCCTL 0xFC14
624
625#define FPGA_PULL_CTL 0xFC1D
626#define OLT_LED_CTL 0xFC1E
627#define GPIO_CTL 0xFC1F
628
629#define LDO_CTL 0xFC1E
630#define SYS_VER 0xFC32
631
632#define CARD_PULL_CTL1 0xFD60
633#define CARD_PULL_CTL2 0xFD61
634#define CARD_PULL_CTL3 0xFD62
635#define CARD_PULL_CTL4 0xFD63
636#define CARD_PULL_CTL5 0xFD64
637#define CARD_PULL_CTL6 0xFD65
638
639/* PCI Express Related Registers */
640#define IRQEN0 0xFE20
641#define IRQSTAT0 0xFE21
642#define IRQEN1 0xFE22
643#define IRQSTAT1 0xFE23
644#define TLPRIEN 0xFE24
645#define TLPRISTAT 0xFE25
646#define TLPTIEN 0xFE26
647#define TLPTISTAT 0xFE27
648#define DMATC0 0xFE28
649#define DMATC1 0xFE29
650#define DMATC2 0xFE2A
651#define DMATC3 0xFE2B
652#define DMACTL 0xFE2C
653#define BCTL 0xFE2D
654#define RBBC0 0xFE2E
655#define RBBC1 0xFE2F
656#define RBDAT 0xFE30
657#define RBCTL 0xFE34
658#define CFGADDR0 0xFE35
659#define CFGADDR1 0xFE36
660#define CFGDATA0 0xFE37
661#define CFGDATA1 0xFE38
662#define CFGDATA2 0xFE39
663#define CFGDATA3 0xFE3A
664#define CFGRWCTL 0xFE3B
665#define PHYRWCTL 0xFE3C
666#define PHYDATA0 0xFE3D
667#define PHYDATA1 0xFE3E
668#define PHYADDR 0xFE3F
669#define MSGRXDATA0 0xFE40
670#define MSGRXDATA1 0xFE41
671#define MSGRXDATA2 0xFE42
672#define MSGRXDATA3 0xFE43
673#define MSGTXDATA0 0xFE44
674#define MSGTXDATA1 0xFE45
675#define MSGTXDATA2 0xFE46
676#define MSGTXDATA3 0xFE47
677#define MSGTXCTL 0xFE48
678#define PETXCFG 0xFE49
Roger Tsenge1237932013-02-04 15:45:59 +0800679#define LTR_CTL 0xFE4A
680#define OBFF_CFG 0xFE4C
Wei WANG67d16a42012-11-09 20:53:33 +0800681
682#define CDRESUMECTL 0xFE52
683#define WAKE_SEL_CTL 0xFE54
684#define PME_FORCE_CTL 0xFE56
685#define ASPM_FORCE_CTL 0xFE57
686#define PM_CLK_FORCE_CTL 0xFE58
687#define PERST_GLITCH_WIDTH 0xFE5C
688#define CHANGE_LINK_STATE 0xFE5B
689#define RESET_LOAD_REG 0xFE5E
690#define EFUSE_CONTENT 0xFE5F
691#define HOST_SLEEP_STATE 0xFE60
692#define SDIO_CFG 0xFE70
693
694#define NFTS_TX_CTRL 0xFE72
695
696#define PWR_GATE_CTRL 0xFE75
697#define PWD_SUSPEND_EN 0xFE76
698#define LDO_PWR_SEL 0xFE78
699
700#define DUMMY_REG_RESET_0 0xFE90
701
Wei WANG773ccdf2013-08-20 14:18:51 +0800702#define AUTOLOAD_CFG_BASE 0xFF00
703
Wei WANG67d16a42012-11-09 20:53:33 +0800704/* Memory mapping */
705#define SRAM_BASE 0xE600
706#define RBUF_BASE 0xF400
707#define PPBUF_BASE1 0xF800
708#define PPBUF_BASE2 0xFA00
709#define IMAGE_FLAG_ADDR0 0xCE80
710#define IMAGE_FLAG_ADDR1 0xCE81
711
Wei WANG4c4b8c12013-04-11 10:43:40 +0800712/* Phy register */
713#define PHY_PCR 0x00
714#define PHY_RCR0 0x01
715#define PHY_RCR1 0x02
716#define PHY_RCR2 0x03
717#define PHY_RTCR 0x04
718#define PHY_RDR 0x05
719#define PHY_TCR0 0x06
720#define PHY_TCR1 0x07
721#define PHY_TUNE 0x08
722#define PHY_IMR 0x09
723#define PHY_BPCR 0x0A
724#define PHY_BIST 0x0B
725#define PHY_RAW_L 0x0C
726#define PHY_RAW_H 0x0D
727#define PHY_RAW_DATA 0x0E
728#define PHY_HOST_CLK_CTRL 0x0F
729#define PHY_DMR 0x10
730#define PHY_BACR 0x11
731#define PHY_IER 0x12
732#define PHY_BCSR 0x13
733#define PHY_BPR 0x14
734#define PHY_BPNR2 0x15
735#define PHY_BPNR 0x16
736#define PHY_BRNR2 0x17
737#define PHY_BENR 0x18
738#define PHY_REG_REV 0x19
739#define PHY_FLD0 0x1A
740#define PHY_FLD1 0x1B
741#define PHY_FLD2 0x1C
742#define PHY_FLD3 0x1D
743#define PHY_FLD4 0x1E
744#define PHY_DUM_REG 0x1F
745
Wei WANG773ccdf2013-08-20 14:18:51 +0800746#define LCTLR 0x80
747#define PCR_SETTING_REG1 0x724
748#define PCR_SETTING_REG2 0x814
749#define PCR_SETTING_REG3 0x747
750
Wei WANG67d16a42012-11-09 20:53:33 +0800751#define rtsx_pci_init_cmd(pcr) ((pcr)->ci = 0)
752
753struct rtsx_pcr;
754
755struct pcr_handle {
756 struct rtsx_pcr *pcr;
757};
758
759struct pcr_ops {
760 int (*extra_init_hw)(struct rtsx_pcr *pcr);
761 int (*optimize_phy)(struct rtsx_pcr *pcr);
762 int (*turn_on_led)(struct rtsx_pcr *pcr);
763 int (*turn_off_led)(struct rtsx_pcr *pcr);
764 int (*enable_auto_blink)(struct rtsx_pcr *pcr);
765 int (*disable_auto_blink)(struct rtsx_pcr *pcr);
766 int (*card_power_on)(struct rtsx_pcr *pcr, int card);
767 int (*card_power_off)(struct rtsx_pcr *pcr, int card);
Wei WANGd817ac42013-01-23 09:51:04 +0800768 int (*switch_output_voltage)(struct rtsx_pcr *pcr,
769 u8 voltage);
Wei WANG67d16a42012-11-09 20:53:33 +0800770 unsigned int (*cd_deglitch)(struct rtsx_pcr *pcr);
Wei WANGab4e8f82013-01-23 09:51:06 +0800771 int (*conv_clk_and_div_n)(int clk, int dir);
Wei WANG773ccdf2013-08-20 14:18:51 +0800772 void (*fetch_vendor_settings)(struct rtsx_pcr *pcr);
Wei WANG67d16a42012-11-09 20:53:33 +0800773};
774
775enum PDEV_STAT {PDEV_STAT_IDLE, PDEV_STAT_RUN};
776
777struct rtsx_pcr {
778 struct pci_dev *pci;
779 unsigned int id;
780
781 /* pci resources */
782 unsigned long addr;
783 void __iomem *remap_addr;
784 int irq;
785
786 /* host reserved buffer */
787 void *rtsx_resv_buf;
788 dma_addr_t rtsx_resv_buf_addr;
789
790 void *host_cmds_ptr;
791 dma_addr_t host_cmds_addr;
792 int ci;
793
794 void *host_sg_tbl_ptr;
795 dma_addr_t host_sg_tbl_addr;
796 int sgi;
797
798 u32 bier;
799 char trans_result;
800
801 unsigned int card_inserted;
802 unsigned int card_removed;
Wei WANGc3481952013-02-08 15:24:27 +0800803 unsigned int card_exist;
Wei WANG67d16a42012-11-09 20:53:33 +0800804
805 struct delayed_work carddet_work;
806 struct delayed_work idle_work;
807
808 spinlock_t lock;
809 struct mutex pcr_mutex;
810 struct completion *done;
811 struct completion *finish_me;
812
813 unsigned int cur_clock;
Wei WANG67d16a42012-11-09 20:53:33 +0800814 bool remove_pci;
815 bool msi_en;
816
817#define EXTRA_CAPS_SD_SDR50 (1 << 0)
818#define EXTRA_CAPS_SD_SDR104 (1 << 1)
819#define EXTRA_CAPS_SD_DDR50 (1 << 2)
820#define EXTRA_CAPS_MMC_HSDDR (1 << 3)
821#define EXTRA_CAPS_MMC_HS200 (1 << 4)
822#define EXTRA_CAPS_MMC_8BIT (1 << 5)
823 u32 extra_caps;
824
825#define IC_VER_A 0
826#define IC_VER_B 1
827#define IC_VER_C 2
828#define IC_VER_D 3
829 u8 ic_version;
830
Wei WANG773ccdf2013-08-20 14:18:51 +0800831 u8 sd30_drive_sel_1v8;
832 u8 sd30_drive_sel_3v3;
833 u8 card_drive_sel;
834#define ASPM_L1_EN 0x02
835 u8 aspm_en;
836
837#define PCR_MS_PMOS (1 << 0)
838#define PCR_REVERSE_SOCKET (1 << 1)
839 u32 flags;
840
Wei WANG67d16a42012-11-09 20:53:33 +0800841 const u32 *sd_pull_ctl_enable_tbl;
842 const u32 *sd_pull_ctl_disable_tbl;
843 const u32 *ms_pull_ctl_enable_tbl;
844 const u32 *ms_pull_ctl_disable_tbl;
845
846 const struct pcr_ops *ops;
847 enum PDEV_STAT state;
848
849 int num_slots;
850 struct rtsx_slot *slots;
851};
852
853#define CHK_PCI_PID(pcr, pid) ((pcr)->pci->device == (pid))
854#define PCI_VID(pcr) ((pcr)->pci->vendor)
855#define PCI_PID(pcr) ((pcr)->pci->device)
856
857void rtsx_pci_start_run(struct rtsx_pcr *pcr);
858int rtsx_pci_write_register(struct rtsx_pcr *pcr, u16 addr, u8 mask, u8 data);
859int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data);
860int rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val);
861int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val);
862void rtsx_pci_stop_cmd(struct rtsx_pcr *pcr);
863void rtsx_pci_add_cmd(struct rtsx_pcr *pcr,
864 u8 cmd_type, u16 reg_addr, u8 mask, u8 data);
865void rtsx_pci_send_cmd_no_wait(struct rtsx_pcr *pcr);
866int rtsx_pci_send_cmd(struct rtsx_pcr *pcr, int timeout);
867int rtsx_pci_transfer_data(struct rtsx_pcr *pcr, struct scatterlist *sglist,
868 int num_sg, bool read, int timeout);
869int rtsx_pci_read_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
870int rtsx_pci_write_ppbuf(struct rtsx_pcr *pcr, u8 *buf, int buf_len);
871int rtsx_pci_card_pull_ctl_enable(struct rtsx_pcr *pcr, int card);
872int rtsx_pci_card_pull_ctl_disable(struct rtsx_pcr *pcr, int card);
873int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
874 u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk);
875int rtsx_pci_card_power_on(struct rtsx_pcr *pcr, int card);
876int rtsx_pci_card_power_off(struct rtsx_pcr *pcr, int card);
Wei WANGc3481952013-02-08 15:24:27 +0800877int rtsx_pci_card_exclusive_check(struct rtsx_pcr *pcr, int card);
Wei WANGd817ac42013-01-23 09:51:04 +0800878int rtsx_pci_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage);
Wei WANG67d16a42012-11-09 20:53:33 +0800879unsigned int rtsx_pci_card_exist(struct rtsx_pcr *pcr);
880void rtsx_pci_complete_unfinished_transfer(struct rtsx_pcr *pcr);
881
882static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr)
883{
884 return (u8 *)(pcr->host_cmds_ptr);
885}
886
887#endif