2 * Support for Sharp SL-C6000x PDAs
5 * Copyright (c) 2005 Dirk Opfer
7 * Based on code written by Sharp/Lineo for 2.4 kernels
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/major.h>
20 #include <linux/interrupt.h>
21 #include <linux/delay.h>
23 #include <linux/mmc/host.h>
24 #include <linux/mfd/tc6393xb.h>
25 #include <linux/mfd/tmio.h>
26 #include <linux/mtd/nand.h>
27 #include <linux/mtd/partitions.h>
29 #include <linux/delay.h>
30 #include <linux/gpio_keys.h>
31 #include <linux/input.h>
32 #include <linux/gpio.h>
33 #include <linux/pda_power.h>
35 #include <asm/setup.h>
36 #include <asm/mach-types.h>
37 #include <asm/arch/pxa2xx-regs.h>
38 #include <asm/arch/mfp-pxa25x.h>
39 #include <asm/arch/irda.h>
40 #include <asm/arch/i2c.h>
41 #include <asm/arch/mmc.h>
42 #include <asm/arch/udc.h>
44 #include <asm/mach/arch.h>
45 #include <asm/arch/tosa.h>
47 #include <asm/hardware/scoop.h>
48 #include <asm/mach/sharpsl_param.h>
53 static unsigned long tosa_pin_config[] = {
54 GPIO78_nCS_2, /* Scoop */
55 GPIO80_nCS_4, /* tg6393xb */
56 GPIO33_nCS_5, /* Scoop */
58 // GPIO76 CARD_VCC_ON1
60 GPIO19_GPIO, /* Reset out */
61 GPIO1_RST | WAKEUP_ON_EDGE_FALL,
63 GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */
64 GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */
65 GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */
66 GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */
67 GPIO20_GPIO, /* EAR_IN */
70 GPIO5_GPIO, /* USB_IN */
71 GPIO32_GPIO, /* Pen IRQ */
73 GPIO7_GPIO, /* Jacket Detect */
74 GPIO14_GPIO, /* BAT0_CRG */
75 GPIO12_GPIO, /* BAT1_CRG */
76 GPIO17_GPIO, /* BAT0_LOW */
77 GPIO84_GPIO, /* BAT1_LOW */
78 GPIO38_GPIO, /* BAT_LOCK */
81 GPIO15_GPIO, /* TC6393XB IRQ */
83 GPIO27_GPIO, /* LCD Sync */
88 GPIO9_GPIO, /* Detect */
89 GPIO10_GPIO, /* nSD_INT */
92 GPIO13_GPIO, /* CD_IRQ */
93 GPIO21_GPIO, /* Main Slot IRQ */
94 GPIO36_GPIO, /* Jacket Slot IRQ */
108 GPIO30_AC97_SDATA_OUT,
110 GPIO29_AC97_SDATA_IN_0,
128 GPIO58_GPIO | MFP_LPM_DRIVE_LOW,
129 GPIO59_GPIO | MFP_LPM_DRIVE_LOW,
130 GPIO60_GPIO | MFP_LPM_DRIVE_LOW,
131 GPIO61_GPIO | MFP_LPM_DRIVE_LOW,
132 GPIO62_GPIO | MFP_LPM_DRIVE_LOW,
133 GPIO63_GPIO | MFP_LPM_DRIVE_LOW,
134 GPIO64_GPIO | MFP_LPM_DRIVE_LOW,
135 GPIO65_GPIO | MFP_LPM_DRIVE_LOW,
136 GPIO66_GPIO | MFP_LPM_DRIVE_LOW,
137 GPIO67_GPIO | MFP_LPM_DRIVE_LOW,
138 GPIO68_GPIO | MFP_LPM_DRIVE_LOW,
139 GPIO69_GPIO | MFP_LPM_DRIVE_LOW,
140 GPIO70_GPIO | MFP_LPM_DRIVE_LOW,
141 GPIO71_GPIO | MFP_LPM_DRIVE_LOW,
142 GPIO72_GPIO | MFP_LPM_DRIVE_LOW,
143 GPIO73_GPIO | MFP_LPM_DRIVE_LOW,
144 GPIO74_GPIO | MFP_LPM_DRIVE_LOW,
145 GPIO75_GPIO | MFP_LPM_DRIVE_LOW,
153 static unsigned long tosa_pin_irda_off[] = {
155 GPIO47_GPIO | MFP_LPM_DRIVE_LOW,
158 static unsigned long tosa_pin_irda_on[] = {
167 static struct resource tosa_scoop_resources[] = {
169 .start = TOSA_CF_PHYS,
170 .end = TOSA_CF_PHYS + 0xfff,
171 .flags = IORESOURCE_MEM,
175 static struct scoop_config tosa_scoop_setup = {
176 .io_dir = TOSA_SCOOP_IO_DIR,
177 .gpio_base = TOSA_SCOOP_GPIO_BASE,
180 static struct platform_device tosascoop_device = {
181 .name = "sharp-scoop",
184 .platform_data = &tosa_scoop_setup,
186 .num_resources = ARRAY_SIZE(tosa_scoop_resources),
187 .resource = tosa_scoop_resources,
192 * SCOOP Device Jacket
194 static struct resource tosa_scoop_jc_resources[] = {
196 .start = TOSA_SCOOP_PHYS + 0x40,
197 .end = TOSA_SCOOP_PHYS + 0xfff,
198 .flags = IORESOURCE_MEM,
202 static struct scoop_config tosa_scoop_jc_setup = {
203 .io_dir = TOSA_SCOOP_JC_IO_DIR,
204 .gpio_base = TOSA_SCOOP_JC_GPIO_BASE,
207 static struct platform_device tosascoop_jc_device = {
208 .name = "sharp-scoop",
211 .platform_data = &tosa_scoop_jc_setup,
212 .parent = &tosascoop_device.dev,
214 .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
215 .resource = tosa_scoop_jc_resources,
221 static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
223 .dev = &tosascoop_device.dev,
224 .irq = TOSA_IRQ_GPIO_CF_IRQ,
225 .cd_irq = TOSA_IRQ_GPIO_CF_CD,
226 .cd_irq_str = "PCMCIA0 CD",
228 .dev = &tosascoop_jc_device.dev,
229 .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
234 static struct scoop_pcmcia_config tosa_pcmcia_config = {
235 .devs = &tosa_pcmcia_scoop[0],
240 * USB Device Controller
242 static struct pxa2xx_udc_mach_info udc_info __initdata = {
243 .gpio_pullup = TOSA_GPIO_USB_PULLUP,
244 .gpio_vbus = TOSA_GPIO_USB_IN,
245 .gpio_vbus_inverted = 1,
251 static struct pxamci_platform_data tosa_mci_platform_data;
253 static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
257 tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
259 err = gpio_request(TOSA_GPIO_nSD_DETECT, "MMC/SD card detect");
261 printk(KERN_ERR "tosa_mci_init: can't request nSD_DETECT gpio\n");
262 goto err_gpio_detect;
264 err = gpio_direction_input(TOSA_GPIO_nSD_DETECT);
266 goto err_gpio_detect_dir;
268 err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int,
269 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
270 "MMC/SD card detect", data);
272 printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
276 err = gpio_request(TOSA_GPIO_SD_WP, "SD Write Protect");
278 printk(KERN_ERR "tosa_mci_init: can't request SD_WP gpio\n");
281 err = gpio_direction_input(TOSA_GPIO_SD_WP);
283 goto err_gpio_wp_dir;
285 err = gpio_request(TOSA_GPIO_PWR_ON, "SD Power");
287 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
290 err = gpio_direction_output(TOSA_GPIO_PWR_ON, 0);
292 goto err_gpio_pwr_dir;
294 err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
296 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
299 err = gpio_direction_input(TOSA_GPIO_nSD_INT);
301 goto err_gpio_int_dir;
306 gpio_free(TOSA_GPIO_nSD_INT);
309 gpio_free(TOSA_GPIO_PWR_ON);
312 gpio_free(TOSA_GPIO_SD_WP);
314 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
317 gpio_free(TOSA_GPIO_nSD_DETECT);
322 static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
324 struct pxamci_platform_data* p_d = dev->platform_data;
326 if (( 1 << vdd) & p_d->ocr_mask) {
327 gpio_set_value(TOSA_GPIO_PWR_ON, 1);
329 gpio_set_value(TOSA_GPIO_PWR_ON, 0);
333 static int tosa_mci_get_ro(struct device *dev)
335 return gpio_get_value(TOSA_GPIO_SD_WP);
338 static void tosa_mci_exit(struct device *dev, void *data)
340 gpio_free(TOSA_GPIO_nSD_INT);
341 gpio_free(TOSA_GPIO_PWR_ON);
342 gpio_free(TOSA_GPIO_SD_WP);
343 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
344 gpio_free(TOSA_GPIO_nSD_DETECT);
347 static struct pxamci_platform_data tosa_mci_platform_data = {
348 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
349 .init = tosa_mci_init,
350 .get_ro = tosa_mci_get_ro,
351 .setpower = tosa_mci_setpower,
352 .exit = tosa_mci_exit,
358 static void tosa_irda_transceiver_mode(struct device *dev, int mode)
361 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
362 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off));
363 gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
365 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_on));
366 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
370 static int tosa_irda_startup(struct device *dev)
374 ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
377 ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
381 ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
385 ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
389 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
394 gpio_free(TOSA_GPIO_IR_POWERDWN);
397 gpio_free(TOSA_GPIO_IRDA_TX);
402 static void tosa_irda_shutdown(struct device *dev)
404 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
405 gpio_free(TOSA_GPIO_IR_POWERDWN);
406 gpio_free(TOSA_GPIO_IRDA_TX);
409 static struct pxaficp_platform_data tosa_ficp_platform_data = {
410 .transceiver_cap = IR_SIRMODE | IR_OFF,
411 .transceiver_mode = tosa_irda_transceiver_mode,
412 .startup = tosa_irda_startup,
413 .shutdown = tosa_irda_shutdown,
419 static int tosa_power_init(struct device *dev)
421 int ret = gpio_request(TOSA_GPIO_AC_IN, "ac in");
425 ret = gpio_direction_input(TOSA_GPIO_AC_IN);
432 gpio_free(TOSA_GPIO_AC_IN);
437 static void tosa_power_exit(struct device *dev)
439 gpio_free(TOSA_GPIO_AC_IN);
442 static int tosa_power_ac_online(void)
444 return gpio_get_value(TOSA_GPIO_AC_IN) == 0;
447 static char *tosa_ac_supplied_to[] = {
453 static struct pda_power_pdata tosa_power_data = {
454 .init = tosa_power_init,
455 .is_ac_online = tosa_power_ac_online,
456 .exit = tosa_power_exit,
457 .supplied_to = tosa_ac_supplied_to,
458 .num_supplicants = ARRAY_SIZE(tosa_ac_supplied_to),
461 static struct resource tosa_power_resource[] = {
464 .start = gpio_to_irq(TOSA_GPIO_AC_IN),
465 .end = gpio_to_irq(TOSA_GPIO_AC_IN),
466 .flags = IORESOURCE_IRQ |
467 IORESOURCE_IRQ_HIGHEDGE |
468 IORESOURCE_IRQ_LOWEDGE,
472 static struct platform_device tosa_power_device = {
475 .dev.platform_data = &tosa_power_data,
476 .resource = tosa_power_resource,
477 .num_resources = ARRAY_SIZE(tosa_power_resource),
483 static struct platform_device tosakbd_device = {
484 .name = "tosa-keyboard",
488 static struct gpio_keys_button tosa_gpio_keys[] = {
490 * Two following keys are directly tied to "ON" button of tosa. Why?
491 * The first one can be used as a wakeup source, the second can't;
492 * also the first one is OR of ac_powered and on_button.
496 .code = KEY_RESERVED,
497 .gpio = TOSA_GPIO_POWERON,
505 .gpio = TOSA_GPIO_ON_KEY,
508 * can't be used as wakeup
515 .code = TOSA_KEY_RECORD,
516 .gpio = TOSA_GPIO_RECORD_BTN,
517 .desc = "Record Button",
523 .code = TOSA_KEY_SYNC,
524 .gpio = TOSA_GPIO_SYNC,
525 .desc = "Sync Button",
531 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
532 .buttons = tosa_gpio_keys,
533 .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
536 static struct platform_device tosa_gpio_keys_device = {
540 .platform_data = &tosa_gpio_keys_platform_data,
547 static struct gpio_led tosa_gpio_leds[] = {
549 .name = "tosa:amber:charge",
550 .default_trigger = "main-battery-charging",
551 .gpio = TOSA_GPIO_CHRG_ERR_LED,
554 .name = "tosa:green:mail",
555 .default_trigger = "nand-disk",
556 .gpio = TOSA_GPIO_NOTE_LED,
559 .name = "tosa:dual:wlan",
560 .default_trigger = "none",
561 .gpio = TOSA_GPIO_WLAN_LED,
564 .name = "tosa:blue:bluetooth",
565 .default_trigger = "none",
566 .gpio = TOSA_GPIO_BT_LED,
570 static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
571 .leds = tosa_gpio_leds,
572 .num_leds = ARRAY_SIZE(tosa_gpio_leds),
575 static struct platform_device tosaled_device = {
579 .platform_data = &tosa_gpio_leds_platform_data,
584 * Toshiba Mobile IO Controller
586 static struct resource tc6393xb_resources[] = {
588 .start = TOSA_LCDC_PHYS,
589 .end = TOSA_LCDC_PHYS + 0x3ffffff,
590 .flags = IORESOURCE_MEM,
594 .start = TOSA_IRQ_GPIO_TC6393XB_INT,
595 .end = TOSA_IRQ_GPIO_TC6393XB_INT,
596 .flags = IORESOURCE_IRQ,
601 static int tosa_tc6393xb_enable(struct platform_device *dev)
605 rc = gpio_request(TOSA_GPIO_TC6393XB_REST_IN, "tc6393xb #pclr");
608 rc = gpio_request(TOSA_GPIO_TC6393XB_SUSPEND, "tc6393xb #suspend");
610 goto err_req_suspend;
611 rc = gpio_request(TOSA_GPIO_TC6393XB_L3V_ON, "l3v");
614 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON, 0);
617 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND, 0);
619 goto err_dir_suspend;
620 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN, 0);
626 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
630 gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN, 1);
631 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
637 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
639 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
641 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
646 static int tosa_tc6393xb_disable(struct platform_device *dev)
648 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
649 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
650 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
655 static int tosa_tc6393xb_resume(struct platform_device *dev)
657 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
659 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
665 static int tosa_tc6393xb_suspend(struct platform_device *dev)
667 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 0);
668 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 0);
672 static struct mtd_partition tosa_nand_partition[] = {
676 .size = 7 * 1024 * 1024,
680 .offset = MTDPART_OFS_APPEND,
681 .size = 28 * 1024 * 1024,
685 .offset = MTDPART_OFS_APPEND,
686 .size = MTDPART_SIZ_FULL,
690 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
692 static struct nand_bbt_descr tosa_tc6393xb_nand_bbt = {
696 .pattern = scan_ff_pattern
699 static struct tmio_nand_data tosa_tc6393xb_nand_config = {
700 .num_partitions = ARRAY_SIZE(tosa_nand_partition),
701 .partition = tosa_nand_partition,
702 .badblock_pattern = &tosa_tc6393xb_nand_bbt,
705 static struct tc6393xb_platform_data tosa_tc6393xb_setup = {
706 .scr_pll2cr = 0x0cc1,
709 TOSA_TC6393XB_GPIO_BIT(TOSA_GPIO_CARD_VCC_ON),
711 TOSA_TC6393XB_GPIO_BIT(TOSA_GPIO_CARD_VCC_ON),
713 .irq_base = IRQ_BOARD_START,
714 .gpio_base = TOSA_TC6393XB_GPIO_BASE,
716 .enable = tosa_tc6393xb_enable,
717 .disable = tosa_tc6393xb_disable,
718 .suspend = tosa_tc6393xb_suspend,
719 .resume = tosa_tc6393xb_resume,
721 .nand_data = &tosa_tc6393xb_nand_config,
725 static struct platform_device tc6393xb_device = {
729 .platform_data = &tosa_tc6393xb_setup,
731 .num_resources = ARRAY_SIZE(tc6393xb_resources),
732 .resource = tc6393xb_resources,
735 static struct platform_device *devices[] __initdata = {
737 &tosascoop_jc_device,
741 &tosa_gpio_keys_device,
745 static void tosa_poweroff(void)
747 arm_machine_restart('g');
750 static void tosa_restart(char mode)
752 /* Bootloader magic for a reboot */
753 if((MSC0 & 0xffff0000) == 0x7ff00000)
754 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
759 static void __init tosa_init(void)
763 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
764 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off));
765 gpio_set_wake(MFP_PIN_GPIO1, 1);
766 /* We can't pass to gpio-keys since it will drop the Reset altfunc */
768 init_gpio_reset(TOSA_GPIO_ON_RESET);
770 pm_power_off = tosa_poweroff;
771 arm_pm_restart = tosa_restart;
775 /* enable batt_fault */
778 dummy = gpiochip_reserve(TOSA_SCOOP_GPIO_BASE, 12);
779 dummy = gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE, 12);
780 dummy = gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE, 16);
782 pxa_set_mci_info(&tosa_mci_platform_data);
783 pxa_set_udc_info(&udc_info);
784 pxa_set_ficp_info(&tosa_ficp_platform_data);
785 pxa_set_i2c_info(NULL);
786 platform_scoop_config = &tosa_pcmcia_config;
788 platform_add_devices(devices, ARRAY_SIZE(devices));
791 static void __init fixup_tosa(struct machine_desc *desc,
792 struct tag *tags, char **cmdline, struct meminfo *mi)
794 sharpsl_save_param();
796 mi->bank[0].start = 0xa0000000;
797 mi->bank[0].node = 0;
798 mi->bank[0].size = (64*1024*1024);
801 MACHINE_START(TOSA, "SHARP Tosa")
802 .phys_io = 0x40000000,
803 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
805 .map_io = pxa_map_io,
806 .init_irq = pxa25x_init_irq,
807 .init_machine = tosa_init,