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 <mach/pxa2xx-regs.h>
38 #include <mach/mfp-pxa25x.h>
39 #include <mach/reset.h>
40 #include <mach/irda.h>
44 #include <mach/tosa_bt.h>
46 #include <asm/mach/arch.h>
47 #include <mach/tosa.h>
49 #include <asm/hardware/scoop.h>
50 #include <asm/mach/sharpsl_param.h>
56 static unsigned long tosa_pin_config[] = {
57 GPIO78_nCS_2, /* Scoop */
58 GPIO80_nCS_4, /* tg6393xb */
59 GPIO33_nCS_5, /* Scoop */
61 // GPIO76 CARD_VCC_ON1
63 GPIO19_GPIO, /* Reset out */
64 GPIO1_RST | WAKEUP_ON_EDGE_FALL,
66 GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */
67 GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */
68 GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */
69 GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */
70 GPIO20_GPIO, /* EAR_IN */
73 GPIO5_GPIO, /* USB_IN */
74 GPIO32_GPIO, /* Pen IRQ */
76 GPIO7_GPIO, /* Jacket Detect */
77 GPIO14_GPIO, /* BAT0_CRG */
78 GPIO12_GPIO, /* BAT1_CRG */
79 GPIO17_GPIO, /* BAT0_LOW */
80 GPIO84_GPIO, /* BAT1_LOW */
81 GPIO38_GPIO, /* BAT_LOCK */
84 GPIO15_GPIO, /* TC6393XB IRQ */
86 GPIO27_GPIO, /* LCD Sync */
91 GPIO9_GPIO, /* Detect */
92 GPIO10_GPIO, /* nSD_INT */
95 GPIO13_GPIO, /* CD_IRQ */
96 GPIO21_GPIO, /* Main Slot IRQ */
97 GPIO36_GPIO, /* Jacket Slot IRQ */
111 GPIO30_AC97_SDATA_OUT,
113 GPIO29_AC97_SDATA_IN_0,
131 GPIO58_GPIO | MFP_LPM_DRIVE_LOW,
132 GPIO59_GPIO | MFP_LPM_DRIVE_LOW,
133 GPIO60_GPIO | MFP_LPM_DRIVE_LOW,
134 GPIO61_GPIO | MFP_LPM_DRIVE_LOW,
135 GPIO62_GPIO | MFP_LPM_DRIVE_LOW,
136 GPIO63_GPIO | MFP_LPM_DRIVE_LOW,
137 GPIO64_GPIO | MFP_LPM_DRIVE_LOW,
138 GPIO65_GPIO | MFP_LPM_DRIVE_LOW,
139 GPIO66_GPIO | MFP_LPM_DRIVE_LOW,
140 GPIO67_GPIO | MFP_LPM_DRIVE_LOW,
141 GPIO68_GPIO | MFP_LPM_DRIVE_LOW,
142 GPIO69_GPIO | MFP_LPM_DRIVE_LOW,
143 GPIO70_GPIO | MFP_LPM_DRIVE_LOW,
144 GPIO71_GPIO | MFP_LPM_DRIVE_LOW,
145 GPIO72_GPIO | MFP_LPM_DRIVE_LOW,
146 GPIO73_GPIO | MFP_LPM_DRIVE_LOW,
147 GPIO74_GPIO | MFP_LPM_DRIVE_LOW,
148 GPIO75_GPIO | MFP_LPM_DRIVE_LOW,
155 /* IrDA is managed in other way */
163 static struct resource tosa_scoop_resources[] = {
165 .start = TOSA_CF_PHYS,
166 .end = TOSA_CF_PHYS + 0xfff,
167 .flags = IORESOURCE_MEM,
171 static struct scoop_config tosa_scoop_setup = {
172 .io_dir = TOSA_SCOOP_IO_DIR,
173 .gpio_base = TOSA_SCOOP_GPIO_BASE,
176 static struct platform_device tosascoop_device = {
177 .name = "sharp-scoop",
180 .platform_data = &tosa_scoop_setup,
182 .num_resources = ARRAY_SIZE(tosa_scoop_resources),
183 .resource = tosa_scoop_resources,
188 * SCOOP Device Jacket
190 static struct resource tosa_scoop_jc_resources[] = {
192 .start = TOSA_SCOOP_PHYS + 0x40,
193 .end = TOSA_SCOOP_PHYS + 0xfff,
194 .flags = IORESOURCE_MEM,
198 static struct scoop_config tosa_scoop_jc_setup = {
199 .io_dir = TOSA_SCOOP_JC_IO_DIR,
200 .gpio_base = TOSA_SCOOP_JC_GPIO_BASE,
203 static struct platform_device tosascoop_jc_device = {
204 .name = "sharp-scoop",
207 .platform_data = &tosa_scoop_jc_setup,
208 .parent = &tosascoop_device.dev,
210 .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
211 .resource = tosa_scoop_jc_resources,
217 static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
219 .dev = &tosascoop_device.dev,
220 .irq = TOSA_IRQ_GPIO_CF_IRQ,
221 .cd_irq = TOSA_IRQ_GPIO_CF_CD,
222 .cd_irq_str = "PCMCIA0 CD",
224 .dev = &tosascoop_jc_device.dev,
225 .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
230 static struct scoop_pcmcia_config tosa_pcmcia_config = {
231 .devs = &tosa_pcmcia_scoop[0],
236 * USB Device Controller
238 static struct pxa2xx_udc_mach_info udc_info __initdata = {
239 .gpio_pullup = TOSA_GPIO_USB_PULLUP,
240 .gpio_vbus = TOSA_GPIO_USB_IN,
241 .gpio_vbus_inverted = 1,
247 static struct pxamci_platform_data tosa_mci_platform_data;
249 static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
253 tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
255 err = gpio_request(TOSA_GPIO_nSD_DETECT, "MMC/SD card detect");
257 printk(KERN_ERR "tosa_mci_init: can't request nSD_DETECT gpio\n");
258 goto err_gpio_detect;
260 err = gpio_direction_input(TOSA_GPIO_nSD_DETECT);
262 goto err_gpio_detect_dir;
264 err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int,
265 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
266 "MMC/SD card detect", data);
268 printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
272 err = gpio_request(TOSA_GPIO_SD_WP, "SD Write Protect");
274 printk(KERN_ERR "tosa_mci_init: can't request SD_WP gpio\n");
277 err = gpio_direction_input(TOSA_GPIO_SD_WP);
279 goto err_gpio_wp_dir;
281 err = gpio_request(TOSA_GPIO_PWR_ON, "SD Power");
283 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
286 err = gpio_direction_output(TOSA_GPIO_PWR_ON, 0);
288 goto err_gpio_pwr_dir;
290 err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
292 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
295 err = gpio_direction_input(TOSA_GPIO_nSD_INT);
297 goto err_gpio_int_dir;
302 gpio_free(TOSA_GPIO_nSD_INT);
305 gpio_free(TOSA_GPIO_PWR_ON);
308 gpio_free(TOSA_GPIO_SD_WP);
310 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
313 gpio_free(TOSA_GPIO_nSD_DETECT);
318 static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
320 struct pxamci_platform_data* p_d = dev->platform_data;
322 if (( 1 << vdd) & p_d->ocr_mask) {
323 gpio_set_value(TOSA_GPIO_PWR_ON, 1);
325 gpio_set_value(TOSA_GPIO_PWR_ON, 0);
329 static int tosa_mci_get_ro(struct device *dev)
331 return gpio_get_value(TOSA_GPIO_SD_WP);
334 static void tosa_mci_exit(struct device *dev, void *data)
336 gpio_free(TOSA_GPIO_nSD_INT);
337 gpio_free(TOSA_GPIO_PWR_ON);
338 gpio_free(TOSA_GPIO_SD_WP);
339 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
340 gpio_free(TOSA_GPIO_nSD_DETECT);
343 static struct pxamci_platform_data tosa_mci_platform_data = {
344 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
345 .init = tosa_mci_init,
346 .get_ro = tosa_mci_get_ro,
347 .setpower = tosa_mci_setpower,
348 .exit = tosa_mci_exit,
354 static void tosa_irda_transceiver_mode(struct device *dev, int mode)
357 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
358 pxa2xx_transceiver_mode(dev, mode);
359 gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
361 pxa2xx_transceiver_mode(dev, mode);
362 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
366 static int tosa_irda_startup(struct device *dev)
370 ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
373 ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
377 ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
381 ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
385 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
390 gpio_free(TOSA_GPIO_IR_POWERDWN);
393 gpio_free(TOSA_GPIO_IRDA_TX);
398 static void tosa_irda_shutdown(struct device *dev)
400 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
401 gpio_free(TOSA_GPIO_IR_POWERDWN);
402 gpio_free(TOSA_GPIO_IRDA_TX);
405 static struct pxaficp_platform_data tosa_ficp_platform_data = {
406 .transceiver_cap = IR_SIRMODE | IR_OFF,
407 .transceiver_mode = tosa_irda_transceiver_mode,
408 .startup = tosa_irda_startup,
409 .shutdown = tosa_irda_shutdown,
415 static int tosa_power_init(struct device *dev)
417 int ret = gpio_request(TOSA_GPIO_AC_IN, "ac in");
421 ret = gpio_direction_input(TOSA_GPIO_AC_IN);
428 gpio_free(TOSA_GPIO_AC_IN);
433 static void tosa_power_exit(struct device *dev)
435 gpio_free(TOSA_GPIO_AC_IN);
438 static int tosa_power_ac_online(void)
440 return gpio_get_value(TOSA_GPIO_AC_IN) == 0;
443 static char *tosa_ac_supplied_to[] = {
449 static struct pda_power_pdata tosa_power_data = {
450 .init = tosa_power_init,
451 .is_ac_online = tosa_power_ac_online,
452 .exit = tosa_power_exit,
453 .supplied_to = tosa_ac_supplied_to,
454 .num_supplicants = ARRAY_SIZE(tosa_ac_supplied_to),
457 static struct resource tosa_power_resource[] = {
460 .start = gpio_to_irq(TOSA_GPIO_AC_IN),
461 .end = gpio_to_irq(TOSA_GPIO_AC_IN),
462 .flags = IORESOURCE_IRQ |
463 IORESOURCE_IRQ_HIGHEDGE |
464 IORESOURCE_IRQ_LOWEDGE,
468 static struct platform_device tosa_power_device = {
471 .dev.platform_data = &tosa_power_data,
472 .resource = tosa_power_resource,
473 .num_resources = ARRAY_SIZE(tosa_power_resource),
479 static struct platform_device tosakbd_device = {
480 .name = "tosa-keyboard",
484 static struct gpio_keys_button tosa_gpio_keys[] = {
486 * Two following keys are directly tied to "ON" button of tosa. Why?
487 * The first one can be used as a wakeup source, the second can't;
488 * also the first one is OR of ac_powered and on_button.
492 .code = KEY_RESERVED,
493 .gpio = TOSA_GPIO_POWERON,
501 .gpio = TOSA_GPIO_ON_KEY,
504 * can't be used as wakeup
511 .code = TOSA_KEY_RECORD,
512 .gpio = TOSA_GPIO_RECORD_BTN,
513 .desc = "Record Button",
519 .code = TOSA_KEY_SYNC,
520 .gpio = TOSA_GPIO_SYNC,
521 .desc = "Sync Button",
527 .code = SW_HEADPHONE_INSERT,
528 .gpio = TOSA_GPIO_EAR_IN,
529 .desc = "HeadPhone insert",
531 .debounce_interval = 300,
535 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
536 .buttons = tosa_gpio_keys,
537 .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
540 static struct platform_device tosa_gpio_keys_device = {
544 .platform_data = &tosa_gpio_keys_platform_data,
551 static struct gpio_led tosa_gpio_leds[] = {
553 .name = "tosa:amber:charge",
554 .default_trigger = "main-battery-charging",
555 .gpio = TOSA_GPIO_CHRG_ERR_LED,
558 .name = "tosa:green:mail",
559 .default_trigger = "nand-disk",
560 .gpio = TOSA_GPIO_NOTE_LED,
563 .name = "tosa:dual:wlan",
564 .default_trigger = "none",
565 .gpio = TOSA_GPIO_WLAN_LED,
568 .name = "tosa:blue:bluetooth",
569 .default_trigger = "tosa-bt",
570 .gpio = TOSA_GPIO_BT_LED,
574 static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
575 .leds = tosa_gpio_leds,
576 .num_leds = ARRAY_SIZE(tosa_gpio_leds),
579 static struct platform_device tosaled_device = {
583 .platform_data = &tosa_gpio_leds_platform_data,
588 * Toshiba Mobile IO Controller
590 static struct resource tc6393xb_resources[] = {
592 .start = TOSA_LCDC_PHYS,
593 .end = TOSA_LCDC_PHYS + 0x3ffffff,
594 .flags = IORESOURCE_MEM,
598 .start = TOSA_IRQ_GPIO_TC6393XB_INT,
599 .end = TOSA_IRQ_GPIO_TC6393XB_INT,
600 .flags = IORESOURCE_IRQ,
605 static int tosa_tc6393xb_enable(struct platform_device *dev)
609 rc = gpio_request(TOSA_GPIO_TC6393XB_REST_IN, "tc6393xb #pclr");
612 rc = gpio_request(TOSA_GPIO_TC6393XB_SUSPEND, "tc6393xb #suspend");
614 goto err_req_suspend;
615 rc = gpio_request(TOSA_GPIO_TC6393XB_L3V_ON, "l3v");
618 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON, 0);
621 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND, 0);
623 goto err_dir_suspend;
624 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN, 0);
630 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
634 gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN, 1);
635 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
641 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
643 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
645 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
650 static int tosa_tc6393xb_disable(struct platform_device *dev)
652 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
653 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
654 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
659 static int tosa_tc6393xb_resume(struct platform_device *dev)
661 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
663 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
669 static int tosa_tc6393xb_suspend(struct platform_device *dev)
671 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 0);
672 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 0);
676 static struct mtd_partition tosa_nand_partition[] = {
680 .size = 7 * 1024 * 1024,
684 .offset = MTDPART_OFS_APPEND,
685 .size = 28 * 1024 * 1024,
689 .offset = MTDPART_OFS_APPEND,
690 .size = MTDPART_SIZ_FULL,
694 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
696 static struct nand_bbt_descr tosa_tc6393xb_nand_bbt = {
700 .pattern = scan_ff_pattern
703 static struct tmio_nand_data tosa_tc6393xb_nand_config = {
704 .num_partitions = ARRAY_SIZE(tosa_nand_partition),
705 .partition = tosa_nand_partition,
706 .badblock_pattern = &tosa_tc6393xb_nand_bbt,
709 static int tosa_tc6393xb_setup(struct platform_device *dev)
713 rc = gpio_request(TOSA_GPIO_CARD_VCC_ON, "CARD_VCC_ON");
717 rc = gpio_direction_output(TOSA_GPIO_CARD_VCC_ON, 1);
724 gpio_free(TOSA_GPIO_CARD_VCC_ON);
729 static void tosa_tc6393xb_teardown(struct platform_device *dev)
731 gpio_free(TOSA_GPIO_CARD_VCC_ON);
734 static struct tc6393xb_platform_data tosa_tc6393xb_data = {
735 .scr_pll2cr = 0x0cc1,
738 .irq_base = IRQ_BOARD_START,
739 .gpio_base = TOSA_TC6393XB_GPIO_BASE,
740 .setup = tosa_tc6393xb_setup,
741 .teardown = tosa_tc6393xb_teardown,
743 .enable = tosa_tc6393xb_enable,
744 .disable = tosa_tc6393xb_disable,
745 .suspend = tosa_tc6393xb_suspend,
746 .resume = tosa_tc6393xb_resume,
748 .nand_data = &tosa_tc6393xb_nand_config,
754 static struct platform_device tc6393xb_device = {
758 .platform_data = &tosa_tc6393xb_data,
760 .num_resources = ARRAY_SIZE(tc6393xb_resources),
761 .resource = tc6393xb_resources,
764 static struct tosa_bt_data tosa_bt_data = {
765 .gpio_pwr = TOSA_GPIO_BT_PWR_EN,
766 .gpio_reset = TOSA_GPIO_BT_RESET,
769 static struct platform_device tosa_bt_device = {
772 .dev.platform_data = &tosa_bt_data,
776 static struct platform_device *devices[] __initdata = {
778 &tosascoop_jc_device,
782 &tosa_gpio_keys_device,
787 static void tosa_poweroff(void)
789 arm_machine_restart('g');
792 static void tosa_restart(char mode)
794 /* Bootloader magic for a reboot */
795 if((MSC0 & 0xffff0000) == 0x7ff00000)
796 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
801 static void __init tosa_init(void)
805 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
806 gpio_set_wake(MFP_PIN_GPIO1, 1);
807 /* We can't pass to gpio-keys since it will drop the Reset altfunc */
809 init_gpio_reset(TOSA_GPIO_ON_RESET, 0);
811 pm_power_off = tosa_poweroff;
812 arm_pm_restart = tosa_restart;
816 /* enable batt_fault */
819 dummy = gpiochip_reserve(TOSA_SCOOP_GPIO_BASE, 12);
820 dummy = gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE, 12);
821 dummy = gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE, 16);
823 pxa_set_mci_info(&tosa_mci_platform_data);
824 pxa_set_udc_info(&udc_info);
825 pxa_set_ficp_info(&tosa_ficp_platform_data);
826 pxa_set_i2c_info(NULL);
827 platform_scoop_config = &tosa_pcmcia_config;
829 clk_add_alias("CLK_CK3P6MI", &tc6393xb_device.dev, "GPIO11_CLK", NULL);
831 platform_add_devices(devices, ARRAY_SIZE(devices));
834 static void __init fixup_tosa(struct machine_desc *desc,
835 struct tag *tags, char **cmdline, struct meminfo *mi)
837 sharpsl_save_param();
839 mi->bank[0].start = 0xa0000000;
840 mi->bank[0].node = 0;
841 mi->bank[0].size = (64*1024*1024);
844 MACHINE_START(TOSA, "SHARP Tosa")
845 .phys_io = 0x40000000,
846 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
848 .map_io = pxa_map_io,
849 .init_irq = pxa25x_init_irq,
850 .init_machine = tosa_init,