diff mbox

[U-Boot,3/5] mmc: uniphier-sd: Add support for 64bit FIFO

Message ID 20170721212436.26073-3-marek.vasut+renesas@gmail.com
State Accepted
Commit 484d9db4f9dce179de10969693d7ceaf75515459
Delegated to: Jaehoon Chung
Headers show

Commit Message

Marek Vasut July 21, 2017, 9:24 p.m. UTC
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>
---
 drivers/mmc/uniphier-sd.c | 84 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 74 insertions(+), 10 deletions(-)

Comments

Masahiro Yamada Aug. 3, 2017, 12:40 p.m. UTC | #1
Hi Marek,


2017-07-22 6:24 GMT+09:00 Marek Vasut <marek.vasut@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>
> ---
>  drivers/mmc/uniphier-sd.c | 84 +++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 74 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mmc/uniphier-sd.c b/drivers/mmc/uniphier-sd.c
> index 93a2c6becd..07436f6ef6 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, const u32 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,
> +                              const u64 val, const u32 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, const u32 reg)
>  {
>         if (priv->caps & UNIPHIER_SD_CAP_64BIT)
> @@ -248,12 +265,37 @@ static int uniphier_sd_pio_read_one_block(struct udevice *dev, u32 **pbuf,


This 'u32 **pbuf' was optimized for my case.
This is pointless for 64bit platform.

you can change it 'char **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) {
> +                       for (i = 0; i < blocksize / 8; i++) {
> +                               u64 data;
> +                               data = uniphier_sd_readq(priv,
> +                                                        UNIPHIER_SD_BUF);
> +                               *(*pbuf)++ = data;
> +                               *(*pbuf)++ = data >> 32;


I do not think this code is efficient for your 64 bit platform.

Perhaps, you can do as follows:


Prepare a 64bit pointer.

      u64 **pbuf64 = (u64 **)pbuf;

Then,

*(*pbuf64)++ = uniphier_sd_readq(priv, UNIPHIER_SD_BUF);



In this case, please be careful for

if (likely(IS_ALIGNED((unsigned long)*pbuf, 4))) {

You will need 8 byte alignment.
diff mbox

Patch

diff --git a/drivers/mmc/uniphier-sd.c b/drivers/mmc/uniphier-sd.c
index 93a2c6becd..07436f6ef6 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, const u32 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,
+			       const u64 val, const u32 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, const u32 reg)
 {
 	if (priv->caps & UNIPHIER_SD_CAP_64BIT)
@@ -248,12 +265,37 @@  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) {
+			for (i = 0; i < blocksize / 8; i++) {
+				u64 data;
+				data = uniphier_sd_readq(priv,
+							 UNIPHIER_SD_BUF);
+				*(*pbuf)++ = data;
+				*(*pbuf)++ = data >> 32;
+			}
+		} else {
+			for (i = 0; i < blocksize / 4; i++) {
+				u32 data;
+				data = uniphier_sd_readl(priv, UNIPHIER_SD_BUF);
+				*(*pbuf)++ = data;
+			}
+		}
 	} else {
-		for (i = 0; i < blocksize / 4; i++)
-			put_unaligned(uniphier_sd_readl(priv, UNIPHIER_SD_BUF),
-				      (*pbuf)++);
+		if (priv->caps & UNIPHIER_SD_CAP_64BIT) {
+			for (i = 0; i < blocksize / 8; i++) {
+				u64 data;
+				data = uniphier_sd_readq(priv,
+							 UNIPHIER_SD_BUF);
+				put_unaligned(data, (*pbuf)++);
+				put_unaligned(data >> 32, (*pbuf)++);
+			}
+		} else {
+			for (i = 0; i < blocksize / 4; i++) {
+				u32 data;
+				data = uniphier_sd_readl(priv, UNIPHIER_SD_BUF);
+				put_unaligned(data, (*pbuf)++);
+			}
+		}
 	}
 
 	return 0;
@@ -274,12 +316,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) {
+			for (i = 0; i < blocksize / 8; i++) {
+				u64 data = *(*pbuf)++;
+				data |= (u64)*(*pbuf)++ << 32;
+				uniphier_sd_writeq(priv, data,
+						   UNIPHIER_SD_BUF);
+			}
+		} else {
+			for (i = 0; i < blocksize / 4; i++) {
+				uniphier_sd_writel(priv, *(*pbuf)++,
+						   UNIPHIER_SD_BUF);
+			}
+		}
 	} else {
-		for (i = 0; i < blocksize / 4; i++)
-			uniphier_sd_writel(priv, get_unaligned((*pbuf)++),
-					   UNIPHIER_SD_BUF);
+		if (priv->caps & UNIPHIER_SD_CAP_64BIT) {
+			for (i = 0; i < blocksize / 8; i++) {
+				u64 data = get_unaligned((*pbuf)++);
+				data |= (u64)get_unaligned((*pbuf)++) << 32;
+				uniphier_sd_writeq(priv, data,
+						   UNIPHIER_SD_BUF);
+			}
+		} else {
+			for (i = 0; i < blocksize / 4; i++) {
+				u32 data = get_unaligned((*pbuf)++);
+				uniphier_sd_writel(priv, data,
+						   UNIPHIER_SD_BUF);
+			}
+		}
 	}
 
 	return 0;