MIPS: Add missing VZ accessor microMIPS encodings
[linux-2.6-block.git] / sound / ppc / powermac.c
CommitLineData
1da177e4
LT
1/*
2 * Driver for PowerMac AWACS
3 * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de>
4 * based on dmasound.c.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
1da177e4 21#include <linux/init.h>
5e12bea0
TI
22#include <linux/err.h>
23#include <linux/platform_device.h>
65a77217 24#include <linux/module.h>
1da177e4
LT
25#include <sound/core.h>
26#include <sound/initval.h>
27#include "pmac.h"
28#include "awacs.h"
29#include "burgundy.h"
30
31#define CHIP_NAME "PMac"
32
33MODULE_DESCRIPTION("PowerMac");
34MODULE_SUPPORTED_DEVICE("{{Apple,PowerMac}}");
35MODULE_LICENSE("GPL");
36
37static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
38static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
a67ff6a5 39static bool enable_beep = 1;
1da177e4
LT
40
41module_param(index, int, 0444);
42MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
43module_param(id, charp, 0444);
44MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
45module_param(enable_beep, bool, 0444);
46MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
47
f7a9275d
CL
48static struct platform_device *device;
49
1da177e4
LT
50
51/*
1da177e4
LT
52 */
53
15afafc2 54static int snd_pmac_probe(struct platform_device *devptr)
1da177e4 55{
65b29f50
TI
56 struct snd_card *card;
57 struct snd_pmac *chip;
1da177e4
LT
58 char *name_ext;
59 int err;
60
10768797 61 err = snd_card_new(&devptr->dev, index, id, THIS_MODULE, 0, &card);
bd7dd77c
TI
62 if (err < 0)
63 return err;
1da177e4
LT
64
65 if ((err = snd_pmac_new(card, &chip)) < 0)
66 goto __error;
5e12bea0 67 card->private_data = chip;
1da177e4
LT
68
69 switch (chip->model) {
70 case PMAC_BURGUNDY:
71 strcpy(card->driver, "PMac Burgundy");
72 strcpy(card->shortname, "PowerMac Burgundy");
73 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
74 card->shortname, chip->device_id, chip->subframe);
75 if ((err = snd_pmac_burgundy_init(chip)) < 0)
76 goto __error;
77 break;
78 case PMAC_DACA:
79 strcpy(card->driver, "PMac DACA");
80 strcpy(card->shortname, "PowerMac DACA");
81 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
82 card->shortname, chip->device_id, chip->subframe);
83 if ((err = snd_pmac_daca_init(chip)) < 0)
84 goto __error;
85 break;
86 case PMAC_TUMBLER:
87 case PMAC_SNAPPER:
88 name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper";
89 sprintf(card->driver, "PMac %s", name_ext);
90 sprintf(card->shortname, "PowerMac %s", name_ext);
91 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
92 card->shortname, chip->device_id, chip->subframe);
93 if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0)
94 goto __error;
95 break;
96 case PMAC_AWACS:
97 case PMAC_SCREAMER:
98 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
99 sprintf(card->driver, "PMac %s", name_ext);
100 sprintf(card->shortname, "PowerMac %s", name_ext);
101 if (chip->is_pbook_3400)
102 name_ext = " [PB3400]";
103 else if (chip->is_pbook_G3)
104 name_ext = " [PBG3]";
105 else
106 name_ext = "";
107 sprintf(card->longname, "%s%s Rev %d",
108 card->shortname, name_ext, chip->revision);
109 if ((err = snd_pmac_awacs_init(chip)) < 0)
110 goto __error;
111 break;
112 default:
6da67113 113 snd_printk(KERN_ERR "unsupported hardware %d\n", chip->model);
1da177e4
LT
114 err = -EINVAL;
115 goto __error;
116 }
117
118 if ((err = snd_pmac_pcm_new(chip)) < 0)
119 goto __error;
120
121 chip->initialized = 1;
122 if (enable_beep)
123 snd_pmac_attach_beep(chip);
124
125 if ((err = snd_card_register(card)) < 0)
126 goto __error;
127
5e12bea0 128 platform_set_drvdata(devptr, card);
1da177e4
LT
129 return 0;
130
131__error:
132 snd_card_free(card);
133 return err;
134}
135
136
15afafc2 137static int snd_pmac_remove(struct platform_device *devptr)
5e12bea0
TI
138{
139 snd_card_free(platform_get_drvdata(devptr));
5e12bea0
TI
140 return 0;
141}
142
d34e4e00 143#ifdef CONFIG_PM_SLEEP
284e7ca7 144static int snd_pmac_driver_suspend(struct device *dev)
5e12bea0 145{
284e7ca7 146 struct snd_card *card = dev_get_drvdata(dev);
5e12bea0
TI
147 snd_pmac_suspend(card->private_data);
148 return 0;
149}
150
284e7ca7 151static int snd_pmac_driver_resume(struct device *dev)
5e12bea0 152{
284e7ca7 153 struct snd_card *card = dev_get_drvdata(dev);
5e12bea0
TI
154 snd_pmac_resume(card->private_data);
155 return 0;
156}
284e7ca7
TI
157
158static SIMPLE_DEV_PM_OPS(snd_pmac_pm, snd_pmac_driver_suspend, snd_pmac_driver_resume);
159#define SND_PMAC_PM_OPS &snd_pmac_pm
160#else
161#define SND_PMAC_PM_OPS NULL
5e12bea0
TI
162#endif
163
164#define SND_PMAC_DRIVER "snd_powermac"
165
166static struct platform_driver snd_pmac_driver = {
167 .probe = snd_pmac_probe,
15afafc2 168 .remove = snd_pmac_remove,
5e12bea0 169 .driver = {
8bf01d8a 170 .name = SND_PMAC_DRIVER,
284e7ca7 171 .pm = SND_PMAC_PM_OPS,
5e12bea0
TI
172 },
173};
1da177e4
LT
174
175static int __init alsa_card_pmac_init(void)
176{
177 int err;
5e12bea0
TI
178
179 if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
1da177e4 180 return err;
5e12bea0 181 device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
545b07d3 182 return 0;
1da177e4
LT
183
184}
185
186static void __exit alsa_card_pmac_exit(void)
187{
545b07d3
JB
188 if (!IS_ERR(device))
189 platform_device_unregister(device);
5e12bea0 190 platform_driver_unregister(&snd_pmac_driver);
1da177e4
LT
191}
192
193module_init(alsa_card_pmac_init)
194module_exit(alsa_card_pmac_exit)