xfi.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * xfi linux driver.
  4. *
  5. * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
  6. */
  7. #include <linux/init.h>
  8. #include <linux/pci.h>
  9. #include <linux/moduleparam.h>
  10. #include <linux/pci_ids.h>
  11. #include <linux/module.h>
  12. #include <sound/core.h>
  13. #include <sound/initval.h>
  14. #include "ctatc.h"
  15. #include "cthardware.h"
  16. MODULE_AUTHOR("Creative Technology Ltd");
  17. MODULE_DESCRIPTION("X-Fi driver version 1.03");
  18. MODULE_LICENSE("GPL v2");
  19. static unsigned int reference_rate = 48000;
  20. static unsigned int multiple = 2;
  21. MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)");
  22. module_param(reference_rate, uint, 0444);
  23. MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)");
  24. module_param(multiple, uint, 0444);
  25. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  26. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  27. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  28. static unsigned int subsystem[SNDRV_CARDS];
  29. module_param_array(index, int, NULL, 0444);
  30. MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver");
  31. module_param_array(id, charp, NULL, 0444);
  32. MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver");
  33. module_param_array(enable, bool, NULL, 0444);
  34. MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver");
  35. module_param_array(subsystem, int, NULL, 0444);
  36. MODULE_PARM_DESC(subsystem, "Override subsystem ID for Creative X-Fi driver");
  37. static const struct pci_device_id ct_pci_dev_ids[] = {
  38. /* only X-Fi is supported, so... */
  39. { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1),
  40. .driver_data = ATC20K1,
  41. },
  42. { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2),
  43. .driver_data = ATC20K2,
  44. },
  45. { 0, }
  46. };
  47. MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids);
  48. static int
  49. ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
  50. {
  51. static int dev;
  52. struct snd_card *card;
  53. struct ct_atc *atc;
  54. int err;
  55. if (dev >= SNDRV_CARDS)
  56. return -ENODEV;
  57. if (!enable[dev]) {
  58. dev++;
  59. return -ENOENT;
  60. }
  61. err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  62. 0, &card);
  63. if (err)
  64. return err;
  65. if ((reference_rate != 48000) && (reference_rate != 44100)) {
  66. dev_err(card->dev,
  67. "Invalid reference_rate value %u!!!\n",
  68. reference_rate);
  69. dev_err(card->dev,
  70. "The valid values for reference_rate are 48000 and 44100, Value 48000 is assumed.\n");
  71. reference_rate = 48000;
  72. }
  73. if ((multiple != 1) && (multiple != 2) && (multiple != 4)) {
  74. dev_err(card->dev, "Invalid multiple value %u!!!\n",
  75. multiple);
  76. dev_err(card->dev,
  77. "The valid values for multiple are 1, 2 and 4, Value 2 is assumed.\n");
  78. multiple = 2;
  79. }
  80. err = ct_atc_create(card, pci, reference_rate, multiple,
  81. pci_id->driver_data, subsystem[dev], &atc);
  82. if (err < 0)
  83. goto error;
  84. card->private_data = atc;
  85. /* Create alsa devices supported by this card */
  86. err = ct_atc_create_alsa_devs(atc);
  87. if (err < 0)
  88. goto error;
  89. strcpy(card->driver, "SB-XFi");
  90. strcpy(card->shortname, "Creative X-Fi");
  91. snprintf(card->longname, sizeof(card->longname), "%s %s %s",
  92. card->shortname, atc->chip_name, atc->model_name);
  93. err = snd_card_register(card);
  94. if (err < 0)
  95. goto error;
  96. pci_set_drvdata(pci, card);
  97. dev++;
  98. return 0;
  99. error:
  100. snd_card_free(card);
  101. return err;
  102. }
  103. static void ct_card_remove(struct pci_dev *pci)
  104. {
  105. snd_card_free(pci_get_drvdata(pci));
  106. }
  107. #ifdef CONFIG_PM_SLEEP
  108. static int ct_card_suspend(struct device *dev)
  109. {
  110. struct snd_card *card = dev_get_drvdata(dev);
  111. struct ct_atc *atc = card->private_data;
  112. return atc->suspend(atc);
  113. }
  114. static int ct_card_resume(struct device *dev)
  115. {
  116. struct snd_card *card = dev_get_drvdata(dev);
  117. struct ct_atc *atc = card->private_data;
  118. return atc->resume(atc);
  119. }
  120. static SIMPLE_DEV_PM_OPS(ct_card_pm, ct_card_suspend, ct_card_resume);
  121. #define CT_CARD_PM_OPS &ct_card_pm
  122. #else
  123. #define CT_CARD_PM_OPS NULL
  124. #endif
  125. static struct pci_driver ct_driver = {
  126. .name = KBUILD_MODNAME,
  127. .id_table = ct_pci_dev_ids,
  128. .probe = ct_card_probe,
  129. .remove = ct_card_remove,
  130. .driver = {
  131. .pm = CT_CARD_PM_OPS,
  132. },
  133. };
  134. module_pci_driver(ct_driver);