cm-x270.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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/rtc-v3020.h>
  16. #include <video/mbxfb.h>
  17. #include <mach/pxa27x.h>
  18. #include <mach/ohci.h>
  19. #include <mach/mmc.h>
  20. #include "generic.h"
  21. /* physical address if local-bus attached devices */
  22. #define RTC_PHYS_BASE (PXA_CS1_PHYS + (5 << 22))
  23. /* GPIO IRQ usage */
  24. #define GPIO83_MMC_IRQ (83)
  25. #define CMX270_MMC_IRQ IRQ_GPIO(GPIO83_MMC_IRQ)
  26. /* MMC power enable */
  27. #define GPIO105_MMC_POWER (105)
  28. static unsigned long cmx270_pin_config[] = {
  29. /* AC'97 */
  30. GPIO28_AC97_BITCLK,
  31. GPIO29_AC97_SDATA_IN_0,
  32. GPIO30_AC97_SDATA_OUT,
  33. GPIO31_AC97_SYNC,
  34. GPIO98_AC97_SYSCLK,
  35. GPIO113_AC97_nRESET,
  36. /* BTUART */
  37. GPIO42_BTUART_RXD,
  38. GPIO43_BTUART_TXD,
  39. GPIO44_BTUART_CTS,
  40. GPIO45_BTUART_RTS,
  41. /* STUART */
  42. GPIO46_STUART_RXD,
  43. GPIO47_STUART_TXD,
  44. /* MCI controller */
  45. GPIO32_MMC_CLK,
  46. GPIO112_MMC_CMD,
  47. GPIO92_MMC_DAT_0,
  48. GPIO109_MMC_DAT_1,
  49. GPIO110_MMC_DAT_2,
  50. GPIO111_MMC_DAT_3,
  51. /* LCD */
  52. GPIO58_LCD_LDD_0,
  53. GPIO59_LCD_LDD_1,
  54. GPIO60_LCD_LDD_2,
  55. GPIO61_LCD_LDD_3,
  56. GPIO62_LCD_LDD_4,
  57. GPIO63_LCD_LDD_5,
  58. GPIO64_LCD_LDD_6,
  59. GPIO65_LCD_LDD_7,
  60. GPIO66_LCD_LDD_8,
  61. GPIO67_LCD_LDD_9,
  62. GPIO68_LCD_LDD_10,
  63. GPIO69_LCD_LDD_11,
  64. GPIO70_LCD_LDD_12,
  65. GPIO71_LCD_LDD_13,
  66. GPIO72_LCD_LDD_14,
  67. GPIO73_LCD_LDD_15,
  68. GPIO74_LCD_FCLK,
  69. GPIO75_LCD_LCLK,
  70. GPIO76_LCD_PCLK,
  71. GPIO77_LCD_BIAS,
  72. /* I2C */
  73. GPIO117_I2C_SCL,
  74. GPIO118_I2C_SDA,
  75. /* SSP1 */
  76. GPIO23_SSP1_SCLK,
  77. GPIO24_SSP1_SFRM,
  78. GPIO25_SSP1_TXD,
  79. GPIO26_SSP1_RXD,
  80. /* SSP2 */
  81. GPIO19_SSP2_SCLK,
  82. GPIO14_SSP2_SFRM,
  83. GPIO87_SSP2_TXD,
  84. GPIO88_SSP2_RXD,
  85. /* PC Card */
  86. GPIO48_nPOE,
  87. GPIO49_nPWE,
  88. GPIO50_nPIOR,
  89. GPIO51_nPIOW,
  90. GPIO85_nPCE_1,
  91. GPIO54_nPCE_2,
  92. GPIO55_nPREG,
  93. GPIO56_nPWAIT,
  94. GPIO57_nIOIS16,
  95. /* SDRAM and local bus */
  96. GPIO15_nCS_1,
  97. GPIO78_nCS_2,
  98. GPIO79_nCS_3,
  99. GPIO80_nCS_4,
  100. GPIO33_nCS_5,
  101. GPIO49_nPWE,
  102. GPIO18_RDY,
  103. /* GPIO */
  104. GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH,
  105. GPIO105_GPIO | MFP_LPM_DRIVE_HIGH, /* MMC/SD power */
  106. GPIO53_GPIO, /* PC card reset */
  107. /* NAND controls */
  108. GPIO11_GPIO | MFP_LPM_DRIVE_HIGH, /* NAND CE# */
  109. GPIO89_GPIO, /* NAND Ready/Busy */
  110. /* interrupts */
  111. GPIO10_GPIO, /* DM9000 interrupt */
  112. GPIO83_GPIO, /* MMC card detect */
  113. };
  114. /* V3020 RTC */
  115. #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
  116. static struct resource cmx270_v3020_resource[] = {
  117. [0] = {
  118. .start = RTC_PHYS_BASE,
  119. .end = RTC_PHYS_BASE + 4,
  120. .flags = IORESOURCE_MEM,
  121. },
  122. };
  123. struct v3020_platform_data cmx270_v3020_pdata = {
  124. .leftshift = 16,
  125. };
  126. static struct platform_device cmx270_rtc_device = {
  127. .name = "v3020",
  128. .num_resources = ARRAY_SIZE(cmx270_v3020_resource),
  129. .resource = cmx270_v3020_resource,
  130. .id = -1,
  131. .dev = {
  132. .platform_data = &cmx270_v3020_pdata,
  133. }
  134. };
  135. static void __init cmx270_init_rtc(void)
  136. {
  137. platform_device_register(&cmx270_rtc_device);
  138. }
  139. #else
  140. static inline void cmx270_init_rtc(void) {}
  141. #endif
  142. /* 2700G graphics */
  143. #if defined(CONFIG_FB_MBX) || defined(CONFIG_FB_MBX_MODULE)
  144. static u64 fb_dma_mask = ~(u64)0;
  145. static struct resource cmx270_2700G_resource[] = {
  146. /* frame buffer memory including ODFB and External SDRAM */
  147. [0] = {
  148. .start = PXA_CS2_PHYS,
  149. .end = PXA_CS2_PHYS + 0x01ffffff,
  150. .flags = IORESOURCE_MEM,
  151. },
  152. /* Marathon registers */
  153. [1] = {
  154. .start = PXA_CS2_PHYS + 0x03fe0000,
  155. .end = PXA_CS2_PHYS + 0x03ffffff,
  156. .flags = IORESOURCE_MEM,
  157. },
  158. };
  159. static unsigned long save_lcd_regs[10];
  160. static int cmx270_marathon_probe(struct fb_info *fb)
  161. {
  162. /* save PXA-270 pin settings before enabling 2700G */
  163. save_lcd_regs[0] = GPDR1;
  164. save_lcd_regs[1] = GPDR2;
  165. save_lcd_regs[2] = GAFR1_U;
  166. save_lcd_regs[3] = GAFR2_L;
  167. save_lcd_regs[4] = GAFR2_U;
  168. /* Disable PXA-270 on-chip controller driving pins */
  169. GPDR1 &= ~(0xfc000000);
  170. GPDR2 &= ~(0x00c03fff);
  171. GAFR1_U &= ~(0xfff00000);
  172. GAFR2_L &= ~(0x0fffffff);
  173. GAFR2_U &= ~(0x0000f000);
  174. return 0;
  175. }
  176. static int cmx270_marathon_remove(struct fb_info *fb)
  177. {
  178. GPDR1 = save_lcd_regs[0];
  179. GPDR2 = save_lcd_regs[1];
  180. GAFR1_U = save_lcd_regs[2];
  181. GAFR2_L = save_lcd_regs[3];
  182. GAFR2_U = save_lcd_regs[4];
  183. return 0;
  184. }
  185. static struct mbxfb_platform_data cmx270_2700G_data = {
  186. .xres = {
  187. .min = 240,
  188. .max = 1200,
  189. .defval = 640,
  190. },
  191. .yres = {
  192. .min = 240,
  193. .max = 1200,
  194. .defval = 480,
  195. },
  196. .bpp = {
  197. .min = 16,
  198. .max = 32,
  199. .defval = 16,
  200. },
  201. .memsize = 8*1024*1024,
  202. .probe = cmx270_marathon_probe,
  203. .remove = cmx270_marathon_remove,
  204. };
  205. static struct platform_device cmx270_2700G = {
  206. .name = "mbx-fb",
  207. .dev = {
  208. .platform_data = &cmx270_2700G_data,
  209. .dma_mask = &fb_dma_mask,
  210. .coherent_dma_mask = 0xffffffff,
  211. },
  212. .num_resources = ARRAY_SIZE(cmx270_2700G_resource),
  213. .resource = cmx270_2700G_resource,
  214. .id = -1,
  215. };
  216. static void __init cmx270_init_2700G(void)
  217. {
  218. platform_device_register(&cmx270_2700G);
  219. }
  220. #else
  221. static inline void cmx270_init_2700G(void) {}
  222. #endif
  223. /* PXA27x OHCI controller setup */
  224. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  225. static struct pxaohci_platform_data cmx270_ohci_platform_data = {
  226. .port_mode = PMM_PERPORT_MODE,
  227. .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
  228. };
  229. static void __init cmx270_init_ohci(void)
  230. {
  231. pxa_set_ohci_info(&cmx270_ohci_platform_data);
  232. }
  233. #else
  234. static inline void cmx270_init_ohci(void) {}
  235. #endif
  236. #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
  237. static int cmx270_mci_init(struct device *dev,
  238. irq_handler_t cmx270_detect_int,
  239. void *data)
  240. {
  241. int err;
  242. err = gpio_request(GPIO105_MMC_POWER, "MMC/SD power");
  243. if (err) {
  244. dev_warn(dev, "power gpio unavailable\n");
  245. return err;
  246. }
  247. gpio_direction_output(GPIO105_MMC_POWER, 0);
  248. err = request_irq(CMX270_MMC_IRQ, cmx270_detect_int,
  249. IRQF_DISABLED | IRQF_TRIGGER_FALLING,
  250. "MMC card detect", data);
  251. if (err) {
  252. gpio_free(GPIO105_MMC_POWER);
  253. dev_err(dev, "cmx270_mci_init: MMC/SD: can't"
  254. " request MMC card detect IRQ\n");
  255. }
  256. return err;
  257. }
  258. static void cmx270_mci_setpower(struct device *dev, unsigned int vdd)
  259. {
  260. struct pxamci_platform_data *p_d = dev->platform_data;
  261. if ((1 << vdd) & p_d->ocr_mask) {
  262. dev_dbg(dev, "power on\n");
  263. gpio_set_value(GPIO105_MMC_POWER, 0);
  264. } else {
  265. gpio_set_value(GPIO105_MMC_POWER, 1);
  266. dev_dbg(dev, "power off\n");
  267. }
  268. }
  269. static void cmx270_mci_exit(struct device *dev, void *data)
  270. {
  271. free_irq(CMX270_MMC_IRQ, data);
  272. gpio_free(GPIO105_MMC_POWER);
  273. }
  274. static struct pxamci_platform_data cmx270_mci_platform_data = {
  275. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  276. .init = cmx270_mci_init,
  277. .setpower = cmx270_mci_setpower,
  278. .exit = cmx270_mci_exit,
  279. };
  280. static void __init cmx270_init_mmc(void)
  281. {
  282. pxa_set_mci_info(&cmx270_mci_platform_data);
  283. }
  284. #else
  285. static inline void cmx270_init_mmc(void) {}
  286. #endif
  287. void __init cmx270_init(void)
  288. {
  289. pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_pin_config));
  290. cmx270_init_rtc();
  291. cmx270_init_mmc();
  292. cmx270_init_ohci();
  293. cmx270_init_2700G();
  294. }