[PATCH v7] mmc: moxart: Add MOXA ART SD/MMC driver

2014-01-21 Thread Jonas Jensen
Add SD/MMC driver for MOXA ART SoCs.

Signed-off-by: Jonas Jensen 
---

Notes:
v6 was supposed to fix a panic from dmaengine_tx_status() but it
still happened. This is the sort of panic that lasts between reboots
but not between kernel reflash.

dmaengine_tx_status() is used only to print DMA error, that's why
I decided to remove it, instead of risking permanent kernel panic.

Changes since v6:

1. use mmc_of_parse()
2. remove duplicate defines MSD_*
3. add reference to bindings/mmc/mmc.txt in DT binding
4. update DT binding example
   ("coreclk" renamed "clk_apb", DMA channel number is no longer needed)
5. rename "sdhci-moxart" "moxart-mmc"
6. remove dmaengine_tx_status() / don't print DMA error
7. format comments / use correct grammar

Applies to next-20140121

 .../devicetree/bindings/mmc/moxa,moxart-mmc.txt|  32 +
 drivers/mmc/host/Kconfig   |   9 +
 drivers/mmc/host/Makefile  |   1 +
 drivers/mmc/host/moxart-mmc.c  | 872 +
 4 files changed, 914 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
 create mode 100644 drivers/mmc/host/moxart-mmc.c

diff --git a/Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt 
b/Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
new file mode 100644
index 000..c2045d1
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
@@ -0,0 +1,32 @@
+MOXA ART SD Host Controller Interface
+
+  Inherits from mmc binding[1].
+
+  [1] Documentation/devicetree/bindings/mmc/mmc.txt
+
+Required properties:
+
+- compatible : Must be "moxa,moxart-mmc"
+- reg :Should contain registers location and length
+- interrupts : Should contain the interrupt number
+- clocks : Should contain phandle for the clock feeding the SDHCI 
controller
+
+Optional properties:
+
+These are optional but required to enable DMA transfer mode:
+
+- dmas :   Should contain two DMA channels, line request number must be 5 
for
+   both channels
+- dma-names :  Must be "tx", "rx"
+
+Example:
+
+   mmc: mmc@98e0 {
+   compatible = "moxa,moxart-mmc";
+   reg = <0x98e0 0x5C>;
+   interrupts = <5 0>;
+   clocks = <_apb>;
+   dmas =  < 5>,
+   < 5>;
+   dma-names = "tx", "rx";
+   };
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 1384f67..15806d6 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -283,6 +283,15 @@ config MMC_SDHCI_BCM2835
 
  If unsure, say N.
 
+config MMC_MOXART
+   tristate "MOXART SD/MMC Host Controller support"
+   depends on ARCH_MOXART && MMC
+   help
+ This selects support for the MOXART SD/MMC Host Controller.
+ MOXA provides one multi-functional card reader which can
+ be found on some embedded hardware such as UC-7112-LX.
+ If you have a controller with this interface, say Y here.
+
 config MMC_OMAP
tristate "TI OMAP Multimedia Card Interface support"
depends on ARCH_OMAP
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 3483b6b..6b90eda 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_MMC_JZ4740)  += jz4740_mmc.o
 obj-$(CONFIG_MMC_VUB300)   += vub300.o
 obj-$(CONFIG_MMC_USHC) += ushc.o
 obj-$(CONFIG_MMC_WMT)  += wmt-sdmmc.o
+obj-$(CONFIG_MMC_MOXART)   += moxart-mmc.o
 
 obj-$(CONFIG_MMC_REALTEK_PCI)  += rtsx_pci_sdmmc.o
 
diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c
new file mode 100644
index 000..be12e12
--- /dev/null
+++ b/drivers/mmc/host/moxart-mmc.c
@@ -0,0 +1,872 @@
+/*
+ * MOXA ART MMC host driver.
+ *
+ * Copyright (C) 2013 Jonas Jensen
+ *
+ * Jonas Jensen 
+ *
+ * Based on code from
+ * Moxa Technologies Co., Ltd. 
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#define MMC_RSP_SHORT  1
+#define MMC_RSP_LONG   2
+#define MMC_RSP_MASK   3
+#define MMC_ERR_NONE   0
+#define MMC_ERR_TIMEOUT1
+#define MMC_MODE_MMC   0
+#define MMC_MODE_SD1
+#define MMC_ERR_BADCRC 2
+#define MMC_VDD_36023
+
+#define MSD_RETRY_COUNT10
+
+#define REG_COMMAND0
+#define REG_ARGUMENT   4
+#define REG_RESPONSE0  8
+#define 

[PATCH v7] mmc: moxart: Add MOXA ART SD/MMC driver

2014-01-21 Thread Jonas Jensen
Add SD/MMC driver for MOXA ART SoCs.

Signed-off-by: Jonas Jensen jonas.jen...@gmail.com
---

Notes:
v6 was supposed to fix a panic from dmaengine_tx_status() but it
still happened. This is the sort of panic that lasts between reboots
but not between kernel reflash.

dmaengine_tx_status() is used only to print DMA error, that's why
I decided to remove it, instead of risking permanent kernel panic.

Changes since v6:

1. use mmc_of_parse()
2. remove duplicate defines MSD_*
3. add reference to bindings/mmc/mmc.txt in DT binding
4. update DT binding example
   (coreclk renamed clk_apb, DMA channel number is no longer needed)
5. rename sdhci-moxart moxart-mmc
6. remove dmaengine_tx_status() / don't print DMA error
7. format comments / use correct grammar

Applies to next-20140121

 .../devicetree/bindings/mmc/moxa,moxart-mmc.txt|  32 +
 drivers/mmc/host/Kconfig   |   9 +
 drivers/mmc/host/Makefile  |   1 +
 drivers/mmc/host/moxart-mmc.c  | 872 +
 4 files changed, 914 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
 create mode 100644 drivers/mmc/host/moxart-mmc.c

diff --git a/Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt 
b/Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
new file mode 100644
index 000..c2045d1
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
@@ -0,0 +1,32 @@
+MOXA ART SD Host Controller Interface
+
+  Inherits from mmc binding[1].
+
+  [1] Documentation/devicetree/bindings/mmc/mmc.txt
+
+Required properties:
+
+- compatible : Must be moxa,moxart-mmc
+- reg :Should contain registers location and length
+- interrupts : Should contain the interrupt number
+- clocks : Should contain phandle for the clock feeding the SDHCI 
controller
+
+Optional properties:
+
+These are optional but required to enable DMA transfer mode:
+
+- dmas :   Should contain two DMA channels, line request number must be 5 
for
+   both channels
+- dma-names :  Must be tx, rx
+
+Example:
+
+   mmc: mmc@98e0 {
+   compatible = moxa,moxart-mmc;
+   reg = 0x98e0 0x5C;
+   interrupts = 5 0;
+   clocks = clk_apb;
+   dmas =  dma 5,
+   dma 5;
+   dma-names = tx, rx;
+   };
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 1384f67..15806d6 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -283,6 +283,15 @@ config MMC_SDHCI_BCM2835
 
  If unsure, say N.
 
+config MMC_MOXART
+   tristate MOXART SD/MMC Host Controller support
+   depends on ARCH_MOXART  MMC
+   help
+ This selects support for the MOXART SD/MMC Host Controller.
+ MOXA provides one multi-functional card reader which can
+ be found on some embedded hardware such as UC-7112-LX.
+ If you have a controller with this interface, say Y here.
+
 config MMC_OMAP
tristate TI OMAP Multimedia Card Interface support
depends on ARCH_OMAP
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 3483b6b..6b90eda 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_MMC_JZ4740)  += jz4740_mmc.o
 obj-$(CONFIG_MMC_VUB300)   += vub300.o
 obj-$(CONFIG_MMC_USHC) += ushc.o
 obj-$(CONFIG_MMC_WMT)  += wmt-sdmmc.o
+obj-$(CONFIG_MMC_MOXART)   += moxart-mmc.o
 
 obj-$(CONFIG_MMC_REALTEK_PCI)  += rtsx_pci_sdmmc.o
 
diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c
new file mode 100644
index 000..be12e12
--- /dev/null
+++ b/drivers/mmc/host/moxart-mmc.c
@@ -0,0 +1,872 @@
+/*
+ * MOXA ART MMC host driver.
+ *
+ * Copyright (C) 2013 Jonas Jensen
+ *
+ * Jonas Jensen jonas.jen...@gmail.com
+ *
+ * Based on code from
+ * Moxa Technologies Co., Ltd. www.moxa.com
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed as is without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include linux/version.h
+#include linux/module.h
+#include linux/init.h
+#include linux/ioport.h
+#include linux/platform_device.h
+#include linux/delay.h
+#include linux/interrupt.h
+#include linux/blkdev.h
+#include linux/dma-mapping.h
+#include linux/dmaengine.h
+#include linux/mmc/host.h
+#include linux/mmc/sd.h
+#include linux/mmc/mmc.h
+#include linux/sched.h
+#include linux/io.h
+#include linux/gpio.h
+#include linux/sizes.h
+#include linux/of_address.h
+#include linux/of_irq.h
+#include linux/clk.h
+#include linux/bitops.h
+#include linux/of_dma.h
+
+#include asm/dma.h
+#include asm/irq.h
+
+#define MMC_RSP_SHORT  1
+#define MMC_RSP_LONG   2
+#define MMC_RSP_MASK   3
+#define