blob: e17af46abddd56747a39e76fda81998b3b100703 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Driver for PowerMac AWACS
4 * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de>
5 * based on dmasound.c.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/init.h>
Takashi Iwai5e12bea2005-11-17 17:17:08 +01009#include <linux/err.h>
10#include <linux/platform_device.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040011#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <sound/core.h>
13#include <sound/initval.h>
14#include "pmac.h"
15#include "awacs.h"
16#include "burgundy.h"
17
18#define CHIP_NAME "PMac"
19
20MODULE_DESCRIPTION("PowerMac");
Linus Torvalds1da177e2005-04-16 15:20:36 -070021MODULE_LICENSE("GPL");
22
23static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
24static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +103025static bool enable_beep = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27module_param(index, int, 0444);
28MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
29module_param(id, charp, 0444);
30MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
31module_param(enable_beep, bool, 0444);
32MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
33
Clemens Ladischf7a92752005-12-07 09:13:42 +010034static struct platform_device *device;
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 */
39
Bill Pemberton15afafc2012-12-06 12:35:23 -050040static int snd_pmac_probe(struct platform_device *devptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
Takashi Iwai65b29f52005-11-17 15:09:46 +010042 struct snd_card *card;
43 struct snd_pmac *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 char *name_ext;
45 int err;
46
Takashi Iwai10768792014-01-29 14:38:59 +010047 err = snd_card_new(&devptr->dev, index, id, THIS_MODULE, 0, &card);
Takashi Iwaibd7dd772008-12-28 16:45:02 +010048 if (err < 0)
49 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Takashi Iwaie73ad382021-06-08 16:05:38 +020051 err = snd_pmac_new(card, &chip);
52 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 goto __error;
Takashi Iwai5e12bea2005-11-17 17:17:08 +010054 card->private_data = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56 switch (chip->model) {
57 case PMAC_BURGUNDY:
58 strcpy(card->driver, "PMac Burgundy");
59 strcpy(card->shortname, "PowerMac Burgundy");
60 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
61 card->shortname, chip->device_id, chip->subframe);
Takashi Iwaie73ad382021-06-08 16:05:38 +020062 err = snd_pmac_burgundy_init(chip);
63 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 goto __error;
65 break;
66 case PMAC_DACA:
67 strcpy(card->driver, "PMac DACA");
68 strcpy(card->shortname, "PowerMac DACA");
69 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
70 card->shortname, chip->device_id, chip->subframe);
Takashi Iwaie73ad382021-06-08 16:05:38 +020071 err = snd_pmac_daca_init(chip);
72 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 goto __error;
74 break;
75 case PMAC_TUMBLER:
76 case PMAC_SNAPPER:
77 name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper";
78 sprintf(card->driver, "PMac %s", name_ext);
79 sprintf(card->shortname, "PowerMac %s", name_ext);
80 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
81 card->shortname, chip->device_id, chip->subframe);
Yang Yingliang80b9c1b2021-06-16 10:11:21 +080082 err = snd_pmac_tumbler_init(chip);
83 if (err < 0)
84 goto __error;
85 err = snd_pmac_tumbler_post_init();
86 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 goto __error;
88 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 case PMAC_AWACS:
90 case PMAC_SCREAMER:
91 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
92 sprintf(card->driver, "PMac %s", name_ext);
93 sprintf(card->shortname, "PowerMac %s", name_ext);
94 if (chip->is_pbook_3400)
95 name_ext = " [PB3400]";
96 else if (chip->is_pbook_G3)
97 name_ext = " [PBG3]";
98 else
99 name_ext = "";
100 sprintf(card->longname, "%s%s Rev %d",
101 card->shortname, name_ext, chip->revision);
Takashi Iwaie73ad382021-06-08 16:05:38 +0200102 err = snd_pmac_awacs_init(chip);
103 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 goto __error;
105 break;
106 default:
Takashi Iwai6da67112009-02-05 16:02:46 +0100107 snd_printk(KERN_ERR "unsupported hardware %d\n", chip->model);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 err = -EINVAL;
109 goto __error;
110 }
111
Takashi Iwaie73ad382021-06-08 16:05:38 +0200112 err = snd_pmac_pcm_new(chip);
113 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 goto __error;
115
116 chip->initialized = 1;
117 if (enable_beep)
118 snd_pmac_attach_beep(chip);
119
Takashi Iwaie73ad382021-06-08 16:05:38 +0200120 err = snd_card_register(card);
121 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 goto __error;
123
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100124 platform_set_drvdata(devptr, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 return 0;
126
127__error:
128 snd_card_free(card);
129 return err;
130}
131
132
Uwe Kleine-Königc3d8cb12023-03-15 16:05:02 +0100133static void snd_pmac_remove(struct platform_device *devptr)
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100134{
135 snd_card_free(platform_get_drvdata(devptr));
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100136}
137
Takashi Iwaid34e4e02012-08-09 15:47:15 +0200138#ifdef CONFIG_PM_SLEEP
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200139static int snd_pmac_driver_suspend(struct device *dev)
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100140{
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200141 struct snd_card *card = dev_get_drvdata(dev);
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100142 snd_pmac_suspend(card->private_data);
143 return 0;
144}
145
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200146static int snd_pmac_driver_resume(struct device *dev)
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100147{
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200148 struct snd_card *card = dev_get_drvdata(dev);
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100149 snd_pmac_resume(card->private_data);
150 return 0;
151}
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200152
153static SIMPLE_DEV_PM_OPS(snd_pmac_pm, snd_pmac_driver_suspend, snd_pmac_driver_resume);
154#define SND_PMAC_PM_OPS &snd_pmac_pm
155#else
156#define SND_PMAC_PM_OPS NULL
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100157#endif
158
159#define SND_PMAC_DRIVER "snd_powermac"
160
161static struct platform_driver snd_pmac_driver = {
162 .probe = snd_pmac_probe,
Uwe Kleine-Königc3d8cb12023-03-15 16:05:02 +0100163 .remove_new = snd_pmac_remove,
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100164 .driver = {
Takashi Iwai8bf01d82012-07-02 10:50:24 +0200165 .name = SND_PMAC_DRIVER,
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200166 .pm = SND_PMAC_PM_OPS,
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100167 },
168};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170static int __init alsa_card_pmac_init(void)
171{
172 int err;
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100173
Takashi Iwaie73ad382021-06-08 16:05:38 +0200174 err = platform_driver_register(&snd_pmac_driver);
175 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return err;
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100177 device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
Johannes Berg545b07d2006-07-25 16:14:16 +0200178 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180}
181
182static void __exit alsa_card_pmac_exit(void)
183{
Johannes Berg545b07d2006-07-25 16:14:16 +0200184 if (!IS_ERR(device))
185 platform_device_unregister(device);
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100186 platform_driver_unregister(&snd_pmac_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187}
188
189module_init(alsa_card_pmac_init)
190module_exit(alsa_card_pmac_exit)