2 * linux/arch/arm/mach-pxa/balloon3.c
4 * Support for Balloonboard.org Balloon3 board.
6 * Author: Nick Bane, Wookey, Jonathan McDowell
8 * Copyright: Toby Churchill Ltd
9 * Derived from mainstone.c, by Nico Pitre
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.
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/interrupt.h>
19 #include <linux/sched.h>
20 #include <linux/bitops.h>
22 #include <linux/gpio.h>
23 #include <linux/ioport.h>
24 #include <linux/ucb1400.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/partitions.h>
27 #include <linux/types.h>
28 #include <linux/i2c/pcf857x.h>
29 #include <linux/i2c/pxa-i2c.h>
30 #include <linux/mtd/nand.h>
31 #include <linux/mtd/physmap.h>
32 #include <linux/regulator/max1586.h>
34 #include <asm/setup.h>
35 #include <asm/mach-types.h>
37 #include <asm/sizes.h>
39 #include <asm/mach/arch.h>
40 #include <asm/mach/map.h>
41 #include <asm/mach/irq.h>
42 #include <asm/mach/flash.h>
44 #include <mach/pxa27x.h>
45 #include <mach/balloon3.h>
46 #include <mach/audio.h>
47 #include <mach/pxafb.h>
50 #include <mach/pxa27x-udc.h>
51 #include <mach/irda.h>
52 #include <mach/ohci.h>
57 /******************************************************************************
59 ******************************************************************************/
60 static unsigned long balloon3_pin_config[] __initdata = {
61 /* Select BTUART 'COM1/ttyS0' as IO option for pins 42/43/44/45 */
67 /* Reset, configured as GPIO wakeup source */
68 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
71 /******************************************************************************
72 * Compatibility: Parameter parsing
73 ******************************************************************************/
74 static unsigned long balloon3_irq_enabled;
76 static unsigned long balloon3_features_present =
77 (1 << BALLOON3_FEATURE_OHCI) | (1 << BALLOON3_FEATURE_CF) |
78 (1 << BALLOON3_FEATURE_AUDIO) |
79 (1 << BALLOON3_FEATURE_TOPPOLY);
81 int balloon3_has(enum balloon3_features feature)
83 return (balloon3_features_present & (1 << feature)) ? 1 : 0;
85 EXPORT_SYMBOL_GPL(balloon3_has);
87 int __init parse_balloon3_features(char *arg)
92 return strict_strtoul(arg, 0, &balloon3_features_present);
94 early_param("balloon3_features", parse_balloon3_features);
96 /******************************************************************************
98 ******************************************************************************/
99 #if defined(CONFIG_PCMCIA_PXA2XX) || defined(CONFIG_PCMCIA_PXA2XX_MODULE)
100 static unsigned long balloon3_cf_pin_config[] __initdata = {
113 static void __init balloon3_cf_init(void)
115 if (!balloon3_has(BALLOON3_FEATURE_CF))
118 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_cf_pin_config));
121 static inline void balloon3_cf_init(void) {}
124 /******************************************************************************
126 ******************************************************************************/
127 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
128 static struct mtd_partition balloon3_nor_partitions[] = {
131 .offset = 0x00000000,
132 .size = MTDPART_SIZ_FULL,
136 static struct physmap_flash_data balloon3_flash_data[] = {
138 .width = 2, /* bankwidth in bytes */
139 .parts = balloon3_nor_partitions,
140 .nr_parts = ARRAY_SIZE(balloon3_nor_partitions)
144 static struct resource balloon3_flash_resource = {
145 .start = PXA_CS0_PHYS,
146 .end = PXA_CS0_PHYS + SZ_64M - 1,
147 .flags = IORESOURCE_MEM,
150 static struct platform_device balloon3_flash = {
151 .name = "physmap-flash",
153 .resource = &balloon3_flash_resource,
156 .platform_data = balloon3_flash_data,
159 static void __init balloon3_nor_init(void)
161 platform_device_register(&balloon3_flash);
164 static inline void balloon3_nor_init(void) {}
167 /******************************************************************************
168 * Audio and Touchscreen
169 ******************************************************************************/
170 #if defined(CONFIG_TOUCHSCREEN_UCB1400) || \
171 defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
172 static unsigned long balloon3_ac97_pin_config[] __initdata = {
174 GPIO29_AC97_SDATA_IN_0,
175 GPIO30_AC97_SDATA_OUT,
181 static struct ucb1400_pdata vpac270_ucb1400_pdata = {
182 .irq = IRQ_GPIO(BALLOON3_GPIO_CODEC_IRQ),
186 static struct platform_device balloon3_ucb1400_device = {
187 .name = "ucb1400_core",
190 .platform_data = &vpac270_ucb1400_pdata,
194 static void __init balloon3_ts_init(void)
196 if (!balloon3_has(BALLOON3_FEATURE_AUDIO))
199 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_ac97_pin_config));
200 pxa_set_ac97_info(NULL);
201 platform_device_register(&balloon3_ucb1400_device);
204 static inline void balloon3_ts_init(void) {}
207 /******************************************************************************
209 ******************************************************************************/
210 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
211 static unsigned long balloon3_lcd_pin_config[] __initdata = {
212 GPIOxx_LCD_TFT_16BPP,
216 static struct pxafb_mode_info balloon3_lcd_modes[] = {
232 static struct pxafb_mach_info balloon3_lcd_screen = {
233 .modes = balloon3_lcd_modes,
234 .num_modes = ARRAY_SIZE(balloon3_lcd_modes),
235 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
238 static void balloon3_backlight_power(int on)
240 gpio_set_value(BALLOON3_GPIO_RUN_BACKLIGHT, on);
243 static void __init balloon3_lcd_init(void)
247 if (!balloon3_has(BALLOON3_FEATURE_TOPPOLY))
250 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_lcd_pin_config));
252 ret = gpio_request(BALLOON3_GPIO_RUN_BACKLIGHT, "BKL-ON");
254 pr_err("Requesting BKL-ON GPIO failed!\n");
258 ret = gpio_direction_output(BALLOON3_GPIO_RUN_BACKLIGHT, 1);
260 pr_err("Setting BKL-ON GPIO direction failed!\n");
264 balloon3_lcd_screen.pxafb_backlight_power = balloon3_backlight_power;
265 pxa_set_fb_info(NULL, &balloon3_lcd_screen);
269 gpio_free(BALLOON3_GPIO_RUN_BACKLIGHT);
274 static inline void balloon3_lcd_init(void) {}
277 /******************************************************************************
278 * SD/MMC card controller
279 ******************************************************************************/
280 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
281 static unsigned long balloon3_mmc_pin_config[] __initdata = {
290 static struct pxamci_platform_data balloon3_mci_platform_data = {
291 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
292 .gpio_card_detect = -1,
295 .detect_delay_ms = 200,
298 static void __init balloon3_mmc_init(void)
300 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_mmc_pin_config));
301 pxa_set_mci_info(&balloon3_mci_platform_data);
304 static inline void balloon3_mmc_init(void) {}
307 /******************************************************************************
309 ******************************************************************************/
310 #if defined(CONFIG_USB_GADGET_PXA27X)||defined(CONFIG_USB_GADGET_PXA27X_MODULE)
311 static void balloon3_udc_command(int cmd)
313 if (cmd == PXA2XX_UDC_CMD_CONNECT)
314 UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
315 else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
316 UP2OCR &= ~UP2OCR_DPPUE;
319 static int balloon3_udc_is_connected(void)
324 static struct pxa2xx_udc_mach_info balloon3_udc_info __initdata = {
325 .udc_command = balloon3_udc_command,
326 .udc_is_connected = balloon3_udc_is_connected,
330 static void __init balloon3_udc_init(void)
332 pxa_set_udc_info(&balloon3_udc_info);
333 platform_device_register(&balloon3_gpio_vbus);
336 static inline void balloon3_udc_init(void) {}
339 /******************************************************************************
341 ******************************************************************************/
342 #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
343 static struct pxaficp_platform_data balloon3_ficp_platform_data = {
344 .transceiver_cap = IR_FIRMODE | IR_SIRMODE | IR_OFF,
347 static void __init balloon3_irda_init(void)
349 pxa_set_ficp_info(&balloon3_ficp_platform_data);
352 static inline void balloon3_irda_init(void) {}
355 /******************************************************************************
357 ******************************************************************************/
358 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
359 static unsigned long balloon3_uhc_pin_config[] __initdata = {
364 static struct pxaohci_platform_data balloon3_ohci_info = {
365 .port_mode = PMM_PERPORT_MODE,
366 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
369 static void __init balloon3_uhc_init(void)
371 if (!balloon3_has(BALLOON3_FEATURE_OHCI))
373 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_uhc_pin_config));
374 pxa_set_ohci_info(&balloon3_ohci_info);
377 static inline void balloon3_uhc_init(void) {}
380 /******************************************************************************
382 ******************************************************************************/
383 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
384 static unsigned long balloon3_led_pin_config[] __initdata = {
385 GPIO9_GPIO, /* NAND activity LED */
386 GPIO10_GPIO, /* Heartbeat LED */
389 struct gpio_led balloon3_gpio_leds[] = {
391 .name = "balloon3:green:idle",
392 .default_trigger = "heartbeat",
393 .gpio = BALLOON3_GPIO_LED_IDLE,
396 .name = "balloon3:green:nand",
397 .default_trigger = "nand-disk",
398 .gpio = BALLOON3_GPIO_LED_NAND,
403 static struct gpio_led_platform_data balloon3_gpio_led_info = {
404 .leds = balloon3_gpio_leds,
405 .num_leds = ARRAY_SIZE(balloon3_gpio_leds),
408 static struct platform_device balloon3_leds = {
412 .platform_data = &balloon3_gpio_led_info,
416 struct gpio_led balloon3_pcf_gpio_leds[] = {
418 .name = "balloon3:green:led0",
419 .gpio = BALLOON3_PCF_GPIO_LED0,
422 .name = "balloon3:green:led1",
423 .gpio = BALLOON3_PCF_GPIO_LED1,
426 .name = "balloon3:orange:led2",
427 .gpio = BALLOON3_PCF_GPIO_LED2,
430 .name = "balloon3:orange:led3",
431 .gpio = BALLOON3_PCF_GPIO_LED3,
434 .name = "balloon3:orange:led4",
435 .gpio = BALLOON3_PCF_GPIO_LED4,
438 .name = "balloon3:orange:led5",
439 .gpio = BALLOON3_PCF_GPIO_LED5,
442 .name = "balloon3:red:led6",
443 .gpio = BALLOON3_PCF_GPIO_LED6,
446 .name = "balloon3:red:led7",
447 .gpio = BALLOON3_PCF_GPIO_LED7,
452 static struct gpio_led_platform_data balloon3_pcf_gpio_led_info = {
453 .leds = balloon3_pcf_gpio_leds,
454 .num_leds = ARRAY_SIZE(balloon3_pcf_gpio_leds),
457 static struct platform_device balloon3_pcf_leds = {
461 .platform_data = &balloon3_pcf_gpio_led_info,
465 static void __init balloon3_leds_init(void)
467 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_led_pin_config));
468 platform_device_register(&balloon3_leds);
469 platform_device_register(&balloon3_pcf_leds);
472 static inline void balloon3_leds_init(void) {}
475 /******************************************************************************
477 ******************************************************************************/
478 static void balloon3_mask_irq(struct irq_data *d)
480 int balloon3_irq = (d->irq - BALLOON3_IRQ(0));
481 balloon3_irq_enabled &= ~(1 << balloon3_irq);
482 __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
485 static void balloon3_unmask_irq(struct irq_data *d)
487 int balloon3_irq = (d->irq - BALLOON3_IRQ(0));
488 balloon3_irq_enabled |= (1 << balloon3_irq);
489 __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
492 static struct irq_chip balloon3_irq_chip = {
494 .irq_ack = balloon3_mask_irq,
495 .irq_mask = balloon3_mask_irq,
496 .irq_unmask = balloon3_unmask_irq,
499 static void balloon3_irq_handler(unsigned int irq, struct irq_desc *desc)
501 unsigned long pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
502 balloon3_irq_enabled;
504 /* clear useless edge notification */
505 if (desc->irq_data.chip->irq_ack) {
508 d = irq_get_irq_data(BALLOON3_AUX_NIRQ);
509 desc->irq_data.chip->irq_ack(d);
513 irq = BALLOON3_IRQ(0) + __ffs(pending);
514 generic_handle_irq(irq);
515 pending &= pending - 1;
517 pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
518 balloon3_irq_enabled;
522 static void __init balloon3_init_irq(void)
527 /* setup extra Balloon3 irqs */
528 for (irq = BALLOON3_IRQ(0); irq <= BALLOON3_IRQ(7); irq++) {
529 irq_set_chip_and_handler(irq, &balloon3_irq_chip,
531 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
534 irq_set_chained_handler(BALLOON3_AUX_NIRQ, balloon3_irq_handler);
535 irq_set_irq_type(BALLOON3_AUX_NIRQ, IRQ_TYPE_EDGE_FALLING);
537 pr_debug("%s: chained handler installed - irq %d automatically "
538 "enabled\n", __func__, BALLOON3_AUX_NIRQ);
541 /******************************************************************************
543 ******************************************************************************/
544 #if defined(CONFIG_GPIO_PCF857X) || defined(CONFIG_GPIO_PCF857X_MODULE)
545 static struct pcf857x_platform_data balloon3_pcf857x_pdata = {
546 .gpio_base = BALLOON3_PCF_GPIO_BASE,
553 static struct i2c_board_info __initdata balloon3_i2c_devs[] = {
555 I2C_BOARD_INFO("pcf8574a", 0x38),
556 .platform_data = &balloon3_pcf857x_pdata,
560 static void __init balloon3_i2c_init(void)
562 pxa_set_i2c_info(NULL);
563 i2c_register_board_info(0, ARRAY_AND_SIZE(balloon3_i2c_devs));
566 static inline void balloon3_i2c_init(void) {}
569 /******************************************************************************
571 ******************************************************************************/
572 #if defined(CONFIG_MTD_NAND_PLATFORM)||defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
573 static void balloon3_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
575 struct nand_chip *this = mtd->priv;
576 uint8_t balloon3_ctl_set = 0, balloon3_ctl_clr = 0;
578 if (ctrl & NAND_CTRL_CHANGE) {
580 balloon3_ctl_set |= BALLOON3_NAND_CONTROL_FLCLE;
582 balloon3_ctl_clr |= BALLOON3_NAND_CONTROL_FLCLE;
585 balloon3_ctl_set |= BALLOON3_NAND_CONTROL_FLALE;
587 balloon3_ctl_clr |= BALLOON3_NAND_CONTROL_FLALE;
589 if (balloon3_ctl_clr)
590 __raw_writel(balloon3_ctl_clr,
591 BALLOON3_NAND_CONTROL_REG);
592 if (balloon3_ctl_set)
593 __raw_writel(balloon3_ctl_set,
594 BALLOON3_NAND_CONTROL_REG +
595 BALLOON3_FPGA_SETnCLR);
598 if (cmd != NAND_CMD_NONE)
599 writeb(cmd, this->IO_ADDR_W);
602 static void balloon3_nand_select_chip(struct mtd_info *mtd, int chip)
604 if (chip < 0 || chip > 3)
607 /* Assert all nCE lines */
609 BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
610 BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3,
611 BALLOON3_NAND_CONTROL_REG + BALLOON3_FPGA_SETnCLR);
613 /* Deassert correct nCE line */
614 __raw_writew(BALLOON3_NAND_CONTROL_FLCE0 << chip,
615 BALLOON3_NAND_CONTROL_REG);
618 static int balloon3_nand_dev_ready(struct mtd_info *mtd)
620 return __raw_readl(BALLOON3_NAND_STAT_REG) & BALLOON3_NAND_STAT_RNB;
623 static int balloon3_nand_probe(struct platform_device *pdev)
628 __raw_writew(BALLOON3_NAND_CONTROL2_16BIT,
629 BALLOON3_NAND_CONTROL2_REG + BALLOON3_FPGA_SETnCLR);
631 ver = __raw_readw(BALLOON3_FPGA_VER);
633 pr_warn("The FPGA code, version 0x%04x, is too old. "
634 "NAND support might be broken in this version!", ver);
636 /* Power up the NAND chips */
637 ret = gpio_request(BALLOON3_GPIO_RUN_NAND, "NAND");
641 ret = gpio_direction_output(BALLOON3_GPIO_RUN_NAND, 1);
645 gpio_set_value(BALLOON3_GPIO_RUN_NAND, 1);
647 /* Deassert all nCE lines and write protect line */
649 BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
650 BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3 |
651 BALLOON3_NAND_CONTROL_FLWP,
652 BALLOON3_NAND_CONTROL_REG + BALLOON3_FPGA_SETnCLR);
656 gpio_free(BALLOON3_GPIO_RUN_NAND);
661 static void balloon3_nand_remove(struct platform_device *pdev)
663 /* Power down the NAND chips */
664 gpio_set_value(BALLOON3_GPIO_RUN_NAND, 0);
665 gpio_free(BALLOON3_GPIO_RUN_NAND);
668 static struct mtd_partition balloon3_partition_info[] = {
676 .offset = MTDPART_OFS_APPEND,
677 .size = MTDPART_SIZ_FULL
681 static const char *balloon3_part_probes[] = { "cmdlinepart", NULL };
683 struct platform_nand_data balloon3_nand_pdata = {
687 .nr_partitions = ARRAY_SIZE(balloon3_partition_info),
688 .partitions = balloon3_partition_info,
690 .part_probe_types = balloon3_part_probes,
694 .dev_ready = balloon3_nand_dev_ready,
695 .select_chip = balloon3_nand_select_chip,
696 .cmd_ctrl = balloon3_nand_cmd_ctl,
697 .probe = balloon3_nand_probe,
698 .remove = balloon3_nand_remove,
702 static struct resource balloon3_nand_resource[] = {
704 .start = BALLOON3_NAND_BASE,
705 .end = BALLOON3_NAND_BASE + 0x4,
706 .flags = IORESOURCE_MEM,
710 static struct platform_device balloon3_nand = {
712 .num_resources = ARRAY_SIZE(balloon3_nand_resource),
713 .resource = balloon3_nand_resource,
716 .platform_data = &balloon3_nand_pdata,
720 static void __init balloon3_nand_init(void)
722 platform_device_register(&balloon3_nand);
725 static inline void balloon3_nand_init(void) {}
728 /******************************************************************************
729 * Core power regulator
730 ******************************************************************************/
731 #if defined(CONFIG_REGULATOR_MAX1586) || \
732 defined(CONFIG_REGULATOR_MAX1586_MODULE)
733 static struct regulator_consumer_supply balloon3_max1587a_consumers[] = {
735 .supply = "vcc_core",
739 static struct regulator_init_data balloon3_max1587a_v3_info = {
741 .name = "vcc_core range",
745 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
747 .consumer_supplies = balloon3_max1587a_consumers,
748 .num_consumer_supplies = ARRAY_SIZE(balloon3_max1587a_consumers),
751 static struct max1586_subdev_data balloon3_max1587a_subdevs[] = {
755 .platform_data = &balloon3_max1587a_v3_info,
759 static struct max1586_platform_data balloon3_max1587a_info = {
760 .subdevs = balloon3_max1587a_subdevs,
761 .num_subdevs = ARRAY_SIZE(balloon3_max1587a_subdevs),
762 .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
765 static struct i2c_board_info __initdata balloon3_pi2c_board_info[] = {
767 I2C_BOARD_INFO("max1586", 0x14),
768 .platform_data = &balloon3_max1587a_info,
772 static void __init balloon3_pmic_init(void)
774 pxa27x_set_i2c_power_info(NULL);
775 i2c_register_board_info(1, ARRAY_AND_SIZE(balloon3_pi2c_board_info));
778 static inline void balloon3_pmic_init(void) {}
781 /******************************************************************************
783 ******************************************************************************/
784 static void __init balloon3_init(void)
786 ARB_CNTRL = ARB_CORE_PARK | 0x234;
788 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_pin_config));
790 pxa_set_ffuart_info(NULL);
791 pxa_set_btuart_info(NULL);
792 pxa_set_stuart_info(NULL);
795 balloon3_irda_init();
797 balloon3_leds_init();
799 balloon3_nand_init();
801 balloon3_pmic_init();
808 static struct map_desc balloon3_io_desc[] __initdata = {
810 .virtual = (unsigned long)BALLOON3_FPGA_VIRT,
811 .pfn = __phys_to_pfn(BALLOON3_FPGA_PHYS),
812 .length = BALLOON3_FPGA_LENGTH,
817 static void __init balloon3_map_io(void)
820 iotable_init(balloon3_io_desc, ARRAY_SIZE(balloon3_io_desc));
823 MACHINE_START(BALLOON3, "Balloon3")
824 /* Maintainer: Nick Bane. */
825 .map_io = balloon3_map_io,
826 .nr_irqs = BALLOON3_NR_IRQS,
827 .init_irq = balloon3_init_irq,
828 .handle_irq = pxa27x_handle_irq,
830 .init_machine = balloon3_init,
831 .atag_offset = 0x100,