neponset.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /*
  2. * linux/arch/arm/mach-sa1100/neponset.c
  3. *
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/init.h>
  7. #include <linux/tty.h>
  8. #include <linux/ioport.h>
  9. #include <linux/serial_core.h>
  10. #include <linux/platform_device.h>
  11. #include <mach/hardware.h>
  12. #include <asm/mach-types.h>
  13. #include <asm/irq.h>
  14. #include <asm/mach/map.h>
  15. #include <asm/mach/irq.h>
  16. #include <asm/mach/serial_sa1100.h>
  17. #include <mach/assabet.h>
  18. #include <mach/neponset.h>
  19. #include <asm/hardware/sa1111.h>
  20. #include <asm/sizes.h>
  21. /*
  22. * Install handler for Neponset IRQ. Note that we have to loop here
  23. * since the ETHERNET and USAR IRQs are level based, and we need to
  24. * ensure that the IRQ signal is deasserted before returning. This
  25. * is rather unfortunate.
  26. */
  27. static void
  28. neponset_irq_handler(unsigned int irq, struct irq_desc *desc)
  29. {
  30. unsigned int irr;
  31. while (1) {
  32. /*
  33. * Acknowledge the parent IRQ.
  34. */
  35. desc->irq_data.chip->irq_ack(&desc->irq_data);
  36. /*
  37. * Read the interrupt reason register. Let's have all
  38. * active IRQ bits high. Note: there is a typo in the
  39. * Neponset user's guide for the SA1111 IRR level.
  40. */
  41. irr = IRR ^ (IRR_ETHERNET | IRR_USAR);
  42. if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0)
  43. break;
  44. /*
  45. * Since there is no individual mask, we have to
  46. * mask the parent IRQ. This is safe, since we'll
  47. * recheck the register for any pending IRQs.
  48. */
  49. if (irr & (IRR_ETHERNET | IRR_USAR)) {
  50. desc->irq_data.chip->irq_mask(&desc->irq_data);
  51. /*
  52. * Ack the interrupt now to prevent re-entering
  53. * this neponset handler. Again, this is safe
  54. * since we'll check the IRR register prior to
  55. * leaving.
  56. */
  57. desc->irq_data.chip->irq_ack(&desc->irq_data);
  58. if (irr & IRR_ETHERNET) {
  59. generic_handle_irq(IRQ_NEPONSET_SMC9196);
  60. }
  61. if (irr & IRR_USAR) {
  62. generic_handle_irq(IRQ_NEPONSET_USAR);
  63. }
  64. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  65. }
  66. if (irr & IRR_SA1111) {
  67. generic_handle_irq(IRQ_NEPONSET_SA1111);
  68. }
  69. }
  70. }
  71. static void neponset_set_mctrl(struct uart_port *port, u_int mctrl)
  72. {
  73. u_int mdm_ctl0 = MDM_CTL_0;
  74. if (port->mapbase == _Ser1UTCR0) {
  75. if (mctrl & TIOCM_RTS)
  76. mdm_ctl0 &= ~MDM_CTL0_RTS2;
  77. else
  78. mdm_ctl0 |= MDM_CTL0_RTS2;
  79. if (mctrl & TIOCM_DTR)
  80. mdm_ctl0 &= ~MDM_CTL0_DTR2;
  81. else
  82. mdm_ctl0 |= MDM_CTL0_DTR2;
  83. } else if (port->mapbase == _Ser3UTCR0) {
  84. if (mctrl & TIOCM_RTS)
  85. mdm_ctl0 &= ~MDM_CTL0_RTS1;
  86. else
  87. mdm_ctl0 |= MDM_CTL0_RTS1;
  88. if (mctrl & TIOCM_DTR)
  89. mdm_ctl0 &= ~MDM_CTL0_DTR1;
  90. else
  91. mdm_ctl0 |= MDM_CTL0_DTR1;
  92. }
  93. MDM_CTL_0 = mdm_ctl0;
  94. }
  95. static u_int neponset_get_mctrl(struct uart_port *port)
  96. {
  97. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  98. u_int mdm_ctl1 = MDM_CTL_1;
  99. if (port->mapbase == _Ser1UTCR0) {
  100. if (mdm_ctl1 & MDM_CTL1_DCD2)
  101. ret &= ~TIOCM_CD;
  102. if (mdm_ctl1 & MDM_CTL1_CTS2)
  103. ret &= ~TIOCM_CTS;
  104. if (mdm_ctl1 & MDM_CTL1_DSR2)
  105. ret &= ~TIOCM_DSR;
  106. } else if (port->mapbase == _Ser3UTCR0) {
  107. if (mdm_ctl1 & MDM_CTL1_DCD1)
  108. ret &= ~TIOCM_CD;
  109. if (mdm_ctl1 & MDM_CTL1_CTS1)
  110. ret &= ~TIOCM_CTS;
  111. if (mdm_ctl1 & MDM_CTL1_DSR1)
  112. ret &= ~TIOCM_DSR;
  113. }
  114. return ret;
  115. }
  116. static struct sa1100_port_fns neponset_port_fns __devinitdata = {
  117. .set_mctrl = neponset_set_mctrl,
  118. .get_mctrl = neponset_get_mctrl,
  119. };
  120. static int __devinit neponset_probe(struct platform_device *dev)
  121. {
  122. sa1100_register_uart_fns(&neponset_port_fns);
  123. /*
  124. * Install handler for GPIO25.
  125. */
  126. irq_set_irq_type(IRQ_GPIO25, IRQ_TYPE_EDGE_RISING);
  127. irq_set_chained_handler(IRQ_GPIO25, neponset_irq_handler);
  128. /*
  129. * We would set IRQ_GPIO25 to be a wake-up IRQ, but
  130. * unfortunately something on the Neponset activates
  131. * this IRQ on sleep (ethernet?)
  132. */
  133. #if 0
  134. enable_irq_wake(IRQ_GPIO25);
  135. #endif
  136. /*
  137. * Setup other Neponset IRQs. SA1111 will be done by the
  138. * generic SA1111 code.
  139. */
  140. irq_set_handler(IRQ_NEPONSET_SMC9196, handle_simple_irq);
  141. set_irq_flags(IRQ_NEPONSET_SMC9196, IRQF_VALID | IRQF_PROBE);
  142. irq_set_handler(IRQ_NEPONSET_USAR, handle_simple_irq);
  143. set_irq_flags(IRQ_NEPONSET_USAR, IRQF_VALID | IRQF_PROBE);
  144. /*
  145. * Disable GPIO 0/1 drivers so the buttons work on the module.
  146. */
  147. NCR_0 = NCR_GP01_OFF;
  148. return 0;
  149. }
  150. #ifdef CONFIG_PM
  151. /*
  152. * LDM power management.
  153. */
  154. static unsigned int neponset_saved_state;
  155. static int neponset_suspend(struct platform_device *dev, pm_message_t state)
  156. {
  157. /*
  158. * Save state.
  159. */
  160. neponset_saved_state = NCR_0;
  161. return 0;
  162. }
  163. static int neponset_resume(struct platform_device *dev)
  164. {
  165. NCR_0 = neponset_saved_state;
  166. return 0;
  167. }
  168. #else
  169. #define neponset_suspend NULL
  170. #define neponset_resume NULL
  171. #endif
  172. static struct platform_driver neponset_device_driver = {
  173. .probe = neponset_probe,
  174. .suspend = neponset_suspend,
  175. .resume = neponset_resume,
  176. .driver = {
  177. .name = "neponset",
  178. },
  179. };
  180. static struct resource neponset_resources[] = {
  181. [0] = {
  182. .start = 0x10000000,
  183. .end = 0x17ffffff,
  184. .flags = IORESOURCE_MEM,
  185. },
  186. };
  187. static struct platform_device neponset_device = {
  188. .name = "neponset",
  189. .id = 0,
  190. .num_resources = ARRAY_SIZE(neponset_resources),
  191. .resource = neponset_resources,
  192. };
  193. static struct resource sa1111_resources[] = {
  194. [0] = {
  195. .start = 0x40000000,
  196. .end = 0x40001fff,
  197. .flags = IORESOURCE_MEM,
  198. },
  199. [1] = {
  200. .start = IRQ_NEPONSET_SA1111,
  201. .end = IRQ_NEPONSET_SA1111,
  202. .flags = IORESOURCE_IRQ,
  203. },
  204. };
  205. static struct sa1111_platform_data sa1111_info = {
  206. .irq_base = IRQ_BOARD_END,
  207. };
  208. static u64 sa1111_dmamask = 0xffffffffUL;
  209. static struct platform_device sa1111_device = {
  210. .name = "sa1111",
  211. .id = 0,
  212. .dev = {
  213. .dma_mask = &sa1111_dmamask,
  214. .coherent_dma_mask = 0xffffffff,
  215. .platform_data = &sa1111_info,
  216. },
  217. .num_resources = ARRAY_SIZE(sa1111_resources),
  218. .resource = sa1111_resources,
  219. };
  220. static struct resource smc91x_resources[] = {
  221. [0] = {
  222. .name = "smc91x-regs",
  223. .start = SA1100_CS3_PHYS,
  224. .end = SA1100_CS3_PHYS + 0x01ffffff,
  225. .flags = IORESOURCE_MEM,
  226. },
  227. [1] = {
  228. .start = IRQ_NEPONSET_SMC9196,
  229. .end = IRQ_NEPONSET_SMC9196,
  230. .flags = IORESOURCE_IRQ,
  231. },
  232. [2] = {
  233. .name = "smc91x-attrib",
  234. .start = SA1100_CS3_PHYS + 0x02000000,
  235. .end = SA1100_CS3_PHYS + 0x03ffffff,
  236. .flags = IORESOURCE_MEM,
  237. },
  238. };
  239. static struct platform_device smc91x_device = {
  240. .name = "smc91x",
  241. .id = 0,
  242. .num_resources = ARRAY_SIZE(smc91x_resources),
  243. .resource = smc91x_resources,
  244. };
  245. static struct platform_device *devices[] __initdata = {
  246. &neponset_device,
  247. &sa1111_device,
  248. &smc91x_device,
  249. };
  250. extern void sa1110_mb_disable(void);
  251. static int __init neponset_init(void)
  252. {
  253. platform_driver_register(&neponset_device_driver);
  254. /*
  255. * The Neponset is only present on the Assabet machine type.
  256. */
  257. if (!machine_is_assabet())
  258. return -ENODEV;
  259. /*
  260. * Ensure that the memory bus request/grant signals are setup,
  261. * and the grant is held in its inactive state, whether or not
  262. * we actually have a Neponset attached.
  263. */
  264. sa1110_mb_disable();
  265. if (!machine_has_neponset()) {
  266. printk(KERN_DEBUG "Neponset expansion board not present\n");
  267. return -ENODEV;
  268. }
  269. if (WHOAMI != 0x11) {
  270. printk(KERN_WARNING "Neponset board detected, but "
  271. "wrong ID: %02x\n", WHOAMI);
  272. return -ENODEV;
  273. }
  274. return platform_add_devices(devices, ARRAY_SIZE(devices));
  275. }
  276. subsys_initcall(neponset_init);
  277. static struct map_desc neponset_io_desc[] __initdata = {
  278. { /* System Registers */
  279. .virtual = 0xf3000000,
  280. .pfn = __phys_to_pfn(0x10000000),
  281. .length = SZ_1M,
  282. .type = MT_DEVICE
  283. }, { /* SA-1111 */
  284. .virtual = 0xf4000000,
  285. .pfn = __phys_to_pfn(0x40000000),
  286. .length = SZ_1M,
  287. .type = MT_DEVICE
  288. }
  289. };
  290. void __init neponset_map_io(void)
  291. {
  292. iotable_init(neponset_io_desc, ARRAY_SIZE(neponset_io_desc));
  293. }