tiger84的笔记 https://passport2.21ic.com/?476150 [收藏] [复制] [RSS]

日志

linux下的SPI口SD卡复用问题

已有 1955 次阅读2010-1-25 16:05 |系统分类:嵌入式系统

接下来打算解决data flash与SD卡共享SPI的问题


理论上来说,data flash与SD卡共用一组SPI,CS不同应该是可以的,但是看了下SPI sd卡的源码,如下:
/* We can use the bus safely iff nobody else will interfere with us.
         * Most commands consist of one SPI message to issue a command, then
         * several more to collect its response, then possibly more for data
         * transfer.  Clocking access to other devices during that period will
         * corrupt the command execution.
         *
         * Until we have software primitives which guarantee non-interference,
         * we'll aim for a hardware-level guarantee.
         *
         * REVISIT we can't guarantee another device won't be added later...
         */
        if (spi->master->num_chipselect > 1) {
                struct count_children cc;

                cc.n = 0;               
                cc.bus = spi->dev.bus;
                status = device_for_each_child(spi->dev.parent, &cc,
                                maybe_count_child);
                if (status < 0) {
                        dev_err(&spi->dev, "can't share SPI bus\n");
                        return status;
                }

                dev_warn(&spi->dev, "ASSUMING SPI bus stays unshared!\n");
        }
觉得共享似乎不太可能了,用过的兄弟指点下吧。


这段代码果然有些问题,如下
Subject: [PATCH 2/2] mmc_spi: lock the SPI bus when accessing the card - msg#06885
List: linux-kernel
Date: Prev Next Index Thread: Prev Next Index
From: Yi Li <yi.li@xxxxxxxxxx>

The MMC/SPI spec does not play well with typical SPI design -- it often
needs to send out a command in one message, read a response, then do some
other arbitrary step. Since we can't let another SPI client use the bus
during this time, use the new SPI lock/unlock s to provide the
required exclusivity.

Signed-off-by: Yi Li <yi.li@xxxxxxxxxx>
Signed-off-by: Mike Frysinger <vapier@xxxxxxxxxx>
---
drivers/mmc/host/mmc_spi.c | 29 ++---------------------------
1 files changed, 2 insertions(+), 27 deletions(-)

diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index a461017..a96e058 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1084,6 +1084,7 @@ static void mmc_spi_request(struct mmc_host *mmc, struct
mmc_request *mrq)
#endif

/* issue command; then optionally data and stop */
+ spi_lock_bus(host->spi);
status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL);
if (status == 0 && mrq->data) {
mmc_spi_data_do(host, mrq->cmd, mrq->data, mrq->data->blksz);
@@ -1092,7 +1093,7 @@ static void mmc_spi_request(struct mmc_host *mmc, struct
mmc_request *mrq)
else
mmc_cs_off(host);
}
-
+ spi_unlock_bus(host->spi);
mmc_request_done(host->mmc, mrq);
}

@@ -1337,32 +1338,6 @@ static int mmc_spi_probe(struct spi_device *spi)
return status;
}

- /* We can use the bus safely iff nobody else will interfere with us.
- * Most commands consist of one SPI message to issue a command, then
- * several more to collect its response, then possibly more for data
- * transfer. Clocking access to other devices during that period will
- * corrupt the command execution.
- *
- * Until we have software primitives which guarantee non-interference,
- * we'll aim for a hardware-level guarantee.
- *
- * REVISIT we can't guarantee another device won't be added later...
- */
- if (spi->master->num_chipselect > 1) {
- struct count_children cc;
-
- cc.n = 0;
- cc.bus = spi->dev.bus;
- status = device_for_each_child(spi->dev.parent, &cc,
- maybe_count_child);
- if (status < 0) {
- dev_err(&spi->dev, "can't share SPI bus\n");
- return status;
- }
-
- dev_warn(&spi->dev, "ASSUMING SPI bus stays unshared!\n");
- }
-
/* We need a supply of ones to transmit. This is the only time
* the CPU touches these, so cache coherency isn't a concern.
*
--
1.6.5.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)