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/gpio_keys.h>
30 #include <linux/input.h>
31 #include <linux/gpio.h>
32 #include <linux/pda_power.h>
33 #include <linux/rfkill.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>
43 #include <asm/arch/tosa_bt.h>
45 #include <asm/mach/arch.h>
46 #include <asm/arch/tosa.h>
48 #include <asm/hardware/scoop.h>
49 #include <asm/mach/sharpsl_param.h>
54 static unsigned long tosa_pin_config[] = {
55 GPIO78_nCS_2, /* Scoop */
56 GPIO80_nCS_4, /* tg6393xb */
57 GPIO33_nCS_5, /* Scoop */
59 // GPIO76 CARD_VCC_ON1
61 GPIO19_GPIO, /* Reset out */
62 GPIO1_RST | WAKEUP_ON_EDGE_FALL,
64 GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */
65 GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */
66 GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */
67 GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */
68 GPIO20_GPIO, /* EAR_IN */
71 GPIO5_GPIO, /* USB_IN */
72 GPIO32_GPIO, /* Pen IRQ */
74 GPIO7_GPIO, /* Jacket Detect */
75 GPIO14_GPIO, /* BAT0_CRG */
76 GPIO12_GPIO, /* BAT1_CRG */
77 GPIO17_GPIO, /* BAT0_LOW */
78 GPIO84_GPIO, /* BAT1_LOW */
79 GPIO38_GPIO, /* BAT_LOCK */
82 GPIO15_GPIO, /* TC6393XB IRQ */
84 GPIO27_GPIO, /* LCD Sync */
89 GPIO9_GPIO, /* Detect */
90 GPIO10_GPIO, /* nSD_INT */
93 GPIO13_GPIO, /* CD_IRQ */
94 GPIO21_GPIO, /* Main Slot IRQ */
95 GPIO36_GPIO, /* Jacket Slot IRQ */
109 GPIO30_AC97_SDATA_OUT,
111 GPIO29_AC97_SDATA_IN_0,
129 GPIO58_GPIO | MFP_LPM_DRIVE_LOW,
130 GPIO59_GPIO | MFP_LPM_DRIVE_LOW,
131 GPIO60_GPIO | MFP_LPM_DRIVE_LOW,
132 GPIO61_GPIO | MFP_LPM_DRIVE_LOW,
133 GPIO62_GPIO | MFP_LPM_DRIVE_LOW,
134 GPIO63_GPIO | MFP_LPM_DRIVE_LOW,
135 GPIO64_GPIO | MFP_LPM_DRIVE_LOW,
136 GPIO65_GPIO | MFP_LPM_DRIVE_LOW,
137 GPIO66_GPIO | MFP_LPM_DRIVE_LOW,
138 GPIO67_GPIO | MFP_LPM_DRIVE_LOW,
139 GPIO68_GPIO | MFP_LPM_DRIVE_LOW,
140 GPIO69_GPIO | MFP_LPM_DRIVE_LOW,
141 GPIO70_GPIO | MFP_LPM_DRIVE_LOW,
142 GPIO71_GPIO | MFP_LPM_DRIVE_LOW,
143 GPIO72_GPIO | MFP_LPM_DRIVE_LOW,
144 GPIO73_GPIO | MFP_LPM_DRIVE_LOW,
145 GPIO74_GPIO | MFP_LPM_DRIVE_LOW,
146 GPIO75_GPIO | MFP_LPM_DRIVE_LOW,
154 static unsigned long tosa_pin_irda_off[] = {
156 GPIO47_GPIO | MFP_LPM_DRIVE_LOW,
159 static unsigned long tosa_pin_irda_on[] = {
168 static struct resource tosa_scoop_resources[] = {
170 .start = TOSA_CF_PHYS,
171 .end = TOSA_CF_PHYS + 0xfff,
172 .flags = IORESOURCE_MEM,
176 static struct scoop_config tosa_scoop_setup = {
177 .io_dir = TOSA_SCOOP_IO_DIR,
178 .gpio_base = TOSA_SCOOP_GPIO_BASE,
181 static struct platform_device tosascoop_device = {
182 .name = "sharp-scoop",
185 .platform_data = &tosa_scoop_setup,
187 .num_resources = ARRAY_SIZE(tosa_scoop_resources),
188 .resource = tosa_scoop_resources,
193 * SCOOP Device Jacket
195 static struct resource tosa_scoop_jc_resources[] = {
197 .start = TOSA_SCOOP_PHYS + 0x40,
198 .end = TOSA_SCOOP_PHYS + 0xfff,
199 .flags = IORESOURCE_MEM,
203 static struct scoop_config tosa_scoop_jc_setup = {
204 .io_dir = TOSA_SCOOP_JC_IO_DIR,
205 .gpio_base = TOSA_SCOOP_JC_GPIO_BASE,
208 static struct platform_device tosascoop_jc_device = {
209 .name = "sharp-scoop",
212 .platform_data = &tosa_scoop_jc_setup,
213 .parent = &tosascoop_device.dev,
215 .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
216 .resource = tosa_scoop_jc_resources,
222 static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
224 .dev = &tosascoop_device.dev,
225 .irq = TOSA_IRQ_GPIO_CF_IRQ,
226 .cd_irq = TOSA_IRQ_GPIO_CF_CD,
227 .cd_irq_str = "PCMCIA0 CD",
229 .dev = &tosascoop_jc_device.dev,
230 .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
235 static struct scoop_pcmcia_config tosa_pcmcia_config = {
236 .devs = &tosa_pcmcia_scoop[0],
241 * USB Device Controller
243 static struct pxa2xx_udc_mach_info udc_info __initdata = {
244 .gpio_pullup = TOSA_GPIO_USB_PULLUP,
245 .gpio_vbus = TOSA_GPIO_USB_IN,
246 .gpio_vbus_inverted = 1,
252 static struct pxamci_platform_data tosa_mci_platform_data;
254 static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
258 tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
260 err = gpio_request(TOSA_GPIO_nSD_DETECT, "MMC/SD card detect");
262 printk(KERN_ERR "tosa_mci_init: can't request nSD_DETECT gpio\n");
263 goto err_gpio_detect;
265 err = gpio_direction_input(TOSA_GPIO_nSD_DETECT);
267 goto err_gpio_detect_dir;
269 err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int,
270 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
271 "MMC/SD card detect", data);
273 printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
277 err = gpio_request(TOSA_GPIO_SD_WP, "SD Write Protect");
279 printk(KERN_ERR "tosa_mci_init: can't request SD_WP gpio\n");
282 err = gpio_direction_input(TOSA_GPIO_SD_WP);
284 goto err_gpio_wp_dir;
286 err = gpio_request(TOSA_GPIO_PWR_ON, "SD Power");
288 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
291 err = gpio_direction_output(TOSA_GPIO_PWR_ON, 0);
293 goto err_gpio_pwr_dir;
295 err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
297 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
300 err = gpio_direction_input(TOSA_GPIO_nSD_INT);
302 goto err_gpio_int_dir;
307 gpio_free(TOSA_GPIO_nSD_INT);
310 gpio_free(TOSA_GPIO_PWR_ON);
313 gpio_free(TOSA_GPIO_SD_WP);
315 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
318 gpio_free(TOSA_GPIO_nSD_DETECT);
323 static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
325 struct pxamci_platform_data* p_d = dev->platform_data;
327 if (( 1 << vdd) & p_d->ocr_mask) {
328 gpio_set_value(TOSA_GPIO_PWR_ON, 1);
330 gpio_set_value(TOSA_GPIO_PWR_ON, 0);
334 static int tosa_mci_get_ro(struct device *dev)
336 return gpio_get_value(TOSA_GPIO_SD_WP);
339 static void tosa_mci_exit(struct device *dev, void *data)
341 gpio_free(TOSA_GPIO_nSD_INT);
342 gpio_free(TOSA_GPIO_PWR_ON);
343 gpio_free(TOSA_GPIO_SD_WP);
344 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
345 gpio_free(TOSA_GPIO_nSD_DETECT);
348 static struct pxamci_platform_data tosa_mci_platform_data = {
349 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
350 .init = tosa_mci_init,
351 .get_ro = tosa_mci_get_ro,
352 .setpower = tosa_mci_setpower,
353 .exit = tosa_mci_exit,
359 static void tosa_irda_transceiver_mode(struct device *dev, int mode)
362 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
363 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off));
364 gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
366 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_on));
367 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
371 static int tosa_irda_startup(struct device *dev)
375 ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
378 ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
382 ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
386 ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
390 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
395 gpio_free(TOSA_GPIO_IR_POWERDWN);
398 gpio_free(TOSA_GPIO_IRDA_TX);
403 static void tosa_irda_shutdown(struct device *dev)
405 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
406 gpio_free(TOSA_GPIO_IR_POWERDWN);
407 gpio_free(TOSA_GPIO_IRDA_TX);
410 static struct pxaficp_platform_data tosa_ficp_platform_data = {
411 .transceiver_cap = IR_SIRMODE | IR_OFF,
412 .transceiver_mode = tosa_irda_transceiver_mode,
413 .startup = tosa_irda_startup,
414 .shutdown = tosa_irda_shutdown,
420 static int tosa_power_init(struct device *dev)
422 int ret = gpio_request(TOSA_GPIO_AC_IN, "ac in");
426 ret = gpio_direction_input(TOSA_GPIO_AC_IN);
433 gpio_free(TOSA_GPIO_AC_IN);
438 static void tosa_power_exit(struct device *dev)
440 gpio_free(TOSA_GPIO_AC_IN);
443 static int tosa_power_ac_online(void)
445 return gpio_get_value(TOSA_GPIO_AC_IN) == 0;
448 static char *tosa_ac_supplied_to[] = {
454 static struct pda_power_pdata tosa_power_data = {
455 .init = tosa_power_init,
456 .is_ac_online = tosa_power_ac_online,
457 .exit = tosa_power_exit,
458 .supplied_to = tosa_ac_supplied_to,
459 .num_supplicants = ARRAY_SIZE(tosa_ac_supplied_to),
462 static struct resource tosa_power_resource[] = {
465 .start = gpio_to_irq(TOSA_GPIO_AC_IN),
466 .end = gpio_to_irq(TOSA_GPIO_AC_IN),
467 .flags = IORESOURCE_IRQ |
468 IORESOURCE_IRQ_HIGHEDGE |
469 IORESOURCE_IRQ_LOWEDGE,
473 static struct platform_device tosa_power_device = {
476 .dev.platform_data = &tosa_power_data,
477 .resource = tosa_power_resource,
478 .num_resources = ARRAY_SIZE(tosa_power_resource),
484 static struct platform_device tosakbd_device = {
485 .name = "tosa-keyboard",
489 static struct gpio_keys_button tosa_gpio_keys[] = {
491 * Two following keys are directly tied to "ON" button of tosa. Why?
492 * The first one can be used as a wakeup source, the second can't;
493 * also the first one is OR of ac_powered and on_button.
497 .code = KEY_RESERVED,
498 .gpio = TOSA_GPIO_POWERON,
506 .gpio = TOSA_GPIO_ON_KEY,
509 * can't be used as wakeup
516 .code = TOSA_KEY_RECORD,
517 .gpio = TOSA_GPIO_RECORD_BTN,
518 .desc = "Record Button",
524 .code = TOSA_KEY_SYNC,
525 .gpio = TOSA_GPIO_SYNC,
526 .desc = "Sync Button",
532 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
533 .buttons = tosa_gpio_keys,
534 .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
537 static struct platform_device tosa_gpio_keys_device = {
541 .platform_data = &tosa_gpio_keys_platform_data,
548 static struct gpio_led tosa_gpio_leds[] = {
550 .name = "tosa:amber:charge",
551 .default_trigger = "main-battery-charging",
552 .gpio = TOSA_GPIO_CHRG_ERR_LED,
555 .name = "tosa:green:mail",
556 .default_trigger = "nand-disk",
557 .gpio = TOSA_GPIO_NOTE_LED,
560 .name = "tosa:dual:wlan",
561 .default_trigger = "none",
562 .gpio = TOSA_GPIO_WLAN_LED,
565 .name = "tosa:blue:bluetooth",
566 .default_trigger = "tosa-bt",
567 .gpio = TOSA_GPIO_BT_LED,
571 static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
572 .leds = tosa_gpio_leds,
573 .num_leds = ARRAY_SIZE(tosa_gpio_leds),
576 static struct platform_device tosaled_device = {
580 .platform_data = &tosa_gpio_leds_platform_data,
585 * Toshiba Mobile IO Controller
587 static struct resource tc6393xb_resources[] = {
589 .start = TOSA_LCDC_PHYS,
590 .end = TOSA_LCDC_PHYS + 0x3ffffff,
591 .flags = IORESOURCE_MEM,
595 .start = TOSA_IRQ_GPIO_TC6393XB_INT,
596 .end = TOSA_IRQ_GPIO_TC6393XB_INT,
597 .flags = IORESOURCE_IRQ,
602 static int tosa_tc6393xb_enable(struct platform_device *dev)
606 rc = gpio_request(TOSA_GPIO_TC6393XB_REST_IN, "tc6393xb #pclr");
609 rc = gpio_request(TOSA_GPIO_TC6393XB_SUSPEND, "tc6393xb #suspend");
611 goto err_req_suspend;
612 rc = gpio_request(TOSA_GPIO_TC6393XB_L3V_ON, "l3v");
615 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON, 0);
618 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND, 0);
620 goto err_dir_suspend;
621 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN, 0);
627 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
631 gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN, 1);
632 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
638 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
640 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
642 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
647 static int tosa_tc6393xb_disable(struct platform_device *dev)
649 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
650 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
651 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
656 static int tosa_tc6393xb_resume(struct platform_device *dev)
658 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
660 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
666 static int tosa_tc6393xb_suspend(struct platform_device *dev)
668 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 0);
669 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 0);
673 static struct mtd_partition tosa_nand_partition[] = {
677 .size = 7 * 1024 * 1024,
681 .offset = MTDPART_OFS_APPEND,
682 .size = 28 * 1024 * 1024,
686 .offset = MTDPART_OFS_APPEND,
687 .size = MTDPART_SIZ_FULL,
691 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
693 static struct nand_bbt_descr tosa_tc6393xb_nand_bbt = {
697 .pattern = scan_ff_pattern
700 static struct tmio_nand_data tosa_tc6393xb_nand_config = {
701 .num_partitions = ARRAY_SIZE(tosa_nand_partition),
702 .partition = tosa_nand_partition,
703 .badblock_pattern = &tosa_tc6393xb_nand_bbt,
706 static struct tc6393xb_platform_data tosa_tc6393xb_setup = {
707 .scr_pll2cr = 0x0cc1,
710 TOSA_TC6393XB_GPIO_BIT(TOSA_GPIO_CARD_VCC_ON),
712 TOSA_TC6393XB_GPIO_BIT(TOSA_GPIO_CARD_VCC_ON),
714 .irq_base = IRQ_BOARD_START,
715 .gpio_base = TOSA_TC6393XB_GPIO_BASE,
717 .enable = tosa_tc6393xb_enable,
718 .disable = tosa_tc6393xb_disable,
719 .suspend = tosa_tc6393xb_suspend,
720 .resume = tosa_tc6393xb_resume,
722 .nand_data = &tosa_tc6393xb_nand_config,
726 static struct platform_device tc6393xb_device = {
730 .platform_data = &tosa_tc6393xb_setup,
732 .num_resources = ARRAY_SIZE(tc6393xb_resources),
733 .resource = tc6393xb_resources,
736 static struct tosa_bt_data tosa_bt_data = {
737 .gpio_pwr = TOSA_GPIO_BT_PWR_EN,
738 .gpio_reset = TOSA_GPIO_BT_RESET,
741 static struct platform_device tosa_bt_device = {
744 .dev.platform_data = &tosa_bt_data,
748 static struct platform_device *devices[] __initdata = {
750 &tosascoop_jc_device,
754 &tosa_gpio_keys_device,
759 static void tosa_poweroff(void)
761 arm_machine_restart('g');
764 static void tosa_restart(char mode)
766 /* Bootloader magic for a reboot */
767 if((MSC0 & 0xffff0000) == 0x7ff00000)
768 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
773 static void __init tosa_init(void)
777 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
778 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off));
779 gpio_set_wake(MFP_PIN_GPIO1, 1);
780 /* We can't pass to gpio-keys since it will drop the Reset altfunc */
782 init_gpio_reset(TOSA_GPIO_ON_RESET);
784 pm_power_off = tosa_poweroff;
785 arm_pm_restart = tosa_restart;
789 /* enable batt_fault */
792 dummy = gpiochip_reserve(TOSA_SCOOP_GPIO_BASE, 12);
793 dummy = gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE, 12);
794 dummy = gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE, 16);
796 pxa_set_mci_info(&tosa_mci_platform_data);
797 pxa_set_udc_info(&udc_info);
798 pxa_set_ficp_info(&tosa_ficp_platform_data);
799 pxa_set_i2c_info(NULL);
800 platform_scoop_config = &tosa_pcmcia_config;
802 platform_add_devices(devices, ARRAY_SIZE(devices));
805 static void __init fixup_tosa(struct machine_desc *desc,
806 struct tag *tags, char **cmdline, struct meminfo *mi)
808 sharpsl_save_param();
810 mi->bank[0].start = 0xa0000000;
811 mi->bank[0].node = 0;
812 mi->bank[0].size = (64*1024*1024);
815 MACHINE_START(TOSA, "SHARP Tosa")
816 .phys_io = 0x40000000,
817 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
819 .map_io = pxa_map_io,
820 .init_irq = pxa25x_init_irq,
821 .init_machine = tosa_init,