parport_gsc.h 6.1 KB

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