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

2017-08-20 Thread Masahiro Yamada
2017-08-21 0:11 GMT+09:00 Marek Vasut :
> 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 
> Cc: Masahiro Yamada 
> Cc: Jaehoon Chung 
> ---
> V2: - Use unsigned int for the reg argument of IO accessors
> - Rework the handling of aligned and unaligned data
> V3: Remove const ...

Thanks!

Acked-by: Masahiro Yamada 


-- 
Best Regards
Masahiro Yamada
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


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

2017-08-20 Thread Marek Vasut
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 
Cc: Masahiro Yamada 
Cc: Jaehoon Chung 
---
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