parport_pc.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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 pci_dev *dev;
  32. };
  33. extern __inline__ void parport_pc_write_data(struct parport *p, unsigned char d)
  34. {
  35. #ifdef DEBUG_PARPORT
  36. printk (KERN_DEBUG "parport_pc_write_data(%p,0x%02x)n", p, d);
  37. #endif
  38. outb(d, DATA(p));
  39. }
  40. extern __inline__ unsigned char parport_pc_read_data(struct parport *p)
  41. {
  42. unsigned char val = inb (DATA (p));
  43. #ifdef DEBUG_PARPORT
  44. printk (KERN_DEBUG "parport_pc_read_data(%p) = 0x%02xn",
  45. p, val);
  46. #endif
  47. return val;
  48. }
  49. #ifdef DEBUG_PARPORT
  50. extern __inline__ void dump_parport_state (char *str, struct parport *p)
  51. {
  52. /* here's hoping that reading these ports won't side-effect anything underneath */
  53. unsigned char ecr = inb (ECONTROL (p));
  54. unsigned char dcr = inb (CONTROL (p));
  55. unsigned char dsr = inb (STATUS (p));
  56. static char *ecr_modes[] = {"SPP", "PS2", "PPFIFO", "ECP", "xXx", "yYy", "TST", "CFG"};
  57. const struct parport_pc_private *priv = (parport_pc_private *)p->physport->private_data;
  58. int i;
  59. printk (KERN_DEBUG "*** parport state (%s): ecr=[%s", str, ecr_modes[(ecr & 0xe0) >> 5]);
  60. if (ecr & 0x10) printk (",nErrIntrEn");
  61. if (ecr & 0x08) printk (",dmaEn");
  62. if (ecr & 0x04) printk (",serviceIntr");
  63. if (ecr & 0x02) printk (",f_full");
  64. if (ecr & 0x01) printk (",f_empty");
  65. for (i=0; i<2; i++) {
  66. printk ("]  dcr(%s)=[", i ? "soft" : "hard");
  67. dcr = i ? priv->ctr : inb (CONTROL (p));
  68. if (dcr & 0x20) {
  69. printk ("rev");
  70. } else {
  71. printk ("fwd");
  72. }
  73. if (dcr & 0x10) printk (",ackIntEn");
  74. if (!(dcr & 0x08)) printk (",N-SELECT-IN");
  75. if (dcr & 0x04) printk (",N-INIT");
  76. if (!(dcr & 0x02)) printk (",N-AUTOFD");
  77. if (!(dcr & 0x01)) printk (",N-STROBE");
  78. }
  79. printk ("]  dsr=[");
  80. if (!(dsr & 0x80)) printk ("BUSY");
  81. if (dsr & 0x40) printk (",N-ACK");
  82. if (dsr & 0x20) printk (",PERROR");
  83. if (dsr & 0x10) printk (",SELECT");
  84. if (dsr & 0x08) printk (",N-FAULT");
  85. printk ("]n");
  86. return;
  87. }
  88. #else /* !DEBUG_PARPORT */
  89. #define dump_parport_state(args...)
  90. #endif /* !DEBUG_PARPORT */
  91. /* __parport_pc_frob_control differs from parport_pc_frob_control in that
  92.  * it doesn't do any extra masking. */
  93. static __inline__ unsigned char __parport_pc_frob_control (struct parport *p,
  94.    unsigned char mask,
  95.    unsigned char val)
  96. {
  97. struct parport_pc_private *priv = p->physport->private_data;
  98. unsigned char ctr = priv->ctr;
  99. #ifdef DEBUG_PARPORT
  100. printk (KERN_DEBUG
  101. "__parport_pc_frob_control(%02x,%02x): %02x -> %02xn",
  102. mask, val, ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable);
  103. #endif
  104. ctr = (ctr & ~mask) ^ val;
  105. ctr &= priv->ctr_writable; /* only write writable bits. */
  106. outb (ctr, CONTROL (p));
  107. priv->ctr = ctr; /* Update soft copy */
  108. return ctr;
  109. }
  110. extern __inline__ void parport_pc_data_reverse (struct parport *p)
  111. {
  112. __parport_pc_frob_control (p, 0x20, 0x20);
  113. }
  114. extern __inline__ void parport_pc_data_forward (struct parport *p)
  115. {
  116. __parport_pc_frob_control (p, 0x20, 0x00);
  117. }
  118. extern __inline__ void parport_pc_write_control (struct parport *p,
  119.  unsigned char d)
  120. {
  121. const unsigned char wm = (PARPORT_CONTROL_STROBE |
  122.   PARPORT_CONTROL_AUTOFD |
  123.   PARPORT_CONTROL_INIT |
  124.   PARPORT_CONTROL_SELECT);
  125. /* Take this out when drivers have adapted to newer interface. */
  126. if (d & 0x20) {
  127. printk (KERN_DEBUG "%s (%s): use data_reverse for this!n",
  128. p->name, p->cad->name);
  129. parport_pc_data_reverse (p);
  130. }
  131. __parport_pc_frob_control (p, wm, d & wm);
  132. }
  133. extern __inline__ unsigned char parport_pc_read_control(struct parport *p)
  134. {
  135. const unsigned char rm = (PARPORT_CONTROL_STROBE |
  136.   PARPORT_CONTROL_AUTOFD |
  137.   PARPORT_CONTROL_INIT |
  138.   PARPORT_CONTROL_SELECT);
  139. const struct parport_pc_private *priv = p->physport->private_data;
  140. return priv->ctr & rm; /* Use soft copy */
  141. }
  142. extern __inline__ unsigned char parport_pc_frob_control (struct parport *p,
  143.  unsigned char mask,
  144.  unsigned char val)
  145. {
  146. const unsigned char wm = (PARPORT_CONTROL_STROBE |
  147.   PARPORT_CONTROL_AUTOFD |
  148.   PARPORT_CONTROL_INIT |
  149.   PARPORT_CONTROL_SELECT);
  150. /* Take this out when drivers have adapted to newer interface. */
  151. if (mask & 0x20) {
  152. printk (KERN_DEBUG "%s (%s): use data_%s for this!n",
  153. p->name, p->cad->name,
  154. (val & 0x20) ? "reverse" : "forward");
  155. if (val & 0x20)
  156. parport_pc_data_reverse (p);
  157. else
  158. parport_pc_data_forward (p);
  159. }
  160. /* Restrict mask and val to control lines. */
  161. mask &= wm;
  162. val &= wm;
  163. return __parport_pc_frob_control (p, mask, val);
  164. }
  165. extern __inline__ unsigned char parport_pc_read_status(struct parport *p)
  166. {
  167. return inb(STATUS(p));
  168. }
  169. extern __inline__ void parport_pc_disable_irq(struct parport *p)
  170. {
  171. __parport_pc_frob_control (p, 0x10, 0x00);
  172. }
  173. extern __inline__ void parport_pc_enable_irq(struct parport *p)
  174. {
  175. __parport_pc_frob_control (p, 0x10, 0x10);
  176. }
  177. extern void parport_pc_release_resources(struct parport *p);
  178. extern int parport_pc_claim_resources(struct parport *p);
  179. extern void parport_pc_init_state(struct pardevice *, struct parport_state *s);
  180. extern void parport_pc_save_state(struct parport *p, struct parport_state *s);
  181. extern void parport_pc_restore_state(struct parport *p, struct parport_state *s);
  182. extern void parport_pc_inc_use_count(void);
  183. extern void parport_pc_dec_use_count(void);
  184. /* PCMCIA code will want to get us to look at a port.  Provide a mechanism. */
  185. extern struct parport *parport_pc_probe_port (unsigned long base,
  186.       unsigned long base_hi,
  187.       int irq, int dma,
  188.       struct pci_dev *dev);
  189. extern void parport_pc_unregister_port (struct parport *p);
  190. #endif