1 /*- 2 * Copyright (c) 1997 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.4 1997/09/01 00:51:48 bde 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 modes. 41 */ 42 #define PPB_AUTODETECT 0x0 /* autodetect */ 43 #define PPB_NIBBLE 0x1 /* standard 4 bit mode */ 44 #define PPB_PS2 0x2 /* PS/2 byte mode */ 45 #define PPB_EPP 0x3 /* EPP mode, 32 bit */ 46 #define PPB_ECP_EPP 0x4 /* ECP in EPP mode */ 47 #define PPB_ECP_PS2 0x5 /* ECP in PS/2 mode */ 48 #define PPB_ECP 0x6 /* ECP mode */ 49 #define PPB_UNKNOWN 0x7 /* the last one */ 50 51 #define PPB_IS_EPP(mode) (mode == PPB_EPP || mode == PPB_ECP_EPP) 52 53 #define PPB_IN_EPP_MODE(dev) (PPB_IS_EPP (ppb_get_mode (dev))) 54 55 /* 56 * Parallel Port Chipset control bits. 57 */ 58 #define STROBE 0x01 59 #define AUTOFEED 0x02 60 #define nINIT 0x04 61 #define SELECTIN 0x08 62 #define PCD 0x20 63 64 /* 65 * Parallel Port Chipset status bits. 66 */ 67 #define TIMEOUT 0x01 68 #define nFAULT 0x08 69 #define SELECT 0x10 70 #define ERROR 0x20 71 #define nACK 0x40 72 #define nBUSY 0x80 73 74 /* 75 * Structure to store status information. 76 */ 77 struct ppb_status { 78 unsigned char status; 79 80 unsigned int timeout:1; 81 unsigned int error:1; 82 unsigned int select:1; 83 unsigned int paper_end:1; 84 unsigned int ack:1; 85 unsigned int busy:1; 86 }; 87 88 /* 89 * How tsleep () is called in ppb_request_bus (). 90 */ 91 #define PPB_DONTWAIT 0 92 #define PPB_NOINTR 0 93 #define PPB_WAIT 0x1 94 #define PPB_INTR 0x2 95 96 struct ppb_data; /* see below */ 97 98 /* 99 * Parallel Port Bus Device structure. 100 */ 101 struct ppb_device { 102 103 int id_unit; /* unit of the device */ 104 105 void (*intr)(int); /* interrupt handler */ 106 107 struct ppb_data *ppb; /* link to the ppbus */ 108 109 LIST_ENTRY(ppb_device) chain; /* list of devices on the bus */ 110 }; 111 112 /* 113 * Parallel Port Bus Adapter structure. 114 */ 115 struct ppb_adapter { 116 117 void (*intr_handler)(int); 118 void (*reset_epp_timeout)(int); 119 void (*ecp_sync)(int); 120 121 void (*outsb_epp)(int, char *, int); 122 void (*outsw_epp)(int, char *, int); 123 void (*outsl_epp)(int, char *, int); 124 void (*insb_epp)(int, char *, int); 125 void (*insw_epp)(int, char *, int); 126 void (*insl_epp)(int, char *, int); 127 128 char (*r_dtr)(int); 129 char (*r_str)(int); 130 char (*r_ctr)(int); 131 char (*r_epp)(int); 132 char (*r_ecr)(int); 133 char (*r_fifo)(int); 134 135 void (*w_dtr)(int, char); 136 void (*w_str)(int, char); 137 void (*w_ctr)(int, char); 138 void (*w_epp)(int, char); 139 void (*w_ecr)(int, char); 140 void (*w_fifo)(int, char); 141 }; 142 143 /* 144 * ppb_link structure. 145 */ 146 struct ppb_link { 147 148 int adapter_unit; /* unit of the adapter */ 149 150 int base; /* base address of the port */ 151 int id_irq; /* != 0 if irq enabled */ 152 int mode; /* NIBBLE, PS2, EPP, ECP */ 153 154 #define EPP_1_9 0x0 /* default */ 155 #define EPP_1_7 0x1 156 157 int epp_protocol; /* EPP protocol: 0=1.9, 1=1.7 */ 158 159 struct ppb_adapter *adapter; /* link to the ppc adapter */ 160 struct ppb_data *ppbus; /* link to the ppbus */ 161 }; 162 163 /* 164 * Maximum size of the PnP info string 165 */ 166 #define PPB_PnP_STRING_SIZE 160 /* XXX */ 167 168 /* 169 * Parallel Port Bus structure. 170 */ 171 struct ppb_data { 172 173 #define PPB_PnP_PRINTER 0 174 #define PPB_PnP_MODEM 1 175 #define PPB_PnP_NET 2 176 #define PPB_PnP_HDC 3 177 #define PPB_PnP_PCMCIA 4 178 #define PPB_PnP_MEDIA 5 179 #define PPB_PnP_FDC 6 180 #define PPB_PnP_PORTS 7 181 #define PPB_PnP_SCANNER 8 182 #define PPB_PnP_DIGICAM 9 183 #define PPB_PnP_UNKNOWN 10 184 int class_id; /* not a PnP device if class_id < 0 */ 185 186 struct ppb_link *ppb_link; /* link to the adapter */ 187 struct ppb_device *ppb_owner; /* device which owns the bus */ 188 LIST_HEAD(, ppb_device) ppb_devs; /* list of devices on the bus */ 189 LIST_ENTRY(ppb_data) ppb_chain; /* list of busses */ 190 }; 191 192 /* 193 * Parallel Port Bus driver structure. 194 */ 195 struct ppb_driver 196 { 197 struct ppb_device *(*probe)(struct ppb_data *ppb); 198 int (*attach)(struct ppb_device *pdp); 199 char *name; 200 }; 201 202 extern struct linker_set ppbdriver_set; 203 204 extern struct ppb_data *ppb_alloc_bus(void); 205 extern struct ppb_data *ppb_next_bus(struct ppb_data *); 206 extern struct ppb_data *ppb_lookup_bus(int); 207 208 extern int ppb_attach_device(struct ppb_device *); 209 extern void ppb_remove_device(struct ppb_device *); 210 extern int ppb_attachdevs(struct ppb_data *); 211 212 extern int ppb_request_bus(struct ppb_device *, int); 213 extern int ppb_release_bus(struct ppb_device *); 214 215 extern void ppb_intr(struct ppb_link *); 216 217 extern int ppb_poll_device(struct ppb_device *, int, char, char, int); 218 219 extern int ppb_reset_epp_timeout(struct ppb_device *); 220 extern int ppb_ecp_sync(struct ppb_device *); 221 extern int ppb_get_status(struct ppb_device *, struct ppb_status *); 222 extern int ppb_get_mode(struct ppb_device *); 223 extern int ppb_get_epp_protocol(struct ppb_device *); 224 extern int ppb_get_irq(struct ppb_device *); 225 226 /* 227 * These are defined as macros for speedup. 228 */ 229 #define ppb_outsb_epp(dev,buf,cnt) \ 230 (*(dev)->ppb->ppb_link->adapter->outsb_epp) \ 231 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 232 #define ppb_outsw_epp(dev,buf,cnt) \ 233 (*(dev)->ppb->ppb_link->adapter->outsw_epp) \ 234 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 235 #define ppb_outsl_epp(dev,buf,cnt) \ 236 (*(dev)->ppb->ppb_link->adapter->outsl_epp) \ 237 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 238 #define ppb_insb_epp(dev,buf,cnt) \ 239 (*(dev)->ppb->ppb_link->adapter->insb_epp) \ 240 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 241 #define ppb_insw_epp(dev,buf,cnt) \ 242 (*(dev)->ppb->ppb_link->adapter->insw_epp) \ 243 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 244 #define ppb_insl_epp(dev,buf,cnt) \ 245 (*(dev)->ppb->ppb_link->adapter->insl_epp) \ 246 ((dev)->ppb->ppb_link->adapter_unit, buf, cnt) 247 248 #define ppb_rdtr(dev) (*(dev)->ppb->ppb_link->adapter->r_dtr) \ 249 ((dev)->ppb->ppb_link->adapter_unit) 250 #define ppb_rstr(dev) (*(dev)->ppb->ppb_link->adapter->r_str) \ 251 ((dev)->ppb->ppb_link->adapter_unit) 252 #define ppb_rctr(dev) (*(dev)->ppb->ppb_link->adapter->r_ctr) \ 253 ((dev)->ppb->ppb_link->adapter_unit) 254 #define ppb_repp(dev) (*(dev)->ppb->ppb_link->adapter->r_epp) \ 255 ((dev)->ppb->ppb_link->adapter_unit) 256 #define ppb_recr(dev) (*(dev)->ppb->ppb_link->adapter->r_ecr) \ 257 ((dev)->ppb->ppb_link->adapter_unit) 258 #define ppb_rfifo(dev) (*(dev)->ppb->ppb_link->adapter->r_fifo) \ 259 ((dev)->ppb->ppb_link->adapter_unit) 260 261 #define ppb_wdtr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_dtr) \ 262 ((dev)->ppb->ppb_link->adapter_unit, byte) 263 #define ppb_wstr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_str) \ 264 ((dev)->ppb->ppb_link->adapter_unit, byte) 265 #define ppb_wctr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ctr) \ 266 ((dev)->ppb->ppb_link->adapter_unit, byte) 267 #define ppb_wepp(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_epp) \ 268 ((dev)->ppb->ppb_link->adapter_unit, byte) 269 #define ppb_wecr(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_ecr) \ 270 ((dev)->ppb->ppb_link->adapter_unit, byte) 271 #define ppb_wfifo(dev,byte) (*(dev)->ppb->ppb_link->adapter->w_fifo) \ 272 ((dev)->ppb->ppb_link->adapter_unit, byte) 273 274 #endif 275