1 /* drivers/mmc/host/rk29_sdmmc.c
3 * Copyright (C) 2010 ROCKCHIP, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * mount -t debugfs debugfs /data/debugfs;cat /data/debugfs/mmc0/status
15 * echo 't' >/proc/sysrq-trigger
16 * echo 19 >/sys/module/wakelock/parameters/debug_mask
17 * vdc volume uevent on
20 #include <linux/blkdev.h>
21 #include <linux/clk.h>
22 #include <linux/debugfs.h>
23 #include <linux/device.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/err.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
28 #include <linux/ioport.h>
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
31 #include <linux/scatterlist.h>
32 #include <linux/seq_file.h>
33 #include <linux/stat.h>
34 #include <linux/delay.h>
35 #include <linux/irq.h>
36 #include <linux/slab.h>
37 #include <linux/version.h>
38 #include <linux/mmc/host.h>
39 #include <linux/mmc/mmc.h>
40 #include <linux/mmc/card.h>
42 #include <mach/board.h>
44 #include <mach/gpio.h>
45 #include <mach/iomux.h>
48 #include <mach/dma-pl330.h>
49 #include <asm/scatterlist.h>
51 #include "rk29_sdmmc.h"
54 #define RK29_SDMMC_xbw_Debug 0
56 #if RK29_SDMMC_xbw_Debug
58 #define xbwprintk(n, format, arg...) \
59 if (n <= debug_level) { \
60 printk(format,##arg); \
63 #define xbwprintk(n, arg...)
66 #if defined(CONFIG_ARCH_RK29)
67 #define SDMMC_USE_INT_UNBUSY 0
69 #define SDMMC_USE_INT_UNBUSY 1
72 #define RK29_SDMMC_ERROR_FLAGS (SDMMC_INT_FRUN | SDMMC_INT_HLE )
74 #if SDMMC_USE_INT_UNBUSY
75 #define RK29_SDMMC_INTMASK_USEDMA (SDMMC_INT_CMD_DONE | SDMMC_INT_DTO | SDMMC_INT_UNBUSY |RK29_SDMMC_ERROR_FLAGS | SDMMC_INT_CD)
76 #define RK29_SDMMC_INTMASK_USEIO (SDMMC_INT_CMD_DONE | SDMMC_INT_DTO | SDMMC_INT_UNBUSY |RK29_SDMMC_ERROR_FLAGS | SDMMC_INT_CD| SDMMC_INT_TXDR | SDMMC_INT_RXDR )
78 #define RK29_SDMMC_INTMASK_USEDMA (SDMMC_INT_CMD_DONE | SDMMC_INT_DTO | RK29_SDMMC_ERROR_FLAGS | SDMMC_INT_CD)
79 #define RK29_SDMMC_INTMASK_USEIO (SDMMC_INT_CMD_DONE | SDMMC_INT_DTO | RK29_SDMMC_ERROR_FLAGS | SDMMC_INT_CD| SDMMC_INT_TXDR | SDMMC_INT_RXDR )
82 #define RK29_SDMMC_SEND_START_TIMEOUT 3000 //The time interval from the time SEND_CMD to START_CMD_BIT cleared.
83 #define RK29_ERROR_PRINTK_INTERVAL 200 //The time interval between the two printk for the same error.
84 #define RK29_SDMMC_WAIT_DTO_INTERNVAL 4500 //The time interval from the CMD_DONE_INT to DTO_INT
85 #define RK29_SDMMC_REMOVAL_DELAY 2000 //The time interval from the CD_INT to detect_timer react.
87 #define RK29_SDMMC_VERSION "Ver.3.06 The last modify date is 2012-04-05"
89 #if !defined(CONFIG_USE_SDMMC0_FOR_WIFI_DEVELOP_BOARD)
90 #define RK29_CTRL_SDMMC_ID 0 //mainly used by SDMMC
91 #define RK29_CTRL_SDIO1_ID 1 //mainly used by sdio-wifi
92 #define RK29_CTRL_SDIO2_ID 2 //mainly used by sdio-card
94 #define RK29_CTRL_SDMMC_ID 5
95 #define RK29_CTRL_SDIO1_ID 1
96 #define RK29_CTRL_SDIO2_ID 2
99 #define SDMMC_CLOCK_TEST 0
101 #define RK29_SDMMC_NOTIFY_REMOVE_INSERTION /* use sysfs to notify the removal or insertion of sd-card*/
102 //#define RK29_SDMMC_LIST_QUEUE /* use list-queue for multi-card*/
104 #define RK29_SDMMC_DEFAULT_SDIO_FREQ 0 // 1--run in default frequency(50Mhz); 0---run in 25Mhz,
105 #define RK29_MAX_SDIO_FREQ 25000000 //set max-sdio-frequency 25Mhz at the present time¡£
108 EVENT_CMD_COMPLETE = 0,
115 enum rk29_sdmmc_state {
124 struct rk29_sdmmc_dma_info {
127 struct rk29_dma_client client;
130 static struct rk29_sdmmc_dma_info rk29_sdmmc_dma_infos[]= {
134 .name = "rk29-dma-sdmmc0",
140 .name = "rk29-dma-sdio1",
147 .name = "rk29-dma-sdio2",
153 /* Interrupt Information */
154 typedef struct TagSDC_INT_INFO
156 u32 transLen; //the length of data sent.
157 u32 desLen; //the total length of the all data.
158 u32 *pBuf; //the data buffer for interrupt read or write.
167 struct mmc_request *mrq;
168 struct mmc_request *new_mrq;
169 struct mmc_command *cmd;
170 struct mmc_data *data;
172 dma_addr_t dma_addr;;
173 unsigned int use_dma:1;
180 u32 cmdr; //the value setted into command-register
181 u32 dodma; //sign the DMA used for transfer.
182 u32 errorstep;//record the error point.
184 SDC_INT_INFO_T intInfo;
185 struct rk29_sdmmc_dma_info dma_info;
190 struct tasklet_struct tasklet;
191 unsigned long pending_events;
192 unsigned long completed_events;
193 enum rk29_sdmmc_state state;
195 #ifdef RK29_SDMMC_LIST_QUEUE
196 struct list_head queue;
197 struct list_head queue_node;
201 struct platform_device *pdev;
202 struct mmc_host *mmc;
207 #define RK29_SDMMC_CARD_PRESENT 0
211 struct timer_list detect_timer;
212 struct timer_list request_timer; //the timer for INT_CMD_DONE
213 struct timer_list DTO_timer; //the timer for INT_DTO
214 struct mmc_command stopcmd;
216 /* flag for current bus settings */
219 unsigned int oldstatus;
220 unsigned int complete_done;
221 unsigned int retryfunc;
228 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT) || defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
232 void (*set_iomux)(int device_id, unsigned int bus_width);
237 #ifdef RK29_SDMMC_NOTIFY_REMOVE_INSERTION
238 static struct rk29_sdmmc *globalSDhost[3];
241 #define rk29_sdmmc_test_and_clear_pending(host, event) \
242 test_and_clear_bit(event, &host->pending_events)
243 #define rk29_sdmmc_test_pending(host, event) \
244 test_bit(event, &host->pending_events)
245 #define rk29_sdmmc_test_completed(host, event) \
246 test_bit(event, &host->completed_events)
247 #define rk29_sdmmc_set_completed(host, event) \
248 set_bit(event, &host->completed_events)
249 #define rk29_sdmmc_set_pending(host, event) \
250 set_bit(event, &host->pending_events)
252 static void rk29_sdmmc_start_error(struct rk29_sdmmc *host);
253 static int rk29_sdmmc_clear_fifo(struct rk29_sdmmc *host);
254 int rk29_sdmmc_hw_init(void *data);
256 static void rk29_sdmmc_write(unsigned char __iomem *regbase, unsigned int regOff,unsigned int val)
258 __raw_writel(val,regbase + regOff);
261 static unsigned int rk29_sdmmc_read(unsigned char __iomem *regbase, unsigned int regOff)
263 return __raw_readl(regbase + regOff);
266 static int rk29_sdmmc_regs_printk(struct rk29_sdmmc *host)
268 printk("SDMMC_CTRL: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CTRL));
269 printk("SDMMC_PWREN: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_PWREN));
270 printk("SDMMC_CLKDIV: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CLKDIV));
271 printk("SDMMC_CLKSRC: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CLKSRC));
272 printk("SDMMC_CLKENA: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CLKENA));
273 printk("SDMMC_TMOUT: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_TMOUT));
274 printk("SDMMC_CTYPE: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CTYPE));
275 printk("SDMMC_BLKSIZ: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_BLKSIZ));
276 printk("SDMMC_BYTCNT: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_BYTCNT));
277 printk("SDMMC_INTMASK:\t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_INTMASK));
278 printk("SDMMC_CMDARG: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CMDARG));
279 printk("SDMMC_CMD: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CMD));
280 printk("SDMMC_RESP0: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RESP0));
281 printk("SDMMC_RESP1: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RESP1));
282 printk("SDMMC_RESP2: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RESP2));
283 printk("SDMMC_RESP3: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RESP3));
284 printk("SDMMC_MINTSTS:\t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_MINTSTS));
285 printk("SDMMC_RINTSTS:\t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RINTSTS));
286 printk("SDMMC_STATUS: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_STATUS));
287 printk("SDMMC_FIFOTH: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_FIFOTH));
288 printk("SDMMC_CDETECT:\t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CDETECT));
289 printk("SDMMC_WRTPRT: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_WRTPRT));
290 printk("SDMMC_TCBCNT: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_TCBCNT));
291 printk("SDMMC_TBBCNT: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_TBBCNT));
292 printk("SDMMC_DEBNCE: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_DEBNCE));
293 printk("SDMMC_USRID: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_USRID));
295 #if !defined(CONFIG_ARCH_RK29)
296 printk("SDMMC_VERID: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_VERID));
297 printk("SDMMC_UHS_REG:\t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_UHS_REG));
298 printk("SDMMC_RST_n: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RST_n));
299 printk("SDMMC_CARDTHRCTL: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CARDTHRCTL));
300 printk("SDMMC_BACK_END_POWER: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_BACK_END_POWER));
302 printk("=======printk %s-register end =========\n", host->dma_name);
307 #ifdef RK29_SDMMC_NOTIFY_REMOVE_INSERTION
308 ssize_t rk29_sdmmc_progress_store(struct kobject *kobj, struct kobj_attribute *attr,
309 const char *buf, size_t count)
311 struct rk29_sdmmc *host = NULL;
312 static u32 unmounting_times = 0;
313 static char oldbuf[64];
315 if( !strncmp(buf,"version" , strlen("version")))
317 printk(KERN_INFO "\n The driver SDMMC named 'rk29_sdmmc.c' is %s.\n", RK29_SDMMC_VERSION);
321 //envalue the address of host base on input-parameter.
322 if( !strncmp(buf,"sd-" , strlen("sd-")) )
324 host = (struct rk29_sdmmc *)globalSDhost[0];
327 printk(KERN_ERR "%s..%d.. fail to call progress_store because the host is null. \n",__FUNCTION__,__LINE__);
331 else if( !strncmp(buf,"sdio1-" , strlen("sdio1-")) )
333 host = (struct rk29_sdmmc *)globalSDhost[RK29_CTRL_SDIO1_ID];
336 printk(KERN_ERR "%s..%d.. fail to call progress_store because the host-sdio1 is null.\n",__FUNCTION__,__LINE__);
340 else if( !strncmp(buf,"sdio2-" , strlen("sdio2-")) )
342 host = (struct rk29_sdmmc *)globalSDhost[RK29_CTRL_SDIO2_ID];
345 printk(KERN_ERR "%s..%d.. fail to call progress_store because the host-sdio2 is null.\n",__FUNCTION__,__LINE__);
351 printk(KERN_ERR "%s..%d.. You want to use sysfs for SDMMC but input-parameter is wrong.\n",__FUNCTION__,__LINE__);
355 spin_lock(&host->lock);
356 if(strncmp(buf,oldbuf , strlen(buf)))
358 printk(KERN_INFO ".%d.. MMC0 receive the message %s from VOLD.[%s]\n", __LINE__, buf, host->dma_name);
363 * //deal with the message
364 * insert card state-change: No-Media ==> Pending ==> Idle-Unmounted ==> Checking ==>Mounted
365 * remove card state-change: Unmounting ==> Idle-Unmounted ==> No-Media
367 #if !defined(CONFIG_USE_SDMMC0_FOR_WIFI_DEVELOP_BOARD)
368 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
370 if(!strncmp(buf, "sd-Unmounting", strlen("sd-Unmounting")))
372 if(unmounting_times++%10 == 0)
374 printk(KERN_INFO ".%d.. MMC0 receive the message Unmounting(waitTimes=%d) from VOLD.[%s]\n", \
375 __LINE__, unmounting_times, host->dma_name);
378 if(0 == host->mmc->re_initialized_flags)
379 mod_timer(&host->detect_timer, jiffies + msecs_to_jiffies(RK29_SDMMC_REMOVAL_DELAY*2));
381 else if(!strncmp(buf, "sd-Idle-Unmounted", strlen("sd-Idle-Unmounted")))
383 if(0 == host->mmc->re_initialized_flags)
384 mod_timer(&host->detect_timer, jiffies + msecs_to_jiffies(RK29_SDMMC_REMOVAL_DELAY*2));
386 else if( !strncmp(buf, "sd-No-Media", strlen("sd-No-Media")))
388 printk(KERN_INFO ".%d.. MMC0 receive the message No-Media from VOLD. waitTimes=%d [%s]\n" ,\
389 __LINE__,unmounting_times, host->dma_name);
391 del_timer_sync(&host->detect_timer);
392 host->mmc->re_initialized_flags = 1;
393 unmounting_times = 0;
395 if(test_bit(RK29_SDMMC_CARD_PRESENT, &host->flags))
397 mmc_detect_change(host->mmc, 0);
400 else if( !strncmp(buf, "sd-Ready", strlen("sd-Ready")))
402 printk(KERN_INFO ".%d.. MMC0 receive the message Ready(ReInitFlag=%d) from VOLD. waitTimes=%d [%s]\n" ,\
403 __LINE__, host->mmc->re_initialized_flags, unmounting_times, host->dma_name);
405 unmounting_times = 0;
406 host->mmc->re_initialized_flags = 1;
408 else if( !strncmp(buf,"sd-reset" , strlen("sd-reset")) )
410 printk(KERN_INFO ".%d.. Now manual reset for SDMMC0. [%s]\n",__LINE__, host->dma_name);
411 rk29_sdmmc_hw_init(host);
412 mmc_detect_change(host->mmc, 0);
414 else if( !strncmp(buf, "sd-regs", strlen("sd-regs")))
416 printk(KERN_INFO ".%d.. Now printk the register of SDMMC0. [%s]\n",__LINE__, host->dma_name);
417 rk29_sdmmc_regs_printk(host);
422 if(0 == host->pdev->id)
424 if( !strncmp(buf,"sd-reset" , strlen("sd-reset")) )
426 printk(KERN_INFO ".%d.. Now manual reset for SDMMC0. [%s]\n",__LINE__, host->dma_name);
427 rk29_sdmmc_hw_init(host);
428 mmc_detect_change(host->mmc, 0);
430 else if( !strncmp(buf, "sd-regs", strlen("sd-regs")))
432 printk(KERN_INFO ".%d.. Now printk the register of SDMMC0. [%s]\n",__LINE__, host->dma_name);
433 rk29_sdmmc_regs_printk(host);
437 else if(RK29_CTRL_SDIO1_ID == host->pdev->id)
439 if( !strncmp(buf, "sdio1-regs", strlen("sdio1-regs")))
441 printk(KERN_INFO ".%d.. Now printk the register of SDMMC1. [%s]\n",__LINE__, host->dma_name);
442 rk29_sdmmc_regs_printk(host);
444 else if( !strncmp(buf,"sdio1-reset" , strlen("sdio1-reset")) )
446 printk(KERN_INFO ".%d.. Now manual reset for SDMMC1. [%s]\n",__LINE__, host->dma_name);
447 rk29_sdmmc_hw_init(host);
448 mmc_detect_change(host->mmc, 0);
451 else if(RK29_CTRL_SDIO2_ID == host->pdev->id)
453 if( !strncmp(buf, "sdio2-regs", strlen("sdio2-regs")))
455 printk(KERN_INFO ".%d.. Now printk the register of SDMMC2. [%s]\n",__LINE__, host->dma_name);
456 rk29_sdmmc_regs_printk(host);
458 else if( !strncmp(buf,"sdio2-reset" , strlen("sdio2-reset")) )
460 printk(KERN_INFO ".%d.. Now manual reset for SDMMC2. [%s]\n",__LINE__, host->dma_name);
461 rk29_sdmmc_hw_init(host);
462 mmc_detect_change(host->mmc, 0);
466 spin_unlock(&host->lock);
473 struct kobj_attribute mmc_reset_attrs =
479 .store = rk29_sdmmc_progress_store,
481 struct attribute *mmc_attrs[] =
483 &mmc_reset_attrs.attr,
487 static struct kobj_type mmc_kset_ktype = {
488 .sysfs_ops = &kobj_sysfs_ops,
489 .default_attrs = &mmc_attrs[0],
492 static int rk29_sdmmc_progress_add_attr( struct platform_device *pdev )
495 struct kobject *parentkobject;
496 struct kobject * me = kmalloc(sizeof(struct kobject) , GFP_KERNEL );
501 memset(me ,0,sizeof(struct kobject));
502 kobject_init( me , &mmc_kset_ktype );
504 parentkobject = &pdev->dev.kobj ;
505 result = kobject_add( me , parentkobject->parent->parent->parent,"%s", "sd-sdio" );
511 #if defined (CONFIG_DEBUG_FS)
512 static int rk29_sdmmc_regs_show(struct seq_file *s, void *v)
514 struct rk29_sdmmc *host = s->private;
516 seq_printf(s, "SDMMC_CTRL: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CTRL));
517 seq_printf(s, "SDMMC_PWREN: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_PWREN));
518 seq_printf(s, "SDMMC_CLKDIV: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CLKDIV));
519 seq_printf(s, "SDMMC_CLKSRC: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CLKSRC));
520 seq_printf(s, "SDMMC_CLKENA: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CLKENA));
521 seq_printf(s, "SDMMC_TMOUT: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_TMOUT));
522 seq_printf(s, "SDMMC_CTYPE: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CTYPE));
523 seq_printf(s, "SDMMC_BLKSIZ: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_BLKSIZ));
524 seq_printf(s, "SDMMC_BYTCNT: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_BYTCNT));
525 seq_printf(s, "SDMMC_INTMASK:\t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_INTMASK));
526 seq_printf(s, "SDMMC_CMDARG: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CMDARG));
527 seq_printf(s, "SDMMC_CMD: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CMD));
528 seq_printf(s, "SDMMC_RESP0: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RESP0));
529 seq_printf(s, "SDMMC_RESP1: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RESP1));
530 seq_printf(s, "SDMMC_RESP2: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RESP2));
531 seq_printf(s, "SDMMC_RESP3: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RESP3));
532 seq_printf(s, "SDMMC_MINTSTS:\t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_MINTSTS));
533 seq_printf(s, "SDMMC_RINTSTS:\t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_RINTSTS));
534 seq_printf(s, "SDMMC_STATUS: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_STATUS));
535 seq_printf(s, "SDMMC_FIFOTH: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_FIFOTH));
536 seq_printf(s, "SDMMC_CDETECT:\t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_CDETECT));
537 seq_printf(s, "SDMMC_WRTPRT: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_WRTPRT));
538 seq_printf(s, "SDMMC_TCBCNT: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_TCBCNT));
539 seq_printf(s, "SDMMC_TBBCNT: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_TBBCNT));
540 seq_printf(s, "SDMMC_DEBNCE: \t0x%08x\n", rk29_sdmmc_read(host->regs, SDMMC_DEBNCE));
547 * The debugfs stuff below is mostly optimized away when
548 * CONFIG_DEBUG_FS is not set.
550 static int rk29_sdmmc_req_show(struct seq_file *s, void *v)
552 struct rk29_sdmmc *host = s->private;
553 struct mmc_request *mrq;
554 struct mmc_command *cmd;
555 struct mmc_command *stop;
556 struct mmc_data *data;
558 /* Make sure we get a consistent snapshot */
559 spin_lock(&host->lock);
570 "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
571 cmd->opcode, cmd->arg, cmd->flags,
572 cmd->resp[0], cmd->resp[1], cmd->resp[2],
573 cmd->resp[2], cmd->error);
575 seq_printf(s, "DATA %u / %u * %u flg %x err %d\n",
576 data->bytes_xfered, data->blocks,
577 data->blksz, data->flags, data->error);
580 "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
581 stop->opcode, stop->arg, stop->flags,
582 stop->resp[0], stop->resp[1], stop->resp[2],
583 stop->resp[2], stop->error);
586 spin_unlock(&host->lock);
591 static int rk29_sdmmc_req_open(struct inode *inode, struct file *file)
593 return single_open(file, rk29_sdmmc_req_show, inode->i_private);
596 static const struct file_operations rk29_sdmmc_req_fops = {
597 .owner = THIS_MODULE,
598 .open = rk29_sdmmc_req_open,
601 .release = single_release,
605 static int rk29_sdmmc_regs_open(struct inode *inode, struct file *file)
607 return single_open(file, rk29_sdmmc_regs_show, inode->i_private);
610 static const struct file_operations rk29_sdmmc_regs_fops = {
611 .owner = THIS_MODULE,
612 .open = rk29_sdmmc_regs_open,
615 .release = single_release,
618 static void rk29_sdmmc_init_debugfs(struct rk29_sdmmc *host)
620 struct mmc_host *mmc = host->mmc;
624 root = mmc->debugfs_root;
628 node = debugfs_create_file("regs", S_IRUSR, root, host,
629 &rk29_sdmmc_regs_fops);
635 node = debugfs_create_file("req", S_IRUSR, root, host, &rk29_sdmmc_req_fops);
639 node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state);
643 node = debugfs_create_x32("pending_events", S_IRUSR, root,
644 (u32 *)&host->pending_events);
648 node = debugfs_create_x32("completed_events", S_IRUSR, root,
649 (u32 *)&host->completed_events);
656 dev_err(&mmc->class_dev, "failed to initialize debugfs for host\n");
660 static u32 rk29_sdmmc_prepare_command(struct mmc_command *cmd)
662 u32 cmdr = cmd->opcode;
666 case MMC_GO_IDLE_STATE:
667 cmdr |= (SDMMC_CMD_INIT | SDMMC_CMD_PRV_DAT_NO_WAIT);
670 case MMC_STOP_TRANSMISSION:
671 cmdr |= (SDMMC_CMD_STOP | SDMMC_CMD_PRV_DAT_NO_WAIT);
673 case MMC_SEND_STATUS:
674 case MMC_GO_INACTIVE_STATE:
675 cmdr |= SDMMC_CMD_PRV_DAT_NO_WAIT;
679 cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
684 switch(mmc_resp_type(cmd))
688 // case MMC_RSP_R5: //R5,R6,R7 is same with the R1
692 cmdr |= (SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_SHORT | SDMMC_CMD_RESP_EXP);
696 /* these response not contain crc7, so don't care crc error and response error */
697 cmdr |= (SDMMC_CMD_RESP_NO_CRC | SDMMC_CMD_RESP_SHORT | SDMMC_CMD_RESP_EXP);
700 cmdr |= (SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_LONG | SDMMC_CMD_RESP_EXP);
703 cmdr |= (SDMMC_CMD_RESP_CRC_NOCARE | SDMMC_CMD_RESP_NOCARE | SDMMC_CMD_RESP_NO_EXP);
706 cmdr |= (SDMMC_CMD_RESP_CRC_NOCARE | SDMMC_CMD_RESP_NOCARE | SDMMC_CMD_RESP_NO_EXP);
713 void rk29_sdmmc_set_frq(struct rk29_sdmmc *host)
715 struct mmc_host *mmchost = platform_get_drvdata(host->pdev);
716 struct mmc_card *card;
718 unsigned int max_dtr;
720 extern void mmc_set_clock(struct mmc_host *host, unsigned int hz);
725 card = (struct mmc_card *)mmchost->card;
726 ios = ( struct mmc_ios *)&mmchost->ios;
731 if(MMC_POWER_ON == ios->power_mode)
734 max_dtr = (unsigned int)-1;
736 if (mmc_card_highspeed(card))
738 if (max_dtr > card->ext_csd.hs_max_dtr)
739 max_dtr = card->ext_csd.hs_max_dtr;
742 else if (max_dtr > card->csd.max_dtr)
744 if(MMC_TYPE_SD == card->type)
746 max_dtr = (card->csd.max_dtr > SD_FPP_FREQ) ? SD_FPP_FREQ : (card->csd.max_dtr);
750 max_dtr = (card->csd.max_dtr > MMC_FPP_FREQ) ? MMC_FPP_FREQ : (card->csd.max_dtr);
754 xbwprintk(7, "%s..%d... call mmc_set_clock() set clk=%d [%s]\n", \
755 __FUNCTION__, __LINE__, max_dtr, host->dma_name);
758 mmc_set_clock(mmchost, max_dtr);
763 static int rk29_sdmmc_start_command(struct rk29_sdmmc *host, struct mmc_command *cmd, u32 cmd_flags)
765 int tmo = RK29_SDMMC_SEND_START_TIMEOUT*10;//wait 60ms cycle.
768 host->old_cmd = cmd->opcode;
770 host->pending_events = 0;
771 host->completed_events = 0;
772 host->complete_done = 0;
774 host->cmd_status = 0;
776 if(MMC_STOP_TRANSMISSION != cmd->opcode)
778 host->data_status = 0;
781 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
783 //adjust the frequency division control of SDMMC0 every time.
784 rk29_sdmmc_set_frq(host);
787 rk29_sdmmc_write(host->regs, SDMMC_CMDARG, cmd->arg); // write to SDMMC_CMDARG register
788 rk29_sdmmc_write(host->regs, SDMMC_CMD, cmd_flags | SDMMC_CMD_START); // write to SDMMC_CMD register
791 xbwprintk(1,"\n%s..%d..************.start cmd=%d, arg=0x%x ******** [%s]\n", \
792 __FUNCTION__, __LINE__, cmd->opcode, cmd->arg, host->dma_name);
794 host->mmc->doneflag = 1;
796 /* wait until CIU accepts the command */
797 while (--tmo && (rk29_sdmmc_read(host->regs, SDMMC_CMD) & SDMMC_CMD_START))
799 udelay(2);//cpu_relax();
806 printk(KERN_ERR "%s..%d.. CMD_START timeout! CMD%d(arg=0x%x, retries=%d) [%s]\n",\
807 __FUNCTION__,__LINE__, cmd->opcode, cmd->arg, cmd->retries,host->dma_name);
810 cmd->error = -ETIMEDOUT;
811 host->mrq->cmd->error = -ETIMEDOUT;
812 del_timer_sync(&host->request_timer);
814 host->errorstep = 0x1;
815 return SDM_WAIT_FOR_CMDSTART_TIMEOUT;
817 host->errorstep = 0xfe;
822 static int rk29_sdmmc_reset_fifo(struct rk29_sdmmc *host)
826 int ret = SDM_SUCCESS;
828 value = rk29_sdmmc_read(host->regs, SDMMC_STATUS);
829 if (!(value & SDMMC_STAUTS_FIFO_EMPTY))
831 value = rk29_sdmmc_read(host->regs, SDMMC_CTRL);
832 value |= SDMMC_CTRL_FIFO_RESET;
833 rk29_sdmmc_write(host->regs, SDMMC_CTRL, value);
836 while (((value = rk29_sdmmc_read(host->regs, SDMMC_CTRL)) & (SDMMC_CTRL_FIFO_RESET)) && (timeout > 0))
843 host->errorstep = 0x2;
844 ret = SDM_WAIT_FOR_FIFORESET_TIMEOUT;
852 static int rk29_sdmmc_wait_unbusy(struct rk29_sdmmc *host)
854 int time_out = 500000;//250000; //max is 250ms; //adapt the value to the sick card. modify at 2011-10-08
856 #if SDMMC_USE_INT_UNBUSY
857 if((24==host->cmd->opcode)||(25==host->cmd->opcode))
860 while (rk29_sdmmc_read(host->regs, SDMMC_STATUS) & (SDMMC_STAUTS_DATA_BUSY|SDMMC_STAUTS_MC_BUSY))
867 host->errorstep = 0x3;
868 return SDM_BUSY_TIMEOUT;
875 static void rk29_sdmmc_dma_cleanup(struct rk29_sdmmc *host)
879 dma_unmap_sg(&host->pdev->dev, host->data->sg, host->data->sg_len,
880 ((host->data->flags & MMC_DATA_WRITE)
881 ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
885 static void rk29_sdmmc_stop_dma(struct rk29_sdmmc *host)
889 if(host->use_dma == 0)
892 if (host->dma_info.chn> 0)
894 rk29_sdmmc_dma_cleanup(host);
896 ret = rk29_dma_ctrl(host->dma_info.chn,RK29_DMAOP_STOP);
899 printk(KERN_ERR "%s..%d...rk29_dma_ctrl STOP error! [%s]\n", __FUNCTION__, __LINE__, host->dma_name);
900 host->errorstep = 0x95;
904 ret = rk29_dma_ctrl(host->dma_info.chn,RK29_DMAOP_FLUSH);
907 printk(KERN_ERR "%s..%d...rk29_dma_ctrl FLUSH error! [%s]\n", __FUNCTION__, __LINE__, host->dma_name);
908 host->errorstep = 0x96;
915 /* Data transfer was stopped by the interrupt handler */
916 rk29_sdmmc_set_pending(host, EVENT_DATA_COMPLETE);
920 static void rk29_sdmmc_control_host_dma(struct rk29_sdmmc *host, bool enable)
922 u32 value = rk29_sdmmc_read(host->regs, SDMMC_CTRL);
926 value |= SDMMC_CTRL_DMA_ENABLE;
930 value &= ~(SDMMC_CTRL_DMA_ENABLE);
933 rk29_sdmmc_write(host->regs, SDMMC_CTRL, value);
936 static void send_stop_cmd(struct rk29_sdmmc *host)
940 if(host->mrq->cmd->error)
945 rk29_sdmmc_stop_dma(host);
946 rk29_sdmmc_control_host_dma(host, FALSE);
951 ret= rk29_sdmmc_clear_fifo(host);
952 if(SDM_SUCCESS != ret)
954 xbwprintk(3, "%s..%d.. clear fifo error before call CMD_STOP [%s]\n", \
955 __FUNCTION__, __LINE__, host->dma_name);
959 mod_timer(&host->request_timer, jiffies + msecs_to_jiffies(RK29_SDMMC_SEND_START_TIMEOUT+1500));
961 host->stopcmd.opcode = MMC_STOP_TRANSMISSION;
962 host->stopcmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;;
963 host->stopcmd.arg = 0;
964 host->stopcmd.data = NULL;
965 host->stopcmd.mrq = NULL;
966 host->stopcmd.retries = 0;
967 host->stopcmd.error = 0;
968 if(host->mrq && host->mrq->stop)
970 host->mrq->stop->error = 0;
973 host->cmdr = rk29_sdmmc_prepare_command(&host->stopcmd);
975 ret = rk29_sdmmc_start_command(host, &host->stopcmd, host->cmdr);
976 if(SDM_SUCCESS != ret)
978 rk29_sdmmc_start_error(host);
980 host->state = STATE_IDLE;
981 host->complete_done = 4;
986 /* This function is called by the DMA driver from tasklet context. */
987 static void rk29_sdmmc_dma_complete(void *arg, int size, enum rk29_dma_buffresult result)
989 struct rk29_sdmmc *host = arg;
991 if(host->use_dma == 0)
994 host->intInfo.transLen = host->intInfo.desLen;
997 static int rk29_sdmmc_submit_data_dma(struct rk29_sdmmc *host, struct mmc_data *data)
999 struct scatterlist *sg;
1000 unsigned int i,direction, sgDirection;
1003 if(host->use_dma == 0)
1005 printk(KERN_ERR "%s..%d...setup DMA fail!!!!!!. host->use_dma=0 [%s]\n", __FUNCTION__, __LINE__, host->dma_name);
1006 host->errorstep = 0x4;
1009 /* If we don't have a channel, we can't do DMA */
1010 if (host->dma_info.chn < 0)
1012 printk(KERN_ERR "%s..%d...setup DMA fail!!!!!!!. dma_info.chn < 0 [%s]\n", __FUNCTION__, __LINE__, host->dma_name);
1013 host->errorstep = 0x5;
1017 if (data->blksz & 3)
1019 for_each_sg(data->sg, sg, data->sg_len, i)
1021 if (sg->offset & 3 || sg->length & 3)
1023 printk(KERN_ERR "%s..%d...call for_each_sg() fail !![%s]\n", __FUNCTION__, __LINE__, host->dma_name);
1024 host->errorstep = 0x7;
1028 if (data->flags & MMC_DATA_READ)
1030 direction = RK29_DMASRC_HW;
1031 sgDirection = DMA_FROM_DEVICE;
1035 direction = RK29_DMASRC_MEM;
1036 sgDirection = DMA_TO_DEVICE;
1039 ret = rk29_dma_ctrl(host->dma_info.chn,RK29_DMAOP_STOP);
1042 printk(KERN_ERR "%s..%d...rk29_dma_ctrl stop error![%s]\n", __FUNCTION__, __LINE__, host->dma_name);
1043 host->errorstep = 0x91;
1047 ret = rk29_dma_ctrl(host->dma_info.chn,RK29_DMAOP_FLUSH);
1050 printk(KERN_ERR "%s..%d...rk29_dma_ctrl flush error![%s]\n", __FUNCTION__, __LINE__, host->dma_name);
1051 host->errorstep = 0x91;
1056 ret = rk29_dma_devconfig(host->dma_info.chn, direction, (unsigned long )(host->dma_addr));
1059 printk(KERN_ERR "%s..%d...call rk29_dma_devconfig() fail ![%s]\n", __FUNCTION__, __LINE__, host->dma_name);
1060 host->errorstep = 0x8;
1064 dma_len = dma_map_sg(&host->pdev->dev, data->sg, data->sg_len, sgDirection);
1065 for (i = 0; i < dma_len; i++)
1067 ret = rk29_dma_enqueue(host->dma_info.chn, host, sg_dma_address(&data->sg[i]),sg_dma_len(&data->sg[i]));
1070 printk(KERN_ERR "%s..%d...call rk29_dma_devconfig() fail ![%s]\n", __FUNCTION__, __LINE__, host->dma_name);
1071 host->errorstep = 0x93;
1076 rk29_sdmmc_control_host_dma(host, TRUE);// enable dma
1077 ret = rk29_dma_ctrl(host->dma_info.chn, RK29_DMAOP_START);
1080 printk(KERN_ERR "%s..%d...rk29_dma_ctrl start error![%s]\n", __FUNCTION__, __LINE__, host->dma_name);
1081 host->errorstep = 0x94;
1089 static int rk29_sdmmc_prepare_write_data(struct rk29_sdmmc *host, struct mmc_data *data)
1094 u32 count, *pBuf = (u32 *)host->pbuf;
1096 output = SDM_SUCCESS;
1097 dataLen = data->blocks*data->blksz;
1099 host->dodma = 0; //DMA still no request;
1101 //SDMMC controller request the data is multiple of 4.
1102 count = (dataLen >> 2) + ((dataLen & 0x3) ? 1:0);
1104 if (count <= FIFO_DEPTH)
1106 for (i=0; i<count; i++)
1108 rk29_sdmmc_write(host->regs, SDMMC_DATA, pBuf[i]);
1113 host->intInfo.desLen = count;
1114 host->intInfo.transLen = 0;
1115 host->intInfo.pBuf = (u32 *)pBuf;
1117 if(0)//(host->intInfo.desLen <= 512 )
1124 xbwprintk(7, "%s..%d... trace data, [%s]\n", __FUNCTION__, __LINE__, host->dma_name);
1125 output = rk29_sdmmc_submit_data_dma(host, data);
1130 printk(KERN_ERR "%s..%d... CMD%d setupDMA failure!!!!! pre_cmd=%d [%s]\n", \
1131 __FUNCTION__, __LINE__, host->cmd->opcode,host->old_cmd, host->dma_name);
1133 host->errorstep = 0x81;
1135 rk29_sdmmc_control_host_dma(host, FALSE);
1151 static int rk29_sdmmc_prepare_read_data(struct rk29_sdmmc *host, struct mmc_data *data)
1157 output = SDM_SUCCESS;
1158 dataLen = data->blocks*data->blksz;
1160 host->dodma = 0;//DMA still no request;
1162 //SDMMC controller request the data is multiple of 4.
1163 count = (dataLen >> 2) ;//+ ((dataLen & 0x3) ? 1:0);
1165 host->intInfo.desLen = (dataLen >> 2);
1166 host->intInfo.transLen = 0;
1167 host->intInfo.pBuf = (u32 *)host->pbuf;
1169 if (count > (RX_WMARK+1)) //datasheet error.actually, it can nont waken the interrupt when less and equal than RX_WMARK+1
1171 if(0) //(host->intInfo.desLen <= 512 )
1178 output = rk29_sdmmc_submit_data_dma(host, data);
1183 printk(KERN_ERR "%s..%d... CMD%d setupDMA failure!!! [%s]\n", \
1184 __FUNCTION__, __LINE__, host->cmd->opcode, host->dma_name);
1186 host->errorstep = 0x82;
1188 rk29_sdmmc_control_host_dma(host, FALSE);
1202 static int rk29_sdmmc_read_remain_data(struct rk29_sdmmc *host, u32 originalLen, void *pDataBuf)
1207 u32 *pBuf = (u32 *)pDataBuf;
1208 u8 *pByteBuf = (u8 *)pDataBuf;
1211 //SDMMC controller must be multiple of 32. so if transfer 13, then actuall we should write or read 16 byte.
1212 u32 count = (originalLen >> 2) + ((originalLen & 0x3) ? 1:0);
1214 if(1 == host->dodma)
1216 //when use DMA, there are remain data only when datalen/4 less than RX_WMARK+1 same as equaltion. or not multiple of 4
1217 if (!((value = rk29_sdmmc_read(host->regs, SDMMC_STATUS)) & SDMMC_STAUTS_FIFO_EMPTY))
1219 if (count <= (RX_WMARK+1))
1222 while ((i<(originalLen >> 2))&&(!(value & SDMMC_STAUTS_FIFO_EMPTY)))
1224 pBuf[i++] = rk29_sdmmc_read(host->regs, SDMMC_DATA);
1225 value = rk29_sdmmc_read(host->regs, SDMMC_STATUS);
1229 if (count > (originalLen >> 2))
1231 lastData = rk29_sdmmc_read(host->regs, SDMMC_DATA);
1233 //fill the 1 to 3 byte.
1234 for (i=0; i<(originalLen & 0x3); i++)
1236 pByteBuf[(originalLen & 0xFFFFFFFC) + i] = (u8)((lastData >> (i << 3)) & 0xFF); //default little-endian
1243 if (!((value = rk29_sdmmc_read(host->regs, SDMMC_STATUS)) & SDMMC_STAUTS_FIFO_EMPTY))
1245 while ( (host->intInfo.transLen < host->intInfo.desLen) && (!(value & SDMMC_STAUTS_FIFO_EMPTY)) )
1247 pBuf[host->intInfo.transLen++] = rk29_sdmmc_read(host->regs, SDMMC_DATA);
1248 value = rk29_sdmmc_read(host->regs, SDMMC_STATUS);
1251 if (count > (originalLen >> 2))
1253 lastData = rk29_sdmmc_read(host->regs, SDMMC_DATA);
1255 //fill the 1 to 3 byte.
1256 for (i=0; i<(originalLen & 0x3); i++)
1258 pByteBuf[(originalLen & 0xFFFFFFFC) + i] = (u8)((lastData >> (i << 3)) & 0xFF); //default little-endian
1268 static void rk29_sdmmc_do_pio_read(struct rk29_sdmmc *host)
1271 for (i=0; i<(RX_WMARK+1); i++)
1273 host->intInfo.pBuf[host->intInfo.transLen + i] = rk29_sdmmc_read(host->regs, SDMMC_DATA);
1275 host->intInfo.transLen += (RX_WMARK+1);
1278 static void rk29_sdmmc_do_pio_write(struct rk29_sdmmc *host)
1281 if ( (host->intInfo.desLen - host->intInfo.transLen) > (FIFO_DEPTH - TX_WMARK) )
1283 for (i=0; i<(FIFO_DEPTH - TX_WMARK); i++)
1285 rk29_sdmmc_write(host->regs, SDMMC_DATA, host->intInfo.pBuf[host->intInfo.transLen + i]);
1287 host->intInfo.transLen += (FIFO_DEPTH - TX_WMARK);
1291 for (i=0; i<(host->intInfo.desLen - host->intInfo.transLen); i++)
1293 rk29_sdmmc_write(host->regs, SDMMC_DATA, host->intInfo.pBuf[host->intInfo.transLen + i]);
1295 host->intInfo.transLen = host->intInfo.desLen;
1301 static void rk29_sdmmc_submit_data(struct rk29_sdmmc *host, struct mmc_data *data)
1309 host->cmd->data = data;
1311 data->bytes_xfered = 0;
1312 host->pbuf = (u32*)sg_virt(data->sg);
1314 if (data->flags & MMC_DATA_STREAM)
1316 host->cmdr |= SDMMC_CMD_STRM_MODE; //set stream mode
1320 host->cmdr |= SDMMC_CMD_BLOCK_MODE; //set block mode
1323 //set the blocks and blocksize
1324 rk29_sdmmc_write(host->regs, SDMMC_BYTCNT,data->blksz*data->blocks);
1325 rk29_sdmmc_write(host->regs, SDMMC_BLKSIZ,data->blksz);
1327 xbwprintk(1, "%s..%d..CMD%d(arg=0x%x), data->blksz=%d, data->blocks=%d [%s]\n", \
1328 __FUNCTION__, __LINE__, host->cmd->opcode,host->cmd->arg,data->blksz, data->blocks, host->dma_name);
1330 if (data->flags & MMC_DATA_WRITE)
1332 host->cmdr |= (SDMMC_CMD_DAT_WRITE | SDMMC_CMD_DAT_EXP);
1333 xbwprintk(7, "%s..%d... write data, len=%d [%s]\n", \
1334 __FUNCTION__, __LINE__, data->blksz*data->blocks, host->dma_name);
1336 ret = rk29_sdmmc_prepare_write_data(host, data);
1340 host->cmdr |= (SDMMC_CMD_DAT_READ | SDMMC_CMD_DAT_EXP);
1341 xbwprintk(7, "%s..%d... read data len=%d [%s]\n", \
1342 __FUNCTION__, __LINE__, data->blksz*data->blocks, host->dma_name);
1344 ret = rk29_sdmmc_prepare_read_data(host, data);
1350 rk29_sdmmc_write(host->regs, SDMMC_BLKSIZ, 0);
1351 rk29_sdmmc_write(host->regs, SDMMC_BYTCNT, 0);
1356 static int sdmmc_send_cmd_start(struct rk29_sdmmc *host, unsigned int cmd)
1358 int tmo = RK29_SDMMC_SEND_START_TIMEOUT*10;//wait 60ms cycle.
1360 rk29_sdmmc_write(host->regs, SDMMC_CMD, SDMMC_CMD_START | cmd);
1361 while (--tmo && (rk29_sdmmc_read(host->regs, SDMMC_CMD) & SDMMC_CMD_START))
1368 printk(KERN_ERR "%s.. %d set cmd(value=0x%x) register timeout error ! [%s]\n",\
1369 __FUNCTION__,__LINE__, cmd, host->dma_name);
1371 host->errorstep = 0x9;
1372 return SDM_START_CMD_FAIL;
1378 static int rk29_sdmmc_get_cd(struct mmc_host *mmc)
1380 struct rk29_sdmmc *host = mmc_priv(mmc);
1383 switch(host->pdev->id)
1388 if(host->gpio_det == INVALID_GPIO)
1392 cdetect = rk29_sdmmc_read(host->regs, SDMMC_CDETECT);
1394 cdetect = (cdetect & SDMMC_CARD_DETECT_N)?0:1;
1401 #if defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
1404 cdetect = test_bit(RK29_SDMMC_CARD_PRESENT, &host->flags)?1:0;
1419 /****************************************************************/
1420 //reset the SDMMC controller of the current host
1421 /****************************************************************/
1422 int rk29_sdmmc_reset_controller(struct rk29_sdmmc *host)
1427 rk29_sdmmc_write(host->regs, SDMMC_PWREN, POWER_ENABLE);
1429 /* reset SDMMC IP */
1430 //SDPAM_SDCClkEnable(host, TRUE);
1433 for(timeOut=0; timeOut<FIFO_DEPTH; timeOut++)
1435 if(rk29_sdmmc_read(host->regs, SDMMC_STATUS) & SDMMC_STAUTS_FIFO_EMPTY)
1438 value = rk29_sdmmc_read(host->regs, SDMMC_DATA);
1442 #if defined(CONFIG_ARCH_RK29)
1443 rk29_sdmmc_write(host->regs, SDMMC_CTRL,(SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET ));
1444 #elif defined(CONFIG_ARCH_RK30)
1445 rk29_sdmmc_write(host->regs, SDMMC_CTRL,(SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_DMA_RESET));
1448 value = rk29_sdmmc_read(host->regs, SDMMC_CTRL);
1449 while (( value & (SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_RESET)) && (timeOut > 0))
1453 value = rk29_sdmmc_read(host->regs, SDMMC_CTRL);
1458 printk(KERN_ERR "%s..%s..%d.. reset controller fail! [%s]=\n",\
1459 __FILE__, __FUNCTION__,__LINE__, host->dma_name);
1461 host->errorstep = 0x0A;
1462 return SDM_WAIT_FOR_FIFORESET_TIMEOUT;
1465 /* FIFO threshold settings */
1466 rk29_sdmmc_write(host->regs, SDMMC_FIFOTH, (SD_MSIZE_16 | (RX_WMARK << RX_WMARK_SHIFT) | (TX_WMARK << TX_WMARK_SHIFT)));
1468 rk29_sdmmc_write(host->regs, SDMMC_CTYPE, SDMMC_CTYPE_1BIT);
1469 rk29_sdmmc_write(host->regs, SDMMC_CLKSRC, CLK_DIV_SRC_0);
1470 /* config debounce */
1471 host->bus_hz = clk_get_rate(host->clk);
1472 if((host->bus_hz > 52000000) || (host->bus_hz <= 0))
1474 printk(KERN_ERR "%s..%s..%d..****Error!!!!!! Bus clock %d hz is beyond the prescribed limits. [%s]\n",\
1475 __FILE__, __FUNCTION__,__LINE__,host->bus_hz, host->dma_name);
1477 host->errorstep = 0x0B;
1478 return SDM_PARAM_ERROR;
1481 rk29_sdmmc_write(host->regs, SDMMC_DEBNCE, (DEBOUNCE_TIME*host->bus_hz)&0xFFFFFF);
1483 /* config interrupt */
1484 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS, 0xFFFFFFFF);
1488 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
1490 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEDMA);
1494 if(0== host->pdev->id)
1496 #if !defined(CONFIG_USE_SDMMC0_FOR_WIFI_DEVELOP_BOARD)
1497 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEDMA | SDMMC_INT_SDIO);
1499 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEDMA);
1502 else if(1== host->pdev->id)
1504 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
1505 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEDMA | SDMMC_INT_SDIO);
1507 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEDMA);
1512 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEDMA | SDMMC_INT_SDIO);
1518 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
1520 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEIO);
1524 if(0== host->pdev->id)
1526 #if !defined(CONFIG_USE_SDMMC0_FOR_WIFI_DEVELOP_BOARD)
1527 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEIO | SDMMC_INT_SDIO);
1529 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEIO);
1532 else if(1== host->pdev->id)
1534 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
1535 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEIO | SDMMC_INT_SDIO);
1537 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEIO);
1542 rk29_sdmmc_write(host->regs, SDMMC_INTMASK,RK29_SDMMC_INTMASK_USEDMA | SDMMC_INT_SDIO);
1547 rk29_sdmmc_write(host->regs, SDMMC_PWREN, POWER_ENABLE);
1549 rk29_sdmmc_write(host->regs, SDMMC_CTRL,SDMMC_CTRL_INT_ENABLE); // enable mci interrupt
1557 //enable/disnable the clk.
1558 static int rk29_sdmmc_control_clock(struct rk29_sdmmc *host, bool enable)
1562 int ret = SDM_SUCCESS;
1564 //wait previous start to clear
1566 while (--tmo && (rk29_sdmmc_read(host->regs, SDMMC_CMD) & SDMMC_CMD_START))
1568 udelay(1);//cpu_relax();
1572 host->errorstep = 0x0C;
1573 ret = SDM_START_CMD_FAIL;
1577 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
1579 //SDMMC use low-power mode
1580 #if SDMMC_CLOCK_TEST
1583 value = (SDMMC_CLKEN_ENABLE);
1587 value = (SDMMC_CLKEN_DISABLE);
1594 value = (SDMMC_CLKEN_LOW_PWR | SDMMC_CLKEN_ENABLE);
1598 value = (SDMMC_CLKEN_LOW_PWR | SDMMC_CLKEN_DISABLE);
1605 //SDIO-card use non-low-power mode
1608 value = (SDMMC_CLKEN_ENABLE);
1612 value = (SDMMC_CLKEN_DISABLE);
1616 rk29_sdmmc_write(host->regs, SDMMC_CLKENA, value);
1619 ret = sdmmc_send_cmd_start(host, SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT);
1620 if(ret != SDM_SUCCESS)
1628 printk(KERN_ERR "\n%s....%d.. control clock fail!!! Enable=%d, ret=0x%x [%s]\n",\
1629 __FILE__,__LINE__,enable,ret, host->dma_name);
1636 //adjust the frequency.ie, to set the frequency division control
1637 int rk29_sdmmc_change_clk_div(struct rk29_sdmmc *host, u32 freqHz)
1641 int ret = SDM_SUCCESS;
1645 ret = SDM_PARAM_ERROR;
1649 ret = rk29_sdmmc_control_clock(host, FALSE);
1650 if (ret != SDM_SUCCESS)
1656 host->bus_hz = clk_get_rate(host->clk);
1657 if((host->bus_hz > 52000000) || (host->bus_hz <= 0))
1659 printk(KERN_ERR "%s..%s..%d..****Error!!!!!! Bus clock %d hz is beyond the prescribed limits [%s]\n",\
1660 __FILE__, __FUNCTION__,__LINE__,host->bus_hz, host->dma_name);
1662 host->errorstep = 0x0D;
1663 ret = SDM_PARAM_ERROR;
1667 //calculate the divider
1668 div = host->bus_hz/freqHz + ((( host->bus_hz%freqHz ) > 0) ? 1:0 );
1669 if( (div & 0x01) && (1 != div) )
1671 //It is sure that the value of div is even.
1677 host->clock = host->bus_hz/div;
1681 host->clock = host->bus_hz;
1685 //wait previous start to clear
1687 while (--tmo && (rk29_sdmmc_read(host->regs, SDMMC_CMD) & SDMMC_CMD_START))
1689 udelay(1);//cpu_relax();
1693 host->errorstep = 0x0E;
1694 ret = SDM_START_CMD_FAIL;
1698 /* set clock to desired speed */
1699 rk29_sdmmc_write(host->regs, SDMMC_CLKDIV, div);
1702 ret = sdmmc_send_cmd_start(host, SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT);
1703 if(ret != SDM_SUCCESS)
1705 host->errorstep = 0x0E1;
1709 if(host->old_div != div)
1711 printk(KERN_INFO "%s..%d.. newDiv=%u, newCLK=%uKhz [%s]\n", \
1712 __FUNCTION__, __LINE__,div, host->clock/1000, host->dma_name);
1715 ret = rk29_sdmmc_control_clock(host, TRUE);
1716 if(ret != SDM_SUCCESS)
1720 host->old_div = div;
1726 printk(KERN_ERR "%s..%d.. change division fail, errorStep=0x%x,ret=%d [%s]\n",\
1727 __FILE__, __LINE__,host->errorstep,ret, host->dma_name);
1733 int rk29_sdmmc_hw_init(void *data)
1735 struct rk29_sdmmc *host = (struct rk29_sdmmc *)data;
1738 host->ctype = SDMMC_CTYPE_1BIT;
1739 host->set_iomux(host->pdev->id, host->ctype);
1741 /* reset controller */
1742 rk29_sdmmc_reset_controller(host);
1744 rk29_sdmmc_change_clk_div(host, FOD_FREQ);
1751 int rk29_sdmmc_set_buswidth(struct rk29_sdmmc *host)
1754 switch (host->ctype)
1756 case SDMMC_CTYPE_1BIT:
1757 case SDMMC_CTYPE_4BIT:
1759 case SDMMC_CTYPE_8BIT:
1760 return SDM_PARAM_ERROR; //Now, not support 8 bit width
1762 return SDM_PARAM_ERROR;
1765 host->set_iomux(host->pdev->id, host->ctype);
1767 /* Set the current bus width */
1768 rk29_sdmmc_write(host->regs, SDMMC_CTYPE, host->ctype);
1774 static void rk29_sdmmc_dealwith_timeout(struct rk29_sdmmc *host)
1776 if(0 == host->mmc->doneflag)
1777 return; //not to generate error flag if the command has been over.
1783 case STATE_SENDING_CMD:
1784 host->cmd_status |= SDMMC_INT_RTO;
1785 host->cmd->error = -ETIME;
1786 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,(SDMMC_INT_CMD_DONE | SDMMC_INT_RTO)); // clear interrupt
1787 rk29_sdmmc_set_pending(host, EVENT_CMD_COMPLETE);
1788 tasklet_schedule(&host->tasklet);
1790 case STATE_DATA_BUSY:
1791 host->data_status |= (SDMMC_INT_DCRC|SDMMC_INT_EBE);
1792 host->cmd->data->error = -EILSEQ;
1793 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_DTO); // clear interrupt
1794 rk29_sdmmc_set_pending(host, EVENT_DATA_COMPLETE);
1795 tasklet_schedule(&host->tasklet);
1797 #if SDMMC_USE_INT_UNBUSY
1798 case STATE_DATA_UNBUSY:
1799 host->data_status |= (SDMMC_INT_DCRC|SDMMC_INT_EBE);
1800 host->cmd->data->error = -EILSEQ;
1801 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_UNBUSY); // clear interrupt
1802 rk29_sdmmc_set_pending(host, EVENT_DATA_UNBUSY);
1803 tasklet_schedule(&host->tasklet);
1806 case STATE_SENDING_STOP:
1807 host->cmd_status |= SDMMC_INT_RTO;
1808 host->cmd->error = -ETIME;
1809 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,(SDMMC_INT_CMD_DONE | SDMMC_INT_RTO)); // clear interrupt
1810 rk29_sdmmc_set_pending(host, EVENT_CMD_COMPLETE);
1811 tasklet_schedule(&host->tasklet);
1813 case STATE_DATA_END:
1821 static void rk29_sdmmc_INT_CMD_DONE_timeout(unsigned long host_data)
1823 struct rk29_sdmmc *host = (struct rk29_sdmmc *) host_data;
1825 spin_lock(&host->lock);
1827 if(STATE_SENDING_CMD == host->state)
1829 if(0==host->cmd->retries)
1831 printk(KERN_ERR "%s..%d... cmd=%d, INT_CMD_DONE timeout, errorStep=0x%x, host->state=%x [%s]\n",\
1832 __FUNCTION__, __LINE__,host->cmd->opcode, host->errorstep,host->state,host->dma_name);
1835 rk29_sdmmc_dealwith_timeout(host);
1837 spin_unlock(&host->lock);
1842 static void rk29_sdmmc_INT_DTO_timeout(unsigned long host_data)
1844 struct rk29_sdmmc *host = (struct rk29_sdmmc *) host_data;
1846 spin_lock(&host->lock);
1848 #if SDMMC_USE_INT_UNBUSY
1849 if( (host->cmdr & SDMMC_CMD_DAT_EXP) &&((STATE_DATA_BUSY == host->state)||(STATE_DATA_UNBUSY == host->state) ))
1851 if( (host->cmdr & SDMMC_CMD_DAT_EXP) && (STATE_DATA_BUSY == host->state))
1854 if(0==host->cmd->retries)
1856 printk(KERN_ERR "%s..%d...cmd=%d DTO_timeout,cmdr=0x%x, errorStep=0x%x, Hoststate=%x [%s]\n", \
1857 __FUNCTION__, __LINE__,host->cmd->opcode,host->cmdr ,host->errorstep,host->state,host->dma_name);
1860 rk29_sdmmc_dealwith_timeout(host);
1862 spin_unlock(&host->lock);
1868 //to excute a request
1869 static int rk29_sdmmc_start_request(struct mmc_host *mmc )
1871 struct rk29_sdmmc *host = mmc_priv(mmc);
1872 struct mmc_request *mrq;
1873 struct mmc_command *cmd;
1876 unsigned long iflags;
1878 spin_lock_irqsave(&host->lock, iflags);
1880 mrq = host->new_mrq;
1884 cmdr = rk29_sdmmc_prepare_command(cmd);
1888 /*clean FIFO if it is a new request*/
1889 if((RK29_CTRL_SDMMC_ID == host->pdev->id) && ( !(cmdr & SDMMC_CMD_STOP)))
1891 ret = rk29_sdmmc_reset_fifo(host);
1892 if(SDM_SUCCESS != ret)
1894 host->mrq = host->new_mrq;///
1895 cmd->error = -ENOMEDIUM;
1896 host->errorstep = 0x0F;
1898 goto start_request_Err;
1902 //check data-busy if the current command has the bit13 in command register.
1903 if( cmdr & SDMMC_CMD_PRV_DAT_WAIT )
1905 if(rk29_sdmmc_read(host->regs, SDMMC_STATUS) & SDMMC_STAUTS_DATA_BUSY)
1907 host->mrq = host->new_mrq;///
1908 cmd->error = -ETIMEDOUT;
1909 ret = SDM_BUSY_TIMEOUT;
1910 host->errorstep = 0x10;
1911 if(0 == cmd->retries)
1913 printk(KERN_ERR "%s..Error happen in CMD_PRV_DAT_WAIT. STATUS-reg=0x%x [%s]\n", \
1914 __FUNCTION__, rk29_sdmmc_read(host->regs, SDMMC_STATUS),host->dma_name);
1916 rk29_sdmmc_clear_fifo(host);
1917 goto start_request_Err;
1921 host->state = STATE_SENDING_CMD;
1922 host->mrq = host->new_mrq;
1930 host->data_status = 0;
1933 host->errorstep = 0;
1938 //setting for the data
1939 rk29_sdmmc_submit_data(host, mrq->data);
1940 host->errorstep = 0xff;
1942 xbwprintk(7, "%s..%d... CMD%d begin to call rk29_sdmmc_start_command(). [%s]\n", \
1943 __FUNCTION__, __LINE__ , cmd->opcode,host->dma_name);
1945 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
1947 mod_timer(&host->request_timer, jiffies + msecs_to_jiffies(RK29_SDMMC_SEND_START_TIMEOUT+700));
1951 mod_timer(&host->request_timer, jiffies + msecs_to_jiffies(RK29_SDMMC_SEND_START_TIMEOUT+500));
1955 ret = rk29_sdmmc_start_command(host, cmd, host->cmdr);
1956 if(SDM_SUCCESS != ret)
1958 cmd->error = -ETIMEDOUT;
1961 printk(KERN_ERR "%s..%d... start_command(CMD%d, arg=%x, retries=%d) fail! ret=%d . [%s]\n",\
1962 __FUNCTION__, __LINE__ , cmd->opcode,cmd->arg, cmd->retries,ret, host->dma_name);
1964 host->errorstep = 0x11;
1965 del_timer_sync(&host->request_timer);
1967 goto start_request_Err;
1969 host->errorstep = 0xfd;
1971 xbwprintk(7, "%s..%d... CMD=%d, wait for INT_CMD_DONE, ret=%d , \n \
1972 host->state=0x%x, cmdINT=0x%x \n host->pendingEvent=0x%lu, host->completeEvents=0x%lu [%s]\n\n",\
1973 __FUNCTION__, __LINE__, host->cmd->opcode,ret, \
1974 host->state,host->cmd_status, host->pending_events,host->completed_events,host->dma_name);
1976 spin_unlock_irqrestore(&host->lock, iflags);
1981 rk29_sdmmc_start_error(host);
1983 if(0 == cmd->retries)
1985 printk(KERN_ERR "%s: CMD%d(arg=%x) fail to start request. err=%d, Errorstep=0x%x [%s]\n",\
1986 __FUNCTION__, cmd->opcode, cmd->arg,ret,host->errorstep,host->dma_name);
1989 host->state = STATE_IDLE; //modifyed by xbw at 2011-08-15
1991 if(host->mrq && host->mmc->doneflag)
1993 host->mmc->doneflag = 0;
1994 spin_unlock_irqrestore(&host->lock, iflags);
1996 mmc_request_done(host->mmc, host->mrq);
2000 spin_unlock_irqrestore(&host->lock, iflags);
2008 static void rk29_sdmmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
2010 unsigned long iflags;
2011 struct rk29_sdmmc *host = mmc_priv(mmc);
2013 spin_lock_irqsave(&host->lock, iflags);
2016 //set 1 to close the controller for Debug.
2017 if(RK29_CTRL_SDIO1_ID==host->pdev->id)//if(RK29_CTRL_SDMMC_ID==host->pdev->id)//
2019 mrq->cmd->error = -ENOMEDIUM;
2020 printk(KERN_ERR "%s..%d.. ==== The %s had been closed by myself for the experiment. [%s]\n",\
2021 __FUNCTION__, __LINE__, host->dma_name, host->dma_name);
2023 host->state = STATE_IDLE;
2024 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS, 0xFFFFFFFF);
2025 spin_unlock_irqrestore(&host->lock, iflags);
2026 mmc_request_done(mmc, mrq);
2031 xbwprintk(6, "\n%s..%d..New cmd=%2d(arg=0x%8x)=== cardPresent=0x%lu, state=0x%x [%s]\n", \
2032 __FUNCTION__, __LINE__,mrq->cmd->opcode, mrq->cmd->arg,host->flags,host->state, host->dma_name);
2034 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
2036 if(!rk29_sdmmc_get_cd(mmc) || ((0==mmc->re_initialized_flags)&&(MMC_GO_IDLE_STATE != mrq->cmd->opcode)))
2038 mrq->cmd->error = -ENOMEDIUM;
2040 if((RK29_CTRL_SDMMC_ID == host->pdev->id)&&(0==mrq->cmd->retries))
2042 if(host->old_cmd != mrq->cmd->opcode)
2044 if( ((17==host->old_cmd)&&(18==mrq->cmd->opcode)) || ((18==host->old_cmd)&&(17==mrq->cmd->opcode)) ||\
2045 ((24==host->old_cmd)&&(25==mrq->cmd->opcode)) || ((25==host->old_cmd)&&(24==mrq->cmd->opcode)))
2047 host->old_cmd = mrq->cmd->opcode;
2048 if(host->error_times++ %RK29_ERROR_PRINTK_INTERVAL ==0)
2050 printk(KERN_INFO "%s: Refuse to run CMD%2d(arg=0x%8x) due to the removal of card. 1==[%s]==\n", \
2051 __FUNCTION__, mrq->cmd->opcode, mrq->cmd->arg, host->dma_name);
2056 host->old_cmd = mrq->cmd->opcode;
2057 host->error_times = 0;
2058 printk(KERN_INFO "%s: Refuse to run CMD%2d(arg=0x%8x) due to the removal of card. 2==[%s]==\n", \
2059 __FUNCTION__, mrq->cmd->opcode, mrq->cmd->arg, host->dma_name);
2064 if(host->error_times++ % (RK29_ERROR_PRINTK_INTERVAL*3) ==0)
2066 printk(KERN_INFO "%s: Refuse to run CMD%2d(arg=0x%8x) due to the removal of card. 3==[%s]==\n", \
2067 __FUNCTION__, mrq->cmd->opcode, mrq->cmd->arg, host->dma_name);
2069 host->old_cmd = mrq->cmd->opcode;
2072 host->state = STATE_IDLE;
2073 spin_unlock_irqrestore(&host->lock, iflags);
2075 mmc_request_done(mmc, mrq);
2080 if(host->old_cmd != mrq->cmd->opcode)
2082 host->old_cmd = mrq->cmd->opcode;
2083 host->error_times = 0;
2089 host->old_cmd = mrq->cmd->opcode;
2090 host->error_times = 0;
2092 if(!test_bit(RK29_SDMMC_CARD_PRESENT, &host->flags))
2094 host->state = STATE_IDLE;
2095 mrq->cmd->error = -ENOMEDIUM;
2096 spin_unlock_irqrestore(&host->lock, iflags);
2098 mmc_request_done(mmc, mrq);
2105 host->new_mrq = mrq;
2107 spin_unlock_irqrestore(&host->lock, iflags);
2109 rk29_sdmmc_start_request(mmc);
2112 if (host->state == STATE_IDLE)
2114 spin_unlock_irqrestore(&host->lock, iflags);
2116 host->new_mrq = mrq;
2117 rk29_sdmmc_start_request(mmc);
2121 #ifdef RK29_SDMMC_LIST_QUEUE
2123 printk(KERN_INFO "%s..%d...Danger! Danger! New request was added to queue. [%s]\n", \
2124 __FUNCTION__, __LINE__,host->dma_name);
2125 list_add_tail(&host->queue_node, &host->queue);
2129 printk(KERN_ERR "%s..%d..state Error! ,old_state=%d, OldCMD=%d ,NewCMD%2d,arg=0x%x [%s]\n", \
2130 __FUNCTION__, __LINE__, host->state, host->cmd->opcode,mrq->cmd->opcode,mrq->cmd->arg, host->dma_name);
2132 mrq->cmd->error = -ENOMEDIUM;
2134 spin_unlock_irqrestore(&host->lock, iflags);
2135 mmc_request_done(mmc, mrq);
2147 static void rk29_sdmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
2151 struct rk29_sdmmc *host = mmc_priv(mmc);
2153 spin_lock(&host->lock);
2155 if(test_bit(RK29_SDMMC_CARD_PRESENT, &host->flags) || (RK29_CTRL_SDMMC_ID == host->pdev->id))
2158 * Waiting SDIO controller to be IDLE.
2160 while (timeout-- > 0)
2162 value = rk29_sdmmc_read(host->regs, SDMMC_STATUS);
2163 if ((value & SDMMC_STAUTS_DATA_BUSY) == 0 &&(value & SDMMC_CMD_FSM_MASK) == SDMMC_CMD_FSM_IDLE)
2172 printk(KERN_ERR "%s..%d...Waiting for SDMMC%d controller to be IDLE timeout.[%s]\n", \
2173 __FUNCTION__, __LINE__, host->pdev->id, host->dma_name);
2179 //if(host->bus_mode != ios->power_mode)
2181 switch (ios->power_mode)
2184 rk29_sdmmc_write(host->regs, SDMMC_PWREN, POWER_ENABLE);
2186 //reset the controller if it is SDMMC0
2187 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
2189 xbwprintk(7, "%s..%d..POWER_UP, call reset_controller, initialized_flags=%d [%s]\n",\
2190 __FUNCTION__, __LINE__, host->mmc->re_initialized_flags,host->dma_name);
2194 rk29_sdmmc_hw_init(host);
2200 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
2202 rk29_sdmmc_control_clock(host, FALSE);
2203 rk29_sdmmc_write(host->regs, SDMMC_PWREN, POWER_DISABLE);
2205 if(5 == host->bus_mode)
2208 xbwprintk(7, "%s..%d..Fisrt powerOFF, call reset_controller [%s]\n", \
2209 __FUNCTION__, __LINE__,host->dma_name);
2211 rk29_sdmmc_reset_controller(host);
2221 host->bus_mode = ios->power_mode;
2225 if(!(test_bit(RK29_SDMMC_CARD_PRESENT, &host->flags) || (RK29_CTRL_SDIO1_ID != host->pdev->id)))
2226 goto out; //exit the set_ios directly if the SDIO is not present.
2228 if(host->ctype != ios->bus_width)
2230 switch (ios->bus_width)
2232 case MMC_BUS_WIDTH_1:
2233 host->ctype = SDMMC_CTYPE_1BIT;
2235 case MMC_BUS_WIDTH_4:
2236 host->ctype = SDMMC_CTYPE_4BIT;
2238 case MMC_BUS_WIDTH_8:
2239 host->ctype = SDMMC_CTYPE_8BIT;
2246 rk29_sdmmc_set_buswidth(host);
2250 if (ios->clock && (ios->clock != host->clock))
2253 * Use mirror of ios->clock to prevent race with mmc
2254 * core ios update when finding the minimum.
2256 //host->clock = ios->clock;
2257 rk29_sdmmc_change_clk_div(host, ios->clock);
2261 spin_unlock(&host->lock);
2265 static int rk29_sdmmc_get_ro(struct mmc_host *mmc)
2267 struct rk29_sdmmc *host = mmc_priv(mmc);
2270 switch(host->pdev->id)
2274 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT) || defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
2275 if(INVALID_GPIO == host->write_protect)
2276 ret = 0;//no write-protect
2278 ret = gpio_get_value(host->write_protect)?1:0;
2280 xbwprintk(7,"%s..%d.. write_prt_pin=%d, get_ro=%d. [%s]\n",\
2281 __FUNCTION__, __LINE__,host->write_protect, ret, host->dma_name);
2284 u32 wrtprt = rk29_sdmmc_read(host->regs, SDMMC_WRTPRT);
2286 ret = (wrtprt & SDMMC_WRITE_PROTECT)?1:0;
2293 ret = 0;//no write-protect
2306 static void rk29_sdmmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
2309 unsigned long flags;
2310 struct rk29_sdmmc *host = mmc_priv(mmc);
2312 spin_lock_irqsave(&host->lock, flags);
2314 intmask = rk29_sdmmc_read(host->regs, SDMMC_INTMASK);
2317 rk29_sdmmc_write(host->regs, SDMMC_INTMASK, intmask | SDMMC_INT_SDIO);
2319 rk29_sdmmc_write(host->regs, SDMMC_INTMASK, intmask & ~SDMMC_INT_SDIO);
2320 spin_unlock_irqrestore(&host->lock, flags);
2324 static void rk29_sdmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
2326 card->quirks = MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
2330 static int rk29_sdmmc_clear_fifo(struct rk29_sdmmc *host)
2332 unsigned int timeout, value;
2333 int ret = SDM_SUCCESS;
2335 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
2337 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS, 0xFFFFFFFF);
2340 rk29_sdmmc_stop_dma(host);
2341 rk29_sdmmc_control_host_dma(host, FALSE);
2345 for(timeout=0; timeout<FIFO_DEPTH; timeout++)
2347 if(rk29_sdmmc_read(host->regs, SDMMC_STATUS) & SDMMC_STAUTS_FIFO_EMPTY)
2350 value = rk29_sdmmc_read(host->regs, SDMMC_DATA);
2355 value = rk29_sdmmc_read(host->regs, SDMMC_CTRL);
2356 value |= (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_DMA_RESET);
2357 rk29_sdmmc_write(host->regs, SDMMC_CTRL, value);
2359 value = rk29_sdmmc_read(host->regs, SDMMC_CTRL);
2361 while( (value & (SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_RESET | SDMMC_CTRL_DMA_RESET)) && (timeout > 0))
2365 value = rk29_sdmmc_read(host->regs, SDMMC_CTRL);
2370 host->errorstep = 0x0A;
2371 ret = SDM_WAIT_FOR_FIFORESET_TIMEOUT;
2379 static const struct mmc_host_ops rk29_sdmmc_ops[] = {
2381 .request = rk29_sdmmc_request,
2382 .set_ios = rk29_sdmmc_set_ios,
2383 .get_ro = rk29_sdmmc_get_ro,
2384 .get_cd = rk29_sdmmc_get_cd,
2387 .request = rk29_sdmmc_request,
2388 .set_ios = rk29_sdmmc_set_ios,
2389 .get_ro = rk29_sdmmc_get_ro,
2390 .get_cd = rk29_sdmmc_get_cd,
2391 .enable_sdio_irq = rk29_sdmmc_enable_sdio_irq,
2392 .init_card = rk29_sdmmc_init_card,
2396 static void rk29_sdmmc_request_end(struct rk29_sdmmc *host, struct mmc_command *cmd)
2398 u32 status = host->data_status;
2399 int output=SDM_SUCCESS;
2401 xbwprintk(7, "%s..%d... cmd=%d, host->state=0x%x,\n pendingEvent=0x%lu, completeEvents=0x%lu [%s]\n",\
2402 __FUNCTION__, __LINE__,cmd->opcode,host->state, host->pending_events,host->completed_events,host->dma_name);
2404 del_timer_sync(&host->DTO_timer);
2406 if(RK29_CTRL_SDMMC_ID == host->pdev->id)
2408 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS, 0xFFFFFFFF); //added by xbw at 2011-08-15
2414 rk29_sdmmc_stop_dma(host);
2415 rk29_sdmmc_control_host_dma(host, FALSE);
2421 goto exit;//It need not to wait-for-busy if the CMD-ERROR happen.
2423 host->errorstep = 0xf7;
2426 if(host->cmdr & SDMMC_CMD_DAT_WRITE)
2428 if(status & (SDMMC_INT_DCRC | SDMMC_INT_EBE))
2430 cmd->data->error = -EILSEQ;
2431 output = SDM_DATA_CRC_ERROR;
2432 host->errorstep = 0x16;
2436 output = rk29_sdmmc_wait_unbusy(host);
2437 if(SDM_SUCCESS != output)
2439 host->errorstep = 0x17;
2440 cmd->data->error = -ETIMEDOUT;
2443 host->data->bytes_xfered = host->data->blocks * host->data->blksz;
2448 if( status & SDMMC_INT_SBE)
2450 cmd->data->error = -EIO;
2451 host->errorstep = 0x18;
2452 output = SDM_START_BIT_ERROR;
2454 else if((status & SDMMC_INT_EBE) && (cmd->opcode != 14)) //MMC4.0, BUSTEST_R, A host read the reserved bus testing data parttern from a card.
2456 cmd->data->error = -EILSEQ;
2457 host->errorstep = 0x19;
2458 output = SDM_END_BIT_ERROR;
2460 else if(status & SDMMC_INT_DRTO)
2462 cmd->data->error = -ETIMEDOUT;
2463 host->errorstep = 0x1A;
2464 output = SDM_DATA_READ_TIMEOUT;
2466 else if(status & SDMMC_INT_DCRC)
2468 host->errorstep = 0x1B;
2469 cmd->data->error = -EILSEQ;
2470 output = SDM_DATA_CRC_ERROR;
2474 output = rk29_sdmmc_read_remain_data(host, (host->data->blocks * host->data->blksz), host->pbuf);
2475 if(SDM_SUCCESS == output)
2477 host->data->bytes_xfered = host->data->blocks * host->data->blksz;
2483 if(SDM_SUCCESS == output)
2485 if ((mmc_resp_type(cmd) == MMC_RSP_R1B) || (MMC_STOP_TRANSMISSION == cmd->opcode))
2487 output = rk29_sdmmc_wait_unbusy(host);
2488 if((SDM_SUCCESS != output) && (!host->mrq->cmd->error))
2490 printk(KERN_ERR "%s..%d... CMD12 wait busy timeout!!!!! errorStep=0x%x [%s]\n", \
2491 __FUNCTION__, __LINE__, host->errorstep, host->dma_name);
2492 rk29_sdmmc_clear_fifo(host);
2493 cmd->error = -ETIMEDOUT;
2494 host->mrq->cmd->error = -ETIMEDOUT;
2495 host->errorstep = 0x1C;
2499 host->errorstep = 0xf6;
2502 if(cmd->data && cmd->data->error)
2504 if( (!cmd->error) && (0==cmd->retries))
2506 printk(KERN_ERR "%s..%d......CMD=%d error!!!(arg=0x%x,cmdretry=%d,blksize=%d, blocks=%d), \n \
2507 statusReg=0x%x, ctrlReg=0x%x, nerrorTimes=%d, errorStep=0x%x. [%s]\n",\
2508 __FUNCTION__, __LINE__, cmd->opcode, cmd->arg, cmd->retries,cmd->data->blksz, cmd->data->blocks,
2509 rk29_sdmmc_read(host->regs, SDMMC_STATUS),
2510 rk29_sdmmc_read(host->regs, SDMMC_CTRL),
2511 host->error_times,host->errorstep, host->dma_name);
2513 cmd->error = -ENODATA;
2515 host->errorstep = 0xf5;
2519 #ifdef RK29_SDMMC_LIST_QUEUE
2520 if (!list_empty(&host->queue))
2522 printk(KERN_ERR "%s..%d.. Danger!Danger!. continue the next request in the queue. [%s]\n",\
2523 __FUNCTION__, __LINE__, host->dma_name);
2525 host = list_entry(host->queue.next,
2526 struct rk29_sdmmc, queue_node);
2527 list_del(&host->queue_node);
2528 host->state = STATE_SENDING_CMD;
2529 rk29_sdmmc_start_request(host->mmc);
2533 dev_vdbg(&host->pdev->dev, "list empty\n");
2534 host->state = STATE_IDLE;
2537 dev_vdbg(&host->pdev->dev, "list empty\n");
2538 host->state = STATE_IDLE;
2543 static int rk29_sdmmc_command_complete(struct rk29_sdmmc *host,
2544 struct mmc_command *cmd)
2546 u32 value, status = host->cmd_status;
2547 int timeout, output= SDM_SUCCESS;
2549 xbwprintk(7, "%s..%d. cmd=%d, host->state=0x%x, cmdINT=0x%x\n,pendingEvent=0x%lu,completeEvents=0x%lu. [%s]\n",\
2550 __FUNCTION__, __LINE__,cmd->opcode,host->state,status, host->pending_events,host->completed_events,host->dma_name);
2553 del_timer_sync(&host->request_timer);
2555 host->cmd_status = 0;
2557 if((RK29_CTRL_SDMMC_ID == host->pdev->id) && (host->cmdr & SDMMC_CMD_STOP))
2559 output = rk29_sdmmc_reset_fifo(host);
2560 if (SDM_SUCCESS != output)
2562 printk(KERN_ERR "%s..%d......reset fifo fail! CMD%d(arg=0x%x, Retries=%d) [%s]\n",__FUNCTION__, __LINE__, \
2563 cmd->opcode, cmd->arg, cmd->retries,host->dma_name);
2565 cmd->error = -ETIMEDOUT;
2566 host->mrq->cmd->error = cmd->error;
2568 host->errorstep = 0x1C;
2573 if(status & SDMMC_INT_RTO)
2575 cmd->error = -ENOMEM;
2576 host->mrq->cmd->error = cmd->error;
2577 output = SDM_BUSY_TIMEOUT;
2579 //rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_RTO);
2580 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,0xFFFFFFFF); //modifyed by xbw at 2011-08-15
2582 if(host->use_dma)//if(host->dodma)
2586 rk29_sdmmc_stop_dma(host);
2587 rk29_sdmmc_control_host_dma(host, FALSE);
2591 value = rk29_sdmmc_read(host->regs, SDMMC_CTRL);
2592 value |= SDMMC_CTRL_FIFO_RESET;
2593 rk29_sdmmc_write(host->regs, SDMMC_CTRL, value);
2596 while (((value = rk29_sdmmc_read(host->regs, SDMMC_CTRL)) & (SDMMC_CTRL_FIFO_RESET)) && (timeout > 0))
2604 host->errorstep = 0x1D;
2605 printk(KERN_ERR "%s..%d......reset CTRL fail! CMD%d(arg=0x%x, Retries=%d).[%s]\n",\
2606 __FUNCTION__, __LINE__, cmd->opcode, cmd->arg, cmd->retries,host->dma_name);
2614 if(cmd->flags & MMC_RSP_PRESENT)
2616 if(cmd->flags & MMC_RSP_136)
2618 cmd->resp[3] = rk29_sdmmc_read(host->regs, SDMMC_RESP0);
2619 cmd->resp[2] = rk29_sdmmc_read(host->regs, SDMMC_RESP1);
2620 cmd->resp[1] = rk29_sdmmc_read(host->regs, SDMMC_RESP2);
2621 cmd->resp[0] = rk29_sdmmc_read(host->regs, SDMMC_RESP3);
2625 cmd->resp[0] = rk29_sdmmc_read(host->regs, SDMMC_RESP0);
2631 del_timer_sync(&host->DTO_timer);
2634 if((0==cmd->retries) && (host->error_times++%RK29_ERROR_PRINTK_INTERVAL == 0) && (12 != cmd->opcode))
2636 if( ((RK29_CTRL_SDMMC_ID==host->pdev->id)&&(MMC_SLEEP_AWAKE!=cmd->opcode)) ||
2637 ((RK29_CTRL_SDMMC_ID!=host->pdev->id)&&(MMC_SEND_EXT_CSD!=cmd->opcode)) )
2639 printk(KERN_ERR "%s..%d...CMD%d(arg=0x%x), hoststate=%d, errorTimes=%d, errorStep=0x%x ! [%s]\n",\
2640 __FUNCTION__, __LINE__, cmd->opcode, cmd->arg, host->state,host->error_times,host->errorstep, host->dma_name);
2645 del_timer_sync(&host->request_timer);
2651 del_timer_sync(&host->request_timer);
2652 del_timer_sync(&host->DTO_timer);
2654 if((0==cmd->retries) && (host->error_times++%RK29_ERROR_PRINTK_INTERVAL == 0))
2656 printk(KERN_ERR "%s..%d....command_complete(CMD=%d, arg=%x) error=%d. [%s]\n",\
2657 __FUNCTION__, __LINE__, host->cmd->opcode,host->cmd->arg, output, host->dma_name);
2665 static void rk29_sdmmc_start_error(struct rk29_sdmmc *host)
2667 host->cmd->error = -EIO;
2668 host->mrq->cmd->error = -EIO;
2669 host->cmd_status |= SDMMC_INT_RTO;
2671 del_timer_sync(&host->request_timer);
2673 rk29_sdmmc_command_complete(host, host->mrq->cmd);
2674 rk29_sdmmc_request_end(host, host->mrq->cmd);
2677 static void rk29_sdmmc_tasklet_func(unsigned long priv)
2679 struct rk29_sdmmc *host = (struct rk29_sdmmc *)priv;
2680 struct mmc_data *data = host->cmd->data;
2681 enum rk29_sdmmc_state state = host->state;
2682 int pending_flag, stopflag;
2683 unsigned long iflags;
2685 spin_lock_irqsave(&host->lock, iflags);
2687 state = host->state;
2697 xbwprintk(7, "%s..%d.. prev_state= STATE_IDLE [%s]\n", \
2698 __FUNCTION__, __LINE__, host->dma_name);
2702 case STATE_SENDING_CMD:
2704 xbwprintk(7, "%s..%d.. prev_state= STATE_SENDING_CMD, pendingEvernt=0x%lu [%s]\n",\
2705 __FUNCTION__, __LINE__,host->completed_events, host->dma_name);
2707 if (!rk29_sdmmc_test_and_clear_pending(host, EVENT_CMD_COMPLETE))
2709 host->errorstep = 0xfb;
2711 del_timer_sync(&host->request_timer); //delete the timer for INT_COME_DONE
2713 rk29_sdmmc_set_completed(host, EVENT_CMD_COMPLETE);
2714 rk29_sdmmc_command_complete(host, host->cmd);
2719 rk29_sdmmc_request_end(host, host->cmd);
2721 xbwprintk(7, "%s..%d.. CMD%d call mmc_request_done() . [%s]\n", \
2722 __FUNCTION__, __LINE__,host->cmd->opcode,host->dma_name);
2724 host->complete_done = 1;
2727 host->errorstep = 0xfa;
2728 if(host->cmd->error)
2730 del_timer_sync(&host->DTO_timer); //delete the timer for INT_DTO
2734 xbwprintk(7, "%s..%d.. cmderr, so call send_stop_cmd() [%s]\n", \
2735 __FUNCTION__, __LINE__, host->dma_name);
2738 state = STATE_SENDING_CMD;//STATE_SENDING_STOP;
2739 send_stop_cmd(host);
2741 stopflag = 1; //Moidfyed by xbw at 2011-09-08
2746 rk29_sdmmc_set_pending(host, EVENT_DATA_COMPLETE);
2749 host->errorstep = 0xf9;
2750 state = STATE_DATA_BUSY;
2754 case STATE_DATA_BUSY:
2756 xbwprintk(7, "%s..%d.. prev_state= STATE_DATA_BUSY, pendingEvernt=0x%lu [%s]\n", \
2757 __FUNCTION__, __LINE__,host->pending_events, host->dma_name);
2759 if (!rk29_sdmmc_test_and_clear_pending(host, EVENT_DATA_COMPLETE))
2761 host->errorstep = 0xf8;
2762 rk29_sdmmc_set_completed(host, EVENT_DATA_COMPLETE);
2764 #if SDMMC_USE_INT_UNBUSY
2765 if((24==host->cmd->opcode)||(25==host->cmd->opcode))
2768 ** use DTO_timer for waiting for INT_UNBUSY.
2769 ** max 250ms in specification, but adapt 500 for the compatibility of all kinds of sick sdcard.
2771 mod_timer(&host->DTO_timer, jiffies + msecs_to_jiffies(500));
2775 del_timer_sync(&host->DTO_timer); //delete the timer for INT_DTO
2778 state = STATE_DATA_UNBUSY;
2781 del_timer_sync(&host->DTO_timer); //delete the timer for INT_DTO
2785 case STATE_DATA_UNBUSY:
2787 #if SDMMC_USE_INT_UNBUSY
2788 if((24==host->cmd->opcode)||(25==host->cmd->opcode))
2790 if (!rk29_sdmmc_test_and_clear_pending(host, EVENT_DATA_UNBUSY))
2793 del_timer_sync(&host->DTO_timer);
2795 rk29_sdmmc_set_completed(host, EVENT_DATA_UNBUSY);
2796 state = STATE_DATA_END;
2798 rk29_sdmmc_request_end(host, host->cmd);
2800 if (data && !data->stop)
2802 xbwprintk(7, "%s..%d.. CMD%d call mmc_request_done(). [%s]\n", \
2803 __FUNCTION__, __LINE__,host->cmd->opcode,host->dma_name);
2805 if(!( (MMC_READ_SINGLE_BLOCK == host->cmd->opcode)&&( -EIO == data->error))) //deal with START_BIT_ERROR
2807 host->complete_done = 2;
2812 host->errorstep = 0xf4;
2813 xbwprintk(7, "%s..%d.. after DATA_COMPLETE, so call send_stop_cmd() [%s]\n", \
2814 __FUNCTION__, __LINE__, host->dma_name);
2817 state = STATE_SENDING_CMD;
2818 send_stop_cmd(host);
2820 stopflag = 2; //Moidfyed by xbw at 2011-09-08
2826 case STATE_SENDING_STOP:
2828 xbwprintk(7, "%s..%d.. prev_state= STATE_SENDING_STOP, pendingEvernt=0x%lu [%s]\n", \
2829 __FUNCTION__, __LINE__, host->pending_events, host->dma_name);
2831 if (!rk29_sdmmc_test_and_clear_pending(host, EVENT_CMD_COMPLETE))
2834 rk29_sdmmc_command_complete(host, host->cmd);
2835 del_timer_sync(&host->request_timer); //delete the timer for INT_CMD_DONE int CMD12
2836 rk29_sdmmc_request_end(host, host->cmd);
2838 host->complete_done = 3;
2842 case STATE_DATA_END:
2848 pending_flag = (host->complete_done > 0) && (host->retryfunc<50) \
2849 && (rk29_sdmmc_test_pending(host, EVENT_CMD_COMPLETE)|| rk29_sdmmc_test_pending(host, EVENT_DATA_COMPLETE) );
2853 xbwprintk(7, "%s..%d... cmd=%d(arg=0x%x),completedone=%d, retrycount=%d, doneflag=%d, \n \
2854 host->state=0x%x, switchstate=%x, \n \
2855 pendingEvent=0x%lu, completeEvents=0x%lu, \n \
2856 mrqCMD=%d, arg=0x%x [%s]\n",\
2858 __FUNCTION__, __LINE__,host->cmd->opcode, host->cmd->arg, host->complete_done,\
2859 host->retryfunc, host->mmc->doneflag,host->state, state, \
2860 host->pending_events,host->completed_events,\
2861 host->mrq->cmd->opcode, host->mrq->cmd->arg, host->dma_name);
2866 } while(pending_flag && ++host->retryfunc); //while(0);
2870 if(host->cmd->error)
2871 xbwprintk(3,"%d: call send_stop_cmd== %d, completedone=%d, doneflag=%d, hoststate=%x, statusReg=0x%x \n", \
2872 __LINE__,stopflag, host->complete_done, host->mmc->doneflag, state, rk29_sdmmc_read(host->regs, SDMMC_STATUS));
2874 state = STATE_SENDING_CMD;
2875 send_stop_cmd(host); //Moidfyed by xbw at 2011-09-08
2878 host->state = state;
2880 if(0==host->complete_done)
2882 host->errorstep = 0xf2;
2884 spin_unlock_irqrestore(&host->lock, iflags);
2887 host->errorstep = 0xf3;
2888 host->state = STATE_IDLE;
2890 if(host->mrq && host->mmc->doneflag)
2892 host->mmc->doneflag = 0;
2893 spin_unlock_irqrestore(&host->lock, iflags);
2894 mmc_request_done(host->mmc, host->mrq);
2898 spin_unlock_irqrestore(&host->lock, iflags);
2903 static inline void rk29_sdmmc_cmd_interrupt(struct rk29_sdmmc *host, u32 status)
2907 host->cmd_status |= status;
2908 host->errorstep = 0xfc;
2909 if((MMC_STOP_TRANSMISSION != host->cmd->opcode) && (host->cmdr & SDMMC_CMD_DAT_EXP))
2912 multi = rk29_sdmmc_read(host->regs, SDMMC_BYTCNT)/unit;
2913 multi += ((rk29_sdmmc_read(host->regs, SDMMC_BYTCNT)%unit) ? 1 :0 );
2914 multi = (multi>0) ? multi : 1;
2915 multi += (host->cmd->retries>2)?2:host->cmd->retries;
2916 mod_timer(&host->DTO_timer, jiffies + msecs_to_jiffies(RK29_SDMMC_WAIT_DTO_INTERNVAL*multi));//max wait 8s larger
2920 rk29_sdmmc_set_pending(host, EVENT_CMD_COMPLETE);
2921 tasklet_schedule(&host->tasklet);
2924 static irqreturn_t rk29_sdmmc_interrupt(int irq, void *dev_id)
2926 struct rk29_sdmmc *host = dev_id;
2927 u32 status, pending;
2932 spin_lock(&host->lock);
2934 status = rk29_sdmmc_read(host->regs, SDMMC_RINTSTS);
2935 pending = rk29_sdmmc_read(host->regs, SDMMC_MINTSTS);// read only mask reg
2942 if(pending & SDMMC_INT_CD)
2944 //disable_irq_nosync(host->irq);
2945 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS, SDMMC_INT_CD); // clear sd detect int
2946 present = rk29_sdmmc_get_cd(host->mmc);
2947 present_old = test_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
2949 if(present != present_old)
2951 printk(KERN_INFO "\n******************\n%s:INT_CD=0x%x,INT-En=%d,hostState=%d, present Old=%d ==> New=%d . [%s]\n",\
2952 __FUNCTION__, pending, host->mmc->re_initialized_flags, host->state, present_old, present, host->dma_name);
2954 rk28_send_wakeup_key(); //wake up backlight
2955 host->error_times = 0;
2958 del_timer(&host->request_timer);
2959 del_timer(&host->DTO_timer);
2960 rk29_sdmmc_dealwith_timeout(host);
2965 set_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
2967 if(host->mmc->re_initialized_flags)
2969 mod_timer(&host->detect_timer, jiffies + msecs_to_jiffies(RK29_SDMMC_REMOVAL_DELAY));
2973 mod_timer(&host->detect_timer, jiffies + msecs_to_jiffies(RK29_SDMMC_REMOVAL_DELAY*2));
2978 clear_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
2979 host->mmc->re_initialized_flags = 0;
2981 mmc_detect_change(host->mmc, 200);
2990 xbwprintk(1,"\n*******test***********\n%s:INT_CD=0x%x,INT-En=%d,hostState=%d, cmd=%d,present Old=%d ==> New=%d [%s]\n",\
2991 __FUNCTION__, pending, host->mmc->re_initialized_flags, host->state, host->cmd->opcode,present_old, present, host->dma_name);
2993 if (pending & SDMMC_INT_CMD_DONE) {
2995 xbwprintk(6, "%s..%d.. CMD%d INT_CMD_DONE INT=0x%x [%s]\n", \
2996 __FUNCTION__, __LINE__, host->cmd->opcode,pending, host->dma_name);
2998 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_CMD_DONE); // clear interrupt
2999 rk29_sdmmc_cmd_interrupt(host, status);
3004 if(pending & SDMMC_INT_SDIO)
3006 xbwprintk(7, "%s..%d.. INT_SDIO INT=0x%x [%s]\n", \
3007 __FUNCTION__, __LINE__, pending, host->dma_name);
3009 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_SDIO);
3016 if(pending & SDMMC_INT_RTO)
3018 xbwprintk(7, "%s..%d.. CMD%d CMD_ERROR_FLAGS INT=0x%x [%s]\n", \
3019 __FUNCTION__, __LINE__, host->cmd->opcode,pending, host->dma_name);
3021 //rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_RTO);
3022 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,0xFFFFFFFF); //Modifyed by xbw at 2011-08-15
3023 host->cmd_status = status;
3025 rk29_sdmmc_set_pending(host, EVENT_CMD_COMPLETE);
3027 if(!(pending & SDMMC_INT_CMD_DONE))
3029 tasklet_schedule(&host->tasklet);
3036 if(pending & SDMMC_INT_HLE)
3038 printk(KERN_ERR "%s: Error due to hardware locked. Please check your hardware. INT=0x%x, CMD%d(arg=0x%x, retries=%d). [%s]\n",\
3039 __FUNCTION__, pending,host->cmd->opcode, host->cmd->arg, host->cmd->retries, host->dma_name);
3041 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_HLE);
3046 if(pending & SDMMC_INT_DTO)
3048 xbwprintk(1,"%d..%s: INT=0x%x ,RINTSTS=0x%x, CMD%d(arg=0x%x, retries=%d),host->state=0x%x. [%s]\n", \
3049 __LINE__,__FUNCTION__, pending,status, host->cmd->opcode, host->cmd->arg, host->cmd->retries, host->state,host->dma_name);
3051 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_DTO);
3052 del_timer(&host->DTO_timer); //delete the timer for INT_DTO
3054 host->data_status |= status;
3058 rk29_sdmmc_set_pending(host, EVENT_DATA_COMPLETE);
3059 tasklet_schedule(&host->tasklet);
3064 if (pending & SDMMC_INT_FRUN)
3066 printk(KERN_ERR "%s: INT=0x%x Oh!My God,let me see!What happened?Why?Where? CMD%d(arg=0x%x, retries=%d). [%s]\n", \
3067 __FUNCTION__, pending, host->cmd->opcode, host->cmd->arg, host->cmd->retries,host->dma_name);
3069 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_FRUN);
3073 if (pending & SDMMC_INT_RXDR)
3075 xbwprintk(6, "%s..%d.. SDMMC_INT_RXDR INT=0x%x [%s]\n", \
3076 __FUNCTION__, __LINE__, pending, host->dma_name);
3078 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_RXDR); // clear interrupt
3079 rk29_sdmmc_do_pio_read(host);
3082 if (pending & SDMMC_INT_TXDR)
3084 xbwprintk(6, "%s..%d.. SDMMC_INT_TXDR INT=0x%x [%s]\n", \
3085 __FUNCTION__, __LINE__, pending, host->dma_name);
3087 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_TXDR); // clear interrupt
3088 rk29_sdmmc_do_pio_write(host);
3091 #if SDMMC_USE_INT_UNBUSY
3092 if(pending & SDMMC_INT_UNBUSY)
3094 xbwprintk(1, "%d..%s: INT=0x%x ,RINTSTS=0x%x, CMD%d(arg=0x%x, retries=%d),host->state=0x%x. [%s]\n", \
3095 __LINE__,__FUNCTION__, pending,status, host->cmd->opcode, host->cmd->arg, host->cmd->retries, \
3096 host->state,host->dma_name);
3098 rk29_sdmmc_write(host->regs, SDMMC_RINTSTS,SDMMC_INT_UNBUSY);
3100 host->data_status = status;
3102 rk29_sdmmc_set_pending(host, EVENT_DATA_UNBUSY);
3103 tasklet_schedule(&host->tasklet);
3111 spin_unlock(&host->lock);
3115 mmc_signal_sdio_irq(host->mmc);
3123 * MMC card detect thread, kicked off from detect interrupt, 1 timer
3126 static void rk29_sdmmc_detect_change(unsigned long data)
3128 struct rk29_sdmmc *host = (struct rk29_sdmmc *)data;
3135 if((RK29_CTRL_SDMMC_ID == host->pdev->id) && rk29_sdmmc_get_cd(host->mmc))
3137 host->mmc->re_initialized_flags =1;
3140 mmc_detect_change(host->mmc, 0);
3144 static void rk29_sdmmc1_check_status(unsigned long data)
3146 struct rk29_sdmmc *host = (struct rk29_sdmmc *)data;
3147 struct rk29_sdmmc_platform_data *pdata = host->pdev->dev.platform_data;
3148 unsigned int status;
3150 status = pdata->status(mmc_dev(host->mmc));
3152 pr_info("%s: slot status change detected(%d-%d)\n",mmc_hostname(host->mmc), host->oldstatus, status);
3154 if (status ^ host->oldstatus)
3158 rk29_sdmmc_hw_init(host);
3159 set_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
3160 mod_timer(&host->detect_timer, jiffies + msecs_to_jiffies(200));
3164 clear_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
3165 rk29_sdmmc_detect_change((unsigned long)host);
3169 host->oldstatus = status;
3172 static void rk29_sdmmc1_status_notify_cb(int card_present, void *dev_id)
3174 struct rk29_sdmmc *host = dev_id;
3176 rk29_sdmmc1_check_status((unsigned long)host);
3180 static int rk29_sdmmc_probe(struct platform_device *pdev)
3182 struct mmc_host *mmc;
3183 struct rk29_sdmmc *host;
3184 struct resource *regs;
3185 struct rk29_sdmmc_platform_data *pdata;
3189 /* must have platform data */
3190 pdata = pdev->dev.platform_data;
3192 dev_err(&pdev->dev, "Platform data missing\n");
3194 host->errorstep = 0x87;
3198 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3201 host->errorstep = 0x88;
3205 mmc = mmc_alloc_host(sizeof(struct rk29_sdmmc), &pdev->dev);
3208 host->errorstep = 0x89;
3213 host = mmc_priv(mmc);
3217 host->ctype = 0; // set default 1 bit mode
3218 host->errorstep = 0;
3220 host->old_cmd = 100;
3222 host->old_div = 0xFF;
3223 host->error_times = 0;
3224 host->state = STATE_IDLE;
3225 host->complete_done = 0;
3226 host->retryfunc = 0;
3228 host->new_mrq = NULL;
3231 host->gpio_det = pdata->detect_irq;
3233 host->set_iomux = pdata->set_iomux;
3238 spin_lock_init(&host->lock);
3240 #ifdef RK29_SDMMC_LIST_QUEUE
3241 INIT_LIST_HEAD(&host->queue);
3244 host->clk = clk_get(&pdev->dev, "mmc");
3246 #if RK29_SDMMC_DEFAULT_SDIO_FREQ
3247 clk_set_rate(host->clk,SDHC_FPP_FREQ);
3249 if(RK29_CTRL_SDMMC_ID== host->pdev->id)
3250 clk_set_rate(host->clk,SDHC_FPP_FREQ);
3252 clk_set_rate(host->clk,RK29_MAX_SDIO_FREQ);
3256 clk_enable(host->clk);
3257 clk_enable(clk_get(&pdev->dev, "hclk_mmc"));
3260 host->regs = ioremap(regs->start, regs->end - regs->start + 1);
3263 host->errorstep = 0x8A;
3267 mmc->ops = &rk29_sdmmc_ops[pdev->id];
3268 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
3269 mmc->pm_flags |= MMC_PM_IGNORE_PM_NOTIFY;
3271 mmc->f_min = FOD_FREQ;
3273 #if RK29_SDMMC_DEFAULT_SDIO_FREQ
3274 mmc->f_max = SDHC_FPP_FREQ;
3276 if(RK29_CTRL_SDMMC_ID== host->pdev->id)
3278 mmc->f_max = SDHC_FPP_FREQ;
3282 mmc->f_max = RK29_MAX_SDIO_FREQ;
3286 //mmc->ocr_avail = pdata->host_ocr_avail;
3287 mmc->ocr_avail = MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|MMC_VDD_30_31
3288 | MMC_VDD_31_32|MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_34_35| MMC_VDD_35_36; ///set valid volage 2.7---3.6v
3289 mmc->caps = pdata->host_caps;
3290 mmc->re_initialized_flags = 1;
3292 mmc->sdmmc_host_hw_init = rk29_sdmmc_hw_init;
3297 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
3300 mmc->max_phys_segs = 64;
3301 mmc->max_hw_segs = 64;
3305 * Block size can be up to 2048 bytes, but must be a power of two.
3307 mmc->max_blk_size = 4095;
3310 * No limit on the number of blocks transferred.
3312 mmc->max_blk_count = 4096;
3315 * Since we only have a 16-bit data length register, we must
3316 * ensure that we don't exceed 2^16-1 bytes in a single request.
3318 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; //8M bytes(2K*4K)
3321 * Set the maximum segment size. Since we aren't doing DMA
3322 * (yet) we are only limited by the data length register.
3324 mmc->max_seg_size = mmc->max_req_size;
3326 tasklet_init(&host->tasklet, rk29_sdmmc_tasklet_func, (unsigned long)host);
3328 /* Create card detect handler thread */
3329 setup_timer(&host->detect_timer, rk29_sdmmc_detect_change,(unsigned long)host);
3330 setup_timer(&host->request_timer,rk29_sdmmc_INT_CMD_DONE_timeout,(unsigned long)host);
3331 setup_timer(&host->DTO_timer,rk29_sdmmc_INT_DTO_timeout,(unsigned long)host);
3333 host->irq = platform_get_irq(pdev, 0);
3336 host->errorstep = 0x8B;
3341 memcpy(host->dma_name, pdata->dma_name, 8);
3342 host->use_dma = pdata->use_dma;
3344 xbwprintk(7,"%s..%s..%d..*********** Bus clock= %d Khz **** [%s]\n",\
3345 __FILE__, __FUNCTION__,__LINE__,clk_get_rate(host->clk)/1000, host->dma_name);
3350 host->dma_info = rk29_sdmmc_dma_infos[host->pdev->id];
3351 ret = rk29_dma_request(host->dma_info.chn, &(host->dma_info.client), NULL);
3354 printk(KERN_ERR "%s..%d...rk29_dma_request error=%d. [%s]\n", \
3355 __FUNCTION__, __LINE__,ret, host->dma_name);
3356 host->errorstep = 0x97;
3360 #if 0 //deal with the old API of DMA-module
3361 ret = rk29_dma_config(host->dma_info.chn, 4);
3362 #else //deal with the new API of DMA-module
3363 if(RK29_CTRL_SDMMC_ID== host->pdev->id)
3365 ret = rk29_dma_config(host->dma_info.chn, 4, 16);
3369 ret = rk29_dma_config(host->dma_info.chn, 4, 1);
3374 printk(KERN_ERR "%s..%d.. rk29_dma_config error=%d. [%s]\n", \
3375 __FUNCTION__, __LINE__, ret, host->dma_name);
3376 host->errorstep = 0x98;
3380 ret = rk29_dma_set_buffdone_fn(host->dma_info.chn, rk29_sdmmc_dma_complete);
3383 printk(KERN_ERR "%s..%d.. dma_set_buffdone_fn error=%d. [%s]\n", \
3384 __FUNCTION__, __LINE__, ret, host->dma_name);
3385 host->errorstep = 0x99;
3389 host->dma_addr = regs->start + SDMMC_DATA;
3392 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT) || defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
3393 host->write_protect = pdata->write_prt;
3396 rk29_sdmmc_hw_init(host);
3398 ret = request_irq(host->irq, rk29_sdmmc_interrupt, 0, dev_name(&pdev->dev), host);
3402 printk(KERN_ERR "%s..%d.. request_irq error=%d. [%s]\n", \
3403 __FUNCTION__, __LINE__, ret, host->dma_name);
3404 host->errorstep = 0x8C;
3408 /* setup sdmmc1 wifi card detect change */
3409 if (pdata->register_status_notify) {
3410 pdata->register_status_notify(rk29_sdmmc1_status_notify_cb, host);
3413 if(RK29_CTRL_SDMMC_ID== host->pdev->id)
3415 if(rk29_sdmmc_get_cd(host->mmc))
3417 set_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
3421 clear_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
3426 #if defined(CONFIG_USE_SDMMC0_FOR_WIFI_DEVELOP_BOARD)
3427 if(0== host->pdev->id)
3429 set_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
3433 #if defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
3434 if(1== host->pdev->id)
3436 set_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
3442 /* sdmmc1 wifi card slot status initially */
3443 if (pdata->status) {
3444 host->oldstatus = pdata->status(mmc_dev(host->mmc));
3445 if (host->oldstatus) {
3446 set_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
3448 clear_bit(RK29_SDMMC_CARD_PRESENT, &host->flags);
3453 platform_set_drvdata(pdev, mmc);
3457 #ifdef RK29_SDMMC_NOTIFY_REMOVE_INSERTION
3459 globalSDhost[pdev->id] = (struct rk29_sdmmc *)host;
3460 if(0== host->pdev->id)
3462 rk29_sdmmc_progress_add_attr(pdev);
3466 #if defined (CONFIG_DEBUG_FS)
3467 rk29_sdmmc_init_debugfs(host);
3470 printk(KERN_INFO ".Line%d..The End of SDMMC-probe %s. [%s]\n", __LINE__, RK29_SDMMC_VERSION,host->dma_name);
3477 rk29_dma_free(host->dma_info.chn, &host->dma_info.client);
3481 iounmap(host->regs);
3493 static int __exit rk29_sdmmc_remove(struct platform_device *pdev)
3496 struct mmc_host *mmc = platform_get_drvdata(pdev);
3497 struct rk29_sdmmc *host;
3498 struct resource *regs;
3503 host = mmc_priv(mmc);
3506 rk29_sdmmc_control_clock(host, 0);
3508 /* Shutdown detect IRQ and kill detect thread */
3509 del_timer_sync(&host->detect_timer);
3510 del_timer_sync(&host->request_timer);
3511 del_timer_sync(&host->DTO_timer);
3513 tasklet_disable(&host->tasklet);
3514 free_irq(platform_get_irq(pdev, 0), host);
3517 rk29_dma_free(host->dma_info.chn, &host->dma_info.client);
3520 mmc_remove_host(mmc);
3522 iounmap(host->regs);
3524 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3525 release_mem_region(regs->start,resource_size(regs));
3528 platform_set_drvdata(pdev, NULL);
3536 #if defined(CONFIG_ARCH_RK29)
3537 static irqreturn_t det_keys_isr(int irq, void *dev_id)
3539 struct rk29_sdmmc *host = dev_id;
3540 dev_info(&host->pdev->dev, "sd det_gpio changed(%s), send wakeup key!\n",
3541 gpio_get_value(RK29_PIN2_PA2)?"removed":"insert");
3542 rk29_sdmmc_detect_change((unsigned long)dev_id);
3547 static int rk29_sdmmc_sdcard_suspend(struct rk29_sdmmc *host)
3550 rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_GPIO2A2);
3551 gpio_request(RK29_PIN2_PA2, "sd_detect");
3552 gpio_direction_input(RK29_PIN2_PA2);
3554 host->gpio_irq = gpio_to_irq(RK29_PIN2_PA2);
3555 ret = request_irq(host->gpio_irq, det_keys_isr,
3556 (gpio_get_value(RK29_PIN2_PA2))?IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING,
3560 enable_irq_wake(host->gpio_irq);
3564 static void rk29_sdmmc_sdcard_resume(struct rk29_sdmmc *host)
3566 disable_irq_wake(host->gpio_irq);
3567 free_irq(host->gpio_irq,host);
3568 gpio_free(RK29_PIN2_PA2);
3569 rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_SDMMC0_DETECT_N);
3572 #elif defined(CONFIG_ARCH_RK30)
3573 static irqreturn_t det_keys_isr(int irq, void *dev_id)
3575 struct rk29_sdmmc *host = dev_id;
3576 dev_info(&host->pdev->dev, "sd det_gpio changed(%s), send wakeup key!\n",
3577 gpio_get_value(RK30_PIN3_PB6)?"removed":"insert");
3578 rk29_sdmmc_detect_change((unsigned long)dev_id);
3583 static int rk29_sdmmc_sdcard_suspend(struct rk29_sdmmc *host)
3586 rk29_mux_api_set(GPIO3B6_SDMMC0DETECTN_NAME, GPIO3B_GPIO3B6);
3587 gpio_request(RK30_PIN3_PB6, "sd_detect");
3588 gpio_direction_input(RK30_PIN3_PB6);
3590 host->gpio_irq = gpio_to_irq(RK30_PIN3_PB6);
3591 ret = request_irq(host->gpio_irq, det_keys_isr,
3592 (gpio_get_value(RK30_PIN3_PB6))?IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING,
3596 enable_irq_wake(host->gpio_irq);
3600 static void rk29_sdmmc_sdcard_resume(struct rk29_sdmmc *host)
3602 disable_irq_wake(host->gpio_irq);
3603 free_irq(host->gpio_irq,host);
3604 gpio_free(RK30_PIN3_PB6);
3605 rk29_mux_api_set(GPIO3B6_SDMMC0DETECTN_NAME, GPIO3B_SDMMC0_DETECT_N);
3611 static int rk29_sdmmc_suspend(struct platform_device *pdev, pm_message_t state)
3613 struct mmc_host *mmc = platform_get_drvdata(pdev);
3614 struct rk29_sdmmc *host = mmc_priv(mmc);
3617 if(host && host->pdev && (RK29_CTRL_SDMMC_ID == host->pdev->id)) //only the SDMMC0 have suspend-resume; noted by xbw
3620 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
3621 ret = mmc_suspend_host(mmc);
3623 ret = mmc_suspend_host(mmc, state);
3626 if(rk29_sdmmc_sdcard_suspend(host) < 0)
3627 dev_info(&host->pdev->dev, "rk29_sdmmc_sdcard_suspend error\n");
3633 static int rk29_sdmmc_resume(struct platform_device *pdev)
3635 struct mmc_host *mmc = platform_get_drvdata(pdev);
3636 struct rk29_sdmmc *host = mmc_priv(mmc);
3639 if(host && host->pdev && (RK29_CTRL_SDMMC_ID == host->pdev->id)) //only the SDMMC0 have suspend-resume; noted by xbw
3643 rk29_sdmmc_sdcard_resume(host);
3644 ret = mmc_resume_host(mmc);
3651 #define rk29_sdmmc_suspend NULL
3652 #define rk29_sdmmc_resume NULL
3655 static struct platform_driver rk29_sdmmc_driver = {
3656 .suspend = rk29_sdmmc_suspend,
3657 .resume = rk29_sdmmc_resume,
3658 .remove = __exit_p(rk29_sdmmc_remove),
3660 .name = "rk29_sdmmc",
3664 static int __init rk29_sdmmc_init(void)
3666 return platform_driver_probe(&rk29_sdmmc_driver, rk29_sdmmc_probe);
3669 static void __exit rk29_sdmmc_exit(void)
3671 platform_driver_unregister(&rk29_sdmmc_driver);
3674 module_init(rk29_sdmmc_init);
3675 module_exit(rk29_sdmmc_exit);
3677 MODULE_DESCRIPTION("Rk29 Multimedia Card Interface driver");
3678 MODULE_AUTHOR("xbw@rock-chips.com");
3679 MODULE_LICENSE("GPL v2");