ppbconf.h revision 28257
11573Srgrimes/*- 214272Spst * Copyright (c) 1997 Nicolas Souchu 31573Srgrimes * All rights reserved. 41573Srgrimes * 51573Srgrimes * Redistribution and use in source and binary forms, with or without 61573Srgrimes * modification, are permitted provided that the following conditions 71573Srgrimes * are met: 81573Srgrimes * 1. Redistributions of source code must retain the above copyright 91573Srgrimes * notice, this list of conditions and the following disclaimer. 101573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111573Srgrimes * notice, this list of conditions and the following disclaimer in the 121573Srgrimes * documentation and/or other materials provided with the distribution. 131573Srgrimes * 141573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 151573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 161573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 171573Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 181573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 191573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 201573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 211573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 221573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 231573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 241573Srgrimes * SUCH DAMAGE. 251573Srgrimes * 261573Srgrimes * $Id: ppbconf.h,v 1.1 1997/08/14 13:57:42 msmith Exp $ 271573Srgrimes * 281573Srgrimes */ 291573Srgrimes#ifndef __PPBCONF_H 301573Srgrimes#define __PPBCONF_H 3114272Spst 321573Srgrimes/* 3392986Sobrien * Parallel Port Bus sleep/wakeup queue. 3492986Sobrien */ 351573Srgrimes#define PPBPRI PZERO+8 361573Srgrimes 371573Srgrimes/* 381573Srgrimes * Parallel Port Chipset modes. 391573Srgrimes */ 401573Srgrimes#define PPB_AUTODETECT 0x0 /* autodetect */ 411573Srgrimes#define PPB_NIBBLE 0x1 /* standard 4 bit mode */ 421573Srgrimes#define PPB_PS2 0x2 /* PS/2 byte mode */ 431573Srgrimes#define PPB_EPP 0x3 /* EPP mode, 32 bit */ 441573Srgrimes#define PPB_ECP_EPP 0x4 /* ECP in EPP mode */ 451573Srgrimes#define PPB_ECP_PS2 0x5 /* ECP in PS/2 mode */ 4614272Spst#define PPB_ECP 0x6 /* ECP mode */ 4714272Spst#define PPB_UNKNOWN 0x7 /* the last one */ 481573Srgrimes 491573Srgrimes#define PPB_IS_EPP(mode) (mode == PPB_EPP || mode == PPB_ECP_EPP) 501573Srgrimes 5114272Spst#define PPB_IN_EPP_MODE(dev) (PPB_IS_EPP (ppb_get_mode (dev))) 5214272Spst 5314272Spst/* 54189327Sdelphij * Parallel Port Chipset control bits. 551573Srgrimes */ 561573Srgrimes#define STROBE 0x01 571573Srgrimes#define AUTOFEED 0x02 581573Srgrimes#define nINIT 0x04 591573Srgrimes#define SELECTIN 0x08 60189291Sdelphij#define PCD 0x20 611573Srgrimes 6214272Spst/* 6314272Spst * Parallel Port Chipset status bits. 641573Srgrimes */ 6514272Spst#define TIMEOUT 0x01 6614272Spst#define nFAULT 0x08 6714272Spst#define SELECT 0x10 6814272Spst#define ERROR 0x20 6914272Spst#define nACK 0x40 7014272Spst#define nBUSY 0x80 7114272Spst 7214272Spst/* 7314272Spst * Structure to store status information. 7414272Spst */ 7514272Spststruct ppb_status { 7614272Spst unsigned char status; 7714272Spst 7814272Spst unsigned int timeout:1; 7914272Spst unsigned int error:1; 8014272Spst unsigned int select:1; 8114272Spst unsigned int paper_end:1; 8214272Spst unsigned int ack:1; 831573Srgrimes unsigned int busy:1; 8414272Spst}; 851573Srgrimes 861573Srgrimes/* 8714272Spst * How tsleep () is called in ppb_request_bus (). 881573Srgrimes */ 891573Srgrimes#define PPB_DONTWAIT 0 901573Srgrimes#define PPB_NOINTR 0 9114272Spst#define PPB_WAIT 0x1 921573Srgrimes#define PPB_INTR 0x2 931573Srgrimes 9414272Spststruct ppb_data; /* see below */ 951573Srgrimes 9614272Spst/* 9714272Spst * Parallel Port Bus Device structure. 981573Srgrimes */ 9914272Spststruct ppb_device { 10014272Spst 10114272Spst int id_unit; /* unit of the device */ 10214272Spst 10314272Spst void (*intr)(int); /* interrupt handler */ 1041573Srgrimes 10514272Spst struct ppb_data *ppb; /* link to the ppbus */ 10614272Spst 1071573Srgrimes LIST_ENTRY(ppb_device) chain; /* list of devices on the bus */ 10814272Spst}; 1091573Srgrimes 11014272Spst/* 1111573Srgrimes * Parallel Port Bus Adapter structure. 1121573Srgrimes */ 1131573Srgrimesstruct ppb_adapter { 1141573Srgrimes 1151573Srgrimes void (*intr_handler)(int); 1161573Srgrimes 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