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