cm-x270.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. * linux/arch/arm/mach-pxa/cm-x270.c
  3. *
  4. * Copyright (C) 2007, 2008 CompuLab, Ltd.
  5. * Mike Rapoport <mike@compulab.co.il>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/platform_device.h>
  12. #include <linux/sysdev.h>
  13. #include <linux/irq.h>
  14. #include <linux/gpio.h>
  15. #include <linux/delay.h>
  16. #include <linux/rtc-v3020.h>
  17. #include <video/mbxfb.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/spi/libertas_spi.h>
  20. #include <mach/pxa27x.h>
  21. #include <mach/ohci.h>
  22. #include <mach/mmc.h>
  23. #include <mach/pxa2xx_spi.h>
  24. #include "generic.h"
  25. /* physical address if local-bus attached devices */
  26. #define RTC_PHYS_BASE (PXA_CS1_PHYS + (5 << 22))
  27. /* GPIO IRQ usage */
  28. #define GPIO83_MMC_IRQ (83)
  29. #define CMX270_MMC_IRQ IRQ_GPIO(GPIO83_MMC_IRQ)
  30. /* MMC power enable */
  31. #define GPIO105_MMC_POWER (105)
  32. /* WLAN GPIOS */
  33. #define GPIO19_WLAN_STRAP (19)
  34. #define GPIO102_WLAN_RST (102)
  35. static unsigned long cmx270_pin_config[] = {
  36. /* AC'97 */
  37. GPIO28_AC97_BITCLK,
  38. GPIO29_AC97_SDATA_IN_0,
  39. GPIO30_AC97_SDATA_OUT,
  40. GPIO31_AC97_SYNC,
  41. GPIO98_AC97_SYSCLK,
  42. GPIO113_AC97_nRESET,
  43. /* BTUART */
  44. GPIO42_BTUART_RXD,
  45. GPIO43_BTUART_TXD,
  46. GPIO44_BTUART_CTS,
  47. GPIO45_BTUART_RTS,
  48. /* STUART */
  49. GPIO46_STUART_RXD,
  50. GPIO47_STUART_TXD,
  51. /* MCI controller */
  52. GPIO32_MMC_CLK,
  53. GPIO112_MMC_CMD,
  54. GPIO92_MMC_DAT_0,
  55. GPIO109_MMC_DAT_1,
  56. GPIO110_MMC_DAT_2,
  57. GPIO111_MMC_DAT_3,
  58. /* LCD */
  59. GPIOxx_LCD_TFT_16BPP,
  60. /* I2C */
  61. GPIO117_I2C_SCL,
  62. GPIO118_I2C_SDA,
  63. /* SSP1 */
  64. GPIO23_SSP1_SCLK,
  65. GPIO24_SSP1_SFRM,
  66. GPIO25_SSP1_TXD,
  67. GPIO26_SSP1_RXD,
  68. /* SSP2 */
  69. GPIO19_GPIO, /* SSP2 clock is used as GPIO for Libertas pin-strap */
  70. GPIO14_GPIO,
  71. GPIO87_SSP2_TXD,
  72. GPIO88_SSP2_RXD,
  73. /* PC Card */
  74. GPIO48_nPOE,
  75. GPIO49_nPWE,
  76. GPIO50_nPIOR,
  77. GPIO51_nPIOW,
  78. GPIO85_nPCE_1,
  79. GPIO54_nPCE_2,
  80. GPIO55_nPREG,
  81. GPIO56_nPWAIT,
  82. GPIO57_nIOIS16,
  83. /* SDRAM and local bus */
  84. GPIO15_nCS_1,
  85. GPIO78_nCS_2,
  86. GPIO79_nCS_3,
  87. GPIO80_nCS_4,
  88. GPIO33_nCS_5,
  89. GPIO49_nPWE,
  90. GPIO18_RDY,
  91. /* GPIO */
  92. GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH,
  93. GPIO105_GPIO | MFP_LPM_DRIVE_HIGH, /* MMC/SD power */
  94. GPIO53_GPIO, /* PC card reset */
  95. GPIO102_GPIO, /* WLAN reset */
  96. /* NAND controls */
  97. GPIO11_GPIO | MFP_LPM_DRIVE_HIGH, /* NAND CE# */
  98. GPIO89_GPIO, /* NAND Ready/Busy */
  99. /* interrupts */
  100. GPIO10_GPIO, /* DM9000 interrupt */
  101. GPIO83_GPIO, /* MMC card detect */
  102. GPIO95_GPIO, /* WLAN interrupt */
  103. };
  104. /* V3020 RTC */
  105. #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
  106. static struct resource cmx270_v3020_resource[] = {
  107. [0] = {
  108. .start = RTC_PHYS_BASE,
  109. .end = RTC_PHYS_BASE + 4,
  110. .flags = IORESOURCE_MEM,
  111. },
  112. };
  113. struct v3020_platform_data cmx270_v3020_pdata = {
  114. .leftshift = 16,
  115. };
  116. static struct platform_device cmx270_rtc_device = {
  117. .name = "v3020",
  118. .num_resources = ARRAY_SIZE(cmx270_v3020_resource),
  119. .resource = cmx270_v3020_resource,
  120. .id = -1,
  121. .dev = {
  122. .platform_data = &cmx270_v3020_pdata,
  123. }
  124. };
  125. static void __init cmx270_init_rtc(void)
  126. {
  127. platform_device_register(&cmx270_rtc_device);
  128. }
  129. #else
  130. static inline void cmx270_init_rtc(void) {}
  131. #endif
  132. /* 2700G graphics */
  133. #if defined(CONFIG_FB_MBX) || defined(CONFIG_FB_MBX_MODULE)
  134. static u64 fb_dma_mask = ~(u64)0;
  135. static struct resource cmx270_2700G_resource[] = {
  136. /* frame buffer memory including ODFB and External SDRAM */
  137. [0] = {
  138. .start = PXA_CS2_PHYS,
  139. .end = PXA_CS2_PHYS + 0x01ffffff,
  140. .flags = IORESOURCE_MEM,
  141. },
  142. /* Marathon registers */
  143. [1] = {
  144. .start = PXA_CS2_PHYS + 0x03fe0000,
  145. .end = PXA_CS2_PHYS + 0x03ffffff,
  146. .flags = IORESOURCE_MEM,
  147. },
  148. };
  149. static unsigned long cmx270_marathon_on[] = {
  150. GPIO58_GPIO,
  151. GPIO59_GPIO,
  152. GPIO60_GPIO,
  153. GPIO61_GPIO,
  154. GPIO62_GPIO,
  155. GPIO63_GPIO,
  156. GPIO64_GPIO,
  157. GPIO65_GPIO,
  158. GPIO66_GPIO,
  159. GPIO67_GPIO,
  160. GPIO68_GPIO,
  161. GPIO69_GPIO,
  162. GPIO70_GPIO,
  163. GPIO71_GPIO,
  164. GPIO72_GPIO,
  165. GPIO73_GPIO,
  166. GPIO74_GPIO,
  167. GPIO75_GPIO,
  168. GPIO76_GPIO,
  169. GPIO77_GPIO,
  170. };
  171. static unsigned long cmx270_marathon_off[] = {
  172. GPIOxx_LCD_TFT_16BPP,
  173. };
  174. static int cmx270_marathon_probe(struct fb_info *fb)
  175. {
  176. int gpio, err;
  177. for (gpio = 58; gpio <= 77; gpio++) {
  178. err = gpio_request(gpio, "LCD");
  179. if (err)
  180. return err;
  181. gpio_direction_input(gpio);
  182. }
  183. pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_marathon_on));
  184. return 0;
  185. }
  186. static int cmx270_marathon_remove(struct fb_info *fb)
  187. {
  188. int gpio;
  189. pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_marathon_off));
  190. for (gpio = 58; gpio <= 77; gpio++)
  191. gpio_free(gpio);
  192. return 0;
  193. }
  194. static struct mbxfb_platform_data cmx270_2700G_data = {
  195. .xres = {
  196. .min = 240,
  197. .max = 1200,
  198. .defval = 640,
  199. },
  200. .yres = {
  201. .min = 240,
  202. .max = 1200,
  203. .defval = 480,
  204. },
  205. .bpp = {
  206. .min = 16,
  207. .max = 32,
  208. .defval = 16,
  209. },
  210. .memsize = 8*1024*1024,
  211. .probe = cmx270_marathon_probe,
  212. .remove = cmx270_marathon_remove,
  213. };
  214. static struct platform_device cmx270_2700G = {
  215. .name = "mbx-fb",
  216. .dev = {
  217. .platform_data = &cmx270_2700G_data,
  218. .dma_mask = &fb_dma_mask,
  219. .coherent_dma_mask = 0xffffffff,
  220. },
  221. .num_resources = ARRAY_SIZE(cmx270_2700G_resource),
  222. .resource = cmx270_2700G_resource,
  223. .id = -1,
  224. };
  225. static void __init cmx270_init_2700G(void)
  226. {
  227. platform_device_register(&cmx270_2700G);
  228. }
  229. #else
  230. static inline void cmx270_init_2700G(void) {}
  231. #endif
  232. /* PXA27x OHCI controller setup */
  233. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  234. static struct pxaohci_platform_data cmx270_ohci_platform_data = {
  235. .port_mode = PMM_PERPORT_MODE,
  236. .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
  237. };
  238. static void __init cmx270_init_ohci(void)
  239. {
  240. pxa_set_ohci_info(&cmx270_ohci_platform_data);
  241. }
  242. #else
  243. static inline void cmx270_init_ohci(void) {}
  244. #endif
  245. #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
  246. static struct pxamci_platform_data cmx270_mci_platform_data = {
  247. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  248. .gpio_card_detect = GPIO83_MMC_IRQ,
  249. .gpio_card_ro = -1,
  250. .gpio_power = GPIO105_MMC_POWER,
  251. .gpio_power_invert = 1,
  252. };
  253. static void __init cmx270_init_mmc(void)
  254. {
  255. pxa_set_mci_info(&cmx270_mci_platform_data);
  256. }
  257. #else
  258. static inline void cmx270_init_mmc(void) {}
  259. #endif
  260. #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
  261. static struct pxa2xx_spi_master cm_x270_spi_info = {
  262. .num_chipselect = 1,
  263. .enable_dma = 1,
  264. };
  265. static struct pxa2xx_spi_chip cm_x270_libertas_chip = {
  266. .rx_threshold = 1,
  267. .tx_threshold = 1,
  268. .timeout = 1000,
  269. .gpio_cs = 14,
  270. };
  271. static unsigned long cm_x270_libertas_pin_config[] = {
  272. /* SSP2 */
  273. GPIO19_SSP2_SCLK,
  274. GPIO14_GPIO,
  275. GPIO87_SSP2_TXD,
  276. GPIO88_SSP2_RXD,
  277. };
  278. static int cm_x270_libertas_setup(struct spi_device *spi)
  279. {
  280. int err = gpio_request(GPIO19_WLAN_STRAP, "WLAN STRAP");
  281. if (err)
  282. return err;
  283. err = gpio_request(GPIO102_WLAN_RST, "WLAN RST");
  284. if (err)
  285. goto err_free_strap;
  286. err = gpio_direction_output(GPIO102_WLAN_RST, 0);
  287. if (err)
  288. goto err_free_strap;
  289. msleep(100);
  290. err = gpio_direction_output(GPIO19_WLAN_STRAP, 1);
  291. if (err)
  292. goto err_free_strap;
  293. msleep(100);
  294. pxa2xx_mfp_config(ARRAY_AND_SIZE(cm_x270_libertas_pin_config));
  295. gpio_set_value(GPIO102_WLAN_RST, 1);
  296. msleep(100);
  297. spi->bits_per_word = 16;
  298. spi_setup(spi);
  299. return 0;
  300. err_free_strap:
  301. gpio_free(GPIO19_WLAN_STRAP);
  302. return err;
  303. }
  304. static int cm_x270_libertas_teardown(struct spi_device *spi)
  305. {
  306. gpio_set_value(GPIO102_WLAN_RST, 0);
  307. gpio_free(GPIO102_WLAN_RST);
  308. gpio_free(GPIO19_WLAN_STRAP);
  309. return 0;
  310. }
  311. struct libertas_spi_platform_data cm_x270_libertas_pdata = {
  312. .use_dummy_writes = 1,
  313. .setup = cm_x270_libertas_setup,
  314. .teardown = cm_x270_libertas_teardown,
  315. };
  316. static struct spi_board_info cm_x270_spi_devices[] __initdata = {
  317. {
  318. .modalias = "libertas_spi",
  319. .max_speed_hz = 13000000,
  320. .bus_num = 2,
  321. .irq = gpio_to_irq(95),
  322. .chip_select = 0,
  323. .controller_data = &cm_x270_libertas_chip,
  324. .platform_data = &cm_x270_libertas_pdata,
  325. },
  326. };
  327. static void __init cmx270_init_spi(void)
  328. {
  329. pxa2xx_set_spi_info(2, &cm_x270_spi_info);
  330. spi_register_board_info(ARRAY_AND_SIZE(cm_x270_spi_devices));
  331. }
  332. #else
  333. static inline void cmx270_init_spi(void) {}
  334. #endif
  335. void __init cmx270_init(void)
  336. {
  337. pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_pin_config));
  338. #ifdef CONFIG_PM
  339. pxa27x_set_pwrmode(PWRMODE_DEEPSLEEP);
  340. #endif
  341. cmx270_init_rtc();
  342. cmx270_init_mmc();
  343. cmx270_init_ohci();
  344. cmx270_init_2700G();
  345. cmx270_init_spi();
  346. }