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.12 1999/01/27 19:44:05 dillon 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 */ 93 struct 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 125 union ppb_insarg { 126 int i; 127 void *p; 128 int (* f)(void *, char *); 129 }; 130 131 struct 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 */ 137 struct ppb_xfer { 138 struct ppb_microseq *loop; /* the loop microsequence */ 139 }; 140 141 /* 142 * Parallel Port Bus Device structure. 143 */ 144 struct ppb_data; /* see below */ 145 146 struct 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 154 struct 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 */ 185 struct 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_A)(int); 208 u_char (*r_epp_D)(int); 209 u_char (*r_ecr)(int); 210 u_char (*r_fifo)(int); 211 212 void (*w_dtr)(int, char); 213 void (*w_str)(int, char); 214 void (*w_ctr)(int, char); 215 void (*w_epp_A)(int, char); 216 void (*w_epp_D)(int, char); 217 void (*w_ecr)(int, char); 218 void (*w_fifo)(int, char); 219 }; 220 221 /* 222 * ppb_link structure. 223 */ 224 struct ppb_link { 225 226 int adapter_unit; /* unit of the adapter */ 227 int base; /* base address of the port */ 228 int id_irq; /* != 0 if irq enabled */ 229 int accum; /* microseq accum */ 230 char *ptr; /* current buffer pointer */ 231 232 #define EPP_1_9 0x0 /* default */ 233 #define EPP_1_7 0x1 234 235 int epp_protocol; /* EPP protocol: 0=1.9, 1=1.7 */ 236 237 struct ppb_adapter *adapter; /* link to the ppc adapter */ 238 struct ppb_data *ppbus; /* link to the ppbus */ 239 }; 240 241 /* 242 * Maximum size of the PnP info string 243 */ 244 #define PPB_PnP_STRING_SIZE 256 /* XXX */ 245 246 /* 247 * Parallel Port Bus structure. 248 */ 249 struct ppb_data { 250 251 #define PPB_PnP_PRINTER 0 252 #define PPB_PnP_MODEM 1 253 #define PPB_PnP_NET 2 254 #define PPB_PnP_HDC 3 255 #define PPB_PnP_PCMCIA 4 256 #define PPB_PnP_MEDIA 5 257 #define PPB_PnP_FDC 6 258 #define PPB_PnP_PORTS 7 259 #define PPB_PnP_SCANNER 8 260 #define PPB_PnP_DIGICAM 9 261 #define PPB_PnP_UNKNOWN 10 262 int class_id; /* not a PnP device if class_id < 0 */ 263 264 int state; /* current IEEE1284 state */ 265 int error; /* last IEEE1284 error */ 266 267 ushort mode; /* IEEE 1284-1994 mode 268 * NIBBLE, PS2, EPP or ECP */ 269 270 struct ppb_link *ppb_link; /* link to the adapter */ 271 struct ppb_device *ppb_owner; /* device which owns the bus */ 272 LIST_HEAD(, ppb_device) ppb_devs; /* list of devices on the bus */ 273 LIST_ENTRY(ppb_data) ppb_chain; /* list of busses */ 274 }; 275 276 /* 277 * Parallel Port Bus driver structure. 278 */ 279 struct ppb_driver 280 { 281 struct ppb_device *(*probe)(struct ppb_data *ppb); 282 int (*attach)(struct ppb_device *pdp); 283 char *name; 284 }; 285 286 extern struct linker_set ppbdriver_set; 287 288 extern struct ppb_data *ppb_alloc_bus(void); 289 extern struct ppb_data *ppb_next_bus(struct ppb_data *); 290 extern struct ppb_data *ppb_lookup_bus(int); 291 extern struct ppb_data *ppb_lookup_link(int); 292 293 extern int ppb_attach_device(struct ppb_device *); 294 extern void ppb_remove_device(struct ppb_device *); 295 extern int ppb_attachdevs(struct ppb_data *); 296 297 extern int ppb_request_bus(struct ppb_device *, int); 298 extern int ppb_release_bus(struct ppb_device *); 299 300 extern void ppb_intr(struct ppb_link *); 301 302 extern int ppb_poll_device(struct ppb_device *, int, char, char, int); 303 304 extern int ppb_reset_epp_timeout(struct ppb_device *); 305 extern int ppb_ecp_sync(struct ppb_device *); 306 extern int ppb_get_status(struct ppb_device *, struct ppb_status *); 307 308 extern int ppb_set_mode(struct ppb_device *, int); 309 extern int ppb_write(struct ppb_device *, char *, int, int); 310 311 /* 312 * These are defined as macros for speedup. 313 */ 314 #define ppb_get_base_addr(dev) ((dev)->ppb->ppb_link->base) 315 #define ppb_get_epp_protocol(dev) ((dev)->ppb->ppb_link->epp_protocol) 316 #define ppb_get_irq(dev) ((dev)->ppb->ppb_link->id_irq) 317 318 #define ppb_get_mode(dev) ((dev)->mode) 319 320 /* This set of function access only to the EPP _data_ registers 321 * in 8, 16 and 32 bit modes */ 322 #define ppb_outsb_epp(dev,buf,cnt) \ 323 (*(dev)->ppb->ppb_link->adapter->outsb_epp) \ 324 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 325 #define ppb_outsw_epp(dev,buf,cnt) \ 326 (*(dev)->ppb->ppb_link->adapter->outsw_epp) \ 327 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 328 #define ppb_outsl_epp(dev,buf,cnt) \ 329 (*(dev)->ppb->ppb_link->adapter->outsl_epp) \ 330 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 331 #define ppb_insb_epp(dev,buf,cnt) \ 332 (*(dev)->ppb->ppb_link->adapter->insb_epp) \ 333 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 334 #define ppb_insw_epp(dev,buf,cnt) \ 335 (*(dev)->ppb->ppb_link->adapter->insw_epp) \ 336 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 337 #define ppb_insl_epp(dev,buf,cnt) \ 338 (*(dev)->ppb->ppb_link->adapter->insl_epp) \ 339 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 340 341 #define ppb_repp_A(dev) (*(dev)->ppb->ppb_link->adapter->r_epp_A) \ 342 ((dev)->ppb->ppb_link->adapter_unit) 343 #define ppb_repp_D(dev) (*(dev)->ppb->ppb_link->adapter->r_epp_D) \ 344 ((dev)->ppb->ppb_link->adapter_unit) 345 #define ppb_recr(dev) (*(dev)->ppb->ppb_link->adapter->r_ecr) \ 346 ((dev)->ppb->ppb_link->adapter_unit) 347 #define ppb_rfifo(dev) (*(dev)->ppb->ppb_link->adapter->r_fifo) \ 348 ((dev)->ppb->ppb_link->adapter_unit) 349 #define ppb_wepp_A(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp_A) \ 350 ((dev)->ppb->ppb_link->adapter_unit, byte) 351 #define ppb_wepp_D(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp_D) \ 352 ((dev)->ppb->ppb_link->adapter_unit, byte) 353 #define ppb_wecr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ecr) \ 354 ((dev)->ppb->ppb_link->adapter_unit, byte) 355 #define ppb_wfifo(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_fifo) \ 356 ((dev)->ppb->ppb_link->adapter_unit, byte) 357 358 #define ppb_rdtr(dev) (*(dev)->ppb->ppb_link->adapter->r_dtr) \ 359 ((dev)->ppb->ppb_link->adapter_unit) 360 #define ppb_rstr(dev) (*(dev)->ppb->ppb_link->adapter->r_str) \ 361 ((dev)->ppb->ppb_link->adapter_unit) 362 #define ppb_rctr(dev) (*(dev)->ppb->ppb_link->adapter->r_ctr) \ 363 ((dev)->ppb->ppb_link->adapter_unit) 364 #define ppb_wdtr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_dtr) \ 365 ((dev)->ppb->ppb_link->adapter_unit, byte) 366 #define ppb_wstr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_str) \ 367 ((dev)->ppb->ppb_link->adapter_unit, byte) 368 #define ppb_wctr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ctr) \ 369 ((dev)->ppb->ppb_link->adapter_unit, byte) 370 371 #endif 372