18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * xfi linux driver. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/init.h> 98c2ecf20Sopenharmony_ci#include <linux/pci.h> 108c2ecf20Sopenharmony_ci#include <linux/moduleparam.h> 118c2ecf20Sopenharmony_ci#include <linux/pci_ids.h> 128c2ecf20Sopenharmony_ci#include <linux/module.h> 138c2ecf20Sopenharmony_ci#include <sound/core.h> 148c2ecf20Sopenharmony_ci#include <sound/initval.h> 158c2ecf20Sopenharmony_ci#include "ctatc.h" 168c2ecf20Sopenharmony_ci#include "cthardware.h" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ciMODULE_AUTHOR("Creative Technology Ltd"); 198c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("X-Fi driver version 1.03"); 208c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 218c2ecf20Sopenharmony_ciMODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}"); 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic unsigned int reference_rate = 48000; 248c2ecf20Sopenharmony_cistatic unsigned int multiple = 2; 258c2ecf20Sopenharmony_ciMODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)"); 268c2ecf20Sopenharmony_cimodule_param(reference_rate, uint, 0444); 278c2ecf20Sopenharmony_ciMODULE_PARM_DESC(multiple, "Rate multiplier (default=2)"); 288c2ecf20Sopenharmony_cimodule_param(multiple, uint, 0444); 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistatic int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 318c2ecf20Sopenharmony_cistatic char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 328c2ecf20Sopenharmony_cistatic bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 338c2ecf20Sopenharmony_cistatic unsigned int subsystem[SNDRV_CARDS]; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cimodule_param_array(index, int, NULL, 0444); 368c2ecf20Sopenharmony_ciMODULE_PARM_DESC(index, "Index value for Creative X-Fi driver"); 378c2ecf20Sopenharmony_cimodule_param_array(id, charp, NULL, 0444); 388c2ecf20Sopenharmony_ciMODULE_PARM_DESC(id, "ID string for Creative X-Fi driver"); 398c2ecf20Sopenharmony_cimodule_param_array(enable, bool, NULL, 0444); 408c2ecf20Sopenharmony_ciMODULE_PARM_DESC(enable, "Enable Creative X-Fi driver"); 418c2ecf20Sopenharmony_cimodule_param_array(subsystem, int, NULL, 0444); 428c2ecf20Sopenharmony_ciMODULE_PARM_DESC(subsystem, "Override subsystem ID for Creative X-Fi driver"); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic const struct pci_device_id ct_pci_dev_ids[] = { 458c2ecf20Sopenharmony_ci /* only X-Fi is supported, so... */ 468c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1), 478c2ecf20Sopenharmony_ci .driver_data = ATC20K1, 488c2ecf20Sopenharmony_ci }, 498c2ecf20Sopenharmony_ci { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2), 508c2ecf20Sopenharmony_ci .driver_data = ATC20K2, 518c2ecf20Sopenharmony_ci }, 528c2ecf20Sopenharmony_ci { 0, } 538c2ecf20Sopenharmony_ci}; 548c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, ct_pci_dev_ids); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic int 578c2ecf20Sopenharmony_cict_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci static int dev; 608c2ecf20Sopenharmony_ci struct snd_card *card; 618c2ecf20Sopenharmony_ci struct ct_atc *atc; 628c2ecf20Sopenharmony_ci int err; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci if (dev >= SNDRV_CARDS) 658c2ecf20Sopenharmony_ci return -ENODEV; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci if (!enable[dev]) { 688c2ecf20Sopenharmony_ci dev++; 698c2ecf20Sopenharmony_ci return -ENOENT; 708c2ecf20Sopenharmony_ci } 718c2ecf20Sopenharmony_ci err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 728c2ecf20Sopenharmony_ci 0, &card); 738c2ecf20Sopenharmony_ci if (err) 748c2ecf20Sopenharmony_ci return err; 758c2ecf20Sopenharmony_ci if ((reference_rate != 48000) && (reference_rate != 44100)) { 768c2ecf20Sopenharmony_ci dev_err(card->dev, 778c2ecf20Sopenharmony_ci "Invalid reference_rate value %u!!!\n", 788c2ecf20Sopenharmony_ci reference_rate); 798c2ecf20Sopenharmony_ci dev_err(card->dev, 808c2ecf20Sopenharmony_ci "The valid values for reference_rate are 48000 and 44100, Value 48000 is assumed.\n"); 818c2ecf20Sopenharmony_ci reference_rate = 48000; 828c2ecf20Sopenharmony_ci } 838c2ecf20Sopenharmony_ci if ((multiple != 1) && (multiple != 2) && (multiple != 4)) { 848c2ecf20Sopenharmony_ci dev_err(card->dev, "Invalid multiple value %u!!!\n", 858c2ecf20Sopenharmony_ci multiple); 868c2ecf20Sopenharmony_ci dev_err(card->dev, 878c2ecf20Sopenharmony_ci "The valid values for multiple are 1, 2 and 4, Value 2 is assumed.\n"); 888c2ecf20Sopenharmony_ci multiple = 2; 898c2ecf20Sopenharmony_ci } 908c2ecf20Sopenharmony_ci err = ct_atc_create(card, pci, reference_rate, multiple, 918c2ecf20Sopenharmony_ci pci_id->driver_data, subsystem[dev], &atc); 928c2ecf20Sopenharmony_ci if (err < 0) 938c2ecf20Sopenharmony_ci goto error; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci card->private_data = atc; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci /* Create alsa devices supported by this card */ 988c2ecf20Sopenharmony_ci err = ct_atc_create_alsa_devs(atc); 998c2ecf20Sopenharmony_ci if (err < 0) 1008c2ecf20Sopenharmony_ci goto error; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci strcpy(card->driver, "SB-XFi"); 1038c2ecf20Sopenharmony_ci strcpy(card->shortname, "Creative X-Fi"); 1048c2ecf20Sopenharmony_ci snprintf(card->longname, sizeof(card->longname), "%s %s %s", 1058c2ecf20Sopenharmony_ci card->shortname, atc->chip_name, atc->model_name); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci err = snd_card_register(card); 1088c2ecf20Sopenharmony_ci if (err < 0) 1098c2ecf20Sopenharmony_ci goto error; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci pci_set_drvdata(pci, card); 1128c2ecf20Sopenharmony_ci dev++; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci return 0; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cierror: 1178c2ecf20Sopenharmony_ci snd_card_free(card); 1188c2ecf20Sopenharmony_ci return err; 1198c2ecf20Sopenharmony_ci} 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistatic void ct_card_remove(struct pci_dev *pci) 1228c2ecf20Sopenharmony_ci{ 1238c2ecf20Sopenharmony_ci snd_card_free(pci_get_drvdata(pci)); 1248c2ecf20Sopenharmony_ci} 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 1278c2ecf20Sopenharmony_cistatic int ct_card_suspend(struct device *dev) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci struct snd_card *card = dev_get_drvdata(dev); 1308c2ecf20Sopenharmony_ci struct ct_atc *atc = card->private_data; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci return atc->suspend(atc); 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic int ct_card_resume(struct device *dev) 1368c2ecf20Sopenharmony_ci{ 1378c2ecf20Sopenharmony_ci struct snd_card *card = dev_get_drvdata(dev); 1388c2ecf20Sopenharmony_ci struct ct_atc *atc = card->private_data; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci return atc->resume(atc); 1418c2ecf20Sopenharmony_ci} 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(ct_card_pm, ct_card_suspend, ct_card_resume); 1448c2ecf20Sopenharmony_ci#define CT_CARD_PM_OPS &ct_card_pm 1458c2ecf20Sopenharmony_ci#else 1468c2ecf20Sopenharmony_ci#define CT_CARD_PM_OPS NULL 1478c2ecf20Sopenharmony_ci#endif 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic struct pci_driver ct_driver = { 1508c2ecf20Sopenharmony_ci .name = KBUILD_MODNAME, 1518c2ecf20Sopenharmony_ci .id_table = ct_pci_dev_ids, 1528c2ecf20Sopenharmony_ci .probe = ct_card_probe, 1538c2ecf20Sopenharmony_ci .remove = ct_card_remove, 1548c2ecf20Sopenharmony_ci .driver = { 1558c2ecf20Sopenharmony_ci .pm = CT_CARD_PM_OPS, 1568c2ecf20Sopenharmony_ci }, 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cimodule_pci_driver(ct_driver); 160