xfi.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 <sound/core.h>
  15. #include <sound/initval.h>
  16. #include "ctatc.h"
  17. #include "cthardware.h"
  18. MODULE_AUTHOR("Creative Technology Ltd");
  19. MODULE_DESCRIPTION("X-Fi driver version 1.03");
  20. MODULE_LICENSE("GPL v2");
  21. MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}");
  22. static unsigned int reference_rate = 48000;
  23. static unsigned int multiple = 2;
  24. MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)");
  25. module_param(reference_rate, uint, S_IRUGO);
  26. MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)");
  27. module_param(multiple, uint, S_IRUGO);
  28. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  29. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  30. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  31. module_param_array(index, int, NULL, 0444);
  32. MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver");
  33. module_param_array(id, charp, NULL, 0444);
  34. MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver");
  35. module_param_array(enable, bool, NULL, 0444);
  36. MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver");
  37. static 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 __devinit
  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_create(index[dev], id[dev], THIS_MODULE, 0, &card);
  62. if (err)
  63. return err;
  64. if ((reference_rate != 48000) && (reference_rate != 44100)) {
  65. printk(KERN_ERR "ctxfi: Invalid reference_rate value %u!!!\n",
  66. reference_rate);
  67. printk(KERN_ERR "ctxfi: The valid values for reference_rate "
  68. "are 48000 and 44100, Value 48000 is assumed.\n");
  69. reference_rate = 48000;
  70. }
  71. if ((multiple != 1) && (multiple != 2)) {
  72. printk(KERN_ERR "ctxfi: Invalid multiple value %u!!!\n",
  73. multiple);
  74. printk(KERN_ERR "ctxfi: The valid values for multiple are "
  75. "1 and 2, Value 2 is assumed.\n");
  76. multiple = 2;
  77. }
  78. err = ct_atc_create(card, pci, reference_rate, multiple,
  79. pci_id->driver_data, &atc);
  80. if (err < 0)
  81. goto error;
  82. card->private_data = atc;
  83. /* Create alsa devices supported by this card */
  84. err = ct_atc_create_alsa_devs(atc);
  85. if (err < 0)
  86. goto error;
  87. strcpy(card->driver, "SB-XFi");
  88. strcpy(card->shortname, "Creative X-Fi");
  89. snprintf(card->longname, sizeof(card->longname), "%s %s %s",
  90. card->shortname, atc->chip_name, atc->model_name);
  91. err = snd_card_register(card);
  92. if (err < 0)
  93. goto error;
  94. pci_set_drvdata(pci, card);
  95. dev++;
  96. return 0;
  97. error:
  98. snd_card_free(card);
  99. return err;
  100. }
  101. static void __devexit ct_card_remove(struct pci_dev *pci)
  102. {
  103. snd_card_free(pci_get_drvdata(pci));
  104. pci_set_drvdata(pci, NULL);
  105. }
  106. #ifdef CONFIG_PM
  107. static int ct_card_suspend(struct pci_dev *pci, pm_message_t state)
  108. {
  109. struct snd_card *card = pci_get_drvdata(pci);
  110. struct ct_atc *atc = card->private_data;
  111. return atc->suspend(atc, state);
  112. }
  113. static int ct_card_resume(struct pci_dev *pci)
  114. {
  115. struct snd_card *card = pci_get_drvdata(pci);
  116. struct ct_atc *atc = card->private_data;
  117. return atc->resume(atc);
  118. }
  119. #endif
  120. static struct pci_driver ct_driver = {
  121. .name = "SB-XFi",
  122. .id_table = ct_pci_dev_ids,
  123. .probe = ct_card_probe,
  124. .remove = __devexit_p(ct_card_remove),
  125. #ifdef CONFIG_PM
  126. .suspend = ct_card_suspend,
  127. .resume = ct_card_resume,
  128. #endif
  129. };
  130. static int __init ct_card_init(void)
  131. {
  132. return pci_register_driver(&ct_driver);
  133. }
  134. static void __exit ct_card_exit(void)
  135. {
  136. pci_unregister_driver(&ct_driver);
  137. }
  138. module_init(ct_card_init)
  139. module_exit(ct_card_exit)