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>
26 #include <linux/delay.h>
27 #include <linux/gpio_keys.h>
28 #include <linux/input.h>
29 #include <linux/gpio.h>
30 #include <linux/pda_power.h>
32 #include <asm/setup.h>
33 #include <asm/mach-types.h>
34 #include <asm/arch/pxa2xx-regs.h>
35 #include <asm/arch/mfp-pxa25x.h>
36 #include <asm/arch/irda.h>
37 #include <asm/arch/i2c.h>
38 #include <asm/arch/mmc.h>
39 #include <asm/arch/udc.h>
41 #include <asm/mach/arch.h>
42 #include <asm/arch/tosa.h>
44 #include <asm/hardware/scoop.h>
45 #include <asm/mach/sharpsl_param.h>
50 static unsigned long tosa_pin_config
[] = {
51 GPIO78_nCS_2
, /* Scoop */
52 GPIO80_nCS_4
, /* tg6393xb */
53 GPIO33_nCS_5
, /* Scoop */
55 // GPIO76 CARD_VCC_ON1
57 GPIO19_GPIO
, /* Reset out */
58 GPIO1_RST
| WAKEUP_ON_EDGE_FALL
,
60 GPIO0_GPIO
| WAKEUP_ON_EDGE_FALL
, /* WAKE_UP */
61 GPIO2_GPIO
| WAKEUP_ON_EDGE_BOTH
, /* AC_IN */
62 GPIO3_GPIO
| WAKEUP_ON_EDGE_FALL
, /* RECORD */
63 GPIO4_GPIO
| WAKEUP_ON_EDGE_FALL
, /* SYNC */
64 GPIO20_GPIO
, /* EAR_IN */
67 GPIO5_GPIO
, /* USB_IN */
68 GPIO32_GPIO
, /* Pen IRQ */
70 GPIO7_GPIO
, /* Jacket Detect */
71 GPIO14_GPIO
, /* BAT0_CRG */
72 GPIO12_GPIO
, /* BAT1_CRG */
73 GPIO17_GPIO
, /* BAT0_LOW */
74 GPIO84_GPIO
, /* BAT1_LOW */
75 GPIO38_GPIO
, /* BAT_LOCK */
78 GPIO15_GPIO
, /* TC6393XB IRQ */
80 GPIO27_GPIO
, /* LCD Sync */
85 GPIO9_GPIO
, /* Detect */
86 GPIO10_GPIO
, /* nSD_INT */
89 GPIO13_GPIO
, /* CD_IRQ */
90 GPIO21_GPIO
, /* Main Slot IRQ */
91 GPIO36_GPIO
, /* Jacket Slot IRQ */
105 GPIO30_AC97_SDATA_OUT
,
107 GPIO29_AC97_SDATA_IN_0
,
125 GPIO58_GPIO
| MFP_LPM_DRIVE_LOW
,
126 GPIO59_GPIO
| MFP_LPM_DRIVE_LOW
,
127 GPIO60_GPIO
| MFP_LPM_DRIVE_LOW
,
128 GPIO61_GPIO
| MFP_LPM_DRIVE_LOW
,
129 GPIO62_GPIO
| MFP_LPM_DRIVE_LOW
,
130 GPIO63_GPIO
| MFP_LPM_DRIVE_LOW
,
131 GPIO64_GPIO
| MFP_LPM_DRIVE_LOW
,
132 GPIO65_GPIO
| MFP_LPM_DRIVE_LOW
,
133 GPIO66_GPIO
| MFP_LPM_DRIVE_LOW
,
134 GPIO67_GPIO
| MFP_LPM_DRIVE_LOW
,
135 GPIO68_GPIO
| MFP_LPM_DRIVE_LOW
,
136 GPIO69_GPIO
| MFP_LPM_DRIVE_LOW
,
137 GPIO70_GPIO
| MFP_LPM_DRIVE_LOW
,
138 GPIO71_GPIO
| MFP_LPM_DRIVE_LOW
,
139 GPIO72_GPIO
| MFP_LPM_DRIVE_LOW
,
140 GPIO73_GPIO
| MFP_LPM_DRIVE_LOW
,
141 GPIO74_GPIO
| MFP_LPM_DRIVE_LOW
,
142 GPIO75_GPIO
| MFP_LPM_DRIVE_LOW
,
150 static unsigned long tosa_pin_irda_off
[] = {
152 GPIO47_GPIO
| MFP_LPM_DRIVE_LOW
,
155 static unsigned long tosa_pin_irda_on
[] = {
164 static struct resource tosa_scoop_resources
[] = {
166 .start
= TOSA_CF_PHYS
,
167 .end
= TOSA_CF_PHYS
+ 0xfff,
168 .flags
= IORESOURCE_MEM
,
172 static struct scoop_config tosa_scoop_setup
= {
173 .io_dir
= TOSA_SCOOP_IO_DIR
,
174 .gpio_base
= TOSA_SCOOP_GPIO_BASE
,
177 static struct platform_device tosascoop_device
= {
178 .name
= "sharp-scoop",
181 .platform_data
= &tosa_scoop_setup
,
183 .num_resources
= ARRAY_SIZE(tosa_scoop_resources
),
184 .resource
= tosa_scoop_resources
,
189 * SCOOP Device Jacket
191 static struct resource tosa_scoop_jc_resources
[] = {
193 .start
= TOSA_SCOOP_PHYS
+ 0x40,
194 .end
= TOSA_SCOOP_PHYS
+ 0xfff,
195 .flags
= IORESOURCE_MEM
,
199 static struct scoop_config tosa_scoop_jc_setup
= {
200 .io_dir
= TOSA_SCOOP_JC_IO_DIR
,
201 .gpio_base
= TOSA_SCOOP_JC_GPIO_BASE
,
204 static struct platform_device tosascoop_jc_device
= {
205 .name
= "sharp-scoop",
208 .platform_data
= &tosa_scoop_jc_setup
,
209 .parent
= &tosascoop_device
.dev
,
211 .num_resources
= ARRAY_SIZE(tosa_scoop_jc_resources
),
212 .resource
= tosa_scoop_jc_resources
,
218 static struct scoop_pcmcia_dev tosa_pcmcia_scoop
[] = {
220 .dev
= &tosascoop_device
.dev
,
221 .irq
= TOSA_IRQ_GPIO_CF_IRQ
,
222 .cd_irq
= TOSA_IRQ_GPIO_CF_CD
,
223 .cd_irq_str
= "PCMCIA0 CD",
225 .dev
= &tosascoop_jc_device
.dev
,
226 .irq
= TOSA_IRQ_GPIO_JC_CF_IRQ
,
231 static struct scoop_pcmcia_config tosa_pcmcia_config
= {
232 .devs
= &tosa_pcmcia_scoop
[0],
237 * USB Device Controller
239 static struct pxa2xx_udc_mach_info udc_info __initdata
= {
240 .gpio_pullup
= TOSA_GPIO_USB_PULLUP
,
241 .gpio_vbus
= TOSA_GPIO_USB_IN
,
242 .gpio_vbus_inverted
= 1,
248 static struct pxamci_platform_data tosa_mci_platform_data
;
250 static int tosa_mci_init(struct device
*dev
, irq_handler_t tosa_detect_int
, void *data
)
254 tosa_mci_platform_data
.detect_delay
= msecs_to_jiffies(250);
256 err
= gpio_request(TOSA_GPIO_nSD_DETECT
, "MMC/SD card detect");
258 printk(KERN_ERR
"tosa_mci_init: can't request nSD_DETECT gpio\n");
259 goto err_gpio_detect
;
261 err
= gpio_direction_input(TOSA_GPIO_nSD_DETECT
);
263 goto err_gpio_detect_dir
;
265 err
= request_irq(TOSA_IRQ_GPIO_nSD_DETECT
, tosa_detect_int
,
266 IRQF_DISABLED
| IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
267 "MMC/SD card detect", data
);
269 printk(KERN_ERR
"tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
273 err
= gpio_request(TOSA_GPIO_SD_WP
, "SD Write Protect");
275 printk(KERN_ERR
"tosa_mci_init: can't request SD_WP gpio\n");
278 err
= gpio_direction_input(TOSA_GPIO_SD_WP
);
280 goto err_gpio_wp_dir
;
282 err
= gpio_request(TOSA_GPIO_PWR_ON
, "SD Power");
284 printk(KERN_ERR
"tosa_mci_init: can't request SD_PWR gpio\n");
287 err
= gpio_direction_output(TOSA_GPIO_PWR_ON
, 0);
289 goto err_gpio_pwr_dir
;
291 err
= gpio_request(TOSA_GPIO_nSD_INT
, "SD Int");
293 printk(KERN_ERR
"tosa_mci_init: can't request SD_PWR gpio\n");
296 err
= gpio_direction_input(TOSA_GPIO_nSD_INT
);
298 goto err_gpio_int_dir
;
303 gpio_free(TOSA_GPIO_nSD_INT
);
306 gpio_free(TOSA_GPIO_PWR_ON
);
309 gpio_free(TOSA_GPIO_SD_WP
);
311 free_irq(TOSA_IRQ_GPIO_nSD_DETECT
, data
);
314 gpio_free(TOSA_GPIO_nSD_DETECT
);
319 static void tosa_mci_setpower(struct device
*dev
, unsigned int vdd
)
321 struct pxamci_platform_data
* p_d
= dev
->platform_data
;
323 if (( 1 << vdd
) & p_d
->ocr_mask
) {
324 gpio_set_value(TOSA_GPIO_PWR_ON
, 1);
326 gpio_set_value(TOSA_GPIO_PWR_ON
, 0);
330 static int tosa_mci_get_ro(struct device
*dev
)
332 return gpio_get_value(TOSA_GPIO_SD_WP
);
335 static void tosa_mci_exit(struct device
*dev
, void *data
)
337 gpio_free(TOSA_GPIO_nSD_INT
);
338 gpio_free(TOSA_GPIO_PWR_ON
);
339 gpio_free(TOSA_GPIO_SD_WP
);
340 free_irq(TOSA_IRQ_GPIO_nSD_DETECT
, data
);
341 gpio_free(TOSA_GPIO_nSD_DETECT
);
344 static struct pxamci_platform_data tosa_mci_platform_data
= {
345 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
346 .init
= tosa_mci_init
,
347 .get_ro
= tosa_mci_get_ro
,
348 .setpower
= tosa_mci_setpower
,
349 .exit
= tosa_mci_exit
,
355 static void tosa_irda_transceiver_mode(struct device
*dev
, int mode
)
358 gpio_set_value(TOSA_GPIO_IR_POWERDWN
, 0);
359 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off
));
360 gpio_direction_output(TOSA_GPIO_IRDA_TX
, 0);
362 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_on
));
363 gpio_set_value(TOSA_GPIO_IR_POWERDWN
, 1);
367 static int tosa_irda_startup(struct device
*dev
)
371 ret
= gpio_request(TOSA_GPIO_IRDA_TX
, "IrDA TX");
374 ret
= gpio_direction_output(TOSA_GPIO_IRDA_TX
, 0);
378 ret
= gpio_request(TOSA_GPIO_IR_POWERDWN
, "IrDA powerdown");
382 ret
= gpio_direction_output(TOSA_GPIO_IR_POWERDWN
, 0);
386 tosa_irda_transceiver_mode(dev
, IR_SIRMODE
| IR_OFF
);
391 gpio_free(TOSA_GPIO_IR_POWERDWN
);
394 gpio_free(TOSA_GPIO_IRDA_TX
);
399 static void tosa_irda_shutdown(struct device
*dev
)
401 tosa_irda_transceiver_mode(dev
, IR_SIRMODE
| IR_OFF
);
402 gpio_free(TOSA_GPIO_IR_POWERDWN
);
403 gpio_free(TOSA_GPIO_IRDA_TX
);
406 static struct pxaficp_platform_data tosa_ficp_platform_data
= {
407 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
408 .transceiver_mode
= tosa_irda_transceiver_mode
,
409 .startup
= tosa_irda_startup
,
410 .shutdown
= tosa_irda_shutdown
,
416 static int tosa_power_init(struct device
*dev
)
418 int ret
= gpio_request(TOSA_GPIO_AC_IN
, "ac in");
422 ret
= gpio_direction_input(TOSA_GPIO_AC_IN
);
429 gpio_free(TOSA_GPIO_AC_IN
);
434 static void tosa_power_exit(struct device
*dev
)
436 gpio_free(TOSA_GPIO_AC_IN
);
439 static int tosa_power_ac_online(void)
441 return gpio_get_value(TOSA_GPIO_AC_IN
) == 0;
444 static char *tosa_ac_supplied_to
[] = {
450 static struct pda_power_pdata tosa_power_data
= {
451 .init
= tosa_power_init
,
452 .is_ac_online
= tosa_power_ac_online
,
453 .exit
= tosa_power_exit
,
454 .supplied_to
= tosa_ac_supplied_to
,
455 .num_supplicants
= ARRAY_SIZE(tosa_ac_supplied_to
),
458 static struct resource tosa_power_resource
[] = {
461 .start
= gpio_to_irq(TOSA_GPIO_AC_IN
),
462 .end
= gpio_to_irq(TOSA_GPIO_AC_IN
),
463 .flags
= IORESOURCE_IRQ
|
464 IORESOURCE_IRQ_HIGHEDGE
|
465 IORESOURCE_IRQ_LOWEDGE
,
469 static struct platform_device tosa_power_device
= {
472 .dev
.platform_data
= &tosa_power_data
,
473 .resource
= tosa_power_resource
,
474 .num_resources
= ARRAY_SIZE(tosa_power_resource
),
480 static struct platform_device tosakbd_device
= {
481 .name
= "tosa-keyboard",
485 static struct gpio_keys_button tosa_gpio_keys
[] = {
487 * Two following keys are directly tied to "ON" button of tosa. Why?
488 * The first one can be used as a wakeup source, the second can't;
489 * also the first one is OR of ac_powered and on_button.
493 .code
= KEY_RESERVED
,
494 .gpio
= TOSA_GPIO_POWERON
,
502 .gpio
= TOSA_GPIO_ON_KEY
,
505 * can't be used as wakeup
512 .code
= TOSA_KEY_RECORD
,
513 .gpio
= TOSA_GPIO_RECORD_BTN
,
514 .desc
= "Record Button",
520 .code
= TOSA_KEY_SYNC
,
521 .gpio
= TOSA_GPIO_SYNC
,
522 .desc
= "Sync Button",
528 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data
= {
529 .buttons
= tosa_gpio_keys
,
530 .nbuttons
= ARRAY_SIZE(tosa_gpio_keys
),
533 static struct platform_device tosa_gpio_keys_device
= {
537 .platform_data
= &tosa_gpio_keys_platform_data
,
544 static struct gpio_led tosa_gpio_leds
[] = {
546 .name
= "tosa:amber:charge",
547 .default_trigger
= "main-battery-charging",
548 .gpio
= TOSA_GPIO_CHRG_ERR_LED
,
551 .name
= "tosa:green:mail",
552 .default_trigger
= "nand-disk",
553 .gpio
= TOSA_GPIO_NOTE_LED
,
556 .name
= "tosa:dual:wlan",
557 .default_trigger
= "none",
558 .gpio
= TOSA_GPIO_WLAN_LED
,
561 .name
= "tosa:blue:bluetooth",
562 .default_trigger
= "none",
563 .gpio
= TOSA_GPIO_BT_LED
,
567 static struct gpio_led_platform_data tosa_gpio_leds_platform_data
= {
568 .leds
= tosa_gpio_leds
,
569 .num_leds
= ARRAY_SIZE(tosa_gpio_leds
),
572 static struct platform_device tosaled_device
= {
576 .platform_data
= &tosa_gpio_leds_platform_data
,
581 * Toshiba Mobile IO Controller
583 static struct resource tc6393xb_resources
[] = {
585 .start
= TOSA_LCDC_PHYS
,
586 .end
= TOSA_LCDC_PHYS
+ 0x3ffffff,
587 .flags
= IORESOURCE_MEM
,
591 .start
= TOSA_IRQ_GPIO_TC6393XB_INT
,
592 .end
= TOSA_IRQ_GPIO_TC6393XB_INT
,
593 .flags
= IORESOURCE_IRQ
,
598 static int tosa_tc6393xb_enable(struct platform_device
*dev
)
602 rc
= gpio_request(TOSA_GPIO_TC6393XB_REST_IN
, "tc6393xb #pclr");
605 rc
= gpio_request(TOSA_GPIO_TC6393XB_SUSPEND
, "tc6393xb #suspend");
607 goto err_req_suspend
;
608 rc
= gpio_request(TOSA_GPIO_TC6393XB_L3V_ON
, "l3v");
611 rc
= gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON
, 0);
614 rc
= gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND
, 0);
616 goto err_dir_suspend
;
617 rc
= gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN
, 0);
623 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND
, 1);
627 gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN
, 1);
628 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON
, 1);
634 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON
);
636 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND
);
638 gpio_free(TOSA_GPIO_TC6393XB_REST_IN
);
643 static int tosa_tc6393xb_disable(struct platform_device
*dev
)
645 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON
);
646 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND
);
647 gpio_free(TOSA_GPIO_TC6393XB_REST_IN
);
652 static int tosa_tc6393xb_resume(struct platform_device
*dev
)
654 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND
, 1);
656 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON
, 1);
662 static int tosa_tc6393xb_suspend(struct platform_device
*dev
)
664 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON
, 0);
665 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND
, 0);
669 static struct tc6393xb_platform_data tosa_tc6393xb_setup
= {
670 .scr_pll2cr
= 0x0cc1,
673 TOSA_TC6393XB_GPIO_BIT(TOSA_GPIO_CARD_VCC_ON
),
675 TOSA_TC6393XB_GPIO_BIT(TOSA_GPIO_CARD_VCC_ON
),
677 .irq_base
= IRQ_BOARD_START
,
678 .gpio_base
= TOSA_TC6393XB_GPIO_BASE
,
680 .enable
= tosa_tc6393xb_enable
,
681 .disable
= tosa_tc6393xb_disable
,
682 .suspend
= tosa_tc6393xb_suspend
,
683 .resume
= tosa_tc6393xb_resume
,
687 static struct platform_device tc6393xb_device
= {
691 .platform_data
= &tosa_tc6393xb_setup
,
693 .num_resources
= ARRAY_SIZE(tc6393xb_resources
),
694 .resource
= tc6393xb_resources
,
697 static struct platform_device
*devices
[] __initdata
= {
699 &tosascoop_jc_device
,
703 &tosa_gpio_keys_device
,
707 static void tosa_poweroff(void)
709 arm_machine_restart('g');
712 static void tosa_restart(char mode
)
714 /* Bootloader magic for a reboot */
715 if((MSC0
& 0xffff0000) == 0x7ff00000)
716 MSC0
= (MSC0
& 0xffff) | 0x7ee00000;
721 static void __init
tosa_init(void)
725 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config
));
726 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off
));
727 gpio_set_wake(MFP_PIN_GPIO1
, 1);
728 /* We can't pass to gpio-keys since it will drop the Reset altfunc */
730 init_gpio_reset(TOSA_GPIO_ON_RESET
);
732 pm_power_off
= tosa_poweroff
;
733 arm_pm_restart
= tosa_restart
;
737 /* enable batt_fault */
740 dummy
= gpiochip_reserve(TOSA_SCOOP_GPIO_BASE
, 12);
741 dummy
= gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE
, 12);
742 dummy
= gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE
, 16);
744 pxa_set_mci_info(&tosa_mci_platform_data
);
745 pxa_set_udc_info(&udc_info
);
746 pxa_set_ficp_info(&tosa_ficp_platform_data
);
747 pxa_set_i2c_info(NULL
);
748 platform_scoop_config
= &tosa_pcmcia_config
;
750 platform_add_devices(devices
, ARRAY_SIZE(devices
));
753 static void __init
fixup_tosa(struct machine_desc
*desc
,
754 struct tag
*tags
, char **cmdline
, struct meminfo
*mi
)
756 sharpsl_save_param();
758 mi
->bank
[0].start
= 0xa0000000;
759 mi
->bank
[0].node
= 0;
760 mi
->bank
[0].size
= (64*1024*1024);
763 MACHINE_START(TOSA
, "SHARP Tosa")
764 .phys_io
= 0x40000000,
765 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
767 .map_io
= pxa_map_io
,
768 .init_irq
= pxa25x_init_irq
,
769 .init_machine
= tosa_init
,