viafb: removed duplicated #include's
[linux-2.6/mini2440.git] / arch / arm / mach-pxa / spitz.c
blob524f656dc56de561d11d4c467220d569380a2718
1 /*
2 * Support for Sharp SL-Cxx00 Series of PDAs
3 * Models: SL-C3000 (Spitz), SL-C1000 (Akita) and SL-C3100 (Borzoi)
5 * Copyright (c) 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/delay.h>
19 #include <linux/major.h>
20 #include <linux/fs.h>
21 #include <linux/interrupt.h>
22 #include <linux/gpio.h>
23 #include <linux/leds.h>
24 #include <linux/mmc/host.h>
25 #include <linux/pm.h>
26 #include <linux/backlight.h>
27 #include <linux/io.h>
28 #include <linux/i2c.h>
29 #include <linux/i2c/pca953x.h>
30 #include <linux/spi/spi.h>
31 #include <linux/spi/ads7846.h>
32 #include <linux/spi/corgi_lcd.h>
34 #include <asm/setup.h>
35 #include <asm/memory.h>
36 #include <asm/mach-types.h>
37 #include <mach/hardware.h>
38 #include <asm/irq.h>
39 #include <asm/system.h>
41 #include <asm/mach/arch.h>
42 #include <asm/mach/map.h>
43 #include <asm/mach/irq.h>
45 #include <mach/pxa-regs.h>
46 #include <mach/pxa2xx-regs.h>
47 #include <mach/mfp-pxa27x.h>
48 #include <mach/pxa27x-udc.h>
49 #include <mach/reset.h>
50 #include <mach/i2c.h>
51 #include <mach/irda.h>
52 #include <mach/mmc.h>
53 #include <mach/ohci.h>
54 #include <mach/udc.h>
55 #include <mach/pxafb.h>
56 #include <mach/pxa2xx_spi.h>
57 #include <mach/spitz.h>
58 #include <mach/sharpsl.h>
60 #include <asm/mach/sharpsl_param.h>
61 #include <asm/hardware/scoop.h>
63 #include "generic.h"
64 #include "devices.h"
65 #include "sharpsl.h"
67 static unsigned long spitz_pin_config[] __initdata = {
68 /* Chip Selects */
69 GPIO78_nCS_2, /* SCOOP #2 */
70 GPIO80_nCS_4, /* SCOOP #1 */
72 /* LCD - 16bpp Active TFT */
73 GPIO58_LCD_LDD_0,
74 GPIO59_LCD_LDD_1,
75 GPIO60_LCD_LDD_2,
76 GPIO61_LCD_LDD_3,
77 GPIO62_LCD_LDD_4,
78 GPIO63_LCD_LDD_5,
79 GPIO64_LCD_LDD_6,
80 GPIO65_LCD_LDD_7,
81 GPIO66_LCD_LDD_8,
82 GPIO67_LCD_LDD_9,
83 GPIO68_LCD_LDD_10,
84 GPIO69_LCD_LDD_11,
85 GPIO70_LCD_LDD_12,
86 GPIO71_LCD_LDD_13,
87 GPIO72_LCD_LDD_14,
88 GPIO73_LCD_LDD_15,
89 GPIO74_LCD_FCLK,
90 GPIO75_LCD_LCLK,
91 GPIO76_LCD_PCLK,
93 /* PC Card */
94 GPIO48_nPOE,
95 GPIO49_nPWE,
96 GPIO50_nPIOR,
97 GPIO51_nPIOW,
98 GPIO85_nPCE_1,
99 GPIO54_nPCE_2,
100 GPIO79_PSKTSEL,
101 GPIO55_nPREG,
102 GPIO56_nPWAIT,
103 GPIO57_nIOIS16,
105 /* MMC */
106 GPIO32_MMC_CLK,
107 GPIO112_MMC_CMD,
108 GPIO92_MMC_DAT_0,
109 GPIO109_MMC_DAT_1,
110 GPIO110_MMC_DAT_2,
111 GPIO111_MMC_DAT_3,
113 /* GPIOs */
114 GPIO9_GPIO, /* SPITZ_GPIO_nSD_DETECT */
115 GPIO81_GPIO, /* SPITZ_GPIO_nSD_WP */
116 GPIO41_GPIO, /* SPITZ_GPIO_USB_CONNECT */
117 GPIO37_GPIO, /* SPITZ_GPIO_USB_HOST */
118 GPIO35_GPIO, /* SPITZ_GPIO_USB_DEVICE */
119 GPIO22_GPIO, /* SPITZ_GPIO_HSYNC */
120 GPIO94_GPIO, /* SPITZ_GPIO_CF_CD */
121 GPIO105_GPIO, /* SPITZ_GPIO_CF_IRQ */
122 GPIO106_GPIO, /* SPITZ_GPIO_CF2_IRQ */
124 GPIO1_GPIO | WAKEUP_ON_EDGE_RISE,
128 * Spitz SCOOP Device #1
130 static struct resource spitz_scoop_resources[] = {
131 [0] = {
132 .start = 0x10800000,
133 .end = 0x10800fff,
134 .flags = IORESOURCE_MEM,
138 static struct scoop_config spitz_scoop_setup = {
139 .io_dir = SPITZ_SCP_IO_DIR,
140 .io_out = SPITZ_SCP_IO_OUT,
141 .suspend_clr = SPITZ_SCP_SUS_CLR,
142 .suspend_set = SPITZ_SCP_SUS_SET,
143 .gpio_base = SPITZ_SCP_GPIO_BASE,
146 struct platform_device spitzscoop_device = {
147 .name = "sharp-scoop",
148 .id = 0,
149 .dev = {
150 .platform_data = &spitz_scoop_setup,
152 .num_resources = ARRAY_SIZE(spitz_scoop_resources),
153 .resource = spitz_scoop_resources,
157 * Spitz SCOOP Device #2
159 static struct resource spitz_scoop2_resources[] = {
160 [0] = {
161 .start = 0x08800040,
162 .end = 0x08800fff,
163 .flags = IORESOURCE_MEM,
167 static struct scoop_config spitz_scoop2_setup = {
168 .io_dir = SPITZ_SCP2_IO_DIR,
169 .io_out = SPITZ_SCP2_IO_OUT,
170 .suspend_clr = SPITZ_SCP2_SUS_CLR,
171 .suspend_set = SPITZ_SCP2_SUS_SET,
172 .gpio_base = SPITZ_SCP2_GPIO_BASE,
175 struct platform_device spitzscoop2_device = {
176 .name = "sharp-scoop",
177 .id = 1,
178 .dev = {
179 .platform_data = &spitz_scoop2_setup,
181 .num_resources = ARRAY_SIZE(spitz_scoop2_resources),
182 .resource = spitz_scoop2_resources,
185 #define SPITZ_PWR_SD 0x01
186 #define SPITZ_PWR_CF 0x02
188 /* Power control is shared with between one of the CF slots and SD */
189 static void spitz_card_pwr_ctrl(int device, unsigned short new_cpr)
191 unsigned short cpr = read_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR);
193 if (new_cpr & 0x0007) {
194 gpio_set_value(SPITZ_GPIO_CF_POWER, 1);
195 if (!(cpr & 0x0002) && !(cpr & 0x0004))
196 mdelay(5);
197 if (device == SPITZ_PWR_CF)
198 cpr |= 0x0002;
199 if (device == SPITZ_PWR_SD)
200 cpr |= 0x0004;
201 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr | new_cpr);
202 } else {
203 if (device == SPITZ_PWR_CF)
204 cpr &= ~0x0002;
205 if (device == SPITZ_PWR_SD)
206 cpr &= ~0x0004;
207 if (!(cpr & 0x0002) && !(cpr & 0x0004)) {
208 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, 0x0000);
209 mdelay(1);
210 gpio_set_value(SPITZ_GPIO_CF_POWER, 0);
211 } else {
212 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr | new_cpr);
217 static void spitz_pcmcia_pwr(struct device *scoop, unsigned short cpr, int nr)
219 /* Only need to override behaviour for slot 0 */
220 if (nr == 0)
221 spitz_card_pwr_ctrl(SPITZ_PWR_CF, cpr);
222 else
223 write_scoop_reg(scoop, SCOOP_CPR, cpr);
226 static struct scoop_pcmcia_dev spitz_pcmcia_scoop[] = {
228 .dev = &spitzscoop_device.dev,
229 .irq = SPITZ_IRQ_GPIO_CF_IRQ,
230 .cd_irq = SPITZ_IRQ_GPIO_CF_CD,
231 .cd_irq_str = "PCMCIA0 CD",
233 .dev = &spitzscoop2_device.dev,
234 .irq = SPITZ_IRQ_GPIO_CF2_IRQ,
235 .cd_irq = -1,
239 static struct scoop_pcmcia_config spitz_pcmcia_config = {
240 .devs = &spitz_pcmcia_scoop[0],
241 .num_devs = 2,
242 .power_ctrl = spitz_pcmcia_pwr,
245 EXPORT_SYMBOL(spitzscoop_device);
246 EXPORT_SYMBOL(spitzscoop2_device);
249 * Spitz Keyboard Device
251 static struct platform_device spitzkbd_device = {
252 .name = "spitz-keyboard",
253 .id = -1,
258 * Spitz LEDs
260 static struct gpio_led spitz_gpio_leds[] = {
262 .name = "spitz:amber:charge",
263 .default_trigger = "sharpsl-charge",
264 .gpio = SPITZ_GPIO_LED_ORANGE,
267 .name = "spitz:green:hddactivity",
268 .default_trigger = "ide-disk",
269 .gpio = SPITZ_GPIO_LED_GREEN,
273 static struct gpio_led_platform_data spitz_gpio_leds_info = {
274 .leds = spitz_gpio_leds,
275 .num_leds = ARRAY_SIZE(spitz_gpio_leds),
278 static struct platform_device spitzled_device = {
279 .name = "leds-gpio",
280 .id = -1,
281 .dev = {
282 .platform_data = &spitz_gpio_leds_info,
286 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
287 static struct pxa2xx_spi_master spitz_spi_info = {
288 .num_chipselect = 3,
291 static struct ads7846_platform_data spitz_ads7846_info = {
292 .model = 7846,
293 .vref_delay_usecs = 100,
294 .x_plate_ohms = 419,
295 .y_plate_ohms = 486,
296 .gpio_pendown = SPITZ_GPIO_TP_INT,
299 static void spitz_ads7846_cs(u32 command)
301 gpio_set_value(SPITZ_GPIO_ADS7846_CS, !(command == PXA2XX_CS_ASSERT));
304 static struct pxa2xx_spi_chip spitz_ads7846_chip = {
305 .cs_control = spitz_ads7846_cs,
308 static void spitz_bl_kick_battery(void)
310 void (*kick_batt)(void);
312 kick_batt = symbol_get(sharpsl_battery_kick);
313 if (kick_batt) {
314 kick_batt();
315 symbol_put(sharpsl_battery_kick);
319 static struct corgi_lcd_platform_data spitz_lcdcon_info = {
320 .init_mode = CORGI_LCD_MODE_VGA,
321 .max_intensity = 0x2f,
322 .default_intensity = 0x1f,
323 .limit_mask = 0x0b,
324 .gpio_backlight_cont = SPITZ_GPIO_BACKLIGHT_CONT,
325 .gpio_backlight_on = SPITZ_GPIO_BACKLIGHT_ON,
326 .kick_battery = spitz_bl_kick_battery,
329 static void spitz_lcdcon_cs(u32 command)
331 gpio_set_value(SPITZ_GPIO_LCDCON_CS, !(command == PXA2XX_CS_ASSERT));
334 static struct pxa2xx_spi_chip spitz_lcdcon_chip = {
335 .cs_control = spitz_lcdcon_cs,
338 static void spitz_max1111_cs(u32 command)
340 gpio_set_value(SPITZ_GPIO_MAX1111_CS, !(command == PXA2XX_CS_ASSERT));
343 static struct pxa2xx_spi_chip spitz_max1111_chip = {
344 .cs_control = spitz_max1111_cs,
347 static struct spi_board_info spitz_spi_devices[] = {
349 .modalias = "ads7846",
350 .max_speed_hz = 1200000,
351 .bus_num = 2,
352 .chip_select = 0,
353 .platform_data = &spitz_ads7846_info,
354 .controller_data= &spitz_ads7846_chip,
355 .irq = gpio_to_irq(SPITZ_GPIO_TP_INT),
356 }, {
357 .modalias = "corgi-lcd",
358 .max_speed_hz = 50000,
359 .bus_num = 2,
360 .chip_select = 1,
361 .platform_data = &spitz_lcdcon_info,
362 .controller_data= &spitz_lcdcon_chip,
363 }, {
364 .modalias = "max1111",
365 .max_speed_hz = 450000,
366 .bus_num = 2,
367 .chip_select = 2,
368 .controller_data= &spitz_max1111_chip,
372 static void __init spitz_init_spi(void)
374 int err;
376 err = gpio_request(SPITZ_GPIO_ADS7846_CS, "ADS7846_CS");
377 if (err)
378 return;
380 err = gpio_request(SPITZ_GPIO_LCDCON_CS, "LCDCON_CS");
381 if (err)
382 goto err_free_1;
384 err = gpio_request(SPITZ_GPIO_MAX1111_CS, "MAX1111_CS");
385 if (err)
386 goto err_free_2;
388 if (machine_is_akita()) {
389 spitz_lcdcon_info.gpio_backlight_cont = AKITA_GPIO_BACKLIGHT_CONT;
390 spitz_lcdcon_info.gpio_backlight_on = AKITA_GPIO_BACKLIGHT_ON;
393 pxa2xx_set_spi_info(2, &spitz_spi_info);
394 spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices));
395 return;
397 err_free_2:
398 gpio_free(SPITZ_GPIO_LCDCON_CS);
399 err_free_1:
400 gpio_free(SPITZ_GPIO_ADS7846_CS);
402 #else
403 static inline void spitz_init_spi(void) {}
404 #endif
407 * MMC/SD Device
409 * The card detect interrupt isn't debounced so we delay it by 250ms
410 * to give the card a chance to fully insert/eject.
413 static struct pxamci_platform_data spitz_mci_platform_data;
415 static int spitz_mci_init(struct device *dev, irq_handler_t spitz_detect_int, void *data)
417 int err;
419 err = gpio_request(SPITZ_GPIO_nSD_DETECT, "nSD_DETECT");
420 if (err)
421 goto err_out;
423 err = gpio_request(SPITZ_GPIO_nSD_WP, "nSD_WP");
424 if (err)
425 goto err_free_1;
427 gpio_direction_input(SPITZ_GPIO_nSD_DETECT);
428 gpio_direction_input(SPITZ_GPIO_nSD_WP);
430 spitz_mci_platform_data.detect_delay = msecs_to_jiffies(250);
432 err = request_irq(SPITZ_IRQ_GPIO_nSD_DETECT, spitz_detect_int,
433 IRQF_DISABLED | IRQF_TRIGGER_RISING |
434 IRQF_TRIGGER_FALLING,
435 "MMC card detect", data);
436 if (err) {
437 pr_err("%s: MMC/SD: can't request MMC card detect IRQ\n",
438 __func__);
439 goto err_free_2;
441 return 0;
443 err_free_2:
444 gpio_free(SPITZ_GPIO_nSD_WP);
445 err_free_1:
446 gpio_free(SPITZ_GPIO_nSD_DETECT);
447 err_out:
448 return err;
451 static void spitz_mci_setpower(struct device *dev, unsigned int vdd)
453 struct pxamci_platform_data* p_d = dev->platform_data;
455 if (( 1 << vdd) & p_d->ocr_mask)
456 spitz_card_pwr_ctrl(SPITZ_PWR_SD, 0x0004);
457 else
458 spitz_card_pwr_ctrl(SPITZ_PWR_SD, 0x0000);
461 static int spitz_mci_get_ro(struct device *dev)
463 return gpio_get_value(SPITZ_GPIO_nSD_WP);
466 static void spitz_mci_exit(struct device *dev, void *data)
468 free_irq(SPITZ_IRQ_GPIO_nSD_DETECT, data);
469 gpio_free(SPITZ_GPIO_nSD_WP);
470 gpio_free(SPITZ_GPIO_nSD_DETECT);
473 static struct pxamci_platform_data spitz_mci_platform_data = {
474 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
475 .init = spitz_mci_init,
476 .get_ro = spitz_mci_get_ro,
477 .setpower = spitz_mci_setpower,
478 .exit = spitz_mci_exit,
483 * USB Host (OHCI)
485 static int spitz_ohci_init(struct device *dev)
487 int err;
489 err = gpio_request(SPITZ_GPIO_USB_HOST, "USB_HOST");
490 if (err)
491 return err;
493 /* Only Port 2 is connected
494 * Setup USB Port 2 Output Control Register
496 UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE;
498 return gpio_direction_output(SPITZ_GPIO_USB_HOST, 1);
501 static struct pxaohci_platform_data spitz_ohci_platform_data = {
502 .port_mode = PMM_NPS_MODE,
503 .init = spitz_ohci_init,
504 .flags = ENABLE_PORT_ALL | NO_OC_PROTECTION,
505 .power_budget = 150,
510 * Irda
512 static int spitz_irda_startup(struct device *dev)
514 int rc;
516 rc = gpio_request(SPITZ_GPIO_IR_ON, "IrDA on");
517 if (rc)
518 goto err;
520 rc = gpio_direction_output(SPITZ_GPIO_IR_ON, 1);
521 if (rc)
522 goto err_dir;
524 return 0;
526 err_dir:
527 gpio_free(SPITZ_GPIO_IR_ON);
528 err:
529 return rc;
532 static void spitz_irda_shutdown(struct device *dev)
534 gpio_free(SPITZ_GPIO_IR_ON);
537 static void spitz_irda_transceiver_mode(struct device *dev, int mode)
539 gpio_set_value(SPITZ_GPIO_IR_ON, mode & IR_OFF);
540 pxa2xx_transceiver_mode(dev, mode);
543 #ifdef CONFIG_MACH_AKITA
544 static void akita_irda_transceiver_mode(struct device *dev, int mode)
546 gpio_set_value(AKITA_GPIO_IR_ON, mode & IR_OFF);
547 pxa2xx_transceiver_mode(dev, mode);
549 #endif
551 static struct pxaficp_platform_data spitz_ficp_platform_data = {
552 .transceiver_cap = IR_SIRMODE | IR_OFF,
553 .transceiver_mode = spitz_irda_transceiver_mode,
554 .startup = spitz_irda_startup,
555 .shutdown = spitz_irda_shutdown,
560 * Spitz PXA Framebuffer
563 static struct pxafb_mode_info spitz_pxafb_modes[] = {
565 .pixclock = 19231,
566 .xres = 480,
567 .yres = 640,
568 .bpp = 16,
569 .hsync_len = 40,
570 .left_margin = 46,
571 .right_margin = 125,
572 .vsync_len = 3,
573 .upper_margin = 1,
574 .lower_margin = 0,
575 .sync = 0,
577 .pixclock = 134617,
578 .xres = 240,
579 .yres = 320,
580 .bpp = 16,
581 .hsync_len = 20,
582 .left_margin = 20,
583 .right_margin = 46,
584 .vsync_len = 2,
585 .upper_margin = 1,
586 .lower_margin = 0,
587 .sync = 0,
591 static struct pxafb_mach_info spitz_pxafb_info = {
592 .modes = &spitz_pxafb_modes[0],
593 .num_modes = 2,
594 .fixed_modes = 1,
595 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_ALTERNATE_MAPPING,
599 static struct platform_device *devices[] __initdata = {
600 &spitzscoop_device,
601 &spitzkbd_device,
602 &spitzled_device,
605 static void spitz_poweroff(void)
607 arm_machine_restart('g');
610 static void spitz_restart(char mode)
612 /* Bootloader magic for a reboot */
613 if((MSC0 & 0xffff0000) == 0x7ff00000)
614 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
616 spitz_poweroff();
619 static void __init common_init(void)
621 init_gpio_reset(SPITZ_GPIO_ON_RESET, 1);
622 pm_power_off = spitz_poweroff;
623 arm_pm_restart = spitz_restart;
625 PMCR = 0x00;
627 /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
628 PCFR |= PCFR_OPDE;
630 pxa2xx_mfp_config(ARRAY_AND_SIZE(spitz_pin_config));
632 spitz_init_spi();
634 platform_add_devices(devices, ARRAY_SIZE(devices));
635 pxa_set_mci_info(&spitz_mci_platform_data);
636 pxa_set_ohci_info(&spitz_ohci_platform_data);
637 pxa_set_ficp_info(&spitz_ficp_platform_data);
638 set_pxa_fb_info(&spitz_pxafb_info);
639 pxa_set_i2c_info(NULL);
642 #if defined(CONFIG_MACH_SPITZ) || defined(CONFIG_MACH_BORZOI)
643 static void __init spitz_init(void)
645 platform_scoop_config = &spitz_pcmcia_config;
647 common_init();
649 platform_device_register(&spitzscoop2_device);
651 #endif
653 #ifdef CONFIG_MACH_AKITA
655 * Akita IO Expander
657 static struct pca953x_platform_data akita_ioexp = {
658 .gpio_base = AKITA_IOEXP_GPIO_BASE,
661 static struct i2c_board_info akita_i2c_board_info[] = {
663 .type = "max7310",
664 .addr = 0x18,
665 .platform_data = &akita_ioexp,
669 static void __init akita_init(void)
671 spitz_ficp_platform_data.transceiver_mode = akita_irda_transceiver_mode;
673 /* We just pretend the second element of the array doesn't exist */
674 spitz_pcmcia_config.num_devs = 1;
675 platform_scoop_config = &spitz_pcmcia_config;
677 pxa_set_i2c_info(NULL);
678 i2c_register_board_info(0, ARRAY_AND_SIZE(akita_i2c_board_info));
680 common_init();
682 #endif
684 static void __init fixup_spitz(struct machine_desc *desc,
685 struct tag *tags, char **cmdline, struct meminfo *mi)
687 sharpsl_save_param();
688 mi->nr_banks = 1;
689 mi->bank[0].start = 0xa0000000;
690 mi->bank[0].node = 0;
691 mi->bank[0].size = (64*1024*1024);
694 #ifdef CONFIG_MACH_SPITZ
695 MACHINE_START(SPITZ, "SHARP Spitz")
696 .phys_io = 0x40000000,
697 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
698 .fixup = fixup_spitz,
699 .map_io = pxa_map_io,
700 .init_irq = pxa27x_init_irq,
701 .init_machine = spitz_init,
702 .timer = &pxa_timer,
703 MACHINE_END
704 #endif
706 #ifdef CONFIG_MACH_BORZOI
707 MACHINE_START(BORZOI, "SHARP Borzoi")
708 .phys_io = 0x40000000,
709 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
710 .fixup = fixup_spitz,
711 .map_io = pxa_map_io,
712 .init_irq = pxa27x_init_irq,
713 .init_machine = spitz_init,
714 .timer = &pxa_timer,
715 MACHINE_END
716 #endif
718 #ifdef CONFIG_MACH_AKITA
719 MACHINE_START(AKITA, "SHARP Akita")
720 .phys_io = 0x40000000,
721 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
722 .fixup = fixup_spitz,
723 .map_io = pxa_map_io,
724 .init_irq = pxa27x_init_irq,
725 .init_machine = akita_init,
726 .timer = &pxa_timer,
727 MACHINE_END
728 #endif