tosa.c 21.1 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
#include <linux/major.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
21 22
#include <linux/delay.h>
#include <linux/fb.h>
23
#include <linux/mmc/host.h>
24
#include <linux/mfd/tc6393xb.h>
25 26 27
#include <linux/mfd/tmio.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/partitions.h>
28
#include <linux/mtd/physmap.h>
29
#include <linux/pm.h>
30 31
#include <linux/gpio_keys.h>
#include <linux/input.h>
32
#include <linux/gpio.h>
33
#include <linux/pda_power.h>
34
#include <linux/spi/spi.h>
35
#include <linux/spi/pxa2xx_spi.h>
36
#include <linux/input/matrix_keypad.h>
37
#include <linux/i2c/pxa-i2c.h>
38
#include <linux/usb/gpio_vbus.h>
39 40 41

#include <asm/setup.h>
#include <asm/mach-types.h>
42 43

#include <mach/pxa25x.h>
44
#include <mach/reset.h>
45 46 47 48
#include <mach/irda.h>
#include <mach/mmc.h>
#include <mach/udc.h>
#include <mach/tosa_bt.h>
49
#include <mach/audio.h>
50
#include <mach/smemc.h>
51 52

#include <asm/mach/arch.h>
53
#include <mach/tosa.h>
54 55 56 57 58

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

#include "generic.h"
59
#include "clock.h"
60
#include "devices.h"
61

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
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 */
98
	GPIO10_GPIO, /* nSD_INT */
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

	/* 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 */
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
	GPIO58_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 0 */
	GPIO59_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 1 */
	GPIO60_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 2 */
	GPIO61_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 3 */
	GPIO62_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 4 */
	GPIO63_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 5 */
	GPIO64_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 6 */
	GPIO65_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 7 */
	GPIO66_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 8 */
	GPIO67_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 9 */
	GPIO68_GPIO | MFP_LPM_DRIVE_LOW,	/* Column 10 */
	GPIO69_GPIO | MFP_LPM_DRIVE_LOW,	/* Row 0 */
	GPIO70_GPIO | MFP_LPM_DRIVE_LOW,	/* Row 1 */
	GPIO71_GPIO | MFP_LPM_DRIVE_LOW,	/* Row 2 */
	GPIO72_GPIO | MFP_LPM_DRIVE_LOW,	/* Row 3 */
	GPIO73_GPIO | MFP_LPM_DRIVE_LOW,	/* Row 4 */
	GPIO74_GPIO | MFP_LPM_DRIVE_LOW,	/* Row 5 */
	GPIO75_GPIO | MFP_LPM_DRIVE_LOW,	/* Row 6 */
155 156 157 158 159

	/* SPI */
	GPIO81_SSP2_CLK_OUT,
	GPIO82_SSP2_FRM_OUT,
	GPIO83_SSP2_TXD,
160

161 162 163
	/* IrDA is managed in other way */
	GPIO46_GPIO,
	GPIO47_GPIO,
164 165
};

166 167 168 169 170 171 172 173 174 175 176 177 178
/*
 * 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,
179
	.gpio_base	= TOSA_SCOOP_GPIO_BASE,
180 181
};

182
static struct platform_device tosascoop_device = {
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
	.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,
206
	.gpio_base	= TOSA_SCOOP_JC_GPIO_BASE,
207 208
};

209
static struct platform_device tosascoop_jc_device = {
210 211 212 213 214 215 216 217 218 219
	.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,
};

220 221 222
/*
 * PCMCIA
 */
223 224 225 226 227 228 229 230 231 232 233 234 235
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,
},
};

236 237 238 239 240
static struct scoop_pcmcia_config tosa_pcmcia_config = {
	.devs         = &tosa_pcmcia_scoop[0],
	.num_devs     = 2,
};

241 242 243
/*
 * USB Device Controller
 */
244
static struct gpio_vbus_mach_info tosa_udc_info = {
245
	.gpio_pullup		= TOSA_GPIO_USB_PULLUP,
246 247
	.gpio_vbus		= TOSA_GPIO_USB_IN,
	.gpio_vbus_inverted	= 1,
248 249
};

250 251 252 253 254 255 256 257
static struct platform_device tosa_gpio_vbus = {
	.name	= "gpio-vbus",
	.id	= -1,
	.dev	= {
		.platform_data	= &tosa_udc_info,
	},
};

258 259 260
/*
 * MMC/SD Device
 */
261
static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
262 263 264
{
	int err;

265 266 267 268 269 270 271 272 273
	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;

274 275
	return 0;

276 277 278
err_gpio_int_dir:
	gpio_free(TOSA_GPIO_nSD_INT);
err_gpio_int:
279
	return err;
280 281 282 283
}

static void tosa_mci_exit(struct device *dev, void *data)
{
284
	gpio_free(TOSA_GPIO_nSD_INT);
285 286 287
}

static struct pxamci_platform_data tosa_mci_platform_data = {
288
	.detect_delay_ms	= 250,
289 290 291 292 293 294
	.ocr_mask       	= MMC_VDD_32_33|MMC_VDD_33_34,
	.init           	= tosa_mci_init,
	.exit           	= tosa_mci_exit,
	.gpio_card_detect	= TOSA_GPIO_nSD_DETECT,
	.gpio_card_ro		= TOSA_GPIO_SD_WP,
	.gpio_power		= TOSA_GPIO_PWR_ON,
295 296 297 298 299
};

/*
 * Irda
 */
300 301 302 303
static void tosa_irda_transceiver_mode(struct device *dev, int mode)
{
	if (mode & IR_OFF) {
		gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
304
		pxa2xx_transceiver_mode(dev, mode);
305 306
		gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
	} else {
307
		pxa2xx_transceiver_mode(dev, mode);
308 309 310 311
		gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
	}
}

312
static int tosa_irda_startup(struct device *dev)
313
{
314 315
	int ret;

316 317 318 319 320 321 322
	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;

323 324
	ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
	if (ret)
325
		goto err_pwr;
326 327 328

	ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
	if (ret)
329
		goto err_pwr_dir;
330

331
	tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
332

333 334 335
	return 0;

err_pwr_dir:
336
	gpio_free(TOSA_GPIO_IR_POWERDWN);
337 338 339 340 341
err_pwr:
err_tx_dir:
	gpio_free(TOSA_GPIO_IRDA_TX);
err_tx:
	return ret;
342 343
}

344
static void tosa_irda_shutdown(struct device *dev)
345
{
346 347 348
	tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
	gpio_free(TOSA_GPIO_IR_POWERDWN);
	gpio_free(TOSA_GPIO_IRDA_TX);
349 350 351
}

static struct pxaficp_platform_data tosa_ficp_platform_data = {
352 353 354 355 356
	.gpio_pwdown		= -1,
	.transceiver_cap	= IR_SIRMODE | IR_OFF,
	.transceiver_mode	= tosa_irda_transceiver_mode,
	.startup		= tosa_irda_startup,
	.shutdown		= tosa_irda_shutdown,
357 358
};

359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 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
/*
 * Tosa AC IN
 */
static int tosa_power_init(struct device *dev)
{
	int ret = gpio_request(TOSA_GPIO_AC_IN, "ac in");
	if (ret)
		goto err_gpio_req;

	ret = gpio_direction_input(TOSA_GPIO_AC_IN);
	if (ret)
		goto err_gpio_in;

	return 0;

err_gpio_in:
	gpio_free(TOSA_GPIO_AC_IN);
err_gpio_req:
	return ret;
}

static void tosa_power_exit(struct device *dev)
{
	gpio_free(TOSA_GPIO_AC_IN);
}

static int tosa_power_ac_online(void)
{
	return gpio_get_value(TOSA_GPIO_AC_IN) == 0;
}

static char *tosa_ac_supplied_to[] = {
	"main-battery",
	"backup-battery",
	"jacket-battery",
};

static struct pda_power_pdata tosa_power_data = {
	.init			= tosa_power_init,
	.is_ac_online		= tosa_power_ac_online,
	.exit			= tosa_power_exit,
	.supplied_to		= tosa_ac_supplied_to,
	.num_supplicants	= ARRAY_SIZE(tosa_ac_supplied_to),
};

static struct resource tosa_power_resource[] = {
	{
		.name		= "ac",
		.start		= gpio_to_irq(TOSA_GPIO_AC_IN),
		.end		= gpio_to_irq(TOSA_GPIO_AC_IN),
		.flags		= IORESOURCE_IRQ |
				  IORESOURCE_IRQ_HIGHEDGE |
				  IORESOURCE_IRQ_LOWEDGE,
	},
};

static struct platform_device tosa_power_device = {
	.name			= "pda-power",
	.id			= -1,
	.dev.platform_data	= &tosa_power_data,
	.resource		= tosa_power_resource,
	.num_resources		= ARRAY_SIZE(tosa_power_resource),
};

423 424 425
/*
 * Tosa Keyboard
 */
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 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 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
static const uint32_t tosakbd_keymap[] = {
	KEY(0, 2, KEY_W),
	KEY(0, 6, KEY_K),
	KEY(0, 7, KEY_BACKSPACE),
	KEY(0, 8, KEY_P),
	KEY(1, 1, KEY_Q),
	KEY(1, 2, KEY_E),
	KEY(1, 3, KEY_T),
	KEY(1, 4, KEY_Y),
	KEY(1, 6, KEY_O),
	KEY(1, 7, KEY_I),
	KEY(1, 8, KEY_COMMA),
	KEY(2, 1, KEY_A),
	KEY(2, 2, KEY_D),
	KEY(2, 3, KEY_G),
	KEY(2, 4, KEY_U),
	KEY(2, 6, KEY_L),
	KEY(2, 7, KEY_ENTER),
	KEY(2, 8, KEY_DOT),
	KEY(3, 1, KEY_Z),
	KEY(3, 2, KEY_C),
	KEY(3, 3, KEY_V),
	KEY(3, 4, KEY_J),
	KEY(3, 5, TOSA_KEY_ADDRESSBOOK),
	KEY(3, 6, TOSA_KEY_CANCEL),
	KEY(3, 7, TOSA_KEY_CENTER),
	KEY(3, 8, TOSA_KEY_OK),
	KEY(3, 9, KEY_LEFTSHIFT),
	KEY(4, 1, KEY_S),
	KEY(4, 2, KEY_R),
	KEY(4, 3, KEY_B),
	KEY(4, 4, KEY_N),
	KEY(4, 5, TOSA_KEY_CALENDAR),
	KEY(4, 6, TOSA_KEY_HOMEPAGE),
	KEY(4, 7, KEY_LEFTCTRL),
	KEY(4, 8, TOSA_KEY_LIGHT),
	KEY(4, 10, KEY_RIGHTSHIFT),
	KEY(5, 1, KEY_TAB),
	KEY(5, 2, KEY_SLASH),
	KEY(5, 3, KEY_H),
	KEY(5, 4, KEY_M),
	KEY(5, 5, TOSA_KEY_MENU),
	KEY(5, 7, KEY_UP),
	KEY(5, 11, TOSA_KEY_FN),
	KEY(6, 1, KEY_X),
	KEY(6, 2, KEY_F),
	KEY(6, 3, KEY_SPACE),
	KEY(6, 4, KEY_APOSTROPHE),
	KEY(6, 5, TOSA_KEY_MAIL),
	KEY(6, 6, KEY_LEFT),
	KEY(6, 7, KEY_DOWN),
	KEY(6, 8, KEY_RIGHT),
};

static struct matrix_keymap_data tosakbd_keymap_data = {
	.keymap		= tosakbd_keymap,
	.keymap_size	= ARRAY_SIZE(tosakbd_keymap),
};

static const int tosakbd_col_gpios[] =
			{ 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68 };
static const int tosakbd_row_gpios[] =
			{ 69, 70, 71, 72, 73, 74, 75 };

static struct matrix_keypad_platform_data tosakbd_pdata = {
	.keymap_data		= &tosakbd_keymap_data,
	.row_gpios		= tosakbd_row_gpios,
	.col_gpios		= tosakbd_col_gpios,
	.num_row_gpios		= ARRAY_SIZE(tosakbd_row_gpios),
	.num_col_gpios		= ARRAY_SIZE(tosakbd_col_gpios),
	.col_scan_delay_us	= 10,
	.debounce_ms		= 10,
	.wakeup			= 1,
};

501
static struct platform_device tosakbd_device = {
502
	.name		= "matrix-keypad",
503
	.id		= -1,
504 505 506
	.dev		= {
		.platform_data = &tosakbd_pdata,
	},
507
};
508

509
static struct gpio_keys_button tosa_gpio_keys[] = {
510 511 512 513 514 515 516 517 518 519 520 521 522
	/*
	 * 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,
	},
523 524 525 526 527
	{
		.type	= EV_PWR,
		.code	= KEY_SUSPEND,
		.gpio	= TOSA_GPIO_ON_KEY,
		.desc	= "On key",
528 529 530 531
		/*
		 * can't be used as wakeup
		 * .wakeup	= 1,
		 */
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
		.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,
	},
550 551 552 553 554 555 556 557
	{
		.type	= EV_SW,
		.code	= SW_HEADPHONE_INSERT,
		.gpio	= TOSA_GPIO_EAR_IN,
		.desc	= "HeadPhone insert",
		.active_low = 1,
		.debounce_interval = 300,
	},
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
};

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,
	},
};

573 574 575
/*
 * Tosa LEDs
 */
576
static struct gpio_led tosa_gpio_leds[] = {
577 578 579 580 581 582 583 584 585 586
	{
		.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,
	},
587 588 589 590 591 592 593
	{
		.name			= "tosa:dual:wlan",
		.default_trigger	= "none",
		.gpio			= TOSA_GPIO_WLAN_LED,
	},
	{
		.name			= "tosa:blue:bluetooth",
594
		.default_trigger	= "tosa-bt",
595 596
		.gpio			= TOSA_GPIO_BT_LED,
	},
597 598
};

599
static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
600 601 602 603
	.leds		= tosa_gpio_leds,
	.num_leds	= ARRAY_SIZE(tosa_gpio_leds),
};

604
static struct platform_device tosaled_device = {
605 606 607 608 609
	.name	= "leds-gpio",
	.id	= -1,
	.dev	= {
		.platform_data	= &tosa_gpio_leds_platform_data,
	},
610 611
};

612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
/*
 * Toshiba Mobile IO Controller
 */
static struct resource tc6393xb_resources[] = {
	[0] = {
		.start	= TOSA_LCDC_PHYS,
		.end	= TOSA_LCDC_PHYS + 0x3ffffff,
		.flags	= IORESOURCE_MEM,
	},

	[1] = {
		.start	= TOSA_IRQ_GPIO_TC6393XB_INT,
		.end	= TOSA_IRQ_GPIO_TC6393XB_INT,
		.flags	= IORESOURCE_IRQ,
	},
};


static int tosa_tc6393xb_enable(struct platform_device *dev)
{
	int rc;

	rc = gpio_request(TOSA_GPIO_TC6393XB_REST_IN, "tc6393xb #pclr");
	if (rc)
		goto err_req_pclr;
	rc = gpio_request(TOSA_GPIO_TC6393XB_SUSPEND, "tc6393xb #suspend");
	if (rc)
		goto err_req_suspend;
640
	rc = gpio_request(TOSA_GPIO_TC6393XB_L3V_ON, "tc6393xb l3v");
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
	if (rc)
		goto err_req_l3v;
	rc = gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON, 0);
	if (rc)
		goto err_dir_l3v;
	rc = gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND, 0);
	if (rc)
		goto err_dir_suspend;
	rc = gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN, 0);
	if (rc)
		goto err_dir_pclr;

	mdelay(1);

	gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);

	mdelay(10);

	gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN, 1);
	gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);

	return 0;
err_dir_pclr:
err_dir_suspend:
err_dir_l3v:
	gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
err_req_l3v:
	gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
err_req_suspend:
	gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
err_req_pclr:
	return rc;
}

static int tosa_tc6393xb_disable(struct platform_device *dev)
{
	gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
	gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
	gpio_free(TOSA_GPIO_TC6393XB_REST_IN);

	return 0;
}

static int tosa_tc6393xb_resume(struct platform_device *dev)
{
	gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
	mdelay(10);
	gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
	mdelay(10);

	return 0;
}

static int tosa_tc6393xb_suspend(struct platform_device *dev)
{
	gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 0);
	gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 0);
	return 0;
}

701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
static struct mtd_partition tosa_nand_partition[] = {
	{
		.name	= "smf",
		.offset	= 0,
		.size	= 7 * 1024 * 1024,
	},
	{
		.name	= "root",
		.offset	= MTDPART_OFS_APPEND,
		.size	= 28 * 1024 * 1024,
	},
	{
		.name	= "home",
		.offset	= MTDPART_OFS_APPEND,
		.size	= MTDPART_SIZ_FULL,
	},
};

static uint8_t scan_ff_pattern[] = { 0xff, 0xff };

static struct nand_bbt_descr tosa_tc6393xb_nand_bbt = {
	.options	= 0,
	.offs		= 4,
	.len		= 2,
	.pattern	= scan_ff_pattern
};

static struct tmio_nand_data tosa_tc6393xb_nand_config = {
	.num_partitions	= ARRAY_SIZE(tosa_nand_partition),
	.partition	= tosa_nand_partition,
	.badblock_pattern = &tosa_tc6393xb_nand_bbt,
};

734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
static int tosa_tc6393xb_setup(struct platform_device *dev)
{
	int rc;

	rc = gpio_request(TOSA_GPIO_CARD_VCC_ON, "CARD_VCC_ON");
	if (rc)
		goto err_req;

	rc = gpio_direction_output(TOSA_GPIO_CARD_VCC_ON, 1);
	if (rc)
		goto err_dir;

	return rc;

err_dir:
	gpio_free(TOSA_GPIO_CARD_VCC_ON);
err_req:
	return rc;
}

static void tosa_tc6393xb_teardown(struct platform_device *dev)
{
	gpio_free(TOSA_GPIO_CARD_VCC_ON);
}

759
#ifdef CONFIG_MFD_TC6393XB
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
static struct fb_videomode tosa_tc6393xb_lcd_mode[] = {
	{
		.xres = 480,
		.yres = 640,
		.pixclock = 0x002cdf00,/* PLL divisor */
		.left_margin = 0x004c,
		.right_margin = 0x005b,
		.upper_margin = 0x0001,
		.lower_margin = 0x000d,
		.hsync_len = 0x0002,
		.vsync_len = 0x0001,
		.sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
		.vmode = FB_VMODE_NONINTERLACED,
	},{
		.xres = 240,
		.yres = 320,
		.pixclock = 0x00e7f203,/* PLL divisor */
		.left_margin = 0x0024,
		.right_margin = 0x002f,
		.upper_margin = 0x0001,
		.lower_margin = 0x000d,
		.hsync_len = 0x0002,
		.vsync_len = 0x0001,
		.sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
		.vmode = FB_VMODE_NONINTERLACED,
	}
};

static struct tmio_fb_data tosa_tc6393xb_fb_config = {
	.lcd_set_power	= tc6393xb_lcd_set_power,
	.lcd_mode	= tc6393xb_lcd_mode,
	.num_modes	= ARRAY_SIZE(tosa_tc6393xb_lcd_mode),
	.modes		= &tosa_tc6393xb_lcd_mode[0],
	.height		= 82,
	.width		= 60,
};
796
#endif
797

798
static struct tc6393xb_platform_data tosa_tc6393xb_data = {
799 800 801 802 803
	.scr_pll2cr	= 0x0cc1,
	.scr_gper	= 0x3300,

	.irq_base	= IRQ_BOARD_START,
	.gpio_base	= TOSA_TC6393XB_GPIO_BASE,
804 805
	.setup		= tosa_tc6393xb_setup,
	.teardown	= tosa_tc6393xb_teardown,
806 807 808 809 810

	.enable		= tosa_tc6393xb_enable,
	.disable	= tosa_tc6393xb_disable,
	.suspend	= tosa_tc6393xb_suspend,
	.resume		= tosa_tc6393xb_resume,
811 812

	.nand_data	= &tosa_tc6393xb_nand_config,
813
#ifdef CONFIG_MFD_TC6393XB
814
	.fb_data	= &tosa_tc6393xb_fb_config,
815
#endif
816 817

	.resume_restore = 1,
818 819 820 821 822 823 824
};


static struct platform_device tc6393xb_device = {
	.name	= "tc6393xb",
	.id	= -1,
	.dev	= {
825
		.platform_data	= &tosa_tc6393xb_data,
826 827 828 829 830
	},
	.num_resources	= ARRAY_SIZE(tc6393xb_resources),
	.resource	= tc6393xb_resources,
};

831 832 833 834 835 836 837 838 839 840 841
static struct tosa_bt_data tosa_bt_data = {
	.gpio_pwr	= TOSA_GPIO_BT_PWR_EN,
	.gpio_reset	= TOSA_GPIO_BT_RESET,
};

static struct platform_device tosa_bt_device = {
	.name	= "tosa-bt",
	.id	= -1,
	.dev.platform_data = &tosa_bt_data,
};

842 843 844 845 846 847 848 849 850 851 852 853 854 855
static struct pxa2xx_spi_master pxa_ssp_master_info = {
	.num_chipselect	= 1,
};

static struct spi_board_info spi_board_info[] __initdata = {
	{
		.modalias	= "tosa-lcd",
		// .platform_data
		.max_speed_hz	= 28750,
		.bus_num	= 2,
		.chip_select	= 0,
		.mode		= SPI_MODE_0,
	},
};
856

857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
static struct mtd_partition sharpsl_rom_parts[] = {
	{
		.name	="Boot PROM Filesystem",
		.offset	= 0x00160000,
		.size	= MTDPART_SIZ_FULL,
	},
};

static struct physmap_flash_data sharpsl_rom_data = {
	.width		= 2,
	.nr_parts	= ARRAY_SIZE(sharpsl_rom_parts),
	.parts		= sharpsl_rom_parts,
};

static struct resource sharpsl_rom_resources[] = {
	{
		.start	= 0x00000000,
		.end	= 0x007fffff,
		.flags	= IORESOURCE_MEM,
	},
};

static struct platform_device sharpsl_rom_device = {
	.name	= "physmap-flash",
	.id	= -1,
	.resource = sharpsl_rom_resources,
	.num_resources = ARRAY_SIZE(sharpsl_rom_resources),
	.dev.platform_data = &sharpsl_rom_data,
};

887 888 889 890 891
static struct platform_device wm9712_device = {
	.name	= "wm9712-codec",
	.id	= -1,
};

892 893 894
static struct platform_device *devices[] __initdata = {
	&tosascoop_device,
	&tosascoop_jc_device,
895
	&tc6393xb_device,
896
	&tosa_power_device,
897
	&tosakbd_device,
898
	&tosa_gpio_keys_device,
899
	&tosaled_device,
900
	&tosa_bt_device,
901
	&sharpsl_rom_device,
902
	&wm9712_device,
903
	&tosa_gpio_vbus,
904 905
};

906 907
static void tosa_poweroff(void)
{
908
	arm_machine_restart('g', NULL);
909 910
}

911
static void tosa_restart(char mode, const char *cmd)
912
{
913 914
	uint32_t msc0 = __raw_readl(MSC0);

915
	/* Bootloader magic for a reboot */
916 917
	if((msc0 & 0xffff0000) == 0x7ff00000)
		__raw_writel((msc0 & 0xffff) | 0x7ee00000, MSC0);
918 919 920 921

	tosa_poweroff();
}

922 923
static void __init tosa_init(void)
{
924 925
	int dummy;

926
	pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
927 928 929 930 931

	pxa_set_ffuart_info(NULL);
	pxa_set_btuart_info(NULL);
	pxa_set_stuart_info(NULL);

932 933 934
	gpio_set_wake(MFP_PIN_GPIO1, 1);
	/* We can't pass to gpio-keys since it will drop the Reset altfunc */

935
	init_gpio_reset(TOSA_GPIO_ON_RESET, 0, 0);
936

937 938 939
	pm_power_off = tosa_poweroff;
	arm_pm_restart = tosa_restart;

940 941
	PCFR |= PCFR_OPDE;

942
	/* enable batt_fault */
943 944
	PMCR = 0x01;

945 946 947 948
	dummy = gpiochip_reserve(TOSA_SCOOP_GPIO_BASE, 12);
	dummy = gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE, 12);
	dummy = gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE, 16);

949 950
	pxa_set_mci_info(&tosa_mci_platform_data);
	pxa_set_ficp_info(&tosa_ficp_platform_data);
951
	pxa_set_i2c_info(NULL);
952
	pxa_set_ac97_info(NULL);
953
	platform_scoop_config = &tosa_pcmcia_config;
954

955 956 957
	pxa2xx_set_spi_info(2, &pxa_ssp_master_info);
	spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));

958
	clk_add_alias("CLK_CK3P6MI", tc6393xb_device.name, "GPIO11_CLK", NULL);
959

960
	platform_add_devices(devices, ARRAY_SIZE(devices));
961 962 963 964 965 966 967 968 969 970 971 972 973
}

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].size = (64*1024*1024);
}

MACHINE_START(TOSA, "SHARP Tosa")
	.fixup          = fixup_tosa,
974
	.map_io         = pxa25x_map_io,
975
	.nr_irqs	= TOSA_NR_IRQS,
976
	.init_irq       = pxa25x_init_irq,
977 978 979
	.init_machine   = tosa_init,
	.timer          = &pxa_timer,
MACHINE_END