xfi.c 4.2 KB

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