summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorkhorben <khorben@NetBSD.org>2022-09-07 03:34:43 +0000
committerkhorben <khorben@NetBSD.org>2022-09-07 03:34:43 +0000
commitc90a6c91dee98166ce26bb658f330a6057b7f4fa (patch)
tree87c4f4d5811e52f1143df2c76585523baec8cdb5 /sys/dev
parentd7ce90c8d52613d62fab2091bce0156ec482c54a (diff)
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!
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/emuxki.c64
-rw-r--r--sys/dev/pci/emuxki_boards.c190
-rw-r--r--sys/dev/pci/emuxki_boards.h58
-rw-r--r--sys/dev/pci/emuxkivar.h5
4 files changed, 280 insertions, 37 deletions
diff --git a/sys/dev/pci/emuxki.c b/sys/dev/pci/emuxki.c
index 95656ba12dd..498e32fb8a7 100644
--- a/sys/dev/pci/emuxki.c
+++ b/sys/dev/pci/emuxki.c
@@ -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.75 2022/09/07 01:00:37 khorben Exp $");
#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.75 2022/09/07 01:00:37 khorben Exp $");
*/
#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 self, void *aux)
{
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 self, void *aux)
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 self, void *aux)
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) {
diff --git a/sys/dev/pci/emuxki_boards.c b/sys/dev/pci/emuxki_boards.c
new file mode 100644
index 00000000000..cd849923b9a
--- /dev/null
+++ b/sys/dev/pci/emuxki_boards.c
@@ -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;
+}
diff --git a/sys/dev/pci/emuxki_boards.h b/sys/dev/pci/emuxki_boards.h
new file mode 100644
index 00000000000..185d1c53110
--- /dev/null
+++ b/sys/dev/pci/emuxki_boards.h
@@ -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_ */
diff --git a/sys/dev/pci/emuxkivar.h b/sys/dev/pci/emuxkivar.h
index 00a39f0b0e7..a5bd7e3b8b7 100644
--- a/sys/dev/pci/emuxkivar.h
+++ b/sys/dev/pci/emuxkivar.h
@@ -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;