blob: 6f594bd410ddd9b00249108bf3101e7118e718ac [file] [log] [blame]
Jonathan McDowell2a23ec32009-07-04 14:43:56 +01001/*
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>
Marek Vasut12a24492010-07-27 01:37:44 +020025#include <linux/ucb1400.h>
Jonathan McDowell2a23ec32009-07-04 14:43:56 +010026#include <linux/mtd/mtd.h>
27#include <linux/mtd/partitions.h>
28#include <linux/types.h>
Marek Vasut02a453e2010-07-27 23:11:03 +020029#include <linux/i2c/pcf857x.h>
Jonathan McDowell2a23ec32009-07-04 14:43:56 +010030
31#include <asm/setup.h>
32#include <asm/mach-types.h>
33#include <asm/irq.h>
34#include <asm/sizes.h>
35
36#include <asm/mach/arch.h>
37#include <asm/mach/map.h>
38#include <asm/mach/irq.h>
39#include <asm/mach/flash.h>
40
41#include <mach/pxa27x.h>
42#include <mach/balloon3.h>
43#include <mach/audio.h>
44#include <mach/pxafb.h>
45#include <mach/mmc.h>
46#include <mach/udc.h>
47#include <mach/pxa27x-udc.h>
48#include <mach/irda.h>
49#include <mach/ohci.h>
50
51#include <plat/i2c.h>
52
53#include "generic.h"
54#include "devices.h"
55
Marek Vasutb0240bf2010-07-26 23:24:44 +020056/******************************************************************************
57 * Pin configuration
58 ******************************************************************************/
59static unsigned long balloon3_pin_config[] __initdata = {
60 /* Select BTUART 'COM1/ttyS0' as IO option for pins 42/43/44/45 */
61 GPIO42_BTUART_RXD,
62 GPIO43_BTUART_TXD,
63 GPIO44_BTUART_CTS,
64 GPIO45_BTUART_RTS,
65
Marek Vasut12a24492010-07-27 01:37:44 +020066 /* Reset, configured as GPIO wakeup source */
Marek Vasutb0240bf2010-07-26 23:24:44 +020067 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
68
Marek Vasut12a24492010-07-27 01:37:44 +020069 /* LEDs */
70 GPIO9_GPIO, /* NAND activity LED */
71 GPIO10_GPIO, /* Heartbeat LED */
Marek Vasutb0240bf2010-07-26 23:24:44 +020072
Marek Vasut12a24492010-07-27 01:37:44 +020073 /* AC97 */
Marek Vasutb0240bf2010-07-26 23:24:44 +020074 GPIO28_AC97_BITCLK,
75 GPIO29_AC97_SDATA_IN_0,
76 GPIO30_AC97_SDATA_OUT,
77 GPIO31_AC97_SYNC,
78 GPIO113_AC97_nRESET,
Marek Vasut12a24492010-07-27 01:37:44 +020079 GPIO95_GPIO,
Marek Vasutb0240bf2010-07-26 23:24:44 +020080
Marek Vasut12a24492010-07-27 01:37:44 +020081 /* MMC */
Marek Vasutb0240bf2010-07-26 23:24:44 +020082 GPIO32_MMC_CLK,
83 GPIO92_MMC_DAT_0,
84 GPIO109_MMC_DAT_1,
85 GPIO110_MMC_DAT_2,
86 GPIO111_MMC_DAT_3,
87 GPIO112_MMC_CMD,
Marek Vasutb0240bf2010-07-26 23:24:44 +020088
Marek Vasut12a24492010-07-27 01:37:44 +020089 /* USB Host */
Marek Vasutb0240bf2010-07-26 23:24:44 +020090 GPIO88_USBH1_PWR,
91 GPIO89_USBH1_PEN,
Marek Vasuta9c06292010-07-27 21:48:10 +020092
93 /* PC Card */
94 GPIO48_nPOE,
95 GPIO49_nPWE,
96 GPIO50_nPIOR,
97 GPIO51_nPIOW,
98 GPIO85_nPCE_1,
99 GPIO54_nPCE_2,
100 GPIO79_PSKTSEL,
101 GPIO55_nPREG,
102 GPIO56_nPWAIT,
103 GPIO57_nIOIS16,
Marek Vasutb0240bf2010-07-26 23:24:44 +0200104};
105
Marek Vasutb0240bf2010-07-26 23:24:44 +0200106/******************************************************************************
107 * Compatibility: Parameter parsing
108 ******************************************************************************/
Jonathan McDowell2a23ec32009-07-04 14:43:56 +0100109static unsigned long balloon3_irq_enabled;
110
111static unsigned long balloon3_features_present =
112 (1 << BALLOON3_FEATURE_OHCI) | (1 << BALLOON3_FEATURE_CF) |
113 (1 << BALLOON3_FEATURE_AUDIO) |
114 (1 << BALLOON3_FEATURE_TOPPOLY);
115
116int balloon3_has(enum balloon3_features feature)
117{
118 return (balloon3_features_present & (1 << feature)) ? 1 : 0;
119}
120EXPORT_SYMBOL_GPL(balloon3_has);
121
122int __init parse_balloon3_features(char *arg)
123{
124 if (!arg)
125 return 0;
126
127 return strict_strtoul(arg, 0, &balloon3_features_present);
128}
129early_param("balloon3_features", parse_balloon3_features);
130
Marek Vasutb0240bf2010-07-26 23:24:44 +0200131/******************************************************************************
Marek Vasut12a24492010-07-27 01:37:44 +0200132 * NOR Flash
133 ******************************************************************************/
134#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
135static struct mtd_partition balloon3_nor_partitions[] = {
136 {
137 .name = "Flash",
138 .offset = 0x00000000,
139 .size = MTDPART_SIZ_FULL,
140 }
141};
142
143static struct physmap_flash_data balloon3_flash_data[] = {
144 {
145 .width = 2, /* bankwidth in bytes */
146 .parts = balloon3_nor_partitions,
147 .nr_parts = ARRAY_SIZE(balloon3_nor_partitions)
148 }
149};
150
151static struct resource balloon3_flash_resource = {
152 .start = PXA_CS0_PHYS,
153 .end = PXA_CS0_PHYS + SZ_64M - 1,
154 .flags = IORESOURCE_MEM,
155};
156
157static struct platform_device balloon3_flash = {
158 .name = "physmap-flash",
159 .id = 0,
160 .resource = &balloon3_flash_resource,
161 .num_resources = 1,
162 .dev = {
163 .platform_data = balloon3_flash_data,
164 },
165};
166static void __init balloon3_nor_init(void)
167{
168 platform_device_register(&balloon3_flash);
169}
170#else
171static inline void balloon3_nor_init(void) {}
172#endif
173
174/******************************************************************************
175 * Audio and Touchscreen
176 ******************************************************************************/
177#if defined(CONFIG_TOUCHSCREEN_UCB1400) || \
178 defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
179static struct ucb1400_pdata vpac270_ucb1400_pdata = {
180 .irq = IRQ_GPIO(BALLOON3_GPIO_CODEC_IRQ),
181};
182
183
184static struct platform_device balloon3_ucb1400_device = {
185 .name = "ucb1400_core",
186 .id = -1,
187 .dev = {
188 .platform_data = &vpac270_ucb1400_pdata,
189 },
190};
191
192static void __init balloon3_ts_init(void)
193{
194 if (!balloon3_has(BALLOON3_FEATURE_AUDIO))
195 return;
196
197 pxa_set_ac97_info(NULL);
198 platform_device_register(&balloon3_ucb1400_device);
199}
200#else
201static inline void balloon3_ts_init(void) {}
202#endif
203
204/******************************************************************************
205 * Framebuffer
206 ******************************************************************************/
207#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
208static struct pxafb_mode_info balloon3_lcd_modes[] = {
209 {
210 .pixclock = 38000,
211 .xres = 480,
212 .yres = 640,
213 .bpp = 16,
214 .hsync_len = 8,
215 .left_margin = 8,
216 .right_margin = 8,
217 .vsync_len = 2,
218 .upper_margin = 4,
219 .lower_margin = 5,
220 .sync = 0,
221 },
222};
223
224static struct pxafb_mach_info balloon3_lcd_screen = {
225 .modes = balloon3_lcd_modes,
226 .num_modes = ARRAY_SIZE(balloon3_lcd_modes),
227 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
228};
229
230static void balloon3_backlight_power(int on)
231{
232 gpio_set_value(BALLOON3_GPIO_RUN_BACKLIGHT, on);
233}
234
235static void __init balloon3_lcd_init(void)
236{
237 int ret;
238
239 if (!balloon3_has(BALLOON3_FEATURE_TOPPOLY))
240 return;
241
242 ret = gpio_request(BALLOON3_GPIO_RUN_BACKLIGHT, "BKL-ON");
243 if (ret) {
244 pr_err("Requesting BKL-ON GPIO failed!\n");
245 goto err;
246 }
247
248 ret = gpio_direction_output(BALLOON3_GPIO_RUN_BACKLIGHT, 1);
249 if (ret) {
250 pr_err("Setting BKL-ON GPIO direction failed!\n");
251 goto err2;
252 }
253
254 balloon3_lcd_screen.pxafb_backlight_power = balloon3_backlight_power;
255 set_pxa_fb_info(&balloon3_lcd_screen);
256 return;
257
258err2:
259 gpio_free(BALLOON3_GPIO_RUN_BACKLIGHT);
260err:
261 return;
262}
263#else
264static inline void balloon3_lcd_init(void) {}
265#endif
266
267/******************************************************************************
268 * SD/MMC card controller
269 ******************************************************************************/
270#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
271static struct pxamci_platform_data balloon3_mci_platform_data = {
272 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
273 .gpio_card_detect = -1,
274 .gpio_card_ro = -1,
275 .gpio_power = -1,
276 .detect_delay_ms = 200,
277};
278
279static void __init balloon3_mmc_init(void)
280{
281 pxa_set_mci_info(&balloon3_mci_platform_data);
282}
283#else
284static inline void balloon3_mmc_init(void) {}
285#endif
286
287/******************************************************************************
288 * USB Gadget
289 ******************************************************************************/
290#if defined(CONFIG_USB_GADGET_PXA27X)||defined(CONFIG_USB_GADGET_PXA27X_MODULE)
291static void balloon3_udc_command(int cmd)
292{
293 if (cmd == PXA2XX_UDC_CMD_CONNECT)
294 UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
295 else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
296 UP2OCR &= ~UP2OCR_DPPUE;
297}
298
299static int balloon3_udc_is_connected(void)
300{
301 return 1;
302}
303
304static struct pxa2xx_udc_mach_info balloon3_udc_info __initdata = {
305 .udc_command = balloon3_udc_command,
306 .udc_is_connected = balloon3_udc_is_connected,
307 .gpio_pullup = -1,
308};
309
310static void __init balloon3_udc_init(void)
311{
312 pxa_set_udc_info(&balloon3_udc_info);
313 platform_device_register(&balloon3_gpio_vbus);
314}
315#else
316static inline void balloon3_udc_init(void) {}
317#endif
318
319/******************************************************************************
320 * IrDA
321 ******************************************************************************/
322#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
323static struct pxaficp_platform_data balloon3_ficp_platform_data = {
324 .transceiver_cap = IR_FIRMODE | IR_SIRMODE | IR_OFF,
325};
326
327static void __init balloon3_irda_init(void)
328{
329 pxa_set_ficp_info(&balloon3_ficp_platform_data);
330}
331#else
332static inline void balloon3_irda_init(void) {}
333#endif
334
335/******************************************************************************
336 * USB Host
337 ******************************************************************************/
338#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
339static struct pxaohci_platform_data balloon3_ohci_info = {
340 .port_mode = PMM_PERPORT_MODE,
341 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
342};
343
344static void __init balloon3_uhc_init(void)
345{
346 if (!balloon3_has(BALLOON3_FEATURE_OHCI))
347 return;
348 pxa_set_ohci_info(&balloon3_ohci_info);
349}
350#else
351static inline void balloon3_uhc_init(void) {}
352#endif
353
354/******************************************************************************
355 * LEDs
356 ******************************************************************************/
357#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
358struct gpio_led balloon3_gpio_leds[] = {
359 {
360 .name = "balloon3:green:idle",
361 .default_trigger = "heartbeat",
362 .gpio = BALLOON3_GPIO_LED_IDLE,
363 .active_low = 1,
364 }, {
365 .name = "balloon3:green:nand",
366 .default_trigger = "nand-disk",
367 .gpio = BALLOON3_GPIO_LED_NAND,
368 .active_low = 1,
369 },
370};
371
372static struct gpio_led_platform_data balloon3_gpio_led_info = {
373 .leds = balloon3_gpio_leds,
374 .num_leds = ARRAY_SIZE(balloon3_gpio_leds),
375};
376
377static struct platform_device balloon3_leds = {
378 .name = "leds-gpio",
Marek Vasut02a453e2010-07-27 23:11:03 +0200379 .id = 0,
Marek Vasut12a24492010-07-27 01:37:44 +0200380 .dev = {
381 .platform_data = &balloon3_gpio_led_info,
382 }
383};
384
Marek Vasut02a453e2010-07-27 23:11:03 +0200385struct gpio_led balloon3_pcf_gpio_leds[] = {
386 {
387 .name = "balloon3:green:led0",
388 .gpio = BALLOON3_PCF_GPIO_LED0,
389 .active_low = 1,
390 }, {
391 .name = "balloon3:green:led1",
392 .gpio = BALLOON3_PCF_GPIO_LED1,
393 .active_low = 1,
394 }, {
395 .name = "balloon3:orange:led2",
396 .gpio = BALLOON3_PCF_GPIO_LED2,
397 .active_low = 1,
398 }, {
399 .name = "balloon3:orange:led3",
400 .gpio = BALLOON3_PCF_GPIO_LED3,
401 .active_low = 1,
402 }, {
403 .name = "balloon3:orange:led4",
404 .gpio = BALLOON3_PCF_GPIO_LED4,
405 .active_low = 1,
406 }, {
407 .name = "balloon3:orange:led5",
408 .gpio = BALLOON3_PCF_GPIO_LED5,
409 .active_low = 1,
410 }, {
411 .name = "balloon3:red:led6",
412 .gpio = BALLOON3_PCF_GPIO_LED6,
413 .active_low = 1,
414 }, {
415 .name = "balloon3:red:led7",
416 .gpio = BALLOON3_PCF_GPIO_LED7,
417 .active_low = 1,
418 },
419};
420
421static struct gpio_led_platform_data balloon3_pcf_gpio_led_info = {
422 .leds = balloon3_pcf_gpio_leds,
423 .num_leds = ARRAY_SIZE(balloon3_pcf_gpio_leds),
424};
425
426static struct platform_device balloon3_pcf_leds = {
427 .name = "leds-gpio",
428 .id = 1,
429 .dev = {
430 .platform_data = &balloon3_pcf_gpio_led_info,
431 }
432};
433
Marek Vasut12a24492010-07-27 01:37:44 +0200434static void __init balloon3_leds_init(void)
435{
436 platform_device_register(&balloon3_leds);
Marek Vasut02a453e2010-07-27 23:11:03 +0200437 platform_device_register(&balloon3_pcf_leds);
Marek Vasut12a24492010-07-27 01:37:44 +0200438}
439#else
440static inline void balloon3_leds_init(void) {}
441#endif
442
443/******************************************************************************
Marek Vasutb0240bf2010-07-26 23:24:44 +0200444 * FPGA IRQ
445 ******************************************************************************/
Jonathan McDowell2a23ec32009-07-04 14:43:56 +0100446static void balloon3_mask_irq(unsigned int irq)
447{
448 int balloon3_irq = (irq - BALLOON3_IRQ(0));
449 balloon3_irq_enabled &= ~(1 << balloon3_irq);
450 __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
451}
452
453static void balloon3_unmask_irq(unsigned int irq)
454{
455 int balloon3_irq = (irq - BALLOON3_IRQ(0));
456 balloon3_irq_enabled |= (1 << balloon3_irq);
457 __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
458}
459
460static struct irq_chip balloon3_irq_chip = {
461 .name = "FPGA",
462 .ack = balloon3_mask_irq,
463 .mask = balloon3_mask_irq,
464 .unmask = balloon3_unmask_irq,
465};
466
467static void balloon3_irq_handler(unsigned int irq, struct irq_desc *desc)
468{
469 unsigned long pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
470 balloon3_irq_enabled;
Jonathan McDowell2a23ec32009-07-04 14:43:56 +0100471 do {
472 /* clear useless edge notification */
473 if (desc->chip->ack)
474 desc->chip->ack(BALLOON3_AUX_NIRQ);
475 while (pending) {
476 irq = BALLOON3_IRQ(0) + __ffs(pending);
477 generic_handle_irq(irq);
478 pending &= pending - 1;
479 }
480 pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
481 balloon3_irq_enabled;
482 } while (pending);
483}
484
485static void __init balloon3_init_irq(void)
486{
487 int irq;
488
489 pxa27x_init_irq();
490 /* setup extra Balloon3 irqs */
491 for (irq = BALLOON3_IRQ(0); irq <= BALLOON3_IRQ(7); irq++) {
492 set_irq_chip(irq, &balloon3_irq_chip);
493 set_irq_handler(irq, handle_level_irq);
494 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
495 }
496
497 set_irq_chained_handler(BALLOON3_AUX_NIRQ, balloon3_irq_handler);
498 set_irq_type(BALLOON3_AUX_NIRQ, IRQ_TYPE_EDGE_FALLING);
499
500 pr_debug("%s: chained handler installed - irq %d automatically "
501 "enabled\n", __func__, BALLOON3_AUX_NIRQ);
502}
503
Marek Vasutb0240bf2010-07-26 23:24:44 +0200504/******************************************************************************
Marek Vasut02a453e2010-07-27 23:11:03 +0200505 * GPIO expander
506 ******************************************************************************/
507#if defined(CONFIG_GPIO_PCF857X) || defined(CONFIG_GPIO_PCF857X_MODULE)
508static struct pcf857x_platform_data balloon3_pcf857x_pdata = {
509 .gpio_base = BALLOON3_PCF_GPIO_BASE,
510 .n_latch = 0,
511 .setup = NULL,
512 .teardown = NULL,
513 .context = NULL,
514};
515
516static struct i2c_board_info __initdata balloon3_i2c_devs[] = {
517 {
518 I2C_BOARD_INFO("pcf8574a", 0x38),
519 .platform_data = &balloon3_pcf857x_pdata,
520 },
521};
522
523static void __init balloon3_i2c_init(void)
524{
525 pxa_set_i2c_info(NULL);
526 i2c_register_board_info(0, ARRAY_AND_SIZE(balloon3_i2c_devs));
527}
528#else
529static inline void balloon3_i2c_init(void) {}
530#endif
531
532/******************************************************************************
Marek Vasutb0240bf2010-07-26 23:24:44 +0200533 * Machine init
534 ******************************************************************************/
Jonathan McDowell2a23ec32009-07-04 14:43:56 +0100535static void __init balloon3_init(void)
536{
Jonathan McDowell2a23ec32009-07-04 14:43:56 +0100537 ARB_CNTRL = ARB_CORE_PARK | 0x234;
538
Marek Vasut12a24492010-07-27 01:37:44 +0200539 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_pin_config));
540
Russell Kingcc155c62009-11-09 13:34:08 +0800541 pxa_set_ffuart_info(NULL);
542 pxa_set_btuart_info(NULL);
543 pxa_set_stuart_info(NULL);
544
Marek Vasut02a453e2010-07-27 23:11:03 +0200545 balloon3_i2c_init();
Marek Vasut12a24492010-07-27 01:37:44 +0200546 balloon3_irda_init();
547 balloon3_lcd_init();
548 balloon3_leds_init();
549 balloon3_mmc_init();
550 balloon3_nor_init();
551 balloon3_ts_init();
552 balloon3_udc_init();
553 balloon3_uhc_init();
Jonathan McDowell2a23ec32009-07-04 14:43:56 +0100554}
555
556static struct map_desc balloon3_io_desc[] __initdata = {
557 { /* CPLD/FPGA */
558 .virtual = BALLOON3_FPGA_VIRT,
559 .pfn = __phys_to_pfn(BALLOON3_FPGA_PHYS),
560 .length = BALLOON3_FPGA_LENGTH,
561 .type = MT_DEVICE,
562 },
563};
564
565static void __init balloon3_map_io(void)
566{
567 pxa_map_io();
568 iotable_init(balloon3_io_desc, ARRAY_SIZE(balloon3_io_desc));
569}
570
571MACHINE_START(BALLOON3, "Balloon3")
572 /* Maintainer: Nick Bane. */
573 .phys_io = 0x40000000,
574 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
575 .map_io = balloon3_map_io,
576 .init_irq = balloon3_init_irq,
577 .timer = &pxa_timer,
578 .init_machine = balloon3_init,
579 .boot_params = PHYS_OFFSET + 0x100,
580MACHINE_END