hiddenDangerAnalysis.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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/irq.h>
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/platform_data/sa11x0-serial.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/pm.h>
  13. #include <linux/serial_core.h>
  14. #include <linux/slab.h>
  15. #include <asm/mach-types.h>
  16. #include <asm/mach/map.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. #include <mach/irqs.h>
  23. #define NEP_IRQ_SMC91X 0
  24. #define NEP_IRQ_USAR 1
  25. #define NEP_IRQ_SA1111 2
  26. #define NEP_IRQ_NR 3
  27. #define WHOAMI 0x00
  28. #define LEDS 0x10
  29. #define SWPK 0x20
  30. #define IRR 0x24
  31. #define KP_Y_IN 0x80
  32. #define KP_X_OUT 0x90
  33. #define NCR_0 0xa0
  34. #define MDM_CTL_0 0xb0
  35. #define MDM_CTL_1 0xb4
  36. #define AUD_CTL 0xc0
  37. #define IRR_ETHERNET (1 << 0)
  38. #define IRR_USAR (1 << 1)
  39. #define IRR_SA1111 (1 << 2)
  40. #define MDM_CTL0_RTS1 (1 << 0)
  41. #define MDM_CTL0_DTR1 (1 << 1)
  42. #define MDM_CTL0_RTS2 (1 << 2)
  43. #define MDM_CTL0_DTR2 (1 << 3)
  44. #define MDM_CTL1_CTS1 (1 << 0)
  45. #define MDM_CTL1_DSR1 (1 << 1)
  46. #define MDM_CTL1_DCD1 (1 << 2)
  47. #define MDM_CTL1_CTS2 (1 << 3)
  48. #define MDM_CTL1_DSR2 (1 << 4)
  49. #define MDM_CTL1_DCD2 (1 << 5)
  50. #define AUD_SEL_1341 (1 << 0)
  51. #define AUD_MUTE_1341 (1 << 1)
  52. extern void sa1110_mb_disable(void);
  53. struct neponset_drvdata {
  54. void __iomem *base;
  55. struct platform_device *sa1111;
  56. struct platform_device *smc91x;
  57. unsigned irq_base;
  58. #ifdef CONFIG_PM_SLEEP
  59. u32 ncr0;
  60. u32 mdm_ctl_0;
  61. #endif
  62. };
  63. static void __iomem *nep_base;
  64. void neponset_ncr_frob(unsigned int mask, unsigned int val)
  65. {
  66. void __iomem *base = nep_base;
  67. if (base) {
  68. unsigned long flags;
  69. unsigned v;
  70. local_irq_save(flags);
  71. v = readb_relaxed(base + NCR_0);
  72. writeb_relaxed((v & ~mask) | val, base + NCR_0);
  73. local_irq_restore(flags);
  74. } else {
  75. WARN(1, "nep_base unset\n");
  76. }
  77. }
  78. EXPORT_SYMBOL(neponset_ncr_frob);
  79. static void neponset_set_mctrl(struct uart_port *port, u_int mctrl)
  80. {
  81. void __iomem *base = nep_base;
  82. u_int mdm_ctl0;
  83. if (!base)
  84. return;
  85. mdm_ctl0 = readb_relaxed(base + MDM_CTL_0);
  86. if (port->mapbase == _Ser1UTCR0) {
  87. if (mctrl & TIOCM_RTS)
  88. mdm_ctl0 &= ~MDM_CTL0_RTS2;
  89. else
  90. mdm_ctl0 |= MDM_CTL0_RTS2;
  91. if (mctrl & TIOCM_DTR)
  92. mdm_ctl0 &= ~MDM_CTL0_DTR2;
  93. else
  94. mdm_ctl0 |= MDM_CTL0_DTR2;
  95. } else if (port->mapbase == _Ser3UTCR0) {
  96. if (mctrl & TIOCM_RTS)
  97. mdm_ctl0 &= ~MDM_CTL0_RTS1;
  98. else
  99. mdm_ctl0 |= MDM_CTL0_RTS1;
  100. if (mctrl & TIOCM_DTR)
  101. mdm_ctl0 &= ~MDM_CTL0_DTR1;
  102. else
  103. mdm_ctl0 |= MDM_CTL0_DTR1;
  104. }
  105. writeb_relaxed(mdm_ctl0, base + MDM_CTL_0);
  106. }
  107. static u_int neponset_get_mctrl(struct uart_port *port)
  108. {
  109. void __iomem *base = nep_base;
  110. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  111. u_int mdm_ctl1;
  112. if (!base)
  113. return ret;
  114. mdm_ctl1 = readb_relaxed(base + MDM_CTL_1);
  115. if (port->mapbase == _Ser1UTCR0) {
  116. if (mdm_ctl1 & MDM_CTL1_DCD2)
  117. ret &= ~TIOCM_CD;
  118. if (mdm_ctl1 & MDM_CTL1_CTS2)
  119. ret &= ~TIOCM_CTS;
  120. if (mdm_ctl1 & MDM_CTL1_DSR2)
  121. ret &= ~TIOCM_DSR;
  122. } else if (port->mapbase == _Ser3UTCR0) {
  123. if (mdm_ctl1 & MDM_CTL1_DCD1)
  124. ret &= ~TIOCM_CD;
  125. if (mdm_ctl1 & MDM_CTL1_CTS1)
  126. ret &= ~TIOCM_CTS;
  127. if (mdm_ctl1 & MDM_CTL1_DSR1)
  128. ret &= ~TIOCM_DSR;
  129. }
  130. return ret;
  131. }
  132. static struct sa1100_port_fns neponset_port_fns = {
  133. .set_mctrl = neponset_set_mctrl,
  134. .get_mctrl = neponset_get_mctrl,
  135. };
  136. /*
  137. * Install handler for Neponset IRQ. Note that we have to loop here
  138. * since the ETHERNET and USAR IRQs are level based, and we need to
  139. * ensure that the IRQ signal is deasserted before returning. This
  140. * is rather unfortunate.
  141. */
  142. static void neponset_irq_handler(unsigned int irq, struct irq_desc *desc)
  143. {
  144. struct neponset_drvdata *d = irq_desc_get_handler_data(desc);
  145. unsigned int irr;
  146. while (1) {
  147. /*
  148. * Acknowledge the parent IRQ.
  149. */
  150. desc->irq_data.chip->irq_ack(&desc->irq_data);
  151. /*
  152. * Read the interrupt reason register. Let's have all
  153. * active IRQ bits high. Note: there is a typo in the
  154. * Neponset user's guide for the SA1111 IRR level.
  155. */
  156. irr = readb_relaxed(d->base + IRR);
  157. irr ^= IRR_ETHERNET | IRR_USAR;
  158. if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0)
  159. break;
  160. /*
  161. * Since there is no individual mask, we have to
  162. * mask the parent IRQ. This is safe, since we'll
  163. * recheck the register for any pending IRQs.
  164. */
  165. if (irr & (IRR_ETHERNET | IRR_USAR)) {
  166. desc->irq_data.chip->irq_mask(&desc->irq_data);
  167. /*
  168. * Ack the interrupt now to prevent re-entering
  169. * this neponset handler. Again, this is safe
  170. * since we'll check the IRR register prior to
  171. * leaving.
  172. */
  173. desc->irq_data.chip->irq_ack(&desc->irq_data);
  174. if (irr & IRR_ETHERNET)
  175. generic_handle_irq(d->irq_base + NEP_IRQ_SMC91X);
  176. if (irr & IRR_USAR)
  177. generic_handle_irq(d->irq_base + NEP_IRQ_USAR);
  178. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  179. }
  180. if (irr & IRR_SA1111)
  181. generic_handle_irq(d->irq_base + NEP_IRQ_SA1111);
  182. }
  183. }
  184. /* Yes, we really do not have any kind of masking or unmasking */
  185. static void nochip_noop(struct irq_data *irq)
  186. {
  187. }
  188. static struct irq_chip nochip = {
  189. .name = "neponset",
  190. .irq_ack = nochip_noop,
  191. .irq_mask = nochip_noop,
  192. .irq_unmask = nochip_noop,
  193. };