0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/init.h>
0010 #include <linux/err.h>
0011 #include <linux/isa.h>
0012 #include <linux/time.h>
0013 #include <linux/wait.h>
0014 #include <linux/module.h>
0015 #include <sound/core.h>
0016 #include <sound/wss.h>
0017 #include <sound/initval.h>
0018
0019 #define CRD_NAME "Generic AD1848/AD1847/CS4248"
0020 #define DEV_NAME "ad1848"
0021
0022 MODULE_DESCRIPTION(CRD_NAME);
0023 MODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@perex.cz>");
0024 MODULE_LICENSE("GPL");
0025
0026 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
0027 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
0028 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
0029 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
0030 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
0031 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
0032 static bool thinkpad[SNDRV_CARDS];
0033
0034 module_param_array(index, int, NULL, 0444);
0035 MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
0036 module_param_array(id, charp, NULL, 0444);
0037 MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
0038 module_param_array(enable, bool, NULL, 0444);
0039 MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
0040 module_param_hw_array(port, long, ioport, NULL, 0444);
0041 MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
0042 module_param_hw_array(irq, int, irq, NULL, 0444);
0043 MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
0044 module_param_hw_array(dma1, int, dma, NULL, 0444);
0045 MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
0046 module_param_array(thinkpad, bool, NULL, 0444);
0047 MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series.");
0048
0049 static int snd_ad1848_match(struct device *dev, unsigned int n)
0050 {
0051 if (!enable[n])
0052 return 0;
0053
0054 if (port[n] == SNDRV_AUTO_PORT) {
0055 dev_err(dev, "please specify port\n");
0056 return 0;
0057 }
0058 if (irq[n] == SNDRV_AUTO_IRQ) {
0059 dev_err(dev, "please specify irq\n");
0060 return 0;
0061 }
0062 if (dma1[n] == SNDRV_AUTO_DMA) {
0063 dev_err(dev, "please specify dma1\n");
0064 return 0;
0065 }
0066 return 1;
0067 }
0068
0069 static int snd_ad1848_probe(struct device *dev, unsigned int n)
0070 {
0071 struct snd_card *card;
0072 struct snd_wss *chip;
0073 int error;
0074
0075 error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
0076 if (error < 0)
0077 return error;
0078
0079 error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], -1,
0080 thinkpad[n] ? WSS_HW_THINKPAD : WSS_HW_DETECT,
0081 0, &chip);
0082 if (error < 0)
0083 return error;
0084
0085 card->private_data = chip;
0086
0087 error = snd_wss_pcm(chip, 0);
0088 if (error < 0)
0089 return error;
0090
0091 error = snd_wss_mixer(chip);
0092 if (error < 0)
0093 return error;
0094
0095 strscpy(card->driver, "AD1848", sizeof(card->driver));
0096 strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
0097
0098 if (!thinkpad[n])
0099 snprintf(card->longname, sizeof(card->longname),
0100 "%s at 0x%lx, irq %d, dma %d",
0101 chip->pcm->name, chip->port, irq[n], dma1[n]);
0102 else
0103 snprintf(card->longname, sizeof(card->longname),
0104 "%s at 0x%lx, irq %d, dma %d [Thinkpad]",
0105 chip->pcm->name, chip->port, irq[n], dma1[n]);
0106
0107 error = snd_card_register(card);
0108 if (error < 0)
0109 return error;
0110
0111 dev_set_drvdata(dev, card);
0112 return 0;
0113 }
0114
0115 #ifdef CONFIG_PM
0116 static int snd_ad1848_suspend(struct device *dev, unsigned int n, pm_message_t state)
0117 {
0118 struct snd_card *card = dev_get_drvdata(dev);
0119 struct snd_wss *chip = card->private_data;
0120
0121 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
0122 chip->suspend(chip);
0123 return 0;
0124 }
0125
0126 static int snd_ad1848_resume(struct device *dev, unsigned int n)
0127 {
0128 struct snd_card *card = dev_get_drvdata(dev);
0129 struct snd_wss *chip = card->private_data;
0130
0131 chip->resume(chip);
0132 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
0133 return 0;
0134 }
0135 #endif
0136
0137 static struct isa_driver snd_ad1848_driver = {
0138 .match = snd_ad1848_match,
0139 .probe = snd_ad1848_probe,
0140 #ifdef CONFIG_PM
0141 .suspend = snd_ad1848_suspend,
0142 .resume = snd_ad1848_resume,
0143 #endif
0144 .driver = {
0145 .name = DEV_NAME
0146 }
0147 };
0148
0149 module_isa_driver(snd_ad1848_driver, SNDRV_CARDS);