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>
21 #include <linux/interrupt.h>
22 #include <linux/gpio.h>
23 #include <linux/leds.h>
24 #include <linux/mmc/host.h>
25 #include <linux/mtd/physmap.h>
27 #include <linux/backlight.h>
29 #include <linux/i2c.h>
30 #include <linux/i2c/pca953x.h>
31 #include <linux/spi/spi.h>
32 #include <linux/spi/ads7846.h>
33 #include <linux/spi/corgi_lcd.h>
34 #include <linux/mtd/sharpsl.h>
36 #include <asm/setup.h>
37 #include <asm/memory.h>
38 #include <asm/mach-types.h>
39 #include <mach/hardware.h>
41 #include <asm/system.h>
43 #include <asm/mach/arch.h>
44 #include <asm/mach/map.h>
45 #include <asm/mach/irq.h>
47 #include <mach/pxa-regs.h>
48 #include <mach/pxa2xx-regs.h>
49 #include <mach/mfp-pxa27x.h>
50 #include <mach/pxa27x-udc.h>
51 #include <mach/reset.h>
53 #include <mach/irda.h>
55 #include <mach/ohci.h>
57 #include <mach/pxafb.h>
58 #include <mach/pxa2xx_spi.h>
59 #include <mach/spitz.h>
60 #include <mach/sharpsl.h>
62 #include <asm/mach/sharpsl_param.h>
63 #include <asm/hardware/scoop.h>
69 static unsigned long spitz_pin_config
[] __initdata
= {
71 GPIO78_nCS_2
, /* SCOOP #2 */
72 GPIO79_nCS_3
, /* NAND */
73 GPIO80_nCS_4
, /* SCOOP #1 */
75 /* LCD - 16bpp Active TFT */
109 GPIO28_I2S_BITCLK_OUT
,
111 GPIO30_I2S_SDATA_OUT
,
123 GPIO9_GPIO
, /* SPITZ_GPIO_nSD_DETECT */
124 GPIO81_GPIO
, /* SPITZ_GPIO_nSD_WP */
125 GPIO41_GPIO
, /* SPITZ_GPIO_USB_CONNECT */
126 GPIO37_GPIO
, /* SPITZ_GPIO_USB_HOST */
127 GPIO35_GPIO
, /* SPITZ_GPIO_USB_DEVICE */
128 GPIO22_GPIO
, /* SPITZ_GPIO_HSYNC */
129 GPIO94_GPIO
, /* SPITZ_GPIO_CF_CD */
130 GPIO105_GPIO
, /* SPITZ_GPIO_CF_IRQ */
131 GPIO106_GPIO
, /* SPITZ_GPIO_CF2_IRQ */
137 GPIO1_GPIO
| WAKEUP_ON_EDGE_RISE
,
141 * Spitz SCOOP Device #1
143 static struct resource spitz_scoop_resources
[] = {
147 .flags
= IORESOURCE_MEM
,
151 static struct scoop_config spitz_scoop_setup
= {
152 .io_dir
= SPITZ_SCP_IO_DIR
,
153 .io_out
= SPITZ_SCP_IO_OUT
,
154 .suspend_clr
= SPITZ_SCP_SUS_CLR
,
155 .suspend_set
= SPITZ_SCP_SUS_SET
,
156 .gpio_base
= SPITZ_SCP_GPIO_BASE
,
159 struct platform_device spitzscoop_device
= {
160 .name
= "sharp-scoop",
163 .platform_data
= &spitz_scoop_setup
,
165 .num_resources
= ARRAY_SIZE(spitz_scoop_resources
),
166 .resource
= spitz_scoop_resources
,
170 * Spitz SCOOP Device #2
172 static struct resource spitz_scoop2_resources
[] = {
176 .flags
= IORESOURCE_MEM
,
180 static struct scoop_config spitz_scoop2_setup
= {
181 .io_dir
= SPITZ_SCP2_IO_DIR
,
182 .io_out
= SPITZ_SCP2_IO_OUT
,
183 .suspend_clr
= SPITZ_SCP2_SUS_CLR
,
184 .suspend_set
= SPITZ_SCP2_SUS_SET
,
185 .gpio_base
= SPITZ_SCP2_GPIO_BASE
,
188 struct platform_device spitzscoop2_device
= {
189 .name
= "sharp-scoop",
192 .platform_data
= &spitz_scoop2_setup
,
194 .num_resources
= ARRAY_SIZE(spitz_scoop2_resources
),
195 .resource
= spitz_scoop2_resources
,
198 #define SPITZ_PWR_SD 0x01
199 #define SPITZ_PWR_CF 0x02
201 /* Power control is shared with between one of the CF slots and SD */
202 static void spitz_card_pwr_ctrl(int device
, unsigned short new_cpr
)
204 unsigned short cpr
= read_scoop_reg(&spitzscoop_device
.dev
, SCOOP_CPR
);
206 if (new_cpr
& 0x0007) {
207 gpio_set_value(SPITZ_GPIO_CF_POWER
, 1);
208 if (!(cpr
& 0x0002) && !(cpr
& 0x0004))
210 if (device
== SPITZ_PWR_CF
)
212 if (device
== SPITZ_PWR_SD
)
214 write_scoop_reg(&spitzscoop_device
.dev
, SCOOP_CPR
, cpr
| new_cpr
);
216 if (device
== SPITZ_PWR_CF
)
218 if (device
== SPITZ_PWR_SD
)
220 if (!(cpr
& 0x0002) && !(cpr
& 0x0004)) {
221 write_scoop_reg(&spitzscoop_device
.dev
, SCOOP_CPR
, 0x0000);
223 gpio_set_value(SPITZ_GPIO_CF_POWER
, 0);
225 write_scoop_reg(&spitzscoop_device
.dev
, SCOOP_CPR
, cpr
| new_cpr
);
230 static void spitz_pcmcia_pwr(struct device
*scoop
, unsigned short cpr
, int nr
)
232 /* Only need to override behaviour for slot 0 */
234 spitz_card_pwr_ctrl(SPITZ_PWR_CF
, cpr
);
236 write_scoop_reg(scoop
, SCOOP_CPR
, cpr
);
239 static struct scoop_pcmcia_dev spitz_pcmcia_scoop
[] = {
241 .dev
= &spitzscoop_device
.dev
,
242 .irq
= SPITZ_IRQ_GPIO_CF_IRQ
,
243 .cd_irq
= SPITZ_IRQ_GPIO_CF_CD
,
244 .cd_irq_str
= "PCMCIA0 CD",
246 .dev
= &spitzscoop2_device
.dev
,
247 .irq
= SPITZ_IRQ_GPIO_CF2_IRQ
,
252 static struct scoop_pcmcia_config spitz_pcmcia_config
= {
253 .devs
= &spitz_pcmcia_scoop
[0],
255 .power_ctrl
= spitz_pcmcia_pwr
,
258 EXPORT_SYMBOL(spitzscoop_device
);
259 EXPORT_SYMBOL(spitzscoop2_device
);
262 * Spitz Keyboard Device
264 static struct platform_device spitzkbd_device
= {
265 .name
= "spitz-keyboard",
273 static struct gpio_led spitz_gpio_leds
[] = {
275 .name
= "spitz:amber:charge",
276 .default_trigger
= "sharpsl-charge",
277 .gpio
= SPITZ_GPIO_LED_ORANGE
,
280 .name
= "spitz:green:hddactivity",
281 .default_trigger
= "ide-disk",
282 .gpio
= SPITZ_GPIO_LED_GREEN
,
286 static struct gpio_led_platform_data spitz_gpio_leds_info
= {
287 .leds
= spitz_gpio_leds
,
288 .num_leds
= ARRAY_SIZE(spitz_gpio_leds
),
291 static struct platform_device spitzled_device
= {
295 .platform_data
= &spitz_gpio_leds_info
,
299 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
300 static struct pxa2xx_spi_master spitz_spi_info
= {
304 static struct ads7846_platform_data spitz_ads7846_info
= {
306 .vref_delay_usecs
= 100,
309 .gpio_pendown
= SPITZ_GPIO_TP_INT
,
312 static void spitz_ads7846_cs(u32 command
)
314 gpio_set_value(SPITZ_GPIO_ADS7846_CS
, !(command
== PXA2XX_CS_ASSERT
));
317 static struct pxa2xx_spi_chip spitz_ads7846_chip
= {
318 .cs_control
= spitz_ads7846_cs
,
321 static void spitz_bl_kick_battery(void)
323 void (*kick_batt
)(void);
325 kick_batt
= symbol_get(sharpsl_battery_kick
);
328 symbol_put(sharpsl_battery_kick
);
332 static struct corgi_lcd_platform_data spitz_lcdcon_info
= {
333 .init_mode
= CORGI_LCD_MODE_VGA
,
334 .max_intensity
= 0x2f,
335 .default_intensity
= 0x1f,
337 .gpio_backlight_cont
= SPITZ_GPIO_BACKLIGHT_CONT
,
338 .gpio_backlight_on
= SPITZ_GPIO_BACKLIGHT_ON
,
339 .kick_battery
= spitz_bl_kick_battery
,
342 static void spitz_lcdcon_cs(u32 command
)
344 gpio_set_value(SPITZ_GPIO_LCDCON_CS
, !(command
== PXA2XX_CS_ASSERT
));
347 static struct pxa2xx_spi_chip spitz_lcdcon_chip
= {
348 .cs_control
= spitz_lcdcon_cs
,
351 static void spitz_max1111_cs(u32 command
)
353 gpio_set_value(SPITZ_GPIO_MAX1111_CS
, !(command
== PXA2XX_CS_ASSERT
));
356 static struct pxa2xx_spi_chip spitz_max1111_chip
= {
357 .cs_control
= spitz_max1111_cs
,
360 static struct spi_board_info spitz_spi_devices
[] = {
362 .modalias
= "ads7846",
363 .max_speed_hz
= 1200000,
366 .platform_data
= &spitz_ads7846_info
,
367 .controller_data
= &spitz_ads7846_chip
,
368 .irq
= gpio_to_irq(SPITZ_GPIO_TP_INT
),
370 .modalias
= "corgi-lcd",
371 .max_speed_hz
= 50000,
374 .platform_data
= &spitz_lcdcon_info
,
375 .controller_data
= &spitz_lcdcon_chip
,
377 .modalias
= "max1111",
378 .max_speed_hz
= 450000,
381 .controller_data
= &spitz_max1111_chip
,
385 static void __init
spitz_init_spi(void)
389 err
= gpio_request(SPITZ_GPIO_ADS7846_CS
, "ADS7846_CS");
393 err
= gpio_request(SPITZ_GPIO_LCDCON_CS
, "LCDCON_CS");
397 err
= gpio_request(SPITZ_GPIO_MAX1111_CS
, "MAX1111_CS");
401 err
= gpio_direction_output(SPITZ_GPIO_ADS7846_CS
, 1);
404 err
= gpio_direction_output(SPITZ_GPIO_LCDCON_CS
, 1);
407 err
= gpio_direction_output(SPITZ_GPIO_MAX1111_CS
, 1);
411 if (machine_is_akita()) {
412 spitz_lcdcon_info
.gpio_backlight_cont
= AKITA_GPIO_BACKLIGHT_CONT
;
413 spitz_lcdcon_info
.gpio_backlight_on
= AKITA_GPIO_BACKLIGHT_ON
;
416 pxa2xx_set_spi_info(2, &spitz_spi_info
);
417 spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices
));
421 gpio_free(SPITZ_GPIO_MAX1111_CS
);
423 gpio_free(SPITZ_GPIO_LCDCON_CS
);
425 gpio_free(SPITZ_GPIO_ADS7846_CS
);
428 static inline void spitz_init_spi(void) {}
434 * The card detect interrupt isn't debounced so we delay it by 250ms
435 * to give the card a chance to fully insert/eject.
438 static struct pxamci_platform_data spitz_mci_platform_data
;
440 static int spitz_mci_init(struct device
*dev
, irq_handler_t spitz_detect_int
, void *data
)
444 err
= gpio_request(SPITZ_GPIO_nSD_DETECT
, "nSD_DETECT");
448 err
= gpio_request(SPITZ_GPIO_nSD_WP
, "nSD_WP");
452 gpio_direction_input(SPITZ_GPIO_nSD_DETECT
);
453 gpio_direction_input(SPITZ_GPIO_nSD_WP
);
455 spitz_mci_platform_data
.detect_delay
= msecs_to_jiffies(250);
457 err
= request_irq(SPITZ_IRQ_GPIO_nSD_DETECT
, spitz_detect_int
,
458 IRQF_DISABLED
| IRQF_TRIGGER_RISING
|
459 IRQF_TRIGGER_FALLING
,
460 "MMC card detect", data
);
462 pr_err("%s: MMC/SD: can't request MMC card detect IRQ\n",
469 gpio_free(SPITZ_GPIO_nSD_WP
);
471 gpio_free(SPITZ_GPIO_nSD_DETECT
);
476 static void spitz_mci_setpower(struct device
*dev
, unsigned int vdd
)
478 struct pxamci_platform_data
* p_d
= dev
->platform_data
;
480 if (( 1 << vdd
) & p_d
->ocr_mask
)
481 spitz_card_pwr_ctrl(SPITZ_PWR_SD
, 0x0004);
483 spitz_card_pwr_ctrl(SPITZ_PWR_SD
, 0x0000);
486 static int spitz_mci_get_ro(struct device
*dev
)
488 return gpio_get_value(SPITZ_GPIO_nSD_WP
);
491 static void spitz_mci_exit(struct device
*dev
, void *data
)
493 free_irq(SPITZ_IRQ_GPIO_nSD_DETECT
, data
);
494 gpio_free(SPITZ_GPIO_nSD_WP
);
495 gpio_free(SPITZ_GPIO_nSD_DETECT
);
498 static struct pxamci_platform_data spitz_mci_platform_data
= {
499 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
500 .init
= spitz_mci_init
,
501 .get_ro
= spitz_mci_get_ro
,
502 .setpower
= spitz_mci_setpower
,
503 .exit
= spitz_mci_exit
,
510 static int spitz_ohci_init(struct device
*dev
)
514 err
= gpio_request(SPITZ_GPIO_USB_HOST
, "USB_HOST");
518 /* Only Port 2 is connected
519 * Setup USB Port 2 Output Control Register
521 UP2OCR
= UP2OCR_HXS
| UP2OCR_HXOE
| UP2OCR_DPPDE
| UP2OCR_DMPDE
;
523 return gpio_direction_output(SPITZ_GPIO_USB_HOST
, 1);
526 static struct pxaohci_platform_data spitz_ohci_platform_data
= {
527 .port_mode
= PMM_NPS_MODE
,
528 .init
= spitz_ohci_init
,
529 .flags
= ENABLE_PORT_ALL
| NO_OC_PROTECTION
,
537 static int spitz_irda_startup(struct device
*dev
)
541 rc
= gpio_request(SPITZ_GPIO_IR_ON
, "IrDA on");
545 rc
= gpio_direction_output(SPITZ_GPIO_IR_ON
, 1);
552 gpio_free(SPITZ_GPIO_IR_ON
);
557 static void spitz_irda_shutdown(struct device
*dev
)
559 gpio_free(SPITZ_GPIO_IR_ON
);
562 static void spitz_irda_transceiver_mode(struct device
*dev
, int mode
)
564 gpio_set_value(SPITZ_GPIO_IR_ON
, mode
& IR_OFF
);
565 pxa2xx_transceiver_mode(dev
, mode
);
568 #ifdef CONFIG_MACH_AKITA
569 static void akita_irda_transceiver_mode(struct device
*dev
, int mode
)
571 gpio_set_value(AKITA_GPIO_IR_ON
, mode
& IR_OFF
);
572 pxa2xx_transceiver_mode(dev
, mode
);
576 static struct pxaficp_platform_data spitz_ficp_platform_data
= {
577 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
578 .transceiver_mode
= spitz_irda_transceiver_mode
,
579 .startup
= spitz_irda_startup
,
580 .shutdown
= spitz_irda_shutdown
,
585 * Spitz PXA Framebuffer
588 static struct pxafb_mode_info spitz_pxafb_modes
[] = {
616 static struct pxafb_mach_info spitz_pxafb_info
= {
617 .modes
= &spitz_pxafb_modes
[0],
620 .lcd_conn
= LCD_COLOR_TFT_16BPP
| LCD_ALTERNATE_MAPPING
,
623 static struct mtd_partition sharpsl_nand_partitions
[] = {
625 .name
= "System Area",
627 .size
= 7 * 1024 * 1024,
630 .name
= "Root Filesystem",
631 .offset
= 7 * 1024 * 1024,
634 .name
= "Home Filesystem",
635 .offset
= MTDPART_OFS_APPEND
,
636 .size
= MTDPART_SIZ_FULL
,
640 static uint8_t scan_ff_pattern
[] = { 0xff, 0xff };
642 static struct nand_bbt_descr sharpsl_bbt
= {
646 .pattern
= scan_ff_pattern
649 static struct sharpsl_nand_platform_data sharpsl_nand_platform_data
= {
650 .badblock_pattern
= &sharpsl_bbt
,
651 .partitions
= sharpsl_nand_partitions
,
652 .nr_partitions
= ARRAY_SIZE(sharpsl_nand_partitions
),
655 static struct resource sharpsl_nand_resources
[] = {
659 .flags
= IORESOURCE_MEM
,
663 static struct platform_device sharpsl_nand_device
= {
664 .name
= "sharpsl-nand",
666 .resource
= sharpsl_nand_resources
,
667 .num_resources
= ARRAY_SIZE(sharpsl_nand_resources
),
668 .dev
.platform_data
= &sharpsl_nand_platform_data
,
672 static struct mtd_partition sharpsl_rom_parts
[] = {
674 .name
="Boot PROM Filesystem",
675 .offset
= 0x00140000,
676 .size
= MTDPART_SIZ_FULL
,
680 static struct physmap_flash_data sharpsl_rom_data
= {
682 .nr_parts
= ARRAY_SIZE(sharpsl_rom_parts
),
683 .parts
= sharpsl_rom_parts
,
686 static struct resource sharpsl_rom_resources
[] = {
690 .flags
= IORESOURCE_MEM
,
694 static struct platform_device sharpsl_rom_device
= {
695 .name
= "physmap-flash",
697 .resource
= sharpsl_rom_resources
,
698 .num_resources
= ARRAY_SIZE(sharpsl_rom_resources
),
699 .dev
.platform_data
= &sharpsl_rom_data
,
702 static struct platform_device
*devices
[] __initdata
= {
706 &sharpsl_nand_device
,
710 static void spitz_poweroff(void)
712 arm_machine_restart('g');
715 static void spitz_restart(char mode
)
717 /* Bootloader magic for a reboot */
718 if((MSC0
& 0xffff0000) == 0x7ff00000)
719 MSC0
= (MSC0
& 0xffff) | 0x7ee00000;
724 static void __init
common_init(void)
726 init_gpio_reset(SPITZ_GPIO_ON_RESET
, 1);
727 pm_power_off
= spitz_poweroff
;
728 arm_pm_restart
= spitz_restart
;
730 if (machine_is_spitz()) {
731 sharpsl_nand_partitions
[1].size
= 5 * 1024 * 1024;
732 } else if (machine_is_akita()) {
733 sharpsl_nand_partitions
[1].size
= 58 * 1024 * 1024;
734 } else if (machine_is_borzoi()) {
735 sharpsl_nand_partitions
[1].size
= 32 * 1024 * 1024;
740 /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
743 pxa2xx_mfp_config(ARRAY_AND_SIZE(spitz_pin_config
));
747 platform_add_devices(devices
, ARRAY_SIZE(devices
));
748 pxa_set_mci_info(&spitz_mci_platform_data
);
749 pxa_set_ohci_info(&spitz_ohci_platform_data
);
750 pxa_set_ficp_info(&spitz_ficp_platform_data
);
751 set_pxa_fb_info(&spitz_pxafb_info
);
752 pxa_set_i2c_info(NULL
);
755 #if defined(CONFIG_MACH_SPITZ) || defined(CONFIG_MACH_BORZOI)
756 static void __init
spitz_init(void)
758 platform_scoop_config
= &spitz_pcmcia_config
;
762 platform_device_register(&spitzscoop2_device
);
766 #ifdef CONFIG_MACH_AKITA
770 static struct pca953x_platform_data akita_ioexp
= {
771 .gpio_base
= AKITA_IOEXP_GPIO_BASE
,
774 static struct i2c_board_info akita_i2c_board_info
[] = {
778 .platform_data
= &akita_ioexp
,
782 static struct nand_bbt_descr sharpsl_akita_bbt
= {
786 .pattern
= scan_ff_pattern
789 static struct nand_ecclayout akita_oobinfo
= {
792 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11,
793 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23,
794 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37},
795 .oobfree
= {{0x08, 0x09}}
798 static void __init
akita_init(void)
800 spitz_ficp_platform_data
.transceiver_mode
= akita_irda_transceiver_mode
;
802 sharpsl_nand_platform_data
.badblock_pattern
= &sharpsl_akita_bbt
;
803 sharpsl_nand_platform_data
.ecc_layout
= &akita_oobinfo
;
805 /* We just pretend the second element of the array doesn't exist */
806 spitz_pcmcia_config
.num_devs
= 1;
807 platform_scoop_config
= &spitz_pcmcia_config
;
809 i2c_register_board_info(0, ARRAY_AND_SIZE(akita_i2c_board_info
));
815 static void __init
fixup_spitz(struct machine_desc
*desc
,
816 struct tag
*tags
, char **cmdline
, struct meminfo
*mi
)
818 sharpsl_save_param();
820 mi
->bank
[0].start
= 0xa0000000;
821 mi
->bank
[0].node
= 0;
822 mi
->bank
[0].size
= (64*1024*1024);
825 #ifdef CONFIG_MACH_SPITZ
826 MACHINE_START(SPITZ
, "SHARP Spitz")
827 .phys_io
= 0x40000000,
828 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
829 .fixup
= fixup_spitz
,
830 .map_io
= pxa_map_io
,
831 .init_irq
= pxa27x_init_irq
,
832 .init_machine
= spitz_init
,
837 #ifdef CONFIG_MACH_BORZOI
838 MACHINE_START(BORZOI
, "SHARP Borzoi")
839 .phys_io
= 0x40000000,
840 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
841 .fixup
= fixup_spitz
,
842 .map_io
= pxa_map_io
,
843 .init_irq
= pxa27x_init_irq
,
844 .init_machine
= spitz_init
,
849 #ifdef CONFIG_MACH_AKITA
850 MACHINE_START(AKITA
, "SHARP Akita")
851 .phys_io
= 0x40000000,
852 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
853 .fixup
= fixup_spitz
,
854 .map_io
= pxa_map_io
,
855 .init_irq
= pxa27x_init_irq
,
856 .init_machine
= akita_init
,