xref: /openbmc/linux/sound/pci/trident/trident.c (revision 8dda2eac)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *  Driver for Trident 4DWave DX/NX & SiS SI7018 Audio PCI soundcard
4  *
5  *  Driver was originated by Trident <audio@tridentmicro.com>
6  *  			     Fri Feb 19 15:55:28 MST 1999
7  */
8 
9 #include <linux/init.h>
10 #include <linux/pci.h>
11 #include <linux/time.h>
12 #include <linux/module.h>
13 #include <sound/core.h>
14 #include "trident.h"
15 #include <sound/initval.h>
16 
17 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, <audio@tridentmicro.com>");
18 MODULE_DESCRIPTION("Trident 4D-WaveDX/NX & SiS SI7018");
19 MODULE_LICENSE("GPL");
20 
21 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
22 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
23 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;	/* Enable this card */
24 static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 32};
25 static int wavetable_size[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8192};
26 
27 module_param_array(index, int, NULL, 0444);
28 MODULE_PARM_DESC(index, "Index value for Trident 4DWave PCI soundcard.");
29 module_param_array(id, charp, NULL, 0444);
30 MODULE_PARM_DESC(id, "ID string for Trident 4DWave PCI soundcard.");
31 module_param_array(enable, bool, NULL, 0444);
32 MODULE_PARM_DESC(enable, "Enable Trident 4DWave PCI soundcard.");
33 module_param_array(pcm_channels, int, NULL, 0444);
34 MODULE_PARM_DESC(pcm_channels, "Number of hardware channels assigned for PCM.");
35 module_param_array(wavetable_size, int, NULL, 0444);
36 MODULE_PARM_DESC(wavetable_size, "Maximum memory size in kB for wavetable synth.");
37 
38 static const struct pci_device_id snd_trident_ids[] = {
39 	{PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_DX),
40 		PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
41 	{PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_NX),
42 		0, 0, 0},
43 	{PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_7018), 0, 0, 0},
44 	{ 0, }
45 };
46 
47 MODULE_DEVICE_TABLE(pci, snd_trident_ids);
48 
49 static int snd_trident_probe(struct pci_dev *pci,
50 			     const struct pci_device_id *pci_id)
51 {
52 	static int dev;
53 	struct snd_card *card;
54 	struct snd_trident *trident;
55 	const char *str;
56 	int err, pcm_dev = 0;
57 
58 	if (dev >= SNDRV_CARDS)
59 		return -ENODEV;
60 	if (!enable[dev]) {
61 		dev++;
62 		return -ENOENT;
63 	}
64 
65 	err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
66 			   0, &card);
67 	if (err < 0)
68 		return err;
69 
70 	err = snd_trident_create(card, pci,
71 				 pcm_channels[dev],
72 				 ((pci->vendor << 16) | pci->device) == TRIDENT_DEVICE_ID_SI7018 ? 1 : 2,
73 				 wavetable_size[dev],
74 				 &trident);
75 	if (err < 0) {
76 		snd_card_free(card);
77 		return err;
78 	}
79 	card->private_data = trident;
80 
81 	switch (trident->device) {
82 	case TRIDENT_DEVICE_ID_DX:
83 		str = "TRID4DWAVEDX";
84 		break;
85 	case TRIDENT_DEVICE_ID_NX:
86 		str = "TRID4DWAVENX";
87 		break;
88 	case TRIDENT_DEVICE_ID_SI7018:
89 		str = "SI7018";
90 		break;
91 	default:
92 		str = "Unknown";
93 	}
94 	strcpy(card->driver, str);
95 	if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
96 		strcpy(card->shortname, "SiS ");
97 	} else {
98 		strcpy(card->shortname, "Trident ");
99 	}
100 	strcat(card->shortname, str);
101 	sprintf(card->longname, "%s PCI Audio at 0x%lx, irq %d",
102 		card->shortname, trident->port, trident->irq);
103 
104 	err = snd_trident_pcm(trident, pcm_dev++);
105 	if (err < 0) {
106 		snd_card_free(card);
107 		return err;
108 	}
109 	switch (trident->device) {
110 	case TRIDENT_DEVICE_ID_DX:
111 	case TRIDENT_DEVICE_ID_NX:
112 		err = snd_trident_foldback_pcm(trident, pcm_dev++);
113 		if (err < 0) {
114 			snd_card_free(card);
115 			return err;
116 		}
117 		break;
118 	}
119 	if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) {
120 		err = snd_trident_spdif_pcm(trident, pcm_dev++);
121 		if (err < 0) {
122 			snd_card_free(card);
123 			return err;
124 		}
125 	}
126 	if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
127 		err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE,
128 					  trident->midi_port,
129 					  MPU401_INFO_INTEGRATED |
130 					  MPU401_INFO_IRQ_HOOK,
131 					  -1, &trident->rmidi);
132 		if (err < 0) {
133 			snd_card_free(card);
134 			return err;
135 		}
136 	}
137 
138 	snd_trident_create_gameport(trident);
139 
140 	err = snd_card_register(card);
141 	if (err < 0) {
142 		snd_card_free(card);
143 		return err;
144 	}
145 	pci_set_drvdata(pci, card);
146 	dev++;
147 	return 0;
148 }
149 
150 static void snd_trident_remove(struct pci_dev *pci)
151 {
152 	snd_card_free(pci_get_drvdata(pci));
153 }
154 
155 static struct pci_driver trident_driver = {
156 	.name = KBUILD_MODNAME,
157 	.id_table = snd_trident_ids,
158 	.probe = snd_trident_probe,
159 	.remove = snd_trident_remove,
160 #ifdef CONFIG_PM_SLEEP
161 	.driver = {
162 		.pm = &snd_trident_pm,
163 	},
164 #endif
165 };
166 
167 module_pci_driver(trident_driver);
168