18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci#ifndef __SOUND_MPU401_H 38c2ecf20Sopenharmony_ci#define __SOUND_MPU401_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* 68c2ecf20Sopenharmony_ci * Header file for MPU-401 and compatible cards 78c2ecf20Sopenharmony_ci * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <sound/rawmidi.h> 118c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define MPU401_HW_MPU401 1 /* native MPU401 */ 148c2ecf20Sopenharmony_ci#define MPU401_HW_SB 2 /* SoundBlaster MPU-401 UART */ 158c2ecf20Sopenharmony_ci#define MPU401_HW_ES1688 3 /* AudioDrive ES1688 MPU-401 UART */ 168c2ecf20Sopenharmony_ci#define MPU401_HW_OPL3SA2 4 /* Yamaha OPL3-SA2 */ 178c2ecf20Sopenharmony_ci#define MPU401_HW_SONICVIBES 5 /* S3 SonicVibes */ 188c2ecf20Sopenharmony_ci#define MPU401_HW_CS4232 6 /* CS4232 */ 198c2ecf20Sopenharmony_ci#define MPU401_HW_ES18XX 7 /* AudioDrive ES18XX MPU-401 UART */ 208c2ecf20Sopenharmony_ci#define MPU401_HW_FM801 8 /* ForteMedia FM801 */ 218c2ecf20Sopenharmony_ci#define MPU401_HW_TRID4DWAVE 9 /* Trident 4DWave */ 228c2ecf20Sopenharmony_ci#define MPU401_HW_AZT2320 10 /* Aztech AZT2320 */ 238c2ecf20Sopenharmony_ci#define MPU401_HW_ALS100 11 /* Avance Logic ALS100 */ 248c2ecf20Sopenharmony_ci#define MPU401_HW_ICE1712 12 /* Envy24 */ 258c2ecf20Sopenharmony_ci#define MPU401_HW_VIA686A 13 /* VIA 82C686A */ 268c2ecf20Sopenharmony_ci#define MPU401_HW_YMFPCI 14 /* YMF DS-XG PCI */ 278c2ecf20Sopenharmony_ci#define MPU401_HW_CMIPCI 15 /* CMIPCI MPU-401 UART */ 288c2ecf20Sopenharmony_ci#define MPU401_HW_ALS4000 16 /* Avance Logic ALS4000 */ 298c2ecf20Sopenharmony_ci#define MPU401_HW_INTEL8X0 17 /* Intel8x0 driver */ 308c2ecf20Sopenharmony_ci#define MPU401_HW_PC98II 18 /* Roland PC98II */ 318c2ecf20Sopenharmony_ci#define MPU401_HW_AUREAL 19 /* Aureal Vortex */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define MPU401_INFO_INPUT (1 << 0) /* input stream */ 348c2ecf20Sopenharmony_ci#define MPU401_INFO_OUTPUT (1 << 1) /* output stream */ 358c2ecf20Sopenharmony_ci#define MPU401_INFO_INTEGRATED (1 << 2) /* integrated h/w port */ 368c2ecf20Sopenharmony_ci#define MPU401_INFO_MMIO (1 << 3) /* MMIO access */ 378c2ecf20Sopenharmony_ci#define MPU401_INFO_TX_IRQ (1 << 4) /* independent TX irq */ 388c2ecf20Sopenharmony_ci#define MPU401_INFO_IRQ_HOOK (1 << 5) /* mpu401 irq handler is called 398c2ecf20Sopenharmony_ci from driver irq handler */ 408c2ecf20Sopenharmony_ci#define MPU401_INFO_NO_ACK (1 << 6) /* No ACK cmd needed */ 418c2ecf20Sopenharmony_ci#define MPU401_INFO_USE_TIMER (1 << 15) /* internal */ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define MPU401_MODE_BIT_INPUT 0 448c2ecf20Sopenharmony_ci#define MPU401_MODE_BIT_OUTPUT 1 458c2ecf20Sopenharmony_ci#define MPU401_MODE_BIT_INPUT_TRIGGER 2 468c2ecf20Sopenharmony_ci#define MPU401_MODE_BIT_OUTPUT_TRIGGER 3 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define MPU401_MODE_INPUT (1<<MPU401_MODE_BIT_INPUT) 498c2ecf20Sopenharmony_ci#define MPU401_MODE_OUTPUT (1<<MPU401_MODE_BIT_OUTPUT) 508c2ecf20Sopenharmony_ci#define MPU401_MODE_INPUT_TRIGGER (1<<MPU401_MODE_BIT_INPUT_TRIGGER) 518c2ecf20Sopenharmony_ci#define MPU401_MODE_OUTPUT_TRIGGER (1<<MPU401_MODE_BIT_OUTPUT_TRIGGER) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define MPU401_MODE_INPUT_TIMER (1<<0) 548c2ecf20Sopenharmony_ci#define MPU401_MODE_OUTPUT_TIMER (1<<1) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistruct snd_mpu401 { 578c2ecf20Sopenharmony_ci struct snd_rawmidi *rmidi; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci unsigned short hardware; /* MPU401_HW_XXXX */ 608c2ecf20Sopenharmony_ci unsigned int info_flags; /* MPU401_INFO_XXX */ 618c2ecf20Sopenharmony_ci unsigned long port; /* base port of MPU-401 chip */ 628c2ecf20Sopenharmony_ci unsigned long cport; /* port + 1 (usually) */ 638c2ecf20Sopenharmony_ci struct resource *res; /* port resource */ 648c2ecf20Sopenharmony_ci int irq; /* IRQ number of MPU-401 chip */ 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci unsigned long mode; /* MPU401_MODE_XXXX */ 678c2ecf20Sopenharmony_ci int timer_invoked; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci int (*open_input) (struct snd_mpu401 * mpu); 708c2ecf20Sopenharmony_ci void (*close_input) (struct snd_mpu401 * mpu); 718c2ecf20Sopenharmony_ci int (*open_output) (struct snd_mpu401 * mpu); 728c2ecf20Sopenharmony_ci void (*close_output) (struct snd_mpu401 * mpu); 738c2ecf20Sopenharmony_ci void *private_data; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci struct snd_rawmidi_substream *substream_input; 768c2ecf20Sopenharmony_ci struct snd_rawmidi_substream *substream_output; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci spinlock_t input_lock; 798c2ecf20Sopenharmony_ci spinlock_t output_lock; 808c2ecf20Sopenharmony_ci spinlock_t timer_lock; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci struct timer_list timer; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci void (*write) (struct snd_mpu401 * mpu, unsigned char data, unsigned long addr); 858c2ecf20Sopenharmony_ci unsigned char (*read) (struct snd_mpu401 *mpu, unsigned long addr); 868c2ecf20Sopenharmony_ci}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* I/O ports */ 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#define MPU401C(mpu) (mpu)->cport 918c2ecf20Sopenharmony_ci#define MPU401D(mpu) (mpu)->port 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* 948c2ecf20Sopenharmony_ci * control register bits 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci/* read MPU401C() */ 978c2ecf20Sopenharmony_ci#define MPU401_RX_EMPTY 0x80 988c2ecf20Sopenharmony_ci#define MPU401_TX_FULL 0x40 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/* write MPU401C() */ 1018c2ecf20Sopenharmony_ci#define MPU401_RESET 0xff 1028c2ecf20Sopenharmony_ci#define MPU401_ENTER_UART 0x3f 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* read MPU401D() */ 1058c2ecf20Sopenharmony_ci#define MPU401_ACK 0xfe 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/* 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciirqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id); 1138c2ecf20Sopenharmony_ciirqreturn_t snd_mpu401_uart_interrupt_tx(int irq, void *dev_id); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ciint snd_mpu401_uart_new(struct snd_card *card, 1168c2ecf20Sopenharmony_ci int device, 1178c2ecf20Sopenharmony_ci unsigned short hardware, 1188c2ecf20Sopenharmony_ci unsigned long port, 1198c2ecf20Sopenharmony_ci unsigned int info_flags, 1208c2ecf20Sopenharmony_ci int irq, 1218c2ecf20Sopenharmony_ci struct snd_rawmidi ** rrawmidi); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci#endif /* __SOUND_MPU401_H */ 124