tcic2var.h revision 1.11 1 1.11 cegger /* $NetBSD: tcic2var.h,v 1.11 2009/03/16 09:32:38 cegger 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.10 ad struct lwp *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.4 perry int tcic_log2(u_int);
139 1.4 perry int tcic_ns2wscnt(int);
140 1.1 bad
141 1.4 perry int tcic_check_reserved_bits(bus_space_tag_t, bus_space_handle_t);
142 1.4 perry int tcic_chipid(bus_space_tag_t, bus_space_handle_t);
143 1.4 perry int tcic_chipid_known(int);
144 1.5 christos const char *tcic_chipid_to_string(int);
145 1.4 perry int tcic_validirqs(int);
146 1.4 perry
147 1.4 perry void tcic_attach(struct tcic_softc *);
148 1.4 perry void tcic_attach_sockets(struct tcic_softc *);
149 1.4 perry int tcic_intr(void *arg);
150 1.4 perry
151 1.8 perry static __inline int tcic_read_1(struct tcic_handle *, int);
152 1.8 perry static __inline int tcic_read_2(struct tcic_handle *, int);
153 1.8 perry static __inline int tcic_read_4(struct tcic_handle *, int);
154 1.8 perry static __inline void tcic_write_1(struct tcic_handle *, int, int);
155 1.8 perry static __inline void tcic_write_2(struct tcic_handle *, int, int);
156 1.8 perry static __inline void tcic_write_4(struct tcic_handle *, int, int);
157 1.8 perry static __inline int tcic_read_ind_2(struct tcic_handle *, int);
158 1.8 perry static __inline void tcic_write_ind_2(struct tcic_handle *, int, int);
159 1.8 perry static __inline void tcic_sel_sock(struct tcic_handle *);
160 1.8 perry static __inline void tcic_wait_ready(struct tcic_handle *);
161 1.8 perry static __inline int tcic_read_aux_1(bus_space_tag_t, bus_space_handle_t, int, int);
162 1.8 perry static __inline int tcic_read_aux_2(bus_space_tag_t, bus_space_handle_t, int);
163 1.8 perry static __inline void tcic_write_aux_1(bus_space_tag_t, bus_space_handle_t, int, int, int);
164 1.8 perry static __inline void tcic_write_aux_2(bus_space_tag_t, bus_space_handle_t, int, int);
165 1.4 perry
166 1.4 perry int tcic_chip_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
167 1.4 perry struct pcmcia_mem_handle *);
168 1.4 perry void tcic_chip_mem_free(pcmcia_chipset_handle_t,
169 1.4 perry struct pcmcia_mem_handle *);
170 1.4 perry int tcic_chip_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
171 1.4 perry bus_size_t, struct pcmcia_mem_handle *, bus_size_t *, int *);
172 1.4 perry void tcic_chip_mem_unmap(pcmcia_chipset_handle_t, int);
173 1.4 perry
174 1.4 perry int tcic_chip_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
175 1.4 perry bus_size_t, bus_size_t, struct pcmcia_io_handle *);
176 1.4 perry void tcic_chip_io_free(pcmcia_chipset_handle_t,
177 1.4 perry struct pcmcia_io_handle *);
178 1.4 perry int tcic_chip_io_map(pcmcia_chipset_handle_t, int, bus_addr_t,
179 1.4 perry bus_size_t, struct pcmcia_io_handle *, int *);
180 1.4 perry void tcic_chip_io_unmap(pcmcia_chipset_handle_t, int);
181 1.4 perry
182 1.4 perry void tcic_chip_socket_enable(pcmcia_chipset_handle_t);
183 1.4 perry void tcic_chip_socket_disable(pcmcia_chipset_handle_t);
184 1.4 perry void tcic_chip_socket_settype(pcmcia_chipset_handle_t, int);
185 1.1 bad
186 1.8 perry static __inline int tcic_read_1(struct tcic_handle *, int);
187 1.8 perry static __inline int
188 1.11 cegger tcic_read_1(struct tcic_handle *h, int reg)
189 1.1 bad {
190 1.1 bad return (bus_space_read_1(h->sc->iot, h->sc->ioh, reg));
191 1.1 bad }
192 1.1 bad
193 1.8 perry static __inline int tcic_read_2(struct tcic_handle *, int);
194 1.8 perry static __inline int
195 1.11 cegger tcic_read_2(struct tcic_handle *h, int reg)
196 1.1 bad {
197 1.1 bad return (bus_space_read_2(h->sc->iot, h->sc->ioh, reg));
198 1.1 bad }
199 1.1 bad
200 1.8 perry static __inline int tcic_read_4(struct tcic_handle *, int);
201 1.8 perry static __inline int
202 1.11 cegger tcic_read_4(struct tcic_handle *h, int reg)
203 1.1 bad {
204 1.1 bad int val;
205 1.1 bad val = bus_space_read_2(h->sc->iot, h->sc->ioh, reg);
206 1.1 bad val |= bus_space_read_2(h->sc->iot, h->sc->ioh, reg+2) << 16;
207 1.1 bad return val;
208 1.1 bad }
209 1.1 bad
210 1.8 perry static __inline void tcic_write_1(struct tcic_handle *, int, int);
211 1.8 perry static __inline void
212 1.11 cegger tcic_write_1(struct tcic_handle *h, int reg, int data)
213 1.1 bad {
214 1.1 bad bus_space_write_1(h->sc->iot, h->sc->ioh, reg, (data));
215 1.1 bad }
216 1.1 bad
217 1.8 perry static __inline void tcic_write_2(struct tcic_handle *, int, int);
218 1.8 perry static __inline void
219 1.11 cegger tcic_write_2(struct tcic_handle *h, int reg, int data)
220 1.1 bad {
221 1.1 bad bus_space_write_2(h->sc->iot, h->sc->ioh, reg, (data));
222 1.1 bad }
223 1.1 bad
224 1.8 perry static __inline void tcic_write_4(struct tcic_handle *, int, int);
225 1.8 perry static __inline void
226 1.11 cegger tcic_write_4(struct tcic_handle *h, int reg, int data)
227 1.1 bad {
228 1.1 bad bus_space_write_2(h->sc->iot, h->sc->ioh, reg, (data));
229 1.1 bad bus_space_write_2(h->sc->iot, h->sc->ioh, reg+2, (data)>>16);
230 1.1 bad }
231 1.1 bad
232 1.8 perry static __inline int tcic_read_ind_2(struct tcic_handle *, int);
233 1.8 perry static __inline int
234 1.11 cegger tcic_read_ind_2(struct tcic_handle *h, int reg)
235 1.1 bad {
236 1.1 bad int r_addr, val;
237 1.1 bad r_addr = tcic_read_4(h, TCIC_R_ADDR);
238 1.1 bad tcic_write_4(h, TCIC_R_ADDR, reg|TCIC_ADDR_INDREG);
239 1.1 bad val = bus_space_read_2(h->sc->iot, h->sc->ioh, TCIC_R_DATA);
240 1.1 bad tcic_write_4(h, TCIC_R_ADDR, r_addr);
241 1.1 bad return val;
242 1.1 bad }
243 1.1 bad
244 1.8 perry static __inline void tcic_write_ind_2(struct tcic_handle *, int, int);
245 1.8 perry static __inline void
246 1.11 cegger tcic_write_ind_2(struct tcic_handle *h, int reg, int data)
247 1.1 bad {
248 1.1 bad int r_addr;
249 1.1 bad r_addr = tcic_read_4(h, TCIC_R_ADDR);
250 1.1 bad tcic_write_4(h, TCIC_R_ADDR, reg|TCIC_ADDR_INDREG);
251 1.1 bad bus_space_write_2(h->sc->iot, h->sc->ioh, TCIC_R_DATA, (data));
252 1.1 bad tcic_write_4(h, TCIC_R_ADDR, r_addr);
253 1.1 bad }
254 1.1 bad
255 1.8 perry static __inline void tcic_sel_sock(struct tcic_handle *);
256 1.8 perry static __inline void
257 1.11 cegger tcic_sel_sock(struct tcic_handle *h)
258 1.1 bad {
259 1.1 bad int r_addr;
260 1.1 bad r_addr = tcic_read_2(h, TCIC_R_ADDR2);
261 1.1 bad tcic_write_2(h, TCIC_R_ADDR2,
262 1.1 bad (h->sock<<TCIC_ADDR2_SS_SHFT)|(r_addr & ~TCIC_ADDR2_SS_MASK));
263 1.1 bad }
264 1.1 bad
265 1.8 perry static __inline void tcic_wait_ready(struct tcic_handle *);
266 1.8 perry static __inline void
267 1.11 cegger tcic_wait_ready(struct tcic_handle *h)
268 1.1 bad {
269 1.1 bad int i;
270 1.1 bad
271 1.1 bad /* XXX appropriate socket must have been selected already. */
272 1.1 bad for (i = 0; i < 10000; i++) {
273 1.1 bad if (tcic_read_1(h, TCIC_R_SSTAT) & TCIC_SSTAT_RDY)
274 1.1 bad return;
275 1.1 bad delay(500);
276 1.1 bad }
277 1.1 bad
278 1.1 bad #ifdef DIAGNOSTIC
279 1.1 bad printf("tcic_wait_ready ready never happened\n");
280 1.1 bad #endif
281 1.1 bad }
282 1.1 bad
283 1.8 perry static __inline int tcic_read_aux_1(bus_space_tag_t, bus_space_handle_t, int, int);
284 1.8 perry static __inline int
285 1.11 cegger tcic_read_aux_1(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg, int reg)
286 1.1 bad {
287 1.1 bad int mode, val;
288 1.1 bad mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
289 1.1 bad bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
290 1.1 bad val = bus_space_read_1(iot, ioh, reg);
291 1.1 bad return val;
292 1.1 bad }
293 1.1 bad
294 1.8 perry static __inline int tcic_read_aux_2(bus_space_tag_t, bus_space_handle_t, int);
295 1.8 perry static __inline int
296 1.11 cegger tcic_read_aux_2(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg)
297 1.1 bad {
298 1.1 bad int mode, val;
299 1.1 bad mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
300 1.1 bad bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
301 1.1 bad val = bus_space_read_2(iot, ioh, TCIC_R_AUX);
302 1.1 bad return val;
303 1.1 bad }
304 1.1 bad
305 1.8 perry static __inline void tcic_write_aux_1(bus_space_tag_t, bus_space_handle_t, int, int, int);
306 1.8 perry static __inline void
307 1.11 cegger tcic_write_aux_1(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg, int reg, int val)
308 1.1 bad {
309 1.1 bad int mode;
310 1.1 bad mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
311 1.1 bad bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
312 1.1 bad bus_space_write_1(iot, ioh, reg, val);
313 1.1 bad }
314 1.1 bad
315 1.8 perry static __inline void tcic_write_aux_2(bus_space_tag_t, bus_space_handle_t, int, int);
316 1.8 perry static __inline void
317 1.11 cegger tcic_write_aux_2(bus_space_tag_t iot, bus_space_handle_t ioh, int auxreg, int val)
318 1.1 bad {
319 1.1 bad int mode;
320 1.1 bad mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
321 1.1 bad bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
322 1.1 bad bus_space_write_2(iot, ioh, TCIC_R_AUX, val);
323 1.1 bad }
324 1.1 bad
325 1.1 bad #endif /* _TCIC2VAR_H */
326