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.13 1999/01/30 15:35:39 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 */ 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 char *c; 129 int (* f)(void *, char *); 130 }; 131 132 struct ppb_microseq { 133 int opcode; /* microins. opcode */ 134 union ppb_insarg arg[PPB_MS_MAXARGS]; /* arguments */ 135 }; 136 137 /* microseqences used for GET/PUT operations */ 138 struct ppb_xfer { 139 struct ppb_microseq *loop; /* the loop microsequence */ 140 }; 141 142 /* 143 * Parallel Port Bus Device structure. 144 */ 145 struct ppb_data; /* see below */ 146 147 struct ppb_context { 148 int valid; /* 1 if the struct is valid */ 149 int mode; /* XXX chipset operating mode */ 150 151 struct microseq *curpc; /* pc in curmsq */ 152 struct microseq *curmsq; /* currently executed microseqence */ 153 }; 154 155 struct ppb_device { 156 157 int id_unit; /* unit of the device */ 158 char *name; /* name of the device */ 159 160 ushort mode; /* current mode of the device */ 161 ushort avm; /* available IEEE1284 modes of 162 * the device */ 163 164 struct ppb_context ctx; /* context of the device */ 165 166 /* mode dependent get msq. If NULL, 167 * IEEE1284 code is used */ 168 struct ppb_xfer 169 get_xfer[PPB_MAX_XFER]; 170 171 /* mode dependent put msq. If NULL, 172 * IEEE1284 code is used */ 173 struct ppb_xfer 174 put_xfer[PPB_MAX_XFER]; 175 176 void (*intr)(int); /* interrupt handler */ 177 178 struct ppb_data *ppb; /* link to the ppbus */ 179 180 LIST_ENTRY(ppb_device) chain; /* list of devices on the bus */ 181 }; 182 183 /* 184 * Parallel Port Bus Adapter structure. 185 */ 186 struct ppb_adapter { 187 188 void (*intr_handler)(int); 189 void (*reset_epp_timeout)(int); 190 void (*ecp_sync)(int); 191 192 int (*exec_microseq)(int, struct ppb_microseq **); 193 194 int (*setmode)(int, int); 195 int (*read)(int, char *, int, int); 196 int (*write)(int, char *, int, int); 197 198 void (*outsb_epp)(int, char *, int); 199 void (*outsw_epp)(int, char *, int); 200 void (*outsl_epp)(int, char *, int); 201 void (*insb_epp)(int, char *, int); 202 void (*insw_epp)(int, char *, int); 203 void (*insl_epp)(int, char *, int); 204 205 u_char (*r_dtr)(int); 206 u_char (*r_str)(int); 207 u_char (*r_ctr)(int); 208 u_char (*r_epp_A)(int); 209 u_char (*r_epp_D)(int); 210 u_char (*r_ecr)(int); 211 u_char (*r_fifo)(int); 212 213 void (*w_dtr)(int, char); 214 void (*w_str)(int, char); 215 void (*w_ctr)(int, char); 216 void (*w_epp_A)(int, char); 217 void (*w_epp_D)(int, char); 218 void (*w_ecr)(int, char); 219 void (*w_fifo)(int, char); 220 }; 221 222 /* 223 * ppb_link structure. 224 */ 225 struct ppb_link { 226 227 int adapter_unit; /* unit of the adapter */ 228 int base; /* base address of the port */ 229 int id_irq; /* != 0 if irq enabled */ 230 int accum; /* microseq accum */ 231 char *ptr; /* current buffer pointer */ 232 233 #define EPP_1_9 0x0 /* default */ 234 #define EPP_1_7 0x1 235 236 int epp_protocol; /* EPP protocol: 0=1.9, 1=1.7 */ 237 238 struct ppb_adapter *adapter; /* link to the ppc adapter */ 239 struct ppb_data *ppbus; /* link to the ppbus */ 240 }; 241 242 /* 243 * Maximum size of the PnP info string 244 */ 245 #define PPB_PnP_STRING_SIZE 256 /* XXX */ 246 247 /* 248 * Parallel Port Bus structure. 249 */ 250 struct ppb_data { 251 252 #define PPB_PnP_PRINTER 0 253 #define PPB_PnP_MODEM 1 254 #define PPB_PnP_NET 2 255 #define PPB_PnP_HDC 3 256 #define PPB_PnP_PCMCIA 4 257 #define PPB_PnP_MEDIA 5 258 #define PPB_PnP_FDC 6 259 #define PPB_PnP_PORTS 7 260 #define PPB_PnP_SCANNER 8 261 #define PPB_PnP_DIGICAM 9 262 #define PPB_PnP_UNKNOWN 10 263 int class_id; /* not a PnP device if class_id < 0 */ 264 265 int state; /* current IEEE1284 state */ 266 int error; /* last IEEE1284 error */ 267 268 ushort mode; /* IEEE 1284-1994 mode 269 * NIBBLE, PS2, EPP or ECP */ 270 271 struct ppb_link *ppb_link; /* link to the adapter */ 272 struct ppb_device *ppb_owner; /* device which owns the bus */ 273 LIST_HEAD(, ppb_device) ppb_devs; /* list of devices on the bus */ 274 LIST_ENTRY(ppb_data) ppb_chain; /* list of busses */ 275 }; 276 277 /* 278 * Parallel Port Bus driver structure. 279 */ 280 struct ppb_driver 281 { 282 struct ppb_device *(*probe)(struct ppb_data *ppb); 283 int (*attach)(struct ppb_device *pdp); 284 char *name; 285 }; 286 287 extern struct linker_set ppbdriver_set; 288 289 extern struct ppb_data *ppb_alloc_bus(void); 290 extern struct ppb_data *ppb_next_bus(struct ppb_data *); 291 extern struct ppb_data *ppb_lookup_bus(int); 292 extern struct ppb_data *ppb_lookup_link(int); 293 294 extern int ppb_attach_device(struct ppb_device *); 295 extern void ppb_remove_device(struct ppb_device *); 296 extern int ppb_attachdevs(struct ppb_data *); 297 298 extern int ppb_request_bus(struct ppb_device *, int); 299 extern int ppb_release_bus(struct ppb_device *); 300 301 extern void ppb_intr(struct ppb_link *); 302 303 extern int ppb_poll_device(struct ppb_device *, int, char, char, int); 304 305 extern int ppb_reset_epp_timeout(struct ppb_device *); 306 extern int ppb_ecp_sync(struct ppb_device *); 307 extern int ppb_get_status(struct ppb_device *, struct ppb_status *); 308 309 extern int ppb_set_mode(struct ppb_device *, int); 310 extern int ppb_write(struct ppb_device *, char *, int, int); 311 312 /* 313 * These are defined as macros for speedup. 314 */ 315 #define ppb_get_base_addr(dev) ((dev)->ppb->ppb_link->base) 316 #define ppb_get_epp_protocol(dev) ((dev)->ppb->ppb_link->epp_protocol) 317 #define ppb_get_irq(dev) ((dev)->ppb->ppb_link->id_irq) 318 319 #define ppb_get_mode(dev) ((dev)->mode) 320 321 /* This set of function access only to the EPP _data_ registers 322 * in 8, 16 and 32 bit modes */ 323 #define ppb_outsb_epp(dev,buf,cnt) \ 324 (*(dev)->ppb->ppb_link->adapter->outsb_epp) \ 325 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 326 #define ppb_outsw_epp(dev,buf,cnt) \ 327 (*(dev)->ppb->ppb_link->adapter->outsw_epp) \ 328 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 329 #define ppb_outsl_epp(dev,buf,cnt) \ 330 (*(dev)->ppb->ppb_link->adapter->outsl_epp) \ 331 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 332 #define ppb_insb_epp(dev,buf,cnt) \ 333 (*(dev)->ppb->ppb_link->adapter->insb_epp) \ 334 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 335 #define ppb_insw_epp(dev,buf,cnt) \ 336 (*(dev)->ppb->ppb_link->adapter->insw_epp) \ 337 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 338 #define ppb_insl_epp(dev,buf,cnt) \ 339 (*(dev)->ppb->ppb_link->adapter->insl_epp) \ 340 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 341 342 #define ppb_repp_A(dev) (*(dev)->ppb->ppb_link->adapter->r_epp_A) \ 343 ((dev)->ppb->ppb_link->adapter_unit) 344 #define ppb_repp_D(dev) (*(dev)->ppb->ppb_link->adapter->r_epp_D) \ 345 ((dev)->ppb->ppb_link->adapter_unit) 346 #define ppb_recr(dev) (*(dev)->ppb->ppb_link->adapter->r_ecr) \ 347 ((dev)->ppb->ppb_link->adapter_unit) 348 #define ppb_rfifo(dev) (*(dev)->ppb->ppb_link->adapter->r_fifo) \ 349 ((dev)->ppb->ppb_link->adapter_unit) 350 #define ppb_wepp_A(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp_A) \ 351 ((dev)->ppb->ppb_link->adapter_unit, byte) 352 #define ppb_wepp_D(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp_D) \ 353 ((dev)->ppb->ppb_link->adapter_unit, byte) 354 #define ppb_wecr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ecr) \ 355 ((dev)->ppb->ppb_link->adapter_unit, byte) 356 #define ppb_wfifo(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_fifo) \ 357 ((dev)->ppb->ppb_link->adapter_unit, byte) 358 359 #define ppb_rdtr(dev) (*(dev)->ppb->ppb_link->adapter->r_dtr) \ 360 ((dev)->ppb->ppb_link->adapter_unit) 361 #define ppb_rstr(dev) (*(dev)->ppb->ppb_link->adapter->r_str) \ 362 ((dev)->ppb->ppb_link->adapter_unit) 363 #define ppb_rctr(dev) (*(dev)->ppb->ppb_link->adapter->r_ctr) \ 364 ((dev)->ppb->ppb_link->adapter_unit) 365 #define ppb_wdtr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_dtr) \ 366 ((dev)->ppb->ppb_link->adapter_unit, byte) 367 #define ppb_wstr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_str) \ 368 ((dev)->ppb->ppb_link->adapter_unit, byte) 369 #define ppb_wctr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ctr) \ 370 ((dev)->ppb->ppb_link->adapter_unit, byte) 371 372 #endif 373