1*1a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 21da177e4SLinus Torvalds /* 3c1017a4cSJaroslav Kysela * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 41da177e4SLinus Torvalds * Routines for control of EMU10K1 MPU-401 in UART mode 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds #include <linux/time.h> 81da177e4SLinus Torvalds #include <linux/init.h> 91da177e4SLinus Torvalds #include <sound/core.h> 101da177e4SLinus Torvalds #include <sound/emu10k1.h> 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds #define EMU10K1_MIDI_MODE_INPUT (1<<0) 131da177e4SLinus Torvalds #define EMU10K1_MIDI_MODE_OUTPUT (1<<1) 141da177e4SLinus Torvalds 15eb4698f3STakashi Iwai static inline unsigned char mpu401_read(struct snd_emu10k1 *emu, 16eb4698f3STakashi Iwai struct snd_emu10k1_midi *mpu, int idx) 171da177e4SLinus Torvalds { 181da177e4SLinus Torvalds if (emu->audigy) 191da177e4SLinus Torvalds return (unsigned char)snd_emu10k1_ptr_read(emu, mpu->port + idx, 0); 201da177e4SLinus Torvalds else 211da177e4SLinus Torvalds return inb(emu->port + mpu->port + idx); 221da177e4SLinus Torvalds } 231da177e4SLinus Torvalds 24eb4698f3STakashi Iwai static inline void mpu401_write(struct snd_emu10k1 *emu, 25eb4698f3STakashi Iwai struct snd_emu10k1_midi *mpu, int data, int idx) 261da177e4SLinus Torvalds { 271da177e4SLinus Torvalds if (emu->audigy) 281da177e4SLinus Torvalds snd_emu10k1_ptr_write(emu, mpu->port + idx, 0, data); 291da177e4SLinus Torvalds else 301da177e4SLinus Torvalds outb(data, emu->port + mpu->port + idx); 311da177e4SLinus Torvalds } 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds #define mpu401_write_data(emu, mpu, data) mpu401_write(emu, mpu, data, 0) 341da177e4SLinus Torvalds #define mpu401_write_cmd(emu, mpu, data) mpu401_write(emu, mpu, data, 1) 351da177e4SLinus Torvalds #define mpu401_read_data(emu, mpu) mpu401_read(emu, mpu, 0) 361da177e4SLinus Torvalds #define mpu401_read_stat(emu, mpu) mpu401_read(emu, mpu, 1) 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #define mpu401_input_avail(emu,mpu) (!(mpu401_read_stat(emu,mpu) & 0x80)) 391da177e4SLinus Torvalds #define mpu401_output_ready(emu,mpu) (!(mpu401_read_stat(emu,mpu) & 0x40)) 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds #define MPU401_RESET 0xff 421da177e4SLinus Torvalds #define MPU401_ENTER_UART 0x3f 431da177e4SLinus Torvalds #define MPU401_ACK 0xfe 441da177e4SLinus Torvalds 45eb4698f3STakashi Iwai static void mpu401_clear_rx(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *mpu) 461da177e4SLinus Torvalds { 471da177e4SLinus Torvalds int timeout = 100000; 481da177e4SLinus Torvalds for (; timeout > 0 && mpu401_input_avail(emu, mpu); timeout--) 491da177e4SLinus Torvalds mpu401_read_data(emu, mpu); 501da177e4SLinus Torvalds #ifdef CONFIG_SND_DEBUG 511da177e4SLinus Torvalds if (timeout <= 0) 526f002b02STakashi Iwai dev_err(emu->card->dev, 536f002b02STakashi Iwai "cmd: clear rx timeout (status = 0x%x)\n", 546f002b02STakashi Iwai mpu401_read_stat(emu, mpu)); 551da177e4SLinus Torvalds #endif 561da177e4SLinus Torvalds } 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds /* 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds */ 611da177e4SLinus Torvalds 62eb4698f3STakashi Iwai static void do_emu10k1_midi_interrupt(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *midi, unsigned int status) 631da177e4SLinus Torvalds { 641da177e4SLinus Torvalds unsigned char byte; 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds if (midi->rmidi == NULL) { 671da177e4SLinus Torvalds snd_emu10k1_intr_disable(emu, midi->tx_enable | midi->rx_enable); 681da177e4SLinus Torvalds return; 691da177e4SLinus Torvalds } 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds spin_lock(&midi->input_lock); 721da177e4SLinus Torvalds if ((status & midi->ipr_rx) && mpu401_input_avail(emu, midi)) { 731da177e4SLinus Torvalds if (!(midi->midi_mode & EMU10K1_MIDI_MODE_INPUT)) { 741da177e4SLinus Torvalds mpu401_clear_rx(emu, midi); 751da177e4SLinus Torvalds } else { 761da177e4SLinus Torvalds byte = mpu401_read_data(emu, midi); 771da177e4SLinus Torvalds if (midi->substream_input) 781da177e4SLinus Torvalds snd_rawmidi_receive(midi->substream_input, &byte, 1); 791da177e4SLinus Torvalds } 801da177e4SLinus Torvalds } 811da177e4SLinus Torvalds spin_unlock(&midi->input_lock); 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds spin_lock(&midi->output_lock); 841da177e4SLinus Torvalds if ((status & midi->ipr_tx) && mpu401_output_ready(emu, midi)) { 851da177e4SLinus Torvalds if (midi->substream_output && 861da177e4SLinus Torvalds snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) { 871da177e4SLinus Torvalds mpu401_write_data(emu, midi, byte); 881da177e4SLinus Torvalds } else { 891da177e4SLinus Torvalds snd_emu10k1_intr_disable(emu, midi->tx_enable); 901da177e4SLinus Torvalds } 911da177e4SLinus Torvalds } 921da177e4SLinus Torvalds spin_unlock(&midi->output_lock); 931da177e4SLinus Torvalds } 941da177e4SLinus Torvalds 95eb4698f3STakashi Iwai static void snd_emu10k1_midi_interrupt(struct snd_emu10k1 *emu, unsigned int status) 961da177e4SLinus Torvalds { 971da177e4SLinus Torvalds do_emu10k1_midi_interrupt(emu, &emu->midi, status); 981da177e4SLinus Torvalds } 991da177e4SLinus Torvalds 100eb4698f3STakashi Iwai static void snd_emu10k1_midi_interrupt2(struct snd_emu10k1 *emu, unsigned int status) 1011da177e4SLinus Torvalds { 1021da177e4SLinus Torvalds do_emu10k1_midi_interrupt(emu, &emu->midi2, status); 1031da177e4SLinus Torvalds } 1041da177e4SLinus Torvalds 105b130807dSRandy Dunlap static int snd_emu10k1_midi_cmd(struct snd_emu10k1 * emu, struct snd_emu10k1_midi *midi, unsigned char cmd, int ack) 1061da177e4SLinus Torvalds { 1071da177e4SLinus Torvalds unsigned long flags; 1081da177e4SLinus Torvalds int timeout, ok; 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds spin_lock_irqsave(&midi->input_lock, flags); 1111da177e4SLinus Torvalds mpu401_write_data(emu, midi, 0x00); 1121da177e4SLinus Torvalds /* mpu401_clear_rx(emu, midi); */ 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds mpu401_write_cmd(emu, midi, cmd); 1151da177e4SLinus Torvalds if (ack) { 1161da177e4SLinus Torvalds ok = 0; 1171da177e4SLinus Torvalds timeout = 10000; 1181da177e4SLinus Torvalds while (!ok && timeout-- > 0) { 1191da177e4SLinus Torvalds if (mpu401_input_avail(emu, midi)) { 1201da177e4SLinus Torvalds if (mpu401_read_data(emu, midi) == MPU401_ACK) 1211da177e4SLinus Torvalds ok = 1; 1221da177e4SLinus Torvalds } 1231da177e4SLinus Torvalds } 1241da177e4SLinus Torvalds if (!ok && mpu401_read_data(emu, midi) == MPU401_ACK) 1251da177e4SLinus Torvalds ok = 1; 1261da177e4SLinus Torvalds } else { 1271da177e4SLinus Torvalds ok = 1; 1281da177e4SLinus Torvalds } 1291da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->input_lock, flags); 130b130807dSRandy Dunlap if (!ok) { 1316f002b02STakashi Iwai dev_err(emu->card->dev, 1326f002b02STakashi Iwai "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n", 1331da177e4SLinus Torvalds cmd, emu->port, 1341da177e4SLinus Torvalds mpu401_read_stat(emu, midi), 1351da177e4SLinus Torvalds mpu401_read_data(emu, midi)); 136b130807dSRandy Dunlap return 1; 137b130807dSRandy Dunlap } 138b130807dSRandy Dunlap return 0; 1391da177e4SLinus Torvalds } 1401da177e4SLinus Torvalds 141eb4698f3STakashi Iwai static int snd_emu10k1_midi_input_open(struct snd_rawmidi_substream *substream) 1421da177e4SLinus Torvalds { 143eb4698f3STakashi Iwai struct snd_emu10k1 *emu; 144eb4698f3STakashi Iwai struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; 1451da177e4SLinus Torvalds unsigned long flags; 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds emu = midi->emu; 148da3cec35STakashi Iwai if (snd_BUG_ON(!emu)) 149da3cec35STakashi Iwai return -ENXIO; 1501da177e4SLinus Torvalds spin_lock_irqsave(&midi->open_lock, flags); 1511da177e4SLinus Torvalds midi->midi_mode |= EMU10K1_MIDI_MODE_INPUT; 1521da177e4SLinus Torvalds midi->substream_input = substream; 1531da177e4SLinus Torvalds if (!(midi->midi_mode & EMU10K1_MIDI_MODE_OUTPUT)) { 1541da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->open_lock, flags); 155b130807dSRandy Dunlap if (snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 1)) 156b130807dSRandy Dunlap goto error_out; 157b130807dSRandy Dunlap if (snd_emu10k1_midi_cmd(emu, midi, MPU401_ENTER_UART, 1)) 158b130807dSRandy Dunlap goto error_out; 1591da177e4SLinus Torvalds } else { 1601da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->open_lock, flags); 1611da177e4SLinus Torvalds } 1621da177e4SLinus Torvalds return 0; 163b130807dSRandy Dunlap 164b130807dSRandy Dunlap error_out: 165b130807dSRandy Dunlap return -EIO; 1661da177e4SLinus Torvalds } 1671da177e4SLinus Torvalds 168eb4698f3STakashi Iwai static int snd_emu10k1_midi_output_open(struct snd_rawmidi_substream *substream) 1691da177e4SLinus Torvalds { 170eb4698f3STakashi Iwai struct snd_emu10k1 *emu; 171eb4698f3STakashi Iwai struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; 1721da177e4SLinus Torvalds unsigned long flags; 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds emu = midi->emu; 175da3cec35STakashi Iwai if (snd_BUG_ON(!emu)) 176da3cec35STakashi Iwai return -ENXIO; 1771da177e4SLinus Torvalds spin_lock_irqsave(&midi->open_lock, flags); 1781da177e4SLinus Torvalds midi->midi_mode |= EMU10K1_MIDI_MODE_OUTPUT; 1791da177e4SLinus Torvalds midi->substream_output = substream; 1801da177e4SLinus Torvalds if (!(midi->midi_mode & EMU10K1_MIDI_MODE_INPUT)) { 1811da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->open_lock, flags); 182b130807dSRandy Dunlap if (snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 1)) 183b130807dSRandy Dunlap goto error_out; 184b130807dSRandy Dunlap if (snd_emu10k1_midi_cmd(emu, midi, MPU401_ENTER_UART, 1)) 185b130807dSRandy Dunlap goto error_out; 1861da177e4SLinus Torvalds } else { 1871da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->open_lock, flags); 1881da177e4SLinus Torvalds } 1891da177e4SLinus Torvalds return 0; 190b130807dSRandy Dunlap 191b130807dSRandy Dunlap error_out: 192b130807dSRandy Dunlap return -EIO; 1931da177e4SLinus Torvalds } 1941da177e4SLinus Torvalds 195eb4698f3STakashi Iwai static int snd_emu10k1_midi_input_close(struct snd_rawmidi_substream *substream) 1961da177e4SLinus Torvalds { 197eb4698f3STakashi Iwai struct snd_emu10k1 *emu; 198eb4698f3STakashi Iwai struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; 1991da177e4SLinus Torvalds unsigned long flags; 200b130807dSRandy Dunlap int err = 0; 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvalds emu = midi->emu; 203da3cec35STakashi Iwai if (snd_BUG_ON(!emu)) 204da3cec35STakashi Iwai return -ENXIO; 2051da177e4SLinus Torvalds spin_lock_irqsave(&midi->open_lock, flags); 2061da177e4SLinus Torvalds snd_emu10k1_intr_disable(emu, midi->rx_enable); 2071da177e4SLinus Torvalds midi->midi_mode &= ~EMU10K1_MIDI_MODE_INPUT; 2081da177e4SLinus Torvalds midi->substream_input = NULL; 2091da177e4SLinus Torvalds if (!(midi->midi_mode & EMU10K1_MIDI_MODE_OUTPUT)) { 2101da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->open_lock, flags); 211b130807dSRandy Dunlap err = snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 0); 2121da177e4SLinus Torvalds } else { 2131da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->open_lock, flags); 2141da177e4SLinus Torvalds } 215b130807dSRandy Dunlap return err; 2161da177e4SLinus Torvalds } 2171da177e4SLinus Torvalds 218eb4698f3STakashi Iwai static int snd_emu10k1_midi_output_close(struct snd_rawmidi_substream *substream) 2191da177e4SLinus Torvalds { 220eb4698f3STakashi Iwai struct snd_emu10k1 *emu; 221eb4698f3STakashi Iwai struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; 2221da177e4SLinus Torvalds unsigned long flags; 223b130807dSRandy Dunlap int err = 0; 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds emu = midi->emu; 226da3cec35STakashi Iwai if (snd_BUG_ON(!emu)) 227da3cec35STakashi Iwai return -ENXIO; 2281da177e4SLinus Torvalds spin_lock_irqsave(&midi->open_lock, flags); 2291da177e4SLinus Torvalds snd_emu10k1_intr_disable(emu, midi->tx_enable); 2301da177e4SLinus Torvalds midi->midi_mode &= ~EMU10K1_MIDI_MODE_OUTPUT; 2311da177e4SLinus Torvalds midi->substream_output = NULL; 2321da177e4SLinus Torvalds if (!(midi->midi_mode & EMU10K1_MIDI_MODE_INPUT)) { 2331da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->open_lock, flags); 234b130807dSRandy Dunlap err = snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 0); 2351da177e4SLinus Torvalds } else { 2361da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->open_lock, flags); 2371da177e4SLinus Torvalds } 238b130807dSRandy Dunlap return err; 2391da177e4SLinus Torvalds } 2401da177e4SLinus Torvalds 241eb4698f3STakashi Iwai static void snd_emu10k1_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) 2421da177e4SLinus Torvalds { 243eb4698f3STakashi Iwai struct snd_emu10k1 *emu; 244eb4698f3STakashi Iwai struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; 2451da177e4SLinus Torvalds emu = midi->emu; 246da3cec35STakashi Iwai if (snd_BUG_ON(!emu)) 247da3cec35STakashi Iwai return; 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds if (up) 2501da177e4SLinus Torvalds snd_emu10k1_intr_enable(emu, midi->rx_enable); 2511da177e4SLinus Torvalds else 2521da177e4SLinus Torvalds snd_emu10k1_intr_disable(emu, midi->rx_enable); 2531da177e4SLinus Torvalds } 2541da177e4SLinus Torvalds 255eb4698f3STakashi Iwai static void snd_emu10k1_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) 2561da177e4SLinus Torvalds { 257eb4698f3STakashi Iwai struct snd_emu10k1 *emu; 258eb4698f3STakashi Iwai struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; 2591da177e4SLinus Torvalds unsigned long flags; 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds emu = midi->emu; 262da3cec35STakashi Iwai if (snd_BUG_ON(!emu)) 263da3cec35STakashi Iwai return; 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds if (up) { 2661da177e4SLinus Torvalds int max = 4; 2671da177e4SLinus Torvalds unsigned char byte; 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds /* try to send some amount of bytes here before interrupts */ 2701da177e4SLinus Torvalds spin_lock_irqsave(&midi->output_lock, flags); 2711da177e4SLinus Torvalds while (max > 0) { 2721da177e4SLinus Torvalds if (mpu401_output_ready(emu, midi)) { 2731da177e4SLinus Torvalds if (!(midi->midi_mode & EMU10K1_MIDI_MODE_OUTPUT) || 2741da177e4SLinus Torvalds snd_rawmidi_transmit(substream, &byte, 1) != 1) { 2751da177e4SLinus Torvalds /* no more data */ 2761da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->output_lock, flags); 2771da177e4SLinus Torvalds return; 2781da177e4SLinus Torvalds } 2791da177e4SLinus Torvalds mpu401_write_data(emu, midi, byte); 2801da177e4SLinus Torvalds max--; 2811da177e4SLinus Torvalds } else { 2821da177e4SLinus Torvalds break; 2831da177e4SLinus Torvalds } 2841da177e4SLinus Torvalds } 2851da177e4SLinus Torvalds spin_unlock_irqrestore(&midi->output_lock, flags); 2861da177e4SLinus Torvalds snd_emu10k1_intr_enable(emu, midi->tx_enable); 2871da177e4SLinus Torvalds } else { 2881da177e4SLinus Torvalds snd_emu10k1_intr_disable(emu, midi->tx_enable); 2891da177e4SLinus Torvalds } 2901da177e4SLinus Torvalds } 2911da177e4SLinus Torvalds 2921da177e4SLinus Torvalds /* 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds */ 2951da177e4SLinus Torvalds 296485885b9STakashi Iwai static const struct snd_rawmidi_ops snd_emu10k1_midi_output = 2971da177e4SLinus Torvalds { 2981da177e4SLinus Torvalds .open = snd_emu10k1_midi_output_open, 2991da177e4SLinus Torvalds .close = snd_emu10k1_midi_output_close, 3001da177e4SLinus Torvalds .trigger = snd_emu10k1_midi_output_trigger, 3011da177e4SLinus Torvalds }; 3021da177e4SLinus Torvalds 303485885b9STakashi Iwai static const struct snd_rawmidi_ops snd_emu10k1_midi_input = 3041da177e4SLinus Torvalds { 3051da177e4SLinus Torvalds .open = snd_emu10k1_midi_input_open, 3061da177e4SLinus Torvalds .close = snd_emu10k1_midi_input_close, 3071da177e4SLinus Torvalds .trigger = snd_emu10k1_midi_input_trigger, 3081da177e4SLinus Torvalds }; 3091da177e4SLinus Torvalds 310eb4698f3STakashi Iwai static void snd_emu10k1_midi_free(struct snd_rawmidi *rmidi) 3111da177e4SLinus Torvalds { 3129fe856e4SJoe Perches struct snd_emu10k1_midi *midi = rmidi->private_data; 3131da177e4SLinus Torvalds midi->interrupt = NULL; 3141da177e4SLinus Torvalds midi->rmidi = NULL; 3151da177e4SLinus Torvalds } 3161da177e4SLinus Torvalds 317e23e7a14SBill Pemberton static int emu10k1_midi_init(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *midi, int device, char *name) 3181da177e4SLinus Torvalds { 319eb4698f3STakashi Iwai struct snd_rawmidi *rmidi; 3201da177e4SLinus Torvalds int err; 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds if ((err = snd_rawmidi_new(emu->card, name, device, 1, 1, &rmidi)) < 0) 3231da177e4SLinus Torvalds return err; 3241da177e4SLinus Torvalds midi->emu = emu; 3251da177e4SLinus Torvalds spin_lock_init(&midi->open_lock); 3261da177e4SLinus Torvalds spin_lock_init(&midi->input_lock); 3271da177e4SLinus Torvalds spin_lock_init(&midi->output_lock); 3281da177e4SLinus Torvalds strcpy(rmidi->name, name); 3291da177e4SLinus Torvalds snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_emu10k1_midi_output); 3301da177e4SLinus Torvalds snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_emu10k1_midi_input); 3311da177e4SLinus Torvalds rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | 3321da177e4SLinus Torvalds SNDRV_RAWMIDI_INFO_INPUT | 3331da177e4SLinus Torvalds SNDRV_RAWMIDI_INFO_DUPLEX; 3341da177e4SLinus Torvalds rmidi->private_data = midi; 3351da177e4SLinus Torvalds rmidi->private_free = snd_emu10k1_midi_free; 3361da177e4SLinus Torvalds midi->rmidi = rmidi; 3371da177e4SLinus Torvalds return 0; 3381da177e4SLinus Torvalds } 3391da177e4SLinus Torvalds 340e23e7a14SBill Pemberton int snd_emu10k1_midi(struct snd_emu10k1 *emu) 3411da177e4SLinus Torvalds { 342eb4698f3STakashi Iwai struct snd_emu10k1_midi *midi = &emu->midi; 3431da177e4SLinus Torvalds int err; 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvalds if ((err = emu10k1_midi_init(emu, midi, 0, "EMU10K1 MPU-401 (UART)")) < 0) 3461da177e4SLinus Torvalds return err; 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds midi->tx_enable = INTE_MIDITXENABLE; 3491da177e4SLinus Torvalds midi->rx_enable = INTE_MIDIRXENABLE; 3501da177e4SLinus Torvalds midi->port = MUDATA; 3511da177e4SLinus Torvalds midi->ipr_tx = IPR_MIDITRANSBUFEMPTY; 3521da177e4SLinus Torvalds midi->ipr_rx = IPR_MIDIRECVBUFEMPTY; 3531da177e4SLinus Torvalds midi->interrupt = snd_emu10k1_midi_interrupt; 3541da177e4SLinus Torvalds return 0; 3551da177e4SLinus Torvalds } 3561da177e4SLinus Torvalds 357e23e7a14SBill Pemberton int snd_emu10k1_audigy_midi(struct snd_emu10k1 *emu) 3581da177e4SLinus Torvalds { 359eb4698f3STakashi Iwai struct snd_emu10k1_midi *midi; 3601da177e4SLinus Torvalds int err; 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds midi = &emu->midi; 3631da177e4SLinus Torvalds if ((err = emu10k1_midi_init(emu, midi, 0, "Audigy MPU-401 (UART)")) < 0) 3641da177e4SLinus Torvalds return err; 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds midi->tx_enable = INTE_MIDITXENABLE; 3671da177e4SLinus Torvalds midi->rx_enable = INTE_MIDIRXENABLE; 3681da177e4SLinus Torvalds midi->port = A_MUDATA1; 3691da177e4SLinus Torvalds midi->ipr_tx = IPR_MIDITRANSBUFEMPTY; 3701da177e4SLinus Torvalds midi->ipr_rx = IPR_MIDIRECVBUFEMPTY; 3711da177e4SLinus Torvalds midi->interrupt = snd_emu10k1_midi_interrupt; 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds midi = &emu->midi2; 3741da177e4SLinus Torvalds if ((err = emu10k1_midi_init(emu, midi, 1, "Audigy MPU-401 #2")) < 0) 3751da177e4SLinus Torvalds return err; 3761da177e4SLinus Torvalds 3771da177e4SLinus Torvalds midi->tx_enable = INTE_A_MIDITXENABLE2; 3781da177e4SLinus Torvalds midi->rx_enable = INTE_A_MIDIRXENABLE2; 3791da177e4SLinus Torvalds midi->port = A_MUDATA2; 3801da177e4SLinus Torvalds midi->ipr_tx = IPR_A_MIDITRANSBUFEMPTY2; 3811da177e4SLinus Torvalds midi->ipr_rx = IPR_A_MIDIRECVBUFEMPTY2; 3821da177e4SLinus Torvalds midi->interrupt = snd_emu10k1_midi_interrupt2; 3831da177e4SLinus Torvalds return 0; 3841da177e4SLinus Torvalds } 385