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> |
a683b14d | 35 | #include <asm/arch/pxa2xx-gpio.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 DO |
50 | |
51 | /* | |
52 | * SCOOP Device | |
53 | */ | |
54 | static struct resource tosa_scoop_resources[] = { | |
55 | [0] = { | |
56 | .start = TOSA_CF_PHYS, | |
57 | .end = TOSA_CF_PHYS + 0xfff, | |
58 | .flags = IORESOURCE_MEM, | |
59 | }, | |
60 | }; | |
61 | ||
62 | static struct scoop_config tosa_scoop_setup = { | |
63 | .io_dir = TOSA_SCOOP_IO_DIR, | |
64 | .io_out = TOSA_SCOOP_IO_OUT, | |
65 | ||
66 | }; | |
67 | ||
68 | struct platform_device tosascoop_device = { | |
69 | .name = "sharp-scoop", | |
70 | .id = 0, | |
71 | .dev = { | |
72 | .platform_data = &tosa_scoop_setup, | |
73 | }, | |
74 | .num_resources = ARRAY_SIZE(tosa_scoop_resources), | |
75 | .resource = tosa_scoop_resources, | |
76 | }; | |
77 | ||
78 | ||
79 | /* | |
80 | * SCOOP Device Jacket | |
81 | */ | |
82 | static struct resource tosa_scoop_jc_resources[] = { | |
83 | [0] = { | |
84 | .start = TOSA_SCOOP_PHYS + 0x40, | |
85 | .end = TOSA_SCOOP_PHYS + 0xfff, | |
86 | .flags = IORESOURCE_MEM, | |
87 | }, | |
88 | }; | |
89 | ||
90 | static struct scoop_config tosa_scoop_jc_setup = { | |
91 | .io_dir = TOSA_SCOOP_JC_IO_DIR, | |
92 | .io_out = TOSA_SCOOP_JC_IO_OUT, | |
93 | }; | |
94 | ||
95 | struct platform_device tosascoop_jc_device = { | |
96 | .name = "sharp-scoop", | |
97 | .id = 1, | |
98 | .dev = { | |
99 | .platform_data = &tosa_scoop_jc_setup, | |
100 | .parent = &tosascoop_device.dev, | |
101 | }, | |
102 | .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources), | |
103 | .resource = tosa_scoop_jc_resources, | |
104 | }; | |
105 | ||
4c18ad20 DO |
106 | /* |
107 | * PCMCIA | |
108 | */ | |
8459c159 DO |
109 | static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = { |
110 | { | |
111 | .dev = &tosascoop_device.dev, | |
112 | .irq = TOSA_IRQ_GPIO_CF_IRQ, | |
113 | .cd_irq = TOSA_IRQ_GPIO_CF_CD, | |
114 | .cd_irq_str = "PCMCIA0 CD", | |
115 | },{ | |
116 | .dev = &tosascoop_jc_device.dev, | |
117 | .irq = TOSA_IRQ_GPIO_JC_CF_IRQ, | |
118 | .cd_irq = -1, | |
119 | }, | |
120 | }; | |
121 | ||
4c18ad20 DO |
122 | static void tosa_pcmcia_init(void) |
123 | { | |
124 | /* Setup default state of GPIO outputs | |
125 | before we enable them as outputs. */ | |
126 | GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) | | |
127 | GPIO_bit(GPIO49_nPWE) | GPIO_bit(GPIO50_nPIOR) | | |
128 | GPIO_bit(GPIO51_nPIOW) | GPIO_bit(GPIO52_nPCE_1) | | |
129 | GPIO_bit(GPIO53_nPCE_2); | |
130 | ||
131 | pxa_gpio_mode(GPIO48_nPOE_MD); | |
132 | pxa_gpio_mode(GPIO49_nPWE_MD); | |
133 | pxa_gpio_mode(GPIO50_nPIOR_MD); | |
134 | pxa_gpio_mode(GPIO51_nPIOW_MD); | |
135 | pxa_gpio_mode(GPIO55_nPREG_MD); | |
136 | pxa_gpio_mode(GPIO56_nPWAIT_MD); | |
137 | pxa_gpio_mode(GPIO57_nIOIS16_MD); | |
138 | pxa_gpio_mode(GPIO52_nPCE_1_MD); | |
139 | pxa_gpio_mode(GPIO53_nPCE_2_MD); | |
140 | pxa_gpio_mode(GPIO54_pSKTSEL_MD); | |
141 | } | |
142 | ||
143 | static struct scoop_pcmcia_config tosa_pcmcia_config = { | |
144 | .devs = &tosa_pcmcia_scoop[0], | |
145 | .num_devs = 2, | |
146 | .pcmcia_init = tosa_pcmcia_init, | |
147 | }; | |
148 | ||
a93876c1 DO |
149 | /* |
150 | * USB Device Controller | |
151 | */ | |
152 | static void tosa_udc_command(int cmd) | |
153 | { | |
154 | switch(cmd) { | |
155 | case PXA2XX_UDC_CMD_CONNECT: | |
156 | set_scoop_gpio(&tosascoop_jc_device.dev,TOSA_SCOOP_JC_USB_PULLUP); | |
157 | break; | |
158 | case PXA2XX_UDC_CMD_DISCONNECT: | |
159 | reset_scoop_gpio(&tosascoop_jc_device.dev,TOSA_SCOOP_JC_USB_PULLUP); | |
160 | break; | |
161 | } | |
162 | } | |
163 | ||
a93876c1 DO |
164 | static struct pxa2xx_udc_mach_info udc_info __initdata = { |
165 | .udc_command = tosa_udc_command, | |
487dc922 DB |
166 | .gpio_vbus = TOSA_GPIO_USB_IN, |
167 | .gpio_vbus_inverted = 1, | |
a93876c1 DO |
168 | }; |
169 | ||
170 | /* | |
171 | * MMC/SD Device | |
172 | */ | |
173 | static struct pxamci_platform_data tosa_mci_platform_data; | |
174 | ||
40220c1a | 175 | static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data) |
a93876c1 DO |
176 | { |
177 | int err; | |
178 | ||
179 | /* setup GPIO for PXA25x MMC controller */ | |
180 | pxa_gpio_mode(GPIO6_MMCCLK_MD); | |
181 | pxa_gpio_mode(GPIO8_MMCCS0_MD); | |
182 | pxa_gpio_mode(TOSA_GPIO_nSD_DETECT | GPIO_IN); | |
183 | ||
184 | tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250); | |
185 | ||
2687bd38 RK |
186 | err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int, |
187 | IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, | |
a93876c1 | 188 | "MMC/SD card detect", data); |
2687bd38 | 189 | if (err) |
a93876c1 | 190 | printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n"); |
a93876c1 | 191 | |
2687bd38 | 192 | return err; |
a93876c1 DO |
193 | } |
194 | ||
195 | static void tosa_mci_setpower(struct device *dev, unsigned int vdd) | |
196 | { | |
197 | struct pxamci_platform_data* p_d = dev->platform_data; | |
198 | ||
199 | if (( 1 << vdd) & p_d->ocr_mask) { | |
200 | set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON); | |
201 | } else { | |
202 | reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON); | |
203 | } | |
204 | } | |
205 | ||
206 | static int tosa_mci_get_ro(struct device *dev) | |
207 | { | |
208 | return (read_scoop_reg(&tosascoop_device.dev, SCOOP_GPWR)&TOSA_SCOOP_SD_WP); | |
209 | } | |
210 | ||
211 | static void tosa_mci_exit(struct device *dev, void *data) | |
212 | { | |
213 | free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data); | |
214 | } | |
215 | ||
216 | static struct pxamci_platform_data tosa_mci_platform_data = { | |
217 | .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, | |
218 | .init = tosa_mci_init, | |
219 | .get_ro = tosa_mci_get_ro, | |
220 | .setpower = tosa_mci_setpower, | |
221 | .exit = tosa_mci_exit, | |
222 | }; | |
223 | ||
224 | /* | |
225 | * Irda | |
226 | */ | |
227 | static void tosa_irda_transceiver_mode(struct device *dev, int mode) | |
228 | { | |
229 | if (mode & IR_OFF) { | |
230 | reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN); | |
231 | pxa_gpio_mode(GPIO47_STTXD|GPIO_DFLT_LOW); | |
232 | pxa_gpio_mode(GPIO47_STTXD|GPIO_OUT); | |
233 | } else { | |
234 | pxa_gpio_mode(GPIO47_STTXD_MD); | |
235 | set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN); | |
236 | } | |
237 | } | |
238 | ||
239 | static struct pxaficp_platform_data tosa_ficp_platform_data = { | |
240 | .transceiver_cap = IR_SIRMODE | IR_OFF, | |
241 | .transceiver_mode = tosa_irda_transceiver_mode, | |
242 | }; | |
243 | ||
244 | /* | |
245 | * Tosa Keyboard | |
246 | */ | |
247 | static struct platform_device tosakbd_device = { | |
248 | .name = "tosa-keyboard", | |
249 | .id = -1, | |
250 | }; | |
8459c159 | 251 | |
93e9012f DB |
252 | static struct gpio_keys_button tosa_gpio_keys[] = { |
253 | { | |
254 | .type = EV_PWR, | |
255 | .code = KEY_SUSPEND, | |
256 | .gpio = TOSA_GPIO_ON_KEY, | |
257 | .desc = "On key", | |
258 | .wakeup = 1, | |
259 | .active_low = 1, | |
260 | }, | |
261 | { | |
262 | .type = EV_KEY, | |
263 | .code = TOSA_KEY_RECORD, | |
264 | .gpio = TOSA_GPIO_RECORD_BTN, | |
265 | .desc = "Record Button", | |
266 | .wakeup = 1, | |
267 | .active_low = 1, | |
268 | }, | |
269 | { | |
270 | .type = EV_KEY, | |
271 | .code = TOSA_KEY_SYNC, | |
272 | .gpio = TOSA_GPIO_SYNC, | |
273 | .desc = "Sync Button", | |
274 | .wakeup = 1, | |
275 | .active_low = 1, | |
276 | }, | |
277 | }; | |
278 | ||
279 | static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = { | |
280 | .buttons = tosa_gpio_keys, | |
281 | .nbuttons = ARRAY_SIZE(tosa_gpio_keys), | |
282 | }; | |
283 | ||
284 | static struct platform_device tosa_gpio_keys_device = { | |
285 | .name = "gpio-keys", | |
286 | .id = -1, | |
287 | .dev = { | |
288 | .platform_data = &tosa_gpio_keys_platform_data, | |
289 | }, | |
290 | }; | |
291 | ||
6d0cf3e0 DO |
292 | /* |
293 | * Tosa LEDs | |
294 | */ | |
295 | static struct platform_device tosaled_device = { | |
296 | .name = "tosa-led", | |
297 | .id = -1, | |
298 | }; | |
299 | ||
8459c159 DO |
300 | static struct platform_device *devices[] __initdata = { |
301 | &tosascoop_device, | |
302 | &tosascoop_jc_device, | |
a93876c1 | 303 | &tosakbd_device, |
93e9012f | 304 | &tosa_gpio_keys_device, |
6d0cf3e0 | 305 | &tosaled_device, |
8459c159 DO |
306 | }; |
307 | ||
74617fb6 RP |
308 | static void tosa_poweroff(void) |
309 | { | |
310 | RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR; | |
311 | ||
312 | pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_OUT); | |
313 | GPSR(TOSA_GPIO_ON_RESET) = GPIO_bit(TOSA_GPIO_ON_RESET); | |
314 | ||
315 | mdelay(1000); | |
316 | arm_machine_restart('h'); | |
317 | } | |
318 | ||
319 | static void tosa_restart(char mode) | |
320 | { | |
321 | /* Bootloader magic for a reboot */ | |
322 | if((MSC0 & 0xffff0000) == 0x7ff00000) | |
323 | MSC0 = (MSC0 & 0xffff) | 0x7ee00000; | |
324 | ||
325 | tosa_poweroff(); | |
326 | } | |
327 | ||
8459c159 DO |
328 | static void __init tosa_init(void) |
329 | { | |
74617fb6 RP |
330 | pm_power_off = tosa_poweroff; |
331 | arm_pm_restart = tosa_restart; | |
332 | ||
8459c159 DO |
333 | pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_IN); |
334 | pxa_gpio_mode(TOSA_GPIO_TC6393_INT | GPIO_IN); | |
a93876c1 | 335 | pxa_gpio_mode(TOSA_GPIO_USB_IN | GPIO_IN); |
8459c159 DO |
336 | |
337 | /* setup sleep mode values */ | |
338 | PWER = 0x00000002; | |
339 | PFER = 0x00000000; | |
340 | PRER = 0x00000002; | |
341 | PGSR0 = 0x00000000; | |
342 | PGSR1 = 0x00FF0002; | |
343 | PGSR2 = 0x00014000; | |
344 | PCFR |= PCFR_OPDE; | |
345 | ||
a93876c1 | 346 | /* enable batt_fault */ |
8459c159 DO |
347 | PMCR = 0x01; |
348 | ||
a93876c1 DO |
349 | pxa_set_mci_info(&tosa_mci_platform_data); |
350 | pxa_set_udc_info(&udc_info); | |
351 | pxa_set_ficp_info(&tosa_ficp_platform_data); | |
4c18ad20 | 352 | platform_scoop_config = &tosa_pcmcia_config; |
8459c159 | 353 | |
4c18ad20 | 354 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
8459c159 DO |
355 | } |
356 | ||
357 | static void __init fixup_tosa(struct machine_desc *desc, | |
358 | struct tag *tags, char **cmdline, struct meminfo *mi) | |
359 | { | |
360 | sharpsl_save_param(); | |
361 | mi->nr_banks=1; | |
362 | mi->bank[0].start = 0xa0000000; | |
363 | mi->bank[0].node = 0; | |
364 | mi->bank[0].size = (64*1024*1024); | |
365 | } | |
366 | ||
367 | MACHINE_START(TOSA, "SHARP Tosa") | |
8459c159 DO |
368 | .phys_io = 0x40000000, |
369 | .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc, | |
370 | .fixup = fixup_tosa, | |
371 | .map_io = pxa_map_io, | |
cd49104d | 372 | .init_irq = pxa25x_init_irq, |
8459c159 DO |
373 | .init_machine = tosa_init, |
374 | .timer = &pxa_timer, | |
375 | MACHINE_END |