OSDN Git Service

Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[uclinux-h8/linux.git] / drivers / mmc / host / sh_mobile_sdhi.c
index 354f4f3..9aa1479 100644 (file)
@@ -1,6 +1,8 @@
 /*
  * SuperH Mobile SDHI
  *
+ * Copyright (C) 2016 Sang Engineering, Wolfram Sang
+ * Copyright (C) 2015-16 Renesas Electronics Corporation
  * Copyright (C) 2009 Magnus Damm
  *
  * This program is free software; you can redistribute it and/or modify
@@ -43,6 +45,7 @@ struct sh_mobile_sdhi_of_data {
        unsigned long capabilities2;
        enum dma_slave_buswidth dma_buswidth;
        dma_addr_t dma_rx_offset;
+       unsigned bus_shift;
 };
 
 static const struct sh_mobile_sdhi_of_data sh_mobile_sdhi_of_cfg[] = {
@@ -59,12 +62,19 @@ static const struct sh_mobile_sdhi_of_data of_rcar_gen1_compatible = {
 
 static const struct sh_mobile_sdhi_of_data of_rcar_gen2_compatible = {
        .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE |
-                         TMIO_MMC_CLK_ACTUAL,
+                         TMIO_MMC_CLK_ACTUAL | TMIO_MMC_FAST_CLK_CHG,
        .capabilities   = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
        .dma_buswidth   = DMA_SLAVE_BUSWIDTH_4_BYTES,
        .dma_rx_offset  = 0x2000,
 };
 
+static const struct sh_mobile_sdhi_of_data of_rcar_gen3_compatible = {
+       .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE |
+                         TMIO_MMC_CLK_ACTUAL | TMIO_MMC_FAST_CLK_CHG,
+       .capabilities   = MMC_CAP_SD_HIGHSPEED,
+       .bus_shift      = 2,
+};
+
 static const struct of_device_id sh_mobile_sdhi_of_match[] = {
        { .compatible = "renesas,sdhi-shmobile" },
        { .compatible = "renesas,sdhi-sh7372" },
@@ -78,6 +88,7 @@ static const struct of_device_id sh_mobile_sdhi_of_match[] = {
        { .compatible = "renesas,sdhi-r8a7792", .data = &of_rcar_gen2_compatible, },
        { .compatible = "renesas,sdhi-r8a7793", .data = &of_rcar_gen2_compatible, },
        { .compatible = "renesas,sdhi-r8a7794", .data = &of_rcar_gen2_compatible, },
+       { .compatible = "renesas,sdhi-r8a7795", .data = &of_rcar_gen3_compatible, },
        {},
 };
 MODULE_DEVICE_TABLE(of, sh_mobile_sdhi_of_match);
@@ -103,6 +114,15 @@ static void sh_mobile_sdhi_sdbuf_width(struct tmio_mmc_host *host, int width)
        case 0xCB0D:
                val = (width == 32) ? 0x0000 : 0x0001;
                break;
+       case 0xCC10: /* Gen3, SD only */
+       case 0xCD10: /* Gen3, SD + MMC */
+               if (width == 64)
+                       val = 0x0000;
+               else if (width == 32)
+                       val = 0x0101;
+               else
+                       val = 0x0001;
+               break;
        default:
                /* nothing to do */
                return;
@@ -163,6 +183,7 @@ static int sh_mobile_sdhi_write16_hook(struct tmio_mmc_host *host, int addr)
        case CTL_SD_MEM_CARD_OPT:
        case CTL_TRANSACTION_CTL:
        case CTL_DMA_ENABLE:
+       case EXT_ACC:
                return sh_mobile_sdhi_wait_idle(host);
        }
 
@@ -213,10 +234,8 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
                return -EINVAL;
 
        priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_mobile_sdhi), GFP_KERNEL);
-       if (priv == NULL) {
-               dev_err(&pdev->dev, "kzalloc failed\n");
+       if (!priv)
                return -ENOMEM;
-       }
 
        mmc_data = &priv->mmc_data;
        dma_priv = &priv->dma_priv;
@@ -234,16 +253,26 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
                goto eprobe;
        }
 
+       if (of_id && of_id->data) {
+               const struct sh_mobile_sdhi_of_data *of_data = of_id->data;
+
+               mmc_data->flags |= of_data->tmio_flags;
+               mmc_data->capabilities |= of_data->capabilities;
+               mmc_data->capabilities2 |= of_data->capabilities2;
+               mmc_data->dma_rx_offset = of_data->dma_rx_offset;
+               dma_priv->dma_buswidth = of_data->dma_buswidth;
+               host->bus_shift = of_data->bus_shift;
+       }
+
        host->dma               = dma_priv;
        host->write16_hook      = sh_mobile_sdhi_write16_hook;
        host->clk_enable        = sh_mobile_sdhi_clk_enable;
        host->clk_disable       = sh_mobile_sdhi_clk_disable;
        host->multi_io_quirk    = sh_mobile_sdhi_multi_io_quirk;
-       /* SD control register space size is 0x100, 0x200 for bus_shift=1 */
-       if (resource_size(res) > 0x100)
+
+       /* Orginally registers were 16 bit apart, could be 32 or 64 nowadays */
+       if (!host->bus_shift && resource_size(res) > 0x100) /* old way to determine the shift */
                host->bus_shift = 1;
-       else
-               host->bus_shift = 0;
 
        if (mmd)
                *mmc_data = *mmd;
@@ -275,15 +304,6 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
         */
        mmc_data->flags |= TMIO_MMC_SDIO_STATUS_QUIRK;
 
-       if (of_id && of_id->data) {
-               const struct sh_mobile_sdhi_of_data *of_data = of_id->data;
-               mmc_data->flags |= of_data->tmio_flags;
-               mmc_data->capabilities |= of_data->capabilities;
-               mmc_data->capabilities2 |= of_data->capabilities2;
-               mmc_data->dma_rx_offset = of_data->dma_rx_offset;
-               dma_priv->dma_buswidth = of_data->dma_buswidth;
-       }
-
        ret = tmio_mmc_host_probe(host, mmc_data);
        if (ret < 0)
                goto efree;