Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  linux/arch/arm/mach-pxa/balloon3.c
0004  *
0005  *  Support for Balloonboard.org Balloon3 board.
0006  *
0007  *  Author: Nick Bane, Wookey, Jonathan McDowell
0008  *  Created:    June, 2006
0009  *  Copyright:  Toby Churchill Ltd
0010  *  Derived from mainstone.c, by Nico Pitre
0011  */
0012 
0013 #include <linux/export.h>
0014 #include <linux/init.h>
0015 #include <linux/platform_device.h>
0016 #include <linux/interrupt.h>
0017 #include <linux/leds.h>
0018 #include <linux/sched.h>
0019 #include <linux/bitops.h>
0020 #include <linux/fb.h>
0021 #include <linux/gpio.h>
0022 #include <linux/ioport.h>
0023 #include <linux/ucb1400.h>
0024 #include <linux/mtd/mtd.h>
0025 #include <linux/types.h>
0026 #include <linux/platform_data/pcf857x.h>
0027 #include <linux/platform_data/i2c-pxa.h>
0028 #include <linux/mtd/platnand.h>
0029 #include <linux/mtd/physmap.h>
0030 #include <linux/regulator/max1586.h>
0031 
0032 #include <asm/setup.h>
0033 #include <asm/mach-types.h>
0034 #include <asm/irq.h>
0035 #include <linux/sizes.h>
0036 
0037 #include <asm/mach/arch.h>
0038 #include <asm/mach/map.h>
0039 #include <asm/mach/irq.h>
0040 #include <asm/mach/flash.h>
0041 
0042 #include "pxa27x.h"
0043 #include "balloon3.h"
0044 #include <linux/platform_data/asoc-pxa.h>
0045 #include <linux/platform_data/video-pxafb.h>
0046 #include <linux/platform_data/mmc-pxamci.h>
0047 #include "udc.h"
0048 #include "pxa27x-udc.h"
0049 #include <linux/platform_data/irda-pxaficp.h>
0050 #include <linux/platform_data/usb-ohci-pxa27x.h>
0051 
0052 #include "generic.h"
0053 #include "devices.h"
0054 
0055 /******************************************************************************
0056  * Pin configuration
0057  ******************************************************************************/
0058 static unsigned long balloon3_pin_config[] __initdata = {
0059     /* Select BTUART 'COM1/ttyS0' as IO option for pins 42/43/44/45 */
0060     GPIO42_BTUART_RXD,
0061     GPIO43_BTUART_TXD,
0062     GPIO44_BTUART_CTS,
0063     GPIO45_BTUART_RTS,
0064 
0065     /* Reset, configured as GPIO wakeup source */
0066     GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
0067 };
0068 
0069 /******************************************************************************
0070  * Compatibility: Parameter parsing
0071  ******************************************************************************/
0072 static unsigned long balloon3_irq_enabled;
0073 
0074 static unsigned long balloon3_features_present =
0075         (1 << BALLOON3_FEATURE_OHCI) | (1 << BALLOON3_FEATURE_CF) |
0076         (1 << BALLOON3_FEATURE_AUDIO) |
0077         (1 << BALLOON3_FEATURE_TOPPOLY);
0078 
0079 int balloon3_has(enum balloon3_features feature)
0080 {
0081     return (balloon3_features_present & (1 << feature)) ? 1 : 0;
0082 }
0083 EXPORT_SYMBOL_GPL(balloon3_has);
0084 
0085 int __init parse_balloon3_features(char *arg)
0086 {
0087     if (!arg)
0088         return 0;
0089 
0090     return kstrtoul(arg, 0, &balloon3_features_present);
0091 }
0092 early_param("balloon3_features", parse_balloon3_features);
0093 
0094 /******************************************************************************
0095  * Compact Flash slot
0096  ******************************************************************************/
0097 #if defined(CONFIG_PCMCIA_PXA2XX) || defined(CONFIG_PCMCIA_PXA2XX_MODULE)
0098 static unsigned long balloon3_cf_pin_config[] __initdata = {
0099     GPIO48_nPOE,
0100     GPIO49_nPWE,
0101     GPIO50_nPIOR,
0102     GPIO51_nPIOW,
0103     GPIO85_nPCE_1,
0104     GPIO54_nPCE_2,
0105     GPIO79_PSKTSEL,
0106     GPIO55_nPREG,
0107     GPIO56_nPWAIT,
0108     GPIO57_nIOIS16,
0109 };
0110 
0111 static void __init balloon3_cf_init(void)
0112 {
0113     if (!balloon3_has(BALLOON3_FEATURE_CF))
0114         return;
0115 
0116     pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_cf_pin_config));
0117 }
0118 #else
0119 static inline void balloon3_cf_init(void) {}
0120 #endif
0121 
0122 /******************************************************************************
0123  * NOR Flash
0124  ******************************************************************************/
0125 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
0126 static struct mtd_partition balloon3_nor_partitions[] = {
0127     {
0128         .name       = "Flash",
0129         .offset     = 0x00000000,
0130         .size       = MTDPART_SIZ_FULL,
0131     }
0132 };
0133 
0134 static struct physmap_flash_data balloon3_flash_data[] = {
0135     {
0136         .width      = 2,    /* bankwidth in bytes */
0137         .parts      = balloon3_nor_partitions,
0138         .nr_parts   = ARRAY_SIZE(balloon3_nor_partitions)
0139     }
0140 };
0141 
0142 static struct resource balloon3_flash_resource = {
0143     .start  = PXA_CS0_PHYS,
0144     .end    = PXA_CS0_PHYS + SZ_64M - 1,
0145     .flags  = IORESOURCE_MEM,
0146 };
0147 
0148 static struct platform_device balloon3_flash = {
0149     .name       = "physmap-flash",
0150     .id     = 0,
0151     .resource   = &balloon3_flash_resource,
0152     .num_resources  = 1,
0153     .dev        = {
0154         .platform_data = balloon3_flash_data,
0155     },
0156 };
0157 static void __init balloon3_nor_init(void)
0158 {
0159     platform_device_register(&balloon3_flash);
0160 }
0161 #else
0162 static inline void balloon3_nor_init(void) {}
0163 #endif
0164 
0165 /******************************************************************************
0166  * Audio and Touchscreen
0167  ******************************************************************************/
0168 #if defined(CONFIG_TOUCHSCREEN_UCB1400) || \
0169     defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
0170 static unsigned long balloon3_ac97_pin_config[] __initdata = {
0171     GPIO28_AC97_BITCLK,
0172     GPIO29_AC97_SDATA_IN_0,
0173     GPIO30_AC97_SDATA_OUT,
0174     GPIO31_AC97_SYNC,
0175     GPIO113_AC97_nRESET,
0176     GPIO95_GPIO,
0177 };
0178 
0179 static struct ucb1400_pdata vpac270_ucb1400_pdata = {
0180     .irq        = PXA_GPIO_TO_IRQ(BALLOON3_GPIO_CODEC_IRQ),
0181 };
0182 
0183 
0184 static struct platform_device balloon3_ucb1400_device = {
0185     .name       = "ucb1400_core",
0186     .id     = -1,
0187     .dev        = {
0188         .platform_data = &vpac270_ucb1400_pdata,
0189     },
0190 };
0191 
0192 static void __init balloon3_ts_init(void)
0193 {
0194     if (!balloon3_has(BALLOON3_FEATURE_AUDIO))
0195         return;
0196 
0197     pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_ac97_pin_config));
0198     pxa_set_ac97_info(NULL);
0199     platform_device_register(&balloon3_ucb1400_device);
0200 }
0201 #else
0202 static inline void balloon3_ts_init(void) {}
0203 #endif
0204 
0205 /******************************************************************************
0206  * Framebuffer
0207  ******************************************************************************/
0208 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
0209 static unsigned long balloon3_lcd_pin_config[] __initdata = {
0210     GPIOxx_LCD_TFT_16BPP,
0211     GPIO99_GPIO,
0212 };
0213 
0214 static struct pxafb_mode_info balloon3_lcd_modes[] = {
0215     {
0216         .pixclock       = 38000,
0217         .xres           = 480,
0218         .yres           = 640,
0219         .bpp            = 16,
0220         .hsync_len      = 8,
0221         .left_margin        = 8,
0222         .right_margin       = 8,
0223         .vsync_len      = 2,
0224         .upper_margin       = 4,
0225         .lower_margin       = 5,
0226         .sync           = 0,
0227     },
0228 };
0229 
0230 static struct pxafb_mach_info balloon3_lcd_screen = {
0231     .modes          = balloon3_lcd_modes,
0232     .num_modes      = ARRAY_SIZE(balloon3_lcd_modes),
0233     .lcd_conn       = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
0234 };
0235 
0236 static void balloon3_backlight_power(int on)
0237 {
0238     gpio_set_value(BALLOON3_GPIO_RUN_BACKLIGHT, on);
0239 }
0240 
0241 static void __init balloon3_lcd_init(void)
0242 {
0243     int ret;
0244 
0245     if (!balloon3_has(BALLOON3_FEATURE_TOPPOLY))
0246         return;
0247 
0248     pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_lcd_pin_config));
0249 
0250     ret = gpio_request(BALLOON3_GPIO_RUN_BACKLIGHT, "BKL-ON");
0251     if (ret) {
0252         pr_err("Requesting BKL-ON GPIO failed!\n");
0253         goto err;
0254     }
0255 
0256     ret = gpio_direction_output(BALLOON3_GPIO_RUN_BACKLIGHT, 1);
0257     if (ret) {
0258         pr_err("Setting BKL-ON GPIO direction failed!\n");
0259         goto err2;
0260     }
0261 
0262     balloon3_lcd_screen.pxafb_backlight_power = balloon3_backlight_power;
0263     pxa_set_fb_info(NULL, &balloon3_lcd_screen);
0264     return;
0265 
0266 err2:
0267     gpio_free(BALLOON3_GPIO_RUN_BACKLIGHT);
0268 err:
0269     return;
0270 }
0271 #else
0272 static inline void balloon3_lcd_init(void) {}
0273 #endif
0274 
0275 /******************************************************************************
0276  * SD/MMC card controller
0277  ******************************************************************************/
0278 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
0279 static unsigned long balloon3_mmc_pin_config[] __initdata = {
0280     GPIO32_MMC_CLK,
0281     GPIO92_MMC_DAT_0,
0282     GPIO109_MMC_DAT_1,
0283     GPIO110_MMC_DAT_2,
0284     GPIO111_MMC_DAT_3,
0285     GPIO112_MMC_CMD,
0286 };
0287 
0288 static struct pxamci_platform_data balloon3_mci_platform_data = {
0289     .ocr_mask       = MMC_VDD_32_33 | MMC_VDD_33_34,
0290     .detect_delay_ms    = 200,
0291 };
0292 
0293 static void __init balloon3_mmc_init(void)
0294 {
0295     pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_mmc_pin_config));
0296     pxa_set_mci_info(&balloon3_mci_platform_data);
0297 }
0298 #else
0299 static inline void balloon3_mmc_init(void) {}
0300 #endif
0301 
0302 /******************************************************************************
0303  * USB Gadget
0304  ******************************************************************************/
0305 #if defined(CONFIG_USB_PXA27X)||defined(CONFIG_USB_PXA27X_MODULE)
0306 static void balloon3_udc_command(int cmd)
0307 {
0308     if (cmd == PXA2XX_UDC_CMD_CONNECT)
0309         UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
0310     else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
0311         UP2OCR &= ~UP2OCR_DPPUE;
0312 }
0313 
0314 static int balloon3_udc_is_connected(void)
0315 {
0316     return 1;
0317 }
0318 
0319 static struct pxa2xx_udc_mach_info balloon3_udc_info __initdata = {
0320     .udc_command        = balloon3_udc_command,
0321     .udc_is_connected   = balloon3_udc_is_connected,
0322     .gpio_pullup        = -1,
0323 };
0324 
0325 static void __init balloon3_udc_init(void)
0326 {
0327     pxa_set_udc_info(&balloon3_udc_info);
0328 }
0329 #else
0330 static inline void balloon3_udc_init(void) {}
0331 #endif
0332 
0333 /******************************************************************************
0334  * IrDA
0335  ******************************************************************************/
0336 #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
0337 static struct pxaficp_platform_data balloon3_ficp_platform_data = {
0338     .transceiver_cap    = IR_FIRMODE | IR_SIRMODE | IR_OFF,
0339 };
0340 
0341 static void __init balloon3_irda_init(void)
0342 {
0343     pxa_set_ficp_info(&balloon3_ficp_platform_data);
0344 }
0345 #else
0346 static inline void balloon3_irda_init(void) {}
0347 #endif
0348 
0349 /******************************************************************************
0350  * USB Host
0351  ******************************************************************************/
0352 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
0353 static unsigned long balloon3_uhc_pin_config[] __initdata = {
0354     GPIO88_USBH1_PWR,
0355     GPIO89_USBH1_PEN,
0356 };
0357 
0358 static struct pxaohci_platform_data balloon3_ohci_info = {
0359     .port_mode  = PMM_PERPORT_MODE,
0360     .flags      = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
0361 };
0362 
0363 static void __init balloon3_uhc_init(void)
0364 {
0365     if (!balloon3_has(BALLOON3_FEATURE_OHCI))
0366         return;
0367     pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_uhc_pin_config));
0368     pxa_set_ohci_info(&balloon3_ohci_info);
0369 }
0370 #else
0371 static inline void balloon3_uhc_init(void) {}
0372 #endif
0373 
0374 /******************************************************************************
0375  * LEDs
0376  ******************************************************************************/
0377 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
0378 static unsigned long balloon3_led_pin_config[] __initdata = {
0379     GPIO9_GPIO, /* NAND activity LED */
0380     GPIO10_GPIO,    /* Heartbeat LED */
0381 };
0382 
0383 struct gpio_led balloon3_gpio_leds[] = {
0384     {
0385         .name           = "balloon3:green:idle",
0386         .default_trigger    = "heartbeat",
0387         .gpio           = BALLOON3_GPIO_LED_IDLE,
0388         .active_low     = 1,
0389     }, {
0390         .name           = "balloon3:green:nand",
0391         .default_trigger    = "nand-disk",
0392         .gpio           = BALLOON3_GPIO_LED_NAND,
0393         .active_low     = 1,
0394     },
0395 };
0396 
0397 static struct gpio_led_platform_data balloon3_gpio_led_info = {
0398     .leds       = balloon3_gpio_leds,
0399     .num_leds   = ARRAY_SIZE(balloon3_gpio_leds),
0400 };
0401 
0402 static struct platform_device balloon3_leds = {
0403     .name   = "leds-gpio",
0404     .id = 0,
0405     .dev    = {
0406         .platform_data  = &balloon3_gpio_led_info,
0407     }
0408 };
0409 
0410 struct gpio_led balloon3_pcf_gpio_leds[] = {
0411     {
0412         .name           = "balloon3:green:led0",
0413         .gpio           = BALLOON3_PCF_GPIO_LED0,
0414         .active_low     = 1,
0415     }, {
0416         .name           = "balloon3:green:led1",
0417         .gpio           = BALLOON3_PCF_GPIO_LED1,
0418         .active_low     = 1,
0419     }, {
0420         .name           = "balloon3:orange:led2",
0421         .gpio           = BALLOON3_PCF_GPIO_LED2,
0422         .active_low     = 1,
0423     }, {
0424         .name           = "balloon3:orange:led3",
0425         .gpio           = BALLOON3_PCF_GPIO_LED3,
0426         .active_low     = 1,
0427     }, {
0428         .name           = "balloon3:orange:led4",
0429         .gpio           = BALLOON3_PCF_GPIO_LED4,
0430         .active_low     = 1,
0431     }, {
0432         .name           = "balloon3:orange:led5",
0433         .gpio           = BALLOON3_PCF_GPIO_LED5,
0434         .active_low     = 1,
0435     }, {
0436         .name           = "balloon3:red:led6",
0437         .gpio           = BALLOON3_PCF_GPIO_LED6,
0438         .active_low     = 1,
0439     }, {
0440         .name           = "balloon3:red:led7",
0441         .gpio           = BALLOON3_PCF_GPIO_LED7,
0442         .active_low     = 1,
0443     },
0444 };
0445 
0446 static struct gpio_led_platform_data balloon3_pcf_gpio_led_info = {
0447     .leds       = balloon3_pcf_gpio_leds,
0448     .num_leds   = ARRAY_SIZE(balloon3_pcf_gpio_leds),
0449 };
0450 
0451 static struct platform_device balloon3_pcf_leds = {
0452     .name   = "leds-gpio",
0453     .id = 1,
0454     .dev    = {
0455         .platform_data  = &balloon3_pcf_gpio_led_info,
0456     }
0457 };
0458 
0459 static void __init balloon3_leds_init(void)
0460 {
0461     pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_led_pin_config));
0462     platform_device_register(&balloon3_leds);
0463     platform_device_register(&balloon3_pcf_leds);
0464 }
0465 #else
0466 static inline void balloon3_leds_init(void) {}
0467 #endif
0468 
0469 /******************************************************************************
0470  * FPGA IRQ
0471  ******************************************************************************/
0472 static void balloon3_mask_irq(struct irq_data *d)
0473 {
0474     int balloon3_irq = (d->irq - BALLOON3_IRQ(0));
0475     balloon3_irq_enabled &= ~(1 << balloon3_irq);
0476     __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
0477 }
0478 
0479 static void balloon3_unmask_irq(struct irq_data *d)
0480 {
0481     int balloon3_irq = (d->irq - BALLOON3_IRQ(0));
0482     balloon3_irq_enabled |= (1 << balloon3_irq);
0483     __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
0484 }
0485 
0486 static struct irq_chip balloon3_irq_chip = {
0487     .name       = "FPGA",
0488     .irq_ack    = balloon3_mask_irq,
0489     .irq_mask   = balloon3_mask_irq,
0490     .irq_unmask = balloon3_unmask_irq,
0491 };
0492 
0493 static void balloon3_irq_handler(struct irq_desc *desc)
0494 {
0495     unsigned long pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
0496                     balloon3_irq_enabled;
0497     do {
0498         struct irq_data *d = irq_desc_get_irq_data(desc);
0499         struct irq_chip *chip = irq_desc_get_chip(desc);
0500         unsigned int irq;
0501 
0502         /* clear useless edge notification */
0503         if (chip->irq_ack)
0504             chip->irq_ack(d);
0505 
0506         while (pending) {
0507             irq = BALLOON3_IRQ(0) + __ffs(pending);
0508             generic_handle_irq(irq);
0509             pending &= pending - 1;
0510         }
0511         pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
0512                 balloon3_irq_enabled;
0513     } while (pending);
0514 }
0515 
0516 static void __init balloon3_init_irq(void)
0517 {
0518     int irq;
0519 
0520     pxa27x_init_irq();
0521     /* setup extra Balloon3 irqs */
0522     for (irq = BALLOON3_IRQ(0); irq <= BALLOON3_IRQ(7); irq++) {
0523         irq_set_chip_and_handler(irq, &balloon3_irq_chip,
0524                      handle_level_irq);
0525         irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
0526     }
0527 
0528     irq_set_chained_handler(BALLOON3_AUX_NIRQ, balloon3_irq_handler);
0529     irq_set_irq_type(BALLOON3_AUX_NIRQ, IRQ_TYPE_EDGE_FALLING);
0530 
0531     pr_debug("%s: chained handler installed - irq %d automatically "
0532         "enabled\n", __func__, BALLOON3_AUX_NIRQ);
0533 }
0534 
0535 /******************************************************************************
0536  * GPIO expander
0537  ******************************************************************************/
0538 #if defined(CONFIG_GPIO_PCF857X) || defined(CONFIG_GPIO_PCF857X_MODULE)
0539 static struct pcf857x_platform_data balloon3_pcf857x_pdata = {
0540     .gpio_base  = BALLOON3_PCF_GPIO_BASE,
0541     .n_latch    = 0,
0542     .setup      = NULL,
0543     .teardown   = NULL,
0544     .context    = NULL,
0545 };
0546 
0547 static struct i2c_board_info __initdata balloon3_i2c_devs[] = {
0548     {
0549         I2C_BOARD_INFO("pcf8574a", 0x38),
0550         .platform_data  = &balloon3_pcf857x_pdata,
0551     },
0552 };
0553 
0554 static void __init balloon3_i2c_init(void)
0555 {
0556     pxa_set_i2c_info(NULL);
0557     i2c_register_board_info(0, ARRAY_AND_SIZE(balloon3_i2c_devs));
0558 }
0559 #else
0560 static inline void balloon3_i2c_init(void) {}
0561 #endif
0562 
0563 /******************************************************************************
0564  * NAND
0565  ******************************************************************************/
0566 #if defined(CONFIG_MTD_NAND_PLATFORM)||defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
0567 static void balloon3_nand_cmd_ctl(struct nand_chip *this, int cmd,
0568                   unsigned int ctrl)
0569 {
0570     uint8_t balloon3_ctl_set = 0, balloon3_ctl_clr = 0;
0571 
0572     if (ctrl & NAND_CTRL_CHANGE) {
0573         if (ctrl & NAND_CLE)
0574             balloon3_ctl_set |= BALLOON3_NAND_CONTROL_FLCLE;
0575         else
0576             balloon3_ctl_clr |= BALLOON3_NAND_CONTROL_FLCLE;
0577 
0578         if (ctrl & NAND_ALE)
0579             balloon3_ctl_set |= BALLOON3_NAND_CONTROL_FLALE;
0580         else
0581             balloon3_ctl_clr |= BALLOON3_NAND_CONTROL_FLALE;
0582 
0583         if (balloon3_ctl_clr)
0584             __raw_writel(balloon3_ctl_clr,
0585                 BALLOON3_NAND_CONTROL_REG);
0586         if (balloon3_ctl_set)
0587             __raw_writel(balloon3_ctl_set,
0588                 BALLOON3_NAND_CONTROL_REG +
0589                 BALLOON3_FPGA_SETnCLR);
0590     }
0591 
0592     if (cmd != NAND_CMD_NONE)
0593         writeb(cmd, this->legacy.IO_ADDR_W);
0594 }
0595 
0596 static void balloon3_nand_select_chip(struct nand_chip *this, int chip)
0597 {
0598     if (chip < 0 || chip > 3)
0599         return;
0600 
0601     /* Assert all nCE lines */
0602     __raw_writew(
0603         BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
0604         BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3,
0605         BALLOON3_NAND_CONTROL_REG + BALLOON3_FPGA_SETnCLR);
0606 
0607     /* Deassert correct nCE line */
0608     __raw_writew(BALLOON3_NAND_CONTROL_FLCE0 << chip,
0609         BALLOON3_NAND_CONTROL_REG);
0610 }
0611 
0612 static int balloon3_nand_dev_ready(struct nand_chip *this)
0613 {
0614     return __raw_readl(BALLOON3_NAND_STAT_REG) & BALLOON3_NAND_STAT_RNB;
0615 }
0616 
0617 static int balloon3_nand_probe(struct platform_device *pdev)
0618 {
0619     uint16_t ver;
0620     int ret;
0621 
0622     __raw_writew(BALLOON3_NAND_CONTROL2_16BIT,
0623         BALLOON3_NAND_CONTROL2_REG + BALLOON3_FPGA_SETnCLR);
0624 
0625     ver = __raw_readw(BALLOON3_FPGA_VER);
0626     if (ver < 0x4f08)
0627         pr_warn("The FPGA code, version 0x%04x, is too old. "
0628             "NAND support might be broken in this version!", ver);
0629 
0630     /* Power up the NAND chips */
0631     ret = gpio_request(BALLOON3_GPIO_RUN_NAND, "NAND");
0632     if (ret)
0633         goto err1;
0634 
0635     ret = gpio_direction_output(BALLOON3_GPIO_RUN_NAND, 1);
0636     if (ret)
0637         goto err2;
0638 
0639     gpio_set_value(BALLOON3_GPIO_RUN_NAND, 1);
0640 
0641     /* Deassert all nCE lines and write protect line */
0642     __raw_writel(
0643         BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
0644         BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3 |
0645         BALLOON3_NAND_CONTROL_FLWP,
0646         BALLOON3_NAND_CONTROL_REG + BALLOON3_FPGA_SETnCLR);
0647     return 0;
0648 
0649 err2:
0650     gpio_free(BALLOON3_GPIO_RUN_NAND);
0651 err1:
0652     return ret;
0653 }
0654 
0655 static void balloon3_nand_remove(struct platform_device *pdev)
0656 {
0657     /* Power down the NAND chips */
0658     gpio_set_value(BALLOON3_GPIO_RUN_NAND, 0);
0659     gpio_free(BALLOON3_GPIO_RUN_NAND);
0660 }
0661 
0662 static struct mtd_partition balloon3_partition_info[] = {
0663     [0] = {
0664         .name   = "Boot",
0665         .offset = 0,
0666         .size   = SZ_4M,
0667     },
0668     [1] = {
0669         .name   = "RootFS",
0670         .offset = MTDPART_OFS_APPEND,
0671         .size   = MTDPART_SIZ_FULL
0672     },
0673 };
0674 
0675 struct platform_nand_data balloon3_nand_pdata = {
0676     .chip = {
0677         .nr_chips   = 4,
0678         .chip_offset    = 0,
0679         .nr_partitions  = ARRAY_SIZE(balloon3_partition_info),
0680         .partitions = balloon3_partition_info,
0681         .chip_delay = 50,
0682     },
0683     .ctrl = {
0684         .dev_ready  = balloon3_nand_dev_ready,
0685         .select_chip    = balloon3_nand_select_chip,
0686         .cmd_ctrl   = balloon3_nand_cmd_ctl,
0687         .probe      = balloon3_nand_probe,
0688         .remove     = balloon3_nand_remove,
0689     },
0690 };
0691 
0692 static struct resource balloon3_nand_resource[] = {
0693     [0] = {
0694         .start = BALLOON3_NAND_BASE,
0695         .end   = BALLOON3_NAND_BASE + 0x4,
0696         .flags = IORESOURCE_MEM,
0697     },
0698 };
0699 
0700 static struct platform_device balloon3_nand = {
0701     .name       = "gen_nand",
0702     .num_resources  = ARRAY_SIZE(balloon3_nand_resource),
0703     .resource   = balloon3_nand_resource,
0704     .id     = -1,
0705     .dev        = {
0706         .platform_data = &balloon3_nand_pdata,
0707     }
0708 };
0709 
0710 static void __init balloon3_nand_init(void)
0711 {
0712     platform_device_register(&balloon3_nand);
0713 }
0714 #else
0715 static inline void balloon3_nand_init(void) {}
0716 #endif
0717 
0718 /******************************************************************************
0719  * Core power regulator
0720  ******************************************************************************/
0721 #if defined(CONFIG_REGULATOR_MAX1586) || \
0722     defined(CONFIG_REGULATOR_MAX1586_MODULE)
0723 static struct regulator_consumer_supply balloon3_max1587a_consumers[] = {
0724     REGULATOR_SUPPLY("vcc_core", NULL),
0725 };
0726 
0727 static struct regulator_init_data balloon3_max1587a_v3_info = {
0728     .constraints = {
0729         .name       = "vcc_core range",
0730         .min_uV     = 900000,
0731         .max_uV     = 1705000,
0732         .always_on  = 1,
0733         .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
0734     },
0735     .consumer_supplies  = balloon3_max1587a_consumers,
0736     .num_consumer_supplies  = ARRAY_SIZE(balloon3_max1587a_consumers),
0737 };
0738 
0739 static struct max1586_subdev_data balloon3_max1587a_subdevs[] = {
0740     {
0741         .name       = "vcc_core",
0742         .id     = MAX1586_V3,
0743         .platform_data  = &balloon3_max1587a_v3_info,
0744     }
0745 };
0746 
0747 static struct max1586_platform_data balloon3_max1587a_info = {
0748     .subdevs     = balloon3_max1587a_subdevs,
0749     .num_subdevs = ARRAY_SIZE(balloon3_max1587a_subdevs),
0750     .v3_gain     = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
0751 };
0752 
0753 static struct i2c_board_info __initdata balloon3_pi2c_board_info[] = {
0754     {
0755         I2C_BOARD_INFO("max1586", 0x14),
0756         .platform_data  = &balloon3_max1587a_info,
0757     },
0758 };
0759 
0760 static void __init balloon3_pmic_init(void)
0761 {
0762     pxa27x_set_i2c_power_info(NULL);
0763     i2c_register_board_info(1, ARRAY_AND_SIZE(balloon3_pi2c_board_info));
0764 }
0765 #else
0766 static inline void balloon3_pmic_init(void) {}
0767 #endif
0768 
0769 /******************************************************************************
0770  * Machine init
0771  ******************************************************************************/
0772 static void __init balloon3_init(void)
0773 {
0774     ARB_CNTRL = ARB_CORE_PARK | 0x234;
0775 
0776     pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_pin_config));
0777 
0778     pxa_set_ffuart_info(NULL);
0779     pxa_set_btuart_info(NULL);
0780     pxa_set_stuart_info(NULL);
0781 
0782     balloon3_i2c_init();
0783     balloon3_irda_init();
0784     balloon3_lcd_init();
0785     balloon3_leds_init();
0786     balloon3_mmc_init();
0787     balloon3_nand_init();
0788     balloon3_nor_init();
0789     balloon3_pmic_init();
0790     balloon3_ts_init();
0791     balloon3_udc_init();
0792     balloon3_uhc_init();
0793     balloon3_cf_init();
0794 }
0795 
0796 static struct map_desc balloon3_io_desc[] __initdata = {
0797     {   /* CPLD/FPGA */
0798         .virtual    = (unsigned long)BALLOON3_FPGA_VIRT,
0799         .pfn        = __phys_to_pfn(BALLOON3_FPGA_PHYS),
0800         .length     = BALLOON3_FPGA_LENGTH,
0801         .type       = MT_DEVICE,
0802     },
0803 };
0804 
0805 static void __init balloon3_map_io(void)
0806 {
0807     pxa27x_map_io();
0808     iotable_init(balloon3_io_desc, ARRAY_SIZE(balloon3_io_desc));
0809 }
0810 
0811 MACHINE_START(BALLOON3, "Balloon3")
0812     /* Maintainer: Nick Bane. */
0813     .map_io     = balloon3_map_io,
0814     .nr_irqs    = BALLOON3_NR_IRQS,
0815     .init_irq   = balloon3_init_irq,
0816     .handle_irq = pxa27x_handle_irq,
0817     .init_time  = pxa_timer_init,
0818     .init_machine   = balloon3_init,
0819     .atag_offset    = 0x100,
0820     .restart    = pxa_restart,
0821 MACHINE_END