Add mmc and emmc drivers.

This commit is contained in:
weety
2015-06-20 23:23:32 +08:00
parent 562ac32e32
commit 41597e8793
6 changed files with 834 additions and 26 deletions
+1
View File
@@ -7,6 +7,7 @@ block_dev.c
mmcsd_core.c
sd.c
sdio.c
mmc.c
""")
# The set of source files associated with this SConscript file.
+3 -10
View File
@@ -149,7 +149,7 @@ static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card,
}
else
{
req.stop = NULL;
req.stop = RT_NULL;
r_cmd = READ_SINGLE_BLOCK;
w_cmd = WRITE_BLOCK;
}
@@ -408,15 +408,8 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
blk_dev->geometry.bytes_per_sector = 1<<9;
blk_dev->geometry.block_size = card->card_blksize;
if (card->flags & CARD_FLAG_SDHC)
{
blk_dev->geometry.sector_count = (card->csd.c_size + 1) * 1024;
}
else
{
blk_dev->geometry.sector_count =
card->card_capacity * 1024 / 512;
}
blk_dev->geometry.sector_count =
card->card_capacity * (1024 / 512);
rt_device_register(&blk_dev->dev, "sd0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
File diff suppressed because it is too large Load Diff
+37 -16
View File
@@ -25,6 +25,7 @@
#include <rtthread.h>
#include <drivers/mmcsd_core.h>
#include <drivers/sd.h>
#include <drivers/mmc.h>
#ifndef RT_MMCSD_STACK_SIZE
#define RT_MMCSD_STACK_SIZE 1024
@@ -60,22 +61,29 @@ void mmcsd_req_complete(struct rt_mmcsd_host *host)
void mmcsd_send_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
{
req->cmd->err = 0;
req->cmd->mrq = req;
if (req->data)
{
req->cmd->data = req->data;
req->data->err = 0;
req->data->mrq = req;
if (req->stop)
{
req->data->stop = req->stop;
req->stop->err = 0;
req->stop->mrq = req;
}
}
host->ops->request(host, req);
rt_sem_take(&host->sem_ack, RT_WAITING_FOREVER);
do {
req->cmd->retries--;
req->cmd->err = 0;
req->cmd->mrq = req;
if (req->data)
{
req->cmd->data = req->data;
req->data->err = 0;
req->data->mrq = req;
if (req->stop)
{
req->data->stop = req->stop;
req->stop->err = 0;
req->stop->mrq = req;
}
}
host->ops->request(host, req);
rt_sem_take(&host->sem_ack, RT_WAITING_FOREVER);
} while(req->cmd->err && req->cmd->retries);
}
rt_int32_t mmcsd_send_cmd(struct rt_mmcsd_host *host,
@@ -86,6 +94,7 @@ rt_int32_t mmcsd_send_cmd(struct rt_mmcsd_host *host,
rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
rt_memset(cmd->resp, 0, sizeof(cmd->resp));
cmd->retries = retries;
req.cmd = cmd;
cmd->data = RT_NULL;
@@ -626,6 +635,18 @@ void mmcsd_detect(void *param)
mmcsd_host_unlock(host);
continue;
}
/*
* detect mmc card
*/
err = mmc_send_op_cond(host, 0, &ocr);
if (!err)
{
if (init_mmc(host, ocr))
mmcsd_power_off(host);
mmcsd_host_unlock(host);
continue;
}
mmcsd_host_unlock(host);
}
}