ppbconf.h revision 42482
1/*- 2 * Copyright (c) 1997, 1998 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.10 1999/01/10 12:04:55 nsouch Exp $ 27 * 28 */ 29#ifndef __PPBCONF_H 30#define __PPBCONF_H 31 32#include <sys/queue.h> 33 34/* 35 * Parallel Port Bus sleep/wakeup queue. 36 */ 37#define PPBPRI PZERO+8 38 39/* 40 * Parallel Port Chipset mode masks. 41 * NIBBLE mode is supposed to be available under each other modes. 42 */ 43#define PPB_COMPATIBLE 0x0 /* Centronics compatible mode */ 44 45#define PPB_NIBBLE 0x1 /* reverse 4 bit mode */ 46#define PPB_PS2 0x2 /* PS/2 byte mode */ 47#define PPB_EPP 0x4 /* EPP mode, 32 bit */ 48#define PPB_ECP 0x8 /* ECP mode */ 49 50/* mode aliases */ 51#define PPB_SPP PPB_NIBBLE|PPB_PS2 52#define PPB_BYTE PPB_PS2 53 54#define PPB_MASK 0x0f 55#define PPB_OPTIONS_MASK 0xf0 56 57#define PPB_IS_EPP(mode) (mode & PPB_EPP) 58#define PPB_IN_EPP_MODE(dev) (PPB_IS_EPP (ppb_get_mode (dev))) 59#define PPB_IN_NIBBLE_MODE(dev) (ppb_get_mode (dev) & PPB_NIBBLE) 60#define PPB_IN_PS2_MODE(dev) (ppb_get_mode (dev) & PPB_PS2) 61 62#define n(flags) (~(flags) & (flags)) 63 64/* 65 * Parallel Port Chipset control bits. 66 */ 67#define STROBE 0x01 68#define AUTOFEED 0x02 69#define nINIT 0x04 70#define SELECTIN 0x08 71#define IRQENABLE 0x10 72#define PCD 0x20 73 74#define nSTROBE n(STROBE) 75#define nAUTOFEED n(AUTOFEED) 76#define INIT n(nINIT) 77#define nSELECTIN n(SELECTIN) 78#define nPCD n(PCD) 79 80/* 81 * Parallel Port Chipset status bits. 82 */ 83#define TIMEOUT 0x01 84#define nFAULT 0x08 85#define SELECT 0x10 86#define PERROR 0x20 87#define nACK 0x40 88#define nBUSY 0x80 89 90/* 91 * Structure to store status information. 92 */ 93struct ppb_status { 94 unsigned char status; 95 96 unsigned int timeout:1; 97 unsigned int error:1; 98 unsigned int select:1; 99 unsigned int paper_end:1; 100 unsigned int ack:1; 101 unsigned int busy:1; 102}; 103 104/* 105 * How tsleep() is called in ppb_request_bus(). 106 */ 107#define PPB_DONTWAIT 0 108#define PPB_NOINTR 0 109#define PPB_WAIT 0x1 110#define PPB_INTR 0x2 111#define PPB_POLL 0x4 112#define PPB_FOREVER -1 113 114/* 115 * Microsequence stuff. 116 */ 117#define PPB_MS_MAXLEN 64 /* XXX according to MS_INS_MASK */ 118#define PPB_MS_MAXARGS 3 /* according to MS_ARG_MASK */ 119 120/* maximum number of mode dependent 121 * submicrosequences for in/out operations 122 */ 123#define PPB_MAX_XFER 6 124 125union ppb_insarg { 126 int i; 127 void *p; 128 int (* f)(void *, char *); 129}; 130 131struct ppb_microseq { 132 int opcode; /* microins. opcode */ 133 union ppb_insarg arg[PPB_MS_MAXARGS]; /* arguments */ 134}; 135 136/* microseqences used for GET/PUT operations */ 137struct ppb_xfer { 138 struct ppb_microseq *loop; /* the loop microsequence */ 139}; 140 141/* 142 * Parallel Port Bus Device structure. 143 */ 144struct ppb_data; /* see below */ 145 146struct ppb_context { 147 int valid; /* 1 if the struct is valid */ 148 int mode; /* XXX chipset operating mode */ 149 150 struct microseq *curpc; /* pc in curmsq */ 151 struct microseq *curmsq; /* currently executed microseqence */ 152}; 153 154struct ppb_device { 155 156 int id_unit; /* unit of the device */ 157 char *name; /* name of the device */ 158 159 ushort mode; /* current mode of the device */ 160 ushort avm; /* available IEEE1284 modes of 161 * the device */ 162 163 struct ppb_context ctx; /* context of the device */ 164 165 /* mode dependent get msq. If NULL, 166 * IEEE1284 code is used */ 167 struct ppb_xfer 168 get_xfer[PPB_MAX_XFER]; 169 170 /* mode dependent put msq. If NULL, 171 * IEEE1284 code is used */ 172 struct ppb_xfer 173 put_xfer[PPB_MAX_XFER]; 174 175 void (*intr)(int); /* interrupt handler */ 176 177 struct ppb_data *ppb; /* link to the ppbus */ 178 179 LIST_ENTRY(ppb_device) chain; /* list of devices on the bus */ 180}; 181 182/* 183 * Parallel Port Bus Adapter structure. 184 */ 185struct ppb_adapter { 186 187 void (*intr_handler)(int); 188 void (*reset_epp_timeout)(int); 189 void (*ecp_sync)(int); 190 191 int (*exec_microseq)(int, struct ppb_microseq **); 192 193 int (*setmode)(int, int); 194 int (*read)(int, char *, int, int); 195 int (*write)(int, char *, int, int); 196 197 void (*outsb_epp)(int, char *, int); 198 void (*outsw_epp)(int, char *, int); 199 void (*outsl_epp)(int, char *, int); 200 void (*insb_epp)(int, char *, int); 201 void (*insw_epp)(int, char *, int); 202 void (*insl_epp)(int, char *, int); 203 204 u_char (*r_dtr)(int); 205 u_char (*r_str)(int); 206 u_char (*r_ctr)(int); 207 u_char (*r_epp)(int); 208 u_char (*r_ecr)(int); 209 u_char (*r_fifo)(int); 210 211 void (*w_dtr)(int, char); 212 void (*w_str)(int, char); 213 void (*w_ctr)(int, char); 214 void (*w_epp)(int, char); 215 void (*w_ecr)(int, char); 216 void (*w_fifo)(int, char); 217}; 218 219/* 220 * ppb_link structure. 221 */ 222struct ppb_link { 223 224 int adapter_unit; /* unit of the adapter */ 225 int base; /* base address of the port */ 226 int id_irq; /* != 0 if irq enabled */ 227 int accum; /* microseq accum */ 228 char *ptr; /* current buffer pointer */ 229 230#define EPP_1_9 0x0 /* default */ 231#define EPP_1_7 0x1 232 233 int epp_protocol; /* EPP protocol: 0=1.9, 1=1.7 */ 234 235 struct ppb_adapter *adapter; /* link to the ppc adapter */ 236 struct ppb_data *ppbus; /* link to the ppbus */ 237}; 238 239/* 240 * Maximum size of the PnP info string 241 */ 242#define PPB_PnP_STRING_SIZE 256 /* XXX */ 243 244/* 245 * Parallel Port Bus structure. 246 */ 247struct ppb_data { 248 249#define PPB_PnP_PRINTER 0 250#define PPB_PnP_MODEM 1 251#define PPB_PnP_NET 2 252#define PPB_PnP_HDC 3 253#define PPB_PnP_PCMCIA 4 254#define PPB_PnP_MEDIA 5 255#define PPB_PnP_FDC 6 256#define PPB_PnP_PORTS 7 257#define PPB_PnP_SCANNER 8 258#define PPB_PnP_DIGICAM 9 259#define PPB_PnP_UNKNOWN 10 260 int class_id; /* not a PnP device if class_id < 0 */ 261 262 int state; /* current IEEE1284 state */ 263 int error; /* last IEEE1284 error */ 264 265 ushort mode; /* IEEE 1284-1994 mode 266 * NIBBLE, PS2, EPP or ECP */ 267 268 struct ppb_link *ppb_link; /* link to the adapter */ 269 struct ppb_device *ppb_owner; /* device which owns the bus */ 270 LIST_HEAD(, ppb_device) ppb_devs; /* list of devices on the bus */ 271 LIST_ENTRY(ppb_data) ppb_chain; /* list of busses */ 272}; 273 274/* 275 * Parallel Port Bus driver structure. 276 */ 277struct ppb_driver 278{ 279 struct ppb_device *(*probe)(struct ppb_data *ppb); 280 int (*attach)(struct ppb_device *pdp); 281 char *name; 282}; 283 284extern struct linker_set ppbdriver_set; 285 286extern struct ppb_data *ppb_alloc_bus(void); 287extern struct ppb_data *ppb_next_bus(struct ppb_data *); 288extern struct ppb_data *ppb_lookup_bus(int); 289extern struct ppb_data *ppb_lookup_link(int); 290 291extern int ppb_attach_device(struct ppb_device *); 292extern void ppb_remove_device(struct ppb_device *); 293extern int ppb_attachdevs(struct ppb_data *); 294 295extern int ppb_request_bus(struct ppb_device *, int); 296extern int ppb_release_bus(struct ppb_device *); 297 298extern void ppb_intr(struct ppb_link *); 299 300extern int ppb_poll_device(struct ppb_device *, int, char, char, int); 301 302extern int ppb_reset_epp_timeout(struct ppb_device *); 303extern int ppb_ecp_sync(struct ppb_device *); 304extern int ppb_get_status(struct ppb_device *, struct ppb_status *); 305 306extern int ppb_set_mode(struct ppb_device *, int); 307extern int ppb_write(struct ppb_device *, char *, int, int); 308 309/* 310 * These are defined as macros for speedup. 311 */ 312#define ppb_get_base_addr(dev) ((dev)->ppb->ppb_link->base) 313#define ppb_get_epp_protocol(dev) ((dev)->ppb->ppb_link->epp_protocol) 314#define ppb_get_irq(dev) ((dev)->ppb->ppb_link->id_irq) 315 316#define ppb_get_mode(dev) ((dev)->mode) 317 318#define ppb_outsb_epp(dev,buf,cnt) \ 319 (*(dev)->ppb->ppb_link->adapter->outsb_epp) \ 320 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 321#define ppb_outsw_epp(dev,buf,cnt) \ 322 (*(dev)->ppb->ppb_link->adapter->outsw_epp) \ 323 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 324#define ppb_outsl_epp(dev,buf,cnt) \ 325 (*(dev)->ppb->ppb_link->adapter->outsl_epp) \ 326 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 327#define ppb_insb_epp(dev,buf,cnt) \ 328 (*(dev)->ppb->ppb_link->adapter->insb_epp) \ 329 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 330#define ppb_insw_epp(dev,buf,cnt) \ 331 (*(dev)->ppb->ppb_link->adapter->insw_epp) \ 332 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 333#define ppb_insl_epp(dev,buf,cnt) \ 334 (*(dev)->ppb->ppb_link->adapter->insl_epp) \ 335 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 336 337#define ppb_repp(dev) (*(dev)->ppb->ppb_link->adapter->r_epp) \ 338 ((dev)->ppb->ppb_link->adapter_unit) 339#define ppb_recr(dev) (*(dev)->ppb->ppb_link->adapter->r_ecr) \ 340 ((dev)->ppb->ppb_link->adapter_unit) 341#define ppb_rfifo(dev) (*(dev)->ppb->ppb_link->adapter->r_fifo) \ 342 ((dev)->ppb->ppb_link->adapter_unit) 343#define ppb_wepp(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp) \ 344 ((dev)->ppb->ppb_link->adapter_unit, byte) 345#define ppb_wecr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ecr) \ 346 ((dev)->ppb->ppb_link->adapter_unit, byte) 347#define ppb_wfifo(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_fifo) \ 348 ((dev)->ppb->ppb_link->adapter_unit, byte) 349 350#define ppb_rdtr(dev) (*(dev)->ppb->ppb_link->adapter->r_dtr) \ 351 ((dev)->ppb->ppb_link->adapter_unit) 352#define ppb_rstr(dev) (*(dev)->ppb->ppb_link->adapter->r_str) \ 353 ((dev)->ppb->ppb_link->adapter_unit) 354#define ppb_rctr(dev) (*(dev)->ppb->ppb_link->adapter->r_ctr) \ 355 ((dev)->ppb->ppb_link->adapter_unit) 356#define ppb_wdtr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_dtr) \ 357 ((dev)->ppb->ppb_link->adapter_unit, byte) 358#define ppb_wstr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_str) \ 359 ((dev)->ppb->ppb_link->adapter_unit, byte) 360#define ppb_wctr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ctr) \ 361 ((dev)->ppb->ppb_link->adapter_unit, byte) 362 363#endif 364