1 /* ISDN4BSD code */
2 /*-
3  * Copyright (c) 2002 The NetBSD Foundation, Inc.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to The NetBSD Foundation
7  * by Martin Husemann <martin@netbsd.org>.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *        This product includes software developed by the NetBSD
20  *        Foundation, Inc. and its contributors.
21  * 4. Neither the name of The NetBSD Foundation nor the names of its
22  *    contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: daic_isa.c,v 1.10 2002/10/02 03:10:46 thorpej Exp $");
40 
41 #include <sys/param.h>
42 #include <sys/errno.h>
43 #include <sys/syslog.h>
44 #include <sys/device.h>
45 
46 #include <sys/timeout.h>
47 
48 #include <machine/cpu.h>
49 #include <machine/intr.h>
50 #include <machine/bus.h>
51 
52 #include <sys/socket.h>
53 #include <net/if.h>
54 #include <dev/isa/isavar.h>
55 #include <netisdn/i4b_ioctl.h>
56 #include <netisdn/i4b_l3l4.h>
57 #include <dev/ic/daicvar.h>
58 
59 /* driver state */
60 struct daic_isa_softc {
61 	struct daic_softc sc_daic;	/* MI driver state */
62 	void *sc_ih;			/* interrupt handler */
63 };
64 
65 /* local functions */
66 #ifdef __BROKEN_INDIRECT_CONFIG
67 static int daic_isa_probe __P((struct device *, void *, void *));
68 #else
69 static int daic_isa_probe __P((struct device *, struct cfdata *, void *));
70 #endif
71 static void daic_isa_attach __P((struct device *, struct device *, void *));
72 static int daic_isa_intr __P((void *));
73 
74 CFATTACH_DECL(daic_isa, sizeof(struct daic_isa_softc),
75     daic_isa_probe, daic_isa_attach, NULL, NULL);
76 
77 static int
78 #ifdef __BROKEN_INDIRECT_CONFIG
daic_isa_probe(parent,match,aux)79 daic_isa_probe(parent, match, aux)
80 #else
81 daic_isa_probe(parent, cf, aux)
82 #endif
83 	struct device *parent;
84 #ifdef __BROKEN_INDIRECT_CONFIG
85 	void *match;
86 #else
87 	struct cfdata *cf;
88 #endif
89 	void *aux;
90 {
91 	struct isa_attach_args *ia = aux;
92 	bus_space_tag_t memt = ia->ia_memt;
93 	bus_space_handle_t memh;
94 	int card, need_unmap = 0;
95 
96 	/* We need some controller memory to comunicate! */
97 	if (ia->ia_iomem[0].ir_addr == 0 || ia->ia_iomem[0].ir_size == -1)
98 		goto bad;
99 
100 	/* Map card RAM. */
101 	ia->ia_iomem[0].ir_size = DAIC_ISA_MEMSIZE;
102 	ia->ia_nio = 0;
103 	ia->ia_ndrq = 0;
104 	ia->ia_nirq = 1;
105 	ia->ia_niomem = 1;
106 	if (bus_space_map(memt, ia->ia_iomem[0].ir_addr, ia->ia_iomem[0].ir_size,
107 	    0, &memh))
108 		goto bad;
109 	need_unmap = 1;
110 
111 	/* MI check for card at this location */
112 	card = daic_probe(memt, memh);
113 	if (card < 0)
114 		goto bad;
115 	if (card == DAIC_TYPE_QUAD)
116 		ia->ia_iomem[0].ir_size = DAIC_ISA_QUADSIZE;
117 
118 	bus_space_unmap(memt, memh, DAIC_ISA_MEMSIZE);
119 	return 1;
120 
121 bad:
122 	/* unmap card RAM if already mapped */
123 	if (need_unmap)
124 		bus_space_unmap(memt, memh, DAIC_ISA_MEMSIZE);
125 	return 0;
126 }
127 
128 static void
daic_isa_attach(parent,self,aux)129 daic_isa_attach(parent, self, aux)
130 	struct device *parent, *self;
131 	void *aux;
132 {
133 	struct daic_isa_softc *sc = (void *)self;
134 	struct isa_attach_args *ia = aux;
135 	bus_space_tag_t memt = ia->ia_memt;
136 	bus_space_handle_t memh;
137 
138 	/* Map card RAM. */
139 	if (bus_space_map(memt, ia->ia_iomem[0].ir_addr, ia->ia_iomem[0].ir_size,
140 	    0, &memh))
141 		return;
142 
143 	sc->sc_daic.sc_iot = memt;
144 	sc->sc_daic.sc_ioh = memh;
145 
146 	/* MI initialization of card */
147 	daic_attach(self, &sc->sc_daic);
148 
149 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, IST_EDGE,
150 	    IPL_NET, daic_isa_intr, sc);
151 }
152 
153 /*
154  * Controller interrupt.
155  */
156 static int
daic_isa_intr(arg)157 daic_isa_intr(arg)
158 	void *arg;
159 {
160 	struct daic_isa_softc *sc = arg;
161 	return daic_intr(&sc->sc_daic);
162 }
163