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 <linux/init.h> 225e12bea0STakashi Iwai #include <linux/err.h> 235e12bea0STakashi Iwai #include <linux/platform_device.h> 2465a77217SPaul Gortmaker #include <linux/module.h> 251da177e4SLinus Torvalds #include <sound/core.h> 261da177e4SLinus Torvalds #include <sound/initval.h> 271da177e4SLinus Torvalds #include "pmac.h" 281da177e4SLinus Torvalds #include "awacs.h" 291da177e4SLinus Torvalds #include "burgundy.h" 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds #define CHIP_NAME "PMac" 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds MODULE_DESCRIPTION("PowerMac"); 341da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{Apple,PowerMac}}"); 351da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ 381da177e4SLinus Torvalds static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ 39*a67ff6a5SRusty Russell static bool enable_beep = 1; 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds module_param(index, int, 0444); 421da177e4SLinus Torvalds MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip."); 431da177e4SLinus Torvalds module_param(id, charp, 0444); 441da177e4SLinus Torvalds MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip."); 451da177e4SLinus Torvalds module_param(enable_beep, bool, 0444); 461da177e4SLinus Torvalds MODULE_PARM_DESC(enable_beep, "Enable beep using PCM."); 471da177e4SLinus Torvalds 48f7a9275dSClemens Ladisch static struct platform_device *device; 49f7a9275dSClemens Ladisch 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds /* 521da177e4SLinus Torvalds */ 531da177e4SLinus Torvalds 547d2ac103SUwe Kleine-König static int __devinit snd_pmac_probe(struct platform_device *devptr) 551da177e4SLinus Torvalds { 5665b29f50STakashi Iwai struct snd_card *card; 5765b29f50STakashi Iwai struct snd_pmac *chip; 581da177e4SLinus Torvalds char *name_ext; 591da177e4SLinus Torvalds int err; 601da177e4SLinus Torvalds 61bd7dd77cSTakashi Iwai err = snd_card_create(index, id, THIS_MODULE, 0, &card); 62bd7dd77cSTakashi Iwai if (err < 0) 63bd7dd77cSTakashi Iwai return err; 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds if ((err = snd_pmac_new(card, &chip)) < 0) 661da177e4SLinus Torvalds goto __error; 675e12bea0STakashi Iwai card->private_data = chip; 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds switch (chip->model) { 701da177e4SLinus Torvalds case PMAC_BURGUNDY: 711da177e4SLinus Torvalds strcpy(card->driver, "PMac Burgundy"); 721da177e4SLinus Torvalds strcpy(card->shortname, "PowerMac Burgundy"); 731da177e4SLinus Torvalds sprintf(card->longname, "%s (Dev %d) Sub-frame %d", 741da177e4SLinus Torvalds card->shortname, chip->device_id, chip->subframe); 751da177e4SLinus Torvalds if ((err = snd_pmac_burgundy_init(chip)) < 0) 761da177e4SLinus Torvalds goto __error; 771da177e4SLinus Torvalds break; 781da177e4SLinus Torvalds case PMAC_DACA: 791da177e4SLinus Torvalds strcpy(card->driver, "PMac DACA"); 801da177e4SLinus Torvalds strcpy(card->shortname, "PowerMac DACA"); 811da177e4SLinus Torvalds sprintf(card->longname, "%s (Dev %d) Sub-frame %d", 821da177e4SLinus Torvalds card->shortname, chip->device_id, chip->subframe); 831da177e4SLinus Torvalds if ((err = snd_pmac_daca_init(chip)) < 0) 841da177e4SLinus Torvalds goto __error; 851da177e4SLinus Torvalds break; 861da177e4SLinus Torvalds case PMAC_TUMBLER: 871da177e4SLinus Torvalds case PMAC_SNAPPER: 881da177e4SLinus Torvalds name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper"; 891da177e4SLinus Torvalds sprintf(card->driver, "PMac %s", name_ext); 901da177e4SLinus Torvalds sprintf(card->shortname, "PowerMac %s", name_ext); 911da177e4SLinus Torvalds sprintf(card->longname, "%s (Dev %d) Sub-frame %d", 921da177e4SLinus Torvalds card->shortname, chip->device_id, chip->subframe); 931da177e4SLinus Torvalds if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0) 941da177e4SLinus Torvalds goto __error; 951da177e4SLinus Torvalds break; 961da177e4SLinus Torvalds case PMAC_AWACS: 971da177e4SLinus Torvalds case PMAC_SCREAMER: 981da177e4SLinus Torvalds name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS"; 991da177e4SLinus Torvalds sprintf(card->driver, "PMac %s", name_ext); 1001da177e4SLinus Torvalds sprintf(card->shortname, "PowerMac %s", name_ext); 1011da177e4SLinus Torvalds if (chip->is_pbook_3400) 1021da177e4SLinus Torvalds name_ext = " [PB3400]"; 1031da177e4SLinus Torvalds else if (chip->is_pbook_G3) 1041da177e4SLinus Torvalds name_ext = " [PBG3]"; 1051da177e4SLinus Torvalds else 1061da177e4SLinus Torvalds name_ext = ""; 1071da177e4SLinus Torvalds sprintf(card->longname, "%s%s Rev %d", 1081da177e4SLinus Torvalds card->shortname, name_ext, chip->revision); 1091da177e4SLinus Torvalds if ((err = snd_pmac_awacs_init(chip)) < 0) 1101da177e4SLinus Torvalds goto __error; 1111da177e4SLinus Torvalds break; 1121da177e4SLinus Torvalds default: 1136da67113STakashi Iwai snd_printk(KERN_ERR "unsupported hardware %d\n", chip->model); 1141da177e4SLinus Torvalds err = -EINVAL; 1151da177e4SLinus Torvalds goto __error; 1161da177e4SLinus Torvalds } 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds if ((err = snd_pmac_pcm_new(chip)) < 0) 1191da177e4SLinus Torvalds goto __error; 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds chip->initialized = 1; 1221da177e4SLinus Torvalds if (enable_beep) 1231da177e4SLinus Torvalds snd_pmac_attach_beep(chip); 1241da177e4SLinus Torvalds 1255e12bea0STakashi Iwai snd_card_set_dev(card, &devptr->dev); 12616dab54bSTakashi Iwai 1271da177e4SLinus Torvalds if ((err = snd_card_register(card)) < 0) 1281da177e4SLinus Torvalds goto __error; 1291da177e4SLinus Torvalds 1305e12bea0STakashi Iwai platform_set_drvdata(devptr, card); 1311da177e4SLinus Torvalds return 0; 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds __error: 1341da177e4SLinus Torvalds snd_card_free(card); 1351da177e4SLinus Torvalds return err; 1361da177e4SLinus Torvalds } 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds 1395e12bea0STakashi Iwai static int __devexit snd_pmac_remove(struct platform_device *devptr) 1405e12bea0STakashi Iwai { 1415e12bea0STakashi Iwai snd_card_free(platform_get_drvdata(devptr)); 1425e12bea0STakashi Iwai platform_set_drvdata(devptr, NULL); 1435e12bea0STakashi Iwai return 0; 1445e12bea0STakashi Iwai } 1455e12bea0STakashi Iwai 1465e12bea0STakashi Iwai #ifdef CONFIG_PM 1475e12bea0STakashi Iwai static int snd_pmac_driver_suspend(struct platform_device *devptr, pm_message_t state) 1485e12bea0STakashi Iwai { 1495e12bea0STakashi Iwai struct snd_card *card = platform_get_drvdata(devptr); 1505e12bea0STakashi Iwai snd_pmac_suspend(card->private_data); 1515e12bea0STakashi Iwai return 0; 1525e12bea0STakashi Iwai } 1535e12bea0STakashi Iwai 1545e12bea0STakashi Iwai static int snd_pmac_driver_resume(struct platform_device *devptr) 1555e12bea0STakashi Iwai { 1565e12bea0STakashi Iwai struct snd_card *card = platform_get_drvdata(devptr); 1575e12bea0STakashi Iwai snd_pmac_resume(card->private_data); 1585e12bea0STakashi Iwai return 0; 1595e12bea0STakashi Iwai } 1605e12bea0STakashi Iwai #endif 1615e12bea0STakashi Iwai 1625e12bea0STakashi Iwai #define SND_PMAC_DRIVER "snd_powermac" 1635e12bea0STakashi Iwai 1645e12bea0STakashi Iwai static struct platform_driver snd_pmac_driver = { 1655e12bea0STakashi Iwai .probe = snd_pmac_probe, 1665e12bea0STakashi Iwai .remove = __devexit_p(snd_pmac_remove), 1675e12bea0STakashi Iwai #ifdef CONFIG_PM 1685e12bea0STakashi Iwai .suspend = snd_pmac_driver_suspend, 1695e12bea0STakashi Iwai .resume = snd_pmac_driver_resume, 1705e12bea0STakashi Iwai #endif 1715e12bea0STakashi Iwai .driver = { 1725e12bea0STakashi Iwai .name = SND_PMAC_DRIVER 1735e12bea0STakashi Iwai }, 1745e12bea0STakashi Iwai }; 1751da177e4SLinus Torvalds 1761da177e4SLinus Torvalds static int __init alsa_card_pmac_init(void) 1771da177e4SLinus Torvalds { 1781da177e4SLinus Torvalds int err; 1795e12bea0STakashi Iwai 1805e12bea0STakashi Iwai if ((err = platform_driver_register(&snd_pmac_driver)) < 0) 1811da177e4SLinus Torvalds return err; 1825e12bea0STakashi Iwai device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0); 1831da177e4SLinus Torvalds return 0; 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds static void __exit alsa_card_pmac_exit(void) 1881da177e4SLinus Torvalds { 189545b07d3SJohannes Berg if (!IS_ERR(device)) 190f7a9275dSClemens Ladisch platform_device_unregister(device); 1915e12bea0STakashi Iwai platform_driver_unregister(&snd_pmac_driver); 1921da177e4SLinus Torvalds } 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds module_init(alsa_card_pmac_init) 1951da177e4SLinus Torvalds module_exit(alsa_card_pmac_exit) 196