parport_pc.h 6.6 KB

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