blob: f4902a219e505176ce82e8f70dd28b2fff549dd5 [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
Clemens Ladischf7a92752005-12-07 09:13:42 +010049static struct platform_device *device;
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 */
54
Takashi Iwai5e12bea2005-11-17 17:17:08 +010055static int __init snd_pmac_probe(struct platform_device *devptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
Takashi Iwai65b29f52005-11-17 15:09:46 +010057 struct snd_card *card;
58 struct snd_pmac *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 char *name_ext;
60 int err;
61
62 card = snd_card_new(index, id, THIS_MODULE, 0);
63 if (card == NULL)
64 return -ENOMEM;
65
66 if ((err = snd_pmac_new(card, &chip)) < 0)
67 goto __error;
Takashi Iwai5e12bea2005-11-17 17:17:08 +010068 card->private_data = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 switch (chip->model) {
71 case PMAC_BURGUNDY:
72 strcpy(card->driver, "PMac Burgundy");
73 strcpy(card->shortname, "PowerMac Burgundy");
74 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
75 card->shortname, chip->device_id, chip->subframe);
76 if ((err = snd_pmac_burgundy_init(chip)) < 0)
77 goto __error;
78 break;
79 case PMAC_DACA:
80 strcpy(card->driver, "PMac DACA");
81 strcpy(card->shortname, "PowerMac DACA");
82 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
83 card->shortname, chip->device_id, chip->subframe);
84 if ((err = snd_pmac_daca_init(chip)) < 0)
85 goto __error;
86 break;
87 case PMAC_TUMBLER:
88 case PMAC_SNAPPER:
89 name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper";
90 sprintf(card->driver, "PMac %s", name_ext);
91 sprintf(card->shortname, "PowerMac %s", name_ext);
92 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
93 card->shortname, chip->device_id, chip->subframe);
94 if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0)
95 goto __error;
96 break;
Benjamin Herrenschmidt1f7b49d2005-05-01 08:58:43 -070097 case PMAC_TOONIE:
98 strcpy(card->driver, "PMac Toonie");
99 strcpy(card->shortname, "PowerMac Toonie");
100 strcpy(card->longname, card->shortname);
101 if ((err = snd_pmac_toonie_init(chip)) < 0)
102 goto __error;
103 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 case PMAC_AWACS:
105 case PMAC_SCREAMER:
106 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
107 sprintf(card->driver, "PMac %s", name_ext);
108 sprintf(card->shortname, "PowerMac %s", name_ext);
109 if (chip->is_pbook_3400)
110 name_ext = " [PB3400]";
111 else if (chip->is_pbook_G3)
112 name_ext = " [PBG3]";
113 else
114 name_ext = "";
115 sprintf(card->longname, "%s%s Rev %d",
116 card->shortname, name_ext, chip->revision);
117 if ((err = snd_pmac_awacs_init(chip)) < 0)
118 goto __error;
119 break;
120 default:
121 snd_printk("unsupported hardware %d\n", chip->model);
122 err = -EINVAL;
123 goto __error;
124 }
125
126 if ((err = snd_pmac_pcm_new(chip)) < 0)
127 goto __error;
128
129 chip->initialized = 1;
130 if (enable_beep)
131 snd_pmac_attach_beep(chip);
132
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100133 snd_card_set_dev(card, &devptr->dev);
Takashi Iwai16dab542005-09-05 17:17:58 +0200134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 if ((err = snd_card_register(card)) < 0)
136 goto __error;
137
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100138 platform_set_drvdata(devptr, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 return 0;
140
141__error:
142 snd_card_free(card);
143 return err;
144}
145
146
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100147static int __devexit snd_pmac_remove(struct platform_device *devptr)
148{
149 snd_card_free(platform_get_drvdata(devptr));
150 platform_set_drvdata(devptr, NULL);
151 return 0;
152}
153
154#ifdef CONFIG_PM
155static int snd_pmac_driver_suspend(struct platform_device *devptr, pm_message_t state)
156{
157 struct snd_card *card = platform_get_drvdata(devptr);
158 snd_pmac_suspend(card->private_data);
159 return 0;
160}
161
162static int snd_pmac_driver_resume(struct platform_device *devptr)
163{
164 struct snd_card *card = platform_get_drvdata(devptr);
165 snd_pmac_resume(card->private_data);
166 return 0;
167}
168#endif
169
170#define SND_PMAC_DRIVER "snd_powermac"
171
172static struct platform_driver snd_pmac_driver = {
173 .probe = snd_pmac_probe,
174 .remove = __devexit_p(snd_pmac_remove),
175#ifdef CONFIG_PM
176 .suspend = snd_pmac_driver_suspend,
177 .resume = snd_pmac_driver_resume,
178#endif
179 .driver = {
180 .name = SND_PMAC_DRIVER
181 },
182};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184static int __init alsa_card_pmac_init(void)
185{
186 int err;
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100187
188 if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 return err;
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100190 device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
191 if (IS_ERR(device)) {
192 platform_driver_unregister(&snd_pmac_driver);
193 return PTR_ERR(device);
194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 return 0;
196
197}
198
199static void __exit alsa_card_pmac_exit(void)
200{
Clemens Ladischf7a92752005-12-07 09:13:42 +0100201 platform_device_unregister(device);
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100202 platform_driver_unregister(&snd_pmac_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203}
204
205module_init(alsa_card_pmac_init)
206module_exit(alsa_card_pmac_exit)