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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 	PCM interface to POD series devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #ifndef PCM_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define PCM_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "driver.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	number of USB frames per URB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	The Line 6 Windows driver always transmits two frames per packet, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	the Linux driver performs significantly better (i.e., lower latency)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	with only one frame per packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define LINE6_ISO_PACKETS	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* in a "full speed" device (such as the PODxt Pro) this means 1ms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *  for "high speed" it's 1/8ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define LINE6_ISO_INTERVAL	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define LINE6_IMPULSE_DEFAULT_PERIOD 100
^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) 	Get substream from Line 6 PCM data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define get_substream(line6pcm, stream)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		(line6pcm->pcm->streams[stream].substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	PCM mode bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	There are several features of the Line 6 USB driver which require PCM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	data to be exchanged with the device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	*) PCM playback and capture via ALSA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	*) software monitoring (for devices without hardware monitoring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	*) optional impulse response measurement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	However, from the device's point of view, there is just a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	capture and playback stream, which must be shared between these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	subsystems. It is therefore necessary to maintain the state of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	subsystems with respect to PCM usage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	We define two bit flags, "opened" and "running", for each playback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	or capture stream.  Both can contain the bit flag corresponding to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	LINE6_STREAM_* type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	  LINE6_STREAM_PCM = ALSA PCM playback or capture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	  LINE6_STREAM_MONITOR = software monitoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	  IMPULSE = optional impulse response measurement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	The opened flag indicates whether the buffer is allocated while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	the running flag indicates whether the stream is running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	For monitor or impulse operations, the driver needs to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	line6_pcm_acquire() or line6_pcm_release() with the appropriate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	LINE6_STREAM_* flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /* stream types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	LINE6_STREAM_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	LINE6_STREAM_MONITOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	LINE6_STREAM_IMPULSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	LINE6_STREAM_CAPTURE_HELPER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /* misc bit flags for PCM operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	LINE6_FLAG_PAUSE_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	LINE6_FLAG_PREPARED,
^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) struct line6_pcm_properties {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct snd_pcm_hardware playback_hw, capture_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct snd_pcm_hw_constraint_ratdens rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int bytes_per_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) struct line6_pcm_stream {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	/* allocated URBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct urb **urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	/* Temporary buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 * Since the packet size is not known in advance, this buffer is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 * large enough to store maximum size packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	unsigned char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	/* Free frame position in the buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	snd_pcm_uframes_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	/* Count processed bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	 * This is modulo period size (to determine when a period is finished).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	unsigned bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/* Counter to create desired sample rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	unsigned count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/* period size in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	unsigned period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	/* Processed frame position in the buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	 * The contents of the ring buffer have been consumed by the USB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	 * subsystem (i.e., sent to the USB device) up to this position.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	snd_pcm_uframes_t pos_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/* Bit mask of active URBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	unsigned long active_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/* Bit mask of URBs currently being unlinked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	unsigned long unlink_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/* Spin lock to protect updates of the buffer positions (not contents)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	/* Bit flags for operational stream types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	unsigned long opened;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* Bit flags for running stream types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	unsigned long running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int last_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct snd_line6_pcm {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	/* Pointer back to the Line 6 driver data structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct usb_line6 *line6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	/* Properties. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct line6_pcm_properties *properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* ALSA pcm stream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	/* protection to state changes of in/out streams */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct mutex state_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* Capture and playback streams */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct line6_pcm_stream in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct line6_pcm_stream out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* Previously captured frame (for software monitoring) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	unsigned char *prev_fbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	/* Size of previously captured frame (for software monitoring/sync) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	int prev_fsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	/* Maximum size of USB packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	int max_packet_size_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	int max_packet_size_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	/* PCM playback volume (left and right) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	int volume_playback[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* PCM monitor volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int volume_monitor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* Volume of impulse response test signal (if zero, test is disabled) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int impulse_volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	/* Period of impulse response test signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int impulse_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* Counter for impulse response test signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	int impulse_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* Several status bits (see LINE6_FLAG_*) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) extern int line6_init_pcm(struct usb_line6 *line6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			  struct line6_pcm_properties *properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) extern int snd_line6_prepare(struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) extern int snd_line6_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			       struct snd_pcm_hw_params *hw_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) extern int snd_line6_hw_free(struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) extern snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			       bool start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) extern void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #endif