Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Line6 Linux USB driver - 0.8.0 |
| 3 | * |
| 4 | * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation, version 2. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include "driver.h" |
| 13 | |
| 14 | #include <linux/usb.h> |
| 15 | |
| 16 | #include <sound/core.h> |
| 17 | #include <sound/rawmidi.h> |
| 18 | |
| 19 | #include "audio.h" |
| 20 | #include "midi.h" |
| 21 | #include "pod.h" |
| 22 | #include "usbdefs.h" |
| 23 | |
| 24 | |
| 25 | #define USE_MIDIBUF 1 |
| 26 | #define OUTPUT_DUMP_ONLY 0 |
| 27 | |
| 28 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 29 | #define line6_rawmidi_substream_midi(substream) \ |
| 30 | ((struct snd_line6_midi *)((substream)->rmidi->private_data)) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 31 | |
| 32 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 33 | static int send_midi_async(struct usb_line6 *line6, unsigned char *data, |
| 34 | int length); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 35 | |
| 36 | |
| 37 | /* |
| 38 | Pass data received via USB to MIDI. |
| 39 | */ |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 40 | void line6_midi_receive(struct usb_line6 *line6, unsigned char *data, |
| 41 | int length) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 42 | { |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 43 | if (line6->line6midi->substream_receive) |
| 44 | snd_rawmidi_receive(line6->line6midi->substream_receive, |
| 45 | data, length); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /* |
| 49 | Read data from MIDI buffer and transmit them via USB. |
| 50 | */ |
| 51 | static void line6_midi_transmit(struct snd_rawmidi_substream *substream) |
| 52 | { |
| 53 | struct usb_line6 *line6 = line6_rawmidi_substream_midi(substream)->line6; |
| 54 | struct snd_line6_midi *line6midi = line6->line6midi; |
| 55 | struct MidiBuffer *mb = &line6midi->midibuf_out; |
| 56 | unsigned long flags; |
| 57 | unsigned char chunk[line6->max_packet_size]; |
| 58 | int req, done; |
| 59 | |
| 60 | spin_lock_irqsave(&line6->line6midi->midi_transmit_lock, flags); |
| 61 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 62 | for (;;) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 63 | req = min(midibuf_bytes_free(mb), line6->max_packet_size); |
| 64 | done = snd_rawmidi_transmit_peek(substream, chunk, req); |
| 65 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 66 | if (done == 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 67 | break; |
| 68 | |
| 69 | #if DO_DUMP_MIDI_SEND |
| 70 | line6_write_hexdump(line6, 's', chunk, done); |
| 71 | #endif |
| 72 | midibuf_write(mb, chunk, done); |
| 73 | snd_rawmidi_transmit_ack(substream, done); |
| 74 | } |
| 75 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 76 | for (;;) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 77 | done = midibuf_read(mb, chunk, line6->max_packet_size); |
| 78 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 79 | if (done == 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 80 | break; |
| 81 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 82 | if (midibuf_skip_message(mb, line6midi->midi_mask_transmit)) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 83 | continue; |
| 84 | |
| 85 | send_midi_async(line6, chunk, done); |
| 86 | } |
| 87 | |
| 88 | spin_unlock_irqrestore(&line6->line6midi->midi_transmit_lock, flags); |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | Notification of completion of MIDI transmission. |
| 93 | */ |
Greg Kroah-Hartman | 0c7ab15 | 2009-02-27 20:28:04 -0800 | [diff] [blame] | 94 | static void midi_sent(struct urb *urb) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 95 | { |
| 96 | unsigned long flags; |
| 97 | int status; |
| 98 | int num; |
| 99 | struct usb_line6 *line6 = (struct usb_line6 *)urb->context; |
| 100 | |
| 101 | status = urb->status; |
| 102 | kfree(urb->transfer_buffer); |
| 103 | usb_free_urb(urb); |
| 104 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 105 | if (status == -ESHUTDOWN) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 106 | return; |
| 107 | |
| 108 | spin_lock_irqsave(&line6->line6midi->send_urb_lock, flags); |
| 109 | num = --line6->line6midi->num_active_send_urbs; |
| 110 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 111 | if (num == 0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 112 | line6_midi_transmit(line6->line6midi->substream_transmit); |
| 113 | num = line6->line6midi->num_active_send_urbs; |
| 114 | } |
| 115 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 116 | if (num == 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 117 | wake_up_interruptible(&line6->line6midi->send_wait); |
| 118 | |
| 119 | spin_unlock_irqrestore(&line6->line6midi->send_urb_lock, flags); |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | Send an asynchronous MIDI message. |
| 124 | Assumes that line6->line6midi->send_urb_lock is held |
| 125 | (i.e., this function is serialized). |
| 126 | */ |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 127 | static int send_midi_async(struct usb_line6 *line6, unsigned char *data, |
| 128 | int length) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 129 | { |
| 130 | struct urb *urb; |
| 131 | int retval; |
| 132 | unsigned char *transfer_buffer; |
| 133 | |
| 134 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 135 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 136 | if (urb == 0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 137 | dev_err(line6->ifcdev, "Out of memory\n"); |
| 138 | return -ENOMEM; |
| 139 | } |
| 140 | |
| 141 | #if DO_DUMP_URB_SEND |
| 142 | line6_write_hexdump(line6, 'S', data, length); |
| 143 | #endif |
| 144 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 145 | transfer_buffer = kmalloc(length, GFP_ATOMIC); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 146 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 147 | if (transfer_buffer == 0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 148 | usb_free_urb(urb); |
| 149 | dev_err(line6->ifcdev, "Out of memory\n"); |
| 150 | return -ENOMEM; |
| 151 | } |
| 152 | |
| 153 | memcpy(transfer_buffer, data, length); |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 154 | usb_fill_int_urb(urb, line6->usbdev, |
| 155 | usb_sndbulkpipe(line6->usbdev, |
| 156 | line6->ep_control_write), |
| 157 | transfer_buffer, length, midi_sent, line6, |
| 158 | line6->interval); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 159 | urb->actual_length = 0; |
| 160 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
| 161 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 162 | if (retval < 0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 163 | dev_err(line6->ifcdev, "usb_submit_urb failed\n"); |
| 164 | usb_free_urb(urb); |
| 165 | return -EINVAL; |
| 166 | } |
| 167 | |
| 168 | ++line6->line6midi->num_active_send_urbs; |
| 169 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 170 | switch (line6->usbdev->descriptor.idProduct) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 171 | case LINE6_DEVID_BASSPODXT: |
| 172 | case LINE6_DEVID_BASSPODXTLIVE: |
| 173 | case LINE6_DEVID_BASSPODXTPRO: |
| 174 | case LINE6_DEVID_PODXT: |
| 175 | case LINE6_DEVID_PODXTLIVE: |
| 176 | case LINE6_DEVID_PODXTPRO: |
| 177 | case LINE6_DEVID_POCKETPOD: |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 178 | pod_midi_postprocess((struct usb_line6_pod *)line6, data, |
| 179 | length); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 180 | break; |
| 181 | |
| 182 | default: |
| 183 | MISSING_CASE; |
| 184 | } |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | static int line6_midi_output_open(struct snd_rawmidi_substream *substream) |
| 190 | { |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static int line6_midi_output_close(struct snd_rawmidi_substream *substream) |
| 195 | { |
| 196 | return 0; |
| 197 | } |
| 198 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 199 | static void line6_midi_output_trigger(struct snd_rawmidi_substream *substream, |
| 200 | int up) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 201 | { |
| 202 | unsigned long flags; |
| 203 | struct usb_line6 *line6 = line6_rawmidi_substream_midi(substream)->line6; |
| 204 | |
| 205 | line6->line6midi->substream_transmit = substream; |
| 206 | spin_lock_irqsave(&line6->line6midi->send_urb_lock, flags); |
| 207 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 208 | if (line6->line6midi->num_active_send_urbs == 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 209 | line6_midi_transmit(substream); |
| 210 | |
| 211 | spin_unlock_irqrestore(&line6->line6midi->send_urb_lock, flags); |
| 212 | } |
| 213 | |
| 214 | static void line6_midi_output_drain(struct snd_rawmidi_substream *substream) |
| 215 | { |
| 216 | struct usb_line6 *line6 = line6_rawmidi_substream_midi(substream)->line6; |
| 217 | wait_queue_head_t *head = &line6->line6midi->send_wait; |
| 218 | DECLARE_WAITQUEUE(wait, current); |
| 219 | add_wait_queue(head, &wait); |
| 220 | current->state = TASK_INTERRUPTIBLE; |
| 221 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 222 | while (line6->line6midi->num_active_send_urbs > 0) |
| 223 | if (signal_pending(current)) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 224 | break; |
| 225 | else |
| 226 | schedule(); |
| 227 | |
| 228 | current->state = TASK_RUNNING; |
| 229 | remove_wait_queue(head, &wait); |
| 230 | } |
| 231 | |
| 232 | static int line6_midi_input_open(struct snd_rawmidi_substream *substream) |
| 233 | { |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int line6_midi_input_close(struct snd_rawmidi_substream *substream) |
| 238 | { |
| 239 | return 0; |
| 240 | } |
| 241 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 242 | static void line6_midi_input_trigger(struct snd_rawmidi_substream *substream, |
| 243 | int up) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 244 | { |
| 245 | struct usb_line6 *line6 = line6_rawmidi_substream_midi(substream)->line6; |
| 246 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 247 | if (up) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 248 | line6->line6midi->substream_receive = substream; |
| 249 | else |
| 250 | line6->line6midi->substream_receive = 0; |
| 251 | } |
| 252 | |
| 253 | static struct snd_rawmidi_ops line6_midi_output_ops = { |
| 254 | .open = line6_midi_output_open, |
| 255 | .close = line6_midi_output_close, |
| 256 | .trigger = line6_midi_output_trigger, |
| 257 | .drain = line6_midi_output_drain, |
| 258 | }; |
| 259 | |
| 260 | static struct snd_rawmidi_ops line6_midi_input_ops = { |
| 261 | .open = line6_midi_input_open, |
| 262 | .close = line6_midi_input_close, |
| 263 | .trigger = line6_midi_input_trigger, |
| 264 | }; |
| 265 | |
| 266 | /* |
| 267 | Cleanup the Line6 MIDI device. |
| 268 | */ |
| 269 | static void line6_cleanup_midi(struct snd_rawmidi *rmidi) |
| 270 | { |
| 271 | } |
| 272 | |
| 273 | /* Create a MIDI device */ |
| 274 | static int snd_line6_new_midi(struct snd_line6_midi *line6midi) |
| 275 | { |
| 276 | struct snd_rawmidi *rmidi; |
| 277 | int err; |
| 278 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 279 | err = snd_rawmidi_new(line6midi->line6->card, "Line6 MIDI", 0, 1, 1, |
| 280 | &rmidi); |
| 281 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 282 | return err; |
| 283 | |
| 284 | rmidi->private_data = line6midi; |
| 285 | rmidi->private_free = line6_cleanup_midi; |
| 286 | strcpy(rmidi->name, line6midi->line6->properties->name); |
| 287 | |
| 288 | rmidi->info_flags = |
| 289 | SNDRV_RAWMIDI_INFO_OUTPUT | |
| 290 | SNDRV_RAWMIDI_INFO_INPUT | |
| 291 | SNDRV_RAWMIDI_INFO_DUPLEX; |
| 292 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 293 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, |
| 294 | &line6_midi_output_ops); |
| 295 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, |
| 296 | &line6_midi_input_ops); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | "read" request on "midi_mask_transmit" special file. |
| 302 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 303 | static ssize_t midi_get_midi_mask_transmit(struct device *dev, |
| 304 | struct device_attribute *attr, |
| 305 | char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 306 | { |
| 307 | struct usb_interface *interface = to_usb_interface(dev); |
| 308 | struct usb_line6 *line6 = usb_get_intfdata(interface); |
| 309 | return sprintf(buf, "%d\n", line6->line6midi->midi_mask_transmit); |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | "write" request on "midi_mask" special file. |
| 314 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 315 | static ssize_t midi_set_midi_mask_transmit(struct device *dev, |
| 316 | struct device_attribute *attr, |
| 317 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 318 | { |
| 319 | struct usb_interface *interface = to_usb_interface(dev); |
| 320 | struct usb_line6 *line6 = usb_get_intfdata(interface); |
Shawn Bohrer | 334a33d | 2009-11-15 22:18:02 -0600 | [diff] [blame] | 321 | unsigned long value; |
| 322 | int ret; |
| 323 | |
| 324 | ret = strict_strtoul(buf, 10, &value); |
| 325 | if (ret) |
| 326 | return ret; |
| 327 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 328 | line6->line6midi->midi_mask_transmit = value; |
| 329 | return count; |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | "read" request on "midi_mask_receive" special file. |
| 334 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 335 | static ssize_t midi_get_midi_mask_receive(struct device *dev, |
| 336 | struct device_attribute *attr, |
| 337 | char *buf) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 338 | { |
| 339 | struct usb_interface *interface = to_usb_interface(dev); |
| 340 | struct usb_line6 *line6 = usb_get_intfdata(interface); |
| 341 | return sprintf(buf, "%d\n", line6->line6midi->midi_mask_receive); |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | "write" request on "midi_mask" special file. |
| 346 | */ |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 347 | static ssize_t midi_set_midi_mask_receive(struct device *dev, |
| 348 | struct device_attribute *attr, |
| 349 | const char *buf, size_t count) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 350 | { |
| 351 | struct usb_interface *interface = to_usb_interface(dev); |
| 352 | struct usb_line6 *line6 = usb_get_intfdata(interface); |
Shawn Bohrer | 334a33d | 2009-11-15 22:18:02 -0600 | [diff] [blame] | 353 | unsigned long value; |
| 354 | int ret; |
| 355 | |
| 356 | ret = strict_strtoul(buf, 10, &value); |
| 357 | if (ret) |
| 358 | return ret; |
| 359 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 360 | line6->line6midi->midi_mask_receive = value; |
| 361 | return count; |
| 362 | } |
| 363 | |
| 364 | static DEVICE_ATTR(midi_mask_transmit, S_IWUGO | S_IRUGO, midi_get_midi_mask_transmit, midi_set_midi_mask_transmit); |
| 365 | static DEVICE_ATTR(midi_mask_receive, S_IWUGO | S_IRUGO, midi_get_midi_mask_receive, midi_set_midi_mask_receive); |
| 366 | |
| 367 | /* MIDI device destructor */ |
| 368 | static int snd_line6_midi_free(struct snd_device *device) |
| 369 | { |
| 370 | struct snd_line6_midi *line6midi = device->device_data; |
| 371 | device_remove_file(line6midi->line6->ifcdev, &dev_attr_midi_mask_transmit); |
| 372 | device_remove_file(line6midi->line6->ifcdev, &dev_attr_midi_mask_receive); |
| 373 | midibuf_destroy(&line6midi->midibuf_in); |
| 374 | midibuf_destroy(&line6midi->midibuf_out); |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | Initialize the Line6 MIDI subsystem. |
| 380 | */ |
| 381 | int line6_init_midi(struct usb_line6 *line6) |
| 382 | { |
| 383 | static struct snd_device_ops midi_ops = { |
| 384 | .dev_free = snd_line6_midi_free, |
| 385 | }; |
| 386 | |
| 387 | int err; |
| 388 | struct snd_line6_midi *line6midi; |
| 389 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 390 | if (!(line6->properties->capabilities & LINE6_BIT_CONTROL)) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 391 | return 0; /* skip MIDI initialization and report success */ |
| 392 | |
| 393 | line6midi = kzalloc(sizeof(struct snd_line6_midi), GFP_KERNEL); |
| 394 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 395 | if (line6midi == NULL) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 396 | return -ENOMEM; |
| 397 | |
| 398 | err = midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0); |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 399 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 400 | return err; |
| 401 | |
| 402 | err = midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1); |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 403 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 404 | return err; |
| 405 | |
| 406 | line6midi->line6 = line6; |
| 407 | line6midi->midi_mask_transmit = 1; |
| 408 | line6midi->midi_mask_receive = 4; |
| 409 | line6->line6midi = line6midi; |
| 410 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 411 | err = snd_device_new(line6->card, SNDRV_DEV_RAWMIDI, line6midi, |
| 412 | &midi_ops); |
| 413 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 414 | return err; |
| 415 | |
| 416 | snd_card_set_dev(line6->card, line6->ifcdev); |
| 417 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 418 | err = snd_line6_new_midi(line6midi); |
| 419 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 420 | return err; |
| 421 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 422 | err = device_create_file(line6->ifcdev, &dev_attr_midi_mask_transmit); |
| 423 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 424 | return err; |
| 425 | |
Greg Kroah-Hartman | d7e3733 | 2009-02-27 22:42:55 -0800 | [diff] [blame] | 426 | err = device_create_file(line6->ifcdev, &dev_attr_midi_mask_receive); |
| 427 | if (err < 0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 428 | return err; |
| 429 | |
| 430 | init_waitqueue_head(&line6midi->send_wait); |
| 431 | spin_lock_init(&line6midi->send_urb_lock); |
| 432 | spin_lock_init(&line6midi->midi_transmit_lock); |
| 433 | return 0; |
| 434 | } |