]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-pxa/tosa.c
[ARM] 5081/1: tosa: fix SD GPIOs
[linux-2.6-omap-h63xx.git] / arch / arm / mach-pxa / tosa.c
1 /*
2  *  Support for Sharp SL-C6000x PDAs
3  *  Model: (Tosa)
4  *
5  *  Copyright (c) 2005 Dirk Opfer
6  *
7  *      Based on code written by Sharp/Lineo for 2.4 kernels
8  *
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.
12  *
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/major.h>
19 #include <linux/fs.h>
20 #include <linux/interrupt.h>
21 #include <linux/mmc/host.h>
22 #include <linux/pm.h>
23 #include <linux/delay.h>
24 #include <linux/gpio_keys.h>
25 #include <linux/input.h>
26 #include <linux/gpio.h>
27 #include <linux/reboot.h>
28
29 #include <asm/setup.h>
30 #include <asm/memory.h>
31 #include <asm/mach-types.h>
32 #include <asm/hardware.h>
33 #include <asm/irq.h>
34 #include <asm/system.h>
35 #include <asm/arch/pxa-regs.h>
36 #include <asm/arch/pxa2xx-regs.h>
37 #include <asm/arch/mfp-pxa25x.h>
38 #include <asm/arch/irda.h>
39 #include <asm/arch/i2c.h>
40 #include <asm/arch/mmc.h>
41 #include <asm/arch/udc.h>
42
43 #include <asm/mach/arch.h>
44 #include <asm/mach/map.h>
45 #include <asm/mach/irq.h>
46 #include <asm/arch/tosa.h>
47
48 #include <asm/hardware/scoop.h>
49 #include <asm/mach/sharpsl_param.h>
50
51 #include "generic.h"
52 #include "devices.h"
53
54 static unsigned long tosa_pin_config[] = {
55         GPIO78_nCS_2, /* Scoop */
56         GPIO80_nCS_4, /* tg6393xb */
57         GPIO33_nCS_5, /* Scoop */
58
59         // GPIO76 CARD_VCC_ON1
60
61         GPIO19_GPIO, /* Reset out */
62         GPIO1_RST | WAKEUP_ON_EDGE_FALL,
63
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 */
69         GPIO22_GPIO, /* On */
70
71         GPIO5_GPIO, /* USB_IN */
72         GPIO32_GPIO, /* Pen IRQ */
73
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 */
80
81         GPIO11_3_6MHz,
82         GPIO15_GPIO, /* TC6393XB IRQ */
83         GPIO18_RDY,
84         GPIO27_GPIO, /* LCD Sync */
85
86         /* MMC */
87         GPIO6_MMC_CLK,
88         GPIO8_MMC_CS0,
89         GPIO9_GPIO, /* Detect */
90         GPIO10_GPIO, /* nSD_INT */
91
92         /* CF */
93         GPIO13_GPIO, /* CD_IRQ */
94         GPIO21_GPIO, /* Main Slot IRQ */
95         GPIO36_GPIO, /* Jacket Slot IRQ */
96         GPIO48_nPOE,
97         GPIO49_nPWE,
98         GPIO50_nPIOR,
99         GPIO51_nPIOW,
100         GPIO52_nPCE_1,
101         GPIO53_nPCE_2,
102         GPIO54_nPSKTSEL,
103         GPIO55_nPREG,
104         GPIO56_nPWAIT,
105         GPIO57_nIOIS16,
106
107         /* AC97 */
108         GPIO31_AC97_SYNC,
109         GPIO30_AC97_SDATA_OUT,
110         GPIO28_AC97_BITCLK,
111         GPIO29_AC97_SDATA_IN_0,
112         // GPIO79 nAUD_IRQ
113
114         /* FFUART */
115         GPIO34_FFUART_RXD,
116         GPIO35_FFUART_CTS,
117         GPIO37_FFUART_DSR,
118         GPIO39_FFUART_TXD,
119         GPIO40_FFUART_DTR,
120         GPIO41_FFUART_RTS,
121
122         /* BTUART */
123         GPIO42_BTUART_RXD,
124         GPIO43_BTUART_TXD,
125         GPIO44_BTUART_CTS,
126         GPIO45_BTUART_RTS,
127
128         /* IrDA */
129         GPIO46_STUART_RXD,
130         GPIO47_STUART_TXD,
131
132         /* Keybd */
133         GPIO58_GPIO | MFP_LPM_DRIVE_LOW,
134         GPIO59_GPIO | MFP_LPM_DRIVE_LOW,
135         GPIO60_GPIO | MFP_LPM_DRIVE_LOW,
136         GPIO61_GPIO | MFP_LPM_DRIVE_LOW,
137         GPIO62_GPIO | MFP_LPM_DRIVE_LOW,
138         GPIO63_GPIO | MFP_LPM_DRIVE_LOW,
139         GPIO64_GPIO | MFP_LPM_DRIVE_LOW,
140         GPIO65_GPIO | MFP_LPM_DRIVE_LOW,
141         GPIO66_GPIO | MFP_LPM_DRIVE_LOW,
142         GPIO67_GPIO | MFP_LPM_DRIVE_LOW,
143         GPIO68_GPIO | MFP_LPM_DRIVE_LOW,
144         GPIO69_GPIO | MFP_LPM_DRIVE_LOW,
145         GPIO70_GPIO | MFP_LPM_DRIVE_LOW,
146         GPIO71_GPIO | MFP_LPM_DRIVE_LOW,
147         GPIO72_GPIO | MFP_LPM_DRIVE_LOW,
148         GPIO73_GPIO | MFP_LPM_DRIVE_LOW,
149         GPIO74_GPIO | MFP_LPM_DRIVE_LOW,
150         GPIO75_GPIO | MFP_LPM_DRIVE_LOW,
151
152         /* SPI */
153         GPIO81_SSP2_CLK_OUT,
154         GPIO82_SSP2_FRM_OUT,
155         GPIO83_SSP2_TXD,
156 };
157
158 /*
159  * SCOOP Device
160  */
161 static struct resource tosa_scoop_resources[] = {
162         [0] = {
163                 .start  = TOSA_CF_PHYS,
164                 .end    = TOSA_CF_PHYS + 0xfff,
165                 .flags  = IORESOURCE_MEM,
166         },
167 };
168
169 static struct scoop_config tosa_scoop_setup = {
170         .io_dir         = TOSA_SCOOP_IO_DIR,
171         .gpio_base      = TOSA_SCOOP_GPIO_BASE,
172 };
173
174 static struct platform_device tosascoop_device = {
175         .name           = "sharp-scoop",
176         .id             = 0,
177         .dev            = {
178                 .platform_data  = &tosa_scoop_setup,
179         },
180         .num_resources  = ARRAY_SIZE(tosa_scoop_resources),
181         .resource       = tosa_scoop_resources,
182 };
183
184
185 /*
186  * SCOOP Device Jacket
187  */
188 static struct resource tosa_scoop_jc_resources[] = {
189         [0] = {
190                 .start          = TOSA_SCOOP_PHYS + 0x40,
191                 .end            = TOSA_SCOOP_PHYS + 0xfff,
192                 .flags          = IORESOURCE_MEM,
193         },
194 };
195
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,
199 };
200
201 static struct platform_device tosascoop_jc_device = {
202         .name           = "sharp-scoop",
203         .id             = 1,
204         .dev            = {
205                 .platform_data  = &tosa_scoop_jc_setup,
206                 .parent         = &tosascoop_device.dev,
207         },
208         .num_resources  = ARRAY_SIZE(tosa_scoop_jc_resources),
209         .resource       = tosa_scoop_jc_resources,
210 };
211
212 /*
213  * PCMCIA
214  */
215 static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
216 {
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",
221 },{
222         .dev        = &tosascoop_jc_device.dev,
223         .irq        = TOSA_IRQ_GPIO_JC_CF_IRQ,
224         .cd_irq     = -1,
225 },
226 };
227
228 static struct scoop_pcmcia_config tosa_pcmcia_config = {
229         .devs         = &tosa_pcmcia_scoop[0],
230         .num_devs     = 2,
231 };
232
233 /*
234  * USB Device Controller
235  */
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,
240 };
241
242 /*
243  * MMC/SD Device
244  */
245 static struct pxamci_platform_data tosa_mci_platform_data;
246
247 static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
248 {
249         int err;
250
251         tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
252
253         err = gpio_request(TOSA_GPIO_nSD_DETECT, "MMC/SD card detect");
254         if (err) {
255                 printk(KERN_ERR "tosa_mci_init: can't request nSD_DETECT gpio\n");
256                 goto err_gpio_detect;
257         }
258         err = gpio_direction_input(TOSA_GPIO_nSD_DETECT);
259         if (err)
260                 goto err_gpio_detect_dir;
261
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);
265         if (err) {
266                 printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
267                 goto err_irq;
268         }
269
270         err = gpio_request(TOSA_GPIO_SD_WP, "SD Write Protect");
271         if (err) {
272                 printk(KERN_ERR "tosa_mci_init: can't request SD_WP gpio\n");
273                 goto err_gpio_wp;
274         }
275         err = gpio_direction_input(TOSA_GPIO_SD_WP);
276         if (err)
277                 goto err_gpio_wp_dir;
278
279         err = gpio_request(TOSA_GPIO_PWR_ON, "SD Power");
280         if (err) {
281                 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
282                 goto err_gpio_pwr;
283         }
284         err = gpio_direction_output(TOSA_GPIO_PWR_ON, 0);
285         if (err)
286                 goto err_gpio_pwr_dir;
287
288         err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
289         if (err) {
290                 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
291                 goto err_gpio_int;
292         }
293         err = gpio_direction_input(TOSA_GPIO_nSD_INT);
294         if (err)
295                 goto err_gpio_int_dir;
296
297         return 0;
298
299 err_gpio_int_dir:
300         gpio_free(TOSA_GPIO_nSD_INT);
301 err_gpio_int:
302 err_gpio_pwr_dir:
303         gpio_free(TOSA_GPIO_PWR_ON);
304 err_gpio_pwr:
305 err_gpio_wp_dir:
306         gpio_free(TOSA_GPIO_SD_WP);
307 err_gpio_wp:
308         free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
309 err_irq:
310 err_gpio_detect_dir:
311         gpio_free(TOSA_GPIO_nSD_DETECT);
312 err_gpio_detect:
313         return err;
314 }
315
316 static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
317 {
318         struct pxamci_platform_data* p_d = dev->platform_data;
319
320         if (( 1 << vdd) & p_d->ocr_mask) {
321                 gpio_set_value(TOSA_GPIO_PWR_ON, 1);
322         } else {
323                 gpio_set_value(TOSA_GPIO_PWR_ON, 0);
324         }
325 }
326
327 static int tosa_mci_get_ro(struct device *dev)
328 {
329         return gpio_get_value(TOSA_GPIO_SD_WP);
330 }
331
332 static void tosa_mci_exit(struct device *dev, void *data)
333 {
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);
339 }
340
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,
347 };
348
349 /*
350  * Irda
351  */
352 static int tosa_irda_startup(struct device *dev)
353 {
354         int ret;
355
356         ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
357         if (ret)
358                 return ret;
359
360         ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
361         if (ret)
362                 gpio_free(TOSA_GPIO_IR_POWERDWN);
363
364         return ret;
365         }
366
367 static void tosa_irda_shutdown(struct device *dev)
368 {
369         gpio_free(TOSA_GPIO_IR_POWERDWN);
370 }
371
372 static void tosa_irda_transceiver_mode(struct device *dev, int mode)
373 {
374         gpio_set_value(TOSA_GPIO_IR_POWERDWN, !(mode & IR_OFF));
375 }
376
377 static struct pxaficp_platform_data tosa_ficp_platform_data = {
378         .transceiver_cap  = IR_SIRMODE | IR_OFF,
379         .transceiver_mode = tosa_irda_transceiver_mode,
380         .startup = tosa_irda_startup,
381         .shutdown = tosa_irda_shutdown,
382 };
383
384 /*
385  * Tosa Keyboard
386  */
387 static struct platform_device tosakbd_device = {
388         .name           = "tosa-keyboard",
389         .id             = -1,
390 };
391
392 static struct gpio_keys_button tosa_gpio_keys[] = {
393         /*
394          * Two following keys are directly tied to "ON" button of tosa. Why?
395          * The first one can be used as a wakeup source, the second can't;
396          * also the first one is OR of ac_powered and on_button.
397          */
398         {
399                 .type   = EV_PWR,
400                 .code   = KEY_RESERVED,
401                 .gpio   = TOSA_GPIO_POWERON,
402                 .desc   = "Poweron",
403                 .wakeup = 1,
404                 .active_low = 1,
405         },
406         {
407                 .type   = EV_PWR,
408                 .code   = KEY_SUSPEND,
409                 .gpio   = TOSA_GPIO_ON_KEY,
410                 .desc   = "On key",
411                 /*
412                  * can't be used as wakeup
413                  * .wakeup      = 1,
414                  */
415                 .active_low = 1,
416         },
417         {
418                 .type   = EV_KEY,
419                 .code   = TOSA_KEY_RECORD,
420                 .gpio   = TOSA_GPIO_RECORD_BTN,
421                 .desc   = "Record Button",
422                 .wakeup = 1,
423                 .active_low = 1,
424         },
425         {
426                 .type   = EV_KEY,
427                 .code   = TOSA_KEY_SYNC,
428                 .gpio   = TOSA_GPIO_SYNC,
429                 .desc   = "Sync Button",
430                 .wakeup = 1,
431                 .active_low = 1,
432         },
433 };
434
435 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
436         .buttons        = tosa_gpio_keys,
437         .nbuttons       = ARRAY_SIZE(tosa_gpio_keys),
438 };
439
440 static struct platform_device tosa_gpio_keys_device = {
441         .name   = "gpio-keys",
442         .id     = -1,
443         .dev    = {
444                 .platform_data  = &tosa_gpio_keys_platform_data,
445         },
446 };
447
448 /*
449  * Tosa LEDs
450  */
451 static struct gpio_led tosa_gpio_leds[] = {
452         {
453                 .name                   = "tosa:amber:charge",
454                 .default_trigger        = "main-battery-charging",
455                 .gpio                   = TOSA_GPIO_CHRG_ERR_LED,
456         },
457         {
458                 .name                   = "tosa:green:mail",
459                 .default_trigger        = "nand-disk",
460                 .gpio                   = TOSA_GPIO_NOTE_LED,
461         },
462         {
463                 .name                   = "tosa:dual:wlan",
464                 .default_trigger        = "none",
465                 .gpio                   = TOSA_GPIO_WLAN_LED,
466         },
467         {
468                 .name                   = "tosa:blue:bluetooth",
469                 .default_trigger        = "none",
470                 .gpio                   = TOSA_GPIO_BT_LED,
471         },
472 };
473
474 static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
475         .leds           = tosa_gpio_leds,
476         .num_leds       = ARRAY_SIZE(tosa_gpio_leds),
477 };
478
479 static struct platform_device tosaled_device = {
480         .name   = "leds-gpio",
481         .id     = -1,
482         .dev    = {
483                 .platform_data  = &tosa_gpio_leds_platform_data,
484         },
485 };
486
487 static struct platform_device *devices[] __initdata = {
488         &tosascoop_device,
489         &tosascoop_jc_device,
490         &tosakbd_device,
491         &tosa_gpio_keys_device,
492         &tosaled_device,
493 };
494
495 static void tosa_poweroff(void)
496 {
497         arm_machine_restart('g');
498 }
499
500 static void tosa_restart(char mode)
501 {
502         /* Bootloader magic for a reboot */
503         if((MSC0 & 0xffff0000) == 0x7ff00000)
504                 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
505
506         tosa_poweroff();
507 }
508
509 static void __init tosa_init(void)
510 {
511         pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
512         gpio_set_wake(MFP_PIN_GPIO1, 1);
513         /* We can't pass to gpio-keys since it will drop the Reset altfunc */
514
515         init_gpio_reset(TOSA_GPIO_ON_RESET);
516
517         pm_power_off = tosa_poweroff;
518         arm_pm_restart = tosa_restart;
519
520         PCFR |= PCFR_OPDE;
521
522         /* enable batt_fault */
523         PMCR = 0x01;
524
525         pxa_set_mci_info(&tosa_mci_platform_data);
526         pxa_set_udc_info(&udc_info);
527         pxa_set_ficp_info(&tosa_ficp_platform_data);
528         pxa_set_i2c_info(NULL);
529         platform_scoop_config = &tosa_pcmcia_config;
530
531         platform_add_devices(devices, ARRAY_SIZE(devices));
532 }
533
534 static void __init fixup_tosa(struct machine_desc *desc,
535                 struct tag *tags, char **cmdline, struct meminfo *mi)
536 {
537         sharpsl_save_param();
538         mi->nr_banks=1;
539         mi->bank[0].start = 0xa0000000;
540         mi->bank[0].node = 0;
541         mi->bank[0].size = (64*1024*1024);
542 }
543
544 MACHINE_START(TOSA, "SHARP Tosa")
545         .phys_io        = 0x40000000,
546         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
547         .fixup          = fixup_tosa,
548         .map_io         = pxa_map_io,
549         .init_irq       = pxa25x_init_irq,
550         .init_machine   = tosa_init,
551         .timer          = &pxa_timer,
552 MACHINE_END