Merge branch 'iommu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip...
[linux-2.6] / arch / arm / mach-pxa / csb726.c
1 /*
2  *  Support for Cogent CSB726
3  *
4  *  Copyright (c) 2008 Dmitry Eremin-Solenikov
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License version 2 as
8  *  published by the Free Software Foundation.
9  *
10  */
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/io.h>
14 #include <linux/gpio.h>
15 #include <linux/platform_device.h>
16 #include <linux/mtd/physmap.h>
17 #include <linux/mtd/partitions.h>
18 #include <linux/sm501.h>
19
20 #include <asm/mach-types.h>
21 #include <asm/mach/arch.h>
22 #include <mach/csb726.h>
23 #include <mach/mfp-pxa27x.h>
24 #include <mach/i2c.h>
25 #include <mach/mmc.h>
26 #include <mach/ohci.h>
27 #include <mach/pxa2xx-regs.h>
28
29 #include "generic.h"
30 #include "devices.h"
31
32 /*
33  * n/a: 2, 5, 6, 7, 8, 23, 24, 25, 26, 27, 87, 88, 89,
34  * nu: 58 -- 77, 90, 91, 93, 102, 105-108, 114-116,
35  * XXX: 21,
36  * XXX: 79 CS_3 for LAN9215 or PSKTSEL on R2, R3
37  * XXX: 33 CS_5 for LAN9215 on R1
38  */
39
40 static unsigned long csb726_pin_config[] = {
41         GPIO78_nCS_2, /* EXP_CS */
42         GPIO79_nCS_3, /* SMSC9215 */
43         GPIO80_nCS_4, /* SM501 */
44
45         GPIO52_GPIO, /* #SMSC9251 int */
46         GPIO53_GPIO, /* SM501 int */
47
48         GPIO1_GPIO, /* GPIO0 */
49         GPIO11_GPIO, /* GPIO1 */
50         GPIO9_GPIO, /* GPIO2 */
51         GPIO10_GPIO, /* GPIO3 */
52         GPIO16_PWM0_OUT, /* or GPIO4 */
53         GPIO17_PWM1_OUT, /* or GPIO5 */
54         GPIO94_GPIO, /* GPIO6 */
55         GPIO95_GPIO, /* GPIO7 */
56         GPIO96_GPIO, /* GPIO8 */
57         GPIO97_GPIO, /* GPIO9 */
58         GPIO15_GPIO, /* EXP_IRQ */
59         GPIO18_RDY, /* EXP_WAIT */
60
61         GPIO0_GPIO, /* PWR_INT */
62         GPIO104_GPIO, /* PWR_OFF */
63
64         GPIO12_GPIO, /* touch irq */
65
66         GPIO13_SSP2_TXD,
67         GPIO14_SSP2_SFRM,
68         MFP_CFG_OUT(GPIO19, AF1, DRIVE_LOW),/* SSP2_SYSCLK */
69         GPIO22_SSP2_SCLK,
70
71         GPIO81_SSP3_TXD,
72         GPIO82_SSP3_RXD,
73         GPIO83_SSP3_SFRM,
74         GPIO84_SSP3_SCLK,
75
76         GPIO20_GPIO, /* SDIO int */
77         GPIO32_MMC_CLK,
78         GPIO92_MMC_DAT_0,
79         GPIO109_MMC_DAT_1,
80         GPIO110_MMC_DAT_2,
81         GPIO111_MMC_DAT_3,
82         GPIO112_MMC_CMD,
83         GPIO100_GPIO, /* SD CD */
84         GPIO101_GPIO, /* SD WP */
85
86         GPIO28_AC97_BITCLK,
87         GPIO29_AC97_SDATA_IN_0,
88         GPIO30_AC97_SDATA_OUT,
89         GPIO31_AC97_SYNC,
90         GPIO113_AC97_nRESET,
91
92         GPIO34_FFUART_RXD,
93         GPIO35_FFUART_CTS,
94         GPIO36_FFUART_DCD,
95         GPIO37_FFUART_DSR,
96         GPIO38_FFUART_RI,
97         GPIO39_FFUART_TXD,
98         GPIO40_FFUART_DTR,
99         GPIO41_FFUART_RTS,
100
101         GPIO42_BTUART_RXD,
102         GPIO43_BTUART_TXD,
103         GPIO44_BTUART_CTS,
104         GPIO45_BTUART_RTS,
105
106         GPIO46_STUART_RXD,
107         GPIO47_STUART_TXD,
108
109         GPIO48_nPOE,
110         GPIO49_nPWE,
111         GPIO50_nPIOR,
112         GPIO51_nPIOW,
113         GPIO54_nPCE_2,
114         GPIO55_nPREG,
115         GPIO56_nPWAIT,
116         GPIO57_nIOIS16, /* maybe unused */
117         GPIO85_nPCE_1,
118         GPIO98_GPIO, /* CF IRQ */
119         GPIO99_GPIO, /* CF CD */
120         GPIO103_GPIO, /* Reset */
121
122         GPIO117_I2C_SCL,
123         GPIO118_I2C_SDA,
124 };
125
126 static struct pxamci_platform_data csb726_mci_data;
127
128 static int csb726_mci_init(struct device *dev,
129                 irq_handler_t detect, void *data)
130 {
131         int err;
132
133         csb726_mci_data.detect_delay = msecs_to_jiffies(500);
134
135         err = gpio_request(CSB726_GPIO_MMC_DETECT, "MMC detect");
136         if (err)
137                 goto err_det_req;
138
139         err = gpio_direction_input(CSB726_GPIO_MMC_DETECT);
140         if (err)
141                 goto err_det_dir;
142
143         err = gpio_request(CSB726_GPIO_MMC_RO, "MMC ro");
144         if (err)
145                 goto err_ro_req;
146
147         err = gpio_direction_input(CSB726_GPIO_MMC_RO);
148         if (err)
149                 goto err_ro_dir;
150
151         err = request_irq(gpio_to_irq(CSB726_GPIO_MMC_DETECT), detect,
152                         IRQF_DISABLED, "MMC card detect", data);
153         if (err)
154                 goto err_irq;
155
156         return 0;
157
158 err_irq:
159 err_ro_dir:
160         gpio_free(CSB726_GPIO_MMC_RO);
161 err_ro_req:
162 err_det_dir:
163         gpio_free(CSB726_GPIO_MMC_DETECT);
164 err_det_req:
165         return err;
166 }
167
168 static int csb726_mci_get_ro(struct device *dev)
169 {
170         return gpio_get_value(CSB726_GPIO_MMC_RO);
171 }
172
173 static void csb726_mci_exit(struct device *dev, void *data)
174 {
175         free_irq(gpio_to_irq(CSB726_GPIO_MMC_DETECT), data);
176         gpio_free(CSB726_GPIO_MMC_RO);
177         gpio_free(CSB726_GPIO_MMC_DETECT);
178 }
179
180 static struct pxamci_platform_data csb726_mci = {
181         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
182         .init           = csb726_mci_init,
183         .get_ro         = csb726_mci_get_ro,
184         /* FIXME setpower */
185         .exit           = csb726_mci_exit,
186 };
187
188 static struct pxaohci_platform_data csb726_ohci_platform_data = {
189         .port_mode      = PMM_NPS_MODE,
190         .flags          = ENABLE_PORT1 | NO_OC_PROTECTION,
191 };
192
193 static struct mtd_partition csb726_flash_partitions[] = {
194         {
195                 .name           = "Bootloader",
196                 .offset         = 0,
197                 .size           = CSB726_FLASH_uMON,
198                 .mask_flags     = MTD_WRITEABLE  /* force read-only */
199         },
200         {
201                 .name           = "root",
202                 .offset         = MTDPART_OFS_APPEND,
203                 .size           = MTDPART_SIZ_FULL,
204         }
205 };
206
207 static struct physmap_flash_data csb726_flash_data = {
208         .width          = 2,
209         .parts          = csb726_flash_partitions,
210         .nr_parts       = ARRAY_SIZE(csb726_flash_partitions),
211 };
212
213 static struct resource csb726_flash_resources[] = {
214         {
215                 .start          = PXA_CS0_PHYS,
216                 .end            = PXA_CS0_PHYS + CSB726_FLASH_SIZE - 1 ,
217                 .flags          = IORESOURCE_MEM,
218         }
219 };
220
221 static struct platform_device csb726_flash = {
222         .name           = "physmap-flash",
223         .dev            = {
224                 .platform_data  = &csb726_flash_data,
225         },
226         .resource       = csb726_flash_resources,
227         .num_resources  = ARRAY_SIZE(csb726_flash_resources),
228 };
229
230 static struct resource csb726_sm501_resources[] = {
231         {
232                 .start          = PXA_CS4_PHYS,
233                 .end            = PXA_CS4_PHYS + SZ_8M - 1,
234                 .flags          = IORESOURCE_MEM,
235                 .name           = "sm501-localmem",
236         },
237         {
238                 .start          = PXA_CS4_PHYS + SZ_64M - SZ_2M,
239                 .end            = PXA_CS4_PHYS + SZ_64M - 1,
240                 .flags          = IORESOURCE_MEM,
241                 .name           = "sm501-regs",
242         },
243         {
244                 .start          = CSB726_IRQ_SM501,
245                 .end            = CSB726_IRQ_SM501,
246                 .flags          = IORESOURCE_IRQ,
247         },
248 };
249
250 static struct sm501_initdata csb726_sm501_initdata = {
251 /*      .devices        = SM501_USE_USB_HOST, */
252         .devices        = SM501_USE_USB_HOST | SM501_USE_UART0 | SM501_USE_UART1,
253 };
254
255 static struct sm501_platdata csb726_sm501_platdata = {
256         .init           = &csb726_sm501_initdata,
257 };
258
259 static struct platform_device csb726_sm501 = {
260         .name           = "sm501",
261         .id             = 0,
262         .num_resources  = ARRAY_SIZE(csb726_sm501_resources),
263         .resource       = csb726_sm501_resources,
264         .dev            = {
265                 .platform_data = &csb726_sm501_platdata,
266         },
267 };
268
269 static struct resource csb726_lan_resources[] = {
270         {
271                 .start  = PXA_CS3_PHYS,
272                 .end    = PXA_CS3_PHYS + SZ_64K - 1,
273                 .flags  = IORESOURCE_MEM,
274         },
275         {
276                 .start  = CSB726_IRQ_LAN,
277                 .end    = CSB726_IRQ_LAN,
278                 .flags  = IORESOURCE_IRQ,
279         },
280 };
281
282 static struct platform_device csb726_lan = {
283         .name           = "smc911x",
284         .id             = -1,
285         .num_resources  = ARRAY_SIZE(csb726_lan_resources),
286         .resource       = csb726_lan_resources,
287 };
288
289 static struct platform_device *devices[] __initdata = {
290         &csb726_flash,
291         &csb726_sm501,
292         &csb726_lan,
293 };
294
295 static void __init csb726_init(void)
296 {
297         pxa2xx_mfp_config(ARRAY_AND_SIZE(csb726_pin_config));
298 /*      MSC1 = 0x7ffc3ffc; *//* LAN9215/EXP_CS */
299 /*      MSC2 = 0x06697ff4; *//* none/SM501 */
300         MSC2 = (MSC2 & ~0xffff) | 0x7ff4; /* SM501 */
301
302         pxa_set_i2c_info(NULL);
303         pxa27x_set_i2c_power_info(NULL);
304         pxa_set_mci_info(&csb726_mci);
305         pxa_set_ohci_info(&csb726_ohci_platform_data);
306
307         platform_add_devices(devices, ARRAY_SIZE(devices));
308 }
309
310 MACHINE_START(CSB726, "Cogent CSB726")
311         .phys_io        = 0x40000000,
312         .boot_params    = 0xa0000100,
313         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
314         .map_io         = pxa_map_io,
315         .init_irq       = pxa27x_init_irq,
316         .init_machine   = csb726_init,
317         .timer          = &pxa_timer,
318 MACHINE_END