summaryrefslogtreecommitdiff
path: root/sys/dev/ic/tcic2var.h
blob: 705d33e42082f236fb3c36266c22667ff0c086ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*	$OpenBSD: tcic2var.h,v 1.4 2005/11/23 11:39:37 mickey Exp $	*/
/*	$NetBSD: tcic2var.h,v 1.1 1999/03/23 20:04:14 bad Exp $	*/

/*
 * Copyright (c) 1998, 1999 Christoph Badura.  All rights reserved.
 * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Marc Horowitz.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _TCIC2VAR_H
#define _TCIC2VAR_H

#include <sys/device.h>

#include <dev/pcmcia/pcmciareg.h>
#include <dev/pcmcia/pcmciachip.h>

#include <dev/ic/tcic2reg.h>

struct proc;

struct tcic_event {
	SIMPLEQ_ENTRY(tcic_event) pe_q;
	int pe_type;
};

/* pe_type */
#define	TCIC_EVENT_INSERTION	0
#define	TCIC_EVENT_REMOVAL	1


struct tcic_handle {
	struct tcic_softc *sc;
	int	sock;				/* socket number */
	int	flags;
	int	sstat;				/* last value of R_SSTAT */
	int	memalloc;
	int	memwins;
	struct {
		bus_addr_t	addr;
		bus_size_t	size;
		int		size2;		/* size as 2^n scaled by 4K */
		long		offset;
		int		speed;		/* in ns */
		int		kind;
	} mem[TCIC_MAX_MEM_WINS];
	int	ioalloc;
	struct {
		bus_addr_t	addr;
		bus_size_t	size;
		int		width;
		int		speed;		/* in ns */
	} io[TCIC_IO_WINS];
	int	ih_irq;
	struct device *pcmcia;

	int shutdown;
	struct proc *event_thread;
	SIMPLEQ_HEAD(, tcic_event) events;
};

#define	TCIC_FLAG_SOCKETP	0x0001
#define	TCIC_FLAG_CARDP		0x0002

/*
 * This is sort of arbitrary.  It merely needs to be "enough". It can be
 * overridden in the conf file, anyway.
 */

#define	TCIC_MEM_PAGES	4
#define	TCIC_MEMSIZE	TCIC_MEM_PAGES*TCIC_MEM_PAGESIZE

#define	TCIC_NSLOTS	2

struct tcic_softc {
	struct device dev;

	bus_space_tag_t memt;
	bus_space_handle_t memh;
	bus_space_tag_t iot;
	bus_space_handle_t ioh;

	int	chipid;
	int	validirqs;
	int	pwrena;		/* holds TCIC_PWR_ENA on'084 and successors */

	/* XXX isa_chipset_tag_t, pci_chipset_tag_t, etc. */
	void	*intr_est;

	pcmcia_chipset_tag_t pct;

	/* this needs to be large enough to hold TCIC_MEM_PAGES bits */
	int	subregionmask;

	/* used by memory window mapping functions */
	bus_addr_t membase;
	int	memsize2;		/* int(log2(memsize)) */

	/*
	 * used by io window mapping functions.  These can actually overlap
	 * with another tcic, since the underlying extent mapper will deal
	 * with individual allocations.  This is here to deal with the fact
	 * that different busses have different real widths (different pc
	 * hardware seems to use 10 or 12 bits for the I/O bus).
	 */
	bus_addr_t iobase;
	bus_size_t iosize;

	int	irq;
	void	*ih;

	struct tcic_handle handle[TCIC_NSLOTS];
};

int	tcic_log2(u_int);
int	tcic_ns2wscnt(int);

int	tcic_check_reserved_bits(bus_space_tag_t, bus_space_handle_t);
int	tcic_chipid(bus_space_tag_t, bus_space_handle_t);
int	tcic_chipid_known(int);
char	*tcic_chipid_to_string(int);
int	tcic_validirqs(int);

void	tcic_attach(struct tcic_softc *);
void	tcic_attach_sockets(struct tcic_softc *);
int	tcic_intr(void *arg);

static __inline__ int tcic_read_1(struct tcic_handle *, int);
static __inline__ int tcic_read_2(struct tcic_handle *, int);
static __inline__ int tcic_read_4(struct tcic_handle *, int);
static __inline__ void tcic_write_1(struct tcic_handle *, int, int);
static __inline__ void tcic_write_2(struct tcic_handle *, int, int);
static __inline__ void tcic_write_4(struct tcic_handle *, int, int);
static __inline__ int tcic_read_ind_2(struct tcic_handle *, int);
static __inline__ void tcic_write_ind_2(struct tcic_handle *, int, int);
static __inline__ void tcic_sel_sock(struct tcic_handle *);
static __inline__ void tcic_wait_ready(struct tcic_handle *);
static __inline__ int tcic_read_aux_1(bus_space_tag_t, bus_space_handle_t, int, int);
static __inline__ int tcic_read_aux_2(bus_space_tag_t, bus_space_handle_t, int);
static __inline__ void tcic_write_aux_1(bus_space_tag_t, bus_space_handle_t, int, int, int);
static __inline__ void tcic_write_aux_2(bus_space_tag_t, bus_space_handle_t, int, int);

int	tcic_chip_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
	    struct pcmcia_mem_handle *);
void	tcic_chip_mem_free(pcmcia_chipset_handle_t,
	    struct pcmcia_mem_handle *);
int	tcic_chip_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
	    bus_size_t, struct pcmcia_mem_handle *, bus_size_t *, int *);
void	tcic_chip_mem_unmap(pcmcia_chipset_handle_t, int);

int	tcic_chip_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
	    bus_size_t, bus_size_t, struct pcmcia_io_handle *);
void	tcic_chip_io_free(pcmcia_chipset_handle_t,
	    struct pcmcia_io_handle *);
int	tcic_chip_io_map(pcmcia_chipset_handle_t, int, bus_addr_t,
	    bus_size_t, struct pcmcia_io_handle *, int *);
void	tcic_chip_io_unmap(pcmcia_chipset_handle_t, int);

void	tcic_chip_socket_enable(pcmcia_chipset_handle_t);
void	tcic_chip_socket_disable(pcmcia_chipset_handle_t);

static __inline__ int tcic_read_1(struct tcic_handle *, int);
static __inline__ int
tcic_read_1(h, reg)
	struct tcic_handle *h;
	int reg;
{
	return (bus_space_read_1(h->sc->iot, h->sc->ioh, reg));
}

static __inline__ int tcic_read_2(struct tcic_handle *, int);
static __inline__ int
tcic_read_2(h, reg)
	struct tcic_handle *h;
	int reg;
{
	return (bus_space_read_2(h->sc->iot, h->sc->ioh, reg));
}

static __inline__ int tcic_read_4(struct tcic_handle *, int);
static __inline__ int
tcic_read_4(h, reg)
	struct tcic_handle *h;
	int reg;
{
	int val;
	val = bus_space_read_2(h->sc->iot, h->sc->ioh, reg);
	val |= bus_space_read_2(h->sc->iot, h->sc->ioh, reg+2) << 16;
	return val;
}

static __inline__ void tcic_write_1(struct tcic_handle *, int, int);
static __inline__ void
tcic_write_1(h, reg, data)
	struct tcic_handle *h;
	int reg;
	int data;
{
	bus_space_write_1(h->sc->iot, h->sc->ioh, reg, (data));
}

static __inline__ void tcic_write_2(struct tcic_handle *, int, int);
static __inline__ void
tcic_write_2(h, reg, data)
	struct tcic_handle *h;
	int reg;
	int data;
{
	bus_space_write_2(h->sc->iot, h->sc->ioh, reg, (data));
}

static __inline__ void tcic_write_4(struct tcic_handle *, int, int);
static __inline__ void
tcic_write_4(h, reg, data)
	struct tcic_handle *h;
	int reg;
	int data;
{
	bus_space_write_2(h->sc->iot, h->sc->ioh, reg, (data));
	bus_space_write_2(h->sc->iot, h->sc->ioh, reg+2, (data)>>16);
}

static __inline__ int tcic_read_ind_2(struct tcic_handle *, int);
static __inline__ int
tcic_read_ind_2(h, reg)
	struct tcic_handle *h;
	int reg;
{
	int r_addr, val;
	r_addr = tcic_read_4(h, TCIC_R_ADDR);
	tcic_write_4(h, TCIC_R_ADDR, reg|TCIC_ADDR_INDREG);
	val = bus_space_read_2(h->sc->iot, h->sc->ioh, TCIC_R_DATA);
	tcic_write_4(h, TCIC_R_ADDR, r_addr);
	return val;
}

static __inline__ void tcic_write_ind_2(struct tcic_handle *, int, int);
static __inline__ void
tcic_write_ind_2(h, reg, data)
	struct tcic_handle *h;
	int reg;
	int data;
{
	int r_addr;
	r_addr = tcic_read_4(h, TCIC_R_ADDR);
	tcic_write_4(h, TCIC_R_ADDR, reg|TCIC_ADDR_INDREG);
	bus_space_write_2(h->sc->iot, h->sc->ioh, TCIC_R_DATA, (data));
	tcic_write_4(h, TCIC_R_ADDR, r_addr);
}

static __inline__ void tcic_sel_sock(struct tcic_handle *);
static __inline__ void
tcic_sel_sock(h)
	struct tcic_handle *h;
{
	int r_addr;
	r_addr = tcic_read_2(h, TCIC_R_ADDR2);
	tcic_write_2(h, TCIC_R_ADDR2,
	    (h->sock<<TCIC_ADDR2_SS_SHFT)|(r_addr & ~TCIC_ADDR2_SS_MASK));
}

static __inline__ void tcic_wait_ready(struct tcic_handle *);
static __inline__ void
tcic_wait_ready(h)
	struct tcic_handle *h;
{
	int i;

	/* XXX appropriate socket must have been selected already. */
	for (i = 0; i < 10000; i++) {
		if (tcic_read_1(h, TCIC_R_SSTAT) & TCIC_SSTAT_RDY)
			return;
		delay(500);
	}

#ifdef DIAGNOSTIC
	printf("tcic_wait_ready ready never happened\n");
#endif
}

static __inline__ int tcic_read_aux_1(bus_space_tag_t, bus_space_handle_t, int, int);
static __inline__ int
tcic_read_aux_1(iot, ioh, auxreg, reg)
	bus_space_tag_t iot;
	bus_space_handle_t ioh;
	int auxreg, reg;
{
	int mode, val;
	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
	val = bus_space_read_1(iot, ioh, reg);
	return val;
}

static __inline__ int tcic_read_aux_2(bus_space_tag_t, bus_space_handle_t, int);
static __inline__ int
tcic_read_aux_2(iot, ioh, auxreg)
	bus_space_tag_t iot;
	bus_space_handle_t ioh;
	int auxreg;
{
	int mode, val;
	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
	val = bus_space_read_2(iot, ioh, TCIC_R_AUX);
	return val;
}

static __inline__ void tcic_write_aux_1(bus_space_tag_t, bus_space_handle_t, int, int, int);
static __inline__ void
tcic_write_aux_1(iot, ioh, auxreg, reg, val)
	bus_space_tag_t iot;
	bus_space_handle_t ioh;
	int auxreg, reg, val;
{
	int mode;
	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
	bus_space_write_1(iot, ioh, reg, val);
}

static __inline__ void tcic_write_aux_2(bus_space_tag_t, bus_space_handle_t, int, int);
static __inline__ void
tcic_write_aux_2(iot, ioh, auxreg, val)
	bus_space_tag_t iot;
	bus_space_handle_t ioh;
	int auxreg, val;
{
	int mode;
	mode = bus_space_read_1(iot, ioh, TCIC_R_MODE);
	bus_space_write_1(iot, ioh, TCIC_R_MODE, (mode & ~TCIC_AR_MASK)|auxreg);
	bus_space_write_2(iot, ioh, TCIC_R_AUX, val);
}

#endif	/* _TCIC2VAR_H */