OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [sound/] [gus_midi.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 * sound/gus2_midi.c
3
 *
4
 * The low level driver for the GUS Midi Interface.
5
 */
6
/*
7
 * Copyright (C) by Hannu Savolainen 1993-1996
8
 *
9
 * USS/Lite for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10
 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11
 * for more info.
12
 */
13
#include <linux/config.h>
14
 
15
 
16
#include "sound_config.h"
17
 
18
#include "gus_hw.h"
19
 
20
#if defined(CONFIG_GUS) && defined(CONFIG_MIDI)
21
 
22
static int      midi_busy = 0, input_opened = 0;
23
static int      my_dev;
24
static int      output_used = 0;
25
static volatile unsigned char gus_midi_control;
26
 
27
static void     (*midi_input_intr) (int dev, unsigned char data);
28
 
29
static unsigned char tmp_queue[256];
30
static volatile int qlen;
31
static volatile unsigned char qhead, qtail;
32
extern int      gus_base, gus_irq, gus_dma;
33
extern int     *gus_osp;
34
 
35
static int
36
GUS_MIDI_STATUS (void)
37
{
38
  return inb (u_MidiStatus);
39
}
40
 
41
static int
42
gus_midi_open (int dev, int mode,
43
               void            (*input) (int dev, unsigned char data),
44
               void            (*output) (int dev)
45
)
46
{
47
 
48
  if (midi_busy)
49
    {
50
      printk ("GUS: Midi busy\n");
51
      return -(EBUSY);
52
    }
53
 
54
  outb (MIDI_RESET, u_MidiControl);
55
  gus_delay ();
56
 
57
  gus_midi_control = 0;
58
  input_opened = 0;
59
 
60
  if (mode == OPEN_READ || mode == OPEN_READWRITE)
61
    {
62
      gus_midi_control |= MIDI_ENABLE_RCV;
63
      input_opened = 1;
64
    }
65
 
66
 
67
  outb (gus_midi_control, u_MidiControl);       /* Enable */
68
 
69
  midi_busy = 1;
70
  qlen = qhead = qtail = output_used = 0;
71
  midi_input_intr = input;
72
 
73
  return 0;
74
}
75
 
76
static int
77
dump_to_midi (unsigned char midi_byte)
78
{
79
  unsigned long   flags;
80
  int             ok = 0;
81
 
82
  output_used = 1;
83
 
84
  save_flags (flags);
85
  cli ();
86
 
87
  if (GUS_MIDI_STATUS () & MIDI_XMIT_EMPTY)
88
    {
89
      ok = 1;
90
      outb (midi_byte, u_MidiData);
91
    }
92
  else
93
    {
94
      /*
95
       * Enable Midi xmit interrupts (again)
96
       */
97
      gus_midi_control |= MIDI_ENABLE_XMIT;
98
      outb (gus_midi_control, u_MidiControl);
99
    }
100
 
101
  restore_flags (flags);
102
  return ok;
103
}
104
 
105
static void
106
gus_midi_close (int dev)
107
{
108
  /*
109
   * Reset FIFO pointers, disable intrs
110
   */
111
 
112
  outb (MIDI_RESET, u_MidiControl);
113
  midi_busy = 0;
114
}
115
 
116
static int
117
gus_midi_out (int dev, unsigned char midi_byte)
118
{
119
 
120
  unsigned long   flags;
121
 
122
  /*
123
   * Drain the local queue first
124
   */
125
 
126
  save_flags (flags);
127
  cli ();
128
 
129
  while (qlen && dump_to_midi (tmp_queue[qhead]))
130
    {
131
      qlen--;
132
      qhead++;
133
    }
134
 
135
  restore_flags (flags);
136
 
137
  /*
138
   * Output the byte if the local queue is empty.
139
   */
140
 
141
  if (!qlen)
142
    if (dump_to_midi (midi_byte))
143
      return 1;                 /*
144
                                 * OK
145
                                 */
146
 
147
  /*
148
   * Put to the local queue
149
   */
150
 
151
  if (qlen >= 256)
152
    return 0;                    /*
153
                                 * Local queue full
154
                                 */
155
 
156
  save_flags (flags);
157
  cli ();
158
 
159
  tmp_queue[qtail] = midi_byte;
160
  qlen++;
161
  qtail++;
162
 
163
  restore_flags (flags);
164
 
165
  return 1;
166
}
167
 
168
static int
169
gus_midi_start_read (int dev)
170
{
171
  return 0;
172
}
173
 
174
static int
175
gus_midi_end_read (int dev)
176
{
177
  return 0;
178
}
179
 
180
static int
181
gus_midi_ioctl (int dev, unsigned cmd, caddr_t arg)
182
{
183
  return -(EINVAL);
184
}
185
 
186
static void
187
gus_midi_kick (int dev)
188
{
189
}
190
 
191
static int
192
gus_midi_buffer_status (int dev)
193
{
194
  unsigned long   flags;
195
 
196
  if (!output_used)
197
    return 0;
198
 
199
  save_flags (flags);
200
  cli ();
201
 
202
  if (qlen && dump_to_midi (tmp_queue[qhead]))
203
    {
204
      qlen--;
205
      qhead++;
206
    }
207
 
208
  restore_flags (flags);
209
 
210
  return (qlen > 0) | !(GUS_MIDI_STATUS () & MIDI_XMIT_EMPTY);
211
}
212
 
213
#define MIDI_SYNTH_NAME "Gravis Ultrasound Midi"
214
#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
215
#include "midi_synth.h"
216
 
217
static struct midi_operations gus_midi_operations =
218
{
219
  {"Gravis UltraSound Midi", 0, 0, SNDCARD_GUS},
220
  &std_midi_synth,
221
  {0},
222
  gus_midi_open,
223
  gus_midi_close,
224
  gus_midi_ioctl,
225
  gus_midi_out,
226
  gus_midi_start_read,
227
  gus_midi_end_read,
228
  gus_midi_kick,
229
  NULL,                         /*
230
                                 * command
231
                                 */
232
  gus_midi_buffer_status,
233
  NULL
234
};
235
 
236
void
237
gus_midi_init (void)
238
{
239
  if (num_midis >= MAX_MIDI_DEV)
240
    {
241
      printk ("Sound: Too many midi devices detected\n");
242
      return;
243
    }
244
 
245
  outb (MIDI_RESET, u_MidiControl);
246
 
247
  std_midi_synth.midi_dev = my_dev = num_midis;
248
  midi_devs[num_midis++] = &gus_midi_operations;
249
  return;
250
}
251
 
252
void
253
gus_midi_interrupt (int dummy)
254
{
255
  volatile unsigned char stat, data;
256
  unsigned long   flags;
257
  int             timeout = 10;
258
 
259
  save_flags (flags);
260
  cli ();
261
 
262
  while (timeout-- > 0 && (stat = GUS_MIDI_STATUS ()) & (MIDI_RCV_FULL | MIDI_XMIT_EMPTY))
263
    {
264
      if (stat & MIDI_RCV_FULL)
265
        {
266
          data = inb (u_MidiData);
267
          if (input_opened)
268
            midi_input_intr (my_dev, data);
269
        }
270
 
271
      if (stat & MIDI_XMIT_EMPTY)
272
        {
273
          while (qlen && dump_to_midi (tmp_queue[qhead]))
274
            {
275
              qlen--;
276
              qhead++;
277
            }
278
 
279
          if (!qlen)
280
            {
281
              /*
282
               * Disable Midi output interrupts, since no data in the buffer
283
               */
284
              gus_midi_control &= ~MIDI_ENABLE_XMIT;
285
              outb (gus_midi_control, u_MidiControl);
286
              outb (gus_midi_control, u_MidiControl);
287
            }
288
        }
289
 
290
    }
291
 
292
  restore_flags (flags);
293
}
294
 
295
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.