11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Generic driver for AD1848/AD1847/CS4248 chips (0.1 Alpha)
41da177e4SLinus Torvalds * Copyright (c) by Tugrul Galatali <galatalt@stuy.edu>,
5c1017a4cSJaroslav Kysela * Jaroslav Kysela <perex@perex.cz>
6c1017a4cSJaroslav Kysela * Based on card-4232.c by Jaroslav Kysela <perex@perex.cz>
71da177e4SLinus Torvalds */
81da177e4SLinus Torvalds
91da177e4SLinus Torvalds #include <linux/init.h>
1068668845STakashi Iwai #include <linux/err.h>
11e2759e33SRene Herman #include <linux/isa.h>
121da177e4SLinus Torvalds #include <linux/time.h>
131da177e4SLinus Torvalds #include <linux/wait.h>
1465a77217SPaul Gortmaker #include <linux/module.h>
151da177e4SLinus Torvalds #include <sound/core.h>
16760fc6b8SKrzysztof Helt #include <sound/wss.h>
171da177e4SLinus Torvalds #include <sound/initval.h>
181da177e4SLinus Torvalds
19e2759e33SRene Herman #define CRD_NAME "Generic AD1848/AD1847/CS4248"
20e2759e33SRene Herman #define DEV_NAME "ad1848"
21e2759e33SRene Herman
22e2759e33SRene Herman MODULE_DESCRIPTION(CRD_NAME);
23c1017a4cSJaroslav Kysela MODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@perex.cz>");
241da177e4SLinus Torvalds MODULE_LICENSE("GPL");
251da177e4SLinus Torvalds
261da177e4SLinus Torvalds static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
271da177e4SLinus Torvalds static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
28a67ff6a5SRusty Russell static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
291da177e4SLinus Torvalds static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
301da177e4SLinus Torvalds static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
311da177e4SLinus Torvalds static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
32a67ff6a5SRusty Russell static bool thinkpad[SNDRV_CARDS]; /* Thinkpad special case */
331da177e4SLinus Torvalds
341da177e4SLinus Torvalds module_param_array(index, int, NULL, 0444);
35e2759e33SRene Herman MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
361da177e4SLinus Torvalds module_param_array(id, charp, NULL, 0444);
37e2759e33SRene Herman MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
381da177e4SLinus Torvalds module_param_array(enable, bool, NULL, 0444);
39e2759e33SRene Herman MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
40e992ef57SDavid Howells module_param_hw_array(port, long, ioport, NULL, 0444);
41e2759e33SRene Herman MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
42e992ef57SDavid Howells module_param_hw_array(irq, int, irq, NULL, 0444);
43e2759e33SRene Herman MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
44e992ef57SDavid Howells module_param_hw_array(dma1, int, dma, NULL, 0444);
45e2759e33SRene Herman MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
461da177e4SLinus Torvalds module_param_array(thinkpad, bool, NULL, 0444);
471da177e4SLinus Torvalds MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series.");
481da177e4SLinus Torvalds
snd_ad1848_match(struct device * dev,unsigned int n)491bff292eSBill Pemberton static int snd_ad1848_match(struct device *dev, unsigned int n)
501da177e4SLinus Torvalds {
51e2759e33SRene Herman if (!enable[n])
52e2759e33SRene Herman return 0;
53e2759e33SRene Herman
54e2759e33SRene Herman if (port[n] == SNDRV_AUTO_PORT) {
550418ff0cSTakashi Iwai dev_err(dev, "please specify port\n");
56e2759e33SRene Herman return 0;
57e2759e33SRene Herman }
58e2759e33SRene Herman if (irq[n] == SNDRV_AUTO_IRQ) {
590418ff0cSTakashi Iwai dev_err(dev, "please specify irq\n");
60e2759e33SRene Herman return 0;
61e2759e33SRene Herman }
62e2759e33SRene Herman if (dma1[n] == SNDRV_AUTO_DMA) {
630418ff0cSTakashi Iwai dev_err(dev, "please specify dma1\n");
64e2759e33SRene Herman return 0;
65e2759e33SRene Herman }
66e2759e33SRene Herman return 1;
67e2759e33SRene Herman }
68e2759e33SRene Herman
snd_ad1848_probe(struct device * dev,unsigned int n)691bff292eSBill Pemberton static int snd_ad1848_probe(struct device *dev, unsigned int n)
70e2759e33SRene Herman {
71c8ff6647STakashi Iwai struct snd_card *card;
72241b3ee7SKrzysztof Helt struct snd_wss *chip;
73e2759e33SRene Herman int error;
741da177e4SLinus Torvalds
75e031577eSTakashi Iwai error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
76c95eadd2STakashi Iwai if (error < 0)
77c95eadd2STakashi Iwai return error;
781da177e4SLinus Torvalds
79760fc6b8SKrzysztof Helt error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], -1,
80760fc6b8SKrzysztof Helt thinkpad[n] ? WSS_HW_THINKPAD : WSS_HW_DETECT,
81760fc6b8SKrzysztof Helt 0, &chip);
82e2759e33SRene Herman if (error < 0)
83e031577eSTakashi Iwai return error;
841da177e4SLinus Torvalds
8568668845STakashi Iwai card->private_data = chip;
861da177e4SLinus Torvalds
87fa60c065SLars-Peter Clausen error = snd_wss_pcm(chip, 0);
88e2759e33SRene Herman if (error < 0)
89e031577eSTakashi Iwai return error;
9043bcd973STakashi Iwai
915664daa1SKrzysztof Helt error = snd_wss_mixer(chip);
92e2759e33SRene Herman if (error < 0)
93e031577eSTakashi Iwai return error;
9443bcd973STakashi Iwai
9575b1a8f9SJoe Perches strscpy(card->driver, "AD1848", sizeof(card->driver));
9675b1a8f9SJoe Perches strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
971da177e4SLinus Torvalds
98003d3e70SArnd Bergmann if (!thinkpad[n])
99*60a9c7f7STakashi Iwai scnprintf(card->longname, sizeof(card->longname),
100003d3e70SArnd Bergmann "%s at 0x%lx, irq %d, dma %d",
101fa60c065SLars-Peter Clausen chip->pcm->name, chip->port, irq[n], dma1[n]);
102003d3e70SArnd Bergmann else
103*60a9c7f7STakashi Iwai scnprintf(card->longname, sizeof(card->longname),
104003d3e70SArnd Bergmann "%s at 0x%lx, irq %d, dma %d [Thinkpad]",
105003d3e70SArnd Bergmann chip->pcm->name, chip->port, irq[n], dma1[n]);
1061da177e4SLinus Torvalds
107e2759e33SRene Herman error = snd_card_register(card);
108e2759e33SRene Herman if (error < 0)
109e031577eSTakashi Iwai return error;
11043bcd973STakashi Iwai
111e2759e33SRene Herman dev_set_drvdata(dev, card);
1121da177e4SLinus Torvalds return 0;
11368668845STakashi Iwai }
11468668845STakashi Iwai
11568668845STakashi Iwai #ifdef CONFIG_PM
snd_ad1848_suspend(struct device * dev,unsigned int n,pm_message_t state)116e2759e33SRene Herman static int snd_ad1848_suspend(struct device *dev, unsigned int n, pm_message_t state)
11768668845STakashi Iwai {
118e2759e33SRene Herman struct snd_card *card = dev_get_drvdata(dev);
119241b3ee7SKrzysztof Helt struct snd_wss *chip = card->private_data;
12068668845STakashi Iwai
12168668845STakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
12268668845STakashi Iwai chip->suspend(chip);
12368668845STakashi Iwai return 0;
12468668845STakashi Iwai }
12568668845STakashi Iwai
snd_ad1848_resume(struct device * dev,unsigned int n)126e2759e33SRene Herman static int snd_ad1848_resume(struct device *dev, unsigned int n)
12768668845STakashi Iwai {
128e2759e33SRene Herman struct snd_card *card = dev_get_drvdata(dev);
129241b3ee7SKrzysztof Helt struct snd_wss *chip = card->private_data;
13068668845STakashi Iwai
13168668845STakashi Iwai chip->resume(chip);
13268668845STakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D0);
13368668845STakashi Iwai return 0;
13468668845STakashi Iwai }
13568668845STakashi Iwai #endif
13668668845STakashi Iwai
137e2759e33SRene Herman static struct isa_driver snd_ad1848_driver = {
138e2759e33SRene Herman .match = snd_ad1848_match,
13968668845STakashi Iwai .probe = snd_ad1848_probe,
14068668845STakashi Iwai #ifdef CONFIG_PM
14168668845STakashi Iwai .suspend = snd_ad1848_suspend,
14268668845STakashi Iwai .resume = snd_ad1848_resume,
14368668845STakashi Iwai #endif
14468668845STakashi Iwai .driver = {
145e2759e33SRene Herman .name = DEV_NAME
146f7a9275dSClemens Ladisch }
147e2759e33SRene Herman };
148f7a9275dSClemens Ladisch
149d2fd147cSWilliam Breathitt Gray module_isa_driver(snd_ad1848_driver, SNDRV_CARDS);
150