xfi.c 3.1 KB

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