2019-05-27 13:55:05 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
2007-10-15 14:50:19 +07:00
|
|
|
* Copyright (c) by Jaroslav Kysela <perex@perex.cz>
|
2005-04-17 05:20:36 +07:00
|
|
|
* Routines for control of MPU-401 in UART mode
|
|
|
|
*
|
|
|
|
* Modified for the Aureal Vortex based Soundcards
|
|
|
|
* by Manuel Jander (mjande@embedded.cl).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/mpu401.h>
|
|
|
|
#include "au88x0.h"
|
|
|
|
|
|
|
|
/* Check for mpu401 mmio support. */
|
|
|
|
/* MPU401 legacy support is only provided as a emergency fallback *
|
|
|
|
* for older versions of ALSA. Its usage is strongly discouraged. */
|
|
|
|
#ifndef MPU401_HW_AUREAL
|
|
|
|
#define VORTEX_MPU401_LEGACY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Vortex MPU401 defines. */
|
|
|
|
#define MIDI_CLOCK_DIV 0x61
|
|
|
|
/* Standart MPU401 defines. */
|
|
|
|
#define MPU401_RESET 0xff
|
|
|
|
#define MPU401_ENTER_UART 0x3f
|
|
|
|
#define MPU401_ACK 0xfe
|
|
|
|
|
2012-12-07 00:35:10 +07:00
|
|
|
static int snd_vortex_midi(vortex_t *vortex)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-11-17 20:55:19 +07:00
|
|
|
struct snd_rawmidi *rmidi;
|
2005-04-17 05:20:36 +07:00
|
|
|
int temp, mode;
|
2005-11-17 20:55:19 +07:00
|
|
|
struct snd_mpu401 *mpu;
|
2006-05-23 18:30:59 +07:00
|
|
|
unsigned long port;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#ifdef VORTEX_MPU401_LEGACY
|
|
|
|
/* EnableHardCodedMPU401Port() */
|
|
|
|
/* Enable Legacy MIDI Interface port. */
|
|
|
|
port = (0x03 << 5); /* FIXME: static address. 0x330 */
|
|
|
|
temp =
|
|
|
|
(hwread(vortex->mmio, VORTEX_CTRL) & ~CTRL_MIDI_PORT) |
|
|
|
|
CTRL_MIDI_EN | port;
|
|
|
|
hwwrite(vortex->mmio, VORTEX_CTRL, temp);
|
|
|
|
#else
|
|
|
|
/* Disable Legacy MIDI Interface port. */
|
|
|
|
temp =
|
|
|
|
(hwread(vortex->mmio, VORTEX_CTRL) & ~CTRL_MIDI_PORT) &
|
|
|
|
~CTRL_MIDI_EN;
|
|
|
|
hwwrite(vortex->mmio, VORTEX_CTRL, temp);
|
|
|
|
#endif
|
|
|
|
/* Mpu401UartInit() */
|
|
|
|
mode = 1;
|
|
|
|
temp = hwread(vortex->mmio, VORTEX_CTRL2) & 0xffff00cf;
|
|
|
|
temp |= (MIDI_CLOCK_DIV << 8) | ((mode >> 24) & 0xff) << 4;
|
|
|
|
hwwrite(vortex->mmio, VORTEX_CTRL2, temp);
|
|
|
|
hwwrite(vortex->mmio, VORTEX_MIDI_CMD, MPU401_RESET);
|
|
|
|
|
|
|
|
/* Check if anything is OK. */
|
|
|
|
temp = hwread(vortex->mmio, VORTEX_MIDI_DATA);
|
|
|
|
if (temp != MPU401_ACK /*0xfe */ ) {
|
2014-10-13 13:07:19 +07:00
|
|
|
dev_err(vortex->card->dev, "midi port doesn't acknowledge!\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
/* Enable MPU401 interrupts. */
|
|
|
|
hwwrite(vortex->mmio, VORTEX_IRQ_CTRL,
|
|
|
|
hwread(vortex->mmio, VORTEX_IRQ_CTRL) | IRQ_MIDI);
|
|
|
|
|
|
|
|
/* Create MPU401 instance. */
|
|
|
|
#ifdef VORTEX_MPU401_LEGACY
|
|
|
|
if ((temp =
|
|
|
|
snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_MPU401, 0x330,
|
ALSA: mpu401: clean up interrupt specification
The semantics of snd_mpu401_uart_new()'s interrupt parameters are
somewhat counterintuitive: To prevent the function from allocating its
own interrupt, either the irq number must be invalid, or the irq_flags
parameter must be zero. At the same time, the irq parameter being
invalid specifies that the mpu401 code has to work without an interrupt
allocated by the caller. This implies that, if there is an interrupt
and it is allocated by the caller, the irq parameter must be set to
a valid-looking number which then isn't actually used.
With the removal of IRQF_DISABLED, zero becomes a valid irq_flags value,
which forces us to handle the parameters differently.
This patch introduces a new flag MPU401_INFO_IRQ_HOOK for when the
device interrupt is handled by the caller, and makes the allocation of
the interrupt to depend only on the irq parameter. As suggested by
Takashi, the irq_flags parameter was dropped because, when used, it had
the constant value IRQF_DISABLED.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-09-13 16:24:41 +07:00
|
|
|
MPU401_INFO_IRQ_HOOK, -1, &rmidi)) != 0) {
|
2005-04-17 05:20:36 +07:00
|
|
|
hwwrite(vortex->mmio, VORTEX_CTRL,
|
|
|
|
(hwread(vortex->mmio, VORTEX_CTRL) &
|
|
|
|
~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
#else
|
2006-01-13 23:16:29 +07:00
|
|
|
port = (unsigned long)(vortex->mmio + VORTEX_MIDI_DATA);
|
2005-04-17 05:20:36 +07:00
|
|
|
if ((temp =
|
|
|
|
snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_AUREAL, port,
|
ALSA: mpu401: clean up interrupt specification
The semantics of snd_mpu401_uart_new()'s interrupt parameters are
somewhat counterintuitive: To prevent the function from allocating its
own interrupt, either the irq number must be invalid, or the irq_flags
parameter must be zero. At the same time, the irq parameter being
invalid specifies that the mpu401 code has to work without an interrupt
allocated by the caller. This implies that, if there is an interrupt
and it is allocated by the caller, the irq parameter must be set to
a valid-looking number which then isn't actually used.
With the removal of IRQF_DISABLED, zero becomes a valid irq_flags value,
which forces us to handle the parameters differently.
This patch introduces a new flag MPU401_INFO_IRQ_HOOK for when the
device interrupt is handled by the caller, and makes the allocation of
the interrupt to depend only on the irq parameter. As suggested by
Takashi, the irq_flags parameter was dropped because, when used, it had
the constant value IRQF_DISABLED.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-09-13 16:24:41 +07:00
|
|
|
MPU401_INFO_INTEGRATED | MPU401_INFO_MMIO |
|
|
|
|
MPU401_INFO_IRQ_HOOK, -1, &rmidi)) != 0) {
|
2005-04-17 05:20:36 +07:00
|
|
|
hwwrite(vortex->mmio, VORTEX_CTRL,
|
|
|
|
(hwread(vortex->mmio, VORTEX_CTRL) &
|
|
|
|
~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
mpu = rmidi->private_data;
|
2006-01-13 23:16:29 +07:00
|
|
|
mpu->cport = (unsigned long)(vortex->mmio + VORTEX_MIDI_CMD);
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
2006-05-03 22:07:29 +07:00
|
|
|
/* Overwrite MIDI name */
|
|
|
|
snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI %d", CARD_NAME_SHORT , vortex->card->number);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
vortex->rmidi = rmidi;
|
|
|
|
return 0;
|
|
|
|
}
|