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