Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[pandora-kernel.git] / arch / arm / mach-pxa / balloon3.c
1 /*
2  *  linux/arch/arm/mach-pxa/balloon3.c
3  *
4  *  Support for Balloonboard.org Balloon3 board.
5  *
6  *  Author:     Nick Bane, Wookey, Jonathan McDowell
7  *  Created:    June, 2006
8  *  Copyright:  Toby Churchill Ltd
9  *  Derived from mainstone.c, by Nico Pitre
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License version 2 as
13  *  published by the Free Software Foundation.
14  */
15
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/sysdev.h>
19 #include <linux/interrupt.h>
20 #include <linux/sched.h>
21 #include <linux/bitops.h>
22 #include <linux/fb.h>
23 #include <linux/gpio.h>
24 #include <linux/ioport.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/partitions.h>
27 #include <linux/types.h>
28
29 #include <asm/setup.h>
30 #include <asm/mach-types.h>
31 #include <asm/irq.h>
32 #include <asm/sizes.h>
33
34 #include <asm/mach/arch.h>
35 #include <asm/mach/map.h>
36 #include <asm/mach/irq.h>
37 #include <asm/mach/flash.h>
38
39 #include <mach/pxa27x.h>
40 #include <mach/balloon3.h>
41 #include <mach/audio.h>
42 #include <mach/pxafb.h>
43 #include <mach/mmc.h>
44 #include <mach/udc.h>
45 #include <mach/pxa27x-udc.h>
46 #include <mach/irda.h>
47 #include <mach/ohci.h>
48
49 #include <plat/i2c.h>
50
51 #include "generic.h"
52 #include "devices.h"
53
54 static unsigned long balloon3_irq_enabled;
55
56 static unsigned long balloon3_features_present =
57                 (1 << BALLOON3_FEATURE_OHCI) | (1 << BALLOON3_FEATURE_CF) |
58                 (1 << BALLOON3_FEATURE_AUDIO) |
59                 (1 << BALLOON3_FEATURE_TOPPOLY);
60
61 int balloon3_has(enum balloon3_features feature)
62 {
63         return (balloon3_features_present & (1 << feature)) ? 1 : 0;
64 }
65 EXPORT_SYMBOL_GPL(balloon3_has);
66
67 int __init parse_balloon3_features(char *arg)
68 {
69         if (!arg)
70                 return 0;
71
72         return strict_strtoul(arg, 0, &balloon3_features_present);
73 }
74 early_param("balloon3_features", parse_balloon3_features);
75
76 static void balloon3_mask_irq(unsigned int irq)
77 {
78         int balloon3_irq = (irq - BALLOON3_IRQ(0));
79         balloon3_irq_enabled &= ~(1 << balloon3_irq);
80         __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
81 }
82
83 static void balloon3_unmask_irq(unsigned int irq)
84 {
85         int balloon3_irq = (irq - BALLOON3_IRQ(0));
86         balloon3_irq_enabled |= (1 << balloon3_irq);
87         __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
88 }
89
90 static struct irq_chip balloon3_irq_chip = {
91         .name           = "FPGA",
92         .ack            = balloon3_mask_irq,
93         .mask           = balloon3_mask_irq,
94         .unmask         = balloon3_unmask_irq,
95 };
96
97 static void balloon3_irq_handler(unsigned int irq, struct irq_desc *desc)
98 {
99         unsigned long pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
100                                         balloon3_irq_enabled;
101
102         do {
103                 /* clear useless edge notification */
104                 if (desc->chip->ack)
105                         desc->chip->ack(BALLOON3_AUX_NIRQ);
106                 while (pending) {
107                         irq = BALLOON3_IRQ(0) + __ffs(pending);
108                         generic_handle_irq(irq);
109                         pending &= pending - 1;
110                 }
111                 pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
112                                 balloon3_irq_enabled;
113         } while (pending);
114 }
115
116 static void __init balloon3_init_irq(void)
117 {
118         int irq;
119
120         pxa27x_init_irq();
121         /* setup extra Balloon3 irqs */
122         for (irq = BALLOON3_IRQ(0); irq <= BALLOON3_IRQ(7); irq++) {
123                 set_irq_chip(irq, &balloon3_irq_chip);
124                 set_irq_handler(irq, handle_level_irq);
125                 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
126         }
127
128         set_irq_chained_handler(BALLOON3_AUX_NIRQ, balloon3_irq_handler);
129         set_irq_type(BALLOON3_AUX_NIRQ, IRQ_TYPE_EDGE_FALLING);
130
131         pr_debug("%s: chained handler installed - irq %d automatically "
132                 "enabled\n", __func__, BALLOON3_AUX_NIRQ);
133 }
134
135 static unsigned long balloon3_ac97_pin_config[] = {
136         GPIO28_AC97_BITCLK,
137         GPIO29_AC97_SDATA_IN_0,
138         GPIO30_AC97_SDATA_OUT,
139         GPIO31_AC97_SYNC,
140         GPIO113_AC97_nRESET,
141 };
142
143 static void balloon3_backlight_power(int on)
144 {
145         pr_debug("%s: power is %s\n", __func__, on ? "on" : "off");
146         gpio_set_value(BALLOON3_GPIO_RUN_BACKLIGHT, on);
147 }
148
149 static unsigned long balloon3_lcd_pin_config[] = {
150         /* LCD - 16bpp Active TFT */
151         GPIOxx_LCD_TFT_16BPP,
152
153         GPIO99_GPIO,            /* Backlight */
154 };
155
156 static struct pxafb_mode_info balloon3_lcd_modes[] = {
157         {
158                 .pixclock               = 38000,
159                 .xres                   = 480,
160                 .yres                   = 640,
161                 .bpp                    = 16,
162                 .hsync_len              = 8,
163                 .left_margin            = 8,
164                 .right_margin           = 8,
165                 .vsync_len              = 2,
166                 .upper_margin           = 4,
167                 .lower_margin           = 5,
168                 .sync                   = 0,
169         },
170 };
171
172 static struct pxafb_mach_info balloon3_pxafb_info = {
173         .modes                  = balloon3_lcd_modes,
174         .num_modes              = ARRAY_SIZE(balloon3_lcd_modes),
175         .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
176         .pxafb_backlight_power  = balloon3_backlight_power,
177 };
178
179 static unsigned long balloon3_mmc_pin_config[] = {
180         GPIO32_MMC_CLK,
181         GPIO92_MMC_DAT_0,
182         GPIO109_MMC_DAT_1,
183         GPIO110_MMC_DAT_2,
184         GPIO111_MMC_DAT_3,
185         GPIO112_MMC_CMD,
186 };
187
188 static void balloon3_mci_setpower(struct device *dev, unsigned int vdd)
189 {
190         struct pxamci_platform_data *p_d = dev->platform_data;
191
192         if ((1 << vdd) & p_d->ocr_mask) {
193                 pr_debug("%s: on\n", __func__);
194                 /* FIXME something to prod here? */
195         } else {
196                 pr_debug("%s: off\n", __func__);
197                 /* FIXME something to prod here? */
198         }
199 }
200
201 static struct pxamci_platform_data balloon3_mci_platform_data = {
202         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
203         .setpower       = balloon3_mci_setpower,
204 };
205
206 static int balloon3_udc_is_connected(void)
207 {
208         pr_debug("%s: udc connected\n", __func__);
209         return 1;
210 }
211
212 static void balloon3_udc_command(int cmd)
213 {
214         switch (cmd) {
215         case PXA2XX_UDC_CMD_CONNECT:
216                 UP2OCR |= (UP2OCR_DPPUE + UP2OCR_DPPUBE);
217                 pr_debug("%s: connect\n", __func__);
218                 break;
219         case PXA2XX_UDC_CMD_DISCONNECT:
220                 UP2OCR &= ~UP2OCR_DPPUE;
221                 pr_debug("%s: disconnect\n", __func__);
222                 break;
223         }
224 }
225
226 static struct pxa2xx_udc_mach_info balloon3_udc_info = {
227         .udc_is_connected = balloon3_udc_is_connected,
228         .udc_command      = balloon3_udc_command,
229 };
230
231 static struct pxaficp_platform_data balloon3_ficp_platform_data = {
232         .transceiver_cap  = IR_SIRMODE | IR_FIRMODE | IR_OFF,
233 };
234
235 static unsigned long balloon3_ohci_pin_config[] = {
236         GPIO88_USBH1_PWR,
237         GPIO89_USBH1_PEN,
238 };
239
240 static struct pxaohci_platform_data balloon3_ohci_platform_data = {
241         .port_mode      = PMM_PERPORT_MODE,
242         .flags          = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
243 };
244
245 static unsigned long balloon3_pin_config[] __initdata = {
246         /* Select BTUART 'COM1/ttyS0' as IO option for pins 42/43/44/45 */
247         GPIO42_BTUART_RXD,
248         GPIO43_BTUART_TXD,
249         GPIO44_BTUART_CTS,
250         GPIO45_BTUART_RTS,
251
252         /* Wakeup GPIO */
253         GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
254
255         /* NAND & IDLE LED GPIOs */
256         GPIO9_GPIO,
257         GPIO10_GPIO,
258 };
259
260 static struct gpio_led balloon3_gpio_leds[] = {
261         {
262                 .name                   = "balloon3:green:idle",
263                 .default_trigger        = "heartbeat",
264                 .gpio                   = BALLOON3_GPIO_LED_IDLE,
265                 .active_low             = 1,
266         },
267         {
268                 .name                   = "balloon3:green:nand",
269                 .default_trigger        = "nand-disk",
270                 .gpio                   = BALLOON3_GPIO_LED_NAND,
271                 .active_low             = 1,
272         },
273 };
274
275 static struct gpio_led_platform_data balloon3_gpio_leds_platform_data = {
276         .leds           = balloon3_gpio_leds,
277         .num_leds       = ARRAY_SIZE(balloon3_gpio_leds),
278 };
279
280 static struct platform_device balloon3led_device = {
281         .name   = "leds-gpio",
282         .id     = -1,
283         .dev    = {
284                 .platform_data  = &balloon3_gpio_leds_platform_data,
285         },
286 };
287
288 static void __init balloon3_init(void)
289 {
290         pr_info("Initialising Balloon3\n");
291
292         /* system bus arbiter setting
293          * - Core_Park
294          * - LCD_wt:DMA_wt:CORE_Wt = 2:3:4
295          */
296         ARB_CNTRL = ARB_CORE_PARK | 0x234;
297
298         pxa_set_ffuart_info(NULL);
299         pxa_set_btuart_info(NULL);
300         pxa_set_stuart_info(NULL);
301
302         pxa_set_i2c_info(NULL);
303         if (balloon3_has(BALLOON3_FEATURE_AUDIO)) {
304                 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_ac97_pin_config));
305                 pxa_set_ac97_info(NULL);
306         }
307
308         if (balloon3_has(BALLOON3_FEATURE_TOPPOLY)) {
309                 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_lcd_pin_config));
310                 gpio_request(BALLOON3_GPIO_RUN_BACKLIGHT,
311                         "LCD Backlight Power");
312                 gpio_direction_output(BALLOON3_GPIO_RUN_BACKLIGHT, 1);
313                 set_pxa_fb_info(&balloon3_pxafb_info);
314         }
315
316         if (balloon3_has(BALLOON3_FEATURE_MMC)) {
317                 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_mmc_pin_config));
318                 pxa_set_mci_info(&balloon3_mci_platform_data);
319         }
320         pxa_set_ficp_info(&balloon3_ficp_platform_data);
321         if (balloon3_has(BALLOON3_FEATURE_OHCI)) {
322                 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_ohci_pin_config));
323                 pxa_set_ohci_info(&balloon3_ohci_platform_data);
324         }
325         pxa_set_udc_info(&balloon3_udc_info);
326
327         pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_pin_config));
328
329         platform_device_register(&balloon3led_device);
330 }
331
332 static struct map_desc balloon3_io_desc[] __initdata = {
333         {       /* CPLD/FPGA */
334                 .virtual        =  BALLOON3_FPGA_VIRT,
335                 .pfn            = __phys_to_pfn(BALLOON3_FPGA_PHYS),
336                 .length         = BALLOON3_FPGA_LENGTH,
337                 .type           = MT_DEVICE,
338         },
339 };
340
341 static void __init balloon3_map_io(void)
342 {
343         pxa_map_io();
344         iotable_init(balloon3_io_desc, ARRAY_SIZE(balloon3_io_desc));
345 }
346
347 MACHINE_START(BALLOON3, "Balloon3")
348         /* Maintainer: Nick Bane. */
349         .phys_io        = 0x40000000,
350         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
351         .map_io         = balloon3_map_io,
352         .init_irq       = balloon3_init_irq,
353         .timer          = &pxa_timer,
354         .init_machine   = balloon3_init,
355         .boot_params    = PHYS_OFFSET + 0x100,
356 MACHINE_END