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