arch-lpd7a40x.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /* arch/arm/mach-lh7a40x/arch-lpd7a40x.c
  2. *
  3. * Copyright (C) 2004 Logic Product Development
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * version 2 as published by the Free Software Foundation.
  8. *
  9. */
  10. #include <linux/tty.h>
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/interrupt.h>
  14. #include <asm/hardware.h>
  15. #include <asm/setup.h>
  16. #include <asm/mach-types.h>
  17. #include <asm/mach/arch.h>
  18. #include <asm/irq.h>
  19. #include <asm/mach/irq.h>
  20. #include <asm/mach/map.h>
  21. #include "common.h"
  22. #define CPLD_INT_NETHERNET (1<<0)
  23. #define CPLD_INTMASK_ETHERNET (1<<2)
  24. #if defined (CONFIG_MACH_LPD7A400)
  25. # define CPLD_INT_NTOUCH (1<<1)
  26. # define CPLD_INTMASK_TOUCH (1<<3)
  27. # define CPLD_INT_PEN (1<<4)
  28. # define CPLD_INTMASK_PEN (1<<4)
  29. # define CPLD_INT_PIRQ (1<<4)
  30. #endif
  31. #define CPLD_INTMASK_CPLD (1<<7)
  32. #define CPLD_INT_CPLD (1<<6)
  33. #define CPLD_CONTROL_SWINT (1<<7) /* Disable all CPLD IRQs */
  34. #define CPLD_CONTROL_OCMSK (1<<6) /* Mask USB1 connect IRQ */
  35. #define CPLD_CONTROL_PDRV (1<<5) /* PCC_nDRV high */
  36. #define CPLD_CONTROL_USB1C (1<<4) /* USB1 connect IRQ active */
  37. #define CPLD_CONTROL_USB1P (1<<3) /* USB1 power disable */
  38. #define CPLD_CONTROL_AWKP (1<<2) /* Auto-wakeup disabled */
  39. #define CPLD_CONTROL_LCD_ENABLE (1<<1) /* LCD Vee enable */
  40. #define CPLD_CONTROL_WRLAN_NENABLE (1<<0) /* SMC91x power disable */
  41. static struct resource smc91x_resources[] = {
  42. [0] = {
  43. .start = CPLD00_PHYS,
  44. .end = CPLD00_PHYS + CPLD00_SIZE - 1, /* Only needs 16B */
  45. .flags = IORESOURCE_MEM,
  46. },
  47. [1] = {
  48. .start = IRQ_LPD7A40X_ETH_INT,
  49. .end = IRQ_LPD7A40X_ETH_INT,
  50. .flags = IORESOURCE_IRQ,
  51. },
  52. };
  53. static struct platform_device smc91x_device = {
  54. .name = "smc91x",
  55. .id = 0,
  56. .num_resources = ARRAY_SIZE(smc91x_resources),
  57. .resource = smc91x_resources,
  58. };
  59. static struct resource lh7a40x_usbclient_resources[] = {
  60. [0] = {
  61. .start = USB_PHYS,
  62. .end = (USB_PHYS + PAGE_SIZE),
  63. .flags = IORESOURCE_MEM,
  64. },
  65. [1] = {
  66. .start = IRQ_USB,
  67. .end = IRQ_USB,
  68. .flags = IORESOURCE_IRQ,
  69. },
  70. };
  71. static u64 lh7a40x_usbclient_dma_mask = 0xffffffffUL;
  72. static struct platform_device lh7a40x_usbclient_device = {
  73. // .name = "lh7a40x_udc",
  74. .name = "lh7-udc",
  75. .id = 0,
  76. .dev = {
  77. .dma_mask = &lh7a40x_usbclient_dma_mask,
  78. .coherent_dma_mask = 0xffffffffUL,
  79. },
  80. .num_resources = ARRAY_SIZE (lh7a40x_usbclient_resources),
  81. .resource = lh7a40x_usbclient_resources,
  82. };
  83. #if defined (CONFIG_ARCH_LH7A404)
  84. static struct resource lh7a404_usbhost_resources [] = {
  85. [0] = {
  86. .start = USBH_PHYS,
  87. .end = (USBH_PHYS + 0xFF),
  88. .flags = IORESOURCE_MEM,
  89. },
  90. [1] = {
  91. .start = IRQ_USHINTR,
  92. .end = IRQ_USHINTR,
  93. .flags = IORESOURCE_IRQ,
  94. },
  95. };
  96. static u64 lh7a404_usbhost_dma_mask = 0xffffffffUL;
  97. static struct platform_device lh7a404_usbhost_device = {
  98. .name = "lh7a404-ohci",
  99. .id = 0,
  100. .dev = {
  101. .dma_mask = &lh7a404_usbhost_dma_mask,
  102. .coherent_dma_mask = 0xffffffffUL,
  103. },
  104. .num_resources = ARRAY_SIZE (lh7a404_usbhost_resources),
  105. .resource = lh7a404_usbhost_resources,
  106. };
  107. #endif
  108. static struct platform_device* lpd7a40x_devs[] __initdata = {
  109. &smc91x_device,
  110. &lh7a40x_usbclient_device,
  111. #if defined (CONFIG_ARCH_LH7A404)
  112. &lh7a404_usbhost_device,
  113. #endif
  114. };
  115. extern void lpd7a400_map_io (void);
  116. static void __init lpd7a40x_init (void)
  117. {
  118. #if defined (CONFIG_MACH_LPD7A400)
  119. CPLD_CONTROL |= 0
  120. | CPLD_CONTROL_SWINT /* Disable software interrupt */
  121. | CPLD_CONTROL_OCMSK; /* Mask USB1 connection IRQ */
  122. CPLD_CONTROL &= ~(0
  123. | CPLD_CONTROL_LCD_ENABLE /* Disable LCD */
  124. | CPLD_CONTROL_WRLAN_NENABLE /* Enable SMC91x */
  125. );
  126. #endif
  127. #if defined (CONFIG_MACH_LPD7A404)
  128. CPLD_CONTROL &= ~(0
  129. | CPLD_CONTROL_WRLAN_NENABLE /* Enable SMC91x */
  130. );
  131. #endif
  132. platform_add_devices (lpd7a40x_devs, ARRAY_SIZE (lpd7a40x_devs));
  133. #if defined (CONFIG_FB_ARMCLCD)
  134. lh7a40x_clcd_init ();
  135. #endif
  136. }
  137. static void lh7a40x_ack_cpld_irq (u32 irq)
  138. {
  139. /* CPLD doesn't have ack capability, but some devices may */
  140. #if defined (CPLD_INTMASK_TOUCH)
  141. /* The touch control *must* mask the the interrupt because the
  142. * interrupt bit is read by the driver to determine if the pen
  143. * is still down. */
  144. if (irq == IRQ_TOUCH)
  145. CPLD_INTERRUPTS |= CPLD_INTMASK_TOUCH;
  146. #endif
  147. }
  148. static void lh7a40x_mask_cpld_irq (u32 irq)
  149. {
  150. switch (irq) {
  151. case IRQ_LPD7A40X_ETH_INT:
  152. CPLD_INTERRUPTS |= CPLD_INTMASK_ETHERNET;
  153. break;
  154. #if defined (IRQ_TOUCH)
  155. case IRQ_TOUCH:
  156. CPLD_INTERRUPTS |= CPLD_INTMASK_TOUCH;
  157. break;
  158. #endif
  159. }
  160. }
  161. static void lh7a40x_unmask_cpld_irq (u32 irq)
  162. {
  163. switch (irq) {
  164. case IRQ_LPD7A40X_ETH_INT:
  165. CPLD_INTERRUPTS &= ~CPLD_INTMASK_ETHERNET;
  166. break;
  167. #if defined (IRQ_TOUCH)
  168. case IRQ_TOUCH:
  169. CPLD_INTERRUPTS &= ~CPLD_INTMASK_TOUCH;
  170. break;
  171. #endif
  172. }
  173. }
  174. static struct irqchip lpd7a40x_cpld_chip = {
  175. .ack = lh7a40x_ack_cpld_irq,
  176. .mask = lh7a40x_mask_cpld_irq,
  177. .unmask = lh7a40x_unmask_cpld_irq,
  178. };
  179. static void lpd7a40x_cpld_handler (unsigned int irq, struct irqdesc *desc,
  180. struct pt_regs *regs)
  181. {
  182. unsigned int mask = CPLD_INTERRUPTS;
  183. desc->chip->ack (irq);
  184. if ((mask & (1<<0)) == 0) /* WLAN */
  185. IRQ_DISPATCH (IRQ_LPD7A40X_ETH_INT);
  186. #if defined (IRQ_TOUCH)
  187. if ((mask & (1<<1)) == 0) /* Touch */
  188. IRQ_DISPATCH (IRQ_TOUCH);
  189. #endif
  190. desc->chip->unmask (irq); /* Level-triggered need this */
  191. }
  192. void __init lh7a40x_init_board_irq (void)
  193. {
  194. int irq;
  195. /* Rev A (v2.8): PF0, PF1, PF2, and PF3 are available IRQs.
  196. PF7 supports the CPLD.
  197. Rev B (v3.4): PF0, PF1, and PF2 are available IRQs.
  198. PF3 supports the CPLD.
  199. (Some) LPD7A404 prerelease boards report a version
  200. number of 0x16, but we force an override since the
  201. hardware is of the newer variety.
  202. */
  203. unsigned char cpld_version = CPLD_REVISION;
  204. int pinCPLD = (cpld_version == 0x28) ? 7 : 3;
  205. #if defined CONFIG_MACH_LPD7A404
  206. cpld_version = 0x34; /* Coerce LPD7A404 to RevB */
  207. #endif
  208. /* First, configure user controlled GPIOF interrupts */
  209. GPIO_PFDD &= ~0x0f; /* PF0-3 are inputs */
  210. GPIO_INTTYPE1 &= ~0x0f; /* PF0-3 are level triggered */
  211. GPIO_INTTYPE2 &= ~0x0f; /* PF0-3 are active low */
  212. barrier ();
  213. GPIO_GPIOFINTEN |= 0x0f; /* Enable PF0, PF1, PF2, and PF3 IRQs */
  214. /* Then, configure CPLD interrupt */
  215. /* Disable all CPLD interrupts */
  216. #if defined (CONFIG_MACH_LPD7A400)
  217. CPLD_INTERRUPTS = CPLD_INTMASK_TOUCH | CPLD_INTMASK_PEN
  218. | CPLD_INTMASK_ETHERNET;
  219. /* *** FIXME: don't know why we need 7 and 4. 7 is way wrong
  220. and 4 is uncefined. */
  221. // (1<<7)|(1<<4)|(1<<3)|(1<<2);
  222. #endif
  223. #if defined (CONFIG_MACH_LPD7A404)
  224. CPLD_INTERRUPTS = CPLD_INTMASK_ETHERNET;
  225. /* *** FIXME: don't know why we need 6 and 5, neither is defined. */
  226. // (1<<6)|(1<<5)|(1<<3);
  227. #endif
  228. GPIO_PFDD &= ~(1 << pinCPLD); /* Make input */
  229. GPIO_INTTYPE1 &= ~(1 << pinCPLD); /* Level triggered */
  230. GPIO_INTTYPE2 &= ~(1 << pinCPLD); /* Active low */
  231. barrier ();
  232. GPIO_GPIOFINTEN |= (1 << pinCPLD); /* Enable */
  233. /* Cascade CPLD interrupts */
  234. for (irq = IRQ_BOARD_START;
  235. irq < IRQ_BOARD_START + NR_IRQ_BOARD; ++irq) {
  236. set_irq_chip (irq, &lpd7a40x_cpld_chip);
  237. set_irq_handler (irq, do_level_IRQ);
  238. set_irq_flags (irq, IRQF_VALID);
  239. }
  240. set_irq_chained_handler ((cpld_version == 0x28)
  241. ? IRQ_CPLD_V28
  242. : IRQ_CPLD_V34,
  243. lpd7a40x_cpld_handler);
  244. }
  245. static struct map_desc lpd7a40x_io_desc[] __initdata = {
  246. {
  247. .virtual = IO_VIRT,
  248. .pfn = __phys_to_pfn(IO_PHYS),
  249. .length = IO_SIZE,
  250. .type = MT_DEVICE
  251. },
  252. { /* Mapping added to work around chip select problems */
  253. .virtual = IOBARRIER_VIRT,
  254. .pfn = __phys_to_pfn(IOBARRIER_PHYS),
  255. .length = IOBARRIER_SIZE,
  256. .type = MT_DEVICE
  257. },
  258. {
  259. .virtual = CF_VIRT,
  260. .pfn = __phys_to_pfn(CF_PHYS),
  261. .length = CF_SIZE,
  262. .type = MT_DEVICE
  263. },
  264. {
  265. .virtual = CPLD02_VIRT,
  266. .pfn = __phys_to_pfn(CPLD02_PHYS),
  267. .length = CPLD02_SIZE,
  268. .type = MT_DEVICE
  269. },
  270. {
  271. .virtual = CPLD06_VIRT,
  272. .pfn = __phys_to_pfn(CPLD06_PHYS),
  273. .length = CPLD06_SIZE,
  274. .type = MT_DEVICE
  275. },
  276. {
  277. .virtual = CPLD08_VIRT,
  278. .pfn = __phys_to_pfn(CPLD08_PHYS),
  279. .length = CPLD08_SIZE,
  280. .type = MT_DEVICE
  281. },
  282. {
  283. .virtual = CPLD08_VIRT,
  284. .pfn = __phys_to_pfn(CPLD08_PHYS),
  285. .length = CPLD08_SIZE,
  286. .type = MT_DEVICE
  287. },
  288. {
  289. .virtual = CPLD0A_VIRT,
  290. .pfn = __phys_to_pfn(CPLD0A_PHYS),
  291. .length = CPLD0A_SIZE,
  292. .type = MT_DEVICE
  293. },
  294. {
  295. .virtual = CPLD0C_VIRT,
  296. .pfn = __phys_to_pfn(CPLD0C_PHYS),
  297. .length = CPLD0C_SIZE,
  298. .type = MT_DEVICE
  299. },
  300. {
  301. .virtual = CPLD0E_VIRT,
  302. .pfn = __phys_to_pfn(CPLD0E_PHYS),
  303. .length = CPLD0E_SIZE,
  304. .type = MT_DEVICE
  305. },
  306. {
  307. .virtual = CPLD10_VIRT,
  308. .pfn = __phys_to_pfn(CPLD10_PHYS),
  309. .length = CPLD10_SIZE,
  310. .type = MT_DEVICE
  311. },
  312. {
  313. .virtual = CPLD12_VIRT,
  314. .pfn = __phys_to_pfn(CPLD12_PHYS),
  315. .length = CPLD12_SIZE,
  316. .type = MT_DEVICE
  317. },
  318. {
  319. .virtual = CPLD14_VIRT,
  320. .pfn = __phys_to_pfn(CPLD14_PHYS),
  321. .length = CPLD14_SIZE,
  322. .type = MT_DEVICE
  323. },
  324. {
  325. .virtual = CPLD16_VIRT,
  326. .pfn = __phys_to_pfn(CPLD16_PHYS),
  327. .length = CPLD16_SIZE,
  328. .type = MT_DEVICE
  329. },
  330. {
  331. .virtual = CPLD18_VIRT,
  332. .pfn = __phys_to_pfn(CPLD18_PHYS),
  333. .length = CPLD18_SIZE,
  334. .type = MT_DEVICE
  335. },
  336. {
  337. .virtual = CPLD1A_VIRT,
  338. .pfn = __phys_to_pfn(CPLD1A_PHYS),
  339. .length = CPLD1A_SIZE,
  340. .type = MT_DEVICE
  341. },
  342. };
  343. void __init
  344. lpd7a40x_map_io(void)
  345. {
  346. iotable_init (lpd7a40x_io_desc, ARRAY_SIZE (lpd7a40x_io_desc));
  347. }
  348. #ifdef CONFIG_MACH_LPD7A400
  349. MACHINE_START (LPD7A400, "Logic Product Development LPD7A400-10")
  350. /* Maintainer: Marc Singer */
  351. .phys_io = 0x80000000,
  352. .io_pg_offst = ((io_p2v (0x80000000))>>18) & 0xfffc,
  353. .boot_params = 0xc0000100,
  354. .map_io = lpd7a40x_map_io,
  355. .init_irq = lh7a400_init_irq,
  356. .timer = &lh7a40x_timer,
  357. .init_machine = lpd7a40x_init,
  358. MACHINE_END
  359. #endif
  360. #ifdef CONFIG_MACH_LPD7A404
  361. MACHINE_START (LPD7A404, "Logic Product Development LPD7A404-10")
  362. /* Maintainer: Marc Singer */
  363. .phys_io = 0x80000000,
  364. .io_pg_offst = ((io_p2v (0x80000000))>>18) & 0xfffc,
  365. .boot_params = 0xc0000100,
  366. .map_io = lpd7a40x_map_io,
  367. .init_irq = lh7a404_init_irq,
  368. .timer = &lh7a40x_timer,
  369. .init_machine = lpd7a40x_init,
  370. MACHINE_END
  371. #endif