1 /* Copyright Statement:
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.
10 * MediaTek Inc. (C) 2010. All rights reserved.
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.
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.
36 #include <linux/module.h>
37 #include <linux/delay.h>
38 #include <linux/dma-mapping.h>
39 #include <linux/spinlock.h>
40 #include <linux/platform_device.h>
41 #include <linux/interrupt.h>
44 #include <linux/mmc/host.h>
45 #include <linux/mmc/mmc.h>
46 #include <linux/mmc/sd.h>
47 #include <linux/mmc/sdio.h>
49 #include <asm/mach-ralink/ralink_regs.h>
53 #include "mt6575_sd.h"
55 //#define IRQ_SDC 14 //MT7620 /*FIXME*/
56 #ifdef CONFIG_SOC_MT7621
57 #define RALINK_SYSCTL_BASE 0xbe000000
58 #define RALINK_MSDC_BASE 0xbe130000
60 #define RALINK_SYSCTL_BASE 0xb0000000
61 #define RALINK_MSDC_BASE 0xb0130000
63 #define IRQ_SDC 22 /*FIXME*/
65 #define DRV_NAME "mtk-sd"
67 #if defined(CONFIG_SOC_MT7620)
68 #define HOST_MAX_MCLK (48000000) /* +/- by chhung */
69 #elif defined(CONFIG_SOC_MT7621)
70 #define HOST_MAX_MCLK (50000000) /* +/- by chhung */
72 #define HOST_MIN_MCLK (260000)
74 #define HOST_MAX_BLKSZ (2048)
76 #define MSDC_OCR_AVAIL (MMC_VDD_28_29 | MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33)
78 #define GPIO_PULL_DOWN (0)
79 #define GPIO_PULL_UP (1)
81 #if 0 /* --- by chhung */
82 #define MSDC_CLKSRC_REG (0xf100000C)
83 #define PDN_REG (0xF1000010)
84 #endif /* end of --- */
86 #define DEFAULT_DEBOUNCE (8) /* 8 cycles */
87 #define DEFAULT_DTOC (40) /* data timeout counter. 65536x40 sclk. */
89 #define CMD_TIMEOUT (HZ / 10) /* 100ms */
90 #define DAT_TIMEOUT (HZ / 2 * 5) /* 500ms x5 */
92 #define MAX_DMA_CNT (64 * 1024 - 512) /* a single transaction for WIFI may be 50K*/
94 #define MAX_GPD_NUM (1 + 1) /* one null gpd */
95 #define MAX_BD_NUM (1024)
96 #define MAX_BD_PER_GPD (MAX_BD_NUM)
98 #define MAX_HW_SGMTS (MAX_BD_NUM)
99 #define MAX_PHY_SGMTS (MAX_BD_NUM)
100 #define MAX_SGMT_SZ (MAX_DMA_CNT)
101 #define MAX_REQ_SZ (MAX_SGMT_SZ * 8)
103 static int cd_active_low
= 1;
105 //=================================
106 #define PERI_MSDC0_PDN (15)
107 //#define PERI_MSDC1_PDN (16)
108 //#define PERI_MSDC2_PDN (17)
109 //#define PERI_MSDC3_PDN (18)
111 #if 0 /* --- by chhung */
112 /* gate means clock power down */
113 static int g_clk_gate
= 0;
114 #define msdc_gate_clock(id) \
116 g_clk_gate &= ~(1 << ((id) + PERI_MSDC0_PDN)); \
118 /* not like power down register. 1 means clock on. */
119 #define msdc_ungate_clock(id) \
121 g_clk_gate |= 1 << ((id) + PERI_MSDC0_PDN); \
124 // do we need sync object or not
125 void msdc_clk_status(int *status
)
127 *status
= g_clk_gate
;
129 #endif /* end of --- */
132 struct msdc_hw msdc0_hw
= {
134 .flags
= MSDC_CD_PIN_EN
| MSDC_REMOVABLE
,
135 // .flags = MSDC_WP_PIN_EN | MSDC_CD_PIN_EN | MSDC_REMOVABLE,
140 static int msdc_rsp
[] = {
152 #define msdc_txfifocnt() ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 16)
153 #define msdc_rxfifocnt() ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
154 #define msdc_fifo_write32(v) sdr_write32(MSDC_TXDATA, (v))
155 #define msdc_fifo_write8(v) sdr_write8(MSDC_TXDATA, (v))
156 #define msdc_fifo_read32() sdr_read32(MSDC_RXDATA)
157 #define msdc_fifo_read8() sdr_read8(MSDC_RXDATA)
159 #define msdc_dma_on() sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
161 #define msdc_retry(expr, retry, cnt) \
168 retry--; mdelay(1); cnt = backup; \
171 WARN_ON(retry == 0); \
174 static void msdc_reset_hw(struct msdc_host
*host
)
176 void __iomem
*base
= host
->base
;
178 sdr_set_bits(MSDC_CFG
, MSDC_CFG_RST
);
179 while (sdr_read32(MSDC_CFG
) & MSDC_CFG_RST
)
183 #define msdc_clr_int() \
185 volatile u32 val = sdr_read32(MSDC_INT); \
186 sdr_write32(MSDC_INT, val); \
189 #define msdc_clr_fifo() \
191 int retry = 3, cnt = 1000; \
192 sdr_set_bits(MSDC_FIFOCS, MSDC_FIFOCS_CLR); \
193 msdc_retry(sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_CLR, retry, cnt); \
196 #define msdc_irq_save(val) \
198 val = sdr_read32(MSDC_INTEN); \
199 sdr_clr_bits(MSDC_INTEN, val); \
202 #define msdc_irq_restore(val) \
204 sdr_set_bits(MSDC_INTEN, val); \
207 /* clock source for host: global */
208 #if defined(CONFIG_SOC_MT7620)
209 static u32 hclks
[] = {48000000}; /* +/- by chhung */
210 #elif defined(CONFIG_SOC_MT7621)
211 static u32 hclks
[] = {50000000}; /* +/- by chhung */
214 //============================================
215 // the power for msdc host controller: global
216 // always keep the VMC on.
217 //============================================
218 #define msdc_vcore_on(host) \
220 INIT_MSG("[+]VMC ref. count<%d>", ++host->pwr_ref); \
221 (void)hwPowerOn(MT65XX_POWER_LDO_VMC, VOL_3300, "SD"); \
223 #define msdc_vcore_off(host) \
225 INIT_MSG("[-]VMC ref. count<%d>", --host->pwr_ref); \
226 (void)hwPowerDown(MT65XX_POWER_LDO_VMC, "SD"); \
229 //====================================
230 // the vdd output for card: global
231 // always keep the VMCH on.
232 //====================================
233 #define msdc_vdd_on(host) \
235 (void)hwPowerOn(MT65XX_POWER_LDO_VMCH, VOL_3300, "SD"); \
237 #define msdc_vdd_off(host) \
239 (void)hwPowerDown(MT65XX_POWER_LDO_VMCH, "SD"); \
242 #define sdc_is_busy() (sdr_read32(SDC_STS) & SDC_STS_SDCBUSY)
243 #define sdc_is_cmd_busy() (sdr_read32(SDC_STS) & SDC_STS_CMDBUSY)
245 #define sdc_send_cmd(cmd, arg) \
247 sdr_write32(SDC_ARG, (arg)); \
248 sdr_write32(SDC_CMD, (cmd)); \
251 // can modify to read h/w register.
252 //#define is_card_present(h) ((sdr_read32(MSDC_PS) & MSDC_PS_CDSTS) ? 0 : 1);
253 #define is_card_present(h) (((struct msdc_host *)(h))->card_inserted)
257 #define PHYSADDR(a) (((unsigned long)(a)) & 0x1fffffff)
259 #define PHYSADDR(a) ((a) & 0x1fffffff)
262 static unsigned int msdc_do_command(struct msdc_host
*host
,
263 struct mmc_command
*cmd
,
265 unsigned long timeout
);
267 static int msdc_tune_cmdrsp(struct msdc_host
*host
, struct mmc_command
*cmd
);
269 #ifdef MT6575_SD_DEBUG
270 static void msdc_dump_card_status(struct msdc_host
*host
, u32 status
)
272 /* N_MSG is currently a no-op */
274 static char *state
[] = {
293 if (status
& R1_OUT_OF_RANGE
)
294 N_MSG(RSP
, "[CARD_STATUS] Out of Range");
295 if (status
& R1_ADDRESS_ERROR
)
296 N_MSG(RSP
, "[CARD_STATUS] Address Error");
297 if (status
& R1_BLOCK_LEN_ERROR
)
298 N_MSG(RSP
, "[CARD_STATUS] Block Len Error");
299 if (status
& R1_ERASE_SEQ_ERROR
)
300 N_MSG(RSP
, "[CARD_STATUS] Erase Seq Error");
301 if (status
& R1_ERASE_PARAM
)
302 N_MSG(RSP
, "[CARD_STATUS] Erase Param");
303 if (status
& R1_WP_VIOLATION
)
304 N_MSG(RSP
, "[CARD_STATUS] WP Violation");
305 if (status
& R1_CARD_IS_LOCKED
)
306 N_MSG(RSP
, "[CARD_STATUS] Card is Locked");
307 if (status
& R1_LOCK_UNLOCK_FAILED
)
308 N_MSG(RSP
, "[CARD_STATUS] Lock/Unlock Failed");
309 if (status
& R1_COM_CRC_ERROR
)
310 N_MSG(RSP
, "[CARD_STATUS] Command CRC Error");
311 if (status
& R1_ILLEGAL_COMMAND
)
312 N_MSG(RSP
, "[CARD_STATUS] Illegal Command");
313 if (status
& R1_CARD_ECC_FAILED
)
314 N_MSG(RSP
, "[CARD_STATUS] Card ECC Failed");
315 if (status
& R1_CC_ERROR
)
316 N_MSG(RSP
, "[CARD_STATUS] CC Error");
317 if (status
& R1_ERROR
)
318 N_MSG(RSP
, "[CARD_STATUS] Error");
319 if (status
& R1_UNDERRUN
)
320 N_MSG(RSP
, "[CARD_STATUS] Underrun");
321 if (status
& R1_OVERRUN
)
322 N_MSG(RSP
, "[CARD_STATUS] Overrun");
323 if (status
& R1_CID_CSD_OVERWRITE
)
324 N_MSG(RSP
, "[CARD_STATUS] CID/CSD Overwrite");
325 if (status
& R1_WP_ERASE_SKIP
)
326 N_MSG(RSP
, "[CARD_STATUS] WP Eraser Skip");
327 if (status
& R1_CARD_ECC_DISABLED
)
328 N_MSG(RSP
, "[CARD_STATUS] Card ECC Disabled");
329 if (status
& R1_ERASE_RESET
)
330 N_MSG(RSP
, "[CARD_STATUS] Erase Reset");
331 if (status
& R1_READY_FOR_DATA
)
332 N_MSG(RSP
, "[CARD_STATUS] Ready for Data");
333 if (status
& R1_SWITCH_ERROR
)
334 N_MSG(RSP
, "[CARD_STATUS] Switch error");
335 if (status
& R1_APP_CMD
)
336 N_MSG(RSP
, "[CARD_STATUS] App Command");
338 N_MSG(RSP
, "[CARD_STATUS] '%s' State", state
[R1_CURRENT_STATE(status
)]);
341 static void msdc_dump_ocr_reg(struct msdc_host
*host
, u32 resp
)
344 N_MSG(RSP
, "[OCR] Low Voltage Range");
345 if (resp
& (1 << 15))
346 N_MSG(RSP
, "[OCR] 2.7-2.8 volt");
347 if (resp
& (1 << 16))
348 N_MSG(RSP
, "[OCR] 2.8-2.9 volt");
349 if (resp
& (1 << 17))
350 N_MSG(RSP
, "[OCR] 2.9-3.0 volt");
351 if (resp
& (1 << 18))
352 N_MSG(RSP
, "[OCR] 3.0-3.1 volt");
353 if (resp
& (1 << 19))
354 N_MSG(RSP
, "[OCR] 3.1-3.2 volt");
355 if (resp
& (1 << 20))
356 N_MSG(RSP
, "[OCR] 3.2-3.3 volt");
357 if (resp
& (1 << 21))
358 N_MSG(RSP
, "[OCR] 3.3-3.4 volt");
359 if (resp
& (1 << 22))
360 N_MSG(RSP
, "[OCR] 3.4-3.5 volt");
361 if (resp
& (1 << 23))
362 N_MSG(RSP
, "[OCR] 3.5-3.6 volt");
363 if (resp
& (1 << 24))
364 N_MSG(RSP
, "[OCR] Switching to 1.8V Accepted (S18A)");
365 if (resp
& (1 << 30))
366 N_MSG(RSP
, "[OCR] Card Capacity Status (CCS)");
367 if (resp
& (1 << 31))
368 N_MSG(RSP
, "[OCR] Card Power Up Status (Idle)");
370 N_MSG(RSP
, "[OCR] Card Power Up Status (Busy)");
373 static void msdc_dump_rca_resp(struct msdc_host
*host
, u32 resp
)
375 u32 status
= (((resp
>> 15) & 0x1) << 23) |
376 (((resp
>> 14) & 0x1) << 22) |
377 (((resp
>> 13) & 0x1) << 19) |
380 N_MSG(RSP
, "[RCA] 0x%.4x", resp
>> 16);
381 msdc_dump_card_status(host
, status
);
384 static void msdc_dump_io_resp(struct msdc_host
*host
, u32 resp
)
386 u32 flags
= (resp
>> 8) & 0xFF;
388 char *state
[] = {"DIS", "CMD", "TRN", "RFU"};
390 if (flags
& (1 << 7))
391 N_MSG(RSP
, "[IO] COM_CRC_ERR");
392 if (flags
& (1 << 6))
393 N_MSG(RSP
, "[IO] Illgal command");
394 if (flags
& (1 << 3))
395 N_MSG(RSP
, "[IO] Error");
396 if (flags
& (1 << 2))
397 N_MSG(RSP
, "[IO] RFU");
398 if (flags
& (1 << 1))
399 N_MSG(RSP
, "[IO] Function number error");
400 if (flags
& (1 << 0))
401 N_MSG(RSP
, "[IO] Out of range");
403 N_MSG(RSP
, "[IO] State: %s, Data:0x%x", state
[(resp
>> 12) & 0x3], resp
& 0xFF);
407 static void msdc_set_timeout(struct msdc_host
*host
, u32 ns
, u32 clks
)
409 void __iomem
*base
= host
->base
;
412 host
->timeout_ns
= ns
;
413 host
->timeout_clks
= clks
;
415 clk_ns
= 1000000000UL / host
->sclk
;
416 timeout
= ns
/ clk_ns
+ clks
;
417 timeout
= timeout
>> 16; /* in 65536 sclk cycle unit */
418 timeout
= timeout
> 1 ? timeout
- 1 : 0;
419 timeout
= timeout
> 255 ? 255 : timeout
;
421 sdr_set_field(SDC_CFG
, SDC_CFG_DTOC
, timeout
);
423 N_MSG(OPS
, "Set read data timeout: %dns %dclks -> %d x 65536 cycles",
424 ns
, clks
, timeout
+ 1);
427 static void msdc_tasklet_card(struct work_struct
*work
)
429 struct msdc_host
*host
= (struct msdc_host
*)container_of(work
,
430 struct msdc_host
, card_delaywork
.work
);
431 void __iomem
*base
= host
->base
;
436 spin_lock(&host
->lock
);
438 status
= sdr_read32(MSDC_PS
);
440 inserted
= (status
& MSDC_PS_CDSTS
) ? 0 : 1;
442 inserted
= (status
& MSDC_PS_CDSTS
) ? 1 : 0;
443 if (host
->mmc
->caps
& MMC_CAP_NEEDS_POLL
)
447 change
= host
->card_inserted
^ inserted
;
448 host
->card_inserted
= inserted
;
450 if (change
&& !host
->suspend
) {
452 host
->mmc
->f_max
= HOST_MAX_MCLK
; // work around
453 mmc_detect_change(host
->mmc
, msecs_to_jiffies(20));
455 #else /* Make sure: handle the last interrupt */
456 host
->card_inserted
= inserted
;
458 if (!host
->suspend
) {
459 host
->mmc
->f_max
= HOST_MAX_MCLK
;
460 mmc_detect_change(host
->mmc
, msecs_to_jiffies(20));
463 IRQ_MSG("card found<%s>", inserted
? "inserted" : "removed");
466 spin_unlock(&host
->lock
);
469 #if 0 /* --- by chhung */
471 static u8 clk_src_bit
[4] = {
475 static void msdc_select_clksrc(struct msdc_host
*host
, unsigned char clksrc
)
478 void __iomem
*base
= host
->base
;
481 INIT_MSG("set clock source to <%d>", clksrc
);
483 val
= sdr_read32(MSDC_CLKSRC_REG
);
484 if (sdr_read32(MSDC_ECO_VER
) >= 4) {
485 val
&= ~(0x3 << clk_src_bit
[host
->id
]);
486 val
|= clksrc
<< clk_src_bit
[host
->id
];
488 val
&= ~0x3; val
|= clksrc
;
490 sdr_write32(MSDC_CLKSRC_REG
, val
);
492 host
->hclk
= hclks
[clksrc
];
493 host
->hw
->clk_src
= clksrc
;
495 #endif /* end of --- */
497 static void msdc_set_mclk(struct msdc_host
*host
, int ddr
, unsigned int hz
)
499 //struct msdc_hw *hw = host->hw;
500 void __iomem
*base
= host
->base
;
505 u32 hclk
= host
->hclk
;
506 //u8 clksrc = hw->clk_src;
508 if (!hz
) { // set mmc system clock to 0 ?
509 //ERR_MSG("set mclk to 0!!!");
514 msdc_irq_save(flags
);
517 mode
= 0x2; /* ddr mode and use divisor */
518 if (hz
>= (hclk
>> 2)) {
519 div
= 1; /* mean div = 1/4 */
520 sclk
= hclk
>> 2; /* sclk = clk / 4 */
522 div
= (hclk
+ ((hz
<< 2) - 1)) / (hz
<< 2);
523 sclk
= (hclk
>> 2) / div
;
525 } else if (hz
>= hclk
) { /* bug fix */
526 mode
= 0x1; /* no divisor and divisor is ignored */
530 mode
= 0x0; /* use divisor */
531 if (hz
>= (hclk
>> 1)) {
532 div
= 0; /* mean div = 1/2 */
533 sclk
= hclk
>> 1; /* sclk = clk / 2 */
535 div
= (hclk
+ ((hz
<< 2) - 1)) / (hz
<< 2);
536 sclk
= (hclk
>> 2) / div
;
540 /* set clock mode and divisor */
541 sdr_set_field(MSDC_CFG
, MSDC_CFG_CKMOD
, mode
);
542 sdr_set_field(MSDC_CFG
, MSDC_CFG_CKDIV
, div
);
544 /* wait clock stable */
545 while (!(sdr_read32(MSDC_CFG
) & MSDC_CFG_CKSTB
))
550 msdc_set_timeout(host
, host
->timeout_ns
, host
->timeout_clks
); // need?
552 INIT_MSG("================");
553 INIT_MSG("!!! Set<%dKHz> Source<%dKHz> -> sclk<%dKHz>", hz
/ 1000, hclk
/ 1000, sclk
/ 1000);
554 INIT_MSG("================");
556 msdc_irq_restore(flags
);
559 /* Fix me. when need to abort */
560 static void msdc_abort_data(struct msdc_host
*host
)
562 void __iomem
*base
= host
->base
;
563 struct mmc_command
*stop
= host
->mrq
->stop
;
565 ERR_MSG("Need to Abort.");
571 // need to check FIFO count 0 ?
573 if (stop
) { /* try to stop, but may not success */
574 ERR_MSG("stop when abort CMD<%d>", stop
->opcode
);
575 (void)msdc_do_command(host
, stop
, 0, CMD_TIMEOUT
);
578 //if (host->mclk >= 25000000) {
579 // msdc_set_mclk(host, 0, host->mclk >> 1);
583 #if 0 /* --- by chhung */
584 static void msdc_pin_config(struct msdc_host
*host
, int mode
)
586 struct msdc_hw
*hw
= host
->hw
;
587 void __iomem
*base
= host
->base
;
588 int pull
= (mode
== MSDC_PIN_PULL_UP
) ? GPIO_PULL_UP
: GPIO_PULL_DOWN
;
591 if (hw
->flags
& MSDC_WP_PIN_EN
) {
592 if (hw
->config_gpio_pin
) /* NULL */
593 hw
->config_gpio_pin(MSDC_WP_PIN
, pull
);
597 case MSDC_PIN_PULL_UP
:
598 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPU, 1); /* Check & FIXME */
599 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPD, 0); /* Check & FIXME */
600 sdr_set_field(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDPU
, 1);
601 sdr_set_field(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDPD
, 0);
602 sdr_set_field(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATPU
, 1);
603 sdr_set_field(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATPD
, 0);
605 case MSDC_PIN_PULL_DOWN
:
606 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPU, 0); /* Check & FIXME */
607 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPD, 1); /* Check & FIXME */
608 sdr_set_field(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDPU
, 0);
609 sdr_set_field(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDPD
, 1);
610 sdr_set_field(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATPU
, 0);
611 sdr_set_field(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATPD
, 1);
613 case MSDC_PIN_PULL_NONE
:
615 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPU, 0); /* Check & FIXME */
616 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPD, 0); /* Check & FIXME */
617 sdr_set_field(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDPU
, 0);
618 sdr_set_field(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDPD
, 0);
619 sdr_set_field(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATPU
, 0);
620 sdr_set_field(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATPD
, 0);
624 N_MSG(CFG
, "Pins mode(%d), down(%d), up(%d)",
625 mode
, MSDC_PIN_PULL_DOWN
, MSDC_PIN_PULL_UP
);
628 void msdc_pin_reset(struct msdc_host
*host
, int mode
)
630 struct msdc_hw
*hw
= (struct msdc_hw
*)host
->hw
;
631 void __iomem
*base
= host
->base
;
632 int pull
= (mode
== MSDC_PIN_PULL_UP
) ? GPIO_PULL_UP
: GPIO_PULL_DOWN
;
634 /* Config reset pin */
635 if (hw
->flags
& MSDC_RST_PIN_EN
) {
636 if (hw
->config_gpio_pin
) /* NULL */
637 hw
->config_gpio_pin(MSDC_RST_PIN
, pull
);
639 if (mode
== MSDC_PIN_PULL_UP
)
640 sdr_clr_bits(EMMC_IOCON
, EMMC_IOCON_BOOTRST
);
642 sdr_set_bits(EMMC_IOCON
, EMMC_IOCON_BOOTRST
);
646 static void msdc_core_power(struct msdc_host
*host
, int on
)
648 N_MSG(CFG
, "Turn %s %s power (copower: %d -> %d)",
649 on
? "on" : "off", "core", host
->core_power
, on
);
651 if (on
&& host
->core_power
== 0) {
653 host
->core_power
= 1;
655 } else if (!on
&& host
->core_power
== 1) {
656 msdc_vcore_off(host
);
657 host
->core_power
= 0;
662 static void msdc_host_power(struct msdc_host
*host
, int on
)
664 N_MSG(CFG
, "Turn %s %s power ", on
? "on" : "off", "host");
667 //msdc_core_power(host, 1); // need do card detection.
668 msdc_pin_reset(host
, MSDC_PIN_PULL_UP
);
670 msdc_pin_reset(host
, MSDC_PIN_PULL_DOWN
);
671 //msdc_core_power(host, 0);
675 static void msdc_card_power(struct msdc_host
*host
, int on
)
677 N_MSG(CFG
, "Turn %s %s power ", on
? "on" : "off", "card");
680 msdc_pin_config(host
, MSDC_PIN_PULL_UP
);
681 //msdc_vdd_on(host); // need todo card detection.
684 //msdc_vdd_off(host);
685 msdc_pin_config(host
, MSDC_PIN_PULL_DOWN
);
690 static void msdc_set_power_mode(struct msdc_host
*host
, u8 mode
)
692 N_MSG(CFG
, "Set power mode(%d)", mode
);
694 if (host
->power_mode
== MMC_POWER_OFF
&& mode
!= MMC_POWER_OFF
) {
695 msdc_host_power(host
, 1);
696 msdc_card_power(host
, 1);
697 } else if (host
->power_mode
!= MMC_POWER_OFF
&& mode
== MMC_POWER_OFF
) {
698 msdc_card_power(host
, 0);
699 msdc_host_power(host
, 0);
701 host
->power_mode
= mode
;
703 #endif /* end of --- */
707 register as callback function of WIFI(combo_sdio_register_pm) .
708 can called by msdc_drv_suspend/resume too.
710 static void msdc_pm(pm_message_t state
, void *data
)
712 struct msdc_host
*host
= (struct msdc_host
*)data
;
713 int evt
= state
.event
;
715 if (evt
== PM_EVENT_USER_RESUME
|| evt
== PM_EVENT_USER_SUSPEND
) {
716 INIT_MSG("USR_%s: suspend<%d> power<%d>",
717 evt
== PM_EVENT_USER_RESUME
? "EVENT_USER_RESUME" : "EVENT_USER_SUSPEND",
718 host
->suspend
, host
->power_mode
);
721 if (evt
== PM_EVENT_SUSPEND
|| evt
== PM_EVENT_USER_SUSPEND
) {
722 if (host
->suspend
) /* already suspend */ /* default 0*/
725 /* for memory card. already power off by mmc */
726 if (evt
== PM_EVENT_SUSPEND
&& host
->power_mode
== MMC_POWER_OFF
)
730 host
->pm_state
= state
; /* default PMSG_RESUME */
732 } else if (evt
== PM_EVENT_RESUME
|| evt
== PM_EVENT_USER_RESUME
) {
733 if (!host
->suspend
) {
734 //ERR_MSG("warning: already resume");
738 /* No PM resume when USR suspend */
739 if (evt
== PM_EVENT_RESUME
&& host
->pm_state
.event
== PM_EVENT_USER_SUSPEND
) {
740 ERR_MSG("PM Resume when in USR Suspend"); /* won't happen. */
745 host
->pm_state
= state
;
751 /*--------------------------------------------------------------------------*/
752 /* mmc_host_ops members */
753 /*--------------------------------------------------------------------------*/
754 static unsigned int msdc_command_start(struct msdc_host
*host
,
755 struct mmc_command
*cmd
,
756 int tune
, /* not used */
757 unsigned long timeout
)
759 void __iomem
*base
= host
->base
;
760 u32 opcode
= cmd
->opcode
;
762 u32 wints
= MSDC_INT_CMDRDY
| MSDC_INT_RSPCRCERR
| MSDC_INT_CMDTMO
|
763 MSDC_INT_ACMDRDY
| MSDC_INT_ACMDCRCERR
| MSDC_INT_ACMDTMO
|
764 MSDC_INT_ACMD19_DONE
;
769 /* Protocol layer does not provide response type, but our hardware needs
770 * to know exact type, not just size!
772 if (opcode
== MMC_SEND_OP_COND
|| opcode
== SD_APP_OP_COND
) {
774 } else if (opcode
== MMC_SET_RELATIVE_ADDR
) {
775 resp
= (mmc_cmd_type(cmd
) == MMC_CMD_BCR
) ? RESP_R6
: RESP_R1
;
776 } else if (opcode
== MMC_FAST_IO
) {
778 } else if (opcode
== MMC_GO_IRQ_STATE
) {
780 } else if (opcode
== MMC_SELECT_CARD
) {
781 resp
= (cmd
->arg
!= 0) ? RESP_R1B
: RESP_NONE
;
782 } else if (opcode
== SD_IO_RW_DIRECT
|| opcode
== SD_IO_RW_EXTENDED
) {
783 resp
= RESP_R1
; /* SDIO workaround. */
784 } else if (opcode
== SD_SEND_IF_COND
&& (mmc_cmd_type(cmd
) == MMC_CMD_BCR
)) {
787 switch (mmc_resp_type(cmd
)) {
809 * vol_swt << 30 | auto_cmd << 28 | blklen << 16 | go_irq << 15 |
810 * stop << 14 | rw << 13 | dtype << 11 | rsptyp << 7 | brk << 6 | opcode
812 rawcmd
= opcode
| msdc_rsp
[resp
] << 7 | host
->blksz
<< 16;
814 if (opcode
== MMC_READ_MULTIPLE_BLOCK
) {
816 } else if (opcode
== MMC_READ_SINGLE_BLOCK
) {
818 } else if (opcode
== MMC_WRITE_MULTIPLE_BLOCK
) {
819 rawcmd
|= ((2 << 11) | (1 << 13));
820 } else if (opcode
== MMC_WRITE_BLOCK
) {
821 rawcmd
|= ((1 << 11) | (1 << 13));
822 } else if (opcode
== SD_IO_RW_EXTENDED
) {
823 if (cmd
->data
->flags
& MMC_DATA_WRITE
)
825 if (cmd
->data
->blocks
> 1)
829 } else if (opcode
== SD_IO_RW_DIRECT
&& cmd
->flags
== (unsigned int)-1) {
831 } else if ((opcode
== SD_APP_SEND_SCR
) ||
832 (opcode
== SD_APP_SEND_NUM_WR_BLKS
) ||
833 (opcode
== SD_SWITCH
&& (mmc_cmd_type(cmd
) == MMC_CMD_ADTC
)) ||
834 (opcode
== SD_APP_SD_STATUS
&& (mmc_cmd_type(cmd
) == MMC_CMD_ADTC
)) ||
835 (opcode
== MMC_SEND_EXT_CSD
&& (mmc_cmd_type(cmd
) == MMC_CMD_ADTC
))) {
837 } else if (opcode
== MMC_STOP_TRANSMISSION
) {
839 rawcmd
&= ~(0x0FFF << 16);
842 N_MSG(CMD
, "CMD<%d><0x%.8x> Arg<0x%.8x>", opcode
, rawcmd
, cmd
->arg
);
844 tmo
= jiffies
+ timeout
;
846 if (opcode
== MMC_SEND_STATUS
) {
848 if (!sdc_is_cmd_busy())
851 if (time_after(jiffies
, tmo
)) {
852 ERR_MSG("XXX cmd_busy timeout: before CMD<%d>", opcode
);
853 cmd
->error
= -ETIMEDOUT
;
862 if (time_after(jiffies
, tmo
)) {
863 ERR_MSG("XXX sdc_busy timeout: before CMD<%d>", opcode
);
864 cmd
->error
= -ETIMEDOUT
;
871 //BUG_ON(in_interrupt());
873 host
->cmd_rsp
= resp
;
875 init_completion(&host
->cmd_done
);
877 sdr_set_bits(MSDC_INTEN
, wints
);
878 sdc_send_cmd(rawcmd
, cmd
->arg
);
884 static unsigned int msdc_command_resp(struct msdc_host
*host
,
885 struct mmc_command
*cmd
,
887 unsigned long timeout
)
888 __must_hold(&host
->lock
)
890 void __iomem
*base
= host
->base
;
891 u32 opcode
= cmd
->opcode
;
894 u32 wints
= MSDC_INT_CMDRDY
| MSDC_INT_RSPCRCERR
| MSDC_INT_CMDTMO
|
895 MSDC_INT_ACMDRDY
| MSDC_INT_ACMDCRCERR
| MSDC_INT_ACMDTMO
|
896 MSDC_INT_ACMD19_DONE
;
898 resp
= host
->cmd_rsp
;
900 BUG_ON(in_interrupt());
901 //init_completion(&host->cmd_done);
902 //sdr_set_bits(MSDC_INTEN, wints);
904 spin_unlock(&host
->lock
);
905 if (!wait_for_completion_timeout(&host
->cmd_done
, 10 * timeout
)) {
906 ERR_MSG("XXX CMD<%d> wait_for_completion timeout ARG<0x%.8x>", opcode
, cmd
->arg
);
907 cmd
->error
= -ETIMEDOUT
;
910 spin_lock(&host
->lock
);
912 sdr_clr_bits(MSDC_INTEN
, wints
);
916 #ifdef MT6575_SD_DEBUG
919 N_MSG(RSP
, "CMD_RSP(%d): %d RSP(%d)", opcode
, cmd
->error
, resp
);
922 N_MSG(RSP
, "CMD_RSP(%d): %d RSP(%d)= %.8x %.8x %.8x %.8x",
923 opcode
, cmd
->error
, resp
, cmd
->resp
[0], cmd
->resp
[1],
924 cmd
->resp
[2], cmd
->resp
[3]);
926 default: /* Response types 1, 3, 4, 5, 6, 7(1b) */
927 N_MSG(RSP
, "CMD_RSP(%d): %d RSP(%d)= 0x%.8x",
928 opcode
, cmd
->error
, resp
, cmd
->resp
[0]);
929 if (cmd
->error
== 0) {
933 msdc_dump_card_status(host
, cmd
->resp
[0]);
936 msdc_dump_ocr_reg(host
, cmd
->resp
[0]);
939 msdc_dump_io_resp(host
, cmd
->resp
[0]);
942 msdc_dump_rca_resp(host
, cmd
->resp
[0]);
950 /* do we need to save card's RCA when SD_SEND_RELATIVE_ADDR */
955 /* memory card CRC */
956 if (host
->hw
->flags
& MSDC_REMOVABLE
&& cmd
->error
== -EIO
) {
957 if (sdr_read32(SDC_CMD
) & 0x1800) { /* check if has data phase */
958 msdc_abort_data(host
);
965 cmd
->error
= msdc_tune_cmdrsp(host
, cmd
);
969 /* if (resp == RESP_R1B) {
970 while ((sdr_read32(MSDC_PS) & 0x10000) != 0x10000);
972 /* CMD12 Error Handle */
977 static unsigned int msdc_do_command(struct msdc_host
*host
,
978 struct mmc_command
*cmd
,
980 unsigned long timeout
)
982 if (msdc_command_start(host
, cmd
, tune
, timeout
))
985 if (msdc_command_resp(host
, cmd
, tune
, timeout
))
990 N_MSG(CMD
, " return<%d> resp<0x%.8x>", cmd
->error
, cmd
->resp
[0]);
994 #if 0 /* --- by chhung */
995 // DMA resume / start / stop
996 static void msdc_dma_resume(struct msdc_host
*host
)
998 void __iomem
*base
= host
->base
;
1000 sdr_set_field(MSDC_DMA_CTRL
, MSDC_DMA_CTRL_RESUME
, 1);
1002 N_MSG(DMA
, "DMA resume");
1004 #endif /* end of --- */
1006 static void msdc_dma_start(struct msdc_host
*host
)
1008 void __iomem
*base
= host
->base
;
1009 u32 wints
= MSDC_INTEN_XFER_COMPL
| MSDC_INTEN_DATTMO
| MSDC_INTEN_DATCRCERR
;
1011 sdr_set_bits(MSDC_INTEN
, wints
);
1012 //dsb(); /* --- by chhung */
1013 sdr_set_field(MSDC_DMA_CTRL
, MSDC_DMA_CTRL_START
, 1);
1015 N_MSG(DMA
, "DMA start");
1018 static void msdc_dma_stop(struct msdc_host
*host
)
1020 void __iomem
*base
= host
->base
;
1022 u32 wints
= MSDC_INTEN_XFER_COMPL
| MSDC_INTEN_DATTMO
| MSDC_INTEN_DATCRCERR
;
1024 N_MSG(DMA
, "DMA status: 0x%.8x", sdr_read32(MSDC_DMA_CFG
));
1025 //while (sdr_read32(MSDC_DMA_CFG) & MSDC_DMA_CFG_STS);
1027 sdr_set_field(MSDC_DMA_CTRL
, MSDC_DMA_CTRL_STOP
, 1);
1028 while (sdr_read32(MSDC_DMA_CFG
) & MSDC_DMA_CFG_STS
)
1031 //dsb(); /* --- by chhung */
1032 sdr_clr_bits(MSDC_INTEN
, wints
); /* Not just xfer_comp */
1034 N_MSG(DMA
, "DMA stop");
1038 static u8
msdc_dma_calcs(u8
*buf
, u32 len
)
1042 for (i
= 0; i
< len
; i
++)
1044 return 0xFF - (u8
)sum
;
1047 /* gpd bd setup + dma registers */
1048 static void msdc_dma_config(struct msdc_host
*host
, struct msdc_dma
*dma
)
1050 void __iomem
*base
= host
->base
;
1051 //u32 i, j, num, bdlen, arg, xfersz;
1053 struct scatterlist
*sg
;
1057 switch (dma
->mode
) {
1058 case MSDC_MODE_DMA_BASIC
:
1059 BUG_ON(host
->xfer_size
> 65535);
1060 BUG_ON(dma
->sglen
!= 1);
1061 sdr_write32(MSDC_DMA_SA
, PHYSADDR(sg_dma_address(sg
)));
1062 sdr_set_field(MSDC_DMA_CTRL
, MSDC_DMA_CTRL_LASTBUF
, 1);
1063 //#if defined (CONFIG_RALINK_MT7620)
1064 if (ralink_soc
== MT762X_SOC_MT7620A
)
1065 sdr_set_field(MSDC_DMA_CTRL
, MSDC_DMA_CTRL_XFERSZ
, sg_dma_len(sg
));
1066 //#elif defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628)
1068 sdr_write32((void __iomem
*)(RALINK_MSDC_BASE
+ 0xa8), sg_dma_len(sg
));
1070 sdr_set_field(MSDC_DMA_CTRL
, MSDC_DMA_CTRL_BRUSTSZ
,
1072 sdr_set_field(MSDC_DMA_CTRL
, MSDC_DMA_CTRL_MODE
, 0);
1074 case MSDC_MODE_DMA_DESC
:
1076 /* calculate the required number of gpd */
1077 num
= (dma
->sglen
+ MAX_BD_PER_GPD
- 1) / MAX_BD_PER_GPD
;
1085 gpd
->hwo
= 1; /* hw will clear it */
1087 gpd
->chksum
= 0; /* need to clear first. */
1088 gpd
->chksum
= msdc_dma_calcs((u8
*)gpd
, 16);
1091 for_each_sg(dma
->sg
, sg
, dma
->sglen
, j
) {
1094 bd
[j
].ptr
= (void *)sg_dma_address(sg
);
1095 bd
[j
].buflen
= sg_dma_len(sg
);
1097 if (j
== dma
->sglen
- 1)
1098 bd
[j
].eol
= 1; /* the last bd */
1102 bd
[j
].chksum
= 0; /* checksume need to clear first */
1103 bd
[j
].chksum
= msdc_dma_calcs((u8
*)(&bd
[j
]), 16);
1106 sdr_set_field(MSDC_DMA_CFG
, MSDC_DMA_CFG_DECSEN
, 1);
1107 sdr_set_field(MSDC_DMA_CTRL
, MSDC_DMA_CTRL_BRUSTSZ
,
1109 sdr_set_field(MSDC_DMA_CTRL
, MSDC_DMA_CTRL_MODE
, 1);
1111 sdr_write32(MSDC_DMA_SA
, PHYSADDR((u32
)dma
->gpd_addr
));
1118 N_MSG(DMA
, "DMA_CTRL = 0x%x", sdr_read32(MSDC_DMA_CTRL
));
1119 N_MSG(DMA
, "DMA_CFG = 0x%x", sdr_read32(MSDC_DMA_CFG
));
1120 N_MSG(DMA
, "DMA_SA = 0x%x", sdr_read32(MSDC_DMA_SA
));
1124 static void msdc_dma_setup(struct msdc_host
*host
, struct msdc_dma
*dma
,
1125 struct scatterlist
*sg
, unsigned int sglen
)
1127 BUG_ON(sglen
> MAX_BD_NUM
); /* not support currently */
1132 dma
->mode
= MSDC_MODE_DMA_DESC
;
1134 N_MSG(DMA
, "DMA mode<%d> sglen<%d> xfersz<%d>", dma
->mode
, dma
->sglen
,
1137 msdc_dma_config(host
, dma
);
1140 static int msdc_do_request(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
1141 __must_hold(&host
->lock
)
1143 struct msdc_host
*host
= mmc_priv(mmc
);
1144 struct mmc_command
*cmd
;
1145 struct mmc_data
*data
;
1146 void __iomem
*base
= host
->base
;
1148 int read
= 1, send_type
= 0;
1153 BUG_ON(mmc
== NULL
);
1154 BUG_ON(mrq
== NULL
);
1159 data
= mrq
->cmd
->data
;
1161 #if 0 /* --- by chhung */
1163 N_MSG(OPS
, "enable clock!");
1164 msdc_ungate_clock(host
->id
);
1166 #endif /* end of --- */
1169 send_type
= SND_CMD
;
1170 if (msdc_do_command(host
, cmd
, 1, CMD_TIMEOUT
) != 0)
1173 BUG_ON(data
->blksz
> HOST_MAX_BLKSZ
);
1174 send_type
= SND_DAT
;
1177 read
= data
->flags
& MMC_DATA_READ
? 1 : 0;
1179 host
->xfer_size
= data
->blocks
* data
->blksz
;
1180 host
->blksz
= data
->blksz
;
1183 if ((host
->timeout_ns
!= data
->timeout_ns
) ||
1184 (host
->timeout_clks
!= data
->timeout_clks
)) {
1185 msdc_set_timeout(host
, data
->timeout_ns
, data
->timeout_clks
);
1189 sdr_write32(SDC_BLK_NUM
, data
->blocks
);
1190 //msdc_clr_fifo(); /* no need */
1192 msdc_dma_on(); /* enable DMA mode first!! */
1193 init_completion(&host
->xfer_done
);
1195 /* start the command first*/
1196 if (msdc_command_start(host
, cmd
, 1, CMD_TIMEOUT
) != 0)
1199 data
->sg_count
= dma_map_sg(mmc_dev(mmc
), data
->sg
,
1201 mmc_get_dma_dir(data
));
1202 msdc_dma_setup(host
, &host
->dma
, data
->sg
,
1205 /* then wait command done */
1206 if (msdc_command_resp(host
, cmd
, 1, CMD_TIMEOUT
) != 0)
1209 /* for read, the data coming too fast, then CRC error
1210 start DMA no business with CRC. */
1211 //init_completion(&host->xfer_done);
1212 msdc_dma_start(host
);
1214 spin_unlock(&host
->lock
);
1215 if (!wait_for_completion_timeout(&host
->xfer_done
, DAT_TIMEOUT
)) {
1216 ERR_MSG("XXX CMD<%d> wait xfer_done<%d> timeout!!", cmd
->opcode
, data
->blocks
* data
->blksz
);
1217 ERR_MSG(" DMA_SA = 0x%x", sdr_read32(MSDC_DMA_SA
));
1218 ERR_MSG(" DMA_CA = 0x%x", sdr_read32(MSDC_DMA_CA
));
1219 ERR_MSG(" DMA_CTRL = 0x%x", sdr_read32(MSDC_DMA_CTRL
));
1220 ERR_MSG(" DMA_CFG = 0x%x", sdr_read32(MSDC_DMA_CFG
));
1221 data
->error
= -ETIMEDOUT
;
1223 msdc_reset_hw(host
);
1227 spin_lock(&host
->lock
);
1228 msdc_dma_stop(host
);
1230 /* Last: stop transfer */
1232 if (msdc_do_command(host
, data
->stop
, 0, CMD_TIMEOUT
) != 0)
1240 dma_unmap_sg(mmc_dev(mmc
), data
->sg
, data
->sg_len
,
1241 mmc_get_dma_dir(data
));
1244 #if 0 // don't stop twice!
1245 if (host
->hw
->flags
& MSDC_REMOVABLE
&& data
->error
) {
1246 msdc_abort_data(host
);
1247 /* reset in IRQ, stop command has issued. -> No need */
1251 N_MSG(OPS
, "CMD<%d> data<%s %s> blksz<%d> block<%d> error<%d>", cmd
->opcode
, (dma
? "dma" : "pio"),
1252 (read
? "read " : "write"), data
->blksz
, data
->blocks
, data
->error
);
1255 #if 0 /* --- by chhung */
1258 if (send_type
== SND_CMD
) {
1259 if (cmd
->opcode
== MMC_SEND_STATUS
) {
1260 if ((cmd
->resp
[0] & CARD_READY_FOR_DATA
) || (CARD_CURRENT_STATE(cmd
->resp
[0]) != 7)) {
1261 N_MSG(OPS
, "disable clock, CMD13 IDLE");
1262 msdc_gate_clock(host
->id
);
1265 N_MSG(OPS
, "disable clock, CMD<%d>", cmd
->opcode
);
1266 msdc_gate_clock(host
->id
);
1270 N_MSG(OPS
, "disable clock!!! Read CMD<%d>", cmd
->opcode
);
1271 msdc_gate_clock(host
->id
);
1276 msdc_gate_clock(host
->id
);
1278 #endif /* end of --- */
1280 if (mrq
->cmd
->error
)
1281 host
->error
= 0x001;
1282 if (mrq
->data
&& mrq
->data
->error
)
1283 host
->error
|= 0x010;
1284 if (mrq
->stop
&& mrq
->stop
->error
)
1285 host
->error
|= 0x100;
1287 //if (host->error) ERR_MSG("host->error<%d>", host->error);
1292 static int msdc_app_cmd(struct mmc_host
*mmc
, struct msdc_host
*host
)
1294 struct mmc_command cmd
;
1295 struct mmc_request mrq
;
1298 memset(&cmd
, 0, sizeof(struct mmc_command
));
1299 cmd
.opcode
= MMC_APP_CMD
;
1300 #if 0 /* bug: we meet mmc->card is null when ACMD6 */
1301 cmd
.arg
= mmc
->card
->rca
<< 16;
1303 cmd
.arg
= host
->app_cmd_arg
;
1305 cmd
.flags
= MMC_RSP_SPI_R1
| MMC_RSP_R1
| MMC_CMD_AC
;
1307 memset(&mrq
, 0, sizeof(struct mmc_request
));
1308 mrq
.cmd
= &cmd
; cmd
.mrq
= &mrq
;
1311 err
= msdc_do_command(host
, &cmd
, 0, CMD_TIMEOUT
);
1315 static int msdc_tune_cmdrsp(struct msdc_host
*host
, struct mmc_command
*cmd
)
1318 void __iomem
*base
= host
->base
;
1319 u32 rsmpl
, cur_rsmpl
, orig_rsmpl
;
1320 u32 rrdly
, cur_rrdly
= 0xffffffff, orig_rrdly
;
1323 /* ==== don't support 3.0 now ====
1325 2: PAD_CMD_RESP_RXDLY[26:22]
1326 ==========================*/
1328 // save the previous tune result
1329 sdr_get_field(MSDC_IOCON
, MSDC_IOCON_RSPL
, &orig_rsmpl
);
1330 sdr_get_field(MSDC_PAD_TUNE
, MSDC_PAD_TUNE_CMDRRDLY
, &orig_rrdly
);
1334 for (rsmpl
= 0; rsmpl
< 2; rsmpl
++) {
1335 /* Lv1: R_SMPL[1] */
1336 cur_rsmpl
= (orig_rsmpl
+ rsmpl
) % 2;
1341 sdr_set_field(MSDC_IOCON
, MSDC_IOCON_RSPL
, cur_rsmpl
);
1343 if (host
->app_cmd
) {
1344 result
= msdc_app_cmd(host
->mmc
, host
);
1346 ERR_MSG("TUNE_CMD app_cmd<%d> failed: RESP_RXDLY<%d>,R_SMPL<%d>",
1347 host
->mrq
->cmd
->opcode
, cur_rrdly
, cur_rsmpl
);
1351 result
= msdc_do_command(host
, cmd
, 0, CMD_TIMEOUT
); // not tune.
1352 ERR_MSG("TUNE_CMD<%d> %s PAD_CMD_RESP_RXDLY[26:22]<%d> R_SMPL[1]<%d>", cmd
->opcode
,
1353 (result
== 0) ? "PASS" : "FAIL", cur_rrdly
, cur_rsmpl
);
1357 if (result
!= -EIO
) {
1358 ERR_MSG("TUNE_CMD<%d> Error<%d> not -EIO", cmd
->opcode
, result
);
1363 if (sdr_read32(SDC_CMD
) & 0x1800) { /* check if has data phase */
1364 msdc_abort_data(host
);
1368 /* Lv2: PAD_CMD_RESP_RXDLY[26:22] */
1369 cur_rrdly
= (orig_rrdly
+ rrdly
+ 1) % 32;
1370 sdr_set_field(MSDC_PAD_TUNE
, MSDC_PAD_TUNE_CMDRRDLY
, cur_rrdly
);
1371 } while (++rrdly
< 32);
1376 /* Support SD2.0 Only */
1377 static int msdc_tune_bread(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
1379 struct msdc_host
*host
= mmc_priv(mmc
);
1380 void __iomem
*base
= host
->base
;
1383 u32 rxdly
, cur_rxdly0
, cur_rxdly1
;
1384 u32 dsmpl
, cur_dsmpl
, orig_dsmpl
;
1385 u32 cur_dat0
, cur_dat1
, cur_dat2
, cur_dat3
;
1386 u32 cur_dat4
, cur_dat5
, cur_dat6
, cur_dat7
;
1387 u32 orig_dat0
, orig_dat1
, orig_dat2
, orig_dat3
;
1388 u32 orig_dat4
, orig_dat5
, orig_dat6
, orig_dat7
;
1392 sdr_get_field(MSDC_IOCON
, MSDC_IOCON_DSPL
, &orig_dsmpl
);
1394 /* Tune Method 2. */
1395 sdr_set_field(MSDC_IOCON
, MSDC_IOCON_DDLSEL
, 1);
1399 for (dsmpl
= 0; dsmpl
< 2; dsmpl
++) {
1400 cur_dsmpl
= (orig_dsmpl
+ dsmpl
) % 2;
1405 sdr_set_field(MSDC_IOCON
, MSDC_IOCON_DSPL
, cur_dsmpl
);
1407 if (host
->app_cmd
) {
1408 result
= msdc_app_cmd(host
->mmc
, host
);
1410 ERR_MSG("TUNE_BREAD app_cmd<%d> failed", host
->mrq
->cmd
->opcode
);
1414 result
= msdc_do_request(mmc
, mrq
);
1416 sdr_get_field(SDC_DCRC_STS
,
1417 SDC_DCRC_STS_POS
| SDC_DCRC_STS_NEG
,
1420 dcrc
&= ~SDC_DCRC_STS_NEG
;
1421 ERR_MSG("TUNE_BREAD<%s> dcrc<0x%x> DATRDDLY0/1<0x%x><0x%x> dsmpl<0x%x>",
1422 (result
== 0 && dcrc
== 0) ? "PASS" : "FAIL", dcrc
,
1423 sdr_read32(MSDC_DAT_RDDLY0
), sdr_read32(MSDC_DAT_RDDLY1
), cur_dsmpl
);
1425 /* Fix me: result is 0, but dcrc is still exist */
1426 if (result
== 0 && dcrc
== 0) {
1429 /* there is a case: command timeout, and data phase not processed */
1430 if (mrq
->data
->error
!= 0 &&
1431 mrq
->data
->error
!= -EIO
) {
1432 ERR_MSG("TUNE_READ: result<0x%x> cmd_error<%d> data_error<%d>",
1433 result
, mrq
->cmd
->error
, mrq
->data
->error
);
1439 cur_rxdly0
= sdr_read32(MSDC_DAT_RDDLY0
);
1440 cur_rxdly1
= sdr_read32(MSDC_DAT_RDDLY1
);
1442 /* E1 ECO. YD: Reverse */
1443 if (sdr_read32(MSDC_ECO_VER
) >= 4) {
1444 orig_dat0
= (cur_rxdly0
>> 24) & 0x1F;
1445 orig_dat1
= (cur_rxdly0
>> 16) & 0x1F;
1446 orig_dat2
= (cur_rxdly0
>> 8) & 0x1F;
1447 orig_dat3
= (cur_rxdly0
>> 0) & 0x1F;
1448 orig_dat4
= (cur_rxdly1
>> 24) & 0x1F;
1449 orig_dat5
= (cur_rxdly1
>> 16) & 0x1F;
1450 orig_dat6
= (cur_rxdly1
>> 8) & 0x1F;
1451 orig_dat7
= (cur_rxdly1
>> 0) & 0x1F;
1453 orig_dat0
= (cur_rxdly0
>> 0) & 0x1F;
1454 orig_dat1
= (cur_rxdly0
>> 8) & 0x1F;
1455 orig_dat2
= (cur_rxdly0
>> 16) & 0x1F;
1456 orig_dat3
= (cur_rxdly0
>> 24) & 0x1F;
1457 orig_dat4
= (cur_rxdly1
>> 0) & 0x1F;
1458 orig_dat5
= (cur_rxdly1
>> 8) & 0x1F;
1459 orig_dat6
= (cur_rxdly1
>> 16) & 0x1F;
1460 orig_dat7
= (cur_rxdly1
>> 24) & 0x1F;
1464 cur_dat0
= (dcrc
& (1 << 0) || dcrc
& (1 << 8)) ? ((orig_dat0
+ 1) % 32) : orig_dat0
;
1465 cur_dat1
= (dcrc
& (1 << 1) || dcrc
& (1 << 9)) ? ((orig_dat1
+ 1) % 32) : orig_dat1
;
1466 cur_dat2
= (dcrc
& (1 << 2) || dcrc
& (1 << 10)) ? ((orig_dat2
+ 1) % 32) : orig_dat2
;
1467 cur_dat3
= (dcrc
& (1 << 3) || dcrc
& (1 << 11)) ? ((orig_dat3
+ 1) % 32) : orig_dat3
;
1469 cur_dat0
= (dcrc
& (1 << 0)) ? ((orig_dat0
+ 1) % 32) : orig_dat0
;
1470 cur_dat1
= (dcrc
& (1 << 1)) ? ((orig_dat1
+ 1) % 32) : orig_dat1
;
1471 cur_dat2
= (dcrc
& (1 << 2)) ? ((orig_dat2
+ 1) % 32) : orig_dat2
;
1472 cur_dat3
= (dcrc
& (1 << 3)) ? ((orig_dat3
+ 1) % 32) : orig_dat3
;
1474 cur_dat4
= (dcrc
& (1 << 4)) ? ((orig_dat4
+ 1) % 32) : orig_dat4
;
1475 cur_dat5
= (dcrc
& (1 << 5)) ? ((orig_dat5
+ 1) % 32) : orig_dat5
;
1476 cur_dat6
= (dcrc
& (1 << 6)) ? ((orig_dat6
+ 1) % 32) : orig_dat6
;
1477 cur_dat7
= (dcrc
& (1 << 7)) ? ((orig_dat7
+ 1) % 32) : orig_dat7
;
1479 cur_rxdly0
= (cur_dat0
<< 24) | (cur_dat1
<< 16) | (cur_dat2
<< 8) | (cur_dat3
<< 0);
1480 cur_rxdly1
= (cur_dat4
<< 24) | (cur_dat5
<< 16) | (cur_dat6
<< 8) | (cur_dat7
<< 0);
1482 sdr_write32(MSDC_DAT_RDDLY0
, cur_rxdly0
);
1483 sdr_write32(MSDC_DAT_RDDLY1
, cur_rxdly1
);
1485 } while (++rxdly
< 32);
1491 static int msdc_tune_bwrite(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
1493 struct msdc_host
*host
= mmc_priv(mmc
);
1494 void __iomem
*base
= host
->base
;
1496 u32 wrrdly
, cur_wrrdly
= 0xffffffff, orig_wrrdly
;
1497 u32 dsmpl
, cur_dsmpl
, orig_dsmpl
;
1498 u32 rxdly
, cur_rxdly0
;
1499 u32 orig_dat0
, orig_dat1
, orig_dat2
, orig_dat3
;
1500 u32 cur_dat0
, cur_dat1
, cur_dat2
, cur_dat3
;
1504 // MSDC_IOCON_DDR50CKD need to check. [Fix me]
1506 sdr_get_field(MSDC_PAD_TUNE
, MSDC_PAD_TUNE_DATWRDLY
, &orig_wrrdly
);
1507 sdr_get_field(MSDC_IOCON
, MSDC_IOCON_DSPL
, &orig_dsmpl
);
1509 /* Tune Method 2. just DAT0 */
1510 sdr_set_field(MSDC_IOCON
, MSDC_IOCON_DDLSEL
, 1);
1511 cur_rxdly0
= sdr_read32(MSDC_DAT_RDDLY0
);
1513 /* E1 ECO. YD: Reverse */
1514 if (sdr_read32(MSDC_ECO_VER
) >= 4) {
1515 orig_dat0
= (cur_rxdly0
>> 24) & 0x1F;
1516 orig_dat1
= (cur_rxdly0
>> 16) & 0x1F;
1517 orig_dat2
= (cur_rxdly0
>> 8) & 0x1F;
1518 orig_dat3
= (cur_rxdly0
>> 0) & 0x1F;
1520 orig_dat0
= (cur_rxdly0
>> 0) & 0x1F;
1521 orig_dat1
= (cur_rxdly0
>> 8) & 0x1F;
1522 orig_dat2
= (cur_rxdly0
>> 16) & 0x1F;
1523 orig_dat3
= (cur_rxdly0
>> 24) & 0x1F;
1530 for (dsmpl
= 0; dsmpl
< 2; dsmpl
++) {
1531 cur_dsmpl
= (orig_dsmpl
+ dsmpl
) % 2;
1536 sdr_set_field(MSDC_IOCON
, MSDC_IOCON_DSPL
, cur_dsmpl
);
1538 if (host
->app_cmd
) {
1539 result
= msdc_app_cmd(host
->mmc
, host
);
1541 ERR_MSG("TUNE_BWRITE app_cmd<%d> failed", host
->mrq
->cmd
->opcode
);
1545 result
= msdc_do_request(mmc
, mrq
);
1547 ERR_MSG("TUNE_BWRITE<%s> DSPL<%d> DATWRDLY<%d> MSDC_DAT_RDDLY0<0x%x>",
1548 result
== 0 ? "PASS" : "FAIL",
1549 cur_dsmpl
, cur_wrrdly
, cur_rxdly0
);
1554 /* there is a case: command timeout, and data phase not processed */
1555 if (mrq
->data
->error
!= -EIO
) {
1556 ERR_MSG("TUNE_READ: result<0x%x> cmd_error<%d> data_error<%d>",
1557 result
, mrq
->cmd
->error
, mrq
->data
->error
);
1562 cur_wrrdly
= (orig_wrrdly
+ wrrdly
+ 1) % 32;
1563 sdr_set_field(MSDC_PAD_TUNE
, MSDC_PAD_TUNE_DATWRDLY
, cur_wrrdly
);
1564 } while (++wrrdly
< 32);
1566 cur_dat0
= (orig_dat0
+ rxdly
) % 32; /* only adjust bit-1 for crc */
1567 cur_dat1
= orig_dat1
;
1568 cur_dat2
= orig_dat2
;
1569 cur_dat3
= orig_dat3
;
1571 cur_rxdly0
= (cur_dat0
<< 24) | (cur_dat1
<< 16) | (cur_dat2
<< 8) | (cur_dat3
<< 0);
1572 sdr_write32(MSDC_DAT_RDDLY0
, cur_rxdly0
);
1573 } while (++rxdly
< 32);
1579 static int msdc_get_card_status(struct mmc_host
*mmc
, struct msdc_host
*host
, u32
*status
)
1581 struct mmc_command cmd
;
1582 struct mmc_request mrq
;
1585 memset(&cmd
, 0, sizeof(struct mmc_command
));
1586 cmd
.opcode
= MMC_SEND_STATUS
;
1588 cmd
.arg
= mmc
->card
->rca
<< 16;
1590 ERR_MSG("cmd13 mmc card is null");
1591 cmd
.arg
= host
->app_cmd_arg
;
1593 cmd
.flags
= MMC_RSP_SPI_R2
| MMC_RSP_R1
| MMC_CMD_AC
;
1595 memset(&mrq
, 0, sizeof(struct mmc_request
));
1596 mrq
.cmd
= &cmd
; cmd
.mrq
= &mrq
;
1599 err
= msdc_do_command(host
, &cmd
, 1, CMD_TIMEOUT
);
1602 *status
= cmd
.resp
[0];
1607 static int msdc_check_busy(struct mmc_host
*mmc
, struct msdc_host
*host
)
1613 err
= msdc_get_card_status(mmc
, host
, &status
);
1617 ERR_MSG("cmd<13> resp<0x%x>", status
);
1618 } while (R1_CURRENT_STATE(status
) == 7);
1623 /* failed when msdc_do_request */
1624 static int msdc_tune_request(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
1626 struct msdc_host
*host
= mmc_priv(mmc
);
1627 struct mmc_command
*cmd
;
1628 struct mmc_data
*data
;
1629 //u32 base = host->base;
1633 data
= mrq
->cmd
->data
;
1635 read
= data
->flags
& MMC_DATA_READ
? 1 : 0;
1638 if (data
->error
== -EIO
)
1639 ret
= msdc_tune_bread(mmc
, mrq
);
1641 ret
= msdc_check_busy(mmc
, host
);
1643 ERR_MSG("XXX cmd13 wait program done failed");
1647 /* Fix me: don't care card status? */
1648 ret
= msdc_tune_bwrite(mmc
, mrq
);
1655 static void msdc_ops_request(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
1657 struct msdc_host
*host
= mmc_priv(mmc
);
1659 //=== for sdio profile ===
1660 #if 0 /* --- by chhung */
1661 u32 old_H32
, old_L32
, new_H32
, new_L32
;
1662 u32 ticks
= 0, opcode
= 0, sizes
= 0, bRx
= 0;
1663 #endif /* end of --- */
1667 /* start to process */
1668 spin_lock(&host
->lock
);
1669 #if 0 /* --- by chhung */
1670 if (sdio_pro_enable
) { //=== for sdio profile ===
1671 if (mrq
->cmd
->opcode
== 52 || mrq
->cmd
->opcode
== 53)
1672 GPT_GetCounter64(&old_L32
, &old_H32
);
1674 #endif /* end of --- */
1678 if (msdc_do_request(mmc
, mrq
)) {
1679 if (host
->hw
->flags
& MSDC_REMOVABLE
&& ralink_soc
== MT762X_SOC_MT7621AT
&& mrq
->data
&& mrq
->data
->error
)
1680 msdc_tune_request(mmc
, mrq
);
1683 /* ==== when request done, check if app_cmd ==== */
1684 if (mrq
->cmd
->opcode
== MMC_APP_CMD
) {
1686 host
->app_cmd_arg
= mrq
->cmd
->arg
; /* save the RCA */
1689 //host->app_cmd_arg = 0;
1694 #if 0 /* --- by chhung */
1695 //=== for sdio profile ===
1696 if (sdio_pro_enable
) {
1697 if (mrq
->cmd
->opcode
== 52 || mrq
->cmd
->opcode
== 53) {
1698 GPT_GetCounter64(&new_L32
, &new_H32
);
1699 ticks
= msdc_time_calc(old_L32
, old_H32
, new_L32
, new_H32
);
1701 opcode
= mrq
->cmd
->opcode
;
1702 if (mrq
->cmd
->data
) {
1703 sizes
= mrq
->cmd
->data
->blocks
* mrq
->cmd
->data
->blksz
;
1704 bRx
= mrq
->cmd
->data
->flags
& MMC_DATA_READ
? 1 : 0;
1706 bRx
= mrq
->cmd
->arg
& 0x80000000 ? 1 : 0;
1709 if (!mrq
->cmd
->error
)
1710 msdc_performance(opcode
, sizes
, bRx
, ticks
);
1713 #endif /* end of --- */
1714 spin_unlock(&host
->lock
);
1716 mmc_request_done(mmc
, mrq
);
1721 /* called by ops.set_ios */
1722 static void msdc_set_buswidth(struct msdc_host
*host
, u32 width
)
1724 void __iomem
*base
= host
->base
;
1725 u32 val
= sdr_read32(SDC_CFG
);
1727 val
&= ~SDC_CFG_BUSWIDTH
;
1731 case MMC_BUS_WIDTH_1
:
1733 val
|= (MSDC_BUS_1BITS
<< 16);
1735 case MMC_BUS_WIDTH_4
:
1736 val
|= (MSDC_BUS_4BITS
<< 16);
1738 case MMC_BUS_WIDTH_8
:
1739 val
|= (MSDC_BUS_8BITS
<< 16);
1743 sdr_write32(SDC_CFG
, val
);
1745 N_MSG(CFG
, "Bus Width = %d", width
);
1749 static void msdc_ops_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
1751 struct msdc_host
*host
= mmc_priv(mmc
);
1752 void __iomem
*base
= host
->base
;
1755 #ifdef MT6575_SD_DEBUG
1756 static char *vdd
[] = {
1757 "1.50v", "1.55v", "1.60v", "1.65v", "1.70v", "1.80v", "1.90v",
1758 "2.00v", "2.10v", "2.20v", "2.30v", "2.40v", "2.50v", "2.60v",
1759 "2.70v", "2.80v", "2.90v", "3.00v", "3.10v", "3.20v", "3.30v",
1760 "3.40v", "3.50v", "3.60v"
1762 static char *power_mode
[] = {
1765 static char *bus_mode
[] = {
1766 "UNKNOWN", "OPENDRAIN", "PUSHPULL"
1768 static char *timing
[] = {
1769 "LEGACY", "MMC_HS", "SD_HS"
1772 printk("SET_IOS: CLK(%dkHz), BUS(%s), BW(%u), PWR(%s), VDD(%s), TIMING(%s)",
1773 ios
->clock
/ 1000, bus_mode
[ios
->bus_mode
],
1774 (ios
->bus_width
== MMC_BUS_WIDTH_4
) ? 4 : 1,
1775 power_mode
[ios
->power_mode
], vdd
[ios
->vdd
], timing
[ios
->timing
]);
1778 msdc_set_buswidth(host
, ios
->bus_width
);
1780 /* Power control ??? */
1781 switch (ios
->power_mode
) {
1784 // msdc_set_power_mode(host, ios->power_mode); /* --- by chhung */
1787 host
->power_mode
= MMC_POWER_ON
;
1794 if (host
->mclk
!= ios
->clock
) {
1795 if (ios
->clock
> 25000000) {
1796 //if (!(host->hw->flags & MSDC_REMOVABLE)) {
1797 INIT_MSG("SD data latch edge<%d>", MSDC_SMPL_FALLING
);
1798 sdr_set_field(MSDC_IOCON
, MSDC_IOCON_RSPL
,
1800 sdr_set_field(MSDC_IOCON
, MSDC_IOCON_DSPL
,
1802 //} /* for tuning debug */
1803 } else { /* default value */
1804 sdr_write32(MSDC_IOCON
, 0x00000000);
1805 // sdr_write32(MSDC_DAT_RDDLY0, 0x00000000);
1806 sdr_write32(MSDC_DAT_RDDLY0
, 0x10101010); // for MT7620 E2 and afterward
1807 sdr_write32(MSDC_DAT_RDDLY1
, 0x00000000);
1808 // sdr_write32(MSDC_PAD_TUNE, 0x00000000);
1809 sdr_write32(MSDC_PAD_TUNE
, 0x84101010); // for MT7620 E2 and afterward
1811 msdc_set_mclk(host
, ddr
, ios
->clock
);
1816 static int msdc_ops_get_ro(struct mmc_host
*mmc
)
1818 struct msdc_host
*host
= mmc_priv(mmc
);
1819 void __iomem
*base
= host
->base
;
1820 unsigned long flags
;
1823 if (host
->hw
->flags
& MSDC_WP_PIN_EN
) { /* set for card */
1824 spin_lock_irqsave(&host
->lock
, flags
);
1825 ro
= (sdr_read32(MSDC_PS
) >> 31);
1826 spin_unlock_irqrestore(&host
->lock
, flags
);
1832 static int msdc_ops_get_cd(struct mmc_host
*mmc
)
1834 struct msdc_host
*host
= mmc_priv(mmc
);
1835 void __iomem
*base
= host
->base
;
1836 unsigned long flags
;
1839 /* for sdio, MSDC_REMOVABLE not set, always return 1 */
1840 if (!(host
->hw
->flags
& MSDC_REMOVABLE
)) {
1841 /* For sdio, read H/W always get<1>, but may timeout some times */
1843 host
->card_inserted
= 1;
1846 host
->card_inserted
= (host
->pm_state
.event
== PM_EVENT_USER_RESUME
) ? 1 : 0;
1847 INIT_MSG("sdio ops_get_cd<%d>", host
->card_inserted
);
1848 return host
->card_inserted
;
1852 /* MSDC_CD_PIN_EN set for card */
1853 if (host
->hw
->flags
& MSDC_CD_PIN_EN
) {
1854 spin_lock_irqsave(&host
->lock
, flags
);
1856 present
= host
->card_inserted
; /* why not read from H/W: Fix me*/
1860 present
= (sdr_read32(MSDC_PS
) & MSDC_PS_CDSTS
) ? 0 : 1;
1862 present
= (sdr_read32(MSDC_PS
) & MSDC_PS_CDSTS
) ? 1 : 0;
1863 if (host
->mmc
->caps
& MMC_CAP_NEEDS_POLL
)
1865 host
->card_inserted
= present
;
1867 spin_unlock_irqrestore(&host
->lock
, flags
);
1869 present
= 0; /* TODO? Check DAT3 pins for card detection */
1872 INIT_MSG("ops_get_cd return<%d>", present
);
1876 static struct mmc_host_ops mt_msdc_ops
= {
1877 .request
= msdc_ops_request
,
1878 .set_ios
= msdc_ops_set_ios
,
1879 .get_ro
= msdc_ops_get_ro
,
1880 .get_cd
= msdc_ops_get_cd
,
1883 /*--------------------------------------------------------------------------*/
1884 /* interrupt handler */
1885 /*--------------------------------------------------------------------------*/
1886 static irqreturn_t
msdc_irq(int irq
, void *dev_id
)
1888 struct msdc_host
*host
= (struct msdc_host
*)dev_id
;
1889 struct mmc_data
*data
= host
->data
;
1890 struct mmc_command
*cmd
= host
->cmd
;
1891 void __iomem
*base
= host
->base
;
1893 u32 cmdsts
= MSDC_INT_RSPCRCERR
| MSDC_INT_CMDTMO
| MSDC_INT_CMDRDY
|
1894 MSDC_INT_ACMDCRCERR
| MSDC_INT_ACMDTMO
| MSDC_INT_ACMDRDY
|
1895 MSDC_INT_ACMD19_DONE
;
1896 u32 datsts
= MSDC_INT_DATCRCERR
| MSDC_INT_DATTMO
;
1898 u32 intsts
= sdr_read32(MSDC_INT
);
1899 u32 inten
= sdr_read32(MSDC_INTEN
); inten
&= intsts
;
1901 sdr_write32(MSDC_INT
, intsts
); /* clear interrupts */
1902 /* MSG will cause fatal error */
1904 /* card change interrupt */
1905 if (intsts
& MSDC_INT_CDSC
) {
1906 if (host
->mmc
->caps
& MMC_CAP_NEEDS_POLL
)
1908 IRQ_MSG("MSDC_INT_CDSC irq<0x%.8x>", intsts
);
1909 schedule_delayed_work(&host
->card_delaywork
, HZ
);
1910 /* tuning when plug card ? */
1913 /* sdio interrupt */
1914 if (intsts
& MSDC_INT_SDIOIRQ
) {
1915 IRQ_MSG("XXX MSDC_INT_SDIOIRQ"); /* seems not sdio irq */
1916 //mmc_signal_sdio_irq(host->mmc);
1919 /* transfer complete interrupt */
1921 if (inten
& MSDC_INT_XFER_COMPL
) {
1922 data
->bytes_xfered
= host
->xfer_size
;
1923 complete(&host
->xfer_done
);
1926 if (intsts
& datsts
) {
1927 /* do basic reset, or stop command will sdc_busy */
1928 msdc_reset_hw(host
);
1932 if (intsts
& MSDC_INT_DATTMO
) {
1933 IRQ_MSG("XXX CMD<%d> MSDC_INT_DATTMO", host
->mrq
->cmd
->opcode
);
1934 data
->error
= -ETIMEDOUT
;
1935 } else if (intsts
& MSDC_INT_DATCRCERR
) {
1936 IRQ_MSG("XXX CMD<%d> MSDC_INT_DATCRCERR, SDC_DCRC_STS<0x%x>", host
->mrq
->cmd
->opcode
, sdr_read32(SDC_DCRC_STS
));
1940 //if(sdr_read32(MSDC_INTEN) & MSDC_INT_XFER_COMPL) {
1941 complete(&host
->xfer_done
); /* Read CRC come fast, XFER_COMPL not enabled */
1945 /* command interrupts */
1946 if ((cmd
!= NULL
) && (intsts
& cmdsts
)) {
1947 if ((intsts
& MSDC_INT_CMDRDY
) || (intsts
& MSDC_INT_ACMDRDY
) ||
1948 (intsts
& MSDC_INT_ACMD19_DONE
)) {
1949 u32
*rsp
= &cmd
->resp
[0];
1951 switch (host
->cmd_rsp
) {
1955 *rsp
++ = sdr_read32(SDC_RESP3
); *rsp
++ = sdr_read32(SDC_RESP2
);
1956 *rsp
++ = sdr_read32(SDC_RESP1
); *rsp
++ = sdr_read32(SDC_RESP0
);
1958 default: /* Response types 1, 3, 4, 5, 6, 7(1b) */
1959 if ((intsts
& MSDC_INT_ACMDRDY
) || (intsts
& MSDC_INT_ACMD19_DONE
))
1960 *rsp
= sdr_read32(SDC_ACMD_RESP
);
1962 *rsp
= sdr_read32(SDC_RESP0
);
1965 } else if ((intsts
& MSDC_INT_RSPCRCERR
) || (intsts
& MSDC_INT_ACMDCRCERR
)) {
1966 if (intsts
& MSDC_INT_ACMDCRCERR
)
1967 IRQ_MSG("XXX CMD<%d> MSDC_INT_ACMDCRCERR", cmd
->opcode
);
1969 IRQ_MSG("XXX CMD<%d> MSDC_INT_RSPCRCERR", cmd
->opcode
);
1971 } else if ((intsts
& MSDC_INT_CMDTMO
) || (intsts
& MSDC_INT_ACMDTMO
)) {
1972 if (intsts
& MSDC_INT_ACMDTMO
)
1973 IRQ_MSG("XXX CMD<%d> MSDC_INT_ACMDTMO", cmd
->opcode
);
1975 IRQ_MSG("XXX CMD<%d> MSDC_INT_CMDTMO", cmd
->opcode
);
1976 cmd
->error
= -ETIMEDOUT
;
1977 msdc_reset_hw(host
);
1981 complete(&host
->cmd_done
);
1984 /* mmc irq interrupts */
1985 if (intsts
& MSDC_INT_MMCIRQ
)
1986 printk(KERN_INFO
"msdc[%d] MMCIRQ: SDC_CSTS=0x%.8x\r\n", host
->id
, sdr_read32(SDC_CSTS
));
1988 #ifdef MT6575_SD_DEBUG
1990 /* msdc_int_reg *int_reg = (msdc_int_reg*)&intsts;*/
1991 N_MSG(INT
, "IRQ_EVT(0x%x): MMCIRQ(%d) CDSC(%d), ACRDY(%d), ACTMO(%d), ACCRE(%d) AC19DN(%d)",
1998 int_reg
->atocmd19done
);
1999 N_MSG(INT
, "IRQ_EVT(0x%x): SDIO(%d) CMDRDY(%d), CMDTMO(%d), RSPCRC(%d), CSTA(%d)",
2006 N_MSG(INT
, "IRQ_EVT(0x%x): XFCMP(%d) DXDONE(%d), DATTMO(%d), DATCRC(%d), DMAEMP(%d)",
2012 int_reg
->dmaqempty
);
2019 /*--------------------------------------------------------------------------*/
2020 /* platform_driver members */
2021 /*--------------------------------------------------------------------------*/
2022 /* called by msdc_drv_probe/remove */
2023 static void msdc_enable_cd_irq(struct msdc_host
*host
, int enable
)
2025 struct msdc_hw
*hw
= host
->hw
;
2026 void __iomem
*base
= host
->base
;
2028 /* for sdio, not set */
2029 if ((hw
->flags
& MSDC_CD_PIN_EN
) == 0) {
2030 /* Pull down card detection pin since it is not avaiable */
2032 if (hw->config_gpio_pin)
2033 hw->config_gpio_pin(MSDC_CD_PIN, GPIO_PULL_DOWN);
2035 sdr_clr_bits(MSDC_PS
, MSDC_PS_CDEN
);
2036 sdr_clr_bits(MSDC_INTEN
, MSDC_INTEN_CDSC
);
2037 sdr_clr_bits(SDC_CFG
, SDC_CFG_INSWKUP
);
2041 N_MSG(CFG
, "CD IRQ Eanable(%d)", enable
);
2044 /* card detection circuit relies on the core power so that the core power
2045 * shouldn't be turned off. Here adds a reference count to keep
2046 * the core power alive.
2048 //msdc_vcore_on(host); //did in msdc_init_hw()
2050 if (hw
->config_gpio_pin
) /* NULL */
2051 hw
->config_gpio_pin(MSDC_CD_PIN
, GPIO_PULL_UP
);
2053 sdr_set_field(MSDC_PS
, MSDC_PS_CDDEBOUNCE
, DEFAULT_DEBOUNCE
);
2054 sdr_set_bits(MSDC_PS
, MSDC_PS_CDEN
);
2055 sdr_set_bits(MSDC_INTEN
, MSDC_INTEN_CDSC
);
2056 sdr_set_bits(SDC_CFG
, SDC_CFG_INSWKUP
); /* not in document! Fix me */
2058 if (hw
->config_gpio_pin
) /* NULL */
2059 hw
->config_gpio_pin(MSDC_CD_PIN
, GPIO_PULL_DOWN
);
2061 sdr_clr_bits(SDC_CFG
, SDC_CFG_INSWKUP
);
2062 sdr_clr_bits(MSDC_PS
, MSDC_PS_CDEN
);
2063 sdr_clr_bits(MSDC_INTEN
, MSDC_INTEN_CDSC
);
2065 /* Here decreases a reference count to core power since card
2066 * detection circuit is shutdown.
2068 //msdc_vcore_off(host);
2072 /* called by msdc_drv_probe */
2073 static void msdc_init_hw(struct msdc_host
*host
)
2075 void __iomem
*base
= host
->base
;
2078 #if 0 /* --- by chhung */
2079 msdc_vcore_on(host
);
2080 msdc_pin_reset(host
, MSDC_PIN_PULL_UP
);
2081 msdc_select_clksrc(host
, hw
->clk_src
);
2082 enable_clock(PERI_MSDC0_PDN
+ host
->id
, "SD");
2084 #endif /* end of --- */
2085 /* Configure to MMC/SD mode */
2086 sdr_set_field(MSDC_CFG
, MSDC_CFG_MODE
, MSDC_SDMMC
);
2089 msdc_reset_hw(host
);
2092 /* Disable card detection */
2093 sdr_clr_bits(MSDC_PS
, MSDC_PS_CDEN
);
2095 /* Disable and clear all interrupts */
2096 sdr_clr_bits(MSDC_INTEN
, sdr_read32(MSDC_INTEN
));
2097 sdr_write32(MSDC_INT
, sdr_read32(MSDC_INT
));
2100 /* reset tuning parameter */
2101 sdr_write32(MSDC_PAD_CTL0
, 0x00090000);
2102 sdr_write32(MSDC_PAD_CTL1
, 0x000A0000);
2103 sdr_write32(MSDC_PAD_CTL2
, 0x000A0000);
2104 // sdr_write32(MSDC_PAD_TUNE, 0x00000000);
2105 sdr_write32(MSDC_PAD_TUNE
, 0x84101010); // for MT7620 E2 and afterward
2106 // sdr_write32(MSDC_DAT_RDDLY0, 0x00000000);
2107 sdr_write32(MSDC_DAT_RDDLY0
, 0x10101010); // for MT7620 E2 and afterward
2108 sdr_write32(MSDC_DAT_RDDLY1
, 0x00000000);
2109 sdr_write32(MSDC_IOCON
, 0x00000000);
2110 #if 0 // use MT7620 default value: 0x403c004f
2111 sdr_write32(MSDC_PATCH_BIT0
, 0x003C000F); /* bit0 modified: Rx Data Clock Source: 1 -> 2.0*/
2114 if (sdr_read32(MSDC_ECO_VER
) >= 4) {
2115 if (host
->id
== 1) {
2116 sdr_set_field(MSDC_PATCH_BIT1
, MSDC_PATCH_BIT1_WRDAT_CRCS
, 1);
2117 sdr_set_field(MSDC_PATCH_BIT1
, MSDC_PATCH_BIT1_CMD_RSP
, 1);
2119 /* internal clock: latch read data */
2120 sdr_set_bits(MSDC_PATCH_BIT0
, MSDC_PATCH_BIT_CKGEN_CK
);
2125 /* for safety, should clear SDC_CFG.SDIO_INT_DET_EN & set SDC_CFG.SDIO in
2126 pre-loader,uboot,kernel drivers. and SDC_CFG.SDIO_INT_DET_EN will be only
2127 set when kernel driver wants to use SDIO bus interrupt */
2128 /* Configure to enable SDIO mode. it's must otherwise sdio cmd5 failed */
2129 sdr_set_bits(SDC_CFG
, SDC_CFG_SDIO
);
2131 /* disable detect SDIO device interupt function */
2132 sdr_clr_bits(SDC_CFG
, SDC_CFG_SDIOIDE
);
2134 /* eneable SMT for glitch filter */
2135 sdr_set_bits(MSDC_PAD_CTL0
, MSDC_PAD_CTL0_CLKSMT
);
2136 sdr_set_bits(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDSMT
);
2137 sdr_set_bits(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATSMT
);
2140 /* set clk, cmd, dat pad driving */
2141 sdr_set_field(MSDC_PAD_CTL0
, MSDC_PAD_CTL0_CLKDRVN
, 4);
2142 sdr_set_field(MSDC_PAD_CTL0
, MSDC_PAD_CTL0_CLKDRVP
, 4);
2143 sdr_set_field(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDDRVN
, 4);
2144 sdr_set_field(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDDRVP
, 4);
2145 sdr_set_field(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATDRVN
, 4);
2146 sdr_set_field(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATDRVP
, 4);
2148 sdr_set_field(MSDC_PAD_CTL0
, MSDC_PAD_CTL0_CLKDRVN
, 0);
2149 sdr_set_field(MSDC_PAD_CTL0
, MSDC_PAD_CTL0_CLKDRVP
, 0);
2150 sdr_set_field(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDDRVN
, 0);
2151 sdr_set_field(MSDC_PAD_CTL1
, MSDC_PAD_CTL1_CMDDRVP
, 0);
2152 sdr_set_field(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATDRVN
, 0);
2153 sdr_set_field(MSDC_PAD_CTL2
, MSDC_PAD_CTL2_DATDRVP
, 0);
2156 /* set sampling edge */
2158 /* write crc timeout detection */
2159 sdr_set_field(MSDC_PATCH_BIT0
, 1 << 30, 1);
2161 /* Configure to default data timeout */
2162 sdr_set_field(SDC_CFG
, SDC_CFG_DTOC
, DEFAULT_DTOC
);
2164 msdc_set_buswidth(host
, MMC_BUS_WIDTH_1
);
2166 N_MSG(FUC
, "init hardware done!");
2169 /* called by msdc_drv_remove */
2170 static void msdc_deinit_hw(struct msdc_host
*host
)
2172 void __iomem
*base
= host
->base
;
2174 /* Disable and clear all interrupts */
2175 sdr_clr_bits(MSDC_INTEN
, sdr_read32(MSDC_INTEN
));
2176 sdr_write32(MSDC_INT
, sdr_read32(MSDC_INT
));
2178 /* Disable card detection */
2179 msdc_enable_cd_irq(host
, 0);
2180 // msdc_set_power_mode(host, MMC_POWER_OFF); /* make sure power down */ /* --- by chhung */
2183 /* init gpd and bd list in msdc_drv_probe */
2184 static void msdc_init_gpd_bd(struct msdc_host
*host
, struct msdc_dma
*dma
)
2186 struct gpd
*gpd
= dma
->gpd
;
2187 struct bd
*bd
= dma
->bd
;
2190 /* we just support one gpd, but gpd->next must be set for desc
2191 * DMA. That's why we alloc 2 gpd structurs.
2194 memset(gpd
, 0, sizeof(struct gpd
) * 2);
2196 gpd
->bdp
= 1; /* hwo, cs, bd pointer */
2197 gpd
->ptr
= (void *)dma
->bd_addr
; /* physical address */
2198 gpd
->next
= (void *)((u32
)dma
->gpd_addr
+ sizeof(struct gpd
));
2200 memset(bd
, 0, sizeof(struct bd
) * MAX_BD_NUM
);
2201 for (i
= 0; i
< (MAX_BD_NUM
- 1); i
++)
2202 bd
[i
].next
= (void *)(dma
->bd_addr
+ sizeof(*bd
) * (i
+ 1));
2205 static int msdc_drv_probe(struct platform_device
*pdev
)
2207 struct resource
*res
;
2209 struct mmc_host
*mmc
;
2210 struct msdc_host
*host
;
2214 //FIXME: this should be done by pinconf and not by the sd driver
2215 if ((ralink_soc
== MT762X_SOC_MT7688
||
2216 ralink_soc
== MT762X_SOC_MT7628AN
) &&
2217 (!(rt_sysc_r32(0x60) & BIT(15))))
2218 rt_sysc_m32(0xf << 17, 0xf << 17, 0x3c);
2222 if (of_property_read_bool(pdev
->dev
.of_node
, "mtk,wp-en"))
2223 msdc0_hw
.flags
|= MSDC_WP_PIN_EN
;
2225 /* Allocate MMC host for this device */
2226 mmc
= mmc_alloc_host(sizeof(struct msdc_host
), &pdev
->dev
);
2230 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2231 base
= devm_ioremap_resource(&pdev
->dev
, res
);
2233 ret
= PTR_ERR(base
);
2237 /* Set host parameters to mmc */
2238 mmc
->ops
= &mt_msdc_ops
;
2239 mmc
->f_min
= HOST_MIN_MCLK
;
2240 mmc
->f_max
= HOST_MAX_MCLK
;
2241 mmc
->ocr_avail
= MSDC_OCR_AVAIL
;
2243 mmc
->caps
= MMC_CAP_MMC_HIGHSPEED
| MMC_CAP_SD_HIGHSPEED
;
2245 //TODO: read this as bus-width from dt (via mmc_of_parse)
2246 mmc
->caps
|= MMC_CAP_4_BIT_DATA
;
2248 cd_active_low
= !of_property_read_bool(pdev
->dev
.of_node
, "mediatek,cd-high");
2250 if (of_property_read_bool(pdev
->dev
.of_node
, "mediatek,cd-poll"))
2251 mmc
->caps
|= MMC_CAP_NEEDS_POLL
;
2253 /* MMC core transfer sizes tunable parameters */
2254 mmc
->max_segs
= MAX_HW_SGMTS
;
2256 mmc
->max_seg_size
= MAX_SGMT_SZ
;
2257 mmc
->max_blk_size
= HOST_MAX_BLKSZ
;
2258 mmc
->max_req_size
= MAX_REQ_SZ
;
2259 mmc
->max_blk_count
= mmc
->max_req_size
;
2261 host
= mmc_priv(mmc
);
2264 host
->id
= pdev
->id
;
2265 if (host
->id
< 0 || host
->id
>= 4)
2269 host
->irq
= platform_get_irq(pdev
, 0);
2270 if (host
->irq
< 0) {
2276 host
->mclk
= 0; /* mclk: the request clock of mmc sub-system */
2277 host
->hclk
= hclks
[hw
->clk_src
]; /* hclk: clock of clock source to msdc controller */
2278 host
->sclk
= 0; /* sclk: the really clock after divition */
2279 host
->pm_state
= PMSG_RESUME
;
2281 host
->core_clkon
= 0;
2282 host
->card_clkon
= 0;
2283 host
->core_power
= 0;
2284 host
->power_mode
= MMC_POWER_OFF
;
2285 // host->card_inserted = hw->flags & MSDC_REMOVABLE ? 0 : 1;
2286 host
->timeout_ns
= 0;
2287 host
->timeout_clks
= DEFAULT_DTOC
* 65536;
2290 //init_MUTEX(&host->sem); /* we don't need to support multiple threads access */
2292 dma_coerce_mask_and_coherent(mmc_dev(mmc
), DMA_BIT_MASK(32));
2294 /* using dma_alloc_coherent*/ /* todo: using 1, for all 4 slots */
2295 host
->dma
.gpd
= dma_alloc_coherent(&pdev
->dev
,
2296 MAX_GPD_NUM
* sizeof(struct gpd
),
2297 &host
->dma
.gpd_addr
, GFP_KERNEL
);
2298 host
->dma
.bd
= dma_alloc_coherent(&pdev
->dev
,
2299 MAX_BD_NUM
* sizeof(struct bd
),
2300 &host
->dma
.bd_addr
, GFP_KERNEL
);
2301 if (!host
->dma
.gpd
|| !host
->dma
.bd
) {
2305 msdc_init_gpd_bd(host
, &host
->dma
);
2307 INIT_DELAYED_WORK(&host
->card_delaywork
, msdc_tasklet_card
);
2308 spin_lock_init(&host
->lock
);
2311 /* TODO check weather flags 0 is correct, the mtk-sd driver uses
2312 * IRQF_TRIGGER_LOW | IRQF_ONESHOT for flags
2314 * for flags 0 the trigger polarity is determined by the
2315 * device tree, but not the oneshot flag, but maybe it is also
2316 * not needed because the soc could be oneshot safe.
2318 ret
= devm_request_irq(&pdev
->dev
, host
->irq
, msdc_irq
, 0, pdev
->name
,
2323 platform_set_drvdata(pdev
, mmc
);
2325 ret
= mmc_add_host(mmc
);
2329 /* Config card detection pin and enable interrupts */
2330 if (hw
->flags
& MSDC_CD_PIN_EN
) { /* set for card */
2331 msdc_enable_cd_irq(host
, 1);
2333 msdc_enable_cd_irq(host
, 0);
2339 platform_set_drvdata(pdev
, NULL
);
2340 msdc_deinit_hw(host
);
2341 cancel_delayed_work_sync(&host
->card_delaywork
);
2345 dma_free_coherent(&pdev
->dev
, MAX_GPD_NUM
* sizeof(struct gpd
),
2346 host
->dma
.gpd
, host
->dma
.gpd_addr
);
2348 dma_free_coherent(&pdev
->dev
, MAX_BD_NUM
* sizeof(struct bd
),
2349 host
->dma
.bd
, host
->dma
.bd_addr
);
2356 /* 4 device share one driver, using "drvdata" to show difference */
2357 static int msdc_drv_remove(struct platform_device
*pdev
)
2359 struct mmc_host
*mmc
;
2360 struct msdc_host
*host
;
2362 mmc
= platform_get_drvdata(pdev
);
2365 host
= mmc_priv(mmc
);
2368 ERR_MSG("removed !!!");
2370 platform_set_drvdata(pdev
, NULL
);
2371 mmc_remove_host(host
->mmc
);
2372 msdc_deinit_hw(host
);
2374 cancel_delayed_work_sync(&host
->card_delaywork
);
2376 dma_free_coherent(&pdev
->dev
, MAX_GPD_NUM
* sizeof(struct gpd
),
2377 host
->dma
.gpd
, host
->dma
.gpd_addr
);
2378 dma_free_coherent(&pdev
->dev
, MAX_BD_NUM
* sizeof(struct bd
),
2379 host
->dma
.bd
, host
->dma
.bd_addr
);
2381 mmc_free_host(host
->mmc
);
2386 /* Fix me: Power Flow */
2389 static void msdc_drv_pm(struct platform_device
*pdev
, pm_message_t state
)
2391 struct mmc_host
*mmc
= platform_get_drvdata(pdev
);
2393 struct msdc_host
*host
= mmc_priv(mmc
);
2394 msdc_pm(state
, (void *)host
);
2398 static int msdc_drv_suspend(struct platform_device
*pdev
, pm_message_t state
)
2400 if (state
.event
== PM_EVENT_SUSPEND
)
2401 msdc_drv_pm(pdev
, state
);
2405 static int msdc_drv_resume(struct platform_device
*pdev
)
2407 struct pm_message state
;
2409 state
.event
= PM_EVENT_RESUME
;
2410 msdc_drv_pm(pdev
, state
);
2415 static const struct of_device_id mt7620_sdhci_match
[] = {
2416 { .compatible
= "ralink,mt7620-sdhci" },
2419 MODULE_DEVICE_TABLE(of
, mt7620_sdhci_match
);
2421 static struct platform_driver mt_msdc_driver
= {
2422 .probe
= msdc_drv_probe
,
2423 .remove
= msdc_drv_remove
,
2425 .suspend
= msdc_drv_suspend
,
2426 .resume
= msdc_drv_resume
,
2430 .of_match_table
= mt7620_sdhci_match
,
2434 /*--------------------------------------------------------------------------*/
2435 /* module init/exit */
2436 /*--------------------------------------------------------------------------*/
2437 static int __init
mt_msdc_init(void)
2441 ret
= platform_driver_register(&mt_msdc_driver
);
2443 printk(KERN_ERR DRV_NAME
": Can't register driver");
2447 #if defined(MT6575_SD_DEBUG)
2448 msdc_debug_proc_init();
2453 static void __exit
mt_msdc_exit(void)
2455 platform_driver_unregister(&mt_msdc_driver
);
2458 module_init(mt_msdc_init
);
2459 module_exit(mt_msdc_exit
);
2460 MODULE_LICENSE("GPL");
2461 MODULE_DESCRIPTION("MediaTek MT6575 SD/MMC Card Driver");
2462 MODULE_AUTHOR("Infinity Chen <infinity.chen@mediatek.com>");