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