[ARM] pxa/vpac270: Add DS1339 RTC support
[pandora-kernel.git] / arch / arm / mach-pxa / vpac270.c
1 /*
2  * Hardware definitions for Voipac PXA270
3  *
4  * Copyright (C) 2010
5  * Marek Vasut <marek.vasut@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  */
12
13 #include <linux/platform_device.h>
14 #include <linux/delay.h>
15 #include <linux/irq.h>
16 #include <linux/gpio_keys.h>
17 #include <linux/input.h>
18 #include <linux/gpio.h>
19 #include <linux/sysdev.h>
20 #include <linux/usb/gpio_vbus.h>
21 #include <linux/mtd/mtd.h>
22 #include <linux/mtd/partitions.h>
23 #include <linux/mtd/physmap.h>
24 #include <linux/dm9000.h>
25 #include <linux/ucb1400.h>
26
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29
30 #include <mach/pxa27x.h>
31 #include <mach/audio.h>
32 #include <mach/vpac270.h>
33 #include <mach/mmc.h>
34 #include <mach/pxafb.h>
35 #include <mach/ohci.h>
36 #include <mach/pxa27x-udc.h>
37 #include <mach/udc.h>
38
39 #include <plat/i2c.h>
40
41 #include "generic.h"
42 #include "devices.h"
43
44 /******************************************************************************
45  * Pin configuration
46  ******************************************************************************/
47 static unsigned long vpac270_pin_config[] __initdata = {
48         /* MMC */
49         GPIO32_MMC_CLK,
50         GPIO92_MMC_DAT_0,
51         GPIO109_MMC_DAT_1,
52         GPIO110_MMC_DAT_2,
53         GPIO111_MMC_DAT_3,
54         GPIO112_MMC_CMD,
55         GPIO53_GPIO,    /* SD detect */
56         GPIO52_GPIO,    /* SD r/o switch */
57
58         /* GPIO KEYS */
59         GPIO1_GPIO,     /* USER BTN */
60
61         /* LEDs */
62         GPIO15_GPIO,    /* orange led */
63
64         /* FFUART */
65         GPIO34_FFUART_RXD,
66         GPIO39_FFUART_TXD,
67         GPIO27_FFUART_RTS,
68         GPIO100_FFUART_CTS,
69         GPIO33_FFUART_DSR,
70         GPIO40_FFUART_DTR,
71         GPIO10_FFUART_DCD,
72         GPIO38_FFUART_RI,
73
74         /* LCD */
75         GPIO58_LCD_LDD_0,
76         GPIO59_LCD_LDD_1,
77         GPIO60_LCD_LDD_2,
78         GPIO61_LCD_LDD_3,
79         GPIO62_LCD_LDD_4,
80         GPIO63_LCD_LDD_5,
81         GPIO64_LCD_LDD_6,
82         GPIO65_LCD_LDD_7,
83         GPIO66_LCD_LDD_8,
84         GPIO67_LCD_LDD_9,
85         GPIO68_LCD_LDD_10,
86         GPIO69_LCD_LDD_11,
87         GPIO70_LCD_LDD_12,
88         GPIO71_LCD_LDD_13,
89         GPIO72_LCD_LDD_14,
90         GPIO73_LCD_LDD_15,
91         GPIO86_LCD_LDD_16,
92         GPIO87_LCD_LDD_17,
93         GPIO74_LCD_FCLK,
94         GPIO75_LCD_LCLK,
95         GPIO76_LCD_PCLK,
96         GPIO77_LCD_BIAS,
97
98         /* PCMCIA */
99         GPIO48_nPOE,
100         GPIO49_nPWE,
101         GPIO50_nPIOR,
102         GPIO51_nPIOW,
103         GPIO85_nPCE_1,
104         GPIO54_nPCE_2,
105         GPIO55_nPREG,
106         GPIO57_nIOIS16,
107         GPIO56_nPWAIT,
108         GPIO104_PSKTSEL,
109         GPIO84_GPIO,    /* PCMCIA CD */
110         GPIO35_GPIO,    /* PCMCIA RDY */
111         GPIO107_GPIO,   /* PCMCIA PPEN */
112         GPIO11_GPIO,    /* PCMCIA RESET */
113         GPIO17_GPIO,    /* CF CD */
114         GPIO12_GPIO,    /* CF RDY */
115         GPIO16_GPIO,    /* CF RESET */
116
117         /* UHC */
118         GPIO88_USBH1_PWR,
119         GPIO89_USBH1_PEN,
120         GPIO119_USBH2_PWR,
121         GPIO120_USBH2_PEN,
122
123         /* UDC */
124         GPIO41_GPIO,
125
126         /* Ethernet */
127         GPIO114_GPIO,   /* IRQ */
128
129         /* AC97 */
130         GPIO28_AC97_BITCLK,
131         GPIO29_AC97_SDATA_IN_0,
132         GPIO30_AC97_SDATA_OUT,
133         GPIO31_AC97_SYNC,
134         GPIO95_AC97_nRESET,
135         GPIO98_AC97_SYSCLK,
136         GPIO113_GPIO,   /* TS IRQ */
137
138         /* I2C */
139         GPIO117_I2C_SCL,
140         GPIO118_I2C_SDA,
141 };
142
143 /******************************************************************************
144  * NOR Flash
145  ******************************************************************************/
146 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
147 static struct mtd_partition vpac270_partitions[] = {
148         {
149                 .name           = "Flash",
150                 .offset         = 0x00000000,
151                 .size           = MTDPART_SIZ_FULL,
152         }
153 };
154
155 static struct physmap_flash_data vpac270_flash_data[] = {
156         {
157                 .width          = 2,    /* bankwidth in bytes */
158                 .parts          = vpac270_partitions,
159                 .nr_parts       = ARRAY_SIZE(vpac270_partitions)
160         }
161 };
162
163 static struct resource vpac270_flash_resource = {
164         .start  = PXA_CS0_PHYS,
165         .end    = PXA_CS0_PHYS + SZ_64M - 1,
166         .flags  = IORESOURCE_MEM,
167 };
168
169 static struct platform_device vpac270_flash = {
170         .name           = "physmap-flash",
171         .id             = 0,
172         .resource       = &vpac270_flash_resource,
173         .num_resources  = 1,
174         .dev            = {
175                 .platform_data = vpac270_flash_data,
176         },
177 };
178 static void __init vpac270_nor_init(void)
179 {
180         platform_device_register(&vpac270_flash);
181 }
182 #else
183 static inline void vpac270_nor_init(void) {}
184 #endif
185
186 /******************************************************************************
187  * SD/MMC card controller
188  ******************************************************************************/
189 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
190 static struct pxamci_platform_data vpac270_mci_platform_data = {
191         .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
192         .gpio_card_detect       = GPIO53_VPAC270_SD_DETECT_N,
193         .gpio_card_ro           = GPIO52_VPAC270_SD_READONLY,
194         .detect_delay           = 20,
195 };
196
197 static void __init vpac270_mmc_init(void)
198 {
199         pxa_set_mci_info(&vpac270_mci_platform_data);
200 }
201 #else
202 static inline void vpac270_mmc_init(void) {}
203 #endif
204
205 /******************************************************************************
206  * GPIO keys
207  ******************************************************************************/
208 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
209 static struct gpio_keys_button vpac270_pxa_buttons[] = {
210         {KEY_POWER, GPIO1_VPAC270_USER_BTN, 0, "USER BTN"},
211 };
212
213 static struct gpio_keys_platform_data vpac270_pxa_keys_data = {
214         .buttons        = vpac270_pxa_buttons,
215         .nbuttons       = ARRAY_SIZE(vpac270_pxa_buttons),
216 };
217
218 static struct platform_device vpac270_pxa_keys = {
219         .name   = "gpio-keys",
220         .id     = -1,
221         .dev    = {
222                 .platform_data = &vpac270_pxa_keys_data,
223         },
224 };
225
226 static void __init vpac270_keys_init(void)
227 {
228         platform_device_register(&vpac270_pxa_keys);
229 }
230 #else
231 static inline void vpac270_keys_init(void) {}
232 #endif
233
234 /******************************************************************************
235  * LED
236  ******************************************************************************/
237 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
238 struct gpio_led vpac270_gpio_leds[] = {
239 {
240         .name                   = "vpac270:orange:user",
241         .default_trigger        = "none",
242         .gpio                   = GPIO15_VPAC270_LED_ORANGE,
243         .active_low             = 1,
244 }
245 };
246
247 static struct gpio_led_platform_data vpac270_gpio_led_info = {
248         .leds           = vpac270_gpio_leds,
249         .num_leds       = ARRAY_SIZE(vpac270_gpio_leds),
250 };
251
252 static struct platform_device vpac270_leds = {
253         .name   = "leds-gpio",
254         .id     = -1,
255         .dev    = {
256                 .platform_data  = &vpac270_gpio_led_info,
257         }
258 };
259
260 static void __init vpac270_leds_init(void)
261 {
262         platform_device_register(&vpac270_leds);
263 }
264 #else
265 static inline void vpac270_leds_init(void) {}
266 #endif
267
268 /******************************************************************************
269  * USB Host
270  ******************************************************************************/
271 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
272 static int vpac270_ohci_init(struct device *dev)
273 {
274         UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE;
275         return 0;
276 }
277
278 static struct pxaohci_platform_data vpac270_ohci_info = {
279         .port_mode      = PMM_PERPORT_MODE,
280         .flags          = ENABLE_PORT1 | ENABLE_PORT2 |
281                         POWER_CONTROL_LOW | POWER_SENSE_LOW,
282         .init           = vpac270_ohci_init,
283 };
284
285 static void __init vpac270_uhc_init(void)
286 {
287         pxa_set_ohci_info(&vpac270_ohci_info);
288 }
289 #else
290 static inline void vpac270_uhc_init(void) {}
291 #endif
292
293 /******************************************************************************
294  * USB Gadget
295  ******************************************************************************/
296 #if defined(CONFIG_USB_GADGET_PXA27X)||defined(CONFIG_USB_GADGET_PXA27X_MODULE)
297 static struct gpio_vbus_mach_info vpac270_gpio_vbus_info = {
298         .gpio_vbus              = GPIO41_VPAC270_UDC_DETECT,
299         .gpio_pullup            = -1,
300 };
301
302 static struct platform_device vpac270_gpio_vbus = {
303         .name   = "gpio-vbus",
304         .id     = -1,
305         .dev    = {
306                 .platform_data  = &vpac270_gpio_vbus_info,
307         },
308 };
309
310 static void vpac270_udc_command(int cmd)
311 {
312         if (cmd == PXA2XX_UDC_CMD_CONNECT)
313                 UP2OCR |= UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE;
314         else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
315                 UP2OCR &= ~(UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE);
316 }
317
318 static struct pxa2xx_udc_mach_info vpac270_udc_info __initdata = {
319         .udc_command            = vpac270_udc_command,
320         .gpio_pullup            = -1,
321 };
322
323 static void __init vpac270_udc_init(void)
324 {
325         pxa_set_udc_info(&vpac270_udc_info);
326         platform_device_register(&vpac270_gpio_vbus);
327 }
328 #else
329 static inline void vpac270_udc_init(void) {}
330 #endif
331
332 /******************************************************************************
333  * Ethernet
334  ******************************************************************************/
335 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
336 static struct resource vpac270_dm9000_resources[] = {
337         [0] = {
338                 .start  = PXA_CS2_PHYS + 0x300,
339                 .end    = PXA_CS2_PHYS + 0x303,
340                 .flags  = IORESOURCE_MEM,
341         },
342         [1] = {
343                 .start  = PXA_CS2_PHYS + 0x304,
344                 .end    = PXA_CS2_PHYS + 0x343,
345                 .flags  = IORESOURCE_MEM,
346         },
347         [2] = {
348                 .start  = IRQ_GPIO(GPIO114_VPAC270_ETH_IRQ),
349                 .end    = IRQ_GPIO(GPIO114_VPAC270_ETH_IRQ),
350                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
351         },
352 };
353
354 static struct dm9000_plat_data vpac270_dm9000_platdata = {
355         .flags          = DM9000_PLATF_32BITONLY,
356 };
357
358 static struct platform_device vpac270_dm9000_device = {
359         .name           = "dm9000",
360         .id             = -1,
361         .num_resources  = ARRAY_SIZE(vpac270_dm9000_resources),
362         .resource       = vpac270_dm9000_resources,
363         .dev            = {
364                 .platform_data = &vpac270_dm9000_platdata,
365         }
366 };
367
368 static void __init vpac270_eth_init(void)
369 {
370         platform_device_register(&vpac270_dm9000_device);
371 }
372 #else
373 static inline void vpac270_eth_init(void) {}
374 #endif
375
376 /******************************************************************************
377  * Audio and Touchscreen
378  ******************************************************************************/
379 #if     defined(CONFIG_TOUCHSCREEN_UCB1400) || \
380         defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
381 static pxa2xx_audio_ops_t vpac270_ac97_pdata = {
382         .reset_gpio     = 95,
383 };
384
385 static struct ucb1400_pdata vpac270_ucb1400_pdata = {
386         .irq            = IRQ_GPIO(113),
387 };
388
389 static struct platform_device vpac270_ucb1400_device = {
390         .name           = "ucb1400_core",
391         .id             = -1,
392         .dev            = {
393                 .platform_data = &vpac270_ucb1400_pdata,
394         },
395 };
396
397 static void __init vpac270_ts_init(void)
398 {
399         pxa_set_ac97_info(&vpac270_ac97_pdata);
400         platform_device_register(&vpac270_ucb1400_device);
401 }
402 #else
403 static inline void vpac270_ts_init(void) {}
404 #endif
405
406 /******************************************************************************
407  * RTC
408  ******************************************************************************/
409 #if defined(CONFIG_RTC_DRV_DS1307) || defined(CONFIG_RTC_DRV_DS1307_MODULE)
410 static struct i2c_board_info __initdata vpac270_i2c_devs[] = {
411         {
412                 I2C_BOARD_INFO("ds1339", 0x68),
413         },
414 };
415
416 static void __init vpac270_rtc_init(void)
417 {
418         pxa_set_i2c_info(NULL);
419         i2c_register_board_info(0, ARRAY_AND_SIZE(vpac270_i2c_devs));
420 }
421 #else
422 static inline void vpac270_rtc_init(void) {}
423 #endif
424
425 /******************************************************************************
426  * Framebuffer
427  ******************************************************************************/
428 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
429 static struct pxafb_mode_info vpac270_lcd_modes[] = {
430 {
431         .pixclock       = 57692,
432         .xres           = 640,
433         .yres           = 480,
434         .bpp            = 32,
435         .depth          = 18,
436
437         .left_margin    = 144,
438         .right_margin   = 32,
439         .upper_margin   = 13,
440         .lower_margin   = 30,
441
442         .hsync_len      = 32,
443         .vsync_len      = 2,
444
445         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
446 },
447 };
448
449 static struct pxafb_mach_info vpac270_lcd_screen = {
450         .modes          = vpac270_lcd_modes,
451         .num_modes      = ARRAY_SIZE(vpac270_lcd_modes),
452         .lcd_conn       = LCD_COLOR_TFT_18BPP,
453 };
454
455 static void vpac270_lcd_power(int on, struct fb_var_screeninfo *info)
456 {
457         gpio_set_value(GPIO81_VPAC270_BKL_ON, on);
458 }
459
460 static void __init vpac270_lcd_init(void)
461 {
462         int ret;
463
464         ret = gpio_request(GPIO81_VPAC270_BKL_ON, "BKL-ON");
465         if (ret) {
466                 pr_err("Requesting BKL-ON GPIO failed!\n");
467                 goto err;
468         }
469
470         ret = gpio_direction_output(GPIO81_VPAC270_BKL_ON, 1);
471         if (ret) {
472                 pr_err("Setting BKL-ON GPIO direction failed!\n");
473                 goto err2;
474         }
475
476         vpac270_lcd_screen.pxafb_lcd_power = vpac270_lcd_power;
477         set_pxa_fb_info(&vpac270_lcd_screen);
478         return;
479
480 err2:
481         gpio_free(GPIO81_VPAC270_BKL_ON);
482 err:
483         return;
484 }
485 #else
486 static inline void vpac270_lcd_init(void) {}
487 #endif
488
489 /******************************************************************************
490  * Machine init
491  ******************************************************************************/
492 static void __init vpac270_init(void)
493 {
494         pxa2xx_mfp_config(ARRAY_AND_SIZE(vpac270_pin_config));
495
496         pxa_set_ffuart_info(NULL);
497         pxa_set_btuart_info(NULL);
498         pxa_set_stuart_info(NULL);
499
500         vpac270_lcd_init();
501         vpac270_mmc_init();
502         vpac270_nor_init();
503         vpac270_leds_init();
504         vpac270_keys_init();
505         vpac270_uhc_init();
506         vpac270_udc_init();
507         vpac270_eth_init();
508         vpac270_ts_init();
509         vpac270_rtc_init();
510 }
511
512 MACHINE_START(VPAC270, "Voipac PXA270")
513         .phys_io        = 0x40000000,
514         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
515         .boot_params    = 0xa0000100,
516         .map_io         = pxa_map_io,
517         .init_irq       = pxa27x_init_irq,
518         .timer          = &pxa_timer,
519         .init_machine   = vpac270_init
520 MACHINE_END