1*e622eac4Sisaki /* $NetBSD: ess_isapnp.c,v 1.23 2019/05/08 13:40:18 isaki Exp $ */
2202c97c5Smatt
3202c97c5Smatt /*
4202c97c5Smatt * Copyright (c) 1991-1993 Regents of the University of California.
5202c97c5Smatt * All rights reserved.
6202c97c5Smatt *
7202c97c5Smatt * Redistribution and use in source and binary forms, with or without
8202c97c5Smatt * modification, are permitted provided that the following conditions
9202c97c5Smatt * are met:
10202c97c5Smatt * 1. Redistributions of source code must retain the above copyright
11202c97c5Smatt * notice, this list of conditions and the following disclaimer.
12202c97c5Smatt * 2. Redistributions in binary form must reproduce the above copyright
13202c97c5Smatt * notice, this list of conditions and the following disclaimer in the
14202c97c5Smatt * documentation and/or other materials provided with the distribution.
15202c97c5Smatt * 3. All advertising materials mentioning features or use of this software
16202c97c5Smatt * must display the following acknowledgement:
17202c97c5Smatt * This product includes software developed by the Computer Systems
18202c97c5Smatt * Engineering Group at Lawrence Berkeley Laboratory.
19202c97c5Smatt * 4. Neither the name of the University nor of the Laboratory may be used
20202c97c5Smatt * to endorse or promote products derived from this software without
21202c97c5Smatt * specific prior written permission.
22202c97c5Smatt *
23202c97c5Smatt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24202c97c5Smatt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25202c97c5Smatt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26202c97c5Smatt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27202c97c5Smatt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28202c97c5Smatt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29202c97c5Smatt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30202c97c5Smatt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31202c97c5Smatt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32202c97c5Smatt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33202c97c5Smatt * SUCH DAMAGE.
34202c97c5Smatt *
35202c97c5Smatt */
36202c97c5Smatt
379d2580ffSlukem #include <sys/cdefs.h>
38*e622eac4Sisaki __KERNEL_RCSID(0, "$NetBSD: ess_isapnp.c,v 1.23 2019/05/08 13:40:18 isaki Exp $");
399d2580ffSlukem
40202c97c5Smatt #include <sys/param.h>
41202c97c5Smatt #include <sys/systm.h>
42202c97c5Smatt #include <sys/errno.h>
43202c97c5Smatt #include <sys/ioctl.h>
44202c97c5Smatt #include <sys/syslog.h>
45202c97c5Smatt #include <sys/device.h>
46202c97c5Smatt #include <sys/proc.h>
47202c97c5Smatt
48a2a38285Sad #include <sys/bus.h>
49202c97c5Smatt
50202c97c5Smatt #include <sys/audioio.h>
51*e622eac4Sisaki #include <dev/audio/audio_if.h>
52202c97c5Smatt
53202c97c5Smatt #include <dev/isa/isavar.h>
54202c97c5Smatt #include <dev/isa/isadmavar.h>
55202c97c5Smatt
56202c97c5Smatt #include <dev/isapnp/isapnpreg.h>
57202c97c5Smatt #include <dev/isapnp/isapnpvar.h>
58202c97c5Smatt #include <dev/isapnp/isapnpdevs.h>
59202c97c5Smatt
60202c97c5Smatt #include <dev/isa/essreg.h>
61202c97c5Smatt #include <dev/isa/essvar.h>
62202c97c5Smatt
6306e69f38Scegger int ess_isapnp_match(device_t, cfdata_t, void *);
6406e69f38Scegger void ess_isapnp_attach(device_t, device_t, void *);
65202c97c5Smatt
669cb526aaStsutsui CFATTACH_DECL_NEW(ess_isapnp, sizeof(struct ess_softc),
67c9b3657cSthorpej ess_isapnp_match, ess_isapnp_attach, NULL, NULL);
68202c97c5Smatt
69202c97c5Smatt /*
70202c97c5Smatt * Probe / attach routines.
71202c97c5Smatt */
72202c97c5Smatt
73202c97c5Smatt /*
74a6a09bcdSaugustss * Probe for the ess hardware.
75202c97c5Smatt */
76202c97c5Smatt int
ess_isapnp_match(device_t parent,cfdata_t match,void * aux)7706e69f38Scegger ess_isapnp_match(device_t parent, cfdata_t match, void *aux)
78202c97c5Smatt {
796ada3afdSmycroft int pri, variant;
802cccf3bdSmycroft
816ada3afdSmycroft pri = isapnp_devmatch(aux, &isapnp_ess_devinfo, &variant);
826ada3afdSmycroft if (pri && variant > 0)
836ada3afdSmycroft pri = 0;
84069e72cbSkent return pri;
85202c97c5Smatt }
86202c97c5Smatt
87202c97c5Smatt
88202c97c5Smatt /*
89202c97c5Smatt * Attach hardware to driver, attach hardware driver to audio
90202c97c5Smatt * pseudo-device driver.
91202c97c5Smatt */
92202c97c5Smatt void
ess_isapnp_attach(device_t parent,device_t self,void * aux)9306e69f38Scegger ess_isapnp_attach(device_t parent, device_t self, void *aux)
94202c97c5Smatt {
95069e72cbSkent struct ess_softc *sc;
96069e72cbSkent struct isapnp_attach_args *ipa;
97202c97c5Smatt
98838ee1e0Sthorpej sc = device_private(self);
999cb526aaStsutsui sc->sc_dev = self;
100069e72cbSkent ipa = aux;
10124b93cebScegger
10224b93cebScegger aprint_naive("\n");
10324b93cebScegger aprint_normal("\n");
104202c97c5Smatt
105202c97c5Smatt if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
10624b93cebScegger aprint_error_dev(self, "error in region allocation\n");
107202c97c5Smatt return;
108202c97c5Smatt }
109202c97c5Smatt
110202c97c5Smatt sc->sc_ic = ipa->ipa_ic;
111202c97c5Smatt
112202c97c5Smatt sc->sc_iot = ipa->ipa_iot;
113202c97c5Smatt sc->sc_iobase = ipa->ipa_io[0].base;
114202c97c5Smatt sc->sc_ioh = ipa->ipa_io[0].h;
115202c97c5Smatt
1164bd7ef02Smycroft sc->sc_audio1.irq = ipa->ipa_irq[0].num;
1174bd7ef02Smycroft sc->sc_audio1.ist = ipa->ipa_irq[0].type;
1184bd7ef02Smycroft sc->sc_audio1.drq = ipa->ipa_drq[0].num;
119270a41c3Smycroft sc->sc_audio2.irq = -1;
1204bd7ef02Smycroft sc->sc_audio2.drq = ipa->ipa_drq[1].num;
121202c97c5Smatt
122202c97c5Smatt if (!essmatch(sc)) {
12324b93cebScegger aprint_error_dev(self, "essmatch failed\n");
124202c97c5Smatt return;
125202c97c5Smatt }
126202c97c5Smatt
12724b93cebScegger aprint_normal_dev(self, "");
128202c97c5Smatt
1297ba5b8cdSdrochner essattach(sc, 0);
130202c97c5Smatt }
131