ppbconf.h revision 45342
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 * 2645342Speter * $Id: ppbconf.h,v 1.13 1999/01/30 15:35:39 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; 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 */ 17728219Smsmith 17828219Smsmith struct ppb_data *ppb; /* link to the ppbus */ 17928219Smsmith 18028219Smsmith LIST_ENTRY(ppb_device) chain; /* list of devices on the bus */ 18128219Smsmith}; 18228219Smsmith 18328219Smsmith/* 18428219Smsmith * Parallel Port Bus Adapter structure. 18528219Smsmith */ 18628219Smsmithstruct ppb_adapter { 18728219Smsmith 18828219Smsmith void (*intr_handler)(int); 18928219Smsmith void (*reset_epp_timeout)(int); 19028219Smsmith void (*ecp_sync)(int); 19128219Smsmith 19239520Snsouch int (*exec_microseq)(int, struct ppb_microseq **); 19338061Smsmith 19438061Smsmith int (*setmode)(int, int); 19542475Snsouch int (*read)(int, char *, int, int); 19642475Snsouch int (*write)(int, char *, int, int); 19738061Smsmith 19828219Smsmith void (*outsb_epp)(int, char *, int); 19928219Smsmith void (*outsw_epp)(int, char *, int); 20028219Smsmith void (*outsl_epp)(int, char *, int); 20128219Smsmith void (*insb_epp)(int, char *, int); 20228219Smsmith void (*insw_epp)(int, char *, int); 20328219Smsmith void (*insl_epp)(int, char *, int); 20428219Smsmith 20542482Snsouch u_char (*r_dtr)(int); 20642482Snsouch u_char (*r_str)(int); 20742482Snsouch u_char (*r_ctr)(int); 20843433Snsouch u_char (*r_epp_A)(int); 20943433Snsouch u_char (*r_epp_D)(int); 21042482Snsouch u_char (*r_ecr)(int); 21142482Snsouch u_char (*r_fifo)(int); 21228219Smsmith 21328219Smsmith void (*w_dtr)(int, char); 21428219Smsmith void (*w_str)(int, char); 21528219Smsmith void (*w_ctr)(int, char); 21643433Snsouch void (*w_epp_A)(int, char); 21743433Snsouch void (*w_epp_D)(int, char); 21828219Smsmith void (*w_ecr)(int, char); 21928219Smsmith void (*w_fifo)(int, char); 22028219Smsmith}; 22128219Smsmith 22228219Smsmith/* 22328219Smsmith * ppb_link structure. 22428219Smsmith */ 22528219Smsmithstruct ppb_link { 22628219Smsmith 22728219Smsmith int adapter_unit; /* unit of the adapter */ 22828257Smsmith int base; /* base address of the port */ 22928219Smsmith int id_irq; /* != 0 if irq enabled */ 23039134Snsouch int accum; /* microseq accum */ 23139134Snsouch char *ptr; /* current buffer pointer */ 23228219Smsmith 23328219Smsmith#define EPP_1_9 0x0 /* default */ 23428219Smsmith#define EPP_1_7 0x1 23528219Smsmith 23628219Smsmith int epp_protocol; /* EPP protocol: 0=1.9, 1=1.7 */ 23728219Smsmith 23828219Smsmith struct ppb_adapter *adapter; /* link to the ppc adapter */ 23928219Smsmith struct ppb_data *ppbus; /* link to the ppbus */ 24028219Smsmith}; 24128219Smsmith 24228219Smsmith/* 24328257Smsmith * Maximum size of the PnP info string 24428257Smsmith */ 24542475Snsouch#define PPB_PnP_STRING_SIZE 256 /* XXX */ 24628257Smsmith 24728257Smsmith/* 24828219Smsmith * Parallel Port Bus structure. 24928219Smsmith */ 25028219Smsmithstruct ppb_data { 25128219Smsmith 25228257Smsmith#define PPB_PnP_PRINTER 0 25328257Smsmith#define PPB_PnP_MODEM 1 25428257Smsmith#define PPB_PnP_NET 2 25528257Smsmith#define PPB_PnP_HDC 3 25628257Smsmith#define PPB_PnP_PCMCIA 4 25728257Smsmith#define PPB_PnP_MEDIA 5 25828257Smsmith#define PPB_PnP_FDC 6 25928257Smsmith#define PPB_PnP_PORTS 7 26028257Smsmith#define PPB_PnP_SCANNER 8 26128257Smsmith#define PPB_PnP_DIGICAM 9 26228257Smsmith#define PPB_PnP_UNKNOWN 10 26328257Smsmith int class_id; /* not a PnP device if class_id < 0 */ 26428257Smsmith 26542475Snsouch int state; /* current IEEE1284 state */ 26642475Snsouch int error; /* last IEEE1284 error */ 26742475Snsouch 26838061Smsmith ushort mode; /* IEEE 1284-1994 mode 26938061Smsmith * NIBBLE, PS2, EPP or ECP */ 27038061Smsmith 27128219Smsmith struct ppb_link *ppb_link; /* link to the adapter */ 27228219Smsmith struct ppb_device *ppb_owner; /* device which owns the bus */ 27328219Smsmith LIST_HEAD(, ppb_device) ppb_devs; /* list of devices on the bus */ 27428219Smsmith LIST_ENTRY(ppb_data) ppb_chain; /* list of busses */ 27528219Smsmith}; 27628219Smsmith 27728219Smsmith/* 27828219Smsmith * Parallel Port Bus driver structure. 27928219Smsmith */ 28028219Smsmithstruct ppb_driver 28128219Smsmith{ 28228219Smsmith struct ppb_device *(*probe)(struct ppb_data *ppb); 28328219Smsmith int (*attach)(struct ppb_device *pdp); 28428219Smsmith char *name; 28528219Smsmith}; 28628219Smsmith 28728219Smsmithextern struct linker_set ppbdriver_set; 28828219Smsmith 28928219Smsmithextern struct ppb_data *ppb_alloc_bus(void); 29028257Smsmithextern struct ppb_data *ppb_next_bus(struct ppb_data *); 29128257Smsmithextern struct ppb_data *ppb_lookup_bus(int); 29238061Smsmithextern struct ppb_data *ppb_lookup_link(int); 29328257Smsmith 29428257Smsmithextern int ppb_attach_device(struct ppb_device *); 29528257Smsmithextern void ppb_remove_device(struct ppb_device *); 29628219Smsmithextern int ppb_attachdevs(struct ppb_data *); 29728257Smsmith 29828219Smsmithextern int ppb_request_bus(struct ppb_device *, int); 29928219Smsmithextern int ppb_release_bus(struct ppb_device *); 30028257Smsmith 30128219Smsmithextern void ppb_intr(struct ppb_link *); 30228219Smsmith 30328257Smsmithextern int ppb_poll_device(struct ppb_device *, int, char, char, int); 30428257Smsmith 30528219Smsmithextern int ppb_reset_epp_timeout(struct ppb_device *); 30628219Smsmithextern int ppb_ecp_sync(struct ppb_device *); 30728219Smsmithextern int ppb_get_status(struct ppb_device *, struct ppb_status *); 30828219Smsmith 30938061Smsmithextern int ppb_set_mode(struct ppb_device *, int); 31042475Snsouchextern int ppb_write(struct ppb_device *, char *, int, int); 31138061Smsmith 31228219Smsmith/* 31328219Smsmith * These are defined as macros for speedup. 31428219Smsmith */ 31538061Smsmith#define ppb_get_base_addr(dev) ((dev)->ppb->ppb_link->base) 31638061Smsmith#define ppb_get_epp_protocol(dev) ((dev)->ppb->ppb_link->epp_protocol) 31738061Smsmith#define ppb_get_irq(dev) ((dev)->ppb->ppb_link->id_irq) 31838061Smsmith 31938061Smsmith#define ppb_get_mode(dev) ((dev)->mode) 32038061Smsmith 32143433Snsouch/* This set of function access only to the EPP _data_ registers 32243433Snsouch * in 8, 16 and 32 bit modes */ 32338061Smsmith#define ppb_outsb_epp(dev,buf,cnt) \ 32438061Smsmith (*(dev)->ppb->ppb_link->adapter->outsb_epp) \ 32528219Smsmith ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 32638061Smsmith#define ppb_outsw_epp(dev,buf,cnt) \ 32738061Smsmith (*(dev)->ppb->ppb_link->adapter->outsw_epp) \ 32828219Smsmith ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 32938061Smsmith#define ppb_outsl_epp(dev,buf,cnt) \ 33038061Smsmith (*(dev)->ppb->ppb_link->adapter->outsl_epp) \ 33128219Smsmith ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 33238061Smsmith#define ppb_insb_epp(dev,buf,cnt) \ 33338061Smsmith (*(dev)->ppb->ppb_link->adapter->insb_epp) \ 33428219Smsmith ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 33538061Smsmith#define ppb_insw_epp(dev,buf,cnt) \ 33638061Smsmith (*(dev)->ppb->ppb_link->adapter->insw_epp) \ 33728219Smsmith ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 33838061Smsmith#define ppb_insl_epp(dev,buf,cnt) \ 33938061Smsmith (*(dev)->ppb->ppb_link->adapter->insl_epp) \ 34028219Smsmith ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 34128219Smsmith 34243433Snsouch#define ppb_repp_A(dev) (*(dev)->ppb->ppb_link->adapter->r_epp_A) \ 34328219Smsmith ((dev)->ppb->ppb_link->adapter_unit) 34443433Snsouch#define ppb_repp_D(dev) (*(dev)->ppb->ppb_link->adapter->r_epp_D) \ 34543433Snsouch ((dev)->ppb->ppb_link->adapter_unit) 34638061Smsmith#define ppb_recr(dev) (*(dev)->ppb->ppb_link->adapter->r_ecr) \ 34728219Smsmith ((dev)->ppb->ppb_link->adapter_unit) 34838061Smsmith#define ppb_rfifo(dev) (*(dev)->ppb->ppb_link->adapter->r_fifo) \ 34928219Smsmith ((dev)->ppb->ppb_link->adapter_unit) 35043433Snsouch#define ppb_wepp_A(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp_A) \ 35138061Smsmith ((dev)->ppb->ppb_link->adapter_unit, byte) 35243433Snsouch#define ppb_wepp_D(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp_D) \ 35343433Snsouch ((dev)->ppb->ppb_link->adapter_unit, byte) 35438061Smsmith#define ppb_wecr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ecr) \ 35538061Smsmith ((dev)->ppb->ppb_link->adapter_unit, byte) 35638061Smsmith#define ppb_wfifo(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_fifo) \ 35738061Smsmith ((dev)->ppb->ppb_link->adapter_unit, byte) 35838061Smsmith 35938061Smsmith#define ppb_rdtr(dev) (*(dev)->ppb->ppb_link->adapter->r_dtr) \ 36028219Smsmith ((dev)->ppb->ppb_link->adapter_unit) 36138061Smsmith#define ppb_rstr(dev) (*(dev)->ppb->ppb_link->adapter->r_str) \ 36228219Smsmith ((dev)->ppb->ppb_link->adapter_unit) 36338061Smsmith#define ppb_rctr(dev) (*(dev)->ppb->ppb_link->adapter->r_ctr) \ 36428219Smsmith ((dev)->ppb->ppb_link->adapter_unit) 36538061Smsmith#define ppb_wdtr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_dtr) \ 36628219Smsmith ((dev)->ppb->ppb_link->adapter_unit, byte) 36738061Smsmith#define ppb_wstr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_str) \ 36828219Smsmith ((dev)->ppb->ppb_link->adapter_unit, byte) 36938061Smsmith#define ppb_wctr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ctr) \ 37028219Smsmith ((dev)->ppb->ppb_link->adapter_unit, byte) 37128219Smsmith 37228219Smsmith#endif 373