]> err.no Git - linux-2.6/blob - arch/arm/mach-pxa/poodle.c
[ARM] 3561/1: Poodle: Correct the MMC/SD power control
[linux-2.6] / arch / arm / mach-pxa / poodle.c
1 /*
2  * linux/arch/arm/mach-pxa/poodle.c
3  *
4  *  Support for the SHARP Poodle Board.
5  *
6  * Based on:
7  *  linux/arch/arm/mach-pxa/lubbock.c Author:   Nicolas Pitre
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  * Change Log
14  *  12-Dec-2002 Sharp Corporation for Poodle
15  *  John Lenz <lenz@cs.wisc.edu> updates to 2.6
16  */
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/platform_device.h>
20 #include <linux/fb.h>
21 #include <linux/pm.h>
22 #include <linux/delay.h>
23
24 #include <asm/hardware.h>
25 #include <asm/mach-types.h>
26 #include <asm/irq.h>
27 #include <asm/setup.h>
28 #include <asm/system.h>
29
30 #include <asm/mach/arch.h>
31 #include <asm/mach/map.h>
32 #include <asm/mach/irq.h>
33
34 #include <asm/arch/pxa-regs.h>
35 #include <asm/arch/mmc.h>
36 #include <asm/arch/udc.h>
37 #include <asm/arch/irda.h>
38 #include <asm/arch/poodle.h>
39 #include <asm/arch/pxafb.h>
40
41 #include <asm/hardware/scoop.h>
42 #include <asm/hardware/locomo.h>
43 #include <asm/mach/sharpsl_param.h>
44
45 #include "generic.h"
46
47 static struct resource poodle_scoop_resources[] = {
48         [0] = {
49                 .start          = 0x10800000,
50                 .end            = 0x10800fff,
51                 .flags          = IORESOURCE_MEM,
52         },
53 };
54
55 static struct scoop_config poodle_scoop_setup = {
56         .io_dir         = POODLE_SCOOP_IO_DIR,
57         .io_out         = POODLE_SCOOP_IO_OUT,
58 };
59
60 struct platform_device poodle_scoop_device = {
61         .name           = "sharp-scoop",
62         .id             = -1,
63         .dev            = {
64                 .platform_data  = &poodle_scoop_setup,
65         },
66         .num_resources  = ARRAY_SIZE(poodle_scoop_resources),
67         .resource       = poodle_scoop_resources,
68 };
69
70 static void poodle_pcmcia_init(void)
71 {
72         /* Setup default state of GPIO outputs
73            before we enable them as outputs. */
74         GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) |
75                 GPIO_bit(GPIO49_nPWE) | GPIO_bit(GPIO50_nPIOR) |
76                 GPIO_bit(GPIO51_nPIOW) | GPIO_bit(GPIO52_nPCE_1) |
77                 GPIO_bit(GPIO53_nPCE_2);
78
79         pxa_gpio_mode(GPIO48_nPOE_MD);
80         pxa_gpio_mode(GPIO49_nPWE_MD);
81         pxa_gpio_mode(GPIO50_nPIOR_MD);
82         pxa_gpio_mode(GPIO51_nPIOW_MD);
83         pxa_gpio_mode(GPIO55_nPREG_MD);
84         pxa_gpio_mode(GPIO56_nPWAIT_MD);
85         pxa_gpio_mode(GPIO57_nIOIS16_MD);
86         pxa_gpio_mode(GPIO52_nPCE_1_MD);
87         pxa_gpio_mode(GPIO53_nPCE_2_MD);
88         pxa_gpio_mode(GPIO54_pSKTSEL_MD);
89 }
90
91 static struct scoop_pcmcia_dev poodle_pcmcia_scoop[] = {
92 {
93         .dev        = &poodle_scoop_device.dev,
94         .irq        = POODLE_IRQ_GPIO_CF_IRQ,
95         .cd_irq     = POODLE_IRQ_GPIO_CF_CD,
96         .cd_irq_str = "PCMCIA0 CD",
97 },
98 };
99
100 static struct scoop_pcmcia_config poodle_pcmcia_config = {
101         .devs         = &poodle_pcmcia_scoop[0],
102         .num_devs     = 1,
103         .pcmcia_init  = poodle_pcmcia_init,
104 };
105
106 EXPORT_SYMBOL(poodle_scoop_device);
107
108
109 /* LoCoMo device */
110 static struct resource locomo_resources[] = {
111         [0] = {
112                 .start          = 0x10000000,
113                 .end            = 0x10001fff,
114                 .flags          = IORESOURCE_MEM,
115         },
116         [1] = {
117                 .start          = IRQ_GPIO(10),
118                 .end            = IRQ_GPIO(10),
119                 .flags          = IORESOURCE_IRQ,
120         },
121 };
122
123 static struct platform_device locomo_device = {
124         .name           = "locomo",
125         .id             = 0,
126         .num_resources  = ARRAY_SIZE(locomo_resources),
127         .resource       = locomo_resources,
128 };
129
130
131 /*
132  * MMC/SD Device
133  *
134  * The card detect interrupt isn't debounced so we delay it by 250ms
135  * to give the card a chance to fully insert/eject.
136  */
137 static struct pxamci_platform_data poodle_mci_platform_data;
138
139 static int poodle_mci_init(struct device *dev, irqreturn_t (*poodle_detect_int)(int, void *, struct pt_regs *), void *data)
140 {
141         int err;
142
143         /* setup GPIO for PXA25x MMC controller */
144         pxa_gpio_mode(GPIO6_MMCCLK_MD);
145         pxa_gpio_mode(GPIO8_MMCCS0_MD);
146         pxa_gpio_mode(POODLE_GPIO_nSD_DETECT | GPIO_IN);
147         pxa_gpio_mode(POODLE_GPIO_nSD_WP | GPIO_IN);
148         pxa_gpio_mode(POODLE_GPIO_SD_PWR | GPIO_OUT);
149         pxa_gpio_mode(POODLE_GPIO_SD_PWR1 | GPIO_OUT);
150
151         poodle_mci_platform_data.detect_delay = msecs_to_jiffies(250);
152
153         err = request_irq(POODLE_IRQ_GPIO_nSD_DETECT, poodle_detect_int,
154                           SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING,
155                           "MMC card detect", data);
156         if (err) {
157                 printk(KERN_ERR "poodle_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
158                 return -1;
159         }
160
161         return 0;
162 }
163
164 static void poodle_mci_setpower(struct device *dev, unsigned int vdd)
165 {
166         struct pxamci_platform_data* p_d = dev->platform_data;
167
168         if (( 1 << vdd) & p_d->ocr_mask) {
169                 GPSR(POODLE_GPIO_SD_PWR) = GPIO_bit(POODLE_GPIO_SD_PWR);
170                 mdelay(2);
171                 GPSR(POODLE_GPIO_SD_PWR1) = GPIO_bit(POODLE_GPIO_SD_PWR1);
172         } else {
173                 GPCR(POODLE_GPIO_SD_PWR1) = GPIO_bit(POODLE_GPIO_SD_PWR1);
174                 GPCR(POODLE_GPIO_SD_PWR) = GPIO_bit(POODLE_GPIO_SD_PWR);
175         }
176 }
177
178 static int poodle_mci_get_ro(struct device *dev)
179 {
180         return GPLR(POODLE_GPIO_nSD_WP) & GPIO_bit(POODLE_GPIO_nSD_WP);
181 }
182
183
184 static void poodle_mci_exit(struct device *dev, void *data)
185 {
186         free_irq(POODLE_IRQ_GPIO_nSD_DETECT, data);
187 }
188
189 static struct pxamci_platform_data poodle_mci_platform_data = {
190         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
191         .init           = poodle_mci_init,
192         .get_ro         = poodle_mci_get_ro,
193         .setpower       = poodle_mci_setpower,
194         .exit           = poodle_mci_exit,
195 };
196
197
198 /*
199  * Irda
200  */
201 static void poodle_irda_transceiver_mode(struct device *dev, int mode)
202 {
203         if (mode & IR_OFF) {
204                 GPSR(POODLE_GPIO_IR_ON) = GPIO_bit(POODLE_GPIO_IR_ON);
205         } else {
206                 GPCR(POODLE_GPIO_IR_ON) = GPIO_bit(POODLE_GPIO_IR_ON);
207         }
208 }
209
210 static struct pxaficp_platform_data poodle_ficp_platform_data = {
211         .transceiver_cap  = IR_SIRMODE | IR_OFF,
212         .transceiver_mode = poodle_irda_transceiver_mode,
213 };
214
215
216 /*
217  * USB Device Controller
218  */
219 static void poodle_udc_command(int cmd)
220 {
221         switch(cmd)     {
222         case PXA2XX_UDC_CMD_CONNECT:
223                 GPSR(POODLE_GPIO_USB_PULLUP) = GPIO_bit(POODLE_GPIO_USB_PULLUP);
224                 break;
225         case PXA2XX_UDC_CMD_DISCONNECT:
226                 GPCR(POODLE_GPIO_USB_PULLUP) = GPIO_bit(POODLE_GPIO_USB_PULLUP);
227                 break;
228         }
229 }
230
231 static struct pxa2xx_udc_mach_info udc_info __initdata = {
232         /* no connect GPIO; poodle can't tell connection status */
233         .udc_command            = poodle_udc_command,
234 };
235
236
237 /* PXAFB device */
238 static struct pxafb_mach_info poodle_fb_info __initdata = {
239         .pixclock       = 144700,
240
241         .xres           = 320,
242         .yres           = 240,
243         .bpp            = 16,
244
245         .hsync_len      = 7,
246         .left_margin    = 11,
247         .right_margin   = 30,
248
249         .vsync_len      = 2,
250         .upper_margin   = 2,
251         .lower_margin   = 0,
252         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
253
254         .lccr0          = LCCR0_Act | LCCR0_Sngl | LCCR0_Color,
255         .lccr3          = 0,
256
257         .pxafb_backlight_power  = NULL,
258         .pxafb_lcd_power        = NULL,
259 };
260
261 static struct platform_device *devices[] __initdata = {
262         &locomo_device,
263         &poodle_scoop_device,
264 };
265
266 static void poodle_poweroff(void)
267 {
268         RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
269         arm_machine_restart('h');
270 }
271
272 static void poodle_restart(char mode)
273 {
274         RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
275         arm_machine_restart('h');
276 }
277
278 static void __init poodle_init(void)
279 {
280         int ret = 0;
281
282         pm_power_off = poodle_poweroff;
283         arm_pm_restart = poodle_restart;
284
285         /* setup sleep mode values */
286         PWER  = 0x00000002;
287         PFER  = 0x00000000;
288         PRER  = 0x00000002;
289         PGSR0 = 0x00008000;
290         PGSR1 = 0x003F0202;
291         PGSR2 = 0x0001C000;
292         PCFR |= PCFR_OPDE;
293
294         /* cpu initialize */
295         /* Pgsr Register */
296         PGSR0 = 0x0146dd80;
297         PGSR1 = 0x03bf0890;
298         PGSR2 = 0x0001c000;
299
300         /* Alternate Register */
301         GAFR0_L = 0x01001000;
302         GAFR0_U = 0x591a8010;
303         GAFR1_L = 0x900a8451;
304         GAFR1_U = 0xaaa5aaaa;
305         GAFR2_L = 0x8aaaaaaa;
306         GAFR2_U = 0x00000002;
307
308         /* Direction Register */
309         GPDR0 = 0xd3f0904c;
310         GPDR1 = 0xfcffb7d3;
311         GPDR2 = 0x0001ffff;
312
313         /* Output Register */
314         GPCR0 = 0x00000000;
315         GPCR1 = 0x00000000;
316         GPCR2 = 0x00000000;
317
318         GPSR0 = 0x00400000;
319         GPSR1 = 0x00000000;
320         GPSR2 = 0x00000000;
321
322         set_pxa_fb_info(&poodle_fb_info);
323         pxa_gpio_mode(POODLE_GPIO_USB_PULLUP | GPIO_OUT);
324         pxa_gpio_mode(POODLE_GPIO_IR_ON | GPIO_OUT);
325         pxa_set_udc_info(&udc_info);
326         pxa_set_mci_info(&poodle_mci_platform_data);
327         pxa_set_ficp_info(&poodle_ficp_platform_data);
328
329         platform_scoop_config = &poodle_pcmcia_config;
330
331         ret = platform_add_devices(devices, ARRAY_SIZE(devices));
332         if (ret) {
333                 printk(KERN_WARNING "poodle: Unable to register LoCoMo device\n");
334         }
335 }
336
337 static void __init fixup_poodle(struct machine_desc *desc,
338                 struct tag *tags, char **cmdline, struct meminfo *mi)
339 {
340         sharpsl_save_param();
341         mi->nr_banks=1;
342         mi->bank[0].start = 0xa0000000;
343         mi->bank[0].node = 0;
344         mi->bank[0].size = (32*1024*1024);
345 }
346
347 MACHINE_START(POODLE, "SHARP Poodle")
348         .phys_io        = 0x40000000,
349         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
350         .fixup          = fixup_poodle,
351         .map_io         = pxa_map_io,
352         .init_irq       = pxa_init_irq,
353         .timer          = &pxa_timer,
354         .init_machine   = poodle_init,
355 MACHINE_END