xref: /freebsd/sys/dev/ppbus/ppbconf.h (revision bdd1243d)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 1997, 1998, 1999 Nicolas Souchu
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  *
30  */
31 #ifndef __PPBCONF_H
32 #define __PPBCONF_H
33 
34 #define n(flags) (~(flags) & (flags))
35 
36 /*
37  * Parallel Port Chipset control bits.
38  */
39 #define STROBE		0x01
40 #define AUTOFEED	0x02
41 #define nINIT		0x04
42 #define SELECTIN	0x08
43 #define IRQENABLE	0x10
44 #define PCD		0x20
45 
46 #define nSTROBE		n(STROBE)
47 #define nAUTOFEED	n(AUTOFEED)
48 #define INIT		n(nINIT)
49 #define nSELECTIN	n(SELECTIN)
50 #define nPCD		n(PCD)
51 
52 /*
53  * Parallel Port Chipset status bits.
54  */
55 #define TIMEOUT		0x01
56 #define nFAULT		0x08
57 #define SELECT		0x10
58 #define PERROR		0x20
59 #define nACK		0x40
60 #define nBUSY		0x80
61 
62 #ifdef _KERNEL
63 #include <sys/queue.h>
64 
65 /*
66  * Parallel Port Bus sleep/wakeup queue.
67  */
68 #define PPBPRI	(PZERO+8)
69 
70 /*
71  * Parallel Port Chipset mode masks.
72  * NIBBLE mode is supposed to be available under each other modes.
73  */
74 #define PPB_COMPATIBLE	0x0	/* Centronics compatible mode */
75 
76 #define PPB_NIBBLE	0x1	/* reverse 4 bit mode */
77 #define PPB_PS2		0x2	/* PS/2 byte mode */
78 #define PPB_EPP		0x4	/* EPP mode, 32 bit */
79 #define PPB_ECP		0x8	/* ECP mode */
80 
81 /* mode aliases */
82 #define PPB_SPP		PPB_NIBBLE|PPB_PS2
83 #define PPB_BYTE	PPB_PS2
84 
85 #define PPB_MASK		0x0f
86 #define PPB_OPTIONS_MASK	0xf0
87 
88 #define PPB_IS_EPP(mode) (mode & PPB_EPP)
89 #define PPB_IN_EPP_MODE(bus) (PPB_IS_EPP (ppb_get_mode (bus)))
90 #define PPB_IN_NIBBLE_MODE(bus) (ppb_get_mode (bus) & PPB_NIBBLE)
91 #define PPB_IN_PS2_MODE(bus) (ppb_get_mode (bus) & PPB_PS2)
92 
93 /*
94  * Structure to store status information.
95  */
96 struct ppb_status {
97 	unsigned char status;
98 
99 	unsigned int timeout:1;
100 	unsigned int error:1;
101 	unsigned int select:1;
102 	unsigned int paper_end:1;
103 	unsigned int ack:1;
104 	unsigned int busy:1;
105 };
106 
107 /* Parallel port bus I/O opcodes */
108 #define PPB_OUTSB_EPP	1
109 #define PPB_OUTSW_EPP	2
110 #define PPB_OUTSL_EPP	3
111 #define PPB_INSB_EPP	4
112 #define PPB_INSW_EPP	5
113 #define PPB_INSL_EPP	6
114 #define PPB_RDTR	7
115 #define PPB_RSTR	8
116 #define PPB_RCTR	9
117 #define PPB_REPP_A	10
118 #define PPB_REPP_D	11
119 #define PPB_RECR	12
120 #define PPB_RFIFO	13
121 #define PPB_WDTR	14
122 #define PPB_WSTR	15
123 #define PPB_WCTR	16
124 #define PPB_WEPP_A	17
125 #define PPB_WEPP_D	18
126 #define PPB_WECR	19
127 #define PPB_WFIFO	20
128 
129 /*
130  * How tsleep() is called in ppb_request_bus().
131  */
132 #define PPB_DONTWAIT	0
133 #define PPB_NOINTR	0
134 #define PPB_WAIT	0x1
135 #define PPB_INTR	0x2
136 #define PPB_POLL	0x4
137 #define PPB_FOREVER	-1
138 
139 /*
140  * Microsequence stuff.
141  */
142 #define PPB_MS_MAXLEN	64		/* XXX according to MS_INS_MASK */
143 #define PPB_MS_MAXARGS	3		/* according to MS_ARG_MASK */
144 
145 /* maximum number of mode dependent
146  * submicrosequences for in/out operations
147  */
148 #define PPB_MAX_XFER	6
149 
150 union ppb_insarg {
151 	int	i;
152 	void	*p;
153 	char	*c;
154 	int	(* f)(void *, char *);
155 };
156 
157 struct ppb_microseq {
158 	int			opcode;			/* microins. opcode */
159 	union ppb_insarg	arg[PPB_MS_MAXARGS];	/* arguments */
160 };
161 
162 /* microseqences used for GET/PUT operations */
163 struct ppb_xfer {
164 	struct ppb_microseq *loop;		/* the loop microsequence */
165 };
166 
167 /*
168  * Parallel Port Bus Device structure.
169  */
170 struct ppb_data;			/* see below */
171 
172 struct ppb_context {
173 	int valid;			/* 1 if the struct is valid */
174 	int mode;			/* XXX chipset operating mode */
175 
176 	struct microseq *curpc;		/* pc in curmsq */
177 	struct microseq *curmsq;	/* currently executed microseqence */
178 };
179 
180 /*
181  * List of IVARS available to ppb device drivers
182  */
183 #define PPBUS_IVAR_MODE 0
184 
185 /* other fields are reserved to the ppbus internals */
186 
187 struct ppb_device {
188 	const char *name;		/* name of the device */
189 
190 	u_int flags;			/* flags */
191 
192 	struct ppb_context ctx;		/* context of the device */
193 
194 					/* mode dependent get msq. If NULL,
195 					 * IEEE1284 code is used */
196 	struct ppb_xfer
197 		get_xfer[PPB_MAX_XFER];
198 
199 					/* mode dependent put msq. If NULL,
200 					 * IEEE1284 code is used */
201 	struct ppb_xfer
202 		put_xfer[PPB_MAX_XFER];
203 
204 	driver_intr_t *intr_hook;
205 	void *intr_arg;
206 };
207 
208 /* EPP standards */
209 #define EPP_1_9		0x0			/* default */
210 #define EPP_1_7		0x1
211 
212 /* Parallel Port Chipset IVARS */		/* elsewhere XXX */
213 #define PPC_IVAR_EPP_PROTO	0
214 #define PPC_IVAR_LOCK		1
215 #define PPC_IVAR_INTR_HANDLER	2
216 
217 /*
218  * Maximum size of the PnP info string
219  */
220 #define PPB_PnP_STRING_SIZE	256			/* XXX */
221 
222 /*
223  * Parallel Port Bus structure.
224  */
225 struct ppb_data {
226 #define PPB_PnP_PRINTER	0
227 #define PPB_PnP_MODEM	1
228 #define PPB_PnP_NET	2
229 #define PPB_PnP_HDC	3
230 #define PPB_PnP_PCMCIA	4
231 #define PPB_PnP_MEDIA	5
232 #define PPB_PnP_FDC	6
233 #define PPB_PnP_PORTS	7
234 #define PPB_PnP_SCANNER	8
235 #define PPB_PnP_DIGICAM	9
236 #define PPB_PnP_UNKNOWN	10
237 	int class_id;		/* not a PnP device if class_id < 0 */
238 
239 	int state;		/* current IEEE1284 state */
240 	int error;		/* last IEEE1284 error */
241 
242 	int mode;		/* IEEE 1284-1994 mode
243 				 * NIBBLE, PS2, EPP or ECP */
244 
245 	device_t ppb_owner;	/* device which owns the bus */
246 
247 	struct mtx *ppc_lock;	/* lock of parent device */
248 	struct resource *ppc_irq_res;
249 };
250 
251 struct callout;
252 
253 typedef int (*ppc_intr_handler)(void *);
254 
255 extern int ppb_attach_device(device_t);
256 extern int ppb_request_bus(device_t, device_t, int);
257 extern int ppb_release_bus(device_t, device_t);
258 
259 /* bus related functions */
260 extern void ppb_lock(device_t);
261 extern void ppb_unlock(device_t);
262 extern struct mtx *ppb_get_lock(device_t);
263 extern void _ppb_assert_locked(device_t, const char *, int);
264 extern void ppb_init_callout(device_t, struct callout *, int);
265 extern int ppb_sleep(device_t, void *, int, const char *, int);
266 extern int ppb_get_status(device_t, struct ppb_status *);
267 extern int ppb_poll_bus(device_t, int, uint8_t, uint8_t, int);
268 extern int ppb_reset_epp_timeout(device_t);
269 extern int ppb_ecp_sync(device_t);
270 extern int ppb_get_epp_protocol(device_t);
271 extern int ppb_set_mode(device_t, int);		/* returns old mode */
272 extern int ppb_get_mode(device_t);		/* returns current mode */
273 extern int ppb_write(device_t, char *, int, int);
274 
275 #ifdef INVARIANTS
276 #define ppb_assert_locked(dev)	_ppb_assert_locked(dev, __FILE__, __LINE__)
277 #else
278 #define ppb_assert_locked(dev)
279 #endif
280 #endif /* _KERNEL */
281 
282 #endif /* !__PPBCONF_H */
283