[ARM] pxa/corgi: convert to use new MFP API
[linux-2.6.git] / arch / arm / mach-pxa / corgi.c
1 /*
2  * Support for Sharp SL-C7xx PDAs
3  * Models: SL-C700 (Corgi), SL-C750 (Shepherd), SL-C760 (Husky)
4  *
5  * Copyright (c) 2004-2005 Richard Purdie
6  *
7  * Based on Sharp's 2.4 kernel patches/lubbock.c
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/gpio.h>
24 #include <linux/backlight.h>
25 #include <video/w100fb.h>
26
27 #include <asm/setup.h>
28 #include <asm/memory.h>
29 #include <asm/mach-types.h>
30 #include <mach/hardware.h>
31 #include <asm/irq.h>
32 #include <asm/io.h>
33 #include <asm/system.h>
34
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
37 #include <asm/mach/irq.h>
38
39 #include <mach/pxa-regs.h>
40 #include <mach/pxa2xx-regs.h>
41 #include <mach/mfp-pxa25x.h>
42 #include <mach/i2c.h>
43 #include <mach/irda.h>
44 #include <mach/mmc.h>
45 #include <mach/udc.h>
46 #include <mach/corgi.h>
47 #include <mach/sharpsl.h>
48
49 #include <asm/mach/sharpsl_param.h>
50 #include <asm/hardware/scoop.h>
51
52 #include "generic.h"
53 #include "devices.h"
54 #include "sharpsl.h"
55
56 static unsigned long corgi_pin_config[] __initdata = {
57         /* Static Memory I/O */
58         GPIO78_nCS_2,   /* w100fb */
59         GPIO80_nCS_4,   /* scoop */
60
61         /* SSP1 */
62         GPIO23_SSP1_SCLK,
63         GPIO25_SSP1_TXD,
64         GPIO26_SSP1_RXD,
65         GPIO24_GPIO,    /* CORGI_GPIO_ADS7846_CS - SFRM as chip select */
66
67         /* I2S */
68         GPIO28_I2S_BITCLK_OUT,
69         GPIO29_I2S_SDATA_IN,
70         GPIO30_I2S_SDATA_OUT,
71         GPIO31_I2S_SYNC,
72         GPIO32_I2S_SYSCLK,
73
74         /* Infra-Red */
75         GPIO47_FICP_TXD,
76         GPIO46_FICP_RXD,
77
78         /* FFUART */
79         GPIO40_FFUART_DTR,
80         GPIO41_FFUART_RTS,
81         GPIO39_FFUART_TXD,
82         GPIO37_FFUART_DSR,
83         GPIO34_FFUART_RXD,
84         GPIO35_FFUART_CTS,
85
86         /* PC Card */
87         GPIO48_nPOE,
88         GPIO49_nPWE,
89         GPIO50_nPIOR,
90         GPIO51_nPIOW,
91         GPIO52_nPCE_1,
92         GPIO53_nPCE_2,
93         GPIO54_nPSKTSEL,
94         GPIO55_nPREG,
95         GPIO56_nPWAIT,
96         GPIO57_nIOIS16,
97
98         /* MMC */
99         GPIO6_MMC_CLK,
100         GPIO8_MMC_CS0,
101
102         /* GPIO */
103         GPIO9_GPIO,     /* CORGI_GPIO_nSD_DETECT */
104         GPIO7_GPIO,     /* CORGI_GPIO_nSD_WP */
105         GPIO33_GPIO,    /* CORGI_GPIO_SD_PWR */
106         GPIO22_GPIO,    /* CORGI_GPIO_IR_ON */
107         GPIO44_GPIO,    /* CORGI_GPIO_HSYNC */
108
109         GPIO1_GPIO | WAKEUP_ON_EDGE_RISE,
110 };
111
112 /*
113  * Corgi SCOOP Device
114  */
115 static struct resource corgi_scoop_resources[] = {
116         [0] = {
117                 .start          = 0x10800000,
118                 .end            = 0x10800fff,
119                 .flags          = IORESOURCE_MEM,
120         },
121 };
122
123 static struct scoop_config corgi_scoop_setup = {
124         .io_dir         = CORGI_SCOOP_IO_DIR,
125         .io_out         = CORGI_SCOOP_IO_OUT,
126 };
127
128 struct platform_device corgiscoop_device = {
129         .name           = "sharp-scoop",
130         .id             = -1,
131         .dev            = {
132                 .platform_data  = &corgi_scoop_setup,
133         },
134         .num_resources  = ARRAY_SIZE(corgi_scoop_resources),
135         .resource       = corgi_scoop_resources,
136 };
137
138 static struct scoop_pcmcia_dev corgi_pcmcia_scoop[] = {
139 {
140         .dev        = &corgiscoop_device.dev,
141         .irq        = CORGI_IRQ_GPIO_CF_IRQ,
142         .cd_irq     = CORGI_IRQ_GPIO_CF_CD,
143         .cd_irq_str = "PCMCIA0 CD",
144 },
145 };
146
147 static struct scoop_pcmcia_config corgi_pcmcia_config = {
148         .devs         = &corgi_pcmcia_scoop[0],
149         .num_devs     = 1,
150 };
151
152 EXPORT_SYMBOL(corgiscoop_device);
153
154
155 /*
156  * Corgi SSP Device
157  *
158  * Set the parent as the scoop device because a lot of SSP devices
159  * also use scoop functions and this makes the power up/down order
160  * work correctly.
161  */
162 struct platform_device corgissp_device = {
163         .name           = "corgi-ssp",
164         .dev            = {
165                 .parent = &corgiscoop_device.dev,
166         },
167         .id             = -1,
168 };
169
170 struct corgissp_machinfo corgi_ssp_machinfo = {
171         .port           = 1,
172         .cs_lcdcon      = CORGI_GPIO_LCDCON_CS,
173         .cs_ads7846     = CORGI_GPIO_ADS7846_CS,
174         .cs_max1111     = CORGI_GPIO_MAX1111_CS,
175         .clk_lcdcon     = 76,
176         .clk_ads7846    = 2,
177         .clk_max1111    = 8,
178 };
179
180
181 /*
182  * LCD/Framebuffer
183  */
184 static void w100_lcdtg_suspend(struct w100fb_par *par)
185 {
186         corgi_lcdtg_suspend();
187 }
188
189 static void w100_lcdtg_init(struct w100fb_par *par)
190 {
191         corgi_lcdtg_hw_init(par->xres);
192 }
193
194
195 static struct w100_tg_info corgi_lcdtg_info = {
196         .change  = w100_lcdtg_init,
197         .suspend = w100_lcdtg_suspend,
198         .resume  = w100_lcdtg_init,
199 };
200
201 static struct w100_mem_info corgi_fb_mem = {
202         .ext_cntl          = 0x00040003,
203         .sdram_mode_reg    = 0x00650021,
204         .ext_timing_cntl   = 0x10002a4a,
205         .io_cntl           = 0x7ff87012,
206         .size              = 0x1fffff,
207 };
208
209 static struct w100_gen_regs corgi_fb_regs = {
210         .lcd_format    = 0x00000003,
211         .lcdd_cntl1    = 0x01CC0000,
212         .lcdd_cntl2    = 0x0003FFFF,
213         .genlcd_cntl1  = 0x00FFFF0D,
214         .genlcd_cntl2  = 0x003F3003,
215         .genlcd_cntl3  = 0x000102aa,
216 };
217
218 static struct w100_gpio_regs corgi_fb_gpio = {
219         .init_data1   = 0x000000bf,
220         .init_data2   = 0x00000000,
221         .gpio_dir1    = 0x00000000,
222         .gpio_oe1     = 0x03c0feff,
223         .gpio_dir2    = 0x00000000,
224         .gpio_oe2     = 0x00000000,
225 };
226
227 static struct w100_mode corgi_fb_modes[] = {
228 {
229         .xres            = 480,
230         .yres            = 640,
231         .left_margin     = 0x56,
232         .right_margin    = 0x55,
233         .upper_margin    = 0x03,
234         .lower_margin    = 0x00,
235         .crtc_ss         = 0x82360056,
236         .crtc_ls         = 0xA0280000,
237         .crtc_gs         = 0x80280028,
238         .crtc_vpos_gs    = 0x02830002,
239         .crtc_rev        = 0x00400008,
240         .crtc_dclk       = 0xA0000000,
241         .crtc_gclk       = 0x8015010F,
242         .crtc_goe        = 0x80100110,
243         .crtc_ps1_active = 0x41060010,
244         .pll_freq        = 75,
245         .fast_pll_freq   = 100,
246         .sysclk_src      = CLK_SRC_PLL,
247         .sysclk_divider  = 0,
248         .pixclk_src      = CLK_SRC_PLL,
249         .pixclk_divider  = 2,
250         .pixclk_divider_rotated = 6,
251 },{
252         .xres            = 240,
253         .yres            = 320,
254         .left_margin     = 0x27,
255         .right_margin    = 0x2e,
256         .upper_margin    = 0x01,
257         .lower_margin    = 0x00,
258         .crtc_ss         = 0x81170027,
259         .crtc_ls         = 0xA0140000,
260         .crtc_gs         = 0xC0140014,
261         .crtc_vpos_gs    = 0x00010141,
262         .crtc_rev        = 0x00400008,
263         .crtc_dclk       = 0xA0000000,
264         .crtc_gclk       = 0x8015010F,
265         .crtc_goe        = 0x80100110,
266         .crtc_ps1_active = 0x41060010,
267         .pll_freq        = 0,
268         .fast_pll_freq   = 0,
269         .sysclk_src      = CLK_SRC_XTAL,
270         .sysclk_divider  = 0,
271         .pixclk_src      = CLK_SRC_XTAL,
272         .pixclk_divider  = 1,
273         .pixclk_divider_rotated = 1,
274 },
275
276 };
277
278 static struct w100fb_mach_info corgi_fb_info = {
279         .tg         = &corgi_lcdtg_info,
280         .init_mode  = INIT_MODE_ROTATED,
281         .mem        = &corgi_fb_mem,
282         .regs       = &corgi_fb_regs,
283         .modelist   = &corgi_fb_modes[0],
284         .num_modes  = 2,
285         .gpio       = &corgi_fb_gpio,
286         .xtal_freq  = 12500000,
287         .xtal_dbl   = 0,
288 };
289
290 static struct resource corgi_fb_resources[] = {
291         [0] = {
292                 .start   = 0x08000000,
293                 .end     = 0x08ffffff,
294                 .flags   = IORESOURCE_MEM,
295         },
296 };
297
298 static struct platform_device corgifb_device = {
299         .name           = "w100fb",
300         .id             = -1,
301         .num_resources  = ARRAY_SIZE(corgi_fb_resources),
302         .resource       = corgi_fb_resources,
303         .dev            = {
304                 .platform_data = &corgi_fb_info,
305                 .parent = &corgissp_device.dev,
306         },
307
308 };
309
310
311 /*
312  * Corgi Backlight Device
313  */
314 static void corgi_bl_kick_battery(void)
315 {
316         void (*kick_batt)(void);
317
318         kick_batt = symbol_get(sharpsl_battery_kick);
319         if (kick_batt) {
320                 kick_batt();
321                 symbol_put(sharpsl_battery_kick);
322         }
323 }
324
325 static void corgi_bl_set_intensity(int intensity)
326 {
327         if (intensity > 0x10)
328                 intensity += 0x10;
329
330         /* Bits 0-4 are accessed via the SSP interface */
331         corgi_ssp_blduty_set(intensity & 0x1f);
332
333         /* Bit 5 is via SCOOP */
334         if (intensity & 0x0020)
335                 set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_BACKLIGHT_CONT);
336         else
337                 reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_BACKLIGHT_CONT);
338 }
339
340 static struct generic_bl_info corgi_bl_machinfo = {
341         .name = "corgi-bl",
342         .max_intensity = 0x2f,
343         .default_intensity = 0x1f,
344         .limit_mask = 0x0b,
345         .set_bl_intensity = corgi_bl_set_intensity,
346         .kick_battery = corgi_bl_kick_battery,
347 };
348
349 static struct platform_device corgibl_device = {
350         .name           = "generic-bl",
351         .dev            = {
352                 .parent = &corgifb_device.dev,
353                 .platform_data  = &corgi_bl_machinfo,
354         },
355         .id             = -1,
356 };
357
358
359 /*
360  * Corgi Keyboard Device
361  */
362 static struct platform_device corgikbd_device = {
363         .name           = "corgi-keyboard",
364         .id             = -1,
365 };
366
367
368 /*
369  * Corgi LEDs
370  */
371 static struct platform_device corgiled_device = {
372         .name           = "corgi-led",
373         .id             = -1,
374 };
375
376
377 /*
378  * Corgi Touch Screen Device
379  */
380 static unsigned long (*get_hsync_invperiod)(struct device *dev);
381
382 static void inline sharpsl_wait_sync(int gpio)
383 {
384         while((GPLR(gpio) & GPIO_bit(gpio)) == 0);
385         while((GPLR(gpio) & GPIO_bit(gpio)) != 0);
386 }
387
388 static unsigned long corgi_get_hsync_invperiod(void)
389 {
390         if (!get_hsync_invperiod)
391                 get_hsync_invperiod = symbol_get(w100fb_get_hsynclen);
392         if (!get_hsync_invperiod)
393                 return 0;
394
395         return get_hsync_invperiod(&corgifb_device.dev);
396 }
397
398 static void corgi_put_hsync(void)
399 {
400         if (get_hsync_invperiod)
401                 symbol_put(w100fb_get_hsynclen);
402         get_hsync_invperiod = NULL;
403 }
404
405 static void corgi_wait_hsync(void)
406 {
407         sharpsl_wait_sync(CORGI_GPIO_HSYNC);
408 }
409
410 static struct resource corgits_resources[] = {
411         [0] = {
412                 .start          = CORGI_IRQ_GPIO_TP_INT,
413                 .end            = CORGI_IRQ_GPIO_TP_INT,
414                 .flags          = IORESOURCE_IRQ,
415         },
416 };
417
418 static struct corgits_machinfo  corgi_ts_machinfo = {
419         .get_hsync_invperiod = corgi_get_hsync_invperiod,
420         .put_hsync           = corgi_put_hsync,
421         .wait_hsync          = corgi_wait_hsync,
422 };
423
424 static struct platform_device corgits_device = {
425         .name           = "corgi-ts",
426         .dev            = {
427                 .parent = &corgissp_device.dev,
428                 .platform_data  = &corgi_ts_machinfo,
429         },
430         .id             = -1,
431         .num_resources  = ARRAY_SIZE(corgits_resources),
432         .resource       = corgits_resources,
433 };
434
435
436 /*
437  * MMC/SD Device
438  *
439  * The card detect interrupt isn't debounced so we delay it by 250ms
440  * to give the card a chance to fully insert/eject.
441  */
442 static struct pxamci_platform_data corgi_mci_platform_data;
443
444 static int corgi_mci_init(struct device *dev, irq_handler_t corgi_detect_int, void *data)
445 {
446         int err;
447
448         err = gpio_request(CORGI_GPIO_nSD_DETECT, "nSD_DETECT");
449         if (err)
450                 goto err_out;
451
452         err = gpio_request(CORGI_GPIO_nSD_WP, "nSD_WP");
453         if (err)
454                 goto err_free_1;
455
456         err = gpio_request(CORGI_GPIO_SD_PWR, "SD_PWR");
457         if (err)
458                 goto err_free_2;
459
460         gpio_direction_input(CORGI_GPIO_nSD_DETECT);
461         gpio_direction_input(CORGI_GPIO_nSD_WP);
462         gpio_direction_output(CORGI_GPIO_SD_PWR, 0);
463
464         corgi_mci_platform_data.detect_delay = msecs_to_jiffies(250);
465
466         err = request_irq(CORGI_IRQ_GPIO_nSD_DETECT, corgi_detect_int,
467                                 IRQF_DISABLED | IRQF_TRIGGER_RISING |
468                                 IRQF_TRIGGER_FALLING,
469                                 "MMC card detect", data);
470         if (err) {
471                 pr_err("%s: MMC/SD: can't request MMC card detect IRQ\n",
472                                 __func__);
473                 goto err_free_3;
474         }
475         return 0;
476
477 err_free_3:
478         gpio_free(CORGI_GPIO_SD_PWR);
479 err_free_2:
480         gpio_free(CORGI_GPIO_nSD_WP);
481 err_free_1:
482         gpio_free(CORGI_GPIO_nSD_DETECT);
483 err_out:
484         return err;
485 }
486
487 static void corgi_mci_setpower(struct device *dev, unsigned int vdd)
488 {
489         struct pxamci_platform_data* p_d = dev->platform_data;
490
491         gpio_set_value(CORGI_GPIO_SD_PWR, ((1 << vdd) & p_d->ocr_mask));
492 }
493
494 static int corgi_mci_get_ro(struct device *dev)
495 {
496         return gpio_get_value(CORGI_GPIO_nSD_WP);
497 }
498
499 static void corgi_mci_exit(struct device *dev, void *data)
500 {
501         free_irq(CORGI_IRQ_GPIO_nSD_DETECT, data);
502         gpio_free(CORGI_GPIO_SD_PWR);
503         gpio_free(CORGI_GPIO_nSD_WP);
504         gpio_free(CORGI_GPIO_nSD_DETECT);
505 }
506
507 static struct pxamci_platform_data corgi_mci_platform_data = {
508         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
509         .init           = corgi_mci_init,
510         .get_ro         = corgi_mci_get_ro,
511         .setpower       = corgi_mci_setpower,
512         .exit           = corgi_mci_exit,
513 };
514
515
516 /*
517  * Irda
518  */
519 static void corgi_irda_transceiver_mode(struct device *dev, int mode)
520 {
521         gpio_set_value(CORGI_GPIO_IR_ON, mode & IR_OFF);
522         pxa2xx_transceiver_mode(dev, mode);
523 }
524
525 static int corgi_irda_startup(struct device *dev)
526 {
527         int err;
528
529         err = gpio_request(CORGI_GPIO_IR_ON, "IR_ON");
530         if (err)
531                 return err;
532
533         gpio_direction_output(CORGI_GPIO_IR_ON, 1);
534         return 0;
535 }
536
537 static void corgi_irda_shutdown(struct device *dev)
538 {
539         gpio_free(CORGI_GPIO_IR_ON);
540 }
541
542 static struct pxaficp_platform_data corgi_ficp_platform_data = {
543         .transceiver_cap        = IR_SIRMODE | IR_OFF,
544         .transceiver_mode       = corgi_irda_transceiver_mode,
545         .startup                = corgi_irda_startup,
546         .shutdown               = corgi_irda_shutdown,
547 };
548
549
550 /*
551  * USB Device Controller
552  */
553 static struct pxa2xx_udc_mach_info udc_info __initdata = {
554         /* no connect GPIO; corgi can't tell connection status */
555         .gpio_pullup            = CORGI_GPIO_USB_PULLUP,
556 };
557
558
559 static struct platform_device *devices[] __initdata = {
560         &corgiscoop_device,
561         &corgissp_device,
562         &corgifb_device,
563         &corgikbd_device,
564         &corgibl_device,
565         &corgits_device,
566         &corgiled_device,
567 };
568
569 static void corgi_poweroff(void)
570 {
571         if (!machine_is_corgi())
572                 /* Green LED off tells the bootloader to halt */
573                 reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
574         arm_machine_restart('h');
575 }
576
577 static void corgi_restart(char mode)
578 {
579         if (!machine_is_corgi())
580                 /* Green LED on tells the bootloader to reboot */
581                 set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
582         arm_machine_restart('h');
583 }
584
585 static void __init corgi_init(void)
586 {
587         pm_power_off = corgi_poweroff;
588         arm_pm_restart = corgi_restart;
589
590         /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
591         PCFR |= PCFR_OPDE;
592
593         pxa2xx_mfp_config(ARRAY_AND_SIZE(corgi_pin_config));
594
595         corgi_ssp_set_machinfo(&corgi_ssp_machinfo);
596
597         pxa_set_udc_info(&udc_info);
598         pxa_set_mci_info(&corgi_mci_platform_data);
599         pxa_set_ficp_info(&corgi_ficp_platform_data);
600         pxa_set_i2c_info(NULL);
601
602         platform_scoop_config = &corgi_pcmcia_config;
603
604         platform_add_devices(devices, ARRAY_SIZE(devices));
605 }
606
607 static void __init fixup_corgi(struct machine_desc *desc,
608                 struct tag *tags, char **cmdline, struct meminfo *mi)
609 {
610         sharpsl_save_param();
611         mi->nr_banks=1;
612         mi->bank[0].start = 0xa0000000;
613         mi->bank[0].node = 0;
614         if (machine_is_corgi())
615                 mi->bank[0].size = (32*1024*1024);
616         else
617                 mi->bank[0].size = (64*1024*1024);
618 }
619
620 #ifdef CONFIG_MACH_CORGI
621 MACHINE_START(CORGI, "SHARP Corgi")
622         .phys_io        = 0x40000000,
623         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
624         .fixup          = fixup_corgi,
625         .map_io         = pxa_map_io,
626         .init_irq       = pxa25x_init_irq,
627         .init_machine   = corgi_init,
628         .timer          = &pxa_timer,
629 MACHINE_END
630 #endif
631
632 #ifdef CONFIG_MACH_SHEPHERD
633 MACHINE_START(SHEPHERD, "SHARP Shepherd")
634         .phys_io        = 0x40000000,
635         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
636         .fixup          = fixup_corgi,
637         .map_io         = pxa_map_io,
638         .init_irq       = pxa25x_init_irq,
639         .init_machine   = corgi_init,
640         .timer          = &pxa_timer,
641 MACHINE_END
642 #endif
643
644 #ifdef CONFIG_MACH_HUSKY
645 MACHINE_START(HUSKY, "SHARP Husky")
646         .phys_io        = 0x40000000,
647         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
648         .fixup          = fixup_corgi,
649         .map_io         = pxa_map_io,
650         .init_irq       = pxa25x_init_irq,
651         .init_machine   = corgi_init,
652         .timer          = &pxa_timer,
653 MACHINE_END
654 #endif
655