Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Support for Sharp SL-C6000x PDAs |
| 3 | * Model: (Tosa) |
| 4 | * |
| 5 | * Copyright (c) 2005 Dirk Opfer |
| 6 | * |
| 7 | * Based on code written by Sharp/Lineo for 2.4 kernels |
| 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> |
Dirk Opfer | 067c904 | 2005-11-21 15:17:06 +0000 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 18 | #include <linux/major.h> |
| 19 | #include <linux/fs.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/mmc/host.h> |
Richard Purdie | 74617fb | 2006-06-19 19:57:12 +0100 | [diff] [blame] | 22 | #include <linux/pm.h> |
Russell King | 905f146 | 2006-06-20 23:27:37 +0100 | [diff] [blame] | 23 | #include <linux/delay.h> |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 24 | |
| 25 | #include <asm/setup.h> |
| 26 | #include <asm/memory.h> |
| 27 | #include <asm/mach-types.h> |
| 28 | #include <asm/hardware.h> |
| 29 | #include <asm/irq.h> |
Richard Purdie | 74617fb | 2006-06-19 19:57:12 +0100 | [diff] [blame] | 30 | #include <asm/system.h> |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 31 | #include <asm/arch/irda.h> |
| 32 | #include <asm/arch/mmc.h> |
| 33 | #include <asm/arch/udc.h> |
| 34 | |
| 35 | #include <asm/mach/arch.h> |
| 36 | #include <asm/mach/map.h> |
| 37 | #include <asm/mach/irq.h> |
| 38 | |
| 39 | #include <asm/arch/pxa-regs.h> |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 40 | #include <asm/arch/tosa.h> |
| 41 | |
| 42 | #include <asm/hardware/scoop.h> |
| 43 | #include <asm/mach/sharpsl_param.h> |
| 44 | |
| 45 | #include "generic.h" |
| 46 | |
| 47 | |
| 48 | /* |
| 49 | * SCOOP Device |
| 50 | */ |
| 51 | static struct resource tosa_scoop_resources[] = { |
| 52 | [0] = { |
| 53 | .start = TOSA_CF_PHYS, |
| 54 | .end = TOSA_CF_PHYS + 0xfff, |
| 55 | .flags = IORESOURCE_MEM, |
| 56 | }, |
| 57 | }; |
| 58 | |
| 59 | static struct scoop_config tosa_scoop_setup = { |
| 60 | .io_dir = TOSA_SCOOP_IO_DIR, |
| 61 | .io_out = TOSA_SCOOP_IO_OUT, |
| 62 | |
| 63 | }; |
| 64 | |
| 65 | struct platform_device tosascoop_device = { |
| 66 | .name = "sharp-scoop", |
| 67 | .id = 0, |
| 68 | .dev = { |
| 69 | .platform_data = &tosa_scoop_setup, |
| 70 | }, |
| 71 | .num_resources = ARRAY_SIZE(tosa_scoop_resources), |
| 72 | .resource = tosa_scoop_resources, |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | /* |
| 77 | * SCOOP Device Jacket |
| 78 | */ |
| 79 | static struct resource tosa_scoop_jc_resources[] = { |
| 80 | [0] = { |
| 81 | .start = TOSA_SCOOP_PHYS + 0x40, |
| 82 | .end = TOSA_SCOOP_PHYS + 0xfff, |
| 83 | .flags = IORESOURCE_MEM, |
| 84 | }, |
| 85 | }; |
| 86 | |
| 87 | static struct scoop_config tosa_scoop_jc_setup = { |
| 88 | .io_dir = TOSA_SCOOP_JC_IO_DIR, |
| 89 | .io_out = TOSA_SCOOP_JC_IO_OUT, |
| 90 | }; |
| 91 | |
| 92 | struct platform_device tosascoop_jc_device = { |
| 93 | .name = "sharp-scoop", |
| 94 | .id = 1, |
| 95 | .dev = { |
| 96 | .platform_data = &tosa_scoop_jc_setup, |
| 97 | .parent = &tosascoop_device.dev, |
| 98 | }, |
| 99 | .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources), |
| 100 | .resource = tosa_scoop_jc_resources, |
| 101 | }; |
| 102 | |
Dirk Opfer | 4c18ad2 | 2005-11-08 19:15:50 +0000 | [diff] [blame] | 103 | /* |
| 104 | * PCMCIA |
| 105 | */ |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 106 | static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = { |
| 107 | { |
| 108 | .dev = &tosascoop_device.dev, |
| 109 | .irq = TOSA_IRQ_GPIO_CF_IRQ, |
| 110 | .cd_irq = TOSA_IRQ_GPIO_CF_CD, |
| 111 | .cd_irq_str = "PCMCIA0 CD", |
| 112 | },{ |
| 113 | .dev = &tosascoop_jc_device.dev, |
| 114 | .irq = TOSA_IRQ_GPIO_JC_CF_IRQ, |
| 115 | .cd_irq = -1, |
| 116 | }, |
| 117 | }; |
| 118 | |
Dirk Opfer | 4c18ad2 | 2005-11-08 19:15:50 +0000 | [diff] [blame] | 119 | static void tosa_pcmcia_init(void) |
| 120 | { |
| 121 | /* Setup default state of GPIO outputs |
| 122 | before we enable them as outputs. */ |
| 123 | GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) | |
| 124 | GPIO_bit(GPIO49_nPWE) | GPIO_bit(GPIO50_nPIOR) | |
| 125 | GPIO_bit(GPIO51_nPIOW) | GPIO_bit(GPIO52_nPCE_1) | |
| 126 | GPIO_bit(GPIO53_nPCE_2); |
| 127 | |
| 128 | pxa_gpio_mode(GPIO48_nPOE_MD); |
| 129 | pxa_gpio_mode(GPIO49_nPWE_MD); |
| 130 | pxa_gpio_mode(GPIO50_nPIOR_MD); |
| 131 | pxa_gpio_mode(GPIO51_nPIOW_MD); |
| 132 | pxa_gpio_mode(GPIO55_nPREG_MD); |
| 133 | pxa_gpio_mode(GPIO56_nPWAIT_MD); |
| 134 | pxa_gpio_mode(GPIO57_nIOIS16_MD); |
| 135 | pxa_gpio_mode(GPIO52_nPCE_1_MD); |
| 136 | pxa_gpio_mode(GPIO53_nPCE_2_MD); |
| 137 | pxa_gpio_mode(GPIO54_pSKTSEL_MD); |
| 138 | } |
| 139 | |
| 140 | static struct scoop_pcmcia_config tosa_pcmcia_config = { |
| 141 | .devs = &tosa_pcmcia_scoop[0], |
| 142 | .num_devs = 2, |
| 143 | .pcmcia_init = tosa_pcmcia_init, |
| 144 | }; |
| 145 | |
Dirk Opfer | a93876c | 2005-11-08 19:15:30 +0000 | [diff] [blame] | 146 | /* |
| 147 | * USB Device Controller |
| 148 | */ |
| 149 | static void tosa_udc_command(int cmd) |
| 150 | { |
| 151 | switch(cmd) { |
| 152 | case PXA2XX_UDC_CMD_CONNECT: |
| 153 | set_scoop_gpio(&tosascoop_jc_device.dev,TOSA_SCOOP_JC_USB_PULLUP); |
| 154 | break; |
| 155 | case PXA2XX_UDC_CMD_DISCONNECT: |
| 156 | reset_scoop_gpio(&tosascoop_jc_device.dev,TOSA_SCOOP_JC_USB_PULLUP); |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | static int tosa_udc_is_connected(void) |
| 162 | { |
| 163 | return ((GPLR(TOSA_GPIO_USB_IN) & GPIO_bit(TOSA_GPIO_USB_IN)) == 0); |
| 164 | } |
| 165 | |
| 166 | |
| 167 | static struct pxa2xx_udc_mach_info udc_info __initdata = { |
| 168 | .udc_command = tosa_udc_command, |
| 169 | .udc_is_connected = tosa_udc_is_connected, |
| 170 | }; |
| 171 | |
| 172 | /* |
| 173 | * MMC/SD Device |
| 174 | */ |
| 175 | static struct pxamci_platform_data tosa_mci_platform_data; |
| 176 | |
David Howells | 40220c1 | 2006-10-09 12:19:47 +0100 | [diff] [blame^] | 177 | static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data) |
Dirk Opfer | a93876c | 2005-11-08 19:15:30 +0000 | [diff] [blame] | 178 | { |
| 179 | int err; |
| 180 | |
| 181 | /* setup GPIO for PXA25x MMC controller */ |
| 182 | pxa_gpio_mode(GPIO6_MMCCLK_MD); |
| 183 | pxa_gpio_mode(GPIO8_MMCCS0_MD); |
| 184 | pxa_gpio_mode(TOSA_GPIO_nSD_DETECT | GPIO_IN); |
| 185 | |
| 186 | tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250); |
| 187 | |
Thomas Gleixner | 52e405e | 2006-07-03 02:20:05 +0200 | [diff] [blame] | 188 | err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int, IRQF_DISABLED, |
Dirk Opfer | a93876c | 2005-11-08 19:15:30 +0000 | [diff] [blame] | 189 | "MMC/SD card detect", data); |
| 190 | if (err) { |
| 191 | printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n"); |
| 192 | return -1; |
| 193 | } |
| 194 | |
| 195 | set_irq_type(TOSA_IRQ_GPIO_nSD_DETECT, IRQT_BOTHEDGE); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static void tosa_mci_setpower(struct device *dev, unsigned int vdd) |
| 201 | { |
| 202 | struct pxamci_platform_data* p_d = dev->platform_data; |
| 203 | |
| 204 | if (( 1 << vdd) & p_d->ocr_mask) { |
| 205 | set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON); |
| 206 | } else { |
| 207 | reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | static int tosa_mci_get_ro(struct device *dev) |
| 212 | { |
| 213 | return (read_scoop_reg(&tosascoop_device.dev, SCOOP_GPWR)&TOSA_SCOOP_SD_WP); |
| 214 | } |
| 215 | |
| 216 | static void tosa_mci_exit(struct device *dev, void *data) |
| 217 | { |
| 218 | free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data); |
| 219 | } |
| 220 | |
| 221 | static struct pxamci_platform_data tosa_mci_platform_data = { |
| 222 | .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, |
| 223 | .init = tosa_mci_init, |
| 224 | .get_ro = tosa_mci_get_ro, |
| 225 | .setpower = tosa_mci_setpower, |
| 226 | .exit = tosa_mci_exit, |
| 227 | }; |
| 228 | |
| 229 | /* |
| 230 | * Irda |
| 231 | */ |
| 232 | static void tosa_irda_transceiver_mode(struct device *dev, int mode) |
| 233 | { |
| 234 | if (mode & IR_OFF) { |
| 235 | reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN); |
| 236 | pxa_gpio_mode(GPIO47_STTXD|GPIO_DFLT_LOW); |
| 237 | pxa_gpio_mode(GPIO47_STTXD|GPIO_OUT); |
| 238 | } else { |
| 239 | pxa_gpio_mode(GPIO47_STTXD_MD); |
| 240 | set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | static struct pxaficp_platform_data tosa_ficp_platform_data = { |
| 245 | .transceiver_cap = IR_SIRMODE | IR_OFF, |
| 246 | .transceiver_mode = tosa_irda_transceiver_mode, |
| 247 | }; |
| 248 | |
| 249 | /* |
| 250 | * Tosa Keyboard |
| 251 | */ |
| 252 | static struct platform_device tosakbd_device = { |
| 253 | .name = "tosa-keyboard", |
| 254 | .id = -1, |
| 255 | }; |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 256 | |
Dirk Opfer | 6d0cf3e | 2006-03-31 02:31:12 -0800 | [diff] [blame] | 257 | /* |
| 258 | * Tosa LEDs |
| 259 | */ |
| 260 | static struct platform_device tosaled_device = { |
| 261 | .name = "tosa-led", |
| 262 | .id = -1, |
| 263 | }; |
| 264 | |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 265 | static struct platform_device *devices[] __initdata = { |
| 266 | &tosascoop_device, |
| 267 | &tosascoop_jc_device, |
Dirk Opfer | a93876c | 2005-11-08 19:15:30 +0000 | [diff] [blame] | 268 | &tosakbd_device, |
Dirk Opfer | 6d0cf3e | 2006-03-31 02:31:12 -0800 | [diff] [blame] | 269 | &tosaled_device, |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 270 | }; |
| 271 | |
Richard Purdie | 74617fb | 2006-06-19 19:57:12 +0100 | [diff] [blame] | 272 | static void tosa_poweroff(void) |
| 273 | { |
| 274 | RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR; |
| 275 | |
| 276 | pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_OUT); |
| 277 | GPSR(TOSA_GPIO_ON_RESET) = GPIO_bit(TOSA_GPIO_ON_RESET); |
| 278 | |
| 279 | mdelay(1000); |
| 280 | arm_machine_restart('h'); |
| 281 | } |
| 282 | |
| 283 | static void tosa_restart(char mode) |
| 284 | { |
| 285 | /* Bootloader magic for a reboot */ |
| 286 | if((MSC0 & 0xffff0000) == 0x7ff00000) |
| 287 | MSC0 = (MSC0 & 0xffff) | 0x7ee00000; |
| 288 | |
| 289 | tosa_poweroff(); |
| 290 | } |
| 291 | |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 292 | static void __init tosa_init(void) |
| 293 | { |
Richard Purdie | 74617fb | 2006-06-19 19:57:12 +0100 | [diff] [blame] | 294 | pm_power_off = tosa_poweroff; |
| 295 | arm_pm_restart = tosa_restart; |
| 296 | |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 297 | pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_IN); |
| 298 | pxa_gpio_mode(TOSA_GPIO_TC6393_INT | GPIO_IN); |
Dirk Opfer | a93876c | 2005-11-08 19:15:30 +0000 | [diff] [blame] | 299 | pxa_gpio_mode(TOSA_GPIO_USB_IN | GPIO_IN); |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 300 | |
| 301 | /* setup sleep mode values */ |
| 302 | PWER = 0x00000002; |
| 303 | PFER = 0x00000000; |
| 304 | PRER = 0x00000002; |
| 305 | PGSR0 = 0x00000000; |
| 306 | PGSR1 = 0x00FF0002; |
| 307 | PGSR2 = 0x00014000; |
| 308 | PCFR |= PCFR_OPDE; |
| 309 | |
Dirk Opfer | a93876c | 2005-11-08 19:15:30 +0000 | [diff] [blame] | 310 | /* enable batt_fault */ |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 311 | PMCR = 0x01; |
| 312 | |
Dirk Opfer | a93876c | 2005-11-08 19:15:30 +0000 | [diff] [blame] | 313 | pxa_set_mci_info(&tosa_mci_platform_data); |
| 314 | pxa_set_udc_info(&udc_info); |
| 315 | pxa_set_ficp_info(&tosa_ficp_platform_data); |
Dirk Opfer | 4c18ad2 | 2005-11-08 19:15:50 +0000 | [diff] [blame] | 316 | platform_scoop_config = &tosa_pcmcia_config; |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 317 | |
Dirk Opfer | 4c18ad2 | 2005-11-08 19:15:50 +0000 | [diff] [blame] | 318 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | static void __init fixup_tosa(struct machine_desc *desc, |
| 322 | struct tag *tags, char **cmdline, struct meminfo *mi) |
| 323 | { |
| 324 | sharpsl_save_param(); |
| 325 | mi->nr_banks=1; |
| 326 | mi->bank[0].start = 0xa0000000; |
| 327 | mi->bank[0].node = 0; |
| 328 | mi->bank[0].size = (64*1024*1024); |
| 329 | } |
| 330 | |
| 331 | MACHINE_START(TOSA, "SHARP Tosa") |
Dirk Opfer | 8459c15 | 2005-11-06 14:27:52 +0000 | [diff] [blame] | 332 | .phys_io = 0x40000000, |
| 333 | .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc, |
| 334 | .fixup = fixup_tosa, |
| 335 | .map_io = pxa_map_io, |
| 336 | .init_irq = pxa_init_irq, |
| 337 | .init_machine = tosa_init, |
| 338 | .timer = &pxa_timer, |
| 339 | MACHINE_END |