18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Driver for Trident 4DWave DX/NX & SiS SI7018 Audio PCI soundcard 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Driver was originated by Trident <audio@tridentmicro.com> 68c2ecf20Sopenharmony_ci * Fri Feb 19 15:55:28 MST 1999 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/init.h> 108c2ecf20Sopenharmony_ci#include <linux/pci.h> 118c2ecf20Sopenharmony_ci#include <linux/time.h> 128c2ecf20Sopenharmony_ci#include <linux/module.h> 138c2ecf20Sopenharmony_ci#include <sound/core.h> 148c2ecf20Sopenharmony_ci#include "trident.h" 158c2ecf20Sopenharmony_ci#include <sound/initval.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ciMODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, <audio@tridentmicro.com>"); 188c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Trident 4D-WaveDX/NX & SiS SI7018"); 198c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 208c2ecf20Sopenharmony_ciMODULE_SUPPORTED_DEVICE("{{Trident,4DWave DX}," 218c2ecf20Sopenharmony_ci "{Trident,4DWave NX}," 228c2ecf20Sopenharmony_ci "{SiS,SI7018 PCI Audio}," 238c2ecf20Sopenharmony_ci "{Best Union,Miss Melody 4DWave PCI}," 248c2ecf20Sopenharmony_ci "{HIS,4DWave PCI}," 258c2ecf20Sopenharmony_ci "{Warpspeed,ONSpeed 4DWave PCI}," 268c2ecf20Sopenharmony_ci "{Aztech Systems,PCI 64-Q3D}," 278c2ecf20Sopenharmony_ci "{Addonics,SV 750}," 288c2ecf20Sopenharmony_ci "{CHIC,True Sound 4Dwave}," 298c2ecf20Sopenharmony_ci "{Shark,Predator4D-PCI}," 308c2ecf20Sopenharmony_ci "{Jaton,SonicWave 4D}," 318c2ecf20Sopenharmony_ci "{Hoontech,SoundTrack Digital 4DWave NX}}"); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistatic int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 348c2ecf20Sopenharmony_cistatic char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 358c2ecf20Sopenharmony_cistatic bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 368c2ecf20Sopenharmony_cistatic int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 32}; 378c2ecf20Sopenharmony_cistatic int wavetable_size[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8192}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cimodule_param_array(index, int, NULL, 0444); 408c2ecf20Sopenharmony_ciMODULE_PARM_DESC(index, "Index value for Trident 4DWave PCI soundcard."); 418c2ecf20Sopenharmony_cimodule_param_array(id, charp, NULL, 0444); 428c2ecf20Sopenharmony_ciMODULE_PARM_DESC(id, "ID string for Trident 4DWave PCI soundcard."); 438c2ecf20Sopenharmony_cimodule_param_array(enable, bool, NULL, 0444); 448c2ecf20Sopenharmony_ciMODULE_PARM_DESC(enable, "Enable Trident 4DWave PCI soundcard."); 458c2ecf20Sopenharmony_cimodule_param_array(pcm_channels, int, NULL, 0444); 468c2ecf20Sopenharmony_ciMODULE_PARM_DESC(pcm_channels, "Number of hardware channels assigned for PCM."); 478c2ecf20Sopenharmony_cimodule_param_array(wavetable_size, int, NULL, 0444); 488c2ecf20Sopenharmony_ciMODULE_PARM_DESC(wavetable_size, "Maximum memory size in kB for wavetable synth."); 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic const struct pci_device_id snd_trident_ids[] = { 518c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_DX), 528c2ecf20Sopenharmony_ci PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0}, 538c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_NX), 548c2ecf20Sopenharmony_ci 0, 0, 0}, 558c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_7018), 0, 0, 0}, 568c2ecf20Sopenharmony_ci { 0, } 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, snd_trident_ids); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistatic int snd_trident_probe(struct pci_dev *pci, 628c2ecf20Sopenharmony_ci const struct pci_device_id *pci_id) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci static int dev; 658c2ecf20Sopenharmony_ci struct snd_card *card; 668c2ecf20Sopenharmony_ci struct snd_trident *trident; 678c2ecf20Sopenharmony_ci const char *str; 688c2ecf20Sopenharmony_ci int err, pcm_dev = 0; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci if (dev >= SNDRV_CARDS) 718c2ecf20Sopenharmony_ci return -ENODEV; 728c2ecf20Sopenharmony_ci if (!enable[dev]) { 738c2ecf20Sopenharmony_ci dev++; 748c2ecf20Sopenharmony_ci return -ENOENT; 758c2ecf20Sopenharmony_ci } 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 788c2ecf20Sopenharmony_ci 0, &card); 798c2ecf20Sopenharmony_ci if (err < 0) 808c2ecf20Sopenharmony_ci return err; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci if ((err = snd_trident_create(card, pci, 838c2ecf20Sopenharmony_ci pcm_channels[dev], 848c2ecf20Sopenharmony_ci ((pci->vendor << 16) | pci->device) == TRIDENT_DEVICE_ID_SI7018 ? 1 : 2, 858c2ecf20Sopenharmony_ci wavetable_size[dev], 868c2ecf20Sopenharmony_ci &trident)) < 0) { 878c2ecf20Sopenharmony_ci snd_card_free(card); 888c2ecf20Sopenharmony_ci return err; 898c2ecf20Sopenharmony_ci } 908c2ecf20Sopenharmony_ci card->private_data = trident; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci switch (trident->device) { 938c2ecf20Sopenharmony_ci case TRIDENT_DEVICE_ID_DX: 948c2ecf20Sopenharmony_ci str = "TRID4DWAVEDX"; 958c2ecf20Sopenharmony_ci break; 968c2ecf20Sopenharmony_ci case TRIDENT_DEVICE_ID_NX: 978c2ecf20Sopenharmony_ci str = "TRID4DWAVENX"; 988c2ecf20Sopenharmony_ci break; 998c2ecf20Sopenharmony_ci case TRIDENT_DEVICE_ID_SI7018: 1008c2ecf20Sopenharmony_ci str = "SI7018"; 1018c2ecf20Sopenharmony_ci break; 1028c2ecf20Sopenharmony_ci default: 1038c2ecf20Sopenharmony_ci str = "Unknown"; 1048c2ecf20Sopenharmony_ci } 1058c2ecf20Sopenharmony_ci strcpy(card->driver, str); 1068c2ecf20Sopenharmony_ci if (trident->device == TRIDENT_DEVICE_ID_SI7018) { 1078c2ecf20Sopenharmony_ci strcpy(card->shortname, "SiS "); 1088c2ecf20Sopenharmony_ci } else { 1098c2ecf20Sopenharmony_ci strcpy(card->shortname, "Trident "); 1108c2ecf20Sopenharmony_ci } 1118c2ecf20Sopenharmony_ci strcat(card->shortname, str); 1128c2ecf20Sopenharmony_ci sprintf(card->longname, "%s PCI Audio at 0x%lx, irq %d", 1138c2ecf20Sopenharmony_ci card->shortname, trident->port, trident->irq); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci if ((err = snd_trident_pcm(trident, pcm_dev++)) < 0) { 1168c2ecf20Sopenharmony_ci snd_card_free(card); 1178c2ecf20Sopenharmony_ci return err; 1188c2ecf20Sopenharmony_ci } 1198c2ecf20Sopenharmony_ci switch (trident->device) { 1208c2ecf20Sopenharmony_ci case TRIDENT_DEVICE_ID_DX: 1218c2ecf20Sopenharmony_ci case TRIDENT_DEVICE_ID_NX: 1228c2ecf20Sopenharmony_ci if ((err = snd_trident_foldback_pcm(trident, pcm_dev++)) < 0) { 1238c2ecf20Sopenharmony_ci snd_card_free(card); 1248c2ecf20Sopenharmony_ci return err; 1258c2ecf20Sopenharmony_ci } 1268c2ecf20Sopenharmony_ci break; 1278c2ecf20Sopenharmony_ci } 1288c2ecf20Sopenharmony_ci if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) { 1298c2ecf20Sopenharmony_ci if ((err = snd_trident_spdif_pcm(trident, pcm_dev++)) < 0) { 1308c2ecf20Sopenharmony_ci snd_card_free(card); 1318c2ecf20Sopenharmony_ci return err; 1328c2ecf20Sopenharmony_ci } 1338c2ecf20Sopenharmony_ci } 1348c2ecf20Sopenharmony_ci if (trident->device != TRIDENT_DEVICE_ID_SI7018 && 1358c2ecf20Sopenharmony_ci (err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE, 1368c2ecf20Sopenharmony_ci trident->midi_port, 1378c2ecf20Sopenharmony_ci MPU401_INFO_INTEGRATED | 1388c2ecf20Sopenharmony_ci MPU401_INFO_IRQ_HOOK, 1398c2ecf20Sopenharmony_ci -1, &trident->rmidi)) < 0) { 1408c2ecf20Sopenharmony_ci snd_card_free(card); 1418c2ecf20Sopenharmony_ci return err; 1428c2ecf20Sopenharmony_ci } 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci snd_trident_create_gameport(trident); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci if ((err = snd_card_register(card)) < 0) { 1478c2ecf20Sopenharmony_ci snd_card_free(card); 1488c2ecf20Sopenharmony_ci return err; 1498c2ecf20Sopenharmony_ci } 1508c2ecf20Sopenharmony_ci pci_set_drvdata(pci, card); 1518c2ecf20Sopenharmony_ci dev++; 1528c2ecf20Sopenharmony_ci return 0; 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic void snd_trident_remove(struct pci_dev *pci) 1568c2ecf20Sopenharmony_ci{ 1578c2ecf20Sopenharmony_ci snd_card_free(pci_get_drvdata(pci)); 1588c2ecf20Sopenharmony_ci} 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_cistatic struct pci_driver trident_driver = { 1618c2ecf20Sopenharmony_ci .name = KBUILD_MODNAME, 1628c2ecf20Sopenharmony_ci .id_table = snd_trident_ids, 1638c2ecf20Sopenharmony_ci .probe = snd_trident_probe, 1648c2ecf20Sopenharmony_ci .remove = snd_trident_remove, 1658c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 1668c2ecf20Sopenharmony_ci .driver = { 1678c2ecf20Sopenharmony_ci .pm = &snd_trident_pm, 1688c2ecf20Sopenharmony_ci }, 1698c2ecf20Sopenharmony_ci#endif 1708c2ecf20Sopenharmony_ci}; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_cimodule_pci_driver(trident_driver); 173