2 * Driver for CS4232 on NEC PC9800 series
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 * Osamu Tomita <tomita@cinet.co.jp>
5 * Takashi Iwai <tiwai@suse.de>
6 * Hideaki Okubo <okubo@msh.biglobe.ne.jp>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <sound/driver.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <sound/core.h>
29 #include <sound/cs4231.h>
30 #include <sound/mpu401.h>
31 #include <sound/opl3.h>
33 #include <sound/initval.h>
34 #include "sound_pc9800.h"
36 #define chip_t cs4231_t
38 MODULE_AUTHOR("Osamu Tomita <tomita@cinet.co.jp>");
39 MODULE_LICENSE("GPL");
40 MODULE_CLASSES("{sound}");
41 MODULE_DESCRIPTION("NEC PC9800 CS4232");
42 MODULE_DEVICES("{{NEC,PC9800}}");
44 #define IDENT "PC98-CS4232"
46 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
47 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
48 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
49 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
51 static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
53 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
54 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
55 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
56 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
57 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
58 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
59 static int pc98ii[SNDRV_CARDS]; /* PC98II */
61 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
62 MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
63 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
64 MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
65 MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
66 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
67 MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
68 MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
69 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
70 MODULE_PARM(port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
71 MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
72 MODULE_PARM_SYNTAX(port, SNDRV_PORT12_DESC);
74 MODULE_PARM(cport, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
75 MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
76 MODULE_PARM_SYNTAX(cport, SNDRV_PORT12_DESC);
78 MODULE_PARM(mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
79 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
80 MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT12_DESC);
81 MODULE_PARM(fm_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
82 MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
83 MODULE_PARM_SYNTAX(fm_port, SNDRV_PORT12_DESC);
84 MODULE_PARM(irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
85 MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
86 MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
87 MODULE_PARM(mpu_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
88 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
89 MODULE_PARM_SYNTAX(mpu_irq, SNDRV_IRQ_DESC);
90 MODULE_PARM(dma1, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
91 MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
92 MODULE_PARM_SYNTAX(dma1, SNDRV_DMA_DESC);
93 MODULE_PARM(dma2, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
94 MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
95 MODULE_PARM_SYNTAX(dma2, SNDRV_DMA_DESC);
96 MODULE_PARM(pc98ii, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
97 MODULE_PARM_DESC(pc98ii, "Roland MPU-PC98II support.");
98 MODULE_PARM_SYNTAX(pc98ii, SNDRV_BOOLEAN_FALSE_DESC);
101 static snd_card_t *snd_pc98_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
104 * initialize MPU401-UART
107 static int __init pc98_mpu401_init(int irq)
109 #include "pc9801_118_magic.h"
110 #define outp118(reg,data) outb((reg),0x148e);outb((data),0x148f)
111 #define WAIT118 outb(0x00,0x5f)
113 #ifdef OOKUBO_ORIGINAL
115 #endif /* OOKUBO_ORIGINAL */
131 snd_printk(KERN_ERR IDENT ": Bad IRQ %d\n", irq);
135 outp118(0x21, mpu_intr);
138 if (inb(0x148f) & 0x08) {
139 snd_printk(KERN_INFO IDENT ": No MIDI daughter board found\n");
145 for (count = 0; count < 35000; count ++)
148 for (count = 0; count < 65000; count ++)
149 if (inb(0x148f) == 0x04)
151 snd_printk(KERN_ERR IDENT ": MIDI daughter board initialize failed at stage1\n\n");
159 for (count = 0; count < sizeof(Data0485_99); count ++) {
160 outb(Data0485_99[count], 0x485);
168 for (count = 0; count < sizeof(Data0485_9E); count ++)
169 if (inb(0x485) != Data0485_9E[count]) {
170 #ifdef OOKUBO_ORIGINAL
172 #endif /* OOKUBO_ORIGINAL */
176 for (count = 0; count < 2000; count ++)
178 #ifdef OOKUBO_ORIGINAL
183 for (count = 0; count < sizeof(Data0485_36); count ++)
184 outb(Data0485_36[count], 0x485);
186 for (count = 0; count < 1500; count ++)
188 outp118(0x05, inb(0x148f) | 0x08);
190 outp118(0x05, inb(0x148f) & 0xf7);
191 for (count = 0; count < 1500; count ++)
194 #endif /* OOKUBO_ORIGINAL */
199 for (count = 0; count < sizeof(Data0485_A9); count ++) {
200 outb(Data0485_A9[count], 0x485);
208 for (count = 0; count < sizeof(Data0485_0C); count ++) {
209 outb(Data0485_0C[count], 0x485);
217 for (count = 0; count < sizeof(Data0485_66); count ++) {
218 outb(Data0485_66[count], 0x485);
226 for (count = 0; count < sizeof(Data0485_60); count ++) {
227 outb(Data0485_60[count], 0x485);
234 for (count = 0; count < 35000; count ++)
237 for (count = 0; count < 65000; count ++)
238 if (inb(0x148f) == 0x00)
240 snd_printk(KERN_ERR IDENT ": MIDI daughter board initialize failed at stage2\n");
245 snd_printk(KERN_INFO IDENT ": MIDI daughter board initialized\n");
249 static int __init pc98_cs4231_chip_init(int dev)
251 int intr_bits, intr_bits2, dma_bits;
271 snd_printk(KERN_ERR IDENT ": Bad IRQ %d\n", irq[dev]);
286 snd_printk(KERN_ERR IDENT ": Bad DMA %d\n", dma1[dev]);
290 if (dma2[dev] >= 2) {
291 snd_printk(KERN_ERR IDENT ": Bad DMA %d\n", dma2[dev]);
295 outb(dma1[dev], 0x29); /* dma1 boundary 64KB */
296 if (dma1[dev] != dma2[dev] && dma2[dev] >= 0) {
297 outb(0, 0x5f); /* wait */
298 outb(dma2[dev], 0x29); /* dma2 boundary 64KB */
302 if (PC9800_SOUND_ID() == PC9800_SOUND_ID_118) {
303 /* Set up CanBe control registers. */
304 snd_printd(KERN_INFO "Setting up CanBe Sound System\n");
305 outb(inb(PC9800_SOUND_IO_ID) | 0x03, PC9800_SOUND_IO_ID);
307 outb(intr_bits2, 0x0f4b);
310 outb(intr_bits | dma_bits, 0xf40);
315 static int __init snd_card_pc98_probe(int dev)
318 snd_pcm_t *pcm = NULL;
323 if (port[dev] == SNDRV_AUTO_PORT) {
324 snd_printk(KERN_ERR IDENT ": specify port\n");
327 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
331 if ((err = pc98_cs4231_chip_init(dev)) < 0) {
336 if ((err = snd_cs4231_create(card,
348 if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) {
352 if ((err = snd_cs4231_mixer(chip)) < 0) {
357 if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) {
362 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
364 outb(0x00, fm_port[dev] + 6);
365 inb(fm_port[dev] + 7);
366 /* Enable OPL-3 Function */
367 outb(inb(PC9800_SOUND_IO_ID) | 0x03, PC9800_SOUND_IO_ID);
368 if (snd_opl3_create(card,
369 fm_port[dev], fm_port[dev] + 2,
370 OPL3_HW_OPL3_PC98, 0, &opl3) < 0) {
371 printk(KERN_ERR IDENT ": OPL3 not detected\n");
373 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
380 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
381 err = pc98_mpu401_init(mpu_irq[dev]);
383 err = snd_mpu401_uart_new(card, 0,
384 pc98ii[dev] ? MPU401_HW_PC98II : MPU401_HW_MPU401,
386 mpu_irq[dev], SA_INTERRUPT, NULL);
388 snd_printk(KERN_INFO IDENT ": MPU401 not detected\n");
392 strcpy(card->driver, pcm->name);
393 strcpy(card->shortname, pcm->name);
394 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
400 sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
401 if ((err = snd_card_register(card)) < 0) {
405 snd_pc98_cards[dev] = card;
409 static int __init alsa_card_pc98_init(void)
413 for (dev = 0; dev < SNDRV_CARDS; dev++) {
416 if (snd_card_pc98_probe(dev) >= 0)
421 printk(KERN_ERR IDENT " soundcard not found or device busy\n");
428 static void __exit alsa_card_pc98_exit(void)
432 for (idx = 0; idx < SNDRV_CARDS; idx++)
433 snd_card_free(snd_pc98_cards[idx]);
436 module_init(alsa_card_pc98_init)
437 module_exit(alsa_card_pc98_exit)
441 /* format is: snd-pc98-cs4232=enable,index,id,port,
443 irq,mpu_irq,dma1,dma2,pc98ii */
445 static int __init alsa_card_pc98_setup(char *str)
447 static unsigned __initdata nr_dev = 0;
449 if (nr_dev >= SNDRV_CARDS)
451 (void)(get_option(&str,&enable[nr_dev]) == 2 &&
452 get_option(&str,&index[nr_dev]) == 2 &&
453 get_id(&str,&id[nr_dev]) == 2 &&
454 get_option_long(&str,&port[nr_dev]) == 2 &&
455 get_option_long(&str,&mpu_port[nr_dev]) == 2 &&
456 get_option_long(&str,&fm_port[nr_dev]) == 2 &&
457 get_option(&str,&irq[nr_dev]) == 2 &&
458 get_option(&str,&mpu_irq[nr_dev]) == 2 &&
459 get_option(&str,&dma1[nr_dev]) == 2 &&
460 get_option(&str,&dma2[nr_dev]) == 2 &&
461 get_option(&str,&pc98ii[nr_dev]) == 2);
466 __setup("snd-pc98-cs4232=", alsa_card_pc98_setup);
468 #endif /* ifndef MODULE */