1ed381522SMike Smith /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 40f210c92SNicolas Souchu * Copyright (c) 1997, 1998, 1999 Nicolas Souchu 5ed381522SMike Smith * All rights reserved. 6ed381522SMike Smith * 7ed381522SMike Smith * Redistribution and use in source and binary forms, with or without 8ed381522SMike Smith * modification, are permitted provided that the following conditions 9ed381522SMike Smith * are met: 10ed381522SMike Smith * 1. Redistributions of source code must retain the above copyright 11ed381522SMike Smith * notice, this list of conditions and the following disclaimer. 12ed381522SMike Smith * 2. Redistributions in binary form must reproduce the above copyright 13ed381522SMike Smith * notice, this list of conditions and the following disclaimer in the 14ed381522SMike Smith * documentation and/or other materials provided with the distribution. 15ed381522SMike Smith * 16ed381522SMike Smith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17ed381522SMike Smith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18ed381522SMike Smith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19ed381522SMike Smith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20ed381522SMike Smith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21ed381522SMike Smith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22ed381522SMike Smith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23ed381522SMike Smith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24ed381522SMike Smith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25ed381522SMike Smith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26ed381522SMike Smith * SUCH DAMAGE. 27ed381522SMike Smith * 28ed381522SMike Smith */ 29ed381522SMike Smith #ifndef __PPBCONF_H 30ed381522SMike Smith #define __PPBCONF_H 31ed381522SMike Smith 32e2f76caeSJohn Baldwin #define n(flags) (~(flags) & (flags)) 33e2f76caeSJohn Baldwin 34e2f76caeSJohn Baldwin /* 35e2f76caeSJohn Baldwin * Parallel Port Chipset control bits. 36e2f76caeSJohn Baldwin */ 37e2f76caeSJohn Baldwin #define STROBE 0x01 38e2f76caeSJohn Baldwin #define AUTOFEED 0x02 39e2f76caeSJohn Baldwin #define nINIT 0x04 40e2f76caeSJohn Baldwin #define SELECTIN 0x08 41e2f76caeSJohn Baldwin #define IRQENABLE 0x10 42e2f76caeSJohn Baldwin #define PCD 0x20 43e2f76caeSJohn Baldwin 44e2f76caeSJohn Baldwin #define nSTROBE n(STROBE) 45e2f76caeSJohn Baldwin #define nAUTOFEED n(AUTOFEED) 46e2f76caeSJohn Baldwin #define INIT n(nINIT) 47e2f76caeSJohn Baldwin #define nSELECTIN n(SELECTIN) 48e2f76caeSJohn Baldwin #define nPCD n(PCD) 49e2f76caeSJohn Baldwin 50e2f76caeSJohn Baldwin /* 51e2f76caeSJohn Baldwin * Parallel Port Chipset status bits. 52e2f76caeSJohn Baldwin */ 53e2f76caeSJohn Baldwin #define TIMEOUT 0x01 54e2f76caeSJohn Baldwin #define nFAULT 0x08 55e2f76caeSJohn Baldwin #define SELECT 0x10 56e2f76caeSJohn Baldwin #define PERROR 0x20 57e2f76caeSJohn Baldwin #define nACK 0x40 58e2f76caeSJohn Baldwin #define nBUSY 0x80 59e2f76caeSJohn Baldwin 60e2f76caeSJohn Baldwin #ifdef _KERNEL 6151f480dfSBruce Evans #include <sys/queue.h> 6251f480dfSBruce Evans 63ed381522SMike Smith /* 64e51b0386SMike Smith * Parallel Port Bus sleep/wakeup queue. 65e51b0386SMike Smith */ 66*8ecc4191SOlivier Certner #define PPBPRI (PWAIT) 67e51b0386SMike Smith 68e51b0386SMike Smith /* 6946f3ff79SMike Smith * Parallel Port Chipset mode masks. 7046f3ff79SMike Smith * NIBBLE mode is supposed to be available under each other modes. 71ed381522SMike Smith */ 7246f3ff79SMike Smith #define PPB_COMPATIBLE 0x0 /* Centronics compatible mode */ 7346f3ff79SMike Smith 7446f3ff79SMike Smith #define PPB_NIBBLE 0x1 /* reverse 4 bit mode */ 75ed381522SMike Smith #define PPB_PS2 0x2 /* PS/2 byte mode */ 7646f3ff79SMike Smith #define PPB_EPP 0x4 /* EPP mode, 32 bit */ 7746f3ff79SMike Smith #define PPB_ECP 0x8 /* ECP mode */ 78ed381522SMike Smith 79bc35c174SNicolas Souchu /* mode aliases */ 8046f3ff79SMike Smith #define PPB_SPP PPB_NIBBLE|PPB_PS2 81bc35c174SNicolas Souchu #define PPB_BYTE PPB_PS2 82bc35c174SNicolas Souchu 83bc35c174SNicolas Souchu #define PPB_MASK 0x0f 84bc35c174SNicolas Souchu #define PPB_OPTIONS_MASK 0xf0 85ed381522SMike Smith 8646f3ff79SMike Smith #define PPB_IS_EPP(mode) (mode & PPB_EPP) 870f210c92SNicolas Souchu #define PPB_IN_EPP_MODE(bus) (PPB_IS_EPP (ppb_get_mode (bus))) 880f210c92SNicolas Souchu #define PPB_IN_NIBBLE_MODE(bus) (ppb_get_mode (bus) & PPB_NIBBLE) 890f210c92SNicolas Souchu #define PPB_IN_PS2_MODE(bus) (ppb_get_mode (bus) & PPB_PS2) 90ed381522SMike Smith 91ed381522SMike Smith /* 92ed381522SMike Smith * Structure to store status information. 93ed381522SMike Smith */ 94ed381522SMike Smith struct ppb_status { 95ed381522SMike Smith unsigned char status; 96ed381522SMike Smith 97ed381522SMike Smith unsigned int timeout:1; 98ed381522SMike Smith unsigned int error:1; 99ed381522SMike Smith unsigned int select:1; 100ed381522SMike Smith unsigned int paper_end:1; 101ed381522SMike Smith unsigned int ack:1; 102ed381522SMike Smith unsigned int busy:1; 103ed381522SMike Smith }; 104ed381522SMike Smith 1050f210c92SNicolas Souchu /* Parallel port bus I/O opcodes */ 1060f210c92SNicolas Souchu #define PPB_OUTSB_EPP 1 1070f210c92SNicolas Souchu #define PPB_OUTSW_EPP 2 1080f210c92SNicolas Souchu #define PPB_OUTSL_EPP 3 1090f210c92SNicolas Souchu #define PPB_INSB_EPP 4 1100f210c92SNicolas Souchu #define PPB_INSW_EPP 5 1110f210c92SNicolas Souchu #define PPB_INSL_EPP 6 1120f210c92SNicolas Souchu #define PPB_RDTR 7 1130f210c92SNicolas Souchu #define PPB_RSTR 8 1140f210c92SNicolas Souchu #define PPB_RCTR 9 1150f210c92SNicolas Souchu #define PPB_REPP_A 10 1160f210c92SNicolas Souchu #define PPB_REPP_D 11 1170f210c92SNicolas Souchu #define PPB_RECR 12 1180f210c92SNicolas Souchu #define PPB_RFIFO 13 1190f210c92SNicolas Souchu #define PPB_WDTR 14 1200f210c92SNicolas Souchu #define PPB_WSTR 15 1210f210c92SNicolas Souchu #define PPB_WCTR 16 1220f210c92SNicolas Souchu #define PPB_WEPP_A 17 1230f210c92SNicolas Souchu #define PPB_WEPP_D 18 1240f210c92SNicolas Souchu #define PPB_WECR 19 1250f210c92SNicolas Souchu #define PPB_WFIFO 20 1260f210c92SNicolas Souchu 127ed381522SMike Smith /* 128ed381522SMike Smith * How tsleep() is called in ppb_request_bus(). 129ed381522SMike Smith */ 130ed381522SMike Smith #define PPB_DONTWAIT 0 131ed381522SMike Smith #define PPB_NOINTR 0 132ed381522SMike Smith #define PPB_WAIT 0x1 133ed381522SMike Smith #define PPB_INTR 0x2 134bc35c174SNicolas Souchu #define PPB_POLL 0x4 135bc35c174SNicolas Souchu #define PPB_FOREVER -1 136ed381522SMike Smith 13746f3ff79SMike Smith /* 13846f3ff79SMike Smith * Microsequence stuff. 13946f3ff79SMike Smith */ 14046f3ff79SMike Smith #define PPB_MS_MAXLEN 64 /* XXX according to MS_INS_MASK */ 14146f3ff79SMike Smith #define PPB_MS_MAXARGS 3 /* according to MS_ARG_MASK */ 14246f3ff79SMike Smith 14346f3ff79SMike Smith /* maximum number of mode dependent 14446f3ff79SMike Smith * submicrosequences for in/out operations 14546f3ff79SMike Smith */ 14646f3ff79SMike Smith #define PPB_MAX_XFER 6 14746f3ff79SMike Smith 14846f3ff79SMike Smith union ppb_insarg { 14946f3ff79SMike Smith int i; 15046f3ff79SMike Smith void *p; 1515734634fSPeter Wemm char *c; 15246f3ff79SMike Smith int (* f)(void *, char *); 15346f3ff79SMike Smith }; 15446f3ff79SMike Smith 15546f3ff79SMike Smith struct ppb_microseq { 15646f3ff79SMike Smith int opcode; /* microins. opcode */ 15746f3ff79SMike Smith union ppb_insarg arg[PPB_MS_MAXARGS]; /* arguments */ 15846f3ff79SMike Smith }; 15946f3ff79SMike Smith 16046f3ff79SMike Smith /* microseqences used for GET/PUT operations */ 16146f3ff79SMike Smith struct ppb_xfer { 16246f3ff79SMike Smith struct ppb_microseq *loop; /* the loop microsequence */ 16346f3ff79SMike Smith }; 164ed381522SMike Smith 165ed381522SMike Smith /* 166ed381522SMike Smith * Parallel Port Bus Device structure. 167ed381522SMike Smith */ 16846f3ff79SMike Smith struct ppb_data; /* see below */ 16946f3ff79SMike Smith 17046f3ff79SMike Smith struct ppb_context { 17146f3ff79SMike Smith int valid; /* 1 if the struct is valid */ 17246f3ff79SMike Smith int mode; /* XXX chipset operating mode */ 17346f3ff79SMike Smith 17446f3ff79SMike Smith struct microseq *curpc; /* pc in curmsq */ 17546f3ff79SMike Smith struct microseq *curmsq; /* currently executed microseqence */ 17646f3ff79SMike Smith }; 17746f3ff79SMike Smith 1780f210c92SNicolas Souchu /* 1790f210c92SNicolas Souchu * List of IVARS available to ppb device drivers 1800f210c92SNicolas Souchu */ 1810f210c92SNicolas Souchu #define PPBUS_IVAR_MODE 0 1820f210c92SNicolas Souchu 1830f210c92SNicolas Souchu /* other fields are reserved to the ppbus internals */ 1840f210c92SNicolas Souchu 185ed381522SMike Smith struct ppb_device { 1860f210c92SNicolas Souchu const char *name; /* name of the device */ 18746f3ff79SMike Smith 1888b149b51SJohn Baldwin u_int flags; /* flags */ 18946f3ff79SMike Smith 19046f3ff79SMike Smith struct ppb_context ctx; /* context of the device */ 19146f3ff79SMike Smith 19246f3ff79SMike Smith /* mode dependent get msq. If NULL, 19346f3ff79SMike Smith * IEEE1284 code is used */ 19446f3ff79SMike Smith struct ppb_xfer 19546f3ff79SMike Smith get_xfer[PPB_MAX_XFER]; 19646f3ff79SMike Smith 19746f3ff79SMike Smith /* mode dependent put msq. If NULL, 19846f3ff79SMike Smith * IEEE1284 code is used */ 19946f3ff79SMike Smith struct ppb_xfer 20046f3ff79SMike Smith put_xfer[PPB_MAX_XFER]; 201ed381522SMike Smith 2022067d312SJohn Baldwin driver_intr_t *intr_hook; 2032067d312SJohn Baldwin void *intr_arg; 204ed381522SMike Smith }; 205ed381522SMike Smith 2060f210c92SNicolas Souchu /* EPP standards */ 207ed381522SMike Smith #define EPP_1_9 0x0 /* default */ 208ed381522SMike Smith #define EPP_1_7 0x1 209ed381522SMike Smith 2100f210c92SNicolas Souchu /* Parallel Port Chipset IVARS */ /* elsewhere XXX */ 2110f210c92SNicolas Souchu #define PPC_IVAR_EPP_PROTO 0 2122067d312SJohn Baldwin #define PPC_IVAR_LOCK 1 2132067d312SJohn Baldwin #define PPC_IVAR_INTR_HANDLER 2 214ed381522SMike Smith 215ed381522SMike Smith /* 216e51b0386SMike Smith * Maximum size of the PnP info string 217e51b0386SMike Smith */ 218bc35c174SNicolas Souchu #define PPB_PnP_STRING_SIZE 256 /* XXX */ 219e51b0386SMike Smith 220e51b0386SMike Smith /* 221ed381522SMike Smith * Parallel Port Bus structure. 222ed381522SMike Smith */ 223ed381522SMike Smith struct ppb_data { 224e51b0386SMike Smith #define PPB_PnP_PRINTER 0 225e51b0386SMike Smith #define PPB_PnP_MODEM 1 226e51b0386SMike Smith #define PPB_PnP_NET 2 227e51b0386SMike Smith #define PPB_PnP_HDC 3 228e51b0386SMike Smith #define PPB_PnP_PCMCIA 4 229e51b0386SMike Smith #define PPB_PnP_MEDIA 5 230e51b0386SMike Smith #define PPB_PnP_FDC 6 231e51b0386SMike Smith #define PPB_PnP_PORTS 7 232e51b0386SMike Smith #define PPB_PnP_SCANNER 8 233e51b0386SMike Smith #define PPB_PnP_DIGICAM 9 234e51b0386SMike Smith #define PPB_PnP_UNKNOWN 10 235e51b0386SMike Smith int class_id; /* not a PnP device if class_id < 0 */ 236e51b0386SMike Smith 237bc35c174SNicolas Souchu int state; /* current IEEE1284 state */ 238bc35c174SNicolas Souchu int error; /* last IEEE1284 error */ 239bc35c174SNicolas Souchu 2400f210c92SNicolas Souchu int mode; /* IEEE 1284-1994 mode 24146f3ff79SMike Smith * NIBBLE, PS2, EPP or ECP */ 24246f3ff79SMike Smith 2432067d312SJohn Baldwin device_t ppb_owner; /* device which owns the bus */ 2442067d312SJohn Baldwin 2452067d312SJohn Baldwin struct mtx *ppc_lock; /* lock of parent device */ 2462067d312SJohn Baldwin struct resource *ppc_irq_res; 247ed381522SMike Smith }; 248ed381522SMike Smith 2492067d312SJohn Baldwin struct callout; 2502067d312SJohn Baldwin 2512067d312SJohn Baldwin typedef int (*ppc_intr_handler)(void *); 2522067d312SJohn Baldwin 2530f210c92SNicolas Souchu extern int ppb_attach_device(device_t); 2540f210c92SNicolas Souchu extern int ppb_request_bus(device_t, device_t, int); 2550f210c92SNicolas Souchu extern int ppb_release_bus(device_t, device_t); 256ed381522SMike Smith 2570f210c92SNicolas Souchu /* bus related functions */ 2582067d312SJohn Baldwin extern void ppb_lock(device_t); 2592067d312SJohn Baldwin extern void ppb_unlock(device_t); 260c62aa65bSWarner Losh extern struct mtx *ppb_get_lock(device_t); 2612067d312SJohn Baldwin extern void _ppb_assert_locked(device_t, const char *, int); 2622067d312SJohn Baldwin extern void ppb_init_callout(device_t, struct callout *, int); 2632067d312SJohn Baldwin extern int ppb_sleep(device_t, void *, int, const char *, int); 2640f210c92SNicolas Souchu extern int ppb_get_status(device_t, struct ppb_status *); 2653128fa9aSDimitry Andric extern int ppb_poll_bus(device_t, int, uint8_t, uint8_t, int); 2660f210c92SNicolas Souchu extern int ppb_reset_epp_timeout(device_t); 2670f210c92SNicolas Souchu extern int ppb_ecp_sync(device_t); 2680f210c92SNicolas Souchu extern int ppb_get_epp_protocol(device_t); 2690f210c92SNicolas Souchu extern int ppb_set_mode(device_t, int); /* returns old mode */ 2700f210c92SNicolas Souchu extern int ppb_get_mode(device_t); /* returns current mode */ 2710f210c92SNicolas Souchu extern int ppb_write(device_t, char *, int, int); 2722067d312SJohn Baldwin 2732067d312SJohn Baldwin #ifdef INVARIANTS 2742067d312SJohn Baldwin #define ppb_assert_locked(dev) _ppb_assert_locked(dev, __FILE__, __LINE__) 2752067d312SJohn Baldwin #else 2762067d312SJohn Baldwin #define ppb_assert_locked(dev) 2772067d312SJohn Baldwin #endif 2787fe1aacaSNick Hibma #endif /* _KERNEL */ 279ed381522SMike Smith 2802067d312SJohn Baldwin #endif /* !__PPBCONF_H */ 281