tcic2var.h revision 1.1 1 1.1 bad /* $NetBSD: tcic2var.h,v 1.1 1999/03/23 20:04:14 bad Exp $ */
2 1.1 bad
3 1.1 bad /*
4 1.1 bad * Copyright (c) 1998, 1999 Christoph Badura. All rights reserved.
5 1.1 bad * Copyright (c) 1997 Marc Horowitz. All rights reserved.
6 1.1 bad *
7 1.1 bad * Redistribution and use in source and binary forms, with or without
8 1.1 bad * modification, are permitted provided that the following conditions
9 1.1 bad * are met:
10 1.1 bad * 1. Redistributions of source code must retain the above copyright
11 1.1 bad * notice, this list of conditions and the following disclaimer.
12 1.1 bad * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 bad * notice, this list of conditions and the following disclaimer in the
14 1.1 bad * documentation and/or other materials provided with the distribution.
15 1.1 bad * 3. All advertising materials mentioning features or use of this software
16 1.1 bad * must display the following acknowledgement:
17 1.1 bad * This product includes software developed by Marc Horowitz.
18 1.1 bad * 4. The name of the author may not be used to endorse or promote products
19 1.1 bad * derived from this software without specific prior written permission.
20 1.1 bad *
21 1.1 bad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 bad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 bad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 bad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 bad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 bad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 bad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 bad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 bad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 bad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 bad */
32 1.1 bad
33 1.1 bad #ifndef _TCIC2VAR_H
34 1.1 bad #define _TCIC2VAR_H
35 1.1 bad
36 1.1 bad #include <sys/device.h>
37 1.1 bad
38 1.1 bad #include <dev/pcmcia/pcmciareg.h>
39 1.1 bad #include <dev/pcmcia/pcmciachip.h>
40 1.1 bad
41 1.1 bad #include <dev/ic/tcic2reg.h>
42 1.1 bad
43 1.1 bad struct proc;
44 1.1 bad
45 1.1 bad struct tcic_event {
46 1.1 bad SIMPLEQ_ENTRY(tcic_event) pe_q;
47 1.1 bad int pe_type;
48 1.1 bad };
49 1.1 bad
50 1.1 bad /* pe_type */
51 1.1 bad #define TCIC_EVENT_INSERTION 0
52 1.1 bad #define TCIC_EVENT_REMOVAL 1
53 1.1 bad
54 1.1 bad
55 1.1 bad struct tcic_handle {
56 1.1 bad struct tcic_softc *sc;
57 1.1 bad int sock; /* socket number */
58 1.1 bad int flags;
59 1.1 bad int sstat; /* last value of R_SSTAT */
60 1.1 bad int memalloc;
61 1.1 bad int memwins;
62 1.1 bad struct {
63 1.1 bad bus_addr_t addr;
64 1.1 bad bus_size_t size;
65 1.1 bad int size2; /* size as 2^n scaled by 4K */
66 1.1 bad long offset;
67 1.1 bad int speed; /* in ns */
68 1.1 bad int kind;
69 1.1 bad } mem[TCIC_MAX_MEM_WINS];
70 1.1 bad int ioalloc;
71 1.1 bad struct {
72 1.1 bad bus_addr_t addr;
73 1.1 bad bus_size_t size;
74 1.1 bad int width;
75 1.1 bad int speed; /* in ns */
76 1.1 bad } io[TCIC_IO_WINS];
77 1.1 bad int ih_irq;
78 1.1 bad struct device *pcmcia;
79 1.1 bad
80 1.1 bad int shutdown;
81 1.1 bad struct proc *event_thread;
82 1.1 bad SIMPLEQ_HEAD(, tcic_event) events;
83 1.1 bad };
84 1.1 bad
85 1.1 bad #define TCIC_FLAG_SOCKETP 0x0001
86 1.1 bad #define TCIC_FLAG_CARDP 0x0002
87 1.1 bad
88 1.1 bad /*
89 1.1 bad * This is sort of arbitrary. It merely needs to be "enough". It can be
90 1.1 bad * overridden in the conf file, anyway.
91 1.1 bad */
92 1.1 bad
93 1.1 bad #define TCIC_MEM_PAGES 4
94 1.1 bad #define TCIC_MEMSIZE TCIC_MEM_PAGES*TCIC_MEM_PAGESIZE
95 1.1 bad
96 1.1 bad #define TCIC_NSLOTS 2
97 1.1 bad
98 1.1 bad struct tcic_softc {
99 1.1 bad struct device dev;
100 1.1 bad
101 1.1 bad bus_space_tag_t memt;
102 1.1 bad bus_space_handle_t memh;
103 1.1 bad bus_space_tag_t iot;
104 1.1 bad bus_space_handle_t ioh;
105 1.1 bad
106 1.1 bad int chipid;
107 1.1 bad int validirqs;
108 1.1 bad int pwrena; /* holds TCIC_PWR_ENA on'084 and successors */
109 1.1 bad
110 1.1 bad /* XXX isa_chipset_tag_t, pci_chipset_tag_t, etc. */
111 1.1 bad void *intr_est;
112 1.1 bad
113 1.1 bad pcmcia_chipset_tag_t pct;
114 1.1 bad
115 1.1 bad /* this needs to be large enough to hold TCIC_MEM_PAGES bits */
116 1.1 bad int subregionmask;
117 1.1 bad
118 1.1 bad /* used by memory window mapping functions */
119 1.1 bad bus_addr_t membase;
120 1.1 bad int memsize2; /* int(log2(memsize)) */
121 1.1 bad
122 1.1 bad /*
123 1.1 bad * used by io window mapping functions. These can actually overlap
124 1.1 bad * with another tcic, since the underlying extent mapper will deal
125 1.1 bad * with individual allocations. This is here to deal with the fact
126 1.1 bad * that different busses have different real widths (different pc
127 1.1 bad * hardware seems to use 10 or 12 bits for the I/O bus).
128 1.1 bad */
129 1.1 bad bus_addr_t iobase;
130 1.1 bad bus_size_t iosize;
131 1.1 bad
132 1.1 bad int irq;
133 1.1 bad void *ih;
134 1.1 bad
135 1.1 bad struct tcic_handle handle[TCIC_NSLOTS];
136 1.1 bad };
137 1.1 bad
138 1.1 bad int tcic_log2 __P((u_int));
139 1.1 bad int tcic_ns2wscnt __P((int));
140 1.1 bad
141 1.1 bad int tcic_check_reserved_bits __P((bus_space_tag_t, bus_space_handle_t));
142 1.1 bad int tcic_chipid __P((bus_space_tag_t, bus_space_handle_t));
143 1.1 bad int tcic_chipid_known __P((int));
144 1.1 bad char *tcic_chipid_to_string __P((int));
145 1.1 bad int tcic_validirqs __P((int));
146 1.1 bad
147 1.1 bad void tcic_attach __P((struct tcic_softc *));
148 1.1 bad void tcic_attach_sockets __P((struct tcic_softc *));
149 1.1 bad int tcic_intr __P((void *arg));
150 1.1 bad
151 1.1 bad static __inline__ int tcic_read_1 __P((struct tcic_handle *, int));
152 1.1 bad static __inline__ int tcic_read_2 __P((struct tcic_handle *, int));
153 1.1 bad static __inline__ int tcic_read_4 __P((struct tcic_handle *, int));
154 1.1 bad static __inline__ void tcic_write_1 __P((struct tcic_handle *, int, int));
155 1.1 bad static __inline__ void tcic_write_2 __P((struct tcic_handle *, int, int));
156 1.1 bad static __inline__ void tcic_write_4 __P((struct tcic_handle *, int, int));
157 1.1 bad static __inline__ int tcic_read_ind_2 __P((struct tcic_handle *, int));
158 1.1 bad static __inline__ void tcic_write_ind_2 __P((struct tcic_handle *, int, int));
159 1.1 bad static __inline__ void tcic_sel_sock __P((struct tcic_handle *));
160 1.1 bad static __inline__ void tcic_wait_ready __P((struct tcic_handle *));
161 1.1 bad static __inline__ int tcic_read_aux_1 __P((bus_space_tag_t, bus_space_handle_t, int, int));
162 1.1 bad static __inline__ int tcic_read_aux_2 __P((bus_space_tag_t, bus_space_handle_t, int));
163 1.1 bad static __inline__ void tcic_write_aux_1 __P((bus_space_tag_t, bus_space_handle_t, int, int, int));
164 1.1 bad static __inline__ void tcic_write_aux_2 __P((bus_space_tag_t, bus_space_handle_t, int, int));
165 1.1 bad
166 1.1 bad int tcic_chip_mem_alloc __P((pcmcia_chipset_handle_t, bus_size_t,
167 1.1 bad struct pcmcia_mem_handle *));
168 1.1 bad void tcic_chip_mem_free __P((pcmcia_chipset_handle_t,
169 1.1 bad struct pcmcia_mem_handle *));
170 1.1 bad int tcic_chip_mem_map __P((pcmcia_chipset_handle_t, int, bus_addr_t,
171 1.1 bad bus_size_t, struct pcmcia_mem_handle *, bus_addr_t *, int *));
172 1.1 bad void tcic_chip_mem_unmap __P((pcmcia_chipset_handle_t, int));
173 1.1 bad
174 1.1 bad int tcic_chip_io_alloc __P((pcmcia_chipset_handle_t, bus_addr_t,
175 1.1 bad bus_size_t, bus_size_t, struct pcmcia_io_handle *));
176 1.1 bad void tcic_chip_io_free __P((pcmcia_chipset_handle_t,
177 1.1 bad struct pcmcia_io_handle *));
178 1.1 bad int tcic_chip_io_map __P((pcmcia_chipset_handle_t, int, bus_addr_t,
179 1.1 bad bus_size_t, struct pcmcia_io_handle *, int *));
180 1.1 bad void tcic_chip_io_unmap __P((pcmcia_chipset_handle_t, int));
181 1.1 bad
182 1.1 bad void tcic_chip_socket_enable __P((pcmcia_chipset_handle_t));
183 1.1 bad void tcic_chip_socket_disable __P((pcmcia_chipset_handle_t));
184 1.1 bad
185 1.1 bad static __inline__ int tcic_read_1 __P((struct tcic_handle *, int));
186 1.1 bad static __inline__ int
187 1.1 bad tcic_read_1(h, reg)
188 1.1 bad struct tcic_handle *h;
189 1.1 bad int reg;
190 1.1 bad {
191 1.1 bad return (bus_space_read_1(h->sc->iot, h->sc->ioh, reg));
192 1.1 bad }
193 1.1 bad
194 1.1 bad static __inline__ int tcic_read_2 __P((struct tcic_handle *, int));
195 1.1 bad static __inline__ int
196 1.1 bad tcic_read_2(h, reg)
197 1.1 bad struct tcic_handle *h;
198 1.1 bad int reg;
199 1.1 bad {
200 1.1 bad return (bus_space_read_2(h->sc->iot, h->sc->ioh, reg));
201 1.1 bad }
202 1.1 bad
203 1.1 bad static __inline__ int tcic_read_4 __P((struct tcic_handle *, int));
204 1.1 bad static __inline__ int
205 1.1 bad tcic_read_4(h, reg)
206 1.1 bad struct tcic_handle *h;
207 1.1 bad int reg;
208 1.1 bad {
209 1.1 bad int val;
210 1.1 bad val = bus_space_read_2(h->sc->iot, h->sc->ioh, reg);
211 1.1 bad val |= bus_space_read_2(h->sc->iot, h->sc->ioh, reg+2) << 16;
212 1.1 bad return val;
213 1.1 bad }
214 1.1 bad
215 1.1 bad static __inline__ void tcic_write_1 __P((struct tcic_handle *, int, int));
216 1.1 bad static __inline__ void
217 1.1 bad tcic_write_1(h, reg, data)
218 1.1 bad struct tcic_handle *h;
219 1.1 bad int reg;
220 1.1 bad int data;
221 1.1 bad {
222 1.1 bad bus_space_write_1(h->sc->iot, h->sc->ioh, reg, (data));
223 1.1 bad }
224 1.1 bad
225 1.1 bad static __inline__ void tcic_write_2 __P((struct tcic_handle *, int, int));
226 1.1 bad static __inline__ void
227 1.1 bad tcic_write_2(h, reg, data)
228 1.1 bad struct tcic_handle *h;
229 1.1 bad int reg;
230 1.1 bad int data;
231 1.1 bad {
232 1.1 bad bus_space_write_2(h->sc->iot, h->sc->ioh, reg, (data));
233 1.1 bad }
234 1.1 bad
235 1.1 bad static __inline__ void tcic_write_4 __P((struct tcic_handle *, int, int));
236 1.1 bad static __inline__ void
237 1.1 bad tcic_write_4(h, reg, data)
238 1.1 bad struct tcic_handle *h;
239 1.1 bad int reg;
240 1.1 bad int data;
241 1.1 bad {
242 1.1 bad bus_space_write_2(h->sc->iot, h->sc->ioh, reg, (data));
243 1.1 bad bus_space_write_2(h->sc->iot, h->sc->ioh, reg+2, (data)>>16);
244 1.1 bad }
245 1.1 bad
246 1.1 bad static __inline__ int tcic_read_ind_2 __P((struct tcic_handle *, int));
247 1.1 bad static __inline__ int
248 1.1 bad tcic_read_ind_2(h, reg)
249 1.1 bad struct tcic_handle *h;
250 1.1 bad int reg;
251 1.1 bad {
252 1.1 bad int r_addr, val;
253 1.1 bad r_addr = tcic_read_4(h, TCIC_R_ADDR);
254 1.1 bad tcic_write_4(h, TCIC_R_ADDR, reg|TCIC_ADDR_INDREG);
255 1.1 bad val = bus_space_read_2(h->sc->iot, h->sc->ioh, TCIC_R_DATA);
256 1.1 bad tcic_write_4(h, TCIC_R_ADDR, r_addr);
257 1.1 bad return val;
258 1.1 bad }
259 1.1 bad
260 1.1 bad static __inline__ void tcic_write_ind_2 __P((struct tcic_handle *, int, int));
261 1.1 bad static __inline__ void
262 1.1 bad tcic_write_ind_2(h, reg, data)
263 1.1 bad struct tcic_handle *h;
264 1.1 bad int reg;
265 1.1 bad int data;
266 1.1 bad {
267 1.1 bad int r_addr;
268 1.1 bad r_addr = tcic_read_4(h, TCIC_R_ADDR);
269 1.1 bad tcic_write_4(h, TCIC_R_ADDR, reg|TCIC_ADDR_INDREG);
270 1.1 bad bus_space_write_2(h->sc->iot, h->sc->ioh, TCIC_R_DATA, (data));
271 1.1 bad tcic_write_4(h, TCIC_R_ADDR, r_addr);
272 1.1 bad }
273 1.1 bad
274 1.1 bad static __inline__ void tcic_sel_sock __P((struct tcic_handle *));
275 1.1 bad static __inline__ void
276 1.1 bad tcic_sel_sock(h)
277 1.1 bad struct tcic_handle *h;
278 1.1 bad {
279 1.1 bad int r_addr;
280 1.1 bad r_addr = tcic_read_2(h, TCIC_R_ADDR2);
281 1.1 bad tcic_write_2(h, TCIC_R_ADDR2,
282 1.1 bad (h->sock<<TCIC_ADDR2_SS_SHFT)|(r_addr & ~TCIC_ADDR2_SS_MASK));
283 1.1 bad }
284 1.1 bad
285 1.1 bad static __inline__ void tcic_wait_ready __P((struct tcic_handle *));
286 1.1 bad static __inline__ void
287 1.1 bad tcic_wait_ready(h)
288 1.1 bad struct tcic_handle *h;
289 1.1 bad {
290 1.1 bad int i;
291 1.1 bad
292 1.1 bad /* XXX appropriate socket must have been selected already. */
293 1.1 bad for (i = 0; i < 10000; i++) {
294 1.1 bad if (tcic_read_1(h, TCIC_R_SSTAT) & TCIC_SSTAT_RDY)
295 1.1 bad return;
296 1.1 bad delay(500);
297 1.1 bad }
298 1.1 bad
299 1.1 bad #ifdef DIAGNOSTIC
300 1.1 bad printf("tcic_wait_ready ready never happened\n");
301 1.1 bad #endif
302 1.1 bad }
303 1.1 bad
304 1.1 bad static __inline__ int tcic_read_aux_1 __P((bus_space_tag_t, bus_space_handle_t, int, int));
305 1.1 bad static __inline__ int
306 1.1 bad tcic_read_aux_1(iot, ioh, auxreg, reg)
307 1.1 bad bus_space_tag_t iot;
308 1.1 bad bus_space_handle_t ioh;
309 1.1 bad int auxreg;
310 1.1 bad {
311 1.1 bad int mode, val;
312 1.1 bad mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
313 1.1 bad bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
314 1.1 bad val = bus_space_read_1(iot, ioh, reg);
315 1.1 bad return val;
316 1.1 bad }
317 1.1 bad
318 1.1 bad static __inline__ int tcic_read_aux_2 __P((bus_space_tag_t, bus_space_handle_t, int));
319 1.1 bad static __inline__ int
320 1.1 bad tcic_read_aux_2(iot, ioh, auxreg)
321 1.1 bad bus_space_tag_t iot;
322 1.1 bad bus_space_handle_t ioh;
323 1.1 bad int auxreg;
324 1.1 bad {
325 1.1 bad int mode, val;
326 1.1 bad mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
327 1.1 bad bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
328 1.1 bad val = bus_space_read_2(iot, ioh, TCIC_R_AUX);
329 1.1 bad return val;
330 1.1 bad }
331 1.1 bad
332 1.1 bad static __inline__ void tcic_write_aux_1 __P((bus_space_tag_t, bus_space_handle_t, int, int, int));
333 1.1 bad static __inline__ void
334 1.1 bad tcic_write_aux_1(iot, ioh, auxreg, reg, val)
335 1.1 bad bus_space_tag_t iot;
336 1.1 bad bus_space_handle_t ioh;
337 1.1 bad int auxreg, reg, val;
338 1.1 bad {
339 1.1 bad int mode;
340 1.1 bad mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
341 1.1 bad bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
342 1.1 bad bus_space_write_1(iot, ioh, reg, val);
343 1.1 bad }
344 1.1 bad
345 1.1 bad static __inline__ void tcic_write_aux_2 __P((bus_space_tag_t, bus_space_handle_t, int, int));
346 1.1 bad static __inline__ void
347 1.1 bad tcic_write_aux_2(iot, ioh, auxreg, val)
348 1.1 bad bus_space_tag_t iot;
349 1.1 bad bus_space_handle_t ioh;
350 1.1 bad int auxreg, val;
351 1.1 bad {
352 1.1 bad int mode;
353 1.1 bad mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
354 1.1 bad bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
355 1.1 bad bus_space_write_2(iot, ioh, TCIC_R_AUX, val);
356 1.1 bad }
357 1.1 bad
358 1.1 bad #endif /* _TCIC2VAR_H */
359