mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/3] mci: add max_req_size support
Date: Tue, 22 Oct 2013 16:35:23 +0200	[thread overview]
Message-ID: <1382452525-26955-1-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20131022143339.GC26639@ns203013.ovh.net>

Some controller such as the ARM AMBA pl181 can not handle more than 16bits
data length request.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/mci/mci-core.c | 38 ++++++++++++++++++++++++++++++--------
 include/mci.h          |  1 +
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 66ddb5b..cfae91b 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1199,6 +1199,11 @@ static int __maybe_unused mci_sd_write(struct block_device *blk,
 	struct mci *mci = part->mci;
 	struct mci_host *host = mci->host;
 	int rc;
+	unsigned max_req_block = num_blocks;
+	int write_block;
+
+	if (mci->host->max_req_size)
+		max_req_block = mci->host->max_req_size / mci->write_bl_len;
 
 	mci_blk_part_switch(part);
 
@@ -1222,10 +1227,16 @@ static int __maybe_unused mci_sd_write(struct block_device *blk,
 		return -EINVAL;
 	}
 
-	rc = mci_block_write(mci, buffer, block, num_blocks);
-	if (rc != 0) {
-		dev_dbg(&mci->dev, "Writing block %d failed with %d\n", block, rc);
-		return rc;
+	while (num_blocks) {
+		write_block = min_t(int, num_blocks, max_req_block);
+		rc = mci_block_write(mci, buffer, block, write_block);
+		if (rc != 0) {
+			dev_dbg(&mci->dev, "Writing block %d failed with %d\n", block, rc);
+			return rc;
+		}
+		num_blocks -= write_block;
+		block += write_block;
+		buffer += write_block * mci->write_bl_len;
 	}
 
 	return 0;
@@ -1246,8 +1257,13 @@ static int mci_sd_read(struct block_device *blk, void *buffer, int block,
 {
 	struct mci_part *part = container_of(blk, struct mci_part, blk);
 	struct mci *mci = part->mci;
+	unsigned max_req_block = num_blocks;
+	int read_block;
 	int rc;
 
+	if (mci->host->max_req_size)
+		max_req_block = mci->host->max_req_size / mci->read_bl_len;
+
 	mci_blk_part_switch(part);
 
 	dev_dbg(&mci->dev, "%s: Read %d block(s), starting at %d\n",
@@ -1264,10 +1280,16 @@ static int mci_sd_read(struct block_device *blk, void *buffer, int block,
 		return -EINVAL;
 	}
 
-	rc = mci_read_block(mci, buffer, block, num_blocks);
-	if (rc != 0) {
-		dev_dbg(&mci->dev, "Reading block %d failed with %d\n", block, rc);
-		return rc;
+	while (num_blocks) {
+		read_block = min_t(int, num_blocks, max_req_block);
+		rc = mci_read_block(mci, buffer, block, read_block);
+		if (rc != 0) {
+			dev_dbg(&mci->dev, "Reading block %d failed with %d\n", block, rc);
+			return rc;
+		}
+		num_blocks -= read_block;
+		block += read_block;
+		buffer += read_block * mci->read_bl_len;
 	}
 
 	return 0;
diff --git a/include/mci.h b/include/mci.h
index 1ca00c7..07ac273 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -293,6 +293,7 @@ struct mci_host {
 	unsigned f_max;		/**< host interface upper limit */
 	unsigned clock;		/**< Current clock used to talk to the card */
 	unsigned bus_width;	/**< used data bus width to the card */
+	unsigned max_req_size;
 
 	/** init the host interface */
 	int (*init)(struct mci_host*, struct device_d*);
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2013-10-22 14:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-22 14:33 [PATCH 0/3 V2] add ARM MMCI support Jean-Christophe PLAGNIOL-VILLARD
2013-10-22 14:35 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-10-22 14:35   ` [PATCH 2/3] add: mmci drivers Jean-Christophe PLAGNIOL-VILLARD
2013-10-22 14:35   ` [PATCH 3/3] vexpress: mmc support Jean-Christophe PLAGNIOL-VILLARD
2013-10-22 14:52 ` [PATCH 0/3 V2] add ARM MMCI support Sascha Hauer
  -- strict thread matches above, loose matches on Subject: below --
2013-10-19  9:24 [PATCH 0/3] " Jean-Christophe PLAGNIOL-VILLARD
2013-10-19  9:25 ` [PATCH 1/3] mci: add max_req_size support Jean-Christophe PLAGNIOL-VILLARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1382452525-26955-1-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox