Merge branch 'core/speculation' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / arch / arm / mach-pxa / cm-x270.c
CommitLineData
4adc5fb6
MR
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>
4adc5fb6
MR
13#include <linux/irq.h>
14#include <linux/gpio.h>
32d15448 15#include <linux/gpio/machine.h>
a2099e49 16#include <linux/delay.h>
4adc5fb6 17
cd9b518b 18#include <linux/platform_data/rtc-v3020.h>
4adc5fb6
MR
19#include <video/mbxfb.h>
20
a2099e49 21#include <linux/spi/spi.h>
8348c259 22#include <linux/spi/pxa2xx_spi.h>
a2099e49
MR
23#include <linux/spi/libertas_spi.h>
24
4c25c5d2 25#include "pxa27x.h"
293b2da1
AB
26#include <linux/platform_data/usb-ohci-pxa27x.h>
27#include <linux/platform_data/mmc-pxamci.h>
4adc5fb6
MR
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
6384fdad 37#define CMX270_MMC_IRQ PXA_GPIO_TO_IRQ(GPIO83_MMC_IRQ)
4adc5fb6
MR
38
39/* MMC power enable */
40#define GPIO105_MMC_POWER (105)
41
a2099e49
MR
42/* WLAN GPIOS */
43#define GPIO19_WLAN_STRAP (19)
44#define GPIO102_WLAN_RST (102)
45
4adc5fb6
MR
46static 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 */
bedbda97 74 GPIOxx_LCD_TFT_16BPP,
4adc5fb6
MR
75
76 /* I2C */
77 GPIO117_I2C_SCL,
78 GPIO118_I2C_SDA,
79
80 /* SSP1 */
81 GPIO23_SSP1_SCLK,
82 GPIO24_SSP1_SFRM,
83 GPIO25_SSP1_TXD,
84 GPIO26_SSP1_RXD,
85
86 /* SSP2 */
a2099e49
MR
87 GPIO19_GPIO, /* SSP2 clock is used as GPIO for Libertas pin-strap */
88 GPIO14_GPIO,
4adc5fb6
MR
89 GPIO87_SSP2_TXD,
90 GPIO88_SSP2_RXD,
91
92 /* PC Card */
93 GPIO48_nPOE,
94 GPIO49_nPWE,
95 GPIO50_nPIOR,
96 GPIO51_nPIOW,
97 GPIO85_nPCE_1,
98 GPIO54_nPCE_2,
99 GPIO55_nPREG,
100 GPIO56_nPWAIT,
101 GPIO57_nIOIS16,
102
103 /* SDRAM and local bus */
104 GPIO15_nCS_1,
105 GPIO78_nCS_2,
106 GPIO79_nCS_3,
107 GPIO80_nCS_4,
108 GPIO33_nCS_5,
109 GPIO49_nPWE,
110 GPIO18_RDY,
111
112 /* GPIO */
113 GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH,
114 GPIO105_GPIO | MFP_LPM_DRIVE_HIGH, /* MMC/SD power */
115 GPIO53_GPIO, /* PC card reset */
a2099e49 116 GPIO102_GPIO, /* WLAN reset */
4adc5fb6
MR
117
118 /* NAND controls */
119 GPIO11_GPIO | MFP_LPM_DRIVE_HIGH, /* NAND CE# */
120 GPIO89_GPIO, /* NAND Ready/Busy */
121
122 /* interrupts */
123 GPIO10_GPIO, /* DM9000 interrupt */
124 GPIO83_GPIO, /* MMC card detect */
a2099e49 125 GPIO95_GPIO, /* WLAN interrupt */
4adc5fb6
MR
126};
127
128/* V3020 RTC */
129#if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
130static struct resource cmx270_v3020_resource[] = {
131 [0] = {
132 .start = RTC_PHYS_BASE,
133 .end = RTC_PHYS_BASE + 4,
134 .flags = IORESOURCE_MEM,
135 },
136};
137
138struct v3020_platform_data cmx270_v3020_pdata = {
139 .leftshift = 16,
140};
141
142static struct platform_device cmx270_rtc_device = {
143 .name = "v3020",
144 .num_resources = ARRAY_SIZE(cmx270_v3020_resource),
145 .resource = cmx270_v3020_resource,
146 .id = -1,
147 .dev = {
148 .platform_data = &cmx270_v3020_pdata,
149 }
150};
151
152static void __init cmx270_init_rtc(void)
153{
154 platform_device_register(&cmx270_rtc_device);
155}
156#else
598dca1f 157static inline void cmx270_init_rtc(void) {}
4adc5fb6
MR
158#endif
159
160/* 2700G graphics */
161#if defined(CONFIG_FB_MBX) || defined(CONFIG_FB_MBX_MODULE)
162static u64 fb_dma_mask = ~(u64)0;
163
164static struct resource cmx270_2700G_resource[] = {
165 /* frame buffer memory including ODFB and External SDRAM */
166 [0] = {
167 .start = PXA_CS2_PHYS,
168 .end = PXA_CS2_PHYS + 0x01ffffff,
169 .flags = IORESOURCE_MEM,
170 },
171 /* Marathon registers */
172 [1] = {
173 .start = PXA_CS2_PHYS + 0x03fe0000,
174 .end = PXA_CS2_PHYS + 0x03ffffff,
175 .flags = IORESOURCE_MEM,
176 },
177};
178
96f6a13a
EM
179static unsigned long cmx270_marathon_on[] = {
180 GPIO58_GPIO,
181 GPIO59_GPIO,
182 GPIO60_GPIO,
183 GPIO61_GPIO,
184 GPIO62_GPIO,
185 GPIO63_GPIO,
186 GPIO64_GPIO,
187 GPIO65_GPIO,
188 GPIO66_GPIO,
189 GPIO67_GPIO,
190 GPIO68_GPIO,
191 GPIO69_GPIO,
192 GPIO70_GPIO,
193 GPIO71_GPIO,
194 GPIO72_GPIO,
195 GPIO73_GPIO,
196 GPIO74_GPIO,
197 GPIO75_GPIO,
198 GPIO76_GPIO,
199 GPIO77_GPIO,
200};
201
202static unsigned long cmx270_marathon_off[] = {
203 GPIOxx_LCD_TFT_16BPP,
204};
4adc5fb6
MR
205
206static int cmx270_marathon_probe(struct fb_info *fb)
207{
96f6a13a
EM
208 int gpio, err;
209
210 for (gpio = 58; gpio <= 77; gpio++) {
211 err = gpio_request(gpio, "LCD");
212 if (err)
213 return err;
214 gpio_direction_input(gpio);
215 }
216
217 pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_marathon_on));
4adc5fb6
MR
218 return 0;
219}
220
221static int cmx270_marathon_remove(struct fb_info *fb)
222{
96f6a13a
EM
223 int gpio;
224
225 pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_marathon_off));
226
227 for (gpio = 58; gpio <= 77; gpio++)
228 gpio_free(gpio);
229
4adc5fb6
MR
230 return 0;
231}
232
233static struct mbxfb_platform_data cmx270_2700G_data = {
234 .xres = {
235 .min = 240,
236 .max = 1200,
237 .defval = 640,
238 },
239 .yres = {
240 .min = 240,
241 .max = 1200,
242 .defval = 480,
243 },
244 .bpp = {
245 .min = 16,
246 .max = 32,
247 .defval = 16,
248 },
249 .memsize = 8*1024*1024,
250 .probe = cmx270_marathon_probe,
251 .remove = cmx270_marathon_remove,
252};
253
254static struct platform_device cmx270_2700G = {
255 .name = "mbx-fb",
256 .dev = {
257 .platform_data = &cmx270_2700G_data,
258 .dma_mask = &fb_dma_mask,
259 .coherent_dma_mask = 0xffffffff,
260 },
261 .num_resources = ARRAY_SIZE(cmx270_2700G_resource),
262 .resource = cmx270_2700G_resource,
263 .id = -1,
264};
265
266static void __init cmx270_init_2700G(void)
267{
268 platform_device_register(&cmx270_2700G);
269}
270#else
271static inline void cmx270_init_2700G(void) {}
272#endif
273
274/* PXA27x OHCI controller setup */
275#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
4adc5fb6
MR
276static struct pxaohci_platform_data cmx270_ohci_platform_data = {
277 .port_mode = PMM_PERPORT_MODE,
097b5334 278 .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
4adc5fb6
MR
279};
280
281static void __init cmx270_init_ohci(void)
282{
283 pxa_set_ohci_info(&cmx270_ohci_platform_data);
284}
285#else
286static inline void cmx270_init_ohci(void) {}
287#endif
288
289#if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
4adc5fb6 290static struct pxamci_platform_data cmx270_mci_platform_data = {
7a648256 291 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
4adc5fb6
MR
292};
293
32d15448
LW
294static struct gpiod_lookup_table cmx270_mci_gpio_table = {
295 .dev_id = "pxa2xx-mci.0",
296 .table = {
297 /* Card detect on GPIO 83 */
298 GPIO_LOOKUP("gpio-pxa", GPIO83_MMC_IRQ, "cd", GPIO_ACTIVE_LOW),
f54005b5
LW
299 /* Power on GPIO 105 */
300 GPIO_LOOKUP("gpio-pxa", GPIO105_MMC_POWER,
301 "power", GPIO_ACTIVE_LOW),
32d15448
LW
302 { },
303 },
304};
305
4adc5fb6
MR
306static void __init cmx270_init_mmc(void)
307{
32d15448 308 gpiod_add_lookup_table(&cmx270_mci_gpio_table);
4adc5fb6
MR
309 pxa_set_mci_info(&cmx270_mci_platform_data);
310}
311#else
312static inline void cmx270_init_mmc(void) {}
313#endif
314
a2099e49 315#if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
51eea52d 316static struct pxa2xx_spi_controller cm_x270_spi_info = {
a2099e49
MR
317 .num_chipselect = 1,
318 .enable_dma = 1,
319};
320
321static struct pxa2xx_spi_chip cm_x270_libertas_chip = {
322 .rx_threshold = 1,
323 .tx_threshold = 1,
324 .timeout = 1000,
325 .gpio_cs = 14,
326};
327
328static unsigned long cm_x270_libertas_pin_config[] = {
329 /* SSP2 */
330 GPIO19_SSP2_SCLK,
331 GPIO14_GPIO,
332 GPIO87_SSP2_TXD,
333 GPIO88_SSP2_RXD,
334
335};
336
337static int cm_x270_libertas_setup(struct spi_device *spi)
338{
339 int err = gpio_request(GPIO19_WLAN_STRAP, "WLAN STRAP");
340 if (err)
341 return err;
342
343 err = gpio_request(GPIO102_WLAN_RST, "WLAN RST");
344 if (err)
345 goto err_free_strap;
346
347 err = gpio_direction_output(GPIO102_WLAN_RST, 0);
348 if (err)
349 goto err_free_strap;
350 msleep(100);
351
352 err = gpio_direction_output(GPIO19_WLAN_STRAP, 1);
353 if (err)
354 goto err_free_strap;
355 msleep(100);
356
357 pxa2xx_mfp_config(ARRAY_AND_SIZE(cm_x270_libertas_pin_config));
358
359 gpio_set_value(GPIO102_WLAN_RST, 1);
360 msleep(100);
361
362 spi->bits_per_word = 16;
363 spi_setup(spi);
364
365 return 0;
366
367err_free_strap:
368 gpio_free(GPIO19_WLAN_STRAP);
369
370 return err;
371}
372
373static int cm_x270_libertas_teardown(struct spi_device *spi)
374{
375 gpio_set_value(GPIO102_WLAN_RST, 0);
376 gpio_free(GPIO102_WLAN_RST);
377 gpio_free(GPIO19_WLAN_STRAP);
378
379 return 0;
380}
381
382struct libertas_spi_platform_data cm_x270_libertas_pdata = {
383 .use_dummy_writes = 1,
384 .setup = cm_x270_libertas_setup,
385 .teardown = cm_x270_libertas_teardown,
386};
387
388static struct spi_board_info cm_x270_spi_devices[] __initdata = {
389 {
390 .modalias = "libertas_spi",
391 .max_speed_hz = 13000000,
392 .bus_num = 2,
4929f5a8 393 .irq = PXA_GPIO_TO_IRQ(95),
a2099e49
MR
394 .chip_select = 0,
395 .controller_data = &cm_x270_libertas_chip,
396 .platform_data = &cm_x270_libertas_pdata,
397 },
398};
399
400static void __init cmx270_init_spi(void)
401{
402 pxa2xx_set_spi_info(2, &cm_x270_spi_info);
403 spi_register_board_info(ARRAY_AND_SIZE(cm_x270_spi_devices));
404}
405#else
406static inline void cmx270_init_spi(void) {}
407#endif
408
4adc5fb6
MR
409void __init cmx270_init(void)
410{
411 pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_pin_config));
412
9599d1db
MR
413#ifdef CONFIG_PM
414 pxa27x_set_pwrmode(PWRMODE_DEEPSLEEP);
415#endif
416
4adc5fb6
MR
417 cmx270_init_rtc();
418 cmx270_init_mmc();
419 cmx270_init_ohci();
420 cmx270_init_2700G();
a2099e49 421 cmx270_init_spi();
4adc5fb6 422}