patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / 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/moduleparam.h>
24 #include <sound/core.h>
25 #include <sound/initval.h>
26 #include "pmac.h"
27 #include "awacs.h"
28 #include "burgundy.h"
29
30 #define CHIP_NAME "PMac"
31
32 MODULE_DESCRIPTION("PowerMac");
33 MODULE_CLASSES("{sound}");
34 MODULE_DEVICES("{{Apple,PowerMac}}");
35 MODULE_LICENSE("GPL");
36
37 static int index = SNDRV_DEFAULT_IDX1;          /* Index 0-MAX */
38 static char *id = SNDRV_DEFAULT_STR1;           /* ID for this card */
39 /* static int enable = 1; */
40 #ifdef PMAC_SUPPORT_PCM_BEEP
41 static int enable_beep = 1;
42 #endif
43
44 module_param(index, int, 0444);
45 MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
46 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
47 module_param(id, charp, 0444);
48 MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
49 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
50 /* module_param(enable, bool, 0444);
51    MODULE_PARM_DESC(enable, "Enable this soundchip.");
52    MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); */
53 #ifdef PMAC_SUPPORT_PCM_BEEP
54 module_param(enable_beep, bool, 0444);
55 MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
56 MODULE_PARM_SYNTAX(enable_beep, SNDRV_ENABLED "," SNDRV_BOOLEAN_TRUE_DESC);
57 #endif
58
59
60 /*
61  * card entry
62  */
63
64 static snd_card_t *snd_pmac_card = NULL;
65
66 /*
67  */
68
69 static int __init snd_pmac_probe(void)
70 {
71         snd_card_t *card;
72         pmac_t *chip;
73         char *name_ext;
74         int err;
75
76         card = snd_card_new(index, id, THIS_MODULE, 0);
77         if (card == NULL)
78                 return -ENOMEM;
79
80         if ((err = snd_pmac_new(card, &chip)) < 0)
81                 goto __error;
82
83         switch (chip->model) {
84         case PMAC_BURGUNDY:
85                 strcpy(card->driver, "PMac Burgundy");
86                 strcpy(card->shortname, "PowerMac Burgundy");
87                 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
88                         card->shortname, chip->device_id, chip->subframe);
89                 if ((err = snd_pmac_burgundy_init(chip)) < 0)
90                         goto __error;
91                 break;
92         case PMAC_DACA:
93                 strcpy(card->driver, "PMac DACA");
94                 strcpy(card->shortname, "PowerMac DACA");
95                 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
96                         card->shortname, chip->device_id, chip->subframe);
97                 if ((err = snd_pmac_daca_init(chip)) < 0)
98                         goto __error;
99                 break;
100         case PMAC_TUMBLER:
101         case PMAC_SNAPPER:
102                 name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper";
103                 sprintf(card->driver, "PMac %s", name_ext);
104                 sprintf(card->shortname, "PowerMac %s", name_ext);
105                 sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
106                         card->shortname, chip->device_id, chip->subframe);
107                 if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0)
108                         goto __error;
109                 break;
110         case PMAC_AWACS:
111         case PMAC_SCREAMER:
112                 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
113                 sprintf(card->driver, "PMac %s", name_ext);
114                 sprintf(card->shortname, "PowerMac %s", name_ext);
115                 if (chip->is_pbook_3400)
116                         name_ext = " [PB3400]";
117                 else if (chip->is_pbook_G3)
118                         name_ext = " [PBG3]";
119                 else
120                         name_ext = "";
121                 sprintf(card->longname, "%s%s Rev %d",
122                         card->shortname, name_ext, chip->revision);
123                 if ((err = snd_pmac_awacs_init(chip)) < 0)
124                         goto __error;
125                 break;
126         default:
127                 snd_printk("unsupported hardware %d\n", chip->model);
128                 err = -EINVAL;
129                 goto __error;
130         }
131
132         if ((err = snd_pmac_pcm_new(chip)) < 0)
133                 goto __error;
134
135         chip->initialized = 1;
136 #ifdef PMAC_SUPPORT_PCM_BEEP
137         if (enable_beep)
138                 snd_pmac_attach_beep(chip);
139 #endif
140
141         if ((err = snd_card_register(card)) < 0)
142                 goto __error;
143
144         snd_pmac_card = card;
145         return 0;
146
147 __error:
148         snd_card_free(card);
149         return err;
150 }
151
152
153 /*
154  * MODULE sutff
155  */
156
157 static int __init alsa_card_pmac_init(void)
158 {
159         int err;
160         if ((err = snd_pmac_probe()) < 0) {
161 #ifdef MODULE
162                 printk(KERN_ERR "no PMac soundchip found\n");
163 #endif
164                 return err;
165         }
166         return 0;
167
168 }
169
170 static void __exit alsa_card_pmac_exit(void)
171 {
172         if (snd_pmac_card)
173                 snd_card_free(snd_pmac_card);
174 }
175
176 module_init(alsa_card_pmac_init)
177 module_exit(alsa_card_pmac_exit)