neponset.c 8.4 KB

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