Merge remote branch 'origin/develop_xbw_update-SDCard' into develop

This commit is contained in:
杨云 2011-07-19 09:02:40 +08:00
commit deaed860bc
18 changed files with 4917 additions and 1155 deletions

View File

@ -1760,14 +1760,13 @@ CONFIG_MMC=y
# CONFIG_MMC_DEBUG is not set
CONFIG_MMC_UNSAFE_RESUME=y
CONFIG_MMC_EMBEDDED_SDIO=y
# CONFIG_MMC_PARANOID_SD_INIT is not set
CONFIG_MMC_PARANOID_SD_INIT=y
#
# MMC/SD/SDIO Card Drivers
#
CONFIG_MMC_BLOCK=y
CONFIG_MMC_BLOCK_BOUNCE=y
CONFIG_MMC_BLOCK_DEFERRED_RESUME=y
# CONFIG_MMC_BLOCK_DEFERRED_RESUME is not set
# CONFIG_SDIO_UART is not set
# CONFIG_MMC_TEST is not set
@ -1779,8 +1778,8 @@ CONFIG_SDMMC_RK29=y
#
# Now, there are two SDMMC controllers selected, SDMMC0 and SDMMC1.
#
# CONFIG_SDMMC_RK29_OLD is not set
CONFIG_SDMMC0_RK29=y
# CONFIG_EMMC_RK29 is not set
CONFIG_SDMMC1_RK29=y
# CONFIG_MMC_SDHCI is not set
# CONFIG_MMC_AT91 is not set

View File

@ -1011,7 +1011,13 @@ static int rk29_sdmmc0_cfg_gpio(void)
rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_SDMMC0_DATA1);
rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_SDMMC0_DATA2);
rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_SDMMC0_DATA3);
#ifdef CONFIG_SDMMC_RK29_OLD
rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_GPIO2A2);
#else
rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_SDMMC0_DETECT_N);//Modifyed by xbw.
#endif
rk29_mux_api_set(GPIO5D5_SDMMC0PWREN_NAME, GPIO5H_GPIO5D5); ///GPIO5H_SDMMC0_PWR_EN); ///GPIO5H_GPIO5D5);
gpio_request(RK29_PIN5_PD5,"sdmmc");
#if 0

View File

@ -43,6 +43,10 @@
MODULE_ALIAS("mmc:block");
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
static DEFINE_MUTEX(block_mutex); //added by xbw at 2011-04-21
#endif
/*
* max 8 partitions per card
*/
@ -105,6 +109,10 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
{
struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
int ret = -ENXIO;
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
mutex_lock(&block_mutex); //added by xbw at 2011-04-21
#endif
if (md) {
if (md->usage == 2)
@ -116,6 +124,9 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
ret = -EROFS;
}
}
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
mutex_unlock(&block_mutex);
#endif
return ret;
}
@ -123,8 +134,17 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
static int mmc_blk_release(struct gendisk *disk, fmode_t mode)
{
struct mmc_blk_data *md = disk->private_data;
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
mutex_lock(&block_mutex); //added by xbw at 2011-04-21
#endif
mmc_blk_put(md);
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
mutex_unlock(&block_mutex);
#endif
return 0;
}
@ -224,6 +244,13 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
return result;
}
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD) //Deleted by xbw@2011-03-21
//static u32 get_card_status(struct mmc_card *card, struct request *req)
//{
// return 0;
//}
#else
static u32 get_card_status(struct mmc_card *card, struct request *req)
{
struct mmc_command cmd;
@ -240,6 +267,7 @@ static u32 get_card_status(struct mmc_card *card, struct request *req)
req->rq_disk->disk_name, err);
return cmd.resp[0];
}
#endif
static int
mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
@ -285,13 +313,22 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
mmc_claim_host(card->host);
do {
struct mmc_command cmd;
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
//struct mmc_command cmd;//Deleted by xbw@2011-03-21
#else
struct mmc_command cmd;
#endif
u32 readcmd, writecmd, status = 0;
memset(&brq, 0, sizeof(struct mmc_blk_request));
brq.mrq.cmd = &brq.cmd;
brq.mrq.data = &brq.data;
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
brq.cmd.retries = 2; //suppot retry read-write; added by xbw@2011-03-21
#endif
brq.cmd.arg = blk_rq_pos(req);
if (!mmc_card_blockaddr(card))
brq.cmd.arg <<= 9;
@ -371,6 +408,11 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
mmc_queue_bounce_post(mq);
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
//not turn CMD18 to CMD17. deleted by xbw at 2011-04-21
#else
/*
* Check for errors here, but don't jump to cmd_err
* until later as we need to wait for the card to leave
@ -387,7 +429,8 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
status = get_card_status(card, req);
} else if (disable_multi == 1) {
disable_multi = 0;
}
}
#endif
if (brq.cmd.error) {
printk(KERN_DEBUG "%s: error %d sending read/write "
@ -414,6 +457,10 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
brq.stop.resp[0], status);
}
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
//Deleted by xbw@2011-03-21
#else
if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
do {
int err;
@ -443,8 +490,9 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
goto cmd_err;
#endif
}
#endif
if (brq.cmd.error || brq.stop.error || brq.data.error) {
if (brq.cmd.error || brq.stop.error || brq.data.error) {
if (rq_data_dir(req) == READ) {
/*
* After an error, we redo I/O one sector at a
@ -572,6 +620,11 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
sprintf(md->disk->disk_name, "mmcblk%d", devidx);
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
printk("%s..%d **** devidx=%d, dev_use[0]=%lu, disk_name=%s *** ==xbw[%s]==\n",\
__FUNCTION__,__LINE__, devidx, dev_use[0], md->disk->disk_name,mmc_hostname(card->host));
#endif
blk_queue_logical_block_size(md->queue.queue, 512);
if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {

View File

@ -279,7 +279,9 @@ void mmc_remove_card(struct mmc_card *card)
#endif
if (mmc_card_present(card)) {
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD)
mmc_card_clr_present(card);
#endif
if (mmc_host_is_spi(card->host)) {
printk(KERN_INFO "%s: SPI card removed\n",
mmc_hostname(card->host));

View File

@ -202,7 +202,11 @@ void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
mmc_start_request(host, mrq);
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
wait_for_completion_timeout(&complete,HZ*3); //for cmd dead. Modifyed by xbw at 2011-06-02
#else
wait_for_completion(&complete);
#endif
}
EXPORT_SYMBOL(mmc_wait_for_req);
@ -1059,7 +1063,7 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay)
EXPORT_SYMBOL(mmc_detect_change);
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
void mmc_rescan(struct work_struct *work)
{
struct mmc_host *host =
@ -1067,6 +1071,156 @@ void mmc_rescan(struct work_struct *work)
u32 ocr;
int err;
int extend_wakelock = 0;
mmc_bus_get(host);
/* if there is a card registered, check whether it is still present */
if ((host->bus_ops != NULL) && host->bus_ops->detect && !host->bus_dead)
host->bus_ops->detect(host);
/* If the card was removed the bus will be marked
* as dead - extend the wakelock so userspace
* can respond */
if (host->bus_dead)
extend_wakelock = 1;
mmc_bus_put(host);
mmc_bus_get(host);
/* if there still is a card present, stop here */
if (host->bus_ops != NULL) {
mmc_bus_put(host);
goto out;
}
/* detect a newly inserted card */
/*
* Only we can add a new handler, so it's safe to
* release the lock here.
*/
mmc_bus_put(host);
printk("\n%s...%d.. ===== mmc_rescan Begin....======xbw[%s]=====\n",__FILE__, __LINE__, mmc_hostname(host));
if (host->ops->get_cd && host->ops->get_cd(host) == 0)
{
printk("\n=================\n%s..%d.. ====find no SDMMC host.====xbw[%s]=====\n", \
__FUNCTION__, __LINE__, mmc_hostname(host));
goto out;
}
mmc_claim_host(host);
mmc_power_up(host);
mmc_go_idle(host);
/*
In oder to improve the initialization process in rockchip IC, I modify the following code about the the initialization process of SDIO-SD-MMC.
So I deleted the CMD8 and add a conditional to distinguish between the two card type,i.e.SDMMC process and SDIO process.
For detail,please refer to "RK29XX Technical Reference Manual" and "SD-MMC-SDIO Specifications".
Noted by xbw@2011-04-09
*/
//mmc_send_if_cond(host, host->ocr_avail); //deleted by xbw@2011-04-09
if( strncmp( mmc_hostname(host) ,"mmc0" , strlen("mmc0")) ){
/*
* First we search for SDIO...
*/
err = mmc_send_io_op_cond(host, 0, &ocr);
if (!err) {
printk("\n%s..%d.. ===== Begin to identify card as SDIO-card===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
if (mmc_attach_sdio(host, ocr))
{
printk("\n=====\n %s..%d.. ===== Initialize SDIO-card unsuccessfully!!! ===xbw[%s]===\n=====\n",\
__FUNCTION__, __LINE__, mmc_hostname(host));
mmc_power_off(host);
}
else
{
printk("%s..%d.. ===== Initialize SDIO successfully. ===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
}
extend_wakelock = 1;
goto out;
}
}
/*
* ...then normal SD...
*/
err = mmc_send_app_op_cond(host, 0, &ocr);
if (!err) {
printk("\n%s..%d.. ===== Begin to identify card as SD-card ===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
if (mmc_attach_sd(host, ocr))
{
printk("\n=====\n%s..%d.. ===== Initialize SD-card unsuccessfully!!! ===xbw[%s]===\n====\n",\
__FUNCTION__, __LINE__, mmc_hostname(host));
mmc_power_off(host);
}
else
{
printk("%s..%d.. ===== Initialize SD-card successfully. ===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
}
extend_wakelock = 1;
goto out;
}
/*
* ...and finally MMC.
*/
err = mmc_send_op_cond(host, 0, &ocr);
if (!err) {
printk("\n%s..%d.. ===== Begin to identify card as MMC-card ===xbw[%s]===\n", __FUNCTION__, __LINE__, mmc_hostname(host));
if (mmc_attach_mmc(host, ocr))
{
printk("\n =====\n%s..%d.. ===== Initialize MMC-card unsuccessfully!!! ===xbw[%s]===\n======\n",\
__FUNCTION__, __LINE__, mmc_hostname(host));
mmc_power_off(host);
}
else
{
printk("%s...%d.. ===== Initialize MMC-card successfully. ===xbw[%s]===\n",__FUNCTION__, __LINE__, mmc_hostname(host));
}
extend_wakelock = 1;
goto out;
}
mmc_release_host(host);
mmc_power_off(host);
out:
if (extend_wakelock)
wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);
else
wake_unlock(&mmc_delayed_work_wake_lock);
if (host->caps & MMC_CAP_NEEDS_POLL)
mmc_schedule_delayed_work(&host->detect, HZ);
}
#else
void mmc_rescan(struct work_struct *work)
{
struct mmc_host *host =
container_of(work, struct mmc_host, detect.work);
u32 ocr;
int err;
int extend_wakelock = 0;
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD)
unsigned long flags;
spin_lock_irqsave(&host->lock, flags);
@ -1077,6 +1231,7 @@ void mmc_rescan(struct work_struct *work)
}
spin_unlock_irqrestore(&host->lock, flags);
#endif
mmc_bus_get(host);
@ -1165,6 +1320,7 @@ void mmc_rescan(struct work_struct *work)
if (host->caps & MMC_CAP_NEEDS_POLL)
mmc_schedule_delayed_work(&host->detect, HZ);
}
#endif
void mmc_start_host(struct mmc_host *host)
{
@ -1301,6 +1457,23 @@ int mmc_suspend_host(struct mmc_host *host, pm_message_t state)
if (host->bus_ops && !host->bus_dead) {
if (host->bus_ops->suspend)
err = host->bus_ops->suspend(host);
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD)
//deleted all detail code.
#else
if (err == -ENOSYS || !host->bus_ops->resume) {
/*
* We simply "remove" the card in this case.
* It will be redetected on resume.
*/
if (host->bus_ops->remove)
host->bus_ops->remove(host);
mmc_claim_host(host);
mmc_detach_bus(host);
mmc_release_host(host);
err = 0;
}
#endif
}
mmc_bus_put(host);
@ -1331,6 +1504,8 @@ int mmc_resume_host(struct mmc_host *host)
mmc_power_up(host);
mmc_select_voltage(host, host->ocr);
BUG_ON(!host->bus_ops->resume);
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD)
err = host->bus_ops->resume(host);
if (err) {
printk(KERN_WARNING "%s: error %d during resume "
@ -1338,13 +1513,44 @@ int mmc_resume_host(struct mmc_host *host)
mmc_hostname(host), err);
err = 0;
}
#elif defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
//panic if the card is being removed during the resume, deleted by xbw at 2011-06-20
host->bus_ops->resume(host);
#else
err = host->bus_ops->resume(host);
if (err) {
printk(KERN_WARNING "%s: error %d during resume "
"(card was removed?)\n",
mmc_hostname(host), err);
if (host->bus_ops->remove)
host->bus_ops->remove(host);
mmc_claim_host(host);
mmc_detach_bus(host);
mmc_release_host(host);
/* no need to bother upper layers */
err = 0;
}
#endif
}
mmc_bus_put(host);
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD)
//delete the detect_change.
#else
/*
* We add a slight delay here so that resume can progress
* in parallel.
*/
mmc_detect_change(host, 1);
#endif
return err;
}
EXPORT_SYMBOL(mmc_resume_host);
///old driver add the function reforming to kernel2.6.38
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD)
/* Do the card removal on suspend if card is assumed removeable
* Do that in pm notifier while userspace isn't yet frozen, so we will be able
to sync the card.
@ -1390,6 +1596,8 @@ int mmc_pm_notify(struct notifier_block *notify_block,
return 0;
}
#endif// endif---defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD)
#endif
#ifdef CONFIG_MMC_EMBEDDED_SDIO

View File

@ -16,8 +16,9 @@
#include <linux/idr.h>
#include <linux/pagemap.h>
#include <linux/leds.h>
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD)
#include <linux/suspend.h>
#endif
#include <linux/mmc/host.h>
#include "core.h"
@ -85,8 +86,10 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
init_waitqueue_head(&host->wq);
INIT_DELAYED_WORK(&host->detect, mmc_rescan);
INIT_DELAYED_WORK_DEFERRABLE(&host->disable, mmc_host_deeper_disable);
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD) // old driver, add pm reform to kernel2.6.38
#ifdef CONFIG_PM
host->pm_notify.notifier_call = mmc_pm_notify;
#endif
#endif
/*
@ -136,8 +139,11 @@ int mmc_add_host(struct mmc_host *host)
#endif
mmc_start_host(host);
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD) // old driver, add pm reform to kernel2.6.38
if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY))
register_pm_notifier(&host->pm_notify);
#endif
return 0;
}
@ -154,8 +160,11 @@ EXPORT_SYMBOL(mmc_add_host);
*/
void mmc_remove_host(struct mmc_host *host)
{
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD) // old driver, add pm reform to kernel2.6.38
if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY))
unregister_pm_notifier(&host->pm_notify);
#endif
mmc_stop_host(host);
#ifdef CONFIG_DEBUG_FS

View File

@ -321,7 +321,13 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
/* The extra bit indicates that we support high capacity */
err = mmc_send_op_cond(host, ocr | (1 << 30), NULL);
if (err)
{
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
printk("%s..%d.. ====*Identify the card as MMC , but OCR error, so fail to initialize.===xbw[%s]===\n",\
__FUNCTION__, __LINE__, mmc_hostname(host));
#endif
goto err;
}
/*
* For SPI, enable CRC as appropriate.
@ -438,6 +444,10 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
if (max_dtr > card->ext_csd.hs_max_dtr)
max_dtr = card->ext_csd.hs_max_dtr;
} else if (max_dtr > card->csd.max_dtr) {
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
//in order to expand the compatibility of card. Added by xbw@2011-03-21
card->csd.max_dtr = (card->csd.max_dtr > MMC_FPP_FREQ) ? MMC_FPP_FREQ : (card->csd.max_dtr);
#endif
max_dtr = card->csd.max_dtr;
}
@ -660,6 +670,9 @@ static void mmc_attach_bus_ops(struct mmc_host *host)
int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
{
int err;
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
int retry_times = 3;
#endif
BUG_ON(!host);
WARN_ON(!host->claimed);
@ -704,10 +717,33 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
goto err;
mmc_release_host(host);
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
//modifyed by xbw at 2011--04-11
Retry_add:
err = mmc_add_card(host->card);
if (err)
{
//retry add the card; Added by xbw
if((--retry_times >= 0))
{
printk("\n%s..%s..%d ****error in add partition, so retry. ===xbw[%s]===\n",__FUNCTION__,__FILE__,__LINE__, mmc_hostname(host));
/* sleep some time */
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(HZ/2);
goto Retry_add;
}
goto remove_card;
}
#else
err = mmc_add_card(host->card);
if (err)
goto remove_card;
#endif
return 0;

View File

@ -362,7 +362,13 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
err = mmc_send_app_op_cond(host, ocr, NULL);
if (err)
{
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
printk("%s..%d.. ====*Identify the card as SD , but OCR error, so fail to initialize.===xbw[%s]===\n", \
__FUNCTION__, __LINE__, mmc_hostname(host));
#endif
goto err;
}
/*
* Fetch CID from card.
@ -458,6 +464,13 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
printk(KERN_WARNING
"%s: read switch failed (attempt %d)\n",
mmc_hostname(host), retries);
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(0 == host->re_initialized_flags)
{
break; //Added by xbw at 2011-06-21
}
#endif
}
}
#else
@ -496,6 +509,11 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
if (max_dtr > card->sw_caps.hs_max_dtr)
max_dtr = card->sw_caps.hs_max_dtr;
} else if (max_dtr > card->csd.max_dtr) {
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
//in order to expand the compatibility of card. Added by xbw@2011-03-21
card->csd.max_dtr = (card->csd.max_dtr > SD_FPP_FREQ) ? SD_FPP_FREQ : (card->csd.max_dtr);
#endif
max_dtr = card->csd.max_dtr;
}
@ -576,6 +594,15 @@ static void mmc_sd_detect(struct mmc_host *host)
err = mmc_send_status(host->card, NULL);
if (err) {
retries--;
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(0 == host->re_initialized_flags)
{
retries = 0;
break; //Added by xbw at 2011-06-21
}
#endif
udelay(5);
continue;
}
@ -643,6 +670,13 @@ static int mmc_sd_resume(struct mmc_host *host)
mmc_hostname(host), err, retries);
mdelay(5);
retries--;
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(0 == host->re_initialized_flags)
{
break; //Added by xbw at 2011-06-21
}
#endif
continue;
}
break;
@ -715,6 +749,10 @@ static void mmc_sd_attach_bus_ops(struct mmc_host *host)
int mmc_attach_sd(struct mmc_host *host, u32 ocr)
{
int err;
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
int retry_times = 3;
#endif
#ifdef CONFIG_MMC_PARANOID_SD_INIT
int retries;
#endif
@ -772,6 +810,14 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
err = mmc_sd_init_card(host, host->ocr, NULL);
if (err) {
retries--;
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(0 == host->re_initialized_flags)
{
retries = 0;
break; //Added by xbw at 2011-06-21
}
#endif
continue;
}
break;
@ -790,9 +836,31 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
mmc_release_host(host);
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
//modifyed by xbw at 2011--04-11
Retry_add:
err = mmc_add_card(host->card);
if (err)
{
//retry add the card; Added by xbw
if((--retry_times >= 0))
{
printk("\n%s..%s..%d ****error in add partition, so retry. ===xbw[%s]===\n",__FUNCTION__,__FILE__,__LINE__, mmc_hostname(host));
/* sleep some time */
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(HZ/2);
goto Retry_add;
}
goto remove_card;
}
#else
err = mmc_add_card(host->card);
if (err)
goto remove_card;
#endif
return 0;

View File

@ -241,7 +241,13 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
*/
err = mmc_send_io_op_cond(host, host->ocr, &ocr);
if (err)
{
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
printk("%s..%d.. ====*Identify the card as SDIO , but OCR error, so fail to initialize.===xbw[%s]===\n", \
__FUNCTION__, __LINE__, mmc_hostname(host));
#endif
goto err;
}
/*
* For SPI, enable CRC as appropriate.
@ -278,6 +284,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
if (err)
goto remove;
#if defined(CONFIG_SDMMC_RK29) && defined(CONFIG_SDMMC_RK29_OLD) //old driver add the code ,reform to kernel2.6.38
/*
* Update oldcard with the new RCA received from the SDIO
* device -- we're doing this so that it's updated in the
@ -285,6 +292,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
*/
if (oldcard)
oldcard->rca = card->rca;
#endif
mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
}

View File

@ -35,18 +35,24 @@ config SDMMC_RK29
SDMMC0 used for sd/mmc card, and SDMMC1 used for sdio.
if SDMMC_RK29
comment "Now, there are two SDMMC controllers selected, SDMMC0 and SDMMC1."
config SDMMC_RK29_OLD
bool "Old driver (DEPRECATED)"
help
You will select old,origin driver for your project if you say Yes.
It is not good to select the driver.
config SDMMC0_RK29
tristate "RK29 SDMMC0 controller support(sdmmc)"
default y
depends on ARCH_RK29
help
This supports the use of the SDMMC0 controller on Rk29 processors.
config EMMC_RK29
tristate "RK29 EMMC controller support(sdmmc)"
default y
depends on SDMMC0_RK29
help
This supports the use of the EMMC controller on Rk29 processors.
# config EMMC_RK29
# tristate "RK29 EMMC controller support(sdmmc)"
# default y
# depends on SDMMC0_RK29
# help
# This supports the use of the EMMC controller on Rk29 processors.
config SDMMC1_RK29
tristate "RK29 SDMMC1 controller support(sdio)"
default y

View File

@ -6,7 +6,12 @@ ifeq ($(CONFIG_MMC_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
endif
ifeq ($(CONFIG_SDMMC_RK29_OLD),y)
obj-$(CONFIG_SDMMC_RK29) += rk29_sdmmc_old.o
else
obj-$(CONFIG_SDMMC_RK29) += rk29_sdmmc.o
endif
obj-$(CONFIG_SDMMC_RK2818) += rk2818-sdmmc.o
obj-$(CONFIG_MMC_ARMMMCI) += mmci.o
obj-$(CONFIG_MMC_PXA) += pxamci.o

3795
drivers/mmc/host/rk29_sdmmc.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,202 @@
/* drivers/mmc/host/rk29_sdmmc.h
*
* Copyright (C) 2011 ROCKCHIP, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef __RK2918_SDMMC_H
#define __RK2918_SDMMC_H
#define MAX_SG_CHN 2
#define SDMMC_CTRL (0x000) //SDMMC Control register
#define SDMMC_PWREN (0x004) //Power enable register
#define SDMMC_CLKDIV (0x008) //Clock divider register
#define SDMMC_CLKSRC (0x00c) //Clock source register
#define SDMMC_CLKENA (0x010) //Clock enable register
#define SDMMC_TMOUT (0x014) //Time out register
#define SDMMC_CTYPE (0x018) //Card type register
#define SDMMC_BLKSIZ (0x01c) //Block size register
#define SDMMC_BYTCNT (0x020) //Byte count register
#define SDMMC_INTMASK (0x024) //Interrupt mask register
#define SDMMC_CMDARG (0x028) //Command argument register
#define SDMMC_CMD (0x02c) //Command register
#define SDMMC_RESP0 (0x030) //Response 0 register
#define SDMMC_RESP1 (0x034) //Response 1 register
#define SDMMC_RESP2 (0x038) //Response 2 register
#define SDMMC_RESP3 (0x03c) //Response 3 register
#define SDMMC_MINTSTS (0x040) //Masked interrupt status register
#define SDMMC_RINTSTS (0x044) //Raw interrupt status register
#define SDMMC_STATUS (0x048) //Status register
#define SDMMC_FIFOTH (0x04c) //FIFO threshold register
#define SDMMC_CDETECT (0x050) //Card detect register
#define SDMMC_WRTPRT (0x054) //Write protect register
#define SDMMC_TCBCNT (0x05c) //Transferred CIU card byte count
#define SDMMC_TBBCNT (0x060) //Transferred host/DMA to/from BIU_FIFO byte count
#define SDMMC_DEBNCE (0x064) //Card detect debounce register
#define SDMMC_DATA (0x100)
#define RK2818_BIT(n) (1<<(n))
#define RK_CLEAR_BIT(n) (0<<(n))
/* Control register defines (base+ 0x00)*/
#define SDMMC_CTRL_OD_PULLUP RK2818_BIT(24)
#define SDMMC_CTRL_DMA_ENABLE RK2818_BIT(5)
#define SDMMC_CTRL_INT_ENABLE RK2818_BIT(4)
#define SDMMC_CTRL_FIFO_RESET RK2818_BIT(1)
#define SDMMC_CTRL_RESET RK2818_BIT(0)
/* Power Enable Register(base+ 0x04) */
#define POWER_ENABLE RK2818_BIT(0) //Power enable
#define POWER_DISABLE RK_CLEAR_BIT(0) //Power off
/* SDMMC Clock source Register(base+ 0x0C) */
#define CLK_DIV_SRC_0 (0x0) //clock divider 0 selected
#define CLK_DIV_SRC_1 (0x1) //clock divider 1 selected
#define CLK_DIV_SRC_2 (0x2) //clock divider 2 selected
#define CLK_DIV_SRC_3 (0x3) //clock divider 3 selected
/* Clock Enable register defines(base+0x10) */
#define SDMMC_CLKEN_LOW_PWR RK2818_BIT(16)
#define SDMMC_CLKEN_NO_LOW_PWR RK_CLEAR_BIT(16) //low-power mode disabled
#define SDMMC_CLKEN_ENABLE RK2818_BIT(0)
#define SDMMC_CLKEN_DISABLE RK_CLEAR_BIT(16) //clock disabled
/* time-out register defines(base+0x14) */
#define SDMMC_TMOUT_DATA(n) _SBF(8, (n))
#define SDMMC_TMOUT_DATA_MSK 0xFFFFFF00
#define SDMMC_TMOUT_RESP(n) ((n) & 0xFF)
#define SDMMC_TMOUT_RESP_MSK 0xFF
/* card-type register defines(base+0x18) */
#define SDMMC_CTYPE_8BIT RK2818_BIT(16)
#define SDMMC_CTYPE_4BIT RK2818_BIT(0)
#define SDMMC_CTYPE_1BIT RK_CLEAR_BIT(0)
/* Interrupt status & mask register defines(base+0x24) */
#define SDMMC_INT_SDIO RK2818_BIT(16) //SDIO interrupt
#define SDMMC_INT_EBE RK2818_BIT(15) //End Bit Error(read)/Write no CRC
#define SDMMC_INT_ACD RK2818_BIT(14) //Auto Command Done
#define SDMMC_INT_SBE RK2818_BIT(13) //Start Bit Error
#define SDMMC_INT_HLE RK2818_BIT(12) //Hardware Locked Write Error
#define SDMMC_INT_FRUN RK2818_BIT(11) //FIFO Underrun/Overrun Error
#define SDMMC_INT_HTO RK2818_BIT(10) //Data Starvation by Host Timeout
#define SDMMC_INT_DRTO RK2818_BIT(9) //Data Read TimeOut
#define SDMMC_INT_RTO RK2818_BIT(8) //Response TimeOut
#define SDMMC_INT_DCRC RK2818_BIT(7) //Data CRC Error
#define SDMMC_INT_RCRC RK2818_BIT(6) //Response CRC Error
#define SDMMC_INT_RXDR RK2818_BIT(5) //Receive FIFO Data Request
#define SDMMC_INT_TXDR RK2818_BIT(4) //Transmit FIFO Data Request
#define SDMMC_INT_DTO RK2818_BIT(3) //Data Transfer Over
#define SDMMC_INT_CMD_DONE RK2818_BIT(2) //Command Done
#define SDMMC_INT_RE RK2818_BIT(1) //Response Error
#define SDMMC_INT_CD RK2818_BIT(0) //Card Detect
/* Command register defines(base+0x2C) */
#define SDMMC_CMD_START RK2818_BIT(31) //start command
#define SDMMC_CMD_UPD_CLK RK2818_BIT(21) //update clock register only
#define SDMMC_CMD_INIT RK2818_BIT(15) //send initialization sequence
#define SDMMC_CMD_STOP RK2818_BIT(14) //stop abort command
#define SDMMC_CMD_PRV_DAT_NO_WAIT RK_CLEAR_BIT(13) //not wait previous data transfer complete, send command at once
#define SDMMC_CMD_PRV_DAT_WAIT RK2818_BIT(13) //wait previous data transfer complete
#define SDMMC_CMD_SEND_STOP RK2818_BIT(12) //send auto stop command at end of data transfer
#define SDMMC_CMD_BLOCK_MODE RK_CLEAR_BIT(11) //block data transfer command
#define SDMMC_CMD_STRM_MODE RK2818_BIT(11) //stream data transfer command
#define SDMMC_CMD_DAT_READ RK_CLEAR_BIT(10) //read from card
#define SDMMC_CMD_DAT_WRITE RK2818_BIT(10) //write to card;
#define SDMMC_CMD_DAT_WR RK2818_BIT(10) //write to card;
#define SDMMC_CMD_DAT_NO_EXP RK_CLEAR_BIT(9) //no data transfer expected
#define SDMMC_CMD_DAT_EXP RK2818_BIT(9) //data transfer expected
#define SDMMC_CMD_RESP_NO_CRC RK_CLEAR_BIT(8) //do not check response crc
#define SDMMC_CMD_RESP_CRC RK2818_BIT(8) //check response crc
#define SDMMC_CMD_RESP_CRC_NOCARE SDMMC_CMD_RESP_CRC //not care response crc
#define SDMMC_CMD_RESP_SHORT RK_CLEAR_BIT(7) //short response expected from card
#define SDMMC_CMD_RESP_LONG RK2818_BIT(7) //long response expected from card;
#define SDMMC_CMD_RESP_NOCARE SDMMC_CMD_RESP_SHORT //not care response length
#define SDMMC_CMD_RESP_NO_EXP RK_CLEAR_BIT(6) //no response expected from card
#define SDMMC_CMD_RESP_EXP RK2818_BIT(6) //response expected from card
#define SDMMC_CMD_INDX(n) ((n) & 0x1F)
/* Status register defines (base+0x48)*/
#define SDMMC_STAUTS_DATA_BUSY RK2818_BIT(9) //Card busy
#define SDMMC_CMD_FSM_MASK (0x0F << 4) //Command FSM status mask
#define SDMMC_CMD_FSM_IDLE (0x00) //CMD FSM is IDLE
#define SDMMC_STAUTS_FIFO_FULL RK2818_BIT(3) //FIFO is full status
#define SDMMC_STAUTS_FIFO_EMPTY RK2818_BIT(2) //FIFO is empty status
#define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FF)//fifo_count, numbers of filled locations in FIFO
#define SDMMC_FIFO_SZ 32
/* FIFO Register (base + 0x4c)*/
#define SD_MSIZE_1 (0x0 << 28) //DW_DMA_Multiple_Transaction_Size
#define SD_MSIZE_4 (0x1 << 28)
#define SD_MSIZE_8 (0x1 << 28)
#define SD_MSIZE_16 (0x3 << 28)
#define SD_MSIZE_32 (0x4 << 28)
#define SD_MSIZE_64 (0x5 << 28)
#define SD_MSIZE_128 (0x6 << 28)
#define SD_MSIZE_256 (0x7 << 28)
#define FIFO_DEPTH (0x20) //FIFO depth = 32 word
#define RX_WMARK_SHIFT (16)
#define TX_WMARK_SHIFT (0)
/* FIFO watermark */
#define RX_WMARK (0xF) //RX watermark level set to 15
#define TX_WMARK (0x10) //TX watermark level set to 16
/* CDETECT register defines (base+0x50)*/
#define SDMMC_CARD_DETECT_N RK2818_BIT(0) //0--represents presence of card.
/* WRIPRT register defines (base+0x54)*/
#define SDMMC_WRITE_PROTECT RK2818_BIT(0) // 1--represents write protect
/* Specifies how often in millisecs to poll for card removal-insertion changes
* when the timer switch is open */
#define RK_SDMMC0_SWITCH_POLL_DELAY 35
/* SDMMC progress return value */
#define SDM_SUCCESS (0)
#define SDM_FALSE (1)
#define SDM_PARAM_ERROR (2)
#define SDM_RESP_ERROR (3)
#define SDM_RESP_TIMEOUT (4)
#define SDM_DATA_CRC_ERROR (5)
#define SDM_DATA_READ_TIMEOUT (6)
#define SDM_END_BIT_ERROR (7)
#define SDM_START_BIT_ERROR (8)
#define SDM_BUSY_TIMEOUT (9)
#define SDM_ERROR (10) //SDMMC host controller error
#define SDM_START_CMD_FAIL (11)
#define SDM_WAIT_FOR_CMDSTART_TIMEOUT (12)
#define SDM_WAIT_FOR_FIFORESET_TIMEOUT (13)
#define FALSE 0
#define TRUE 1
#define DEBOUNCE_TIME (25) //uint is ms, recommend 5--25ms
#endif

1558
drivers/mmc/host/rk29_sdmmc_old.c Executable file

File diff suppressed because it is too large Load Diff

View File

@ -541,7 +541,16 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
int p, highest, res;
if (bdev->bd_part_count)
{
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(179 == MAJOR(bdev->bd_dev))
{
printk("%s..%d.. The sdcard partition have been using.So device busy! ====xbw===\n",__FUNCTION__, __LINE__);
}
#endif
return -EBUSY;
}
res = invalidate_partition(disk, 0);
if (res)
return res;
@ -556,7 +565,15 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
check_disk_size_change(disk, bdev);
bdev->bd_invalidated = 0;
if (!get_capacity(disk) || !(state = check_partition(disk, bdev)))
{
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(179 == MAJOR(bdev->bd_dev))
{
printk("%s..%d... ==== check partition fail. partitionAddr=%x ====xbw===\n",__FUNCTION__, __LINE__, state);
}
#endif
return 0;
}
if (IS_ERR(state)) /* I/O error reading the partition table */
return -EIO;

View File

@ -440,6 +440,13 @@ int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
return 0;
}
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(179 == MAJOR(bdev->bd_dev))
{
printk("\n%s..%d... ==== Begin to parse sdcard-partition. ====xbw[mmc0]===\n",__FUNCTION__, __LINE__);
}
#endif
/*
* Now that the 55aa signature is present, this is probably
* either the boot sector of a FAT filesystem or a DOS-type
@ -449,6 +456,12 @@ int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
p = (struct partition *) (data + 0x1be);
for (slot = 1; slot <= 4; slot++, p++) {
if (p->boot_ind != 0 && p->boot_ind != 0x80) {
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(179 == MAJOR(bdev->bd_dev))
{
printk("%s..%d... ==== The sdcard has not MBR. ====xbw[mmc0]===\n",__FUNCTION__, __LINE__);
}
#endif
/*
* Even without a valid boot inidicator value
* its still possible this is valid FAT filesystem
@ -459,9 +472,21 @@ int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
&& fat_valid_media(fb->media)) {
printk("\n");
put_dev_sector(sect);
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(179 == MAJOR(bdev->bd_dev))
{
printk("%s..%d... ==== The DBR(slot=%d) is valid. ====xbw[mmc0]===\n",__FUNCTION__, __LINE__, slot);
}
#endif
return 1;
} else {
put_dev_sector(sect);
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(179 == MAJOR(bdev->bd_dev))
{
printk("%s..%d... ==== The DBR is invalid. ====xbw[mmc0]===\n",__FUNCTION__, __LINE__);
}
#endif
return 0;
}
}
@ -484,13 +509,25 @@ int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
* First find the primary and DOS-type extended partitions.
* On the second pass look inside *BSD, Unixware and Solaris partitions.
*/
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(179 == MAJOR(bdev->bd_dev))
{
printk("%s..%d... ==== The sdcard has MBR. ====xbw[mmc0]===\n", __FUNCTION__, __LINE__);
}
#endif
state->next = 5;
for (slot = 1 ; slot <= 4 ; slot++, p++) {
sector_t start = start_sect(p)*sector_size;
sector_t size = nr_sects(p)*sector_size;
if (!size)
continue;
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(179 == MAJOR(bdev->bd_dev))
{
printk("%s..%d... ==== partition-%d, size=%luKB ====xbw[mmc0]===\n",\
__FUNCTION__, __LINE__, slot, size/2);
}
#endif
if (is_extended_partition(p)) {
/*
* prevent someone doing mkfs or mkswap on an
@ -500,6 +537,12 @@ int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
*/
sector_t n = 2;
n = min(size, max(sector_size, n));
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(179 == MAJOR(bdev->bd_dev))
{
printk("%s...%d... ==== extend partition-%d....====xbw[mmc0]===\n",__FUNCTION__, __LINE__, slot);
}
#endif
put_partition(state, slot, start, n);
printk(" <");
@ -507,6 +550,12 @@ int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
printk(" >");
continue;
}
#if defined(CONFIG_SDMMC_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
if(179 == MAJOR(bdev->bd_dev))
{
printk("%s..%d... ==== main partition-%d....====xbw[mmc0]===\n",__FUNCTION__, __LINE__, slot);
}
#endif
put_partition(state, slot, start, size);
if (SYS_IND(p) == LINUX_RAID_PARTITION)
state->parts[slot].flags = 1;

View File

@ -203,6 +203,8 @@ struct mmc_host {
#define MMC_BUSRESUME_MANUAL_RESUME (1 << 0)
#define MMC_BUSRESUME_NEEDS_RESUME (1 << 1)
unsigned int re_initialized_flags; //in order to begin the rescan ; added by xbw@2011-04-07
unsigned int sdio_irqs;
struct task_struct *sdio_irq_thread;
atomic_t sdio_irq_thread_abort;

View File

@ -282,5 +282,18 @@ struct _mmc_csd {
#define MMC_SWITCH_MODE_CLEAR_BITS 0x02 /* Clear bits which are 1 in value */
#define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target to value */
/*
* some limit value of SDMMC about protocol ; Added by xbw at 2011-03-21
*/
#define FOD_FREQ (300000) // in the identify stage, unit: hz, max is 400Khz,
// the least frequency is FREQ_HCLK_MAX/8
#define SD_FPP_FREQ (24000000) // normal sd freq, 25Mhz
#define SDHC_FPP_FREQ (49000000) // SDHC in the highspeed. unit is hz, max is 50Mhz.
#define MMC_FPP_FREQ (19000000) // MMC freq, unit is hz, max is 20MHz
#define MMCHS_26_FPP_FREQ (24000000) // highspeed mode support 26M HS-MMC, unit is hz, max is 26Mhz,
#define MMCHS_52_FPP_FREQ (49000000) // highspeed support 52M HS-MMC, unit is hz, max is 52Mhz,
#endif /* MMC_MMC_PROTOCOL_H */