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