----- Original Message ----
From: Clemens Ladisch <cladisch@googlemail.com>
To: Alexander Saydakov <sandy_saydakov@yahoo.com>
Cc: alsa-user@lists.sourceforge.net
Sent: Friday, September 28, 2007 9:14:21 AM
Subject: Re: [Alsa-user] midi port does not work

>Alexander Saydakov wrote:
>> I am trying to hook up a MIDI keyboard. Here is my configuration:
>> Asus P4P800-E motherboard with on-board sound and MIDI/game port.
>> MIDI port is configured 0x330 irq 5 in BIOS setup
>> ...
>> $ aseqdump -l
>>  Port    Client name                      Port name
>> ...
>>  20:0    MPU-401 UART                     MPU-401 UART MIDI
>> $ aseqdump -p 20:0
>> Cannot connect from port 20:0 - Input/output error
>> # tail /var/log/messages
>> ...mpu401_uart.c:263: cmd: 0x3f failed at 0x330 (status = 0x80, data = 0x90)
>This indicates that the driver was not able to switch the device into
>UART mode.  It's possible that there was some data on the MIDI port that
>prevented the driver from reading the port's status message; please try
>running aseqdump after rebooting, before pressing any key on the MIDI

I found the following explanation of midi uart on the web. Is there such a reset in the alsa code?
Uart mode

When an MPU powers up, it defaults to Intelligent mode (ie, assuming it supports such. Devices which only implement Uart mode typically power up in Uart mode). So, in order to use Uart mode, you need to put the MPU into Uart mode. You do this by sending the command byte 3F (hex) to the MPU's COMMAND port.

Before you do this, it's a good idea to reset the MPU by sending the command byte FF to the COMMAND port. This is the Reset command. Besides clearing out the MPU's input buffer, and running status, this command actually puts the MPU into Intelligent mode. After you send the MPU a command byte, you need to wait for that acknowledge byte from the MPU (ie, at the DATA port). After you get that acknowledge, you can follow up by writing the 3F command byte to kick the MPU into UART mode. Normally, you'd wait for an acknowledge to each written command byte, but the 3F command is an exception. The MPU does not send an acknowledge for this one command, and instead launches right into Uart mode. You're home free now. All you need to do is install your interrupt handler to read incoming MIDI bytes (assuming you want interrupt-driven input as opposed to doing polled input). With output, you need to do polling. The MPU doesn't interrupt the computer after its done outputting a byte.