parport_gsc.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. struct pci_dev *dev;
  55. };
  56. static inline void parport_gsc_write_data(struct parport *p, unsigned char d)
  57. {
  58. #ifdef DEBUG_PARPORT
  59. printk(KERN_DEBUG "%s(%p,0x%02x)\n", __func__, p, d);
  60. #endif
  61. parport_writeb(d, DATA(p));
  62. }
  63. static inline unsigned char parport_gsc_read_data(struct parport *p)
  64. {
  65. unsigned char val = parport_readb (DATA (p));
  66. #ifdef DEBUG_PARPORT
  67. printk(KERN_DEBUG "%s(%p) = 0x%02x\n", __func__, p, val);
  68. #endif
  69. return val;
  70. }
  71. /* __parport_gsc_frob_control differs from parport_gsc_frob_control in that
  72. * it doesn't do any extra masking. */
  73. static inline unsigned char __parport_gsc_frob_control(struct parport *p,
  74. unsigned char mask,
  75. unsigned char val)
  76. {
  77. struct parport_gsc_private *priv = p->physport->private_data;
  78. unsigned char ctr = priv->ctr;
  79. #ifdef DEBUG_PARPORT
  80. printk(KERN_DEBUG "%s(%02x,%02x): %02x -> %02x\n",
  81. __func__, mask, val,
  82. ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable);
  83. #endif
  84. ctr = (ctr & ~mask) ^ val;
  85. ctr &= priv->ctr_writable; /* only write writable bits. */
  86. parport_writeb (ctr, CONTROL (p));
  87. priv->ctr = ctr; /* Update soft copy */
  88. return ctr;
  89. }
  90. static inline void parport_gsc_data_reverse(struct parport *p)
  91. {
  92. __parport_gsc_frob_control (p, 0x20, 0x20);
  93. }
  94. static inline void parport_gsc_data_forward(struct parport *p)
  95. {
  96. __parport_gsc_frob_control (p, 0x20, 0x00);
  97. }
  98. static inline void parport_gsc_write_control(struct parport *p,
  99. unsigned char d)
  100. {
  101. const unsigned char wm = (PARPORT_CONTROL_STROBE |
  102. PARPORT_CONTROL_AUTOFD |
  103. PARPORT_CONTROL_INIT |
  104. PARPORT_CONTROL_SELECT);
  105. /* Take this out when drivers have adapted to newer interface. */
  106. if (d & 0x20) {
  107. printk(KERN_DEBUG "%s (%s): use data_reverse for this!\n",
  108. p->name, p->cad->name);
  109. parport_gsc_data_reverse (p);
  110. }
  111. __parport_gsc_frob_control (p, wm, d & wm);
  112. }
  113. static inline unsigned char parport_gsc_read_control(struct parport *p)
  114. {
  115. const unsigned char rm = (PARPORT_CONTROL_STROBE |
  116. PARPORT_CONTROL_AUTOFD |
  117. PARPORT_CONTROL_INIT |
  118. PARPORT_CONTROL_SELECT);
  119. const struct parport_gsc_private *priv = p->physport->private_data;
  120. return priv->ctr & rm; /* Use soft copy */
  121. }
  122. static inline unsigned char parport_gsc_frob_control(struct parport *p,
  123. unsigned char mask,
  124. unsigned char val)
  125. {
  126. const unsigned char wm = (PARPORT_CONTROL_STROBE |
  127. PARPORT_CONTROL_AUTOFD |
  128. PARPORT_CONTROL_INIT |
  129. PARPORT_CONTROL_SELECT);
  130. /* Take this out when drivers have adapted to newer interface. */
  131. if (mask & 0x20) {
  132. printk(KERN_DEBUG "%s (%s): use data_%s for this!\n",
  133. p->name, p->cad->name,
  134. (val & 0x20) ? "reverse" : "forward");
  135. if (val & 0x20)
  136. parport_gsc_data_reverse (p);
  137. else
  138. parport_gsc_data_forward (p);
  139. }
  140. /* Restrict mask and val to control lines. */
  141. mask &= wm;
  142. val &= wm;
  143. return __parport_gsc_frob_control (p, mask, val);
  144. }
  145. static inline unsigned char parport_gsc_read_status(struct parport *p)
  146. {
  147. return parport_readb (STATUS(p));
  148. }
  149. static inline void parport_gsc_disable_irq(struct parport *p)
  150. {
  151. __parport_gsc_frob_control (p, 0x10, 0x00);
  152. }
  153. static inline void parport_gsc_enable_irq(struct parport *p)
  154. {
  155. __parport_gsc_frob_control (p, 0x10, 0x10);
  156. }
  157. extern void parport_gsc_release_resources(struct parport *p);
  158. extern int parport_gsc_claim_resources(struct parport *p);
  159. extern void parport_gsc_init_state(struct pardevice *, struct parport_state *s);
  160. extern void parport_gsc_save_state(struct parport *p, struct parport_state *s);
  161. extern void parport_gsc_restore_state(struct parport *p, struct parport_state *s);
  162. extern void parport_gsc_inc_use_count(void);
  163. extern void parport_gsc_dec_use_count(void);
  164. #endif /* __DRIVERS_PARPORT_PARPORT_GSC_H */