~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/sound/sb_midi.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.