1*9cb526aaStsutsui /* $NetBSD: ess_isa.c,v 1.24 2010/05/22 16:35:00 tsutsui Exp $ */
2bd7b26e3Snathanw
3bd7b26e3Snathanw /*-
4bd7b26e3Snathanw * Copyright (c) 1999 The NetBSD Foundation, Inc.
5bd7b26e3Snathanw * All rights reserved.
6bd7b26e3Snathanw *
7bd7b26e3Snathanw * This code is derived from software contributed to The NetBSD Foundation
8bd7b26e3Snathanw * by Nathan J. Williams.
9bd7b26e3Snathanw *
10bd7b26e3Snathanw * Redistribution and use in source and binary forms, with or without
11bd7b26e3Snathanw * modification, are permitted provided that the following conditions
12bd7b26e3Snathanw * are met:
13bd7b26e3Snathanw * 1. Redistributions of source code must retain the above copyright
14bd7b26e3Snathanw * notice, this list of conditions and the following disclaimer.
15bd7b26e3Snathanw * 2. Redistributions in binary form must reproduce the above copyright
16bd7b26e3Snathanw * notice, this list of conditions and the following disclaimer in the
17bd7b26e3Snathanw * documentation and/or other materials provided with the distribution.
18bd7b26e3Snathanw *
19bd7b26e3Snathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20bd7b26e3Snathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21bd7b26e3Snathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22bd7b26e3Snathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23bd7b26e3Snathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24bd7b26e3Snathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25bd7b26e3Snathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26bd7b26e3Snathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27bd7b26e3Snathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28bd7b26e3Snathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29bd7b26e3Snathanw * POSSIBILITY OF SUCH DAMAGE.
30bd7b26e3Snathanw */
31bd7b26e3Snathanw
323f7d8d47Slukem #include <sys/cdefs.h>
33*9cb526aaStsutsui __KERNEL_RCSID(0, "$NetBSD: ess_isa.c,v 1.24 2010/05/22 16:35:00 tsutsui Exp $");
34bd7b26e3Snathanw
35bd7b26e3Snathanw #include <sys/param.h>
36bd7b26e3Snathanw #include <sys/systm.h>
37bd7b26e3Snathanw #include <sys/device.h>
38bd7b26e3Snathanw
39a2a38285Sad #include <sys/cpu.h>
40a2a38285Sad #include <sys/bus.h>
41bd7b26e3Snathanw
42bd7b26e3Snathanw #include <dev/isa/isavar.h>
43bd7b26e3Snathanw
44bd7b26e3Snathanw #include <dev/isa/essreg.h>
45bd7b26e3Snathanw #include <dev/isa/essvar.h>
46bd7b26e3Snathanw
47955c2f90Sdrochner #include "joy_ess.h"
48955c2f90Sdrochner
49bd7b26e3Snathanw #ifdef ESS_ISA_DEBUG
50bd7b26e3Snathanw #define DPRINTF(x) printf x
51bd7b26e3Snathanw #else
52f64c33e8Sreinoud #define DPRINTF(x) {}
53bd7b26e3Snathanw #endif
54bd7b26e3Snathanw
55f2bccc0aScegger int ess_isa_probe(device_t, cfdata_t, void *);
56f2bccc0aScegger void ess_isa_attach(device_t, device_t, void *);
57bd7b26e3Snathanw
58*9cb526aaStsutsui CFATTACH_DECL_NEW(ess_isa, sizeof(struct ess_softc),
590dac35b5Sthorpej ess_isa_probe, ess_isa_attach, NULL, NULL);
60bd7b26e3Snathanw
61bd7b26e3Snathanw int
ess_isa_probe(device_t parent,cfdata_t match,void * aux)62f2bccc0aScegger ess_isa_probe(device_t parent, cfdata_t match, void *aux)
63bd7b26e3Snathanw {
64bd7b26e3Snathanw int ret;
65b85368e3Skent struct isa_attach_args *ia;
66b85368e3Skent struct ess_softc probesc, *sc;
67bd7b26e3Snathanw
68b85368e3Skent ia = aux;
69b85368e3Skent sc= &probesc;
703835413bSthorpej if (ia->ia_nio < 1)
71b85368e3Skent return 0;
723835413bSthorpej if (ia->ia_nirq < 1)
73b85368e3Skent return 0;
743835413bSthorpej if (ia->ia_ndrq < 1)
75b85368e3Skent return 0;
763835413bSthorpej
773835413bSthorpej if (ISA_DIRECT_CONFIG(ia))
78b85368e3Skent return 0;
793835413bSthorpej
80bd7b26e3Snathanw memset(sc, 0, sizeof *sc);
81bd7b26e3Snathanw
82bd7b26e3Snathanw sc->sc_ic = ia->ia_ic;
83bd7b26e3Snathanw sc->sc_iot = ia->ia_iot;
843835413bSthorpej sc->sc_iobase = ia->ia_io[0].ir_addr;
853835413bSthorpej if (bus_space_map(sc->sc_iot, sc->sc_iobase, ESS_NPORT, 0,
863835413bSthorpej &sc->sc_ioh)) {
873835413bSthorpej DPRINTF(("ess_isa_probe: Couldn't map I/O region at %x, "
883835413bSthorpej "size %x\n", sc->sc_iobase, ESS_NPORT));
89bd7b26e3Snathanw return 0;
90bd7b26e3Snathanw }
91bd7b26e3Snathanw
923835413bSthorpej sc->sc_audio1.irq = ia->ia_irq[0].ir_irq;
939e041fd8Smycroft sc->sc_audio1.ist = IST_EDGE;
943835413bSthorpej sc->sc_audio1.drq = ia->ia_drq[0].ir_drq;
955a20d4dfSmycroft sc->sc_audio2.irq = -1;
963835413bSthorpej sc->sc_audio2.drq = (ia->ia_ndrq > 1) ? ia->ia_drq[1].ir_drq : -1;
97bd7b26e3Snathanw
98bd7b26e3Snathanw ret = essmatch(sc);
99bd7b26e3Snathanw
100bd7b26e3Snathanw bus_space_unmap(sc->sc_iot, sc->sc_ioh, ESS_NPORT);
101bd7b26e3Snathanw
102b45b384eSmycroft if (ret) {
103bd7b26e3Snathanw DPRINTF(("ess_isa_probe succeeded (score %d)\n", ret));
1043835413bSthorpej ia->ia_nio = 1;
1053835413bSthorpej ia->ia_io[0].ir_size = ESS_NPORT;
1063835413bSthorpej
1073835413bSthorpej ia->ia_nirq = 1;
1083835413bSthorpej
1093835413bSthorpej if (ia->ia_ndrq > 1 &&
1101308c6d7Sdrochner ia->ia_drq[1].ir_drq != ISA_UNKNOWN_DRQ)
1113835413bSthorpej ia->ia_ndrq = 2;
1123835413bSthorpej else
1133835413bSthorpej ia->ia_ndrq = 1;
1143835413bSthorpej
1153835413bSthorpej ia->ia_niomem = 0;
116b45b384eSmycroft } else
117a6a09bcdSaugustss DPRINTF(("ess_isa_probe failed\n"));
118bd7b26e3Snathanw
119bd7b26e3Snathanw return ret;
120bd7b26e3Snathanw }
121bd7b26e3Snathanw
122b85368e3Skent void
ess_isa_attach(device_t parent,device_t self,void * aux)123f2bccc0aScegger ess_isa_attach(device_t parent, device_t self, void *aux)
124bd7b26e3Snathanw {
125b85368e3Skent struct ess_softc *sc;
126b85368e3Skent struct isa_attach_args *ia;
127b85368e3Skent int enablejoy;
128bd7b26e3Snathanw
129f2bccc0aScegger sc = device_private(self);
130*9cb526aaStsutsui
131*9cb526aaStsutsui sc->sc_dev = self;
132b85368e3Skent ia = aux;
133b85368e3Skent enablejoy = 0;
13424b93cebScegger
13524b93cebScegger aprint_naive("\n");
13624b93cebScegger aprint_normal("\n");
137bd7b26e3Snathanw
138bd7b26e3Snathanw sc->sc_ic = ia->ia_ic;
139bd7b26e3Snathanw sc->sc_iot = ia->ia_iot;
1403835413bSthorpej sc->sc_iobase = ia->ia_io[0].ir_addr;
1413835413bSthorpej if (bus_space_map(sc->sc_iot, sc->sc_iobase, ESS_NPORT, 0,
1423835413bSthorpej &sc->sc_ioh)) {
1433835413bSthorpej DPRINTF(("ess_isa_attach: Couldn't map I/O region at %x, "
1443835413bSthorpej "size %x\n", sc->sc_iobase, ESS_NPORT));
145bd7b26e3Snathanw return;
146bd7b26e3Snathanw }
147bd7b26e3Snathanw
1483835413bSthorpej sc->sc_audio1.irq = ia->ia_irq[0].ir_irq;
1499e041fd8Smycroft sc->sc_audio1.ist = IST_EDGE;
1503835413bSthorpej sc->sc_audio1.drq = ia->ia_drq[0].ir_drq;
1515a20d4dfSmycroft sc->sc_audio2.irq = -1;
1523835413bSthorpej sc->sc_audio2.drq = ia->ia_ndrq > 1 ? ia->ia_drq[1].ir_drq : -1;
153bd7b26e3Snathanw
154955c2f90Sdrochner #if NJOY_ESS > 0
15524b93cebScegger if (device_cfdata(self)->cf_flags & 1) {
156955c2f90Sdrochner sc->sc_joy_iot = ia->ia_iot;
157955c2f90Sdrochner if (!bus_space_map(sc->sc_joy_iot, 0x201, 1, 0,
158955c2f90Sdrochner &sc->sc_joy_ioh))
159955c2f90Sdrochner enablejoy = 1;
160955c2f90Sdrochner }
161955c2f90Sdrochner #endif
162955c2f90Sdrochner
16324b93cebScegger aprint_normal_dev(self, "");
164bd7b26e3Snathanw
165955c2f90Sdrochner essattach(sc, enablejoy);
166bd7b26e3Snathanw }
167