[ALSA] powermac - Use platform_device
[safe/jmp/linux-2.6] / sound / ppc / powermac.c
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
21 #include <sound/driver.h>
22 #include <linux/init.h>
23 #include <linux/err.h>
24 #include <linux/platform_device.h>
25 #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
34 MODULE_DESCRIPTION("PowerMac");
35 MODULE_SUPPORTED_DEVICE("{{Apple,PowerMac}}");
36 MODULE_LICENSE("GPL");
37
38 static int index = SNDRV_DEFAULT_IDX1;          /* Index 0-MAX */
39 static char *id = SNDRV_DEFAULT_STR1;           /* ID for this card */
40 static int enable_beep = 1;
41
42 module_param(index, int, 0444);
43 MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
44 module_param(id, charp, 0444);
45 MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
46 module_param(enable_beep, bool, 0444);
47 MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
48
49
50 /*
51  */
52
53 static int __init snd_pmac_probe(struct platform_device *devptr)
54 {
55         struct snd_card *card;
56         struct snd_pmac *chip;
57         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;
66         card->private_data = chip;
67
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;
95         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;
102         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
131         snd_card_set_dev(card, &devptr->dev);
132
133         if ((err = snd_card_register(card)) < 0)
134                 goto __error;
135
136         platform_set_drvdata(devptr, card);
137         return 0;
138
139 __error:
140         snd_card_free(card);
141         return err;
142 }
143
144
145 static 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
153 static 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
160 static 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
170 static 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 };
181
182 static int __init alsa_card_pmac_init(void)
183 {
184         int err;
185         struct platform_device *device;
186
187         if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
188                 return err;
189         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         }
194         return 0;
195
196 }
197
198 static void __exit alsa_card_pmac_exit(void)
199 {
200         platform_driver_unregister(&snd_pmac_driver);
201 }
202
203 module_init(alsa_card_pmac_init)
204 module_exit(alsa_card_pmac_exit)