cregit-Linux how code gets into the kernel

Release 4.11 sound/usb/line6/midi.c

Directory: sound/usb/line6
/*
 * Line 6 Linux USB driver
 *
 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
 *
 *      This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License as
 *      published by the Free Software Foundation, version 2.
 *
 */

#include <linux/slab.h>
#include <linux/usb.h>
#include <linux/export.h>
#include <sound/core.h>
#include <sound/rawmidi.h>

#include "driver.h"
#include "midi.h"


#define line6_rawmidi_substream_midi(substream) \
	((struct snd_line6_midi *)((substream)->rmidi->private_data))

static int send_midi_async(struct usb_line6 *line6, unsigned char *data,
			   int length);

/*
        Pass data received via USB to MIDI.
*/

void line6_midi_receive(struct usb_line6 *line6, unsigned char *data, int length) { if (line6->line6midi->substream_receive) snd_rawmidi_receive(line6->line6midi->substream_receive, data, length); }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner39100.00%1100.00%
Total39100.00%1100.00%

/* Read data from MIDI buffer and transmit them via USB. */
static void line6_midi_transmit(struct snd_rawmidi_substream *substream) { struct usb_line6 *line6 = line6_rawmidi_substream_midi(substream)->line6; struct snd_line6_midi *line6midi = line6->line6midi; struct midi_buffer *mb = &line6midi->midibuf_out; unsigned char chunk[LINE6_FALLBACK_MAXPACKETSIZE]; int req, done; for (;;) { req = min(line6_midibuf_bytes_free(mb), line6->max_packet_size); done = snd_rawmidi_transmit_peek(substream, chunk, req); if (done == 0) break; line6_midibuf_write(mb, chunk, done); snd_rawmidi_transmit_ack(substream, done); } for (;;) { done = line6_midibuf_read(mb, chunk, LINE6_FALLBACK_MAXPACKETSIZE); if (done == 0) break; send_midi_async(line6, chunk, done); } }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner14097.90%250.00%
Himangi Saraogi21.40%125.00%
Stefan Hajnoczi10.70%125.00%
Total143100.00%4100.00%

/* Notification of completion of MIDI transmission. */
static void midi_sent(struct urb *urb) { unsigned long flags; int status; int num; struct usb_line6 *line6 = (struct usb_line6 *)urb->context; status = urb->status; kfree(urb->transfer_buffer); usb_free_urb(urb); if (status == -ESHUTDOWN) return; spin_lock_irqsave(&line6->line6midi->lock, flags); num = --line6->line6midi->num_active_send_urbs; if (num == 0) { line6_midi_transmit(line6->line6midi->substream_transmit); num = line6->line6midi->num_active_send_urbs; } if (num == 0) wake_up(&line6->line6midi->send_wait); spin_unlock_irqrestore(&line6->line6midi->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner13398.52%266.67%
Takashi Iwai21.48%133.33%
Total135100.00%3100.00%

/* Send an asynchronous MIDI message. Assumes that line6->line6midi->lock is held (i.e., this function is serialized). */
static int send_midi_async(struct usb_line6 *line6, unsigned char *data, int length) { struct urb *urb; int retval; unsigned char *transfer_buffer; urb = usb_alloc_urb(0, GFP_ATOMIC); if (urb == NULL) return -ENOMEM; transfer_buffer = kmemdup(data, length, GFP_ATOMIC); if (transfer_buffer == NULL) { usb_free_urb(urb); return -ENOMEM; } usb_fill_int_urb(urb, line6->usbdev, usb_sndbulkpipe(line6->usbdev, line6->properties->ep_ctrl_w), transfer_buffer, length, midi_sent, line6, line6->interval); urb->actual_length = 0; retval = usb_submit_urb(urb, GFP_ATOMIC); if (retval < 0) { dev_err(line6->ifcdev, "usb_submit_urb failed\n"); usb_free_urb(urb); return retval; } ++line6->line6midi->num_active_send_urbs; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner15494.48%120.00%
Chris Rorvick31.84%120.00%
Thomas Meyer31.84%120.00%
Peter Hüwe21.23%120.00%
Ashvini Varatharaj10.61%120.00%
Total163100.00%5100.00%


static int line6_midi_output_open(struct snd_rawmidi_substream *substream) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner14100.00%1100.00%
Total14100.00%1100.00%


static int line6_midi_output_close(struct snd_rawmidi_substream *substream) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner14100.00%1100.00%
Total14100.00%1100.00%


static void line6_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) { unsigned long flags; struct usb_line6 *line6 = line6_rawmidi_substream_midi(substream)->line6; line6->line6midi->substream_transmit = substream; spin_lock_irqsave(&line6->line6midi->lock, flags); if (line6->line6midi->num_active_send_urbs == 0) line6_midi_transmit(substream); spin_unlock_irqrestore(&line6->line6midi->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner7597.40%150.00%
Takashi Iwai22.60%150.00%
Total77100.00%2100.00%


static void line6_midi_output_drain(struct snd_rawmidi_substream *substream) { struct usb_line6 *line6 = line6_rawmidi_substream_midi(substream)->line6; struct snd_line6_midi *midi = line6->line6midi; wait_event_interruptible(midi->send_wait, midi->num_active_send_urbs == 0); }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner45100.00%2100.00%
Total45100.00%2100.00%


static int line6_midi_input_open(struct snd_rawmidi_substream *substream) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner14100.00%1100.00%
Total14100.00%1100.00%


static int line6_midi_input_close(struct snd_rawmidi_substream *substream) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner14100.00%1100.00%
Total14100.00%1100.00%


static void line6_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) { struct usb_line6 *line6 = line6_rawmidi_substream_midi(substream)->line6; if (up) line6->line6midi->substream_receive = substream; else line6->line6midi->substream_receive = NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner4697.87%150.00%
Sachin Kamat12.13%150.00%
Total47100.00%2100.00%

static const struct snd_rawmidi_ops line6_midi_output_ops = { .open = line6_midi_output_open, .close = line6_midi_output_close, .trigger = line6_midi_output_trigger, .drain = line6_midi_output_drain, }; static const struct snd_rawmidi_ops line6_midi_input_ops = { .open = line6_midi_input_open, .close = line6_midi_input_close, .trigger = line6_midi_input_trigger, }; /* Create a MIDI device */
static int snd_line6_new_midi(struct usb_line6 *line6, struct snd_rawmidi **rmidi_ret) { struct snd_rawmidi *rmidi; int err; err = snd_rawmidi_new(line6->card, "Line 6 MIDI", 0, 1, 1, rmidi_ret); if (err < 0) return err; rmidi = *rmidi_ret; strcpy(rmidi->id, line6->properties->id); strcpy(rmidi->name, line6->properties->name); rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &line6_midi_output_ops); snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &line6_midi_input_ops); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner10186.32%240.00%
Takashi Iwai119.40%120.00%
Greg Kroah-Hartman43.42%120.00%
Chris Rorvick10.85%120.00%
Total117100.00%5100.00%

/* MIDI device destructor */
static void snd_line6_midi_free(struct snd_rawmidi *rmidi) { struct snd_line6_midi *line6midi = rmidi->private_data; line6_midibuf_destroy(&line6midi->midibuf_in); line6_midibuf_destroy(&line6midi->midibuf_out); kfree(line6midi); }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner3175.61%266.67%
Takashi Iwai1024.39%133.33%
Total41100.00%3100.00%

/* Initialize the Line 6 MIDI subsystem. */
int line6_init_midi(struct usb_line6 *line6) { int err; struct snd_rawmidi *rmidi; struct snd_line6_midi *line6midi; if (!(line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI)) { /* skip MIDI initialization and report success */ return 0; } err = snd_line6_new_midi(line6, &rmidi); if (err < 0) return err; line6midi = kzalloc(sizeof(struct snd_line6_midi), GFP_KERNEL); if (!line6midi) return -ENOMEM; rmidi->private_data = line6midi; rmidi->private_free = snd_line6_midi_free; init_waitqueue_head(&line6midi->send_wait); spin_lock_init(&line6midi->lock); line6midi->line6 = line6; err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0); if (err < 0) return err; err = line6_midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1); if (err < 0) return err; line6->line6midi = line6midi; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner9957.56%114.29%
Takashi Iwai5431.40%228.57%
Greg Kroah-Hartman116.40%228.57%
Jesper Juhl74.07%114.29%
Andrej Krutak10.58%114.29%
Total172100.00%7100.00%

EXPORT_SYMBOL_GPL(line6_init_midi);

Overall Contributors

PersonTokensPropCommitsCommitProp
Markus Grabner101488.48%210.00%
Takashi Iwai907.85%420.00%
Greg Kroah-Hartman161.40%210.00%
Jesper Juhl70.61%15.00%
Chris Rorvick60.52%315.00%
Thomas Meyer30.26%15.00%
Himangi Saraogi20.17%15.00%
Peter Hüwe20.17%15.00%
Tejun Heo20.17%15.00%
Andrej Krutak10.09%15.00%
Stefan Hajnoczi10.09%15.00%
Sachin Kamat10.09%15.00%
Ashvini Varatharaj10.09%15.00%
Total1146100.00%20100.00%
Directory: sound/usb/line6
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.