xref: /openbmc/linux/sound/ppc/powermac.c (revision 1da177e4)
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_SUPPORTED_DEVICE("{{Apple,PowerMac}}");
34 MODULE_LICENSE("GPL");
35 
36 static int index = SNDRV_DEFAULT_IDX1;		/* Index 0-MAX */
37 static char *id = SNDRV_DEFAULT_STR1;		/* ID for this card */
38 static int enable_beep = 1;
39 
40 module_param(index, int, 0444);
41 MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
42 module_param(id, charp, 0444);
43 MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
44 module_param(enable_beep, bool, 0444);
45 MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
46 
47 
48 /*
49  * card entry
50  */
51 
52 static snd_card_t *snd_pmac_card = NULL;
53 
54 /*
55  */
56 
57 static int __init snd_pmac_probe(void)
58 {
59 	snd_card_t *card;
60 	pmac_t *chip;
61 	char *name_ext;
62 	int err;
63 
64 	card = snd_card_new(index, id, THIS_MODULE, 0);
65 	if (card == NULL)
66 		return -ENOMEM;
67 
68 	if ((err = snd_pmac_new(card, &chip)) < 0)
69 		goto __error;
70 
71 	switch (chip->model) {
72 	case PMAC_BURGUNDY:
73 		strcpy(card->driver, "PMac Burgundy");
74 		strcpy(card->shortname, "PowerMac Burgundy");
75 		sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
76 			card->shortname, chip->device_id, chip->subframe);
77 		if ((err = snd_pmac_burgundy_init(chip)) < 0)
78 			goto __error;
79 		break;
80 	case PMAC_DACA:
81 		strcpy(card->driver, "PMac DACA");
82 		strcpy(card->shortname, "PowerMac DACA");
83 		sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
84 			card->shortname, chip->device_id, chip->subframe);
85 		if ((err = snd_pmac_daca_init(chip)) < 0)
86 			goto __error;
87 		break;
88 	case PMAC_TUMBLER:
89 	case PMAC_SNAPPER:
90 		name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper";
91 		sprintf(card->driver, "PMac %s", name_ext);
92 		sprintf(card->shortname, "PowerMac %s", name_ext);
93 		sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
94 			card->shortname, chip->device_id, chip->subframe);
95 		if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0)
96 			goto __error;
97 		break;
98 	case PMAC_AWACS:
99 	case PMAC_SCREAMER:
100 		name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
101 		sprintf(card->driver, "PMac %s", name_ext);
102 		sprintf(card->shortname, "PowerMac %s", name_ext);
103 		if (chip->is_pbook_3400)
104 			name_ext = " [PB3400]";
105 		else if (chip->is_pbook_G3)
106 			name_ext = " [PBG3]";
107 		else
108 			name_ext = "";
109 		sprintf(card->longname, "%s%s Rev %d",
110 			card->shortname, name_ext, chip->revision);
111 		if ((err = snd_pmac_awacs_init(chip)) < 0)
112 			goto __error;
113 		break;
114 	default:
115 		snd_printk("unsupported hardware %d\n", chip->model);
116 		err = -EINVAL;
117 		goto __error;
118 	}
119 
120 	if ((err = snd_pmac_pcm_new(chip)) < 0)
121 		goto __error;
122 
123 	chip->initialized = 1;
124 	if (enable_beep)
125 		snd_pmac_attach_beep(chip);
126 
127 	if ((err = snd_card_register(card)) < 0)
128 		goto __error;
129 
130 	snd_pmac_card = card;
131 	return 0;
132 
133 __error:
134 	snd_card_free(card);
135 	return err;
136 }
137 
138 
139 /*
140  * MODULE stuff
141  */
142 
143 static int __init alsa_card_pmac_init(void)
144 {
145 	int err;
146 	if ((err = snd_pmac_probe()) < 0)
147 		return err;
148 	return 0;
149 
150 }
151 
152 static void __exit alsa_card_pmac_exit(void)
153 {
154 	if (snd_pmac_card)
155 		snd_card_free(snd_pmac_card);
156 }
157 
158 module_init(alsa_card_pmac_init)
159 module_exit(alsa_card_pmac_exit)
160