cm-x300.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /*
  2. * linux/arch/arm/mach-pxa/cm-x300.c
  3. *
  4. * Support for the CompuLab CM-X300 modules
  5. *
  6. * Copyright (C) 2008 CompuLab Ltd.
  7. *
  8. * Mike Rapoport <mike@compulab.co.il>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/init.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/gpio.h>
  20. #include <linux/dm9000.h>
  21. #include <linux/leds.h>
  22. #include <linux/rtc-v3020.h>
  23. #include <linux/i2c.h>
  24. #include <linux/i2c/pca953x.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/mach/arch.h>
  27. #include <mach/pxa300.h>
  28. #include <mach/pxafb.h>
  29. #include <mach/mmc.h>
  30. #include <mach/ohci.h>
  31. #include <plat/i2c.h>
  32. #include <mach/pxa3xx_nand.h>
  33. #include <asm/mach/map.h>
  34. #include "generic.h"
  35. #define CM_X300_ETH_PHYS 0x08000010
  36. #define GPIO82_MMC2_IRQ (82)
  37. #define GPIO85_MMC2_WP (85)
  38. #define CM_X300_MMC2_IRQ IRQ_GPIO(GPIO82_MMC2_IRQ)
  39. #define GPIO95_RTC_CS (95)
  40. #define GPIO96_RTC_WR (96)
  41. #define GPIO97_RTC_RD (97)
  42. #define GPIO98_RTC_IO (98)
  43. static mfp_cfg_t cm_x300_mfp_cfg[] __initdata = {
  44. /* LCD */
  45. GPIO54_LCD_LDD_0,
  46. GPIO55_LCD_LDD_1,
  47. GPIO56_LCD_LDD_2,
  48. GPIO57_LCD_LDD_3,
  49. GPIO58_LCD_LDD_4,
  50. GPIO59_LCD_LDD_5,
  51. GPIO60_LCD_LDD_6,
  52. GPIO61_LCD_LDD_7,
  53. GPIO62_LCD_LDD_8,
  54. GPIO63_LCD_LDD_9,
  55. GPIO64_LCD_LDD_10,
  56. GPIO65_LCD_LDD_11,
  57. GPIO66_LCD_LDD_12,
  58. GPIO67_LCD_LDD_13,
  59. GPIO68_LCD_LDD_14,
  60. GPIO69_LCD_LDD_15,
  61. GPIO72_LCD_FCLK,
  62. GPIO73_LCD_LCLK,
  63. GPIO74_LCD_PCLK,
  64. GPIO75_LCD_BIAS,
  65. /* BTUART */
  66. GPIO111_UART2_RTS,
  67. GPIO112_UART2_RXD | MFP_LPM_EDGE_FALL,
  68. GPIO113_UART2_TXD,
  69. GPIO114_UART2_CTS | MFP_LPM_EDGE_BOTH,
  70. /* STUART */
  71. GPIO109_UART3_TXD,
  72. GPIO110_UART3_RXD | MFP_LPM_EDGE_FALL,
  73. /* AC97 */
  74. GPIO23_AC97_nACRESET,
  75. GPIO24_AC97_SYSCLK,
  76. GPIO29_AC97_BITCLK,
  77. GPIO25_AC97_SDATA_IN_0,
  78. GPIO27_AC97_SDATA_OUT,
  79. GPIO28_AC97_SYNC,
  80. /* Keypad */
  81. GPIO115_KP_MKIN_0 | MFP_LPM_EDGE_BOTH,
  82. GPIO116_KP_MKIN_1 | MFP_LPM_EDGE_BOTH,
  83. GPIO117_KP_MKIN_2 | MFP_LPM_EDGE_BOTH,
  84. GPIO118_KP_MKIN_3 | MFP_LPM_EDGE_BOTH,
  85. GPIO119_KP_MKIN_4 | MFP_LPM_EDGE_BOTH,
  86. GPIO120_KP_MKIN_5 | MFP_LPM_EDGE_BOTH,
  87. GPIO2_2_KP_MKIN_6 | MFP_LPM_EDGE_BOTH,
  88. GPIO3_2_KP_MKIN_7 | MFP_LPM_EDGE_BOTH,
  89. GPIO121_KP_MKOUT_0,
  90. GPIO122_KP_MKOUT_1,
  91. GPIO123_KP_MKOUT_2,
  92. GPIO124_KP_MKOUT_3,
  93. GPIO125_KP_MKOUT_4,
  94. GPIO4_2_KP_MKOUT_5,
  95. /* MMC1 */
  96. GPIO3_MMC1_DAT0,
  97. GPIO4_MMC1_DAT1 | MFP_LPM_EDGE_BOTH,
  98. GPIO5_MMC1_DAT2,
  99. GPIO6_MMC1_DAT3,
  100. GPIO7_MMC1_CLK,
  101. GPIO8_MMC1_CMD, /* CMD0 for slot 0 */
  102. /* MMC2 */
  103. GPIO9_MMC2_DAT0,
  104. GPIO10_MMC2_DAT1 | MFP_LPM_EDGE_BOTH,
  105. GPIO11_MMC2_DAT2,
  106. GPIO12_MMC2_DAT3,
  107. GPIO13_MMC2_CLK,
  108. GPIO14_MMC2_CMD,
  109. /* FFUART */
  110. GPIO30_UART1_RXD | MFP_LPM_EDGE_FALL,
  111. GPIO31_UART1_TXD,
  112. GPIO32_UART1_CTS,
  113. GPIO37_UART1_RTS,
  114. GPIO33_UART1_DCD,
  115. GPIO34_UART1_DSR | MFP_LPM_EDGE_FALL,
  116. GPIO35_UART1_RI,
  117. GPIO36_UART1_DTR,
  118. /* GPIOs */
  119. GPIO79_GPIO, /* LED */
  120. GPIO82_GPIO | MFP_PULL_HIGH, /* MMC CD */
  121. GPIO85_GPIO, /* MMC WP */
  122. GPIO99_GPIO, /* Ethernet IRQ */
  123. /* RTC GPIOs */
  124. GPIO95_GPIO, /* RTC CS */
  125. GPIO96_GPIO, /* RTC WR */
  126. GPIO97_GPIO, /* RTC RD */
  127. GPIO98_GPIO, /* RTC IO */
  128. /* Standard I2C */
  129. GPIO21_I2C_SCL,
  130. GPIO22_I2C_SDA,
  131. };
  132. #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
  133. static struct resource dm9000_resources[] = {
  134. [0] = {
  135. .start = CM_X300_ETH_PHYS,
  136. .end = CM_X300_ETH_PHYS + 0x3,
  137. .flags = IORESOURCE_MEM,
  138. },
  139. [1] = {
  140. .start = CM_X300_ETH_PHYS + 0x4,
  141. .end = CM_X300_ETH_PHYS + 0x4 + 500,
  142. .flags = IORESOURCE_MEM,
  143. },
  144. [2] = {
  145. .start = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO99)),
  146. .end = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO99)),
  147. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  148. }
  149. };
  150. static struct dm9000_plat_data cm_x300_dm9000_platdata = {
  151. .flags = DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM,
  152. };
  153. static struct platform_device dm9000_device = {
  154. .name = "dm9000",
  155. .id = 0,
  156. .num_resources = ARRAY_SIZE(dm9000_resources),
  157. .resource = dm9000_resources,
  158. .dev = {
  159. .platform_data = &cm_x300_dm9000_platdata,
  160. }
  161. };
  162. static void __init cm_x300_init_dm9000(void)
  163. {
  164. platform_device_register(&dm9000_device);
  165. }
  166. #else
  167. static inline void cm_x300_init_dm9000(void) {}
  168. #endif
  169. #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
  170. static struct pxafb_mode_info cm_x300_lcd_modes[] = {
  171. [0] = {
  172. .pixclock = 38000,
  173. .bpp = 16,
  174. .xres = 480,
  175. .yres = 640,
  176. .hsync_len = 8,
  177. .vsync_len = 2,
  178. .left_margin = 8,
  179. .upper_margin = 0,
  180. .right_margin = 24,
  181. .lower_margin = 4,
  182. .cmap_greyscale = 0,
  183. },
  184. [1] = {
  185. .pixclock = 153800,
  186. .bpp = 16,
  187. .xres = 240,
  188. .yres = 320,
  189. .hsync_len = 8,
  190. .vsync_len = 2,
  191. .left_margin = 8,
  192. .upper_margin = 2,
  193. .right_margin = 88,
  194. .lower_margin = 2,
  195. .cmap_greyscale = 0,
  196. },
  197. };
  198. static struct pxafb_mach_info cm_x300_lcd = {
  199. .modes = cm_x300_lcd_modes,
  200. .num_modes = 2,
  201. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  202. };
  203. static void __init cm_x300_init_lcd(void)
  204. {
  205. set_pxa_fb_info(&cm_x300_lcd);
  206. }
  207. #else
  208. static inline void cm_x300_init_lcd(void) {}
  209. #endif
  210. #if defined(CONFIG_MTD_NAND_PXA3xx) || defined(CONFIG_MTD_NAND_PXA3xx_MODULE)
  211. static struct mtd_partition cm_x300_nand_partitions[] = {
  212. [0] = {
  213. .name = "OBM",
  214. .offset = 0,
  215. .size = SZ_256K,
  216. .mask_flags = MTD_WRITEABLE, /* force read-only */
  217. },
  218. [1] = {
  219. .name = "U-Boot",
  220. .offset = MTDPART_OFS_APPEND,
  221. .size = SZ_256K,
  222. .mask_flags = MTD_WRITEABLE, /* force read-only */
  223. },
  224. [2] = {
  225. .name = "Environment",
  226. .offset = MTDPART_OFS_APPEND,
  227. .size = SZ_256K,
  228. },
  229. [3] = {
  230. .name = "reserved",
  231. .offset = MTDPART_OFS_APPEND,
  232. .size = SZ_256K + SZ_1M,
  233. .mask_flags = MTD_WRITEABLE, /* force read-only */
  234. },
  235. [4] = {
  236. .name = "kernel",
  237. .offset = MTDPART_OFS_APPEND,
  238. .size = SZ_4M,
  239. },
  240. [5] = {
  241. .name = "fs",
  242. .offset = MTDPART_OFS_APPEND,
  243. .size = MTDPART_SIZ_FULL,
  244. },
  245. };
  246. static struct pxa3xx_nand_platform_data cm_x300_nand_info = {
  247. .enable_arbiter = 1,
  248. .keep_config = 1,
  249. .parts = cm_x300_nand_partitions,
  250. .nr_parts = ARRAY_SIZE(cm_x300_nand_partitions),
  251. };
  252. static void __init cm_x300_init_nand(void)
  253. {
  254. pxa3xx_set_nand_info(&cm_x300_nand_info);
  255. }
  256. #else
  257. static inline void cm_x300_init_nand(void) {}
  258. #endif
  259. #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
  260. /* The first MMC slot of CM-X300 is hardwired to Libertas card and has
  261. no detection/ro pins */
  262. static int cm_x300_mci_init(struct device *dev,
  263. irq_handler_t cm_x300_detect_int,
  264. void *data)
  265. {
  266. return 0;
  267. }
  268. static void cm_x300_mci_exit(struct device *dev, void *data)
  269. {
  270. }
  271. static struct pxamci_platform_data cm_x300_mci_platform_data = {
  272. .detect_delay = 20,
  273. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  274. .init = cm_x300_mci_init,
  275. .exit = cm_x300_mci_exit,
  276. };
  277. static int cm_x300_mci2_ro(struct device *dev)
  278. {
  279. return gpio_get_value(GPIO85_MMC2_WP);
  280. }
  281. static int cm_x300_mci2_init(struct device *dev,
  282. irq_handler_t cm_x300_detect_int,
  283. void *data)
  284. {
  285. int err;
  286. /*
  287. * setup GPIO for CM-X300 MMC controller
  288. */
  289. err = gpio_request(GPIO82_MMC2_IRQ, "mmc card detect");
  290. if (err)
  291. goto err_request_cd;
  292. gpio_direction_input(GPIO82_MMC2_IRQ);
  293. err = gpio_request(GPIO85_MMC2_WP, "mmc write protect");
  294. if (err)
  295. goto err_request_wp;
  296. gpio_direction_input(GPIO85_MMC2_WP);
  297. err = request_irq(CM_X300_MMC2_IRQ, cm_x300_detect_int,
  298. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  299. "MMC card detect", data);
  300. if (err) {
  301. printk(KERN_ERR "%s: MMC/SD/SDIO: "
  302. "can't request card detect IRQ\n", __func__);
  303. goto err_request_irq;
  304. }
  305. return 0;
  306. err_request_irq:
  307. gpio_free(GPIO85_MMC2_WP);
  308. err_request_wp:
  309. gpio_free(GPIO82_MMC2_IRQ);
  310. err_request_cd:
  311. return err;
  312. }
  313. static void cm_x300_mci2_exit(struct device *dev, void *data)
  314. {
  315. free_irq(CM_X300_MMC2_IRQ, data);
  316. gpio_free(GPIO82_MMC2_IRQ);
  317. gpio_free(GPIO85_MMC2_WP);
  318. }
  319. static struct pxamci_platform_data cm_x300_mci2_platform_data = {
  320. .detect_delay = 20,
  321. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  322. .init = cm_x300_mci2_init,
  323. .exit = cm_x300_mci2_exit,
  324. .get_ro = cm_x300_mci2_ro,
  325. };
  326. static void __init cm_x300_init_mmc(void)
  327. {
  328. pxa_set_mci_info(&cm_x300_mci_platform_data);
  329. pxa3xx_set_mci2_info(&cm_x300_mci2_platform_data);
  330. }
  331. #else
  332. static inline void cm_x300_init_mmc(void) {}
  333. #endif
  334. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  335. static struct pxaohci_platform_data cm_x300_ohci_platform_data = {
  336. .port_mode = PMM_PERPORT_MODE,
  337. .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
  338. };
  339. static void __init cm_x300_init_ohci(void)
  340. {
  341. pxa_set_ohci_info(&cm_x300_ohci_platform_data);
  342. }
  343. #else
  344. static inline void cm_x300_init_ohci(void) {}
  345. #endif
  346. #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  347. static struct gpio_led cm_x300_leds[] = {
  348. [0] = {
  349. .name = "cm-x300:green",
  350. .default_trigger = "heartbeat",
  351. .gpio = 79,
  352. .active_low = 1,
  353. },
  354. };
  355. static struct gpio_led_platform_data cm_x300_gpio_led_pdata = {
  356. .num_leds = ARRAY_SIZE(cm_x300_leds),
  357. .leds = cm_x300_leds,
  358. };
  359. static struct platform_device cm_x300_led_device = {
  360. .name = "leds-gpio",
  361. .id = -1,
  362. .dev = {
  363. .platform_data = &cm_x300_gpio_led_pdata,
  364. },
  365. };
  366. static void __init cm_x300_init_leds(void)
  367. {
  368. platform_device_register(&cm_x300_led_device);
  369. }
  370. #else
  371. static inline void cm_x300_init_leds(void) {}
  372. #endif
  373. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  374. /* PCA9555 */
  375. static struct pca953x_platform_data cm_x300_gpio_ext_pdata_0 = {
  376. .gpio_base = 128,
  377. };
  378. static struct pca953x_platform_data cm_x300_gpio_ext_pdata_1 = {
  379. .gpio_base = 144,
  380. };
  381. static struct i2c_board_info cm_x300_gpio_ext_info[] = {
  382. [0] = {
  383. I2C_BOARD_INFO("pca9555", 0x24),
  384. .platform_data = &cm_x300_gpio_ext_pdata_0,
  385. },
  386. [1] = {
  387. I2C_BOARD_INFO("pca9555", 0x25),
  388. .platform_data = &cm_x300_gpio_ext_pdata_1,
  389. },
  390. };
  391. static void __init cm_x300_init_i2c(void)
  392. {
  393. pxa_set_i2c_info(NULL);
  394. i2c_register_board_info(0, cm_x300_gpio_ext_info,
  395. ARRAY_SIZE(cm_x300_gpio_ext_info));
  396. }
  397. #else
  398. static inline void cm_x300_init_i2c(void) {}
  399. #endif
  400. #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
  401. struct v3020_platform_data cm_x300_v3020_pdata = {
  402. .use_gpio = 1,
  403. .gpio_cs = GPIO95_RTC_CS,
  404. .gpio_wr = GPIO96_RTC_WR,
  405. .gpio_rd = GPIO97_RTC_RD,
  406. .gpio_io = GPIO98_RTC_IO,
  407. };
  408. static struct platform_device cm_x300_rtc_device = {
  409. .name = "v3020",
  410. .id = -1,
  411. .dev = {
  412. .platform_data = &cm_x300_v3020_pdata,
  413. }
  414. };
  415. static void __init cm_x300_init_rtc(void)
  416. {
  417. platform_device_register(&cm_x300_rtc_device);
  418. }
  419. #else
  420. static inline void cm_x300_init_rtc(void) {}
  421. #endif
  422. static void __init cm_x300_init(void)
  423. {
  424. /* board-processor specific GPIO initialization */
  425. pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x300_mfp_cfg));
  426. cm_x300_init_dm9000();
  427. cm_x300_init_lcd();
  428. cm_x300_init_ohci();
  429. cm_x300_init_mmc();
  430. cm_x300_init_nand();
  431. cm_x300_init_leds();
  432. cm_x300_init_i2c();
  433. cm_x300_init_rtc();
  434. }
  435. MACHINE_START(CM_X300, "CM-X300 module")
  436. .phys_io = 0x40000000,
  437. .boot_params = 0xa0000100,
  438. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  439. .map_io = pxa_map_io,
  440. .init_irq = pxa3xx_init_irq,
  441. .timer = &pxa_timer,
  442. .init_machine = cm_x300_init,
  443. MACHINE_END