xref: /freebsd/sys/dev/ppbus/ppbconf.h (revision a8445737e740901f5f2c8d24c12ef7fc8b00134e)
1 /*-
2  * Copyright (c) 1997, 1998 Nicolas Souchu
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  *	$Id: ppbconf.h,v 1.7 1998/08/03 19:14:31 msmith Exp $
27  *
28  */
29 #ifndef __PPBCONF_H
30 #define __PPBCONF_H
31 
32 #include <sys/queue.h>
33 
34 /*
35  * Parallel Port Bus sleep/wakeup queue.
36  */
37 #define PPBPRI	PZERO+8
38 
39 /*
40  * Parallel Port Chipset mode masks.
41  * NIBBLE mode is supposed to be available under each other modes.
42  */
43 #define PPB_COMPATIBLE	0x0	/* Centronics compatible mode */
44 
45 #define PPB_NIBBLE	0x1	/* reverse 4 bit mode */
46 #define PPB_PS2		0x2	/* PS/2 byte mode */
47 #define PPB_EPP		0x4	/* EPP mode, 32 bit */
48 #define PPB_ECP		0x8	/* ECP mode */
49 
50 #define PPB_SPP PPB_NIBBLE|PPB_PS2
51 
52 #define PPB_IS_EPP(mode) (mode & PPB_EPP)
53 #define PPB_IN_EPP_MODE(dev) (PPB_IS_EPP (ppb_get_mode (dev)))
54 #define PPB_IN_NIBBLE_MODE(dev) (ppb_get_mode (dev) & PPB_NIBBLE)
55 #define PPB_IN_PS2_MODE(dev) (ppb_get_mode (dev) & PPB_PS2)
56 
57 #define n(flags) (~(flags) & (flags))
58 
59 /*
60  * Parallel Port Chipset control bits.
61  */
62 #define STROBE		0x01
63 #define AUTOFEED	0x02
64 #define nINIT		0x04
65 #define SELECTIN	0x08
66 #define IRQENABLE	0x10
67 #define PCD		0x20
68 
69 #define nSTROBE		n(STROBE)
70 #define nAUTOFEED	n(AUTOFEED)
71 #define INIT		n(nINIT)
72 #define nSELECTIN	n(SELECTIN)
73 #define nPCD		n(PCD)
74 
75 /*
76  * Parallel Port Chipset status bits.
77  */
78 #define TIMEOUT		0x01
79 #define nFAULT		0x08
80 #define SELECT		0x10
81 #define PERROR		0x20
82 #define nACK		0x40
83 #define nBUSY		0x80
84 
85 /*
86  * Structure to store status information.
87  */
88 struct ppb_status {
89 	unsigned char status;
90 
91 	unsigned int timeout:1;
92 	unsigned int error:1;
93 	unsigned int select:1;
94 	unsigned int paper_end:1;
95 	unsigned int ack:1;
96 	unsigned int busy:1;
97 };
98 
99 /*
100  * How tsleep() is called in ppb_request_bus().
101  */
102 #define PPB_DONTWAIT	0
103 #define PPB_NOINTR	0
104 #define PPB_WAIT	0x1
105 #define PPB_INTR	0x2
106 
107 /*
108  * Microsequence stuff.
109  */
110 #define PPB_MS_MAXLEN	64		/* XXX according to MS_INS_MASK */
111 #define PPB_MS_MAXARGS	3		/* according to MS_ARG_MASK */
112 
113 /* maximum number of mode dependent
114  * submicrosequences for in/out operations
115  */
116 #define PPB_MAX_XFER	6
117 
118 union ppb_insarg {
119 	int	i;
120 	void	*p;
121 	int	(* f)(void *, char *);
122 };
123 
124 struct ppb_microseq {
125 	int			opcode;			/* microins. opcode */
126 	union ppb_insarg	arg[PPB_MS_MAXARGS];	/* arguments */
127 };
128 
129 /* microseqences used for GET/PUT operations */
130 struct ppb_xfer {
131 	struct ppb_microseq *loop;		/* the loop microsequence */
132 };
133 
134 /*
135  * Parallel Port Bus Device structure.
136  */
137 struct ppb_data;			/* see below */
138 
139 struct ppb_context {
140 	int valid;			/* 1 if the struct is valid */
141 	int mode;			/* XXX chipset operating mode */
142 
143 	struct microseq *curpc;		/* pc in curmsq */
144 	struct microseq *curmsq;	/* currently executed microseqence */
145 };
146 
147 
148 struct ppb_device {
149 
150 	int id_unit;			/* unit of the device */
151 	char *name;			/* name of the device */
152 
153 	ushort mode;			/* current mode of the device */
154 	ushort avm;			/* available modes of the device */
155 
156 	struct ppb_context ctx;		/* context of the device */
157 
158 					/* mode dependent get msq. If NULL,
159 					 * IEEE1284 code is used */
160 	struct ppb_xfer
161 		get_xfer[PPB_MAX_XFER];
162 
163 					/* mode dependent put msq. If NULL,
164 					 * IEEE1284 code is used */
165 	struct ppb_xfer
166 		put_xfer[PPB_MAX_XFER];
167 
168 	void (*intr)(int);		/* interrupt handler */
169 
170 	struct ppb_data *ppb;		/* link to the ppbus */
171 
172 	LIST_ENTRY(ppb_device)	chain;	/* list of devices on the bus */
173 };
174 
175 /*
176  * Parallel Port Bus Adapter structure.
177  */
178 struct ppb_adapter {
179 
180 	void (*intr_handler)(int);
181 	void (*reset_epp_timeout)(int);
182 	void (*ecp_sync)(int);
183 
184 	int (*exec_microseq)(int, struct ppb_microseq *, int *);
185 
186 	int (*setmode)(int, int);
187 
188 	void (*outsb_epp)(int, char *, int);
189 	void (*outsw_epp)(int, char *, int);
190 	void (*outsl_epp)(int, char *, int);
191 	void (*insb_epp)(int, char *, int);
192 	void (*insw_epp)(int, char *, int);
193 	void (*insl_epp)(int, char *, int);
194 
195 	char (*r_dtr)(int);
196 	char (*r_str)(int);
197 	char (*r_ctr)(int);
198 	char (*r_epp)(int);
199 	char (*r_ecr)(int);
200 	char (*r_fifo)(int);
201 
202 	void (*w_dtr)(int, char);
203 	void (*w_str)(int, char);
204 	void (*w_ctr)(int, char);
205 	void (*w_epp)(int, char);
206 	void (*w_ecr)(int, char);
207 	void (*w_fifo)(int, char);
208 };
209 
210 /*
211  * ppb_link structure.
212  */
213 struct ppb_link {
214 
215 	int adapter_unit;			/* unit of the adapter */
216 	int base;				/* base address of the port */
217 	int id_irq;				/* != 0 if irq enabled */
218 	int accum;				/* microseq accum */
219 	char *ptr;				/* current buffer pointer */
220 
221 #define EPP_1_9		0x0			/* default */
222 #define EPP_1_7		0x1
223 
224 	int epp_protocol;			/* EPP protocol: 0=1.9, 1=1.7 */
225 
226 	struct ppb_adapter *adapter;		/* link to the ppc adapter */
227 	struct ppb_data *ppbus;			/* link to the ppbus */
228 };
229 
230 /*
231  * Maximum size of the PnP info string
232  */
233 #define PPB_PnP_STRING_SIZE	128			/* XXX */
234 
235 /*
236  * Parallel Port Bus structure.
237  */
238 struct ppb_data {
239 
240 #define PPB_PnP_PRINTER	0
241 #define PPB_PnP_MODEM	1
242 #define PPB_PnP_NET	2
243 #define PPB_PnP_HDC	3
244 #define PPB_PnP_PCMCIA	4
245 #define PPB_PnP_MEDIA	5
246 #define PPB_PnP_FDC	6
247 #define PPB_PnP_PORTS	7
248 #define PPB_PnP_SCANNER	8
249 #define PPB_PnP_DIGICAM	9
250 #define PPB_PnP_UNKNOWN	10
251 	int	class_id;	/* not a PnP device if class_id < 0 */
252 
253 	ushort mode;				/* IEEE 1284-1994 mode
254 						 * NIBBLE, PS2, EPP or ECP */
255 	ushort avm;				/* IEEE 1284-1994 available
256 						 * modes */
257 
258 	struct ppb_link *ppb_link;		/* link to the adapter */
259 	struct ppb_device *ppb_owner;		/* device which owns the bus */
260 	LIST_HEAD(, ppb_device)	ppb_devs;	/* list of devices on the bus */
261 	LIST_ENTRY(ppb_data)	ppb_chain;	/* list of busses */
262 };
263 
264 /*
265  * Parallel Port Bus driver structure.
266  */
267 struct ppb_driver
268 {
269     struct ppb_device	*(*probe)(struct ppb_data *ppb);
270     int			(*attach)(struct ppb_device *pdp);
271     char		*name;
272 };
273 
274 extern struct linker_set ppbdriver_set;
275 
276 extern struct ppb_data *ppb_alloc_bus(void);
277 extern struct ppb_data *ppb_next_bus(struct ppb_data *);
278 extern struct ppb_data *ppb_lookup_bus(int);
279 extern struct ppb_data *ppb_lookup_link(int);
280 
281 extern int ppb_attach_device(struct ppb_device *);
282 extern void ppb_remove_device(struct ppb_device *);
283 extern int ppb_attachdevs(struct ppb_data *);
284 
285 extern int ppb_request_bus(struct ppb_device *, int);
286 extern int ppb_release_bus(struct ppb_device *);
287 
288 extern void ppb_intr(struct ppb_link *);
289 
290 extern int ppb_poll_device(struct ppb_device *, int, char, char, int);
291 
292 extern int ppb_reset_epp_timeout(struct ppb_device *);
293 extern int ppb_ecp_sync(struct ppb_device *);
294 extern int ppb_get_status(struct ppb_device *, struct ppb_status *);
295 
296 extern int ppb_set_mode(struct ppb_device *, int);
297 
298 /*
299  * These are defined as macros for speedup.
300  */
301 #define ppb_get_base_addr(dev) ((dev)->ppb->ppb_link->base)
302 #define ppb_get_epp_protocol(dev) ((dev)->ppb->ppb_link->epp_protocol)
303 #define ppb_get_irq(dev) ((dev)->ppb->ppb_link->id_irq)
304 
305 #define ppb_get_mode(dev) ((dev)->mode)
306 
307 #define ppb_outsb_epp(dev,buf,cnt)					    \
308 			(*(dev)->ppb->ppb_link->adapter->outsb_epp)	    \
309 			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
310 #define ppb_outsw_epp(dev,buf,cnt)					    \
311 			(*(dev)->ppb->ppb_link->adapter->outsw_epp)	    \
312 			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
313 #define ppb_outsl_epp(dev,buf,cnt)					    \
314 			(*(dev)->ppb->ppb_link->adapter->outsl_epp)	    \
315 			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
316 #define ppb_insb_epp(dev,buf,cnt)					    \
317 			(*(dev)->ppb->ppb_link->adapter->insb_epp)	    \
318 			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
319 #define ppb_insw_epp(dev,buf,cnt)					    \
320 			(*(dev)->ppb->ppb_link->adapter->insw_epp)	    \
321 			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
322 #define ppb_insl_epp(dev,buf,cnt)					    \
323 			(*(dev)->ppb->ppb_link->adapter->insl_epp)	    \
324 			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
325 
326 #define ppb_repp(dev) (*(dev)->ppb->ppb_link->adapter->r_epp)		    \
327 				((dev)->ppb->ppb_link->adapter_unit)
328 #define ppb_recr(dev) (*(dev)->ppb->ppb_link->adapter->r_ecr)		    \
329 				((dev)->ppb->ppb_link->adapter_unit)
330 #define ppb_rfifo(dev) (*(dev)->ppb->ppb_link->adapter->r_fifo)		    \
331 				((dev)->ppb->ppb_link->adapter_unit)
332 #define ppb_wepp(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp)	    \
333 				((dev)->ppb->ppb_link->adapter_unit, byte)
334 #define ppb_wecr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ecr)	    \
335 				((dev)->ppb->ppb_link->adapter_unit, byte)
336 #define ppb_wfifo(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_fifo)	    \
337 				((dev)->ppb->ppb_link->adapter_unit, byte)
338 
339 #define ppb_rdtr(dev) (*(dev)->ppb->ppb_link->adapter->r_dtr)		    \
340 				((dev)->ppb->ppb_link->adapter_unit)
341 #define ppb_rstr(dev) (*(dev)->ppb->ppb_link->adapter->r_str)		    \
342 				((dev)->ppb->ppb_link->adapter_unit)
343 #define ppb_rctr(dev) (*(dev)->ppb->ppb_link->adapter->r_ctr)		    \
344 				((dev)->ppb->ppb_link->adapter_unit)
345 #define ppb_wdtr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_dtr)	    \
346 				((dev)->ppb->ppb_link->adapter_unit, byte)
347 #define ppb_wstr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_str)	    \
348 				((dev)->ppb->ppb_link->adapter_unit, byte)
349 #define ppb_wctr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ctr)	    \
350 				((dev)->ppb->ppb_link->adapter_unit, byte)
351 
352 #endif
353