cs4231.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Generic driver for CS4231 chips
  4. * Copyright (c) by Jaroslav Kysela <[email protected]>
  5. * Originally the CS4232/CS4232A driver, modified for use on CS4231 by
  6. * Tugrul Galatali <[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/mpu401.h>
  17. #include <sound/initval.h>
  18. #define CRD_NAME "Generic CS4231"
  19. #define DEV_NAME "cs4231"
  20. MODULE_DESCRIPTION(CRD_NAME);
  21. MODULE_AUTHOR("Jaroslav Kysela <[email protected]>");
  22. MODULE_LICENSE("GPL");
  23. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  24. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  25. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  26. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  27. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  28. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
  29. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
  30. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  31. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  32. module_param_array(index, int, NULL, 0444);
  33. MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
  34. module_param_array(id, charp, NULL, 0444);
  35. MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
  36. module_param_array(enable, bool, NULL, 0444);
  37. MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
  38. module_param_hw_array(port, long, ioport, NULL, 0444);
  39. MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
  40. module_param_hw_array(mpu_port, long, ioport, NULL, 0444);
  41. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver.");
  42. module_param_hw_array(irq, int, irq, NULL, 0444);
  43. MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
  44. module_param_hw_array(mpu_irq, int, irq, NULL, 0444);
  45. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver.");
  46. module_param_hw_array(dma1, int, dma, NULL, 0444);
  47. MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
  48. module_param_hw_array(dma2, int, dma, NULL, 0444);
  49. MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver.");
  50. static int snd_cs4231_match(struct device *dev, unsigned int n)
  51. {
  52. if (!enable[n])
  53. return 0;
  54. if (port[n] == SNDRV_AUTO_PORT) {
  55. dev_err(dev, "please specify port\n");
  56. return 0;
  57. }
  58. if (irq[n] == SNDRV_AUTO_IRQ) {
  59. dev_err(dev, "please specify irq\n");
  60. return 0;
  61. }
  62. if (dma1[n] == SNDRV_AUTO_DMA) {
  63. dev_err(dev, "please specify dma1\n");
  64. return 0;
  65. }
  66. return 1;
  67. }
  68. static int snd_cs4231_probe(struct device *dev, unsigned int n)
  69. {
  70. struct snd_card *card;
  71. struct snd_wss *chip;
  72. int error;
  73. error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
  74. if (error < 0)
  75. return error;
  76. error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], dma2[n],
  77. WSS_HW_DETECT, 0, &chip);
  78. if (error < 0)
  79. return error;
  80. card->private_data = chip;
  81. error = snd_wss_pcm(chip, 0);
  82. if (error < 0)
  83. return error;
  84. strscpy(card->driver, "CS4231", sizeof(card->driver));
  85. strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
  86. if (dma2[n] < 0)
  87. snprintf(card->longname, sizeof(card->longname),
  88. "%s at 0x%lx, irq %d, dma %d",
  89. chip->pcm->name, chip->port, irq[n], dma1[n]);
  90. else
  91. snprintf(card->longname, sizeof(card->longname),
  92. "%s at 0x%lx, irq %d, dma %d&%d",
  93. chip->pcm->name, chip->port, irq[n], dma1[n], dma2[n]);
  94. error = snd_wss_mixer(chip);
  95. if (error < 0)
  96. return error;
  97. error = snd_wss_timer(chip, 0);
  98. if (error < 0)
  99. return error;
  100. if (mpu_port[n] > 0 && mpu_port[n] != SNDRV_AUTO_PORT) {
  101. if (mpu_irq[n] == SNDRV_AUTO_IRQ)
  102. mpu_irq[n] = -1;
  103. if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
  104. mpu_port[n], 0, mpu_irq[n],
  105. NULL) < 0)
  106. dev_warn(dev, "MPU401 not detected\n");
  107. }
  108. error = snd_card_register(card);
  109. if (error < 0)
  110. return error;
  111. dev_set_drvdata(dev, card);
  112. return 0;
  113. }
  114. #ifdef CONFIG_PM
  115. static int snd_cs4231_suspend(struct device *dev, unsigned int n, pm_message_t state)
  116. {
  117. struct snd_card *card = dev_get_drvdata(dev);
  118. struct snd_wss *chip = card->private_data;
  119. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  120. chip->suspend(chip);
  121. return 0;
  122. }
  123. static int snd_cs4231_resume(struct device *dev, unsigned int n)
  124. {
  125. struct snd_card *card = dev_get_drvdata(dev);
  126. struct snd_wss *chip = card->private_data;
  127. chip->resume(chip);
  128. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  129. return 0;
  130. }
  131. #endif
  132. static struct isa_driver snd_cs4231_driver = {
  133. .match = snd_cs4231_match,
  134. .probe = snd_cs4231_probe,
  135. #ifdef CONFIG_PM
  136. .suspend = snd_cs4231_suspend,
  137. .resume = snd_cs4231_resume,
  138. #endif
  139. .driver = {
  140. .name = DEV_NAME
  141. }
  142. };
  143. module_isa_driver(snd_cs4231_driver, SNDRV_CARDS);