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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 * sound/sb_dsp.c
3
 *
4
 * The low level driver for the Sound Blaster DS chips.
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
#if defined(CONFIG_SBDSP) && defined(CONFIG_MIDI)
19
 
20
#include "sb.h"
21
#undef SB_TEST_IRQ
22
 
23
/*
24
 * The DSP channel can be used either for input or output. Variable
25
 * 'sb_irq_mode' will be set when the program calls read or write first time
26
 * after open. Current version doesn't support mode changes without closing
27
 * and reopening the device. Support for this feature may be implemented in a
28
 * future version of this driver.
29
 */
30
 
31
void            (*midi_input_intr) (int dev, unsigned char data);
32
 
33
static int
34
sb_midi_open (int dev, int mode,
35
              void            (*input) (int dev, unsigned char data),
36
              void            (*output) (int dev)
37
)
38
{
39
  sb_devc        *devc = midi_devs[dev]->devc;
40
  unsigned long   flags;
41
 
42
  if (devc == NULL)
43
    return -(ENXIO);
44
 
45
  save_flags (flags);
46
  cli ();
47
  if (devc->opened)
48
    {
49
      restore_flags (flags);
50
      return -(EBUSY);
51
    }
52
  devc->opened = 1;
53
  restore_flags (flags);
54
 
55
  devc->irq_mode = IMODE_MIDI;
56
 
57
  sb_dsp_reset (devc);
58
 
59
  if (!sb_dsp_command (devc, 0x35))     /* Start MIDI UART mode */
60
    {
61
      devc->opened = 0;
62
      return -(EIO);
63
    }
64
 
65
  devc->intr_active = 1;
66
 
67
  if (mode & OPEN_READ)
68
    {
69
      devc->input_opened = 1;
70
      devc->midi_input_intr = input;
71
    }
72
 
73
  return 0;
74
}
75
 
76
static void
77
sb_midi_close (int dev)
78
{
79
  sb_devc        *devc = midi_devs[dev]->devc;
80
  unsigned long   flags;
81
 
82
  if (devc == NULL)
83
    return;
84
 
85
  save_flags (flags);
86
  cli ();
87
  sb_dsp_reset (devc);
88
  devc->intr_active = 0;
89
  devc->input_opened = 0;
90
  devc->opened = 0;
91
  restore_flags (flags);
92
}
93
 
94
static int
95
sb_midi_out (int dev, unsigned char midi_byte)
96
{
97
  sb_devc        *devc = midi_devs[dev]->devc;
98
 
99
  if (devc == NULL)
100
    return -(ENXIO);
101
 
102
  sb_dsp_command (devc, midi_byte);
103
 
104
  return 1;
105
}
106
 
107
static int
108
sb_midi_start_read (int dev)
109
{
110
  return 0;
111
}
112
 
113
static int
114
sb_midi_end_read (int dev)
115
{
116
  sb_devc        *devc = midi_devs[dev]->devc;
117
 
118
  if (devc == NULL)
119
    return -(ENXIO);
120
 
121
  sb_dsp_reset (devc);
122
  devc->intr_active = 0;
123
  return 0;
124
}
125
 
126
static int
127
sb_midi_ioctl (int dev, unsigned cmd, caddr_t arg)
128
{
129
  return -(EPERM);
130
}
131
 
132
void
133
sb_midi_interrupt (sb_devc * devc)
134
{
135
  unsigned long   flags;
136
  unsigned char   data;
137
 
138
  if (devc == NULL)
139
    return;
140
 
141
  save_flags (flags);
142
  cli ();
143
 
144
  data = inb (DSP_READ);
145
  if (devc->input_opened)
146
    devc->midi_input_intr (devc->my_mididev, data);
147
 
148
  restore_flags (flags);
149
}
150
 
151
#define MIDI_SYNTH_NAME "Sound Blaster Midi"
152
#define MIDI_SYNTH_CAPS 0
153
#include "midi_synth.h"
154
 
155
static struct midi_operations sb_midi_operations =
156
{
157
  {"Sound Blaster", 0, 0, SNDCARD_SB},
158
  &std_midi_synth,
159
  {0},
160
  sb_midi_open,
161
  sb_midi_close,
162
  sb_midi_ioctl,
163
  sb_midi_out,
164
  sb_midi_start_read,
165
  sb_midi_end_read,
166
  NULL,
167
  NULL,
168
  NULL,
169
  NULL
170
};
171
 
172
void
173
sb_dsp_midi_init (sb_devc * devc)
174
{
175
  if (devc->model < 2)          /* No MIDI support for SB 1.x */
176
    return;
177
 
178
  if (num_midis >= MAX_MIDI_DEV)
179
    {
180
      printk ("Sound: Too many midi devices detected\n");
181
      return;
182
    }
183
 
184
  std_midi_synth.midi_dev = num_midis;
185
  devc->my_mididev = num_midis;
186
 
187
  std_midi_synth.midi_dev = devc->my_mididev = num_midis;
188
 
189
 
190
  midi_devs[num_midis] = (struct midi_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc (sizeof (struct midi_operations)));
191
 
192
  if (sound_nblocks < 1024)
193
    sound_nblocks++;;
194
  if (midi_devs[num_midis] == NULL)
195
    {
196
      printk ("sb MIDI: Failed to allocate memory\n");
197
      return;
198
    }
199
 
200
  memcpy ((char *) midi_devs[num_midis], (char *) &sb_midi_operations,
201
          sizeof (struct midi_operations));
202
 
203
  midi_devs[num_midis]->devc = devc;
204
 
205
 
206
  midi_devs[num_midis]->converter = (struct synth_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc (sizeof (struct synth_operations)));
207
 
208
  if (sound_nblocks < 1024)
209
    sound_nblocks++;;
210
 
211
  if (midi_devs[num_midis]->converter == NULL)
212
    {
213
      printk ("sb MIDI: Failed to allocate memory\n");
214
      return;
215
    }
216
 
217
  memcpy ((char *) midi_devs[num_midis]->converter, (char *) &std_midi_synth,
218
          sizeof (struct synth_operations));
219
 
220
  num_midis++;
221
}
222
 
223
#endif

powered by: WebSVN 2.1.0

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