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