public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V3 3/5] mmc: uniphier-sd: Add support for 64bit FIFO
Date: Sun, 20 Aug 2017 17:11:17 +0200	[thread overview]
Message-ID: <20170820151119.2303-3-marek.vasut+renesas@gmail.com> (raw)
In-Reply-To: <20170820151119.2303-1-marek.vasut+renesas@gmail.com>

The Renesas RCar Gen3 contains the same controller, originally
Matsushita. This patch adds support for handling of the 64bit
FIFO on this controller.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
---
V2: - Use unsigned int for the reg argument of IO accessors
    - Rework the handling of aligned and unaligned data
V3: Remove const ...
---
 drivers/mmc/uniphier-sd.c | 101 +++++++++++++++++++++++++++++++++++++---------
 1 file changed, 83 insertions(+), 18 deletions(-)

diff --git a/drivers/mmc/uniphier-sd.c b/drivers/mmc/uniphier-sd.c
index bb9b2c4e04..0b594a0c90 100644
--- a/drivers/mmc/uniphier-sd.c
+++ b/drivers/mmc/uniphier-sd.c
@@ -135,6 +135,23 @@ struct uniphier_sd_priv {
 #define UNIPHIER_SD_CAP_64BIT		BIT(3)	/* Controller is 64bit */
 };
 
+static u64 uniphier_sd_readq(struct uniphier_sd_priv *priv, unsigned int reg)
+{
+	if (priv->caps & UNIPHIER_SD_CAP_64BIT)
+		return readq(priv->regbase + (reg << 1));
+	else
+		return readq(priv->regbase + reg);
+}
+
+static void uniphier_sd_writeq(struct uniphier_sd_priv *priv,
+			       u64 val, unsigned int reg)
+{
+	if (priv->caps & UNIPHIER_SD_CAP_64BIT)
+		writeq(val, priv->regbase + (reg << 1));
+	else
+		writeq(val, priv->regbase + reg);
+}
+
 static u32 uniphier_sd_readl(struct uniphier_sd_priv *priv, unsigned int reg)
 {
 	if (priv->caps & UNIPHIER_SD_CAP_64BIT)
@@ -229,7 +246,7 @@ static int uniphier_sd_wait_for_irq(struct udevice *dev, unsigned int reg,
 	return 0;
 }
 
-static int uniphier_sd_pio_read_one_block(struct udevice *dev, u32 **pbuf,
+static int uniphier_sd_pio_read_one_block(struct udevice *dev, char *pbuf,
 					  uint blocksize)
 {
 	struct uniphier_sd_priv *priv = dev_get_priv(dev);
@@ -247,20 +264,42 @@ static int uniphier_sd_pio_read_one_block(struct udevice *dev, u32 **pbuf,
 	 */
 	uniphier_sd_writel(priv, 0, UNIPHIER_SD_INFO2);
 
-	if (likely(IS_ALIGNED((unsigned long)*pbuf, 4))) {
-		for (i = 0; i < blocksize / 4; i++)
-			*(*pbuf)++ = uniphier_sd_readl(priv, UNIPHIER_SD_BUF);
+	if (priv->caps & UNIPHIER_SD_CAP_64BIT) {
+		u64 *buf = (u64 *)pbuf;
+		if (likely(IS_ALIGNED((uintptr_t)buf, 8))) {
+			for (i = 0; i < blocksize / 8; i++) {
+				*buf++ = uniphier_sd_readq(priv,
+							   UNIPHIER_SD_BUF);
+			}
+		} else {
+			for (i = 0; i < blocksize / 8; i++) {
+				u64 data;
+				data = uniphier_sd_readq(priv,
+							 UNIPHIER_SD_BUF);
+				put_unaligned(data, buf++);
+			}
+		}
 	} else {
-		for (i = 0; i < blocksize / 4; i++)
-			put_unaligned(uniphier_sd_readl(priv, UNIPHIER_SD_BUF),
-				      (*pbuf)++);
+		u32 *buf = (u32 *)pbuf;
+		if (likely(IS_ALIGNED((uintptr_t)buf, 4))) {
+			for (i = 0; i < blocksize / 4; i++) {
+				*buf++ = uniphier_sd_readl(priv,
+							   UNIPHIER_SD_BUF);
+			}
+		} else {
+			for (i = 0; i < blocksize / 4; i++) {
+				u32 data;
+				data = uniphier_sd_readl(priv, UNIPHIER_SD_BUF);
+				put_unaligned(data, buf++);
+			}
+		}
 	}
 
 	return 0;
 }
 
 static int uniphier_sd_pio_write_one_block(struct udevice *dev,
-					   const u32 **pbuf, uint blocksize)
+					   const char *pbuf, uint blocksize)
 {
 	struct uniphier_sd_priv *priv = dev_get_priv(dev);
 	int i, ret;
@@ -273,13 +312,34 @@ static int uniphier_sd_pio_write_one_block(struct udevice *dev,
 
 	uniphier_sd_writel(priv, 0, UNIPHIER_SD_INFO2);
 
-	if (likely(IS_ALIGNED((unsigned long)*pbuf, 4))) {
-		for (i = 0; i < blocksize / 4; i++)
-			uniphier_sd_writel(priv, *(*pbuf)++, UNIPHIER_SD_BUF);
+	if (priv->caps & UNIPHIER_SD_CAP_64BIT) {
+		const u64 *buf = (const u64 *)pbuf;
+		if (likely(IS_ALIGNED((uintptr_t)buf, 8))) {
+			for (i = 0; i < blocksize / 8; i++) {
+				uniphier_sd_writeq(priv, *buf++,
+						   UNIPHIER_SD_BUF);
+			}
+		} else {
+			for (i = 0; i < blocksize / 8; i++) {
+				u64 data = get_unaligned(buf++);
+				uniphier_sd_writeq(priv, data,
+						   UNIPHIER_SD_BUF);
+			}
+		}
 	} else {
-		for (i = 0; i < blocksize / 4; i++)
-			uniphier_sd_writel(priv, get_unaligned((*pbuf)++),
-					   UNIPHIER_SD_BUF);
+		const u32 *buf = (const u32 *)pbuf;
+		if (likely(IS_ALIGNED((uintptr_t)buf, 4))) {
+			for (i = 0; i < blocksize / 4; i++) {
+				uniphier_sd_writel(priv, *buf++,
+						   UNIPHIER_SD_BUF);
+			}
+		} else {
+			for (i = 0; i < blocksize / 4; i++) {
+				u32 data = get_unaligned(buf++);
+				uniphier_sd_writel(priv, data,
+						   UNIPHIER_SD_BUF);
+			}
+		}
 	}
 
 	return 0;
@@ -287,19 +347,24 @@ static int uniphier_sd_pio_write_one_block(struct udevice *dev,
 
 static int uniphier_sd_pio_xfer(struct udevice *dev, struct mmc_data *data)
 {
-	u32 *dest = (u32 *)data->dest;
-	const u32 *src = (const u32 *)data->src;
+	const char *src = data->src;
+	char *dest = data->dest;
 	int i, ret;
 
 	for (i = 0; i < data->blocks; i++) {
 		if (data->flags & MMC_DATA_READ)
-			ret = uniphier_sd_pio_read_one_block(dev, &dest,
+			ret = uniphier_sd_pio_read_one_block(dev, dest,
 							     data->blocksize);
 		else
-			ret = uniphier_sd_pio_write_one_block(dev, &src,
+			ret = uniphier_sd_pio_write_one_block(dev, src,
 							      data->blocksize);
 		if (ret)
 			return ret;
+
+		if (data->flags & MMC_DATA_READ)
+			dest += data->blocksize;
+		else
+			src += data->blocksize;
 	}
 
 	return 0;
-- 
2.11.0

  parent reply	other threads:[~2017-08-20 15:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170820152705epcas2p374259bc866fbe62c31d667deb101cc2f@epcas2p3.samsung.com>
2017-08-20 15:11 ` [U-Boot] [PATCH V3 1/5] mmc: uniphier-sd: Factor out register IO Marek Vasut
2017-08-20 15:11   ` [U-Boot] [PATCH 2/5] mmc: uniphier-sd: Add support for 64bit controller Marek Vasut
2017-08-20 15:44     ` Masahiro Yamada
2017-08-20 15:11   ` Marek Vasut [this message]
2017-08-20 15:44     ` [U-Boot] [PATCH V3 3/5] mmc: uniphier-sd: Add support for 64bit FIFO Masahiro Yamada
2017-08-20 15:11   ` [U-Boot] [PATCH 4/5] mmc: uniphier-sd: Add support for quirks Marek Vasut
2017-08-20 15:45     ` Masahiro Yamada
2017-08-20 15:11   ` [U-Boot] [PATCH 5/5] mmc: uniphier-sd: Add support for R8A7795 and R7A7796 Marek Vasut
2017-08-20 15:45     ` Masahiro Yamada
2017-08-20 15:43   ` [U-Boot] [PATCH V3 1/5] mmc: uniphier-sd: Factor out register IO Masahiro Yamada
2017-09-12 17:04   ` Marek Vasut
2017-09-19 19:39     ` Marek Vasut
2017-09-22 13:54   ` Jaehoon Chung
2017-09-26 15:56     ` Masahiro Yamada

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=20170820151119.2303-3-marek.vasut+renesas@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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