ppbconf.h revision 50477
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 *
2650477Speter * $FreeBSD: head/sys/dev/ppbus/ppbconf.h 50477 1999-08-28 01:08:13Z peter $
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;
12845342Speter	char	*c;
12938061Smsmith	int	(* f)(void *, char *);
13038061Smsmith};
13138061Smsmith
13238061Smsmithstruct ppb_microseq {
13338061Smsmith	int			opcode;			/* microins. opcode */
13438061Smsmith	union ppb_insarg	arg[PPB_MS_MAXARGS];	/* arguments */
13538061Smsmith};
13638061Smsmith
13738061Smsmith/* microseqences used for GET/PUT operations */
13838061Smsmithstruct ppb_xfer {
13938061Smsmith	struct ppb_microseq *loop;		/* the loop microsequence */
14038061Smsmith};
14138061Smsmith
14228219Smsmith/*
14328219Smsmith * Parallel Port Bus Device structure.
14428219Smsmith */
14538061Smsmithstruct ppb_data;			/* see below */
14638061Smsmith
14738061Smsmithstruct ppb_context {
14838061Smsmith	int valid;			/* 1 if the struct is valid */
14938061Smsmith	int mode;			/* XXX chipset operating mode */
15038061Smsmith
15138061Smsmith	struct microseq *curpc;		/* pc in curmsq */
15238061Smsmith	struct microseq *curmsq;	/* currently executed microseqence */
15338061Smsmith};
15438061Smsmith
15528219Smsmithstruct ppb_device {
15628219Smsmith
15728219Smsmith	int id_unit;			/* unit of the device */
15838061Smsmith	char *name;			/* name of the device */
15928219Smsmith
16038061Smsmith	ushort mode;			/* current mode of the device */
16142475Snsouch	ushort avm;			/* available IEEE1284 modes of
16242475Snsouch					 * the device */
16338061Smsmith
16438061Smsmith	struct ppb_context ctx;		/* context of the device */
16538061Smsmith
16638061Smsmith					/* mode dependent get msq. If NULL,
16738061Smsmith					 * IEEE1284 code is used */
16838061Smsmith	struct ppb_xfer
16938061Smsmith		get_xfer[PPB_MAX_XFER];
17038061Smsmith
17138061Smsmith					/* mode dependent put msq. If NULL,
17238061Smsmith					 * IEEE1284 code is used */
17338061Smsmith	struct ppb_xfer
17438061Smsmith		put_xfer[PPB_MAX_XFER];
17538061Smsmith
17628219Smsmith	void (*intr)(int);		/* interrupt handler */
17749549Sphk	void (*bintr)(struct ppb_device *);	/* interrupt handler */
17828219Smsmith
17949549Sphk	void *drv1, *drv2;		/* drivers private data */
18049549Sphk
18128219Smsmith	struct ppb_data *ppb;		/* link to the ppbus */
18228219Smsmith
18328219Smsmith	LIST_ENTRY(ppb_device)	chain;	/* list of devices on the bus */
18428219Smsmith};
18528219Smsmith
18628219Smsmith/*
18728219Smsmith * Parallel Port Bus Adapter structure.
18828219Smsmith */
18928219Smsmithstruct ppb_adapter {
19028219Smsmith
19128219Smsmith	void (*intr_handler)(int);
19228219Smsmith	void (*reset_epp_timeout)(int);
19328219Smsmith	void (*ecp_sync)(int);
19428219Smsmith
19539520Snsouch	int (*exec_microseq)(int, struct ppb_microseq **);
19638061Smsmith
19738061Smsmith	int (*setmode)(int, int);
19842475Snsouch	int (*read)(int, char *, int, int);
19942475Snsouch	int (*write)(int, char *, int, int);
20038061Smsmith
20128219Smsmith	void (*outsb_epp)(int, char *, int);
20228219Smsmith	void (*outsw_epp)(int, char *, int);
20328219Smsmith	void (*outsl_epp)(int, char *, int);
20428219Smsmith	void (*insb_epp)(int, char *, int);
20528219Smsmith	void (*insw_epp)(int, char *, int);
20628219Smsmith	void (*insl_epp)(int, char *, int);
20728219Smsmith
20842482Snsouch	u_char (*r_dtr)(int);
20942482Snsouch	u_char (*r_str)(int);
21042482Snsouch	u_char (*r_ctr)(int);
21143433Snsouch	u_char (*r_epp_A)(int);
21243433Snsouch	u_char (*r_epp_D)(int);
21342482Snsouch	u_char (*r_ecr)(int);
21442482Snsouch	u_char (*r_fifo)(int);
21528219Smsmith
21628219Smsmith	void (*w_dtr)(int, char);
21728219Smsmith	void (*w_str)(int, char);
21828219Smsmith	void (*w_ctr)(int, char);
21943433Snsouch	void (*w_epp_A)(int, char);
22043433Snsouch	void (*w_epp_D)(int, char);
22128219Smsmith	void (*w_ecr)(int, char);
22228219Smsmith	void (*w_fifo)(int, char);
22328219Smsmith};
22428219Smsmith
22528219Smsmith/*
22628219Smsmith * ppb_link structure.
22728219Smsmith */
22828219Smsmithstruct ppb_link {
22928219Smsmith
23028219Smsmith	int adapter_unit;			/* unit of the adapter */
23128257Smsmith	int base;				/* base address of the port */
23228219Smsmith	int id_irq;				/* != 0 if irq enabled */
23339134Snsouch	int accum;				/* microseq accum */
23439134Snsouch	char *ptr;				/* current buffer pointer */
23528219Smsmith
23628219Smsmith#define EPP_1_9		0x0			/* default */
23728219Smsmith#define EPP_1_7		0x1
23828219Smsmith
23928219Smsmith	int epp_protocol;			/* EPP protocol: 0=1.9, 1=1.7 */
24028219Smsmith
24128219Smsmith	struct ppb_adapter *adapter;		/* link to the ppc adapter */
24228219Smsmith	struct ppb_data *ppbus;			/* link to the ppbus */
24328219Smsmith};
24428219Smsmith
24528219Smsmith/*
24628257Smsmith * Maximum size of the PnP info string
24728257Smsmith */
24842475Snsouch#define PPB_PnP_STRING_SIZE	256			/* XXX */
24928257Smsmith
25028257Smsmith/*
25128219Smsmith * Parallel Port Bus structure.
25228219Smsmith */
25328219Smsmithstruct ppb_data {
25428219Smsmith
25528257Smsmith#define PPB_PnP_PRINTER	0
25628257Smsmith#define PPB_PnP_MODEM	1
25728257Smsmith#define PPB_PnP_NET	2
25828257Smsmith#define PPB_PnP_HDC	3
25928257Smsmith#define PPB_PnP_PCMCIA	4
26028257Smsmith#define PPB_PnP_MEDIA	5
26128257Smsmith#define PPB_PnP_FDC	6
26228257Smsmith#define PPB_PnP_PORTS	7
26328257Smsmith#define PPB_PnP_SCANNER	8
26428257Smsmith#define PPB_PnP_DIGICAM	9
26528257Smsmith#define PPB_PnP_UNKNOWN	10
26628257Smsmith	int	class_id;	/* not a PnP device if class_id < 0 */
26728257Smsmith
26842475Snsouch	int state;				/* current IEEE1284 state */
26942475Snsouch	int error;				/* last IEEE1284 error */
27042475Snsouch
27138061Smsmith	ushort mode;				/* IEEE 1284-1994 mode
27238061Smsmith						 * NIBBLE, PS2, EPP or ECP */
27338061Smsmith
27428219Smsmith	struct ppb_link *ppb_link;		/* link to the adapter */
27528219Smsmith	struct ppb_device *ppb_owner;		/* device which owns the bus */
27628219Smsmith	LIST_HEAD(, ppb_device)	ppb_devs;	/* list of devices on the bus */
27728219Smsmith	LIST_ENTRY(ppb_data)	ppb_chain;	/* list of busses */
27828219Smsmith};
27928219Smsmith
28028219Smsmith/*
28128219Smsmith * Parallel Port Bus driver structure.
28228219Smsmith */
28328219Smsmithstruct ppb_driver
28428219Smsmith{
28528219Smsmith    struct ppb_device	*(*probe)(struct ppb_data *ppb);
28628219Smsmith    int			(*attach)(struct ppb_device *pdp);
28728219Smsmith    char		*name;
28828219Smsmith};
28928219Smsmith
29028219Smsmithextern struct linker_set ppbdriver_set;
29128219Smsmith
29228219Smsmithextern struct ppb_data *ppb_alloc_bus(void);
29328257Smsmithextern struct ppb_data *ppb_next_bus(struct ppb_data *);
29428257Smsmithextern struct ppb_data *ppb_lookup_bus(int);
29538061Smsmithextern struct ppb_data *ppb_lookup_link(int);
29628257Smsmith
29728257Smsmithextern int ppb_attach_device(struct ppb_device *);
29828257Smsmithextern void ppb_remove_device(struct ppb_device *);
29928219Smsmithextern int ppb_attachdevs(struct ppb_data *);
30028257Smsmith
30128219Smsmithextern int ppb_request_bus(struct ppb_device *, int);
30228219Smsmithextern int ppb_release_bus(struct ppb_device *);
30328257Smsmith
30428219Smsmithextern void ppb_intr(struct ppb_link *);
30528219Smsmith
30628257Smsmithextern int ppb_poll_device(struct ppb_device *, int, char, char, int);
30728257Smsmith
30828219Smsmithextern int ppb_reset_epp_timeout(struct ppb_device *);
30928219Smsmithextern int ppb_ecp_sync(struct ppb_device *);
31028219Smsmithextern int ppb_get_status(struct ppb_device *, struct ppb_status *);
31128219Smsmith
31238061Smsmithextern int ppb_set_mode(struct ppb_device *, int);
31342475Snsouchextern int ppb_write(struct ppb_device *, char *, int, int);
31438061Smsmith
31528219Smsmith/*
31628219Smsmith * These are defined as macros for speedup.
31728219Smsmith */
31838061Smsmith#define ppb_get_base_addr(dev) ((dev)->ppb->ppb_link->base)
31938061Smsmith#define ppb_get_epp_protocol(dev) ((dev)->ppb->ppb_link->epp_protocol)
32038061Smsmith#define ppb_get_irq(dev) ((dev)->ppb->ppb_link->id_irq)
32138061Smsmith
32238061Smsmith#define ppb_get_mode(dev) ((dev)->mode)
32338061Smsmith
32443433Snsouch/* This set of function access only to the EPP _data_ registers
32543433Snsouch * in 8, 16 and 32 bit modes */
32638061Smsmith#define ppb_outsb_epp(dev,buf,cnt)					    \
32738061Smsmith			(*(dev)->ppb->ppb_link->adapter->outsb_epp)	    \
32828219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
32938061Smsmith#define ppb_outsw_epp(dev,buf,cnt)					    \
33038061Smsmith			(*(dev)->ppb->ppb_link->adapter->outsw_epp)	    \
33128219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
33238061Smsmith#define ppb_outsl_epp(dev,buf,cnt)					    \
33338061Smsmith			(*(dev)->ppb->ppb_link->adapter->outsl_epp)	    \
33428219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
33538061Smsmith#define ppb_insb_epp(dev,buf,cnt)					    \
33638061Smsmith			(*(dev)->ppb->ppb_link->adapter->insb_epp)	    \
33728219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
33838061Smsmith#define ppb_insw_epp(dev,buf,cnt)					    \
33938061Smsmith			(*(dev)->ppb->ppb_link->adapter->insw_epp)	    \
34028219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
34138061Smsmith#define ppb_insl_epp(dev,buf,cnt)					    \
34238061Smsmith			(*(dev)->ppb->ppb_link->adapter->insl_epp)	    \
34328219Smsmith			((dev)->ppb->ppb_link->adapter_unit, buf, cnt)
34428219Smsmith
34543433Snsouch#define ppb_repp_A(dev) (*(dev)->ppb->ppb_link->adapter->r_epp_A)	    \
34628219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
34743433Snsouch#define ppb_repp_D(dev) (*(dev)->ppb->ppb_link->adapter->r_epp_D)	    \
34843433Snsouch				((dev)->ppb->ppb_link->adapter_unit)
34938061Smsmith#define ppb_recr(dev) (*(dev)->ppb->ppb_link->adapter->r_ecr)		    \
35028219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
35138061Smsmith#define ppb_rfifo(dev) (*(dev)->ppb->ppb_link->adapter->r_fifo)		    \
35228219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
35343433Snsouch#define ppb_wepp_A(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp_A)	    \
35438061Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
35543433Snsouch#define ppb_wepp_D(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp_D)	    \
35643433Snsouch				((dev)->ppb->ppb_link->adapter_unit, byte)
35738061Smsmith#define ppb_wecr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ecr)	    \
35838061Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
35938061Smsmith#define ppb_wfifo(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_fifo)	    \
36038061Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
36138061Smsmith
36238061Smsmith#define ppb_rdtr(dev) (*(dev)->ppb->ppb_link->adapter->r_dtr)		    \
36328219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
36438061Smsmith#define ppb_rstr(dev) (*(dev)->ppb->ppb_link->adapter->r_str)		    \
36528219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
36638061Smsmith#define ppb_rctr(dev) (*(dev)->ppb->ppb_link->adapter->r_ctr)		    \
36728219Smsmith				((dev)->ppb->ppb_link->adapter_unit)
36838061Smsmith#define ppb_wdtr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_dtr)	    \
36928219Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
37038061Smsmith#define ppb_wstr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_str)	    \
37128219Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
37238061Smsmith#define ppb_wctr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ctr)	    \
37328219Smsmith				((dev)->ppb->ppb_link->adapter_unit, byte)
37428219Smsmith
37528219Smsmith#endif
376