ppbconf.h revision 28980
1/*-
2 * Copyright (c) 1997 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.3 1997/09/01 00:18:02 bde Exp $
27 *
28 */
29#ifndef __PPBCONF_H
30#define __PPBCONF_H
31
32/*
33 * Parallel Port Bus sleep/wakeup queue.
34 */
35#define PPBPRI	PZERO+8
36
37/*
38 * Parallel Port Chipset modes.
39 */
40#define PPB_AUTODETECT	0x0	/* autodetect */
41#define PPB_NIBBLE	0x1	/* standard 4 bit mode */
42#define PPB_PS2		0x2	/* PS/2 byte mode */
43#define PPB_EPP		0x3	/* EPP mode, 32 bit */
44#define PPB_ECP_EPP	0x4	/* ECP in EPP mode */
45#define PPB_ECP_PS2	0x5	/* ECP in PS/2 mode */
46#define PPB_ECP		0x6	/* ECP mode */
47#define PPB_UNKNOWN	0x7	/* the last one */
48
49#define PPB_IS_EPP(mode) (mode == PPB_EPP || mode == PPB_ECP_EPP)
50
51#define PPB_IN_EPP_MODE(dev) (PPB_IS_EPP (ppb_get_mode (dev)))
52
53/*
54 * Parallel Port Chipset control bits.
55 */
56#define STROBE		0x01
57#define AUTOFEED	0x02
58#define nINIT		0x04
59#define SELECTIN	0x08
60#define PCD		0x20
61
62/*
63 * Parallel Port Chipset status bits.
64 */
65#define TIMEOUT		0x01
66#define nFAULT		0x08
67#define SELECT		0x10
68#define ERROR		0x20
69#define nACK		0x40
70#define nBUSY		0x80
71
72/*
73 * Structure to store status information.
74 */
75struct ppb_status {
76	unsigned char status;
77
78	unsigned int timeout:1;
79	unsigned int error:1;
80	unsigned int select:1;
81	unsigned int paper_end:1;
82	unsigned int ack:1;
83	unsigned int busy:1;
84};
85
86/*
87 * How tsleep () is called in ppb_request_bus ().
88 */
89#define PPB_DONTWAIT	0
90#define PPB_NOINTR	0
91#define PPB_WAIT	0x1
92#define PPB_INTR	0x2
93
94struct ppb_data;	/* see below */
95
96/*
97 * Parallel Port Bus Device structure.
98 */
99struct ppb_device {
100
101	int id_unit;			/* unit of the device */
102
103	void (*intr)(int);		/* interrupt handler */
104
105	struct ppb_data *ppb;		/* link to the ppbus */
106
107	LIST_ENTRY(ppb_device)	chain;	/* list of devices on the bus */
108};
109
110/*
111 * Parallel Port Bus Adapter structure.
112 */
113struct ppb_adapter {
114
115	void (*intr_handler)(int);
116	void (*reset_epp_timeout)(int);
117	void (*ecp_sync)(int);
118
119	void (*outsb_epp)(int, char *, int);
120	void (*outsw_epp)(int, char *, int);
121	void (*outsl_epp)(int, char *, int);
122	void (*insb_epp)(int, char *, int);
123	void (*insw_epp)(int, char *, int);
124	void (*insl_epp)(int, char *, int);
125
126	char (*r_dtr)(int);
127	char (*r_str)(int);
128	char (*r_ctr)(int);
129	char (*r_epp)(int);
130	char (*r_ecr)(int);
131	char (*r_fifo)(int);
132
133	void (*w_dtr)(int, char);
134	void (*w_str)(int, char);
135	void (*w_ctr)(int, char);
136	void (*w_epp)(int, char);
137	void (*w_ecr)(int, char);
138	void (*w_fifo)(int, char);
139};
140
141/*
142 * ppb_link structure.
143 */
144struct ppb_link {
145
146	int adapter_unit;			/* unit of the adapter */
147
148	int base;				/* base address of the port */
149	int id_irq;				/* != 0 if irq enabled */
150	int mode;				/* NIBBLE, PS2, EPP, ECP */
151
152#define EPP_1_9		0x0			/* default */
153#define EPP_1_7		0x1
154
155	int epp_protocol;			/* EPP protocol: 0=1.9, 1=1.7 */
156
157	struct ppb_adapter *adapter;		/* link to the ppc adapter */
158	struct ppb_data *ppbus;			/* link to the ppbus */
159};
160
161/*
162 * Maximum size of the PnP info string
163 */
164#define PPB_PnP_STRING_SIZE	160			/* XXX */
165
166/*
167 * Parallel Port Bus structure.
168 */
169struct ppb_data {
170
171#define PPB_PnP_PRINTER	0
172#define PPB_PnP_MODEM	1
173#define PPB_PnP_NET	2
174#define PPB_PnP_HDC	3
175#define PPB_PnP_PCMCIA	4
176#define PPB_PnP_MEDIA	5
177#define PPB_PnP_FDC	6
178#define PPB_PnP_PORTS	7
179#define PPB_PnP_SCANNER	8
180#define PPB_PnP_DIGICAM	9
181#define PPB_PnP_UNKNOWN	10
182	int	class_id;	/* not a PnP device if class_id < 0 */
183
184	struct ppb_link *ppb_link;		/* link to the adapter */
185	struct ppb_device *ppb_owner;		/* device which owns the bus */
186	LIST_HEAD(, ppb_device)	ppb_devs;	/* list of devices on the bus */
187	LIST_ENTRY(ppb_data)	ppb_chain;	/* list of busses */
188};
189
190/*
191 * Parallel Port Bus driver structure.
192 */
193struct ppb_driver
194{
195    struct ppb_device	*(*probe)(struct ppb_data *ppb);
196    int			(*attach)(struct ppb_device *pdp);
197    char		*name;
198};
199
200extern struct linker_set ppbdriver_set;
201
202extern struct ppb_data *ppb_alloc_bus(void);
203extern struct ppb_data *ppb_next_bus(struct ppb_data *);
204extern struct ppb_data *ppb_lookup_bus(int);
205
206extern int ppb_attach_device(struct ppb_device *);
207extern void ppb_remove_device(struct ppb_device *);
208extern int ppb_attachdevs(struct ppb_data *);
209
210extern int ppb_request_bus(struct ppb_device *, int);
211extern int ppb_release_bus(struct ppb_device *);
212
213extern void ppb_intr(struct ppb_link *);
214
215extern int ppb_poll_device(struct ppb_device *, int, char, char, int);
216
217extern int ppb_reset_epp_timeout(struct ppb_device *);
218extern int ppb_ecp_sync(struct ppb_device *);
219extern int ppb_get_status(struct ppb_device *, struct ppb_status *);
220extern int ppb_get_mode(struct ppb_device *);
221extern int ppb_get_epp_protocol(struct ppb_device *);
222extern int ppb_get_irq(struct ppb_device *);
223
224/*
225 * These are defined as macros for speedup.
226 */
227#define ppb_outsb_epp(dev,buf,cnt) \
228			(*(dev)->ppb->ppb_link->adapter->outsb_epp) \
229			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
230#define ppb_outsw_epp(dev,buf,cnt) \
231			(*(dev)->ppb->ppb_link->adapter->outsw_epp) \
232			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
233#define ppb_outsl_epp(dev,buf,cnt) \
234			(*(dev)->ppb->ppb_link->adapter->outsl_epp) \
235			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
236#define ppb_insb_epp(dev,buf,cnt) \
237			(*(dev)->ppb->ppb_link->adapter->insb_epp) \
238			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
239#define ppb_insw_epp(dev,buf,cnt) \
240			(*(dev)->ppb->ppb_link->adapter->insw_epp) \
241			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
242#define ppb_insl_epp(dev,buf,cnt) \
243			(*(dev)->ppb->ppb_link->adapter->insl_epp) \
244			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
245
246#define ppb_rdtr(dev) (*(dev)->ppb->ppb_link->adapter->r_dtr) \
247				((dev)->ppb->ppb_link->adapter_unit)
248#define ppb_rstr(dev) (*(dev)->ppb->ppb_link->adapter->r_str) \
249				((dev)->ppb->ppb_link->adapter_unit)
250#define ppb_rctr(dev) (*(dev)->ppb->ppb_link->adapter->r_ctr) \
251				((dev)->ppb->ppb_link->adapter_unit)
252#define ppb_repp(dev) (*(dev)->ppb->ppb_link->adapter->r_epp) \
253				((dev)->ppb->ppb_link->adapter_unit)
254#define ppb_recr(dev) (*(dev)->ppb->ppb_link->adapter->r_ecr) \
255				((dev)->ppb->ppb_link->adapter_unit)
256#define ppb_rfifo(dev) (*(dev)->ppb->ppb_link->adapter->r_fifo) \
257				((dev)->ppb->ppb_link->adapter_unit)
258
259#define ppb_wdtr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_dtr) \
260				((dev)->ppb->ppb_link->adapter_unit, byte)
261#define ppb_wstr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_str) \
262				((dev)->ppb->ppb_link->adapter_unit, byte)
263#define ppb_wctr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ctr) \
264				((dev)->ppb->ppb_link->adapter_unit, byte)
265#define ppb_wepp(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp) \
266				((dev)->ppb->ppb_link->adapter_unit, byte)
267#define ppb_wecr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ecr) \
268				((dev)->ppb->ppb_link->adapter_unit, byte)
269#define ppb_wfifo(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_fifo) \
270				((dev)->ppb->ppb_link->adapter_unit, byte)
271
272#endif
273