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>
34 #include <linux/spi/spi.h>
36 #include <asm/setup.h>
37 #include <asm/mach-types.h>
38 #include <mach/pxa2xx-regs.h>
39 #include <mach/mfp-pxa25x.h>
40 #include <mach/reset.h>
41 #include <mach/irda.h>
45 #include <mach/tosa_bt.h>
46 #include <mach/pxa2xx_spi.h>
48 #include <asm/mach/arch.h>
49 #include <mach/tosa.h>
51 #include <asm/hardware/scoop.h>
52 #include <asm/mach/sharpsl_param.h>
58 static unsigned long tosa_pin_config[] = {
59 GPIO78_nCS_2, /* Scoop */
60 GPIO80_nCS_4, /* tg6393xb */
61 GPIO33_nCS_5, /* Scoop */
63 // GPIO76 CARD_VCC_ON1
65 GPIO19_GPIO, /* Reset out */
66 GPIO1_RST | WAKEUP_ON_EDGE_FALL,
68 GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */
69 GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */
70 GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */
71 GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */
72 GPIO20_GPIO, /* EAR_IN */
75 GPIO5_GPIO, /* USB_IN */
76 GPIO32_GPIO, /* Pen IRQ */
78 GPIO7_GPIO, /* Jacket Detect */
79 GPIO14_GPIO, /* BAT0_CRG */
80 GPIO12_GPIO, /* BAT1_CRG */
81 GPIO17_GPIO, /* BAT0_LOW */
82 GPIO84_GPIO, /* BAT1_LOW */
83 GPIO38_GPIO, /* BAT_LOCK */
86 GPIO15_GPIO, /* TC6393XB IRQ */
88 GPIO27_GPIO, /* LCD Sync */
93 GPIO9_GPIO, /* Detect */
94 GPIO10_GPIO, /* nSD_INT */
97 GPIO13_GPIO, /* CD_IRQ */
98 GPIO21_GPIO, /* Main Slot IRQ */
99 GPIO36_GPIO, /* Jacket Slot IRQ */
113 GPIO30_AC97_SDATA_OUT,
115 GPIO29_AC97_SDATA_IN_0,
133 GPIO58_GPIO | MFP_LPM_DRIVE_LOW,
134 GPIO59_GPIO | MFP_LPM_DRIVE_LOW,
135 GPIO60_GPIO | MFP_LPM_DRIVE_LOW,
136 GPIO61_GPIO | MFP_LPM_DRIVE_LOW,
137 GPIO62_GPIO | MFP_LPM_DRIVE_LOW,
138 GPIO63_GPIO | MFP_LPM_DRIVE_LOW,
139 GPIO64_GPIO | MFP_LPM_DRIVE_LOW,
140 GPIO65_GPIO | MFP_LPM_DRIVE_LOW,
141 GPIO66_GPIO | MFP_LPM_DRIVE_LOW,
142 GPIO67_GPIO | MFP_LPM_DRIVE_LOW,
143 GPIO68_GPIO | MFP_LPM_DRIVE_LOW,
144 GPIO69_GPIO | MFP_LPM_DRIVE_LOW,
145 GPIO70_GPIO | MFP_LPM_DRIVE_LOW,
146 GPIO71_GPIO | MFP_LPM_DRIVE_LOW,
147 GPIO72_GPIO | MFP_LPM_DRIVE_LOW,
148 GPIO73_GPIO | MFP_LPM_DRIVE_LOW,
149 GPIO74_GPIO | MFP_LPM_DRIVE_LOW,
150 GPIO75_GPIO | MFP_LPM_DRIVE_LOW,
157 /* IrDA is managed in other way */
165 static struct resource tosa_scoop_resources[] = {
167 .start = TOSA_CF_PHYS,
168 .end = TOSA_CF_PHYS + 0xfff,
169 .flags = IORESOURCE_MEM,
173 static struct scoop_config tosa_scoop_setup = {
174 .io_dir = TOSA_SCOOP_IO_DIR,
175 .gpio_base = TOSA_SCOOP_GPIO_BASE,
178 static struct platform_device tosascoop_device = {
179 .name = "sharp-scoop",
182 .platform_data = &tosa_scoop_setup,
184 .num_resources = ARRAY_SIZE(tosa_scoop_resources),
185 .resource = tosa_scoop_resources,
190 * SCOOP Device Jacket
192 static struct resource tosa_scoop_jc_resources[] = {
194 .start = TOSA_SCOOP_PHYS + 0x40,
195 .end = TOSA_SCOOP_PHYS + 0xfff,
196 .flags = IORESOURCE_MEM,
200 static struct scoop_config tosa_scoop_jc_setup = {
201 .io_dir = TOSA_SCOOP_JC_IO_DIR,
202 .gpio_base = TOSA_SCOOP_JC_GPIO_BASE,
205 static struct platform_device tosascoop_jc_device = {
206 .name = "sharp-scoop",
209 .platform_data = &tosa_scoop_jc_setup,
210 .parent = &tosascoop_device.dev,
212 .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
213 .resource = tosa_scoop_jc_resources,
219 static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
221 .dev = &tosascoop_device.dev,
222 .irq = TOSA_IRQ_GPIO_CF_IRQ,
223 .cd_irq = TOSA_IRQ_GPIO_CF_CD,
224 .cd_irq_str = "PCMCIA0 CD",
226 .dev = &tosascoop_jc_device.dev,
227 .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
232 static struct scoop_pcmcia_config tosa_pcmcia_config = {
233 .devs = &tosa_pcmcia_scoop[0],
238 * USB Device Controller
240 static struct pxa2xx_udc_mach_info udc_info __initdata = {
241 .gpio_pullup = TOSA_GPIO_USB_PULLUP,
242 .gpio_vbus = TOSA_GPIO_USB_IN,
243 .gpio_vbus_inverted = 1,
249 static struct pxamci_platform_data tosa_mci_platform_data;
251 static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
255 tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
257 err = gpio_request(TOSA_GPIO_nSD_DETECT, "MMC/SD card detect");
259 printk(KERN_ERR "tosa_mci_init: can't request nSD_DETECT gpio\n");
260 goto err_gpio_detect;
262 err = gpio_direction_input(TOSA_GPIO_nSD_DETECT);
264 goto err_gpio_detect_dir;
266 err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int,
267 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
268 "MMC/SD card detect", data);
270 printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
274 err = gpio_request(TOSA_GPIO_SD_WP, "SD Write Protect");
276 printk(KERN_ERR "tosa_mci_init: can't request SD_WP gpio\n");
279 err = gpio_direction_input(TOSA_GPIO_SD_WP);
281 goto err_gpio_wp_dir;
283 err = gpio_request(TOSA_GPIO_PWR_ON, "SD Power");
285 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
288 err = gpio_direction_output(TOSA_GPIO_PWR_ON, 0);
290 goto err_gpio_pwr_dir;
292 err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
294 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
297 err = gpio_direction_input(TOSA_GPIO_nSD_INT);
299 goto err_gpio_int_dir;
304 gpio_free(TOSA_GPIO_nSD_INT);
307 gpio_free(TOSA_GPIO_PWR_ON);
310 gpio_free(TOSA_GPIO_SD_WP);
312 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
315 gpio_free(TOSA_GPIO_nSD_DETECT);
320 static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
322 struct pxamci_platform_data* p_d = dev->platform_data;
324 if (( 1 << vdd) & p_d->ocr_mask) {
325 gpio_set_value(TOSA_GPIO_PWR_ON, 1);
327 gpio_set_value(TOSA_GPIO_PWR_ON, 0);
331 static int tosa_mci_get_ro(struct device *dev)
333 return gpio_get_value(TOSA_GPIO_SD_WP);
336 static void tosa_mci_exit(struct device *dev, void *data)
338 gpio_free(TOSA_GPIO_nSD_INT);
339 gpio_free(TOSA_GPIO_PWR_ON);
340 gpio_free(TOSA_GPIO_SD_WP);
341 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
342 gpio_free(TOSA_GPIO_nSD_DETECT);
345 static struct pxamci_platform_data tosa_mci_platform_data = {
346 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
347 .init = tosa_mci_init,
348 .get_ro = tosa_mci_get_ro,
349 .setpower = tosa_mci_setpower,
350 .exit = tosa_mci_exit,
356 static void tosa_irda_transceiver_mode(struct device *dev, int mode)
359 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
360 pxa2xx_transceiver_mode(dev, mode);
361 gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
363 pxa2xx_transceiver_mode(dev, mode);
364 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
368 static int tosa_irda_startup(struct device *dev)
372 ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
375 ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
379 ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
383 ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
387 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
392 gpio_free(TOSA_GPIO_IR_POWERDWN);
395 gpio_free(TOSA_GPIO_IRDA_TX);
400 static void tosa_irda_shutdown(struct device *dev)
402 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
403 gpio_free(TOSA_GPIO_IR_POWERDWN);
404 gpio_free(TOSA_GPIO_IRDA_TX);
407 static struct pxaficp_platform_data tosa_ficp_platform_data = {
408 .transceiver_cap = IR_SIRMODE | IR_OFF,
409 .transceiver_mode = tosa_irda_transceiver_mode,
410 .startup = tosa_irda_startup,
411 .shutdown = tosa_irda_shutdown,
417 static int tosa_power_init(struct device *dev)
419 int ret = gpio_request(TOSA_GPIO_AC_IN, "ac in");
423 ret = gpio_direction_input(TOSA_GPIO_AC_IN);
430 gpio_free(TOSA_GPIO_AC_IN);
435 static void tosa_power_exit(struct device *dev)
437 gpio_free(TOSA_GPIO_AC_IN);
440 static int tosa_power_ac_online(void)
442 return gpio_get_value(TOSA_GPIO_AC_IN) == 0;
445 static char *tosa_ac_supplied_to[] = {
451 static struct pda_power_pdata tosa_power_data = {
452 .init = tosa_power_init,
453 .is_ac_online = tosa_power_ac_online,
454 .exit = tosa_power_exit,
455 .supplied_to = tosa_ac_supplied_to,
456 .num_supplicants = ARRAY_SIZE(tosa_ac_supplied_to),
459 static struct resource tosa_power_resource[] = {
462 .start = gpio_to_irq(TOSA_GPIO_AC_IN),
463 .end = gpio_to_irq(TOSA_GPIO_AC_IN),
464 .flags = IORESOURCE_IRQ |
465 IORESOURCE_IRQ_HIGHEDGE |
466 IORESOURCE_IRQ_LOWEDGE,
470 static struct platform_device tosa_power_device = {
473 .dev.platform_data = &tosa_power_data,
474 .resource = tosa_power_resource,
475 .num_resources = ARRAY_SIZE(tosa_power_resource),
481 static struct platform_device tosakbd_device = {
482 .name = "tosa-keyboard",
486 static struct gpio_keys_button tosa_gpio_keys[] = {
488 * Two following keys are directly tied to "ON" button of tosa. Why?
489 * The first one can be used as a wakeup source, the second can't;
490 * also the first one is OR of ac_powered and on_button.
494 .code = KEY_RESERVED,
495 .gpio = TOSA_GPIO_POWERON,
503 .gpio = TOSA_GPIO_ON_KEY,
506 * can't be used as wakeup
513 .code = TOSA_KEY_RECORD,
514 .gpio = TOSA_GPIO_RECORD_BTN,
515 .desc = "Record Button",
521 .code = TOSA_KEY_SYNC,
522 .gpio = TOSA_GPIO_SYNC,
523 .desc = "Sync Button",
529 .code = SW_HEADPHONE_INSERT,
530 .gpio = TOSA_GPIO_EAR_IN,
531 .desc = "HeadPhone insert",
533 .debounce_interval = 300,
537 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
538 .buttons = tosa_gpio_keys,
539 .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
542 static struct platform_device tosa_gpio_keys_device = {
546 .platform_data = &tosa_gpio_keys_platform_data,
553 static struct gpio_led tosa_gpio_leds[] = {
555 .name = "tosa:amber:charge",
556 .default_trigger = "main-battery-charging",
557 .gpio = TOSA_GPIO_CHRG_ERR_LED,
560 .name = "tosa:green:mail",
561 .default_trigger = "nand-disk",
562 .gpio = TOSA_GPIO_NOTE_LED,
565 .name = "tosa:dual:wlan",
566 .default_trigger = "none",
567 .gpio = TOSA_GPIO_WLAN_LED,
570 .name = "tosa:blue:bluetooth",
571 .default_trigger = "tosa-bt",
572 .gpio = TOSA_GPIO_BT_LED,
576 static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
577 .leds = tosa_gpio_leds,
578 .num_leds = ARRAY_SIZE(tosa_gpio_leds),
581 static struct platform_device tosaled_device = {
585 .platform_data = &tosa_gpio_leds_platform_data,
590 * Toshiba Mobile IO Controller
592 static struct resource tc6393xb_resources[] = {
594 .start = TOSA_LCDC_PHYS,
595 .end = TOSA_LCDC_PHYS + 0x3ffffff,
596 .flags = IORESOURCE_MEM,
600 .start = TOSA_IRQ_GPIO_TC6393XB_INT,
601 .end = TOSA_IRQ_GPIO_TC6393XB_INT,
602 .flags = IORESOURCE_IRQ,
607 static int tosa_tc6393xb_enable(struct platform_device *dev)
611 rc = gpio_request(TOSA_GPIO_TC6393XB_REST_IN, "tc6393xb #pclr");
614 rc = gpio_request(TOSA_GPIO_TC6393XB_SUSPEND, "tc6393xb #suspend");
616 goto err_req_suspend;
617 rc = gpio_request(TOSA_GPIO_TC6393XB_L3V_ON, "tc6393xb l3v");
620 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON, 0);
623 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND, 0);
625 goto err_dir_suspend;
626 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN, 0);
632 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
636 gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN, 1);
637 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
643 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
645 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
647 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
652 static int tosa_tc6393xb_disable(struct platform_device *dev)
654 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
655 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
656 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
661 static int tosa_tc6393xb_resume(struct platform_device *dev)
663 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
665 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
671 static int tosa_tc6393xb_suspend(struct platform_device *dev)
673 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 0);
674 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 0);
678 static struct mtd_partition tosa_nand_partition[] = {
682 .size = 7 * 1024 * 1024,
686 .offset = MTDPART_OFS_APPEND,
687 .size = 28 * 1024 * 1024,
691 .offset = MTDPART_OFS_APPEND,
692 .size = MTDPART_SIZ_FULL,
696 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
698 static struct nand_bbt_descr tosa_tc6393xb_nand_bbt = {
702 .pattern = scan_ff_pattern
705 static struct tmio_nand_data tosa_tc6393xb_nand_config = {
706 .num_partitions = ARRAY_SIZE(tosa_nand_partition),
707 .partition = tosa_nand_partition,
708 .badblock_pattern = &tosa_tc6393xb_nand_bbt,
711 static int tosa_tc6393xb_setup(struct platform_device *dev)
715 rc = gpio_request(TOSA_GPIO_CARD_VCC_ON, "CARD_VCC_ON");
719 rc = gpio_direction_output(TOSA_GPIO_CARD_VCC_ON, 1);
726 gpio_free(TOSA_GPIO_CARD_VCC_ON);
731 static void tosa_tc6393xb_teardown(struct platform_device *dev)
733 gpio_free(TOSA_GPIO_CARD_VCC_ON);
736 static struct tc6393xb_platform_data tosa_tc6393xb_data = {
737 .scr_pll2cr = 0x0cc1,
740 .irq_base = IRQ_BOARD_START,
741 .gpio_base = TOSA_TC6393XB_GPIO_BASE,
742 .setup = tosa_tc6393xb_setup,
743 .teardown = tosa_tc6393xb_teardown,
745 .enable = tosa_tc6393xb_enable,
746 .disable = tosa_tc6393xb_disable,
747 .suspend = tosa_tc6393xb_suspend,
748 .resume = tosa_tc6393xb_resume,
750 .nand_data = &tosa_tc6393xb_nand_config,
756 static struct platform_device tc6393xb_device = {
760 .platform_data = &tosa_tc6393xb_data,
762 .num_resources = ARRAY_SIZE(tc6393xb_resources),
763 .resource = tc6393xb_resources,
766 static struct tosa_bt_data tosa_bt_data = {
767 .gpio_pwr = TOSA_GPIO_BT_PWR_EN,
768 .gpio_reset = TOSA_GPIO_BT_RESET,
771 static struct platform_device tosa_bt_device = {
774 .dev.platform_data = &tosa_bt_data,
777 static struct pxa2xx_spi_master pxa_ssp_master_info = {
781 static struct spi_board_info spi_board_info[] __initdata = {
783 .modalias = "tosa-lcd",
785 .max_speed_hz = 28750,
792 static struct platform_device *devices[] __initdata = {
794 &tosascoop_jc_device,
798 &tosa_gpio_keys_device,
803 static void tosa_poweroff(void)
805 arm_machine_restart('g');
808 static void tosa_restart(char mode)
810 /* Bootloader magic for a reboot */
811 if((MSC0 & 0xffff0000) == 0x7ff00000)
812 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
817 static void __init tosa_init(void)
821 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
822 gpio_set_wake(MFP_PIN_GPIO1, 1);
823 /* We can't pass to gpio-keys since it will drop the Reset altfunc */
825 init_gpio_reset(TOSA_GPIO_ON_RESET, 0);
827 pm_power_off = tosa_poweroff;
828 arm_pm_restart = tosa_restart;
832 /* enable batt_fault */
835 dummy = gpiochip_reserve(TOSA_SCOOP_GPIO_BASE, 12);
836 dummy = gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE, 12);
837 dummy = gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE, 16);
839 pxa_set_mci_info(&tosa_mci_platform_data);
840 pxa_set_udc_info(&udc_info);
841 pxa_set_ficp_info(&tosa_ficp_platform_data);
842 pxa_set_i2c_info(NULL);
843 platform_scoop_config = &tosa_pcmcia_config;
845 pxa2xx_set_spi_info(2, &pxa_ssp_master_info);
846 spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
848 clk_add_alias("CLK_CK3P6MI", &tc6393xb_device.dev, "GPIO11_CLK", NULL);
850 platform_add_devices(devices, ARRAY_SIZE(devices));
853 static void __init fixup_tosa(struct machine_desc *desc,
854 struct tag *tags, char **cmdline, struct meminfo *mi)
856 sharpsl_save_param();
858 mi->bank[0].start = 0xa0000000;
859 mi->bank[0].node = 0;
860 mi->bank[0].size = (64*1024*1024);
863 MACHINE_START(TOSA, "SHARP Tosa")
864 .phys_io = 0x40000000,
865 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
867 .map_io = pxa_map_io,
868 .init_irq = pxa25x_init_irq,
869 .init_machine = tosa_init,