cm-x300.c 10 KB

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