Merge branch 'master' into upstream
[pandora-kernel.git] / arch / arm / plat-mxc / devices / platform-imx-dma.c
1 /*
2  * Copyright (C) 2010 Pengutronix
3  * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 2 as published by the
7  * Free Software Foundation.
8  */
9 #include <linux/compiler.h>
10 #include <linux/err.h>
11 #include <linux/init.h>
12
13 #include <mach/hardware.h>
14 #include <mach/devices-common.h>
15 #include <mach/sdma.h>
16
17 struct imx_imx_sdma_data {
18         resource_size_t iobase;
19         resource_size_t irq;
20         struct sdma_platform_data pdata;
21 };
22
23 #define imx_imx_sdma_data_entry_single(soc, _sdma_version, _cpu_name, _to_version)\
24         {                                                               \
25                 .iobase = soc ## _SDMA ## _BASE_ADDR,                   \
26                 .irq = soc ## _INT_SDMA,                                \
27                 .pdata = {                                              \
28                         .sdma_version = _sdma_version,                  \
29                         .cpu_name = _cpu_name,                          \
30                         .to_version = _to_version,                      \
31                 },                                                      \
32         }
33
34 #ifdef CONFIG_ARCH_MX25
35 const struct imx_imx_sdma_data imx25_imx_sdma_data __initconst =
36         imx_imx_sdma_data_entry_single(MX25, 1, "imx25", 0);
37 #endif /* ifdef CONFIG_ARCH_MX25 */
38
39 #ifdef CONFIG_ARCH_MX31
40 struct imx_imx_sdma_data imx31_imx_sdma_data __initdata =
41         imx_imx_sdma_data_entry_single(MX31, 1, "imx31", 0);
42 #endif /* ifdef CONFIG_ARCH_MX31 */
43
44 #ifdef CONFIG_ARCH_MX35
45 struct imx_imx_sdma_data imx35_imx_sdma_data __initdata =
46         imx_imx_sdma_data_entry_single(MX35, 2, "imx35", 0);
47 #endif /* ifdef CONFIG_ARCH_MX35 */
48
49 #ifdef CONFIG_ARCH_MX51
50 const struct imx_imx_sdma_data imx51_imx_sdma_data __initconst =
51         imx_imx_sdma_data_entry_single(MX51, 2, "imx51", 0);
52 #endif /* ifdef CONFIG_ARCH_MX51 */
53
54 static struct platform_device __init __maybe_unused *imx_add_imx_sdma(
55                 const struct imx_imx_sdma_data *data)
56 {
57         struct resource res[] = {
58                 {
59                         .start = data->iobase,
60                         .end = data->iobase + SZ_4K - 1,
61                         .flags = IORESOURCE_MEM,
62                 }, {
63                         .start = data->irq,
64                         .end = data->irq,
65                         .flags = IORESOURCE_IRQ,
66                 },
67         };
68
69         return imx_add_platform_device("imx-sdma", -1,
70                         res, ARRAY_SIZE(res),
71                         &data->pdata, sizeof(data->pdata));
72 }
73
74 static struct platform_device __init __maybe_unused *imx_add_imx_dma(void)
75 {
76         return imx_add_platform_device("imx-dma", -1, NULL, 0, NULL, 0);
77 }
78
79 static int __init imxXX_add_imx_dma(void)
80 {
81         struct platform_device *ret;
82
83 #if defined(CONFIG_SOC_IMX21) || defined(CONFIG_SOC_IMX27)
84         if (cpu_is_mx21() || cpu_is_mx27())
85                 ret = imx_add_imx_dma();
86         else
87 #endif
88
89 #if defined(CONFIG_ARCH_MX25)
90         if (cpu_is_mx25())
91                 ret = imx_add_imx_sdma(&imx25_imx_sdma_data);
92         else
93 #endif
94
95 #if defined(CONFIG_ARCH_MX31)
96         if (cpu_is_mx31()) {
97                 imx31_imx_sdma_data.pdata.to_version = mx31_revision() >> 4;
98                 ret = imx_add_imx_sdma(&imx31_imx_sdma_data);
99         } else
100 #endif
101
102 #if defined(CONFIG_ARCH_MX35)
103         if (cpu_is_mx35()) {
104                 imx35_imx_sdma_data.pdata.to_version = mx35_revision() >> 4;
105                 ret = imx_add_imx_sdma(&imx35_imx_sdma_data);
106         } else
107 #endif
108
109 #if defined(CONFIG_ARCH_MX51)
110         if (cpu_is_mx51())
111                 ret = imx_add_imx_sdma(&imx51_imx_sdma_data);
112         else
113 #endif
114                 ret = ERR_PTR(-ENODEV);
115
116         if (IS_ERR(ret))
117                 return PTR_ERR(ret);
118
119         return 0;
120 }
121 arch_initcall(imxXX_add_imx_dma);