1 /* MOXART MMC/SD device driver (based on MOXA sources)
2 * Copyright (C) 2013 Jonas Jensen <jonas.jensen@gmail.com>
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2 of the License,
6 * or (at your option) any later version. */
13 #define MSD_RESP0_REG 8
14 #define MSD_RESP1_REG 0x0c
15 #define MSD_RESP2_REG 0x10
16 #define MSD_RESP3_REG 0x14
17 #define MSD_RESP_CMD_REG 0x18
18 #define MSD_DATA_CTRL_REG 0x1c
19 #define MSD_DATA_TIMER_REG 0x20
20 #define MSD_DATA_LEN_REG 0x24
21 #define MSD_STATUS_REG 0x28
22 #define MSD_CLEAR_REG 0x2c
23 #define MSD_INT_MASK_REG 0x30
24 #define MSD_POWER_CTRL_REG 0x34
25 #define MSD_CLOCK_CTRL_REG 0x38
26 #define MSD_BUS_WIDTH_REG 0x3c
27 #define MSD_DATA_WIN_REG 0x40
28 #define MSD_FEATURE_REG 0x44
29 #define MSD_REVISION_REG 0x48
32 #define MMC_RSP_SHORT (1 << 0)
33 #define MMC_RSP_LONG (2 << 0)
34 #define MMC_RSP_MASK (3 << 0)
35 #define MMC_ERR_NONE 0
36 #define MMC_ERR_TIMEOUT 1
37 #define MMC_MODE_MMC 0
39 #define MMC_ERR_BADCRC 2
40 #define MMC_VDD_360 23
42 #define MSD_RETRY_COUNT 100
44 #define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */
48 #define MSD_SDC_RST (1<<10)
49 #define MSD_CMD_EN (1<<9)
50 #define MSD_APP_CMD (1<<8)
51 #define MSD_LONG_RSP (1<<7)
52 #define MSD_NEED_RSP (1<<6)
53 #define MSD_CMD_IDX_MASK 0x3f
54 unsigned int argument
;
55 unsigned int response0
;
56 unsigned int response1
;
57 unsigned int response2
;
58 unsigned int response3
;
59 unsigned int response_command
;
60 #define MSD_RSP_CMD_APP (1<<6)
61 #define MSD_RSP_CMD_IDX_MASK 0x3f
62 unsigned int data_control
;
63 #define MSD_DATA_EN (1<<6)
64 #define MSD_DMA_EN (1<<5)
65 #define MSD_DATA_WRITE (1<<4)
66 #define MSD_BLK_SIZE_MASK 0x0f
67 unsigned int data_timer
;
68 unsigned int data_length
;
69 #define MSD_DATA_LEN_MASK 0xffffff
71 #define MSD_WRITE_PROT (1<<12)
72 #define MSD_CARD_DETECT (1<<11)
73 #define MSD_CARD_CHANGE (1<<10)
74 #define MSD_FIFO_ORUN (1<<9)
75 #define MSD_FIFO_URUN (1<<8)
76 #define MSD_DATA_END (1<<7)
77 #define MSD_CMD_SENT (1<<6)
78 #define MSD_DATA_CRC_OK (1<<5)
79 #define MSD_RSP_CRC_OK (1<<4)
80 #define MSD_DATA_TIMEOUT (1<<3)
81 #define MSD_RSP_TIMEOUT (1<<2)
82 #define MSD_DATA_CRC_FAIL (1<<1)
83 #define MSD_RSP_CRC_FAIL (1<<0)
85 #define MSD_CLR_CARD_CHANGE (1<<10)
86 #define MSD_CLR_FIFO_ORUN (1<<9)
87 #define MSD_CLR_FIFO_URUN (1<<8)
88 #define MSD_CLR_DATA_END (1<<7)
89 #define MSD_CLR_CMD_SENT (1<<6)
90 #define MSD_CLR_DATA_CRC_OK (1<<5)
91 #define MSD_CLR_RSP_CRC_OK (1<<4)
92 #define MSD_CLR_DATA_TIMEOUT (1<<3)
93 #define MSD_CLR_RSP_TIMEOUT (1<<2)
94 #define MSD_CLR_DATA_CRC_FAIL (1<<1)
95 #define MSD_CLR_RSP_CRC_FAIL (1<<0)
96 unsigned int interrupt_mask
;
97 #define MSD_INT_CARD_CHANGE (1<<10)
98 #define MSD_INT_FIFO_ORUN (1<<9)
99 #define MSD_INT_FIFO_URUN (1<<8)
100 #define MSD_INT_DATA_END (1<<7)
101 #define MSD_INT_CMD_SENT (1<<6)
102 #define MSD_INT_DATA_CRC_OK (1<<5)
103 #define MSD_INT_RSP_CRC_OK (1<<4)
104 #define MSD_INT_DATA_TIMEOUT (1<<3)
105 #define MSD_INT_RSP_TIMEOUT (1<<2)
106 #define MSD_INT_DATA_CRC_FAIL (1<<1)
107 #define MSD_INT_RSP_CRC_FAIL (1<<0)
108 unsigned int power_control
;
109 #define MSD_SD_POWER_ON (1<<4)
110 #define MSD_SD_POWER_MASK 0x0f
111 unsigned int clock_control
;
112 #define MSD_CLK_DIS (1<<8)
113 #define MSD_CLK_SD (1<<7)
114 #define MSD_CLK_DIV_MASK 0x7f
115 unsigned int bus_width
;
116 #define MSD_WIDE_BUS_SUPPORT (1<<3)
117 #define MSD_WIDE_BUS (1<<2) /* bus width=4 */
118 #define MSD_SINGLE_BUS (1<<0) /* bus width=1 */
119 unsigned int data_window
;
120 unsigned int feature
;
121 #define MSD_CPRM_FUNCTION (1<<8)
122 unsigned int revision
;
126 struct mmc_host
*mmc
;
128 struct moxart_reg
*reg
;
129 struct apb_dma_priv
*dma
;
130 #ifdef MSD_SUPPORT_GET_CLOCK
133 struct mmc_request
*mrq
;
134 struct mmc_data
*data
;
136 struct scatterlist
*cur_sg
; /* Current SG entry */
137 unsigned int num_sg
; /* Number of entries left */
138 void *mapped_sg
; /* vaddr of mapped sg */
139 unsigned int remain
; /* Data left in curren entry */
140 int size
; /* Total size of transfer */
142 struct tasklet_struct card_change_tasklet
;
143 struct tasklet_struct fifo_run_tasklet
;
146 #define MSD_FIFO_LENW 4 /* 4 words, total 4 * 4 = 16 bytes */
147 #define MSD_FIFO_LENB 16 /* 16 bytes */
149 #endif /* _MOXART_H */