[ARM] pxa/poodle: convert to use the new MFP API to configure pins
[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 #include <linux/gpio.h>
24
25 #include <mach/hardware.h>
26 #include <asm/mach-types.h>
27 #include <asm/irq.h>
28 #include <asm/setup.h>
29 #include <asm/system.h>
30
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33 #include <asm/mach/irq.h>
34
35 #include <mach/pxa-regs.h>
36 #include <mach/pxa2xx-regs.h>
37 #include <mach/mfp-pxa25x.h>
38 #include <mach/mmc.h>
39 #include <mach/udc.h>
40 #include <mach/i2c.h>
41 #include <mach/irda.h>
42 #include <mach/poodle.h>
43 #include <mach/pxafb.h>
44 #include <mach/sharpsl.h>
45 #include <mach/ssp.h>
46
47 #include <asm/hardware/scoop.h>
48 #include <asm/hardware/locomo.h>
49 #include <asm/mach/sharpsl_param.h>
50
51 #include "generic.h"
52 #include "devices.h"
53 #include "sharpsl.h"
54
55 static unsigned long poodle_pin_config[] __initdata = {
56         /* I/O */
57         GPIO79_nCS_3,
58         GPIO80_nCS_4,
59         GPIO18_RDY,
60
61         /* Clock */
62         GPIO12_32KHz,
63
64         /* SSP1 */
65         GPIO23_SSP1_SCLK,
66         GPIO24_SSP1_SFRM,
67         GPIO25_SSP1_TXD,
68         GPIO26_SSP1_RXD,
69
70         /* I2S */
71         GPIO28_I2S_BITCLK_OUT,
72         GPIO29_I2S_SDATA_IN,
73         GPIO30_I2S_SDATA_OUT,
74         GPIO31_I2S_SYNC,
75         GPIO32_I2S_SYSCLK,
76
77         /* Infra-Red */
78         GPIO47_FICP_TXD,
79         GPIO46_FICP_RXD,
80
81         /* FFUART */
82         GPIO40_FFUART_DTR,
83         GPIO41_FFUART_RTS,
84         GPIO39_FFUART_TXD,
85         GPIO37_FFUART_DSR,
86         GPIO34_FFUART_RXD,
87         GPIO35_FFUART_CTS,
88
89         /* LCD */
90         GPIO58_LCD_LDD_0,
91         GPIO59_LCD_LDD_1,
92         GPIO60_LCD_LDD_2,
93         GPIO61_LCD_LDD_3,
94         GPIO62_LCD_LDD_4,
95         GPIO63_LCD_LDD_5,
96         GPIO64_LCD_LDD_6,
97         GPIO65_LCD_LDD_7,
98         GPIO66_LCD_LDD_8,
99         GPIO67_LCD_LDD_9,
100         GPIO68_LCD_LDD_10,
101         GPIO69_LCD_LDD_11,
102         GPIO70_LCD_LDD_12,
103         GPIO71_LCD_LDD_13,
104         GPIO72_LCD_LDD_14,
105         GPIO73_LCD_LDD_15,
106         GPIO74_LCD_FCLK,
107         GPIO75_LCD_LCLK,
108         GPIO76_LCD_PCLK,
109         GPIO77_LCD_ACBIAS,
110
111         /* PC Card */
112         GPIO48_nPOE,
113         GPIO49_nPWE,
114         GPIO50_nPIOR,
115         GPIO51_nPIOW,
116         GPIO52_nPCE_1,
117         GPIO53_nPCE_2,
118         GPIO54_nPSKTSEL,
119         GPIO55_nPREG,
120         GPIO56_nPWAIT,
121         GPIO57_nIOIS16,
122
123         /* MMC */
124         GPIO6_MMC_CLK,
125         GPIO8_MMC_CS0,
126
127         /* GPIO */
128         GPIO9_GPIO,     /* POODLE_GPIO_nSD_DETECT */
129         GPIO7_GPIO,     /* POODLE_GPIO_nSD_WP */
130         GPIO3_GPIO,     /* POODLE_GPIO_SD_PWR */
131         GPIO33_GPIO,    /* POODLE_GPIO_SD_PWR1 */
132
133         GPIO20_GPIO,    /* POODLE_GPIO_USB_PULLUP */
134         GPIO22_GPIO,    /* POODLE_GPIO_IR_ON */
135 };
136
137 static struct resource poodle_scoop_resources[] = {
138         [0] = {
139                 .start          = 0x10800000,
140                 .end            = 0x10800fff,
141                 .flags          = IORESOURCE_MEM,
142         },
143 };
144
145 static struct scoop_config poodle_scoop_setup = {
146         .io_dir         = POODLE_SCOOP_IO_DIR,
147         .io_out         = POODLE_SCOOP_IO_OUT,
148 };
149
150 struct platform_device poodle_scoop_device = {
151         .name           = "sharp-scoop",
152         .id             = -1,
153         .dev            = {
154                 .platform_data  = &poodle_scoop_setup,
155         },
156         .num_resources  = ARRAY_SIZE(poodle_scoop_resources),
157         .resource       = poodle_scoop_resources,
158 };
159
160 static struct scoop_pcmcia_dev poodle_pcmcia_scoop[] = {
161 {
162         .dev        = &poodle_scoop_device.dev,
163         .irq        = POODLE_IRQ_GPIO_CF_IRQ,
164         .cd_irq     = POODLE_IRQ_GPIO_CF_CD,
165         .cd_irq_str = "PCMCIA0 CD",
166 },
167 };
168
169 static struct scoop_pcmcia_config poodle_pcmcia_config = {
170         .devs         = &poodle_pcmcia_scoop[0],
171         .num_devs     = 1,
172 };
173
174 EXPORT_SYMBOL(poodle_scoop_device);
175
176
177 /* LoCoMo device */
178 static struct resource locomo_resources[] = {
179         [0] = {
180                 .start          = 0x10000000,
181                 .end            = 0x10001fff,
182                 .flags          = IORESOURCE_MEM,
183         },
184         [1] = {
185                 .start          = IRQ_GPIO(10),
186                 .end            = IRQ_GPIO(10),
187                 .flags          = IORESOURCE_IRQ,
188         },
189 };
190
191 struct platform_device poodle_locomo_device = {
192         .name           = "locomo",
193         .id             = 0,
194         .num_resources  = ARRAY_SIZE(locomo_resources),
195         .resource       = locomo_resources,
196 };
197
198 EXPORT_SYMBOL(poodle_locomo_device);
199
200 /*
201  * Poodle SSP Device
202  */
203
204 struct platform_device poodle_ssp_device = {
205         .name           = "corgi-ssp",
206         .id             = -1,
207 };
208
209 struct corgissp_machinfo poodle_ssp_machinfo = {
210         .port           = 1,
211         .cs_lcdcon      = -1,
212         .cs_ads7846     = -1,
213         .cs_max1111     = -1,
214         .clk_lcdcon     = 2,
215         .clk_ads7846    = 36,
216         .clk_max1111    = 2,
217 };
218
219
220 /*
221  * Poodle Touch Screen Device
222  */
223 static struct resource poodlets_resources[] = {
224         [0] = {
225                 .start          = POODLE_IRQ_GPIO_TP_INT,
226                 .end            = POODLE_IRQ_GPIO_TP_INT,
227                 .flags          = IORESOURCE_IRQ,
228         },
229 };
230
231 static unsigned long poodle_get_hsync_invperiod(void)
232 {
233         return 0;
234 }
235
236 static void poodle_null_hsync(void)
237 {
238 }
239
240 static struct corgits_machinfo  poodle_ts_machinfo = {
241         .get_hsync_invperiod    = poodle_get_hsync_invperiod,
242         .put_hsync              = poodle_null_hsync,
243         .wait_hsync             = poodle_null_hsync,
244 };
245
246 static struct platform_device poodle_ts_device = {
247         .name           = "corgi-ts",
248         .dev            = {
249                 .platform_data  = &poodle_ts_machinfo,
250         },
251         .id             = -1,
252         .num_resources  = ARRAY_SIZE(poodlets_resources),
253         .resource       = poodlets_resources,
254 };
255
256
257 /*
258  * MMC/SD Device
259  *
260  * The card detect interrupt isn't debounced so we delay it by 250ms
261  * to give the card a chance to fully insert/eject.
262  */
263 static struct pxamci_platform_data poodle_mci_platform_data;
264
265 static int poodle_mci_init(struct device *dev, irq_handler_t poodle_detect_int, void *data)
266 {
267         int err;
268
269         err = gpio_request(POODLE_GPIO_nSD_DETECT, "nSD_DETECT");
270         if (err)
271                 goto err_out;
272
273         err = gpio_request(POODLE_GPIO_nSD_WP, "nSD_WP");
274         if (err)
275                 goto err_free_1;
276
277         err = gpio_request(POODLE_GPIO_SD_PWR, "SD_PWR");
278         if (err)
279                 goto err_free_2;
280
281         err = gpio_request(POODLE_GPIO_SD_PWR1, "SD_PWR1");
282         if (err)
283                 goto err_free_3;
284
285         gpio_direction_input(POODLE_GPIO_nSD_DETECT);
286         gpio_direction_input(POODLE_GPIO_nSD_WP);
287
288         gpio_direction_output(POODLE_GPIO_SD_PWR, 0);
289         gpio_direction_output(POODLE_GPIO_SD_PWR1, 0);
290
291         poodle_mci_platform_data.detect_delay = msecs_to_jiffies(250);
292
293         err = request_irq(POODLE_IRQ_GPIO_nSD_DETECT, poodle_detect_int,
294                           IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
295                           "MMC card detect", data);
296         if (err) {
297                 pr_err("%s: MMC/SD: can't request MMC card detect IRQ\n",
298                                 __func__);
299                 goto err_free_4;
300         }
301
302         return 0;
303
304 err_free_4:
305         gpio_free(POODLE_GPIO_SD_PWR1);
306 err_free_3:
307         gpio_free(POODLE_GPIO_SD_PWR);
308 err_free_2:
309         gpio_free(POODLE_GPIO_nSD_WP);
310 err_free_1:
311         gpio_free(POODLE_GPIO_nSD_DETECT);
312 err_out:
313         return err;
314 }
315
316 static void poodle_mci_setpower(struct device *dev, unsigned int vdd)
317 {
318         struct pxamci_platform_data* p_d = dev->platform_data;
319
320         if ((1 << vdd) & p_d->ocr_mask) {
321                 gpio_set_value(POODLE_GPIO_SD_PWR, 1);
322                 mdelay(2);
323                 gpio_set_value(POODLE_GPIO_SD_PWR1, 1);
324         } else {
325                 gpio_set_value(POODLE_GPIO_SD_PWR1, 0);
326                 gpio_set_value(POODLE_GPIO_SD_PWR, 0);
327         }
328 }
329
330 static int poodle_mci_get_ro(struct device *dev)
331 {
332         return !!gpio_get_value(POODLE_GPIO_nSD_WP);
333         return GPLR(POODLE_GPIO_nSD_WP) & GPIO_bit(POODLE_GPIO_nSD_WP);
334 }
335
336
337 static void poodle_mci_exit(struct device *dev, void *data)
338 {
339         free_irq(POODLE_IRQ_GPIO_nSD_DETECT, data);
340         gpio_free(POODLE_GPIO_SD_PWR1);
341         gpio_free(POODLE_GPIO_SD_PWR);
342         gpio_free(POODLE_GPIO_nSD_WP);
343         gpio_free(POODLE_GPIO_nSD_DETECT);
344 }
345
346 static struct pxamci_platform_data poodle_mci_platform_data = {
347         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
348         .init           = poodle_mci_init,
349         .get_ro         = poodle_mci_get_ro,
350         .setpower       = poodle_mci_setpower,
351         .exit           = poodle_mci_exit,
352 };
353
354
355 /*
356  * Irda
357  */
358 static void poodle_irda_transceiver_mode(struct device *dev, int mode)
359 {
360         gpio_set_value(POODLE_GPIO_IR_ON, mode & IR_OFF);
361         pxa2xx_transceiver_mode(dev, mode);
362 }
363
364 static int poodle_irda_startup(struct device *dev)
365 {
366         int err;
367
368         err = gpio_request(POODLE_GPIO_IR_ON, "IR_ON");
369         if (err)
370                 return err;
371
372         gpio_direction_output(POODLE_GPIO_IR_ON, 1);
373         return 0;
374 }
375
376 static void poodle_irda_shutdown(struct device *dev)
377 {
378         gpio_free(POODLE_GPIO_IR_ON);
379 }
380
381 static struct pxaficp_platform_data poodle_ficp_platform_data = {
382         .transceiver_cap        = IR_SIRMODE | IR_OFF,
383         .transceiver_mode       = poodle_irda_transceiver_mode,
384         .startup                = poodle_irda_startup,
385         .shutdown               = poodle_irda_shutdown,
386 };
387
388
389 /*
390  * USB Device Controller
391  */
392 static struct pxa2xx_udc_mach_info udc_info __initdata = {
393         /* no connect GPIO; poodle can't tell connection status */
394         .gpio_pullup    = POODLE_GPIO_USB_PULLUP,
395 };
396
397
398 /* PXAFB device */
399 static struct pxafb_mode_info poodle_fb_mode = {
400         .pixclock       = 144700,
401         .xres           = 320,
402         .yres           = 240,
403         .bpp            = 16,
404         .hsync_len      = 7,
405         .left_margin    = 11,
406         .right_margin   = 30,
407         .vsync_len      = 2,
408         .upper_margin   = 2,
409         .lower_margin   = 0,
410         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
411 };
412
413 static struct pxafb_mach_info poodle_fb_info = {
414         .modes          = &poodle_fb_mode,
415         .num_modes      = 1,
416         .lcd_conn       = LCD_COLOR_TFT_16BPP,
417 };
418
419 static struct platform_device *devices[] __initdata = {
420         &poodle_locomo_device,
421         &poodle_scoop_device,
422         &poodle_ssp_device,
423         &poodle_ts_device,
424 };
425
426 static void poodle_poweroff(void)
427 {
428         arm_machine_restart('h');
429 }
430
431 static void poodle_restart(char mode)
432 {
433         arm_machine_restart('h');
434 }
435
436 static void __init poodle_init(void)
437 {
438         int ret = 0;
439
440         pm_power_off = poodle_poweroff;
441         arm_pm_restart = poodle_restart;
442
443         PCFR |= PCFR_OPDE;
444
445         pxa2xx_mfp_config(ARRAY_AND_SIZE(poodle_pin_config));
446
447         platform_scoop_config = &poodle_pcmcia_config;
448         corgi_ssp_set_machinfo(&poodle_ssp_machinfo);
449
450         ret = platform_add_devices(devices, ARRAY_SIZE(devices));
451         if (ret)
452                 pr_warning("poodle: Unable to register LoCoMo device\n");
453
454         set_pxa_fb_parent(&poodle_locomo_device.dev);
455         set_pxa_fb_info(&poodle_fb_info);
456         pxa_set_udc_info(&udc_info);
457         pxa_set_mci_info(&poodle_mci_platform_data);
458         pxa_set_ficp_info(&poodle_ficp_platform_data);
459         pxa_set_i2c_info(NULL);
460 }
461
462 static void __init fixup_poodle(struct machine_desc *desc,
463                 struct tag *tags, char **cmdline, struct meminfo *mi)
464 {
465         sharpsl_save_param();
466         mi->nr_banks=1;
467         mi->bank[0].start = 0xa0000000;
468         mi->bank[0].node = 0;
469         mi->bank[0].size = (32*1024*1024);
470 }
471
472 MACHINE_START(POODLE, "SHARP Poodle")
473         .phys_io        = 0x40000000,
474         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
475         .fixup          = fixup_poodle,
476         .map_io         = pxa_map_io,
477         .init_irq       = pxa25x_init_irq,
478         .timer          = &pxa_timer,
479         .init_machine   = poodle_init,
480 MACHINE_END