neponset.c 7.6 KB

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