Merge pull request #1774 from EvalZero/sdio_dev

[DeviceDriver][SDIO] Update sdio debug log.
This commit is contained in:
Bernard Xiong 2018-09-11 19:03:10 +08:00 committed by GitHub
commit 8c2448a4d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 101 additions and 48 deletions

View File

@ -138,6 +138,10 @@ config RT_USING_SDIO
config RT_MMCSD_MAX_PARTITION
int "mmcsd max partition"
default 16
config RT_SDIO_DEBUG
bool "Enable SDIO debug log output"
default n
endif
config RT_USING_SPI

View File

@ -27,6 +27,16 @@
#include <drivers/mmcsd_core.h>
#define DBG_ENABLE
#define DBG_SECTION_NAME "[SDIO]"
#ifdef RT_SDIO_DEBUG
#define DBG_LEVEL DBG_LOG
#else
#define DBG_LEVEL DBG_INFO
#endif /* RT_SDIO_DEBUG */
#define DBG_COLOR
#include <rtdbg.h>
static rt_list_t blk_devices = RT_LIST_OBJECT_INIT(blk_devices);
#define BLK_MIN(a, b) ((a) < (b) ? (a) : (b))
@ -182,7 +192,7 @@ static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card,
err = mmcsd_send_cmd(card->host, &cmd, 5);
if (err)
{
rt_kprintf("error %d requesting status\n", err);
LOG_E("error %d requesting status", err);
break;
}
/*
@ -198,8 +208,8 @@ static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card,
if (cmd.err || data.err || stop.err)
{
rt_kprintf("mmcsd request blocks error\n");
rt_kprintf("%d,%d,%d, 0x%08x,0x%08x\n",
LOG_E("mmcsd request blocks error");
LOG_E("%d,%d,%d, 0x%08x,0x%08x",
cmd.err, data.err, stop.err, data.flags, sector);
return -RT_ERROR;
@ -338,7 +348,7 @@ static rt_int32_t mmcsd_set_blksize(struct rt_mmcsd_card *card)
if (err)
{
rt_kprintf("MMCSD: unable to set block size to %d: %d\n", cmd.arg, err);
LOG_E("MMCSD: unable to set block size to %d: %d", cmd.arg, err);
return -RT_ERROR;
}
@ -373,13 +383,13 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
return err;
}
rt_kprintf("probe mmcsd block device!\n");
LOG_I("probe mmcsd block device!");
/* get the first sector to read partition table */
sector = (rt_uint8_t *)rt_malloc(SECTOR_SIZE);
if (sector == RT_NULL)
{
rt_kprintf("allocate partition sector buffer failed\n");
LOG_E("allocate partition sector buffer failed!");
return -RT_ENOMEM;
}
@ -392,7 +402,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device));
if (!blk_dev)
{
rt_kprintf("mmcsd:malloc memory failed!\n");
LOG_E("mmcsd:malloc memory failed!");
break;
}
@ -480,7 +490,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
#ifdef RT_USING_DFS_MNTTABLE
if (0) // if (blk_dev)
{
rt_kprintf("try to mount file system!\n");
LOG_I("try to mount file system!");
/* try to mount file system on this block device */
dfs_mount_device(&(blk_dev->dev));
}
@ -489,7 +499,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
}
else
{
rt_kprintf("read mmcsd first sector failed\n");
LOG_E("read mmcsd first sector failed");
err = -RT_ERROR;
}

View File

@ -25,6 +25,16 @@
#include <drivers/mmcsd_core.h>
#include <drivers/mmc.h>
#define DBG_ENABLE
#define DBG_SECTION_NAME "[SDIO]"
#ifdef RT_SDIO_DEBUG
#define DBG_LEVEL DBG_LOG
#else
#define DBG_LEVEL DBG_INFO
#endif /* RT_SDIO_DEBUG */
#define DBG_COLOR
#include <rtdbg.h>
static const rt_uint32_t tran_unit[] =
{
10000, 100000, 1000000, 10000000,
@ -81,7 +91,7 @@ static rt_int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card)
*/
csd->csd_structure = GET_BITS(resp, 126, 2);
if (csd->csd_structure == 0) {
rt_kprintf("unrecognised CSD structure version %d\n", csd->csd_structure);
LOG_E("unrecognised CSD structure version %d!", csd->csd_structure);
return -RT_ERROR;
}
@ -137,7 +147,7 @@ static int mmc_get_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t **new_ext_csd)
*/
ext_csd = rt_malloc(512);
if (!ext_csd) {
rt_kprintf("alloc memory failed when get ext csd\n");
LOG_E("alloc memory failed when get ext csd!");
return -RT_ENOMEM;
}
@ -194,7 +204,7 @@ static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
card->card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]);
card->card_capacity *= card->card_blksize;
card->card_capacity >>= 10; /* unit:KB */
rt_kprintf("emmc card capacity %d KB\n", card->card_capacity);
LOG_I("emmc card capacity %d KB.", card->card_capacity);
return 0;
}
@ -333,13 +343,13 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
} else {
switch(ext_csd_bits[idx]){
case 0:
rt_kprintf("switch to bus width 1 bit failed\n");
LOG_E("switch to bus width 1 bit failed!");
break;
case 1:
rt_kprintf("switch to bus width 4 bit failed\n");
LOG_E("switch to bus width 4 bit failed!");
break;
case 2:
rt_kprintf("switch to bus width 8 bit failed\n");
LOG_E("switch to bus width 8 bit failed!");
break;
default:
break;
@ -443,7 +453,7 @@ static rt_int32_t mmcsd_mmc_init_card(struct rt_mmcsd_host *host,
card = rt_malloc(sizeof(struct rt_mmcsd_card));
if (!card)
{
rt_kprintf("malloc card failed\n");
LOG_E("malloc card failed!");
err = -RT_ENOMEM;
goto err;
}
@ -580,7 +590,7 @@ remove_card:
host->card = RT_NULL;
err:
rt_kprintf("init MMC card failed\n");
LOG_E("init MMC card failed!");
return err;
}

View File

@ -28,6 +28,16 @@
#include <drivers/mmc.h>
#include <drivers/sdio.h>
#define DBG_ENABLE
#define DBG_SECTION_NAME "[SDIO]"
#ifdef RT_SDIO_DEBUG
#define DBG_LEVEL DBG_LOG
#else
#define DBG_LEVEL DBG_INFO
#endif /* RT_SDIO_DEBUG */
#define DBG_COLOR
#include <rtdbg.h>
#ifndef RT_MMCSD_STACK_SIZE
#define RT_MMCSD_STACK_SIZE 1024
#endif
@ -206,7 +216,7 @@ rt_int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid)
buf = (rt_uint32_t *)rt_malloc(16);
if (!buf)
{
rt_kprintf("allocate memory failed\n");
LOG_E("allocate memory failed!");
return -RT_ENOMEM;
}
@ -282,7 +292,7 @@ rt_int32_t mmcsd_get_csd(struct rt_mmcsd_card *card, rt_uint32_t *csd)
buf = (rt_uint32_t*)rt_malloc(16);
if (!buf)
{
rt_kprintf("allocate memory failed\n");
LOG_E("allocate memory failed!");
return -RT_ENOMEM;
}
@ -418,7 +428,7 @@ void mmcsd_set_clock(struct rt_mmcsd_host *host, rt_uint32_t clk)
{
if (clk < host->freq_min)
{
rt_kprintf("clock too low\n");
LOG_W("clock too low!");
}
host->io_cfg.clock = clk;
@ -539,7 +549,7 @@ rt_uint32_t mmcsd_select_voltage(struct rt_mmcsd_host *host, rt_uint32_t ocr)
}
else
{
rt_kprintf("host doesn't support card's voltages\n");
LOG_W("host doesn't support card's voltages!");
ocr = 0;
}
@ -679,7 +689,7 @@ void mmcsd_detect(void *param)
mmcsd_host_lock(host);
if (host->card->sdio_function_num != 0)
{
rt_kprintf("unsupport sdio card plug out!\n");
LOG_W("unsupport sdio card plug out!");
}
else
{
@ -702,7 +712,7 @@ struct rt_mmcsd_host *mmcsd_alloc_host(void)
host = rt_malloc(sizeof(struct rt_mmcsd_host));
if (!host)
{
rt_kprintf("alloc host failed\n");
LOG_E("alloc host failed");
return RT_NULL;
}

View File

@ -25,6 +25,16 @@
#include <drivers/mmcsd_core.h>
#include <drivers/sd.h>
#define DBG_ENABLE
#define DBG_SECTION_NAME "[SDIO]"
#ifdef RT_SDIO_DEBUG
#define DBG_LEVEL DBG_LOG
#else
#define DBG_LEVEL DBG_INFO
#endif /* RT_SDIO_DEBUG */
#define DBG_COLOR
#include <rtdbg.h>
static const rt_uint32_t tran_unit[] =
{
10000, 100000, 1000000, 10000000,
@ -167,11 +177,11 @@ static rt_int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card)
#endif
break;
default:
rt_kprintf("unrecognised CSD structure version %d\n", csd->csd_structure);
LOG_E("unrecognised CSD structure version %d!", csd->csd_structure);
return -RT_ERROR;
}
rt_kprintf("SD card capacity %d KB\n", card->card_capacity);
LOG_I("SD card capacity %d KB.", card->card_capacity);
return 0;
}
@ -201,7 +211,7 @@ static rt_int32_t mmcsd_switch(struct rt_mmcsd_card *card)
buf = (rt_uint8_t*)rt_malloc(64);
if (!buf)
{
rt_kprintf("alloc memory failed\n");
LOG_E("alloc memory failed!");
return -RT_ENOMEM;
}
@ -270,7 +280,7 @@ static rt_int32_t mmcsd_switch(struct rt_mmcsd_card *card)
if ((buf[16] & 0xF) != 1)
{
rt_kprintf("switching card to high speed failed\n");
LOG_E("switching card to high speed failed!");
goto err;
}
@ -588,7 +598,7 @@ static rt_int32_t mmcsd_sd_init_card(struct rt_mmcsd_host *host,
card = rt_malloc(sizeof(struct rt_mmcsd_card));
if (!card)
{
rt_kprintf("malloc card failed\n");
LOG_E("malloc card failed!");
err = -RT_ENOMEM;
goto err;
}
@ -703,9 +713,9 @@ rt_int32_t init_sd(struct rt_mmcsd_host *host, rt_uint32_t ocr)
if (ocr & VDD_165_195)
{
rt_kprintf(" SD card claims to support the "
LOG_I(" SD card claims to support the "
"incompletely defined 'low voltage range'. This "
"will be ignored.\n");
"will be ignored.");
ocr &= ~VDD_165_195;
}
@ -743,7 +753,7 @@ remove_card:
host->card = RT_NULL;
err:
rt_kprintf("init SD card failed\n");
LOG_D("init SD card failed!");
return err;
}

View File

@ -26,6 +26,16 @@
#include <drivers/sdio.h>
#include <drivers/sd.h>
#define DBG_ENABLE
#define DBG_SECTION_NAME "[SDIO]"
#ifdef RT_SDIO_DEBUG
#define DBG_LEVEL DBG_LOG
#else
#define DBG_LEVEL DBG_INFO
#endif /* RT_SDIO_DEBUG */
#define DBG_COLOR
#include <rtdbg.h>
#ifndef RT_SDIO_STACK_SIZE
#define RT_SDIO_STACK_SIZE 512
#endif
@ -432,7 +442,7 @@ static rt_int32_t sdio_read_cccr(struct rt_mmcsd_card *card)
if (cccr_version > SDIO_CCCR_REV_3_00)
{
rt_kprintf("unrecognised CCCR structure version %d\n", cccr_version);
LOG_E("unrecognised CCCR structure version %d", cccr_version);
return -RT_ERROR;
}
@ -579,7 +589,7 @@ static rt_int32_t sdio_read_cis(struct rt_sdio_function *func)
case CISTPL_MANFID:
if (tpl_link < 4)
{
rt_kprintf("bad CISTPL_MANFID length\n");
LOG_D("bad CISTPL_MANFID length");
break;
}
if (func->num != 0)
@ -605,15 +615,15 @@ static rt_int32_t sdio_read_cis(struct rt_sdio_function *func)
if (ret)
{
rt_kprintf("bad CISTPL_FUNCE size %u "
"type %u\n", tpl_link, curr->data[0]);
LOG_D("bad CISTPL_FUNCE size %u "
"type %u", tpl_link, curr->data[0]);
}
break;
case CISTPL_VERS_1:
if (tpl_link < 2)
{
rt_kprintf("CISTPL_VERS_1 too short\n");
LOG_D("CISTPL_VERS_1 too short");
}
break;
default:
@ -623,7 +633,7 @@ static rt_int32_t sdio_read_cis(struct rt_sdio_function *func)
curr->size = tpl_link;
*prev = curr;
prev = &curr->next;
rt_kprintf( "function %d, CIS tuple code %#x, length %d\n",
LOG_D( "function %d, CIS tuple code %#x, length %d",
func->num, tpl_code, tpl_link);
break;
}
@ -686,7 +696,6 @@ err:
return ret;
}
static rt_int32_t sdio_initialize_function(struct rt_mmcsd_card *card,
rt_uint32_t func_num)
{
@ -698,7 +707,7 @@ static rt_int32_t sdio_initialize_function(struct rt_mmcsd_card *card,
func = rt_malloc(sizeof(struct rt_sdio_function));
if (!func)
{
rt_kprintf("malloc rt_sdio_function failed\n");
LOG_E("malloc rt_sdio_function failed");
ret = -RT_ENOMEM;
goto err;
}
@ -788,7 +797,7 @@ static rt_int32_t sdio_register_card(struct rt_mmcsd_card *card)
sc = rt_malloc(sizeof(struct sdio_card));
if (sc == RT_NULL)
{
rt_kprintf("malloc sdio card failed\n");
LOG_E("malloc sdio card failed");
return -RT_ENOMEM;
}
@ -836,7 +845,7 @@ static rt_int32_t sdio_init_card(struct rt_mmcsd_host *host, rt_uint32_t ocr)
card = rt_malloc(sizeof(struct rt_mmcsd_card));
if (!card)
{
rt_kprintf("malloc card failed\n");
LOG_E("malloc card failed");
err = -RT_ENOMEM;
goto err;
}
@ -850,7 +859,7 @@ static rt_int32_t sdio_init_card(struct rt_mmcsd_host *host, rt_uint32_t ocr)
card->sdio_function[0] = rt_malloc(sizeof(struct rt_sdio_function));
if (!card->sdio_function[0])
{
rt_kprintf("malloc sdio_func0 failed\n");
LOG_E("malloc sdio_func0 failed");
err = -RT_ENOMEM;
goto err1;
}
@ -944,7 +953,7 @@ err1:
rt_free(host->card);
}
err:
rt_kprintf("error %d while initialising SDIO card\n", err);
LOG_E("error %d while initialising SDIO card", err);
return err;
}
@ -958,13 +967,13 @@ rt_int32_t init_sdio(struct rt_mmcsd_host *host, rt_uint32_t ocr)
if (ocr & 0x7F)
{
rt_kprintf("Card ocr below the defined voltage rang.\n");
LOG_W("Card ocr below the defined voltage rang.");
ocr &= ~0x7F;
}
if (ocr & VDD_165_195)
{
rt_kprintf("Can't support the low voltage SDIO card.\n");
LOG_W("Can't support the low voltage SDIO card.");
ocr &= ~VDD_165_195;
}
@ -987,7 +996,7 @@ remove_card:
host->card = RT_NULL;
err:
rt_kprintf("init SDIO card failed\n");
LOG_E("init SDIO card failed");
return err;
}
@ -1341,7 +1350,7 @@ rt_int32_t sdio_register_driver(struct rt_sdio_driver *driver)
sd = rt_malloc(sizeof(struct sdio_driver));
if (sd == RT_NULL)
{
rt_kprintf("malloc sdio driver failed\n");
LOG_E("malloc sdio driver failed");
return -RT_ENOMEM;
}
@ -1378,7 +1387,7 @@ rt_int32_t sdio_unregister_driver(struct rt_sdio_driver *driver)
if (sd == RT_NULL)
{
rt_kprintf("SDIO driver %s not register\n", driver->name);
LOG_E("SDIO driver %s not register", driver->name);
return -RT_ERROR;
}