tosa.c 12.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 *  Support for Sharp SL-C6000x PDAs
 *  Model: (Tosa)
 *
 *  Copyright (c) 2005 Dirk Opfer
 *
 *	Based on code written by Sharp/Lineo for 2.4 kernels
 *
 *  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/kernel.h>
#include <linux/init.h>
17
#include <linux/platform_device.h>
18 19 20 21
#include <linux/major.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
#include <linux/mmc/host.h>
22
#include <linux/pm.h>
R
Russell King 已提交
23
#include <linux/delay.h>
24 25
#include <linux/gpio_keys.h>
#include <linux/input.h>
26
#include <linux/gpio.h>
27 28 29

#include <asm/setup.h>
#include <asm/mach-types.h>
30
#include <asm/arch/pxa2xx-regs.h>
31
#include <asm/arch/mfp-pxa25x.h>
32
#include <asm/arch/irda.h>
33
#include <asm/arch/i2c.h>
34 35 36 37 38 39 40 41 42 43
#include <asm/arch/mmc.h>
#include <asm/arch/udc.h>

#include <asm/mach/arch.h>
#include <asm/arch/tosa.h>

#include <asm/hardware/scoop.h>
#include <asm/mach/sharpsl_param.h>

#include "generic.h"
44
#include "devices.h"
45

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
static unsigned long tosa_pin_config[] = {
	GPIO78_nCS_2, /* Scoop */
	GPIO80_nCS_4, /* tg6393xb */
	GPIO33_nCS_5, /* Scoop */

	// GPIO76 CARD_VCC_ON1

	GPIO19_GPIO, /* Reset out */
	GPIO1_RST | WAKEUP_ON_EDGE_FALL,

	GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */
	GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */
	GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */
	GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */
	GPIO20_GPIO, /* EAR_IN */
	GPIO22_GPIO, /* On */

	GPIO5_GPIO, /* USB_IN */
	GPIO32_GPIO, /* Pen IRQ */

	GPIO7_GPIO, /* Jacket Detect */
	GPIO14_GPIO, /* BAT0_CRG */
	GPIO12_GPIO, /* BAT1_CRG */
	GPIO17_GPIO, /* BAT0_LOW */
	GPIO84_GPIO, /* BAT1_LOW */
	GPIO38_GPIO, /* BAT_LOCK */

	GPIO11_3_6MHz,
	GPIO15_GPIO, /* TC6393XB IRQ */
	GPIO18_RDY,
	GPIO27_GPIO, /* LCD Sync */

	/* MMC */
	GPIO6_MMC_CLK,
	GPIO8_MMC_CS0,
	GPIO9_GPIO, /* Detect */
82
	GPIO10_GPIO, /* nSD_INT */
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

	/* CF */
	GPIO13_GPIO, /* CD_IRQ */
	GPIO21_GPIO, /* Main Slot IRQ */
	GPIO36_GPIO, /* Jacket Slot IRQ */
	GPIO48_nPOE,
	GPIO49_nPWE,
	GPIO50_nPIOR,
	GPIO51_nPIOW,
	GPIO52_nPCE_1,
	GPIO53_nPCE_2,
	GPIO54_nPSKTSEL,
	GPIO55_nPREG,
	GPIO56_nPWAIT,
	GPIO57_nIOIS16,

	/* AC97 */
	GPIO31_AC97_SYNC,
	GPIO30_AC97_SDATA_OUT,
	GPIO28_AC97_BITCLK,
	GPIO29_AC97_SDATA_IN_0,
	// GPIO79 nAUD_IRQ

	/* FFUART */
	GPIO34_FFUART_RXD,
	GPIO35_FFUART_CTS,
	GPIO37_FFUART_DSR,
	GPIO39_FFUART_TXD,
	GPIO40_FFUART_DTR,
	GPIO41_FFUART_RTS,

	/* BTUART */
	GPIO42_BTUART_RXD,
	GPIO43_BTUART_TXD,
	GPIO44_BTUART_CTS,
	GPIO45_BTUART_RTS,

	/* Keybd */
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
	GPIO58_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO59_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO60_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO61_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO62_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO63_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO64_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO65_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO66_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO67_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO68_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO69_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO70_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO71_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO72_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO73_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO74_GPIO | MFP_LPM_DRIVE_LOW,
	GPIO75_GPIO | MFP_LPM_DRIVE_LOW,
139 140 141 142 143 144 145

	/* SPI */
	GPIO81_SSP2_CLK_OUT,
	GPIO82_SSP2_FRM_OUT,
	GPIO83_SSP2_TXD,
};

146 147 148 149 150 151 152 153 154 155 156
static unsigned long tosa_pin_irda_off[] = {
	GPIO46_STUART_RXD,
	GPIO47_GPIO | MFP_LPM_DRIVE_LOW,
};

static unsigned long tosa_pin_irda_on[] = {
	GPIO46_STUART_RXD,
	GPIO47_STUART_TXD,
};


157 158 159 160 161 162 163 164 165 166 167 168 169
/*
 * SCOOP Device
 */
static struct resource tosa_scoop_resources[] = {
	[0] = {
		.start	= TOSA_CF_PHYS,
		.end	= TOSA_CF_PHYS + 0xfff,
		.flags	= IORESOURCE_MEM,
	},
};

static struct scoop_config tosa_scoop_setup = {
	.io_dir 	= TOSA_SCOOP_IO_DIR,
170
	.gpio_base	= TOSA_SCOOP_GPIO_BASE,
171 172
};

173
static struct platform_device tosascoop_device = {
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
	.name		= "sharp-scoop",
	.id		= 0,
	.dev		= {
 		.platform_data	= &tosa_scoop_setup,
	},
	.num_resources	= ARRAY_SIZE(tosa_scoop_resources),
	.resource	= tosa_scoop_resources,
};


/*
 * SCOOP Device Jacket
 */
static struct resource tosa_scoop_jc_resources[] = {
	[0] = {
		.start		= TOSA_SCOOP_PHYS + 0x40,
		.end		= TOSA_SCOOP_PHYS + 0xfff,
		.flags		= IORESOURCE_MEM,
	},
};

static struct scoop_config tosa_scoop_jc_setup = {
	.io_dir 	= TOSA_SCOOP_JC_IO_DIR,
197
	.gpio_base	= TOSA_SCOOP_JC_GPIO_BASE,
198 199
};

200
static struct platform_device tosascoop_jc_device = {
201 202 203 204 205 206 207 208 209 210
	.name		= "sharp-scoop",
	.id		= 1,
	.dev		= {
 		.platform_data	= &tosa_scoop_jc_setup,
		.parent 	= &tosascoop_device.dev,
	},
	.num_resources	= ARRAY_SIZE(tosa_scoop_jc_resources),
	.resource	= tosa_scoop_jc_resources,
};

211 212 213
/*
 * PCMCIA
 */
214 215 216 217 218 219 220 221 222 223 224 225 226
static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
{
	.dev        = &tosascoop_device.dev,
	.irq        = TOSA_IRQ_GPIO_CF_IRQ,
	.cd_irq     = TOSA_IRQ_GPIO_CF_CD,
	.cd_irq_str = "PCMCIA0 CD",
},{
	.dev        = &tosascoop_jc_device.dev,
	.irq        = TOSA_IRQ_GPIO_JC_CF_IRQ,
	.cd_irq     = -1,
},
};

227 228 229 230 231
static struct scoop_pcmcia_config tosa_pcmcia_config = {
	.devs         = &tosa_pcmcia_scoop[0],
	.num_devs     = 2,
};

232 233 234 235
/*
 * USB Device Controller
 */
static struct pxa2xx_udc_mach_info udc_info __initdata = {
236
	.gpio_pullup		= TOSA_GPIO_USB_PULLUP,
237 238
	.gpio_vbus		= TOSA_GPIO_USB_IN,
	.gpio_vbus_inverted	= 1,
239 240 241 242 243 244 245
};

/*
 * MMC/SD Device
 */
static struct pxamci_platform_data tosa_mci_platform_data;

246
static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
247 248 249 250 251
{
	int err;

	tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);

252 253 254 255 256 257 258 259 260
	err = gpio_request(TOSA_GPIO_nSD_DETECT, "MMC/SD card detect");
	if (err) {
		printk(KERN_ERR "tosa_mci_init: can't request nSD_DETECT gpio\n");
		goto err_gpio_detect;
	}
	err = gpio_direction_input(TOSA_GPIO_nSD_DETECT);
	if (err)
		goto err_gpio_detect_dir;

261 262
	err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int,
			  IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
263
				"MMC/SD card detect", data);
264
	if (err) {
265
		printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
266 267 268
		goto err_irq;
	}

269
	err = gpio_request(TOSA_GPIO_SD_WP, "SD Write Protect");
270 271 272 273 274 275 276 277
	if (err) {
		printk(KERN_ERR "tosa_mci_init: can't request SD_WP gpio\n");
		goto err_gpio_wp;
	}
	err = gpio_direction_input(TOSA_GPIO_SD_WP);
	if (err)
		goto err_gpio_wp_dir;

278
	err = gpio_request(TOSA_GPIO_PWR_ON, "SD Power");
279 280 281 282 283 284 285
	if (err) {
		printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
		goto err_gpio_pwr;
	}
	err = gpio_direction_output(TOSA_GPIO_PWR_ON, 0);
	if (err)
		goto err_gpio_pwr_dir;
286

287 288 289 290 291 292 293 294 295
	err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
	if (err) {
		printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
		goto err_gpio_int;
	}
	err = gpio_direction_input(TOSA_GPIO_nSD_INT);
	if (err)
		goto err_gpio_int_dir;

296 297
	return 0;

298 299 300
err_gpio_int_dir:
	gpio_free(TOSA_GPIO_nSD_INT);
err_gpio_int:
301 302 303 304 305 306 307 308
err_gpio_pwr_dir:
	gpio_free(TOSA_GPIO_PWR_ON);
err_gpio_pwr:
err_gpio_wp_dir:
	gpio_free(TOSA_GPIO_SD_WP);
err_gpio_wp:
	free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
err_irq:
309 310 311
err_gpio_detect_dir:
	gpio_free(TOSA_GPIO_nSD_DETECT);
err_gpio_detect:
312
	return err;
313 314 315 316 317 318 319
}

static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
{
	struct pxamci_platform_data* p_d = dev->platform_data;

	if (( 1 << vdd) & p_d->ocr_mask) {
320
		gpio_set_value(TOSA_GPIO_PWR_ON, 1);
321
	} else {
322
		gpio_set_value(TOSA_GPIO_PWR_ON, 0);
323 324 325 326 327
	}
}

static int tosa_mci_get_ro(struct device *dev)
{
328
	return gpio_get_value(TOSA_GPIO_SD_WP);
329 330 331 332
}

static void tosa_mci_exit(struct device *dev, void *data)
{
333
	gpio_free(TOSA_GPIO_nSD_INT);
334 335
	gpio_free(TOSA_GPIO_PWR_ON);
	gpio_free(TOSA_GPIO_SD_WP);
336
	free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
337
	gpio_free(TOSA_GPIO_nSD_DETECT);
338 339 340 341 342 343 344 345 346 347 348 349 350
}

static struct pxamci_platform_data tosa_mci_platform_data = {
	.ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
	.init           = tosa_mci_init,
	.get_ro		= tosa_mci_get_ro,
	.setpower       = tosa_mci_setpower,
	.exit           = tosa_mci_exit,
};

/*
 * Irda
 */
351 352 353 354 355 356 357 358 359 360 361 362
static void tosa_irda_transceiver_mode(struct device *dev, int mode)
{
	if (mode & IR_OFF) {
		gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
		pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off));
		gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
	} else {
		pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_on));
		gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
	}
}

363
static int tosa_irda_startup(struct device *dev)
364
{
365 366
	int ret;

367 368 369 370 371 372 373
	ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
	if (ret)
		goto err_tx;
	ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
	if (ret)
		goto err_tx_dir;

374 375
	ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
	if (ret)
376
		goto err_pwr;
377 378 379

	ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
	if (ret)
380
		goto err_pwr_dir;
381

382
	tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
383

384 385 386
	return 0;

err_pwr_dir:
387
	gpio_free(TOSA_GPIO_IR_POWERDWN);
388 389 390 391 392
err_pwr:
err_tx_dir:
	gpio_free(TOSA_GPIO_IRDA_TX);
err_tx:
	return ret;
393 394
}

395
static void tosa_irda_shutdown(struct device *dev)
396
{
397 398 399
	tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
	gpio_free(TOSA_GPIO_IR_POWERDWN);
	gpio_free(TOSA_GPIO_IRDA_TX);
400 401 402 403 404
}

static struct pxaficp_platform_data tosa_ficp_platform_data = {
	.transceiver_cap  = IR_SIRMODE | IR_OFF,
	.transceiver_mode = tosa_irda_transceiver_mode,
405 406
	.startup = tosa_irda_startup,
	.shutdown = tosa_irda_shutdown,
407 408 409 410 411 412 413 414 415
};

/*
 * Tosa Keyboard
 */
static struct platform_device tosakbd_device = {
	.name		= "tosa-keyboard",
	.id		= -1,
};
416

417
static struct gpio_keys_button tosa_gpio_keys[] = {
418 419 420 421 422 423 424 425 426 427 428 429 430
	/*
	 * Two following keys are directly tied to "ON" button of tosa. Why?
	 * The first one can be used as a wakeup source, the second can't;
	 * also the first one is OR of ac_powered and on_button.
	 */
	{
		.type	= EV_PWR,
		.code	= KEY_RESERVED,
		.gpio	= TOSA_GPIO_POWERON,
		.desc	= "Poweron",
		.wakeup	= 1,
		.active_low = 1,
	},
431 432 433 434 435
	{
		.type	= EV_PWR,
		.code	= KEY_SUSPEND,
		.gpio	= TOSA_GPIO_ON_KEY,
		.desc	= "On key",
436 437 438 439
		/*
		 * can't be used as wakeup
		 * .wakeup	= 1,
		 */
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
		.active_low = 1,
	},
	{
		.type	= EV_KEY,
		.code	= TOSA_KEY_RECORD,
		.gpio	= TOSA_GPIO_RECORD_BTN,
		.desc	= "Record Button",
		.wakeup	= 1,
		.active_low = 1,
	},
	{
		.type	= EV_KEY,
		.code	= TOSA_KEY_SYNC,
		.gpio	= TOSA_GPIO_SYNC,
		.desc	= "Sync Button",
		.wakeup	= 1,
		.active_low = 1,
	},
};

static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
	.buttons	= tosa_gpio_keys,
	.nbuttons	= ARRAY_SIZE(tosa_gpio_keys),
};

static struct platform_device tosa_gpio_keys_device = {
	.name	= "gpio-keys",
	.id	= -1,
	.dev	= {
		.platform_data	= &tosa_gpio_keys_platform_data,
	},
};

473 474 475
/*
 * Tosa LEDs
 */
476
static struct gpio_led tosa_gpio_leds[] = {
477 478 479 480 481 482 483 484 485 486
	{
		.name			= "tosa:amber:charge",
		.default_trigger	= "main-battery-charging",
		.gpio			= TOSA_GPIO_CHRG_ERR_LED,
	},
	{
		.name			= "tosa:green:mail",
		.default_trigger	= "nand-disk",
		.gpio			= TOSA_GPIO_NOTE_LED,
	},
487 488 489 490 491 492 493 494 495 496
	{
		.name			= "tosa:dual:wlan",
		.default_trigger	= "none",
		.gpio			= TOSA_GPIO_WLAN_LED,
	},
	{
		.name			= "tosa:blue:bluetooth",
		.default_trigger	= "none",
		.gpio			= TOSA_GPIO_BT_LED,
	},
497 498
};

499
static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
500 501 502 503
	.leds		= tosa_gpio_leds,
	.num_leds	= ARRAY_SIZE(tosa_gpio_leds),
};

504
static struct platform_device tosaled_device = {
505 506 507 508 509
	.name	= "leds-gpio",
	.id	= -1,
	.dev	= {
		.platform_data	= &tosa_gpio_leds_platform_data,
	},
510 511
};

512 513 514
static struct platform_device *devices[] __initdata = {
	&tosascoop_device,
	&tosascoop_jc_device,
515
	&tosakbd_device,
516
	&tosa_gpio_keys_device,
517
	&tosaled_device,
518 519
};

520 521
static void tosa_poweroff(void)
{
522
	arm_machine_restart('g');
523 524 525 526 527 528 529 530 531 532 533
}

static void tosa_restart(char mode)
{
	/* Bootloader magic for a reboot */
	if((MSC0 & 0xffff0000) == 0x7ff00000)
		MSC0 = (MSC0 & 0xffff) | 0x7ee00000;

	tosa_poweroff();
}

534 535
static void __init tosa_init(void)
{
536
	pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
537
	pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off));
538 539 540
	gpio_set_wake(MFP_PIN_GPIO1, 1);
	/* We can't pass to gpio-keys since it will drop the Reset altfunc */

541 542
	init_gpio_reset(TOSA_GPIO_ON_RESET);

543 544 545
	pm_power_off = tosa_poweroff;
	arm_pm_restart = tosa_restart;

546 547
	PCFR |= PCFR_OPDE;

548
	/* enable batt_fault */
549 550
	PMCR = 0x01;

551 552 553
	pxa_set_mci_info(&tosa_mci_platform_data);
	pxa_set_udc_info(&udc_info);
	pxa_set_ficp_info(&tosa_ficp_platform_data);
554
	pxa_set_i2c_info(NULL);
555
	platform_scoop_config = &tosa_pcmcia_config;
556

557
	platform_add_devices(devices, ARRAY_SIZE(devices));
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
}

static void __init fixup_tosa(struct machine_desc *desc,
		struct tag *tags, char **cmdline, struct meminfo *mi)
{
	sharpsl_save_param();
	mi->nr_banks=1;
	mi->bank[0].start = 0xa0000000;
	mi->bank[0].node = 0;
	mi->bank[0].size = (64*1024*1024);
}

MACHINE_START(TOSA, "SHARP Tosa")
	.phys_io	= 0x40000000,
	.io_pg_offst	= (io_p2v(0x40000000) >> 18) & 0xfffc,
	.fixup          = fixup_tosa,
	.map_io         = pxa_map_io,
575
	.init_irq       = pxa25x_init_irq,
576 577 578
	.init_machine   = tosa_init,
	.timer          = &pxa_timer,
MACHINE_END