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/export.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/interrupt.h>
20 #include <linux/leds.h>
21 #include <linux/sched.h>
22 #include <linux/bitops.h>
24 #include <linux/gpio.h>
25 #include <linux/ioport.h>
26 #include <linux/ucb1400.h>
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/partitions.h>
29 #include <linux/types.h>
30 #include <linux/platform_data/pcf857x.h>
31 #include <linux/platform_data/i2c-pxa.h>
32 #include <linux/mtd/rawnand.h>
33 #include <linux/mtd/physmap.h>
34 #include <linux/regulator/max1586.h>
36 #include <asm/setup.h>
37 #include <asm/mach-types.h>
39 #include <asm/sizes.h>
41 #include <asm/mach/arch.h>
42 #include <asm/mach/map.h>
43 #include <asm/mach/irq.h>
44 #include <asm/mach/flash.h>
47 #include <mach/balloon3.h>
48 #include <mach/audio.h>
49 #include <linux/platform_data/video-pxafb.h>
50 #include <linux/platform_data/mmc-pxamci.h>
52 #include "pxa27x-udc.h"
53 #include <linux/platform_data/irda-pxaficp.h>
54 #include <linux/platform_data/usb-ohci-pxa27x.h>
59 /******************************************************************************
61 ******************************************************************************/
62 static unsigned long balloon3_pin_config[] __initdata = {
63 /* Select BTUART 'COM1/ttyS0' as IO option for pins 42/43/44/45 */
69 /* Reset, configured as GPIO wakeup source */
70 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
73 /******************************************************************************
74 * Compatibility: Parameter parsing
75 ******************************************************************************/
76 static unsigned long balloon3_irq_enabled;
78 static unsigned long balloon3_features_present =
79 (1 << BALLOON3_FEATURE_OHCI) | (1 << BALLOON3_FEATURE_CF) |
80 (1 << BALLOON3_FEATURE_AUDIO) |
81 (1 << BALLOON3_FEATURE_TOPPOLY);
83 int balloon3_has(enum balloon3_features feature)
85 return (balloon3_features_present & (1 << feature)) ? 1 : 0;
87 EXPORT_SYMBOL_GPL(balloon3_has);
89 int __init parse_balloon3_features(char *arg)
94 return kstrtoul(arg, 0, &balloon3_features_present);
96 early_param("balloon3_features", parse_balloon3_features);
98 /******************************************************************************
100 ******************************************************************************/
101 #if defined(CONFIG_PCMCIA_PXA2XX) || defined(CONFIG_PCMCIA_PXA2XX_MODULE)
102 static unsigned long balloon3_cf_pin_config[] __initdata = {
115 static void __init balloon3_cf_init(void)
117 if (!balloon3_has(BALLOON3_FEATURE_CF))
120 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_cf_pin_config));
123 static inline void balloon3_cf_init(void) {}
126 /******************************************************************************
128 ******************************************************************************/
129 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
130 static struct mtd_partition balloon3_nor_partitions[] = {
133 .offset = 0x00000000,
134 .size = MTDPART_SIZ_FULL,
138 static struct physmap_flash_data balloon3_flash_data[] = {
140 .width = 2, /* bankwidth in bytes */
141 .parts = balloon3_nor_partitions,
142 .nr_parts = ARRAY_SIZE(balloon3_nor_partitions)
146 static struct resource balloon3_flash_resource = {
147 .start = PXA_CS0_PHYS,
148 .end = PXA_CS0_PHYS + SZ_64M - 1,
149 .flags = IORESOURCE_MEM,
152 static struct platform_device balloon3_flash = {
153 .name = "physmap-flash",
155 .resource = &balloon3_flash_resource,
158 .platform_data = balloon3_flash_data,
161 static void __init balloon3_nor_init(void)
163 platform_device_register(&balloon3_flash);
166 static inline void balloon3_nor_init(void) {}
169 /******************************************************************************
170 * Audio and Touchscreen
171 ******************************************************************************/
172 #if defined(CONFIG_TOUCHSCREEN_UCB1400) || \
173 defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
174 static unsigned long balloon3_ac97_pin_config[] __initdata = {
176 GPIO29_AC97_SDATA_IN_0,
177 GPIO30_AC97_SDATA_OUT,
183 static struct ucb1400_pdata vpac270_ucb1400_pdata = {
184 .irq = PXA_GPIO_TO_IRQ(BALLOON3_GPIO_CODEC_IRQ),
188 static struct platform_device balloon3_ucb1400_device = {
189 .name = "ucb1400_core",
192 .platform_data = &vpac270_ucb1400_pdata,
196 static void __init balloon3_ts_init(void)
198 if (!balloon3_has(BALLOON3_FEATURE_AUDIO))
201 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_ac97_pin_config));
202 pxa_set_ac97_info(NULL);
203 platform_device_register(&balloon3_ucb1400_device);
206 static inline void balloon3_ts_init(void) {}
209 /******************************************************************************
211 ******************************************************************************/
212 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
213 static unsigned long balloon3_lcd_pin_config[] __initdata = {
214 GPIOxx_LCD_TFT_16BPP,
218 static struct pxafb_mode_info balloon3_lcd_modes[] = {
234 static struct pxafb_mach_info balloon3_lcd_screen = {
235 .modes = balloon3_lcd_modes,
236 .num_modes = ARRAY_SIZE(balloon3_lcd_modes),
237 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
240 static void balloon3_backlight_power(int on)
242 gpio_set_value(BALLOON3_GPIO_RUN_BACKLIGHT, on);
245 static void __init balloon3_lcd_init(void)
249 if (!balloon3_has(BALLOON3_FEATURE_TOPPOLY))
252 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_lcd_pin_config));
254 ret = gpio_request(BALLOON3_GPIO_RUN_BACKLIGHT, "BKL-ON");
256 pr_err("Requesting BKL-ON GPIO failed!\n");
260 ret = gpio_direction_output(BALLOON3_GPIO_RUN_BACKLIGHT, 1);
262 pr_err("Setting BKL-ON GPIO direction failed!\n");
266 balloon3_lcd_screen.pxafb_backlight_power = balloon3_backlight_power;
267 pxa_set_fb_info(NULL, &balloon3_lcd_screen);
271 gpio_free(BALLOON3_GPIO_RUN_BACKLIGHT);
276 static inline void balloon3_lcd_init(void) {}
279 /******************************************************************************
280 * SD/MMC card controller
281 ******************************************************************************/
282 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
283 static unsigned long balloon3_mmc_pin_config[] __initdata = {
292 static struct pxamci_platform_data balloon3_mci_platform_data = {
293 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
294 .gpio_card_detect = -1,
297 .detect_delay_ms = 200,
300 static void __init balloon3_mmc_init(void)
302 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_mmc_pin_config));
303 pxa_set_mci_info(&balloon3_mci_platform_data);
306 static inline void balloon3_mmc_init(void) {}
309 /******************************************************************************
311 ******************************************************************************/
312 #if defined(CONFIG_USB_PXA27X)||defined(CONFIG_USB_PXA27X_MODULE)
313 static void balloon3_udc_command(int cmd)
315 if (cmd == PXA2XX_UDC_CMD_CONNECT)
316 UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
317 else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
318 UP2OCR &= ~UP2OCR_DPPUE;
321 static int balloon3_udc_is_connected(void)
326 static struct pxa2xx_udc_mach_info balloon3_udc_info __initdata = {
327 .udc_command = balloon3_udc_command,
328 .udc_is_connected = balloon3_udc_is_connected,
332 static void __init balloon3_udc_init(void)
334 pxa_set_udc_info(&balloon3_udc_info);
337 static inline void balloon3_udc_init(void) {}
340 /******************************************************************************
342 ******************************************************************************/
343 #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
344 static struct pxaficp_platform_data balloon3_ficp_platform_data = {
345 .transceiver_cap = IR_FIRMODE | IR_SIRMODE | IR_OFF,
348 static void __init balloon3_irda_init(void)
350 pxa_set_ficp_info(&balloon3_ficp_platform_data);
353 static inline void balloon3_irda_init(void) {}
356 /******************************************************************************
358 ******************************************************************************/
359 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
360 static unsigned long balloon3_uhc_pin_config[] __initdata = {
365 static struct pxaohci_platform_data balloon3_ohci_info = {
366 .port_mode = PMM_PERPORT_MODE,
367 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
370 static void __init balloon3_uhc_init(void)
372 if (!balloon3_has(BALLOON3_FEATURE_OHCI))
374 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_uhc_pin_config));
375 pxa_set_ohci_info(&balloon3_ohci_info);
378 static inline void balloon3_uhc_init(void) {}
381 /******************************************************************************
383 ******************************************************************************/
384 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
385 static unsigned long balloon3_led_pin_config[] __initdata = {
386 GPIO9_GPIO, /* NAND activity LED */
387 GPIO10_GPIO, /* Heartbeat LED */
390 struct gpio_led balloon3_gpio_leds[] = {
392 .name = "balloon3:green:idle",
393 .default_trigger = "heartbeat",
394 .gpio = BALLOON3_GPIO_LED_IDLE,
397 .name = "balloon3:green:nand",
398 .default_trigger = "nand-disk",
399 .gpio = BALLOON3_GPIO_LED_NAND,
404 static struct gpio_led_platform_data balloon3_gpio_led_info = {
405 .leds = balloon3_gpio_leds,
406 .num_leds = ARRAY_SIZE(balloon3_gpio_leds),
409 static struct platform_device balloon3_leds = {
413 .platform_data = &balloon3_gpio_led_info,
417 struct gpio_led balloon3_pcf_gpio_leds[] = {
419 .name = "balloon3:green:led0",
420 .gpio = BALLOON3_PCF_GPIO_LED0,
423 .name = "balloon3:green:led1",
424 .gpio = BALLOON3_PCF_GPIO_LED1,
427 .name = "balloon3:orange:led2",
428 .gpio = BALLOON3_PCF_GPIO_LED2,
431 .name = "balloon3:orange:led3",
432 .gpio = BALLOON3_PCF_GPIO_LED3,
435 .name = "balloon3:orange:led4",
436 .gpio = BALLOON3_PCF_GPIO_LED4,
439 .name = "balloon3:orange:led5",
440 .gpio = BALLOON3_PCF_GPIO_LED5,
443 .name = "balloon3:red:led6",
444 .gpio = BALLOON3_PCF_GPIO_LED6,
447 .name = "balloon3:red:led7",
448 .gpio = BALLOON3_PCF_GPIO_LED7,
453 static struct gpio_led_platform_data balloon3_pcf_gpio_led_info = {
454 .leds = balloon3_pcf_gpio_leds,
455 .num_leds = ARRAY_SIZE(balloon3_pcf_gpio_leds),
458 static struct platform_device balloon3_pcf_leds = {
462 .platform_data = &balloon3_pcf_gpio_led_info,
466 static void __init balloon3_leds_init(void)
468 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_led_pin_config));
469 platform_device_register(&balloon3_leds);
470 platform_device_register(&balloon3_pcf_leds);
473 static inline void balloon3_leds_init(void) {}
476 /******************************************************************************
478 ******************************************************************************/
479 static void balloon3_mask_irq(struct irq_data *d)
481 int balloon3_irq = (d->irq - BALLOON3_IRQ(0));
482 balloon3_irq_enabled &= ~(1 << balloon3_irq);
483 __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
486 static void balloon3_unmask_irq(struct irq_data *d)
488 int balloon3_irq = (d->irq - BALLOON3_IRQ(0));
489 balloon3_irq_enabled |= (1 << balloon3_irq);
490 __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
493 static struct irq_chip balloon3_irq_chip = {
495 .irq_ack = balloon3_mask_irq,
496 .irq_mask = balloon3_mask_irq,
497 .irq_unmask = balloon3_unmask_irq,
500 static void balloon3_irq_handler(struct irq_desc *desc)
502 unsigned long pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
503 balloon3_irq_enabled;
505 struct irq_data *d = irq_desc_get_irq_data(desc);
506 struct irq_chip *chip = irq_desc_get_chip(desc);
509 /* clear useless edge notification */
514 irq = BALLOON3_IRQ(0) + __ffs(pending);
515 generic_handle_irq(irq);
516 pending &= pending - 1;
518 pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
519 balloon3_irq_enabled;
523 static void __init balloon3_init_irq(void)
528 /* setup extra Balloon3 irqs */
529 for (irq = BALLOON3_IRQ(0); irq <= BALLOON3_IRQ(7); irq++) {
530 irq_set_chip_and_handler(irq, &balloon3_irq_chip,
532 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
535 irq_set_chained_handler(BALLOON3_AUX_NIRQ, balloon3_irq_handler);
536 irq_set_irq_type(BALLOON3_AUX_NIRQ, IRQ_TYPE_EDGE_FALLING);
538 pr_debug("%s: chained handler installed - irq %d automatically "
539 "enabled\n", __func__, BALLOON3_AUX_NIRQ);
542 /******************************************************************************
544 ******************************************************************************/
545 #if defined(CONFIG_GPIO_PCF857X) || defined(CONFIG_GPIO_PCF857X_MODULE)
546 static struct pcf857x_platform_data balloon3_pcf857x_pdata = {
547 .gpio_base = BALLOON3_PCF_GPIO_BASE,
554 static struct i2c_board_info __initdata balloon3_i2c_devs[] = {
556 I2C_BOARD_INFO("pcf8574a", 0x38),
557 .platform_data = &balloon3_pcf857x_pdata,
561 static void __init balloon3_i2c_init(void)
563 pxa_set_i2c_info(NULL);
564 i2c_register_board_info(0, ARRAY_AND_SIZE(balloon3_i2c_devs));
567 static inline void balloon3_i2c_init(void) {}
570 /******************************************************************************
572 ******************************************************************************/
573 #if defined(CONFIG_MTD_NAND_PLATFORM)||defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
574 static void balloon3_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
576 struct nand_chip *this = mtd_to_nand(mtd);
577 uint8_t balloon3_ctl_set = 0, balloon3_ctl_clr = 0;
579 if (ctrl & NAND_CTRL_CHANGE) {
581 balloon3_ctl_set |= BALLOON3_NAND_CONTROL_FLCLE;
583 balloon3_ctl_clr |= BALLOON3_NAND_CONTROL_FLCLE;
586 balloon3_ctl_set |= BALLOON3_NAND_CONTROL_FLALE;
588 balloon3_ctl_clr |= BALLOON3_NAND_CONTROL_FLALE;
590 if (balloon3_ctl_clr)
591 __raw_writel(balloon3_ctl_clr,
592 BALLOON3_NAND_CONTROL_REG);
593 if (balloon3_ctl_set)
594 __raw_writel(balloon3_ctl_set,
595 BALLOON3_NAND_CONTROL_REG +
596 BALLOON3_FPGA_SETnCLR);
599 if (cmd != NAND_CMD_NONE)
600 writeb(cmd, this->IO_ADDR_W);
603 static void balloon3_nand_select_chip(struct mtd_info *mtd, int chip)
605 if (chip < 0 || chip > 3)
608 /* Assert all nCE lines */
610 BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
611 BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3,
612 BALLOON3_NAND_CONTROL_REG + BALLOON3_FPGA_SETnCLR);
614 /* Deassert correct nCE line */
615 __raw_writew(BALLOON3_NAND_CONTROL_FLCE0 << chip,
616 BALLOON3_NAND_CONTROL_REG);
619 static int balloon3_nand_dev_ready(struct mtd_info *mtd)
621 return __raw_readl(BALLOON3_NAND_STAT_REG) & BALLOON3_NAND_STAT_RNB;
624 static int balloon3_nand_probe(struct platform_device *pdev)
629 __raw_writew(BALLOON3_NAND_CONTROL2_16BIT,
630 BALLOON3_NAND_CONTROL2_REG + BALLOON3_FPGA_SETnCLR);
632 ver = __raw_readw(BALLOON3_FPGA_VER);
634 pr_warn("The FPGA code, version 0x%04x, is too old. "
635 "NAND support might be broken in this version!", ver);
637 /* Power up the NAND chips */
638 ret = gpio_request(BALLOON3_GPIO_RUN_NAND, "NAND");
642 ret = gpio_direction_output(BALLOON3_GPIO_RUN_NAND, 1);
646 gpio_set_value(BALLOON3_GPIO_RUN_NAND, 1);
648 /* Deassert all nCE lines and write protect line */
650 BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
651 BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3 |
652 BALLOON3_NAND_CONTROL_FLWP,
653 BALLOON3_NAND_CONTROL_REG + BALLOON3_FPGA_SETnCLR);
657 gpio_free(BALLOON3_GPIO_RUN_NAND);
662 static void balloon3_nand_remove(struct platform_device *pdev)
664 /* Power down the NAND chips */
665 gpio_set_value(BALLOON3_GPIO_RUN_NAND, 0);
666 gpio_free(BALLOON3_GPIO_RUN_NAND);
669 static struct mtd_partition balloon3_partition_info[] = {
677 .offset = MTDPART_OFS_APPEND,
678 .size = MTDPART_SIZ_FULL
682 struct platform_nand_data balloon3_nand_pdata = {
686 .nr_partitions = ARRAY_SIZE(balloon3_partition_info),
687 .partitions = balloon3_partition_info,
691 .dev_ready = balloon3_nand_dev_ready,
692 .select_chip = balloon3_nand_select_chip,
693 .cmd_ctrl = balloon3_nand_cmd_ctl,
694 .probe = balloon3_nand_probe,
695 .remove = balloon3_nand_remove,
699 static struct resource balloon3_nand_resource[] = {
701 .start = BALLOON3_NAND_BASE,
702 .end = BALLOON3_NAND_BASE + 0x4,
703 .flags = IORESOURCE_MEM,
707 static struct platform_device balloon3_nand = {
709 .num_resources = ARRAY_SIZE(balloon3_nand_resource),
710 .resource = balloon3_nand_resource,
713 .platform_data = &balloon3_nand_pdata,
717 static void __init balloon3_nand_init(void)
719 platform_device_register(&balloon3_nand);
722 static inline void balloon3_nand_init(void) {}
725 /******************************************************************************
726 * Core power regulator
727 ******************************************************************************/
728 #if defined(CONFIG_REGULATOR_MAX1586) || \
729 defined(CONFIG_REGULATOR_MAX1586_MODULE)
730 static struct regulator_consumer_supply balloon3_max1587a_consumers[] = {
731 REGULATOR_SUPPLY("vcc_core", NULL),
734 static struct regulator_init_data balloon3_max1587a_v3_info = {
736 .name = "vcc_core range",
740 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
742 .consumer_supplies = balloon3_max1587a_consumers,
743 .num_consumer_supplies = ARRAY_SIZE(balloon3_max1587a_consumers),
746 static struct max1586_subdev_data balloon3_max1587a_subdevs[] = {
750 .platform_data = &balloon3_max1587a_v3_info,
754 static struct max1586_platform_data balloon3_max1587a_info = {
755 .subdevs = balloon3_max1587a_subdevs,
756 .num_subdevs = ARRAY_SIZE(balloon3_max1587a_subdevs),
757 .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
760 static struct i2c_board_info __initdata balloon3_pi2c_board_info[] = {
762 I2C_BOARD_INFO("max1586", 0x14),
763 .platform_data = &balloon3_max1587a_info,
767 static void __init balloon3_pmic_init(void)
769 pxa27x_set_i2c_power_info(NULL);
770 i2c_register_board_info(1, ARRAY_AND_SIZE(balloon3_pi2c_board_info));
773 static inline void balloon3_pmic_init(void) {}
776 /******************************************************************************
778 ******************************************************************************/
779 static void __init balloon3_init(void)
781 ARB_CNTRL = ARB_CORE_PARK | 0x234;
783 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_pin_config));
785 pxa_set_ffuart_info(NULL);
786 pxa_set_btuart_info(NULL);
787 pxa_set_stuart_info(NULL);
790 balloon3_irda_init();
792 balloon3_leds_init();
794 balloon3_nand_init();
796 balloon3_pmic_init();
803 static struct map_desc balloon3_io_desc[] __initdata = {
805 .virtual = (unsigned long)BALLOON3_FPGA_VIRT,
806 .pfn = __phys_to_pfn(BALLOON3_FPGA_PHYS),
807 .length = BALLOON3_FPGA_LENGTH,
812 static void __init balloon3_map_io(void)
815 iotable_init(balloon3_io_desc, ARRAY_SIZE(balloon3_io_desc));
818 MACHINE_START(BALLOON3, "Balloon3")
819 /* Maintainer: Nick Bane. */
820 .map_io = balloon3_map_io,
821 .nr_irqs = BALLOON3_NR_IRQS,
822 .init_irq = balloon3_init_irq,
823 .handle_irq = pxa27x_handle_irq,
824 .init_time = pxa_timer_init,
825 .init_machine = balloon3_init,
826 .atag_offset = 0x100,
827 .restart = pxa_restart,