blob: b6a51340270b9a433c0fbce5335793237c30ee18 [file] [log] [blame]
Mike Rapoportcf75d8d2008-08-26 14:03:44 +01001/*
2 * linux/arch/arm/mach-pxa/cm-x300.c
3 *
4 * Support for the CompuLab CM-X300 modules
5 *
Igor Grinberg14fd9e02009-10-14 09:20:25 +02006 * Copyright (C) 2008,2009 CompuLab Ltd.
Mike Rapoportcf75d8d2008-08-26 14:03:44 +01007 *
8 * Mike Rapoport <mike@compulab.co.il>
Igor Grinberg14fd9e02009-10-14 09:20:25 +02009 * Igor Grinberg <grinberg@compulab.co.il>
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
Igor Grinberg32de50e2011-05-09 14:41:48 +030015#define pr_fmt(fmt) "%s: " fmt, __func__
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010016
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/interrupt.h>
20#include <linux/init.h>
Igor Grinbergb3d01da2009-10-14 09:20:21 +020021#include <linux/delay.h>
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010022#include <linux/platform_device.h>
Igor Grinberg1b43d8e2010-07-27 15:07:00 +030023#include <linux/clk.h>
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010024
25#include <linux/gpio.h>
26#include <linux/dm9000.h>
27#include <linux/leds.h>
Mike Rapoport1858ced2009-06-04 10:44:52 +030028#include <linux/rtc-v3020.h>
Igor Grinbergdb205462009-11-10 14:18:41 +020029#include <linux/pwm_backlight.h>
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010030
31#include <linux/i2c.h>
32#include <linux/i2c/pca953x.h>
Sebastian Andrzej Siewiorb4593962011-02-23 12:38:16 +010033#include <linux/i2c/pxa-i2c.h>
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010034
Igor Grinberg9c017ca2009-10-14 09:20:24 +020035#include <linux/mfd/da903x.h>
Igor Grinbergd176d642010-03-09 11:43:51 +020036#include <linux/regulator/machine.h>
Igor Grinberg03ba7e02010-03-09 11:43:48 +020037#include <linux/power_supply.h>
38#include <linux/apm-emulation.h>
Igor Grinberg9c017ca2009-10-14 09:20:24 +020039
Igor Grinberg83e560e2009-10-14 09:20:19 +020040#include <linux/spi/spi.h>
41#include <linux/spi/spi_gpio.h>
42#include <linux/spi/tdo24m.h>
43
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010044#include <asm/mach-types.h>
45#include <asm/mach/arch.h>
Mike Rapoportb5a5c472009-06-04 10:44:54 +030046#include <asm/setup.h>
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010047
Eric Miao51c62982009-01-02 23:17:22 +080048#include <mach/pxa300.h>
Igor Grinbergedaa64c2009-10-14 09:20:23 +020049#include <mach/pxa27x-udc.h>
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010050#include <mach/pxafb.h>
51#include <mach/mmc.h>
52#include <mach/ohci.h>
Haojian Zhuang82b95ec2009-09-10 13:55:23 +080053#include <plat/pxa3xx_nand.h>
Igor Grinberg74e74de2009-10-14 09:20:20 +020054#include <mach/audio.h>
Igor Grinberg1b43d8e2010-07-27 15:07:00 +030055#include <mach/pxa3xx-u2d.h>
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010056
57#include <asm/mach/map.h>
58
59#include "generic.h"
Igor Grinbergdb205462009-11-10 14:18:41 +020060#include "devices.h"
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010061
62#define CM_X300_ETH_PHYS 0x08000010
63
Mike Rapoport0bff2fc2009-10-15 10:11:09 +020064#define GPIO82_MMC_IRQ (82)
65#define GPIO85_MMC_WP (85)
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010066
Mike Rapoport0bff2fc2009-10-15 10:11:09 +020067#define CM_X300_MMC_IRQ IRQ_GPIO(GPIO82_MMC_IRQ)
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010068
Mike Rapoport1858ced2009-06-04 10:44:52 +030069#define GPIO95_RTC_CS (95)
70#define GPIO96_RTC_WR (96)
71#define GPIO97_RTC_RD (97)
72#define GPIO98_RTC_IO (98)
73
Igor Grinberg1b43d8e2010-07-27 15:07:00 +030074#define GPIO_ULPI_PHY_RST (127)
75
Igor Grinbergdef82522009-10-14 09:20:22 +020076static mfp_cfg_t cm_x3xx_mfp_cfg[] __initdata = {
Mike Rapoportcf75d8d2008-08-26 14:03:44 +010077 /* LCD */
78 GPIO54_LCD_LDD_0,
79 GPIO55_LCD_LDD_1,
80 GPIO56_LCD_LDD_2,
81 GPIO57_LCD_LDD_3,
82 GPIO58_LCD_LDD_4,
83 GPIO59_LCD_LDD_5,
84 GPIO60_LCD_LDD_6,
85 GPIO61_LCD_LDD_7,
86 GPIO62_LCD_LDD_8,
87 GPIO63_LCD_LDD_9,
88 GPIO64_LCD_LDD_10,
89 GPIO65_LCD_LDD_11,
90 GPIO66_LCD_LDD_12,
91 GPIO67_LCD_LDD_13,
92 GPIO68_LCD_LDD_14,
93 GPIO69_LCD_LDD_15,
94 GPIO72_LCD_FCLK,
95 GPIO73_LCD_LCLK,
96 GPIO74_LCD_PCLK,
97 GPIO75_LCD_BIAS,
98
99 /* BTUART */
100 GPIO111_UART2_RTS,
101 GPIO112_UART2_RXD | MFP_LPM_EDGE_FALL,
102 GPIO113_UART2_TXD,
103 GPIO114_UART2_CTS | MFP_LPM_EDGE_BOTH,
104
105 /* STUART */
106 GPIO109_UART3_TXD,
107 GPIO110_UART3_RXD | MFP_LPM_EDGE_FALL,
108
109 /* AC97 */
110 GPIO23_AC97_nACRESET,
111 GPIO24_AC97_SYSCLK,
112 GPIO29_AC97_BITCLK,
113 GPIO25_AC97_SDATA_IN_0,
114 GPIO27_AC97_SDATA_OUT,
115 GPIO28_AC97_SYNC,
116
117 /* Keypad */
118 GPIO115_KP_MKIN_0 | MFP_LPM_EDGE_BOTH,
119 GPIO116_KP_MKIN_1 | MFP_LPM_EDGE_BOTH,
120 GPIO117_KP_MKIN_2 | MFP_LPM_EDGE_BOTH,
121 GPIO118_KP_MKIN_3 | MFP_LPM_EDGE_BOTH,
122 GPIO119_KP_MKIN_4 | MFP_LPM_EDGE_BOTH,
123 GPIO120_KP_MKIN_5 | MFP_LPM_EDGE_BOTH,
124 GPIO2_2_KP_MKIN_6 | MFP_LPM_EDGE_BOTH,
125 GPIO3_2_KP_MKIN_7 | MFP_LPM_EDGE_BOTH,
126 GPIO121_KP_MKOUT_0,
127 GPIO122_KP_MKOUT_1,
128 GPIO123_KP_MKOUT_2,
129 GPIO124_KP_MKOUT_3,
130 GPIO125_KP_MKOUT_4,
131 GPIO4_2_KP_MKOUT_5,
132
133 /* MMC1 */
134 GPIO3_MMC1_DAT0,
135 GPIO4_MMC1_DAT1 | MFP_LPM_EDGE_BOTH,
136 GPIO5_MMC1_DAT2,
137 GPIO6_MMC1_DAT3,
138 GPIO7_MMC1_CLK,
139 GPIO8_MMC1_CMD, /* CMD0 for slot 0 */
140
141 /* MMC2 */
142 GPIO9_MMC2_DAT0,
143 GPIO10_MMC2_DAT1 | MFP_LPM_EDGE_BOTH,
144 GPIO11_MMC2_DAT2,
145 GPIO12_MMC2_DAT3,
146 GPIO13_MMC2_CLK,
147 GPIO14_MMC2_CMD,
148
149 /* FFUART */
150 GPIO30_UART1_RXD | MFP_LPM_EDGE_FALL,
151 GPIO31_UART1_TXD,
152 GPIO32_UART1_CTS,
153 GPIO37_UART1_RTS,
154 GPIO33_UART1_DCD,
155 GPIO34_UART1_DSR | MFP_LPM_EDGE_FALL,
156 GPIO35_UART1_RI,
157 GPIO36_UART1_DTR,
158
159 /* GPIOs */
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100160 GPIO82_GPIO | MFP_PULL_HIGH, /* MMC CD */
161 GPIO85_GPIO, /* MMC WP */
162 GPIO99_GPIO, /* Ethernet IRQ */
Eric Miao6f584cf2008-11-28 16:00:24 +0800163
Mike Rapoport1858ced2009-06-04 10:44:52 +0300164 /* RTC GPIOs */
Igor Grinberg6c7b3ea2011-05-09 14:41:46 +0300165 GPIO95_GPIO | MFP_LPM_DRIVE_HIGH, /* RTC CS */
166 GPIO96_GPIO | MFP_LPM_DRIVE_HIGH, /* RTC WR */
167 GPIO97_GPIO | MFP_LPM_DRIVE_HIGH, /* RTC RD */
168 GPIO98_GPIO, /* RTC IO */
Mike Rapoport1858ced2009-06-04 10:44:52 +0300169
Eric Miao6f584cf2008-11-28 16:00:24 +0800170 /* Standard I2C */
171 GPIO21_I2C_SCL,
172 GPIO22_I2C_SDA,
Igor Grinbergdb205462009-11-10 14:18:41 +0200173
174 /* PWM Backlight */
175 GPIO19_PWM2_OUT,
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100176};
177
Igor Grinbergdef82522009-10-14 09:20:22 +0200178static mfp_cfg_t cm_x3xx_rev_lt130_mfp_cfg[] __initdata = {
Igor Grinberg55052ea2009-10-14 09:20:18 +0200179 /* GPIOs */
180 GPIO79_GPIO, /* LED */
181 GPIO77_GPIO, /* WiFi reset */
182 GPIO78_GPIO, /* BT reset */
183};
184
Igor Grinbergdef82522009-10-14 09:20:22 +0200185static mfp_cfg_t cm_x3xx_rev_ge130_mfp_cfg[] __initdata = {
Igor Grinberg55052ea2009-10-14 09:20:18 +0200186 /* GPIOs */
187 GPIO76_GPIO, /* LED */
188 GPIO71_GPIO, /* WiFi reset */
189 GPIO70_GPIO, /* BT reset */
190};
191
Igor Grinbergdef82522009-10-14 09:20:22 +0200192static mfp_cfg_t cm_x310_mfp_cfg[] __initdata = {
193 /* USB PORT 2 */
194 ULPI_STP,
195 ULPI_NXT,
196 ULPI_DIR,
197 GPIO30_ULPI_DATA_OUT_0,
198 GPIO31_ULPI_DATA_OUT_1,
199 GPIO32_ULPI_DATA_OUT_2,
200 GPIO33_ULPI_DATA_OUT_3,
201 GPIO34_ULPI_DATA_OUT_4,
202 GPIO35_ULPI_DATA_OUT_5,
203 GPIO36_ULPI_DATA_OUT_6,
204 GPIO37_ULPI_DATA_OUT_7,
205 GPIO38_ULPI_CLK,
206 /* external PHY reset pin */
207 GPIO127_GPIO,
208
209 /* USB PORT 3 */
210 GPIO77_USB_P3_1,
211 GPIO78_USB_P3_2,
212 GPIO79_USB_P3_3,
213 GPIO80_USB_P3_4,
214 GPIO81_USB_P3_5,
215 GPIO82_USB_P3_6,
216 GPIO0_2_USBH_PEN,
217};
218
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100219#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
220static struct resource dm9000_resources[] = {
221 [0] = {
222 .start = CM_X300_ETH_PHYS,
223 .end = CM_X300_ETH_PHYS + 0x3,
224 .flags = IORESOURCE_MEM,
225 },
226 [1] = {
227 .start = CM_X300_ETH_PHYS + 0x4,
228 .end = CM_X300_ETH_PHYS + 0x4 + 500,
229 .flags = IORESOURCE_MEM,
230 },
231 [2] = {
232 .start = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO99)),
233 .end = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO99)),
234 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
235 }
236};
237
238static struct dm9000_plat_data cm_x300_dm9000_platdata = {
Mike Rapoportbff22c92009-02-23 18:01:12 +0200239 .flags = DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM,
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100240};
241
242static struct platform_device dm9000_device = {
243 .name = "dm9000",
244 .id = 0,
245 .num_resources = ARRAY_SIZE(dm9000_resources),
246 .resource = dm9000_resources,
247 .dev = {
248 .platform_data = &cm_x300_dm9000_platdata,
249 }
250
251};
252
253static void __init cm_x300_init_dm9000(void)
254{
255 platform_device_register(&dm9000_device);
256}
257#else
258static inline void cm_x300_init_dm9000(void) {}
259#endif
260
Igor Grinberg83e560e2009-10-14 09:20:19 +0200261/* LCD */
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100262#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
263static struct pxafb_mode_info cm_x300_lcd_modes[] = {
264 [0] = {
Igor Grinberg83e560e2009-10-14 09:20:19 +0200265 .pixclock = 38250,
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100266 .bpp = 16,
267 .xres = 480,
268 .yres = 640,
269 .hsync_len = 8,
270 .vsync_len = 2,
271 .left_margin = 8,
Igor Grinberg83e560e2009-10-14 09:20:19 +0200272 .upper_margin = 2,
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100273 .right_margin = 24,
274 .lower_margin = 4,
275 .cmap_greyscale = 0,
276 },
277 [1] = {
278 .pixclock = 153800,
279 .bpp = 16,
280 .xres = 240,
281 .yres = 320,
282 .hsync_len = 8,
283 .vsync_len = 2,
284 .left_margin = 8,
285 .upper_margin = 2,
286 .right_margin = 88,
287 .lower_margin = 2,
288 .cmap_greyscale = 0,
289 },
290};
291
292static struct pxafb_mach_info cm_x300_lcd = {
293 .modes = cm_x300_lcd_modes,
Igor Grinberg83e560e2009-10-14 09:20:19 +0200294 .num_modes = ARRAY_SIZE(cm_x300_lcd_modes),
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100295 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
296};
297
298static void __init cm_x300_init_lcd(void)
299{
Russell King - ARM Linux4321e1a2011-02-15 15:37:30 +0800300 pxa_set_fb_info(NULL, &cm_x300_lcd);
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100301}
302#else
303static inline void cm_x300_init_lcd(void) {}
304#endif
305
Igor Grinbergdb205462009-11-10 14:18:41 +0200306#if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
307static struct platform_pwm_backlight_data cm_x300_backlight_data = {
308 .pwm_id = 2,
309 .max_brightness = 100,
310 .dft_brightness = 100,
311 .pwm_period_ns = 10000,
312};
313
314static struct platform_device cm_x300_backlight_device = {
315 .name = "pwm-backlight",
316 .dev = {
317 .parent = &pxa27x_device_pwm0.dev,
318 .platform_data = &cm_x300_backlight_data,
319 },
320};
321
322static void cm_x300_init_bl(void)
323{
324 platform_device_register(&cm_x300_backlight_device);
325}
326#else
327static inline void cm_x300_init_bl(void) {}
328#endif
329
Igor Grinberg83e560e2009-10-14 09:20:19 +0200330#if defined(CONFIG_SPI_GPIO) || defined(CONFIG_SPI_GPIO_MODULE)
331#define GPIO_LCD_BASE (144)
332#define GPIO_LCD_DIN (GPIO_LCD_BASE + 8) /* aux_gpio3_0 */
333#define GPIO_LCD_DOUT (GPIO_LCD_BASE + 9) /* aux_gpio3_1 */
334#define GPIO_LCD_SCL (GPIO_LCD_BASE + 10) /* aux_gpio3_2 */
335#define GPIO_LCD_CS (GPIO_LCD_BASE + 11) /* aux_gpio3_3 */
336#define LCD_SPI_BUS_NUM (1)
337
338static struct spi_gpio_platform_data cm_x300_spi_gpio_pdata = {
339 .sck = GPIO_LCD_SCL,
340 .mosi = GPIO_LCD_DIN,
341 .miso = GPIO_LCD_DOUT,
342 .num_chipselect = 1,
343};
344
345static struct platform_device cm_x300_spi_gpio = {
346 .name = "spi_gpio",
347 .id = LCD_SPI_BUS_NUM,
348 .dev = {
349 .platform_data = &cm_x300_spi_gpio_pdata,
350 },
351};
352
353static struct tdo24m_platform_data cm_x300_tdo24m_pdata = {
354 .model = TDO35S,
355};
356
357static struct spi_board_info cm_x300_spi_devices[] __initdata = {
358 {
359 .modalias = "tdo24m",
360 .max_speed_hz = 1000000,
361 .bus_num = LCD_SPI_BUS_NUM,
362 .chip_select = 0,
363 .controller_data = (void *) GPIO_LCD_CS,
364 .platform_data = &cm_x300_tdo24m_pdata,
365 },
366};
367
368static void __init cm_x300_init_spi(void)
369{
370 spi_register_board_info(cm_x300_spi_devices,
371 ARRAY_SIZE(cm_x300_spi_devices));
372 platform_device_register(&cm_x300_spi_gpio);
373}
374#else
375static inline void cm_x300_init_spi(void) {}
376#endif
377
Igor Grinberg74e74de2009-10-14 09:20:20 +0200378#if defined(CONFIG_SND_PXA2XX_LIB_AC97)
379static void __init cm_x300_init_ac97(void)
380{
381 pxa_set_ac97_info(NULL);
382}
383#else
384static inline void cm_x300_init_ac97(void) {}
385#endif
386
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100387#if defined(CONFIG_MTD_NAND_PXA3xx) || defined(CONFIG_MTD_NAND_PXA3xx_MODULE)
388static struct mtd_partition cm_x300_nand_partitions[] = {
389 [0] = {
390 .name = "OBM",
391 .offset = 0,
392 .size = SZ_256K,
393 .mask_flags = MTD_WRITEABLE, /* force read-only */
394 },
395 [1] = {
396 .name = "U-Boot",
397 .offset = MTDPART_OFS_APPEND,
398 .size = SZ_256K,
399 .mask_flags = MTD_WRITEABLE, /* force read-only */
400 },
401 [2] = {
402 .name = "Environment",
403 .offset = MTDPART_OFS_APPEND,
404 .size = SZ_256K,
405 },
406 [3] = {
407 .name = "reserved",
408 .offset = MTDPART_OFS_APPEND,
409 .size = SZ_256K + SZ_1M,
410 .mask_flags = MTD_WRITEABLE, /* force read-only */
411 },
412 [4] = {
413 .name = "kernel",
414 .offset = MTDPART_OFS_APPEND,
415 .size = SZ_4M,
416 },
417 [5] = {
418 .name = "fs",
419 .offset = MTDPART_OFS_APPEND,
420 .size = MTDPART_SIZ_FULL,
421 },
422};
423
424static struct pxa3xx_nand_platform_data cm_x300_nand_info = {
425 .enable_arbiter = 1,
Mike Rapoportb3992b62009-06-04 10:44:51 +0300426 .keep_config = 1,
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100427 .parts = cm_x300_nand_partitions,
428 .nr_parts = ARRAY_SIZE(cm_x300_nand_partitions),
429};
430
431static void __init cm_x300_init_nand(void)
432{
433 pxa3xx_set_nand_info(&cm_x300_nand_info);
434}
435#else
436static inline void cm_x300_init_nand(void) {}
437#endif
438
439#if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
Mike Rapoport0bff2fc2009-10-15 10:11:09 +0200440static struct pxamci_platform_data cm_x300_mci_platform_data = {
Eric Miaof97cab22010-04-14 07:00:42 +0800441 .detect_delay_ms = 200,
Mike Rapoport0bff2fc2009-10-15 10:11:09 +0200442 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
443 .gpio_card_detect = GPIO82_MMC_IRQ,
444 .gpio_card_ro = GPIO85_MMC_WP,
445 .gpio_power = -1,
446};
447
448/* The second MMC slot of CM-X300 is hardwired to Libertas card and has
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100449 no detection/ro pins */
Mike Rapoport0bff2fc2009-10-15 10:11:09 +0200450static int cm_x300_mci2_init(struct device *dev,
451 irq_handler_t cm_x300_detect_int,
452 void *data)
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100453{
454 return 0;
455}
456
Mike Rapoport0bff2fc2009-10-15 10:11:09 +0200457static void cm_x300_mci2_exit(struct device *dev, void *data)
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100458{
459}
460
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100461static struct pxamci_platform_data cm_x300_mci2_platform_data = {
Eric Miaof97cab22010-04-14 07:00:42 +0800462 .detect_delay_ms = 200,
Robert Jarzmik7a648252009-07-06 22:16:42 +0200463 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
Mike Rapoport0bff2fc2009-10-15 10:11:09 +0200464 .init = cm_x300_mci2_init,
465 .exit = cm_x300_mci2_exit,
466 .gpio_card_detect = -1,
467 .gpio_card_ro = -1,
Robert Jarzmik7a648252009-07-06 22:16:42 +0200468 .gpio_power = -1,
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100469};
470
471static void __init cm_x300_init_mmc(void)
472{
473 pxa_set_mci_info(&cm_x300_mci_platform_data);
474 pxa3xx_set_mci2_info(&cm_x300_mci2_platform_data);
475}
476#else
477static inline void cm_x300_init_mmc(void) {}
478#endif
479
Igor Grinberg1b43d8e2010-07-27 15:07:00 +0300480#if defined(CONFIG_PXA310_ULPI)
481static struct clk *pout_clk;
482
483static int cm_x300_ulpi_phy_reset(void)
484{
485 int err;
486
487 /* reset the PHY */
Igor Grinberg5a009df2011-05-09 14:41:47 +0300488 err = gpio_request_one(GPIO_ULPI_PHY_RST, GPIOF_OUT_INIT_LOW,
489 "ulpi reset");
Igor Grinberg1b43d8e2010-07-27 15:07:00 +0300490 if (err) {
Igor Grinberg32de50e2011-05-09 14:41:48 +0300491 pr_err("failed to request ULPI reset GPIO: %d\n", err);
Igor Grinberg1b43d8e2010-07-27 15:07:00 +0300492 return err;
493 }
494
Igor Grinberg1b43d8e2010-07-27 15:07:00 +0300495 msleep(10);
496 gpio_set_value(GPIO_ULPI_PHY_RST, 1);
497 msleep(10);
498
499 gpio_free(GPIO_ULPI_PHY_RST);
500
501 return 0;
502}
503
504static inline int cm_x300_u2d_init(struct device *dev)
505{
506 int err = 0;
507
508 if (cpu_is_pxa310()) {
509 /* CLK_POUT is connected to the ULPI PHY */
510 pout_clk = clk_get(NULL, "CLK_POUT");
511 if (IS_ERR(pout_clk)) {
512 err = PTR_ERR(pout_clk);
Igor Grinberg32de50e2011-05-09 14:41:48 +0300513 pr_err("failed to get CLK_POUT: %d\n", err);
Igor Grinberg1b43d8e2010-07-27 15:07:00 +0300514 return err;
515 }
516 clk_enable(pout_clk);
517
518 err = cm_x300_ulpi_phy_reset();
519 if (err) {
520 clk_disable(pout_clk);
521 clk_put(pout_clk);
522 }
523 }
524
525 return err;
526}
527
528static void cm_x300_u2d_exit(struct device *dev)
529{
530 if (cpu_is_pxa310()) {
531 clk_disable(pout_clk);
532 clk_put(pout_clk);
533 }
534}
535
536static struct pxa3xx_u2d_platform_data cm_x300_u2d_platform_data = {
537 .ulpi_mode = ULPI_SER_6PIN,
538 .init = cm_x300_u2d_init,
539 .exit = cm_x300_u2d_exit,
540};
541
542static void cm_x300_init_u2d(void)
543{
544 pxa3xx_set_u2d_info(&cm_x300_u2d_platform_data);
545}
546#else
547static inline void cm_x300_init_u2d(void) {}
548#endif
549
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100550#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
Igor Grinbergedaa64c2009-10-14 09:20:23 +0200551static int cm_x300_ohci_init(struct device *dev)
552{
553 if (cpu_is_pxa300())
554 UP2OCR = UP2OCR_HXS
555 | UP2OCR_HXOE | UP2OCR_DMPDE | UP2OCR_DPPDE;
556
557 return 0;
558}
559
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100560static struct pxaohci_platform_data cm_x300_ohci_platform_data = {
561 .port_mode = PMM_PERPORT_MODE,
Igor Grinbergedaa64c2009-10-14 09:20:23 +0200562 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW,
563 .init = cm_x300_ohci_init,
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100564};
Eric Miao097b5332008-09-27 15:49:57 +0800565
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100566static void __init cm_x300_init_ohci(void)
567{
568 pxa_set_ohci_info(&cm_x300_ohci_platform_data);
569}
570#else
571static inline void cm_x300_init_ohci(void) {}
572#endif
573
574#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
575static struct gpio_led cm_x300_leds[] = {
576 [0] = {
577 .name = "cm-x300:green",
578 .default_trigger = "heartbeat",
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100579 .active_low = 1,
580 },
581};
582
583static struct gpio_led_platform_data cm_x300_gpio_led_pdata = {
584 .num_leds = ARRAY_SIZE(cm_x300_leds),
585 .leds = cm_x300_leds,
586};
587
588static struct platform_device cm_x300_led_device = {
589 .name = "leds-gpio",
590 .id = -1,
591 .dev = {
592 .platform_data = &cm_x300_gpio_led_pdata,
593 },
594};
595
596static void __init cm_x300_init_leds(void)
597{
Igor Grinberg55052ea2009-10-14 09:20:18 +0200598 if (system_rev < 130)
599 cm_x300_leds[0].gpio = 79;
600 else
601 cm_x300_leds[0].gpio = 76;
602
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100603 platform_device_register(&cm_x300_led_device);
604}
605#else
606static inline void cm_x300_init_leds(void) {}
607#endif
608
609#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
610/* PCA9555 */
611static struct pca953x_platform_data cm_x300_gpio_ext_pdata_0 = {
612 .gpio_base = 128,
613};
614
615static struct pca953x_platform_data cm_x300_gpio_ext_pdata_1 = {
616 .gpio_base = 144,
617};
618
619static struct i2c_board_info cm_x300_gpio_ext_info[] = {
620 [0] = {
621 I2C_BOARD_INFO("pca9555", 0x24),
622 .platform_data = &cm_x300_gpio_ext_pdata_0,
623 },
624 [1] = {
625 I2C_BOARD_INFO("pca9555", 0x25),
626 .platform_data = &cm_x300_gpio_ext_pdata_1,
627 },
628};
629
630static void __init cm_x300_init_i2c(void)
631{
632 pxa_set_i2c_info(NULL);
633 i2c_register_board_info(0, cm_x300_gpio_ext_info,
634 ARRAY_SIZE(cm_x300_gpio_ext_info));
635}
636#else
637static inline void cm_x300_init_i2c(void) {}
638#endif
639
Mike Rapoport1858ced2009-06-04 10:44:52 +0300640#if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
641struct v3020_platform_data cm_x300_v3020_pdata = {
642 .use_gpio = 1,
643 .gpio_cs = GPIO95_RTC_CS,
644 .gpio_wr = GPIO96_RTC_WR,
645 .gpio_rd = GPIO97_RTC_RD,
646 .gpio_io = GPIO98_RTC_IO,
647};
648
649static struct platform_device cm_x300_rtc_device = {
650 .name = "v3020",
651 .id = -1,
652 .dev = {
653 .platform_data = &cm_x300_v3020_pdata,
654 }
655};
656
657static void __init cm_x300_init_rtc(void)
658{
659 platform_device_register(&cm_x300_rtc_device);
660}
661#else
662static inline void cm_x300_init_rtc(void) {}
663#endif
664
Igor Grinberg03ba7e02010-03-09 11:43:48 +0200665/* Battery */
666struct power_supply_info cm_x300_psy_info = {
667 .name = "battery",
668 .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
669 .voltage_max_design = 4200000,
670 .voltage_min_design = 3000000,
671 .use_for_apm = 1,
672};
673
674static void cm_x300_battery_low(void)
675{
676#if defined(CONFIG_APM_EMULATION)
677 apm_queue_event(APM_LOW_BATTERY);
678#endif
679}
680
681static void cm_x300_battery_critical(void)
682{
683#if defined(CONFIG_APM_EMULATION)
684 apm_queue_event(APM_CRITICAL_SUSPEND);
685#endif
686}
687
688struct da9030_battery_info cm_x300_battery_info = {
689 .battery_info = &cm_x300_psy_info,
690
691 .charge_milliamp = 1000,
692 .charge_millivolt = 4200,
693
694 .vbat_low = 3600,
695 .vbat_crit = 3400,
696 .vbat_charge_start = 4100,
697 .vbat_charge_stop = 4200,
698 .vbat_charge_restart = 4000,
699
700 .vcharge_min = 3200,
701 .vcharge_max = 5500,
702
703 .tbat_low = 197,
704 .tbat_high = 78,
705 .tbat_restart = 100,
706
707 .batmon_interval = 0,
708
709 .battery_low = cm_x300_battery_low,
710 .battery_critical = cm_x300_battery_critical,
711};
712
Igor Grinbergd176d642010-03-09 11:43:51 +0200713static struct regulator_consumer_supply buck2_consumers[] = {
714 {
715 .dev = NULL,
716 .supply = "vcc_core",
717 },
718};
719
720static struct regulator_init_data buck2_data = {
721 .constraints = {
722 .min_uV = 1375000,
723 .max_uV = 1375000,
724 .state_mem = {
725 .enabled = 0,
726 },
727 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
728 .apply_uV = 1,
729 },
730 .num_consumer_supplies = ARRAY_SIZE(buck2_consumers),
731 .consumer_supplies = buck2_consumers,
732};
733
Igor Grinberg9c017ca2009-10-14 09:20:24 +0200734/* DA9030 */
735struct da903x_subdev_info cm_x300_da9030_subdevs[] = {
736 {
Igor Grinberg03ba7e02010-03-09 11:43:48 +0200737 .name = "da903x-battery",
738 .id = DA9030_ID_BAT,
739 .platform_data = &cm_x300_battery_info,
740 },
Igor Grinbergd176d642010-03-09 11:43:51 +0200741 {
742 .name = "da903x-regulator",
743 .id = DA9030_ID_BUCK2,
744 .platform_data = &buck2_data,
745 },
Igor Grinberg9c017ca2009-10-14 09:20:24 +0200746};
747
748static struct da903x_platform_data cm_x300_da9030_info = {
749 .num_subdevs = ARRAY_SIZE(cm_x300_da9030_subdevs),
750 .subdevs = cm_x300_da9030_subdevs,
751};
752
753static struct i2c_board_info cm_x300_pmic_info = {
754 I2C_BOARD_INFO("da9030", 0x49),
Igor Grinberge4e30972010-03-09 11:43:50 +0200755 .irq = IRQ_WAKEUP0,
Igor Grinberg9c017ca2009-10-14 09:20:24 +0200756 .platform_data = &cm_x300_da9030_info,
757};
758
759static struct i2c_pxa_platform_data cm_x300_pwr_i2c_info = {
760 .use_pio = 1,
761};
762
763static void __init cm_x300_init_da9030(void)
764{
765 pxa3xx_set_i2c_power_info(&cm_x300_pwr_i2c_info);
766 i2c_register_board_info(1, &cm_x300_pmic_info, 1);
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100767 irq_set_irq_wake(IRQ_WAKEUP0, 1);
Igor Grinberg9c017ca2009-10-14 09:20:24 +0200768}
769
Igor Grinberg5a009df2011-05-09 14:41:47 +0300770/* wi2wi gpio setting for system_rev >= 130 */
771static struct gpio cm_x300_wi2wi_gpios[] __initdata = {
772 { 71, GPIOF_OUT_INIT_HIGH, "wlan en" },
773 { 70, GPIOF_OUT_INIT_HIGH, "bt reset" },
774};
775
Igor Grinbergb3d01da2009-10-14 09:20:21 +0200776static void __init cm_x300_init_wi2wi(void)
777{
778 int bt_reset, wlan_en;
779 int err;
780
781 if (system_rev < 130) {
Igor Grinberg5a009df2011-05-09 14:41:47 +0300782 cm_x300_wi2wi_gpios[0].gpio = 77; /* wlan en */
783 cm_x300_wi2wi_gpios[1].gpio = 78; /* bt reset */
Igor Grinbergb3d01da2009-10-14 09:20:21 +0200784 }
785
786 /* Libertas and CSR reset */
Igor Grinberg5a009df2011-05-09 14:41:47 +0300787 err = gpio_request_array(ARRAY_AND_SIZE(cm_x300_wi2wi_gpios));
Igor Grinbergb3d01da2009-10-14 09:20:21 +0200788 if (err) {
Igor Grinberg32de50e2011-05-09 14:41:48 +0300789 pr_err("failed to request wifi/bt gpios: %d\n", err);
Igor Grinberg5a009df2011-05-09 14:41:47 +0300790 return;
Igor Grinbergb3d01da2009-10-14 09:20:21 +0200791 }
792
Igor Grinberg5a009df2011-05-09 14:41:47 +0300793 udelay(10);
794 gpio_set_value(bt_reset, 0);
795 udelay(10);
796 gpio_set_value(bt_reset, 1);
797
798 gpio_free(wlan_en);
799 gpio_free(bt_reset);
Igor Grinbergb3d01da2009-10-14 09:20:21 +0200800}
801
802/* MFP */
Igor Grinberg55052ea2009-10-14 09:20:18 +0200803static void __init cm_x300_init_mfp(void)
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100804{
805 /* board-processor specific GPIO initialization */
Igor Grinbergdef82522009-10-14 09:20:22 +0200806 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_mfp_cfg));
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100807
Igor Grinberg55052ea2009-10-14 09:20:18 +0200808 if (system_rev < 130)
Igor Grinbergdef82522009-10-14 09:20:22 +0200809 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_lt130_mfp_cfg));
Igor Grinberg55052ea2009-10-14 09:20:18 +0200810 else
Igor Grinbergdef82522009-10-14 09:20:22 +0200811 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_ge130_mfp_cfg));
812
813 if (cpu_is_pxa310())
814 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x310_mfp_cfg));
Igor Grinberg55052ea2009-10-14 09:20:18 +0200815}
816
817static void __init cm_x300_init(void)
818{
819 cm_x300_init_mfp();
820
Russell Kingcc155c62009-11-09 13:34:08 +0800821 pxa_set_btuart_info(NULL);
822 pxa_set_stuart_info(NULL);
Igor Grinberga6cd7eb2010-07-20 10:58:52 +0300823 if (cpu_is_pxa300())
824 pxa_set_ffuart_info(NULL);
Russell Kingcc155c62009-11-09 13:34:08 +0800825
Igor Grinberg9c017ca2009-10-14 09:20:24 +0200826 cm_x300_init_da9030();
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100827 cm_x300_init_dm9000();
828 cm_x300_init_lcd();
Igor Grinberg1b43d8e2010-07-27 15:07:00 +0300829 cm_x300_init_u2d();
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100830 cm_x300_init_ohci();
831 cm_x300_init_mmc();
832 cm_x300_init_nand();
833 cm_x300_init_leds();
834 cm_x300_init_i2c();
Igor Grinberg83e560e2009-10-14 09:20:19 +0200835 cm_x300_init_spi();
Mike Rapoport1858ced2009-06-04 10:44:52 +0300836 cm_x300_init_rtc();
Igor Grinberg74e74de2009-10-14 09:20:20 +0200837 cm_x300_init_ac97();
Igor Grinbergb3d01da2009-10-14 09:20:21 +0200838 cm_x300_init_wi2wi();
Igor Grinbergdb205462009-11-10 14:18:41 +0200839 cm_x300_init_bl();
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100840}
841
Mike Rapoportb5a5c472009-06-04 10:44:54 +0300842static void __init cm_x300_fixup(struct machine_desc *mdesc, struct tag *tags,
843 char **cmdline, struct meminfo *mi)
844{
Igor Grinberg81880972010-03-09 11:43:52 +0200845 /* Make sure that mi->bank[0].start = PHYS_ADDR */
846 for (; tags->hdr.size; tags = tag_next(tags))
847 if (tags->hdr.tag == ATAG_MEM &&
848 tags->u.mem.start == 0x80000000) {
849 tags->u.mem.start = 0xa0000000;
850 break;
851 }
Mike Rapoportb5a5c472009-06-04 10:44:54 +0300852}
853
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100854MACHINE_START(CM_X300, "CM-X300 module")
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100855 .boot_params = 0xa0000100,
Marek Vasut851982c2010-10-11 02:20:19 +0200856 .map_io = pxa3xx_map_io,
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100857 .init_irq = pxa3xx_init_irq,
Eric Miao8a97ae22011-05-18 21:30:04 +0800858 .handle_irq = pxa3xx_handle_irq,
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100859 .timer = &pxa_timer,
860 .init_machine = cm_x300_init,
Mike Rapoportb5a5c472009-06-04 10:44:54 +0300861 .fixup = cm_x300_fixup,
Mike Rapoportcf75d8d2008-08-26 14:03:44 +0100862MACHINE_END