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> 261da177e4SLinus Torvalds #include <linux/time.h> 271da177e4SLinus Torvalds #include <linux/wait.h> 281da177e4SLinus Torvalds #include <linux/moduleparam.h> 291da177e4SLinus Torvalds #include <sound/core.h> 301da177e4SLinus Torvalds #include <sound/ad1848.h> 311da177e4SLinus Torvalds #include <sound/initval.h> 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds MODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@suse.cz>"); 341da177e4SLinus Torvalds MODULE_DESCRIPTION("AD1848/AD1847/CS4248"); 351da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 361da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1848}," 371da177e4SLinus Torvalds "{Analog Devices,AD1847}," 381da177e4SLinus Torvalds "{Crystal Semiconductors,CS4248}}"); 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 411da177e4SLinus Torvalds static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 421da177e4SLinus Torvalds static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ 431da177e4SLinus Torvalds static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ 441da177e4SLinus Torvalds static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */ 451da177e4SLinus Torvalds static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ 461da177e4SLinus Torvalds static int thinkpad[SNDRV_CARDS]; /* Thinkpad special case */ 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds module_param_array(index, int, NULL, 0444); 491da177e4SLinus Torvalds MODULE_PARM_DESC(index, "Index value for AD1848 soundcard."); 501da177e4SLinus Torvalds module_param_array(id, charp, NULL, 0444); 511da177e4SLinus Torvalds MODULE_PARM_DESC(id, "ID string for AD1848 soundcard."); 521da177e4SLinus Torvalds module_param_array(enable, bool, NULL, 0444); 531da177e4SLinus Torvalds MODULE_PARM_DESC(enable, "Enable AD1848 soundcard."); 541da177e4SLinus Torvalds module_param_array(port, long, NULL, 0444); 551da177e4SLinus Torvalds MODULE_PARM_DESC(port, "Port # for AD1848 driver."); 561da177e4SLinus Torvalds module_param_array(irq, int, NULL, 0444); 571da177e4SLinus Torvalds MODULE_PARM_DESC(irq, "IRQ # for AD1848 driver."); 581da177e4SLinus Torvalds module_param_array(dma1, int, NULL, 0444); 591da177e4SLinus Torvalds MODULE_PARM_DESC(dma1, "DMA1 # for AD1848 driver."); 601da177e4SLinus Torvalds module_param_array(thinkpad, bool, NULL, 0444); 611da177e4SLinus Torvalds MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series."); 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds static snd_card_t *snd_ad1848_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds static int __init snd_card_ad1848_probe(int dev) 671da177e4SLinus Torvalds { 681da177e4SLinus Torvalds snd_card_t *card; 691da177e4SLinus Torvalds ad1848_t *chip; 701da177e4SLinus Torvalds snd_pcm_t *pcm; 711da177e4SLinus Torvalds int err; 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds if (port[dev] == SNDRV_AUTO_PORT) { 741da177e4SLinus Torvalds snd_printk(KERN_ERR "ad1848: specify port\n"); 751da177e4SLinus Torvalds return -EINVAL; 761da177e4SLinus Torvalds } 771da177e4SLinus Torvalds if (irq[dev] == SNDRV_AUTO_IRQ) { 781da177e4SLinus Torvalds snd_printk(KERN_ERR "ad1848: specify irq\n"); 791da177e4SLinus Torvalds return -EINVAL; 801da177e4SLinus Torvalds } 811da177e4SLinus Torvalds if (dma1[dev] == SNDRV_AUTO_DMA) { 821da177e4SLinus Torvalds snd_printk(KERN_ERR "ad1848: specify dma1\n"); 831da177e4SLinus Torvalds return -EINVAL; 841da177e4SLinus Torvalds } 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 871da177e4SLinus Torvalds if (card == NULL) 881da177e4SLinus Torvalds return -ENOMEM; 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds if ((err = snd_ad1848_create(card, port[dev], 911da177e4SLinus Torvalds irq[dev], 921da177e4SLinus Torvalds dma1[dev], 931da177e4SLinus Torvalds thinkpad[dev] ? AD1848_HW_THINKPAD : AD1848_HW_DETECT, 94*43bcd973STakashi Iwai &chip)) < 0) 95*43bcd973STakashi Iwai goto _err; 961da177e4SLinus Torvalds 97*43bcd973STakashi Iwai if ((err = snd_ad1848_pcm(chip, 0, &pcm)) < 0) 98*43bcd973STakashi Iwai goto _err; 99*43bcd973STakashi Iwai 100*43bcd973STakashi Iwai if ((err = snd_ad1848_mixer(chip)) < 0) 101*43bcd973STakashi Iwai goto _err; 102*43bcd973STakashi Iwai 1031da177e4SLinus Torvalds strcpy(card->driver, "AD1848"); 1041da177e4SLinus Torvalds strcpy(card->shortname, pcm->name); 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", 1071da177e4SLinus Torvalds pcm->name, chip->port, irq[dev], dma1[dev]); 1081da177e4SLinus Torvalds 109*43bcd973STakashi Iwai if (thinkpad[dev]) 1101da177e4SLinus Torvalds strcat(card->longname, " [Thinkpad]"); 1111da177e4SLinus Torvalds 112*43bcd973STakashi Iwai if ((err = snd_card_set_generic_dev(card)) < 0) 113*43bcd973STakashi Iwai goto _err; 114*43bcd973STakashi Iwai 115*43bcd973STakashi Iwai if ((err = snd_card_register(card)) < 0) 116*43bcd973STakashi Iwai goto _err; 117*43bcd973STakashi Iwai 1181da177e4SLinus Torvalds snd_ad1848_cards[dev] = card; 1191da177e4SLinus Torvalds return 0; 120*43bcd973STakashi Iwai 121*43bcd973STakashi Iwai _err: 122*43bcd973STakashi Iwai snd_card_free(card); 123*43bcd973STakashi Iwai return err; 1241da177e4SLinus Torvalds } 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds static int __init alsa_card_ad1848_init(void) 1271da177e4SLinus Torvalds { 1281da177e4SLinus Torvalds int dev, cards; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) 1311da177e4SLinus Torvalds if (snd_card_ad1848_probe(dev) >= 0) 1321da177e4SLinus Torvalds cards++; 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds if (!cards) { 1351da177e4SLinus Torvalds #ifdef MODULE 1361da177e4SLinus Torvalds printk(KERN_ERR "AD1848 soundcard not found or device busy\n"); 1371da177e4SLinus Torvalds #endif 1381da177e4SLinus Torvalds return -ENODEV; 1391da177e4SLinus Torvalds } 1401da177e4SLinus Torvalds return 0; 1411da177e4SLinus Torvalds } 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds static void __exit alsa_card_ad1848_exit(void) 1441da177e4SLinus Torvalds { 1451da177e4SLinus Torvalds int idx; 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds for (idx = 0; idx < SNDRV_CARDS; idx++) 1481da177e4SLinus Torvalds snd_card_free(snd_ad1848_cards[idx]); 1491da177e4SLinus Torvalds } 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds module_init(alsa_card_ad1848_init) 1521da177e4SLinus Torvalds module_exit(alsa_card_ad1848_exit) 153