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>
34 #include <linux/rfkill.h>
36 #include <asm/setup.h>
37 #include <asm/mach-types.h>
38 #include <asm/arch/pxa2xx-regs.h>
39 #include <asm/arch/mfp-pxa25x.h>
40 #include <asm/arch/irda.h>
41 #include <asm/arch/i2c.h>
42 #include <asm/arch/mmc.h>
43 #include <asm/arch/udc.h>
44 #include <asm/arch/tosa_bt.h>
46 #include <asm/mach/arch.h>
47 #include <asm/arch/tosa.h>
49 #include <asm/hardware/scoop.h>
50 #include <asm/mach/sharpsl_param.h>
55 static unsigned long tosa_pin_config[] = {
56 GPIO78_nCS_2, /* Scoop */
57 GPIO80_nCS_4, /* tg6393xb */
58 GPIO33_nCS_5, /* Scoop */
60 // GPIO76 CARD_VCC_ON1
62 GPIO19_GPIO, /* Reset out */
63 GPIO1_RST | WAKEUP_ON_EDGE_FALL,
65 GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */
66 GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */
67 GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */
68 GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */
69 GPIO20_GPIO, /* EAR_IN */
72 GPIO5_GPIO, /* USB_IN */
73 GPIO32_GPIO, /* Pen IRQ */
75 GPIO7_GPIO, /* Jacket Detect */
76 GPIO14_GPIO, /* BAT0_CRG */
77 GPIO12_GPIO, /* BAT1_CRG */
78 GPIO17_GPIO, /* BAT0_LOW */
79 GPIO84_GPIO, /* BAT1_LOW */
80 GPIO38_GPIO, /* BAT_LOCK */
83 GPIO15_GPIO, /* TC6393XB IRQ */
85 GPIO27_GPIO, /* LCD Sync */
90 GPIO9_GPIO, /* Detect */
91 GPIO10_GPIO, /* nSD_INT */
94 GPIO13_GPIO, /* CD_IRQ */
95 GPIO21_GPIO, /* Main Slot IRQ */
96 GPIO36_GPIO, /* Jacket Slot IRQ */
110 GPIO30_AC97_SDATA_OUT,
112 GPIO29_AC97_SDATA_IN_0,
130 GPIO58_GPIO | MFP_LPM_DRIVE_LOW,
131 GPIO59_GPIO | MFP_LPM_DRIVE_LOW,
132 GPIO60_GPIO | MFP_LPM_DRIVE_LOW,
133 GPIO61_GPIO | MFP_LPM_DRIVE_LOW,
134 GPIO62_GPIO | MFP_LPM_DRIVE_LOW,
135 GPIO63_GPIO | MFP_LPM_DRIVE_LOW,
136 GPIO64_GPIO | MFP_LPM_DRIVE_LOW,
137 GPIO65_GPIO | MFP_LPM_DRIVE_LOW,
138 GPIO66_GPIO | MFP_LPM_DRIVE_LOW,
139 GPIO67_GPIO | MFP_LPM_DRIVE_LOW,
140 GPIO68_GPIO | MFP_LPM_DRIVE_LOW,
141 GPIO69_GPIO | MFP_LPM_DRIVE_LOW,
142 GPIO70_GPIO | MFP_LPM_DRIVE_LOW,
143 GPIO71_GPIO | MFP_LPM_DRIVE_LOW,
144 GPIO72_GPIO | MFP_LPM_DRIVE_LOW,
145 GPIO73_GPIO | MFP_LPM_DRIVE_LOW,
146 GPIO74_GPIO | MFP_LPM_DRIVE_LOW,
147 GPIO75_GPIO | MFP_LPM_DRIVE_LOW,
155 static unsigned long tosa_pin_irda_off[] = {
157 GPIO47_GPIO | MFP_LPM_DRIVE_LOW,
160 static unsigned long tosa_pin_irda_on[] = {
169 static struct resource tosa_scoop_resources[] = {
171 .start = TOSA_CF_PHYS,
172 .end = TOSA_CF_PHYS + 0xfff,
173 .flags = IORESOURCE_MEM,
177 static struct scoop_config tosa_scoop_setup = {
178 .io_dir = TOSA_SCOOP_IO_DIR,
179 .gpio_base = TOSA_SCOOP_GPIO_BASE,
182 static struct platform_device tosascoop_device = {
183 .name = "sharp-scoop",
186 .platform_data = &tosa_scoop_setup,
188 .num_resources = ARRAY_SIZE(tosa_scoop_resources),
189 .resource = tosa_scoop_resources,
194 * SCOOP Device Jacket
196 static struct resource tosa_scoop_jc_resources[] = {
198 .start = TOSA_SCOOP_PHYS + 0x40,
199 .end = TOSA_SCOOP_PHYS + 0xfff,
200 .flags = IORESOURCE_MEM,
204 static struct scoop_config tosa_scoop_jc_setup = {
205 .io_dir = TOSA_SCOOP_JC_IO_DIR,
206 .gpio_base = TOSA_SCOOP_JC_GPIO_BASE,
209 static struct platform_device tosascoop_jc_device = {
210 .name = "sharp-scoop",
213 .platform_data = &tosa_scoop_jc_setup,
214 .parent = &tosascoop_device.dev,
216 .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
217 .resource = tosa_scoop_jc_resources,
223 static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
225 .dev = &tosascoop_device.dev,
226 .irq = TOSA_IRQ_GPIO_CF_IRQ,
227 .cd_irq = TOSA_IRQ_GPIO_CF_CD,
228 .cd_irq_str = "PCMCIA0 CD",
230 .dev = &tosascoop_jc_device.dev,
231 .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
236 static struct scoop_pcmcia_config tosa_pcmcia_config = {
237 .devs = &tosa_pcmcia_scoop[0],
242 * USB Device Controller
244 static struct pxa2xx_udc_mach_info udc_info __initdata = {
245 .gpio_pullup = TOSA_GPIO_USB_PULLUP,
246 .gpio_vbus = TOSA_GPIO_USB_IN,
247 .gpio_vbus_inverted = 1,
253 static struct pxamci_platform_data tosa_mci_platform_data;
255 static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
259 tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
261 err = gpio_request(TOSA_GPIO_nSD_DETECT, "MMC/SD card detect");
263 printk(KERN_ERR "tosa_mci_init: can't request nSD_DETECT gpio\n");
264 goto err_gpio_detect;
266 err = gpio_direction_input(TOSA_GPIO_nSD_DETECT);
268 goto err_gpio_detect_dir;
270 err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int,
271 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
272 "MMC/SD card detect", data);
274 printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
278 err = gpio_request(TOSA_GPIO_SD_WP, "SD Write Protect");
280 printk(KERN_ERR "tosa_mci_init: can't request SD_WP gpio\n");
283 err = gpio_direction_input(TOSA_GPIO_SD_WP);
285 goto err_gpio_wp_dir;
287 err = gpio_request(TOSA_GPIO_PWR_ON, "SD Power");
289 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
292 err = gpio_direction_output(TOSA_GPIO_PWR_ON, 0);
294 goto err_gpio_pwr_dir;
296 err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
298 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
301 err = gpio_direction_input(TOSA_GPIO_nSD_INT);
303 goto err_gpio_int_dir;
308 gpio_free(TOSA_GPIO_nSD_INT);
311 gpio_free(TOSA_GPIO_PWR_ON);
314 gpio_free(TOSA_GPIO_SD_WP);
316 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
319 gpio_free(TOSA_GPIO_nSD_DETECT);
324 static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
326 struct pxamci_platform_data* p_d = dev->platform_data;
328 if (( 1 << vdd) & p_d->ocr_mask) {
329 gpio_set_value(TOSA_GPIO_PWR_ON, 1);
331 gpio_set_value(TOSA_GPIO_PWR_ON, 0);
335 static int tosa_mci_get_ro(struct device *dev)
337 return gpio_get_value(TOSA_GPIO_SD_WP);
340 static void tosa_mci_exit(struct device *dev, void *data)
342 gpio_free(TOSA_GPIO_nSD_INT);
343 gpio_free(TOSA_GPIO_PWR_ON);
344 gpio_free(TOSA_GPIO_SD_WP);
345 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
346 gpio_free(TOSA_GPIO_nSD_DETECT);
349 static struct pxamci_platform_data tosa_mci_platform_data = {
350 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
351 .init = tosa_mci_init,
352 .get_ro = tosa_mci_get_ro,
353 .setpower = tosa_mci_setpower,
354 .exit = tosa_mci_exit,
360 static void tosa_irda_transceiver_mode(struct device *dev, int mode)
363 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
364 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off));
365 gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
367 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_on));
368 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
372 static int tosa_irda_startup(struct device *dev)
376 ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
379 ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
383 ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
387 ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
391 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
396 gpio_free(TOSA_GPIO_IR_POWERDWN);
399 gpio_free(TOSA_GPIO_IRDA_TX);
404 static void tosa_irda_shutdown(struct device *dev)
406 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
407 gpio_free(TOSA_GPIO_IR_POWERDWN);
408 gpio_free(TOSA_GPIO_IRDA_TX);
411 static struct pxaficp_platform_data tosa_ficp_platform_data = {
412 .transceiver_cap = IR_SIRMODE | IR_OFF,
413 .transceiver_mode = tosa_irda_transceiver_mode,
414 .startup = tosa_irda_startup,
415 .shutdown = tosa_irda_shutdown,
421 static int tosa_power_init(struct device *dev)
423 int ret = gpio_request(TOSA_GPIO_AC_IN, "ac in");
427 ret = gpio_direction_input(TOSA_GPIO_AC_IN);
434 gpio_free(TOSA_GPIO_AC_IN);
439 static void tosa_power_exit(struct device *dev)
441 gpio_free(TOSA_GPIO_AC_IN);
444 static int tosa_power_ac_online(void)
446 return gpio_get_value(TOSA_GPIO_AC_IN) == 0;
449 static char *tosa_ac_supplied_to[] = {
455 static struct pda_power_pdata tosa_power_data = {
456 .init = tosa_power_init,
457 .is_ac_online = tosa_power_ac_online,
458 .exit = tosa_power_exit,
459 .supplied_to = tosa_ac_supplied_to,
460 .num_supplicants = ARRAY_SIZE(tosa_ac_supplied_to),
463 static struct resource tosa_power_resource[] = {
466 .start = gpio_to_irq(TOSA_GPIO_AC_IN),
467 .end = gpio_to_irq(TOSA_GPIO_AC_IN),
468 .flags = IORESOURCE_IRQ |
469 IORESOURCE_IRQ_HIGHEDGE |
470 IORESOURCE_IRQ_LOWEDGE,
474 static struct platform_device tosa_power_device = {
477 .dev.platform_data = &tosa_power_data,
478 .resource = tosa_power_resource,
479 .num_resources = ARRAY_SIZE(tosa_power_resource),
485 static struct platform_device tosakbd_device = {
486 .name = "tosa-keyboard",
490 static struct gpio_keys_button tosa_gpio_keys[] = {
492 * Two following keys are directly tied to "ON" button of tosa. Why?
493 * The first one can be used as a wakeup source, the second can't;
494 * also the first one is OR of ac_powered and on_button.
498 .code = KEY_RESERVED,
499 .gpio = TOSA_GPIO_POWERON,
507 .gpio = TOSA_GPIO_ON_KEY,
510 * can't be used as wakeup
517 .code = TOSA_KEY_RECORD,
518 .gpio = TOSA_GPIO_RECORD_BTN,
519 .desc = "Record Button",
525 .code = TOSA_KEY_SYNC,
526 .gpio = TOSA_GPIO_SYNC,
527 .desc = "Sync Button",
533 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
534 .buttons = tosa_gpio_keys,
535 .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
538 static struct platform_device tosa_gpio_keys_device = {
542 .platform_data = &tosa_gpio_keys_platform_data,
549 static struct gpio_led tosa_gpio_leds[] = {
551 .name = "tosa:amber:charge",
552 .default_trigger = "main-battery-charging",
553 .gpio = TOSA_GPIO_CHRG_ERR_LED,
556 .name = "tosa:green:mail",
557 .default_trigger = "nand-disk",
558 .gpio = TOSA_GPIO_NOTE_LED,
561 .name = "tosa:dual:wlan",
562 .default_trigger = "none",
563 .gpio = TOSA_GPIO_WLAN_LED,
566 .name = "tosa:blue:bluetooth",
567 .default_trigger = "tosa-bt",
568 .gpio = TOSA_GPIO_BT_LED,
572 static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
573 .leds = tosa_gpio_leds,
574 .num_leds = ARRAY_SIZE(tosa_gpio_leds),
577 static struct platform_device tosaled_device = {
581 .platform_data = &tosa_gpio_leds_platform_data,
586 * Toshiba Mobile IO Controller
588 static struct resource tc6393xb_resources[] = {
590 .start = TOSA_LCDC_PHYS,
591 .end = TOSA_LCDC_PHYS + 0x3ffffff,
592 .flags = IORESOURCE_MEM,
596 .start = TOSA_IRQ_GPIO_TC6393XB_INT,
597 .end = TOSA_IRQ_GPIO_TC6393XB_INT,
598 .flags = IORESOURCE_IRQ,
603 static int tosa_tc6393xb_enable(struct platform_device *dev)
607 rc = gpio_request(TOSA_GPIO_TC6393XB_REST_IN, "tc6393xb #pclr");
610 rc = gpio_request(TOSA_GPIO_TC6393XB_SUSPEND, "tc6393xb #suspend");
612 goto err_req_suspend;
613 rc = gpio_request(TOSA_GPIO_TC6393XB_L3V_ON, "l3v");
616 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON, 0);
619 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND, 0);
621 goto err_dir_suspend;
622 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN, 0);
628 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
632 gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN, 1);
633 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
639 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
641 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
643 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
648 static int tosa_tc6393xb_disable(struct platform_device *dev)
650 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
651 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
652 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
657 static int tosa_tc6393xb_resume(struct platform_device *dev)
659 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
661 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
667 static int tosa_tc6393xb_suspend(struct platform_device *dev)
669 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 0);
670 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 0);
674 static struct mtd_partition tosa_nand_partition[] = {
678 .size = 7 * 1024 * 1024,
682 .offset = MTDPART_OFS_APPEND,
683 .size = 28 * 1024 * 1024,
687 .offset = MTDPART_OFS_APPEND,
688 .size = MTDPART_SIZ_FULL,
692 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
694 static struct nand_bbt_descr tosa_tc6393xb_nand_bbt = {
698 .pattern = scan_ff_pattern
701 static struct tmio_nand_data tosa_tc6393xb_nand_config = {
702 .num_partitions = ARRAY_SIZE(tosa_nand_partition),
703 .partition = tosa_nand_partition,
704 .badblock_pattern = &tosa_tc6393xb_nand_bbt,
707 static struct tc6393xb_platform_data tosa_tc6393xb_setup = {
708 .scr_pll2cr = 0x0cc1,
711 TOSA_TC6393XB_GPIO_BIT(TOSA_GPIO_CARD_VCC_ON),
713 TOSA_TC6393XB_GPIO_BIT(TOSA_GPIO_CARD_VCC_ON),
715 .irq_base = IRQ_BOARD_START,
716 .gpio_base = TOSA_TC6393XB_GPIO_BASE,
718 .enable = tosa_tc6393xb_enable,
719 .disable = tosa_tc6393xb_disable,
720 .suspend = tosa_tc6393xb_suspend,
721 .resume = tosa_tc6393xb_resume,
723 .nand_data = &tosa_tc6393xb_nand_config,
727 static struct platform_device tc6393xb_device = {
731 .platform_data = &tosa_tc6393xb_setup,
733 .num_resources = ARRAY_SIZE(tc6393xb_resources),
734 .resource = tc6393xb_resources,
737 static struct tosa_bt_data tosa_bt_data = {
738 .gpio_pwr = TOSA_GPIO_BT_PWR_EN,
739 .gpio_reset = TOSA_GPIO_BT_RESET,
742 static struct platform_device tosa_bt_device = {
745 .dev.platform_data = &tosa_bt_data,
749 static struct platform_device *devices[] __initdata = {
751 &tosascoop_jc_device,
755 &tosa_gpio_keys_device,
760 static void tosa_poweroff(void)
762 arm_machine_restart('g');
765 static void tosa_restart(char mode)
767 /* Bootloader magic for a reboot */
768 if((MSC0 & 0xffff0000) == 0x7ff00000)
769 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
774 static void __init tosa_init(void)
778 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
779 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off));
780 gpio_set_wake(MFP_PIN_GPIO1, 1);
781 /* We can't pass to gpio-keys since it will drop the Reset altfunc */
783 init_gpio_reset(TOSA_GPIO_ON_RESET);
785 pm_power_off = tosa_poweroff;
786 arm_pm_restart = tosa_restart;
790 /* enable batt_fault */
793 dummy = gpiochip_reserve(TOSA_SCOOP_GPIO_BASE, 12);
794 dummy = gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE, 12);
795 dummy = gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE, 16);
797 pxa_set_mci_info(&tosa_mci_platform_data);
798 pxa_set_udc_info(&udc_info);
799 pxa_set_ficp_info(&tosa_ficp_platform_data);
800 pxa_set_i2c_info(NULL);
801 platform_scoop_config = &tosa_pcmcia_config;
803 platform_add_devices(devices, ARRAY_SIZE(devices));
806 static void __init fixup_tosa(struct machine_desc *desc,
807 struct tag *tags, char **cmdline, struct meminfo *mi)
809 sharpsl_save_param();
811 mi->bank[0].start = 0xa0000000;
812 mi->bank[0].node = 0;
813 mi->bank[0].size = (64*1024*1024);
816 MACHINE_START(TOSA, "SHARP Tosa")
817 .phys_io = 0x40000000,
818 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
820 .map_io = pxa_map_io,
821 .init_irq = pxa25x_init_irq,
822 .init_machine = tosa_init,