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