Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Behringer BCD2000 driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *   Copyright (C) 2014 Mario Kicherer (dev@kicherer.org)
^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/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/usb/audio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <sound/rawmidi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define PREFIX "snd-bcd2000: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define BUFSIZE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static const struct usb_device_id id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	{ USB_DEVICE(0x1397, 0x00bd) },
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static const unsigned char device_cmd_prefix[] = {0x03, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static const unsigned char bcd2000_init_sequence[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	0x07, 0x00, 0x00, 0x00, 0x78, 0x48, 0x1c, 0x81,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	0xc4, 0x00, 0x00, 0x00, 0x5e, 0x53, 0x4a, 0xf7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	0x18, 0xfa, 0x11, 0xff, 0x6c, 0xf3, 0x90, 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	0x18, 0xfa, 0x11, 0xff, 0x14, 0x00, 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	0x00, 0x00, 0x00, 0x00, 0xf2, 0x34, 0x4a, 0xf7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	0x18, 0xfa, 0x11, 0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) struct bcd2000 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct usb_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int card_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	int midi_out_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct snd_rawmidi *rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct snd_rawmidi_substream *midi_receive_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct snd_rawmidi_substream *midi_out_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	unsigned char midi_in_buf[BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned char midi_out_buf[BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct urb *midi_out_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct urb *midi_in_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct usb_anchor anchor;
^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) static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static DEFINE_MUTEX(devices_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static struct usb_driver bcd2000_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #ifdef CONFIG_SND_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static void bcd2000_dump_buffer(const char *prefix, const char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	print_hex_dump(KERN_DEBUG, prefix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			DUMP_PREFIX_NONE, 16, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			buf, len, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static void bcd2000_dump_buffer(const char *prefix, const char *buf, int len) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static int bcd2000_midi_input_open(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int bcd2000_midi_input_close(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) /* (de)register midi substream from client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static void bcd2000_midi_input_trigger(struct snd_rawmidi_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 						int up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct bcd2000 *bcd2k = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	bcd2k->midi_receive_substream = up ? substream : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static void bcd2000_midi_handle_input(struct bcd2000 *bcd2k,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				const unsigned char *buf, unsigned int buf_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	unsigned int payload_length, tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct snd_rawmidi_substream *midi_receive_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	midi_receive_substream = READ_ONCE(bcd2k->midi_receive_substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (!midi_receive_substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	bcd2000_dump_buffer(PREFIX "received from device: ", buf, buf_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (buf_len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	payload_length = buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/* ignore packets without payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (payload_length == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	tocopy = min(payload_length, buf_len-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	bcd2000_dump_buffer(PREFIX "sending to userspace: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 					&buf[1], tocopy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	snd_rawmidi_receive(midi_receive_substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 					&buf[1], tocopy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static void bcd2000_midi_send(struct bcd2000 *bcd2k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	int len, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct snd_rawmidi_substream *midi_out_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	BUILD_BUG_ON(sizeof(device_cmd_prefix) >= BUFSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	midi_out_substream = READ_ONCE(bcd2k->midi_out_substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (!midi_out_substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	/* copy command prefix bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	memcpy(bcd2k->midi_out_buf, device_cmd_prefix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		sizeof(device_cmd_prefix));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	 * get MIDI packet and leave space for command prefix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	 * and payload length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	len = snd_rawmidi_transmit(midi_out_substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				bcd2k->midi_out_buf + 3, BUFSIZE - 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		dev_err(&bcd2k->dev->dev, "%s: snd_rawmidi_transmit error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				__func__, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/* set payload length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	bcd2k->midi_out_buf[2] = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	bcd2k->midi_out_urb->transfer_buffer_length = BUFSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	bcd2000_dump_buffer(PREFIX "sending to device: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			bcd2k->midi_out_buf, len+3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* send packet to the BCD2000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	ret = usb_submit_urb(bcd2k->midi_out_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		dev_err(&bcd2k->dev->dev, PREFIX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			"%s (%p): usb_submit_urb() failed, ret=%d, len=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			__func__, midi_out_substream, ret, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		bcd2k->midi_out_active = 1;
^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 int bcd2000_midi_output_open(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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int bcd2000_midi_output_close(struct snd_rawmidi_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct bcd2000 *bcd2k = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (bcd2k->midi_out_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		usb_kill_urb(bcd2k->midi_out_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		bcd2k->midi_out_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* (de)register midi substream from client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static void bcd2000_midi_output_trigger(struct snd_rawmidi_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 						int up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct bcd2000 *bcd2k = substream->rmidi->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		bcd2k->midi_out_substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		/* check if there is data userspace wants to send */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		if (!bcd2k->midi_out_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			bcd2000_midi_send(bcd2k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		bcd2k->midi_out_substream = 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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static void bcd2000_output_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct bcd2000 *bcd2k = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	bcd2k->midi_out_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (urb->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		dev_warn(&urb->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			PREFIX "output urb->status: %d\n", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (urb->status == -ESHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	/* check if there is more data userspace wants to send */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	bcd2000_midi_send(bcd2k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static void bcd2000_input_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct bcd2000 *bcd2k = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (urb->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		dev_warn(&urb->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			PREFIX "input urb->status: %i\n", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (!bcd2k || urb->status == -ESHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (urb->actual_length > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		bcd2000_midi_handle_input(bcd2k, urb->transfer_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 					urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* return URB to device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	ret = usb_submit_urb(bcd2k->midi_in_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		dev_err(&bcd2k->dev->dev, PREFIX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			"%s: usb_submit_urb() failed, ret=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			__func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static const struct snd_rawmidi_ops bcd2000_midi_output = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	.open =    bcd2000_midi_output_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.close =   bcd2000_midi_output_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	.trigger = bcd2000_midi_output_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static const struct snd_rawmidi_ops bcd2000_midi_input = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	.open =    bcd2000_midi_input_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	.close =   bcd2000_midi_input_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	.trigger = bcd2000_midi_input_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static void bcd2000_init_device(struct bcd2000 *bcd2k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	init_usb_anchor(&bcd2k->anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	usb_anchor_urb(bcd2k->midi_out_urb, &bcd2k->anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	usb_anchor_urb(bcd2k->midi_in_urb, &bcd2k->anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	/* copy init sequence into buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	memcpy(bcd2k->midi_out_buf, bcd2000_init_sequence, 52);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	bcd2k->midi_out_urb->transfer_buffer_length = 52;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	/* submit sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	ret = usb_submit_urb(bcd2k->midi_out_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		dev_err(&bcd2k->dev->dev, PREFIX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			"%s: usb_submit_urb() out failed, ret=%d: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			__func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		bcd2k->midi_out_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	/* pass URB to device to enable button and controller events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	ret = usb_submit_urb(bcd2k->midi_in_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		dev_err(&bcd2k->dev->dev, PREFIX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			"%s: usb_submit_urb() in failed, ret=%d: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			__func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	/* ensure initialization is finished */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	usb_wait_anchor_empty_timeout(&bcd2k->anchor, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int bcd2000_init_midi(struct bcd2000 *bcd2k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct snd_rawmidi *rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	ret = snd_rawmidi_new(bcd2k->card, bcd2k->card->shortname, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 					1, /* output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 					1, /* input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 					&rmidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	strlcpy(rmidi->name, bcd2k->card->shortname, sizeof(rmidi->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	rmidi->info_flags = SNDRV_RAWMIDI_INFO_DUPLEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	rmidi->private_data = bcd2k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 					&bcd2000_midi_output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 					&bcd2000_midi_input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	bcd2k->rmidi = rmidi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	bcd2k->midi_in_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	bcd2k->midi_out_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (!bcd2k->midi_in_urb || !bcd2k->midi_out_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		dev_err(&bcd2k->dev->dev, PREFIX "usb_alloc_urb failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return -ENOMEM;
^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) 	usb_fill_int_urb(bcd2k->midi_in_urb, bcd2k->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 				usb_rcvintpipe(bcd2k->dev, 0x81),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 				bcd2k->midi_in_buf, BUFSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				bcd2000_input_complete, bcd2k, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	usb_fill_int_urb(bcd2k->midi_out_urb, bcd2k->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				usb_sndintpipe(bcd2k->dev, 0x1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				bcd2k->midi_out_buf, BUFSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 				bcd2000_output_complete, bcd2k, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	/* sanity checks of EPs before actually submitting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (usb_urb_ep_type_check(bcd2k->midi_in_urb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	    usb_urb_ep_type_check(bcd2k->midi_out_urb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		dev_err(&bcd2k->dev->dev, "invalid MIDI EP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	bcd2000_init_device(bcd2k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static void bcd2000_free_usb_related_resources(struct bcd2000 *bcd2k,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 						struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	/* usb_kill_urb not necessary, urb is aborted automatically */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	usb_free_urb(bcd2k->midi_out_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	usb_free_urb(bcd2k->midi_in_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	if (bcd2k->intf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		usb_set_intfdata(bcd2k->intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		bcd2k->intf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static int bcd2000_probe(struct usb_interface *interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 				const struct usb_device_id *usb_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	struct bcd2000 *bcd2k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	unsigned int card_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	char usb_path[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	mutex_lock(&devices_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	for (card_index = 0; card_index < SNDRV_CARDS; ++card_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		if (!test_bit(card_index, devices_used))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if (card_index >= SNDRV_CARDS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		mutex_unlock(&devices_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	err = snd_card_new(&interface->dev, index[card_index], id[card_index],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			THIS_MODULE, sizeof(*bcd2k), &card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		mutex_unlock(&devices_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	bcd2k = card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	bcd2k->dev = interface_to_usbdev(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	bcd2k->card = card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	bcd2k->card_index = card_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	bcd2k->intf = interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	snd_card_set_dev(card, &interface->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	strncpy(card->driver, "snd-bcd2000", sizeof(card->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	strncpy(card->shortname, "BCD2000", sizeof(card->shortname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	usb_make_path(bcd2k->dev, usb_path, sizeof(usb_path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	snprintf(bcd2k->card->longname, sizeof(bcd2k->card->longname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		    "Behringer BCD2000 at %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			usb_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	err = bcd2000_init_midi(bcd2k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		goto probe_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	err = snd_card_register(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		goto probe_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	usb_set_intfdata(interface, bcd2k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	set_bit(card_index, devices_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	mutex_unlock(&devices_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) probe_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	dev_info(&bcd2k->dev->dev, PREFIX "error during probing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	bcd2000_free_usb_related_resources(bcd2k, interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	mutex_unlock(&devices_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static void bcd2000_disconnect(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	struct bcd2000 *bcd2k = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (!bcd2k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	mutex_lock(&devices_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	/* make sure that userspace cannot create new requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	snd_card_disconnect(bcd2k->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	bcd2000_free_usb_related_resources(bcd2k, interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	clear_bit(bcd2k->card_index, devices_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	snd_card_free_when_closed(bcd2k->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	mutex_unlock(&devices_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) static struct usb_driver bcd2000_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	.name =		"snd-bcd2000",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	.probe =	bcd2000_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	.disconnect =	bcd2000_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	.id_table =	id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) module_usb_driver(bcd2000_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) MODULE_DEVICE_TABLE(usb, id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) MODULE_AUTHOR("Mario Kicherer, dev@kicherer.org");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) MODULE_DESCRIPTION("Behringer BCD2000 driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) MODULE_LICENSE("GPL");