blob: 9b26fa5edad69200756d02384cdfcb941e8911d7 [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>
Dirk Opfer8459c152005-11-06 14:27:52 +000024
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 Purdie74617fb2006-06-19 19:57:12 +010030#include <asm/system.h>
Richard Purdie77483032007-03-07 00:02:15 +010031#include <asm/arch/pxa-regs.h>
eric miaobb548dd2008-01-30 09:39:48 +010032#include <asm/arch/pxa2xx-regs.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000033#include <asm/arch/irda.h>
34#include <asm/arch/mmc.h>
35#include <asm/arch/udc.h>
36
37#include <asm/mach/arch.h>
38#include <asm/mach/map.h>
39#include <asm/mach/irq.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000040#include <asm/arch/tosa.h>
41
42#include <asm/hardware/scoop.h>
43#include <asm/mach/sharpsl_param.h>
44
45#include "generic.h"
Russell King46c41e62007-05-15 15:39:36 +010046#include "devices.h"
Dirk Opfer8459c152005-11-06 14:27:52 +000047
48/*
49 * SCOOP Device
50 */
51static 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
59static struct scoop_config tosa_scoop_setup = {
60 .io_dir = TOSA_SCOOP_IO_DIR,
61 .io_out = TOSA_SCOOP_IO_OUT,
62
63};
64
65struct 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 */
79static 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
87static 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
92struct 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 Opfer4c18ad22005-11-08 19:15:50 +0000103/*
104 * PCMCIA
105 */
Dirk Opfer8459c152005-11-06 14:27:52 +0000106static 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 Opfer4c18ad22005-11-08 19:15:50 +0000119static 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
140static 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 Opfera93876c2005-11-08 19:15:30 +0000146/*
147 * USB Device Controller
148 */
149static 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
Dirk Opfera93876c2005-11-08 19:15:30 +0000161static struct pxa2xx_udc_mach_info udc_info __initdata = {
162 .udc_command = tosa_udc_command,
Dmitry Baryshkov487dc922007-12-21 12:18:01 +0300163 .gpio_vbus = TOSA_GPIO_USB_IN,
164 .gpio_vbus_inverted = 1,
Dirk Opfera93876c2005-11-08 19:15:30 +0000165};
166
167/*
168 * MMC/SD Device
169 */
170static struct pxamci_platform_data tosa_mci_platform_data;
171
David Howells40220c12006-10-09 12:19:47 +0100172static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
Dirk Opfera93876c2005-11-08 19:15:30 +0000173{
174 int err;
175
176 /* setup GPIO for PXA25x MMC controller */
177 pxa_gpio_mode(GPIO6_MMCCLK_MD);
178 pxa_gpio_mode(GPIO8_MMCCS0_MD);
179 pxa_gpio_mode(TOSA_GPIO_nSD_DETECT | GPIO_IN);
180
181 tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
182
Russell King2687bd32008-01-23 14:05:58 +0000183 err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int,
184 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
Dirk Opfera93876c2005-11-08 19:15:30 +0000185 "MMC/SD card detect", data);
Russell King2687bd32008-01-23 14:05:58 +0000186 if (err)
Dirk Opfera93876c2005-11-08 19:15:30 +0000187 printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
Dirk Opfera93876c2005-11-08 19:15:30 +0000188
Russell King2687bd32008-01-23 14:05:58 +0000189 return err;
Dirk Opfera93876c2005-11-08 19:15:30 +0000190}
191
192static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
193{
194 struct pxamci_platform_data* p_d = dev->platform_data;
195
196 if (( 1 << vdd) & p_d->ocr_mask) {
197 set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON);
198 } else {
199 reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON);
200 }
201}
202
203static int tosa_mci_get_ro(struct device *dev)
204{
205 return (read_scoop_reg(&tosascoop_device.dev, SCOOP_GPWR)&TOSA_SCOOP_SD_WP);
206}
207
208static void tosa_mci_exit(struct device *dev, void *data)
209{
210 free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
211}
212
213static struct pxamci_platform_data tosa_mci_platform_data = {
214 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
215 .init = tosa_mci_init,
216 .get_ro = tosa_mci_get_ro,
217 .setpower = tosa_mci_setpower,
218 .exit = tosa_mci_exit,
219};
220
221/*
222 * Irda
223 */
224static void tosa_irda_transceiver_mode(struct device *dev, int mode)
225{
226 if (mode & IR_OFF) {
227 reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN);
228 pxa_gpio_mode(GPIO47_STTXD|GPIO_DFLT_LOW);
229 pxa_gpio_mode(GPIO47_STTXD|GPIO_OUT);
230 } else {
231 pxa_gpio_mode(GPIO47_STTXD_MD);
232 set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN);
233 }
234}
235
236static struct pxaficp_platform_data tosa_ficp_platform_data = {
237 .transceiver_cap = IR_SIRMODE | IR_OFF,
238 .transceiver_mode = tosa_irda_transceiver_mode,
239};
240
241/*
242 * Tosa Keyboard
243 */
244static struct platform_device tosakbd_device = {
245 .name = "tosa-keyboard",
246 .id = -1,
247};
Dirk Opfer8459c152005-11-06 14:27:52 +0000248
Dirk Opfer6d0cf3e2006-03-31 02:31:12 -0800249/*
250 * Tosa LEDs
251 */
252static struct platform_device tosaled_device = {
253 .name = "tosa-led",
254 .id = -1,
255};
256
Dirk Opfer8459c152005-11-06 14:27:52 +0000257static struct platform_device *devices[] __initdata = {
258 &tosascoop_device,
259 &tosascoop_jc_device,
Dirk Opfera93876c2005-11-08 19:15:30 +0000260 &tosakbd_device,
Dirk Opfer6d0cf3e2006-03-31 02:31:12 -0800261 &tosaled_device,
Dirk Opfer8459c152005-11-06 14:27:52 +0000262};
263
Richard Purdie74617fb2006-06-19 19:57:12 +0100264static void tosa_poweroff(void)
265{
266 RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
267
268 pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_OUT);
269 GPSR(TOSA_GPIO_ON_RESET) = GPIO_bit(TOSA_GPIO_ON_RESET);
270
271 mdelay(1000);
272 arm_machine_restart('h');
273}
274
275static void tosa_restart(char mode)
276{
277 /* Bootloader magic for a reboot */
278 if((MSC0 & 0xffff0000) == 0x7ff00000)
279 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
280
281 tosa_poweroff();
282}
283
Dirk Opfer8459c152005-11-06 14:27:52 +0000284static void __init tosa_init(void)
285{
Richard Purdie74617fb2006-06-19 19:57:12 +0100286 pm_power_off = tosa_poweroff;
287 arm_pm_restart = tosa_restart;
288
Dirk Opfer8459c152005-11-06 14:27:52 +0000289 pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_IN);
290 pxa_gpio_mode(TOSA_GPIO_TC6393_INT | GPIO_IN);
Dirk Opfera93876c2005-11-08 19:15:30 +0000291 pxa_gpio_mode(TOSA_GPIO_USB_IN | GPIO_IN);
Dirk Opfer8459c152005-11-06 14:27:52 +0000292
293 /* setup sleep mode values */
294 PWER = 0x00000002;
295 PFER = 0x00000000;
296 PRER = 0x00000002;
297 PGSR0 = 0x00000000;
298 PGSR1 = 0x00FF0002;
299 PGSR2 = 0x00014000;
300 PCFR |= PCFR_OPDE;
301
Dirk Opfera93876c2005-11-08 19:15:30 +0000302 /* enable batt_fault */
Dirk Opfer8459c152005-11-06 14:27:52 +0000303 PMCR = 0x01;
304
Dirk Opfera93876c2005-11-08 19:15:30 +0000305 pxa_set_mci_info(&tosa_mci_platform_data);
306 pxa_set_udc_info(&udc_info);
307 pxa_set_ficp_info(&tosa_ficp_platform_data);
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000308 platform_scoop_config = &tosa_pcmcia_config;
Dirk Opfer8459c152005-11-06 14:27:52 +0000309
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000310 platform_add_devices(devices, ARRAY_SIZE(devices));
Dirk Opfer8459c152005-11-06 14:27:52 +0000311}
312
313static void __init fixup_tosa(struct machine_desc *desc,
314 struct tag *tags, char **cmdline, struct meminfo *mi)
315{
316 sharpsl_save_param();
317 mi->nr_banks=1;
318 mi->bank[0].start = 0xa0000000;
319 mi->bank[0].node = 0;
320 mi->bank[0].size = (64*1024*1024);
321}
322
323MACHINE_START(TOSA, "SHARP Tosa")
Dirk Opfer8459c152005-11-06 14:27:52 +0000324 .phys_io = 0x40000000,
325 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
326 .fixup = fixup_tosa,
327 .map_io = pxa_map_io,
Eric Miaocd491042007-06-22 04:14:09 +0100328 .init_irq = pxa25x_init_irq,
Dirk Opfer8459c152005-11-06 14:27:52 +0000329 .init_machine = tosa_init,
330 .timer = &pxa_timer,
331MACHINE_END