138032Speter/*	$NetBSD: opl_ess.c,v 1.20 2022/09/24 23:21:59 thorpej Exp $	*/
238032Speter
3261194Sgshapiro/*-
464562Sgshapiro * Copyright (c) 1999, 2008 The NetBSD Foundation, Inc.
538032Speter * All rights reserved.
638032Speter *
738032Speter * This code is derived from software contributed to The NetBSD Foundation
838032Speter * by Lennart Augustsson.
938032Speter *
1038032Speter * Redistribution and use in source and binary forms, with or without
1138032Speter * modification, are permitted provided that the following conditions
1238032Speter * are met:
1338032Speter * 1. Redistributions of source code must retain the above copyright
1438032Speter *    notice, this list of conditions and the following disclaimer.
1538032Speter * 2. Redistributions in binary form must reproduce the above copyright
1638032Speter *    notice, this list of conditions and the following disclaimer in the
1738032Speter *    documentation and/or other materials provided with the distribution.
1838032Speter *
1938032Speter * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2038032Speter * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2138032Speter * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2238032Speter * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2338032Speter * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2438032Speter * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2538032Speter * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2638032Speter * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2738032Speter * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2838032Speter * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2938032Speter * POSSIBILITY OF SUCH DAMAGE.
3038032Speter */
3138032Speter
32266527Sgshapiro#include <sys/cdefs.h>
3364562Sgshapiro__KERNEL_RCSID(0, "$NetBSD: opl_ess.c,v 1.20 2022/09/24 23:21:59 thorpej Exp $");
3438032Speter
3538032Speter#include <sys/param.h>
3664562Sgshapiro#include <sys/systm.h>
3738032Speter#include <sys/kernel.h>
3838032Speter#include <sys/errno.h>
3938032Speter#include <sys/device.h>
40#include <sys/proc.h>
41#include <sys/conf.h>
42#include <sys/select.h>
43#include <sys/audioio.h>
44#include <sys/midiio.h>
45
46#include <sys/bus.h>
47
48#include <dev/audio/audio_if.h>
49#include <dev/midi_if.h>
50#include <dev/ic/oplreg.h>
51#include <dev/ic/oplvar.h>
52
53#include <dev/isa/isavar.h>
54#include <dev/isa/essvar.h>
55
56extern int	ess_speaker_ctl(void *, int);
57
58int	opl_ess_match(device_t, cfdata_t, void *);
59void	opl_ess_attach(device_t, device_t, void *);
60
61CFATTACH_DECL_NEW(opl_ess, sizeof(struct opl_softc),
62    opl_ess_match, opl_ess_attach, NULL, NULL);
63
64int
65opl_ess_match(device_t parent, cfdata_t match, void *aux)
66{
67	struct audio_attach_args *aa = (struct audio_attach_args *)aux;
68	struct ess_softc *ssc = device_private(parent);
69
70	if (aa->type != AUDIODEV_TYPE_OPL)
71		return (0);
72	return opl_match(ssc->sc_iot, ssc->sc_ioh, 0);
73}
74
75void
76opl_ess_attach(device_t parent, device_t self, void *aux)
77{
78	struct ess_softc *ssc = device_private(parent);
79	struct opl_softc *sc = device_private(self);
80
81	sc->dev = self;
82	sc->ioh = ssc->sc_ioh;
83	sc->iot = ssc->sc_iot;
84	sc->offs = 0;
85	sc->spkrctl = ess_speaker_ctl;
86	sc->spkrarg = ssc;
87	sc->lock = &ssc->sc_intr_lock;
88	strcpy(sc->syn.name, "ESS ");
89
90	opl_attach(sc);
91}
92