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/sysdev.h>
19 #include <linux/interrupt.h>
20 #include <linux/sched.h>
21 #include <linux/bitops.h>
23 #include <linux/gpio.h>
24 #include <linux/ioport.h>
25 #include <linux/ucb1400.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/types.h>
29 #include <linux/i2c/pcf857x.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>
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 GPIO9_GPIO, /* NAND activity LED */
74 GPIO10_GPIO, /* Heartbeat LED */
78 GPIO29_AC97_SDATA_IN_0,
79 GPIO30_AC97_SDATA_OUT,
109 /******************************************************************************
110 * Compatibility: Parameter parsing
111 ******************************************************************************/
112 static unsigned long balloon3_irq_enabled;
114 static unsigned long balloon3_features_present =
115 (1 << BALLOON3_FEATURE_OHCI) | (1 << BALLOON3_FEATURE_CF) |
116 (1 << BALLOON3_FEATURE_AUDIO) |
117 (1 << BALLOON3_FEATURE_TOPPOLY);
119 int balloon3_has(enum balloon3_features feature)
121 return (balloon3_features_present & (1 << feature)) ? 1 : 0;
123 EXPORT_SYMBOL_GPL(balloon3_has);
125 int __init parse_balloon3_features(char *arg)
130 return strict_strtoul(arg, 0, &balloon3_features_present);
132 early_param("balloon3_features", parse_balloon3_features);
134 /******************************************************************************
136 ******************************************************************************/
137 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
138 static struct mtd_partition balloon3_nor_partitions[] = {
141 .offset = 0x00000000,
142 .size = MTDPART_SIZ_FULL,
146 static struct physmap_flash_data balloon3_flash_data[] = {
148 .width = 2, /* bankwidth in bytes */
149 .parts = balloon3_nor_partitions,
150 .nr_parts = ARRAY_SIZE(balloon3_nor_partitions)
154 static struct resource balloon3_flash_resource = {
155 .start = PXA_CS0_PHYS,
156 .end = PXA_CS0_PHYS + SZ_64M - 1,
157 .flags = IORESOURCE_MEM,
160 static struct platform_device balloon3_flash = {
161 .name = "physmap-flash",
163 .resource = &balloon3_flash_resource,
166 .platform_data = balloon3_flash_data,
169 static void __init balloon3_nor_init(void)
171 platform_device_register(&balloon3_flash);
174 static inline void balloon3_nor_init(void) {}
177 /******************************************************************************
178 * Audio and Touchscreen
179 ******************************************************************************/
180 #if defined(CONFIG_TOUCHSCREEN_UCB1400) || \
181 defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
182 static struct ucb1400_pdata vpac270_ucb1400_pdata = {
183 .irq = IRQ_GPIO(BALLOON3_GPIO_CODEC_IRQ),
187 static struct platform_device balloon3_ucb1400_device = {
188 .name = "ucb1400_core",
191 .platform_data = &vpac270_ucb1400_pdata,
195 static void __init balloon3_ts_init(void)
197 if (!balloon3_has(BALLOON3_FEATURE_AUDIO))
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 struct pxafb_mode_info balloon3_lcd_modes[] = {
227 static struct pxafb_mach_info balloon3_lcd_screen = {
228 .modes = balloon3_lcd_modes,
229 .num_modes = ARRAY_SIZE(balloon3_lcd_modes),
230 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
233 static void balloon3_backlight_power(int on)
235 gpio_set_value(BALLOON3_GPIO_RUN_BACKLIGHT, on);
238 static void __init balloon3_lcd_init(void)
242 if (!balloon3_has(BALLOON3_FEATURE_TOPPOLY))
245 ret = gpio_request(BALLOON3_GPIO_RUN_BACKLIGHT, "BKL-ON");
247 pr_err("Requesting BKL-ON GPIO failed!\n");
251 ret = gpio_direction_output(BALLOON3_GPIO_RUN_BACKLIGHT, 1);
253 pr_err("Setting BKL-ON GPIO direction failed!\n");
257 balloon3_lcd_screen.pxafb_backlight_power = balloon3_backlight_power;
258 set_pxa_fb_info(&balloon3_lcd_screen);
262 gpio_free(BALLOON3_GPIO_RUN_BACKLIGHT);
267 static inline void balloon3_lcd_init(void) {}
270 /******************************************************************************
271 * SD/MMC card controller
272 ******************************************************************************/
273 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
274 static struct pxamci_platform_data balloon3_mci_platform_data = {
275 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
276 .gpio_card_detect = -1,
279 .detect_delay_ms = 200,
282 static void __init balloon3_mmc_init(void)
284 pxa_set_mci_info(&balloon3_mci_platform_data);
287 static inline void balloon3_mmc_init(void) {}
290 /******************************************************************************
292 ******************************************************************************/
293 #if defined(CONFIG_USB_GADGET_PXA27X)||defined(CONFIG_USB_GADGET_PXA27X_MODULE)
294 static void balloon3_udc_command(int cmd)
296 if (cmd == PXA2XX_UDC_CMD_CONNECT)
297 UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
298 else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
299 UP2OCR &= ~UP2OCR_DPPUE;
302 static int balloon3_udc_is_connected(void)
307 static struct pxa2xx_udc_mach_info balloon3_udc_info __initdata = {
308 .udc_command = balloon3_udc_command,
309 .udc_is_connected = balloon3_udc_is_connected,
313 static void __init balloon3_udc_init(void)
315 pxa_set_udc_info(&balloon3_udc_info);
316 platform_device_register(&balloon3_gpio_vbus);
319 static inline void balloon3_udc_init(void) {}
322 /******************************************************************************
324 ******************************************************************************/
325 #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
326 static struct pxaficp_platform_data balloon3_ficp_platform_data = {
327 .transceiver_cap = IR_FIRMODE | IR_SIRMODE | IR_OFF,
330 static void __init balloon3_irda_init(void)
332 pxa_set_ficp_info(&balloon3_ficp_platform_data);
335 static inline void balloon3_irda_init(void) {}
338 /******************************************************************************
340 ******************************************************************************/
341 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
342 static struct pxaohci_platform_data balloon3_ohci_info = {
343 .port_mode = PMM_PERPORT_MODE,
344 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
347 static void __init balloon3_uhc_init(void)
349 if (!balloon3_has(BALLOON3_FEATURE_OHCI))
351 pxa_set_ohci_info(&balloon3_ohci_info);
354 static inline void balloon3_uhc_init(void) {}
357 /******************************************************************************
359 ******************************************************************************/
360 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
361 struct gpio_led balloon3_gpio_leds[] = {
363 .name = "balloon3:green:idle",
364 .default_trigger = "heartbeat",
365 .gpio = BALLOON3_GPIO_LED_IDLE,
368 .name = "balloon3:green:nand",
369 .default_trigger = "nand-disk",
370 .gpio = BALLOON3_GPIO_LED_NAND,
375 static struct gpio_led_platform_data balloon3_gpio_led_info = {
376 .leds = balloon3_gpio_leds,
377 .num_leds = ARRAY_SIZE(balloon3_gpio_leds),
380 static struct platform_device balloon3_leds = {
384 .platform_data = &balloon3_gpio_led_info,
388 struct gpio_led balloon3_pcf_gpio_leds[] = {
390 .name = "balloon3:green:led0",
391 .gpio = BALLOON3_PCF_GPIO_LED0,
394 .name = "balloon3:green:led1",
395 .gpio = BALLOON3_PCF_GPIO_LED1,
398 .name = "balloon3:orange:led2",
399 .gpio = BALLOON3_PCF_GPIO_LED2,
402 .name = "balloon3:orange:led3",
403 .gpio = BALLOON3_PCF_GPIO_LED3,
406 .name = "balloon3:orange:led4",
407 .gpio = BALLOON3_PCF_GPIO_LED4,
410 .name = "balloon3:orange:led5",
411 .gpio = BALLOON3_PCF_GPIO_LED5,
414 .name = "balloon3:red:led6",
415 .gpio = BALLOON3_PCF_GPIO_LED6,
418 .name = "balloon3:red:led7",
419 .gpio = BALLOON3_PCF_GPIO_LED7,
424 static struct gpio_led_platform_data balloon3_pcf_gpio_led_info = {
425 .leds = balloon3_pcf_gpio_leds,
426 .num_leds = ARRAY_SIZE(balloon3_pcf_gpio_leds),
429 static struct platform_device balloon3_pcf_leds = {
433 .platform_data = &balloon3_pcf_gpio_led_info,
437 static void __init balloon3_leds_init(void)
439 platform_device_register(&balloon3_leds);
440 platform_device_register(&balloon3_pcf_leds);
443 static inline void balloon3_leds_init(void) {}
446 /******************************************************************************
448 ******************************************************************************/
449 static void balloon3_mask_irq(unsigned int irq)
451 int balloon3_irq = (irq - BALLOON3_IRQ(0));
452 balloon3_irq_enabled &= ~(1 << balloon3_irq);
453 __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
456 static void balloon3_unmask_irq(unsigned int irq)
458 int balloon3_irq = (irq - BALLOON3_IRQ(0));
459 balloon3_irq_enabled |= (1 << balloon3_irq);
460 __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
463 static struct irq_chip balloon3_irq_chip = {
465 .ack = balloon3_mask_irq,
466 .mask = balloon3_mask_irq,
467 .unmask = balloon3_unmask_irq,
470 static void balloon3_irq_handler(unsigned int irq, struct irq_desc *desc)
472 unsigned long pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
473 balloon3_irq_enabled;
475 /* clear useless edge notification */
477 desc->chip->ack(BALLOON3_AUX_NIRQ);
479 irq = BALLOON3_IRQ(0) + __ffs(pending);
480 generic_handle_irq(irq);
481 pending &= pending - 1;
483 pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
484 balloon3_irq_enabled;
488 static void __init balloon3_init_irq(void)
493 /* setup extra Balloon3 irqs */
494 for (irq = BALLOON3_IRQ(0); irq <= BALLOON3_IRQ(7); irq++) {
495 set_irq_chip(irq, &balloon3_irq_chip);
496 set_irq_handler(irq, handle_level_irq);
497 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
500 set_irq_chained_handler(BALLOON3_AUX_NIRQ, balloon3_irq_handler);
501 set_irq_type(BALLOON3_AUX_NIRQ, IRQ_TYPE_EDGE_FALLING);
503 pr_debug("%s: chained handler installed - irq %d automatically "
504 "enabled\n", __func__, BALLOON3_AUX_NIRQ);
507 /******************************************************************************
509 ******************************************************************************/
510 #if defined(CONFIG_GPIO_PCF857X) || defined(CONFIG_GPIO_PCF857X_MODULE)
511 static struct pcf857x_platform_data balloon3_pcf857x_pdata = {
512 .gpio_base = BALLOON3_PCF_GPIO_BASE,
519 static struct i2c_board_info __initdata balloon3_i2c_devs[] = {
521 I2C_BOARD_INFO("pcf8574a", 0x38),
522 .platform_data = &balloon3_pcf857x_pdata,
526 static void __init balloon3_i2c_init(void)
528 pxa_set_i2c_info(NULL);
529 i2c_register_board_info(0, ARRAY_AND_SIZE(balloon3_i2c_devs));
532 static inline void balloon3_i2c_init(void) {}
535 /******************************************************************************
537 ******************************************************************************/
538 #if defined(CONFIG_MTD_NAND_PLATFORM)||defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
539 static uint16_t balloon3_ctl =
540 BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
541 BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3 |
542 BALLOON3_NAND_CONTROL_FLWP;
544 static void balloon3_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
546 struct nand_chip *this = mtd->priv;
548 if (ctrl & NAND_CTRL_CHANGE) {
550 balloon3_ctl |= BALLOON3_NAND_CONTROL_FLCLE;
552 balloon3_ctl &= ~BALLOON3_NAND_CONTROL_FLCLE;
555 balloon3_ctl |= BALLOON3_NAND_CONTROL_FLALE;
557 balloon3_ctl &= ~BALLOON3_NAND_CONTROL_FLALE;
559 __raw_writel(balloon3_ctl, BALLOON3_NAND_CONTROL_REG);
562 if (cmd != NAND_CMD_NONE)
563 writeb(cmd, this->IO_ADDR_W);
566 static void balloon3_nand_select_chip(struct mtd_info *mtd, int chip)
568 if (chip < 0 || chip > 3)
571 balloon3_ctl |= BALLOON3_NAND_CONTROL_FLCE0 |
572 BALLOON3_NAND_CONTROL_FLCE1 |
573 BALLOON3_NAND_CONTROL_FLCE2 |
574 BALLOON3_NAND_CONTROL_FLCE3;
576 /* Deassert correct nCE line */
577 balloon3_ctl &= ~(BALLOON3_NAND_CONTROL_FLCE0 << chip);
579 __raw_writew(balloon3_ctl, BALLOON3_NAND_CONTROL_REG);
582 static int balloon3_nand_probe(struct platform_device *pdev)
584 void __iomem *temp_map;
588 __raw_writew(BALLOON3_NAND_CONTROL2_16BIT, BALLOON3_NAND_CONTROL2_REG);
590 ver = __raw_readw(BALLOON3_FPGA_VER);
592 pr_warn("The FPGA code, version 0x%04x, is newer than rel-0.3. "
593 "NAND support might be broken in this version!", ver);
595 /* Power up the NAND chips */
596 ret = gpio_request(BALLOON3_GPIO_RUN_NAND, "NAND");
600 ret = gpio_direction_output(BALLOON3_GPIO_RUN_NAND, 1);
604 gpio_set_value(BALLOON3_GPIO_RUN_NAND, 1);
606 /* Deassert all nCE lines and write protect line */
607 __raw_writel(balloon3_ctl, BALLOON3_NAND_CONTROL_REG);
611 gpio_free(BALLOON3_GPIO_RUN_NAND);
616 static void balloon3_nand_remove(struct platform_device *pdev)
618 /* Power down the NAND chips */
619 gpio_set_value(BALLOON3_GPIO_RUN_NAND, 0);
620 gpio_free(BALLOON3_GPIO_RUN_NAND);
623 static struct mtd_partition balloon3_partition_info[] = {
631 .offset = MTDPART_OFS_APPEND,
632 .size = MTDPART_SIZ_FULL
636 static const char *balloon3_part_probes[] = { "cmdlinepart", NULL };
638 struct platform_nand_data balloon3_nand_pdata = {
642 .nr_partitions = ARRAY_SIZE(balloon3_partition_info),
643 .partitions = balloon3_partition_info,
645 .part_probe_types = balloon3_part_probes,
650 .select_chip = balloon3_nand_select_chip,
651 .cmd_ctrl = balloon3_nand_cmd_ctl,
652 .probe = balloon3_nand_probe,
653 .remove = balloon3_nand_remove,
657 static struct resource balloon3_nand_resource[] = {
659 .start = BALLOON3_NAND_BASE,
660 .end = BALLOON3_NAND_BASE + 0x4,
661 .flags = IORESOURCE_MEM,
665 static struct platform_device balloon3_nand = {
667 .num_resources = ARRAY_SIZE(balloon3_nand_resource),
668 .resource = balloon3_nand_resource,
671 .platform_data = &balloon3_nand_pdata,
675 static void __init balloon3_nand_init(void)
677 platform_device_register(&balloon3_nand);
680 static inline void balloon3_nand_init(void) {}
683 /******************************************************************************
684 * Core power regulator
685 ******************************************************************************/
686 #if defined(CONFIG_REGULATOR_MAX1586) || \
687 defined(CONFIG_REGULATOR_MAX1586_MODULE)
688 static struct regulator_consumer_supply balloon3_max1587a_consumers[] = {
690 .supply = "vcc_core",
694 static struct regulator_init_data balloon3_max1587a_v3_info = {
696 .name = "vcc_core range",
700 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
702 .consumer_supplies = balloon3_max1587a_consumers,
703 .num_consumer_supplies = ARRAY_SIZE(balloon3_max1587a_consumers),
706 static struct max1586_subdev_data balloon3_max1587a_subdevs[] = {
710 .platform_data = &balloon3_max1587a_v3_info,
714 static struct max1586_platform_data balloon3_max1587a_info = {
715 .subdevs = balloon3_max1587a_subdevs,
716 .num_subdevs = ARRAY_SIZE(balloon3_max1587a_subdevs),
717 .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
720 static struct i2c_board_info __initdata balloon3_pi2c_board_info[] = {
722 I2C_BOARD_INFO("max1586", 0x14),
723 .platform_data = &balloon3_max1587a_info,
727 static void __init balloon3_pmic_init(void)
729 pxa27x_set_i2c_power_info(NULL);
730 i2c_register_board_info(1, ARRAY_AND_SIZE(balloon3_pi2c_board_info));
733 static inline void balloon3_pmic_init(void) {}
736 /******************************************************************************
738 ******************************************************************************/
739 static void __init balloon3_init(void)
741 ARB_CNTRL = ARB_CORE_PARK | 0x234;
743 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_pin_config));
745 pxa_set_ffuart_info(NULL);
746 pxa_set_btuart_info(NULL);
747 pxa_set_stuart_info(NULL);
750 balloon3_irda_init();
752 balloon3_leds_init();
754 balloon3_nand_init();
756 balloon3_pmic_init();
762 static struct map_desc balloon3_io_desc[] __initdata = {
764 .virtual = BALLOON3_FPGA_VIRT,
765 .pfn = __phys_to_pfn(BALLOON3_FPGA_PHYS),
766 .length = BALLOON3_FPGA_LENGTH,
771 static void __init balloon3_map_io(void)
774 iotable_init(balloon3_io_desc, ARRAY_SIZE(balloon3_io_desc));
777 MACHINE_START(BALLOON3, "Balloon3")
778 /* Maintainer: Nick Bane. */
779 .phys_io = 0x40000000,
780 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
781 .map_io = balloon3_map_io,
782 .init_irq = balloon3_init_irq,
784 .init_machine = balloon3_init,
785 .boot_params = PHYS_OFFSET + 0x100,