ALSA: control_led - fix initialization in the mode show callback
[linux-2.6-block.git] / sound / ppc / powermac.c
CommitLineData
1a59d1b8 1// SPDX-License-Identifier: GPL-2.0-or-later
1da177e4
LT
2/*
3 * Driver for PowerMac AWACS
4 * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de>
5 * based on dmasound.c.
1da177e4
LT
6 */
7
1da177e4 8#include <linux/init.h>
5e12bea0
TI
9#include <linux/err.h>
10#include <linux/platform_device.h>
65a77217 11#include <linux/module.h>
1da177e4
LT
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");
1da177e4
LT
21MODULE_LICENSE("GPL");
22
23static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
24static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
a67ff6a5 25static bool enable_beep = 1;
1da177e4
LT
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
f7a9275d
CL
34static struct platform_device *device;
35
1da177e4
LT
36
37/*
1da177e4
LT
38 */
39
15afafc2 40static int snd_pmac_probe(struct platform_device *devptr)
1da177e4 41{
65b29f50
TI
42 struct snd_card *card;
43 struct snd_pmac *chip;
1da177e4
LT
44 char *name_ext;
45 int err;
46
10768797 47 err = snd_card_new(&devptr->dev, index, id, THIS_MODULE, 0, &card);
bd7dd77c
TI
48 if (err < 0)
49 return err;
1da177e4 50
e73ad388
TI
51 err = snd_pmac_new(card, &chip);
52 if (err < 0)
1da177e4 53 goto __error;
5e12bea0 54 card->private_data = chip;
1da177e4
LT
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);
e73ad388
TI
62 err = snd_pmac_burgundy_init(chip);
63 if (err < 0)
1da177e4
LT
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);
e73ad388
TI
71 err = snd_pmac_daca_init(chip);
72 if (err < 0)
1da177e4
LT
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 if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0)
83 goto __error;
84 break;
85 case PMAC_AWACS:
86 case PMAC_SCREAMER:
87 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
88 sprintf(card->driver, "PMac %s", name_ext);
89 sprintf(card->shortname, "PowerMac %s", name_ext);
90 if (chip->is_pbook_3400)
91 name_ext = " [PB3400]";
92 else if (chip->is_pbook_G3)
93 name_ext = " [PBG3]";
94 else
95 name_ext = "";
96 sprintf(card->longname, "%s%s Rev %d",
97 card->shortname, name_ext, chip->revision);
e73ad388
TI
98 err = snd_pmac_awacs_init(chip);
99 if (err < 0)
1da177e4
LT
100 goto __error;
101 break;
102 default:
6da67113 103 snd_printk(KERN_ERR "unsupported hardware %d\n", chip->model);
1da177e4
LT
104 err = -EINVAL;
105 goto __error;
106 }
107
e73ad388
TI
108 err = snd_pmac_pcm_new(chip);
109 if (err < 0)
1da177e4
LT
110 goto __error;
111
112 chip->initialized = 1;
113 if (enable_beep)
114 snd_pmac_attach_beep(chip);
115
e73ad388
TI
116 err = snd_card_register(card);
117 if (err < 0)
1da177e4
LT
118 goto __error;
119
5e12bea0 120 platform_set_drvdata(devptr, card);
1da177e4
LT
121 return 0;
122
123__error:
124 snd_card_free(card);
125 return err;
126}
127
128
15afafc2 129static int snd_pmac_remove(struct platform_device *devptr)
5e12bea0
TI
130{
131 snd_card_free(platform_get_drvdata(devptr));
5e12bea0
TI
132 return 0;
133}
134
d34e4e00 135#ifdef CONFIG_PM_SLEEP
284e7ca7 136static int snd_pmac_driver_suspend(struct device *dev)
5e12bea0 137{
284e7ca7 138 struct snd_card *card = dev_get_drvdata(dev);
5e12bea0
TI
139 snd_pmac_suspend(card->private_data);
140 return 0;
141}
142
284e7ca7 143static int snd_pmac_driver_resume(struct device *dev)
5e12bea0 144{
284e7ca7 145 struct snd_card *card = dev_get_drvdata(dev);
5e12bea0
TI
146 snd_pmac_resume(card->private_data);
147 return 0;
148}
284e7ca7
TI
149
150static SIMPLE_DEV_PM_OPS(snd_pmac_pm, snd_pmac_driver_suspend, snd_pmac_driver_resume);
151#define SND_PMAC_PM_OPS &snd_pmac_pm
152#else
153#define SND_PMAC_PM_OPS NULL
5e12bea0
TI
154#endif
155
156#define SND_PMAC_DRIVER "snd_powermac"
157
158static struct platform_driver snd_pmac_driver = {
159 .probe = snd_pmac_probe,
15afafc2 160 .remove = snd_pmac_remove,
5e12bea0 161 .driver = {
8bf01d8a 162 .name = SND_PMAC_DRIVER,
284e7ca7 163 .pm = SND_PMAC_PM_OPS,
5e12bea0
TI
164 },
165};
1da177e4
LT
166
167static int __init alsa_card_pmac_init(void)
168{
169 int err;
5e12bea0 170
e73ad388
TI
171 err = platform_driver_register(&snd_pmac_driver);
172 if (err < 0)
1da177e4 173 return err;
5e12bea0 174 device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
545b07d3 175 return 0;
1da177e4
LT
176
177}
178
179static void __exit alsa_card_pmac_exit(void)
180{
545b07d3
JB
181 if (!IS_ERR(device))
182 platform_device_unregister(device);
5e12bea0 183 platform_driver_unregister(&snd_pmac_driver);
1da177e4
LT
184}
185
186module_init(alsa_card_pmac_init)
187module_exit(alsa_card_pmac_exit)