parport_gsc.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Low-level parallel-support for PC-style hardware integrated in the
  4. * LASI-Controller (on GSC-Bus) for HP-PARISC Workstations
  5. *
  6. * (C) 1999-2001 by Helge Deller <deller@gmx.de>
  7. *
  8. * based on parport_pc.c by
  9. * Grant Guenther <grant@torque.net>
  10. * Phil Blundell <Philip.Blundell@pobox.com>
  11. * Tim Waugh <tim@cyberelk.demon.co.uk>
  12. * Jose Renau <renau@acm.org>
  13. * David Campbell
  14. * Andrea Arcangeli
  15. */
  16. #ifndef __DRIVERS_PARPORT_PARPORT_GSC_H
  17. #define __DRIVERS_PARPORT_PARPORT_GSC_H
  18. #include <asm/io.h>
  19. #include <linux/delay.h>
  20. #undef DEBUG_PARPORT /* undefine for production */
  21. #define DELAY_TIME 0
  22. #if DELAY_TIME == 0
  23. #define parport_readb gsc_readb
  24. #define parport_writeb gsc_writeb
  25. #else
  26. static __inline__ unsigned char parport_readb( unsigned long port )
  27. {
  28. udelay(DELAY_TIME);
  29. return gsc_readb(port);
  30. }
  31. static __inline__ void parport_writeb( unsigned char value, unsigned long port )
  32. {
  33. gsc_writeb(value,port);
  34. udelay(DELAY_TIME);
  35. }
  36. #endif
  37. /* --- register definitions ------------------------------- */
  38. #define EPPDATA(p) ((p)->base + 0x4)
  39. #define EPPADDR(p) ((p)->base + 0x3)
  40. #define CONTROL(p) ((p)->base + 0x2)
  41. #define STATUS(p) ((p)->base + 0x1)
  42. #define DATA(p) ((p)->base + 0x0)
  43. struct parport_gsc_private {
  44. /* Contents of CTR. */
  45. unsigned char ctr;
  46. /* Bitmask of writable CTR bits. */
  47. unsigned char ctr_writable;
  48. /* Number of bytes per portword. */
  49. int pword;
  50. /* Not used yet. */
  51. int readIntrThreshold;
  52. int writeIntrThreshold;
  53. /* buffer suitable for DMA, if DMA enabled */
  54. char *dma_buf;
  55. dma_addr_t dma_handle;
  56. struct pci_dev *dev;
  57. };
  58. static inline void parport_gsc_write_data(struct parport *p, unsigned char d)
  59. {
  60. #ifdef DEBUG_PARPORT
  61. printk (KERN_DEBUG "parport_gsc_write_data(%p,0x%02x)\n", p, d);
  62. #endif
  63. parport_writeb(d, DATA(p));
  64. }
  65. static inline unsigned char parport_gsc_read_data(struct parport *p)
  66. {
  67. unsigned char val = parport_readb (DATA (p));
  68. #ifdef DEBUG_PARPORT
  69. printk (KERN_DEBUG "parport_gsc_read_data(%p) = 0x%02x\n",
  70. p, val);
  71. #endif
  72. return val;
  73. }
  74. /* __parport_gsc_frob_control differs from parport_gsc_frob_control in that
  75. * it doesn't do any extra masking. */
  76. static inline unsigned char __parport_gsc_frob_control(struct parport *p,
  77. unsigned char mask,
  78. unsigned char val)
  79. {
  80. struct parport_gsc_private *priv = p->physport->private_data;
  81. unsigned char ctr = priv->ctr;
  82. #ifdef DEBUG_PARPORT
  83. printk (KERN_DEBUG
  84. "__parport_gsc_frob_control(%02x,%02x): %02x -> %02x\n",
  85. mask, val, ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable);
  86. #endif
  87. ctr = (ctr & ~mask) ^ val;
  88. ctr &= priv->ctr_writable; /* only write writable bits. */
  89. parport_writeb (ctr, CONTROL (p));
  90. priv->ctr = ctr; /* Update soft copy */
  91. return ctr;
  92. }
  93. static inline void parport_gsc_data_reverse(struct parport *p)
  94. {
  95. __parport_gsc_frob_control (p, 0x20, 0x20);
  96. }
  97. static inline void parport_gsc_data_forward(struct parport *p)
  98. {
  99. __parport_gsc_frob_control (p, 0x20, 0x00);
  100. }
  101. static inline void parport_gsc_write_control(struct parport *p,
  102. unsigned char d)
  103. {
  104. const unsigned char wm = (PARPORT_CONTROL_STROBE |
  105. PARPORT_CONTROL_AUTOFD |
  106. PARPORT_CONTROL_INIT |
  107. PARPORT_CONTROL_SELECT);
  108. /* Take this out when drivers have adapted to newer interface. */
  109. if (d & 0x20) {
  110. printk (KERN_DEBUG "%s (%s): use data_reverse for this!\n",
  111. p->name, p->cad->name);
  112. parport_gsc_data_reverse (p);
  113. }
  114. __parport_gsc_frob_control (p, wm, d & wm);
  115. }
  116. static inline unsigned char parport_gsc_read_control(struct parport *p)
  117. {
  118. const unsigned char rm = (PARPORT_CONTROL_STROBE |
  119. PARPORT_CONTROL_AUTOFD |
  120. PARPORT_CONTROL_INIT |
  121. PARPORT_CONTROL_SELECT);
  122. const struct parport_gsc_private *priv = p->physport->private_data;
  123. return priv->ctr & rm; /* Use soft copy */
  124. }
  125. static inline unsigned char parport_gsc_frob_control(struct parport *p,
  126. unsigned char mask,
  127. unsigned char val)
  128. {
  129. const unsigned char wm = (PARPORT_CONTROL_STROBE |
  130. PARPORT_CONTROL_AUTOFD |
  131. PARPORT_CONTROL_INIT |
  132. PARPORT_CONTROL_SELECT);
  133. /* Take this out when drivers have adapted to newer interface. */
  134. if (mask & 0x20) {
  135. printk (KERN_DEBUG "%s (%s): use data_%s for this!\n",
  136. p->name, p->cad->name,
  137. (val & 0x20) ? "reverse" : "forward");
  138. if (val & 0x20)
  139. parport_gsc_data_reverse (p);
  140. else
  141. parport_gsc_data_forward (p);
  142. }
  143. /* Restrict mask and val to control lines. */
  144. mask &= wm;
  145. val &= wm;
  146. return __parport_gsc_frob_control (p, mask, val);
  147. }
  148. static inline unsigned char parport_gsc_read_status(struct parport *p)
  149. {
  150. return parport_readb (STATUS(p));
  151. }
  152. static inline void parport_gsc_disable_irq(struct parport *p)
  153. {
  154. __parport_gsc_frob_control (p, 0x10, 0x00);
  155. }
  156. static inline void parport_gsc_enable_irq(struct parport *p)
  157. {
  158. __parport_gsc_frob_control (p, 0x10, 0x10);
  159. }
  160. extern void parport_gsc_release_resources(struct parport *p);
  161. extern int parport_gsc_claim_resources(struct parport *p);
  162. extern void parport_gsc_init_state(struct pardevice *, struct parport_state *s);
  163. extern void parport_gsc_save_state(struct parport *p, struct parport_state *s);
  164. extern void parport_gsc_restore_state(struct parport *p, struct parport_state *s);
  165. extern void parport_gsc_inc_use_count(void);
  166. extern void parport_gsc_dec_use_count(void);
  167. extern struct parport *parport_gsc_probe_port(unsigned long base,
  168. unsigned long base_hi,
  169. int irq, int dma,
  170. struct parisc_device *padev);
  171. #endif /* __DRIVERS_PARPORT_PARPORT_GSC_H */