Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[pandora-kernel.git] / arch / arm / mach-pxa / cm-x270.c
1 /*
2  * linux/arch/arm/mach-pxa/cm-x270.c
3  *
4  * Copyright (C) 2007, 2008 CompuLab, Ltd.
5  * Mike Rapoport <mike@compulab.co.il>
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 #include <linux/platform_device.h>
13 #include <linux/sysdev.h>
14 #include <linux/irq.h>
15 #include <linux/gpio.h>
16 #include <linux/delay.h>
17
18 #include <linux/rtc-v3020.h>
19 #include <video/mbxfb.h>
20
21 #include <linux/spi/spi.h>
22 #include <linux/spi/libertas_spi.h>
23
24 #include <mach/pxa27x.h>
25 #include <mach/ohci.h>
26 #include <mach/mmc.h>
27 #include <mach/pxa2xx_spi.h>
28
29 #include "generic.h"
30
31 /* physical address if local-bus attached devices */
32 #define RTC_PHYS_BASE           (PXA_CS1_PHYS + (5 << 22))
33
34 /* GPIO IRQ usage */
35 #define GPIO83_MMC_IRQ          (83)
36
37 #define CMX270_MMC_IRQ          IRQ_GPIO(GPIO83_MMC_IRQ)
38
39 /* MMC power enable */
40 #define GPIO105_MMC_POWER       (105)
41
42 /* WLAN GPIOS */
43 #define GPIO19_WLAN_STRAP       (19)
44 #define GPIO102_WLAN_RST        (102)
45
46 static unsigned long cmx270_pin_config[] = {
47         /* AC'97 */
48         GPIO28_AC97_BITCLK,
49         GPIO29_AC97_SDATA_IN_0,
50         GPIO30_AC97_SDATA_OUT,
51         GPIO31_AC97_SYNC,
52         GPIO98_AC97_SYSCLK,
53         GPIO113_AC97_nRESET,
54
55         /* BTUART */
56         GPIO42_BTUART_RXD,
57         GPIO43_BTUART_TXD,
58         GPIO44_BTUART_CTS,
59         GPIO45_BTUART_RTS,
60
61         /* STUART */
62         GPIO46_STUART_RXD,
63         GPIO47_STUART_TXD,
64
65         /* MCI controller */
66         GPIO32_MMC_CLK,
67         GPIO112_MMC_CMD,
68         GPIO92_MMC_DAT_0,
69         GPIO109_MMC_DAT_1,
70         GPIO110_MMC_DAT_2,
71         GPIO111_MMC_DAT_3,
72
73         /* LCD */
74         GPIO58_LCD_LDD_0,
75         GPIO59_LCD_LDD_1,
76         GPIO60_LCD_LDD_2,
77         GPIO61_LCD_LDD_3,
78         GPIO62_LCD_LDD_4,
79         GPIO63_LCD_LDD_5,
80         GPIO64_LCD_LDD_6,
81         GPIO65_LCD_LDD_7,
82         GPIO66_LCD_LDD_8,
83         GPIO67_LCD_LDD_9,
84         GPIO68_LCD_LDD_10,
85         GPIO69_LCD_LDD_11,
86         GPIO70_LCD_LDD_12,
87         GPIO71_LCD_LDD_13,
88         GPIO72_LCD_LDD_14,
89         GPIO73_LCD_LDD_15,
90         GPIO74_LCD_FCLK,
91         GPIO75_LCD_LCLK,
92         GPIO76_LCD_PCLK,
93         GPIO77_LCD_BIAS,
94
95         /* I2C */
96         GPIO117_I2C_SCL,
97         GPIO118_I2C_SDA,
98
99         /* SSP1 */
100         GPIO23_SSP1_SCLK,
101         GPIO24_SSP1_SFRM,
102         GPIO25_SSP1_TXD,
103         GPIO26_SSP1_RXD,
104
105         /* SSP2 */
106         GPIO19_GPIO,    /* SSP2 clock is used as GPIO for Libertas pin-strap */
107         GPIO14_GPIO,
108         GPIO87_SSP2_TXD,
109         GPIO88_SSP2_RXD,
110
111         /* PC Card */
112         GPIO48_nPOE,
113         GPIO49_nPWE,
114         GPIO50_nPIOR,
115         GPIO51_nPIOW,
116         GPIO85_nPCE_1,
117         GPIO54_nPCE_2,
118         GPIO55_nPREG,
119         GPIO56_nPWAIT,
120         GPIO57_nIOIS16,
121
122         /* SDRAM and local bus */
123         GPIO15_nCS_1,
124         GPIO78_nCS_2,
125         GPIO79_nCS_3,
126         GPIO80_nCS_4,
127         GPIO33_nCS_5,
128         GPIO49_nPWE,
129         GPIO18_RDY,
130
131         /* GPIO */
132         GPIO0_GPIO      | WAKEUP_ON_EDGE_BOTH,
133         GPIO105_GPIO    | MFP_LPM_DRIVE_HIGH,   /* MMC/SD power */
134         GPIO53_GPIO,                            /* PC card reset */
135         GPIO102_GPIO,                           /* WLAN reset */
136
137         /* NAND controls */
138         GPIO11_GPIO     | MFP_LPM_DRIVE_HIGH,   /* NAND CE# */
139         GPIO89_GPIO,                            /* NAND Ready/Busy */
140
141         /* interrupts */
142         GPIO10_GPIO,    /* DM9000 interrupt */
143         GPIO83_GPIO,    /* MMC card detect */
144         GPIO95_GPIO,    /* WLAN interrupt */
145 };
146
147 /* V3020 RTC */
148 #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
149 static struct resource cmx270_v3020_resource[] = {
150         [0] = {
151                 .start = RTC_PHYS_BASE,
152                 .end   = RTC_PHYS_BASE + 4,
153                 .flags = IORESOURCE_MEM,
154         },
155 };
156
157 struct v3020_platform_data cmx270_v3020_pdata = {
158         .leftshift = 16,
159 };
160
161 static struct platform_device cmx270_rtc_device = {
162         .name           = "v3020",
163         .num_resources  = ARRAY_SIZE(cmx270_v3020_resource),
164         .resource       = cmx270_v3020_resource,
165         .id             = -1,
166         .dev            = {
167                 .platform_data = &cmx270_v3020_pdata,
168         }
169 };
170
171 static void __init cmx270_init_rtc(void)
172 {
173         platform_device_register(&cmx270_rtc_device);
174 }
175 #else
176 static inline void cmx270_init_rtc(void) {}
177 #endif
178
179 /* 2700G graphics */
180 #if defined(CONFIG_FB_MBX) || defined(CONFIG_FB_MBX_MODULE)
181 static u64 fb_dma_mask = ~(u64)0;
182
183 static struct resource cmx270_2700G_resource[] = {
184         /* frame buffer memory including ODFB and External SDRAM */
185         [0] = {
186                 .start = PXA_CS2_PHYS,
187                 .end   = PXA_CS2_PHYS + 0x01ffffff,
188                 .flags = IORESOURCE_MEM,
189         },
190         /* Marathon registers */
191         [1] = {
192                 .start = PXA_CS2_PHYS + 0x03fe0000,
193                 .end   = PXA_CS2_PHYS + 0x03ffffff,
194                 .flags = IORESOURCE_MEM,
195         },
196 };
197
198 static unsigned long save_lcd_regs[10];
199
200 static int cmx270_marathon_probe(struct fb_info *fb)
201 {
202         /* save PXA-270 pin settings before enabling 2700G */
203         save_lcd_regs[0] = GPDR1;
204         save_lcd_regs[1] = GPDR2;
205         save_lcd_regs[2] = GAFR1_U;
206         save_lcd_regs[3] = GAFR2_L;
207         save_lcd_regs[4] = GAFR2_U;
208
209         /* Disable PXA-270 on-chip controller driving pins */
210         GPDR1 &= ~(0xfc000000);
211         GPDR2 &= ~(0x00c03fff);
212         GAFR1_U &= ~(0xfff00000);
213         GAFR2_L &= ~(0x0fffffff);
214         GAFR2_U &= ~(0x0000f000);
215         return 0;
216 }
217
218 static int cmx270_marathon_remove(struct fb_info *fb)
219 {
220         GPDR1 =   save_lcd_regs[0];
221         GPDR2 =   save_lcd_regs[1];
222         GAFR1_U = save_lcd_regs[2];
223         GAFR2_L = save_lcd_regs[3];
224         GAFR2_U = save_lcd_regs[4];
225         return 0;
226 }
227
228 static struct mbxfb_platform_data cmx270_2700G_data = {
229         .xres = {
230                 .min = 240,
231                 .max = 1200,
232                 .defval = 640,
233         },
234         .yres = {
235                 .min = 240,
236                 .max = 1200,
237                 .defval = 480,
238         },
239         .bpp = {
240                 .min = 16,
241                 .max = 32,
242                 .defval = 16,
243         },
244         .memsize = 8*1024*1024,
245         .probe = cmx270_marathon_probe,
246         .remove = cmx270_marathon_remove,
247 };
248
249 static struct platform_device cmx270_2700G = {
250         .name           = "mbx-fb",
251         .dev            = {
252                 .platform_data  = &cmx270_2700G_data,
253                 .dma_mask       = &fb_dma_mask,
254                 .coherent_dma_mask = 0xffffffff,
255         },
256         .num_resources  = ARRAY_SIZE(cmx270_2700G_resource),
257         .resource       = cmx270_2700G_resource,
258         .id             = -1,
259 };
260
261 static void __init cmx270_init_2700G(void)
262 {
263         platform_device_register(&cmx270_2700G);
264 }
265 #else
266 static inline void cmx270_init_2700G(void) {}
267 #endif
268
269 /* PXA27x OHCI controller setup */
270 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
271 static struct pxaohci_platform_data cmx270_ohci_platform_data = {
272         .port_mode      = PMM_PERPORT_MODE,
273         .flags          = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
274 };
275
276 static void __init cmx270_init_ohci(void)
277 {
278         pxa_set_ohci_info(&cmx270_ohci_platform_data);
279 }
280 #else
281 static inline void cmx270_init_ohci(void) {}
282 #endif
283
284 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
285 static struct pxamci_platform_data cmx270_mci_platform_data = {
286         .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
287         .gpio_card_detect       = GPIO83_MMC_IRQ,
288         .gpio_card_ro           = -1,
289         .gpio_power             = GPIO105_MMC_POWER,
290         .gpio_power_invert      = 1,
291 };
292
293 static void __init cmx270_init_mmc(void)
294 {
295         pxa_set_mci_info(&cmx270_mci_platform_data);
296 }
297 #else
298 static inline void cmx270_init_mmc(void) {}
299 #endif
300
301 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
302 static struct pxa2xx_spi_master cm_x270_spi_info = {
303         .num_chipselect = 1,
304         .enable_dma     = 1,
305 };
306
307 static struct pxa2xx_spi_chip cm_x270_libertas_chip = {
308         .rx_threshold   = 1,
309         .tx_threshold   = 1,
310         .timeout        = 1000,
311         .gpio_cs        = 14,
312 };
313
314 static unsigned long cm_x270_libertas_pin_config[] = {
315         /* SSP2 */
316         GPIO19_SSP2_SCLK,
317         GPIO14_GPIO,
318         GPIO87_SSP2_TXD,
319         GPIO88_SSP2_RXD,
320
321 };
322
323 static int cm_x270_libertas_setup(struct spi_device *spi)
324 {
325         int err = gpio_request(GPIO19_WLAN_STRAP, "WLAN STRAP");
326         if (err)
327                 return err;
328
329         err = gpio_request(GPIO102_WLAN_RST, "WLAN RST");
330         if (err)
331                 goto err_free_strap;
332
333         err = gpio_direction_output(GPIO102_WLAN_RST, 0);
334         if (err)
335                 goto err_free_strap;
336         msleep(100);
337
338         err = gpio_direction_output(GPIO19_WLAN_STRAP, 1);
339         if (err)
340                 goto err_free_strap;
341         msleep(100);
342
343         pxa2xx_mfp_config(ARRAY_AND_SIZE(cm_x270_libertas_pin_config));
344
345         gpio_set_value(GPIO102_WLAN_RST, 1);
346         msleep(100);
347
348         spi->bits_per_word = 16;
349         spi_setup(spi);
350
351         return 0;
352
353 err_free_strap:
354         gpio_free(GPIO19_WLAN_STRAP);
355
356         return err;
357 }
358
359 static int cm_x270_libertas_teardown(struct spi_device *spi)
360 {
361         gpio_set_value(GPIO102_WLAN_RST, 0);
362         gpio_free(GPIO102_WLAN_RST);
363         gpio_free(GPIO19_WLAN_STRAP);
364
365         return 0;
366 }
367
368 struct libertas_spi_platform_data cm_x270_libertas_pdata = {
369         .use_dummy_writes       = 1,
370         .setup                  = cm_x270_libertas_setup,
371         .teardown               = cm_x270_libertas_teardown,
372 };
373
374 static struct spi_board_info cm_x270_spi_devices[] __initdata = {
375         {
376                 .modalias               = "libertas_spi",
377                 .max_speed_hz           = 13000000,
378                 .bus_num                = 2,
379                 .irq                    = gpio_to_irq(95),
380                 .chip_select            = 0,
381                 .controller_data        = &cm_x270_libertas_chip,
382                 .platform_data          = &cm_x270_libertas_pdata,
383         },
384 };
385
386 static void __init cmx270_init_spi(void)
387 {
388         pxa2xx_set_spi_info(2, &cm_x270_spi_info);
389         spi_register_board_info(ARRAY_AND_SIZE(cm_x270_spi_devices));
390 }
391 #else
392 static inline void cmx270_init_spi(void) {}
393 #endif
394
395 void __init cmx270_init(void)
396 {
397         pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_pin_config));
398
399 #ifdef CONFIG_PM
400         pxa27x_set_pwrmode(PWRMODE_DEEPSLEEP);
401 #endif
402
403         cmx270_init_rtc();
404         cmx270_init_mmc();
405         cmx270_init_ohci();
406         cmx270_init_2700G();
407         cmx270_init_spi();
408 }