balloon3.c 12.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 *  linux/arch/arm/mach-pxa/balloon3.c
 *
 *  Support for Balloonboard.org Balloon3 board.
 *
 *  Author:	Nick Bane, Wookey, Jonathan McDowell
 *  Created:	June, 2006
 *  Copyright:	Toby Churchill Ltd
 *  Derived from mainstone.c, by Nico Pitre
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 */

#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/sysdev.h>
#include <linux/interrupt.h>
#include <linux/sched.h>
#include <linux/bitops.h>
#include <linux/fb.h>
#include <linux/gpio.h>
#include <linux/ioport.h>
25
#include <linux/ucb1400.h>
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/types.h>

#include <asm/setup.h>
#include <asm/mach-types.h>
#include <asm/irq.h>
#include <asm/sizes.h>

#include <asm/mach/arch.h>
#include <asm/mach/map.h>
#include <asm/mach/irq.h>
#include <asm/mach/flash.h>

#include <mach/pxa27x.h>
#include <mach/balloon3.h>
#include <mach/audio.h>
#include <mach/pxafb.h>
#include <mach/mmc.h>
#include <mach/udc.h>
#include <mach/pxa27x-udc.h>
#include <mach/irda.h>
#include <mach/ohci.h>

#include <plat/i2c.h>

#include "generic.h"
#include "devices.h"

55 56 57 58 59 60 61 62 63
/******************************************************************************
 * Pin configuration
 ******************************************************************************/
static unsigned long balloon3_pin_config[] __initdata = {
	/* Select BTUART 'COM1/ttyS0' as IO option for pins 42/43/44/45 */
	GPIO42_BTUART_RXD,
	GPIO43_BTUART_TXD,
	GPIO44_BTUART_CTS,
	GPIO45_BTUART_RTS,
64

65
	/* Reset, configured as GPIO wakeup source */
66
	GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
67

68 69 70
	/* LEDs */
	GPIO9_GPIO,	/* NAND activity LED */
	GPIO10_GPIO,	/* Heartbeat LED */
71

72
	/* AC97 */
73 74 75 76 77
	GPIO28_AC97_BITCLK,
	GPIO29_AC97_SDATA_IN_0,
	GPIO30_AC97_SDATA_OUT,
	GPIO31_AC97_SYNC,
	GPIO113_AC97_nRESET,
78 79 80 81 82 83 84 85 86 87 88 89 90
	GPIO95_GPIO,

	/* MMC */
	GPIO32_MMC_CLK,
	GPIO92_MMC_DAT_0,
	GPIO109_MMC_DAT_1,
	GPIO110_MMC_DAT_2,
	GPIO111_MMC_DAT_3,
	GPIO112_MMC_CMD,

	/* USB Host */
	GPIO88_USBH1_PWR,
	GPIO89_USBH1_PEN,
M
Marek Vasut 已提交
91 92 93 94 95 96 97 98 99 100 101 102

	/* PC Card */
	GPIO48_nPOE,
	GPIO49_nPWE,
	GPIO50_nPIOR,
	GPIO51_nPIOW,
	GPIO85_nPCE_1,
	GPIO54_nPCE_2,
	GPIO79_PSKTSEL,
	GPIO55_nPREG,
	GPIO56_nPWAIT,
	GPIO57_nIOIS16,
103 104
};

105
/******************************************************************************
106
 * Compatibility: Parameter parsing
107
 ******************************************************************************/
108
static unsigned long balloon3_irq_enabled;
109

110 111 112 113 114 115
static unsigned long balloon3_features_present =
		(1 << BALLOON3_FEATURE_OHCI) | (1 << BALLOON3_FEATURE_CF) |
		(1 << BALLOON3_FEATURE_AUDIO) |
		(1 << BALLOON3_FEATURE_TOPPOLY);

int balloon3_has(enum balloon3_features feature)
116
{
117 118 119 120 121 122 123 124 125 126
	return (balloon3_features_present & (1 << feature)) ? 1 : 0;
}
EXPORT_SYMBOL_GPL(balloon3_has);

int __init parse_balloon3_features(char *arg)
{
	if (!arg)
		return 0;

	return strict_strtoul(arg, 0, &balloon3_features_present);
127
}
128
early_param("balloon3_features", parse_balloon3_features);
129

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
/******************************************************************************
 * NOR Flash
 ******************************************************************************/
#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
static struct mtd_partition balloon3_nor_partitions[] = {
	{
		.name		= "Flash",
		.offset		= 0x00000000,
		.size		= MTDPART_SIZ_FULL,
	}
};

static struct physmap_flash_data balloon3_flash_data[] = {
	{
		.width		= 2,	/* bankwidth in bytes */
		.parts		= balloon3_nor_partitions,
		.nr_parts	= ARRAY_SIZE(balloon3_nor_partitions)
	}
};

static struct resource balloon3_flash_resource = {
	.start	= PXA_CS0_PHYS,
	.end	= PXA_CS0_PHYS + SZ_64M - 1,
	.flags	= IORESOURCE_MEM,
};

static struct platform_device balloon3_flash = {
	.name		= "physmap-flash",
	.id		= 0,
	.resource	= &balloon3_flash_resource,
	.num_resources	= 1,
	.dev 		= {
		.platform_data = balloon3_flash_data,
	},
};
static void __init balloon3_nor_init(void)
{
	platform_device_register(&balloon3_flash);
}
#else
static inline void balloon3_nor_init(void) {}
#endif

/******************************************************************************
 * Audio and Touchscreen
 ******************************************************************************/
#if	defined(CONFIG_TOUCHSCREEN_UCB1400) || \
	defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
static struct ucb1400_pdata vpac270_ucb1400_pdata = {
	.irq		= IRQ_GPIO(BALLOON3_GPIO_CODEC_IRQ),
};


static struct platform_device balloon3_ucb1400_device = {
	.name		= "ucb1400_core",
	.id		= -1,
	.dev		= {
		.platform_data = &vpac270_ucb1400_pdata,
	},
};

static void __init balloon3_ts_init(void)
{
	if (!balloon3_has(BALLOON3_FEATURE_AUDIO))
		return;

	pxa_set_ac97_info(NULL);
	platform_device_register(&balloon3_ucb1400_device);
}
#else
static inline void balloon3_ts_init(void) {}
#endif

/******************************************************************************
 * Framebuffer
 ******************************************************************************/
#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
static struct pxafb_mode_info balloon3_lcd_modes[] = {
	{
		.pixclock		= 38000,
		.xres			= 480,
		.yres			= 640,
		.bpp			= 16,
		.hsync_len		= 8,
		.left_margin		= 8,
		.right_margin		= 8,
		.vsync_len		= 2,
		.upper_margin		= 4,
		.lower_margin		= 5,
		.sync			= 0,
	},
};

223
static struct pxafb_mach_info balloon3_lcd_screen = {
224 225 226 227 228
	.modes			= balloon3_lcd_modes,
	.num_modes		= ARRAY_SIZE(balloon3_lcd_modes),
	.lcd_conn		= LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
};

229 230 231 232
static void balloon3_backlight_power(int on)
{
	gpio_set_value(BALLOON3_GPIO_RUN_BACKLIGHT, on);
}
233

234
static void __init balloon3_lcd_init(void)
235
{
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
	int ret;

	if (!balloon3_has(BALLOON3_FEATURE_TOPPOLY))
		return;

	ret = gpio_request(BALLOON3_GPIO_RUN_BACKLIGHT, "BKL-ON");
	if (ret) {
		pr_err("Requesting BKL-ON GPIO failed!\n");
		goto err;
	}

	ret = gpio_direction_output(BALLOON3_GPIO_RUN_BACKLIGHT, 1);
	if (ret) {
		pr_err("Setting BKL-ON GPIO direction failed!\n");
		goto err2;
251
	}
252 253 254 255 256 257 258 259 260

	balloon3_lcd_screen.pxafb_backlight_power = balloon3_backlight_power;
	set_pxa_fb_info(&balloon3_lcd_screen);
	return;

err2:
	gpio_free(BALLOON3_GPIO_RUN_BACKLIGHT);
err:
	return;
261
}
262 263 264
#else
static inline void balloon3_lcd_init(void) {}
#endif
265

266 267 268 269
/******************************************************************************
 * SD/MMC card controller
 ******************************************************************************/
#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
270
static struct pxamci_platform_data balloon3_mci_platform_data = {
271 272 273 274 275
	.ocr_mask		= MMC_VDD_32_33 | MMC_VDD_33_34,
	.gpio_card_detect	= -1,
	.gpio_card_ro		= -1,
	.gpio_power		= -1,
	.detect_delay_ms	= 200,
276 277
};

278 279 280 281 282 283 284 285
static void __init balloon3_mmc_init(void)
{
	pxa_set_mci_info(&balloon3_mci_platform_data);
}
#else
static inline void balloon3_mmc_init(void) {}
#endif

286 287 288
/******************************************************************************
 * USB Gadget
 ******************************************************************************/
289 290
#if defined(CONFIG_USB_GADGET_PXA27X)||defined(CONFIG_USB_GADGET_PXA27X_MODULE)
static void balloon3_udc_command(int cmd)
291
{
292 293 294 295
	if (cmd == PXA2XX_UDC_CMD_CONNECT)
		UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
	else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
		UP2OCR &= ~UP2OCR_DPPUE;
296 297
}

298
static int balloon3_udc_is_connected(void)
299
{
300
	return 1;
301 302
}

303 304 305 306
static struct pxa2xx_udc_mach_info balloon3_udc_info __initdata = {
	.udc_command		= balloon3_udc_command,
	.udc_is_connected	= balloon3_udc_is_connected,
	.gpio_pullup		= -1,
307 308
};

309 310 311 312 313 314 315 316 317
static void __init balloon3_udc_init(void)
{
	pxa_set_udc_info(&balloon3_udc_info);
	platform_device_register(&balloon3_gpio_vbus);
}
#else
static inline void balloon3_udc_init(void) {}
#endif

318 319 320
/******************************************************************************
 * IrDA
 ******************************************************************************/
321
#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
322
static struct pxaficp_platform_data balloon3_ficp_platform_data = {
323
	.transceiver_cap	= IR_FIRMODE | IR_SIRMODE | IR_OFF,
324 325
};

326 327 328 329 330 331 332 333
static void __init balloon3_irda_init(void)
{
	pxa_set_ficp_info(&balloon3_ficp_platform_data);
}
#else
static inline void balloon3_irda_init(void) {}
#endif

334 335 336
/******************************************************************************
 * USB Host
 ******************************************************************************/
337 338
#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
static struct pxaohci_platform_data balloon3_ohci_info = {
339 340 341 342
	.port_mode	= PMM_PERPORT_MODE,
	.flags		= ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
};

343 344 345 346 347 348 349 350 351 352
static void __init balloon3_uhc_init(void)
{
	if (!balloon3_has(BALLOON3_FEATURE_OHCI))
		return;
	pxa_set_ohci_info(&balloon3_ohci_info);
}
#else
static inline void balloon3_uhc_init(void) {}
#endif

353
/******************************************************************************
354
 * LEDs
355
 ******************************************************************************/
356 357
#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
struct gpio_led balloon3_gpio_leds[] = {
358 359 360 361 362
	{
		.name			= "balloon3:green:idle",
		.default_trigger	= "heartbeat",
		.gpio			= BALLOON3_GPIO_LED_IDLE,
		.active_low		= 1,
363
	}, {
364 365 366 367 368 369 370
		.name			= "balloon3:green:nand",
		.default_trigger	= "nand-disk",
		.gpio			= BALLOON3_GPIO_LED_NAND,
		.active_low		= 1,
	},
};

371
static struct gpio_led_platform_data balloon3_gpio_led_info = {
372 373 374 375
	.leds		= balloon3_gpio_leds,
	.num_leds	= ARRAY_SIZE(balloon3_gpio_leds),
};

376
static struct platform_device balloon3_leds = {
377 378 379
	.name	= "leds-gpio",
	.id	= -1,
	.dev	= {
380 381
		.platform_data	= &balloon3_gpio_led_info,
	}
382 383
};

384
static void __init balloon3_leds_init(void)
385
{
386
	platform_device_register(&balloon3_leds);
387
}
388 389 390
#else
static inline void balloon3_leds_init(void) {}
#endif
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455

/******************************************************************************
 * FPGA IRQ
 ******************************************************************************/
static void balloon3_mask_irq(unsigned int irq)
{
	int balloon3_irq = (irq - BALLOON3_IRQ(0));
	balloon3_irq_enabled &= ~(1 << balloon3_irq);
	__raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
}

static void balloon3_unmask_irq(unsigned int irq)
{
	int balloon3_irq = (irq - BALLOON3_IRQ(0));
	balloon3_irq_enabled |= (1 << balloon3_irq);
	__raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
}

static struct irq_chip balloon3_irq_chip = {
	.name		= "FPGA",
	.ack		= balloon3_mask_irq,
	.mask		= balloon3_mask_irq,
	.unmask		= balloon3_unmask_irq,
};

static void balloon3_irq_handler(unsigned int irq, struct irq_desc *desc)
{
	unsigned long pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
					balloon3_irq_enabled;
	do {
		/* clear useless edge notification */
		if (desc->chip->ack)
			desc->chip->ack(BALLOON3_AUX_NIRQ);
		while (pending) {
			irq = BALLOON3_IRQ(0) + __ffs(pending);
			generic_handle_irq(irq);
			pending &= pending - 1;
		}
		pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
				balloon3_irq_enabled;
	} while (pending);
}

static void __init balloon3_init_irq(void)
{
	int irq;

	pxa27x_init_irq();
	/* setup extra Balloon3 irqs */
	for (irq = BALLOON3_IRQ(0); irq <= BALLOON3_IRQ(7); irq++) {
		set_irq_chip(irq, &balloon3_irq_chip);
		set_irq_handler(irq, handle_level_irq);
		set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
	}

	set_irq_chained_handler(BALLOON3_AUX_NIRQ, balloon3_irq_handler);
	set_irq_type(BALLOON3_AUX_NIRQ, IRQ_TYPE_EDGE_FALLING);

	pr_debug("%s: chained handler installed - irq %d automatically "
		"enabled\n", __func__, BALLOON3_AUX_NIRQ);
}

/******************************************************************************
 * Machine init
 ******************************************************************************/
456 457 458 459
static void __init balloon3_init(void)
{
	ARB_CNTRL = ARB_CORE_PARK | 0x234;

460 461
	pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_pin_config));

462 463 464 465
	pxa_set_ffuart_info(NULL);
	pxa_set_btuart_info(NULL);
	pxa_set_stuart_info(NULL);

466 467
	pxa_set_i2c_info(NULL);

468 469 470 471 472 473 474 475
	balloon3_irda_init();
	balloon3_lcd_init();
	balloon3_leds_init();
	balloon3_mmc_init();
	balloon3_nor_init();
	balloon3_ts_init();
	balloon3_udc_init();
	balloon3_uhc_init();
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
}

static struct map_desc balloon3_io_desc[] __initdata = {
	{	/* CPLD/FPGA */
		.virtual	=  BALLOON3_FPGA_VIRT,
		.pfn		= __phys_to_pfn(BALLOON3_FPGA_PHYS),
		.length		= BALLOON3_FPGA_LENGTH,
		.type		= MT_DEVICE,
	},
};

static void __init balloon3_map_io(void)
{
	pxa_map_io();
	iotable_init(balloon3_io_desc, ARRAY_SIZE(balloon3_io_desc));
}

MACHINE_START(BALLOON3, "Balloon3")
	/* Maintainer: Nick Bane. */
	.phys_io	= 0x40000000,
	.io_pg_offst	= (io_p2v(0x40000000) >> 18) & 0xfffc,
	.map_io		= balloon3_map_io,
	.init_irq	= balloon3_init_irq,
	.timer		= &pxa_timer,
	.init_machine	= balloon3_init,
	.boot_params	= PHYS_OFFSET + 0x100,
MACHINE_END