162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci#ifndef __SOUND_MPU401_H 362306a36Sopenharmony_ci#define __SOUND_MPU401_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci/* 662306a36Sopenharmony_ci * Header file for MPU-401 and compatible cards 762306a36Sopenharmony_ci * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <sound/rawmidi.h> 1162306a36Sopenharmony_ci#include <linux/interrupt.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#define MPU401_HW_MPU401 1 /* native MPU401 */ 1462306a36Sopenharmony_ci#define MPU401_HW_SB 2 /* SoundBlaster MPU-401 UART */ 1562306a36Sopenharmony_ci#define MPU401_HW_ES1688 3 /* AudioDrive ES1688 MPU-401 UART */ 1662306a36Sopenharmony_ci#define MPU401_HW_OPL3SA2 4 /* Yamaha OPL3-SA2 */ 1762306a36Sopenharmony_ci#define MPU401_HW_SONICVIBES 5 /* S3 SonicVibes */ 1862306a36Sopenharmony_ci#define MPU401_HW_CS4232 6 /* CS4232 */ 1962306a36Sopenharmony_ci#define MPU401_HW_ES18XX 7 /* AudioDrive ES18XX MPU-401 UART */ 2062306a36Sopenharmony_ci#define MPU401_HW_FM801 8 /* ForteMedia FM801 */ 2162306a36Sopenharmony_ci#define MPU401_HW_TRID4DWAVE 9 /* Trident 4DWave */ 2262306a36Sopenharmony_ci#define MPU401_HW_AZT2320 10 /* Aztech AZT2320 */ 2362306a36Sopenharmony_ci#define MPU401_HW_ALS100 11 /* Avance Logic ALS100 */ 2462306a36Sopenharmony_ci#define MPU401_HW_ICE1712 12 /* Envy24 */ 2562306a36Sopenharmony_ci#define MPU401_HW_VIA686A 13 /* VIA 82C686A */ 2662306a36Sopenharmony_ci#define MPU401_HW_YMFPCI 14 /* YMF DS-XG PCI */ 2762306a36Sopenharmony_ci#define MPU401_HW_CMIPCI 15 /* CMIPCI MPU-401 UART */ 2862306a36Sopenharmony_ci#define MPU401_HW_ALS4000 16 /* Avance Logic ALS4000 */ 2962306a36Sopenharmony_ci#define MPU401_HW_INTEL8X0 17 /* Intel8x0 driver */ 3062306a36Sopenharmony_ci#define MPU401_HW_PC98II 18 /* Roland PC98II */ 3162306a36Sopenharmony_ci#define MPU401_HW_AUREAL 19 /* Aureal Vortex */ 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci#define MPU401_INFO_INPUT (1 << 0) /* input stream */ 3462306a36Sopenharmony_ci#define MPU401_INFO_OUTPUT (1 << 1) /* output stream */ 3562306a36Sopenharmony_ci#define MPU401_INFO_INTEGRATED (1 << 2) /* integrated h/w port */ 3662306a36Sopenharmony_ci#define MPU401_INFO_MMIO (1 << 3) /* MMIO access */ 3762306a36Sopenharmony_ci#define MPU401_INFO_TX_IRQ (1 << 4) /* independent TX irq */ 3862306a36Sopenharmony_ci#define MPU401_INFO_IRQ_HOOK (1 << 5) /* mpu401 irq handler is called 3962306a36Sopenharmony_ci from driver irq handler */ 4062306a36Sopenharmony_ci#define MPU401_INFO_NO_ACK (1 << 6) /* No ACK cmd needed */ 4162306a36Sopenharmony_ci#define MPU401_INFO_USE_TIMER (1 << 15) /* internal */ 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define MPU401_MODE_BIT_INPUT 0 4462306a36Sopenharmony_ci#define MPU401_MODE_BIT_OUTPUT 1 4562306a36Sopenharmony_ci#define MPU401_MODE_BIT_INPUT_TRIGGER 2 4662306a36Sopenharmony_ci#define MPU401_MODE_BIT_OUTPUT_TRIGGER 3 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci#define MPU401_MODE_INPUT (1<<MPU401_MODE_BIT_INPUT) 4962306a36Sopenharmony_ci#define MPU401_MODE_OUTPUT (1<<MPU401_MODE_BIT_OUTPUT) 5062306a36Sopenharmony_ci#define MPU401_MODE_INPUT_TRIGGER (1<<MPU401_MODE_BIT_INPUT_TRIGGER) 5162306a36Sopenharmony_ci#define MPU401_MODE_OUTPUT_TRIGGER (1<<MPU401_MODE_BIT_OUTPUT_TRIGGER) 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define MPU401_MODE_INPUT_TIMER (1<<0) 5462306a36Sopenharmony_ci#define MPU401_MODE_OUTPUT_TIMER (1<<1) 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_cistruct snd_mpu401 { 5762306a36Sopenharmony_ci struct snd_rawmidi *rmidi; 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci unsigned short hardware; /* MPU401_HW_XXXX */ 6062306a36Sopenharmony_ci unsigned int info_flags; /* MPU401_INFO_XXX */ 6162306a36Sopenharmony_ci unsigned long port; /* base port of MPU-401 chip */ 6262306a36Sopenharmony_ci unsigned long cport; /* port + 1 (usually) */ 6362306a36Sopenharmony_ci struct resource *res; /* port resource */ 6462306a36Sopenharmony_ci int irq; /* IRQ number of MPU-401 chip */ 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci unsigned long mode; /* MPU401_MODE_XXXX */ 6762306a36Sopenharmony_ci int timer_invoked; 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci int (*open_input) (struct snd_mpu401 * mpu); 7062306a36Sopenharmony_ci void (*close_input) (struct snd_mpu401 * mpu); 7162306a36Sopenharmony_ci int (*open_output) (struct snd_mpu401 * mpu); 7262306a36Sopenharmony_ci void (*close_output) (struct snd_mpu401 * mpu); 7362306a36Sopenharmony_ci void *private_data; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci struct snd_rawmidi_substream *substream_input; 7662306a36Sopenharmony_ci struct snd_rawmidi_substream *substream_output; 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci spinlock_t input_lock; 7962306a36Sopenharmony_ci spinlock_t output_lock; 8062306a36Sopenharmony_ci spinlock_t timer_lock; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci struct timer_list timer; 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci void (*write) (struct snd_mpu401 * mpu, unsigned char data, unsigned long addr); 8562306a36Sopenharmony_ci unsigned char (*read) (struct snd_mpu401 *mpu, unsigned long addr); 8662306a36Sopenharmony_ci}; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci/* I/O ports */ 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci#define MPU401C(mpu) (mpu)->cport 9162306a36Sopenharmony_ci#define MPU401D(mpu) (mpu)->port 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci/* 9462306a36Sopenharmony_ci * control register bits 9562306a36Sopenharmony_ci */ 9662306a36Sopenharmony_ci/* read MPU401C() */ 9762306a36Sopenharmony_ci#define MPU401_RX_EMPTY 0x80 9862306a36Sopenharmony_ci#define MPU401_TX_FULL 0x40 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci/* write MPU401C() */ 10162306a36Sopenharmony_ci#define MPU401_RESET 0xff 10262306a36Sopenharmony_ci#define MPU401_ENTER_UART 0x3f 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci/* read MPU401D() */ 10562306a36Sopenharmony_ci#define MPU401_ACK 0xfe 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci/* 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci */ 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ciirqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id); 11362306a36Sopenharmony_ciirqreturn_t snd_mpu401_uart_interrupt_tx(int irq, void *dev_id); 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ciint snd_mpu401_uart_new(struct snd_card *card, 11662306a36Sopenharmony_ci int device, 11762306a36Sopenharmony_ci unsigned short hardware, 11862306a36Sopenharmony_ci unsigned long port, 11962306a36Sopenharmony_ci unsigned int info_flags, 12062306a36Sopenharmony_ci int irq, 12162306a36Sopenharmony_ci struct snd_rawmidi ** rrawmidi); 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci#endif /* __SOUND_MPU401_H */ 124