^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/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.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 <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <sound/hwdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "capture.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "driver.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "midi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "playback.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define DRIVER_AUTHOR "Markus Grabner <grabner@icg.tugraz.at>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DRIVER_DESC "Line 6 USB Driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) This is Line 6's MIDI manufacturer ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) const unsigned char line6_midi_id[3] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 0x00, 0x01, 0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) EXPORT_SYMBOL_GPL(line6_midi_id);
^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) Code to request version of POD, Variax interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) (and maybe other devices).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static const char line6_request_version[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) Class for asynchronous messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct message {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct usb_line6 *line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) const char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) Forward declarations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static void line6_data_received(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int line6_send_raw_message_async_part(struct message *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) Start to listen on endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int line6_start_listen(struct usb_line6 *line6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) usb_fill_int_urb(line6->urb_listen, line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) usb_rcvintpipe(line6->usbdev, line6->properties->ep_ctrl_r),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) line6_data_received, line6, line6->interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) usb_fill_bulk_urb(line6->urb_listen, line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) usb_rcvbulkpipe(line6->usbdev, line6->properties->ep_ctrl_r),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) line6_data_received, line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* sanity checks of EP before actually submitting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (usb_urb_ep_type_check(line6->urb_listen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) dev_err(line6->ifcdev, "invalid control EP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) line6->urb_listen->actual_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) Stop listening on endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static void line6_stop_listen(struct usb_line6 *line6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) usb_kill_urb(line6->urb_listen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) Send raw message in pieces of wMaxPacketSize bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int line6_send_raw_message(struct usb_line6 *line6, const char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int i, done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) const struct line6_properties *properties = line6->properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) for (i = 0; i < size; i += line6->max_packet_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) const char *frag_buf = buffer + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int frag_size = min(line6->max_packet_size, size - i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) retval = usb_interrupt_msg(line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) usb_sndintpipe(line6->usbdev, properties->ep_ctrl_w),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) (char *)frag_buf, frag_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) &partial, LINE6_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) retval = usb_bulk_msg(line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) usb_sndbulkpipe(line6->usbdev, properties->ep_ctrl_w),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) (char *)frag_buf, frag_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) &partial, LINE6_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) dev_err(line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) "usb_bulk_msg failed (%d)\n", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) done += frag_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) EXPORT_SYMBOL_GPL(line6_send_raw_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) Notification of completion of asynchronous request transmission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static void line6_async_request_sent(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct message *msg = (struct message *)urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (msg->done >= msg->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) kfree(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) line6_send_raw_message_async_part(msg, urb);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) Asynchronously send part of a raw message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static int line6_send_raw_message_async_part(struct message *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct usb_line6 *line6 = msg->line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) int done = msg->done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int bytes = min(msg->size - done, line6->max_packet_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) usb_fill_int_urb(urb, line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) usb_sndintpipe(line6->usbdev, line6->properties->ep_ctrl_w),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) (char *)msg->buffer + done, bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) line6_async_request_sent, msg, line6->interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) usb_fill_bulk_urb(urb, line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) usb_sndbulkpipe(line6->usbdev, line6->properties->ep_ctrl_w),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) (char *)msg->buffer + done, bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) line6_async_request_sent, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) msg->done += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* sanity checks of EP before actually submitting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) retval = usb_urb_ep_type_check(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) retval = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) __func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) kfree(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) Asynchronously send raw message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct message *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* create message: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (msg == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* create URB: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) urb = usb_alloc_urb(0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (urb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) kfree(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return -ENOMEM;
^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) /* set message data: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) msg->line6 = line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) msg->buffer = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) msg->size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) msg->done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* start sending: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return line6_send_raw_message_async_part(msg, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) EXPORT_SYMBOL_GPL(line6_send_raw_message_async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) Send asynchronous device version request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int line6_version_request_async(struct usb_line6 *line6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) buffer = kmemdup(line6_request_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) sizeof(line6_request_version), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (buffer == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) retval = line6_send_raw_message_async(line6, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) sizeof(line6_request_version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) EXPORT_SYMBOL_GPL(line6_version_request_async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) Send sysex message in pieces of wMaxPacketSize bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return line6_send_raw_message(line6, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) size + SYSEX_EXTRA_SIZE) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) SYSEX_EXTRA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) EXPORT_SYMBOL_GPL(line6_send_sysex_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) Allocate buffer for sysex message and prepare header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) @param code sysex message code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) @param size number of bytes between code and sysex end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) buffer[0] = LINE6_SYSEX_BEGIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) buffer[sizeof(line6_midi_id) + 1] = code1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) buffer[sizeof(line6_midi_id) + 2] = code2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) buffer[sizeof(line6_midi_id) + 3 + size] = LINE6_SYSEX_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) EXPORT_SYMBOL_GPL(line6_alloc_sysex_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) Notification of data received from the Line 6 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static void line6_data_received(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct midi_buffer *mb = &line6->line6midi->midibuf_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (urb->status == -ESHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) done =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) line6_midibuf_write(mb, urb->transfer_buffer, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (done < urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) line6_midibuf_ignore(mb, done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) dev_dbg(line6->ifcdev, "%d %d buffer overflow - message skipped\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) done, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) done =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) line6_midibuf_read(mb, line6->buffer_message,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) LINE6_MIDI_MESSAGE_MAXLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (done <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) line6->message_length = done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) line6_midi_receive(line6, line6->buffer_message, done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (line6->process_message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) line6->process_message(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) line6->buffer_message = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) line6->message_length = urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (line6->process_message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) line6->process_message(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) line6->buffer_message = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) line6_start_listen(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #define LINE6_READ_WRITE_STATUS_DELAY 2 /* milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) #define LINE6_READ_WRITE_MAX_RETRIES 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) Read data from device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) int line6_read_data(struct usb_line6 *line6, unsigned address, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) unsigned datalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct usb_device *usbdev = line6->usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) u8 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) unsigned count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (address > 0xffff || datalen > 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* query the serial number: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) ret = usb_control_msg_send(usbdev, 0, 0x67,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) (datalen << 8) | 0x21, address, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) LINE6_TIMEOUT, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) dev_err(line6->ifcdev, "read request failed (error %d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /* Wait for data length. We'll get 0xff until length arrives. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) mdelay(LINE6_READ_WRITE_STATUS_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) ret = usb_control_msg_recv(usbdev, 0, 0x67,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 0x0012, 0x0000, &len, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) LINE6_TIMEOUT, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) dev_err(line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) "receive length failed (error %d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (len != 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (len == 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) dev_err(line6->ifcdev, "read failed after %d retries\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) } else if (len != datalen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /* should be equal or something went wrong */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) dev_err(line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) "length mismatch (expected %d, got %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) (int)datalen, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /* receive the result: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) ret = usb_control_msg_recv(usbdev, 0, 0x67,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 0x0013, 0x0000, data, datalen, LINE6_TIMEOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) dev_err(line6->ifcdev, "read failed (error %d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) EXPORT_SYMBOL_GPL(line6_read_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) Write data to device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int line6_write_data(struct usb_line6 *line6, unsigned address, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) unsigned datalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct usb_device *usbdev = line6->usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) unsigned char *status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (address > 0xffff || datalen > 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) status = kmalloc(1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) ret = usb_control_msg_send(usbdev, 0, 0x67,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 0x0022, address, data, datalen, LINE6_TIMEOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) dev_err(line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) "write request failed (error %d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) mdelay(LINE6_READ_WRITE_STATUS_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) ret = usb_control_msg_recv(usbdev, 0, 0x67,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 0x0012, 0x0000, status, 1, LINE6_TIMEOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) dev_err(line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) "receiving status failed (error %d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (*status != 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (*status == 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) dev_err(line6->ifcdev, "write failed after %d retries\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) } else if (*status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) kfree(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) EXPORT_SYMBOL_GPL(line6_write_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) Read Line 6 device serial number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) (POD, TonePort, GuitarPort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) int line6_read_serial_number(struct usb_line6 *line6, u32 *serial_number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) return line6_read_data(line6, 0x80d0, serial_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) sizeof(*serial_number));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) EXPORT_SYMBOL_GPL(line6_read_serial_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) Card destructor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static void line6_destruct(struct snd_card *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct usb_line6 *line6 = card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct usb_device *usbdev = line6->usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* Free buffer memory first. We cannot depend on the existence of private
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) * data from the (podhd) module, it may be gone already during this call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) kfree(line6->buffer_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) kfree(line6->buffer_listen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) /* then free URBs: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) usb_free_urb(line6->urb_listen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) line6->urb_listen = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /* decrement reference counters: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) usb_put_dev(usbdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static void line6_get_usb_properties(struct usb_line6 *line6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) struct usb_device *usbdev = line6->usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) const struct line6_properties *properties = line6->properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) struct usb_host_endpoint *ep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (properties->capabilities & LINE6_CAP_CONTROL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) pipe = usb_rcvintpipe(line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) line6->properties->ep_ctrl_r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) pipe = usb_rcvbulkpipe(line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) line6->properties->ep_ctrl_r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) ep = usbdev->ep_in[usb_pipeendpoint(pipe)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /* Control data transfer properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) line6->interval = ep->desc.bInterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (properties->capabilities & LINE6_CAP_CONTROL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) dev_err(line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) "endpoint not available, using fallback values");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) line6->interval = LINE6_FALLBACK_INTERVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) /* Isochronous transfer properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (usbdev->speed == USB_SPEED_LOW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) line6->intervals_per_second = USB_LOW_INTERVALS_PER_SECOND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) line6->iso_buffers = USB_LOW_ISO_BUFFERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) line6->intervals_per_second = USB_HIGH_INTERVALS_PER_SECOND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) line6->iso_buffers = USB_HIGH_ISO_BUFFERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) /* Enable buffering of incoming messages, flush the buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) static int line6_hwdep_open(struct snd_hwdep *hw, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct usb_line6 *line6 = hw->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /* NOTE: hwdep layer provides atomicity here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) line6->messages.active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) line6->messages.nonblock = file->f_flags & O_NONBLOCK ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) /* Stop buffering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) static int line6_hwdep_release(struct snd_hwdep *hw, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) struct usb_line6 *line6 = hw->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) line6->messages.active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /* Read from circular buffer, return to user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) line6_hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct usb_line6 *line6 = hwdep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) long rv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) unsigned int out_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) if (mutex_lock_interruptible(&line6->messages.read_lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) while (kfifo_len(&line6->messages.fifo) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) mutex_unlock(&line6->messages.read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (line6->messages.nonblock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) rv = wait_event_interruptible(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) line6->messages.wait_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) kfifo_len(&line6->messages.fifo) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (mutex_lock_interruptible(&line6->messages.read_lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (kfifo_peek_len(&line6->messages.fifo) > count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) /* Buffer too small; allow re-read of the current item... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) rv = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) rv = kfifo_to_user(&line6->messages.fifo, buf, count, &out_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) if (rv == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) rv = out_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) mutex_unlock(&line6->messages.read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /* Write directly (no buffering) to device by user*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) line6_hwdep_write(struct snd_hwdep *hwdep, const char __user *data, long count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) struct usb_line6 *line6 = hwdep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) char *data_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (count > line6->max_packet_size * LINE6_RAW_MESSAGES_MAXCOUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /* This is an arbitrary limit - still better than nothing... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) data_copy = memdup_user(data, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (IS_ERR(data_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return PTR_ERR(data_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) rv = line6_send_raw_message(line6, data_copy, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) kfree(data_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) static __poll_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) line6_hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) __poll_t rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) struct usb_line6 *line6 = hwdep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) poll_wait(file, &line6->messages.wait_queue, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) mutex_lock(&line6->messages.read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) rv = kfifo_len(&line6->messages.fifo) == 0 ? 0 : EPOLLIN | EPOLLRDNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) mutex_unlock(&line6->messages.read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static const struct snd_hwdep_ops hwdep_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) .open = line6_hwdep_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) .release = line6_hwdep_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) .read = line6_hwdep_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) .write = line6_hwdep_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) .poll = line6_hwdep_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) /* Insert into circular buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) static void line6_hwdep_push_message(struct usb_line6 *line6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (!line6->messages.active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (kfifo_avail(&line6->messages.fifo) >= line6->message_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) /* No race condition here, there's only one writer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) kfifo_in(&line6->messages.fifo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) line6->buffer_message, line6->message_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) } /* else TODO: signal overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) wake_up_interruptible(&line6->messages.wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) static int line6_hwdep_init(struct usb_line6 *line6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) struct snd_hwdep *hwdep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) /* TODO: usb_driver_claim_interface(); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) line6->process_message = line6_hwdep_push_message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) line6->messages.active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) init_waitqueue_head(&line6->messages.wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) mutex_init(&line6->messages.read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) INIT_KFIFO(line6->messages.fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) err = snd_hwdep_new(line6->card, "config", 0, &hwdep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) strcpy(hwdep->name, "config");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) hwdep->iface = SNDRV_HWDEP_IFACE_LINE6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) hwdep->ops = hwdep_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) hwdep->private_data = line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) hwdep->exclusive = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) static int line6_init_cap_control(struct usb_line6 *line6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) /* initialize USB buffers: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if (!line6->buffer_listen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (!line6->urb_listen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (line6->properties->capabilities & LINE6_CAP_CONTROL_MIDI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) line6->buffer_message = kmalloc(LINE6_MIDI_MESSAGE_MAXLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (!line6->buffer_message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) ret = line6_init_midi(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) ret = line6_hwdep_init(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) ret = line6_start_listen(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) dev_err(line6->ifcdev, "cannot start listening: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) static void line6_startup_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct usb_line6 *line6 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) container_of(work, struct usb_line6, startup_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if (line6->startup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) line6->startup(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) Probe USB device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) int line6_probe(struct usb_interface *interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) const struct usb_device_id *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) const char *driver_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) const struct line6_properties *properties,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) size_t data_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) struct usb_device *usbdev = interface_to_usbdev(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) struct usb_line6 *line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) int interface_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (WARN_ON(data_size < sizeof(*line6)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) /* we don't handle multiple configurations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) if (usbdev->descriptor.bNumConfigurations != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) ret = snd_card_new(&interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) THIS_MODULE, data_size, &card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) /* store basic data: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) line6 = card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) line6->card = card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) line6->properties = properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) line6->usbdev = usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) line6->ifcdev = &interface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) INIT_DELAYED_WORK(&line6->startup_work, line6_startup_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) strcpy(card->id, properties->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) strcpy(card->driver, driver_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) strcpy(card->shortname, properties->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) sprintf(card->longname, "Line 6 %s at USB %s", properties->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) dev_name(line6->ifcdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) card->private_free = line6_destruct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) usb_set_intfdata(interface, line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) /* increment reference counters: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) usb_get_dev(usbdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) /* initialize device info: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) dev_info(&interface->dev, "Line 6 %s found\n", properties->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) /* query interface number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) interface_number = interface->cur_altsetting->desc.bInterfaceNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) /* TODO reserves the bus bandwidth even without actual transfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) ret = usb_set_interface(usbdev, interface_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) properties->altsetting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) dev_err(&interface->dev, "set_interface failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) line6_get_usb_properties(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (properties->capabilities & LINE6_CAP_CONTROL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) ret = line6_init_cap_control(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) /* initialize device data based on device: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) ret = private_init(line6, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) /* creation of additional special files should go here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) dev_info(&interface->dev, "Line 6 %s now attached\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) properties->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) /* we can call disconnect callback here because no close-sync is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) * needed yet at this point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) line6_disconnect(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) EXPORT_SYMBOL_GPL(line6_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) Line 6 device disconnected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) void line6_disconnect(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) struct usb_line6 *line6 = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) struct usb_device *usbdev = interface_to_usbdev(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (!line6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) if (WARN_ON(usbdev != line6->usbdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) cancel_delayed_work_sync(&line6->startup_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (line6->urb_listen != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) line6_stop_listen(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) snd_card_disconnect(line6->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (line6->line6pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) line6_pcm_disconnect(line6->line6pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) if (line6->disconnect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) line6->disconnect(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) dev_info(&interface->dev, "Line 6 %s now disconnected\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) line6->properties->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) /* make sure the device isn't destructed twice: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) usb_set_intfdata(interface, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) snd_card_free_when_closed(line6->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) EXPORT_SYMBOL_GPL(line6_disconnect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) Suspend Line 6 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) int line6_suspend(struct usb_interface *interface, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) struct usb_line6 *line6 = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) struct snd_line6_pcm *line6pcm = line6->line6pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) snd_power_change_state(line6->card, SNDRV_CTL_POWER_D3hot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) if (line6->properties->capabilities & LINE6_CAP_CONTROL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) line6_stop_listen(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (line6pcm != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) line6pcm->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) EXPORT_SYMBOL_GPL(line6_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) Resume Line 6 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) int line6_resume(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) struct usb_line6 *line6 = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) if (line6->properties->capabilities & LINE6_CAP_CONTROL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) line6_start_listen(line6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) snd_power_change_state(line6->card, SNDRV_CTL_POWER_D0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) EXPORT_SYMBOL_GPL(line6_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) #endif /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)