1 | /*
|
---|
2 | * The driver for the Yamaha's DS1/DS1E cards
|
---|
3 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
|
---|
4 | *
|
---|
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 |
|
---|
22 | #define SNDRV_MAIN_OBJECT_FILE
|
---|
23 | #include <sound/driver.h>
|
---|
24 | #include <sound/ymfpci.h>
|
---|
25 | #include <sound/mpu401.h>
|
---|
26 | #include <sound/opl3.h>
|
---|
27 | #define SNDRV_GET_ID
|
---|
28 | #include <sound/initval.h>
|
---|
29 |
|
---|
30 | EXPORT_NO_SYMBOLS;
|
---|
31 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
|
---|
32 | MODULE_DESCRIPTION("Yamaha DS-XG PCI");
|
---|
33 | MODULE_LICENSE("GPL");
|
---|
34 | MODULE_CLASSES("{sound}");
|
---|
35 | MODULE_DEVICES("{{Yamaha,YMF724},"
|
---|
36 | "{Yamaha,YMF724F},"
|
---|
37 | "{Yamaha,YMF740},"
|
---|
38 | "{Yamaha,YMF740C},"
|
---|
39 | "{Yamaha,YMF744},"
|
---|
40 | "{Yamaha,YMF754}}");
|
---|
41 |
|
---|
42 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
---|
43 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
---|
44 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
|
---|
45 | #ifdef TARGET_OS2
|
---|
46 | static long fm_port[SNDRV_CARDS] = {REPEAT_SNDRV(-1)};
|
---|
47 | static long mpu_port[SNDRV_CARDS] = {REPEAT_SNDRV(-1)};
|
---|
48 | #else
|
---|
49 | static long fm_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
|
---|
50 | static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
|
---|
51 | #endif
|
---|
52 | static int rear_switch[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
|
---|
53 |
|
---|
54 | MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
55 | MODULE_PARM_DESC(index, "Index value for the Yamaha DS-XG PCI soundcard.");
|
---|
56 | MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
|
---|
57 | MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
|
---|
58 | MODULE_PARM_DESC(id, "ID string for the Yamaha DS-XG PCI soundcard.");
|
---|
59 | MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
|
---|
60 | MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
61 | MODULE_PARM_DESC(enable, "Enable Yamaha DS-XG soundcard.");
|
---|
62 | MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
|
---|
63 | MODULE_PARM(mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
|
---|
64 | MODULE_PARM_DESC(mpu_port, "MPU-401 Port.");
|
---|
65 | MODULE_PARM_SYNTAX(mpu_port, SNDRV_ENABLED);
|
---|
66 | MODULE_PARM(fm_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
|
---|
67 | MODULE_PARM_DESC(fm_port, "FM OPL-3 Port.");
|
---|
68 | MODULE_PARM_SYNTAX(fm_port, SNDRV_ENABLED);
|
---|
69 | MODULE_PARM(rear_switch, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
70 | MODULE_PARM_DESC(rear_switch, "Enable shared rear/line-in switch");
|
---|
71 | MODULE_PARM_SYNTAX(rear_switch, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
|
---|
72 |
|
---|
73 | static struct pci_device_id snd_ymfpci_ids[] = {
|
---|
74 | { 0x1073, 0x0004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF724 */
|
---|
75 | { 0x1073, 0x000d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF724F */
|
---|
76 | { 0x1073, 0x000a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF740 */
|
---|
77 | { 0x1073, 0x000c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF740C */
|
---|
78 | { 0x1073, 0x0010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF744 */
|
---|
79 | { 0x1073, 0x0012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF754 */
|
---|
80 | { 0, }
|
---|
81 | };
|
---|
82 |
|
---|
83 | MODULE_DEVICE_TABLE(pci, snd_ymfpci_ids);
|
---|
84 |
|
---|
85 | static int __devinit snd_card_ymfpci_probe(struct pci_dev *pci,
|
---|
86 | const struct pci_device_id *pci_id)
|
---|
87 | {
|
---|
88 | static int dev;
|
---|
89 | snd_card_t *card;
|
---|
90 | struct resource *fm_res = NULL;
|
---|
91 | struct resource *mpu_res = NULL;
|
---|
92 | ymfpci_t *chip;
|
---|
93 | opl3_t *opl3;
|
---|
94 | char *str;
|
---|
95 | int err;
|
---|
96 | u16 legacy_ctrl, legacy_ctrl2, old_legacy_ctrl;
|
---|
97 |
|
---|
98 | if (dev >= SNDRV_CARDS)
|
---|
99 | return -ENODEV;
|
---|
100 | if (!enable[dev]) {
|
---|
101 | dev++;
|
---|
102 | return -ENOENT;
|
---|
103 | }
|
---|
104 |
|
---|
105 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
|
---|
106 | if (card == NULL)
|
---|
107 | return -ENOMEM;
|
---|
108 |
|
---|
109 | switch (pci_id->device) {
|
---|
110 | case 0x0004: str = "YMF724"; break;
|
---|
111 | case 0x000d: str = "YMF724F"; break;
|
---|
112 | case 0x000a: str = "YMF740"; break;
|
---|
113 | case 0x000c: str = "YMF740C"; break;
|
---|
114 | case 0x0010: str = "YMF744"; break;
|
---|
115 | case 0x0012: str = "YMF754"; break;
|
---|
116 | default: str = "???"; break;
|
---|
117 | }
|
---|
118 | legacy_ctrl = 0;
|
---|
119 | legacy_ctrl2 = 0x0800; /* SBEN = 0, SMOD = 01, LAD = 0 */
|
---|
120 |
|
---|
121 | #if 1
|
---|
122 |
|
---|
123 | if (pci_id->device >= 0x0010) { /* YMF 744/754 */
|
---|
124 | if (fm_port[dev] < 0) {
|
---|
125 | fm_port[dev] = pci_resource_start(pci, 1);
|
---|
126 | }
|
---|
127 | if (fm_port[dev] >= 0 &&
|
---|
128 | (fm_res = request_region(fm_port[dev], 4, "YMFPCI OPL3")) != NULL) {
|
---|
129 | legacy_ctrl |= YMFPCI_LEGACY_FMEN;
|
---|
130 | pci_write_config_word(pci, PCIR_DSXG_FMBASE, fm_port[dev]);
|
---|
131 | }
|
---|
132 | if (mpu_port[dev] < 0) {
|
---|
133 | mpu_port[dev] = pci_resource_start(pci, 1) + 0x20;
|
---|
134 | }
|
---|
135 | if (mpu_port[dev] >= 0 &&
|
---|
136 | (mpu_res = request_region(mpu_port[dev], 2, "YMFPCI MPU401")) != NULL) {
|
---|
137 | legacy_ctrl |= YMFPCI_LEGACY_MEN;
|
---|
138 | pci_write_config_word(pci, PCIR_DSXG_MPU401BASE, mpu_port[dev]);
|
---|
139 | }
|
---|
140 | } else {
|
---|
141 | switch (fm_port[dev]) {
|
---|
142 | case 0x388: legacy_ctrl2 |= 0; break;
|
---|
143 | case 0x398: legacy_ctrl2 |= 1; break;
|
---|
144 | case 0x3a0: legacy_ctrl2 |= 2; break;
|
---|
145 | case 0x3a8: legacy_ctrl2 |= 3; break;
|
---|
146 | default: fm_port[dev] = -1; break;
|
---|
147 | }
|
---|
148 | if (fm_port[dev] > 0 &&
|
---|
149 | (fm_res = request_region(fm_port[dev], 4, "YMFPCI OPL3")) != NULL) {
|
---|
150 | legacy_ctrl |= YMFPCI_LEGACY_FMEN;
|
---|
151 | } else {
|
---|
152 | legacy_ctrl2 &= ~YMFPCI_LEGACY2_FMIO;
|
---|
153 | fm_port[dev] = -1;
|
---|
154 | }
|
---|
155 | switch (mpu_port[dev]) {
|
---|
156 | case 0x330: legacy_ctrl2 |= 0 << 4; break;
|
---|
157 | case 0x300: legacy_ctrl2 |= 1 << 4; break;
|
---|
158 | case 0x332: legacy_ctrl2 |= 2 << 4; break;
|
---|
159 | case 0x334: legacy_ctrl2 |= 3 << 4; break;
|
---|
160 | default: mpu_port[dev] = -1; break;
|
---|
161 | }
|
---|
162 | if (mpu_port[dev] > 0 &&
|
---|
163 | (mpu_res = request_region(mpu_port[dev], 2, "YMFPCI MPU401")) != NULL) {
|
---|
164 | legacy_ctrl |= YMFPCI_LEGACY_MEN;
|
---|
165 | } else {
|
---|
166 | legacy_ctrl2 &= ~YMFPCI_LEGACY2_MPUIO;
|
---|
167 | mpu_port[dev] = -1;
|
---|
168 | }
|
---|
169 | }
|
---|
170 | if (mpu_res) {
|
---|
171 | legacy_ctrl |= YMFPCI_LEGACY_MIEN;
|
---|
172 | legacy_ctrl2 |= YMFPCI_LEGACY2_IMOD;
|
---|
173 | }
|
---|
174 | #endif
|
---|
175 | pci_read_config_word(pci, PCIR_DSXG_LEGACY, &old_legacy_ctrl);
|
---|
176 | pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
|
---|
177 | pci_write_config_word(pci, PCIR_DSXG_ELEGACY, legacy_ctrl2);
|
---|
178 | if ((err = snd_ymfpci_create(card, pci,
|
---|
179 | old_legacy_ctrl,
|
---|
180 | &chip)) < 0) {
|
---|
181 | snd_card_free(card);
|
---|
182 | if (mpu_res) {
|
---|
183 | release_resource(mpu_res);
|
---|
184 | kfree_nocheck(mpu_res);
|
---|
185 | }
|
---|
186 | if (fm_res) {
|
---|
187 | release_resource(fm_res);
|
---|
188 | kfree_nocheck(fm_res);
|
---|
189 | }
|
---|
190 | return err;
|
---|
191 | }
|
---|
192 | chip->fm_res = fm_res;
|
---|
193 | chip->mpu_res = mpu_res;
|
---|
194 | strcpy(card->driver, str);
|
---|
195 | sprintf(card->shortname, "Yamaha DS-XG (%s)", str);
|
---|
196 | sprintf(card->longname, "%s at 0x%lx, irq %i",
|
---|
197 | card->shortname,
|
---|
198 | chip->reg_area_phys,
|
---|
199 | chip->irq);
|
---|
200 | if ((err = snd_ymfpci_pcm(chip, 0, NULL)) < 0) {
|
---|
201 | snd_card_free(card);
|
---|
202 | return err;
|
---|
203 | }
|
---|
204 | if ((err = snd_ymfpci_pcm_spdif(chip, 1, NULL)) < 0) {
|
---|
205 | snd_card_free(card);
|
---|
206 | return err;
|
---|
207 | }
|
---|
208 | if ((err = snd_ymfpci_pcm_4ch(chip, 2, NULL)) < 0) {
|
---|
209 | snd_card_free(card);
|
---|
210 | return err;
|
---|
211 | }
|
---|
212 | if ((err = snd_ymfpci_pcm2(chip, 3, NULL)) < 0) {
|
---|
213 | snd_card_free(card);
|
---|
214 | return err;
|
---|
215 | }
|
---|
216 | if ((err = snd_ymfpci_mixer(chip, rear_switch[dev])) < 0) {
|
---|
217 | snd_card_free(card);
|
---|
218 | return err;
|
---|
219 | }
|
---|
220 | if ((err = snd_ymfpci_timer(chip, 0)) < 0) {
|
---|
221 | snd_card_free(card);
|
---|
222 | return err;
|
---|
223 | }
|
---|
224 | #if 1
|
---|
225 | if (chip->mpu_res) {
|
---|
226 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI,
|
---|
227 | mpu_port[dev], 1,
|
---|
228 | pci->irq, 0, &chip->rawmidi)) < 0) {
|
---|
229 | printk(KERN_WARNING "ymfpci: cannot initialize MPU401 at 0x%lx, skipping...\n", mpu_port[dev]);
|
---|
230 | legacy_ctrl &= ~YMFPCI_LEGACY_MIEN; /* disable MPU401 irq */
|
---|
231 | pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
|
---|
232 | }
|
---|
233 | }
|
---|
234 | if (chip->fm_res) {
|
---|
235 | if ((err = snd_opl3_create(card,
|
---|
236 | fm_port[dev],
|
---|
237 | fm_port[dev] + 2,
|
---|
238 | OPL3_HW_OPL3, 1, &opl3)) < 0) {
|
---|
239 | printk(KERN_WARNING "ymfpci: cannot initialize FM OPL3 at 0x%lx, skipping...\n", fm_port[dev]);
|
---|
240 | legacy_ctrl &= ~YMFPCI_LEGACY_FMEN;
|
---|
241 | pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
|
---|
242 | } else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
|
---|
243 | snd_card_free(card);
|
---|
244 | snd_printk("cannot create opl3 hwdep\n");
|
---|
245 | return err;
|
---|
246 | }
|
---|
247 | }
|
---|
248 | #endif
|
---|
249 | #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
|
---|
250 | if ((err = snd_ymfpci_joystick(chip)) < 0) {
|
---|
251 | printk(KERN_WARNING "ymfpci: cannot initialize joystick, skipping...\n");
|
---|
252 | }
|
---|
253 | #endif
|
---|
254 |
|
---|
255 | if ((err = snd_card_register(card)) < 0) {
|
---|
256 | snd_card_free(card);
|
---|
257 | return err;
|
---|
258 | }
|
---|
259 | pci_set_drvdata(pci, card);
|
---|
260 | dev++;
|
---|
261 | return 0;
|
---|
262 | }
|
---|
263 |
|
---|
264 |
|
---|
265 | static void __devexit snd_card_ymfpci_remove(struct pci_dev *pci)
|
---|
266 | {
|
---|
267 | snd_card_free(pci_get_drvdata(pci));
|
---|
268 | pci_set_drvdata(pci, NULL);
|
---|
269 | }
|
---|
270 |
|
---|
271 | static struct pci_driver driver = {
|
---|
272 | 0,0,0,"Yamaha DS-XG PCI",
|
---|
273 | snd_ymfpci_ids,
|
---|
274 | snd_card_ymfpci_probe,
|
---|
275 | snd_card_ymfpci_remove,
|
---|
276 | SND_PCI_PM_CALLBACKS
|
---|
277 | };
|
---|
278 |
|
---|
279 | static int __init alsa_card_ymfpci_init(void)
|
---|
280 | {
|
---|
281 | int err;
|
---|
282 |
|
---|
283 | if ((err = pci_module_init(&driver)) < 0) {
|
---|
284 | #ifdef MODULE
|
---|
285 | // snd_printk("Yamaha DS-XG PCI soundcard not found or device busy\n");
|
---|
286 | #endif
|
---|
287 | return err;
|
---|
288 | }
|
---|
289 | return 0;
|
---|
290 | }
|
---|
291 |
|
---|
292 | static void __exit alsa_card_ymfpci_exit(void)
|
---|
293 | {
|
---|
294 | pci_unregister_driver(&driver);
|
---|
295 | }
|
---|
296 |
|
---|
297 | module_init(alsa_card_ymfpci_init)
|
---|
298 | module_exit(alsa_card_ymfpci_exit)
|
---|
299 |
|
---|
300 | #ifndef MODULE
|
---|
301 |
|
---|
302 | /* format is: snd-card-ymfpci=snd_enable,snd_index,snd_id,
|
---|
303 | snd_fm_port,snd_mpu_port,snd_mpu_irq */
|
---|
304 |
|
---|
305 | static int __init alsa_card_ymfpci_setup(char *str)
|
---|
306 | {
|
---|
307 | static unsigned __initdata nr_dev = 0;
|
---|
308 |
|
---|
309 | if (nr_dev >= SNDRV_CARDS)
|
---|
310 | return 0;
|
---|
311 | (void)(get_option(&str,&enable[nr_dev]) == 2 &&
|
---|
312 | get_option(&str,&index[nr_dev]) == 2 &&
|
---|
313 | get_id(&str,&id[nr_dev]) == 2 &&
|
---|
314 | get_option(&str,(int *)&fm_port[nr_dev]) == 2 &&
|
---|
315 | get_option(&str,(int *)&mpu_port[nr_dev]) == 2);
|
---|
316 | nr_dev++;
|
---|
317 | return 1;
|
---|
318 | }
|
---|
319 |
|
---|
320 | __setup("snd-ymfpci=", alsa_card_ymfpci_setup);
|
---|
321 |
|
---|
322 | #endif /* ifndef MODULE */
|
---|