blob: f99112d50b41ef44b82b99e9c187767646bb777b [file] [log] [blame]
Dirk Opfer8459c152005-11-06 14:27:52 +00001/*
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 Opfer067c9042005-11-21 15:17:06 +000017#include <linux/platform_device.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000018#include <linux/major.h>
19#include <linux/fs.h>
20#include <linux/interrupt.h>
21#include <linux/mmc/host.h>
Richard Purdie74617fb2006-06-19 19:57:12 +010022#include <linux/pm.h>
Russell King905f1462006-06-20 23:27:37 +010023#include <linux/delay.h>
Dmitry Baryshkov93e9012f2008-01-21 01:04:20 -050024#include <linux/gpio_keys.h>
25#include <linux/input.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000026
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>
Richard Purdie74617fb2006-06-19 19:57:12 +010032#include <asm/system.h>
Richard Purdie77483032007-03-07 00:02:15 +010033#include <asm/arch/pxa-regs.h>
eric miaobb548dd2008-01-30 09:39:48 +010034#include <asm/arch/pxa2xx-regs.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000035#include <asm/arch/irda.h>
36#include <asm/arch/mmc.h>
37#include <asm/arch/udc.h>
38
39#include <asm/mach/arch.h>
40#include <asm/mach/map.h>
41#include <asm/mach/irq.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000042#include <asm/arch/tosa.h>
43
44#include <asm/hardware/scoop.h>
45#include <asm/mach/sharpsl_param.h>
46
47#include "generic.h"
Russell King46c41e62007-05-15 15:39:36 +010048#include "devices.h"
Dirk Opfer8459c152005-11-06 14:27:52 +000049
50/*
51 * SCOOP Device
52 */
53static struct resource tosa_scoop_resources[] = {
54 [0] = {
55 .start = TOSA_CF_PHYS,
56 .end = TOSA_CF_PHYS + 0xfff,
57 .flags = IORESOURCE_MEM,
58 },
59};
60
61static struct scoop_config tosa_scoop_setup = {
62 .io_dir = TOSA_SCOOP_IO_DIR,
63 .io_out = TOSA_SCOOP_IO_OUT,
64
65};
66
67struct platform_device tosascoop_device = {
68 .name = "sharp-scoop",
69 .id = 0,
70 .dev = {
71 .platform_data = &tosa_scoop_setup,
72 },
73 .num_resources = ARRAY_SIZE(tosa_scoop_resources),
74 .resource = tosa_scoop_resources,
75};
76
77
78/*
79 * SCOOP Device Jacket
80 */
81static struct resource tosa_scoop_jc_resources[] = {
82 [0] = {
83 .start = TOSA_SCOOP_PHYS + 0x40,
84 .end = TOSA_SCOOP_PHYS + 0xfff,
85 .flags = IORESOURCE_MEM,
86 },
87};
88
89static struct scoop_config tosa_scoop_jc_setup = {
90 .io_dir = TOSA_SCOOP_JC_IO_DIR,
91 .io_out = TOSA_SCOOP_JC_IO_OUT,
92};
93
94struct platform_device tosascoop_jc_device = {
95 .name = "sharp-scoop",
96 .id = 1,
97 .dev = {
98 .platform_data = &tosa_scoop_jc_setup,
99 .parent = &tosascoop_device.dev,
100 },
101 .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
102 .resource = tosa_scoop_jc_resources,
103};
104
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000105/*
106 * PCMCIA
107 */
Dirk Opfer8459c152005-11-06 14:27:52 +0000108static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
109{
110 .dev = &tosascoop_device.dev,
111 .irq = TOSA_IRQ_GPIO_CF_IRQ,
112 .cd_irq = TOSA_IRQ_GPIO_CF_CD,
113 .cd_irq_str = "PCMCIA0 CD",
114},{
115 .dev = &tosascoop_jc_device.dev,
116 .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
117 .cd_irq = -1,
118},
119};
120
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000121static void tosa_pcmcia_init(void)
122{
123 /* Setup default state of GPIO outputs
124 before we enable them as outputs. */
125 GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) |
126 GPIO_bit(GPIO49_nPWE) | GPIO_bit(GPIO50_nPIOR) |
127 GPIO_bit(GPIO51_nPIOW) | GPIO_bit(GPIO52_nPCE_1) |
128 GPIO_bit(GPIO53_nPCE_2);
129
130 pxa_gpio_mode(GPIO48_nPOE_MD);
131 pxa_gpio_mode(GPIO49_nPWE_MD);
132 pxa_gpio_mode(GPIO50_nPIOR_MD);
133 pxa_gpio_mode(GPIO51_nPIOW_MD);
134 pxa_gpio_mode(GPIO55_nPREG_MD);
135 pxa_gpio_mode(GPIO56_nPWAIT_MD);
136 pxa_gpio_mode(GPIO57_nIOIS16_MD);
137 pxa_gpio_mode(GPIO52_nPCE_1_MD);
138 pxa_gpio_mode(GPIO53_nPCE_2_MD);
139 pxa_gpio_mode(GPIO54_pSKTSEL_MD);
140}
141
142static struct scoop_pcmcia_config tosa_pcmcia_config = {
143 .devs = &tosa_pcmcia_scoop[0],
144 .num_devs = 2,
145 .pcmcia_init = tosa_pcmcia_init,
146};
147
Dirk Opfera93876c2005-11-08 19:15:30 +0000148/*
149 * USB Device Controller
150 */
151static void tosa_udc_command(int cmd)
152{
153 switch(cmd) {
154 case PXA2XX_UDC_CMD_CONNECT:
155 set_scoop_gpio(&tosascoop_jc_device.dev,TOSA_SCOOP_JC_USB_PULLUP);
156 break;
157 case PXA2XX_UDC_CMD_DISCONNECT:
158 reset_scoop_gpio(&tosascoop_jc_device.dev,TOSA_SCOOP_JC_USB_PULLUP);
159 break;
160 }
161}
162
Dirk Opfera93876c2005-11-08 19:15:30 +0000163static struct pxa2xx_udc_mach_info udc_info __initdata = {
164 .udc_command = tosa_udc_command,
Dmitry Baryshkov487dc922007-12-21 12:18:01 +0300165 .gpio_vbus = TOSA_GPIO_USB_IN,
166 .gpio_vbus_inverted = 1,
Dirk Opfera93876c2005-11-08 19:15:30 +0000167};
168
169/*
170 * MMC/SD Device
171 */
172static struct pxamci_platform_data tosa_mci_platform_data;
173
David Howells40220c12006-10-09 12:19:47 +0100174static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
Dirk Opfera93876c2005-11-08 19:15:30 +0000175{
176 int err;
177
178 /* setup GPIO for PXA25x MMC controller */
179 pxa_gpio_mode(GPIO6_MMCCLK_MD);
180 pxa_gpio_mode(GPIO8_MMCCS0_MD);
181 pxa_gpio_mode(TOSA_GPIO_nSD_DETECT | GPIO_IN);
182
183 tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
184
Russell King2687bd32008-01-23 14:05:58 +0000185 err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int,
186 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
Dirk Opfera93876c2005-11-08 19:15:30 +0000187 "MMC/SD card detect", data);
Russell King2687bd32008-01-23 14:05:58 +0000188 if (err)
Dirk Opfera93876c2005-11-08 19:15:30 +0000189 printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
Dirk Opfera93876c2005-11-08 19:15:30 +0000190
Russell King2687bd32008-01-23 14:05:58 +0000191 return err;
Dirk Opfera93876c2005-11-08 19:15:30 +0000192}
193
194static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
195{
196 struct pxamci_platform_data* p_d = dev->platform_data;
197
198 if (( 1 << vdd) & p_d->ocr_mask) {
199 set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON);
200 } else {
201 reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON);
202 }
203}
204
205static int tosa_mci_get_ro(struct device *dev)
206{
207 return (read_scoop_reg(&tosascoop_device.dev, SCOOP_GPWR)&TOSA_SCOOP_SD_WP);
208}
209
210static void tosa_mci_exit(struct device *dev, void *data)
211{
212 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
213}
214
215static struct pxamci_platform_data tosa_mci_platform_data = {
216 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
217 .init = tosa_mci_init,
218 .get_ro = tosa_mci_get_ro,
219 .setpower = tosa_mci_setpower,
220 .exit = tosa_mci_exit,
221};
222
223/*
224 * Irda
225 */
226static void tosa_irda_transceiver_mode(struct device *dev, int mode)
227{
228 if (mode & IR_OFF) {
229 reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN);
230 pxa_gpio_mode(GPIO47_STTXD|GPIO_DFLT_LOW);
231 pxa_gpio_mode(GPIO47_STTXD|GPIO_OUT);
232 } else {
233 pxa_gpio_mode(GPIO47_STTXD_MD);
234 set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN);
235 }
236}
237
238static struct pxaficp_platform_data tosa_ficp_platform_data = {
239 .transceiver_cap = IR_SIRMODE | IR_OFF,
240 .transceiver_mode = tosa_irda_transceiver_mode,
241};
242
243/*
244 * Tosa Keyboard
245 */
246static struct platform_device tosakbd_device = {
247 .name = "tosa-keyboard",
248 .id = -1,
249};
Dirk Opfer8459c152005-11-06 14:27:52 +0000250
Dmitry Baryshkov93e9012f2008-01-21 01:04:20 -0500251static struct gpio_keys_button tosa_gpio_keys[] = {
252 {
253 .type = EV_PWR,
254 .code = KEY_SUSPEND,
255 .gpio = TOSA_GPIO_ON_KEY,
256 .desc = "On key",
257 .wakeup = 1,
258 .active_low = 1,
259 },
260 {
261 .type = EV_KEY,
262 .code = TOSA_KEY_RECORD,
263 .gpio = TOSA_GPIO_RECORD_BTN,
264 .desc = "Record Button",
265 .wakeup = 1,
266 .active_low = 1,
267 },
268 {
269 .type = EV_KEY,
270 .code = TOSA_KEY_SYNC,
271 .gpio = TOSA_GPIO_SYNC,
272 .desc = "Sync Button",
273 .wakeup = 1,
274 .active_low = 1,
275 },
276};
277
278static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
279 .buttons = tosa_gpio_keys,
280 .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
281};
282
283static struct platform_device tosa_gpio_keys_device = {
284 .name = "gpio-keys",
285 .id = -1,
286 .dev = {
287 .platform_data = &tosa_gpio_keys_platform_data,
288 },
289};
290
Dirk Opfer6d0cf3e2006-03-31 02:31:12 -0800291/*
292 * Tosa LEDs
293 */
294static struct platform_device tosaled_device = {
295 .name = "tosa-led",
296 .id = -1,
297};
298
Dirk Opfer8459c152005-11-06 14:27:52 +0000299static struct platform_device *devices[] __initdata = {
300 &tosascoop_device,
301 &tosascoop_jc_device,
Dirk Opfera93876c2005-11-08 19:15:30 +0000302 &tosakbd_device,
Dmitry Baryshkov93e9012f2008-01-21 01:04:20 -0500303 &tosa_gpio_keys_device,
Dirk Opfer6d0cf3e2006-03-31 02:31:12 -0800304 &tosaled_device,
Dirk Opfer8459c152005-11-06 14:27:52 +0000305};
306
Richard Purdie74617fb2006-06-19 19:57:12 +0100307static void tosa_poweroff(void)
308{
309 RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
310
311 pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_OUT);
312 GPSR(TOSA_GPIO_ON_RESET) = GPIO_bit(TOSA_GPIO_ON_RESET);
313
314 mdelay(1000);
315 arm_machine_restart('h');
316}
317
318static void tosa_restart(char mode)
319{
320 /* Bootloader magic for a reboot */
321 if((MSC0 & 0xffff0000) == 0x7ff00000)
322 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
323
324 tosa_poweroff();
325}
326
Dirk Opfer8459c152005-11-06 14:27:52 +0000327static void __init tosa_init(void)
328{
Richard Purdie74617fb2006-06-19 19:57:12 +0100329 pm_power_off = tosa_poweroff;
330 arm_pm_restart = tosa_restart;
331
Dirk Opfer8459c152005-11-06 14:27:52 +0000332 pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_IN);
333 pxa_gpio_mode(TOSA_GPIO_TC6393_INT | GPIO_IN);
Dirk Opfera93876c2005-11-08 19:15:30 +0000334 pxa_gpio_mode(TOSA_GPIO_USB_IN | GPIO_IN);
Dirk Opfer8459c152005-11-06 14:27:52 +0000335
336 /* setup sleep mode values */
337 PWER = 0x00000002;
338 PFER = 0x00000000;
339 PRER = 0x00000002;
340 PGSR0 = 0x00000000;
341 PGSR1 = 0x00FF0002;
342 PGSR2 = 0x00014000;
343 PCFR |= PCFR_OPDE;
344
Dirk Opfera93876c2005-11-08 19:15:30 +0000345 /* enable batt_fault */
Dirk Opfer8459c152005-11-06 14:27:52 +0000346 PMCR = 0x01;
347
Dirk Opfera93876c2005-11-08 19:15:30 +0000348 pxa_set_mci_info(&tosa_mci_platform_data);
349 pxa_set_udc_info(&udc_info);
350 pxa_set_ficp_info(&tosa_ficp_platform_data);
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000351 platform_scoop_config = &tosa_pcmcia_config;
Dirk Opfer8459c152005-11-06 14:27:52 +0000352
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000353 platform_add_devices(devices, ARRAY_SIZE(devices));
Dirk Opfer8459c152005-11-06 14:27:52 +0000354}
355
356static void __init fixup_tosa(struct machine_desc *desc,
357 struct tag *tags, char **cmdline, struct meminfo *mi)
358{
359 sharpsl_save_param();
360 mi->nr_banks=1;
361 mi->bank[0].start = 0xa0000000;
362 mi->bank[0].node = 0;
363 mi->bank[0].size = (64*1024*1024);
364}
365
366MACHINE_START(TOSA, "SHARP Tosa")
Dirk Opfer8459c152005-11-06 14:27:52 +0000367 .phys_io = 0x40000000,
368 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
369 .fixup = fixup_tosa,
370 .map_io = pxa_map_io,
Eric Miaocd491042007-06-22 04:14:09 +0100371 .init_irq = pxa25x_init_irq,
Dirk Opfer8459c152005-11-06 14:27:52 +0000372 .init_machine = tosa_init,
373 .timer = &pxa_timer,
374MACHINE_END