ppbconf.h revision 43293
128219Smsmith/*-
238061Smsmith * Copyright (c) 1997, 1998 Nicolas Souchu
328219Smsmith * All rights reserved.
428219Smsmith *
528219Smsmith * Redistribution and use in source and binary forms, with or without
628219Smsmith * modification, are permitted provided that the following conditions
728219Smsmith * are met:
828219Smsmith * 1. Redistributions of source code must retain the above copyright
928219Smsmith *    notice, this list of conditions and the following disclaimer.
1028219Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1128219Smsmith *    notice, this list of conditions and the following disclaimer in the
1228219Smsmith *    documentation and/or other materials provided with the distribution.
1328219Smsmith *
1428219Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1528219Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1628219Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1728219Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1828219Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1928219Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2028219Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2128219Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2228219Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2328219Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2428219Smsmith * SUCH DAMAGE.
2528219Smsmith *
2643293Sdillon *	$Id: ppbconf.h,v 1.11 1999/01/10 16:41:14 nsouch Exp $
2728219Smsmith *
2828219Smsmith */
2928219Smsmith#ifndef __PPBCONF_H
3028219Smsmith#define __PPBCONF_H
3128219Smsmith
3229020Sbde#include <sys/queue.h>
3329020Sbde
3428219Smsmith/*
3528257Smsmith * Parallel Port Bus sleep/wakeup queue.
3628257Smsmith */
3743293Sdillon#define PPBPRI	(PZERO+8)
3828257Smsmith
3928257Smsmith/*
4038061Smsmith * Parallel Port Chipset mode masks.
4138061Smsmith * NIBBLE mode is supposed to be available under each other modes.
4228219Smsmith */
4338061Smsmith#define PPB_COMPATIBLE	0x0	/* Centronics compatible mode */
4438061Smsmith
4538061Smsmith#define PPB_NIBBLE	0x1	/* reverse 4 bit mode */
4628219Smsmith#define PPB_PS2		0x2	/* PS/2 byte mode */
4738061Smsmith#define PPB_EPP		0x4	/* EPP mode, 32 bit */
4838061Smsmith#define PPB_ECP		0x8	/* ECP mode */
4928219Smsmith
5042475Snsouch/* mode aliases */
5142475Snsouch#define PPB_SPP		PPB_NIBBLE|PPB_PS2
5242475Snsouch#define PPB_BYTE	PPB_PS2
5328219Smsmith
5442475Snsouch#define PPB_MASK		0x0f
5542475Snsouch#define PPB_OPTIONS_MASK	0xf0
5642475Snsouch
5738061Smsmith#define PPB_IS_EPP(mode) (mode & PPB_EPP)
5828219Smsmith#define PPB_IN_EPP_MODE(dev) (PPB_IS_EPP (ppb_get_mode (dev)))
5939134Snsouch#define PPB_IN_NIBBLE_MODE(dev) (ppb_get_mode (dev) & PPB_NIBBLE)
6039134Snsouch#define PPB_IN_PS2_MODE(dev) (ppb_get_mode (dev) & PPB_PS2)
6128219Smsmith
6238061Smsmith#define n(flags) (~(flags) & (flags))
6338061Smsmith
6428219Smsmith/*
6528219Smsmith * Parallel Port Chipset control bits.
6628219Smsmith */
6728219Smsmith#define STROBE		0x01
6828219Smsmith#define AUTOFEED	0x02
6928219Smsmith#define nINIT		0x04
7028219Smsmith#define SELECTIN	0x08
7136739Sphk#define IRQENABLE	0x10
7228219Smsmith#define PCD		0x20
7328219Smsmith
7438061Smsmith#define nSTROBE		n(STROBE)
7538061Smsmith#define nAUTOFEED	n(AUTOFEED)
7638061Smsmith#define INIT		n(nINIT)
7738061Smsmith#define nSELECTIN	n(SELECTIN)
7838061Smsmith#define nPCD		n(PCD)
7938061Smsmith
8028219Smsmith/*
8128219Smsmith * Parallel Port Chipset status bits.
8228219Smsmith */
8328219Smsmith#define TIMEOUT		0x01
8428219Smsmith#define nFAULT		0x08
8528219Smsmith#define SELECT		0x10
8639134Snsouch#define PERROR		0x20
8728219Smsmith#define nACK		0x40
8828219Smsmith#define nBUSY		0x80
8928219Smsmith
9028219Smsmith/*
9128219Smsmith * Structure to store status information.
9228219Smsmith */
9328219Smsmithstruct ppb_status {
9428219Smsmith	unsigned char status;
9528219Smsmith
9628219Smsmith	unsigned int timeout:1;
9728219Smsmith	unsigned int error:1;
9828219Smsmith	unsigned int select:1;
9928219Smsmith	unsigned int paper_end:1;
10028219Smsmith	unsigned int ack:1;
10128219Smsmith	unsigned int busy:1;
10228219Smsmith};
10328219Smsmith
10428219Smsmith/*
10538061Smsmith * How tsleep() is called in ppb_request_bus().
10628219Smsmith */
10728219Smsmith#define PPB_DONTWAIT	0
10828219Smsmith#define PPB_NOINTR	0
10928219Smsmith#define PPB_WAIT	0x1
11028219Smsmith#define PPB_INTR	0x2
11142475Snsouch#define PPB_POLL	0x4
11242475Snsouch#define PPB_FOREVER	-1
11328219Smsmith
11438061Smsmith/*
11538061Smsmith * Microsequence stuff.
11638061Smsmith */
11738061Smsmith#define PPB_MS_MAXLEN	64		/* XXX according to MS_INS_MASK */
11838061Smsmith#define PPB_MS_MAXARGS	3		/* according to MS_ARG_MASK */
11928219Smsmith
12038061Smsmith/* maximum number of mode dependent
12138061Smsmith * submicrosequences for in/out operations
12238061Smsmith */
12338061Smsmith#define PPB_MAX_XFER	6
12438061Smsmith
12538061Smsmithunion ppb_insarg {
12638061Smsmith	int	i;
12738061Smsmith	void	*p;
12838061Smsmith	int	(* f)(void *, char *);
12938061Smsmith};
13038061Smsmith
13138061Smsmithstruct ppb_microseq {
13238061Smsmith	int			opcode;			/* microins. opcode */
13338061Smsmith	union ppb_insarg	arg[PPB_MS_MAXARGS];	/* arguments */
13438061Smsmith};
13538061Smsmith
13638061Smsmith/* microseqences used for GET/PUT operations */
13738061Smsmithstruct ppb_xfer {
13838061Smsmith	struct ppb_microseq *loop;		/* the loop microsequence */
13938061Smsmith};
14038061Smsmith
14128219Smsmith/*
14228219Smsmith * Parallel Port Bus Device structure.
14328219Smsmith */
14438061Smsmithstruct ppb_data;			/* see below */
14538061Smsmith
14638061Smsmithstruct ppb_context {
14738061Smsmith	int valid;			/* 1 if the struct is valid */
14838061Smsmith	int mode;			/* XXX chipset operating mode */
14938061Smsmith
15038061Smsmith	struct microseq *curpc;		/* pc in curmsq */
15138061Smsmith	struct microseq *curmsq;	/* currently executed microseqence */
15238061Smsmith};
15338061Smsmith
15428219Smsmithstruct ppb_device {
15528219Smsmith
15628219Smsmith	int id_unit;			/* unit of the device */
15738061Smsmith	char *name;			/* name of the device */
15828219Smsmith
15938061Smsmith	ushort mode;			/* current mode of the device */
16042475Snsouch	ushort avm;			/* available IEEE1284 modes of
16142475Snsouch					 * the device */
16238061Smsmith
16338061Smsmith	struct ppb_context ctx;		/* context of the device */
16438061Smsmith
16538061Smsmith					/* mode dependent get msq. If NULL,
16638061Smsmith					 * IEEE1284 code is used */
16738061Smsmith	struct ppb_xfer
16838061Smsmith		get_xfer[PPB_MAX_XFER];
16938061Smsmith
17038061Smsmith					/* mode dependent put msq. If NULL,
17138061Smsmith					 * IEEE1284 code is used */
17238061Smsmith	struct ppb_xfer
17338061Smsmith		put_xfer[PPB_MAX_XFER];
17438061Smsmith
17528219Smsmith	void (*intr)(int);		/* interrupt handler */
17628219Smsmith
17728219Smsmith	struct ppb_data *ppb;		/* link to the ppbus */
17828219Smsmith
17928219Smsmith	LIST_ENTRY(ppb_device)	chain;	/* list of devices on the bus */
18028219Smsmith};
18128219Smsmith
18228219Smsmith/*
18328219Smsmith * Parallel Port Bus Adapter structure.
18428219Smsmith */
18528219Smsmithstruct ppb_adapter {
18628219Smsmith
18728219Smsmith	void (*intr_handler)(int);
18828219Smsmith	void (*reset_epp_timeout)(int);
18928219Smsmith	void (*ecp_sync)(int);
19028219Smsmith
19139520Snsouch	int (*exec_microseq)(int, struct ppb_microseq **);
19238061Smsmith
19338061Smsmith	int (*setmode)(int, int);
19442475Snsouch	int (*read)(int, char *, int, int);
19542475Snsouch	int (*write)(int, char *, int, int);
19638061Smsmith
19728219Smsmith	void (*outsb_epp)(int, char *, int);
19828219Smsmith	void (*outsw_epp)(int, char *, int);
19928219Smsmith	void (*outsl_epp)(int, char *, int);
20028219Smsmith	void (*insb_epp)(int, char *, int);
20128219Smsmith	void (*insw_epp)(int, char *, int);
20228219Smsmith	void (*insl_epp)(int, char *, int);
20328219Smsmith
20442482Snsouch	u_char (*r_dtr)(int);
20542482Snsouch	u_char (*r_str)(int);
20642482Snsouch	u_char (*r_ctr)(int);
20742482Snsouch	u_char (*r_epp)(int);
20842482Snsouch	u_char (*r_ecr)(int);
20942482Snsouch	u_char (*r_fifo)(int);
21028219Smsmith
21128219Smsmith	void (*w_dtr)(int, char);
21228219Smsmith	void (*w_str)(int, char);
21328219Smsmith	void (*w_ctr)(int, char);
21428219Smsmith	void (*w_epp)(int, char);
21528219Smsmith	void (*w_ecr)(int, char);
21628219Smsmith	void (*w_fifo)(int, char);
21728219Smsmith};
21828219Smsmith
21928219Smsmith/*
22028219Smsmith * ppb_link structure.
22128219Smsmith */
22228219Smsmithstruct ppb_link {
22328219Smsmith
22428219Smsmith	int adapter_unit;			/* unit of the adapter */
22528257Smsmith	int base;				/* base address of the port */
22628219Smsmith	int id_irq;				/* != 0 if irq enabled */
22739134Snsouch	int accum;				/* microseq accum */
22839134Snsouch	char *ptr;				/* current buffer pointer */
22928219Smsmith
23028219Smsmith#define EPP_1_9		0x0			/* default */
23128219Smsmith#define EPP_1_7		0x1
23228219Smsmith
23328219Smsmith	int epp_protocol;			/* EPP protocol: 0=1.9, 1=1.7 */
23428219Smsmith
23528219Smsmith	struct ppb_adapter *adapter;		/* link to the ppc adapter */
23628219Smsmith	struct ppb_data *ppbus;			/* link to the ppbus */
23728219Smsmith};
23828219Smsmith
23928219Smsmith/*
24028257Smsmith * Maximum size of the PnP info string
24128257Smsmith */
24242475Snsouch#define PPB_PnP_STRING_SIZE	256			/* XXX */
24328257Smsmith
24428257Smsmith/*
24528219Smsmith * Parallel Port Bus structure.
24628219Smsmith */
24728219Smsmithstruct ppb_data {
24828219Smsmith
24928257Smsmith#define PPB_PnP_PRINTER	0
25028257Smsmith#define PPB_PnP_MODEM	1
25128257Smsmith#define PPB_PnP_NET	2
25228257Smsmith#define PPB_PnP_HDC	3
25328257Smsmith#define PPB_PnP_PCMCIA	4
25428257Smsmith#define PPB_PnP_MEDIA	5
25528257Smsmith#define PPB_PnP_FDC	6
25628257Smsmith#define PPB_PnP_PORTS	7
25728257Smsmith#define PPB_PnP_SCANNER	8
25828257Smsmith#define PPB_PnP_DIGICAM	9
25928257Smsmith#define PPB_PnP_UNKNOWN	10
26028257Smsmith	int	class_id;	/* not a PnP device if class_id < 0 */
26128257Smsmith
26242475Snsouch	int state;				/* current IEEE1284 state */
26342475Snsouch	int error;				/* last IEEE1284 error */
26442475Snsouch
26538061Smsmith	ushort mode;				/* IEEE 1284-1994 mode
26638061Smsmith						 * NIBBLE, PS2, EPP or ECP */
26738061Smsmith
26828219Smsmith	struct ppb_link *ppb_link;		/* link to the adapter */
26928219Smsmith	struct ppb_device *ppb_owner;		/* device which owns the bus */
27028219Smsmith	LIST_HEAD(, ppb_device)	ppb_devs;	/* list of devices on the bus */
27128219Smsmith	LIST_ENTRY(ppb_data)	ppb_chain;	/* list of busses */
27228219Smsmith};
27328219Smsmith
27428219Smsmith/*
27528219Smsmith * Parallel Port Bus driver structure.
27628219Smsmith */
27728219Smsmithstruct ppb_driver
27828219Smsmith{
27928219Smsmith    struct ppb_device	*(*probe)(struct ppb_data *ppb);
28028219Smsmith    int			(*attach)(struct ppb_device *pdp);
28128219Smsmith    char		*name;
28228219Smsmith};
28328219Smsmith
28428219Smsmithextern struct linker_set ppbdriver_set;
28528219Smsmith
28628219Smsmithextern struct ppb_data *ppb_alloc_bus(void);
28728257Smsmithextern struct ppb_data *ppb_next_bus(struct ppb_data *);
28828257Smsmithextern struct ppb_data *ppb_lookup_bus(int);
28938061Smsmithextern struct ppb_data *ppb_lookup_link(int);
29028257Smsmith
29128257Smsmithextern int ppb_attach_device(struct ppb_device *);
29228257Smsmithextern void ppb_remove_device(struct ppb_device *);
29328219Smsmithextern int ppb_attachdevs(struct ppb_data *);
29428257Smsmith
29528219Smsmithextern int ppb_request_bus(struct ppb_device *, int);
29628219Smsmithextern int ppb_release_bus(struct ppb_device *);
29728257Smsmith
29828219Smsmithextern void ppb_intr(struct ppb_link *);
29928219Smsmith
30028257Smsmithextern int ppb_poll_device(struct ppb_device *, int, char, char, int);
30128257Smsmith
30228219Smsmithextern int ppb_reset_epp_timeout(struct ppb_device *);
30328219Smsmithextern int ppb_ecp_sync(struct ppb_device *);
30428219Smsmithextern int ppb_get_status(struct ppb_device *, struct ppb_status *);
30528219Smsmith
30638061Smsmithextern int ppb_set_mode(struct ppb_device *, int);
30742475Snsouchextern int ppb_write(struct ppb_device *, char *, int, int);
30838061Smsmith
30928219Smsmith/*
31028219Smsmith * These are defined as macros for speedup.
31128219Smsmith */
31238061Smsmith#define ppb_get_base_addr(dev) ((dev)->ppb->ppb_link->base)
31338061Smsmith#define ppb_get_epp_protocol(dev) ((dev)->ppb->ppb_link->epp_protocol)
31438061Smsmith#define ppb_get_irq(dev) ((dev)->ppb->ppb_link->id_irq)
31538061Smsmith
31638061Smsmith#define ppb_get_mode(dev) ((dev)->mode)
31738061Smsmith
31838061Smsmith#define ppb_outsb_epp(dev,buf,cnt)					    \
31938061Smsmith			(*(dev)->ppb->ppb_link->adapter->outsb_epp)	    \
32028219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
32138061Smsmith#define ppb_outsw_epp(dev,buf,cnt)					    \
32238061Smsmith			(*(dev)->ppb->ppb_link->adapter->outsw_epp)	    \
32328219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
32438061Smsmith#define ppb_outsl_epp(dev,buf,cnt)					    \
32538061Smsmith			(*(dev)->ppb->ppb_link->adapter->outsl_epp)	    \
32628219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
32738061Smsmith#define ppb_insb_epp(dev,buf,cnt)					    \
32838061Smsmith			(*(dev)->ppb->ppb_link->adapter->insb_epp)	    \
32928219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
33038061Smsmith#define ppb_insw_epp(dev,buf,cnt)					    \
33138061Smsmith			(*(dev)->ppb->ppb_link->adapter->insw_epp)	    \
33228219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
33338061Smsmith#define ppb_insl_epp(dev,buf,cnt)					    \
33438061Smsmith			(*(dev)->ppb->ppb_link->adapter->insl_epp)	    \
33528219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
33628219Smsmith
33738061Smsmith#define ppb_repp(dev) (*(dev)->ppb->ppb_link->adapter->r_epp)		    \
33828219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
33938061Smsmith#define ppb_recr(dev) (*(dev)->ppb->ppb_link->adapter->r_ecr)		    \
34028219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
34138061Smsmith#define ppb_rfifo(dev) (*(dev)->ppb->ppb_link->adapter->r_fifo)		    \
34228219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
34338061Smsmith#define ppb_wepp(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp)	    \
34438061Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
34538061Smsmith#define ppb_wecr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ecr)	    \
34638061Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
34738061Smsmith#define ppb_wfifo(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_fifo)	    \
34838061Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
34938061Smsmith
35038061Smsmith#define ppb_rdtr(dev) (*(dev)->ppb->ppb_link->adapter->r_dtr)		    \
35128219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
35238061Smsmith#define ppb_rstr(dev) (*(dev)->ppb->ppb_link->adapter->r_str)		    \
35328219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
35438061Smsmith#define ppb_rctr(dev) (*(dev)->ppb->ppb_link->adapter->r_ctr)		    \
35528219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
35638061Smsmith#define ppb_wdtr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_dtr)	    \
35728219Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
35838061Smsmith#define ppb_wstr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_str)	    \
35928219Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
36038061Smsmith#define ppb_wctr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ctr)	    \
36128219Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
36228219Smsmith
36328219Smsmith#endif
364