x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / sound / firewire / oxfw / oxfw-midi.c
blobb7bbd77dfff179581120489a2d85a2127fd7773c
1 /*
2 * oxfw_midi.c - a part of driver for OXFW970/971 based devices
4 * Copyright (c) 2014 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
9 #include "oxfw.h"
11 static int midi_capture_open(struct snd_rawmidi_substream *substream)
13 struct snd_oxfw *oxfw = substream->rmidi->private_data;
14 int err;
16 err = snd_oxfw_stream_lock_try(oxfw);
17 if (err < 0)
18 return err;
20 mutex_lock(&oxfw->mutex);
22 oxfw->capture_substreams++;
23 err = snd_oxfw_stream_start_simplex(oxfw, &oxfw->tx_stream, 0, 0);
25 mutex_unlock(&oxfw->mutex);
27 if (err < 0)
28 snd_oxfw_stream_lock_release(oxfw);
30 return err;
33 static int midi_playback_open(struct snd_rawmidi_substream *substream)
35 struct snd_oxfw *oxfw = substream->rmidi->private_data;
36 int err;
38 err = snd_oxfw_stream_lock_try(oxfw);
39 if (err < 0)
40 return err;
42 mutex_lock(&oxfw->mutex);
44 oxfw->playback_substreams++;
45 err = snd_oxfw_stream_start_simplex(oxfw, &oxfw->rx_stream, 0, 0);
47 mutex_unlock(&oxfw->mutex);
49 if (err < 0)
50 snd_oxfw_stream_lock_release(oxfw);
52 return err;
55 static int midi_capture_close(struct snd_rawmidi_substream *substream)
57 struct snd_oxfw *oxfw = substream->rmidi->private_data;
59 mutex_lock(&oxfw->mutex);
61 oxfw->capture_substreams--;
62 snd_oxfw_stream_stop_simplex(oxfw, &oxfw->tx_stream);
64 mutex_unlock(&oxfw->mutex);
66 snd_oxfw_stream_lock_release(oxfw);
67 return 0;
70 static int midi_playback_close(struct snd_rawmidi_substream *substream)
72 struct snd_oxfw *oxfw = substream->rmidi->private_data;
74 mutex_lock(&oxfw->mutex);
76 oxfw->playback_substreams--;
77 snd_oxfw_stream_stop_simplex(oxfw, &oxfw->rx_stream);
79 mutex_unlock(&oxfw->mutex);
81 snd_oxfw_stream_lock_release(oxfw);
82 return 0;
85 static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
87 struct snd_oxfw *oxfw = substrm->rmidi->private_data;
88 unsigned long flags;
90 spin_lock_irqsave(&oxfw->lock, flags);
92 if (up)
93 amdtp_am824_midi_trigger(&oxfw->tx_stream,
94 substrm->number, substrm);
95 else
96 amdtp_am824_midi_trigger(&oxfw->tx_stream,
97 substrm->number, NULL);
99 spin_unlock_irqrestore(&oxfw->lock, flags);
102 static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
104 struct snd_oxfw *oxfw = substrm->rmidi->private_data;
105 unsigned long flags;
107 spin_lock_irqsave(&oxfw->lock, flags);
109 if (up)
110 amdtp_am824_midi_trigger(&oxfw->rx_stream,
111 substrm->number, substrm);
112 else
113 amdtp_am824_midi_trigger(&oxfw->rx_stream,
114 substrm->number, NULL);
116 spin_unlock_irqrestore(&oxfw->lock, flags);
119 static void set_midi_substream_names(struct snd_oxfw *oxfw,
120 struct snd_rawmidi_str *str)
122 struct snd_rawmidi_substream *subs;
124 list_for_each_entry(subs, &str->substreams, list) {
125 snprintf(subs->name, sizeof(subs->name),
126 "%s MIDI %d",
127 oxfw->card->shortname, subs->number + 1);
131 int snd_oxfw_create_midi(struct snd_oxfw *oxfw)
133 static const struct snd_rawmidi_ops capture_ops = {
134 .open = midi_capture_open,
135 .close = midi_capture_close,
136 .trigger = midi_capture_trigger,
138 static const struct snd_rawmidi_ops playback_ops = {
139 .open = midi_playback_open,
140 .close = midi_playback_close,
141 .trigger = midi_playback_trigger,
143 struct snd_rawmidi *rmidi;
144 struct snd_rawmidi_str *str;
145 int err;
147 if (oxfw->midi_input_ports == 0 && oxfw->midi_output_ports == 0)
148 return 0;
150 /* create midi ports */
151 err = snd_rawmidi_new(oxfw->card, oxfw->card->driver, 0,
152 oxfw->midi_output_ports, oxfw->midi_input_ports,
153 &rmidi);
154 if (err < 0)
155 return err;
157 snprintf(rmidi->name, sizeof(rmidi->name),
158 "%s MIDI", oxfw->card->shortname);
159 rmidi->private_data = oxfw;
161 if (oxfw->midi_input_ports > 0) {
162 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
164 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
165 &capture_ops);
167 str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT];
169 set_midi_substream_names(oxfw, str);
172 if (oxfw->midi_output_ports > 0) {
173 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
175 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
176 &playback_ops);
178 str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT];
180 set_midi_substream_names(oxfw, str);
183 if ((oxfw->midi_output_ports > 0) && (oxfw->midi_input_ports > 0))
184 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;
186 return 0;