xfi.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <sound/core.h>
  14. #include <sound/initval.h>
  15. #include "ctatc.h"
  16. #include "ctdrv.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_CREATIVE, PCI_DEVICE_CREATIVE_20K1) },
  31. { PCI_DEVICE(PCI_VENDOR_CREATIVE, PCI_DEVICE_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 "Invalid reference_rate value %u!!!\n"
  53. "The valid values for reference_rate "
  54. "are 48000 and 44100.\nValue 48000 is "
  55. "assumed.\n", reference_rate);
  56. reference_rate = 48000;
  57. }
  58. if ((multiple != 1) && (multiple != 2)) {
  59. printk(KERN_ERR "Invalid multiple value %u!!!\nThe valid "
  60. "values for multiple are 1 and 2.\nValue 2 "
  61. "is assumed.\n", multiple);
  62. multiple = 2;
  63. }
  64. err = ct_atc_create(card, pci, reference_rate, multiple, &atc);
  65. if (err < 0)
  66. goto error;
  67. card->private_data = atc;
  68. /* Create alsa devices supported by this card */
  69. err = atc->create_alsa_devs(atc);
  70. if (err < 0)
  71. goto error;
  72. strcpy(card->driver, "SB-XFi");
  73. strcpy(card->shortname, "Creative X-Fi");
  74. strcpy(card->longname, "Creative ALSA Driver X-Fi");
  75. err = snd_card_register(card);
  76. if (err < 0)
  77. goto error;
  78. pci_set_drvdata(pci, card);
  79. dev++;
  80. return 0;
  81. error:
  82. snd_card_free(card);
  83. return err;
  84. }
  85. static void __devexit ct_card_remove(struct pci_dev *pci)
  86. {
  87. snd_card_free(pci_get_drvdata(pci));
  88. pci_set_drvdata(pci, NULL);
  89. }
  90. static struct pci_driver ct_driver = {
  91. .name = "SB-XFi",
  92. .id_table = ct_pci_dev_ids,
  93. .probe = ct_card_probe,
  94. .remove = __devexit_p(ct_card_remove),
  95. };
  96. static int __init ct_card_init(void)
  97. {
  98. return pci_register_driver(&ct_driver);
  99. }
  100. static void __exit ct_card_exit(void)
  101. {
  102. pci_unregister_driver(&ct_driver);
  103. }
  104. module_init(ct_card_init)
  105. module_exit(ct_card_exit)