[PATCH v4] mmc: moxart: fix probe logic

2015-02-03 Thread Jonas Jensen
From: Arnd Bergmann 

Jonas Jensen wanted to submit a patch for these, but apparently
forgot about it. I stumbled over this symptom first:

drivers/built-in.o: In function `moxart_probe':
:(.text+0x2af128): undefined reference to `of_dma_request_slave_channel'

This is because of_dma_request_slave_channel is an internal helper
and not exported to loadable module. I'm changing the driver to
use dma_request_slave_channel_reason() instead.

Further problems from inspection:

* The remove function must not call kfree on the host pointer,
  because it is allocated together with the mmc_host.

* The clock is never released

* The dma_cap_mask_t is completely unused and can be removed

* deferred probing does not work if the dma driver is loaded
  after the mmc driver.

This patch should fix all of the above.

Signed-off-by: Arnd Bergmann 
Signed-off-by: Jonas Jensen 
---

Notes:
This is a forward of Arnd's v2 patch.

v2:  do not call clk_put() on an error pointer
v3:  fix NULL dereference on host->clk
v4:  rework to use devm_clk_get()

Applies to next-20150113

 drivers/mmc/host/moxart-mmc.c | 21 ++---
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c
index d2a1ef6..6cb4053 100644
--- a/drivers/mmc/host/moxart-mmc.c
+++ b/drivers/mmc/host/moxart-mmc.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -562,7 +563,6 @@ static int moxart_probe(struct platform_device *pdev)
struct dma_slave_config cfg;
struct clk *clk;
void __iomem *reg_mmc;
-   dma_cap_mask_t mask;
int irq, ret;
u32 i;
 
@@ -586,9 +586,9 @@ static int moxart_probe(struct platform_device *pdev)
goto out;
}
 
-   clk = of_clk_get(node, 0);
+   clk = devm_clk_get(dev, 0);
if (IS_ERR(clk)) {
-   dev_err(dev, "of_clk_get failed\n");
+   dev_err(dev, "devm_clk_get failed\n");
ret = PTR_ERR(clk);
goto out;
}
@@ -603,9 +603,6 @@ static int moxart_probe(struct platform_device *pdev)
if (ret)
goto out;
 
-   dma_cap_zero(mask);
-   dma_cap_set(DMA_SLAVE, mask);
-
host = mmc_priv(mmc);
host->mmc = mmc;
host->base = reg_mmc;
@@ -613,8 +610,8 @@ static int moxart_probe(struct platform_device *pdev)
host->timeout = msecs_to_jiffies(1000);
host->sysclk = clk_get_rate(clk);
host->fifo_width = readl(host->base + REG_FEATURE) << 2;
-   host->dma_chan_tx = of_dma_request_slave_channel(node, "tx");
-   host->dma_chan_rx = of_dma_request_slave_channel(node, "rx");
+   host->dma_chan_tx = dma_request_slave_channel_reason(dev, "tx");
+   host->dma_chan_rx = dma_request_slave_channel_reason(dev, "rx");
 
spin_lock_init(&host->lock);
 
@@ -624,6 +621,11 @@ static int moxart_probe(struct platform_device *pdev)
mmc->ocr_avail = 0x00;  /* Support 2.0v - 3.6v power. */
 
if (IS_ERR(host->dma_chan_tx) || IS_ERR(host->dma_chan_rx)) {
+   if (PTR_ERR(host->dma_chan_tx) == -EPROBE_DEFER ||
+   PTR_ERR(host->dma_chan_rx) == -EPROBE_DEFER) {
+   ret = -EPROBE_DEFER;
+   goto out;
+   }
dev_dbg(dev, "PIO mode transfer enabled\n");
host->have_dma = false;
} else {
@@ -702,9 +704,6 @@ static int moxart_remove(struct platform_device *pdev)
writel(readl(host->base + REG_CLOCK_CONTROL) | CLK_OFF,
   host->base + REG_CLOCK_CONTROL);
}
-
-   kfree(host);
-
return 0;
 }
 
-- 
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] mmc: moxart: fix probe logic

2015-02-02 Thread Jonas Jensen
Jonas Jensen wanted to submit a patch for these, but apparently
forgot about it. I stumbled over this symptom first:

drivers/built-in.o: In function `moxart_probe':
:(.text+0x2af128): undefined reference to `of_dma_request_slave_channel'

This is because of_dma_request_slave_channel is an internal helper
and not exported to loadable module. I'm changing the driver to
use dma_request_slave_channel_reason() instead.

Further problems from inspection:

* The remove function must not call kfree on the host pointer,
  because it is allocated together with the mmc_host.

* The clock is never released

* The dma_cap_mask_t is completely unused and can be removed

* deferred probing does not work if the dma driver is loaded
  after the mmc driver.

This patch should fix all of the above.

Signed-off-by: Jonas Jensen 
---

Notes:
This is a forward (with a single line fix) of Arnd's v2 patch.

v2:  do not call clk_put() on an error pointer
v3:  fix NULL dereference on host->clk

Applies to next-20150113

 drivers/mmc/host/moxart-mmc.c | 34 +++---
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c
index d2a1ef6..6ab57d1e 100644
--- a/drivers/mmc/host/moxart-mmc.c
+++ b/drivers/mmc/host/moxart-mmc.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -131,6 +132,7 @@ struct moxart_host {
struct mmc_host *mmc;
struct mmc_request  *mrq;
struct scatterlist  *cur_sg;
+   struct clk  *clk;
struct completion   dma_complete;
struct completion   pio_complete;
 
@@ -560,9 +562,7 @@ static int moxart_probe(struct platform_device *pdev)
struct mmc_host *mmc;
struct moxart_host *host = NULL;
struct dma_slave_config cfg;
-   struct clk *clk;
void __iomem *reg_mmc;
-   dma_cap_mask_t mask;
int irq, ret;
u32 i;
 
@@ -573,6 +573,8 @@ static int moxart_probe(struct platform_device *pdev)
goto out;
}
 
+   host = mmc_priv(mmc);
+
ret = of_address_to_resource(node, 0, &res_mmc);
if (ret) {
dev_err(dev, "of_address_to_resource failed\n");
@@ -586,10 +588,11 @@ static int moxart_probe(struct platform_device *pdev)
goto out;
}
 
-   clk = of_clk_get(node, 0);
-   if (IS_ERR(clk)) {
+   host->clk = of_clk_get(node, 0);
+   if (IS_ERR(host->clk)) {
dev_err(dev, "of_clk_get failed\n");
-   ret = PTR_ERR(clk);
+   ret = PTR_ERR(host->clk);
+   host->clk = NULL;
goto out;
}
 
@@ -603,18 +606,14 @@ static int moxart_probe(struct platform_device *pdev)
if (ret)
goto out;
 
-   dma_cap_zero(mask);
-   dma_cap_set(DMA_SLAVE, mask);
-
-   host = mmc_priv(mmc);
host->mmc = mmc;
host->base = reg_mmc;
host->reg_phys = res_mmc.start;
host->timeout = msecs_to_jiffies(1000);
-   host->sysclk = clk_get_rate(clk);
+   host->sysclk = clk_get_rate(host->clk);
host->fifo_width = readl(host->base + REG_FEATURE) << 2;
-   host->dma_chan_tx = of_dma_request_slave_channel(node, "tx");
-   host->dma_chan_rx = of_dma_request_slave_channel(node, "rx");
+   host->dma_chan_tx = dma_request_slave_channel_reason(dev, "tx");
+   host->dma_chan_rx = dma_request_slave_channel_reason(dev, "rx");
 
spin_lock_init(&host->lock);
 
@@ -624,6 +623,11 @@ static int moxart_probe(struct platform_device *pdev)
mmc->ocr_avail = 0x00;  /* Support 2.0v - 3.6v power. */
 
if (IS_ERR(host->dma_chan_tx) || IS_ERR(host->dma_chan_rx)) {
+   if (PTR_ERR(host->dma_chan_tx) == -EPROBE_DEFER ||
+   PTR_ERR(host->dma_chan_rx) == -EPROBE_DEFER) {
+   ret = -EPROBE_DEFER;
+   goto out;
+   }
dev_dbg(dev, "PIO mode transfer enabled\n");
host->have_dma = false;
} else {
@@ -677,6 +681,8 @@ static int moxart_probe(struct platform_device *pdev)
return 0;
 
 out:
+   if (host->clk)
+   clk_put(host->clk);
if (mmc)
mmc_free_host(mmc);
return ret;
@@ -694,6 +700,7 @@ static int moxart_remove(struct platform_device *pdev)
dma_release_channel(host->dma_chan_tx);
if (!IS_ERR(host->dma_chan_rx))
dma_release_channel(host->dma_chan_rx);
+   clk_put(host->clk);
mmc_remove_host(mmc);
   

Re: [PATCH v2] mmc: moxart: fix probe logic

2015-02-02 Thread Jonas Jensen
Thanks for taking the time.


On 29 January 2015 at 23:06, Arnd Bergmann  wrote:
> Jonas Jensen wanted to submit a patch for these, but apparently
> forgot about it. I stumbled over this symptom first:

Sorry about this, I remember thinking about the changes but only made
a mental note (which was lost over time). I was sidetracked with other
changes and work.


> @@ -586,10 +586,10 @@ static int moxart_probe(struct platform_device *pdev)
> goto out;
> }
>
> -   clk = of_clk_get(node, 0);
> -   if (IS_ERR(clk)) {
> +   host->clk = of_clk_get(node, 0);

host->clk is a NULL dereference at this point in probe() (log below).

I moved the single line "host = mmc_priv(mmc);" to happen just before,
and everything is working normally again.


Uncompressing Linux... done, booting the kernel.
[0.00] Booting Linux on physical CPU 0x0
[0.00] Linux version 3.17.0-00628-g572d48d-dirty (i@Ildjarn)
(gcc version 4.9.1 (crosstool-NG 1.20.0) ) #3509 PREEMPT Mon Feb 2
10:57:21 CET 2015
[0.00] CPU: FA526 [66015261] revision 1 (ARMv4), cr=397f
[0.00] CPU: VIVT data cache, VIVT instruction cache
[0.00] Machine model: MOXA UC-7112-LX
[0.00] bootconsole [earlycon0] enabled
[0.00] Memory policy: Data cache writeback
[0.00] On node 0 totalpages: 8192
[0.00] free_area_init_node: node 0, pgdat c03633c4,
node_mem_map c1fba000
[0.00]   Normal zone: 64 pages used for memmap
[0.00]   Normal zone: 0 pages reserved
[0.00]   Normal zone: 8192 pages, LIFO batch:0
[0.00] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[0.00] pcpu-alloc: [0] 0
[0.00] Built 1 zonelists in Zone order, mobility grouping on.
Total pages: 8128
[0.00] Kernel command line: console=ttyS0,115200n8 earlyprintk
root=/dev/mmcblk0p1 rw rootwait debug
[0.00] PID hash table entries: 128 (order: -3, 512 bytes)
[0.00] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
[0.00] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
[0.00] Memory: 28824K/32768K available (2710K kernel code, 94K
rwdata, 508K rodata, 116K init, 125K bss, 3944K reserved)
[0.00] Virtual kernel memory layout:
[0.00] vector  : 0x - 0x1000   (   4 kB)
[0.00] fixmap  : 0xffc0 - 0xffe0   (2048 kB)
[0.00] vmalloc : 0xc280 - 0xff00   ( 968 MB)
[0.00] lowmem  : 0xc000 - 0xc200   (  32 MB)
[0.00]   .text : 0xc0008000 - 0xc032ccd0   (3220 kB)
[0.00]   .init : 0xc032d000 - 0xc034a390   ( 117 kB)
[0.00]   .data : 0xc034c000 - 0xc0363b20   (  95 kB)
[0.00].bss : 0xc0363b20 - 0xc03831c8   ( 126 kB)
[0.00] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[0.00] Preemptible hierarchical RCU implementation.
[0.00] NR_IRQS:16 nr_irqs:16 16
[0.00] sched_clock: 32 bits at 100 Hz, resolution 1000ns,
wraps every 2147483648000ns
[0.01] Calibrating delay loop... 146.84 BogoMIPS (lpj=734208)
[0.10] pid_max: default: 4096 minimum: 301
[0.10] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[0.11] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[0.12] CPU: Testing write buffer coherency: ok
[0.13] Setting up static identity map for 0x2955c8 - 0x295610
[0.15] devtmpfs: initialized
[0.17] NET: Registered protocol family 16
[0.18] DMA: preallocated 256 KiB pool for atomic coherent allocations
[0.28] Switched to clocksource moxart_timer
[0.29] NET: Registered protocol family 2
[0.30] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[0.31] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[0.32] TCP: Hash tables configured (established 1024 bind 1024)
[0.33] TCP: reno registered
[0.33] UDP hash table entries: 256 (order: 0, 4096 bytes)
[0.34] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[0.35] NET: Registered protocol family 1
[0.36] futex hash table entries: 16 (order: -5, 192 bytes)
[0.41] jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
[0.42] msgmni has been set to 56
[0.43] io scheduler noop registered
[0.43] io scheduler cfq registered (default)
[0.44] gpiochip_find_base: found new base at 224
[0.44] gpiochip_add: registered GPIOs 224 to 255 on device: moxart-gpio
[0.45] Serial: 8250/16550 driver, 1 ports, IRQ sharing enabled
[0.47] console [ttyS0] disabled
[0.47] 9820.uart0: ttyS0 at MMIO 0x9820 (irq = 21,
base_baud = 921600) is a 16550A
[0.48] console [ttyS0] enabled
[0.48] console [ttyS0] enabled
[0.49] bootconsole [earlycon0] disabled
[0.49] bootconso

Re: mmc: moxart: Add MOXA ART SD/MMC driver

2014-05-21 Thread Jonas Jensen
On 21 May 2014 14:28, Dan Carpenter  wrote:
> Hello Jonas Jensen,
>
> The patch 1b66e94e6b99: "mmc: moxart: Add MOXA ART SD/MMC driver"
> from Apr 9, 2014, leads to the following static checker warning:
>
> drivers/mmc/host/moxart-mmc.c:691 moxart_remove()
> warn: variable dereferenced before check 'mmc' (see line 687)


Thanks, I'll post a patch with fixes for this and bugs spotted by Arnd.

Regards,
Jonas
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2014-04-09 Thread Jonas Jensen
Add SD/MMC driver for MOXA ART SoCs.

The "MOXA ART MMC controller" is likely a faraday "ftsdc010",
a controller with support in U-Boot:

http://git.denx.de/?p=u-boot.git;a=blob;f=drivers/mmc/ftsdc010_mci.c

Signed-off-by: Jonas Jensen 
---

Notes:
This has been cleaned up further, especially the return value fiasco in v7.

The "MOXA ART MMC controller" is likely a faraday "ftsdc010" (supported by 
U-Boot [1]).
Registers are the same albeit named slightly different.

I think this can support other "ftsdc010" SoCs with one reservation for
power control, which may need hardware specific changes.

Changes since v7:

1. merge code from U-Boot "ftsdc010" driver [1]

   Specifically how it implements status wait, clock divider, fifo width, 
bus width.

2. return value cleanup, MMC_ERR_TIMEOUT is no longer used or set at the 
top of every request

   i.e. the default (no error) return value (0) is respected.

   Error is only set on actual error, "MMC_ERR_NONE" is no longer used.

3. FIFO size is now read from register (and respected during PIO transfer)
4. supported bus width(s) is now read from register
5. !(of_dma_request_slave_channel()) return value check is wrong,
   IS_ERR() must be used.
6. clean up and remove unused defines / header includes
7. add "faraday,ftsdc010" compatible string (requested by Arnd)

[1] http://git.denx.de/?p=u-boot.git;a=blob;f=drivers/mmc/ftsdc010_mci.c

Applies to next-20140409

 .../devicetree/bindings/mmc/moxa,moxart-mmc.txt|  30 +
 drivers/mmc/host/Kconfig   |   9 +
 drivers/mmc/host/Makefile  |   1 +
 drivers/mmc/host/moxart-mmc.c  | 730 +
 4 files changed, 770 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..b638191
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
@@ -0,0 +1,30 @@
+MOXA ART MMC Host Controller Interface
+
+  Inherits from mmc binding[1].
+
+  [1] Documentation/devicetree/bindings/mmc/mmc.txt
+
+Required properties:
+
+- compatible : Must be "moxa,moxart-mmc" or "faraday,ftsdc010"
+- reg :Should contain registers location and length
+- interrupts : Should contain the interrupt number
+- clocks : Should contain phandle for the clock feeding the MMC controller
+
+Optional properties:
+
+- 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 8aaf8c1..eb93b81 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 0c8aa5e..dfa6ecb 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -50,6 +50,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..74924a0
--- /dev/null
+++ b/drivers/mmc/host/moxart-mmc.c
@@ -0,0 +1,730 @@
+/*
+ * MOXA ART MMC host driver.
+ *
+ * Copyright (C) 2014 Jonas Jensen
+ *
+ * Jonas Jensen 
+ *
+ * Based on code from
+ * Moxa Technologies Co., Ltd. 
+ *
+ * This file is licensed under the terms of the GNU General Pub

[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 = <&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 
+ *
+ * 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
+#

[PATCH v6] mmc: sdhci-moxart: Add MOXA ART SDHCI driver

2014-01-17 Thread Jonas Jensen
Add SDHCI driver for MOXA ART SoCs.

Signed-off-by: Jonas Jensen 
---

Notes:
Changes in v6 fixes a kernel panic in moxart_dma_complete().

Panic only happens with CONFIG_SLAB or CONFIG_SLOB, the same code
works for CONFIG_SLUB, and happens because a cookie belonging
to the channel is passed to dmaengine_tx_status(), e.g.
"host->tx_desc->chan->cookie".

Panic log:
[4.13] mmc0: new SD card at address e624
[4.17] nf_conntrack version 0.5.0 (357 buckets, 1428 max)
[4.19] ip_tables: (C) 2000-2006 Netfilter Core Team
[4.19] TCP: cubic registered
[4.20] NET: Registered protocol family 10
[4.24] sit: IPv6 over IPv4 tunneling driver
[4.27] mmcblk0: mmc0:e624 SD02G 1.84 GiB
[4.32]  mmcblk0: p1
[4.37] NET: Registered protocol family 17
[4.44] console [netcon0] enabled
[4.44] netconsole: network logging started
[4.45] moxart-rtc rtc.0: setting system clock to 2014-01-16 
13:39:54 UTC (1389879594)
[4.55] kjournald starting.  Commit interval 5 seconds
[4.55] EXT3-fs (mmcblk0p1): warning: maximal mount count reached, 
running e2fsck is recommended
[4.57] EXT3-fs (mmcblk0p1): using internal journal
[4.58] EXT3-fs (mmcblk0p1): mounted filesystem with ordered data 
mode
[4.59] VFS: Mounted root (ext3 filesystem) on device 179:1.
[4.61] devtmpfs: mounted
[4.63] Freeing unused kernel memory: 156K (c0339000 - c036)
[4.64] Unable to handle kernel paging request at virtual address 

[4.64] pgd = c0004000
[4.64] [] *pgd=
[4.64] Internal error: Oops: 1 [#1] ARM
[4.64] CPU: 0 PID: 0 Comm: swapper Not tainted 
3.13.0-rc8-next-20140115+ #1577
[4.64] task: c03676a8 ti: c0362000 task.ti: c0362000
[4.64] PC is at moxart_dma_complete+0x14/0x68
[4.64] LR is at vchan_complete+0xcc/0xf4
[4.64] pc : []lr : []psr: a013
[4.64] sp : c0363e98  ip : c037ffcc  fp : c0380f00
[4.64] r10: c1a867e0  r9 : c0380f38  r8 : c0363eb0
[4.64] r7 : 00100100  r6 : 00200200  r5 : c01a6710  r4 : c1a867e0
[4.64] r3 : c1ac0030  r2 : c0363e9c  r1 : c03676a8  r0 : 
[4.64] Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment 
kernel
[4.64] Control: 397f  Table: 4000  DAC: 0017
[4.64] Process swapper (pid: 0, stack limit = 0xc03621c0)
[4.64] Stack: (0xc0363e98 to 0xc0364000)
[4.64] 3e80:   
c1a867e0 c03676a8
[4.64] 3ea0:  c03676a8 c1871158 c0154a28 c0363eb0 c0363eb0 
6013 c1871184
[4.64] 3ec0: c03694d4   0006 0100 c0018fc4 
c036bc60 0007
[4.64] 3ee0: 0040 c0362000 c0380f20 c0018950 c185b894 c185b894 
c185b840 0006
[4.64] 3f00: 000a 0020 0001 8ca1  0011 
 c0934d40
[4.64] 3f20: 0001 c0363f68 66015261 c0352624  c0018d38 
0011 c0009a14
[4.64] 3f40: c18020e4 0100 0018 c0008538 c0009b94 2013 
 c0363f9c
[4.64] 3f60: c0998200 c000bfb8 0001 c03676a8  2013 
c0362000 c0364020
[4.64] 3f80: c0364110  c0998200 66015261 c0352624  
f6aa4ecf c0363fb0
[4.64] 3fa0: c003da20 c0009b94 2013  c03676a8 c0047548 
c03676a8 c0339988
[4.64] 3fc0:   c03394d4   c0352624 
 397d
[4.64] 3fe0: c03640a4 c0352620 c03689ec 4000 003517b4 8040 
 
[4.64] [] (moxart_dma_complete) from [] 
(vchan_complete+0xcc/0xf4)
[4.64] [] (vchan_complete) from [] 
(tasklet_action+0x84/0xd4)
[4.64] [] (tasklet_action) from [] 
(__do_softirq+0x170/0x2a4)
[4.64] [] (__do_softirq) from [] 
(irq_exit+0x80/0x100)
[4.64] [] (irq_exit) from [] 
(handle_IRQ+0x60/0x80)
[4.64] [] (handle_IRQ) from [] 
(handle_irq+0x88/0x9c)
[4.64] [] (handle_irq) from [] 
(__irq_svc+0x38/0x48)
[4.64] Exception stack(0xc0363f68 to 0xc0363fb0)
[4.64] 3f60:   0001 c03676a8  2013 
c0362000 c0364020
[4.64] 3f80: c0364110  c0998200 66015261 c0352624  
f6aa4ecf c0363fb0
[4.64] 3fa0: c003da20 c0009b94 2013 
[4.64] [] (__irq_svc) from [] 
(arch_cpu_idle+0x3c/0x48)
[4.64] [] (arch_cpu_idle) from [] 
(cpu_startup_entry+0x80/0xf0)
[4.64] [] (cpu_startup_entry) from [] 
(start_kernel+0x298/0x2e0)
[4.64] Code: e5903030 e1a04000 e593000c e28d2004 (e5903000)
[   

[PATCH v5] mmc: sdhci-moxart: Add MOXA ART SDHCI driver

2013-12-11 Thread Jonas Jensen
Add SDHCI driver for MOXA ART SoCs.

Signed-off-by: Jonas Jensen 
---

Notes:
Changes since v4:

1.  remove dma_chan_cur pointer from host structure
2.  add local dma_chan_cur pointer in moxart_transfer_dma()
3.  add dma_async_tx_descriptor pointer (host structure)
4.  save descriptor pointers between transfers
5.  use [3] to check for DMA transfer error (with dmaengine_tx_status())
6.  use !!(condition) construct in moxart_get_ro()
7.  set both source/destination DMA transfer width early in probe,
this fixes the problem that dst_addr_width is left uninitialized
for dma_chan_tx

both "src_addr_width" and "dst_addr_width" (dma_slave_config)
are now assigned DMA_SLAVE_BUSWIDTH_4_BYTES
(before configuring channels with dmaengine_slave_config())

8.  remove redundant dev_err() call in moxart_probe(),
devm_ioremap_resource() prints a similar message
9.  use dev_err(), not pr_err() in moxart_transfer_dma()
10. bail on irq_of_parse_and_map() failure
11. remove unused host variable "wait_for"
12. change driver name and compatible strings "mmc" to "sdhci"

Applies to next-20131211

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

diff --git a/Documentation/devicetree/bindings/mmc/moxa,moxart-sdhci.txt 
b/Documentation/devicetree/bindings/mmc/moxa,moxart-sdhci.txt
new file mode 100644
index 000..020b13e
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/moxa,moxart-sdhci.txt
@@ -0,0 +1,28 @@
+MOXA ART SD Host Controller Interface
+
+Required properties:
+
+- compatible : Must be "moxa,moxart-sdhci"
+- 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:
+
+   sdhci: sdhci@98e0 {
+   compatible = "moxa,moxart-sdhci";
+   reg = <0x98e0 0x5C>;
+   interrupts = <5 0>;
+   clocks = <&coreclk>;
+   dmas =  <&dma 0 5>,
+   <&dma 1 5>;
+   dma-names = "tx", "rx";
+   };
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 7fc5099..3421424 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -271,6 +271,15 @@ config MMC_SDHCI_BCM2835
 
  If unsure, say N.
 
+config MMC_SDHCI_MOXART
+   tristate "MOXART SD Host Controller Interface support"
+   depends on ARCH_MOXART && MMC
+   help
+ This selects the MOXART SD Host Controller Interface.
+ 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 c41d0c3..7f6ebc3 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_MMC_SDHCI_OF_ESDHC)  += sdhci-of-esdhc.o
 obj-$(CONFIG_MMC_SDHCI_OF_HLWD)+= sdhci-of-hlwd.o
 obj-$(CONFIG_MMC_SDHCI_BCM_KONA)   += sdhci-bcm-kona.o
 obj-$(CONFIG_MMC_SDHCI_BCM2835)+= sdhci-bcm2835.o
+obj-$(CONFIG_MMC_SDHCI_MOXART) += sdhci-moxart.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
CFLAGS-cb710-mmc+= -DDEBUG
diff --git a/drivers/mmc/host/sdhci-moxart.c b/drivers/mmc/host/sdhci-moxart.c
new file mode 100644
index 000..5fb854e
--- /dev/null
+++ b/drivers/mmc/host/sdhci-moxart.c
@@ -0,0 +1,929 @@
+/*
+ * 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 

[PATCH v4] mmc: sdhci-moxart: Add MOXA ART SDHCI driver

2013-08-06 Thread Jonas Jensen
Add SDHCI driver for MOXA ART SoCs.

Signed-off-by: Jonas Jensen 
---

Notes:
Changes since v3:

1. don't rely on structs for register offsets
2. use DT probed DMA, remove extern bool moxart_filter_fn()
3. remove unnecessary ternary operator in moxart_get_ro
4. check return value of devm_request_irq

device tree bindings document:
5. add description of DT DMA node

Applies to next-20130806

 .../devicetree/bindings/mmc/moxa,moxart-mmc.txt|  28 +
 drivers/mmc/host/Kconfig   |   9 +
 drivers/mmc/host/Makefile  |   1 +
 drivers/mmc/host/sdhci-moxart.c| 917 +
 4 files changed, 955 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
 create mode 100644 drivers/mmc/host/sdhci-moxart.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..c9ad588
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
@@ -0,0 +1,28 @@
+MOXA ART SD Host Controller Interface
+
+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 = <&coreclk>;
+   dmas =  <&dma 0 5>,
+   <&dma 1 5>;
+   dma-names = "tx", "rx";
+   };
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 8a4c066..3c246390 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -271,6 +271,15 @@ config MMC_SDHCI_BCM2835
 
  If unsure, say N.
 
+config MMC_SDHCI_MOXART
+   tristate "MOXART SD Host Controller Interface support"
+   depends on ARCH_MOXART && MMC
+   help
+ This selects the MOXART SD Host Controller Interface.
+ 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 d422e21..c91317f 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -63,6 +63,7 @@ obj-$(CONFIG_MMC_SDHCI_OF_ESDHC)  += sdhci-of-esdhc.o
 obj-$(CONFIG_MMC_SDHCI_OF_HLWD)+= sdhci-of-hlwd.o
 obj-$(CONFIG_MMC_SDHCI_BCM_KONA)   += sdhci-bcm-kona.o
 obj-$(CONFIG_MMC_SDHCI_BCM2835)+= sdhci-bcm2835.o
+obj-$(CONFIG_MMC_SDHCI_MOXART) += sdhci-moxart.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
CFLAGS-cb710-mmc+= -DDEBUG
diff --git a/drivers/mmc/host/sdhci-moxart.c b/drivers/mmc/host/sdhci-moxart.c
new file mode 100644
index 000..c8c1807
--- /dev/null
+++ b/drivers/mmc/host/sdhci-moxart.c
@@ -0,0 +1,917 @@
+/*
+ * MOXA ART MMC host driver.
+ *
+ * Copyright (C) 2013 Jonas Jensen
+ *
+ * Jonas Jensen 
+ *
+ * Based on code from
+ * Moxa Technology 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 MSD_CMD_REG0
+#define MSD_ARG_REG4
+#define MSD_RESP0_REG  8
+#define MSD_RESP1_REG  0x0c
+#define MSD_RESP2_REG  0x10
+#define MSD_RESP3_REG  0x14
+#define MSD_RESP_CMD_REG   0x18
+#define MSD_DATA_CTRL_REG  0x1c
+#define MSD_DATA_TIMER_REG 0x20
+#define MSD_DATA_LEN_REG   0x24
+#define MSD_STATUS_REG 0x28
+#define MSD_CLEAR_REG  0x2c
+#define MSD_INT_MASK_REG   0x30
+#define MSD_POWER_CTRL_REG 0x34
+#define MSD_CLOCK_CTRL_REG 0x38
+#define MSD_BUS_WIDTH_REG  0x3c
+#define MSD_DATA_WIN_REG   0x40
+#define MSD_FEATURE_REG0x44
+#define MSD_REVISION_REG   0x48
+

[PATCH v3] mmc: sdhci-moxart: Add MOXA ART SDHCI driver

2013-07-29 Thread Jonas Jensen
Add SDHCI driver for MOXA ART SoCs.

Signed-off-by: Jonas Jensen 
---

Notes:
Changes since v2:

1. #include  because BIT() comes from there
2. reinsert dev_set_drvdata() in moxart_remove
3. remove MODULE_VERSION()

device tree bindings document:
4. describe compatible variable "Must be" instead of "Should be".
5. change description so it's from the point of view of the device

Applies to next-20130729

 .../devicetree/bindings/mmc/moxa,moxart-mmc.txt|  17 +
 drivers/mmc/host/Kconfig   |   9 +
 drivers/mmc/host/Makefile  |   1 +
 drivers/mmc/host/sdhci-moxart.c| 782 +
 drivers/mmc/host/sdhci-moxart.h| 155 
 5 files changed, 964 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
 create mode 100644 drivers/mmc/host/sdhci-moxart.c
 create mode 100644 drivers/mmc/host/sdhci-moxart.h

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..67782ad
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
@@ -0,0 +1,17 @@
+MOXA ART SD Host Controller Interface
+
+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
+
+Example:
+
+   mmc: mmc@98e0 {
+   compatible = "moxa,moxart-mmc";
+   reg = <0x98e0 0x5C>;
+   interrupts = <5 0>;
+   clocks = <&coreclk>;
+   };
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 8a4c066..3c246390 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -271,6 +271,15 @@ config MMC_SDHCI_BCM2835
 
  If unsure, say N.
 
+config MMC_SDHCI_MOXART
+   tristate "MOXART SD Host Controller Interface support"
+   depends on ARCH_MOXART && MMC
+   help
+ This selects the MOXART SD Host Controller Interface.
+ 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 d422e21..c91317f 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -63,6 +63,7 @@ obj-$(CONFIG_MMC_SDHCI_OF_ESDHC)  += sdhci-of-esdhc.o
 obj-$(CONFIG_MMC_SDHCI_OF_HLWD)+= sdhci-of-hlwd.o
 obj-$(CONFIG_MMC_SDHCI_BCM_KONA)   += sdhci-bcm-kona.o
 obj-$(CONFIG_MMC_SDHCI_BCM2835)+= sdhci-bcm2835.o
+obj-$(CONFIG_MMC_SDHCI_MOXART) += sdhci-moxart.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
CFLAGS-cb710-mmc+= -DDEBUG
diff --git a/drivers/mmc/host/sdhci-moxart.c b/drivers/mmc/host/sdhci-moxart.c
new file mode 100644
index 000..fa9056c
--- /dev/null
+++ b/drivers/mmc/host/sdhci-moxart.c
@@ -0,0 +1,782 @@
+/*
+ * MOXA ART MMC host driver.
+ *
+ * Copyright (C) 2013 Jonas Jensen
+ *
+ * Jonas Jensen 
+ *
+ * Based on code from
+ * Moxa Technology 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 "sdhci-moxart.h"
+
+#define DMA_FIFO_LEN_FORCE 0
+#define APB_DMA_SD_REQ_NO  5
+#define MIN_POWER (MMC_VDD_360 - MSD_SD_POWER_MASK)
+
+static inline void moxart_init_sg(struct moxart_host *host,
+ struct mmc_data *data)
+{
+   host->cur_sg = data->sg;
+   host->num_sg = data->sg_len;
+   host->remain = host->cur_sg->length;
+
+   if (host->remain > host->size)
+   host->remain = host->size;
+
+   data->error = MMC_ERR_NONE;
+}
+
+static inline int moxart_next_sg(struct moxart_host *host)
+{
+   int remain;
+   struct mmc_data *data = host->mrq->cmd->data;
+
+   host->cur_sg++;
+   host->num_sg--;
+
+   if (host->num_sg > 0) {
+   host->remain = host->cur_sg->length;
+   remain = host->size - data->bytes_xfered;
+   if (remain > 0 && remai

[PATCH v2] mmc: sdhci-moxart: Add MOXA ART SDHCI driver

2013-07-17 Thread Jonas Jensen
Add SDHCI driver for MOXA ART SoCs.

Signed-off-by: Jonas Jensen 
---

Notes:
Changes since v1:

1. remove IRQF_DISABLED
2. use devm_request_irq, remove free_irq
3. remove unnecessary dev_set_drvdata in moxart_remove
4. add devicetree bindings document
5. use BIT macro in header file

Applies to next-20130716

 .../devicetree/bindings/mmc/moxa,moxart-mmc.txt|  17 +
 drivers/mmc/host/Kconfig   |   9 +
 drivers/mmc/host/Makefile  |   1 +
 drivers/mmc/host/sdhci-moxart.c| 780 +
 drivers/mmc/host/sdhci-moxart.h| 155 
 5 files changed, 962 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
 create mode 100644 drivers/mmc/host/sdhci-moxart.c
 create mode 100644 drivers/mmc/host/sdhci-moxart.h

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..9ec8650
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/moxa,moxart-mmc.txt
@@ -0,0 +1,17 @@
+MOXA ART SD Host Controller Interface
+
+Required properties:
+
+- compatible : Should be "moxa,moxart-mmc"
+- reg : Should contain registers location and length
+- interrupts : Should contain the interrupt number
+- clocks : Should contain phandle for APB clock "clkapb"
+
+Example:
+
+   mmc: mmc@98e0 {
+   compatible = "moxa,moxart-mmc";
+   reg = <0x98e0 0x5C>;
+   interrupts = <5 0>;
+   clocks = <&clkapb>;
+   };
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 8a4c066..3c246390 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -271,6 +271,15 @@ config MMC_SDHCI_BCM2835
 
  If unsure, say N.
 
+config MMC_SDHCI_MOXART
+   tristate "MOXART SD Host Controller Interface support"
+   depends on ARCH_MOXART && MMC
+   help
+ This selects the MOXART SD Host Controller Interface.
+ 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 d422e21..c91317f 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -63,6 +63,7 @@ obj-$(CONFIG_MMC_SDHCI_OF_ESDHC)  += sdhci-of-esdhc.o
 obj-$(CONFIG_MMC_SDHCI_OF_HLWD)+= sdhci-of-hlwd.o
 obj-$(CONFIG_MMC_SDHCI_BCM_KONA)   += sdhci-bcm-kona.o
 obj-$(CONFIG_MMC_SDHCI_BCM2835)+= sdhci-bcm2835.o
+obj-$(CONFIG_MMC_SDHCI_MOXART) += sdhci-moxart.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
CFLAGS-cb710-mmc+= -DDEBUG
diff --git a/drivers/mmc/host/sdhci-moxart.c b/drivers/mmc/host/sdhci-moxart.c
new file mode 100644
index 000..9d809b5
--- /dev/null
+++ b/drivers/mmc/host/sdhci-moxart.c
@@ -0,0 +1,780 @@
+/*
+ * MOXA ART MMC host driver.
+ *
+ * Copyright (C) 2013 Jonas Jensen
+ *
+ * Jonas Jensen 
+ *
+ * Based on code from
+ * Moxa Technology 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 "sdhci-moxart.h"
+
+#define DMA_FIFO_LEN_FORCE 0
+#define APB_DMA_SD_REQ_NO  5
+#define MIN_POWER (MMC_VDD_360 - MSD_SD_POWER_MASK)
+
+static inline void moxart_init_sg(struct moxart_host *host,
+ struct mmc_data *data)
+{
+   host->cur_sg = data->sg;
+   host->num_sg = data->sg_len;
+   host->remain = host->cur_sg->length;
+
+   if (host->remain > host->size)
+   host->remain = host->size;
+
+   data->error = MMC_ERR_NONE;
+}
+
+static inline int moxart_next_sg(struct moxart_host *host)
+{
+   int remain;
+   struct mmc_data *data = host->mrq->cmd->data;
+
+   host->cur_sg++;
+   host->num_sg--;
+
+   if (host->num_sg > 0) {
+   host->remain = host->cur_sg->length;
+   remain = host->size - data->bytes_xfered;
+   if (remain > 0 && remain < host->remain)
+   host->remain = remain;
+   }
+
+   return host->num_sg;
+}
+
+static void moxa

[PATCH] mmc: sdhci-moxart: Add MOXA ART SDHCI driver

2013-07-10 Thread Jonas Jensen
Add SDHCI driver for MOXA ART SoCs.

Signed-off-by: Jonas Jensen 
---

Notes:
Applies to next-20130703

I know this is a large chunk and there are many pitfalls with
the controller. I give you my word it does work / seem to be stable,
with or without DMA. Any feedback is appreciated.

Tested by creating multiple directories/files and moving the card
back and forth to different reader.

IRQF_DISABLED is now pointless, remove it from request_irq?

 drivers/mmc/host/Kconfig|   9 +
 drivers/mmc/host/Makefile   |   1 +
 drivers/mmc/host/sdhci-moxart.c | 786 
 drivers/mmc/host/sdhci-moxart.h | 155 
 4 files changed, 951 insertions(+)
 create mode 100644 drivers/mmc/host/sdhci-moxart.c
 create mode 100644 drivers/mmc/host/sdhci-moxart.h

diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 1be2289..fb401c4 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -260,6 +260,15 @@ config MMC_SDHCI_BCM2835
 
  If unsure, say N.
 
+config MMC_SDHCI_MOXART
+   tristate "MOXART SD Host Controller Interface support"
+   depends on ARCH_MOXART && MMC
+   help
+ This selects the MOXART SD Host Controller Interface.
+ 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 67718c1..274199a 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_MMC_SDHCI_TEGRA) += sdhci-tegra.o
 obj-$(CONFIG_MMC_SDHCI_OF_ESDHC)   += sdhci-of-esdhc.o
 obj-$(CONFIG_MMC_SDHCI_OF_HLWD)+= sdhci-of-hlwd.o
 obj-$(CONFIG_MMC_SDHCI_BCM2835)+= sdhci-bcm2835.o
+obj-$(CONFIG_MMC_SDHCI_MOXART) += sdhci-moxart.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
CFLAGS-cb710-mmc+= -DDEBUG
diff --git a/drivers/mmc/host/sdhci-moxart.c b/drivers/mmc/host/sdhci-moxart.c
new file mode 100644
index 000..f5aaea6
--- /dev/null
+++ b/drivers/mmc/host/sdhci-moxart.c
@@ -0,0 +1,786 @@
+/*
+ * MOXA ART MMC host driver.
+ *
+ * Copyright (C) 2013 Jonas Jensen
+ *
+ * Jonas Jensen 
+ *
+ * Based on code from
+ * Moxa Technology 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 "sdhci-moxart.h"
+
+#define DMA_FIFO_LEN_FORCE 0
+#define APB_DMA_SD_REQ_NO  5
+#define MIN_POWER (MMC_VDD_360 - MSD_SD_POWER_MASK)
+
+static inline void moxart_init_sg(struct moxart_host *host,
+ struct mmc_data *data)
+{
+   host->cur_sg = data->sg;
+   host->num_sg = data->sg_len;
+   host->remain = host->cur_sg->length;
+
+   if (host->remain > host->size)
+   host->remain = host->size;
+
+   data->error = MMC_ERR_NONE;
+}
+
+static inline int moxart_next_sg(struct moxart_host *host)
+{
+   int remain;
+   struct mmc_data *data = host->mrq->cmd->data;
+
+   host->cur_sg++;
+   host->num_sg--;
+
+   if (host->num_sg > 0) {
+   host->remain = host->cur_sg->length;
+   remain = host->size - data->bytes_xfered;
+   if (remain > 0 && remain < host->remain)
+   host->remain = remain;
+   }
+
+   return host->num_sg;
+}
+
+static void moxart_send_command(struct moxart_host *host,
+   struct mmc_command *cmd)
+{
+   unsigned int status, cmdctrl;
+   int retry = 0;
+
+   dev_dbg(mmc_dev(host->mmc), "%s: cmd->opcode=%d\n",
+   __func__, cmd->opcode);
+
+   cmd->error = MMC_ERR_TIMEOUT;
+
+   writel(MSD_RSP_TIMEOUT | MSD_RSP_CRC_OK |
+  MSD_RSP_CRC_FAIL | MSD_CMD_SENT, &host->reg->clear);
+   writel(cmd->arg, &host->reg->argument);
+
+   cmdctrl = cmd->opcode & MSD_CMD_IDX_MASK;
+   if (cmdctrl == SD_APP_SET_BUS_WIDTH || cmdctrl == SD_APP_OP_COND ||
+   cmdctrl == SD_APP_SEND_SCR || cmdctrl == SD_APP_SD_STATUS ||
+   cmdctrl == SD_APP_SEND_NUM_WR_BLKS)
+   cmdctrl |= MSD_APP_CMD;
+
+   if (cmd->flags & MMC_RSP_136)
+   cmdctrl |= (MSD_LONG_RS

Re: [PATCH] ARM: mach-moxart: platform port for MOXA ART SoC

2013-03-17 Thread Jonas Jensen
Thank you for the feedback.

Some of the changes are sure to be a challenge for me, but I want to
move this forward, and having a list helps.

3.2.40 is as far as it'll go right now, nothing prints to UART
starting with 3.3.8 (last tested, it's somewhere around there).

I have been advised to enable early_printk (by landley on freenode IRC #edev).

Best regards,
Jonas
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] ARM: mach-moxart: platform port for MOXA ART SoC

2013-03-13 Thread Jonas Jensen
Hi,

I ask for feedback and to submit (if possible) a new ARM SoC platform
port. This is now near complete (I think) (tested on UC-7112-LX Plus)
and applies to 2.6.34.14.

The patch contains the following drivers and platform specific implementations:

* ARCH_MOXART (FA526 processor)
* 100Hz interrupt timer
* UART
* MTD map driver
* Ethernet driver (RTL8201CP)
* MMC driver
* MOXA Smartio/Industio family multiport serial driver
* RTC driver
* Watchdog driver
* GPIO driver

Predicted patch rejects below (in need of a solution, feedback is much
appreciated) because they are critical in areas of boot, MMC and TTY.

arch/arm/boot/compressed/head.S:
A valid (and unique) architecture ID is not loaded to r1. Looks like
the bootloader is broken, it should be doing this!
http://gicl.cs.drexel.edu/people/sevy/linux/ARM_Linux_boot_sequence.html

arch/arm/tools/mach-types:
Omitted (do not edit manually / add a new machine using
http://www.arm.linux.org.uk/developer/machines/?action=new). A fix to
this and above is not feasible as long as MOXA withholds bootloader
sources (requested without success).

drivers/char/mxser.c drivers/char/mxser.h: MOXA
SMARTIO/INDUSTIO/INTELLIO SERIAL CARD (Jiří Slabý):
Force board setup for CONFIG_ARCH_MOXART.
ASYNCB_CLOSING is avoided because of a lockup (infinite wait after
tty_wait_until_sent). Why this happens is unknown (to me) I'm hoping
someone (Jiří?) can shed light. SysRq trace @ http://ideone.com/e845mr
What significance does ASYNCB_CLOSING have?
Obviously, automatic detection is better but "mxser_read_register" is
pointless on this hardware. What to do instead? Is it better to make a
copy and submit a new driver?

drivers/mmc/core/sd.c:
The MMC controller is "special"? "UNSTUFF_BITS" is redefined here
http://repo.or.cz/w/linux-2.6.19-moxart.git/blob/50cdf2c57662f9f69c5615976412f76bfd73311a:/drivers/mmc/mmc.c
. Without the new macro it'll report the wrong geometry and prod_name.
I'm thinking a driver should never have to redefine UNSTUFF_BITS.
Possible workaround: modify bits (in driver) to line up as expected
before returning the response (mmc_request_done).


For reference, this is my previous post from a few months back:
http://lists.infradead.org/pipermail/linux-arm-kernel/2012-December/137130.html

Gitweb: 
http://repo.or.cz/w/linux-2.6.34.14-moxart.git/commitdiff/?h=3bc2e98ebb92961e1c5992736186920cd070f4ee&hp=b7f1d43323eceb02fd663a71eb2f8be9c17e6740

Download link (size: 193K):
https://linux-2-6-34-14-moxart.googlecode.com/files/linux-2.6.34.14-moxart.patch
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html