ramips: move mtk-mmc driver code out of patches-*/ and into files-*/
[openwrt/openwrt.git] / target / linux / ramips / files-4.9 / drivers / mmc / host / mtk-mmc / mt6575_sd.h
1 /* Copyright Statement:
2 *
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
9 */
10 /* MediaTek Inc. (C) 2010. All rights reserved.
11 *
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30 *
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
34 */
35
36 #ifndef MT6575_SD_H
37 #define MT6575_SD_H
38
39 #include <linux/bitops.h>
40 #include <linux/mmc/host.h>
41
42 // #include <mach/mt6575_reg_base.h> /* --- by chhung */
43
44 /*--------------------------------------------------------------------------*/
45 /* Common Macro */
46 /*--------------------------------------------------------------------------*/
47 #define REG_ADDR(x) ((volatile u32*)(base + OFFSET_##x))
48
49 /*--------------------------------------------------------------------------*/
50 /* Common Definition */
51 /*--------------------------------------------------------------------------*/
52 #define MSDC_FIFO_SZ (128)
53 #define MSDC_FIFO_THD (64) // (128)
54 #define MSDC_NUM (4)
55
56 #define MSDC_MS (0)
57 #define MSDC_SDMMC (1)
58
59 #define MSDC_MODE_UNKNOWN (0)
60 #define MSDC_MODE_PIO (1)
61 #define MSDC_MODE_DMA_BASIC (2)
62 #define MSDC_MODE_DMA_DESC (3)
63 #define MSDC_MODE_DMA_ENHANCED (4)
64 #define MSDC_MODE_MMC_STREAM (5)
65
66 #define MSDC_BUS_1BITS (0)
67 #define MSDC_BUS_4BITS (1)
68 #define MSDC_BUS_8BITS (2)
69
70 #define MSDC_BRUST_8B (3)
71 #define MSDC_BRUST_16B (4)
72 #define MSDC_BRUST_32B (5)
73 #define MSDC_BRUST_64B (6)
74
75 #define MSDC_PIN_PULL_NONE (0)
76 #define MSDC_PIN_PULL_DOWN (1)
77 #define MSDC_PIN_PULL_UP (2)
78 #define MSDC_PIN_KEEP (3)
79
80 #define MSDC_MAX_SCLK (48000000) /* +/- by chhung */
81 #define MSDC_MIN_SCLK (260000)
82
83 #define MSDC_AUTOCMD12 (0x0001)
84 #define MSDC_AUTOCMD23 (0x0002)
85 #define MSDC_AUTOCMD19 (0x0003)
86
87 #define MSDC_EMMC_BOOTMODE0 (0) /* Pull low CMD mode */
88 #define MSDC_EMMC_BOOTMODE1 (1) /* Reset CMD mode */
89
90 enum {
91 RESP_NONE = 0,
92 RESP_R1,
93 RESP_R2,
94 RESP_R3,
95 RESP_R4,
96 RESP_R5,
97 RESP_R6,
98 RESP_R7,
99 RESP_R1B
100 };
101
102 /*--------------------------------------------------------------------------*/
103 /* Register Offset */
104 /*--------------------------------------------------------------------------*/
105 #define OFFSET_MSDC_CFG (0x0)
106 #define OFFSET_MSDC_IOCON (0x04)
107 #define OFFSET_MSDC_PS (0x08)
108 #define OFFSET_MSDC_INT (0x0c)
109 #define OFFSET_MSDC_INTEN (0x10)
110 #define OFFSET_MSDC_FIFOCS (0x14)
111 #define OFFSET_MSDC_TXDATA (0x18)
112 #define OFFSET_MSDC_RXDATA (0x1c)
113 #define OFFSET_SDC_CFG (0x30)
114 #define OFFSET_SDC_CMD (0x34)
115 #define OFFSET_SDC_ARG (0x38)
116 #define OFFSET_SDC_STS (0x3c)
117 #define OFFSET_SDC_RESP0 (0x40)
118 #define OFFSET_SDC_RESP1 (0x44)
119 #define OFFSET_SDC_RESP2 (0x48)
120 #define OFFSET_SDC_RESP3 (0x4c)
121 #define OFFSET_SDC_BLK_NUM (0x50)
122 #define OFFSET_SDC_CSTS (0x58)
123 #define OFFSET_SDC_CSTS_EN (0x5c)
124 #define OFFSET_SDC_DCRC_STS (0x60)
125 #define OFFSET_EMMC_CFG0 (0x70)
126 #define OFFSET_EMMC_CFG1 (0x74)
127 #define OFFSET_EMMC_STS (0x78)
128 #define OFFSET_EMMC_IOCON (0x7c)
129 #define OFFSET_SDC_ACMD_RESP (0x80)
130 #define OFFSET_SDC_ACMD19_TRG (0x84)
131 #define OFFSET_SDC_ACMD19_STS (0x88)
132 #define OFFSET_MSDC_DMA_SA (0x90)
133 #define OFFSET_MSDC_DMA_CA (0x94)
134 #define OFFSET_MSDC_DMA_CTRL (0x98)
135 #define OFFSET_MSDC_DMA_CFG (0x9c)
136 #define OFFSET_MSDC_DBG_SEL (0xa0)
137 #define OFFSET_MSDC_DBG_OUT (0xa4)
138 #define OFFSET_MSDC_PATCH_BIT (0xb0)
139 #define OFFSET_MSDC_PATCH_BIT1 (0xb4)
140 #define OFFSET_MSDC_PAD_CTL0 (0xe0)
141 #define OFFSET_MSDC_PAD_CTL1 (0xe4)
142 #define OFFSET_MSDC_PAD_CTL2 (0xe8)
143 #define OFFSET_MSDC_PAD_TUNE (0xec)
144 #define OFFSET_MSDC_DAT_RDDLY0 (0xf0)
145 #define OFFSET_MSDC_DAT_RDDLY1 (0xf4)
146 #define OFFSET_MSDC_HW_DBG (0xf8)
147 #define OFFSET_MSDC_VERSION (0x100)
148 #define OFFSET_MSDC_ECO_VER (0x104)
149
150 /*--------------------------------------------------------------------------*/
151 /* Register Address */
152 /*--------------------------------------------------------------------------*/
153
154 /* common register */
155 #define MSDC_CFG REG_ADDR(MSDC_CFG)
156 #define MSDC_IOCON REG_ADDR(MSDC_IOCON)
157 #define MSDC_PS REG_ADDR(MSDC_PS)
158 #define MSDC_INT REG_ADDR(MSDC_INT)
159 #define MSDC_INTEN REG_ADDR(MSDC_INTEN)
160 #define MSDC_FIFOCS REG_ADDR(MSDC_FIFOCS)
161 #define MSDC_TXDATA REG_ADDR(MSDC_TXDATA)
162 #define MSDC_RXDATA REG_ADDR(MSDC_RXDATA)
163 #define MSDC_PATCH_BIT0 REG_ADDR(MSDC_PATCH_BIT)
164
165 /* sdmmc register */
166 #define SDC_CFG REG_ADDR(SDC_CFG)
167 #define SDC_CMD REG_ADDR(SDC_CMD)
168 #define SDC_ARG REG_ADDR(SDC_ARG)
169 #define SDC_STS REG_ADDR(SDC_STS)
170 #define SDC_RESP0 REG_ADDR(SDC_RESP0)
171 #define SDC_RESP1 REG_ADDR(SDC_RESP1)
172 #define SDC_RESP2 REG_ADDR(SDC_RESP2)
173 #define SDC_RESP3 REG_ADDR(SDC_RESP3)
174 #define SDC_BLK_NUM REG_ADDR(SDC_BLK_NUM)
175 #define SDC_CSTS REG_ADDR(SDC_CSTS)
176 #define SDC_CSTS_EN REG_ADDR(SDC_CSTS_EN)
177 #define SDC_DCRC_STS REG_ADDR(SDC_DCRC_STS)
178
179 /* emmc register*/
180 #define EMMC_CFG0 REG_ADDR(EMMC_CFG0)
181 #define EMMC_CFG1 REG_ADDR(EMMC_CFG1)
182 #define EMMC_STS REG_ADDR(EMMC_STS)
183 #define EMMC_IOCON REG_ADDR(EMMC_IOCON)
184
185 /* auto command register */
186 #define SDC_ACMD_RESP REG_ADDR(SDC_ACMD_RESP)
187 #define SDC_ACMD19_TRG REG_ADDR(SDC_ACMD19_TRG)
188 #define SDC_ACMD19_STS REG_ADDR(SDC_ACMD19_STS)
189
190 /* dma register */
191 #define MSDC_DMA_SA REG_ADDR(MSDC_DMA_SA)
192 #define MSDC_DMA_CA REG_ADDR(MSDC_DMA_CA)
193 #define MSDC_DMA_CTRL REG_ADDR(MSDC_DMA_CTRL)
194 #define MSDC_DMA_CFG REG_ADDR(MSDC_DMA_CFG)
195
196 /* pad ctrl register */
197 #define MSDC_PAD_CTL0 REG_ADDR(MSDC_PAD_CTL0)
198 #define MSDC_PAD_CTL1 REG_ADDR(MSDC_PAD_CTL1)
199 #define MSDC_PAD_CTL2 REG_ADDR(MSDC_PAD_CTL2)
200
201 /* data read delay */
202 #define MSDC_DAT_RDDLY0 REG_ADDR(MSDC_DAT_RDDLY0)
203 #define MSDC_DAT_RDDLY1 REG_ADDR(MSDC_DAT_RDDLY1)
204
205 /* debug register */
206 #define MSDC_DBG_SEL REG_ADDR(MSDC_DBG_SEL)
207 #define MSDC_DBG_OUT REG_ADDR(MSDC_DBG_OUT)
208
209 /* misc register */
210 #define MSDC_PATCH_BIT REG_ADDR(MSDC_PATCH_BIT)
211 #define MSDC_PATCH_BIT1 REG_ADDR(MSDC_PATCH_BIT1)
212 #define MSDC_PAD_TUNE REG_ADDR(MSDC_PAD_TUNE)
213 #define MSDC_HW_DBG REG_ADDR(MSDC_HW_DBG)
214 #define MSDC_VERSION REG_ADDR(MSDC_VERSION)
215 #define MSDC_ECO_VER REG_ADDR(MSDC_ECO_VER) /* ECO Version */
216
217 /*--------------------------------------------------------------------------*/
218 /* Register Mask */
219 /*--------------------------------------------------------------------------*/
220
221 /* MSDC_CFG mask */
222 #define MSDC_CFG_MODE (0x1 << 0) /* RW */
223 #define MSDC_CFG_CKPDN (0x1 << 1) /* RW */
224 #define MSDC_CFG_RST (0x1 << 2) /* RW */
225 #define MSDC_CFG_PIO (0x1 << 3) /* RW */
226 #define MSDC_CFG_CKDRVEN (0x1 << 4) /* RW */
227 #define MSDC_CFG_BV18SDT (0x1 << 5) /* RW */
228 #define MSDC_CFG_BV18PSS (0x1 << 6) /* R */
229 #define MSDC_CFG_CKSTB (0x1 << 7) /* R */
230 #define MSDC_CFG_CKDIV (0xff << 8) /* RW */
231 #define MSDC_CFG_CKMOD (0x3 << 16) /* RW */
232
233 /* MSDC_IOCON mask */
234 #define MSDC_IOCON_SDR104CKS (0x1 << 0) /* RW */
235 #define MSDC_IOCON_RSPL (0x1 << 1) /* RW */
236 #define MSDC_IOCON_DSPL (0x1 << 2) /* RW */
237 #define MSDC_IOCON_DDLSEL (0x1 << 3) /* RW */
238 #define MSDC_IOCON_DDR50CKD (0x1 << 4) /* RW */
239 #define MSDC_IOCON_DSPLSEL (0x1 << 5) /* RW */
240 #define MSDC_IOCON_D0SPL (0x1 << 16) /* RW */
241 #define MSDC_IOCON_D1SPL (0x1 << 17) /* RW */
242 #define MSDC_IOCON_D2SPL (0x1 << 18) /* RW */
243 #define MSDC_IOCON_D3SPL (0x1 << 19) /* RW */
244 #define MSDC_IOCON_D4SPL (0x1 << 20) /* RW */
245 #define MSDC_IOCON_D5SPL (0x1 << 21) /* RW */
246 #define MSDC_IOCON_D6SPL (0x1 << 22) /* RW */
247 #define MSDC_IOCON_D7SPL (0x1 << 23) /* RW */
248 #define MSDC_IOCON_RISCSZ (0x3 << 24) /* RW */
249
250 /* MSDC_PS mask */
251 #define MSDC_PS_CDEN (0x1 << 0) /* RW */
252 #define MSDC_PS_CDSTS (0x1 << 1) /* R */
253 #define MSDC_PS_CDDEBOUNCE (0xf << 12) /* RW */
254 #define MSDC_PS_DAT (0xff << 16) /* R */
255 #define MSDC_PS_CMD (0x1 << 24) /* R */
256 #define MSDC_PS_WP (0x1UL<< 31) /* R */
257
258 /* MSDC_INT mask */
259 #define MSDC_INT_MMCIRQ (0x1 << 0) /* W1C */
260 #define MSDC_INT_CDSC (0x1 << 1) /* W1C */
261 #define MSDC_INT_ACMDRDY (0x1 << 3) /* W1C */
262 #define MSDC_INT_ACMDTMO (0x1 << 4) /* W1C */
263 #define MSDC_INT_ACMDCRCERR (0x1 << 5) /* W1C */
264 #define MSDC_INT_DMAQ_EMPTY (0x1 << 6) /* W1C */
265 #define MSDC_INT_SDIOIRQ (0x1 << 7) /* W1C */
266 #define MSDC_INT_CMDRDY (0x1 << 8) /* W1C */
267 #define MSDC_INT_CMDTMO (0x1 << 9) /* W1C */
268 #define MSDC_INT_RSPCRCERR (0x1 << 10) /* W1C */
269 #define MSDC_INT_CSTA (0x1 << 11) /* R */
270 #define MSDC_INT_XFER_COMPL (0x1 << 12) /* W1C */
271 #define MSDC_INT_DXFER_DONE (0x1 << 13) /* W1C */
272 #define MSDC_INT_DATTMO (0x1 << 14) /* W1C */
273 #define MSDC_INT_DATCRCERR (0x1 << 15) /* W1C */
274 #define MSDC_INT_ACMD19_DONE (0x1 << 16) /* W1C */
275
276 /* MSDC_INTEN mask */
277 #define MSDC_INTEN_MMCIRQ (0x1 << 0) /* RW */
278 #define MSDC_INTEN_CDSC (0x1 << 1) /* RW */
279 #define MSDC_INTEN_ACMDRDY (0x1 << 3) /* RW */
280 #define MSDC_INTEN_ACMDTMO (0x1 << 4) /* RW */
281 #define MSDC_INTEN_ACMDCRCERR (0x1 << 5) /* RW */
282 #define MSDC_INTEN_DMAQ_EMPTY (0x1 << 6) /* RW */
283 #define MSDC_INTEN_SDIOIRQ (0x1 << 7) /* RW */
284 #define MSDC_INTEN_CMDRDY (0x1 << 8) /* RW */
285 #define MSDC_INTEN_CMDTMO (0x1 << 9) /* RW */
286 #define MSDC_INTEN_RSPCRCERR (0x1 << 10) /* RW */
287 #define MSDC_INTEN_CSTA (0x1 << 11) /* RW */
288 #define MSDC_INTEN_XFER_COMPL (0x1 << 12) /* RW */
289 #define MSDC_INTEN_DXFER_DONE (0x1 << 13) /* RW */
290 #define MSDC_INTEN_DATTMO (0x1 << 14) /* RW */
291 #define MSDC_INTEN_DATCRCERR (0x1 << 15) /* RW */
292 #define MSDC_INTEN_ACMD19_DONE (0x1 << 16) /* RW */
293
294 /* MSDC_FIFOCS mask */
295 #define MSDC_FIFOCS_RXCNT (0xff << 0) /* R */
296 #define MSDC_FIFOCS_TXCNT (0xff << 16) /* R */
297 #define MSDC_FIFOCS_CLR (0x1UL<< 31) /* RW */
298
299 /* SDC_CFG mask */
300 #define SDC_CFG_SDIOINTWKUP (0x1 << 0) /* RW */
301 #define SDC_CFG_INSWKUP (0x1 << 1) /* RW */
302 #define SDC_CFG_BUSWIDTH (0x3 << 16) /* RW */
303 #define SDC_CFG_SDIO (0x1 << 19) /* RW */
304 #define SDC_CFG_SDIOIDE (0x1 << 20) /* RW */
305 #define SDC_CFG_INTATGAP (0x1 << 21) /* RW */
306 #define SDC_CFG_DTOC (0xffUL << 24) /* RW */
307
308 /* SDC_CMD mask */
309 #define SDC_CMD_OPC (0x3f << 0) /* RW */
310 #define SDC_CMD_BRK (0x1 << 6) /* RW */
311 #define SDC_CMD_RSPTYP (0x7 << 7) /* RW */
312 #define SDC_CMD_DTYP (0x3 << 11) /* RW */
313 #define SDC_CMD_DTYP (0x3 << 11) /* RW */
314 #define SDC_CMD_RW (0x1 << 13) /* RW */
315 #define SDC_CMD_STOP (0x1 << 14) /* RW */
316 #define SDC_CMD_GOIRQ (0x1 << 15) /* RW */
317 #define SDC_CMD_BLKLEN (0xfff<< 16) /* RW */
318 #define SDC_CMD_AUTOCMD (0x3 << 28) /* RW */
319 #define SDC_CMD_VOLSWTH (0x1 << 30) /* RW */
320
321 /* SDC_STS mask */
322 #define SDC_STS_SDCBUSY (0x1 << 0) /* RW */
323 #define SDC_STS_CMDBUSY (0x1 << 1) /* RW */
324 #define SDC_STS_SWR_COMPL (0x1 << 31) /* RW */
325
326 /* SDC_DCRC_STS mask */
327 #define SDC_DCRC_STS_NEG (0xf << 8) /* RO */
328 #define SDC_DCRC_STS_POS (0xff << 0) /* RO */
329
330 /* EMMC_CFG0 mask */
331 #define EMMC_CFG0_BOOTSTART (0x1 << 0) /* W */
332 #define EMMC_CFG0_BOOTSTOP (0x1 << 1) /* W */
333 #define EMMC_CFG0_BOOTMODE (0x1 << 2) /* RW */
334 #define EMMC_CFG0_BOOTACKDIS (0x1 << 3) /* RW */
335 #define EMMC_CFG0_BOOTWDLY (0x7 << 12) /* RW */
336 #define EMMC_CFG0_BOOTSUPP (0x1 << 15) /* RW */
337
338 /* EMMC_CFG1 mask */
339 #define EMMC_CFG1_BOOTDATTMC (0xfffff << 0) /* RW */
340 #define EMMC_CFG1_BOOTACKTMC (0xfffUL << 20) /* RW */
341
342 /* EMMC_STS mask */
343 #define EMMC_STS_BOOTCRCERR (0x1 << 0) /* W1C */
344 #define EMMC_STS_BOOTACKERR (0x1 << 1) /* W1C */
345 #define EMMC_STS_BOOTDATTMO (0x1 << 2) /* W1C */
346 #define EMMC_STS_BOOTACKTMO (0x1 << 3) /* W1C */
347 #define EMMC_STS_BOOTUPSTATE (0x1 << 4) /* R */
348 #define EMMC_STS_BOOTACKRCV (0x1 << 5) /* W1C */
349 #define EMMC_STS_BOOTDATRCV (0x1 << 6) /* R */
350
351 /* EMMC_IOCON mask */
352 #define EMMC_IOCON_BOOTRST (0x1 << 0) /* RW */
353
354 /* SDC_ACMD19_TRG mask */
355 #define SDC_ACMD19_TRG_TUNESEL (0xf << 0) /* RW */
356
357 /* MSDC_DMA_CTRL mask */
358 #define MSDC_DMA_CTRL_START (0x1 << 0) /* W */
359 #define MSDC_DMA_CTRL_STOP (0x1 << 1) /* W */
360 #define MSDC_DMA_CTRL_RESUME (0x1 << 2) /* W */
361 #define MSDC_DMA_CTRL_MODE (0x1 << 8) /* RW */
362 #define MSDC_DMA_CTRL_LASTBUF (0x1 << 10) /* RW */
363 #define MSDC_DMA_CTRL_BRUSTSZ (0x7 << 12) /* RW */
364 #define MSDC_DMA_CTRL_XFERSZ (0xffffUL << 16)/* RW */
365
366 /* MSDC_DMA_CFG mask */
367 #define MSDC_DMA_CFG_STS (0x1 << 0) /* R */
368 #define MSDC_DMA_CFG_DECSEN (0x1 << 1) /* RW */
369 #define MSDC_DMA_CFG_BDCSERR (0x1 << 4) /* R */
370 #define MSDC_DMA_CFG_GPDCSERR (0x1 << 5) /* R */
371
372 /* MSDC_PATCH_BIT mask */
373 #define MSDC_PATCH_BIT_WFLSMODE (0x1 << 0) /* RW */
374 #define MSDC_PATCH_BIT_ODDSUPP (0x1 << 1) /* RW */
375 #define MSDC_PATCH_BIT_CKGEN_CK (0x1 << 6) /* E2: Fixed to 1 */
376 #define MSDC_PATCH_BIT_IODSSEL (0x1 << 16) /* RW */
377 #define MSDC_PATCH_BIT_IOINTSEL (0x1 << 17) /* RW */
378 #define MSDC_PATCH_BIT_BUSYDLY (0xf << 18) /* RW */
379 #define MSDC_PATCH_BIT_WDOD (0xf << 22) /* RW */
380 #define MSDC_PATCH_BIT_IDRTSEL (0x1 << 26) /* RW */
381 #define MSDC_PATCH_BIT_CMDFSEL (0x1 << 27) /* RW */
382 #define MSDC_PATCH_BIT_INTDLSEL (0x1 << 28) /* RW */
383 #define MSDC_PATCH_BIT_SPCPUSH (0x1 << 29) /* RW */
384 #define MSDC_PATCH_BIT_DECRCTMO (0x1 << 30) /* RW */
385
386 /* MSDC_PATCH_BIT1 mask */
387 #define MSDC_PATCH_BIT1_WRDAT_CRCS (0x7 << 3)
388 #define MSDC_PATCH_BIT1_CMD_RSP (0x7 << 0)
389
390 /* MSDC_PAD_CTL0 mask */
391 #define MSDC_PAD_CTL0_CLKDRVN (0x7 << 0) /* RW */
392 #define MSDC_PAD_CTL0_CLKDRVP (0x7 << 4) /* RW */
393 #define MSDC_PAD_CTL0_CLKSR (0x1 << 8) /* RW */
394 #define MSDC_PAD_CTL0_CLKPD (0x1 << 16) /* RW */
395 #define MSDC_PAD_CTL0_CLKPU (0x1 << 17) /* RW */
396 #define MSDC_PAD_CTL0_CLKSMT (0x1 << 18) /* RW */
397 #define MSDC_PAD_CTL0_CLKIES (0x1 << 19) /* RW */
398 #define MSDC_PAD_CTL0_CLKTDSEL (0xf << 20) /* RW */
399 #define MSDC_PAD_CTL0_CLKRDSEL (0xffUL<< 24) /* RW */
400
401 /* MSDC_PAD_CTL1 mask */
402 #define MSDC_PAD_CTL1_CMDDRVN (0x7 << 0) /* RW */
403 #define MSDC_PAD_CTL1_CMDDRVP (0x7 << 4) /* RW */
404 #define MSDC_PAD_CTL1_CMDSR (0x1 << 8) /* RW */
405 #define MSDC_PAD_CTL1_CMDPD (0x1 << 16) /* RW */
406 #define MSDC_PAD_CTL1_CMDPU (0x1 << 17) /* RW */
407 #define MSDC_PAD_CTL1_CMDSMT (0x1 << 18) /* RW */
408 #define MSDC_PAD_CTL1_CMDIES (0x1 << 19) /* RW */
409 #define MSDC_PAD_CTL1_CMDTDSEL (0xf << 20) /* RW */
410 #define MSDC_PAD_CTL1_CMDRDSEL (0xffUL<< 24) /* RW */
411
412 /* MSDC_PAD_CTL2 mask */
413 #define MSDC_PAD_CTL2_DATDRVN (0x7 << 0) /* RW */
414 #define MSDC_PAD_CTL2_DATDRVP (0x7 << 4) /* RW */
415 #define MSDC_PAD_CTL2_DATSR (0x1 << 8) /* RW */
416 #define MSDC_PAD_CTL2_DATPD (0x1 << 16) /* RW */
417 #define MSDC_PAD_CTL2_DATPU (0x1 << 17) /* RW */
418 #define MSDC_PAD_CTL2_DATIES (0x1 << 19) /* RW */
419 #define MSDC_PAD_CTL2_DATSMT (0x1 << 18) /* RW */
420 #define MSDC_PAD_CTL2_DATTDSEL (0xf << 20) /* RW */
421 #define MSDC_PAD_CTL2_DATRDSEL (0xffUL<< 24) /* RW */
422
423 /* MSDC_PAD_TUNE mask */
424 #define MSDC_PAD_TUNE_DATWRDLY (0x1F << 0) /* RW */
425 #define MSDC_PAD_TUNE_DATRRDLY (0x1F << 8) /* RW */
426 #define MSDC_PAD_TUNE_CMDRDLY (0x1F << 16) /* RW */
427 #define MSDC_PAD_TUNE_CMDRRDLY (0x1FUL << 22) /* RW */
428 #define MSDC_PAD_TUNE_CLKTXDLY (0x1FUL << 27) /* RW */
429
430 /* MSDC_DAT_RDDLY0/1 mask */
431 #define MSDC_DAT_RDDLY0_D0 (0x1F << 0) /* RW */
432 #define MSDC_DAT_RDDLY0_D1 (0x1F << 8) /* RW */
433 #define MSDC_DAT_RDDLY0_D2 (0x1F << 16) /* RW */
434 #define MSDC_DAT_RDDLY0_D3 (0x1F << 24) /* RW */
435
436 #define MSDC_DAT_RDDLY1_D4 (0x1F << 0) /* RW */
437 #define MSDC_DAT_RDDLY1_D5 (0x1F << 8) /* RW */
438 #define MSDC_DAT_RDDLY1_D6 (0x1F << 16) /* RW */
439 #define MSDC_DAT_RDDLY1_D7 (0x1F << 24) /* RW */
440
441 #define MSDC_CKGEN_MSDC_DLY_SEL (0x1F<<10)
442 #define MSDC_INT_DAT_LATCH_CK_SEL (0x7<<7)
443 #define MSDC_CKGEN_MSDC_CK_SEL (0x1<<6)
444 #define CARD_READY_FOR_DATA (1<<8)
445 #define CARD_CURRENT_STATE(x) ((x&0x00001E00)>>9)
446
447 /*--------------------------------------------------------------------------*/
448 /* Descriptor Structure */
449 /*--------------------------------------------------------------------------*/
450 typedef struct {
451 u32 hwo:1; /* could be changed by hw */
452 u32 bdp:1;
453 u32 rsv0:6;
454 u32 chksum:8;
455 u32 intr:1;
456 u32 rsv1:15;
457 void *next;
458 void *ptr;
459 u32 buflen:16;
460 u32 extlen:8;
461 u32 rsv2:8;
462 u32 arg;
463 u32 blknum;
464 u32 cmd;
465 } gpd_t;
466
467 typedef struct {
468 u32 eol:1;
469 u32 rsv0:7;
470 u32 chksum:8;
471 u32 rsv1:1;
472 u32 blkpad:1;
473 u32 dwpad:1;
474 u32 rsv2:13;
475 void *next;
476 void *ptr;
477 u32 buflen:16;
478 u32 rsv3:16;
479 } bd_t;
480
481 /*--------------------------------------------------------------------------*/
482 /* Register Debugging Structure */
483 /*--------------------------------------------------------------------------*/
484
485 typedef struct {
486 u32 msdc:1;
487 u32 ckpwn:1;
488 u32 rst:1;
489 u32 pio:1;
490 u32 ckdrven:1;
491 u32 start18v:1;
492 u32 pass18v:1;
493 u32 ckstb:1;
494 u32 ckdiv:8;
495 u32 ckmod:2;
496 u32 pad:14;
497 } msdc_cfg_reg;
498 typedef struct {
499 u32 sdr104cksel:1;
500 u32 rsmpl:1;
501 u32 dsmpl:1;
502 u32 ddlysel:1;
503 u32 ddr50ckd:1;
504 u32 dsplsel:1;
505 u32 pad1:10;
506 u32 d0spl:1;
507 u32 d1spl:1;
508 u32 d2spl:1;
509 u32 d3spl:1;
510 u32 d4spl:1;
511 u32 d5spl:1;
512 u32 d6spl:1;
513 u32 d7spl:1;
514 u32 riscsz:1;
515 u32 pad2:7;
516 } msdc_iocon_reg;
517 typedef struct {
518 u32 cden:1;
519 u32 cdsts:1;
520 u32 pad1:10;
521 u32 cddebounce:4;
522 u32 dat:8;
523 u32 cmd:1;
524 u32 pad2:6;
525 u32 wp:1;
526 } msdc_ps_reg;
527 typedef struct {
528 u32 mmcirq:1;
529 u32 cdsc:1;
530 u32 pad1:1;
531 u32 atocmdrdy:1;
532 u32 atocmdtmo:1;
533 u32 atocmdcrc:1;
534 u32 dmaqempty:1;
535 u32 sdioirq:1;
536 u32 cmdrdy:1;
537 u32 cmdtmo:1;
538 u32 rspcrc:1;
539 u32 csta:1;
540 u32 xfercomp:1;
541 u32 dxferdone:1;
542 u32 dattmo:1;
543 u32 datcrc:1;
544 u32 atocmd19done:1;
545 u32 pad2:15;
546 } msdc_int_reg;
547 typedef struct {
548 u32 mmcirq:1;
549 u32 cdsc:1;
550 u32 pad1:1;
551 u32 atocmdrdy:1;
552 u32 atocmdtmo:1;
553 u32 atocmdcrc:1;
554 u32 dmaqempty:1;
555 u32 sdioirq:1;
556 u32 cmdrdy:1;
557 u32 cmdtmo:1;
558 u32 rspcrc:1;
559 u32 csta:1;
560 u32 xfercomp:1;
561 u32 dxferdone:1;
562 u32 dattmo:1;
563 u32 datcrc:1;
564 u32 atocmd19done:1;
565 u32 pad2:15;
566 } msdc_inten_reg;
567 typedef struct {
568 u32 rxcnt:8;
569 u32 pad1:8;
570 u32 txcnt:8;
571 u32 pad2:7;
572 u32 clr:1;
573 } msdc_fifocs_reg;
574 typedef struct {
575 u32 val;
576 } msdc_txdat_reg;
577 typedef struct {
578 u32 val;
579 } msdc_rxdat_reg;
580 typedef struct {
581 u32 sdiowkup:1;
582 u32 inswkup:1;
583 u32 pad1:14;
584 u32 buswidth:2;
585 u32 pad2:1;
586 u32 sdio:1;
587 u32 sdioide:1;
588 u32 intblkgap:1;
589 u32 pad4:2;
590 u32 dtoc:8;
591 } sdc_cfg_reg;
592 typedef struct {
593 u32 cmd:6;
594 u32 brk:1;
595 u32 rsptyp:3;
596 u32 pad1:1;
597 u32 dtype:2;
598 u32 rw:1;
599 u32 stop:1;
600 u32 goirq:1;
601 u32 blklen:12;
602 u32 atocmd:2;
603 u32 volswth:1;
604 u32 pad2:1;
605 } sdc_cmd_reg;
606 typedef struct {
607 u32 arg;
608 } sdc_arg_reg;
609 typedef struct {
610 u32 sdcbusy:1;
611 u32 cmdbusy:1;
612 u32 pad:29;
613 u32 swrcmpl:1;
614 } sdc_sts_reg;
615 typedef struct {
616 u32 val;
617 } sdc_resp0_reg;
618 typedef struct {
619 u32 val;
620 } sdc_resp1_reg;
621 typedef struct {
622 u32 val;
623 } sdc_resp2_reg;
624 typedef struct {
625 u32 val;
626 } sdc_resp3_reg;
627 typedef struct {
628 u32 num;
629 } sdc_blknum_reg;
630 typedef struct {
631 u32 sts;
632 } sdc_csts_reg;
633 typedef struct {
634 u32 sts;
635 } sdc_cstsen_reg;
636 typedef struct {
637 u32 datcrcsts:8;
638 u32 ddrcrcsts:4;
639 u32 pad:20;
640 } sdc_datcrcsts_reg;
641 typedef struct {
642 u32 bootstart:1;
643 u32 bootstop:1;
644 u32 bootmode:1;
645 u32 pad1:9;
646 u32 bootwaidly:3;
647 u32 bootsupp:1;
648 u32 pad2:16;
649 } emmc_cfg0_reg;
650 typedef struct {
651 u32 bootcrctmc:16;
652 u32 pad:4;
653 u32 bootacktmc:12;
654 } emmc_cfg1_reg;
655 typedef struct {
656 u32 bootcrcerr:1;
657 u32 bootackerr:1;
658 u32 bootdattmo:1;
659 u32 bootacktmo:1;
660 u32 bootupstate:1;
661 u32 bootackrcv:1;
662 u32 bootdatrcv:1;
663 u32 pad:25;
664 } emmc_sts_reg;
665 typedef struct {
666 u32 bootrst:1;
667 u32 pad:31;
668 } emmc_iocon_reg;
669 typedef struct {
670 u32 val;
671 } msdc_acmd_resp_reg;
672 typedef struct {
673 u32 tunesel:4;
674 u32 pad:28;
675 } msdc_acmd19_trg_reg;
676 typedef struct {
677 u32 val;
678 } msdc_acmd19_sts_reg;
679 typedef struct {
680 u32 addr;
681 } msdc_dma_sa_reg;
682 typedef struct {
683 u32 addr;
684 } msdc_dma_ca_reg;
685 typedef struct {
686 u32 start:1;
687 u32 stop:1;
688 u32 resume:1;
689 u32 pad1:5;
690 u32 mode:1;
691 u32 pad2:1;
692 u32 lastbuf:1;
693 u32 pad3:1;
694 u32 brustsz:3;
695 u32 pad4:1;
696 u32 xfersz:16;
697 } msdc_dma_ctrl_reg;
698 typedef struct {
699 u32 status:1;
700 u32 decsen:1;
701 u32 pad1:2;
702 u32 bdcsen:1;
703 u32 gpdcsen:1;
704 u32 pad2:26;
705 } msdc_dma_cfg_reg;
706 typedef struct {
707 u32 sel:16;
708 u32 pad2:16;
709 } msdc_dbg_sel_reg;
710 typedef struct {
711 u32 val;
712 } msdc_dbg_out_reg;
713 typedef struct {
714 u32 clkdrvn:3;
715 u32 rsv0:1;
716 u32 clkdrvp:3;
717 u32 rsv1:1;
718 u32 clksr:1;
719 u32 rsv2:7;
720 u32 clkpd:1;
721 u32 clkpu:1;
722 u32 clksmt:1;
723 u32 clkies:1;
724 u32 clktdsel:4;
725 u32 clkrdsel:8;
726 } msdc_pad_ctl0_reg;
727 typedef struct {
728 u32 cmddrvn:3;
729 u32 rsv0:1;
730 u32 cmddrvp:3;
731 u32 rsv1:1;
732 u32 cmdsr:1;
733 u32 rsv2:7;
734 u32 cmdpd:1;
735 u32 cmdpu:1;
736 u32 cmdsmt:1;
737 u32 cmdies:1;
738 u32 cmdtdsel:4;
739 u32 cmdrdsel:8;
740 } msdc_pad_ctl1_reg;
741 typedef struct {
742 u32 datdrvn:3;
743 u32 rsv0:1;
744 u32 datdrvp:3;
745 u32 rsv1:1;
746 u32 datsr:1;
747 u32 rsv2:7;
748 u32 datpd:1;
749 u32 datpu:1;
750 u32 datsmt:1;
751 u32 daties:1;
752 u32 dattdsel:4;
753 u32 datrdsel:8;
754 } msdc_pad_ctl2_reg;
755 typedef struct {
756 u32 wrrxdly:3;
757 u32 pad1:5;
758 u32 rdrxdly:8;
759 u32 pad2:16;
760 } msdc_pad_tune_reg;
761 typedef struct {
762 u32 dat0:5;
763 u32 rsv0:3;
764 u32 dat1:5;
765 u32 rsv1:3;
766 u32 dat2:5;
767 u32 rsv2:3;
768 u32 dat3:5;
769 u32 rsv3:3;
770 } msdc_dat_rddly0;
771 typedef struct {
772 u32 dat4:5;
773 u32 rsv4:3;
774 u32 dat5:5;
775 u32 rsv5:3;
776 u32 dat6:5;
777 u32 rsv6:3;
778 u32 dat7:5;
779 u32 rsv7:3;
780 } msdc_dat_rddly1;
781 typedef struct {
782 u32 dbg0sel:8;
783 u32 dbg1sel:6;
784 u32 pad1:2;
785 u32 dbg2sel:6;
786 u32 pad2:2;
787 u32 dbg3sel:6;
788 u32 pad3:2;
789 } msdc_hw_dbg_reg;
790 typedef struct {
791 u32 val;
792 } msdc_version_reg;
793 typedef struct {
794 u32 val;
795 } msdc_eco_ver_reg;
796
797 struct msdc_regs {
798 msdc_cfg_reg msdc_cfg; /* base+0x00h */
799 msdc_iocon_reg msdc_iocon; /* base+0x04h */
800 msdc_ps_reg msdc_ps; /* base+0x08h */
801 msdc_int_reg msdc_int; /* base+0x0ch */
802 msdc_inten_reg msdc_inten; /* base+0x10h */
803 msdc_fifocs_reg msdc_fifocs; /* base+0x14h */
804 msdc_txdat_reg msdc_txdat; /* base+0x18h */
805 msdc_rxdat_reg msdc_rxdat; /* base+0x1ch */
806 u32 rsv1[4];
807 sdc_cfg_reg sdc_cfg; /* base+0x30h */
808 sdc_cmd_reg sdc_cmd; /* base+0x34h */
809 sdc_arg_reg sdc_arg; /* base+0x38h */
810 sdc_sts_reg sdc_sts; /* base+0x3ch */
811 sdc_resp0_reg sdc_resp0; /* base+0x40h */
812 sdc_resp1_reg sdc_resp1; /* base+0x44h */
813 sdc_resp2_reg sdc_resp2; /* base+0x48h */
814 sdc_resp3_reg sdc_resp3; /* base+0x4ch */
815 sdc_blknum_reg sdc_blknum; /* base+0x50h */
816 u32 rsv2[1];
817 sdc_csts_reg sdc_csts; /* base+0x58h */
818 sdc_cstsen_reg sdc_cstsen; /* base+0x5ch */
819 sdc_datcrcsts_reg sdc_dcrcsta; /* base+0x60h */
820 u32 rsv3[3];
821 emmc_cfg0_reg emmc_cfg0; /* base+0x70h */
822 emmc_cfg1_reg emmc_cfg1; /* base+0x74h */
823 emmc_sts_reg emmc_sts; /* base+0x78h */
824 emmc_iocon_reg emmc_iocon; /* base+0x7ch */
825 msdc_acmd_resp_reg acmd_resp; /* base+0x80h */
826 msdc_acmd19_trg_reg acmd19_trg; /* base+0x84h */
827 msdc_acmd19_sts_reg acmd19_sts; /* base+0x88h */
828 u32 rsv4[1];
829 msdc_dma_sa_reg dma_sa; /* base+0x90h */
830 msdc_dma_ca_reg dma_ca; /* base+0x94h */
831 msdc_dma_ctrl_reg dma_ctrl; /* base+0x98h */
832 msdc_dma_cfg_reg dma_cfg; /* base+0x9ch */
833 msdc_dbg_sel_reg dbg_sel; /* base+0xa0h */
834 msdc_dbg_out_reg dbg_out; /* base+0xa4h */
835 u32 rsv5[2];
836 u32 patch0; /* base+0xb0h */
837 u32 patch1; /* base+0xb4h */
838 u32 rsv6[10];
839 msdc_pad_ctl0_reg pad_ctl0; /* base+0xe0h */
840 msdc_pad_ctl1_reg pad_ctl1; /* base+0xe4h */
841 msdc_pad_ctl2_reg pad_ctl2; /* base+0xe8h */
842 msdc_pad_tune_reg pad_tune; /* base+0xech */
843 msdc_dat_rddly0 dat_rddly0; /* base+0xf0h */
844 msdc_dat_rddly1 dat_rddly1; /* base+0xf4h */
845 msdc_hw_dbg_reg hw_dbg; /* base+0xf8h */
846 u32 rsv7[1];
847 msdc_version_reg version; /* base+0x100h */
848 msdc_eco_ver_reg eco_ver; /* base+0x104h */
849 };
850
851 struct scatterlist_ex {
852 u32 cmd;
853 u32 arg;
854 u32 sglen;
855 struct scatterlist *sg;
856 };
857
858 #define DMA_FLAG_NONE (0x00000000)
859 #define DMA_FLAG_EN_CHKSUM (0x00000001)
860 #define DMA_FLAG_PAD_BLOCK (0x00000002)
861 #define DMA_FLAG_PAD_DWORD (0x00000004)
862
863 struct msdc_dma {
864 u32 flags; /* flags */
865 u32 xfersz; /* xfer size in bytes */
866 u32 sglen; /* size of scatter list */
867 u32 blklen; /* block size */
868 struct scatterlist *sg; /* I/O scatter list */
869 struct scatterlist_ex *esg; /* extended I/O scatter list */
870 u8 mode; /* dma mode */
871 u8 burstsz; /* burst size */
872 u8 intr; /* dma done interrupt */
873 u8 padding; /* padding */
874 u32 cmd; /* enhanced mode command */
875 u32 arg; /* enhanced mode arg */
876 u32 rsp; /* enhanced mode command response */
877 u32 autorsp; /* auto command response */
878
879 gpd_t *gpd; /* pointer to gpd array */
880 bd_t *bd; /* pointer to bd array */
881 dma_addr_t gpd_addr; /* the physical address of gpd array */
882 dma_addr_t bd_addr; /* the physical address of bd array */
883 u32 used_gpd; /* the number of used gpd elements */
884 u32 used_bd; /* the number of used bd elements */
885 };
886
887 struct msdc_host
888 {
889 struct msdc_hw *hw;
890
891 struct mmc_host *mmc; /* mmc structure */
892 struct mmc_command *cmd;
893 struct mmc_data *data;
894 struct mmc_request *mrq;
895 int cmd_rsp;
896 int cmd_rsp_done;
897 int cmd_r1b_done;
898
899 int error;
900 spinlock_t lock; /* mutex */
901 struct semaphore sem;
902
903 u32 blksz; /* host block size */
904 u32 base; /* host base address */
905 int id; /* host id */
906 int pwr_ref; /* core power reference count */
907
908 u32 xfer_size; /* total transferred size */
909
910 struct msdc_dma dma; /* dma channel */
911 u32 dma_addr; /* dma transfer address */
912 u32 dma_left_size; /* dma transfer left size */
913 u32 dma_xfer_size; /* dma transfer size in bytes */
914 int dma_xfer; /* dma transfer mode */
915
916 u32 timeout_ns; /* data timeout ns */
917 u32 timeout_clks; /* data timeout clks */
918
919 atomic_t abort; /* abort transfer */
920
921 int irq; /* host interrupt */
922
923 struct tasklet_struct card_tasklet;
924 #if 0
925 struct work_struct card_workqueue;
926 #else
927 struct delayed_work card_delaywork;
928 #endif
929
930 struct completion cmd_done;
931 struct completion xfer_done;
932 struct pm_message pm_state;
933
934 u32 mclk; /* mmc subsystem clock */
935 u32 hclk; /* host clock speed */
936 u32 sclk; /* SD/MS clock speed */
937 u8 core_clkon; /* Host core clock on ? */
938 u8 card_clkon; /* Card clock on ? */
939 u8 core_power; /* core power */
940 u8 power_mode; /* host power mode */
941 u8 card_inserted; /* card inserted ? */
942 u8 suspend; /* host suspended ? */
943 u8 reserved;
944 u8 app_cmd; /* for app command */
945 u32 app_cmd_arg;
946 u64 starttime;
947 };
948
949 static inline unsigned int uffs(unsigned int x)
950 {
951 unsigned int r = 1;
952
953 if (!x)
954 return 0;
955 if (!(x & 0xffff)) {
956 x >>= 16;
957 r += 16;
958 }
959 if (!(x & 0xff)) {
960 x >>= 8;
961 r += 8;
962 }
963 if (!(x & 0xf)) {
964 x >>= 4;
965 r += 4;
966 }
967 if (!(x & 3)) {
968 x >>= 2;
969 r += 2;
970 }
971 if (!(x & 1)) {
972 x >>= 1;
973 r += 1;
974 }
975 return r;
976 }
977 #define sdr_read8(reg) __raw_readb(reg)
978 #define sdr_read16(reg) __raw_readw(reg)
979 #define sdr_read32(reg) __raw_readl(reg)
980 #define sdr_write8(reg,val) __raw_writeb(val,reg)
981 #define sdr_write16(reg,val) __raw_writew(val,reg)
982 #define sdr_write32(reg,val) __raw_writel(val,reg)
983
984 #define sdr_set_bits(reg,bs) ((*(volatile u32*)(reg)) |= (u32)(bs))
985 #define sdr_clr_bits(reg,bs) ((*(volatile u32*)(reg)) &= ~((u32)(bs)))
986
987 #define sdr_set_field(reg,field,val) \
988 do { \
989 volatile unsigned int tv = sdr_read32(reg); \
990 tv &= ~(field); \
991 tv |= ((val) << (uffs((unsigned int)field) - 1)); \
992 sdr_write32(reg,tv); \
993 } while(0)
994 #define sdr_get_field(reg,field,val) \
995 do { \
996 volatile unsigned int tv = sdr_read32(reg); \
997 val = ((tv & (field)) >> (uffs((unsigned int)field) - 1)); \
998 } while(0)
999
1000 #endif
1001