sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / firewire / tascam / tascam-midi.c
blob41f842079d9ddff8b2ab8a41eb470d06c3c1cf2b
1 /*
2 * tascam-midi.c - a part of driver for TASCAM FireWire series
4 * Copyright (c) 2015 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
9 #include "tascam.h"
11 static int midi_capture_open(struct snd_rawmidi_substream *substream)
13 /* Do nothing. */
14 return 0;
17 static int midi_playback_open(struct snd_rawmidi_substream *substream)
19 struct snd_tscm *tscm = substream->rmidi->private_data;
21 /* Initialize internal status. */
22 tscm->running_status[substream->number] = 0;
23 tscm->on_sysex[substream->number] = 0;
24 return 0;
27 static int midi_capture_close(struct snd_rawmidi_substream *substream)
29 /* Do nothing. */
30 return 0;
33 static int midi_playback_close(struct snd_rawmidi_substream *substream)
35 struct snd_tscm *tscm = substream->rmidi->private_data;
37 snd_fw_async_midi_port_finish(&tscm->out_ports[substream->number]);
39 return 0;
42 static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
44 struct snd_tscm *tscm = substrm->rmidi->private_data;
45 unsigned long flags;
47 spin_lock_irqsave(&tscm->lock, flags);
49 if (up)
50 tscm->tx_midi_substreams[substrm->number] = substrm;
51 else
52 tscm->tx_midi_substreams[substrm->number] = NULL;
54 spin_unlock_irqrestore(&tscm->lock, flags);
57 static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
59 struct snd_tscm *tscm = substrm->rmidi->private_data;
60 unsigned long flags;
62 spin_lock_irqsave(&tscm->lock, flags);
64 if (up)
65 snd_fw_async_midi_port_run(&tscm->out_ports[substrm->number],
66 substrm);
68 spin_unlock_irqrestore(&tscm->lock, flags);
71 static struct snd_rawmidi_ops midi_capture_ops = {
72 .open = midi_capture_open,
73 .close = midi_capture_close,
74 .trigger = midi_capture_trigger,
77 static struct snd_rawmidi_ops midi_playback_ops = {
78 .open = midi_playback_open,
79 .close = midi_playback_close,
80 .trigger = midi_playback_trigger,
83 int snd_tscm_create_midi_devices(struct snd_tscm *tscm)
85 struct snd_rawmidi *rmidi;
86 struct snd_rawmidi_str *stream;
87 struct snd_rawmidi_substream *subs;
88 int err;
90 err = snd_rawmidi_new(tscm->card, tscm->card->driver, 0,
91 tscm->spec->midi_playback_ports,
92 tscm->spec->midi_capture_ports,
93 &rmidi);
94 if (err < 0)
95 return err;
97 snprintf(rmidi->name, sizeof(rmidi->name),
98 "%s MIDI", tscm->card->shortname);
99 rmidi->private_data = tscm;
101 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
102 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
103 &midi_capture_ops);
104 stream = &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT];
106 /* Set port names for MIDI input. */
107 list_for_each_entry(subs, &stream->substreams, list) {
108 /* TODO: support virtual MIDI ports. */
109 if (subs->number < tscm->spec->midi_capture_ports) {
110 /* Hardware MIDI ports. */
111 snprintf(subs->name, sizeof(subs->name),
112 "%s MIDI %d",
113 tscm->card->shortname, subs->number + 1);
117 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
118 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
119 &midi_playback_ops);
120 stream = &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT];
122 /* Set port names for MIDI ourput. */
123 list_for_each_entry(subs, &stream->substreams, list) {
124 if (subs->number < tscm->spec->midi_playback_ports) {
125 /* Hardware MIDI ports only. */
126 snprintf(subs->name, sizeof(subs->name),
127 "%s MIDI %d",
128 tscm->card->shortname, subs->number + 1);
132 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;
134 return 0;