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> 26*68668845STakashi Iwai #include <linux/err.h> 27*68668845STakashi Iwai #include <linux/platform_device.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 351da177e4SLinus Torvalds MODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@suse.cz>"); 361da177e4SLinus Torvalds MODULE_DESCRIPTION("AD1848/AD1847/CS4248"); 371da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 381da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1848}," 391da177e4SLinus Torvalds "{Analog Devices,AD1847}," 401da177e4SLinus Torvalds "{Crystal Semiconductors,CS4248}}"); 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 431da177e4SLinus Torvalds static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 441da177e4SLinus Torvalds static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ 451da177e4SLinus Torvalds static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ 461da177e4SLinus Torvalds static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */ 471da177e4SLinus Torvalds static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ 481da177e4SLinus Torvalds static int thinkpad[SNDRV_CARDS]; /* Thinkpad special case */ 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds module_param_array(index, int, NULL, 0444); 511da177e4SLinus Torvalds MODULE_PARM_DESC(index, "Index value for AD1848 soundcard."); 521da177e4SLinus Torvalds module_param_array(id, charp, NULL, 0444); 531da177e4SLinus Torvalds MODULE_PARM_DESC(id, "ID string for AD1848 soundcard."); 541da177e4SLinus Torvalds module_param_array(enable, bool, NULL, 0444); 551da177e4SLinus Torvalds MODULE_PARM_DESC(enable, "Enable AD1848 soundcard."); 561da177e4SLinus Torvalds module_param_array(port, long, NULL, 0444); 571da177e4SLinus Torvalds MODULE_PARM_DESC(port, "Port # for AD1848 driver."); 581da177e4SLinus Torvalds module_param_array(irq, int, NULL, 0444); 591da177e4SLinus Torvalds MODULE_PARM_DESC(irq, "IRQ # for AD1848 driver."); 601da177e4SLinus Torvalds module_param_array(dma1, int, NULL, 0444); 611da177e4SLinus Torvalds MODULE_PARM_DESC(dma1, "DMA1 # for AD1848 driver."); 621da177e4SLinus Torvalds module_param_array(thinkpad, bool, NULL, 0444); 631da177e4SLinus Torvalds MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series."); 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds 66*68668845STakashi Iwai static int __init snd_ad1848_probe(struct platform_device *pdev) 671da177e4SLinus Torvalds { 68*68668845STakashi Iwai int dev = pdev->id; 69c8ff6647STakashi Iwai struct snd_card *card; 70c8ff6647STakashi Iwai struct snd_ad1848 *chip; 71c8ff6647STakashi Iwai struct snd_pcm *pcm; 721da177e4SLinus Torvalds int err; 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds if (port[dev] == SNDRV_AUTO_PORT) { 751da177e4SLinus Torvalds snd_printk(KERN_ERR "ad1848: specify port\n"); 761da177e4SLinus Torvalds return -EINVAL; 771da177e4SLinus Torvalds } 781da177e4SLinus Torvalds if (irq[dev] == SNDRV_AUTO_IRQ) { 791da177e4SLinus Torvalds snd_printk(KERN_ERR "ad1848: specify irq\n"); 801da177e4SLinus Torvalds return -EINVAL; 811da177e4SLinus Torvalds } 821da177e4SLinus Torvalds if (dma1[dev] == SNDRV_AUTO_DMA) { 831da177e4SLinus Torvalds snd_printk(KERN_ERR "ad1848: specify dma1\n"); 841da177e4SLinus Torvalds return -EINVAL; 851da177e4SLinus Torvalds } 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 881da177e4SLinus Torvalds if (card == NULL) 891da177e4SLinus Torvalds return -ENOMEM; 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds if ((err = snd_ad1848_create(card, port[dev], 921da177e4SLinus Torvalds irq[dev], 931da177e4SLinus Torvalds dma1[dev], 941da177e4SLinus Torvalds thinkpad[dev] ? AD1848_HW_THINKPAD : AD1848_HW_DETECT, 9543bcd973STakashi Iwai &chip)) < 0) 9643bcd973STakashi Iwai goto _err; 97*68668845STakashi Iwai card->private_data = chip; 981da177e4SLinus Torvalds 9943bcd973STakashi Iwai if ((err = snd_ad1848_pcm(chip, 0, &pcm)) < 0) 10043bcd973STakashi Iwai goto _err; 10143bcd973STakashi Iwai 10243bcd973STakashi Iwai if ((err = snd_ad1848_mixer(chip)) < 0) 10343bcd973STakashi Iwai goto _err; 10443bcd973STakashi Iwai 1051da177e4SLinus Torvalds strcpy(card->driver, "AD1848"); 1061da177e4SLinus Torvalds strcpy(card->shortname, pcm->name); 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", 1091da177e4SLinus Torvalds pcm->name, chip->port, irq[dev], dma1[dev]); 1101da177e4SLinus Torvalds 11143bcd973STakashi Iwai if (thinkpad[dev]) 1121da177e4SLinus Torvalds strcat(card->longname, " [Thinkpad]"); 1131da177e4SLinus Torvalds 114*68668845STakashi Iwai snd_card_set_dev(card, &pdev->dev); 11543bcd973STakashi Iwai 11643bcd973STakashi Iwai if ((err = snd_card_register(card)) < 0) 11743bcd973STakashi Iwai goto _err; 11843bcd973STakashi Iwai 119*68668845STakashi Iwai platform_set_drvdata(pdev, card); 1201da177e4SLinus Torvalds return 0; 12143bcd973STakashi Iwai 12243bcd973STakashi Iwai _err: 12343bcd973STakashi Iwai snd_card_free(card); 12443bcd973STakashi Iwai return err; 1251da177e4SLinus Torvalds } 1261da177e4SLinus Torvalds 127*68668845STakashi Iwai static int __devexit snd_ad1848_remove(struct platform_device *devptr) 128*68668845STakashi Iwai { 129*68668845STakashi Iwai snd_card_free(platform_get_drvdata(devptr)); 130*68668845STakashi Iwai platform_set_drvdata(devptr, NULL); 131*68668845STakashi Iwai return 0; 132*68668845STakashi Iwai } 133*68668845STakashi Iwai 134*68668845STakashi Iwai #ifdef CONFIG_PM 135*68668845STakashi Iwai static int snd_ad1848_suspend(struct platform_device *pdev, pm_message_t state) 136*68668845STakashi Iwai { 137*68668845STakashi Iwai struct snd_card *card = platform_get_drvdata(pdev); 138*68668845STakashi Iwai struct snd_ad1848 *chip = card->private_data; 139*68668845STakashi Iwai 140*68668845STakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 141*68668845STakashi Iwai chip->suspend(chip); 142*68668845STakashi Iwai return 0; 143*68668845STakashi Iwai } 144*68668845STakashi Iwai 145*68668845STakashi Iwai static int snd_ad1848_resume(struct platform_device *pdev) 146*68668845STakashi Iwai { 147*68668845STakashi Iwai struct snd_card *card = platform_get_drvdata(pdev); 148*68668845STakashi Iwai struct snd_ad1848 *chip = card->private_data; 149*68668845STakashi Iwai 150*68668845STakashi Iwai chip->resume(chip); 151*68668845STakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D0); 152*68668845STakashi Iwai return 0; 153*68668845STakashi Iwai } 154*68668845STakashi Iwai #endif 155*68668845STakashi Iwai 156*68668845STakashi Iwai #define SND_AD1848_DRIVER "snd_ad1848" 157*68668845STakashi Iwai 158*68668845STakashi Iwai static struct platform_driver snd_ad1848_driver = { 159*68668845STakashi Iwai .probe = snd_ad1848_probe, 160*68668845STakashi Iwai .remove = __devexit_p(snd_ad1848_remove), 161*68668845STakashi Iwai #ifdef CONFIG_PM 162*68668845STakashi Iwai .suspend = snd_ad1848_suspend, 163*68668845STakashi Iwai .resume = snd_ad1848_resume, 164*68668845STakashi Iwai #endif 165*68668845STakashi Iwai .driver = { 166*68668845STakashi Iwai .name = SND_AD1848_DRIVER 167*68668845STakashi Iwai }, 168*68668845STakashi Iwai }; 169*68668845STakashi Iwai 1701da177e4SLinus Torvalds static int __init alsa_card_ad1848_init(void) 1711da177e4SLinus Torvalds { 172*68668845STakashi Iwai int i, cards, err; 1731da177e4SLinus Torvalds 174*68668845STakashi Iwai err = platform_driver_register(&snd_ad1848_driver); 175*68668845STakashi Iwai if (err < 0) 176*68668845STakashi Iwai return err; 177*68668845STakashi Iwai 178*68668845STakashi Iwai cards = 0; 179*68668845STakashi Iwai for (i = 0; i < SNDRV_CARDS && enable[i]; i++) { 180*68668845STakashi Iwai struct platform_device *device; 181*68668845STakashi Iwai device = platform_device_register_simple(SND_AD1848_DRIVER, 182*68668845STakashi Iwai i, NULL, 0); 183*68668845STakashi Iwai if (IS_ERR(device)) { 184*68668845STakashi Iwai err = PTR_ERR(device); 185*68668845STakashi Iwai goto errout; 186*68668845STakashi Iwai } 1871da177e4SLinus Torvalds cards++; 188*68668845STakashi Iwai } 1891da177e4SLinus Torvalds if (!cards) { 1901da177e4SLinus Torvalds #ifdef MODULE 1911da177e4SLinus Torvalds printk(KERN_ERR "AD1848 soundcard not found or device busy\n"); 1921da177e4SLinus Torvalds #endif 193*68668845STakashi Iwai err = -ENODEV; 194*68668845STakashi Iwai goto errout; 1951da177e4SLinus Torvalds } 1961da177e4SLinus Torvalds return 0; 197*68668845STakashi Iwai 198*68668845STakashi Iwai errout: 199*68668845STakashi Iwai platform_driver_unregister(&snd_ad1848_driver); 200*68668845STakashi Iwai return err; 2011da177e4SLinus Torvalds } 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds static void __exit alsa_card_ad1848_exit(void) 2041da177e4SLinus Torvalds { 205*68668845STakashi Iwai platform_driver_unregister(&snd_ad1848_driver); 2061da177e4SLinus Torvalds } 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds module_init(alsa_card_ad1848_init) 2091da177e4SLinus Torvalds module_exit(alsa_card_ad1848_exit) 210