blob: efa06fe5f01b78e9ecbca908a7fbc30a79d7376f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
21#include <sound/driver.h>
22#include <linux/init.h>
Takashi Iwai5e12bea2005-11-17 17:17:08 +010023#include <linux/err.h>
24#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/moduleparam.h>
26#include <sound/core.h>
27#include <sound/initval.h>
28#include "pmac.h"
29#include "awacs.h"
30#include "burgundy.h"
31
32#define CHIP_NAME "PMac"
33
34MODULE_DESCRIPTION("PowerMac");
35MODULE_SUPPORTED_DEVICE("{{Apple,PowerMac}}");
36MODULE_LICENSE("GPL");
37
38static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
39static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
40static int enable_beep = 1;
41
42module_param(index, int, 0444);
43MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
44module_param(id, charp, 0444);
45MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
46module_param(enable_beep, bool, 0444);
47MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
48
49
50/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 */
52
Takashi Iwai5e12bea2005-11-17 17:17:08 +010053static int __init snd_pmac_probe(struct platform_device *devptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
Takashi Iwai65b29f52005-11-17 15:09:46 +010055 struct snd_card *card;
56 struct snd_pmac *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 char *name_ext;
58 int err;
59
60 card = snd_card_new(index, id, THIS_MODULE, 0);
61 if (card == NULL)
62 return -ENOMEM;
63
64 if ((err = snd_pmac_new(card, &chip)) < 0)
65 goto __error;
Takashi Iwai5e12bea2005-11-17 17:17:08 +010066 card->private_data = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 switch (chip->model) {
69 case PMAC_BURGUNDY:
70 strcpy(card->driver, "PMac Burgundy");
71 strcpy(card->shortname, "PowerMac Burgundy");
72 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
73 card->shortname, chip->device_id, chip->subframe);
74 if ((err = snd_pmac_burgundy_init(chip)) < 0)
75 goto __error;
76 break;
77 case PMAC_DACA:
78 strcpy(card->driver, "PMac DACA");
79 strcpy(card->shortname, "PowerMac DACA");
80 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
81 card->shortname, chip->device_id, chip->subframe);
82 if ((err = snd_pmac_daca_init(chip)) < 0)
83 goto __error;
84 break;
85 case PMAC_TUMBLER:
86 case PMAC_SNAPPER:
87 name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper";
88 sprintf(card->driver, "PMac %s", name_ext);
89 sprintf(card->shortname, "PowerMac %s", name_ext);
90 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
91 card->shortname, chip->device_id, chip->subframe);
92 if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0)
93 goto __error;
94 break;
Benjamin Herrenschmidt1f7b49d2005-05-01 08:58:43 -070095 case PMAC_TOONIE:
96 strcpy(card->driver, "PMac Toonie");
97 strcpy(card->shortname, "PowerMac Toonie");
98 strcpy(card->longname, card->shortname);
99 if ((err = snd_pmac_toonie_init(chip)) < 0)
100 goto __error;
101 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 case PMAC_AWACS:
103 case PMAC_SCREAMER:
104 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
105 sprintf(card->driver, "PMac %s", name_ext);
106 sprintf(card->shortname, "PowerMac %s", name_ext);
107 if (chip->is_pbook_3400)
108 name_ext = " [PB3400]";
109 else if (chip->is_pbook_G3)
110 name_ext = " [PBG3]";
111 else
112 name_ext = "";
113 sprintf(card->longname, "%s%s Rev %d",
114 card->shortname, name_ext, chip->revision);
115 if ((err = snd_pmac_awacs_init(chip)) < 0)
116 goto __error;
117 break;
118 default:
119 snd_printk("unsupported hardware %d\n", chip->model);
120 err = -EINVAL;
121 goto __error;
122 }
123
124 if ((err = snd_pmac_pcm_new(chip)) < 0)
125 goto __error;
126
127 chip->initialized = 1;
128 if (enable_beep)
129 snd_pmac_attach_beep(chip);
130
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100131 snd_card_set_dev(card, &devptr->dev);
Takashi Iwai16dab542005-09-05 17:17:58 +0200132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 if ((err = snd_card_register(card)) < 0)
134 goto __error;
135
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100136 platform_set_drvdata(devptr, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return 0;
138
139__error:
140 snd_card_free(card);
141 return err;
142}
143
144
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100145static int __devexit snd_pmac_remove(struct platform_device *devptr)
146{
147 snd_card_free(platform_get_drvdata(devptr));
148 platform_set_drvdata(devptr, NULL);
149 return 0;
150}
151
152#ifdef CONFIG_PM
153static int snd_pmac_driver_suspend(struct platform_device *devptr, pm_message_t state)
154{
155 struct snd_card *card = platform_get_drvdata(devptr);
156 snd_pmac_suspend(card->private_data);
157 return 0;
158}
159
160static int snd_pmac_driver_resume(struct platform_device *devptr)
161{
162 struct snd_card *card = platform_get_drvdata(devptr);
163 snd_pmac_resume(card->private_data);
164 return 0;
165}
166#endif
167
168#define SND_PMAC_DRIVER "snd_powermac"
169
170static struct platform_driver snd_pmac_driver = {
171 .probe = snd_pmac_probe,
172 .remove = __devexit_p(snd_pmac_remove),
173#ifdef CONFIG_PM
174 .suspend = snd_pmac_driver_suspend,
175 .resume = snd_pmac_driver_resume,
176#endif
177 .driver = {
178 .name = SND_PMAC_DRIVER
179 },
180};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182static int __init alsa_card_pmac_init(void)
183{
184 int err;
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100185 struct platform_device *device;
186
187 if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 return err;
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100189 device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
190 if (IS_ERR(device)) {
191 platform_driver_unregister(&snd_pmac_driver);
192 return PTR_ERR(device);
193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return 0;
195
196}
197
198static void __exit alsa_card_pmac_exit(void)
199{
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100200 platform_driver_unregister(&snd_pmac_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
203module_init(alsa_card_pmac_init)
204module_exit(alsa_card_pmac_exit)