aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/spi/Kconfig4
-rw-r--r--drivers/spi/Makefile1
-rw-r--r--drivers/spi/dw_spi_mmio.c148
3 files changed, 153 insertions, 0 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 28becdd4dea9..201746ad825c 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -334,6 +334,10 @@ config SPI_DW_PCI
334 tristate "PCI interface driver for DW SPI core" 334 tristate "PCI interface driver for DW SPI core"
335 depends on SPI_DESIGNWARE && PCI 335 depends on SPI_DESIGNWARE && PCI
336 336
337config SPI_DW_MMIO
338 tristate "Memory-mapped io interface driver for DW SPI core"
339 depends on SPI_DESIGNWARE
340
337# 341#
338# There are lots of SPI device types, with sensors and memory 342# There are lots of SPI device types, with sensors and memory
339# being probably the most widely used ones. 343# being probably the most widely used ones.
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index d3a65ab8ebbf..d7d0f89b797b 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_SPI_COLDFIRE_QSPI) += coldfire_qspi.o
20obj-$(CONFIG_SPI_DAVINCI) += davinci_spi.o 20obj-$(CONFIG_SPI_DAVINCI) += davinci_spi.o
21obj-$(CONFIG_SPI_DESIGNWARE) += dw_spi.o 21obj-$(CONFIG_SPI_DESIGNWARE) += dw_spi.o
22obj-$(CONFIG_SPI_DW_PCI) += dw_spi_pci.o 22obj-$(CONFIG_SPI_DW_PCI) += dw_spi_pci.o
23obj-$(CONFIG_SPI_DW_MMIO) += dw_spi_mmio.o
23obj-$(CONFIG_SPI_GPIO) += spi_gpio.o 24obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
24obj-$(CONFIG_SPI_IMX) += spi_imx.o 25obj-$(CONFIG_SPI_IMX) += spi_imx.o
25obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o 26obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
diff --git a/drivers/spi/dw_spi_mmio.c b/drivers/spi/dw_spi_mmio.c
new file mode 100644
index 000000000000..26c4b49bdd5c
--- /dev/null
+++ b/drivers/spi/dw_spi_mmio.c
@@ -0,0 +1,148 @@
1/*
2 * dw_spi_mmio.c - Memory-mapped interface driver for DW SPI Core
3 *
4 * Copyright (c) 2010, Octasic semiconductor.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 */
10
11#include <linux/clk.h>
12#include <linux/interrupt.h>
13#include <linux/platform_device.h>
14#include <linux/spi/dw_spi.h>
15#include <linux/spi/spi.h>
16
17#define DRIVER_NAME "dw_spi_mmio"
18
19struct dw_spi_mmio {
20 struct dw_spi dws;
21 struct clk *clk;
22};
23
24static int __devinit dw_spi_mmio_probe(struct platform_device *pdev)
25{
26 struct dw_spi_mmio *dwsmmio;
27 struct dw_spi *dws;
28 struct resource *mem, *ioarea;
29 int ret;
30
31 dwsmmio = kzalloc(sizeof(struct dw_spi_mmio), GFP_KERNEL);
32 if (!dwsmmio) {
33 ret = -ENOMEM;
34 goto err_end;
35 }
36
37 dws = &dwsmmio->dws;
38
39 /* Get basic io resource and map it */
40 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
41 if (!mem) {
42 dev_err(&pdev->dev, "no mem resource?\n");
43 ret = -EINVAL;
44 goto err_kfree;
45 }
46
47 ioarea = request_mem_region(mem->start, resource_size(mem),
48 pdev->name);
49 if (!ioarea) {
50 dev_err(&pdev->dev, "SPI region already claimed\n");
51 ret = -EBUSY;
52 goto err_kfree;
53 }
54
55 dws->regs = ioremap_nocache(mem->start, resource_size(mem));
56 if (!dws->regs) {
57 dev_err(&pdev->dev, "SPI region already mapped\n");
58 ret = -ENOMEM;
59 goto err_release_reg;
60 }
61
62 dws->irq = platform_get_irq(pdev, 0);
63 if (dws->irq < 0) {
64 dev_err(&pdev->dev, "no irq resource?\n");
65 ret = dws->irq; /* -ENXIO */
66 goto err_unmap;
67 }
68
69 dwsmmio->clk = clk_get(&pdev->dev, NULL);
70 if (!dwsmmio->clk) {
71 ret = -ENODEV;
72 goto err_irq;
73 }
74 clk_enable(dwsmmio->clk);
75
76 dws->parent_dev = &pdev->dev;
77 dws->bus_num = 0;
78 dws->num_cs = 4;
79 dws->max_freq = clk_get_rate(dwsmmio->clk);
80
81 ret = dw_spi_add_host(dws);
82 if (ret)
83 goto err_clk;
84
85 platform_set_drvdata(pdev, dwsmmio);
86 return 0;
87
88err_clk:
89 clk_disable(dwsmmio->clk);
90 clk_put(dwsmmio->clk);
91 dwsmmio->clk = NULL;
92err_irq:
93 free_irq(dws->irq, dws);
94err_unmap:
95 iounmap(dws->regs);
96err_release_reg:
97 release_mem_region(mem->start, resource_size(mem));
98err_kfree:
99 kfree(dwsmmio);
100err_end:
101 return ret;
102}
103
104static int __devexit dw_spi_mmio_remove(struct platform_device *pdev)
105{
106 struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev);
107 struct resource *mem;
108
109 platform_set_drvdata(pdev, NULL);
110
111 clk_disable(dwsmmio->clk);
112 clk_put(dwsmmio->clk);
113 dwsmmio->clk = NULL;
114
115 free_irq(dwsmmio->dws.irq, &dwsmmio->dws);
116 dw_spi_remove_host(&dwsmmio->dws);
117 iounmap(dwsmmio->dws.regs);
118 kfree(dwsmmio);
119
120 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
121 release_mem_region(mem->start, resource_size(mem));
122 return 0;
123}
124
125static struct platform_driver dw_spi_mmio_driver = {
126 .remove = __devexit_p(dw_spi_mmio_remove),
127 .driver = {
128 .name = DRIVER_NAME,
129 .owner = THIS_MODULE,
130 },
131};
132
133static int __init dw_spi_mmio_init(void)
134{
135 return platform_driver_probe(&dw_spi_mmio_driver, dw_spi_mmio_probe);
136}
137
138static void __exit dw_spi_mmio_exit(void)
139{
140 platform_driver_unregister(&dw_spi_mmio_driver);
141}
142
143module_init(dw_spi_mmio_init);
144module_exit(dw_spi_mmio_exit);
145
146MODULE_AUTHOR("Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>");
147MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core");
148MODULE_LICENSE("GPL v2");