^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Line 6 Linux USB driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <sound/rawmidi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "driver.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "midi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define line6_rawmidi_substream_midi(substream) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ((struct snd_line6_midi *)((substream)->rmidi->private_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static int send_midi_async(struct usb_line6 *line6, unsigned char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) int length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) Pass data received via USB to MIDI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) void line6_midi_receive(struct usb_line6 *line6, unsigned char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (line6->line6midi->substream_receive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) snd_rawmidi_receive(line6->line6midi->substream_receive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) data, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) Read data from MIDI buffer and transmit them via USB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static void line6_midi_transmit(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct usb_line6 *line6 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) line6_rawmidi_substream_midi(substream)->line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct snd_line6_midi *line6midi = line6->line6midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct midi_buffer *mb = &line6midi->midibuf_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned char chunk[LINE6_FALLBACK_MAXPACKETSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int req, done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) req = min(line6_midibuf_bytes_free(mb), line6->max_packet_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) done = snd_rawmidi_transmit_peek(substream, chunk, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (done == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) line6_midibuf_write(mb, chunk, done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) snd_rawmidi_transmit_ack(substream, done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) done = line6_midibuf_read(mb, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) LINE6_FALLBACK_MAXPACKETSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (done == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) send_midi_async(line6, chunk, done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) Notification of completion of MIDI transmission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static void midi_sent(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) kfree(urb->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (status == -ESHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) spin_lock_irqsave(&line6->line6midi->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) num = --line6->line6midi->num_active_send_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (num == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) line6_midi_transmit(line6->line6midi->substream_transmit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) num = line6->line6midi->num_active_send_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (num == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) wake_up(&line6->line6midi->send_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) spin_unlock_irqrestore(&line6->line6midi->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) Send an asynchronous MIDI message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) Assumes that line6->line6midi->lock is held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) (i.e., this function is serialized).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int send_midi_async(struct usb_line6 *line6, unsigned char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned char *transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) urb = usb_alloc_urb(0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (urb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) transfer_buffer = kmemdup(data, length, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (transfer_buffer == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) usb_fill_int_urb(urb, line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) usb_sndintpipe(line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) line6->properties->ep_ctrl_w),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) transfer_buffer, length, midi_sent, line6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) line6->interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) urb->actual_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) retval = usb_urb_ep_type_check(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) retval = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ++line6->line6midi->num_active_send_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) dev_err(line6->ifcdev, "usb_submit_urb failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int line6_midi_output_open(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int line6_midi_output_close(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static void line6_midi_output_trigger(struct snd_rawmidi_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct usb_line6 *line6 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) line6_rawmidi_substream_midi(substream)->line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) line6->line6midi->substream_transmit = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) spin_lock_irqsave(&line6->line6midi->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (line6->line6midi->num_active_send_urbs == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) line6_midi_transmit(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) spin_unlock_irqrestore(&line6->line6midi->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static void line6_midi_output_drain(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct usb_line6 *line6 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) line6_rawmidi_substream_midi(substream)->line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct snd_line6_midi *midi = line6->line6midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) wait_event_interruptible(midi->send_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) midi->num_active_send_urbs == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static int line6_midi_input_open(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static int line6_midi_input_close(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static void line6_midi_input_trigger(struct snd_rawmidi_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct usb_line6 *line6 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) line6_rawmidi_substream_midi(substream)->line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) line6->line6midi->substream_receive = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) line6->line6midi->substream_receive = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static const struct snd_rawmidi_ops line6_midi_output_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .open = line6_midi_output_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) .close = line6_midi_output_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) .trigger = line6_midi_output_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .drain = line6_midi_output_drain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static const struct snd_rawmidi_ops line6_midi_input_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) .open = line6_midi_input_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) .close = line6_midi_input_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) .trigger = line6_midi_input_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* Create a MIDI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static int snd_line6_new_midi(struct usb_line6 *line6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct snd_rawmidi **rmidi_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct snd_rawmidi *rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) err = snd_rawmidi_new(line6->card, "Line 6 MIDI", 0, 1, 1, rmidi_ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) rmidi = *rmidi_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) strcpy(rmidi->id, line6->properties->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) strcpy(rmidi->name, line6->properties->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) rmidi->info_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) SNDRV_RAWMIDI_INFO_OUTPUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) &line6_midi_output_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) &line6_midi_input_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* MIDI device destructor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static void snd_line6_midi_free(struct snd_rawmidi *rmidi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct snd_line6_midi *line6midi = rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) line6_midibuf_destroy(&line6midi->midibuf_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) line6_midibuf_destroy(&line6midi->midibuf_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) kfree(line6midi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) Initialize the Line 6 MIDI subsystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int line6_init_midi(struct usb_line6 *line6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct snd_rawmidi *rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct snd_line6_midi *line6midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (!(line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* skip MIDI initialization and report success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) err = snd_line6_new_midi(line6, &rmidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) line6midi = kzalloc(sizeof(struct snd_line6_midi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (!line6midi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) rmidi->private_data = line6midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) rmidi->private_free = snd_line6_midi_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) init_waitqueue_head(&line6midi->send_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) spin_lock_init(&line6midi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) line6midi->line6 = line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) err = line6_midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) line6->line6midi = line6midi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) EXPORT_SYMBOL_GPL(line6_init_midi);