atppcvar.h revision 1.1 1 /*-
2 * Copyright (c) 2001 Alcove - 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: src/sys/isa/ppcreg.h,v 1.10.2.4 2001/10/02 05:21:45 nsouch Exp $
27 *
28 */
29
30 #ifndef __ATPPCVAR_H
31 #define __ATPPCVAR_H
32
33 #include <machine/bus.h>
34 #include <machine/types.h>
35 #include <sys/device.h>
36 #include <sys/callout.h>
37
38 #include <dev/ppbus/ppbus_conf.h>
39
40
41 /* Maximum time to wait for device response */
42 #define MAXBUSYWAIT (5 * (hz))
43
44 /* Poll interval when wating for device to become ready */
45 #define ATPPC_POLL ((hz)/10)
46
47 /* Interrupt priority level for atppc device */
48 #define IPL_ATPPC IPL_TTY
49 #define splatppc spltty
50
51
52 /* Diagnostic and verbose printing macros */
53
54 #ifdef ATPPC_DEBUG
55 extern int atppc_debug;
56 #define ATPPC_DPRINTF(arg) if(atppc_debug) printf arg
57 #else
58 #define ATPPC_DPRINTF(arg)
59 #endif
60
61 #ifdef ATPPC_VERBOSE
62 extern int atppc_verbose;
63 #define ATPPC_VPRINTF(arg) if(atppc_verbose) printf arg
64 #else
65 #define ATPPC_VPRINTF(arg)
66 #endif
67
68
69 /* Flag used in DMA transfer */
70 #define ATPPC_DMA_MODE_READ 0x0
71 #define ATPPC_DMA_MODE_WRITE 0x1
72
73
74 /* Flags passed via config */
75 #define ATPPC_FLAG_DISABLE_INTR 0x01
76 #define ATPPC_FLAG_DISABLE_DMA 0x02
77
78
79 /* Locking for atppc device */
80 #if defined(MULTIPROCESSOR) || defined (LOCKDEBUG)
81 #include <sys/lock.h>
82 #define ATPPC_SC_LOCK(sc) (&((sc)->sc_lock))
83 #define ATPPC_LOCK(sc) simple_lock(ATPPC_SC_LOCK((sc)))
84 #define ATPPC_UNLOCK(sc) simple_unlock(ATPPC_SC_LOCK((sc)))
85 #else /* !(MULTIPROCESSOR) && !(LOCKDEBUG) */
86 #define ATPPC_LOCK(sc)
87 #define ATPPC_UNLOCK(sc)
88 #define ATPPC_SC_LOCK(sc) NULL
89 #endif /* MULTIPROCESSOR || LOCKDEBUG */
90
91 /* Single softintr callback entry */
92 struct atppc_handler_node {
93 void (*func)(void *);
94 void * arg;
95 SLIST_ENTRY(atppc_handler_node) entries;
96 };
97
98 /* Generic structure to hold parallel port chipset info. */
99 struct atppc_softc {
100 /* Generic device attributes */
101 struct device sc_dev;
102
103 #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
104 /* Simple lock */
105 struct simplelock sc_lock;
106 #endif
107
108 /* Machine independent bus infrastructure */
109 bus_space_tag_t sc_iot;
110 bus_space_handle_t sc_ioh;
111 bus_dma_tag_t sc_dmat;
112 bus_dmamap_t sc_dmapt;
113 bus_size_t sc_dma_maxsize;
114
115 /* Child device */
116 struct device * child;
117
118 /* Opaque handle used for interrupt handler establishment */
119 void * sc_ieh;
120
121 /* List of soft interrupts to call */
122 SLIST_HEAD(handler_list, atppc_handler_node) sc_handler_listhead;
123
124 /* Input buffer: working pointers, and size in bytes. */
125 char * sc_inb;
126 char * sc_inbstart;
127 u_int32_t sc_inb_nbytes;
128 int sc_inerr;
129
130 /* Output buffer pointer, working pointer, and size in bytes. */
131 char * sc_outb;
132 char * sc_outbstart;
133 u_int32_t sc_outb_nbytes;
134 int sc_outerr;
135
136 /* DMA functions: setup by bus specific attach code */
137 int (*sc_dma_start)(struct atppc_softc *, void *, u_int, u_int8_t);
138 int (*sc_dma_finish)(struct atppc_softc *);
139 int (*sc_dma_abort)(struct atppc_softc *);
140 int (*sc_dma_malloc)(struct device *, caddr_t *, bus_addr_t *,
141 bus_size_t);
142 void (*sc_dma_free)(struct device *, caddr_t *, bus_addr_t *,
143 bus_size_t);
144
145 /* Microsequence related members */
146 char * sc_ptr; /* microseq current pointer */
147 int sc_accum; /* microseq accumulator */
148
149 /* Device attachment state */
150 #define ATPPC_ATTACHED 1
151 #define ATPPC_NOATTACH 0
152 u_int8_t sc_dev_ok;
153
154 /*
155 * Hardware capabilities flags: standard mode and nibble mode are
156 * assumed to always be available since if they aren't you don't
157 * HAVE a parallel port.
158 */
159 #define ATPPC_HAS_INTR 0x01 /* Interrupt available */
160 #define ATPPC_HAS_DMA 0x02 /* DMA available */
161 #define ATPPC_HAS_FIFO 0x04 /* FIFO available */
162 #define ATPPC_HAS_PS2 0x08 /* PS2 mode capable */
163 #define ATPPC_HAS_ECP 0x10 /* ECP mode available */
164 #define ATPPC_HAS_EPP 0x20 /* EPP mode available */
165 u_int8_t sc_has; /* Chipset detected capabilities */
166
167 /* Flags specifying mode of chipset operation . */
168 #define ATPPC_MODE_STD 0x01 /* Use centronics-compatible mode */
169 #define ATPPC_MODE_PS2 0x02 /* Use PS2 mode */
170 #define ATPPC_MODE_EPP 0x04 /* Use EPP mode */
171 #define ATPPC_MODE_ECP 0x08 /* Use ECP mode */
172 #define ATPPC_MODE_NIBBLE 0x10 /* Use nibble mode */
173 #define ATPPC_MODE_FAST 0x20 /* Use Fast Centronics mode */
174 u_int8_t sc_mode; /* Current operational mode */
175
176 /* Flags which further define chipset operation */
177 #define ATPPC_USE_INTR 0x01 /* Use interrupts */
178 #define ATPPC_USE_DMA 0x02 /* Use DMA */
179 u_int8_t sc_use; /* Capabilities to use */
180
181 /* Parallel Port Chipset model. */
182 #define SMC_LIKE 0
183 #define SMC_37C665GT 1
184 #define SMC_37C666GT 2
185 #define NS_PC87332 3
186 #define NS_PC87306 4
187 #define INTEL_820191AA 5 /* XXX not implemented */
188 #define GENERIC 6
189 #define WINB_W83877F 7
190 #define WINB_W83877AF 8
191 #define WINB_UNKNOWN 9
192 #define NS_PC87334 10
193 #define SMC_37C935 11
194 #define NS_PC87303 12
195 u_int8_t sc_model; /* chipset model */
196
197 /* EPP mode */
198 #define ATPPC_EPP_1_9 0x0
199 #define ATPPC_EPP_1_7 0x1
200 u_int8_t sc_epp;
201
202 /* Parallel Port Chipset Type. SMC versus GENERIC (others) */
203 #define ATPPC_TYPE_SMCLIKE 0
204 #define ATPPC_TYPE_GENERIC 1
205 u_int8_t sc_type; /* generic or smclike chipset type */
206
207 /* Stored register values after an interrupt occurs */
208 u_int8_t sc_ecr_intr;
209 u_int8_t sc_ctr_intr;
210 u_int8_t sc_str_intr;
211
212 #define ATPPC_IRQ_NONE 0x0
213 #define ATPPC_IRQ_nACK 0x1
214 #define ATPPC_IRQ_DMA 0x2
215 #define ATPPC_IRQ_FIFO 0x4
216 #define ATPPC_IRQ_nFAULT 0x8
217 u_int8_t sc_irqstat; /* Record irq settings */
218
219 #define ATPPC_DMA_INIT 0x01
220 #define ATPPC_DMA_STARTED 0x02
221 #define ATPPC_DMA_COMPLETE 0x03
222 #define ATPPC_DMA_INTERRUPTED 0x04
223 #define ATPPC_DMA_ERROR 0x05
224 u_int8_t sc_dmastat; /* Record dma state */
225
226 #define ATPPC_PWORD_MASK 0x30
227 #define ATPPC_PWORD_16 0x00
228 #define ATPPC_PWORD_8 0x10
229 #define ATPPC_PWORD_32 0x20
230 u_int8_t sc_pword; /* PWord size: used for FIFO DMA transfers */
231 u_int8_t sc_fifo; /* FIFO size */
232
233 /* Indicates number of PWords in FIFO queues that generate interrupt */
234 u_int8_t sc_wthr; /* writeIntrThresold */
235 u_int8_t sc_rthr; /* readIntrThresold */
236 };
237
238
239
240 #ifdef _KERNEL
241
242 /* Function prototypes */
243
244 /* Soft config attach/detach routines */
245 void atppc_sc_attach __P((struct atppc_softc *));
246 int atppc_sc_detach __P((struct atppc_softc *, int));
247
248 /* Detection routines */
249 int atppc_detect_port __P((bus_space_tag_t, bus_space_handle_t));
250
251 /* Interrupt handler for atppc device */
252 int atppcintr __P((void *));
253
254 #endif /* _KERNEL */
255
256 #endif /* __ATPPCVAR_H */
257