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
,
153 /* IrDA is managed in other way */
161 static struct resource tosa_scoop_resources
[] = {
163 .start
= TOSA_CF_PHYS
,
164 .end
= TOSA_CF_PHYS
+ 0xfff,
165 .flags
= IORESOURCE_MEM
,
169 static struct scoop_config tosa_scoop_setup
= {
170 .io_dir
= TOSA_SCOOP_IO_DIR
,
171 .gpio_base
= TOSA_SCOOP_GPIO_BASE
,
174 static struct platform_device tosascoop_device
= {
175 .name
= "sharp-scoop",
178 .platform_data
= &tosa_scoop_setup
,
180 .num_resources
= ARRAY_SIZE(tosa_scoop_resources
),
181 .resource
= tosa_scoop_resources
,
186 * SCOOP Device Jacket
188 static struct resource tosa_scoop_jc_resources
[] = {
190 .start
= TOSA_SCOOP_PHYS
+ 0x40,
191 .end
= TOSA_SCOOP_PHYS
+ 0xfff,
192 .flags
= IORESOURCE_MEM
,
196 static struct scoop_config tosa_scoop_jc_setup
= {
197 .io_dir
= TOSA_SCOOP_JC_IO_DIR
,
198 .gpio_base
= TOSA_SCOOP_JC_GPIO_BASE
,
201 static struct platform_device tosascoop_jc_device
= {
202 .name
= "sharp-scoop",
205 .platform_data
= &tosa_scoop_jc_setup
,
206 .parent
= &tosascoop_device
.dev
,
208 .num_resources
= ARRAY_SIZE(tosa_scoop_jc_resources
),
209 .resource
= tosa_scoop_jc_resources
,
215 static struct scoop_pcmcia_dev tosa_pcmcia_scoop
[] = {
217 .dev
= &tosascoop_device
.dev
,
218 .irq
= TOSA_IRQ_GPIO_CF_IRQ
,
219 .cd_irq
= TOSA_IRQ_GPIO_CF_CD
,
220 .cd_irq_str
= "PCMCIA0 CD",
222 .dev
= &tosascoop_jc_device
.dev
,
223 .irq
= TOSA_IRQ_GPIO_JC_CF_IRQ
,
228 static struct scoop_pcmcia_config tosa_pcmcia_config
= {
229 .devs
= &tosa_pcmcia_scoop
[0],
234 * USB Device Controller
236 static struct pxa2xx_udc_mach_info udc_info __initdata
= {
237 .gpio_pullup
= TOSA_GPIO_USB_PULLUP
,
238 .gpio_vbus
= TOSA_GPIO_USB_IN
,
239 .gpio_vbus_inverted
= 1,
245 static struct pxamci_platform_data tosa_mci_platform_data
;
247 static int tosa_mci_init(struct device
*dev
, irq_handler_t tosa_detect_int
, void *data
)
251 tosa_mci_platform_data
.detect_delay
= msecs_to_jiffies(250);
253 err
= gpio_request(TOSA_GPIO_nSD_DETECT
, "MMC/SD card detect");
255 printk(KERN_ERR
"tosa_mci_init: can't request nSD_DETECT gpio\n");
256 goto err_gpio_detect
;
258 err
= gpio_direction_input(TOSA_GPIO_nSD_DETECT
);
260 goto err_gpio_detect_dir
;
262 err
= request_irq(TOSA_IRQ_GPIO_nSD_DETECT
, tosa_detect_int
,
263 IRQF_DISABLED
| IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
264 "MMC/SD card detect", data
);
266 printk(KERN_ERR
"tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
270 err
= gpio_request(TOSA_GPIO_SD_WP
, "SD Write Protect");
272 printk(KERN_ERR
"tosa_mci_init: can't request SD_WP gpio\n");
275 err
= gpio_direction_input(TOSA_GPIO_SD_WP
);
277 goto err_gpio_wp_dir
;
279 err
= gpio_request(TOSA_GPIO_PWR_ON
, "SD Power");
281 printk(KERN_ERR
"tosa_mci_init: can't request SD_PWR gpio\n");
284 err
= gpio_direction_output(TOSA_GPIO_PWR_ON
, 0);
286 goto err_gpio_pwr_dir
;
288 err
= gpio_request(TOSA_GPIO_nSD_INT
, "SD Int");
290 printk(KERN_ERR
"tosa_mci_init: can't request SD_PWR gpio\n");
293 err
= gpio_direction_input(TOSA_GPIO_nSD_INT
);
295 goto err_gpio_int_dir
;
300 gpio_free(TOSA_GPIO_nSD_INT
);
303 gpio_free(TOSA_GPIO_PWR_ON
);
306 gpio_free(TOSA_GPIO_SD_WP
);
308 free_irq(TOSA_IRQ_GPIO_nSD_DETECT
, data
);
311 gpio_free(TOSA_GPIO_nSD_DETECT
);
316 static void tosa_mci_setpower(struct device
*dev
, unsigned int vdd
)
318 struct pxamci_platform_data
* p_d
= dev
->platform_data
;
320 if (( 1 << vdd
) & p_d
->ocr_mask
) {
321 gpio_set_value(TOSA_GPIO_PWR_ON
, 1);
323 gpio_set_value(TOSA_GPIO_PWR_ON
, 0);
327 static int tosa_mci_get_ro(struct device
*dev
)
329 return gpio_get_value(TOSA_GPIO_SD_WP
);
332 static void tosa_mci_exit(struct device
*dev
, void *data
)
334 gpio_free(TOSA_GPIO_nSD_INT
);
335 gpio_free(TOSA_GPIO_PWR_ON
);
336 gpio_free(TOSA_GPIO_SD_WP
);
337 free_irq(TOSA_IRQ_GPIO_nSD_DETECT
, data
);
338 gpio_free(TOSA_GPIO_nSD_DETECT
);
341 static struct pxamci_platform_data tosa_mci_platform_data
= {
342 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
343 .init
= tosa_mci_init
,
344 .get_ro
= tosa_mci_get_ro
,
345 .setpower
= tosa_mci_setpower
,
346 .exit
= tosa_mci_exit
,
352 static void tosa_irda_transceiver_mode(struct device
*dev
, int mode
)
355 gpio_set_value(TOSA_GPIO_IR_POWERDWN
, 0);
356 pxa2xx_transceiver_mode(dev
, mode
);
357 gpio_direction_output(TOSA_GPIO_IRDA_TX
, 0);
359 pxa2xx_transceiver_mode(dev
, mode
);
360 gpio_set_value(TOSA_GPIO_IR_POWERDWN
, 1);
364 static int tosa_irda_startup(struct device
*dev
)
368 ret
= gpio_request(TOSA_GPIO_IRDA_TX
, "IrDA TX");
371 ret
= gpio_direction_output(TOSA_GPIO_IRDA_TX
, 0);
375 ret
= gpio_request(TOSA_GPIO_IR_POWERDWN
, "IrDA powerdown");
379 ret
= gpio_direction_output(TOSA_GPIO_IR_POWERDWN
, 0);
383 tosa_irda_transceiver_mode(dev
, IR_SIRMODE
| IR_OFF
);
388 gpio_free(TOSA_GPIO_IR_POWERDWN
);
391 gpio_free(TOSA_GPIO_IRDA_TX
);
396 static void tosa_irda_shutdown(struct device
*dev
)
398 tosa_irda_transceiver_mode(dev
, IR_SIRMODE
| IR_OFF
);
399 gpio_free(TOSA_GPIO_IR_POWERDWN
);
400 gpio_free(TOSA_GPIO_IRDA_TX
);
403 static struct pxaficp_platform_data tosa_ficp_platform_data
= {
404 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
405 .transceiver_mode
= tosa_irda_transceiver_mode
,
406 .startup
= tosa_irda_startup
,
407 .shutdown
= tosa_irda_shutdown
,
413 static int tosa_power_init(struct device
*dev
)
415 int ret
= gpio_request(TOSA_GPIO_AC_IN
, "ac in");
419 ret
= gpio_direction_input(TOSA_GPIO_AC_IN
);
426 gpio_free(TOSA_GPIO_AC_IN
);
431 static void tosa_power_exit(struct device
*dev
)
433 gpio_free(TOSA_GPIO_AC_IN
);
436 static int tosa_power_ac_online(void)
438 return gpio_get_value(TOSA_GPIO_AC_IN
) == 0;
441 static char *tosa_ac_supplied_to
[] = {
447 static struct pda_power_pdata tosa_power_data
= {
448 .init
= tosa_power_init
,
449 .is_ac_online
= tosa_power_ac_online
,
450 .exit
= tosa_power_exit
,
451 .supplied_to
= tosa_ac_supplied_to
,
452 .num_supplicants
= ARRAY_SIZE(tosa_ac_supplied_to
),
455 static struct resource tosa_power_resource
[] = {
458 .start
= gpio_to_irq(TOSA_GPIO_AC_IN
),
459 .end
= gpio_to_irq(TOSA_GPIO_AC_IN
),
460 .flags
= IORESOURCE_IRQ
|
461 IORESOURCE_IRQ_HIGHEDGE
|
462 IORESOURCE_IRQ_LOWEDGE
,
466 static struct platform_device tosa_power_device
= {
469 .dev
.platform_data
= &tosa_power_data
,
470 .resource
= tosa_power_resource
,
471 .num_resources
= ARRAY_SIZE(tosa_power_resource
),
477 static struct platform_device tosakbd_device
= {
478 .name
= "tosa-keyboard",
482 static struct gpio_keys_button tosa_gpio_keys
[] = {
484 * Two following keys are directly tied to "ON" button of tosa. Why?
485 * The first one can be used as a wakeup source, the second can't;
486 * also the first one is OR of ac_powered and on_button.
490 .code
= KEY_RESERVED
,
491 .gpio
= TOSA_GPIO_POWERON
,
499 .gpio
= TOSA_GPIO_ON_KEY
,
502 * can't be used as wakeup
509 .code
= TOSA_KEY_RECORD
,
510 .gpio
= TOSA_GPIO_RECORD_BTN
,
511 .desc
= "Record Button",
517 .code
= TOSA_KEY_SYNC
,
518 .gpio
= TOSA_GPIO_SYNC
,
519 .desc
= "Sync Button",
525 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data
= {
526 .buttons
= tosa_gpio_keys
,
527 .nbuttons
= ARRAY_SIZE(tosa_gpio_keys
),
530 static struct platform_device tosa_gpio_keys_device
= {
534 .platform_data
= &tosa_gpio_keys_platform_data
,
541 static struct gpio_led tosa_gpio_leds
[] = {
543 .name
= "tosa:amber:charge",
544 .default_trigger
= "main-battery-charging",
545 .gpio
= TOSA_GPIO_CHRG_ERR_LED
,
548 .name
= "tosa:green:mail",
549 .default_trigger
= "nand-disk",
550 .gpio
= TOSA_GPIO_NOTE_LED
,
553 .name
= "tosa:dual:wlan",
554 .default_trigger
= "none",
555 .gpio
= TOSA_GPIO_WLAN_LED
,
558 .name
= "tosa:blue:bluetooth",
559 .default_trigger
= "tosa-bt",
560 .gpio
= TOSA_GPIO_BT_LED
,
564 static struct gpio_led_platform_data tosa_gpio_leds_platform_data
= {
565 .leds
= tosa_gpio_leds
,
566 .num_leds
= ARRAY_SIZE(tosa_gpio_leds
),
569 static struct platform_device tosaled_device
= {
573 .platform_data
= &tosa_gpio_leds_platform_data
,
578 * Toshiba Mobile IO Controller
580 static struct resource tc6393xb_resources
[] = {
582 .start
= TOSA_LCDC_PHYS
,
583 .end
= TOSA_LCDC_PHYS
+ 0x3ffffff,
584 .flags
= IORESOURCE_MEM
,
588 .start
= TOSA_IRQ_GPIO_TC6393XB_INT
,
589 .end
= TOSA_IRQ_GPIO_TC6393XB_INT
,
590 .flags
= IORESOURCE_IRQ
,
595 static int tosa_tc6393xb_enable(struct platform_device
*dev
)
599 rc
= gpio_request(TOSA_GPIO_TC6393XB_REST_IN
, "tc6393xb #pclr");
602 rc
= gpio_request(TOSA_GPIO_TC6393XB_SUSPEND
, "tc6393xb #suspend");
604 goto err_req_suspend
;
605 rc
= gpio_request(TOSA_GPIO_TC6393XB_L3V_ON
, "l3v");
608 rc
= gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON
, 0);
611 rc
= gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND
, 0);
613 goto err_dir_suspend
;
614 rc
= gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN
, 0);
620 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND
, 1);
624 gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN
, 1);
625 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON
, 1);
631 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON
);
633 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND
);
635 gpio_free(TOSA_GPIO_TC6393XB_REST_IN
);
640 static int tosa_tc6393xb_disable(struct platform_device
*dev
)
642 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON
);
643 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND
);
644 gpio_free(TOSA_GPIO_TC6393XB_REST_IN
);
649 static int tosa_tc6393xb_resume(struct platform_device
*dev
)
651 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND
, 1);
653 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON
, 1);
659 static int tosa_tc6393xb_suspend(struct platform_device
*dev
)
661 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON
, 0);
662 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND
, 0);
666 static struct mtd_partition tosa_nand_partition
[] = {
670 .size
= 7 * 1024 * 1024,
674 .offset
= MTDPART_OFS_APPEND
,
675 .size
= 28 * 1024 * 1024,
679 .offset
= MTDPART_OFS_APPEND
,
680 .size
= MTDPART_SIZ_FULL
,
684 static uint8_t scan_ff_pattern
[] = { 0xff, 0xff };
686 static struct nand_bbt_descr tosa_tc6393xb_nand_bbt
= {
690 .pattern
= scan_ff_pattern
693 static struct tmio_nand_data tosa_tc6393xb_nand_config
= {
694 .num_partitions
= ARRAY_SIZE(tosa_nand_partition
),
695 .partition
= tosa_nand_partition
,
696 .badblock_pattern
= &tosa_tc6393xb_nand_bbt
,
699 static struct tc6393xb_platform_data tosa_tc6393xb_setup
= {
700 .scr_pll2cr
= 0x0cc1,
703 TOSA_TC6393XB_GPIO_BIT(TOSA_GPIO_CARD_VCC_ON
),
705 TOSA_TC6393XB_GPIO_BIT(TOSA_GPIO_CARD_VCC_ON
),
707 .irq_base
= IRQ_BOARD_START
,
708 .gpio_base
= TOSA_TC6393XB_GPIO_BASE
,
710 .enable
= tosa_tc6393xb_enable
,
711 .disable
= tosa_tc6393xb_disable
,
712 .suspend
= tosa_tc6393xb_suspend
,
713 .resume
= tosa_tc6393xb_resume
,
715 .nand_data
= &tosa_tc6393xb_nand_config
,
719 static struct platform_device tc6393xb_device
= {
723 .platform_data
= &tosa_tc6393xb_setup
,
725 .num_resources
= ARRAY_SIZE(tc6393xb_resources
),
726 .resource
= tc6393xb_resources
,
729 static struct tosa_bt_data tosa_bt_data
= {
730 .gpio_pwr
= TOSA_GPIO_BT_PWR_EN
,
731 .gpio_reset
= TOSA_GPIO_BT_RESET
,
734 static struct platform_device tosa_bt_device
= {
737 .dev
.platform_data
= &tosa_bt_data
,
741 static struct platform_device
*devices
[] __initdata
= {
743 &tosascoop_jc_device
,
747 &tosa_gpio_keys_device
,
752 static void tosa_poweroff(void)
754 arm_machine_restart('g');
757 static void tosa_restart(char mode
)
759 /* Bootloader magic for a reboot */
760 if((MSC0
& 0xffff0000) == 0x7ff00000)
761 MSC0
= (MSC0
& 0xffff) | 0x7ee00000;
766 static void __init
tosa_init(void)
770 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config
));
771 gpio_set_wake(MFP_PIN_GPIO1
, 1);
772 /* We can't pass to gpio-keys since it will drop the Reset altfunc */
774 init_gpio_reset(TOSA_GPIO_ON_RESET
);
776 pm_power_off
= tosa_poweroff
;
777 arm_pm_restart
= tosa_restart
;
781 /* enable batt_fault */
784 dummy
= gpiochip_reserve(TOSA_SCOOP_GPIO_BASE
, 12);
785 dummy
= gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE
, 12);
786 dummy
= gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE
, 16);
788 pxa_set_mci_info(&tosa_mci_platform_data
);
789 pxa_set_udc_info(&udc_info
);
790 pxa_set_ficp_info(&tosa_ficp_platform_data
);
791 pxa_set_i2c_info(NULL
);
792 platform_scoop_config
= &tosa_pcmcia_config
;
794 platform_add_devices(devices
, ARRAY_SIZE(devices
));
797 static void __init
fixup_tosa(struct machine_desc
*desc
,
798 struct tag
*tags
, char **cmdline
, struct meminfo
*mi
)
800 sharpsl_save_param();
802 mi
->bank
[0].start
= 0xa0000000;
803 mi
->bank
[0].node
= 0;
804 mi
->bank
[0].size
= (64*1024*1024);
807 MACHINE_START(TOSA
, "SHARP Tosa")
808 .phys_io
= 0x40000000,
809 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
811 .map_io
= pxa_map_io
,
812 .init_irq
= pxa25x_init_irq
,
813 .init_machine
= tosa_init
,