Path: blob/master/sound/pci/au88x0/au88x0_mpu401.c
10817 views
/*1* Copyright (c) by Jaroslav Kysela <[email protected]>2* Routines for control of MPU-401 in UART mode3*4* Modified for the Aureal Vortex based Soundcards5* by Manuel Jander ([email protected]).6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA20*21*/2223#include <linux/time.h>24#include <linux/init.h>25#include <sound/core.h>26#include <sound/mpu401.h>27#include "au88x0.h"2829/* Check for mpu401 mmio support. */30/* MPU401 legacy support is only provided as a emergency fallback *31* for older versions of ALSA. Its usage is strongly discouraged. */32#ifndef MPU401_HW_AUREAL33#define VORTEX_MPU401_LEGACY34#endif3536/* Vortex MPU401 defines. */37#define MIDI_CLOCK_DIV 0x6138/* Standart MPU401 defines. */39#define MPU401_RESET 0xff40#define MPU401_ENTER_UART 0x3f41#define MPU401_ACK 0xfe4243static int __devinit snd_vortex_midi(vortex_t * vortex)44{45struct snd_rawmidi *rmidi;46int temp, mode;47struct snd_mpu401 *mpu;48unsigned long port;4950#ifdef VORTEX_MPU401_LEGACY51/* EnableHardCodedMPU401Port() */52/* Enable Legacy MIDI Interface port. */53port = (0x03 << 5); /* FIXME: static address. 0x330 */54temp =55(hwread(vortex->mmio, VORTEX_CTRL) & ~CTRL_MIDI_PORT) |56CTRL_MIDI_EN | port;57hwwrite(vortex->mmio, VORTEX_CTRL, temp);58#else59/* Disable Legacy MIDI Interface port. */60temp =61(hwread(vortex->mmio, VORTEX_CTRL) & ~CTRL_MIDI_PORT) &62~CTRL_MIDI_EN;63hwwrite(vortex->mmio, VORTEX_CTRL, temp);64#endif65/* Mpu401UartInit() */66mode = 1;67temp = hwread(vortex->mmio, VORTEX_CTRL2) & 0xffff00cf;68temp |= (MIDI_CLOCK_DIV << 8) | ((mode >> 24) & 0xff) << 4;69hwwrite(vortex->mmio, VORTEX_CTRL2, temp);70hwwrite(vortex->mmio, VORTEX_MIDI_CMD, MPU401_RESET);7172/* Check if anything is OK. */73temp = hwread(vortex->mmio, VORTEX_MIDI_DATA);74if (temp != MPU401_ACK /*0xfe */ ) {75printk(KERN_ERR "midi port doesn't acknowledge!\n");76return -ENODEV;77}78/* Enable MPU401 interrupts. */79hwwrite(vortex->mmio, VORTEX_IRQ_CTRL,80hwread(vortex->mmio, VORTEX_IRQ_CTRL) | IRQ_MIDI);8182/* Create MPU401 instance. */83#ifdef VORTEX_MPU401_LEGACY84if ((temp =85snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_MPU401, 0x330,860, 0, 0, &rmidi)) != 0) {87hwwrite(vortex->mmio, VORTEX_CTRL,88(hwread(vortex->mmio, VORTEX_CTRL) &89~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);90return temp;91}92#else93port = (unsigned long)(vortex->mmio + VORTEX_MIDI_DATA);94if ((temp =95snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_AUREAL, port,96MPU401_INFO_INTEGRATED | MPU401_INFO_MMIO,970, 0, &rmidi)) != 0) {98hwwrite(vortex->mmio, VORTEX_CTRL,99(hwread(vortex->mmio, VORTEX_CTRL) &100~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);101return temp;102}103mpu = rmidi->private_data;104mpu->cport = (unsigned long)(vortex->mmio + VORTEX_MIDI_CMD);105#endif106/* Overwrite MIDI name */107snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI %d", CARD_NAME_SHORT , vortex->card->number);108109vortex->rmidi = rmidi;110return 0;111}112113114