[PATCH v2 5/6] mmc: sdhci-omap: Add OMAP SDHCI driver

2017-08-31 Thread Kishon Vijay Abraham I
Create a new sdhci-omap driver to configure the eMMC/SD/SDIO controller
in TI's OMAP SoCs making use of the SDHCI core library. For OMAP specific
configurations, populate sdhci_ops with OMAP specific callbacks and use
SDHCI quirks.
Enable only high speed mode for both SD and eMMC here and add other
UHS mode support later.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/mmc/host/Kconfig  |  12 +
 drivers/mmc/host/Makefile |   1 +
 drivers/mmc/host/sdhci-omap.c | 604 ++
 3 files changed, 617 insertions(+)
 create mode 100644 drivers/mmc/host/sdhci-omap.c

diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 02179ed2a40d..03178c42efbb 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -899,3 +899,15 @@ config MMC_SDHCI_XENON
  This selects Marvell Xenon eMMC/SD/SDIO SDHCI.
  If you have a controller with this interface, say Y or M here.
  If unsure, say N.
+
+config MMC_SDHCI_OMAP
+   tristate "TI SDHCI Controller Support"
+   depends on MMC_SDHCI_PLTFM && OF
+   help
+ This selects the Secure Digital Host Controller Interface (SDHCI)
+ support present in TI's DRA7 SOCs. The controller supports
+ SD/MMC/SDIO devices.
+
+ If you have a controller with this interface, say Y or M here.
+
+ If unsure, say N.
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 303f5cd46cd9..2b5a8133948d 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -89,6 +89,7 @@ obj-$(CONFIG_MMC_SDHCI_MSM)   += sdhci-msm.o
 obj-$(CONFIG_MMC_SDHCI_ST) += sdhci-st.o
 obj-$(CONFIG_MMC_SDHCI_MICROCHIP_PIC32)+= sdhci-pic32.o
 obj-$(CONFIG_MMC_SDHCI_BRCMSTB)+= sdhci-brcmstb.o
+obj-$(CONFIG_MMC_SDHCI_OMAP)   += sdhci-omap.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
CFLAGS-cb710-mmc+= -DDEBUG
diff --git a/drivers/mmc/host/sdhci-omap.c b/drivers/mmc/host/sdhci-omap.c
new file mode 100644
index ..cdbd3e1b894e
--- /dev/null
+++ b/drivers/mmc/host/sdhci-omap.c
@@ -0,0 +1,604 @@
+/**
+ * SDHCI Controller driver for TI's OMAP SoCs
+ *
+ * Copyright (C) 2017 Texas Instruments
+ * Author: Kishon Vijay Abraham I 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sdhci-pltfm.h"
+
+#define SDHCI_OMAP_CON 0x12c
+#define CON_DW8BIT(5)
+#define CON_DMA_MASTER BIT(20)
+#define CON_INIT   BIT(1)
+#define CON_OD BIT(0)
+
+#define SDHCI_OMAP_CMD 0x20c
+
+#define SDHCI_OMAP_HCTL0x228
+#define HCTL_SDBP  BIT(8)
+#define HCTL_SDVS_SHIFT9
+#define HCTL_SDVS_MASK (0x7 << HCTL_SDVS_SHIFT)
+#define HCTL_SDVS_33   (0x7 << HCTL_SDVS_SHIFT)
+#define HCTL_SDVS_30   (0x6 << HCTL_SDVS_SHIFT)
+#define HCTL_SDVS_18   (0x5 << HCTL_SDVS_SHIFT)
+
+#define SDHCI_OMAP_SYSCTL  0x22c
+#define SYSCTL_CEN BIT(2)
+#define SYSCTL_CLKD_SHIFT  6
+#define SYSCTL_CLKD_MASK   0x3ff
+
+#define SDHCI_OMAP_STAT0x230
+
+#define SDHCI_OMAP_IE  0x234
+#define INT_CC_EN  BIT(0)
+
+#define SDHCI_OMAP_AC120x23c
+#define AC12_V1V8_SIGENBIT(19)
+
+#define SDHCI_OMAP_CAPA0x240
+#define CAPA_VS33  BIT(24)
+#define CAPA_VS30  BIT(25)
+#define CAPA_VS18  BIT(26)
+
+#define SDHCI_OMAP_TIMEOUT 1   /* 1 msec */
+
+#define SYSCTL_CLKD_MAX0x3FF
+
+#define IOV_1V8180 /* 18 uV */
+#define IOV_3V0300 /* 30 uV */
+#define IOV_3V3330 /* 33 uV */
+
+struct sdhci_omap_data {
+   u32 offset;
+};
+
+struct sdhci_omap_host {
+   void __iomem*base;
+   struct device   *dev;
+   struct  regulator   *pbias;
+   boolpbias_enabled;
+   struct sdhci_host   *host;
+   u8  bus_mode;
+   u8  power_mode;
+};
+
+static inline u32 sdhci_omap_readl(struct sdhci_omap_host *host,
+  

[PATCH v2 5/6] mmc: sdhci-omap: Add OMAP SDHCI driver

2017-08-31 Thread Kishon Vijay Abraham I
Create a new sdhci-omap driver to configure the eMMC/SD/SDIO controller
in TI's OMAP SoCs making use of the SDHCI core library. For OMAP specific
configurations, populate sdhci_ops with OMAP specific callbacks and use
SDHCI quirks.
Enable only high speed mode for both SD and eMMC here and add other
UHS mode support later.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/mmc/host/Kconfig  |  12 +
 drivers/mmc/host/Makefile |   1 +
 drivers/mmc/host/sdhci-omap.c | 604 ++
 3 files changed, 617 insertions(+)
 create mode 100644 drivers/mmc/host/sdhci-omap.c

diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 02179ed2a40d..03178c42efbb 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -899,3 +899,15 @@ config MMC_SDHCI_XENON
  This selects Marvell Xenon eMMC/SD/SDIO SDHCI.
  If you have a controller with this interface, say Y or M here.
  If unsure, say N.
+
+config MMC_SDHCI_OMAP
+   tristate "TI SDHCI Controller Support"
+   depends on MMC_SDHCI_PLTFM && OF
+   help
+ This selects the Secure Digital Host Controller Interface (SDHCI)
+ support present in TI's DRA7 SOCs. The controller supports
+ SD/MMC/SDIO devices.
+
+ If you have a controller with this interface, say Y or M here.
+
+ If unsure, say N.
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 303f5cd46cd9..2b5a8133948d 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -89,6 +89,7 @@ obj-$(CONFIG_MMC_SDHCI_MSM)   += sdhci-msm.o
 obj-$(CONFIG_MMC_SDHCI_ST) += sdhci-st.o
 obj-$(CONFIG_MMC_SDHCI_MICROCHIP_PIC32)+= sdhci-pic32.o
 obj-$(CONFIG_MMC_SDHCI_BRCMSTB)+= sdhci-brcmstb.o
+obj-$(CONFIG_MMC_SDHCI_OMAP)   += sdhci-omap.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
CFLAGS-cb710-mmc+= -DDEBUG
diff --git a/drivers/mmc/host/sdhci-omap.c b/drivers/mmc/host/sdhci-omap.c
new file mode 100644
index ..cdbd3e1b894e
--- /dev/null
+++ b/drivers/mmc/host/sdhci-omap.c
@@ -0,0 +1,604 @@
+/**
+ * SDHCI Controller driver for TI's OMAP SoCs
+ *
+ * Copyright (C) 2017 Texas Instruments
+ * Author: Kishon Vijay Abraham I 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sdhci-pltfm.h"
+
+#define SDHCI_OMAP_CON 0x12c
+#define CON_DW8BIT(5)
+#define CON_DMA_MASTER BIT(20)
+#define CON_INIT   BIT(1)
+#define CON_OD BIT(0)
+
+#define SDHCI_OMAP_CMD 0x20c
+
+#define SDHCI_OMAP_HCTL0x228
+#define HCTL_SDBP  BIT(8)
+#define HCTL_SDVS_SHIFT9
+#define HCTL_SDVS_MASK (0x7 << HCTL_SDVS_SHIFT)
+#define HCTL_SDVS_33   (0x7 << HCTL_SDVS_SHIFT)
+#define HCTL_SDVS_30   (0x6 << HCTL_SDVS_SHIFT)
+#define HCTL_SDVS_18   (0x5 << HCTL_SDVS_SHIFT)
+
+#define SDHCI_OMAP_SYSCTL  0x22c
+#define SYSCTL_CEN BIT(2)
+#define SYSCTL_CLKD_SHIFT  6
+#define SYSCTL_CLKD_MASK   0x3ff
+
+#define SDHCI_OMAP_STAT0x230
+
+#define SDHCI_OMAP_IE  0x234
+#define INT_CC_EN  BIT(0)
+
+#define SDHCI_OMAP_AC120x23c
+#define AC12_V1V8_SIGENBIT(19)
+
+#define SDHCI_OMAP_CAPA0x240
+#define CAPA_VS33  BIT(24)
+#define CAPA_VS30  BIT(25)
+#define CAPA_VS18  BIT(26)
+
+#define SDHCI_OMAP_TIMEOUT 1   /* 1 msec */
+
+#define SYSCTL_CLKD_MAX0x3FF
+
+#define IOV_1V8180 /* 18 uV */
+#define IOV_3V0300 /* 30 uV */
+#define IOV_3V3330 /* 33 uV */
+
+struct sdhci_omap_data {
+   u32 offset;
+};
+
+struct sdhci_omap_host {
+   void __iomem*base;
+   struct device   *dev;
+   struct  regulator   *pbias;
+   boolpbias_enabled;
+   struct sdhci_host   *host;
+   u8  bus_mode;
+   u8  power_mode;
+};
+
+static inline u32 sdhci_omap_readl(struct sdhci_omap_host *host,
+  unsigned int offset)
+{
+