ACPICA: Add support for zero-length buffer-to-string conversions
[linux-2.6/mini2440.git] / arch / arm / mach-pxa / corgi.c
blobe703a8d209e243d87410b2bde4f520ac5bd75769
1 /*
2 * Support for Sharp SL-C7xx PDAs
3 * Models: SL-C700 (Corgi), SL-C750 (Shepherd), SL-C760 (Husky)
5 * Copyright (c) 2004-2005 Richard Purdie
7 * Based on Sharp's 2.4 kernel patches/lubbock.c
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>
19 #include <linux/fs.h>
20 #include <linux/interrupt.h>
21 #include <linux/mmc/host.h>
22 #include <linux/pm.h>
23 #include <linux/backlight.h>
24 #include <video/w100fb.h>
26 #include <asm/setup.h>
27 #include <asm/memory.h>
28 #include <asm/mach-types.h>
29 #include <mach/hardware.h>
30 #include <asm/irq.h>
31 #include <asm/io.h>
32 #include <asm/system.h>
34 #include <asm/mach/arch.h>
35 #include <asm/mach/map.h>
36 #include <asm/mach/irq.h>
38 #include <mach/pxa-regs.h>
39 #include <mach/pxa2xx-regs.h>
40 #include <mach/pxa2xx-gpio.h>
41 #include <mach/i2c.h>
42 #include <mach/irda.h>
43 #include <mach/mmc.h>
44 #include <mach/udc.h>
45 #include <mach/corgi.h>
46 #include <mach/sharpsl.h>
48 #include <asm/mach/sharpsl_param.h>
49 #include <asm/hardware/scoop.h>
51 #include "generic.h"
52 #include "devices.h"
53 #include "sharpsl.h"
57 * Corgi SCOOP Device
59 static struct resource corgi_scoop_resources[] = {
60 [0] = {
61 .start = 0x10800000,
62 .end = 0x10800fff,
63 .flags = IORESOURCE_MEM,
67 static struct scoop_config corgi_scoop_setup = {
68 .io_dir = CORGI_SCOOP_IO_DIR,
69 .io_out = CORGI_SCOOP_IO_OUT,
72 struct platform_device corgiscoop_device = {
73 .name = "sharp-scoop",
74 .id = -1,
75 .dev = {
76 .platform_data = &corgi_scoop_setup,
78 .num_resources = ARRAY_SIZE(corgi_scoop_resources),
79 .resource = corgi_scoop_resources,
82 static void corgi_pcmcia_init(void)
84 /* Setup default state of GPIO outputs
85 before we enable them as outputs. */
86 GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) |
87 GPIO_bit(GPIO49_nPWE) | GPIO_bit(GPIO50_nPIOR) |
88 GPIO_bit(GPIO51_nPIOW) | GPIO_bit(GPIO52_nPCE_1) |
89 GPIO_bit(GPIO53_nPCE_2);
91 pxa_gpio_mode(GPIO48_nPOE_MD);
92 pxa_gpio_mode(GPIO49_nPWE_MD);
93 pxa_gpio_mode(GPIO50_nPIOR_MD);
94 pxa_gpio_mode(GPIO51_nPIOW_MD);
95 pxa_gpio_mode(GPIO55_nPREG_MD);
96 pxa_gpio_mode(GPIO56_nPWAIT_MD);
97 pxa_gpio_mode(GPIO57_nIOIS16_MD);
98 pxa_gpio_mode(GPIO52_nPCE_1_MD);
99 pxa_gpio_mode(GPIO53_nPCE_2_MD);
100 pxa_gpio_mode(GPIO54_pSKTSEL_MD);
103 static struct scoop_pcmcia_dev corgi_pcmcia_scoop[] = {
105 .dev = &corgiscoop_device.dev,
106 .irq = CORGI_IRQ_GPIO_CF_IRQ,
107 .cd_irq = CORGI_IRQ_GPIO_CF_CD,
108 .cd_irq_str = "PCMCIA0 CD",
112 static struct scoop_pcmcia_config corgi_pcmcia_config = {
113 .devs = &corgi_pcmcia_scoop[0],
114 .num_devs = 1,
115 .pcmcia_init = corgi_pcmcia_init,
118 EXPORT_SYMBOL(corgiscoop_device);
122 * Corgi SSP Device
124 * Set the parent as the scoop device because a lot of SSP devices
125 * also use scoop functions and this makes the power up/down order
126 * work correctly.
128 struct platform_device corgissp_device = {
129 .name = "corgi-ssp",
130 .dev = {
131 .parent = &corgiscoop_device.dev,
133 .id = -1,
136 struct corgissp_machinfo corgi_ssp_machinfo = {
137 .port = 1,
138 .cs_lcdcon = CORGI_GPIO_LCDCON_CS,
139 .cs_ads7846 = CORGI_GPIO_ADS7846_CS,
140 .cs_max1111 = CORGI_GPIO_MAX1111_CS,
141 .clk_lcdcon = 76,
142 .clk_ads7846 = 2,
143 .clk_max1111 = 8,
148 * LCD/Framebuffer
150 static void w100_lcdtg_suspend(struct w100fb_par *par)
152 corgi_lcdtg_suspend();
155 static void w100_lcdtg_init(struct w100fb_par *par)
157 corgi_lcdtg_hw_init(par->xres);
161 static struct w100_tg_info corgi_lcdtg_info = {
162 .change = w100_lcdtg_init,
163 .suspend = w100_lcdtg_suspend,
164 .resume = w100_lcdtg_init,
167 static struct w100_mem_info corgi_fb_mem = {
168 .ext_cntl = 0x00040003,
169 .sdram_mode_reg = 0x00650021,
170 .ext_timing_cntl = 0x10002a4a,
171 .io_cntl = 0x7ff87012,
172 .size = 0x1fffff,
175 static struct w100_gen_regs corgi_fb_regs = {
176 .lcd_format = 0x00000003,
177 .lcdd_cntl1 = 0x01CC0000,
178 .lcdd_cntl2 = 0x0003FFFF,
179 .genlcd_cntl1 = 0x00FFFF0D,
180 .genlcd_cntl2 = 0x003F3003,
181 .genlcd_cntl3 = 0x000102aa,
184 static struct w100_gpio_regs corgi_fb_gpio = {
185 .init_data1 = 0x000000bf,
186 .init_data2 = 0x00000000,
187 .gpio_dir1 = 0x00000000,
188 .gpio_oe1 = 0x03c0feff,
189 .gpio_dir2 = 0x00000000,
190 .gpio_oe2 = 0x00000000,
193 static struct w100_mode corgi_fb_modes[] = {
195 .xres = 480,
196 .yres = 640,
197 .left_margin = 0x56,
198 .right_margin = 0x55,
199 .upper_margin = 0x03,
200 .lower_margin = 0x00,
201 .crtc_ss = 0x82360056,
202 .crtc_ls = 0xA0280000,
203 .crtc_gs = 0x80280028,
204 .crtc_vpos_gs = 0x02830002,
205 .crtc_rev = 0x00400008,
206 .crtc_dclk = 0xA0000000,
207 .crtc_gclk = 0x8015010F,
208 .crtc_goe = 0x80100110,
209 .crtc_ps1_active = 0x41060010,
210 .pll_freq = 75,
211 .fast_pll_freq = 100,
212 .sysclk_src = CLK_SRC_PLL,
213 .sysclk_divider = 0,
214 .pixclk_src = CLK_SRC_PLL,
215 .pixclk_divider = 2,
216 .pixclk_divider_rotated = 6,
218 .xres = 240,
219 .yres = 320,
220 .left_margin = 0x27,
221 .right_margin = 0x2e,
222 .upper_margin = 0x01,
223 .lower_margin = 0x00,
224 .crtc_ss = 0x81170027,
225 .crtc_ls = 0xA0140000,
226 .crtc_gs = 0xC0140014,
227 .crtc_vpos_gs = 0x00010141,
228 .crtc_rev = 0x00400008,
229 .crtc_dclk = 0xA0000000,
230 .crtc_gclk = 0x8015010F,
231 .crtc_goe = 0x80100110,
232 .crtc_ps1_active = 0x41060010,
233 .pll_freq = 0,
234 .fast_pll_freq = 0,
235 .sysclk_src = CLK_SRC_XTAL,
236 .sysclk_divider = 0,
237 .pixclk_src = CLK_SRC_XTAL,
238 .pixclk_divider = 1,
239 .pixclk_divider_rotated = 1,
244 static struct w100fb_mach_info corgi_fb_info = {
245 .tg = &corgi_lcdtg_info,
246 .init_mode = INIT_MODE_ROTATED,
247 .mem = &corgi_fb_mem,
248 .regs = &corgi_fb_regs,
249 .modelist = &corgi_fb_modes[0],
250 .num_modes = 2,
251 .gpio = &corgi_fb_gpio,
252 .xtal_freq = 12500000,
253 .xtal_dbl = 0,
256 static struct resource corgi_fb_resources[] = {
257 [0] = {
258 .start = 0x08000000,
259 .end = 0x08ffffff,
260 .flags = IORESOURCE_MEM,
264 static struct platform_device corgifb_device = {
265 .name = "w100fb",
266 .id = -1,
267 .num_resources = ARRAY_SIZE(corgi_fb_resources),
268 .resource = corgi_fb_resources,
269 .dev = {
270 .platform_data = &corgi_fb_info,
271 .parent = &corgissp_device.dev,
278 * Corgi Backlight Device
280 static void corgi_bl_kick_battery(void)
282 void (*kick_batt)(void);
284 kick_batt = symbol_get(sharpsl_battery_kick);
285 if (kick_batt) {
286 kick_batt();
287 symbol_put(sharpsl_battery_kick);
291 static void corgi_bl_set_intensity(int intensity)
293 if (intensity > 0x10)
294 intensity += 0x10;
296 /* Bits 0-4 are accessed via the SSP interface */
297 corgi_ssp_blduty_set(intensity & 0x1f);
299 /* Bit 5 is via SCOOP */
300 if (intensity & 0x0020)
301 set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_BACKLIGHT_CONT);
302 else
303 reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_BACKLIGHT_CONT);
306 static struct generic_bl_info corgi_bl_machinfo = {
307 .name = "corgi-bl",
308 .max_intensity = 0x2f,
309 .default_intensity = 0x1f,
310 .limit_mask = 0x0b,
311 .set_bl_intensity = corgi_bl_set_intensity,
312 .kick_battery = corgi_bl_kick_battery,
315 static struct platform_device corgibl_device = {
316 .name = "generic-bl",
317 .dev = {
318 .parent = &corgifb_device.dev,
319 .platform_data = &corgi_bl_machinfo,
321 .id = -1,
326 * Corgi Keyboard Device
328 static struct platform_device corgikbd_device = {
329 .name = "corgi-keyboard",
330 .id = -1,
335 * Corgi LEDs
337 static struct platform_device corgiled_device = {
338 .name = "corgi-led",
339 .id = -1,
344 * Corgi Touch Screen Device
346 static unsigned long (*get_hsync_invperiod)(struct device *dev);
348 static void inline sharpsl_wait_sync(int gpio)
350 while((GPLR(gpio) & GPIO_bit(gpio)) == 0);
351 while((GPLR(gpio) & GPIO_bit(gpio)) != 0);
354 static unsigned long corgi_get_hsync_invperiod(void)
356 if (!get_hsync_invperiod)
357 get_hsync_invperiod = symbol_get(w100fb_get_hsynclen);
358 if (!get_hsync_invperiod)
359 return 0;
361 return get_hsync_invperiod(&corgifb_device.dev);
364 static void corgi_put_hsync(void)
366 if (get_hsync_invperiod)
367 symbol_put(w100fb_get_hsynclen);
368 get_hsync_invperiod = NULL;
371 static void corgi_wait_hsync(void)
373 sharpsl_wait_sync(CORGI_GPIO_HSYNC);
376 static struct resource corgits_resources[] = {
377 [0] = {
378 .start = CORGI_IRQ_GPIO_TP_INT,
379 .end = CORGI_IRQ_GPIO_TP_INT,
380 .flags = IORESOURCE_IRQ,
384 static struct corgits_machinfo corgi_ts_machinfo = {
385 .get_hsync_invperiod = corgi_get_hsync_invperiod,
386 .put_hsync = corgi_put_hsync,
387 .wait_hsync = corgi_wait_hsync,
390 static struct platform_device corgits_device = {
391 .name = "corgi-ts",
392 .dev = {
393 .parent = &corgissp_device.dev,
394 .platform_data = &corgi_ts_machinfo,
396 .id = -1,
397 .num_resources = ARRAY_SIZE(corgits_resources),
398 .resource = corgits_resources,
403 * MMC/SD Device
405 * The card detect interrupt isn't debounced so we delay it by 250ms
406 * to give the card a chance to fully insert/eject.
408 static struct pxamci_platform_data corgi_mci_platform_data;
410 static int corgi_mci_init(struct device *dev, irq_handler_t corgi_detect_int, void *data)
412 int err;
414 /* setup GPIO for PXA25x MMC controller */
415 pxa_gpio_mode(GPIO6_MMCCLK_MD);
416 pxa_gpio_mode(GPIO8_MMCCS0_MD);
417 pxa_gpio_mode(CORGI_GPIO_nSD_DETECT | GPIO_IN);
418 pxa_gpio_mode(CORGI_GPIO_SD_PWR | GPIO_OUT);
420 corgi_mci_platform_data.detect_delay = msecs_to_jiffies(250);
422 err = request_irq(CORGI_IRQ_GPIO_nSD_DETECT, corgi_detect_int,
423 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
424 "MMC card detect", data);
425 if (err)
426 printk(KERN_ERR "corgi_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
428 return err;
431 static void corgi_mci_setpower(struct device *dev, unsigned int vdd)
433 struct pxamci_platform_data* p_d = dev->platform_data;
435 if (( 1 << vdd) & p_d->ocr_mask)
436 GPSR1 = GPIO_bit(CORGI_GPIO_SD_PWR);
437 else
438 GPCR1 = GPIO_bit(CORGI_GPIO_SD_PWR);
441 static int corgi_mci_get_ro(struct device *dev)
443 return GPLR(CORGI_GPIO_nSD_WP) & GPIO_bit(CORGI_GPIO_nSD_WP);
446 static void corgi_mci_exit(struct device *dev, void *data)
448 free_irq(CORGI_IRQ_GPIO_nSD_DETECT, data);
451 static struct pxamci_platform_data corgi_mci_platform_data = {
452 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
453 .init = corgi_mci_init,
454 .get_ro = corgi_mci_get_ro,
455 .setpower = corgi_mci_setpower,
456 .exit = corgi_mci_exit,
461 * Irda
463 static void corgi_irda_transceiver_mode(struct device *dev, int mode)
465 if (mode & IR_OFF)
466 GPSR(CORGI_GPIO_IR_ON) = GPIO_bit(CORGI_GPIO_IR_ON);
467 else
468 GPCR(CORGI_GPIO_IR_ON) = GPIO_bit(CORGI_GPIO_IR_ON);
469 pxa2xx_transceiver_mode(dev, mode);
472 static struct pxaficp_platform_data corgi_ficp_platform_data = {
473 .transceiver_cap = IR_SIRMODE | IR_OFF,
474 .transceiver_mode = corgi_irda_transceiver_mode,
479 * USB Device Controller
481 static struct pxa2xx_udc_mach_info udc_info __initdata = {
482 /* no connect GPIO; corgi can't tell connection status */
483 .gpio_pullup = CORGI_GPIO_USB_PULLUP,
487 static struct platform_device *devices[] __initdata = {
488 &corgiscoop_device,
489 &corgissp_device,
490 &corgifb_device,
491 &corgikbd_device,
492 &corgibl_device,
493 &corgits_device,
494 &corgiled_device,
497 static void corgi_poweroff(void)
499 if (!machine_is_corgi())
500 /* Green LED off tells the bootloader to halt */
501 reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
502 arm_machine_restart('h');
505 static void corgi_restart(char mode)
507 if (!machine_is_corgi())
508 /* Green LED on tells the bootloader to reboot */
509 set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
510 arm_machine_restart('h');
513 static void __init corgi_init(void)
515 pm_power_off = corgi_poweroff;
516 arm_pm_restart = corgi_restart;
518 /* setup sleep mode values */
519 PWER = 0x00000002;
520 PFER = 0x00000000;
521 PRER = 0x00000002;
522 PGSR0 = 0x0158C000;
523 PGSR1 = 0x00FF0080;
524 PGSR2 = 0x0001C004;
525 /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
526 PCFR |= PCFR_OPDE;
528 corgi_ssp_set_machinfo(&corgi_ssp_machinfo);
530 pxa_gpio_mode(CORGI_GPIO_IR_ON | GPIO_OUT);
531 pxa_gpio_mode(CORGI_GPIO_HSYNC | GPIO_IN);
533 pxa_set_udc_info(&udc_info);
534 pxa_set_mci_info(&corgi_mci_platform_data);
535 pxa_set_ficp_info(&corgi_ficp_platform_data);
536 pxa_set_i2c_info(NULL);
538 platform_scoop_config = &corgi_pcmcia_config;
540 platform_add_devices(devices, ARRAY_SIZE(devices));
543 static void __init fixup_corgi(struct machine_desc *desc,
544 struct tag *tags, char **cmdline, struct meminfo *mi)
546 sharpsl_save_param();
547 mi->nr_banks=1;
548 mi->bank[0].start = 0xa0000000;
549 mi->bank[0].node = 0;
550 if (machine_is_corgi())
551 mi->bank[0].size = (32*1024*1024);
552 else
553 mi->bank[0].size = (64*1024*1024);
556 #ifdef CONFIG_MACH_CORGI
557 MACHINE_START(CORGI, "SHARP Corgi")
558 .phys_io = 0x40000000,
559 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
560 .fixup = fixup_corgi,
561 .map_io = pxa_map_io,
562 .init_irq = pxa25x_init_irq,
563 .init_machine = corgi_init,
564 .timer = &pxa_timer,
565 MACHINE_END
566 #endif
568 #ifdef CONFIG_MACH_SHEPHERD
569 MACHINE_START(SHEPHERD, "SHARP Shepherd")
570 .phys_io = 0x40000000,
571 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
572 .fixup = fixup_corgi,
573 .map_io = pxa_map_io,
574 .init_irq = pxa25x_init_irq,
575 .init_machine = corgi_init,
576 .timer = &pxa_timer,
577 MACHINE_END
578 #endif
580 #ifdef CONFIG_MACH_HUSKY
581 MACHINE_START(HUSKY, "SHARP Husky")
582 .phys_io = 0x40000000,
583 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
584 .fixup = fixup_corgi,
585 .map_io = pxa_map_io,
586 .init_irq = pxa25x_init_irq,
587 .init_machine = corgi_init,
588 .timer = &pxa_timer,
589 MACHINE_END
590 #endif