Merge master.kernel.org:/pub/scm/linux/kernel/git/dtor/input
[linux-2.6] / arch / arm / mach-pxa / lubbock.c
1 /*
2  *  linux/arch/arm/mach-pxa/lubbock.c
3  *
4  *  Support for the Intel DBPXA250 Development Platform.
5  *
6  *  Author:     Nicolas Pitre
7  *  Created:    Jun 15, 2001
8  *  Copyright:  MontaVista Software Inc.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License version 2 as
12  *  published by the Free Software Foundation.
13  */
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/sysdev.h>
19 #include <linux/major.h>
20 #include <linux/fb.h>
21 #include <linux/interrupt.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/partitions.h>
24
25 #include <asm/setup.h>
26 #include <asm/memory.h>
27 #include <asm/mach-types.h>
28 #include <asm/hardware.h>
29 #include <asm/irq.h>
30 #include <asm/sizes.h>
31
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34 #include <asm/mach/irq.h>
35 #include <asm/mach/flash.h>
36
37 #include <asm/hardware/sa1111.h>
38
39 #include <asm/arch/pxa-regs.h>
40 #include <asm/arch/lubbock.h>
41 #include <asm/arch/udc.h>
42 #include <asm/arch/irda.h>
43 #include <asm/arch/pxafb.h>
44 #include <asm/arch/mmc.h>
45
46 #include "generic.h"
47
48
49 #define LUB_MISC_WR             __LUB_REG(LUBBOCK_FPGA_PHYS + 0x080)
50
51 void lubbock_set_misc_wr(unsigned int mask, unsigned int set)
52 {
53         unsigned long flags;
54
55         local_irq_save(flags);
56         LUB_MISC_WR = (LUB_MISC_WR & ~mask) | (set & mask);
57         local_irq_restore(flags);
58 }
59 EXPORT_SYMBOL(lubbock_set_misc_wr);
60
61 static unsigned long lubbock_irq_enabled;
62
63 static void lubbock_mask_irq(unsigned int irq)
64 {
65         int lubbock_irq = (irq - LUBBOCK_IRQ(0));
66         LUB_IRQ_MASK_EN = (lubbock_irq_enabled &= ~(1 << lubbock_irq));
67 }
68
69 static void lubbock_unmask_irq(unsigned int irq)
70 {
71         int lubbock_irq = (irq - LUBBOCK_IRQ(0));
72         /* the irq can be acknowledged only if deasserted, so it's done here */
73         LUB_IRQ_SET_CLR &= ~(1 << lubbock_irq);
74         LUB_IRQ_MASK_EN = (lubbock_irq_enabled |= (1 << lubbock_irq));
75 }
76
77 static struct irqchip lubbock_irq_chip = {
78         .ack            = lubbock_mask_irq,
79         .mask           = lubbock_mask_irq,
80         .unmask         = lubbock_unmask_irq,
81 };
82
83 static void lubbock_irq_handler(unsigned int irq, struct irqdesc *desc,
84                                 struct pt_regs *regs)
85 {
86         unsigned long pending = LUB_IRQ_SET_CLR & lubbock_irq_enabled;
87         do {
88                 GEDR(0) = GPIO_bit(0);  /* clear our parent irq */
89                 if (likely(pending)) {
90                         irq = LUBBOCK_IRQ(0) + __ffs(pending);
91                         desc = irq_desc + irq;
92                         desc_handle_irq(irq, desc, regs);
93                 }
94                 pending = LUB_IRQ_SET_CLR & lubbock_irq_enabled;
95         } while (pending);
96 }
97
98 static void __init lubbock_init_irq(void)
99 {
100         int irq;
101
102         pxa_init_irq();
103
104         /* setup extra lubbock irqs */
105         for (irq = LUBBOCK_IRQ(0); irq <= LUBBOCK_LAST_IRQ; irq++) {
106                 set_irq_chip(irq, &lubbock_irq_chip);
107                 set_irq_handler(irq, do_level_IRQ);
108                 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
109         }
110
111         set_irq_chained_handler(IRQ_GPIO(0), lubbock_irq_handler);
112         set_irq_type(IRQ_GPIO(0), IRQT_FALLING);
113 }
114
115 #ifdef CONFIG_PM
116
117 static int lubbock_irq_resume(struct sys_device *dev)
118 {
119         LUB_IRQ_MASK_EN = lubbock_irq_enabled;
120         return 0;
121 }
122
123 static struct sysdev_class lubbock_irq_sysclass = {
124         set_kset_name("cpld_irq"),
125         .resume = lubbock_irq_resume,
126 };
127
128 static struct sys_device lubbock_irq_device = {
129         .cls = &lubbock_irq_sysclass,
130 };
131
132 static int __init lubbock_irq_device_init(void)
133 {
134         int ret = sysdev_class_register(&lubbock_irq_sysclass);
135         if (ret == 0)
136                 ret = sysdev_register(&lubbock_irq_device);
137         return ret;
138 }
139
140 device_initcall(lubbock_irq_device_init);
141
142 #endif
143
144 static int lubbock_udc_is_connected(void)
145 {
146         return (LUB_MISC_RD & (1 << 9)) == 0;
147 }
148
149 static struct pxa2xx_udc_mach_info udc_info __initdata = {
150         .udc_is_connected       = lubbock_udc_is_connected,
151         // no D+ pullup; lubbock can't connect/disconnect in software
152 };
153
154 static struct platform_device lub_audio_device = {
155         .name           = "pxa2xx-ac97",
156         .id             = -1,
157 };
158
159 static struct resource sa1111_resources[] = {
160         [0] = {
161                 .start  = 0x10000000,
162                 .end    = 0x10001fff,
163                 .flags  = IORESOURCE_MEM,
164         },
165         [1] = {
166                 .start  = LUBBOCK_SA1111_IRQ,
167                 .end    = LUBBOCK_SA1111_IRQ,
168                 .flags  = IORESOURCE_IRQ,
169         },
170 };
171
172 static struct platform_device sa1111_device = {
173         .name           = "sa1111",
174         .id             = -1,
175         .num_resources  = ARRAY_SIZE(sa1111_resources),
176         .resource       = sa1111_resources,
177 };
178
179 static struct resource smc91x_resources[] = {
180         [0] = {
181                 .name   = "smc91x-regs",
182                 .start  = 0x0c000c00,
183                 .end    = 0x0c0fffff,
184                 .flags  = IORESOURCE_MEM,
185         },
186         [1] = {
187                 .start  = LUBBOCK_ETH_IRQ,
188                 .end    = LUBBOCK_ETH_IRQ,
189                 .flags  = IORESOURCE_IRQ,
190         },
191         [2] = {
192                 .name   = "smc91x-attrib",
193                 .start  = 0x0e000000,
194                 .end    = 0x0e0fffff,
195                 .flags  = IORESOURCE_MEM,
196         },
197 };
198
199 static struct platform_device smc91x_device = {
200         .name           = "smc91x",
201         .id             = -1,
202         .num_resources  = ARRAY_SIZE(smc91x_resources),
203         .resource       = smc91x_resources,
204 };
205
206 static struct resource flash_resources[] = {
207         [0] = {
208                 .start  = 0x00000000,
209                 .end    = SZ_64M - 1,
210                 .flags  = IORESOURCE_MEM,
211         },
212         [1] = {
213                 .start  = 0x04000000,
214                 .end    = 0x04000000 + SZ_64M - 1,
215                 .flags  = IORESOURCE_MEM,
216         },
217 };
218
219 static struct mtd_partition lubbock_partitions[] = {
220         {
221                 .name =         "Bootloader",
222                 .size =         0x00040000,
223                 .offset =       0,
224                 .mask_flags =   MTD_WRITEABLE  /* force read-only */
225         },{
226                 .name =         "Kernel",
227                 .size =         0x00100000,
228                 .offset =       0x00040000,
229         },{
230                 .name =         "Filesystem",
231                 .size =         MTDPART_SIZ_FULL,
232                 .offset =       0x00140000
233         }
234 };
235
236 static struct flash_platform_data lubbock_flash_data[2] = {
237         {
238                 .map_name       = "cfi_probe",
239                 .parts          = lubbock_partitions,
240                 .nr_parts       = ARRAY_SIZE(lubbock_partitions),
241         }, {
242                 .map_name       = "cfi_probe",
243                 .parts          = NULL,
244                 .nr_parts       = 0,
245         }
246 };
247
248 static struct platform_device lubbock_flash_device[2] = {
249         {
250                 .name           = "pxa2xx-flash",
251                 .id             = 0,
252                 .dev = {
253                         .platform_data = &lubbock_flash_data[0],
254                 },
255                 .resource = &flash_resources[0],
256                 .num_resources = 1,
257         },
258         {
259                 .name           = "pxa2xx-flash",
260                 .id             = 1,
261                 .dev = {
262                         .platform_data = &lubbock_flash_data[1],
263                 },
264                 .resource = &flash_resources[1],
265                 .num_resources = 1,
266         },
267 };
268
269 static struct platform_device *devices[] __initdata = {
270         &sa1111_device,
271         &lub_audio_device,
272         &smc91x_device,
273         &lubbock_flash_device[0],
274         &lubbock_flash_device[1],
275 };
276
277 static struct pxafb_mach_info sharp_lm8v31 __initdata = {
278         .pixclock       = 270000,
279         .xres           = 640,
280         .yres           = 480,
281         .bpp            = 16,
282         .hsync_len      = 1,
283         .left_margin    = 3,
284         .right_margin   = 3,
285         .vsync_len      = 1,
286         .upper_margin   = 0,
287         .lower_margin   = 0,
288         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
289         .cmap_greyscale = 0,
290         .cmap_inverse   = 0,
291         .cmap_static    = 0,
292         .lccr0          = LCCR0_SDS,
293         .lccr3          = LCCR3_PCP | LCCR3_Acb(255),
294 };
295
296 #define MMC_POLL_RATE           msecs_to_jiffies(1000)
297
298 static void lubbock_mmc_poll(unsigned long);
299 static irqreturn_t (*mmc_detect_int)(int, void *, struct pt_regs *);
300
301 static struct timer_list mmc_timer = {
302         .function       = lubbock_mmc_poll,
303 };
304
305 static void lubbock_mmc_poll(unsigned long data)
306 {
307         unsigned long flags;
308
309         /* clear any previous irq state, then ... */
310         local_irq_save(flags);
311         LUB_IRQ_SET_CLR &= ~(1 << 0);
312         local_irq_restore(flags);
313
314         /* poll until mmc/sd card is removed */
315         if (LUB_IRQ_SET_CLR & (1 << 0))
316                 mod_timer(&mmc_timer, jiffies + MMC_POLL_RATE);
317         else {
318                 (void) mmc_detect_int(LUBBOCK_SD_IRQ, (void *)data, NULL);
319                 enable_irq(LUBBOCK_SD_IRQ);
320         }
321 }
322
323 static irqreturn_t lubbock_detect_int(int irq, void *data, struct pt_regs *regs)
324 {
325         /* IRQ is level triggered; disable, and poll for removal */
326         disable_irq(irq);
327         mod_timer(&mmc_timer, jiffies + MMC_POLL_RATE);
328
329         return mmc_detect_int(irq, data, regs);
330 }
331
332 static int lubbock_mci_init(struct device *dev,
333                 irqreturn_t (*detect_int)(int, void *, struct pt_regs *),
334                 void *data)
335 {
336         /* setup GPIO for PXA25x MMC controller */
337         pxa_gpio_mode(GPIO6_MMCCLK_MD);
338         pxa_gpio_mode(GPIO8_MMCCS0_MD);
339
340         /* detect card insert/eject */
341         mmc_detect_int = detect_int;
342         init_timer(&mmc_timer);
343         mmc_timer.data = (unsigned long) data;
344         return request_irq(LUBBOCK_SD_IRQ, lubbock_detect_int,
345                         SA_SAMPLE_RANDOM, "lubbock-sd-detect", data);
346 }
347
348 static int lubbock_mci_get_ro(struct device *dev)
349 {
350         return (LUB_MISC_RD & (1 << 2)) != 0;
351 }
352
353 static void lubbock_mci_exit(struct device *dev, void *data)
354 {
355         free_irq(LUBBOCK_SD_IRQ, data);
356         del_timer_sync(&mmc_timer);
357 }
358
359 static struct pxamci_platform_data lubbock_mci_platform_data = {
360         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
361         .detect_delay   = 1,
362         .init           = lubbock_mci_init,
363         .get_ro         = lubbock_mci_get_ro,
364         .exit           = lubbock_mci_exit,
365 };
366
367 static void lubbock_irda_transceiver_mode(struct device *dev, int mode)
368 {
369         unsigned long flags;
370
371         local_irq_save(flags);
372         if (mode & IR_SIRMODE) {
373                 LUB_MISC_WR &= ~(1 << 4);
374         } else if (mode & IR_FIRMODE) {
375                 LUB_MISC_WR |= 1 << 4;
376         }
377         local_irq_restore(flags);
378 }
379
380 static struct pxaficp_platform_data lubbock_ficp_platform_data = {
381         .transceiver_cap  = IR_SIRMODE | IR_FIRMODE,
382         .transceiver_mode = lubbock_irda_transceiver_mode,
383 };
384
385 static void __init lubbock_init(void)
386 {
387         int flashboot = (LUB_CONF_SWITCHES & 1);
388
389         pxa_set_udc_info(&udc_info);
390         set_pxa_fb_info(&sharp_lm8v31);
391         pxa_set_mci_info(&lubbock_mci_platform_data);
392         pxa_set_ficp_info(&lubbock_ficp_platform_data);
393
394         lubbock_flash_data[0].width = lubbock_flash_data[1].width =
395                 (BOOT_DEF & 1) ? 2 : 4;
396         /* Compensate for the nROMBT switch which swaps the flash banks */
397         printk(KERN_NOTICE "Lubbock configured to boot from %s (bank %d)\n",
398                flashboot?"Flash":"ROM", flashboot);
399
400         lubbock_flash_data[flashboot^1].name = "application-flash";
401         lubbock_flash_data[flashboot].name = "boot-rom";
402         (void) platform_add_devices(devices, ARRAY_SIZE(devices));
403 }
404
405 static struct map_desc lubbock_io_desc[] __initdata = {
406         {       /* CPLD */
407                 .virtual        =  LUBBOCK_FPGA_VIRT,
408                 .pfn            = __phys_to_pfn(LUBBOCK_FPGA_PHYS),
409                 .length         = 0x00100000,
410                 .type           = MT_DEVICE
411         }
412 };
413
414 static void __init lubbock_map_io(void)
415 {
416         pxa_map_io();
417         iotable_init(lubbock_io_desc, ARRAY_SIZE(lubbock_io_desc));
418
419         /* This enables the BTUART */
420         pxa_gpio_mode(GPIO42_BTRXD_MD);
421         pxa_gpio_mode(GPIO43_BTTXD_MD);
422         pxa_gpio_mode(GPIO44_BTCTS_MD);
423         pxa_gpio_mode(GPIO45_BTRTS_MD);
424
425         /* This is for the SMC chip select */
426         pxa_gpio_mode(GPIO79_nCS_3_MD);
427
428         /* setup sleep mode values */
429         PWER  = 0x00000002;
430         PFER  = 0x00000000;
431         PRER  = 0x00000002;
432         PGSR0 = 0x00008000;
433         PGSR1 = 0x003F0202;
434         PGSR2 = 0x0001C000;
435         PCFR |= PCFR_OPDE;
436 }
437
438 MACHINE_START(LUBBOCK, "Intel DBPXA250 Development Platform (aka Lubbock)")
439         /* Maintainer: MontaVista Software Inc. */
440         .phys_ram       = 0xa0000000,
441         .phys_io        = 0x40000000,
442         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
443         .map_io         = lubbock_map_io,
444         .init_irq       = lubbock_init_irq,
445         .timer          = &pxa_timer,
446         .init_machine   = lubbock_init,
447 MACHINE_END