cm-x270.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. GPIO58_LCD_LDD_0,
  60. GPIO59_LCD_LDD_1,
  61. GPIO60_LCD_LDD_2,
  62. GPIO61_LCD_LDD_3,
  63. GPIO62_LCD_LDD_4,
  64. GPIO63_LCD_LDD_5,
  65. GPIO64_LCD_LDD_6,
  66. GPIO65_LCD_LDD_7,
  67. GPIO66_LCD_LDD_8,
  68. GPIO67_LCD_LDD_9,
  69. GPIO68_LCD_LDD_10,
  70. GPIO69_LCD_LDD_11,
  71. GPIO70_LCD_LDD_12,
  72. GPIO71_LCD_LDD_13,
  73. GPIO72_LCD_LDD_14,
  74. GPIO73_LCD_LDD_15,
  75. GPIO74_LCD_FCLK,
  76. GPIO75_LCD_LCLK,
  77. GPIO76_LCD_PCLK,
  78. GPIO77_LCD_BIAS,
  79. /* I2C */
  80. GPIO117_I2C_SCL,
  81. GPIO118_I2C_SDA,
  82. /* SSP1 */
  83. GPIO23_SSP1_SCLK,
  84. GPIO24_SSP1_SFRM,
  85. GPIO25_SSP1_TXD,
  86. GPIO26_SSP1_RXD,
  87. /* SSP2 */
  88. GPIO19_GPIO, /* SSP2 clock is used as GPIO for Libertas pin-strap */
  89. GPIO14_GPIO,
  90. GPIO87_SSP2_TXD,
  91. GPIO88_SSP2_RXD,
  92. /* PC Card */
  93. GPIO48_nPOE,
  94. GPIO49_nPWE,
  95. GPIO50_nPIOR,
  96. GPIO51_nPIOW,
  97. GPIO85_nPCE_1,
  98. GPIO54_nPCE_2,
  99. GPIO55_nPREG,
  100. GPIO56_nPWAIT,
  101. GPIO57_nIOIS16,
  102. /* SDRAM and local bus */
  103. GPIO15_nCS_1,
  104. GPIO78_nCS_2,
  105. GPIO79_nCS_3,
  106. GPIO80_nCS_4,
  107. GPIO33_nCS_5,
  108. GPIO49_nPWE,
  109. GPIO18_RDY,
  110. /* GPIO */
  111. GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH,
  112. GPIO105_GPIO | MFP_LPM_DRIVE_HIGH, /* MMC/SD power */
  113. GPIO53_GPIO, /* PC card reset */
  114. GPIO102_GPIO, /* WLAN reset */
  115. /* NAND controls */
  116. GPIO11_GPIO | MFP_LPM_DRIVE_HIGH, /* NAND CE# */
  117. GPIO89_GPIO, /* NAND Ready/Busy */
  118. /* interrupts */
  119. GPIO10_GPIO, /* DM9000 interrupt */
  120. GPIO83_GPIO, /* MMC card detect */
  121. GPIO95_GPIO, /* WLAN interrupt */
  122. };
  123. /* V3020 RTC */
  124. #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
  125. static struct resource cmx270_v3020_resource[] = {
  126. [0] = {
  127. .start = RTC_PHYS_BASE,
  128. .end = RTC_PHYS_BASE + 4,
  129. .flags = IORESOURCE_MEM,
  130. },
  131. };
  132. struct v3020_platform_data cmx270_v3020_pdata = {
  133. .leftshift = 16,
  134. };
  135. static struct platform_device cmx270_rtc_device = {
  136. .name = "v3020",
  137. .num_resources = ARRAY_SIZE(cmx270_v3020_resource),
  138. .resource = cmx270_v3020_resource,
  139. .id = -1,
  140. .dev = {
  141. .platform_data = &cmx270_v3020_pdata,
  142. }
  143. };
  144. static void __init cmx270_init_rtc(void)
  145. {
  146. platform_device_register(&cmx270_rtc_device);
  147. }
  148. #else
  149. static inline void cmx270_init_rtc(void) {}
  150. #endif
  151. /* 2700G graphics */
  152. #if defined(CONFIG_FB_MBX) || defined(CONFIG_FB_MBX_MODULE)
  153. static u64 fb_dma_mask = ~(u64)0;
  154. static struct resource cmx270_2700G_resource[] = {
  155. /* frame buffer memory including ODFB and External SDRAM */
  156. [0] = {
  157. .start = PXA_CS2_PHYS,
  158. .end = PXA_CS2_PHYS + 0x01ffffff,
  159. .flags = IORESOURCE_MEM,
  160. },
  161. /* Marathon registers */
  162. [1] = {
  163. .start = PXA_CS2_PHYS + 0x03fe0000,
  164. .end = PXA_CS2_PHYS + 0x03ffffff,
  165. .flags = IORESOURCE_MEM,
  166. },
  167. };
  168. static unsigned long save_lcd_regs[10];
  169. static int cmx270_marathon_probe(struct fb_info *fb)
  170. {
  171. /* save PXA-270 pin settings before enabling 2700G */
  172. save_lcd_regs[0] = GPDR1;
  173. save_lcd_regs[1] = GPDR2;
  174. save_lcd_regs[2] = GAFR1_U;
  175. save_lcd_regs[3] = GAFR2_L;
  176. save_lcd_regs[4] = GAFR2_U;
  177. /* Disable PXA-270 on-chip controller driving pins */
  178. GPDR1 &= ~(0xfc000000);
  179. GPDR2 &= ~(0x00c03fff);
  180. GAFR1_U &= ~(0xfff00000);
  181. GAFR2_L &= ~(0x0fffffff);
  182. GAFR2_U &= ~(0x0000f000);
  183. return 0;
  184. }
  185. static int cmx270_marathon_remove(struct fb_info *fb)
  186. {
  187. GPDR1 = save_lcd_regs[0];
  188. GPDR2 = save_lcd_regs[1];
  189. GAFR1_U = save_lcd_regs[2];
  190. GAFR2_L = save_lcd_regs[3];
  191. GAFR2_U = save_lcd_regs[4];
  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. }