initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / linux / parport_pc.h
blob2b5ad1bf19a275342cdb622207f697f7a30e54fc
1 #ifndef __LINUX_PARPORT_PC_H
2 #define __LINUX_PARPORT_PC_H
4 #include <asm/io.h>
6 /* --- register definitions ------------------------------- */
8 #define ECONTROL(p) ((p)->base_hi + 0x2)
9 #define CONFIGB(p) ((p)->base_hi + 0x1)
10 #define CONFIGA(p) ((p)->base_hi + 0x0)
11 #define FIFO(p) ((p)->base_hi + 0x0)
12 #define EPPDATA(p) ((p)->base + 0x4)
13 #define EPPADDR(p) ((p)->base + 0x3)
14 #define CONTROL(p) ((p)->base + 0x2)
15 #define STATUS(p) ((p)->base + 0x1)
16 #define DATA(p) ((p)->base + 0x0)
18 struct parport_pc_private {
19 /* Contents of CTR. */
20 unsigned char ctr;
22 /* Bitmask of writable CTR bits. */
23 unsigned char ctr_writable;
25 /* Whether or not there's an ECR. */
26 int ecr;
28 /* Number of PWords that FIFO will hold. */
29 int fifo_depth;
31 /* Number of bytes per portword. */
32 int pword;
34 /* Not used yet. */
35 int readIntrThreshold;
36 int writeIntrThreshold;
38 /* buffer suitable for DMA, if DMA enabled */
39 char *dma_buf;
40 dma_addr_t dma_handle;
41 struct pci_dev *dev;
42 struct list_head list;
43 struct parport *port;
46 static __inline__ void parport_pc_write_data(struct parport *p, unsigned char d)
48 #ifdef DEBUG_PARPORT
49 printk (KERN_DEBUG "parport_pc_write_data(%p,0x%02x)\n", p, d);
50 #endif
51 outb(d, DATA(p));
54 static __inline__ unsigned char parport_pc_read_data(struct parport *p)
56 unsigned char val = inb (DATA (p));
57 #ifdef DEBUG_PARPORT
58 printk (KERN_DEBUG "parport_pc_read_data(%p) = 0x%02x\n",
59 p, val);
60 #endif
61 return val;
64 #ifdef DEBUG_PARPORT
65 extern __inline__ void dump_parport_state (char *str, struct parport *p)
67 /* here's hoping that reading these ports won't side-effect anything underneath */
68 unsigned char ecr = inb (ECONTROL (p));
69 unsigned char dcr = inb (CONTROL (p));
70 unsigned char dsr = inb (STATUS (p));
71 static char *ecr_modes[] = {"SPP", "PS2", "PPFIFO", "ECP", "xXx", "yYy", "TST", "CFG"};
72 const struct parport_pc_private *priv = (parport_pc_private *)p->physport->private_data;
73 int i;
75 printk (KERN_DEBUG "*** parport state (%s): ecr=[%s", str, ecr_modes[(ecr & 0xe0) >> 5]);
76 if (ecr & 0x10) printk (",nErrIntrEn");
77 if (ecr & 0x08) printk (",dmaEn");
78 if (ecr & 0x04) printk (",serviceIntr");
79 if (ecr & 0x02) printk (",f_full");
80 if (ecr & 0x01) printk (",f_empty");
81 for (i=0; i<2; i++) {
82 printk ("] dcr(%s)=[", i ? "soft" : "hard");
83 dcr = i ? priv->ctr : inb (CONTROL (p));
85 if (dcr & 0x20) {
86 printk ("rev");
87 } else {
88 printk ("fwd");
90 if (dcr & 0x10) printk (",ackIntEn");
91 if (!(dcr & 0x08)) printk (",N-SELECT-IN");
92 if (dcr & 0x04) printk (",N-INIT");
93 if (!(dcr & 0x02)) printk (",N-AUTOFD");
94 if (!(dcr & 0x01)) printk (",N-STROBE");
96 printk ("] dsr=[");
97 if (!(dsr & 0x80)) printk ("BUSY");
98 if (dsr & 0x40) printk (",N-ACK");
99 if (dsr & 0x20) printk (",PERROR");
100 if (dsr & 0x10) printk (",SELECT");
101 if (dsr & 0x08) printk (",N-FAULT");
102 printk ("]\n");
103 return;
105 #else /* !DEBUG_PARPORT */
106 #define dump_parport_state(args...)
107 #endif /* !DEBUG_PARPORT */
109 /* __parport_pc_frob_control differs from parport_pc_frob_control in that
110 * it doesn't do any extra masking. */
111 static __inline__ unsigned char __parport_pc_frob_control (struct parport *p,
112 unsigned char mask,
113 unsigned char val)
115 struct parport_pc_private *priv = p->physport->private_data;
116 unsigned char ctr = priv->ctr;
117 #ifdef DEBUG_PARPORT
118 printk (KERN_DEBUG
119 "__parport_pc_frob_control(%02x,%02x): %02x -> %02x\n",
120 mask, val, ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable);
121 #endif
122 ctr = (ctr & ~mask) ^ val;
123 ctr &= priv->ctr_writable; /* only write writable bits. */
124 outb (ctr, CONTROL (p));
125 priv->ctr = ctr; /* Update soft copy */
126 return ctr;
129 static __inline__ void parport_pc_data_reverse (struct parport *p)
131 __parport_pc_frob_control (p, 0x20, 0x20);
134 static __inline__ void parport_pc_data_forward (struct parport *p)
136 __parport_pc_frob_control (p, 0x20, 0x00);
139 static __inline__ void parport_pc_write_control (struct parport *p,
140 unsigned char d)
142 const unsigned char wm = (PARPORT_CONTROL_STROBE |
143 PARPORT_CONTROL_AUTOFD |
144 PARPORT_CONTROL_INIT |
145 PARPORT_CONTROL_SELECT);
147 /* Take this out when drivers have adapted to newer interface. */
148 if (d & 0x20) {
149 printk (KERN_DEBUG "%s (%s): use data_reverse for this!\n",
150 p->name, p->cad->name);
151 parport_pc_data_reverse (p);
154 __parport_pc_frob_control (p, wm, d & wm);
157 static __inline__ unsigned char parport_pc_read_control(struct parport *p)
159 const unsigned char rm = (PARPORT_CONTROL_STROBE |
160 PARPORT_CONTROL_AUTOFD |
161 PARPORT_CONTROL_INIT |
162 PARPORT_CONTROL_SELECT);
163 const struct parport_pc_private *priv = p->physport->private_data;
164 return priv->ctr & rm; /* Use soft copy */
167 static __inline__ unsigned char parport_pc_frob_control (struct parport *p,
168 unsigned char mask,
169 unsigned char val)
171 const unsigned char wm = (PARPORT_CONTROL_STROBE |
172 PARPORT_CONTROL_AUTOFD |
173 PARPORT_CONTROL_INIT |
174 PARPORT_CONTROL_SELECT);
176 /* Take this out when drivers have adapted to newer interface. */
177 if (mask & 0x20) {
178 printk (KERN_DEBUG "%s (%s): use data_%s for this!\n",
179 p->name, p->cad->name,
180 (val & 0x20) ? "reverse" : "forward");
181 if (val & 0x20)
182 parport_pc_data_reverse (p);
183 else
184 parport_pc_data_forward (p);
187 /* Restrict mask and val to control lines. */
188 mask &= wm;
189 val &= wm;
191 return __parport_pc_frob_control (p, mask, val);
194 static __inline__ unsigned char parport_pc_read_status(struct parport *p)
196 return inb(STATUS(p));
200 static __inline__ void parport_pc_disable_irq(struct parport *p)
202 __parport_pc_frob_control (p, 0x10, 0x00);
205 static __inline__ void parport_pc_enable_irq(struct parport *p)
207 __parport_pc_frob_control (p, 0x10, 0x10);
210 extern void parport_pc_release_resources(struct parport *p);
212 extern int parport_pc_claim_resources(struct parport *p);
214 extern void parport_pc_init_state(struct pardevice *, struct parport_state *s);
216 extern void parport_pc_save_state(struct parport *p, struct parport_state *s);
218 extern void parport_pc_restore_state(struct parport *p, struct parport_state *s);
220 /* PCMCIA code will want to get us to look at a port. Provide a mechanism. */
221 extern struct parport *parport_pc_probe_port (unsigned long base,
222 unsigned long base_hi,
223 int irq, int dma,
224 struct pci_dev *dev);
225 extern void parport_pc_unregister_port (struct parport *p);
227 #endif