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/mmc/host.h>
23 #include <linux/delay.h>
24 #include <linux/gpio_keys.h>
25 #include <linux/input.h>
26 #include <linux/gpio.h>
28 #include <asm/setup.h>
29 #include <asm/mach-types.h>
30 #include <asm/arch/pxa2xx-regs.h>
31 #include <asm/arch/mfp-pxa25x.h>
32 #include <asm/arch/irda.h>
33 #include <asm/arch/i2c.h>
34 #include <asm/arch/mmc.h>
35 #include <asm/arch/udc.h>
37 #include <asm/mach/arch.h>
38 #include <asm/arch/tosa.h>
40 #include <asm/hardware/scoop.h>
41 #include <asm/mach/sharpsl_param.h>
46 static unsigned long tosa_pin_config
[] = {
47 GPIO78_nCS_2
, /* Scoop */
48 GPIO80_nCS_4
, /* tg6393xb */
49 GPIO33_nCS_5
, /* Scoop */
51 // GPIO76 CARD_VCC_ON1
53 GPIO19_GPIO
, /* Reset out */
54 GPIO1_RST
| WAKEUP_ON_EDGE_FALL
,
56 GPIO0_GPIO
| WAKEUP_ON_EDGE_FALL
, /* WAKE_UP */
57 GPIO2_GPIO
| WAKEUP_ON_EDGE_BOTH
, /* AC_IN */
58 GPIO3_GPIO
| WAKEUP_ON_EDGE_FALL
, /* RECORD */
59 GPIO4_GPIO
| WAKEUP_ON_EDGE_FALL
, /* SYNC */
60 GPIO20_GPIO
, /* EAR_IN */
63 GPIO5_GPIO
, /* USB_IN */
64 GPIO32_GPIO
, /* Pen IRQ */
66 GPIO7_GPIO
, /* Jacket Detect */
67 GPIO14_GPIO
, /* BAT0_CRG */
68 GPIO12_GPIO
, /* BAT1_CRG */
69 GPIO17_GPIO
, /* BAT0_LOW */
70 GPIO84_GPIO
, /* BAT1_LOW */
71 GPIO38_GPIO
, /* BAT_LOCK */
74 GPIO15_GPIO
, /* TC6393XB IRQ */
76 GPIO27_GPIO
, /* LCD Sync */
81 GPIO9_GPIO
, /* Detect */
82 GPIO10_GPIO
, /* nSD_INT */
85 GPIO13_GPIO
, /* CD_IRQ */
86 GPIO21_GPIO
, /* Main Slot IRQ */
87 GPIO36_GPIO
, /* Jacket Slot IRQ */
101 GPIO30_AC97_SDATA_OUT
,
103 GPIO29_AC97_SDATA_IN_0
,
121 GPIO58_GPIO
| MFP_LPM_DRIVE_LOW
,
122 GPIO59_GPIO
| MFP_LPM_DRIVE_LOW
,
123 GPIO60_GPIO
| MFP_LPM_DRIVE_LOW
,
124 GPIO61_GPIO
| MFP_LPM_DRIVE_LOW
,
125 GPIO62_GPIO
| MFP_LPM_DRIVE_LOW
,
126 GPIO63_GPIO
| MFP_LPM_DRIVE_LOW
,
127 GPIO64_GPIO
| MFP_LPM_DRIVE_LOW
,
128 GPIO65_GPIO
| MFP_LPM_DRIVE_LOW
,
129 GPIO66_GPIO
| MFP_LPM_DRIVE_LOW
,
130 GPIO67_GPIO
| MFP_LPM_DRIVE_LOW
,
131 GPIO68_GPIO
| MFP_LPM_DRIVE_LOW
,
132 GPIO69_GPIO
| MFP_LPM_DRIVE_LOW
,
133 GPIO70_GPIO
| MFP_LPM_DRIVE_LOW
,
134 GPIO71_GPIO
| MFP_LPM_DRIVE_LOW
,
135 GPIO72_GPIO
| MFP_LPM_DRIVE_LOW
,
136 GPIO73_GPIO
| MFP_LPM_DRIVE_LOW
,
137 GPIO74_GPIO
| MFP_LPM_DRIVE_LOW
,
138 GPIO75_GPIO
| MFP_LPM_DRIVE_LOW
,
146 static unsigned long tosa_pin_irda_off
[] = {
148 GPIO47_GPIO
| MFP_LPM_DRIVE_LOW
,
151 static unsigned long tosa_pin_irda_on
[] = {
160 static struct resource tosa_scoop_resources
[] = {
162 .start
= TOSA_CF_PHYS
,
163 .end
= TOSA_CF_PHYS
+ 0xfff,
164 .flags
= IORESOURCE_MEM
,
168 static struct scoop_config tosa_scoop_setup
= {
169 .io_dir
= TOSA_SCOOP_IO_DIR
,
170 .gpio_base
= TOSA_SCOOP_GPIO_BASE
,
173 static struct platform_device tosascoop_device
= {
174 .name
= "sharp-scoop",
177 .platform_data
= &tosa_scoop_setup
,
179 .num_resources
= ARRAY_SIZE(tosa_scoop_resources
),
180 .resource
= tosa_scoop_resources
,
185 * SCOOP Device Jacket
187 static struct resource tosa_scoop_jc_resources
[] = {
189 .start
= TOSA_SCOOP_PHYS
+ 0x40,
190 .end
= TOSA_SCOOP_PHYS
+ 0xfff,
191 .flags
= IORESOURCE_MEM
,
195 static struct scoop_config tosa_scoop_jc_setup
= {
196 .io_dir
= TOSA_SCOOP_JC_IO_DIR
,
197 .gpio_base
= TOSA_SCOOP_JC_GPIO_BASE
,
200 static struct platform_device tosascoop_jc_device
= {
201 .name
= "sharp-scoop",
204 .platform_data
= &tosa_scoop_jc_setup
,
205 .parent
= &tosascoop_device
.dev
,
207 .num_resources
= ARRAY_SIZE(tosa_scoop_jc_resources
),
208 .resource
= tosa_scoop_jc_resources
,
214 static struct scoop_pcmcia_dev tosa_pcmcia_scoop
[] = {
216 .dev
= &tosascoop_device
.dev
,
217 .irq
= TOSA_IRQ_GPIO_CF_IRQ
,
218 .cd_irq
= TOSA_IRQ_GPIO_CF_CD
,
219 .cd_irq_str
= "PCMCIA0 CD",
221 .dev
= &tosascoop_jc_device
.dev
,
222 .irq
= TOSA_IRQ_GPIO_JC_CF_IRQ
,
227 static struct scoop_pcmcia_config tosa_pcmcia_config
= {
228 .devs
= &tosa_pcmcia_scoop
[0],
233 * USB Device Controller
235 static struct pxa2xx_udc_mach_info udc_info __initdata
= {
236 .gpio_pullup
= TOSA_GPIO_USB_PULLUP
,
237 .gpio_vbus
= TOSA_GPIO_USB_IN
,
238 .gpio_vbus_inverted
= 1,
244 static struct pxamci_platform_data tosa_mci_platform_data
;
246 static int tosa_mci_init(struct device
*dev
, irq_handler_t tosa_detect_int
, void *data
)
250 tosa_mci_platform_data
.detect_delay
= msecs_to_jiffies(250);
252 err
= gpio_request(TOSA_GPIO_nSD_DETECT
, "MMC/SD card detect");
254 printk(KERN_ERR
"tosa_mci_init: can't request nSD_DETECT gpio\n");
255 goto err_gpio_detect
;
257 err
= gpio_direction_input(TOSA_GPIO_nSD_DETECT
);
259 goto err_gpio_detect_dir
;
261 err
= request_irq(TOSA_IRQ_GPIO_nSD_DETECT
, tosa_detect_int
,
262 IRQF_DISABLED
| IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
263 "MMC/SD card detect", data
);
265 printk(KERN_ERR
"tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
269 err
= gpio_request(TOSA_GPIO_SD_WP
, "SD Write Protect");
271 printk(KERN_ERR
"tosa_mci_init: can't request SD_WP gpio\n");
274 err
= gpio_direction_input(TOSA_GPIO_SD_WP
);
276 goto err_gpio_wp_dir
;
278 err
= gpio_request(TOSA_GPIO_PWR_ON
, "SD Power");
280 printk(KERN_ERR
"tosa_mci_init: can't request SD_PWR gpio\n");
283 err
= gpio_direction_output(TOSA_GPIO_PWR_ON
, 0);
285 goto err_gpio_pwr_dir
;
287 err
= gpio_request(TOSA_GPIO_nSD_INT
, "SD Int");
289 printk(KERN_ERR
"tosa_mci_init: can't request SD_PWR gpio\n");
292 err
= gpio_direction_input(TOSA_GPIO_nSD_INT
);
294 goto err_gpio_int_dir
;
299 gpio_free(TOSA_GPIO_nSD_INT
);
302 gpio_free(TOSA_GPIO_PWR_ON
);
305 gpio_free(TOSA_GPIO_SD_WP
);
307 free_irq(TOSA_IRQ_GPIO_nSD_DETECT
, data
);
310 gpio_free(TOSA_GPIO_nSD_DETECT
);
315 static void tosa_mci_setpower(struct device
*dev
, unsigned int vdd
)
317 struct pxamci_platform_data
* p_d
= dev
->platform_data
;
319 if (( 1 << vdd
) & p_d
->ocr_mask
) {
320 gpio_set_value(TOSA_GPIO_PWR_ON
, 1);
322 gpio_set_value(TOSA_GPIO_PWR_ON
, 0);
326 static int tosa_mci_get_ro(struct device
*dev
)
328 return gpio_get_value(TOSA_GPIO_SD_WP
);
331 static void tosa_mci_exit(struct device
*dev
, void *data
)
333 gpio_free(TOSA_GPIO_nSD_INT
);
334 gpio_free(TOSA_GPIO_PWR_ON
);
335 gpio_free(TOSA_GPIO_SD_WP
);
336 free_irq(TOSA_IRQ_GPIO_nSD_DETECT
, data
);
337 gpio_free(TOSA_GPIO_nSD_DETECT
);
340 static struct pxamci_platform_data tosa_mci_platform_data
= {
341 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
342 .init
= tosa_mci_init
,
343 .get_ro
= tosa_mci_get_ro
,
344 .setpower
= tosa_mci_setpower
,
345 .exit
= tosa_mci_exit
,
351 static void tosa_irda_transceiver_mode(struct device
*dev
, int mode
)
354 gpio_set_value(TOSA_GPIO_IR_POWERDWN
, 0);
355 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off
));
356 gpio_direction_output(TOSA_GPIO_IRDA_TX
, 0);
358 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_on
));
359 gpio_set_value(TOSA_GPIO_IR_POWERDWN
, 1);
363 static int tosa_irda_startup(struct device
*dev
)
367 ret
= gpio_request(TOSA_GPIO_IRDA_TX
, "IrDA TX");
370 ret
= gpio_direction_output(TOSA_GPIO_IRDA_TX
, 0);
374 ret
= gpio_request(TOSA_GPIO_IR_POWERDWN
, "IrDA powerdown");
378 ret
= gpio_direction_output(TOSA_GPIO_IR_POWERDWN
, 0);
382 tosa_irda_transceiver_mode(dev
, IR_SIRMODE
| IR_OFF
);
387 gpio_free(TOSA_GPIO_IR_POWERDWN
);
390 gpio_free(TOSA_GPIO_IRDA_TX
);
395 static void tosa_irda_shutdown(struct device
*dev
)
397 tosa_irda_transceiver_mode(dev
, IR_SIRMODE
| IR_OFF
);
398 gpio_free(TOSA_GPIO_IR_POWERDWN
);
399 gpio_free(TOSA_GPIO_IRDA_TX
);
402 static struct pxaficp_platform_data tosa_ficp_platform_data
= {
403 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
404 .transceiver_mode
= tosa_irda_transceiver_mode
,
405 .startup
= tosa_irda_startup
,
406 .shutdown
= tosa_irda_shutdown
,
412 static struct platform_device tosakbd_device
= {
413 .name
= "tosa-keyboard",
417 static struct gpio_keys_button tosa_gpio_keys
[] = {
419 * Two following keys are directly tied to "ON" button of tosa. Why?
420 * The first one can be used as a wakeup source, the second can't;
421 * also the first one is OR of ac_powered and on_button.
425 .code
= KEY_RESERVED
,
426 .gpio
= TOSA_GPIO_POWERON
,
434 .gpio
= TOSA_GPIO_ON_KEY
,
437 * can't be used as wakeup
444 .code
= TOSA_KEY_RECORD
,
445 .gpio
= TOSA_GPIO_RECORD_BTN
,
446 .desc
= "Record Button",
452 .code
= TOSA_KEY_SYNC
,
453 .gpio
= TOSA_GPIO_SYNC
,
454 .desc
= "Sync Button",
460 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data
= {
461 .buttons
= tosa_gpio_keys
,
462 .nbuttons
= ARRAY_SIZE(tosa_gpio_keys
),
465 static struct platform_device tosa_gpio_keys_device
= {
469 .platform_data
= &tosa_gpio_keys_platform_data
,
476 static struct gpio_led tosa_gpio_leds
[] = {
478 .name
= "tosa:amber:charge",
479 .default_trigger
= "main-battery-charging",
480 .gpio
= TOSA_GPIO_CHRG_ERR_LED
,
483 .name
= "tosa:green:mail",
484 .default_trigger
= "nand-disk",
485 .gpio
= TOSA_GPIO_NOTE_LED
,
488 .name
= "tosa:dual:wlan",
489 .default_trigger
= "none",
490 .gpio
= TOSA_GPIO_WLAN_LED
,
493 .name
= "tosa:blue:bluetooth",
494 .default_trigger
= "none",
495 .gpio
= TOSA_GPIO_BT_LED
,
499 static struct gpio_led_platform_data tosa_gpio_leds_platform_data
= {
500 .leds
= tosa_gpio_leds
,
501 .num_leds
= ARRAY_SIZE(tosa_gpio_leds
),
504 static struct platform_device tosaled_device
= {
508 .platform_data
= &tosa_gpio_leds_platform_data
,
512 static struct platform_device
*devices
[] __initdata
= {
514 &tosascoop_jc_device
,
516 &tosa_gpio_keys_device
,
520 static void tosa_poweroff(void)
522 arm_machine_restart('g');
525 static void tosa_restart(char mode
)
527 /* Bootloader magic for a reboot */
528 if((MSC0
& 0xffff0000) == 0x7ff00000)
529 MSC0
= (MSC0
& 0xffff) | 0x7ee00000;
534 static void __init
tosa_init(void)
536 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config
));
537 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off
));
538 gpio_set_wake(MFP_PIN_GPIO1
, 1);
539 /* We can't pass to gpio-keys since it will drop the Reset altfunc */
541 init_gpio_reset(TOSA_GPIO_ON_RESET
);
543 pm_power_off
= tosa_poweroff
;
544 arm_pm_restart
= tosa_restart
;
548 /* enable batt_fault */
551 pxa_set_mci_info(&tosa_mci_platform_data
);
552 pxa_set_udc_info(&udc_info
);
553 pxa_set_ficp_info(&tosa_ficp_platform_data
);
554 pxa_set_i2c_info(NULL
);
555 platform_scoop_config
= &tosa_pcmcia_config
;
557 platform_add_devices(devices
, ARRAY_SIZE(devices
));
560 static void __init
fixup_tosa(struct machine_desc
*desc
,
561 struct tag
*tags
, char **cmdline
, struct meminfo
*mi
)
563 sharpsl_save_param();
565 mi
->bank
[0].start
= 0xa0000000;
566 mi
->bank
[0].node
= 0;
567 mi
->bank
[0].size
= (64*1024*1024);
570 MACHINE_START(TOSA
, "SHARP Tosa")
571 .phys_io
= 0x40000000,
572 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
574 .map_io
= pxa_map_io
,
575 .init_irq
= pxa25x_init_irq
,
576 .init_machine
= tosa_init
,