xfi.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. MODULE_AUTHOR("Creative Technology Ltd");
  18. MODULE_DESCRIPTION("X-Fi driver version 1.03");
  19. MODULE_LICENSE("GPLv2");
  20. MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}");
  21. static unsigned int reference_rate = 48000;
  22. static unsigned int multiple = 2;
  23. MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)");
  24. module_param(reference_rate, uint, S_IRUGO);
  25. MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)");
  26. module_param(multiple, uint, S_IRUGO);
  27. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  28. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  29. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  30. module_param_array(index, int, NULL, 0444);
  31. MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver");
  32. module_param_array(id, charp, NULL, 0444);
  33. MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver");
  34. module_param_array(enable, bool, NULL, 0444);
  35. MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver");
  36. static struct pci_device_id ct_pci_dev_ids[] = {
  37. /* only X-Fi is supported, so... */
  38. { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1) },
  39. { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2) },
  40. { 0, }
  41. };
  42. MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids);
  43. static int __devinit
  44. ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
  45. {
  46. static int dev;
  47. struct snd_card *card;
  48. struct ct_atc *atc;
  49. int err;
  50. if (dev >= SNDRV_CARDS)
  51. return -ENODEV;
  52. if (!enable[dev]) {
  53. dev++;
  54. return -ENOENT;
  55. }
  56. err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
  57. if (err)
  58. return err;
  59. if ((reference_rate != 48000) && (reference_rate != 44100)) {
  60. printk(KERN_ERR "ctxfi: Invalid reference_rate value %u!!!\n",
  61. reference_rate);
  62. printk(KERN_ERR "ctxfi: The valid values for reference_rate "
  63. "are 48000 and 44100, Value 48000 is assumed.\n");
  64. reference_rate = 48000;
  65. }
  66. if ((multiple != 1) && (multiple != 2)) {
  67. printk(KERN_ERR "ctxfi: Invalid multiple value %u!!!\n",
  68. multiple);
  69. printk(KERN_ERR "ctxfi: The valid values for multiple are "
  70. "1 and 2, Value 2 is assumed.\n");
  71. multiple = 2;
  72. }
  73. err = ct_atc_create(card, pci, reference_rate, multiple, &atc);
  74. if (err < 0)
  75. goto error;
  76. card->private_data = atc;
  77. /* Create alsa devices supported by this card */
  78. err = atc->create_alsa_devs(atc);
  79. if (err < 0)
  80. goto error;
  81. strcpy(card->driver, "SB-XFi");
  82. strcpy(card->shortname, "Creative X-Fi");
  83. strcpy(card->longname, "Creative ALSA Driver X-Fi");
  84. err = snd_card_register(card);
  85. if (err < 0)
  86. goto error;
  87. pci_set_drvdata(pci, card);
  88. dev++;
  89. return 0;
  90. error:
  91. snd_card_free(card);
  92. return err;
  93. }
  94. static void __devexit ct_card_remove(struct pci_dev *pci)
  95. {
  96. snd_card_free(pci_get_drvdata(pci));
  97. pci_set_drvdata(pci, NULL);
  98. }
  99. static struct pci_driver ct_driver = {
  100. .name = "SB-XFi",
  101. .id_table = ct_pci_dev_ids,
  102. .probe = ct_card_probe,
  103. .remove = __devexit_p(ct_card_remove),
  104. };
  105. static int __init ct_card_init(void)
  106. {
  107. return pci_register_driver(&ct_driver);
  108. }
  109. static void __exit ct_card_exit(void)
  110. {
  111. pci_unregister_driver(&ct_driver);
  112. }
  113. module_init(ct_card_init)
  114. module_exit(ct_card_exit)