blob: eea78b6c2bc5a596e3735c47ed1bb8997f184ed4 [file] [log] [blame]
Mike Rapoport4adc5fb2008-10-05 10:26:10 +01001/*
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>
Mike Rapoporta2099e42009-08-03 12:07:52 +030016#include <linux/delay.h>
Mike Rapoport4adc5fb2008-10-05 10:26:10 +010017
18#include <linux/rtc-v3020.h>
19#include <video/mbxfb.h>
20
Mike Rapoporta2099e42009-08-03 12:07:52 +030021#include <linux/spi/spi.h>
22#include <linux/spi/libertas_spi.h>
23
Eric Miao51c62982009-01-02 23:17:22 +080024#include <mach/pxa27x.h>
Mike Rapoport4adc5fb2008-10-05 10:26:10 +010025#include <mach/ohci.h>
26#include <mach/mmc.h>
Mike Rapoporta2099e42009-08-03 12:07:52 +030027#include <mach/pxa2xx_spi.h>
Mike Rapoport4adc5fb2008-10-05 10:26:10 +010028
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
Mike Rapoporta2099e42009-08-03 12:07:52 +030042/* WLAN GPIOS */
43#define GPIO19_WLAN_STRAP (19)
44#define GPIO102_WLAN_RST (102)
45
Mike Rapoport4adc5fb2008-10-05 10:26:10 +010046static 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 */
Mike Rapoporta2099e42009-08-03 12:07:52 +0300106 GPIO19_GPIO, /* SSP2 clock is used as GPIO for Libertas pin-strap */
107 GPIO14_GPIO,
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100108 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 */
Mike Rapoporta2099e42009-08-03 12:07:52 +0300135 GPIO102_GPIO, /* WLAN reset */
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100136
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 */
Mike Rapoporta2099e42009-08-03 12:07:52 +0300144 GPIO95_GPIO, /* WLAN interrupt */
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100145};
146
147/* V3020 RTC */
148#if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
149static 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
157struct v3020_platform_data cmx270_v3020_pdata = {
158 .leftshift = 16,
159};
160
161static 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
171static void __init cmx270_init_rtc(void)
172{
173 platform_device_register(&cmx270_rtc_device);
174}
175#else
Mike Rapoport598dca12008-10-15 11:07:21 +0100176static inline void cmx270_init_rtc(void) {}
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100177#endif
178
179/* 2700G graphics */
180#if defined(CONFIG_FB_MBX) || defined(CONFIG_FB_MBX_MODULE)
181static u64 fb_dma_mask = ~(u64)0;
182
183static 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
198static unsigned long save_lcd_regs[10];
199
200static 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
218static 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
228static 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
249static 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
261static void __init cmx270_init_2700G(void)
262{
263 platform_device_register(&cmx270_2700G);
264}
265#else
266static 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)
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100271static struct pxaohci_platform_data cmx270_ohci_platform_data = {
272 .port_mode = PMM_PERPORT_MODE,
Eric Miao097b5332008-09-27 15:49:57 +0800273 .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100274};
275
276static void __init cmx270_init_ohci(void)
277{
278 pxa_set_ohci_info(&cmx270_ohci_platform_data);
279}
280#else
281static inline void cmx270_init_ohci(void) {}
282#endif
283
284#if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100285static struct pxamci_platform_data cmx270_mci_platform_data = {
Robert Jarzmik7a648252009-07-06 22:16:42 +0200286 .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,
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100291};
292
293static void __init cmx270_init_mmc(void)
294{
295 pxa_set_mci_info(&cmx270_mci_platform_data);
296}
297#else
298static inline void cmx270_init_mmc(void) {}
299#endif
300
Mike Rapoporta2099e42009-08-03 12:07:52 +0300301#if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
302static struct pxa2xx_spi_master cm_x270_spi_info = {
303 .num_chipselect = 1,
304 .enable_dma = 1,
305};
306
307static 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
314static 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
323static 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
353err_free_strap:
354 gpio_free(GPIO19_WLAN_STRAP);
355
356 return err;
357}
358
359static 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
368struct 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
374static 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
386static 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
392static inline void cmx270_init_spi(void) {}
393#endif
394
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100395void __init cmx270_init(void)
396{
397 pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_pin_config));
398
Mike Rapoport9599d1d2009-05-26 09:41:46 +0300399#ifdef CONFIG_PM
400 pxa27x_set_pwrmode(PWRMODE_DEEPSLEEP);
401#endif
402
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100403 cmx270_init_rtc();
404 cmx270_init_mmc();
405 cmx270_init_ohci();
406 cmx270_init_2700G();
Mike Rapoporta2099e42009-08-03 12:07:52 +0300407 cmx270_init_spi();
Mike Rapoport4adc5fb2008-10-05 10:26:10 +0100408}