[ARM] 5083/2: Tosa: fix IrDA transciver powerup.
[deliverable/linux.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
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>
36
37 #include <asm/mach/arch.h>
38 #include <asm/arch/tosa.h>
39
40 #include <asm/hardware/scoop.h>
41 #include <asm/mach/sharpsl_param.h>
42
43 #include "generic.h"
44 #include "devices.h"
45
46 static unsigned long tosa_pin_config[] = {
47 GPIO78_nCS_2, /* Scoop */
48 GPIO80_nCS_4, /* tg6393xb */
49 GPIO33_nCS_5, /* Scoop */
50
51 // GPIO76 CARD_VCC_ON1
52
53 GPIO19_GPIO, /* Reset out */
54 GPIO1_RST | WAKEUP_ON_EDGE_FALL,
55
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 */
61 GPIO22_GPIO, /* On */
62
63 GPIO5_GPIO, /* USB_IN */
64 GPIO32_GPIO, /* Pen IRQ */
65
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 */
72
73 GPIO11_3_6MHz,
74 GPIO15_GPIO, /* TC6393XB IRQ */
75 GPIO18_RDY,
76 GPIO27_GPIO, /* LCD Sync */
77
78 /* MMC */
79 GPIO6_MMC_CLK,
80 GPIO8_MMC_CS0,
81 GPIO9_GPIO, /* Detect */
82 GPIO10_GPIO, /* nSD_INT */
83
84 /* CF */
85 GPIO13_GPIO, /* CD_IRQ */
86 GPIO21_GPIO, /* Main Slot IRQ */
87 GPIO36_GPIO, /* Jacket Slot IRQ */
88 GPIO48_nPOE,
89 GPIO49_nPWE,
90 GPIO50_nPIOR,
91 GPIO51_nPIOW,
92 GPIO52_nPCE_1,
93 GPIO53_nPCE_2,
94 GPIO54_nPSKTSEL,
95 GPIO55_nPREG,
96 GPIO56_nPWAIT,
97 GPIO57_nIOIS16,
98
99 /* AC97 */
100 GPIO31_AC97_SYNC,
101 GPIO30_AC97_SDATA_OUT,
102 GPIO28_AC97_BITCLK,
103 GPIO29_AC97_SDATA_IN_0,
104 // GPIO79 nAUD_IRQ
105
106 /* FFUART */
107 GPIO34_FFUART_RXD,
108 GPIO35_FFUART_CTS,
109 GPIO37_FFUART_DSR,
110 GPIO39_FFUART_TXD,
111 GPIO40_FFUART_DTR,
112 GPIO41_FFUART_RTS,
113
114 /* BTUART */
115 GPIO42_BTUART_RXD,
116 GPIO43_BTUART_TXD,
117 GPIO44_BTUART_CTS,
118 GPIO45_BTUART_RTS,
119
120 /* Keybd */
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,
139
140 /* SPI */
141 GPIO81_SSP2_CLK_OUT,
142 GPIO82_SSP2_FRM_OUT,
143 GPIO83_SSP2_TXD,
144 };
145
146 static unsigned long tosa_pin_irda_off[] = {
147 GPIO46_STUART_RXD,
148 GPIO47_GPIO | MFP_LPM_DRIVE_LOW,
149 };
150
151 static unsigned long tosa_pin_irda_on[] = {
152 GPIO46_STUART_RXD,
153 GPIO47_STUART_TXD,
154 };
155
156
157 /*
158 * SCOOP Device
159 */
160 static struct resource tosa_scoop_resources[] = {
161 [0] = {
162 .start = TOSA_CF_PHYS,
163 .end = TOSA_CF_PHYS + 0xfff,
164 .flags = IORESOURCE_MEM,
165 },
166 };
167
168 static struct scoop_config tosa_scoop_setup = {
169 .io_dir = TOSA_SCOOP_IO_DIR,
170 .gpio_base = TOSA_SCOOP_GPIO_BASE,
171 };
172
173 static struct platform_device tosascoop_device = {
174 .name = "sharp-scoop",
175 .id = 0,
176 .dev = {
177 .platform_data = &tosa_scoop_setup,
178 },
179 .num_resources = ARRAY_SIZE(tosa_scoop_resources),
180 .resource = tosa_scoop_resources,
181 };
182
183
184 /*
185 * SCOOP Device Jacket
186 */
187 static struct resource tosa_scoop_jc_resources[] = {
188 [0] = {
189 .start = TOSA_SCOOP_PHYS + 0x40,
190 .end = TOSA_SCOOP_PHYS + 0xfff,
191 .flags = IORESOURCE_MEM,
192 },
193 };
194
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,
198 };
199
200 static struct platform_device tosascoop_jc_device = {
201 .name = "sharp-scoop",
202 .id = 1,
203 .dev = {
204 .platform_data = &tosa_scoop_jc_setup,
205 .parent = &tosascoop_device.dev,
206 },
207 .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
208 .resource = tosa_scoop_jc_resources,
209 };
210
211 /*
212 * PCMCIA
213 */
214 static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
215 {
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",
220 },{
221 .dev = &tosascoop_jc_device.dev,
222 .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
223 .cd_irq = -1,
224 },
225 };
226
227 static struct scoop_pcmcia_config tosa_pcmcia_config = {
228 .devs = &tosa_pcmcia_scoop[0],
229 .num_devs = 2,
230 };
231
232 /*
233 * USB Device Controller
234 */
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,
239 };
240
241 /*
242 * MMC/SD Device
243 */
244 static struct pxamci_platform_data tosa_mci_platform_data;
245
246 static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
247 {
248 int err;
249
250 tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
251
252 err = gpio_request(TOSA_GPIO_nSD_DETECT, "MMC/SD card detect");
253 if (err) {
254 printk(KERN_ERR "tosa_mci_init: can't request nSD_DETECT gpio\n");
255 goto err_gpio_detect;
256 }
257 err = gpio_direction_input(TOSA_GPIO_nSD_DETECT);
258 if (err)
259 goto err_gpio_detect_dir;
260
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);
264 if (err) {
265 printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
266 goto err_irq;
267 }
268
269 err = gpio_request(TOSA_GPIO_SD_WP, "SD Write Protect");
270 if (err) {
271 printk(KERN_ERR "tosa_mci_init: can't request SD_WP gpio\n");
272 goto err_gpio_wp;
273 }
274 err = gpio_direction_input(TOSA_GPIO_SD_WP);
275 if (err)
276 goto err_gpio_wp_dir;
277
278 err = gpio_request(TOSA_GPIO_PWR_ON, "SD Power");
279 if (err) {
280 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
281 goto err_gpio_pwr;
282 }
283 err = gpio_direction_output(TOSA_GPIO_PWR_ON, 0);
284 if (err)
285 goto err_gpio_pwr_dir;
286
287 err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
288 if (err) {
289 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
290 goto err_gpio_int;
291 }
292 err = gpio_direction_input(TOSA_GPIO_nSD_INT);
293 if (err)
294 goto err_gpio_int_dir;
295
296 return 0;
297
298 err_gpio_int_dir:
299 gpio_free(TOSA_GPIO_nSD_INT);
300 err_gpio_int:
301 err_gpio_pwr_dir:
302 gpio_free(TOSA_GPIO_PWR_ON);
303 err_gpio_pwr:
304 err_gpio_wp_dir:
305 gpio_free(TOSA_GPIO_SD_WP);
306 err_gpio_wp:
307 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
308 err_irq:
309 err_gpio_detect_dir:
310 gpio_free(TOSA_GPIO_nSD_DETECT);
311 err_gpio_detect:
312 return err;
313 }
314
315 static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
316 {
317 struct pxamci_platform_data* p_d = dev->platform_data;
318
319 if (( 1 << vdd) & p_d->ocr_mask) {
320 gpio_set_value(TOSA_GPIO_PWR_ON, 1);
321 } else {
322 gpio_set_value(TOSA_GPIO_PWR_ON, 0);
323 }
324 }
325
326 static int tosa_mci_get_ro(struct device *dev)
327 {
328 return gpio_get_value(TOSA_GPIO_SD_WP);
329 }
330
331 static void tosa_mci_exit(struct device *dev, void *data)
332 {
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);
338 }
339
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,
346 };
347
348 /*
349 * Irda
350 */
351 static void tosa_irda_transceiver_mode(struct device *dev, int mode)
352 {
353 if (mode & IR_OFF) {
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);
357 } else {
358 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_on));
359 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
360 }
361 }
362
363 static int tosa_irda_startup(struct device *dev)
364 {
365 int ret;
366
367 ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
368 if (ret)
369 goto err_tx;
370 ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
371 if (ret)
372 goto err_tx_dir;
373
374 ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
375 if (ret)
376 goto err_pwr;
377
378 ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
379 if (ret)
380 goto err_pwr_dir;
381
382 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
383
384 return 0;
385
386 err_pwr_dir:
387 gpio_free(TOSA_GPIO_IR_POWERDWN);
388 err_pwr:
389 err_tx_dir:
390 gpio_free(TOSA_GPIO_IRDA_TX);
391 err_tx:
392 return ret;
393 }
394
395 static void tosa_irda_shutdown(struct device *dev)
396 {
397 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
398 gpio_free(TOSA_GPIO_IR_POWERDWN);
399 gpio_free(TOSA_GPIO_IRDA_TX);
400 }
401
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,
407 };
408
409 /*
410 * Tosa Keyboard
411 */
412 static struct platform_device tosakbd_device = {
413 .name = "tosa-keyboard",
414 .id = -1,
415 };
416
417 static struct gpio_keys_button tosa_gpio_keys[] = {
418 /*
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.
422 */
423 {
424 .type = EV_PWR,
425 .code = KEY_RESERVED,
426 .gpio = TOSA_GPIO_POWERON,
427 .desc = "Poweron",
428 .wakeup = 1,
429 .active_low = 1,
430 },
431 {
432 .type = EV_PWR,
433 .code = KEY_SUSPEND,
434 .gpio = TOSA_GPIO_ON_KEY,
435 .desc = "On key",
436 /*
437 * can't be used as wakeup
438 * .wakeup = 1,
439 */
440 .active_low = 1,
441 },
442 {
443 .type = EV_KEY,
444 .code = TOSA_KEY_RECORD,
445 .gpio = TOSA_GPIO_RECORD_BTN,
446 .desc = "Record Button",
447 .wakeup = 1,
448 .active_low = 1,
449 },
450 {
451 .type = EV_KEY,
452 .code = TOSA_KEY_SYNC,
453 .gpio = TOSA_GPIO_SYNC,
454 .desc = "Sync Button",
455 .wakeup = 1,
456 .active_low = 1,
457 },
458 };
459
460 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
461 .buttons = tosa_gpio_keys,
462 .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
463 };
464
465 static struct platform_device tosa_gpio_keys_device = {
466 .name = "gpio-keys",
467 .id = -1,
468 .dev = {
469 .platform_data = &tosa_gpio_keys_platform_data,
470 },
471 };
472
473 /*
474 * Tosa LEDs
475 */
476 static struct gpio_led tosa_gpio_leds[] = {
477 {
478 .name = "tosa:amber:charge",
479 .default_trigger = "main-battery-charging",
480 .gpio = TOSA_GPIO_CHRG_ERR_LED,
481 },
482 {
483 .name = "tosa:green:mail",
484 .default_trigger = "nand-disk",
485 .gpio = TOSA_GPIO_NOTE_LED,
486 },
487 {
488 .name = "tosa:dual:wlan",
489 .default_trigger = "none",
490 .gpio = TOSA_GPIO_WLAN_LED,
491 },
492 {
493 .name = "tosa:blue:bluetooth",
494 .default_trigger = "none",
495 .gpio = TOSA_GPIO_BT_LED,
496 },
497 };
498
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),
502 };
503
504 static struct platform_device tosaled_device = {
505 .name = "leds-gpio",
506 .id = -1,
507 .dev = {
508 .platform_data = &tosa_gpio_leds_platform_data,
509 },
510 };
511
512 static struct platform_device *devices[] __initdata = {
513 &tosascoop_device,
514 &tosascoop_jc_device,
515 &tosakbd_device,
516 &tosa_gpio_keys_device,
517 &tosaled_device,
518 };
519
520 static void tosa_poweroff(void)
521 {
522 arm_machine_restart('g');
523 }
524
525 static void tosa_restart(char mode)
526 {
527 /* Bootloader magic for a reboot */
528 if((MSC0 & 0xffff0000) == 0x7ff00000)
529 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
530
531 tosa_poweroff();
532 }
533
534 static void __init tosa_init(void)
535 {
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 */
540
541 init_gpio_reset(TOSA_GPIO_ON_RESET);
542
543 pm_power_off = tosa_poweroff;
544 arm_pm_restart = tosa_restart;
545
546 PCFR |= PCFR_OPDE;
547
548 /* enable batt_fault */
549 PMCR = 0x01;
550
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;
556
557 platform_add_devices(devices, ARRAY_SIZE(devices));
558 }
559
560 static void __init fixup_tosa(struct machine_desc *desc,
561 struct tag *tags, char **cmdline, struct meminfo *mi)
562 {
563 sharpsl_save_param();
564 mi->nr_banks=1;
565 mi->bank[0].start = 0xa0000000;
566 mi->bank[0].node = 0;
567 mi->bank[0].size = (64*1024*1024);
568 }
569
570 MACHINE_START(TOSA, "SHARP Tosa")
571 .phys_io = 0x40000000,
572 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
573 .fixup = fixup_tosa,
574 .map_io = pxa_map_io,
575 .init_irq = pxa25x_init_irq,
576 .init_machine = tosa_init,
577 .timer = &pxa_timer,
578 MACHINE_END
This page took 0.043533 seconds and 5 git commands to generate.