SPI口的SD卡
已有 2367 次阅读2010-1-25 16:03
|系统分类:嵌入式系统
手上的板子使用的SPI接口的SD卡,SPI0,片选1。也就是说用的和data flash芯片 at45db161同一路SPI,片选不一样而已。
在驱动里面选择 (*)MMC/SD card support
(*)MMC block device driver
<*> MMC/SD over SPI
然后在文件board-sam9260ek.c里面的ek_spi_devices做如下改动
static struct spi_board_info ek_spi_devices[] = {
#if !defined(CONFIG_MMC_AT91)
{ // DataFlash chip
.modalias = "mtd_dataflash",
// .chip_select = 1,
.chip_select = 0, //zhh
.max_speed_hz = 15 * 1000 * 1000,
.bus_num = 0,
},
#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
{ // DataFlash card
.modalias = "mtd_dataflash",
.chip_select = 0,
.max_speed_hz = 15 * 1000 * 1000,
.bus_num = 0,
},
#endif
#endif
#if defined(CONFIG_MMC_SPI)
{ /* DataFlash card */
.modalias = "mmc_spi",
.chip_select = 1,
.max_speed_hz = 15 * 1000 * 1000,
.bus_num = 0,
},
#endif
#if defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
{ /* AT73C213 DAC */
.modalias = "at73c213",
.chip_select = 0,
.max_speed_hz = 10 * 1000 * 1000,
.bus_num = 1,
.mode = SPI_MODE_1,
.platform_data = &at73c213_data,
},
#endif
};
也就是增加了mmc_spi的初始化部分。
编译完毕,
启动系统,
提示
can't share SPI bus
为了简单,我直接把SPI其他部分屏蔽掉了,重新编译,启动,提示如下:
mmc0: error -84 whilst initialising SD card
一路跟踪
mmc_sd_init_card() ----->mmc_send_cid()----->mmc_send_cxd_data()----->
static int
mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
u32 opcode, void *buf, unsigned len)
{
struct mmc_request mrq;
struct mmc_command cmd;
struct mmc_data data;
struct scatterlist sg;
void *data_buf;
/* dma onto stack is unsafe/nonportable, but callers to this
* routine normally provide temporary on-stack buffers ...
*/
data_buf = kmalloc(len, GFP_KERNEL);
if (data_buf == NULL)
return -ENOMEM;
memset(&mrq, 0, sizeof(struct mmc_request));
memset(&cmd, 0, sizeof(struct mmc_command));
memset(&data, 0, sizeof(struct mmc_data));
mrq.cmd = &cmd;
mrq.data = &data;
cmd.opcode = opcode;
cmd.arg = 0;
/* NOTE HACK: the MMC_RSP_SPI_R1 is always correct here, but we
* rely on callers to never use this with "native" calls for reading
* CSD or CID. Native versions of those commands use the R2 type,
* not R1 plus a data block.
*/
cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
data.blksz = len;
data.blocks = 1;
data.flags = MMC_DATA_READ;
data.sg = &sg;
data.sg_len = 1;
sg_init_one(&sg, data_buf, len);
if (card)
mmc_set_data_timeout(&data, card);
mmc_wait_for_req(host, &mrq);
memcpy(buf, data_buf, len);
kfree(data_buf);
if (cmd.error)
{
return cmd.error;
}
if (data.error)
{
printk("hello mmc_send_cxd_data data.error is %d\n",data.error);
return data.error;
}
return 0;
}
就是上面的 (data.error),从这里跳出去的。
我估计我得把SD卡协议看看才能解决这个问题