Commit | Line | Data |
---|---|---|
8459c159 DO |
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> | |
067c9048 | 17 | #include <linux/platform_device.h> |
8459c159 DO |
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> |
905f1467 | 23 | #include <linux/delay.h> |
93e9012f DB |
24 | #include <linux/gpio_keys.h> |
25 | #include <linux/input.h> | |
8459c159 DO |
26 | |
27 | #include <asm/setup.h> | |
28 | #include <asm/memory.h> | |
29 | #include <asm/mach-types.h> | |
30 | #include <asm/hardware.h> | |
31 | #include <asm/irq.h> | |
74617fb6 | 32 | #include <asm/system.h> |
77483037 | 33 | #include <asm/arch/pxa-regs.h> |
bb548dd4 | 34 | #include <asm/arch/pxa2xx-regs.h> |
2cb47342 | 35 | #include <asm/arch/mfp-pxa25x.h> |
8459c159 | 36 | #include <asm/arch/irda.h> |
481ea5a1 | 37 | #include <asm/arch/i2c.h> |
8459c159 DO |
38 | #include <asm/arch/mmc.h> |
39 | #include <asm/arch/udc.h> | |
40 | ||
41 | #include <asm/mach/arch.h> | |
42 | #include <asm/mach/map.h> | |
43 | #include <asm/mach/irq.h> | |
8459c159 DO |
44 | #include <asm/arch/tosa.h> |
45 | ||
46 | #include <asm/hardware/scoop.h> | |
47 | #include <asm/mach/sharpsl_param.h> | |
48 | ||
49 | #include "generic.h" | |
46c41e62 | 50 | #include "devices.h" |
8459c159 | 51 | |
2cb47342 DB |
52 | static unsigned long tosa_pin_config[] = { |
53 | GPIO78_nCS_2, /* Scoop */ | |
54 | GPIO80_nCS_4, /* tg6393xb */ | |
55 | GPIO33_nCS_5, /* Scoop */ | |
56 | ||
57 | // GPIO76 CARD_VCC_ON1 | |
58 | ||
59 | GPIO19_GPIO, /* Reset out */ | |
60 | GPIO1_RST | WAKEUP_ON_EDGE_FALL, | |
61 | ||
62 | GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */ | |
63 | GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */ | |
64 | GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */ | |
65 | GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */ | |
66 | GPIO20_GPIO, /* EAR_IN */ | |
67 | GPIO22_GPIO, /* On */ | |
68 | ||
69 | GPIO5_GPIO, /* USB_IN */ | |
70 | GPIO32_GPIO, /* Pen IRQ */ | |
71 | ||
72 | GPIO7_GPIO, /* Jacket Detect */ | |
73 | GPIO14_GPIO, /* BAT0_CRG */ | |
74 | GPIO12_GPIO, /* BAT1_CRG */ | |
75 | GPIO17_GPIO, /* BAT0_LOW */ | |
76 | GPIO84_GPIO, /* BAT1_LOW */ | |
77 | GPIO38_GPIO, /* BAT_LOCK */ | |
78 | ||
79 | GPIO11_3_6MHz, | |
80 | GPIO15_GPIO, /* TC6393XB IRQ */ | |
81 | GPIO18_RDY, | |
82 | GPIO27_GPIO, /* LCD Sync */ | |
83 | ||
84 | /* MMC */ | |
85 | GPIO6_MMC_CLK, | |
86 | GPIO8_MMC_CS0, | |
87 | GPIO9_GPIO, /* Detect */ | |
88 | // GPIO10 nSD_INT | |
89 | ||
90 | /* CF */ | |
91 | GPIO13_GPIO, /* CD_IRQ */ | |
92 | GPIO21_GPIO, /* Main Slot IRQ */ | |
93 | GPIO36_GPIO, /* Jacket Slot IRQ */ | |
94 | GPIO48_nPOE, | |
95 | GPIO49_nPWE, | |
96 | GPIO50_nPIOR, | |
97 | GPIO51_nPIOW, | |
98 | GPIO52_nPCE_1, | |
99 | GPIO53_nPCE_2, | |
100 | GPIO54_nPSKTSEL, | |
101 | GPIO55_nPREG, | |
102 | GPIO56_nPWAIT, | |
103 | GPIO57_nIOIS16, | |
104 | ||
105 | /* AC97 */ | |
106 | GPIO31_AC97_SYNC, | |
107 | GPIO30_AC97_SDATA_OUT, | |
108 | GPIO28_AC97_BITCLK, | |
109 | GPIO29_AC97_SDATA_IN_0, | |
110 | // GPIO79 nAUD_IRQ | |
111 | ||
112 | /* FFUART */ | |
113 | GPIO34_FFUART_RXD, | |
114 | GPIO35_FFUART_CTS, | |
115 | GPIO37_FFUART_DSR, | |
116 | GPIO39_FFUART_TXD, | |
117 | GPIO40_FFUART_DTR, | |
118 | GPIO41_FFUART_RTS, | |
119 | ||
120 | /* BTUART */ | |
121 | GPIO42_BTUART_RXD, | |
122 | GPIO43_BTUART_TXD, | |
123 | GPIO44_BTUART_CTS, | |
124 | GPIO45_BTUART_RTS, | |
125 | ||
126 | /* IrDA */ | |
127 | GPIO46_STUART_RXD, | |
128 | GPIO47_STUART_TXD, | |
129 | ||
130 | /* Keybd */ | |
131 | GPIO58_GPIO, | |
132 | GPIO59_GPIO, | |
133 | GPIO60_GPIO, | |
134 | GPIO61_GPIO, | |
135 | GPIO62_GPIO, | |
136 | GPIO63_GPIO, | |
137 | GPIO64_GPIO, | |
138 | GPIO65_GPIO, | |
139 | GPIO66_GPIO, | |
140 | GPIO67_GPIO, | |
141 | GPIO68_GPIO, | |
142 | GPIO69_GPIO, | |
143 | GPIO70_GPIO, | |
144 | GPIO71_GPIO, | |
145 | GPIO72_GPIO, | |
146 | GPIO73_GPIO, | |
147 | GPIO74_GPIO, | |
148 | GPIO75_GPIO, | |
149 | ||
150 | /* SPI */ | |
151 | GPIO81_SSP2_CLK_OUT, | |
152 | GPIO82_SSP2_FRM_OUT, | |
153 | GPIO83_SSP2_TXD, | |
154 | }; | |
155 | ||
8459c159 DO |
156 | /* |
157 | * SCOOP Device | |
158 | */ | |
159 | static struct resource tosa_scoop_resources[] = { | |
160 | [0] = { | |
161 | .start = TOSA_CF_PHYS, | |
162 | .end = TOSA_CF_PHYS + 0xfff, | |
163 | .flags = IORESOURCE_MEM, | |
164 | }, | |
165 | }; | |
166 | ||
167 | static struct scoop_config tosa_scoop_setup = { | |
168 | .io_dir = TOSA_SCOOP_IO_DIR, | |
169 | .io_out = TOSA_SCOOP_IO_OUT, | |
170 | ||
171 | }; | |
172 | ||
173 | struct platform_device tosascoop_device = { | |
174 | .name = "sharp-scoop", | |
175 | .id = 0, | |
176 | .dev = { | |
177 | .platform_data = &tosa_scoop_setup, | |
178 | }, | |
179 | .num_resources = ARRAY_SIZE(tosa_scoop_resources), | |
180 | .resource = tosa_scoop_resources, | |
181 | }; | |
182 | ||
183 | ||
184 | /* | |
185 | * SCOOP Device Jacket | |
186 | */ | |
187 | static struct resource tosa_scoop_jc_resources[] = { | |
188 | [0] = { | |
189 | .start = TOSA_SCOOP_PHYS + 0x40, | |
190 | .end = TOSA_SCOOP_PHYS + 0xfff, | |
191 | .flags = IORESOURCE_MEM, | |
192 | }, | |
193 | }; | |
194 | ||
195 | static struct scoop_config tosa_scoop_jc_setup = { | |
196 | .io_dir = TOSA_SCOOP_JC_IO_DIR, | |
197 | .io_out = TOSA_SCOOP_JC_IO_OUT, | |
198 | }; | |
199 | ||
200 | struct platform_device tosascoop_jc_device = { | |
201 | .name = "sharp-scoop", | |
202 | .id = 1, | |
203 | .dev = { | |
204 | .platform_data = &tosa_scoop_jc_setup, | |
205 | .parent = &tosascoop_device.dev, | |
206 | }, | |
207 | .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources), | |
208 | .resource = tosa_scoop_jc_resources, | |
209 | }; | |
210 | ||
4c18ad20 DO |
211 | /* |
212 | * PCMCIA | |
213 | */ | |
8459c159 DO |
214 | static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = { |
215 | { | |
216 | .dev = &tosascoop_device.dev, | |
217 | .irq = TOSA_IRQ_GPIO_CF_IRQ, | |
218 | .cd_irq = TOSA_IRQ_GPIO_CF_CD, | |
219 | .cd_irq_str = "PCMCIA0 CD", | |
220 | },{ | |
221 | .dev = &tosascoop_jc_device.dev, | |
222 | .irq = TOSA_IRQ_GPIO_JC_CF_IRQ, | |
223 | .cd_irq = -1, | |
224 | }, | |
225 | }; | |
226 | ||
4c18ad20 DO |
227 | static struct scoop_pcmcia_config tosa_pcmcia_config = { |
228 | .devs = &tosa_pcmcia_scoop[0], | |
229 | .num_devs = 2, | |
4c18ad20 DO |
230 | }; |
231 | ||
a93876c1 DO |
232 | /* |
233 | * USB Device Controller | |
234 | */ | |
235 | static void tosa_udc_command(int cmd) | |
236 | { | |
237 | switch(cmd) { | |
238 | case PXA2XX_UDC_CMD_CONNECT: | |
239 | set_scoop_gpio(&tosascoop_jc_device.dev,TOSA_SCOOP_JC_USB_PULLUP); | |
240 | break; | |
241 | case PXA2XX_UDC_CMD_DISCONNECT: | |
242 | reset_scoop_gpio(&tosascoop_jc_device.dev,TOSA_SCOOP_JC_USB_PULLUP); | |
243 | break; | |
244 | } | |
245 | } | |
246 | ||
a93876c1 DO |
247 | static struct pxa2xx_udc_mach_info udc_info __initdata = { |
248 | .udc_command = tosa_udc_command, | |
487dc922 DB |
249 | .gpio_vbus = TOSA_GPIO_USB_IN, |
250 | .gpio_vbus_inverted = 1, | |
a93876c1 DO |
251 | }; |
252 | ||
253 | /* | |
254 | * MMC/SD Device | |
255 | */ | |
256 | static struct pxamci_platform_data tosa_mci_platform_data; | |
257 | ||
40220c1a | 258 | static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data) |
a93876c1 DO |
259 | { |
260 | int err; | |
261 | ||
a93876c1 DO |
262 | tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250); |
263 | ||
2687bd38 RK |
264 | err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int, |
265 | IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, | |
a93876c1 | 266 | "MMC/SD card detect", data); |
2687bd38 | 267 | if (err) |
a93876c1 | 268 | printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n"); |
a93876c1 | 269 | |
2687bd38 | 270 | return err; |
a93876c1 DO |
271 | } |
272 | ||
273 | static void tosa_mci_setpower(struct device *dev, unsigned int vdd) | |
274 | { | |
275 | struct pxamci_platform_data* p_d = dev->platform_data; | |
276 | ||
277 | if (( 1 << vdd) & p_d->ocr_mask) { | |
278 | set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON); | |
279 | } else { | |
280 | reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON); | |
281 | } | |
282 | } | |
283 | ||
284 | static int tosa_mci_get_ro(struct device *dev) | |
285 | { | |
286 | return (read_scoop_reg(&tosascoop_device.dev, SCOOP_GPWR)&TOSA_SCOOP_SD_WP); | |
287 | } | |
288 | ||
289 | static void tosa_mci_exit(struct device *dev, void *data) | |
290 | { | |
291 | free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data); | |
292 | } | |
293 | ||
294 | static struct pxamci_platform_data tosa_mci_platform_data = { | |
295 | .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, | |
296 | .init = tosa_mci_init, | |
297 | .get_ro = tosa_mci_get_ro, | |
298 | .setpower = tosa_mci_setpower, | |
299 | .exit = tosa_mci_exit, | |
300 | }; | |
301 | ||
302 | /* | |
303 | * Irda | |
304 | */ | |
305 | static void tosa_irda_transceiver_mode(struct device *dev, int mode) | |
306 | { | |
307 | if (mode & IR_OFF) { | |
308 | reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN); | |
a93876c1 | 309 | } else { |
a93876c1 DO |
310 | set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN); |
311 | } | |
312 | } | |
313 | ||
314 | static struct pxaficp_platform_data tosa_ficp_platform_data = { | |
315 | .transceiver_cap = IR_SIRMODE | IR_OFF, | |
316 | .transceiver_mode = tosa_irda_transceiver_mode, | |
317 | }; | |
318 | ||
319 | /* | |
320 | * Tosa Keyboard | |
321 | */ | |
322 | static struct platform_device tosakbd_device = { | |
323 | .name = "tosa-keyboard", | |
324 | .id = -1, | |
325 | }; | |
8459c159 | 326 | |
93e9012f DB |
327 | static struct gpio_keys_button tosa_gpio_keys[] = { |
328 | { | |
329 | .type = EV_PWR, | |
330 | .code = KEY_SUSPEND, | |
331 | .gpio = TOSA_GPIO_ON_KEY, | |
332 | .desc = "On key", | |
333 | .wakeup = 1, | |
334 | .active_low = 1, | |
335 | }, | |
336 | { | |
337 | .type = EV_KEY, | |
338 | .code = TOSA_KEY_RECORD, | |
339 | .gpio = TOSA_GPIO_RECORD_BTN, | |
340 | .desc = "Record Button", | |
341 | .wakeup = 1, | |
342 | .active_low = 1, | |
343 | }, | |
344 | { | |
345 | .type = EV_KEY, | |
346 | .code = TOSA_KEY_SYNC, | |
347 | .gpio = TOSA_GPIO_SYNC, | |
348 | .desc = "Sync Button", | |
349 | .wakeup = 1, | |
350 | .active_low = 1, | |
351 | }, | |
352 | }; | |
353 | ||
354 | static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = { | |
355 | .buttons = tosa_gpio_keys, | |
356 | .nbuttons = ARRAY_SIZE(tosa_gpio_keys), | |
357 | }; | |
358 | ||
359 | static struct platform_device tosa_gpio_keys_device = { | |
360 | .name = "gpio-keys", | |
361 | .id = -1, | |
362 | .dev = { | |
363 | .platform_data = &tosa_gpio_keys_platform_data, | |
364 | }, | |
365 | }; | |
366 | ||
6d0cf3e0 DO |
367 | /* |
368 | * Tosa LEDs | |
369 | */ | |
370 | static struct platform_device tosaled_device = { | |
371 | .name = "tosa-led", | |
372 | .id = -1, | |
373 | }; | |
374 | ||
8459c159 DO |
375 | static struct platform_device *devices[] __initdata = { |
376 | &tosascoop_device, | |
377 | &tosascoop_jc_device, | |
a93876c1 | 378 | &tosakbd_device, |
93e9012f | 379 | &tosa_gpio_keys_device, |
6d0cf3e0 | 380 | &tosaled_device, |
8459c159 DO |
381 | }; |
382 | ||
74617fb6 RP |
383 | static void tosa_poweroff(void) |
384 | { | |
385 | RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR; | |
386 | ||
387 | pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_OUT); | |
388 | GPSR(TOSA_GPIO_ON_RESET) = GPIO_bit(TOSA_GPIO_ON_RESET); | |
389 | ||
390 | mdelay(1000); | |
391 | arm_machine_restart('h'); | |
392 | } | |
393 | ||
394 | static void tosa_restart(char mode) | |
395 | { | |
396 | /* Bootloader magic for a reboot */ | |
397 | if((MSC0 & 0xffff0000) == 0x7ff00000) | |
398 | MSC0 = (MSC0 & 0xffff) | 0x7ee00000; | |
399 | ||
400 | tosa_poweroff(); | |
401 | } | |
402 | ||
8459c159 DO |
403 | static void __init tosa_init(void) |
404 | { | |
2cb47342 DB |
405 | pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config)); |
406 | gpio_set_wake(MFP_PIN_GPIO1, 1); | |
407 | /* We can't pass to gpio-keys since it will drop the Reset altfunc */ | |
408 | ||
74617fb6 RP |
409 | pm_power_off = tosa_poweroff; |
410 | arm_pm_restart = tosa_restart; | |
411 | ||
8459c159 DO |
412 | PCFR |= PCFR_OPDE; |
413 | ||
a93876c1 | 414 | /* enable batt_fault */ |
8459c159 DO |
415 | PMCR = 0x01; |
416 | ||
a93876c1 DO |
417 | pxa_set_mci_info(&tosa_mci_platform_data); |
418 | pxa_set_udc_info(&udc_info); | |
419 | pxa_set_ficp_info(&tosa_ficp_platform_data); | |
481ea5a1 | 420 | pxa_set_i2c_info(NULL); |
4c18ad20 | 421 | platform_scoop_config = &tosa_pcmcia_config; |
8459c159 | 422 | |
4c18ad20 | 423 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
8459c159 DO |
424 | } |
425 | ||
426 | static void __init fixup_tosa(struct machine_desc *desc, | |
427 | struct tag *tags, char **cmdline, struct meminfo *mi) | |
428 | { | |
429 | sharpsl_save_param(); | |
430 | mi->nr_banks=1; | |
431 | mi->bank[0].start = 0xa0000000; | |
432 | mi->bank[0].node = 0; | |
433 | mi->bank[0].size = (64*1024*1024); | |
434 | } | |
435 | ||
436 | MACHINE_START(TOSA, "SHARP Tosa") | |
8459c159 DO |
437 | .phys_io = 0x40000000, |
438 | .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc, | |
439 | .fixup = fixup_tosa, | |
440 | .map_io = pxa_map_io, | |
cd49104d | 441 | .init_irq = pxa25x_init_irq, |
8459c159 DO |
442 | .init_machine = tosa_init, |
443 | .timer = &pxa_timer, | |
444 | MACHINE_END |