xref: /openbmc/linux/sound/isa/ad1848/ad1848.c (revision 241b3ee70d2d69e88d5c144ce938b1887cd6d3fc)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  Generic driver for AD1848/AD1847/CS4248 chips (0.1 Alpha)
31da177e4SLinus Torvalds  *  Copyright (c) by Tugrul Galatali <galatalt@stuy.edu>,
4c1017a4cSJaroslav Kysela  *                   Jaroslav Kysela <perex@perex.cz>
5c1017a4cSJaroslav Kysela  *  Based on card-4232.c by Jaroslav Kysela <perex@perex.cz>
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  *   This program is free software; you can redistribute it and/or modify
91da177e4SLinus Torvalds  *   it under the terms of the GNU General Public License as published by
101da177e4SLinus Torvalds  *   the Free Software Foundation; either version 2 of the License, or
111da177e4SLinus Torvalds  *   (at your option) any later version.
121da177e4SLinus Torvalds  *
131da177e4SLinus Torvalds  *   This program is distributed in the hope that it will be useful,
141da177e4SLinus Torvalds  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
151da177e4SLinus Torvalds  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161da177e4SLinus Torvalds  *   GNU General Public License for more details.
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  *   You should have received a copy of the GNU General Public License
191da177e4SLinus Torvalds  *   along with this program; if not, write to the Free Software
201da177e4SLinus Torvalds  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
211da177e4SLinus Torvalds  *
221da177e4SLinus Torvalds  */
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds #include <linux/init.h>
2568668845STakashi Iwai #include <linux/err.h>
26e2759e33SRene Herman #include <linux/isa.h>
271da177e4SLinus Torvalds #include <linux/time.h>
281da177e4SLinus Torvalds #include <linux/wait.h>
291da177e4SLinus Torvalds #include <linux/moduleparam.h>
301da177e4SLinus Torvalds #include <sound/core.h>
311da177e4SLinus Torvalds #include <sound/ad1848.h>
321da177e4SLinus Torvalds #include <sound/initval.h>
331da177e4SLinus Torvalds 
34e2759e33SRene Herman #define CRD_NAME "Generic AD1848/AD1847/CS4248"
35e2759e33SRene Herman #define DEV_NAME "ad1848"
36e2759e33SRene Herman 
37e2759e33SRene Herman MODULE_DESCRIPTION(CRD_NAME);
38c1017a4cSJaroslav Kysela MODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@perex.cz>");
391da177e4SLinus Torvalds MODULE_LICENSE("GPL");
401da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1848},"
411da177e4SLinus Torvalds 	        "{Analog Devices,AD1847},"
421da177e4SLinus Torvalds 		"{Crystal Semiconductors,CS4248}}");
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
451da177e4SLinus Torvalds static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
461da177e4SLinus Torvalds static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;	/* Enable this card */
471da177e4SLinus Torvalds static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
481da177e4SLinus Torvalds static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 5,7,9,11,12,15 */
491da177e4SLinus Torvalds static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */
501da177e4SLinus Torvalds static int thinkpad[SNDRV_CARDS];			/* Thinkpad special case */
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds module_param_array(index, int, NULL, 0444);
53e2759e33SRene Herman MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
541da177e4SLinus Torvalds module_param_array(id, charp, NULL, 0444);
55e2759e33SRene Herman MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
561da177e4SLinus Torvalds module_param_array(enable, bool, NULL, 0444);
57e2759e33SRene Herman MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
581da177e4SLinus Torvalds module_param_array(port, long, NULL, 0444);
59e2759e33SRene Herman MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
601da177e4SLinus Torvalds module_param_array(irq, int, NULL, 0444);
61e2759e33SRene Herman MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
621da177e4SLinus Torvalds module_param_array(dma1, int, NULL, 0444);
63e2759e33SRene Herman MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
641da177e4SLinus Torvalds module_param_array(thinkpad, bool, NULL, 0444);
651da177e4SLinus Torvalds MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series.");
661da177e4SLinus Torvalds 
67e2759e33SRene Herman static int __devinit snd_ad1848_match(struct device *dev, unsigned int n)
681da177e4SLinus Torvalds {
69e2759e33SRene Herman 	if (!enable[n])
70e2759e33SRene Herman 		return 0;
71e2759e33SRene Herman 
72e2759e33SRene Herman 	if (port[n] == SNDRV_AUTO_PORT) {
73e2759e33SRene Herman 		snd_printk(KERN_ERR "%s: please specify port\n", dev->bus_id);
74e2759e33SRene Herman 		return 0;
75e2759e33SRene Herman 	}
76e2759e33SRene Herman 	if (irq[n] == SNDRV_AUTO_IRQ) {
77e2759e33SRene Herman 		snd_printk(KERN_ERR "%s: please specify irq\n", dev->bus_id);
78e2759e33SRene Herman 		return 0;
79e2759e33SRene Herman 	}
80e2759e33SRene Herman 	if (dma1[n] == SNDRV_AUTO_DMA) {
81e2759e33SRene Herman 		snd_printk(KERN_ERR "%s: please specify dma1\n", dev->bus_id);
82e2759e33SRene Herman 		return 0;
83e2759e33SRene Herman 	}
84e2759e33SRene Herman 	return 1;
85e2759e33SRene Herman }
86e2759e33SRene Herman 
87e2759e33SRene Herman static int __devinit snd_ad1848_probe(struct device *dev, unsigned int n)
88e2759e33SRene Herman {
89c8ff6647STakashi Iwai 	struct snd_card *card;
90*241b3ee7SKrzysztof Helt 	struct snd_wss *chip;
91c8ff6647STakashi Iwai 	struct snd_pcm *pcm;
92e2759e33SRene Herman 	int error;
931da177e4SLinus Torvalds 
94e2759e33SRene Herman 	card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
95e2759e33SRene Herman 	if (!card)
961da177e4SLinus Torvalds 		return -EINVAL;
971da177e4SLinus Torvalds 
98e2759e33SRene Herman 	error = snd_ad1848_create(card, port[n], irq[n], dma1[n],
99e2759e33SRene Herman 			thinkpad[n] ? AD1848_HW_THINKPAD : AD1848_HW_DETECT, &chip);
100e2759e33SRene Herman 	if (error < 0)
101e2759e33SRene Herman 		goto out;
1021da177e4SLinus Torvalds 
10368668845STakashi Iwai 	card->private_data = chip;
1041da177e4SLinus Torvalds 
105e2759e33SRene Herman 	error = snd_ad1848_pcm(chip, 0, &pcm);
106e2759e33SRene Herman 	if (error < 0)
107e2759e33SRene Herman 		goto out;
10843bcd973STakashi Iwai 
109e2759e33SRene Herman 	error = snd_ad1848_mixer(chip);
110e2759e33SRene Herman 	if (error < 0)
111e2759e33SRene Herman 		goto out;
11243bcd973STakashi Iwai 
1131da177e4SLinus Torvalds 	strcpy(card->driver, "AD1848");
1141da177e4SLinus Torvalds 	strcpy(card->shortname, pcm->name);
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds 	sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
117e2759e33SRene Herman 		pcm->name, chip->port, irq[n], dma1[n]);
118e2759e33SRene Herman 	if (thinkpad[n])
1191da177e4SLinus Torvalds 		strcat(card->longname, " [Thinkpad]");
1201da177e4SLinus Torvalds 
121e2759e33SRene Herman 	snd_card_set_dev(card, dev);
12243bcd973STakashi Iwai 
123e2759e33SRene Herman 	error = snd_card_register(card);
124e2759e33SRene Herman 	if (error < 0)
125e2759e33SRene Herman 		goto out;
12643bcd973STakashi Iwai 
127e2759e33SRene Herman 	dev_set_drvdata(dev, card);
1281da177e4SLinus Torvalds 	return 0;
12943bcd973STakashi Iwai 
130e2759e33SRene Herman out:	snd_card_free(card);
131e2759e33SRene Herman 	return error;
1321da177e4SLinus Torvalds }
1331da177e4SLinus Torvalds 
134e2759e33SRene Herman static int __devexit snd_ad1848_remove(struct device *dev, unsigned int n)
13568668845STakashi Iwai {
136e2759e33SRene Herman 	snd_card_free(dev_get_drvdata(dev));
137e2759e33SRene Herman 	dev_set_drvdata(dev, NULL);
13868668845STakashi Iwai 	return 0;
13968668845STakashi Iwai }
14068668845STakashi Iwai 
14168668845STakashi Iwai #ifdef CONFIG_PM
142e2759e33SRene Herman static int snd_ad1848_suspend(struct device *dev, unsigned int n, pm_message_t state)
14368668845STakashi Iwai {
144e2759e33SRene Herman 	struct snd_card *card = dev_get_drvdata(dev);
145*241b3ee7SKrzysztof Helt 	struct snd_wss *chip = card->private_data;
14668668845STakashi Iwai 
14768668845STakashi Iwai 	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
14868668845STakashi Iwai 	chip->suspend(chip);
14968668845STakashi Iwai 	return 0;
15068668845STakashi Iwai }
15168668845STakashi Iwai 
152e2759e33SRene Herman static int snd_ad1848_resume(struct device *dev, unsigned int n)
15368668845STakashi Iwai {
154e2759e33SRene Herman 	struct snd_card *card = dev_get_drvdata(dev);
155*241b3ee7SKrzysztof Helt 	struct snd_wss *chip = card->private_data;
15668668845STakashi Iwai 
15768668845STakashi Iwai 	chip->resume(chip);
15868668845STakashi Iwai 	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
15968668845STakashi Iwai 	return 0;
16068668845STakashi Iwai }
16168668845STakashi Iwai #endif
16268668845STakashi Iwai 
163e2759e33SRene Herman static struct isa_driver snd_ad1848_driver = {
164e2759e33SRene Herman 	.match		= snd_ad1848_match,
16568668845STakashi Iwai 	.probe		= snd_ad1848_probe,
16668668845STakashi Iwai 	.remove		= __devexit_p(snd_ad1848_remove),
16768668845STakashi Iwai #ifdef CONFIG_PM
16868668845STakashi Iwai 	.suspend	= snd_ad1848_suspend,
16968668845STakashi Iwai 	.resume		= snd_ad1848_resume,
17068668845STakashi Iwai #endif
17168668845STakashi Iwai 	.driver		= {
172e2759e33SRene Herman 		.name	= DEV_NAME
173f7a9275dSClemens Ladisch 	}
174e2759e33SRene Herman };
175f7a9275dSClemens Ladisch 
1761da177e4SLinus Torvalds static int __init alsa_card_ad1848_init(void)
1771da177e4SLinus Torvalds {
178e2759e33SRene Herman 	return isa_register_driver(&snd_ad1848_driver, SNDRV_CARDS);
1791da177e4SLinus Torvalds }
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds static void __exit alsa_card_ad1848_exit(void)
1821da177e4SLinus Torvalds {
183e2759e33SRene Herman 	isa_unregister_driver(&snd_ad1848_driver);
1841da177e4SLinus Torvalds }
1851da177e4SLinus Torvalds 
186e2759e33SRene Herman module_init(alsa_card_ad1848_init);
187e2759e33SRene Herman module_exit(alsa_card_ad1848_exit);
188