x86: kmalloc + memset conversion to kzalloc
[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 static struct platform_device *device;
50
51
52 /*
53  */
54
55 static int __init snd_pmac_probe(struct platform_device *devptr)
56 {
57         struct snd_card *card;
58         struct snd_pmac *chip;
59         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;
68         card->private_data = chip;
69
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;
97         case PMAC_AWACS:
98         case PMAC_SCREAMER:
99                 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
100                 sprintf(card->driver, "PMac %s", name_ext);
101                 sprintf(card->shortname, "PowerMac %s", name_ext);
102                 if (chip->is_pbook_3400)
103                         name_ext = " [PB3400]";
104                 else if (chip->is_pbook_G3)
105                         name_ext = " [PBG3]";
106                 else
107                         name_ext = "";
108                 sprintf(card->longname, "%s%s Rev %d",
109                         card->shortname, name_ext, chip->revision);
110                 if ((err = snd_pmac_awacs_init(chip)) < 0)
111                         goto __error;
112                 break;
113         default:
114                 snd_printk("unsupported hardware %d\n", chip->model);
115                 err = -EINVAL;
116                 goto __error;
117         }
118
119         if ((err = snd_pmac_pcm_new(chip)) < 0)
120                 goto __error;
121
122         chip->initialized = 1;
123         if (enable_beep)
124                 snd_pmac_attach_beep(chip);
125
126         snd_card_set_dev(card, &devptr->dev);
127
128         if ((err = snd_card_register(card)) < 0)
129                 goto __error;
130
131         platform_set_drvdata(devptr, card);
132         return 0;
133
134 __error:
135         snd_card_free(card);
136         return err;
137 }
138
139
140 static int __devexit snd_pmac_remove(struct platform_device *devptr)
141 {
142         snd_card_free(platform_get_drvdata(devptr));
143         platform_set_drvdata(devptr, NULL);
144         return 0;
145 }
146
147 #ifdef CONFIG_PM
148 static int snd_pmac_driver_suspend(struct platform_device *devptr, pm_message_t state)
149 {
150         struct snd_card *card = platform_get_drvdata(devptr);
151         snd_pmac_suspend(card->private_data);
152         return 0;
153 }
154
155 static int snd_pmac_driver_resume(struct platform_device *devptr)
156 {
157         struct snd_card *card = platform_get_drvdata(devptr);
158         snd_pmac_resume(card->private_data);
159         return 0;
160 }
161 #endif
162
163 #define SND_PMAC_DRIVER         "snd_powermac"
164
165 static struct platform_driver snd_pmac_driver = {
166         .probe          = snd_pmac_probe,
167         .remove         = __devexit_p(snd_pmac_remove),
168 #ifdef CONFIG_PM
169         .suspend        = snd_pmac_driver_suspend,
170         .resume         = snd_pmac_driver_resume,
171 #endif
172         .driver         = {
173                 .name   = SND_PMAC_DRIVER
174         },
175 };
176
177 static int __init alsa_card_pmac_init(void)
178 {
179         int err;
180
181         if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
182                 return err;
183         device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
184         return 0;
185
186 }
187
188 static void __exit alsa_card_pmac_exit(void)
189 {
190         if (!IS_ERR(device))
191                 platform_device_unregister(device);
192         platform_driver_unregister(&snd_pmac_driver);
193 }
194
195 module_init(alsa_card_pmac_init)
196 module_exit(alsa_card_pmac_exit)