Last active
September 22, 2021 07:53
-
-
Save yamori813/b8913634566be3cdc4039fc75ede9561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hint.mpu401.0.at="isa" | |
hint.mpu401.0.port="0x330" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*- | |
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | |
* | |
* Redistribution and use in source and binary forms, with or without | |
* modification, are permitted provided that the following conditions | |
* are met: | |
* 1. Redistributions of source code must retain the above copyright | |
* notice, this list of conditions and the following disclaimer. | |
* 2. Redistributions in binary form must reproduce the above copyright | |
* notice, this list of conditions and the following disclaimer in the | |
* documentation and/or other materials provided with the distribution. | |
* | |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
* SUCH DAMAGE. | |
*/ | |
#include <sys/cdefs.h> | |
__FBSDID("$FreeBSD$"); | |
#include <sys/param.h> | |
#include <sys/systm.h> | |
#include <sys/bus.h> | |
#include <sys/conf.h> | |
#include <sys/kernel.h> | |
#include <sys/module.h> | |
#include <machine/bus.h> | |
#include <sys/rman.h> | |
#include <machine/resource.h> | |
#include <dev/sound/chip.h> | |
#include <dev/sound/pcm/sound.h> | |
#include <dev/sound/midi/midi.h> | |
#include <dev/sound/midi/mpu401.h> | |
#include <isa/isavar.h> | |
#include "mpufoi_if.h" | |
SND_DECLARE_FILE("$FreeBSD$"); | |
struct isa_mpu_softc { | |
struct mtx mtx; | |
struct resource *io_base; /* I/O address for the board */ | |
bus_space_tag_t st; | |
bus_space_handle_t sh; | |
struct mpu401 *mpu; | |
mpu401_intr_t *mpu_intr; | |
}; | |
static devclass_t isa_mpu_devclass; | |
static void | |
isa_mpu_intr(void *arg) | |
{ | |
struct isa_mpu_softc *scp; | |
scp = arg; | |
if (scp->mpu_intr) | |
(scp->mpu_intr)(scp->mpu); | |
} | |
static unsigned char | |
isa_mpufoi_mread(struct mpu401 *arg __unused, void *cookie, int reg) | |
{ | |
struct isa_mpu_softc *scp; | |
unsigned int d; | |
scp = cookie; | |
d = bus_space_read_1(scp->st, scp->sh, reg); | |
return d; | |
} | |
static void | |
isa_mpufoi_mwrite(struct mpu401 *arg __unused, void *cookie, int reg, unsigned char b) | |
{ | |
struct isa_mpu_softc *scp; | |
scp = cookie; | |
bus_space_write_1(scp->st, scp->sh, reg, b); | |
} | |
static int | |
isa_mpufoi_muninit(struct mpu401 *arg __unused, void *cookie) | |
{ | |
struct isa_mpu_softc *scp; | |
scp = cookie; | |
mtx_lock(&scp->mtx); | |
scp->mpu_intr = NULL; | |
mtx_unlock(&scp->mtx); | |
return 0; | |
} | |
static kobj_method_t isa_mpufoi_methods[] = { | |
KOBJMETHOD(mpufoi_read, isa_mpufoi_mread), | |
KOBJMETHOD(mpufoi_write, isa_mpufoi_mwrite), | |
KOBJMETHOD(mpufoi_uninit, isa_mpufoi_muninit), | |
KOBJMETHOD_END | |
}; | |
static DEFINE_CLASS(isa_mpufoi, isa_mpufoi_methods, 0); | |
/************************************************************/ | |
static int | |
isa_mpu_probe(device_t dev) | |
{ | |
device_set_desc(dev, "MPU401 on ISA"); | |
return BUS_PROBE_DEFAULT; | |
} | |
static int | |
isa_mpu_attach(device_t dev) | |
{ | |
struct isa_mpu_softc *scp; | |
int rc; | |
int rid; | |
rc = 0; | |
scp = device_get_softc(dev); | |
mtx_init(&scp->mtx, device_get_nameunit(dev), "midi softc", MTX_DEF); | |
rid = 0; | |
scp->io_base = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); | |
scp->st = rman_get_bustag(scp->io_base); | |
scp->sh = rman_get_bushandle(scp->io_base); | |
/* init the MPU401 interface. */ | |
scp->mpu = mpu401_init(&isa_mpufoi_class, scp, isa_mpu_intr, | |
&scp->mpu_intr); | |
return rc; | |
} | |
static int | |
isa_mpu_detach(device_t dev) | |
{ | |
struct isa_mpu_softc *scp; | |
int rc; | |
rc = 0; | |
scp = device_get_softc(dev); | |
return rc; | |
} | |
static device_method_t isa_mpu_methods[] = { | |
/* Device interface */ | |
DEVMETHOD(device_probe, isa_mpu_probe), | |
DEVMETHOD(device_attach, isa_mpu_attach), | |
DEVMETHOD(device_detach, isa_mpu_detach), | |
DEVMETHOD_END | |
}; | |
static driver_t isa_mpu_driver = { | |
"mpu401", | |
isa_mpu_methods, | |
sizeof(struct isa_mpu_softc), | |
}; | |
DRIVER_MODULE(isa_mpu, isa, isa_mpu_driver, isa_mpu_devclass, 0, 0); | |
MODULE_DEPEND(isa_mpu, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER); | |
MODULE_VERSION(isa_mpu, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment