11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Driver for PowerMac AWACS 31da177e4SLinus Torvalds * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de> 41da177e4SLinus Torvalds * based on dmasound.c. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 71da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 81da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 91da177e4SLinus Torvalds * (at your option) any later version. 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 121da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 131da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 141da177e4SLinus Torvalds * GNU General Public License for more details. 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 171da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 181da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 191da177e4SLinus Torvalds */ 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds #include <sound/driver.h> 221da177e4SLinus Torvalds #include <linux/init.h> 235e12bea0STakashi Iwai #include <linux/err.h> 245e12bea0STakashi Iwai #include <linux/platform_device.h> 251da177e4SLinus Torvalds #include <linux/moduleparam.h> 261da177e4SLinus Torvalds #include <sound/core.h> 271da177e4SLinus Torvalds #include <sound/initval.h> 281da177e4SLinus Torvalds #include "pmac.h" 291da177e4SLinus Torvalds #include "awacs.h" 301da177e4SLinus Torvalds #include "burgundy.h" 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds #define CHIP_NAME "PMac" 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds MODULE_DESCRIPTION("PowerMac"); 351da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{Apple,PowerMac}}"); 361da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ 391da177e4SLinus Torvalds static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ 401da177e4SLinus Torvalds static int enable_beep = 1; 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds module_param(index, int, 0444); 431da177e4SLinus Torvalds MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip."); 441da177e4SLinus Torvalds module_param(id, charp, 0444); 451da177e4SLinus Torvalds MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip."); 461da177e4SLinus Torvalds module_param(enable_beep, bool, 0444); 471da177e4SLinus Torvalds MODULE_PARM_DESC(enable_beep, "Enable beep using PCM."); 481da177e4SLinus Torvalds 49*f7a9275dSClemens Ladisch static struct platform_device *device; 50*f7a9275dSClemens Ladisch 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds /* 531da177e4SLinus Torvalds */ 541da177e4SLinus Torvalds 555e12bea0STakashi Iwai static int __init snd_pmac_probe(struct platform_device *devptr) 561da177e4SLinus Torvalds { 5765b29f50STakashi Iwai struct snd_card *card; 5865b29f50STakashi Iwai struct snd_pmac *chip; 591da177e4SLinus Torvalds char *name_ext; 601da177e4SLinus Torvalds int err; 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds card = snd_card_new(index, id, THIS_MODULE, 0); 631da177e4SLinus Torvalds if (card == NULL) 641da177e4SLinus Torvalds return -ENOMEM; 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds if ((err = snd_pmac_new(card, &chip)) < 0) 671da177e4SLinus Torvalds goto __error; 685e12bea0STakashi Iwai card->private_data = chip; 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds switch (chip->model) { 711da177e4SLinus Torvalds case PMAC_BURGUNDY: 721da177e4SLinus Torvalds strcpy(card->driver, "PMac Burgundy"); 731da177e4SLinus Torvalds strcpy(card->shortname, "PowerMac Burgundy"); 741da177e4SLinus Torvalds sprintf(card->longname, "%s (Dev %d) Sub-frame %d", 751da177e4SLinus Torvalds card->shortname, chip->device_id, chip->subframe); 761da177e4SLinus Torvalds if ((err = snd_pmac_burgundy_init(chip)) < 0) 771da177e4SLinus Torvalds goto __error; 781da177e4SLinus Torvalds break; 791da177e4SLinus Torvalds case PMAC_DACA: 801da177e4SLinus Torvalds strcpy(card->driver, "PMac DACA"); 811da177e4SLinus Torvalds strcpy(card->shortname, "PowerMac DACA"); 821da177e4SLinus Torvalds sprintf(card->longname, "%s (Dev %d) Sub-frame %d", 831da177e4SLinus Torvalds card->shortname, chip->device_id, chip->subframe); 841da177e4SLinus Torvalds if ((err = snd_pmac_daca_init(chip)) < 0) 851da177e4SLinus Torvalds goto __error; 861da177e4SLinus Torvalds break; 871da177e4SLinus Torvalds case PMAC_TUMBLER: 881da177e4SLinus Torvalds case PMAC_SNAPPER: 891da177e4SLinus Torvalds name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper"; 901da177e4SLinus Torvalds sprintf(card->driver, "PMac %s", name_ext); 911da177e4SLinus Torvalds sprintf(card->shortname, "PowerMac %s", name_ext); 921da177e4SLinus Torvalds sprintf(card->longname, "%s (Dev %d) Sub-frame %d", 931da177e4SLinus Torvalds card->shortname, chip->device_id, chip->subframe); 941da177e4SLinus Torvalds if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0) 951da177e4SLinus Torvalds goto __error; 961da177e4SLinus Torvalds break; 971f7b49d0SBenjamin Herrenschmidt case PMAC_TOONIE: 981f7b49d0SBenjamin Herrenschmidt strcpy(card->driver, "PMac Toonie"); 991f7b49d0SBenjamin Herrenschmidt strcpy(card->shortname, "PowerMac Toonie"); 1001f7b49d0SBenjamin Herrenschmidt strcpy(card->longname, card->shortname); 1011f7b49d0SBenjamin Herrenschmidt if ((err = snd_pmac_toonie_init(chip)) < 0) 1021f7b49d0SBenjamin Herrenschmidt goto __error; 1031f7b49d0SBenjamin Herrenschmidt break; 1041da177e4SLinus Torvalds case PMAC_AWACS: 1051da177e4SLinus Torvalds case PMAC_SCREAMER: 1061da177e4SLinus Torvalds name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS"; 1071da177e4SLinus Torvalds sprintf(card->driver, "PMac %s", name_ext); 1081da177e4SLinus Torvalds sprintf(card->shortname, "PowerMac %s", name_ext); 1091da177e4SLinus Torvalds if (chip->is_pbook_3400) 1101da177e4SLinus Torvalds name_ext = " [PB3400]"; 1111da177e4SLinus Torvalds else if (chip->is_pbook_G3) 1121da177e4SLinus Torvalds name_ext = " [PBG3]"; 1131da177e4SLinus Torvalds else 1141da177e4SLinus Torvalds name_ext = ""; 1151da177e4SLinus Torvalds sprintf(card->longname, "%s%s Rev %d", 1161da177e4SLinus Torvalds card->shortname, name_ext, chip->revision); 1171da177e4SLinus Torvalds if ((err = snd_pmac_awacs_init(chip)) < 0) 1181da177e4SLinus Torvalds goto __error; 1191da177e4SLinus Torvalds break; 1201da177e4SLinus Torvalds default: 1211da177e4SLinus Torvalds snd_printk("unsupported hardware %d\n", chip->model); 1221da177e4SLinus Torvalds err = -EINVAL; 1231da177e4SLinus Torvalds goto __error; 1241da177e4SLinus Torvalds } 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds if ((err = snd_pmac_pcm_new(chip)) < 0) 1271da177e4SLinus Torvalds goto __error; 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds chip->initialized = 1; 1301da177e4SLinus Torvalds if (enable_beep) 1311da177e4SLinus Torvalds snd_pmac_attach_beep(chip); 1321da177e4SLinus Torvalds 1335e12bea0STakashi Iwai snd_card_set_dev(card, &devptr->dev); 13416dab54bSTakashi Iwai 1351da177e4SLinus Torvalds if ((err = snd_card_register(card)) < 0) 1361da177e4SLinus Torvalds goto __error; 1371da177e4SLinus Torvalds 1385e12bea0STakashi Iwai platform_set_drvdata(devptr, card); 1391da177e4SLinus Torvalds return 0; 1401da177e4SLinus Torvalds 1411da177e4SLinus Torvalds __error: 1421da177e4SLinus Torvalds snd_card_free(card); 1431da177e4SLinus Torvalds return err; 1441da177e4SLinus Torvalds } 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds 1475e12bea0STakashi Iwai static int __devexit snd_pmac_remove(struct platform_device *devptr) 1485e12bea0STakashi Iwai { 1495e12bea0STakashi Iwai snd_card_free(platform_get_drvdata(devptr)); 1505e12bea0STakashi Iwai platform_set_drvdata(devptr, NULL); 1515e12bea0STakashi Iwai return 0; 1525e12bea0STakashi Iwai } 1535e12bea0STakashi Iwai 1545e12bea0STakashi Iwai #ifdef CONFIG_PM 1555e12bea0STakashi Iwai static int snd_pmac_driver_suspend(struct platform_device *devptr, pm_message_t state) 1565e12bea0STakashi Iwai { 1575e12bea0STakashi Iwai struct snd_card *card = platform_get_drvdata(devptr); 1585e12bea0STakashi Iwai snd_pmac_suspend(card->private_data); 1595e12bea0STakashi Iwai return 0; 1605e12bea0STakashi Iwai } 1615e12bea0STakashi Iwai 1625e12bea0STakashi Iwai static int snd_pmac_driver_resume(struct platform_device *devptr) 1635e12bea0STakashi Iwai { 1645e12bea0STakashi Iwai struct snd_card *card = platform_get_drvdata(devptr); 1655e12bea0STakashi Iwai snd_pmac_resume(card->private_data); 1665e12bea0STakashi Iwai return 0; 1675e12bea0STakashi Iwai } 1685e12bea0STakashi Iwai #endif 1695e12bea0STakashi Iwai 1705e12bea0STakashi Iwai #define SND_PMAC_DRIVER "snd_powermac" 1715e12bea0STakashi Iwai 1725e12bea0STakashi Iwai static struct platform_driver snd_pmac_driver = { 1735e12bea0STakashi Iwai .probe = snd_pmac_probe, 1745e12bea0STakashi Iwai .remove = __devexit_p(snd_pmac_remove), 1755e12bea0STakashi Iwai #ifdef CONFIG_PM 1765e12bea0STakashi Iwai .suspend = snd_pmac_driver_suspend, 1775e12bea0STakashi Iwai .resume = snd_pmac_driver_resume, 1785e12bea0STakashi Iwai #endif 1795e12bea0STakashi Iwai .driver = { 1805e12bea0STakashi Iwai .name = SND_PMAC_DRIVER 1815e12bea0STakashi Iwai }, 1825e12bea0STakashi Iwai }; 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds static int __init alsa_card_pmac_init(void) 1851da177e4SLinus Torvalds { 1861da177e4SLinus Torvalds int err; 1875e12bea0STakashi Iwai 1885e12bea0STakashi Iwai if ((err = platform_driver_register(&snd_pmac_driver)) < 0) 1891da177e4SLinus Torvalds return err; 1905e12bea0STakashi Iwai device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0); 1915e12bea0STakashi Iwai if (IS_ERR(device)) { 1925e12bea0STakashi Iwai platform_driver_unregister(&snd_pmac_driver); 1935e12bea0STakashi Iwai return PTR_ERR(device); 1945e12bea0STakashi Iwai } 1951da177e4SLinus Torvalds return 0; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds } 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds static void __exit alsa_card_pmac_exit(void) 2001da177e4SLinus Torvalds { 201*f7a9275dSClemens Ladisch platform_device_unregister(device); 2025e12bea0STakashi Iwai platform_driver_unregister(&snd_pmac_driver); 2031da177e4SLinus Torvalds } 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds module_init(alsa_card_pmac_init) 2061da177e4SLinus Torvalds module_exit(alsa_card_pmac_exit) 207