ad1848.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Generic driver for AD1848/AD1847/CS4248 chips (0.1 Alpha)
  4. * Copyright (c) by Tugrul Galatali <[email protected]>,
  5. * Jaroslav Kysela <[email protected]>
  6. * Based on card-4232.c by Jaroslav Kysela <[email protected]>
  7. */
  8. #include <linux/init.h>
  9. #include <linux/err.h>
  10. #include <linux/isa.h>
  11. #include <linux/time.h>
  12. #include <linux/wait.h>
  13. #include <linux/module.h>
  14. #include <sound/core.h>
  15. #include <sound/wss.h>
  16. #include <sound/initval.h>
  17. #define CRD_NAME "Generic AD1848/AD1847/CS4248"
  18. #define DEV_NAME "ad1848"
  19. MODULE_DESCRIPTION(CRD_NAME);
  20. MODULE_AUTHOR("Tugrul Galatali <[email protected]>, Jaroslav Kysela <[email protected]>");
  21. MODULE_LICENSE("GPL");
  22. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  23. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  24. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  25. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  26. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
  27. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  28. static bool thinkpad[SNDRV_CARDS]; /* Thinkpad special case */
  29. module_param_array(index, int, NULL, 0444);
  30. MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
  31. module_param_array(id, charp, NULL, 0444);
  32. MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
  33. module_param_array(enable, bool, NULL, 0444);
  34. MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
  35. module_param_hw_array(port, long, ioport, NULL, 0444);
  36. MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
  37. module_param_hw_array(irq, int, irq, NULL, 0444);
  38. MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
  39. module_param_hw_array(dma1, int, dma, NULL, 0444);
  40. MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
  41. module_param_array(thinkpad, bool, NULL, 0444);
  42. MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series.");
  43. static int snd_ad1848_match(struct device *dev, unsigned int n)
  44. {
  45. if (!enable[n])
  46. return 0;
  47. if (port[n] == SNDRV_AUTO_PORT) {
  48. dev_err(dev, "please specify port\n");
  49. return 0;
  50. }
  51. if (irq[n] == SNDRV_AUTO_IRQ) {
  52. dev_err(dev, "please specify irq\n");
  53. return 0;
  54. }
  55. if (dma1[n] == SNDRV_AUTO_DMA) {
  56. dev_err(dev, "please specify dma1\n");
  57. return 0;
  58. }
  59. return 1;
  60. }
  61. static int snd_ad1848_probe(struct device *dev, unsigned int n)
  62. {
  63. struct snd_card *card;
  64. struct snd_wss *chip;
  65. int error;
  66. error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
  67. if (error < 0)
  68. return error;
  69. error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], -1,
  70. thinkpad[n] ? WSS_HW_THINKPAD : WSS_HW_DETECT,
  71. 0, &chip);
  72. if (error < 0)
  73. return error;
  74. card->private_data = chip;
  75. error = snd_wss_pcm(chip, 0);
  76. if (error < 0)
  77. return error;
  78. error = snd_wss_mixer(chip);
  79. if (error < 0)
  80. return error;
  81. strscpy(card->driver, "AD1848", sizeof(card->driver));
  82. strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
  83. if (!thinkpad[n])
  84. snprintf(card->longname, sizeof(card->longname),
  85. "%s at 0x%lx, irq %d, dma %d",
  86. chip->pcm->name, chip->port, irq[n], dma1[n]);
  87. else
  88. snprintf(card->longname, sizeof(card->longname),
  89. "%s at 0x%lx, irq %d, dma %d [Thinkpad]",
  90. chip->pcm->name, chip->port, irq[n], dma1[n]);
  91. error = snd_card_register(card);
  92. if (error < 0)
  93. return error;
  94. dev_set_drvdata(dev, card);
  95. return 0;
  96. }
  97. #ifdef CONFIG_PM
  98. static int snd_ad1848_suspend(struct device *dev, unsigned int n, pm_message_t state)
  99. {
  100. struct snd_card *card = dev_get_drvdata(dev);
  101. struct snd_wss *chip = card->private_data;
  102. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  103. chip->suspend(chip);
  104. return 0;
  105. }
  106. static int snd_ad1848_resume(struct device *dev, unsigned int n)
  107. {
  108. struct snd_card *card = dev_get_drvdata(dev);
  109. struct snd_wss *chip = card->private_data;
  110. chip->resume(chip);
  111. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  112. return 0;
  113. }
  114. #endif
  115. static struct isa_driver snd_ad1848_driver = {
  116. .match = snd_ad1848_match,
  117. .probe = snd_ad1848_probe,
  118. #ifdef CONFIG_PM
  119. .suspend = snd_ad1848_suspend,
  120. .resume = snd_ad1848_resume,
  121. #endif
  122. .driver = {
  123. .name = DEV_NAME
  124. }
  125. };
  126. module_isa_driver(snd_ad1848_driver, SNDRV_CARDS);