11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Generic driver for AD1848/AD1847/CS4248 chips (0.1 Alpha) 31da177e4SLinus Torvalds * Copyright (c) by Tugrul Galatali <galatalt@stuy.edu>, 41da177e4SLinus Torvalds * Jaroslav Kysela <perex@suse.cz> 51da177e4SLinus Torvalds * Based on card-4232.c by Jaroslav Kysela <perex@suse.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 <sound/driver.h> 251da177e4SLinus Torvalds #include <linux/init.h> 2668668845STakashi Iwai #include <linux/err.h> 27*e2759e33SRene Herman #include <linux/isa.h> 281da177e4SLinus Torvalds #include <linux/time.h> 291da177e4SLinus Torvalds #include <linux/wait.h> 301da177e4SLinus Torvalds #include <linux/moduleparam.h> 311da177e4SLinus Torvalds #include <sound/core.h> 321da177e4SLinus Torvalds #include <sound/ad1848.h> 331da177e4SLinus Torvalds #include <sound/initval.h> 341da177e4SLinus Torvalds 35*e2759e33SRene Herman #define CRD_NAME "Generic AD1848/AD1847/CS4248" 36*e2759e33SRene Herman #define DEV_NAME "ad1848" 37*e2759e33SRene Herman 38*e2759e33SRene Herman MODULE_DESCRIPTION(CRD_NAME); 391da177e4SLinus Torvalds MODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@suse.cz>"); 401da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 411da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1848}," 421da177e4SLinus Torvalds "{Analog Devices,AD1847}," 431da177e4SLinus Torvalds "{Crystal Semiconductors,CS4248}}"); 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 461da177e4SLinus Torvalds static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 471da177e4SLinus Torvalds static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ 481da177e4SLinus Torvalds static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ 491da177e4SLinus Torvalds static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */ 501da177e4SLinus Torvalds static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ 511da177e4SLinus Torvalds static int thinkpad[SNDRV_CARDS]; /* Thinkpad special case */ 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds module_param_array(index, int, NULL, 0444); 54*e2759e33SRene Herman MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); 551da177e4SLinus Torvalds module_param_array(id, charp, NULL, 0444); 56*e2759e33SRene Herman MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); 571da177e4SLinus Torvalds module_param_array(enable, bool, NULL, 0444); 58*e2759e33SRene Herman MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); 591da177e4SLinus Torvalds module_param_array(port, long, NULL, 0444); 60*e2759e33SRene Herman MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); 611da177e4SLinus Torvalds module_param_array(irq, int, NULL, 0444); 62*e2759e33SRene Herman MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); 631da177e4SLinus Torvalds module_param_array(dma1, int, NULL, 0444); 64*e2759e33SRene Herman MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver."); 651da177e4SLinus Torvalds module_param_array(thinkpad, bool, NULL, 0444); 661da177e4SLinus Torvalds MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series."); 671da177e4SLinus Torvalds 68*e2759e33SRene Herman static int __devinit snd_ad1848_match(struct device *dev, unsigned int n) 691da177e4SLinus Torvalds { 70*e2759e33SRene Herman if (!enable[n]) 71*e2759e33SRene Herman return 0; 72*e2759e33SRene Herman 73*e2759e33SRene Herman if (port[n] == SNDRV_AUTO_PORT) { 74*e2759e33SRene Herman snd_printk(KERN_ERR "%s: please specify port\n", dev->bus_id); 75*e2759e33SRene Herman return 0; 76*e2759e33SRene Herman } 77*e2759e33SRene Herman if (irq[n] == SNDRV_AUTO_IRQ) { 78*e2759e33SRene Herman snd_printk(KERN_ERR "%s: please specify irq\n", dev->bus_id); 79*e2759e33SRene Herman return 0; 80*e2759e33SRene Herman } 81*e2759e33SRene Herman if (dma1[n] == SNDRV_AUTO_DMA) { 82*e2759e33SRene Herman snd_printk(KERN_ERR "%s: please specify dma1\n", dev->bus_id); 83*e2759e33SRene Herman return 0; 84*e2759e33SRene Herman } 85*e2759e33SRene Herman return 1; 86*e2759e33SRene Herman } 87*e2759e33SRene Herman 88*e2759e33SRene Herman static int __devinit snd_ad1848_probe(struct device *dev, unsigned int n) 89*e2759e33SRene Herman { 90c8ff6647STakashi Iwai struct snd_card *card; 91c8ff6647STakashi Iwai struct snd_ad1848 *chip; 92c8ff6647STakashi Iwai struct snd_pcm *pcm; 93*e2759e33SRene Herman int error; 941da177e4SLinus Torvalds 95*e2759e33SRene Herman card = snd_card_new(index[n], id[n], THIS_MODULE, 0); 96*e2759e33SRene Herman if (!card) 971da177e4SLinus Torvalds return -EINVAL; 981da177e4SLinus Torvalds 99*e2759e33SRene Herman error = snd_ad1848_create(card, port[n], irq[n], dma1[n], 100*e2759e33SRene Herman thinkpad[n] ? AD1848_HW_THINKPAD : AD1848_HW_DETECT, &chip); 101*e2759e33SRene Herman if (error < 0) 102*e2759e33SRene Herman goto out; 1031da177e4SLinus Torvalds 10468668845STakashi Iwai card->private_data = chip; 1051da177e4SLinus Torvalds 106*e2759e33SRene Herman error = snd_ad1848_pcm(chip, 0, &pcm); 107*e2759e33SRene Herman if (error < 0) 108*e2759e33SRene Herman goto out; 10943bcd973STakashi Iwai 110*e2759e33SRene Herman error = snd_ad1848_mixer(chip); 111*e2759e33SRene Herman if (error < 0) 112*e2759e33SRene 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", 118*e2759e33SRene Herman pcm->name, chip->port, irq[n], dma1[n]); 119*e2759e33SRene Herman if (thinkpad[n]) 1201da177e4SLinus Torvalds strcat(card->longname, " [Thinkpad]"); 1211da177e4SLinus Torvalds 122*e2759e33SRene Herman snd_card_set_dev(card, dev); 12343bcd973STakashi Iwai 124*e2759e33SRene Herman error = snd_card_register(card); 125*e2759e33SRene Herman if (error < 0) 126*e2759e33SRene Herman goto out; 12743bcd973STakashi Iwai 128*e2759e33SRene Herman dev_set_drvdata(dev, card); 1291da177e4SLinus Torvalds return 0; 13043bcd973STakashi Iwai 131*e2759e33SRene Herman out: snd_card_free(card); 132*e2759e33SRene Herman return error; 1331da177e4SLinus Torvalds } 1341da177e4SLinus Torvalds 135*e2759e33SRene Herman static int __devexit snd_ad1848_remove(struct device *dev, unsigned int n) 13668668845STakashi Iwai { 137*e2759e33SRene Herman snd_card_free(dev_get_drvdata(dev)); 138*e2759e33SRene Herman dev_set_drvdata(dev, NULL); 13968668845STakashi Iwai return 0; 14068668845STakashi Iwai } 14168668845STakashi Iwai 14268668845STakashi Iwai #ifdef CONFIG_PM 143*e2759e33SRene Herman static int snd_ad1848_suspend(struct device *dev, unsigned int n, pm_message_t state) 14468668845STakashi Iwai { 145*e2759e33SRene Herman struct snd_card *card = dev_get_drvdata(dev); 14668668845STakashi Iwai struct snd_ad1848 *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 153*e2759e33SRene Herman static int snd_ad1848_resume(struct device *dev, unsigned int n) 15468668845STakashi Iwai { 155*e2759e33SRene Herman struct snd_card *card = dev_get_drvdata(dev); 15668668845STakashi Iwai struct snd_ad1848 *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 164*e2759e33SRene Herman static struct isa_driver snd_ad1848_driver = { 165*e2759e33SRene 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 = { 173*e2759e33SRene Herman .name = DEV_NAME 174f7a9275dSClemens Ladisch } 175*e2759e33SRene Herman }; 176f7a9275dSClemens Ladisch 1771da177e4SLinus Torvalds static int __init alsa_card_ad1848_init(void) 1781da177e4SLinus Torvalds { 179*e2759e33SRene 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 { 184*e2759e33SRene Herman isa_unregister_driver(&snd_ad1848_driver); 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 187*e2759e33SRene Herman module_init(alsa_card_ad1848_init); 188*e2759e33SRene Herman module_exit(alsa_card_ad1848_exit); 189