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/pxa27x.h>
48 #include <mach/pxa27x-udc.h>
49 #include <mach/reset.h>
51 #include <mach/irda.h>
53 #include <mach/ohci.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>
67 static unsigned long spitz_pin_config
[] __initdata
= {
69 GPIO78_nCS_2
, /* SCOOP #2 */
70 GPIO79_nCS_3
, /* NAND */
71 GPIO80_nCS_4
, /* SCOOP #1 */
73 /* LCD - 16bpp Active TFT */
107 GPIO28_I2S_BITCLK_OUT
,
109 GPIO30_I2S_SDATA_OUT
,
121 GPIO9_GPIO
, /* SPITZ_GPIO_nSD_DETECT */
122 GPIO81_GPIO
, /* SPITZ_GPIO_nSD_WP */
123 GPIO41_GPIO
, /* SPITZ_GPIO_USB_CONNECT */
124 GPIO37_GPIO
, /* SPITZ_GPIO_USB_HOST */
125 GPIO35_GPIO
, /* SPITZ_GPIO_USB_DEVICE */
126 GPIO22_GPIO
, /* SPITZ_GPIO_HSYNC */
127 GPIO94_GPIO
, /* SPITZ_GPIO_CF_CD */
128 GPIO105_GPIO
, /* SPITZ_GPIO_CF_IRQ */
129 GPIO106_GPIO
, /* SPITZ_GPIO_CF2_IRQ */
135 GPIO1_GPIO
| WAKEUP_ON_EDGE_RISE
,
139 * Spitz SCOOP Device #1
141 static struct resource spitz_scoop_resources
[] = {
145 .flags
= IORESOURCE_MEM
,
149 static struct scoop_config spitz_scoop_setup
= {
150 .io_dir
= SPITZ_SCP_IO_DIR
,
151 .io_out
= SPITZ_SCP_IO_OUT
,
152 .suspend_clr
= SPITZ_SCP_SUS_CLR
,
153 .suspend_set
= SPITZ_SCP_SUS_SET
,
154 .gpio_base
= SPITZ_SCP_GPIO_BASE
,
157 struct platform_device spitzscoop_device
= {
158 .name
= "sharp-scoop",
161 .platform_data
= &spitz_scoop_setup
,
163 .num_resources
= ARRAY_SIZE(spitz_scoop_resources
),
164 .resource
= spitz_scoop_resources
,
168 * Spitz SCOOP Device #2
170 static struct resource spitz_scoop2_resources
[] = {
174 .flags
= IORESOURCE_MEM
,
178 static struct scoop_config spitz_scoop2_setup
= {
179 .io_dir
= SPITZ_SCP2_IO_DIR
,
180 .io_out
= SPITZ_SCP2_IO_OUT
,
181 .suspend_clr
= SPITZ_SCP2_SUS_CLR
,
182 .suspend_set
= SPITZ_SCP2_SUS_SET
,
183 .gpio_base
= SPITZ_SCP2_GPIO_BASE
,
186 struct platform_device spitzscoop2_device
= {
187 .name
= "sharp-scoop",
190 .platform_data
= &spitz_scoop2_setup
,
192 .num_resources
= ARRAY_SIZE(spitz_scoop2_resources
),
193 .resource
= spitz_scoop2_resources
,
196 #define SPITZ_PWR_SD 0x01
197 #define SPITZ_PWR_CF 0x02
199 /* Power control is shared with between one of the CF slots and SD */
200 static void spitz_card_pwr_ctrl(int device
, unsigned short new_cpr
)
202 unsigned short cpr
= read_scoop_reg(&spitzscoop_device
.dev
, SCOOP_CPR
);
204 if (new_cpr
& 0x0007) {
205 gpio_set_value(SPITZ_GPIO_CF_POWER
, 1);
206 if (!(cpr
& 0x0002) && !(cpr
& 0x0004))
208 if (device
== SPITZ_PWR_CF
)
210 if (device
== SPITZ_PWR_SD
)
212 write_scoop_reg(&spitzscoop_device
.dev
, SCOOP_CPR
, cpr
| new_cpr
);
214 if (device
== SPITZ_PWR_CF
)
216 if (device
== SPITZ_PWR_SD
)
218 if (!(cpr
& 0x0002) && !(cpr
& 0x0004)) {
219 write_scoop_reg(&spitzscoop_device
.dev
, SCOOP_CPR
, 0x0000);
221 gpio_set_value(SPITZ_GPIO_CF_POWER
, 0);
223 write_scoop_reg(&spitzscoop_device
.dev
, SCOOP_CPR
, cpr
| new_cpr
);
228 static void spitz_pcmcia_pwr(struct device
*scoop
, unsigned short cpr
, int nr
)
230 /* Only need to override behaviour for slot 0 */
232 spitz_card_pwr_ctrl(SPITZ_PWR_CF
, cpr
);
234 write_scoop_reg(scoop
, SCOOP_CPR
, cpr
);
237 static struct scoop_pcmcia_dev spitz_pcmcia_scoop
[] = {
239 .dev
= &spitzscoop_device
.dev
,
240 .irq
= SPITZ_IRQ_GPIO_CF_IRQ
,
241 .cd_irq
= SPITZ_IRQ_GPIO_CF_CD
,
242 .cd_irq_str
= "PCMCIA0 CD",
244 .dev
= &spitzscoop2_device
.dev
,
245 .irq
= SPITZ_IRQ_GPIO_CF2_IRQ
,
250 static struct scoop_pcmcia_config spitz_pcmcia_config
= {
251 .devs
= &spitz_pcmcia_scoop
[0],
253 .power_ctrl
= spitz_pcmcia_pwr
,
256 EXPORT_SYMBOL(spitzscoop_device
);
257 EXPORT_SYMBOL(spitzscoop2_device
);
260 * Spitz Keyboard Device
262 static struct platform_device spitzkbd_device
= {
263 .name
= "spitz-keyboard",
271 static struct gpio_led spitz_gpio_leds
[] = {
273 .name
= "spitz:amber:charge",
274 .default_trigger
= "sharpsl-charge",
275 .gpio
= SPITZ_GPIO_LED_ORANGE
,
278 .name
= "spitz:green:hddactivity",
279 .default_trigger
= "ide-disk",
280 .gpio
= SPITZ_GPIO_LED_GREEN
,
284 static struct gpio_led_platform_data spitz_gpio_leds_info
= {
285 .leds
= spitz_gpio_leds
,
286 .num_leds
= ARRAY_SIZE(spitz_gpio_leds
),
289 static struct platform_device spitzled_device
= {
293 .platform_data
= &spitz_gpio_leds_info
,
297 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
298 static struct pxa2xx_spi_master spitz_spi_info
= {
302 static void spitz_wait_for_hsync(void)
304 while (gpio_get_value(SPITZ_GPIO_HSYNC
))
307 while (!gpio_get_value(SPITZ_GPIO_HSYNC
))
311 static struct ads7846_platform_data spitz_ads7846_info
= {
313 .vref_delay_usecs
= 100,
316 .gpio_pendown
= SPITZ_GPIO_TP_INT
,
317 .wait_for_sync
= spitz_wait_for_hsync
,
320 static void spitz_ads7846_cs(u32 command
)
322 gpio_set_value(SPITZ_GPIO_ADS7846_CS
, !(command
== PXA2XX_CS_ASSERT
));
325 static struct pxa2xx_spi_chip spitz_ads7846_chip
= {
326 .cs_control
= spitz_ads7846_cs
,
329 static void spitz_bl_kick_battery(void)
331 void (*kick_batt
)(void);
333 kick_batt
= symbol_get(sharpsl_battery_kick
);
336 symbol_put(sharpsl_battery_kick
);
340 static struct corgi_lcd_platform_data spitz_lcdcon_info
= {
341 .init_mode
= CORGI_LCD_MODE_VGA
,
342 .max_intensity
= 0x2f,
343 .default_intensity
= 0x1f,
345 .gpio_backlight_cont
= SPITZ_GPIO_BACKLIGHT_CONT
,
346 .gpio_backlight_on
= SPITZ_GPIO_BACKLIGHT_ON
,
347 .kick_battery
= spitz_bl_kick_battery
,
350 static void spitz_lcdcon_cs(u32 command
)
352 gpio_set_value(SPITZ_GPIO_LCDCON_CS
, !(command
== PXA2XX_CS_ASSERT
));
355 static struct pxa2xx_spi_chip spitz_lcdcon_chip
= {
356 .cs_control
= spitz_lcdcon_cs
,
359 static void spitz_max1111_cs(u32 command
)
361 gpio_set_value(SPITZ_GPIO_MAX1111_CS
, !(command
== PXA2XX_CS_ASSERT
));
364 static struct pxa2xx_spi_chip spitz_max1111_chip
= {
365 .cs_control
= spitz_max1111_cs
,
368 static struct spi_board_info spitz_spi_devices
[] = {
370 .modalias
= "ads7846",
371 .max_speed_hz
= 1200000,
374 .platform_data
= &spitz_ads7846_info
,
375 .controller_data
= &spitz_ads7846_chip
,
376 .irq
= gpio_to_irq(SPITZ_GPIO_TP_INT
),
378 .modalias
= "corgi-lcd",
379 .max_speed_hz
= 50000,
382 .platform_data
= &spitz_lcdcon_info
,
383 .controller_data
= &spitz_lcdcon_chip
,
385 .modalias
= "max1111",
386 .max_speed_hz
= 450000,
389 .controller_data
= &spitz_max1111_chip
,
393 static void __init
spitz_init_spi(void)
397 err
= gpio_request(SPITZ_GPIO_ADS7846_CS
, "ADS7846_CS");
401 err
= gpio_request(SPITZ_GPIO_LCDCON_CS
, "LCDCON_CS");
405 err
= gpio_request(SPITZ_GPIO_MAX1111_CS
, "MAX1111_CS");
409 err
= gpio_direction_output(SPITZ_GPIO_ADS7846_CS
, 1);
412 err
= gpio_direction_output(SPITZ_GPIO_LCDCON_CS
, 1);
415 err
= gpio_direction_output(SPITZ_GPIO_MAX1111_CS
, 1);
419 if (machine_is_akita()) {
420 spitz_lcdcon_info
.gpio_backlight_cont
= AKITA_GPIO_BACKLIGHT_CONT
;
421 spitz_lcdcon_info
.gpio_backlight_on
= AKITA_GPIO_BACKLIGHT_ON
;
424 pxa2xx_set_spi_info(2, &spitz_spi_info
);
425 spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices
));
429 gpio_free(SPITZ_GPIO_MAX1111_CS
);
431 gpio_free(SPITZ_GPIO_LCDCON_CS
);
433 gpio_free(SPITZ_GPIO_ADS7846_CS
);
436 static inline void spitz_init_spi(void) {}
442 * The card detect interrupt isn't debounced so we delay it by 250ms
443 * to give the card a chance to fully insert/eject.
446 static struct pxamci_platform_data spitz_mci_platform_data
;
448 static int spitz_mci_init(struct device
*dev
, irq_handler_t spitz_detect_int
, void *data
)
452 err
= gpio_request(SPITZ_GPIO_nSD_DETECT
, "nSD_DETECT");
456 err
= gpio_request(SPITZ_GPIO_nSD_WP
, "nSD_WP");
460 gpio_direction_input(SPITZ_GPIO_nSD_DETECT
);
461 gpio_direction_input(SPITZ_GPIO_nSD_WP
);
463 spitz_mci_platform_data
.detect_delay
= msecs_to_jiffies(250);
465 err
= request_irq(SPITZ_IRQ_GPIO_nSD_DETECT
, spitz_detect_int
,
466 IRQF_DISABLED
| IRQF_TRIGGER_RISING
|
467 IRQF_TRIGGER_FALLING
,
468 "MMC card detect", data
);
470 pr_err("%s: MMC/SD: can't request MMC card detect IRQ\n",
477 gpio_free(SPITZ_GPIO_nSD_WP
);
479 gpio_free(SPITZ_GPIO_nSD_DETECT
);
484 static void spitz_mci_setpower(struct device
*dev
, unsigned int vdd
)
486 struct pxamci_platform_data
* p_d
= dev
->platform_data
;
488 if (( 1 << vdd
) & p_d
->ocr_mask
)
489 spitz_card_pwr_ctrl(SPITZ_PWR_SD
, 0x0004);
491 spitz_card_pwr_ctrl(SPITZ_PWR_SD
, 0x0000);
494 static int spitz_mci_get_ro(struct device
*dev
)
496 return gpio_get_value(SPITZ_GPIO_nSD_WP
);
499 static void spitz_mci_exit(struct device
*dev
, void *data
)
501 free_irq(SPITZ_IRQ_GPIO_nSD_DETECT
, data
);
502 gpio_free(SPITZ_GPIO_nSD_WP
);
503 gpio_free(SPITZ_GPIO_nSD_DETECT
);
506 static struct pxamci_platform_data spitz_mci_platform_data
= {
507 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
508 .init
= spitz_mci_init
,
509 .get_ro
= spitz_mci_get_ro
,
510 .setpower
= spitz_mci_setpower
,
511 .exit
= spitz_mci_exit
,
518 static int spitz_ohci_init(struct device
*dev
)
522 err
= gpio_request(SPITZ_GPIO_USB_HOST
, "USB_HOST");
526 /* Only Port 2 is connected
527 * Setup USB Port 2 Output Control Register
529 UP2OCR
= UP2OCR_HXS
| UP2OCR_HXOE
| UP2OCR_DPPDE
| UP2OCR_DMPDE
;
531 return gpio_direction_output(SPITZ_GPIO_USB_HOST
, 1);
534 static struct pxaohci_platform_data spitz_ohci_platform_data
= {
535 .port_mode
= PMM_NPS_MODE
,
536 .init
= spitz_ohci_init
,
537 .flags
= ENABLE_PORT_ALL
| NO_OC_PROTECTION
,
545 static int spitz_irda_startup(struct device
*dev
)
549 rc
= gpio_request(SPITZ_GPIO_IR_ON
, "IrDA on");
553 rc
= gpio_direction_output(SPITZ_GPIO_IR_ON
, 1);
560 gpio_free(SPITZ_GPIO_IR_ON
);
565 static void spitz_irda_shutdown(struct device
*dev
)
567 gpio_free(SPITZ_GPIO_IR_ON
);
570 static void spitz_irda_transceiver_mode(struct device
*dev
, int mode
)
572 gpio_set_value(SPITZ_GPIO_IR_ON
, mode
& IR_OFF
);
573 pxa2xx_transceiver_mode(dev
, mode
);
576 #ifdef CONFIG_MACH_AKITA
577 static void akita_irda_transceiver_mode(struct device
*dev
, int mode
)
579 gpio_set_value(AKITA_GPIO_IR_ON
, mode
& IR_OFF
);
580 pxa2xx_transceiver_mode(dev
, mode
);
584 static struct pxaficp_platform_data spitz_ficp_platform_data
= {
585 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
586 .transceiver_mode
= spitz_irda_transceiver_mode
,
587 .startup
= spitz_irda_startup
,
588 .shutdown
= spitz_irda_shutdown
,
593 * Spitz PXA Framebuffer
596 static struct pxafb_mode_info spitz_pxafb_modes
[] = {
624 static struct pxafb_mach_info spitz_pxafb_info
= {
625 .modes
= &spitz_pxafb_modes
[0],
628 .lcd_conn
= LCD_COLOR_TFT_16BPP
| LCD_ALTERNATE_MAPPING
,
631 static struct mtd_partition sharpsl_nand_partitions
[] = {
633 .name
= "System Area",
635 .size
= 7 * 1024 * 1024,
638 .name
= "Root Filesystem",
639 .offset
= 7 * 1024 * 1024,
642 .name
= "Home Filesystem",
643 .offset
= MTDPART_OFS_APPEND
,
644 .size
= MTDPART_SIZ_FULL
,
648 static uint8_t scan_ff_pattern
[] = { 0xff, 0xff };
650 static struct nand_bbt_descr sharpsl_bbt
= {
654 .pattern
= scan_ff_pattern
657 static struct sharpsl_nand_platform_data sharpsl_nand_platform_data
= {
658 .badblock_pattern
= &sharpsl_bbt
,
659 .partitions
= sharpsl_nand_partitions
,
660 .nr_partitions
= ARRAY_SIZE(sharpsl_nand_partitions
),
663 static struct resource sharpsl_nand_resources
[] = {
667 .flags
= IORESOURCE_MEM
,
671 static struct platform_device sharpsl_nand_device
= {
672 .name
= "sharpsl-nand",
674 .resource
= sharpsl_nand_resources
,
675 .num_resources
= ARRAY_SIZE(sharpsl_nand_resources
),
676 .dev
.platform_data
= &sharpsl_nand_platform_data
,
680 static struct mtd_partition sharpsl_rom_parts
[] = {
682 .name
="Boot PROM Filesystem",
683 .offset
= 0x00140000,
684 .size
= MTDPART_SIZ_FULL
,
688 static struct physmap_flash_data sharpsl_rom_data
= {
690 .nr_parts
= ARRAY_SIZE(sharpsl_rom_parts
),
691 .parts
= sharpsl_rom_parts
,
694 static struct resource sharpsl_rom_resources
[] = {
698 .flags
= IORESOURCE_MEM
,
702 static struct platform_device sharpsl_rom_device
= {
703 .name
= "physmap-flash",
705 .resource
= sharpsl_rom_resources
,
706 .num_resources
= ARRAY_SIZE(sharpsl_rom_resources
),
707 .dev
.platform_data
= &sharpsl_rom_data
,
710 static struct platform_device
*devices
[] __initdata
= {
714 &sharpsl_nand_device
,
718 static void spitz_poweroff(void)
720 arm_machine_restart('g', NULL
);
723 static void spitz_restart(char mode
, const char *cmd
)
725 /* Bootloader magic for a reboot */
726 if((MSC0
& 0xffff0000) == 0x7ff00000)
727 MSC0
= (MSC0
& 0xffff) | 0x7ee00000;
732 static void __init
common_init(void)
734 init_gpio_reset(SPITZ_GPIO_ON_RESET
, 1);
735 pm_power_off
= spitz_poweroff
;
736 arm_pm_restart
= spitz_restart
;
738 if (machine_is_spitz()) {
739 sharpsl_nand_partitions
[1].size
= 5 * 1024 * 1024;
740 } else if (machine_is_akita()) {
741 sharpsl_nand_partitions
[1].size
= 58 * 1024 * 1024;
742 } else if (machine_is_borzoi()) {
743 sharpsl_nand_partitions
[1].size
= 32 * 1024 * 1024;
748 /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
751 pxa2xx_mfp_config(ARRAY_AND_SIZE(spitz_pin_config
));
755 platform_add_devices(devices
, ARRAY_SIZE(devices
));
756 pxa_set_mci_info(&spitz_mci_platform_data
);
757 pxa_set_ohci_info(&spitz_ohci_platform_data
);
758 pxa_set_ficp_info(&spitz_ficp_platform_data
);
759 set_pxa_fb_info(&spitz_pxafb_info
);
760 pxa_set_i2c_info(NULL
);
763 #if defined(CONFIG_MACH_SPITZ) || defined(CONFIG_MACH_BORZOI)
764 static void __init
spitz_init(void)
766 platform_scoop_config
= &spitz_pcmcia_config
;
770 platform_device_register(&spitzscoop2_device
);
774 #ifdef CONFIG_MACH_AKITA
778 static struct pca953x_platform_data akita_ioexp
= {
779 .gpio_base
= AKITA_IOEXP_GPIO_BASE
,
782 static struct i2c_board_info akita_i2c_board_info
[] = {
786 .platform_data
= &akita_ioexp
,
790 static struct nand_bbt_descr sharpsl_akita_bbt
= {
794 .pattern
= scan_ff_pattern
797 static struct nand_ecclayout akita_oobinfo
= {
800 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11,
801 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23,
802 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37},
803 .oobfree
= {{0x08, 0x09}}
806 static void __init
akita_init(void)
808 spitz_ficp_platform_data
.transceiver_mode
= akita_irda_transceiver_mode
;
810 sharpsl_nand_platform_data
.badblock_pattern
= &sharpsl_akita_bbt
;
811 sharpsl_nand_platform_data
.ecc_layout
= &akita_oobinfo
;
813 /* We just pretend the second element of the array doesn't exist */
814 spitz_pcmcia_config
.num_devs
= 1;
815 platform_scoop_config
= &spitz_pcmcia_config
;
817 i2c_register_board_info(0, ARRAY_AND_SIZE(akita_i2c_board_info
));
823 static void __init
fixup_spitz(struct machine_desc
*desc
,
824 struct tag
*tags
, char **cmdline
, struct meminfo
*mi
)
826 sharpsl_save_param();
828 mi
->bank
[0].start
= 0xa0000000;
829 mi
->bank
[0].node
= 0;
830 mi
->bank
[0].size
= (64*1024*1024);
833 #ifdef CONFIG_MACH_SPITZ
834 MACHINE_START(SPITZ
, "SHARP Spitz")
835 .phys_io
= 0x40000000,
836 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
837 .fixup
= fixup_spitz
,
838 .map_io
= pxa_map_io
,
839 .init_irq
= pxa27x_init_irq
,
840 .init_machine
= spitz_init
,
845 #ifdef CONFIG_MACH_BORZOI
846 MACHINE_START(BORZOI
, "SHARP Borzoi")
847 .phys_io
= 0x40000000,
848 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
849 .fixup
= fixup_spitz
,
850 .map_io
= pxa_map_io
,
851 .init_irq
= pxa27x_init_irq
,
852 .init_machine
= spitz_init
,
857 #ifdef CONFIG_MACH_AKITA
858 MACHINE_START(AKITA
, "SHARP Akita")
859 .phys_io
= 0x40000000,
860 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
861 .fixup
= fixup_spitz
,
862 .map_io
= pxa_map_io
,
863 .init_irq
= pxa27x_init_irq
,
864 .init_machine
= akita_init
,