xref: /openbmc/linux/sound/isa/ad1848/ad1848.c (revision 1a59d1b8e05ea6ab45f7e18897de1ef0e6bc3da6)
1*1a59d1b8SThomas 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 MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1848},"
261da177e4SLinus Torvalds 	        "{Analog Devices,AD1847},"
271da177e4SLinus Torvalds 		"{Crystal Semiconductors,CS4248}}");
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
301da177e4SLinus Torvalds static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
31a67ff6a5SRusty Russell static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;	/* Enable this card */
321da177e4SLinus Torvalds static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
331da177e4SLinus Torvalds static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 5,7,9,11,12,15 */
341da177e4SLinus Torvalds static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */
35a67ff6a5SRusty Russell static bool thinkpad[SNDRV_CARDS];			/* Thinkpad special case */
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds module_param_array(index, int, NULL, 0444);
38e2759e33SRene Herman MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
391da177e4SLinus Torvalds module_param_array(id, charp, NULL, 0444);
40e2759e33SRene Herman MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
411da177e4SLinus Torvalds module_param_array(enable, bool, NULL, 0444);
42e2759e33SRene Herman MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
43e992ef57SDavid Howells module_param_hw_array(port, long, ioport, NULL, 0444);
44e2759e33SRene Herman MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
45e992ef57SDavid Howells module_param_hw_array(irq, int, irq, NULL, 0444);
46e2759e33SRene Herman MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
47e992ef57SDavid Howells module_param_hw_array(dma1, int, dma, NULL, 0444);
48e2759e33SRene Herman MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
491da177e4SLinus Torvalds module_param_array(thinkpad, bool, NULL, 0444);
501da177e4SLinus Torvalds MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series.");
511da177e4SLinus Torvalds 
521bff292eSBill Pemberton static int snd_ad1848_match(struct device *dev, unsigned int n)
531da177e4SLinus Torvalds {
54e2759e33SRene Herman 	if (!enable[n])
55e2759e33SRene Herman 		return 0;
56e2759e33SRene Herman 
57e2759e33SRene Herman 	if (port[n] == SNDRV_AUTO_PORT) {
580418ff0cSTakashi Iwai 		dev_err(dev, "please specify port\n");
59e2759e33SRene Herman 		return 0;
60e2759e33SRene Herman 	}
61e2759e33SRene Herman 	if (irq[n] == SNDRV_AUTO_IRQ) {
620418ff0cSTakashi Iwai 		dev_err(dev, "please specify irq\n");
63e2759e33SRene Herman 		return 0;
64e2759e33SRene Herman 	}
65e2759e33SRene Herman 	if (dma1[n] == SNDRV_AUTO_DMA) {
660418ff0cSTakashi Iwai 		dev_err(dev, "please specify dma1\n");
67e2759e33SRene Herman 		return 0;
68e2759e33SRene Herman 	}
69e2759e33SRene Herman 	return 1;
70e2759e33SRene Herman }
71e2759e33SRene Herman 
721bff292eSBill Pemberton static int snd_ad1848_probe(struct device *dev, unsigned int n)
73e2759e33SRene Herman {
74c8ff6647STakashi Iwai 	struct snd_card *card;
75241b3ee7SKrzysztof Helt 	struct snd_wss *chip;
76e2759e33SRene Herman 	int error;
771da177e4SLinus Torvalds 
784323cc4dSTakashi Iwai 	error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
79c95eadd2STakashi Iwai 	if (error < 0)
80c95eadd2STakashi Iwai 		return error;
811da177e4SLinus Torvalds 
82760fc6b8SKrzysztof Helt 	error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], -1,
83760fc6b8SKrzysztof Helt 			thinkpad[n] ? WSS_HW_THINKPAD : WSS_HW_DETECT,
84760fc6b8SKrzysztof Helt 			0, &chip);
85e2759e33SRene Herman 	if (error < 0)
86e2759e33SRene Herman 		goto out;
871da177e4SLinus Torvalds 
8868668845STakashi Iwai 	card->private_data = chip;
891da177e4SLinus Torvalds 
90fa60c065SLars-Peter Clausen 	error = snd_wss_pcm(chip, 0);
91e2759e33SRene Herman 	if (error < 0)
92e2759e33SRene Herman 		goto out;
9343bcd973STakashi Iwai 
945664daa1SKrzysztof Helt 	error = snd_wss_mixer(chip);
95e2759e33SRene Herman 	if (error < 0)
96e2759e33SRene Herman 		goto out;
9743bcd973STakashi Iwai 
98003d3e70SArnd Bergmann 	strlcpy(card->driver, "AD1848", sizeof(card->driver));
99003d3e70SArnd Bergmann 	strlcpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
1001da177e4SLinus Torvalds 
101003d3e70SArnd Bergmann 	if (!thinkpad[n])
102003d3e70SArnd Bergmann 		snprintf(card->longname, sizeof(card->longname),
103003d3e70SArnd Bergmann 			 "%s at 0x%lx, irq %d, dma %d",
104fa60c065SLars-Peter Clausen 			 chip->pcm->name, chip->port, irq[n], dma1[n]);
105003d3e70SArnd Bergmann 	else
106003d3e70SArnd Bergmann 		snprintf(card->longname, sizeof(card->longname),
107003d3e70SArnd Bergmann 			 "%s at 0x%lx, irq %d, dma %d [Thinkpad]",
108003d3e70SArnd Bergmann 			 chip->pcm->name, chip->port, irq[n], dma1[n]);
1091da177e4SLinus Torvalds 
110e2759e33SRene Herman 	error = snd_card_register(card);
111e2759e33SRene Herman 	if (error < 0)
112e2759e33SRene Herman 		goto out;
11343bcd973STakashi Iwai 
114e2759e33SRene Herman 	dev_set_drvdata(dev, card);
1151da177e4SLinus Torvalds 	return 0;
11643bcd973STakashi Iwai 
117e2759e33SRene Herman out:	snd_card_free(card);
118e2759e33SRene Herman 	return error;
1191da177e4SLinus Torvalds }
1201da177e4SLinus Torvalds 
1211bff292eSBill Pemberton static int snd_ad1848_remove(struct device *dev, unsigned int n)
12268668845STakashi Iwai {
123e2759e33SRene Herman 	snd_card_free(dev_get_drvdata(dev));
12468668845STakashi Iwai 	return 0;
12568668845STakashi Iwai }
12668668845STakashi Iwai 
12768668845STakashi Iwai #ifdef CONFIG_PM
128e2759e33SRene Herman static int snd_ad1848_suspend(struct device *dev, unsigned int n, pm_message_t state)
12968668845STakashi Iwai {
130e2759e33SRene Herman 	struct snd_card *card = dev_get_drvdata(dev);
131241b3ee7SKrzysztof Helt 	struct snd_wss *chip = card->private_data;
13268668845STakashi Iwai 
13368668845STakashi Iwai 	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
13468668845STakashi Iwai 	chip->suspend(chip);
13568668845STakashi Iwai 	return 0;
13668668845STakashi Iwai }
13768668845STakashi Iwai 
138e2759e33SRene Herman static int snd_ad1848_resume(struct device *dev, unsigned int n)
13968668845STakashi Iwai {
140e2759e33SRene Herman 	struct snd_card *card = dev_get_drvdata(dev);
141241b3ee7SKrzysztof Helt 	struct snd_wss *chip = card->private_data;
14268668845STakashi Iwai 
14368668845STakashi Iwai 	chip->resume(chip);
14468668845STakashi Iwai 	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
14568668845STakashi Iwai 	return 0;
14668668845STakashi Iwai }
14768668845STakashi Iwai #endif
14868668845STakashi Iwai 
149e2759e33SRene Herman static struct isa_driver snd_ad1848_driver = {
150e2759e33SRene Herman 	.match		= snd_ad1848_match,
15168668845STakashi Iwai 	.probe		= snd_ad1848_probe,
1521bff292eSBill Pemberton 	.remove		= snd_ad1848_remove,
15368668845STakashi Iwai #ifdef CONFIG_PM
15468668845STakashi Iwai 	.suspend	= snd_ad1848_suspend,
15568668845STakashi Iwai 	.resume		= snd_ad1848_resume,
15668668845STakashi Iwai #endif
15768668845STakashi Iwai 	.driver		= {
158e2759e33SRene Herman 		.name	= DEV_NAME
159f7a9275dSClemens Ladisch 	}
160e2759e33SRene Herman };
161f7a9275dSClemens Ladisch 
162d2fd147cSWilliam Breathitt Gray module_isa_driver(snd_ad1848_driver, SNDRV_CARDS);
163