/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Line 6 Linux USB driver3*4* Copyright (C) 2004-2010 Markus Grabner ([email protected])5*/67/*8PCM interface to POD series devices.9*/1011#ifndef PCM_H12#define PCM_H1314#include <sound/pcm.h>1516#include "driver.h"1718/*19number of USB frames per URB20The Line 6 Windows driver always transmits two frames per packet, but21the Linux driver performs significantly better (i.e., lower latency)22with only one frame per packet.23*/24#define LINE6_ISO_PACKETS 12526/* in a "full speed" device (such as the PODxt Pro) this means 1ms,27* for "high speed" it's 1/8ms28*/29#define LINE6_ISO_INTERVAL 13031#define LINE6_IMPULSE_DEFAULT_PERIOD 1003233/*34Get substream from Line 6 PCM data structure35*/36#define get_substream(line6pcm, stream) \37(line6pcm->pcm->streams[stream].substream)3839/*40PCM mode bits.4142There are several features of the Line 6 USB driver which require PCM43data to be exchanged with the device:44*) PCM playback and capture via ALSA45*) software monitoring (for devices without hardware monitoring)46*) optional impulse response measurement47However, from the device's point of view, there is just a single48capture and playback stream, which must be shared between these49subsystems. It is therefore necessary to maintain the state of the50subsystems with respect to PCM usage.5152We define two bit flags, "opened" and "running", for each playback53or capture stream. Both can contain the bit flag corresponding to54LINE6_STREAM_* type,55LINE6_STREAM_PCM = ALSA PCM playback or capture56LINE6_STREAM_MONITOR = software monitoring57IMPULSE = optional impulse response measurement58The opened flag indicates whether the buffer is allocated while59the running flag indicates whether the stream is running.6061For monitor or impulse operations, the driver needs to call62line6_pcm_acquire() or line6_pcm_release() with the appropriate63LINE6_STREAM_* flag.64*/6566/* stream types */67enum {68LINE6_STREAM_PCM,69LINE6_STREAM_MONITOR,70LINE6_STREAM_IMPULSE,71LINE6_STREAM_CAPTURE_HELPER,72};7374/* misc bit flags for PCM operation */75enum {76LINE6_FLAG_PAUSE_PLAYBACK,77LINE6_FLAG_PREPARED,78};7980struct line6_pcm_properties {81struct snd_pcm_hardware playback_hw, capture_hw;82struct snd_pcm_hw_constraint_ratdens rates;83int bytes_per_channel;84};8586struct line6_pcm_stream {87/* allocated URBs */88struct urb **urbs;8990/* Temporary buffer;91* Since the packet size is not known in advance, this buffer is92* large enough to store maximum size packets.93*/94unsigned char *buffer;9596/* Free frame position in the buffer. */97snd_pcm_uframes_t pos;9899/* Count processed bytes;100* This is modulo period size (to determine when a period is finished).101*/102unsigned bytes;103104/* Counter to create desired sample rate */105unsigned count;106107/* period size in bytes */108unsigned period;109110/* Processed frame position in the buffer;111* The contents of the ring buffer have been consumed by the USB112* subsystem (i.e., sent to the USB device) up to this position.113*/114snd_pcm_uframes_t pos_done;115116/* Bit mask of active URBs */117unsigned long active_urbs;118119/* Bit mask of URBs currently being unlinked */120unsigned long unlink_urbs;121122/* Spin lock to protect updates of the buffer positions (not contents)123*/124spinlock_t lock;125126/* Bit flags for operational stream types */127unsigned long opened;128129/* Bit flags for running stream types */130unsigned long running;131132int last_frame;133};134135struct snd_line6_pcm {136/* Pointer back to the Line 6 driver data structure */137struct usb_line6 *line6;138139/* Properties. */140struct line6_pcm_properties *properties;141142/* ALSA pcm stream */143struct snd_pcm *pcm;144145/* protection to state changes of in/out streams */146struct mutex state_mutex;147148/* Capture and playback streams */149struct line6_pcm_stream in;150struct line6_pcm_stream out;151152/* Previously captured frame (for software monitoring) */153unsigned char *prev_fbuf;154155/* Size of previously captured frame (for software monitoring/sync) */156int prev_fsize;157158/* Maximum size of USB packet */159int max_packet_size_in;160int max_packet_size_out;161162/* PCM playback volume (left and right) */163int volume_playback[2];164165/* PCM monitor volume */166int volume_monitor;167168/* Volume of impulse response test signal (if zero, test is disabled) */169int impulse_volume;170171/* Period of impulse response test signal */172int impulse_period;173174/* Counter for impulse response test signal */175int impulse_count;176177/* Several status bits (see LINE6_FLAG_*) */178unsigned long flags;179};180181extern int line6_init_pcm(struct usb_line6 *line6,182struct line6_pcm_properties *properties);183extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd);184extern int snd_line6_prepare(struct snd_pcm_substream *substream);185extern int snd_line6_hw_params(struct snd_pcm_substream *substream,186struct snd_pcm_hw_params *hw_params);187extern int snd_line6_hw_free(struct snd_pcm_substream *substream);188extern snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream);189extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm);190extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type,191bool start);192extern void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type);193194#endif195196197