• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __LINUX_PARPORT_PC_H
2 #define __LINUX_PARPORT_PC_H
3 
4 #include <asm/io.h>
5 
6 /* --- register definitions ------------------------------- */
7 
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)
17 
18 struct parport_pc_private {
19 	/* Contents of CTR. */
20 	unsigned char ctr;
21 
22 	/* Bitmask of writable CTR bits. */
23 	unsigned char ctr_writable;
24 
25 	/* Whether or not there's an ECR. */
26 	int ecr;
27 
28 	/* Number of PWords that FIFO will hold. */
29 	int fifo_depth;
30 
31 	/* Number of bytes per portword. */
32 	int pword;
33 
34 	/* Not used yet. */
35 	int readIntrThreshold;
36 	int writeIntrThreshold;
37 
38 	/* buffer suitable for DMA, if DMA enabled */
39 	char *dma_buf;
40 	dma_addr_t dma_handle;
41 	struct list_head list;
42 	struct parport *port;
43 };
44 
45 struct parport_pc_via_data
46 {
47 	/* ISA PnP IRQ routing register 1 */
48 	u8 via_pci_parport_irq_reg;
49 	/* ISA PnP DMA request routing register */
50 	u8 via_pci_parport_dma_reg;
51 	/* Register and value to enable SuperIO configuration access */
52 	u8 via_pci_superio_config_reg;
53 	u8 via_pci_superio_config_data;
54 	/* SuperIO function register number */
55 	u8 viacfg_function;
56 	/* parallel port control register number */
57 	u8 viacfg_parport_control;
58 	/* Parallel port base address register */
59 	u8 viacfg_parport_base;
60 };
61 
parport_pc_write_data(struct parport * p,unsigned char d)62 static __inline__ void parport_pc_write_data(struct parport *p, unsigned char d)
63 {
64 #ifdef DEBUG_PARPORT
65 	printk (KERN_DEBUG "parport_pc_write_data(%p,0x%02x)\n", p, d);
66 #endif
67 	outb(d, DATA(p));
68 }
69 
parport_pc_read_data(struct parport * p)70 static __inline__ unsigned char parport_pc_read_data(struct parport *p)
71 {
72 	unsigned char val = inb (DATA (p));
73 #ifdef DEBUG_PARPORT
74 	printk (KERN_DEBUG "parport_pc_read_data(%p) = 0x%02x\n",
75 		p, val);
76 #endif
77 	return val;
78 }
79 
80 #ifdef DEBUG_PARPORT
dump_parport_state(char * str,struct parport * p)81 static inline void dump_parport_state (char *str, struct parport *p)
82 {
83 	/* here's hoping that reading these ports won't side-effect anything underneath */
84 	unsigned char ecr = inb (ECONTROL (p));
85 	unsigned char dcr = inb (CONTROL (p));
86 	unsigned char dsr = inb (STATUS (p));
87 	static const char *const ecr_modes[] = {"SPP", "PS2", "PPFIFO", "ECP", "xXx", "yYy", "TST", "CFG"};
88 	const struct parport_pc_private *priv = p->physport->private_data;
89 	int i;
90 
91 	printk (KERN_DEBUG "*** parport state (%s): ecr=[%s", str, ecr_modes[(ecr & 0xe0) >> 5]);
92 	if (ecr & 0x10) printk (",nErrIntrEn");
93 	if (ecr & 0x08) printk (",dmaEn");
94 	if (ecr & 0x04) printk (",serviceIntr");
95 	if (ecr & 0x02) printk (",f_full");
96 	if (ecr & 0x01) printk (",f_empty");
97 	for (i=0; i<2; i++) {
98 		printk ("]  dcr(%s)=[", i ? "soft" : "hard");
99 		dcr = i ? priv->ctr : inb (CONTROL (p));
100 
101 		if (dcr & 0x20) {
102 			printk ("rev");
103 		} else {
104 			printk ("fwd");
105 		}
106 		if (dcr & 0x10) printk (",ackIntEn");
107 		if (!(dcr & 0x08)) printk (",N-SELECT-IN");
108 		if (dcr & 0x04) printk (",N-INIT");
109 		if (!(dcr & 0x02)) printk (",N-AUTOFD");
110 		if (!(dcr & 0x01)) printk (",N-STROBE");
111 	}
112 	printk ("]  dsr=[");
113 	if (!(dsr & 0x80)) printk ("BUSY");
114 	if (dsr & 0x40) printk (",N-ACK");
115 	if (dsr & 0x20) printk (",PERROR");
116 	if (dsr & 0x10) printk (",SELECT");
117 	if (dsr & 0x08) printk (",N-FAULT");
118 	printk ("]\n");
119 	return;
120 }
121 #else	/* !DEBUG_PARPORT */
122 #define dump_parport_state(args...)
123 #endif	/* !DEBUG_PARPORT */
124 
125 /* __parport_pc_frob_control differs from parport_pc_frob_control in that
126  * it doesn't do any extra masking. */
__parport_pc_frob_control(struct parport * p,unsigned char mask,unsigned char val)127 static __inline__ unsigned char __parport_pc_frob_control (struct parport *p,
128 							   unsigned char mask,
129 							   unsigned char val)
130 {
131 	struct parport_pc_private *priv = p->physport->private_data;
132 	unsigned char ctr = priv->ctr;
133 #ifdef DEBUG_PARPORT
134 	printk (KERN_DEBUG
135 		"__parport_pc_frob_control(%02x,%02x): %02x -> %02x\n",
136 		mask, val, ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable);
137 #endif
138 	ctr = (ctr & ~mask) ^ val;
139 	ctr &= priv->ctr_writable; /* only write writable bits. */
140 	outb (ctr, CONTROL (p));
141 	priv->ctr = ctr;	/* Update soft copy */
142 	return ctr;
143 }
144 
parport_pc_data_reverse(struct parport * p)145 static __inline__ void parport_pc_data_reverse (struct parport *p)
146 {
147 	__parport_pc_frob_control (p, 0x20, 0x20);
148 }
149 
parport_pc_data_forward(struct parport * p)150 static __inline__ void parport_pc_data_forward (struct parport *p)
151 {
152 	__parport_pc_frob_control (p, 0x20, 0x00);
153 }
154 
parport_pc_write_control(struct parport * p,unsigned char d)155 static __inline__ void parport_pc_write_control (struct parport *p,
156 						 unsigned char d)
157 {
158 	const unsigned char wm = (PARPORT_CONTROL_STROBE |
159 				  PARPORT_CONTROL_AUTOFD |
160 				  PARPORT_CONTROL_INIT |
161 				  PARPORT_CONTROL_SELECT);
162 
163 	/* Take this out when drivers have adapted to newer interface. */
164 	if (d & 0x20) {
165 		printk (KERN_DEBUG "%s (%s): use data_reverse for this!\n",
166 			p->name, p->cad->name);
167 		parport_pc_data_reverse (p);
168 	}
169 
170 	__parport_pc_frob_control (p, wm, d & wm);
171 }
172 
parport_pc_read_control(struct parport * p)173 static __inline__ unsigned char parport_pc_read_control(struct parport *p)
174 {
175 	const unsigned char rm = (PARPORT_CONTROL_STROBE |
176 				  PARPORT_CONTROL_AUTOFD |
177 				  PARPORT_CONTROL_INIT |
178 				  PARPORT_CONTROL_SELECT);
179 	const struct parport_pc_private *priv = p->physport->private_data;
180 	return priv->ctr & rm; /* Use soft copy */
181 }
182 
parport_pc_frob_control(struct parport * p,unsigned char mask,unsigned char val)183 static __inline__ unsigned char parport_pc_frob_control (struct parport *p,
184 							 unsigned char mask,
185 							 unsigned char val)
186 {
187 	const unsigned char wm = (PARPORT_CONTROL_STROBE |
188 				  PARPORT_CONTROL_AUTOFD |
189 				  PARPORT_CONTROL_INIT |
190 				  PARPORT_CONTROL_SELECT);
191 
192 	/* Take this out when drivers have adapted to newer interface. */
193 	if (mask & 0x20) {
194 		printk (KERN_DEBUG "%s (%s): use data_%s for this!\n",
195 			p->name, p->cad->name,
196 			(val & 0x20) ? "reverse" : "forward");
197 		if (val & 0x20)
198 			parport_pc_data_reverse (p);
199 		else
200 			parport_pc_data_forward (p);
201 	}
202 
203 	/* Restrict mask and val to control lines. */
204 	mask &= wm;
205 	val &= wm;
206 
207 	return __parport_pc_frob_control (p, mask, val);
208 }
209 
parport_pc_read_status(struct parport * p)210 static __inline__ unsigned char parport_pc_read_status(struct parport *p)
211 {
212 	return inb(STATUS(p));
213 }
214 
215 
parport_pc_disable_irq(struct parport * p)216 static __inline__ void parport_pc_disable_irq(struct parport *p)
217 {
218 	__parport_pc_frob_control (p, 0x10, 0x00);
219 }
220 
parport_pc_enable_irq(struct parport * p)221 static __inline__ void parport_pc_enable_irq(struct parport *p)
222 {
223 	__parport_pc_frob_control (p, 0x10, 0x10);
224 }
225 
226 extern void parport_pc_release_resources(struct parport *p);
227 
228 extern int parport_pc_claim_resources(struct parport *p);
229 
230 /* PCMCIA code will want to get us to look at a port.  Provide a mechanism. */
231 extern struct parport *parport_pc_probe_port(unsigned long base,
232 					     unsigned long base_hi,
233 					     int irq, int dma,
234 					     struct device *dev,
235 					     int irqflags);
236 extern void parport_pc_unregister_port(struct parport *p);
237 
238 #endif
239