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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Line 6 Linux USB driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "capture.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "driver.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "pcm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	Find a free URB and submit it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	must be called in line6pcm->in.lock context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static int submit_audio_in_urb(struct snd_line6_pcm *line6pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	int i, urb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct urb *urb_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	index = find_first_zero_bit(&line6pcm->in.active_urbs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 				    line6pcm->line6->iso_buffers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (index < 0 || index >= line6pcm->line6->iso_buffers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		dev_err(line6pcm->line6->ifcdev, "no free URB found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	urb_in = line6pcm->in.urbs[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	urb_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		struct usb_iso_packet_descriptor *fin =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		    &urb_in->iso_frame_desc[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		fin->offset = urb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		fin->length = line6pcm->max_packet_size_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		urb_size += line6pcm->max_packet_size_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	urb_in->transfer_buffer =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	    line6pcm->in.buffer +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	    index * LINE6_ISO_PACKETS * line6pcm->max_packet_size_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	urb_in->transfer_buffer_length = urb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	urb_in->context = line6pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	ret = usb_submit_urb(urb_in, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		set_bit(index, &line6pcm->in.active_urbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		dev_err(line6pcm->line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			"URB in #%d submission failed (%d)\n", index, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	Submit all currently available capture URBs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	must be called in line6pcm->in.lock context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) int line6_submit_audio_in_all_urbs(struct snd_line6_pcm *line6pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	int ret = 0, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	for (i = 0; i < line6pcm->line6->iso_buffers; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		ret = submit_audio_in_urb(line6pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			break;
^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) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	Copy data into ALSA capture buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct snd_pcm_substream *substream =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	    get_substream(line6pcm, SNDRV_PCM_STREAM_CAPTURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	const int bytes_per_frame =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		line6pcm->properties->bytes_per_channel *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		line6pcm->properties->capture_hw.channels_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	int frames = fsize / bytes_per_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (runtime == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (line6pcm->in.pos_done + frames > runtime->buffer_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		   The transferred area goes over buffer boundary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		   copy two separate chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		len = runtime->buffer_size - line6pcm->in.pos_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		if (len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			memcpy(runtime->dma_area +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			       line6pcm->in.pos_done * bytes_per_frame, fbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			       len * bytes_per_frame);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			memcpy(runtime->dma_area, fbuf + len * bytes_per_frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			       (frames - len) * bytes_per_frame);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			/* this is somewhat paranoid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			dev_err(line6pcm->line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 				"driver bug: len = %d\n", len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		/* copy single chunk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		memcpy(runtime->dma_area +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		       line6pcm->in.pos_done * bytes_per_frame, fbuf, fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	line6pcm->in.pos_done += frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (line6pcm->in.pos_done >= runtime->buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		line6pcm->in.pos_done -= runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) void line6_capture_check_period(struct snd_line6_pcm *line6pcm, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct snd_pcm_substream *substream =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	    get_substream(line6pcm, SNDRV_PCM_STREAM_CAPTURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	line6pcm->in.bytes += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (line6pcm->in.bytes >= line6pcm->in.period) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		line6pcm->in.bytes %= line6pcm->in.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		spin_unlock(&line6pcm->in.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		snd_pcm_period_elapsed(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		spin_lock(&line6pcm->in.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * Callback for completed capture URB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static void audio_in_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int i, index, length = 0, shutdown = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct snd_line6_pcm *line6pcm = (struct snd_line6_pcm *)urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	line6pcm->in.last_frame = urb->start_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	/* find index of URB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	for (index = 0; index < line6pcm->line6->iso_buffers; ++index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		if (urb == line6pcm->in.urbs[index])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	spin_lock_irqsave(&line6pcm->in.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		char *fbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		int fsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		struct usb_iso_packet_descriptor *fin = &urb->iso_frame_desc[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (fin->status == -EXDEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			shutdown = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		fbuf = urb->transfer_buffer + fin->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		fsize = fin->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		if (fsize > line6pcm->max_packet_size_in) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			dev_err(line6pcm->line6->ifcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 				"driver and/or device bug: packet too large (%d > %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				fsize, line6pcm->max_packet_size_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		length += fsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		BUILD_BUG_ON_MSG(LINE6_ISO_PACKETS != 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			"The following code assumes LINE6_ISO_PACKETS == 1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		/* TODO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		 * Also, if iso_buffers != 2, the prev frame is almost random at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		 * playback side.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		 * This needs to be redesigned. It should be "stable", but we may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		 * experience sync problems on such high-speed configs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		line6pcm->prev_fbuf = fbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		line6pcm->prev_fsize = fsize /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			(line6pcm->properties->bytes_per_channel *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			line6pcm->properties->capture_hw.channels_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		if (!test_bit(LINE6_STREAM_IMPULSE, &line6pcm->in.running) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		    test_bit(LINE6_STREAM_PCM, &line6pcm->in.running) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		    fsize > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			line6_capture_copy(line6pcm, fbuf, fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	clear_bit(index, &line6pcm->in.active_urbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (test_and_clear_bit(index, &line6pcm->in.unlink_urbs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		shutdown = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (!shutdown) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		submit_audio_in_urb(line6pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		if (!test_bit(LINE6_STREAM_IMPULSE, &line6pcm->in.running) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		    test_bit(LINE6_STREAM_PCM, &line6pcm->in.running))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			line6_capture_check_period(line6pcm, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	spin_unlock_irqrestore(&line6pcm->in.lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* open capture callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int snd_line6_capture_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	err = snd_pcm_hw_constraint_ratdens(runtime, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 					    SNDRV_PCM_HW_PARAM_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 					    &line6pcm->properties->rates);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	line6_pcm_acquire(line6pcm, LINE6_STREAM_CAPTURE_HELPER, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	runtime->hw = line6pcm->properties->capture_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /* close capture callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static int snd_line6_capture_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	line6_pcm_release(line6pcm, LINE6_STREAM_CAPTURE_HELPER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return 0;
^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) /* capture operators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) const struct snd_pcm_ops snd_line6_capture_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.open = snd_line6_capture_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	.close = snd_line6_capture_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	.hw_params = snd_line6_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	.hw_free = snd_line6_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	.prepare = snd_line6_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	.trigger = snd_line6_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	.pointer = snd_line6_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct usb_line6 *line6 = line6pcm->line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	line6pcm->in.urbs = kcalloc(line6->iso_buffers, sizeof(struct urb *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 				    GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (line6pcm->in.urbs == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	/* create audio URBs and fill in constant values: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	for (i = 0; i < line6->iso_buffers; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		/* URB for audio in: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		urb = line6pcm->in.urbs[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		    usb_alloc_urb(LINE6_ISO_PACKETS, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		if (urb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		urb->dev = line6->usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		urb->pipe =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		    usb_rcvisocpipe(line6->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				    line6->properties->ep_audio_r &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 				    USB_ENDPOINT_NUMBER_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		urb->transfer_flags = URB_ISO_ASAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		urb->start_frame = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		urb->number_of_packets = LINE6_ISO_PACKETS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		urb->interval = LINE6_ISO_INTERVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		urb->error_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		urb->complete = audio_in_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		if (usb_urb_ep_type_check(urb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }