Merge pull request #758 from JianRuiqian/master

[DeviceDrivers] improve sdio
This commit is contained in:
Bernard Xiong 2017-07-04 07:19:44 +08:00 committed by GitHub
commit e47515d876
5 changed files with 35 additions and 13 deletions

View File

@ -135,6 +135,8 @@ struct rt_sdio_function {
rt_uint32_t enable_timeout_val; /* max enable timeout in msec */
struct rt_sdio_function_tuple *tuples;
void *priv;
};
#define SDIO_MAX_FUNCTIONS 7

View File

@ -111,7 +111,7 @@ struct rt_mmcsd_host {
rt_uint32_t max_blk_count; /* maximum block count */
rt_uint32_t spi_use_crc;
struct rt_semaphore bus_lock;
struct rt_mutex bus_lock;
struct rt_semaphore sem_ack;
rt_uint32_t sdio_irq_num;

View File

@ -229,6 +229,8 @@ rt_int32_t sdio_detach_irq(struct rt_sdio_function *func);
void sdio_irq_wakeup(struct rt_mmcsd_host *host);
rt_int32_t sdio_enable_func(struct rt_sdio_function *func);
rt_int32_t sdio_disable_func(struct rt_sdio_function *func);
void sdio_set_drvdata(struct rt_sdio_function *func, void *data);
void* sdio_get_drvdata(struct rt_sdio_function *func);
rt_int32_t sdio_set_block_size(struct rt_sdio_function *func,
rt_uint32_t blksize);
rt_int32_t sdio_register_driver(struct rt_sdio_driver *driver);

View File

@ -49,12 +49,12 @@ static rt_uint32_t mmcsd_hotpluge_mb_pool[4];
void mmcsd_host_lock(struct rt_mmcsd_host *host)
{
rt_sem_take(&host->bus_lock, RT_WAITING_FOREVER);
rt_mutex_take(&host->bus_lock, RT_WAITING_FOREVER);
}
void mmcsd_host_unlock(struct rt_mmcsd_host *host)
{
rt_sem_release(&host->bus_lock);
rt_mutex_release(&host->bus_lock);
}
void mmcsd_req_complete(struct rt_mmcsd_host *host)
@ -713,7 +713,7 @@ struct rt_mmcsd_host *mmcsd_alloc_host(void)
host->max_blk_size = 512;
host->max_blk_count = 4096;
rt_sem_init(&host->bus_lock, "sd_bus_lock", 1, RT_IPC_FLAG_FIFO);
rt_mutex_init(&host->bus_lock, "sd_bus_lock", RT_IPC_FLAG_FIFO);
rt_sem_init(&host->sem_ack, "sd_ack", 0, RT_IPC_FLAG_FIFO);
return host;
@ -721,7 +721,7 @@ struct rt_mmcsd_host *mmcsd_alloc_host(void)
void mmcsd_free_host(struct rt_mmcsd_host *host)
{
rt_sem_detach(&host->bus_lock);
rt_mutex_detach(&host->bus_lock);
rt_sem_detach(&host->sem_ack);
rt_free(host);
}

View File

@ -29,8 +29,8 @@
#ifndef RT_SDIO_STACK_SIZE
#define RT_SDIO_STACK_SIZE 512
#endif
#ifndef RT_SDIO_THREAD_PREORITY
#define RT_SDIO_THREAD_PREORITY 0x40
#ifndef RT_SDIO_THREAD_PRIORITY
#define RT_SDIO_THREAD_PRIORITY 0x40
#endif
static rt_list_t sdio_cards;
@ -1059,7 +1059,7 @@ static rt_int32_t sdio_irq_thread_create(struct rt_mmcsd_card *card)
RT_ASSERT(host->sdio_irq_sem != RT_NULL);
host->sdio_irq_thread = rt_thread_create("sdio_irq", sdio_irq_thread, host,
RT_SDIO_STACK_SIZE, RT_SDIO_THREAD_PREORITY, 20);
RT_SDIO_STACK_SIZE, RT_SDIO_THREAD_PRIORITY, 20);
if (host->sdio_irq_thread != RT_NULL)
{
rt_thread_startup(host->sdio_irq_thread);
@ -1079,7 +1079,7 @@ static rt_int32_t sdio_irq_thread_delete(struct rt_mmcsd_card *card)
if (!host->sdio_irq_num)
{
if (host->flags & MMCSD_SUP_SDIO_IRQ)
host->ops->enable_sdio_irq(host, 0);
host->ops->enable_sdio_irq(host, 0);
rt_sem_delete(host->sdio_irq_sem);
host->sdio_irq_sem = RT_NULL;
rt_thread_delete(host->sdio_irq_thread);
@ -1253,6 +1253,16 @@ err:
return -RT_EIO;
}
void sdio_set_drvdata(struct rt_sdio_function *func, void *data)
{
func->priv = data;
}
void* sdio_get_drvdata(struct rt_sdio_function *func)
{
return func->priv;
}
rt_int32_t sdio_set_block_size(struct rt_sdio_function *func,
rt_uint32_t blksize)
{
@ -1284,16 +1294,24 @@ rt_int32_t sdio_set_block_size(struct rt_sdio_function *func,
rt_inline rt_int32_t sdio_match_card(struct rt_mmcsd_card *card,
const struct rt_sdio_device_id *id)
{
rt_uint8_t num = 1;
if ((id->manufacturer != SDIO_ANY_MAN_ID) &&
(id->manufacturer != card->cis.manufacturer))
return 0;
if ((id->product != SDIO_ANY_PROD_ID) &&
(id->product != (card->cis.product | 1)))
return 0;
return 1;
while (num <= card->sdio_function_num)
{
if ((id->product != SDIO_ANY_PROD_ID) &&
(id->product == card->sdio_function[num]->product))
return 1;
num++;
}
return 0;
}
static struct rt_mmcsd_card *sdio_match_driver(struct rt_sdio_device_id *id)
{
rt_list_t *l;