Module Name: src Committed By: khorben Date: Wed Sep 7 03:34:44 UTC 2022
Modified Files: src/sys/dev/pci: emuxki.c emuxkivar.h src/sys/modules/emuxki: Makefile.inc Added Files: src/sys/dev/pci: emuxki_boards.c emuxki_boards.h Log Message: emuxki(4): import a list of board definitions This is inspired by the cxdtv(4) driver. Tested on NetBSD/amd64 with a Sound Blaster Live! Value (CT4870, PCI) and with a Sound Blaster Audigy Rx 7.1 (SB1550, PCIe). Additional sound cards sponsored by the NetBSD Foundation; thanks! To generate a diff of this commit: cvs rdiff -u -r1.75 -r1.76 src/sys/dev/pci/emuxki.c cvs rdiff -u -r0 -r1.1 src/sys/dev/pci/emuxki_boards.c \ src/sys/dev/pci/emuxki_boards.h cvs rdiff -u -r1.15 -r1.16 src/sys/dev/pci/emuxkivar.h cvs rdiff -u -r1.1 -r1.2 src/sys/modules/emuxki/Makefile.inc Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pci/emuxki.c diff -u src/sys/dev/pci/emuxki.c:1.75 src/sys/dev/pci/emuxki.c:1.76 --- src/sys/dev/pci/emuxki.c:1.75 Wed Sep 7 01:00:37 2022 +++ src/sys/dev/pci/emuxki.c Wed Sep 7 03:34:43 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: emuxki.c,v 1.75 2022/09/07 01:00:37 khorben Exp $ */ +/* $NetBSD: emuxki.c,v 1.76 2022/09/07 03:34:43 khorben Exp $ */ /*- * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: emuxki.c,v 1.75 2022/09/07 01:00:37 khorben Exp $"); +__KERNEL_RCSID(0, "$NetBSD: emuxki.c,v 1.76 2022/09/07 03:34:43 khorben Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -56,6 +56,7 @@ __KERNEL_RCSID(0, "$NetBSD: emuxki.c,v 1 #include <dev/pci/emuxkireg.h> #include <dev/pci/emuxkivar.h> +#include <dev/pci/emuxki_boards.h> /* #define EMUXKI_DEBUG 1 */ #ifdef EMUXKI_DEBUG @@ -74,7 +75,6 @@ __KERNEL_RCSID(0, "$NetBSD: emuxki.c,v 1 */ #define EMU_PCI_CBIO (0x10) -#define EMU_SUBSYS_APS (0x40011102) /* blackmagic */ #define X1(x) ((sc->sc_type & EMUXKI_AUDIGY) ? EMU_A_##x : EMU_##x) @@ -357,20 +357,17 @@ static int emuxki_match(device_t parent, cfdata_t match, void *aux) { struct pci_attach_args *pa; + pcireg_t reg; pa = aux; - if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_CREATIVELABS) - return 0; - switch (PCI_PRODUCT(pa->pa_id)) { - case PCI_PRODUCT_CREATIVELABS_SBLIVE: - case PCI_PRODUCT_CREATIVELABS_SBLIVE2: - case PCI_PRODUCT_CREATIVELABS_AUDIGY: - case PCI_PRODUCT_CREATIVELABS_SBAUDIGY4: + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG); + if (emuxki_board_lookup(PCI_VENDOR(pa->pa_id), + PCI_PRODUCT(pa->pa_id), reg, + PCI_REVISION(pa->pa_class)) != NULL) return 1; - default: - return 0; - } + + return 0; } static void @@ -378,6 +375,7 @@ emuxki_attach(device_t parent, device_t { struct emuxki_softc *sc; struct pci_attach_args *pa; + const struct emuxki_board *sb; pci_intr_handle_t ih; const char *intrstr; char intrbuf[PCI_INTRSTR_LEN]; @@ -387,7 +385,14 @@ emuxki_attach(device_t parent, device_t sc->sc_dev = self; pa = aux; + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG); + sb = emuxki_board_lookup(PCI_VENDOR(pa->pa_id), + PCI_PRODUCT(pa->pa_id), reg, + PCI_REVISION(pa->pa_class)); + KASSERT(sb != NULL); + pci_aprint_devinfo(pa, "Audio controller"); + aprint_normal_dev(self, "%s [%s]\n", sb->sb_name, sb->sb_board); DPRINTF("dmat=%p\n", (char *)pa->pa_dmat); mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE); @@ -434,28 +439,17 @@ emuxki_attach(device_t parent, device_t aprint_normal_dev(self, "interrupting at %s\n", intrstr); /* XXX it's unknown whether APS is made from Audigy as well */ - if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CREATIVELABS_SBAUDIGY4) { - sc->sc_type = EMUXKI_AUDIGY; - sc->sc_type |= EMUXKI_AUDIGY2; - sc->sc_type |= EMUXKI_AUDIGY2_VALUE; - strlcpy(sc->sc_audv.name, "Audigy2 (value)", + sc->sc_type = sb->sb_flags; + if (sc->sc_type & EMUXKI_AUDIGY2_CA0108) { + strlcpy(sc->sc_audv.name, "Audigy2+CA0108", sizeof(sc->sc_audv.name)); - } else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CREATIVELABS_AUDIGY) { - sc->sc_type = EMUXKI_AUDIGY; - if (PCI_REVISION(pa->pa_class) == 0x04) { - sc->sc_type |= EMUXKI_AUDIGY2; - strlcpy(sc->sc_audv.name, "Audigy2", - sizeof(sc->sc_audv.name)); - } else { - strlcpy(sc->sc_audv.name, "Audigy", - sizeof(sc->sc_audv.name)); - } - } else if (pci_conf_read(pa->pa_pc, pa->pa_tag, - PCI_SUBSYS_ID_REG) == EMU_SUBSYS_APS) { - sc->sc_type = EMUXKI_APS; + } else if (sc->sc_type & EMUXKI_AUDIGY2) { + strlcpy(sc->sc_audv.name, "Audigy2", sizeof(sc->sc_audv.name)); + } else if (sc->sc_type & EMUXKI_AUDIGY) { + strlcpy(sc->sc_audv.name, "Audigy", sizeof(sc->sc_audv.name)); + } else if (sc->sc_type & EMUXKI_APS) { strlcpy(sc->sc_audv.name, "E-mu APS", sizeof(sc->sc_audv.name)); } else { - sc->sc_type = EMUXKI_SBLIVE; strlcpy(sc->sc_audv.name, "SB Live!", sizeof(sc->sc_audv.name)); } snprintf(sc->sc_audv.version, sizeof(sc->sc_audv.version), "0x%02x", @@ -609,7 +603,7 @@ emuxki_init(struct emuxki_softc *sc) emuxki_write(sc, 0, EMU_SPCS1, spcs); emuxki_write(sc, 0, EMU_SPCS2, spcs); - if (sc->sc_type & EMUXKI_AUDIGY2_VALUE) { + if (sc->sc_type & EMUXKI_AUDIGY2_CA0108) { /* Setup SRCMulti_I2S SamplingRate */ emuxki_write(sc, 0, EMU_A2_SPDIF_SAMPLERATE, emuxki_read(sc, 0, EMU_A2_SPDIF_SAMPLERATE) & 0xfffff1ff); @@ -661,7 +655,7 @@ emuxki_init(struct emuxki_softc *sc) EMU_INTE_VOLDECRENABLE | EMU_INTE_MUTEENABLE); - if (sc->sc_type & EMUXKI_AUDIGY2_VALUE) { + if (sc->sc_type & EMUXKI_AUDIGY2_CA0108) { emuxki_writeio_4(sc, EMU_A_IOCFG, 0x0060 | emuxki_readio_4(sc, EMU_A_IOCFG)); } else if (sc->sc_type & EMUXKI_AUDIGY2) { Index: src/sys/dev/pci/emuxkivar.h diff -u src/sys/dev/pci/emuxkivar.h:1.15 src/sys/dev/pci/emuxkivar.h:1.16 --- src/sys/dev/pci/emuxkivar.h:1.15 Wed Sep 7 01:00:37 2022 +++ src/sys/dev/pci/emuxkivar.h Wed Sep 7 03:34:43 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: emuxkivar.h,v 1.15 2022/09/07 01:00:37 khorben Exp $ */ +/* $NetBSD: emuxkivar.h,v 1.16 2022/09/07 03:34:43 khorben Exp $ */ /*- * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc. @@ -32,6 +32,7 @@ #ifndef _DEV_PCI_EMUXKIVAR_H_ #define _DEV_PCI_EMUXKIVAR_H_ +#include <sys/types.h> #include <sys/device.h> #include <sys/audioio.h> #include <sys/mutex.h> @@ -103,7 +104,7 @@ struct emuxki_softc { EMUXKI_SBLIVE = 0x00, EMUXKI_AUDIGY = 0x01, EMUXKI_AUDIGY2 = 0x02, - EMUXKI_AUDIGY2_VALUE = 0x04, + EMUXKI_AUDIGY2_CA0108 = 0x04, EMUXKI_LIVE_5_1 = 0x08, EMUXKI_APS = 0x10 } sc_type; Index: src/sys/modules/emuxki/Makefile.inc diff -u src/sys/modules/emuxki/Makefile.inc:1.1 src/sys/modules/emuxki/Makefile.inc:1.2 --- src/sys/modules/emuxki/Makefile.inc:1.1 Wed Sep 7 00:29:23 2022 +++ src/sys/modules/emuxki/Makefile.inc Wed Sep 7 03:34:44 2022 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.1 2022/09/07 00:29:23 khorben Exp $ +# $NetBSD: Makefile.inc,v 1.2 2022/09/07 03:34:44 khorben Exp $ # This file is used by modules and rump kernels @@ -8,3 +8,4 @@ IOCONFDIR:= ${.PARSEDIR} IOCONF= emuxki.ioconf SRCS+= emuxki.c +SRCS+= emuxki_boards.c Added files: Index: src/sys/dev/pci/emuxki_boards.c diff -u /dev/null src/sys/dev/pci/emuxki_boards.c:1.1 --- /dev/null Wed Sep 7 03:34:44 2022 +++ src/sys/dev/pci/emuxki_boards.c Wed Sep 7 03:34:43 2022 @@ -0,0 +1,190 @@ +/* $NetBSD: emuxki_boards.c,v 1.1 2022/09/07 03:34:43 khorben Exp $ */ + +/*- + * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Yannick Montulet, and by Andrew Doran. + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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> +__KERNEL_RCSID(0, "$NetBSD: emuxki_boards.c,v 1.1 2022/09/07 03:34:43 khorben Exp $"); + +#include <dev/pci/emuxkivar.h> +#include <dev/pci/emuxki_boards.h> + +/* generic fallbacks must be after any corresponding precise match */ +static const struct emuxki_board emuxki_boards[] = { + { + .sb_board = "SB1550", + .sb_name = "Sound Blaster Audigy Rx", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_SBAUDIGY4, + .sb_subsystem = 0x10241102, + .sb_flags = EMUXKI_AUDIGY | EMUXKI_AUDIGY2 | EMUXKI_AUDIGY2_CA0108, + }, + { + .sb_board = "SB0610", + .sb_name = "Sound Blaster Audigy 4", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_SBAUDIGY4, + .sb_subsystem = 0x10211102, + .sb_flags = EMUXKI_AUDIGY | EMUXKI_AUDIGY2 | EMUXKI_AUDIGY2_CA0108, + }, + { + .sb_board = "SB0400", + .sb_name = "Sound Blaster Audigy 2 Value", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_SBAUDIGY4, + .sb_subsystem = 0x10011102, + .sb_flags = EMUXKI_AUDIGY | EMUXKI_AUDIGY2 | EMUXKI_AUDIGY2_CA0108, + }, + { + .sb_board = "generic", + .sb_name = "Sound Blaster Audigy 2 Value", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_SBAUDIGY4, + .sb_flags = EMUXKI_AUDIGY | EMUXKI_AUDIGY2 | EMUXKI_AUDIGY2_CA0108, + }, + { + .sb_board = "SB0350", + .sb_name = "Sound Blaster Audigy 2 ZS", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_AUDIGY, + .sb_subsystem = 0x20021102, + .sb_flags = EMUXKI_AUDIGY | EMUXKI_AUDIGY2, + }, + { + .sb_board = "SB0350", + .sb_name = "Sound Blaster Audigy 2", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_AUDIGY, + .sb_subsystem = 0x20051102, + .sb_flags = EMUXKI_AUDIGY | EMUXKI_AUDIGY2, + }, + { + .sb_board = "SB0240", + .sb_name = "Sound Blaster Audigy 2", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_AUDIGY, + .sb_subsystem = 0x10021102, + .sb_flags = EMUXKI_AUDIGY | EMUXKI_AUDIGY2, + }, + { + .sb_board = "generic", + .sb_name = "Sound Blaster Audigy 2", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_AUDIGY, + .sb_revision = 0x8, + .sb_flags = EMUXKI_AUDIGY | EMUXKI_AUDIGY2, + }, + { + .sb_board = "generic", + .sb_name = "Sound Blaster Audigy 2", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_AUDIGY, + .sb_revision = 0x4, + .sb_flags = EMUXKI_AUDIGY | EMUXKI_AUDIGY2, + }, + { + .sb_board = "generic", + .sb_name = "Sound Blaster Audigy", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_AUDIGY, + .sb_flags = EMUXKI_AUDIGY, + }, + { + .sb_board = "generic", + .sb_name = "Sound Blaster Live! 2", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_SBLIVE2, + .sb_flags = EMUXKI_SBLIVE, + }, + { + .sb_board = "CT4870", + .sb_name = "Sound Blaster Live! Value", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_SBLIVE, + .sb_subsystem = 0x80281102, + .sb_flags = EMUXKI_SBLIVE, + }, + { + .sb_board = "CT4790", + .sb_name = "Sound Blaster PCI512", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_SBLIVE, + .sb_subsystem = 0x80231102, + .sb_flags = EMUXKI_SBLIVE, + }, + { + .sb_board = "PC545", + .sb_name = "Sound Blaster E-mu APS", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_SBLIVE, + .sb_subsystem = 0x40011102, + .sb_flags = EMUXKI_APS, + }, + { + .sb_board = "generic", + .sb_name = "Sound Blaster Live!", + .sb_vendor = PCI_VENDOR_CREATIVELABS, + .sb_product = PCI_PRODUCT_CREATIVELABS_SBLIVE, + .sb_flags = EMUXKI_SBLIVE, + }, +}; + +const struct emuxki_board * +emuxki_board_lookup(pci_vendor_id_t vendor, pci_product_id_t product, + uint32_t subsystem, uint8_t revision) +{ + const struct emuxki_board *sb; + unsigned int i; + + for (i = 0; i < __arraycount(emuxki_boards); i++) { + sb = &emuxki_boards[i]; + + /* precise match */ + if (vendor == sb->sb_vendor && product == sb->sb_product && + subsystem == sb->sb_subsystem && revision == sb->sb_revision) + return sb; + + /* generic fallback (same subsystem, any revision) */ + if (vendor == sb->sb_vendor && product == sb->sb_product && + subsystem == sb->sb_subsystem && sb->sb_revision == 0) + return sb; + + /* generic fallback (any subsystem, specific revision) */ + if (vendor == sb->sb_vendor && product == sb->sb_product && + sb->sb_subsystem == 0 && revision == sb->sb_revision) + return sb; + + /* generic fallback (same vendor, same product) */ + if (vendor == sb->sb_vendor && product == sb->sb_product && + sb->sb_subsystem == 0 && sb->sb_revision == 0) + return sb; + } + + return NULL; +} Index: src/sys/dev/pci/emuxki_boards.h diff -u /dev/null src/sys/dev/pci/emuxki_boards.h:1.1 --- /dev/null Wed Sep 7 03:34:44 2022 +++ src/sys/dev/pci/emuxki_boards.h Wed Sep 7 03:34:43 2022 @@ -0,0 +1,58 @@ +/* $NetBSD: emuxki_boards.h,v 1.1 2022/09/07 03:34:43 khorben Exp $ */ + +/*- + * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Yannick Montulet, and by Andrew Doran. + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef _DEV_PCI_EMUXKI_BOARDS_H_ +#define _DEV_PCI_EMUXKI_BOARDS_H_ + +#include <sys/types.h> +#include <sys/device.h> + +#include <dev/pci/pcidevs.h> +#include <dev/pci/pcireg.h> +#include <dev/pci/pcivar.h> + +#include <dev/pci/emuxkireg.h> + +struct emuxki_board { + const char sb_board[8]; + const char *sb_name; + pci_vendor_id_t sb_vendor; + pci_product_id_t sb_product; + uint32_t sb_subsystem; + uint8_t sb_revision; + + uint32_t sb_flags; +}; + +const struct emuxki_board * +emuxki_board_lookup(pci_vendor_id_t, pci_product_id_t, uint32_t, uint8_t); + +#endif /* _DEV_PCI_EMUXKI_BOARDS_H_ */