parport_gsc.h 5.4 KB

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