xref: /openbmc/linux/sound/ppc/powermac.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * Driver for PowerMac AWACS
41da177e4SLinus Torvalds  * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de>
51da177e4SLinus Torvalds  *   based on dmasound.c.
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds #include <linux/init.h>
95e12bea0STakashi Iwai #include <linux/err.h>
105e12bea0STakashi Iwai #include <linux/platform_device.h>
1165a77217SPaul Gortmaker #include <linux/module.h>
121da177e4SLinus Torvalds #include <sound/core.h>
131da177e4SLinus Torvalds #include <sound/initval.h>
141da177e4SLinus Torvalds #include "pmac.h"
151da177e4SLinus Torvalds #include "awacs.h"
161da177e4SLinus Torvalds #include "burgundy.h"
171da177e4SLinus Torvalds 
181da177e4SLinus Torvalds #define CHIP_NAME "PMac"
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds MODULE_DESCRIPTION("PowerMac");
211da177e4SLinus Torvalds MODULE_LICENSE("GPL");
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds static int index = SNDRV_DEFAULT_IDX1;		/* Index 0-MAX */
241da177e4SLinus Torvalds static char *id = SNDRV_DEFAULT_STR1;		/* ID for this card */
25a67ff6a5SRusty Russell static bool enable_beep = 1;
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds module_param(index, int, 0444);
281da177e4SLinus Torvalds MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
291da177e4SLinus Torvalds module_param(id, charp, 0444);
301da177e4SLinus Torvalds MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
311da177e4SLinus Torvalds module_param(enable_beep, bool, 0444);
321da177e4SLinus Torvalds MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
331da177e4SLinus Torvalds 
34f7a9275dSClemens Ladisch static struct platform_device *device;
35f7a9275dSClemens Ladisch 
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds /*
381da177e4SLinus Torvalds  */
391da177e4SLinus Torvalds 
snd_pmac_probe(struct platform_device * devptr)4015afafc2SBill Pemberton static int snd_pmac_probe(struct platform_device *devptr)
411da177e4SLinus Torvalds {
4265b29f50STakashi Iwai 	struct snd_card *card;
4365b29f50STakashi Iwai 	struct snd_pmac *chip;
441da177e4SLinus Torvalds 	char *name_ext;
451da177e4SLinus Torvalds 	int err;
461da177e4SLinus Torvalds 
4710768797STakashi Iwai 	err = snd_card_new(&devptr->dev, index, id, THIS_MODULE, 0, &card);
48bd7dd77cSTakashi Iwai 	if (err < 0)
49bd7dd77cSTakashi Iwai 		return err;
501da177e4SLinus Torvalds 
51e73ad388STakashi Iwai 	err = snd_pmac_new(card, &chip);
52e73ad388STakashi Iwai 	if (err < 0)
531da177e4SLinus Torvalds 		goto __error;
545e12bea0STakashi Iwai 	card->private_data = chip;
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds 	switch (chip->model) {
571da177e4SLinus Torvalds 	case PMAC_BURGUNDY:
581da177e4SLinus Torvalds 		strcpy(card->driver, "PMac Burgundy");
591da177e4SLinus Torvalds 		strcpy(card->shortname, "PowerMac Burgundy");
601da177e4SLinus Torvalds 		sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
611da177e4SLinus Torvalds 			card->shortname, chip->device_id, chip->subframe);
62e73ad388STakashi Iwai 		err = snd_pmac_burgundy_init(chip);
63e73ad388STakashi Iwai 		if (err < 0)
641da177e4SLinus Torvalds 			goto __error;
651da177e4SLinus Torvalds 		break;
661da177e4SLinus Torvalds 	case PMAC_DACA:
671da177e4SLinus Torvalds 		strcpy(card->driver, "PMac DACA");
681da177e4SLinus Torvalds 		strcpy(card->shortname, "PowerMac DACA");
691da177e4SLinus Torvalds 		sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
701da177e4SLinus Torvalds 			card->shortname, chip->device_id, chip->subframe);
71e73ad388STakashi Iwai 		err = snd_pmac_daca_init(chip);
72e73ad388STakashi Iwai 		if (err < 0)
731da177e4SLinus Torvalds 			goto __error;
741da177e4SLinus Torvalds 		break;
751da177e4SLinus Torvalds 	case PMAC_TUMBLER:
761da177e4SLinus Torvalds 	case PMAC_SNAPPER:
771da177e4SLinus Torvalds 		name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper";
781da177e4SLinus Torvalds 		sprintf(card->driver, "PMac %s", name_ext);
791da177e4SLinus Torvalds 		sprintf(card->shortname, "PowerMac %s", name_ext);
801da177e4SLinus Torvalds 		sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
811da177e4SLinus Torvalds 			card->shortname, chip->device_id, chip->subframe);
8280b9c1beSYang Yingliang 		err = snd_pmac_tumbler_init(chip);
8380b9c1beSYang Yingliang 		if (err < 0)
8480b9c1beSYang Yingliang 			goto __error;
8580b9c1beSYang Yingliang 		err = snd_pmac_tumbler_post_init();
8680b9c1beSYang Yingliang 		if (err < 0)
871da177e4SLinus Torvalds 			goto __error;
881da177e4SLinus Torvalds 		break;
891da177e4SLinus Torvalds 	case PMAC_AWACS:
901da177e4SLinus Torvalds 	case PMAC_SCREAMER:
911da177e4SLinus Torvalds 		name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
921da177e4SLinus Torvalds 		sprintf(card->driver, "PMac %s", name_ext);
931da177e4SLinus Torvalds 		sprintf(card->shortname, "PowerMac %s", name_ext);
941da177e4SLinus Torvalds 		if (chip->is_pbook_3400)
951da177e4SLinus Torvalds 			name_ext = " [PB3400]";
961da177e4SLinus Torvalds 		else if (chip->is_pbook_G3)
971da177e4SLinus Torvalds 			name_ext = " [PBG3]";
981da177e4SLinus Torvalds 		else
991da177e4SLinus Torvalds 			name_ext = "";
1001da177e4SLinus Torvalds 		sprintf(card->longname, "%s%s Rev %d",
1011da177e4SLinus Torvalds 			card->shortname, name_ext, chip->revision);
102e73ad388STakashi Iwai 		err = snd_pmac_awacs_init(chip);
103e73ad388STakashi Iwai 		if (err < 0)
1041da177e4SLinus Torvalds 			goto __error;
1051da177e4SLinus Torvalds 		break;
1061da177e4SLinus Torvalds 	default:
1076da67113STakashi Iwai 		snd_printk(KERN_ERR "unsupported hardware %d\n", chip->model);
1081da177e4SLinus Torvalds 		err = -EINVAL;
1091da177e4SLinus Torvalds 		goto __error;
1101da177e4SLinus Torvalds 	}
1111da177e4SLinus Torvalds 
112e73ad388STakashi Iwai 	err = snd_pmac_pcm_new(chip);
113e73ad388STakashi Iwai 	if (err < 0)
1141da177e4SLinus Torvalds 		goto __error;
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds 	chip->initialized = 1;
1171da177e4SLinus Torvalds 	if (enable_beep)
1181da177e4SLinus Torvalds 		snd_pmac_attach_beep(chip);
1191da177e4SLinus Torvalds 
120e73ad388STakashi Iwai 	err = snd_card_register(card);
121e73ad388STakashi Iwai 	if (err < 0)
1221da177e4SLinus Torvalds 		goto __error;
1231da177e4SLinus Torvalds 
1245e12bea0STakashi Iwai 	platform_set_drvdata(devptr, card);
1251da177e4SLinus Torvalds 	return 0;
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds __error:
1281da177e4SLinus Torvalds 	snd_card_free(card);
1291da177e4SLinus Torvalds 	return err;
1301da177e4SLinus Torvalds }
1311da177e4SLinus Torvalds 
1321da177e4SLinus Torvalds 
snd_pmac_remove(struct platform_device * devptr)133*c3d8cb19SUwe Kleine-König static void snd_pmac_remove(struct platform_device *devptr)
1345e12bea0STakashi Iwai {
1355e12bea0STakashi Iwai 	snd_card_free(platform_get_drvdata(devptr));
1365e12bea0STakashi Iwai }
1375e12bea0STakashi Iwai 
138d34e4e00STakashi Iwai #ifdef CONFIG_PM_SLEEP
snd_pmac_driver_suspend(struct device * dev)139284e7ca7STakashi Iwai static int snd_pmac_driver_suspend(struct device *dev)
1405e12bea0STakashi Iwai {
141284e7ca7STakashi Iwai 	struct snd_card *card = dev_get_drvdata(dev);
1425e12bea0STakashi Iwai 	snd_pmac_suspend(card->private_data);
1435e12bea0STakashi Iwai 	return 0;
1445e12bea0STakashi Iwai }
1455e12bea0STakashi Iwai 
snd_pmac_driver_resume(struct device * dev)146284e7ca7STakashi Iwai static int snd_pmac_driver_resume(struct device *dev)
1475e12bea0STakashi Iwai {
148284e7ca7STakashi Iwai 	struct snd_card *card = dev_get_drvdata(dev);
1495e12bea0STakashi Iwai 	snd_pmac_resume(card->private_data);
1505e12bea0STakashi Iwai 	return 0;
1515e12bea0STakashi Iwai }
152284e7ca7STakashi Iwai 
153284e7ca7STakashi Iwai static SIMPLE_DEV_PM_OPS(snd_pmac_pm, snd_pmac_driver_suspend, snd_pmac_driver_resume);
154284e7ca7STakashi Iwai #define SND_PMAC_PM_OPS	&snd_pmac_pm
155284e7ca7STakashi Iwai #else
156284e7ca7STakashi Iwai #define SND_PMAC_PM_OPS	NULL
1575e12bea0STakashi Iwai #endif
1585e12bea0STakashi Iwai 
1595e12bea0STakashi Iwai #define SND_PMAC_DRIVER		"snd_powermac"
1605e12bea0STakashi Iwai 
1615e12bea0STakashi Iwai static struct platform_driver snd_pmac_driver = {
1625e12bea0STakashi Iwai 	.probe		= snd_pmac_probe,
163*c3d8cb19SUwe Kleine-König 	.remove_new	= snd_pmac_remove,
1645e12bea0STakashi Iwai 	.driver		= {
1658bf01d8aSTakashi Iwai 		.name	= SND_PMAC_DRIVER,
166284e7ca7STakashi Iwai 		.pm	= SND_PMAC_PM_OPS,
1675e12bea0STakashi Iwai 	},
1685e12bea0STakashi Iwai };
1691da177e4SLinus Torvalds 
alsa_card_pmac_init(void)1701da177e4SLinus Torvalds static int __init alsa_card_pmac_init(void)
1711da177e4SLinus Torvalds {
1721da177e4SLinus Torvalds 	int err;
1735e12bea0STakashi Iwai 
174e73ad388STakashi Iwai 	err = platform_driver_register(&snd_pmac_driver);
175e73ad388STakashi Iwai 	if (err < 0)
1761da177e4SLinus Torvalds 		return err;
1775e12bea0STakashi Iwai 	device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
1781da177e4SLinus Torvalds 	return 0;
1791da177e4SLinus Torvalds 
1801da177e4SLinus Torvalds }
1811da177e4SLinus Torvalds 
alsa_card_pmac_exit(void)1821da177e4SLinus Torvalds static void __exit alsa_card_pmac_exit(void)
1831da177e4SLinus Torvalds {
184545b07d3SJohannes Berg 	if (!IS_ERR(device))
185f7a9275dSClemens Ladisch 		platform_device_unregister(device);
1865e12bea0STakashi Iwai 	platform_driver_unregister(&snd_pmac_driver);
1871da177e4SLinus Torvalds }
1881da177e4SLinus Torvalds 
1891da177e4SLinus Torvalds module_init(alsa_card_pmac_init)
1901da177e4SLinus Torvalds module_exit(alsa_card_pmac_exit)
191