GNU Linux-libre 5.13.14-gnu1
[releases.git] / sound / ppc / powermac.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Driver for PowerMac AWACS
4  * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de>
5  *   based on dmasound.c.
6  */
7
8 #include <linux/init.h>
9 #include <linux/err.h>
10 #include <linux/platform_device.h>
11 #include <linux/module.h>
12 #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
20 MODULE_DESCRIPTION("PowerMac");
21 MODULE_LICENSE("GPL");
22
23 static int index = SNDRV_DEFAULT_IDX1;          /* Index 0-MAX */
24 static char *id = SNDRV_DEFAULT_STR1;           /* ID for this card */
25 static bool enable_beep = 1;
26
27 module_param(index, int, 0444);
28 MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
29 module_param(id, charp, 0444);
30 MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
31 module_param(enable_beep, bool, 0444);
32 MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
33
34 static struct platform_device *device;
35
36
37 /*
38  */
39
40 static int snd_pmac_probe(struct platform_device *devptr)
41 {
42         struct snd_card *card;
43         struct snd_pmac *chip;
44         char *name_ext;
45         int err;
46
47         err = snd_card_new(&devptr->dev, index, id, THIS_MODULE, 0, &card);
48         if (err < 0)
49                 return err;
50
51         if ((err = snd_pmac_new(card, &chip)) < 0)
52                 goto __error;
53         card->private_data = chip;
54
55         switch (chip->model) {
56         case PMAC_BURGUNDY:
57                 strcpy(card->driver, "PMac Burgundy");
58                 strcpy(card->shortname, "PowerMac Burgundy");
59                 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
60                         card->shortname, chip->device_id, chip->subframe);
61                 if ((err = snd_pmac_burgundy_init(chip)) < 0)
62                         goto __error;
63                 break;
64         case PMAC_DACA:
65                 strcpy(card->driver, "PMac DACA");
66                 strcpy(card->shortname, "PowerMac DACA");
67                 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
68                         card->shortname, chip->device_id, chip->subframe);
69                 if ((err = snd_pmac_daca_init(chip)) < 0)
70                         goto __error;
71                 break;
72         case PMAC_TUMBLER:
73         case PMAC_SNAPPER:
74                 name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper";
75                 sprintf(card->driver, "PMac %s", name_ext);
76                 sprintf(card->shortname, "PowerMac %s", name_ext);
77                 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
78                         card->shortname, chip->device_id, chip->subframe);
79                 err = snd_pmac_tumbler_init(chip);
80                 if (err < 0)
81                         goto __error;
82                 err = snd_pmac_tumbler_post_init();
83                 if (err < 0)
84                         goto __error;
85                 break;
86         case PMAC_AWACS:
87         case PMAC_SCREAMER:
88                 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
89                 sprintf(card->driver, "PMac %s", name_ext);
90                 sprintf(card->shortname, "PowerMac %s", name_ext);
91                 if (chip->is_pbook_3400)
92                         name_ext = " [PB3400]";
93                 else if (chip->is_pbook_G3)
94                         name_ext = " [PBG3]";
95                 else
96                         name_ext = "";
97                 sprintf(card->longname, "%s%s Rev %d",
98                         card->shortname, name_ext, chip->revision);
99                 if ((err = snd_pmac_awacs_init(chip)) < 0)
100                         goto __error;
101                 break;
102         default:
103                 snd_printk(KERN_ERR "unsupported hardware %d\n", chip->model);
104                 err = -EINVAL;
105                 goto __error;
106         }
107
108         if ((err = snd_pmac_pcm_new(chip)) < 0)
109                 goto __error;
110
111         chip->initialized = 1;
112         if (enable_beep)
113                 snd_pmac_attach_beep(chip);
114
115         if ((err = snd_card_register(card)) < 0)
116                 goto __error;
117
118         platform_set_drvdata(devptr, card);
119         return 0;
120
121 __error:
122         snd_card_free(card);
123         return err;
124 }
125
126
127 static int snd_pmac_remove(struct platform_device *devptr)
128 {
129         snd_card_free(platform_get_drvdata(devptr));
130         return 0;
131 }
132
133 #ifdef CONFIG_PM_SLEEP
134 static int snd_pmac_driver_suspend(struct device *dev)
135 {
136         struct snd_card *card = dev_get_drvdata(dev);
137         snd_pmac_suspend(card->private_data);
138         return 0;
139 }
140
141 static int snd_pmac_driver_resume(struct device *dev)
142 {
143         struct snd_card *card = dev_get_drvdata(dev);
144         snd_pmac_resume(card->private_data);
145         return 0;
146 }
147
148 static SIMPLE_DEV_PM_OPS(snd_pmac_pm, snd_pmac_driver_suspend, snd_pmac_driver_resume);
149 #define SND_PMAC_PM_OPS &snd_pmac_pm
150 #else
151 #define SND_PMAC_PM_OPS NULL
152 #endif
153
154 #define SND_PMAC_DRIVER         "snd_powermac"
155
156 static struct platform_driver snd_pmac_driver = {
157         .probe          = snd_pmac_probe,
158         .remove         = snd_pmac_remove,
159         .driver         = {
160                 .name   = SND_PMAC_DRIVER,
161                 .pm     = SND_PMAC_PM_OPS,
162         },
163 };
164
165 static int __init alsa_card_pmac_init(void)
166 {
167         int err;
168
169         if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
170                 return err;
171         device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
172         return 0;
173
174 }
175
176 static void __exit alsa_card_pmac_exit(void)
177 {
178         if (!IS_ERR(device))
179                 platform_device_unregister(device);
180         platform_driver_unregister(&snd_pmac_driver);
181 }
182
183 module_init(alsa_card_pmac_init)
184 module_exit(alsa_card_pmac_exit)