neponset.c 7.3 KB

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