neponset.c 7.7 KB

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