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> 29*65a77217SPaul Gortmaker #include <linux/module.h> 301da177e4SLinus Torvalds #include <sound/core.h> 31760fc6b8SKrzysztof Helt #include <sound/wss.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) { 730418ff0cSTakashi Iwai dev_err(dev, "please specify port\n"); 74e2759e33SRene Herman return 0; 75e2759e33SRene Herman } 76e2759e33SRene Herman if (irq[n] == SNDRV_AUTO_IRQ) { 770418ff0cSTakashi Iwai dev_err(dev, "please specify irq\n"); 78e2759e33SRene Herman return 0; 79e2759e33SRene Herman } 80e2759e33SRene Herman if (dma1[n] == SNDRV_AUTO_DMA) { 810418ff0cSTakashi Iwai dev_err(dev, "please specify dma1\n"); 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; 90241b3ee7SKrzysztof Helt struct snd_wss *chip; 91c8ff6647STakashi Iwai struct snd_pcm *pcm; 92e2759e33SRene Herman int error; 931da177e4SLinus Torvalds 94c95eadd2STakashi Iwai error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card); 95c95eadd2STakashi Iwai if (error < 0) 96c95eadd2STakashi Iwai return error; 971da177e4SLinus Torvalds 98760fc6b8SKrzysztof Helt error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], -1, 99760fc6b8SKrzysztof Helt thinkpad[n] ? WSS_HW_THINKPAD : WSS_HW_DETECT, 100760fc6b8SKrzysztof Helt 0, &chip); 101e2759e33SRene Herman if (error < 0) 102e2759e33SRene Herman goto out; 1031da177e4SLinus Torvalds 10468668845STakashi Iwai card->private_data = chip; 1051da177e4SLinus Torvalds 106ead893c0SKrzysztof Helt error = snd_wss_pcm(chip, 0, &pcm); 107e2759e33SRene Herman if (error < 0) 108e2759e33SRene Herman goto out; 10943bcd973STakashi Iwai 1105664daa1SKrzysztof Helt error = snd_wss_mixer(chip); 111e2759e33SRene Herman if (error < 0) 112e2759e33SRene Herman goto out; 11343bcd973STakashi Iwai 1141da177e4SLinus Torvalds strcpy(card->driver, "AD1848"); 1151da177e4SLinus Torvalds strcpy(card->shortname, pcm->name); 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", 118e2759e33SRene Herman pcm->name, chip->port, irq[n], dma1[n]); 119e2759e33SRene Herman if (thinkpad[n]) 1201da177e4SLinus Torvalds strcat(card->longname, " [Thinkpad]"); 1211da177e4SLinus Torvalds 122e2759e33SRene Herman snd_card_set_dev(card, dev); 12343bcd973STakashi Iwai 124e2759e33SRene Herman error = snd_card_register(card); 125e2759e33SRene Herman if (error < 0) 126e2759e33SRene Herman goto out; 12743bcd973STakashi Iwai 128e2759e33SRene Herman dev_set_drvdata(dev, card); 1291da177e4SLinus Torvalds return 0; 13043bcd973STakashi Iwai 131e2759e33SRene Herman out: snd_card_free(card); 132e2759e33SRene Herman return error; 1331da177e4SLinus Torvalds } 1341da177e4SLinus Torvalds 135e2759e33SRene Herman static int __devexit snd_ad1848_remove(struct device *dev, unsigned int n) 13668668845STakashi Iwai { 137e2759e33SRene Herman snd_card_free(dev_get_drvdata(dev)); 138e2759e33SRene Herman dev_set_drvdata(dev, NULL); 13968668845STakashi Iwai return 0; 14068668845STakashi Iwai } 14168668845STakashi Iwai 14268668845STakashi Iwai #ifdef CONFIG_PM 143e2759e33SRene Herman static int snd_ad1848_suspend(struct device *dev, unsigned int n, pm_message_t state) 14468668845STakashi Iwai { 145e2759e33SRene Herman struct snd_card *card = dev_get_drvdata(dev); 146241b3ee7SKrzysztof Helt struct snd_wss *chip = card->private_data; 14768668845STakashi Iwai 14868668845STakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 14968668845STakashi Iwai chip->suspend(chip); 15068668845STakashi Iwai return 0; 15168668845STakashi Iwai } 15268668845STakashi Iwai 153e2759e33SRene Herman static int snd_ad1848_resume(struct device *dev, unsigned int n) 15468668845STakashi Iwai { 155e2759e33SRene Herman struct snd_card *card = dev_get_drvdata(dev); 156241b3ee7SKrzysztof Helt struct snd_wss *chip = card->private_data; 15768668845STakashi Iwai 15868668845STakashi Iwai chip->resume(chip); 15968668845STakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D0); 16068668845STakashi Iwai return 0; 16168668845STakashi Iwai } 16268668845STakashi Iwai #endif 16368668845STakashi Iwai 164e2759e33SRene Herman static struct isa_driver snd_ad1848_driver = { 165e2759e33SRene Herman .match = snd_ad1848_match, 16668668845STakashi Iwai .probe = snd_ad1848_probe, 16768668845STakashi Iwai .remove = __devexit_p(snd_ad1848_remove), 16868668845STakashi Iwai #ifdef CONFIG_PM 16968668845STakashi Iwai .suspend = snd_ad1848_suspend, 17068668845STakashi Iwai .resume = snd_ad1848_resume, 17168668845STakashi Iwai #endif 17268668845STakashi Iwai .driver = { 173e2759e33SRene Herman .name = DEV_NAME 174f7a9275dSClemens Ladisch } 175e2759e33SRene Herman }; 176f7a9275dSClemens Ladisch 1771da177e4SLinus Torvalds static int __init alsa_card_ad1848_init(void) 1781da177e4SLinus Torvalds { 179e2759e33SRene Herman return isa_register_driver(&snd_ad1848_driver, SNDRV_CARDS); 1801da177e4SLinus Torvalds } 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds static void __exit alsa_card_ad1848_exit(void) 1831da177e4SLinus Torvalds { 184e2759e33SRene Herman isa_unregister_driver(&snd_ad1848_driver); 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 187e2759e33SRene Herman module_init(alsa_card_ad1848_init); 188e2759e33SRene Herman module_exit(alsa_card_ad1848_exit); 189