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>
28 #include <linux/mtd/physmap.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/spi/spi.h>
36 #include <asm/setup.h>
37 #include <asm/mach-types.h>
39 #include <mach/pxa25x.h>
40 #include <mach/reset.h>
41 #include <mach/irda.h>
45 #include <mach/tosa_bt.h>
46 #include <mach/pxa2xx_spi.h>
47 #include <mach/audio.h>
49 #include <asm/mach/arch.h>
50 #include <mach/tosa.h>
52 #include <asm/hardware/scoop.h>
53 #include <asm/mach/sharpsl_param.h>
59 static unsigned long tosa_pin_config[] = {
60 GPIO78_nCS_2, /* Scoop */
61 GPIO80_nCS_4, /* tg6393xb */
62 GPIO33_nCS_5, /* Scoop */
64 // GPIO76 CARD_VCC_ON1
66 GPIO19_GPIO, /* Reset out */
67 GPIO1_RST | WAKEUP_ON_EDGE_FALL,
69 GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */
70 GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */
71 GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */
72 GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */
73 GPIO20_GPIO, /* EAR_IN */
76 GPIO5_GPIO, /* USB_IN */
77 GPIO32_GPIO, /* Pen IRQ */
79 GPIO7_GPIO, /* Jacket Detect */
80 GPIO14_GPIO, /* BAT0_CRG */
81 GPIO12_GPIO, /* BAT1_CRG */
82 GPIO17_GPIO, /* BAT0_LOW */
83 GPIO84_GPIO, /* BAT1_LOW */
84 GPIO38_GPIO, /* BAT_LOCK */
87 GPIO15_GPIO, /* TC6393XB IRQ */
89 GPIO27_GPIO, /* LCD Sync */
94 GPIO9_GPIO, /* Detect */
95 GPIO10_GPIO, /* nSD_INT */
98 GPIO13_GPIO, /* CD_IRQ */
99 GPIO21_GPIO, /* Main Slot IRQ */
100 GPIO36_GPIO, /* Jacket Slot IRQ */
114 GPIO30_AC97_SDATA_OUT,
116 GPIO29_AC97_SDATA_IN_0,
134 GPIO58_GPIO | MFP_LPM_DRIVE_LOW,
135 GPIO59_GPIO | MFP_LPM_DRIVE_LOW,
136 GPIO60_GPIO | MFP_LPM_DRIVE_LOW,
137 GPIO61_GPIO | MFP_LPM_DRIVE_LOW,
138 GPIO62_GPIO | MFP_LPM_DRIVE_LOW,
139 GPIO63_GPIO | MFP_LPM_DRIVE_LOW,
140 GPIO64_GPIO | MFP_LPM_DRIVE_LOW,
141 GPIO65_GPIO | MFP_LPM_DRIVE_LOW,
142 GPIO66_GPIO | MFP_LPM_DRIVE_LOW,
143 GPIO67_GPIO | MFP_LPM_DRIVE_LOW,
144 GPIO68_GPIO | MFP_LPM_DRIVE_LOW,
145 GPIO69_GPIO | MFP_LPM_DRIVE_LOW,
146 GPIO70_GPIO | MFP_LPM_DRIVE_LOW,
147 GPIO71_GPIO | MFP_LPM_DRIVE_LOW,
148 GPIO72_GPIO | MFP_LPM_DRIVE_LOW,
149 GPIO73_GPIO | MFP_LPM_DRIVE_LOW,
150 GPIO74_GPIO | MFP_LPM_DRIVE_LOW,
151 GPIO75_GPIO | MFP_LPM_DRIVE_LOW,
158 /* IrDA is managed in other way */
166 static struct resource tosa_scoop_resources[] = {
168 .start = TOSA_CF_PHYS,
169 .end = TOSA_CF_PHYS + 0xfff,
170 .flags = IORESOURCE_MEM,
174 static struct scoop_config tosa_scoop_setup = {
175 .io_dir = TOSA_SCOOP_IO_DIR,
176 .gpio_base = TOSA_SCOOP_GPIO_BASE,
179 static struct platform_device tosascoop_device = {
180 .name = "sharp-scoop",
183 .platform_data = &tosa_scoop_setup,
185 .num_resources = ARRAY_SIZE(tosa_scoop_resources),
186 .resource = tosa_scoop_resources,
191 * SCOOP Device Jacket
193 static struct resource tosa_scoop_jc_resources[] = {
195 .start = TOSA_SCOOP_PHYS + 0x40,
196 .end = TOSA_SCOOP_PHYS + 0xfff,
197 .flags = IORESOURCE_MEM,
201 static struct scoop_config tosa_scoop_jc_setup = {
202 .io_dir = TOSA_SCOOP_JC_IO_DIR,
203 .gpio_base = TOSA_SCOOP_JC_GPIO_BASE,
206 static struct platform_device tosascoop_jc_device = {
207 .name = "sharp-scoop",
210 .platform_data = &tosa_scoop_jc_setup,
211 .parent = &tosascoop_device.dev,
213 .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
214 .resource = tosa_scoop_jc_resources,
220 static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
222 .dev = &tosascoop_device.dev,
223 .irq = TOSA_IRQ_GPIO_CF_IRQ,
224 .cd_irq = TOSA_IRQ_GPIO_CF_CD,
225 .cd_irq_str = "PCMCIA0 CD",
227 .dev = &tosascoop_jc_device.dev,
228 .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
233 static struct scoop_pcmcia_config tosa_pcmcia_config = {
234 .devs = &tosa_pcmcia_scoop[0],
239 * USB Device Controller
241 static struct pxa2xx_udc_mach_info udc_info __initdata = {
242 .gpio_pullup = TOSA_GPIO_USB_PULLUP,
243 .gpio_vbus = TOSA_GPIO_USB_IN,
244 .gpio_vbus_inverted = 1,
250 static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
254 err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
256 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
259 err = gpio_direction_input(TOSA_GPIO_nSD_INT);
261 goto err_gpio_int_dir;
266 gpio_free(TOSA_GPIO_nSD_INT);
271 static void tosa_mci_exit(struct device *dev, void *data)
273 gpio_free(TOSA_GPIO_nSD_INT);
276 static struct pxamci_platform_data tosa_mci_platform_data = {
277 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
278 .init = tosa_mci_init,
279 .exit = tosa_mci_exit,
280 .gpio_card_detect = TOSA_GPIO_nSD_DETECT,
281 .gpio_card_ro = TOSA_GPIO_SD_WP,
282 .gpio_power = TOSA_GPIO_PWR_ON,
288 static void tosa_irda_transceiver_mode(struct device *dev, int mode)
291 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
292 pxa2xx_transceiver_mode(dev, mode);
293 gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
295 pxa2xx_transceiver_mode(dev, mode);
296 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
300 static int tosa_irda_startup(struct device *dev)
304 ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
307 ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
311 ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
315 ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
319 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
324 gpio_free(TOSA_GPIO_IR_POWERDWN);
327 gpio_free(TOSA_GPIO_IRDA_TX);
332 static void tosa_irda_shutdown(struct device *dev)
334 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
335 gpio_free(TOSA_GPIO_IR_POWERDWN);
336 gpio_free(TOSA_GPIO_IRDA_TX);
339 static struct pxaficp_platform_data tosa_ficp_platform_data = {
340 .transceiver_cap = IR_SIRMODE | IR_OFF,
341 .transceiver_mode = tosa_irda_transceiver_mode,
342 .startup = tosa_irda_startup,
343 .shutdown = tosa_irda_shutdown,
349 static int tosa_power_init(struct device *dev)
351 int ret = gpio_request(TOSA_GPIO_AC_IN, "ac in");
355 ret = gpio_direction_input(TOSA_GPIO_AC_IN);
362 gpio_free(TOSA_GPIO_AC_IN);
367 static void tosa_power_exit(struct device *dev)
369 gpio_free(TOSA_GPIO_AC_IN);
372 static int tosa_power_ac_online(void)
374 return gpio_get_value(TOSA_GPIO_AC_IN) == 0;
377 static char *tosa_ac_supplied_to[] = {
383 static struct pda_power_pdata tosa_power_data = {
384 .init = tosa_power_init,
385 .is_ac_online = tosa_power_ac_online,
386 .exit = tosa_power_exit,
387 .supplied_to = tosa_ac_supplied_to,
388 .num_supplicants = ARRAY_SIZE(tosa_ac_supplied_to),
391 static struct resource tosa_power_resource[] = {
394 .start = gpio_to_irq(TOSA_GPIO_AC_IN),
395 .end = gpio_to_irq(TOSA_GPIO_AC_IN),
396 .flags = IORESOURCE_IRQ |
397 IORESOURCE_IRQ_HIGHEDGE |
398 IORESOURCE_IRQ_LOWEDGE,
402 static struct platform_device tosa_power_device = {
405 .dev.platform_data = &tosa_power_data,
406 .resource = tosa_power_resource,
407 .num_resources = ARRAY_SIZE(tosa_power_resource),
413 static struct platform_device tosakbd_device = {
414 .name = "tosa-keyboard",
418 static struct gpio_keys_button tosa_gpio_keys[] = {
420 * Two following keys are directly tied to "ON" button of tosa. Why?
421 * The first one can be used as a wakeup source, the second can't;
422 * also the first one is OR of ac_powered and on_button.
426 .code = KEY_RESERVED,
427 .gpio = TOSA_GPIO_POWERON,
435 .gpio = TOSA_GPIO_ON_KEY,
438 * can't be used as wakeup
445 .code = TOSA_KEY_RECORD,
446 .gpio = TOSA_GPIO_RECORD_BTN,
447 .desc = "Record Button",
453 .code = TOSA_KEY_SYNC,
454 .gpio = TOSA_GPIO_SYNC,
455 .desc = "Sync Button",
461 .code = SW_HEADPHONE_INSERT,
462 .gpio = TOSA_GPIO_EAR_IN,
463 .desc = "HeadPhone insert",
465 .debounce_interval = 300,
469 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
470 .buttons = tosa_gpio_keys,
471 .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
474 static struct platform_device tosa_gpio_keys_device = {
478 .platform_data = &tosa_gpio_keys_platform_data,
485 static struct gpio_led tosa_gpio_leds[] = {
487 .name = "tosa:amber:charge",
488 .default_trigger = "main-battery-charging",
489 .gpio = TOSA_GPIO_CHRG_ERR_LED,
492 .name = "tosa:green:mail",
493 .default_trigger = "nand-disk",
494 .gpio = TOSA_GPIO_NOTE_LED,
497 .name = "tosa:dual:wlan",
498 .default_trigger = "none",
499 .gpio = TOSA_GPIO_WLAN_LED,
502 .name = "tosa:blue:bluetooth",
503 .default_trigger = "tosa-bt",
504 .gpio = TOSA_GPIO_BT_LED,
508 static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
509 .leds = tosa_gpio_leds,
510 .num_leds = ARRAY_SIZE(tosa_gpio_leds),
513 static struct platform_device tosaled_device = {
517 .platform_data = &tosa_gpio_leds_platform_data,
522 * Toshiba Mobile IO Controller
524 static struct resource tc6393xb_resources[] = {
526 .start = TOSA_LCDC_PHYS,
527 .end = TOSA_LCDC_PHYS + 0x3ffffff,
528 .flags = IORESOURCE_MEM,
532 .start = TOSA_IRQ_GPIO_TC6393XB_INT,
533 .end = TOSA_IRQ_GPIO_TC6393XB_INT,
534 .flags = IORESOURCE_IRQ,
539 static int tosa_tc6393xb_enable(struct platform_device *dev)
543 rc = gpio_request(TOSA_GPIO_TC6393XB_REST_IN, "tc6393xb #pclr");
546 rc = gpio_request(TOSA_GPIO_TC6393XB_SUSPEND, "tc6393xb #suspend");
548 goto err_req_suspend;
549 rc = gpio_request(TOSA_GPIO_TC6393XB_L3V_ON, "tc6393xb l3v");
552 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON, 0);
555 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND, 0);
557 goto err_dir_suspend;
558 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN, 0);
564 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
568 gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN, 1);
569 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
575 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
577 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
579 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
584 static int tosa_tc6393xb_disable(struct platform_device *dev)
586 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
587 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
588 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
593 static int tosa_tc6393xb_resume(struct platform_device *dev)
595 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
597 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
603 static int tosa_tc6393xb_suspend(struct platform_device *dev)
605 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 0);
606 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 0);
610 static struct mtd_partition tosa_nand_partition[] = {
614 .size = 7 * 1024 * 1024,
618 .offset = MTDPART_OFS_APPEND,
619 .size = 28 * 1024 * 1024,
623 .offset = MTDPART_OFS_APPEND,
624 .size = MTDPART_SIZ_FULL,
628 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
630 static struct nand_bbt_descr tosa_tc6393xb_nand_bbt = {
634 .pattern = scan_ff_pattern
637 static struct tmio_nand_data tosa_tc6393xb_nand_config = {
638 .num_partitions = ARRAY_SIZE(tosa_nand_partition),
639 .partition = tosa_nand_partition,
640 .badblock_pattern = &tosa_tc6393xb_nand_bbt,
643 static int tosa_tc6393xb_setup(struct platform_device *dev)
647 rc = gpio_request(TOSA_GPIO_CARD_VCC_ON, "CARD_VCC_ON");
651 rc = gpio_direction_output(TOSA_GPIO_CARD_VCC_ON, 1);
658 gpio_free(TOSA_GPIO_CARD_VCC_ON);
663 static void tosa_tc6393xb_teardown(struct platform_device *dev)
665 gpio_free(TOSA_GPIO_CARD_VCC_ON);
668 #ifdef CONFIG_MFD_TC6393XB
669 static struct fb_videomode tosa_tc6393xb_lcd_mode[] = {
673 .pixclock = 0x002cdf00,/* PLL divisor */
674 .left_margin = 0x004c,
675 .right_margin = 0x005b,
676 .upper_margin = 0x0001,
677 .lower_margin = 0x000d,
680 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
681 .vmode = FB_VMODE_NONINTERLACED,
685 .pixclock = 0x00e7f203,/* PLL divisor */
686 .left_margin = 0x0024,
687 .right_margin = 0x002f,
688 .upper_margin = 0x0001,
689 .lower_margin = 0x000d,
692 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
693 .vmode = FB_VMODE_NONINTERLACED,
697 static struct tmio_fb_data tosa_tc6393xb_fb_config = {
698 .lcd_set_power = tc6393xb_lcd_set_power,
699 .lcd_mode = tc6393xb_lcd_mode,
700 .num_modes = ARRAY_SIZE(tosa_tc6393xb_lcd_mode),
701 .modes = &tosa_tc6393xb_lcd_mode[0],
707 static struct tc6393xb_platform_data tosa_tc6393xb_data = {
708 .scr_pll2cr = 0x0cc1,
711 .irq_base = IRQ_BOARD_START,
712 .gpio_base = TOSA_TC6393XB_GPIO_BASE,
713 .setup = tosa_tc6393xb_setup,
714 .teardown = tosa_tc6393xb_teardown,
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,
722 #ifdef CONFIG_MFD_TC6393XB
723 .fb_data = &tosa_tc6393xb_fb_config,
730 static struct platform_device tc6393xb_device = {
734 .platform_data = &tosa_tc6393xb_data,
736 .num_resources = ARRAY_SIZE(tc6393xb_resources),
737 .resource = tc6393xb_resources,
740 static struct tosa_bt_data tosa_bt_data = {
741 .gpio_pwr = TOSA_GPIO_BT_PWR_EN,
742 .gpio_reset = TOSA_GPIO_BT_RESET,
745 static struct platform_device tosa_bt_device = {
748 .dev.platform_data = &tosa_bt_data,
751 static struct pxa2xx_spi_master pxa_ssp_master_info = {
755 static struct spi_board_info spi_board_info[] __initdata = {
757 .modalias = "tosa-lcd",
759 .max_speed_hz = 28750,
766 static struct mtd_partition sharpsl_rom_parts[] = {
768 .name ="Boot PROM Filesystem",
769 .offset = 0x00160000,
770 .size = MTDPART_SIZ_FULL,
774 static struct physmap_flash_data sharpsl_rom_data = {
776 .nr_parts = ARRAY_SIZE(sharpsl_rom_parts),
777 .parts = sharpsl_rom_parts,
780 static struct resource sharpsl_rom_resources[] = {
784 .flags = IORESOURCE_MEM,
788 static struct platform_device sharpsl_rom_device = {
789 .name = "physmap-flash",
791 .resource = sharpsl_rom_resources,
792 .num_resources = ARRAY_SIZE(sharpsl_rom_resources),
793 .dev.platform_data = &sharpsl_rom_data,
796 static struct platform_device *devices[] __initdata = {
798 &tosascoop_jc_device,
802 &tosa_gpio_keys_device,
808 static void tosa_poweroff(void)
810 arm_machine_restart('g', NULL);
813 static void tosa_restart(char mode, const char *cmd)
815 /* Bootloader magic for a reboot */
816 if((MSC0 & 0xffff0000) == 0x7ff00000)
817 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
822 static void __init tosa_init(void)
826 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
827 gpio_set_wake(MFP_PIN_GPIO1, 1);
828 /* We can't pass to gpio-keys since it will drop the Reset altfunc */
830 init_gpio_reset(TOSA_GPIO_ON_RESET, 0, 0);
832 pm_power_off = tosa_poweroff;
833 arm_pm_restart = tosa_restart;
837 /* enable batt_fault */
840 dummy = gpiochip_reserve(TOSA_SCOOP_GPIO_BASE, 12);
841 dummy = gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE, 12);
842 dummy = gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE, 16);
844 tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
845 pxa_set_mci_info(&tosa_mci_platform_data);
846 pxa_set_udc_info(&udc_info);
847 pxa_set_ficp_info(&tosa_ficp_platform_data);
848 pxa_set_i2c_info(NULL);
849 pxa_set_ac97_info(NULL);
850 platform_scoop_config = &tosa_pcmcia_config;
852 pxa2xx_set_spi_info(2, &pxa_ssp_master_info);
853 spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
855 clk_add_alias("CLK_CK3P6MI", tc6393xb_device.name, "GPIO11_CLK", NULL);
857 platform_add_devices(devices, ARRAY_SIZE(devices));
860 static void __init fixup_tosa(struct machine_desc *desc,
861 struct tag *tags, char **cmdline, struct meminfo *mi)
863 sharpsl_save_param();
865 mi->bank[0].start = 0xa0000000;
866 mi->bank[0].node = 0;
867 mi->bank[0].size = (64*1024*1024);
870 MACHINE_START(TOSA, "SHARP Tosa")
871 .phys_io = 0x40000000,
872 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
874 .map_io = pxa_map_io,
875 .init_irq = pxa25x_init_irq,
876 .init_machine = tosa_init,