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