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 <linux/moduleparam.h>
29 #include <sound/core.h>
30 #include <sound/cs4231.h>
31 #include <sound/mpu401.h>
32 #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 */
62 module_param_array(index, int, boot_devs, 0444);
63 MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
64 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
65 module_param_array(id, charp, boot_devs, 0444);
66 MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
67 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
68 module_param_array(enable, bool, boot_devs, 0444);
69 MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
70 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
71 module_param_array(port, long, boot_devs, 0444);
72 MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
73 MODULE_PARM_SYNTAX(port, SNDRV_PORT12_DESC);
75 module_param_array(cport, long, boot_devs, 0444);
76 MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
77 MODULE_PARM_SYNTAX(cport, SNDRV_PORT12_DESC);
79 module_param_array(mpu_port, long, boot_devs, 0444);
80 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
81 MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT12_DESC);
82 module_param_array(fm_port, long, boot_devs, 0444);
83 MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
84 MODULE_PARM_SYNTAX(fm_port, SNDRV_PORT12_DESC);
85 module_param_array(irq, int, boot_devs, 0444);
86 MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
87 MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
88 module_param_array(mpu_irq, int, boot_devs, 0444);
89 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
90 MODULE_PARM_SYNTAX(mpu_irq, SNDRV_IRQ_DESC);
91 module_param_array(dma1, int, boot_devs, 0444);
92 MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
93 MODULE_PARM_SYNTAX(dma1, SNDRV_DMA_DESC);
94 module_param_array(dma2, int, boot_devs, 0444);
95 MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
96 MODULE_PARM_SYNTAX(dma2, SNDRV_DMA_DESC);
97 module_param_array(pc98ii, bool, boot_devs, 0444);
98 MODULE_PARM_DESC(pc98ii, "Roland MPU-PC98II support.");
99 MODULE_PARM_SYNTAX(pc98ii, SNDRV_BOOLEAN_FALSE_DESC);
102 static snd_card_t *snd_pc98_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
105 * initialize MPU401-UART
108 static int __init pc98_mpu401_init(int irq)
110 #include "pc9801_118_magic.h"
111 #define outp118(reg,data) outb((reg),0x148e);outb((data),0x148f)
112 #define WAIT118 outb(0x00,0x5f)
114 #ifdef OOKUBO_ORIGINAL
116 #endif /* OOKUBO_ORIGINAL */
132 snd_printk(KERN_ERR IDENT ": Bad IRQ %d\n", irq);
136 outp118(0x21, mpu_intr);
139 if (inb(0x148f) & 0x08) {
140 snd_printk(KERN_INFO IDENT ": No MIDI daughter board found\n");
146 for (count = 0; count < 35000; count ++)
149 for (count = 0; count < 65000; count ++)
150 if (inb(0x148f) == 0x04)
152 snd_printk(KERN_ERR IDENT ": MIDI daughter board initialize failed at stage1\n\n");
160 for (count = 0; count < sizeof(Data0485_99); count ++) {
161 outb(Data0485_99[count], 0x485);
169 for (count = 0; count < sizeof(Data0485_9E); count ++)
170 if (inb(0x485) != Data0485_9E[count]) {
171 #ifdef OOKUBO_ORIGINAL
173 #endif /* OOKUBO_ORIGINAL */
177 for (count = 0; count < 2000; count ++)
179 #ifdef OOKUBO_ORIGINAL
184 for (count = 0; count < sizeof(Data0485_36); count ++)
185 outb(Data0485_36[count], 0x485);
187 for (count = 0; count < 1500; count ++)
189 outp118(0x05, inb(0x148f) | 0x08);
191 outp118(0x05, inb(0x148f) & 0xf7);
192 for (count = 0; count < 1500; count ++)
195 #endif /* OOKUBO_ORIGINAL */
200 for (count = 0; count < sizeof(Data0485_A9); count ++) {
201 outb(Data0485_A9[count], 0x485);
209 for (count = 0; count < sizeof(Data0485_0C); count ++) {
210 outb(Data0485_0C[count], 0x485);
218 for (count = 0; count < sizeof(Data0485_66); count ++) {
219 outb(Data0485_66[count], 0x485);
227 for (count = 0; count < sizeof(Data0485_60); count ++) {
228 outb(Data0485_60[count], 0x485);
235 for (count = 0; count < 35000; count ++)
238 for (count = 0; count < 65000; count ++)
239 if (inb(0x148f) == 0x00)
241 snd_printk(KERN_ERR IDENT ": MIDI daughter board initialize failed at stage2\n");
246 snd_printk(KERN_INFO IDENT ": MIDI daughter board initialized\n");
250 static int __init pc98_cs4231_chip_init(int dev)
252 int intr_bits, intr_bits2, dma_bits;
272 snd_printk(KERN_ERR IDENT ": Bad IRQ %d\n", irq[dev]);
287 snd_printk(KERN_ERR IDENT ": Bad DMA %d\n", dma1[dev]);
291 if (dma2[dev] >= 2) {
292 snd_printk(KERN_ERR IDENT ": Bad DMA %d\n", dma2[dev]);
296 outb(dma1[dev], 0x29); /* dma1 boundary 64KB */
297 if (dma1[dev] != dma2[dev] && dma2[dev] >= 0) {
298 outb(0, 0x5f); /* wait */
299 outb(dma2[dev], 0x29); /* dma2 boundary 64KB */
303 if (PC9800_SOUND_ID() == PC9800_SOUND_ID_118) {
304 /* Set up CanBe control registers. */
305 snd_printd(KERN_INFO "Setting up CanBe Sound System\n");
306 outb(inb(PC9800_SOUND_IO_ID) | 0x03, PC9800_SOUND_IO_ID);
308 outb(intr_bits2, 0x0f4b);
311 outb(intr_bits | dma_bits, 0xf40);
316 static int __init snd_card_pc98_probe(int dev)
319 snd_pcm_t *pcm = NULL;
324 if (port[dev] == SNDRV_AUTO_PORT) {
325 snd_printk(KERN_ERR IDENT ": specify port\n");
328 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
332 if ((err = pc98_cs4231_chip_init(dev)) < 0) {
337 if ((err = snd_cs4231_create(card,
349 if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) {
353 if ((err = snd_cs4231_mixer(chip)) < 0) {
358 if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) {
363 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
365 outb(0x00, fm_port[dev] + 6);
366 inb(fm_port[dev] + 7);
367 /* Enable OPL-3 Function */
368 outb(inb(PC9800_SOUND_IO_ID) | 0x03, PC9800_SOUND_IO_ID);
369 if (snd_opl3_create(card,
370 fm_port[dev], fm_port[dev] + 2,
371 OPL3_HW_OPL3_PC98, 0, &opl3) < 0) {
372 printk(KERN_ERR IDENT ": OPL3 not detected\n");
374 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
381 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
382 err = pc98_mpu401_init(mpu_irq[dev]);
384 err = snd_mpu401_uart_new(card, 0,
385 pc98ii[dev] ? MPU401_HW_PC98II : MPU401_HW_MPU401,
387 mpu_irq[dev], SA_INTERRUPT, NULL);
389 snd_printk(KERN_INFO IDENT ": MPU401 not detected\n");
393 strcpy(card->driver, pcm->name);
394 strcpy(card->shortname, pcm->name);
395 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
401 sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
402 if ((err = snd_card_register(card)) < 0) {
406 snd_pc98_cards[dev] = card;
410 static int __init alsa_card_pc98_init(void)
414 for (dev = 0; dev < SNDRV_CARDS; dev++) {
417 if (snd_card_pc98_probe(dev) >= 0)
422 printk(KERN_ERR IDENT " soundcard not found or device busy\n");
429 static void __exit alsa_card_pc98_exit(void)
433 for (idx = 0; idx < SNDRV_CARDS; idx++)
434 snd_card_free(snd_pc98_cards[idx]);
437 module_init(alsa_card_pc98_init)
438 module_exit(alsa_card_pc98_exit)