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