cm-x300.c 10 KB

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