Merge branch 'x86/prototypes' into x86-v28-for-linus-phase1
[linux-2.6-block.git] / arch / arm / mach-pxa / corgi.c
CommitLineData
1da177e4
LT
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>
d052d1be 17#include <linux/platform_device.h>
1da177e4
LT
18#include <linux/major.h>
19#include <linux/fs.h>
20#include <linux/interrupt.h>
21#include <linux/mmc/host.h>
74617fb6 22#include <linux/pm.h>
c3f8f650 23#include <linux/backlight.h>
ca4d6cfc 24#include <video/w100fb.h>
1da177e4
LT
25
26#include <asm/setup.h>
27#include <asm/memory.h>
28#include <asm/mach-types.h>
a09e64fb 29#include <mach/hardware.h>
1da177e4
LT
30#include <asm/irq.h>
31#include <asm/io.h>
74617fb6 32#include <asm/system.h>
1da177e4
LT
33
34#include <asm/mach/arch.h>
35#include <asm/mach/map.h>
36#include <asm/mach/irq.h>
37
a09e64fb
RK
38#include <mach/pxa-regs.h>
39#include <mach/pxa2xx-regs.h>
40#include <mach/pxa2xx-gpio.h>
f8787fdc 41#include <mach/i2c.h>
a09e64fb
RK
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>
1da177e4
LT
47
48#include <asm/mach/sharpsl_param.h>
49#include <asm/hardware/scoop.h>
1da177e4
LT
50
51#include "generic.h"
46c41e62 52#include "devices.h"
50a5de44 53#include "sharpsl.h"
1da177e4
LT
54
55
56/*
57 * Corgi SCOOP Device
58 */
59static struct resource corgi_scoop_resources[] = {
60 [0] = {
61 .start = 0x10800000,
62 .end = 0x10800fff,
63 .flags = IORESOURCE_MEM,
64 },
65};
66
67static struct scoop_config corgi_scoop_setup = {
68 .io_dir = CORGI_SCOOP_IO_DIR,
69 .io_out = CORGI_SCOOP_IO_OUT,
70};
71
a63ae442
RP
72struct platform_device corgiscoop_device = {
73 .name = "sharp-scoop",
74 .id = -1,
75 .dev = {
76 .platform_data = &corgi_scoop_setup,
77 },
78 .num_resources = ARRAY_SIZE(corgi_scoop_resources),
79 .resource = corgi_scoop_resources,
80};
81
82static void corgi_pcmcia_init(void)
83{
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);
90
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);
101}
102
0ce7625f
RP
103static struct scoop_pcmcia_dev corgi_pcmcia_scoop[] = {
104{
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",
109},
110};
111
a63ae442
RP
112static struct scoop_pcmcia_config corgi_pcmcia_config = {
113 .devs = &corgi_pcmcia_scoop[0],
114 .num_devs = 1,
115 .pcmcia_init = corgi_pcmcia_init,
1da177e4
LT
116};
117
a63ae442
RP
118EXPORT_SYMBOL(corgiscoop_device);
119
1da177e4
LT
120
121/*
122 * Corgi SSP Device
123 *
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.
127 */
41b1bce8 128struct platform_device corgissp_device = {
1da177e4
LT
129 .name = "corgi-ssp",
130 .dev = {
131 .parent = &corgiscoop_device.dev,
132 },
133 .id = -1,
134};
135
50a5de44
RP
136struct 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,
144};
145
1da177e4 146
ca4d6cfc
RP
147/*
148 * LCD/Framebuffer
149 */
150static void w100_lcdtg_suspend(struct w100fb_par *par)
151{
152 corgi_lcdtg_suspend();
153}
154
155static void w100_lcdtg_init(struct w100fb_par *par)
156{
157 corgi_lcdtg_hw_init(par->xres);
158}
159
160
161static struct w100_tg_info corgi_lcdtg_info = {
162 .change = w100_lcdtg_init,
163 .suspend = w100_lcdtg_suspend,
164 .resume = w100_lcdtg_init,
165};
166
167static 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,
173};
174
175static 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,
182};
183
184static 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,
191};
192
193static struct w100_mode corgi_fb_modes[] = {
194{
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,
217},{
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,
240},
241
242};
243
244static 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,
254};
255
256static struct resource corgi_fb_resources[] = {
257 [0] = {
258 .start = 0x08000000,
259 .end = 0x08ffffff,
260 .flags = IORESOURCE_MEM,
261 },
262};
263
264static 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,
272 },
273
274};
275
276
1da177e4
LT
277/*
278 * Corgi Backlight Device
279 */
c3f8f650
RP
280static void corgi_bl_kick_battery(void)
281{
282 void (*kick_batt)(void);
283
284 kick_batt = symbol_get(sharpsl_battery_kick);
285 if (kick_batt) {
286 kick_batt();
287 symbol_put(sharpsl_battery_kick);
288 }
289}
290
ca4d6cfc
RP
291static void corgi_bl_set_intensity(int intensity)
292{
293 if (intensity > 0x10)
294 intensity += 0x10;
295
296 /* Bits 0-4 are accessed via the SSP interface */
297 corgi_ssp_blduty_set(intensity & 0x1f);
298
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);
304}
305
c3f8f650
RP
306static struct generic_bl_info corgi_bl_machinfo = {
307 .name = "corgi-bl",
1351e6e0 308 .max_intensity = 0x2f,
2c0f5fb0
RP
309 .default_intensity = 0x1f,
310 .limit_mask = 0x0b,
1351e6e0 311 .set_bl_intensity = corgi_bl_set_intensity,
c3f8f650 312 .kick_battery = corgi_bl_kick_battery,
1351e6e0
RP
313};
314
1da177e4 315static struct platform_device corgibl_device = {
c3f8f650 316 .name = "generic-bl",
1da177e4
LT
317 .dev = {
318 .parent = &corgifb_device.dev,
1351e6e0 319 .platform_data = &corgi_bl_machinfo,
1da177e4
LT
320 },
321 .id = -1,
322};
323
324
f7ceff34
RP
325/*
326 * Corgi Keyboard Device
327 */
328static struct platform_device corgikbd_device = {
329 .name = "corgi-keyboard",
330 .id = -1,
331};
332
333
3179108d
RP
334/*
335 * Corgi LEDs
336 */
337static struct platform_device corgiled_device = {
338 .name = "corgi-led",
339 .id = -1,
340};
341
ca4d6cfc 342
f7ceff34
RP
343/*
344 * Corgi Touch Screen Device
345 */
ca4d6cfc
RP
346static unsigned long (*get_hsync_invperiod)(struct device *dev);
347
348static void inline sharpsl_wait_sync(int gpio)
349{
350 while((GPLR(gpio) & GPIO_bit(gpio)) == 0);
351 while((GPLR(gpio) & GPIO_bit(gpio)) != 0);
352}
353
354static unsigned long corgi_get_hsync_invperiod(void)
355{
356 if (!get_hsync_invperiod)
357 get_hsync_invperiod = symbol_get(w100fb_get_hsynclen);
358 if (!get_hsync_invperiod)
359 return 0;
360
361 return get_hsync_invperiod(&corgifb_device.dev);
362}
363
364static void corgi_put_hsync(void)
365{
366 if (get_hsync_invperiod)
367 symbol_put(w100fb_get_hsynclen);
368 get_hsync_invperiod = NULL;
369}
370
371static void corgi_wait_hsync(void)
372{
373 sharpsl_wait_sync(CORGI_GPIO_HSYNC);
374}
375
513b6e1a
RP
376static struct resource corgits_resources[] = {
377 [0] = {
378 .start = CORGI_IRQ_GPIO_TP_INT,
379 .end = CORGI_IRQ_GPIO_TP_INT,
380 .flags = IORESOURCE_IRQ,
381 },
382};
383
384static struct corgits_machinfo corgi_ts_machinfo = {
ca4d6cfc
RP
385 .get_hsync_invperiod = corgi_get_hsync_invperiod,
386 .put_hsync = corgi_put_hsync,
387 .wait_hsync = corgi_wait_hsync,
513b6e1a
RP
388};
389
f7ceff34
RP
390static struct platform_device corgits_device = {
391 .name = "corgi-ts",
392 .dev = {
393 .parent = &corgissp_device.dev,
513b6e1a 394 .platform_data = &corgi_ts_machinfo,
f7ceff34
RP
395 },
396 .id = -1,
513b6e1a
RP
397 .num_resources = ARRAY_SIZE(corgits_resources),
398 .resource = corgits_resources,
f7ceff34
RP
399};
400
401
1da177e4
LT
402/*
403 * MMC/SD Device
404 *
aa6c2e79 405 * The card detect interrupt isn't debounced so we delay it by 250ms
1da177e4
LT
406 * to give the card a chance to fully insert/eject.
407 */
aa6c2e79 408static struct pxamci_platform_data corgi_mci_platform_data;
1da177e4 409
40220c1a 410static int corgi_mci_init(struct device *dev, irq_handler_t corgi_detect_int, void *data)
1da177e4
LT
411{
412 int err;
413
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);
419
aa6c2e79 420 corgi_mci_platform_data.detect_delay = msecs_to_jiffies(250);
1da177e4 421
9ded96f2 422 err = request_irq(CORGI_IRQ_GPIO_nSD_DETECT, corgi_detect_int,
52e405ea 423 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
9ded96f2 424 "MMC card detect", data);
2687bd38 425 if (err)
1da177e4 426 printk(KERN_ERR "corgi_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
1da177e4 427
2687bd38 428 return err;
1da177e4
LT
429}
430
431static void corgi_mci_setpower(struct device *dev, unsigned int vdd)
432{
433 struct pxamci_platform_data* p_d = dev->platform_data;
434
fdce05bb 435 if (( 1 << vdd) & p_d->ocr_mask)
1da177e4 436 GPSR1 = GPIO_bit(CORGI_GPIO_SD_PWR);
fdce05bb 437 else
1da177e4 438 GPCR1 = GPIO_bit(CORGI_GPIO_SD_PWR);
1da177e4
LT
439}
440
3870ee8c
RP
441static int corgi_mci_get_ro(struct device *dev)
442{
443 return GPLR(CORGI_GPIO_nSD_WP) & GPIO_bit(CORGI_GPIO_nSD_WP);
444}
445
1da177e4
LT
446static void corgi_mci_exit(struct device *dev, void *data)
447{
448 free_irq(CORGI_IRQ_GPIO_nSD_DETECT, data);
1da177e4
LT
449}
450
451static struct pxamci_platform_data corgi_mci_platform_data = {
452 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
453 .init = corgi_mci_init,
3870ee8c 454 .get_ro = corgi_mci_get_ro,
1da177e4
LT
455 .setpower = corgi_mci_setpower,
456 .exit = corgi_mci_exit,
457};
458
459
ca1140b5
RP
460/*
461 * Irda
462 */
463static void corgi_irda_transceiver_mode(struct device *dev, int mode)
464{
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);
0fc3ff31 469 pxa2xx_transceiver_mode(dev, mode);
ca1140b5
RP
470}
471
472static struct pxaficp_platform_data corgi_ficp_platform_data = {
473 .transceiver_cap = IR_SIRMODE | IR_OFF,
474 .transceiver_mode = corgi_irda_transceiver_mode,
475};
476
f7ceff34 477
1da177e4
LT
478/*
479 * USB Device Controller
480 */
1da177e4
LT
481static struct pxa2xx_udc_mach_info udc_info __initdata = {
482 /* no connect GPIO; corgi can't tell connection status */
b2bbb20b 483 .gpio_pullup = CORGI_GPIO_USB_PULLUP,
1da177e4
LT
484};
485
486
487static struct platform_device *devices[] __initdata = {
488 &corgiscoop_device,
489 &corgissp_device,
490 &corgifb_device,
f7ceff34 491 &corgikbd_device,
1da177e4 492 &corgibl_device,
f7ceff34 493 &corgits_device,
3179108d 494 &corgiled_device,
1da177e4
LT
495};
496
74617fb6
RP
497static void corgi_poweroff(void)
498{
74617fb6
RP
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');
503}
504
505static void corgi_restart(char mode)
506{
74617fb6
RP
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');
511}
512
1da177e4
LT
513static void __init corgi_init(void)
514{
74617fb6
RP
515 pm_power_off = corgi_poweroff;
516 arm_pm_restart = corgi_restart;
517
fdce05bb
RP
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;
527
50a5de44
RP
528 corgi_ssp_set_machinfo(&corgi_ssp_machinfo);
529
ca1140b5 530 pxa_gpio_mode(CORGI_GPIO_IR_ON | GPIO_OUT);
513b6e1a 531 pxa_gpio_mode(CORGI_GPIO_HSYNC | GPIO_IN);
ca1140b5 532
1da177e4
LT
533 pxa_set_udc_info(&udc_info);
534 pxa_set_mci_info(&corgi_mci_platform_data);
ca1140b5 535 pxa_set_ficp_info(&corgi_ficp_platform_data);
f8787fdc 536 pxa_set_i2c_info(NULL);
1da177e4 537
a63ae442 538 platform_scoop_config = &corgi_pcmcia_config;
0ce7625f 539
1da177e4
LT
540 platform_add_devices(devices, ARRAY_SIZE(devices));
541}
542
543static void __init fixup_corgi(struct machine_desc *desc,
544 struct tag *tags, char **cmdline, struct meminfo *mi)
545{
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);
554}
555
1da177e4
LT
556#ifdef CONFIG_MACH_CORGI
557MACHINE_START(CORGI, "SHARP Corgi")
e9dea0c6 558 .phys_io = 0x40000000,
68070bde 559 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
e9dea0c6 560 .fixup = fixup_corgi,
fdce05bb 561 .map_io = pxa_map_io,
cd49104d 562 .init_irq = pxa25x_init_irq,
e9dea0c6
RK
563 .init_machine = corgi_init,
564 .timer = &pxa_timer,
1da177e4
LT
565MACHINE_END
566#endif
567
568#ifdef CONFIG_MACH_SHEPHERD
569MACHINE_START(SHEPHERD, "SHARP Shepherd")
e9dea0c6 570 .phys_io = 0x40000000,
68070bde 571 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
e9dea0c6 572 .fixup = fixup_corgi,
fdce05bb 573 .map_io = pxa_map_io,
cd49104d 574 .init_irq = pxa25x_init_irq,
e9dea0c6
RK
575 .init_machine = corgi_init,
576 .timer = &pxa_timer,
1da177e4
LT
577MACHINE_END
578#endif
579
580#ifdef CONFIG_MACH_HUSKY
581MACHINE_START(HUSKY, "SHARP Husky")
e9dea0c6 582 .phys_io = 0x40000000,
68070bde 583 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
e9dea0c6 584 .fixup = fixup_corgi,
fdce05bb 585 .map_io = pxa_map_io,
cd49104d 586 .init_irq = pxa25x_init_irq,
e9dea0c6
RK
587 .init_machine = corgi_init,
588 .timer = &pxa_timer,
1da177e4
LT
589MACHINE_END
590#endif
591