gus.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. #ifndef __SOUND_GUS_H
  2. #define __SOUND_GUS_H
  3. /*
  4. * Global structures used for GUS part of ALSA driver
  5. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include "pcm.h"
  24. #include "rawmidi.h"
  25. #include "timer.h"
  26. #include "seq_midi_emul.h"
  27. #include "seq_device.h"
  28. #include "ainstr_iw.h"
  29. #include "ainstr_gf1.h"
  30. #include "ainstr_simple.h"
  31. #include <asm/io.h>
  32. #define SNDRV_SEQ_DEV_ID_GUS "gus-synth"
  33. /* IO ports */
  34. #define GUSP(gus, x) ((gus)->gf1.port + SNDRV_g_u_s_##x)
  35. #define SNDRV_g_u_s_MIDICTRL (0x320-0x220)
  36. #define SNDRV_g_u_s_MIDISTAT (0x320-0x220)
  37. #define SNDRV_g_u_s_MIDIDATA (0x321-0x220)
  38. #define SNDRV_g_u_s_GF1PAGE (0x322-0x220)
  39. #define SNDRV_g_u_s_GF1REGSEL (0x323-0x220)
  40. #define SNDRV_g_u_s_GF1DATALOW (0x324-0x220)
  41. #define SNDRV_g_u_s_GF1DATAHIGH (0x325-0x220)
  42. #define SNDRV_g_u_s_IRQSTAT (0x226-0x220)
  43. #define SNDRV_g_u_s_TIMERCNTRL (0x228-0x220)
  44. #define SNDRV_g_u_s_TIMERDATA (0x229-0x220)
  45. #define SNDRV_g_u_s_DRAM (0x327-0x220)
  46. #define SNDRV_g_u_s_MIXCNTRLREG (0x220-0x220)
  47. #define SNDRV_g_u_s_IRQDMACNTRLREG (0x22b-0x220)
  48. #define SNDRV_g_u_s_REGCNTRLS (0x22f-0x220)
  49. #define SNDRV_g_u_s_BOARDVERSION (0x726-0x220)
  50. #define SNDRV_g_u_s_MIXCNTRLPORT (0x726-0x220)
  51. #define SNDRV_g_u_s_IVER (0x325-0x220)
  52. #define SNDRV_g_u_s_MIXDATAPORT (0x326-0x220)
  53. #define SNDRV_g_u_s_MAXCNTRLPORT (0x326-0x220)
  54. /* GF1 registers */
  55. /* global registers */
  56. #define SNDRV_GF1_GB_ACTIVE_VOICES 0x0e
  57. #define SNDRV_GF1_GB_VOICES_IRQ 0x0f
  58. #define SNDRV_GF1_GB_GLOBAL_MODE 0x19
  59. #define SNDRV_GF1_GW_LFO_BASE 0x1a
  60. #define SNDRV_GF1_GB_VOICES_IRQ_READ 0x1f
  61. #define SNDRV_GF1_GB_DRAM_DMA_CONTROL 0x41
  62. #define SNDRV_GF1_GW_DRAM_DMA_LOW 0x42
  63. #define SNDRV_GF1_GW_DRAM_IO_LOW 0x43
  64. #define SNDRV_GF1_GB_DRAM_IO_HIGH 0x44
  65. #define SNDRV_GF1_GB_SOUND_BLASTER_CONTROL 0x45
  66. #define SNDRV_GF1_GB_ADLIB_TIMER_1 0x46
  67. #define SNDRV_GF1_GB_ADLIB_TIMER_2 0x47
  68. #define SNDRV_GF1_GB_RECORD_RATE 0x48
  69. #define SNDRV_GF1_GB_REC_DMA_CONTROL 0x49
  70. #define SNDRV_GF1_GB_JOYSTICK_DAC_LEVEL 0x4b
  71. #define SNDRV_GF1_GB_RESET 0x4c
  72. #define SNDRV_GF1_GB_DRAM_DMA_HIGH 0x50
  73. #define SNDRV_GF1_GW_DRAM_IO16 0x51
  74. #define SNDRV_GF1_GW_MEMORY_CONFIG 0x52
  75. #define SNDRV_GF1_GB_MEMORY_CONTROL 0x53
  76. #define SNDRV_GF1_GW_FIFO_RECORD_BASE_ADDR 0x54
  77. #define SNDRV_GF1_GW_FIFO_PLAY_BASE_ADDR 0x55
  78. #define SNDRV_GF1_GW_FIFO_SIZE 0x56
  79. #define SNDRV_GF1_GW_INTERLEAVE 0x57
  80. #define SNDRV_GF1_GB_COMPATIBILITY 0x59
  81. #define SNDRV_GF1_GB_DECODE_CONTROL 0x5a
  82. #define SNDRV_GF1_GB_VERSION_NUMBER 0x5b
  83. #define SNDRV_GF1_GB_MPU401_CONTROL_A 0x5c
  84. #define SNDRV_GF1_GB_MPU401_CONTROL_B 0x5d
  85. #define SNDRV_GF1_GB_EMULATION_IRQ 0x60
  86. /* voice specific registers */
  87. #define SNDRV_GF1_VB_ADDRESS_CONTROL 0x00
  88. #define SNDRV_GF1_VW_FREQUENCY 0x01
  89. #define SNDRV_GF1_VW_START_HIGH 0x02
  90. #define SNDRV_GF1_VW_START_LOW 0x03
  91. #define SNDRV_GF1_VA_START SNDRV_GF1_VW_START_HIGH
  92. #define SNDRV_GF1_VW_END_HIGH 0x04
  93. #define SNDRV_GF1_VW_END_LOW 0x05
  94. #define SNDRV_GF1_VA_END SNDRV_GF1_VW_END_HIGH
  95. #define SNDRV_GF1_VB_VOLUME_RATE 0x06
  96. #define SNDRV_GF1_VB_VOLUME_START 0x07
  97. #define SNDRV_GF1_VB_VOLUME_END 0x08
  98. #define SNDRV_GF1_VW_VOLUME 0x09
  99. #define SNDRV_GF1_VW_CURRENT_HIGH 0x0a
  100. #define SNDRV_GF1_VW_CURRENT_LOW 0x0b
  101. #define SNDRV_GF1_VA_CURRENT SNDRV_GF1_VW_CURRENT_HIGH
  102. #define SNDRV_GF1_VB_PAN 0x0c
  103. #define SNDRV_GF1_VW_OFFSET_RIGHT 0x0c
  104. #define SNDRV_GF1_VB_VOLUME_CONTROL 0x0d
  105. #define SNDRV_GF1_VB_UPPER_ADDRESS 0x10
  106. #define SNDRV_GF1_VW_EFFECT_HIGH 0x11
  107. #define SNDRV_GF1_VW_EFFECT_LOW 0x12
  108. #define SNDRV_GF1_VA_EFFECT SNDRV_GF1_VW_EFFECT_HIGH
  109. #define SNDRV_GF1_VW_OFFSET_LEFT 0x13
  110. #define SNDRV_GF1_VB_ACCUMULATOR 0x14
  111. #define SNDRV_GF1_VB_MODE 0x15
  112. #define SNDRV_GF1_VW_EFFECT_VOLUME 0x16
  113. #define SNDRV_GF1_VB_FREQUENCY_LFO 0x17
  114. #define SNDRV_GF1_VB_VOLUME_LFO 0x18
  115. #define SNDRV_GF1_VW_OFFSET_RIGHT_FINAL 0x1b
  116. #define SNDRV_GF1_VW_OFFSET_LEFT_FINAL 0x1c
  117. #define SNDRV_GF1_VW_EFFECT_VOLUME_FINAL 0x1d
  118. /* ICS registers */
  119. #define SNDRV_ICS_MIC_DEV 0
  120. #define SNDRV_ICS_LINE_DEV 1
  121. #define SNDRV_ICS_CD_DEV 2
  122. #define SNDRV_ICS_GF1_DEV 3
  123. #define SNDRV_ICS_NONE_DEV 4
  124. #define SNDRV_ICS_MASTER_DEV 5
  125. /* LFO */
  126. #define SNDRV_LFO_TREMOLO 0
  127. #define SNDRV_LFO_VIBRATO 1
  128. /* misc */
  129. #define SNDRV_GF1_DMA_UNSIGNED 0x80
  130. #define SNDRV_GF1_DMA_16BIT 0x40
  131. #define SNDRV_GF1_DMA_IRQ 0x20
  132. #define SNDRV_GF1_DMA_WIDTH16 0x04
  133. #define SNDRV_GF1_DMA_READ 0x02 /* read from GUS's DRAM */
  134. #define SNDRV_GF1_DMA_ENABLE 0x01
  135. /* ramp ranges */
  136. #define SNDRV_GF1_ATTEN(x) (snd_gf1_atten_table[x])
  137. #define SNDRV_GF1_MIN_VOLUME 1800
  138. #define SNDRV_GF1_MAX_VOLUME 4095
  139. #define SNDRV_GF1_MIN_OFFSET (SNDRV_GF1_MIN_VOLUME>>4)
  140. #define SNDRV_GF1_MAX_OFFSET 255
  141. #define SNDRV_GF1_MAX_TDEPTH 90
  142. /* defines for memory manager */
  143. #define SNDRV_GF1_MEM_BLOCK_16BIT 0x0001
  144. #define SNDRV_GF1_MEM_OWNER_DRIVER 0x0001
  145. #define SNDRV_GF1_MEM_OWNER_WAVE_SIMPLE 0x0002
  146. #define SNDRV_GF1_MEM_OWNER_WAVE_GF1 0x0003
  147. #define SNDRV_GF1_MEM_OWNER_WAVE_IWFFFF 0x0004
  148. /* constants for interrupt handlers */
  149. #define SNDRV_GF1_HANDLER_MIDI_OUT 0x00010000
  150. #define SNDRV_GF1_HANDLER_MIDI_IN 0x00020000
  151. #define SNDRV_GF1_HANDLER_TIMER1 0x00040000
  152. #define SNDRV_GF1_HANDLER_TIMER2 0x00080000
  153. #define SNDRV_GF1_HANDLER_VOICE 0x00100000
  154. #define SNDRV_GF1_HANDLER_DMA_WRITE 0x00200000
  155. #define SNDRV_GF1_HANDLER_DMA_READ 0x00400000
  156. #define SNDRV_GF1_HANDLER_ALL (0xffff0000&~SNDRV_GF1_HANDLER_VOICE)
  157. /* constants for DMA flags */
  158. #define SNDRV_GF1_DMA_TRIGGER 1
  159. /* --- */
  160. struct _snd_gus_card;
  161. typedef struct _snd_gus_card snd_gus_card_t;
  162. /* GF1 specific structure */
  163. typedef struct _snd_gf1_bank_info {
  164. unsigned int address;
  165. unsigned int size;
  166. } snd_gf1_bank_info_t;
  167. typedef struct _snd_gf1_mem_block {
  168. unsigned short flags; /* flags - SNDRV_GF1_MEM_BLOCK_XXXX */
  169. unsigned short owner; /* owner - SNDRV_GF1_MEM_OWNER_XXXX */
  170. unsigned int share; /* share count */
  171. unsigned int share_id[4]; /* share ID */
  172. unsigned int ptr;
  173. unsigned int size;
  174. char *name;
  175. struct _snd_gf1_mem_block *next;
  176. struct _snd_gf1_mem_block *prev;
  177. } snd_gf1_mem_block_t;
  178. typedef struct _snd_gf1_mem {
  179. snd_gf1_bank_info_t banks_8[4];
  180. snd_gf1_bank_info_t banks_16[4];
  181. snd_gf1_mem_block_t *first;
  182. snd_gf1_mem_block_t *last;
  183. struct semaphore memory_mutex;
  184. } snd_gf1_mem_t;
  185. typedef struct snd_gf1_dma_block {
  186. void *buffer; /* buffer in computer's RAM */
  187. unsigned long buf_addr; /* buffer address */
  188. unsigned int addr; /* address in onboard memory */
  189. unsigned int count; /* count in bytes */
  190. unsigned int cmd; /* DMA command (format) */
  191. void (*ack)(snd_gus_card_t * gus, void *private_data);
  192. void *private_data;
  193. struct snd_gf1_dma_block *next;
  194. } snd_gf1_dma_block_t;
  195. typedef struct {
  196. snd_midi_channel_set_t * chset;
  197. snd_gus_card_t * gus;
  198. int mode; /* operation mode */
  199. int client; /* sequencer client number */
  200. int port; /* sequencer port number */
  201. unsigned int midi_has_voices: 1;
  202. } snd_gus_port_t;
  203. typedef struct _snd_gus_voice snd_gus_voice_t;
  204. typedef struct {
  205. void (*sample_start)(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_position_t position);
  206. void (*sample_stop)(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_stop_mode_t mode);
  207. void (*sample_freq)(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_frequency_t freq);
  208. void (*sample_volume)(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_ev_volume_t *volume);
  209. void (*sample_loop)(snd_gus_card_t *card, snd_gus_voice_t *voice, snd_seq_ev_loop_t *loop);
  210. void (*sample_pos)(snd_gus_card_t *card, snd_gus_voice_t *voice, snd_seq_position_t position);
  211. void (*sample_private1)(snd_gus_card_t *card, snd_gus_voice_t *voice, unsigned char *data);
  212. } snd_gus_sample_ops_t;
  213. #define SNDRV_GF1_VOICE_TYPE_PCM 0
  214. #define SNDRV_GF1_VOICE_TYPE_SYNTH 1
  215. #define SNDRV_GF1_VOICE_TYPE_MIDI 2
  216. #define SNDRV_GF1_VFLG_RUNNING (1<<0)
  217. #define SNDRV_GF1_VFLG_EFFECT_TIMER1 (1<<1)
  218. #define SNDRV_GF1_VFLG_PAN (1<<2)
  219. typedef enum {
  220. VENV_BEFORE,
  221. VENV_ATTACK,
  222. VENV_SUSTAIN,
  223. VENV_RELEASE,
  224. VENV_DONE,
  225. VENV_VOLUME
  226. } snd_gus_volume_state_t;
  227. struct _snd_gus_voice {
  228. int number;
  229. unsigned int use: 1,
  230. pcm: 1,
  231. synth:1,
  232. midi: 1;
  233. unsigned int flags;
  234. unsigned char client;
  235. unsigned char port;
  236. unsigned char index;
  237. unsigned char pad;
  238. #ifdef CONFIG_SND_DEBUG
  239. unsigned int interrupt_stat_wave;
  240. unsigned int interrupt_stat_volume;
  241. #endif
  242. void (*handler_wave) (snd_gus_card_t * gus, snd_gus_voice_t * voice);
  243. void (*handler_volume) (snd_gus_card_t * gus, snd_gus_voice_t * voice);
  244. void (*handler_effect) (snd_gus_card_t * gus, snd_gus_voice_t * voice);
  245. void (*volume_change) (snd_gus_card_t * gus);
  246. snd_gus_sample_ops_t *sample_ops;
  247. snd_seq_instr_t instr;
  248. /* running status / registers */
  249. snd_seq_ev_volume_t sample_volume;
  250. unsigned short fc_register;
  251. unsigned short fc_lfo;
  252. unsigned short gf1_volume;
  253. unsigned char control;
  254. unsigned char mode;
  255. unsigned char gf1_pan;
  256. unsigned char effect_accumulator;
  257. unsigned char volume_control;
  258. unsigned char venv_value_next;
  259. snd_gus_volume_state_t venv_state;
  260. snd_gus_volume_state_t venv_state_prev;
  261. unsigned short vlo;
  262. unsigned short vro;
  263. unsigned short gf1_effect_volume;
  264. /* --- */
  265. void *private_data;
  266. void (*private_free)(snd_gus_voice_t *voice);
  267. };
  268. struct _snd_gf1 {
  269. unsigned int enh_mode:1, /* enhanced mode (GFA1) */
  270. hw_lfo:1, /* use hardware LFO */
  271. sw_lfo:1, /* use software LFO */
  272. effect:1; /* use effect voices */
  273. unsigned long port; /* port of GF1 chip */
  274. struct resource *res_port1;
  275. struct resource *res_port2;
  276. int irq; /* IRQ number */
  277. int dma1; /* DMA1 number */
  278. int dma2; /* DMA2 number */
  279. unsigned int memory; /* GUS's DRAM size in bytes */
  280. unsigned int rom_memory; /* GUS's ROM size in bytes */
  281. unsigned int rom_present; /* bitmask */
  282. unsigned int rom_banks; /* GUS's ROM banks */
  283. snd_gf1_mem_t mem_alloc;
  284. /* registers */
  285. unsigned short reg_page;
  286. unsigned short reg_regsel;
  287. unsigned short reg_data8;
  288. unsigned short reg_data16;
  289. unsigned short reg_irqstat;
  290. unsigned short reg_dram;
  291. unsigned short reg_timerctrl;
  292. unsigned short reg_timerdata;
  293. unsigned char ics_regs[6][2];
  294. /* --------- */
  295. unsigned char active_voices; /* active voices */
  296. unsigned char active_voice; /* selected voice (GF1PAGE register) */
  297. snd_gus_voice_t voices[32]; /* GF1 voices */
  298. unsigned int default_voice_address;
  299. unsigned short playback_freq; /* GF1 playback (mixing) frequency */
  300. unsigned short mode; /* see to SNDRV_GF1_MODE_XXXX */
  301. unsigned char volume_ramp;
  302. unsigned char smooth_pan;
  303. unsigned char full_range_pan;
  304. unsigned char pad0;
  305. unsigned char *lfos;
  306. /* interrupt handlers */
  307. void (*interrupt_handler_midi_out) (snd_gus_card_t * gus);
  308. void (*interrupt_handler_midi_in) (snd_gus_card_t * gus);
  309. void (*interrupt_handler_timer1) (snd_gus_card_t * gus);
  310. void (*interrupt_handler_timer2) (snd_gus_card_t * gus);
  311. void (*interrupt_handler_dma_write) (snd_gus_card_t * gus);
  312. void (*interrupt_handler_dma_read) (snd_gus_card_t * gus);
  313. #ifdef CONFIG_SND_DEBUG
  314. unsigned int interrupt_stat_midi_out;
  315. unsigned int interrupt_stat_midi_in;
  316. unsigned int interrupt_stat_timer1;
  317. unsigned int interrupt_stat_timer2;
  318. unsigned int interrupt_stat_dma_write;
  319. unsigned int interrupt_stat_dma_read;
  320. unsigned int interrupt_stat_voice_lost;
  321. #endif
  322. /* synthesizer */
  323. int seq_client;
  324. snd_gus_port_t seq_ports[4];
  325. snd_seq_kinstr_list_t *ilist;
  326. snd_iwffff_ops_t iwffff_ops;
  327. snd_gf1_ops_t gf1_ops;
  328. snd_simple_ops_t simple_ops;
  329. /* timer */
  330. unsigned short timer_enabled;
  331. snd_timer_t *timer1;
  332. snd_timer_t *timer2;
  333. /* midi */
  334. unsigned short uart_cmd;
  335. unsigned int uart_framing;
  336. unsigned int uart_overrun;
  337. /* dma operations */
  338. unsigned int dma_flags;
  339. unsigned int dma_shared;
  340. snd_gf1_dma_block_t *dma_data_pcm;
  341. snd_gf1_dma_block_t *dma_data_pcm_last;
  342. snd_gf1_dma_block_t *dma_data_synth;
  343. snd_gf1_dma_block_t *dma_data_synth_last;
  344. void (*dma_ack)(snd_gus_card_t * gus, void *private_data);
  345. void *dma_private_data;
  346. /* pcm */
  347. int pcm_channels;
  348. int pcm_alloc_voices;
  349. unsigned short pcm_volume_level_left;
  350. unsigned short pcm_volume_level_right;
  351. unsigned short pcm_volume_level_left1;
  352. unsigned short pcm_volume_level_right1;
  353. unsigned char pcm_rcntrl_reg;
  354. unsigned char pad_end;
  355. };
  356. /* main structure for GUS card */
  357. struct _snd_gus_card {
  358. snd_card_t *card;
  359. unsigned int
  360. initialized: 1, /* resources were initialized */
  361. equal_irq:1, /* GF1 and CODEC shares IRQ (GUS MAX only) */
  362. equal_dma:1, /* if dma channels are equal (not valid for daughter board) */
  363. ics_flag:1, /* have we ICS mixer chip */
  364. ics_flipped:1, /* ICS mixer have flipped some channels? */
  365. codec_flag:1, /* have we CODEC chip? */
  366. max_flag:1, /* have we GUS MAX card? */
  367. max_ctrl_flag:1, /* have we original GUS MAX card? */
  368. daughter_flag:1, /* have we daughter board? */
  369. interwave:1, /* hey - we have InterWave card */
  370. ess_flag:1, /* ESS chip found... GUS Extreme */
  371. ace_flag:1, /* GUS ACE detected */
  372. uart_enable:1; /* enable MIDI UART */
  373. unsigned short revision; /* revision of chip */
  374. unsigned short max_cntrl_val; /* GUS MAX control value */
  375. unsigned short mix_cntrl_reg; /* mixer control register */
  376. unsigned short joystick_dac; /* joystick DAC level */
  377. int timer_dev; /* timer device */
  378. struct _snd_gf1 gf1; /* gf1 specific variables */
  379. snd_pcm_t *pcm;
  380. snd_pcm_substream_t *pcm_cap_substream;
  381. unsigned int c_dma_size;
  382. unsigned int c_period_size;
  383. unsigned int c_pos;
  384. snd_rawmidi_t *midi_uart;
  385. snd_rawmidi_substream_t *midi_substream_output;
  386. snd_rawmidi_substream_t *midi_substream_input;
  387. snd_seq_device_t *seq_dev;
  388. spinlock_t reg_lock;
  389. spinlock_t voice_alloc;
  390. spinlock_t active_voice_lock;
  391. spinlock_t event_lock;
  392. spinlock_t dma_lock;
  393. spinlock_t pcm_volume_level_lock;
  394. spinlock_t uart_cmd_lock;
  395. struct semaphore dma_mutex;
  396. struct semaphore register_mutex;
  397. };
  398. /* I/O functions for GF1/InterWave chip - gus_io.c */
  399. static inline void snd_gf1_select_voice(snd_gus_card_t * gus, int voice)
  400. {
  401. unsigned long flags;
  402. spin_lock_irqsave(&gus->active_voice_lock, flags);
  403. if (voice != gus->gf1.active_voice) {
  404. gus->gf1.active_voice = voice;
  405. outb(voice, GUSP(gus, GF1PAGE));
  406. }
  407. spin_unlock_irqrestore(&gus->active_voice_lock, flags);
  408. }
  409. static inline void snd_gf1_uart_cmd(snd_gus_card_t * gus, unsigned char b)
  410. {
  411. outb(gus->gf1.uart_cmd = b, GUSP(gus, MIDICTRL));
  412. }
  413. static inline unsigned char snd_gf1_uart_stat(snd_gus_card_t * gus)
  414. {
  415. return inb(GUSP(gus, MIDISTAT));
  416. }
  417. static inline void snd_gf1_uart_put(snd_gus_card_t * gus, unsigned char b)
  418. {
  419. outb(b, GUSP(gus, MIDIDATA));
  420. }
  421. static inline unsigned char snd_gf1_uart_get(snd_gus_card_t * gus)
  422. {
  423. return inb(GUSP(gus, MIDIDATA));
  424. }
  425. extern void snd_gf1_delay(snd_gus_card_t * gus);
  426. extern void snd_gf1_ctrl_stop(snd_gus_card_t * gus, unsigned char reg);
  427. extern void snd_gf1_write8(snd_gus_card_t * gus, unsigned char reg, unsigned char data);
  428. extern unsigned char snd_gf1_look8(snd_gus_card_t * gus, unsigned char reg);
  429. static inline unsigned char snd_gf1_read8(snd_gus_card_t * gus, unsigned char reg)
  430. {
  431. return snd_gf1_look8(gus, reg | 0x80);
  432. }
  433. extern void snd_gf1_write16(snd_gus_card_t * gus, unsigned char reg, unsigned int data);
  434. extern unsigned short snd_gf1_look16(snd_gus_card_t * gus, unsigned char reg);
  435. static inline unsigned short snd_gf1_read16(snd_gus_card_t * gus, unsigned char reg)
  436. {
  437. return snd_gf1_look16(gus, reg | 0x80);
  438. }
  439. extern void snd_gf1_adlib_write(snd_gus_card_t * gus, unsigned char reg, unsigned char data);
  440. extern void snd_gf1_dram_addr(snd_gus_card_t * gus, unsigned int addr);
  441. extern void snd_gf1_poke(snd_gus_card_t * gus, unsigned int addr, unsigned char data);
  442. extern unsigned char snd_gf1_peek(snd_gus_card_t * gus, unsigned int addr);
  443. extern void snd_gf1_write_addr(snd_gus_card_t * gus, unsigned char reg, unsigned int addr, short w_16bit);
  444. extern unsigned int snd_gf1_read_addr(snd_gus_card_t * gus, unsigned char reg, short w_16bit);
  445. extern void snd_gf1_i_ctrl_stop(snd_gus_card_t * gus, unsigned char reg);
  446. extern void snd_gf1_i_write8(snd_gus_card_t * gus, unsigned char reg, unsigned char data);
  447. extern unsigned char snd_gf1_i_look8(snd_gus_card_t * gus, unsigned char reg);
  448. extern void snd_gf1_i_write16(snd_gus_card_t * gus, unsigned char reg, unsigned int data);
  449. static inline unsigned char snd_gf1_i_read8(snd_gus_card_t * gus, unsigned char reg)
  450. {
  451. return snd_gf1_i_look8(gus, reg | 0x80);
  452. }
  453. extern unsigned short snd_gf1_i_look16(snd_gus_card_t * gus, unsigned char reg);
  454. static inline unsigned short snd_gf1_i_read16(snd_gus_card_t * gus, unsigned char reg)
  455. {
  456. return snd_gf1_i_look16(gus, reg | 0x80);
  457. }
  458. extern void snd_gf1_select_active_voices(snd_gus_card_t * gus);
  459. /* gus_lfo.c */
  460. struct _SND_IW_LFO_PROGRAM {
  461. unsigned short freq_and_control;
  462. unsigned char depth_final;
  463. unsigned char depth_inc;
  464. unsigned short twave;
  465. unsigned short depth;
  466. };
  467. #if 0
  468. extern irqreturn_t snd_gf1_lfo_effect_interrupt(snd_gus_card_t * gus, snd_gf1_voice_t * voice);
  469. #endif
  470. extern void snd_gf1_lfo_init(snd_gus_card_t * gus);
  471. extern void snd_gf1_lfo_done(snd_gus_card_t * gus);
  472. extern void snd_gf1_lfo_program(snd_gus_card_t * gus, int voice, int lfo_type, struct _SND_IW_LFO_PROGRAM *program);
  473. extern void snd_gf1_lfo_enable(snd_gus_card_t * gus, int voice, int lfo_type);
  474. extern void snd_gf1_lfo_disable(snd_gus_card_t * gus, int voice, int lfo_type);
  475. extern void snd_gf1_lfo_change_freq(snd_gus_card_t * gus, int voice, int lfo_type, int freq);
  476. extern void snd_gf1_lfo_change_depth(snd_gus_card_t * gus, int voice, int lfo_type, int depth);
  477. extern void snd_gf1_lfo_setup(snd_gus_card_t * gus, int voice, int lfo_type, int freq, int current_depth, int depth, int sweep, int shape);
  478. extern void snd_gf1_lfo_shutdown(snd_gus_card_t * gus, int voice, int lfo_type);
  479. #if 0
  480. extern void snd_gf1_lfo_command(snd_gus_card_t * gus, int voice, unsigned char *command);
  481. #endif
  482. /* gus_mem.c */
  483. void snd_gf1_mem_lock(snd_gf1_mem_t * alloc, int xup);
  484. int snd_gf1_mem_xfree(snd_gf1_mem_t * alloc, snd_gf1_mem_block_t * block);
  485. snd_gf1_mem_block_t *snd_gf1_mem_alloc(snd_gf1_mem_t * alloc, int owner,
  486. char *name, int size, int w_16,
  487. int align, unsigned int *share_id);
  488. int snd_gf1_mem_free(snd_gf1_mem_t * alloc, unsigned int address);
  489. int snd_gf1_mem_free_owner(snd_gf1_mem_t * alloc, int owner);
  490. int snd_gf1_mem_init(snd_gus_card_t * gus);
  491. int snd_gf1_mem_done(snd_gus_card_t * gus);
  492. /* gus_mem_proc.c */
  493. int snd_gf1_mem_proc_init(snd_gus_card_t * gus);
  494. /* gus_dma.c */
  495. int snd_gf1_dma_init(snd_gus_card_t * gus);
  496. int snd_gf1_dma_done(snd_gus_card_t * gus);
  497. int snd_gf1_dma_transfer_block(snd_gus_card_t * gus,
  498. snd_gf1_dma_block_t * block,
  499. int atomic,
  500. int synth);
  501. /* gus_volume.c */
  502. unsigned short snd_gf1_lvol_to_gvol_raw(unsigned int vol);
  503. unsigned short snd_gf1_translate_freq(snd_gus_card_t * gus, unsigned int freq2);
  504. /* gus_reset.c */
  505. void snd_gf1_set_default_handlers(snd_gus_card_t * gus, unsigned int what);
  506. void snd_gf1_smart_stop_voice(snd_gus_card_t * gus, unsigned short voice);
  507. void snd_gf1_stop_voice(snd_gus_card_t * gus, unsigned short voice);
  508. void snd_gf1_stop_voices(snd_gus_card_t * gus, unsigned short v_min, unsigned short v_max);
  509. snd_gus_voice_t *snd_gf1_alloc_voice(snd_gus_card_t * gus, int type, int client, int port);
  510. void snd_gf1_free_voice(snd_gus_card_t * gus, snd_gus_voice_t *voice);
  511. int snd_gf1_start(snd_gus_card_t * gus);
  512. int snd_gf1_stop(snd_gus_card_t * gus);
  513. /* gus_mixer.c */
  514. int snd_gf1_new_mixer(snd_gus_card_t * gus);
  515. /* gus_pcm.c */
  516. int snd_gf1_pcm_new(snd_gus_card_t * gus, int pcm_dev, int control_index, snd_pcm_t ** rpcm);
  517. #ifdef CONFIG_SND_DEBUG
  518. extern void snd_gf1_print_voice_registers(snd_gus_card_t * gus);
  519. #endif
  520. /* gus.c */
  521. int snd_gus_use_inc(snd_gus_card_t * gus);
  522. void snd_gus_use_dec(snd_gus_card_t * gus);
  523. int snd_gus_create(snd_card_t * card,
  524. unsigned long port,
  525. int irq, int dma1, int dma2,
  526. int timer_dev,
  527. int voices,
  528. int pcm_channels,
  529. int effect,
  530. snd_gus_card_t ** rgus);
  531. int snd_gus_initialize(snd_gus_card_t * gus);
  532. /* gus_irq.c */
  533. irqreturn_t snd_gus_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  534. #ifdef CONFIG_SND_DEBUG
  535. void snd_gus_irq_profile_init(snd_gus_card_t *gus);
  536. #endif
  537. /* gus_uart.c */
  538. int snd_gf1_rawmidi_new(snd_gus_card_t * gus, int device, snd_rawmidi_t **rrawmidi);
  539. #if 0
  540. extern void snd_engine_instrument_register(unsigned short mode,
  541. struct _SND_INSTRUMENT_VOICE_COMMANDS *voice_cmds,
  542. struct _SND_INSTRUMENT_NOTE_COMMANDS *note_cmds,
  543. struct _SND_INSTRUMENT_CHANNEL_COMMANDS *channel_cmds);
  544. extern int snd_engine_instrument_register_ask(unsigned short mode);
  545. #endif
  546. /* gus_dram.c */
  547. int snd_gus_dram_write(snd_gus_card_t *gus, char __user *ptr,
  548. unsigned int addr, unsigned int size);
  549. int snd_gus_dram_read(snd_gus_card_t *gus, char __user *ptr,
  550. unsigned int addr, unsigned int size, int rom);
  551. #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
  552. /* gus_sample.c */
  553. void snd_gus_sample_event(snd_seq_event_t *ev, snd_gus_port_t *p);
  554. /* gus_simple.c */
  555. void snd_gf1_simple_init(snd_gus_voice_t *voice);
  556. /* gus_instr.c */
  557. int snd_gus_iwffff_put_sample(void *private_data, iwffff_wave_t *wave,
  558. char __user *data, long len, int atomic);
  559. int snd_gus_iwffff_get_sample(void *private_data, iwffff_wave_t *wave,
  560. char __user *data, long len, int atomic);
  561. int snd_gus_iwffff_remove_sample(void *private_data, iwffff_wave_t *wave,
  562. int atomic);
  563. int snd_gus_gf1_put_sample(void *private_data, gf1_wave_t *wave,
  564. char __user *data, long len, int atomic);
  565. int snd_gus_gf1_get_sample(void *private_data, gf1_wave_t *wave,
  566. char __user *data, long len, int atomic);
  567. int snd_gus_gf1_remove_sample(void *private_data, gf1_wave_t *wave,
  568. int atomic);
  569. int snd_gus_simple_put_sample(void *private_data, simple_instrument_t *instr,
  570. char __user *data, long len, int atomic);
  571. int snd_gus_simple_get_sample(void *private_data, simple_instrument_t *instr,
  572. char __user *data, long len, int atomic);
  573. int snd_gus_simple_remove_sample(void *private_data, simple_instrument_t *instr,
  574. int atomic);
  575. #endif /* CONFIG_SND_SEQUENCER */
  576. #endif /* __SOUND_GUS_H */