parport_pc.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #ifndef __LINUX_PARPORT_PC_H
  2. #define __LINUX_PARPORT_PC_H
  3. #include <asm/io.h>
  4. /* --- register definitions ------------------------------- */
  5. #define ECONTROL(p) ((p)->base_hi + 0x2)
  6. #define CONFIGB(p) ((p)->base_hi + 0x1)
  7. #define CONFIGA(p) ((p)->base_hi + 0x0)
  8. #define FIFO(p) ((p)->base_hi + 0x0)
  9. #define EPPDATA(p) ((p)->base + 0x4)
  10. #define EPPADDR(p) ((p)->base + 0x3)
  11. #define CONTROL(p) ((p)->base + 0x2)
  12. #define STATUS(p) ((p)->base + 0x1)
  13. #define DATA(p) ((p)->base + 0x0)
  14. struct parport_pc_private {
  15. /* Contents of CTR. */
  16. unsigned char ctr;
  17. /* Bitmask of writable CTR bits. */
  18. unsigned char ctr_writable;
  19. /* Whether or not there's an ECR. */
  20. int ecr;
  21. /* Number of PWords that FIFO will hold. */
  22. int fifo_depth;
  23. /* Number of bytes per portword. */
  24. int pword;
  25. /* Not used yet. */
  26. int readIntrThreshold;
  27. int writeIntrThreshold;
  28. /* buffer suitable for DMA, if DMA enabled */
  29. char *dma_buf;
  30. dma_addr_t dma_handle;
  31. struct list_head list;
  32. struct parport *port;
  33. };
  34. struct parport_pc_via_data
  35. {
  36. /* ISA PnP IRQ routing register 1 */
  37. u8 via_pci_parport_irq_reg;
  38. /* ISA PnP DMA request routing register */
  39. u8 via_pci_parport_dma_reg;
  40. /* Register and value to enable SuperIO configuration access */
  41. u8 via_pci_superio_config_reg;
  42. u8 via_pci_superio_config_data;
  43. /* SuperIO function register number */
  44. u8 viacfg_function;
  45. /* parallel port control register number */
  46. u8 viacfg_parport_control;
  47. /* Parallel port base address register */
  48. u8 viacfg_parport_base;
  49. };
  50. static __inline__ void parport_pc_write_data(struct parport *p, unsigned char d)
  51. {
  52. #ifdef DEBUG_PARPORT
  53. printk (KERN_DEBUG "parport_pc_write_data(%p,0x%02x)\n", p, d);
  54. #endif
  55. outb(d, DATA(p));
  56. }
  57. static __inline__ unsigned char parport_pc_read_data(struct parport *p)
  58. {
  59. unsigned char val = inb (DATA (p));
  60. #ifdef DEBUG_PARPORT
  61. printk (KERN_DEBUG "parport_pc_read_data(%p) = 0x%02x\n",
  62. p, val);
  63. #endif
  64. return val;
  65. }
  66. #ifdef DEBUG_PARPORT
  67. static inline void dump_parport_state (char *str, struct parport *p)
  68. {
  69. /* here's hoping that reading these ports won't side-effect anything underneath */
  70. unsigned char ecr = inb (ECONTROL (p));
  71. unsigned char dcr = inb (CONTROL (p));
  72. unsigned char dsr = inb (STATUS (p));
  73. static const char *const ecr_modes[] = {"SPP", "PS2", "PPFIFO", "ECP", "xXx", "yYy", "TST", "CFG"};
  74. const struct parport_pc_private *priv = p->physport->private_data;
  75. int i;
  76. printk (KERN_DEBUG "*** parport state (%s): ecr=[%s", str, ecr_modes[(ecr & 0xe0) >> 5]);
  77. if (ecr & 0x10) printk (",nErrIntrEn");
  78. if (ecr & 0x08) printk (",dmaEn");
  79. if (ecr & 0x04) printk (",serviceIntr");
  80. if (ecr & 0x02) printk (",f_full");
  81. if (ecr & 0x01) printk (",f_empty");
  82. for (i=0; i<2; i++) {
  83. printk ("] dcr(%s)=[", i ? "soft" : "hard");
  84. dcr = i ? priv->ctr : inb (CONTROL (p));
  85. if (dcr & 0x20) {
  86. printk ("rev");
  87. } else {
  88. printk ("fwd");
  89. }
  90. if (dcr & 0x10) printk (",ackIntEn");
  91. if (!(dcr & 0x08)) printk (",N-SELECT-IN");
  92. if (dcr & 0x04) printk (",N-INIT");
  93. if (!(dcr & 0x02)) printk (",N-AUTOFD");
  94. if (!(dcr & 0x01)) printk (",N-STROBE");
  95. }
  96. printk ("] dsr=[");
  97. if (!(dsr & 0x80)) printk ("BUSY");
  98. if (dsr & 0x40) printk (",N-ACK");
  99. if (dsr & 0x20) printk (",PERROR");
  100. if (dsr & 0x10) printk (",SELECT");
  101. if (dsr & 0x08) printk (",N-FAULT");
  102. printk ("]\n");
  103. return;
  104. }
  105. #else /* !DEBUG_PARPORT */
  106. #define dump_parport_state(args...)
  107. #endif /* !DEBUG_PARPORT */
  108. /* __parport_pc_frob_control differs from parport_pc_frob_control in that
  109. * it doesn't do any extra masking. */
  110. static __inline__ unsigned char __parport_pc_frob_control (struct parport *p,
  111. unsigned char mask,
  112. unsigned char val)
  113. {
  114. struct parport_pc_private *priv = p->physport->private_data;
  115. unsigned char ctr = priv->ctr;
  116. #ifdef DEBUG_PARPORT
  117. printk (KERN_DEBUG
  118. "__parport_pc_frob_control(%02x,%02x): %02x -> %02x\n",
  119. mask, val, ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable);
  120. #endif
  121. ctr = (ctr & ~mask) ^ val;
  122. ctr &= priv->ctr_writable; /* only write writable bits. */
  123. outb (ctr, CONTROL (p));
  124. priv->ctr = ctr; /* Update soft copy */
  125. return ctr;
  126. }
  127. static __inline__ void parport_pc_data_reverse (struct parport *p)
  128. {
  129. __parport_pc_frob_control (p, 0x20, 0x20);
  130. }
  131. static __inline__ void parport_pc_data_forward (struct parport *p)
  132. {
  133. __parport_pc_frob_control (p, 0x20, 0x00);
  134. }
  135. static __inline__ void parport_pc_write_control (struct parport *p,
  136. unsigned char d)
  137. {
  138. const unsigned char wm = (PARPORT_CONTROL_STROBE |
  139. PARPORT_CONTROL_AUTOFD |
  140. PARPORT_CONTROL_INIT |
  141. PARPORT_CONTROL_SELECT);
  142. /* Take this out when drivers have adapted to newer interface. */
  143. if (d & 0x20) {
  144. printk (KERN_DEBUG "%s (%s): use data_reverse for this!\n",
  145. p->name, p->cad->name);
  146. parport_pc_data_reverse (p);
  147. }
  148. __parport_pc_frob_control (p, wm, d & wm);
  149. }
  150. static __inline__ unsigned char parport_pc_read_control(struct parport *p)
  151. {
  152. const unsigned char rm = (PARPORT_CONTROL_STROBE |
  153. PARPORT_CONTROL_AUTOFD |
  154. PARPORT_CONTROL_INIT |
  155. PARPORT_CONTROL_SELECT);
  156. const struct parport_pc_private *priv = p->physport->private_data;
  157. return priv->ctr & rm; /* Use soft copy */
  158. }
  159. static __inline__ unsigned char parport_pc_frob_control (struct parport *p,
  160. unsigned char mask,
  161. unsigned char val)
  162. {
  163. const unsigned char wm = (PARPORT_CONTROL_STROBE |
  164. PARPORT_CONTROL_AUTOFD |
  165. PARPORT_CONTROL_INIT |
  166. PARPORT_CONTROL_SELECT);
  167. /* Take this out when drivers have adapted to newer interface. */
  168. if (mask & 0x20) {
  169. printk (KERN_DEBUG "%s (%s): use data_%s for this!\n",
  170. p->name, p->cad->name,
  171. (val & 0x20) ? "reverse" : "forward");
  172. if (val & 0x20)
  173. parport_pc_data_reverse (p);
  174. else
  175. parport_pc_data_forward (p);
  176. }
  177. /* Restrict mask and val to control lines. */
  178. mask &= wm;
  179. val &= wm;
  180. return __parport_pc_frob_control (p, mask, val);
  181. }
  182. static __inline__ unsigned char parport_pc_read_status(struct parport *p)
  183. {
  184. return inb(STATUS(p));
  185. }
  186. static __inline__ void parport_pc_disable_irq(struct parport *p)
  187. {
  188. __parport_pc_frob_control (p, 0x10, 0x00);
  189. }
  190. static __inline__ void parport_pc_enable_irq(struct parport *p)
  191. {
  192. __parport_pc_frob_control (p, 0x10, 0x10);
  193. }
  194. extern void parport_pc_release_resources(struct parport *p);
  195. extern int parport_pc_claim_resources(struct parport *p);
  196. /* PCMCIA code will want to get us to look at a port. Provide a mechanism. */
  197. extern struct parport *parport_pc_probe_port(unsigned long base,
  198. unsigned long base_hi,
  199. int irq, int dma,
  200. struct device *dev,
  201. int irqflags);
  202. extern void parport_pc_unregister_port(struct parport *p);
  203. #endif