2019-05-27 09:55:05 +03:00
// SPDX-License-Identifier: GPL-2.0-or-later
2005-04-17 02:20:36 +04:00
/*
*/
/* USX2Y "rawusb" aka hwdep_pcm implementation
Its usb ' s unableness to atomically handle power of 2 period sized data chuncs
at standard samplerates ,
2021-05-17 16:15:36 +03:00
what led to this part of the usx2y module :
2005-04-17 02:20:36 +04:00
It provides the alsa kernel half of the usx2y - alsa - jack driver pair .
2011-03-31 05:57:33 +04:00
The pair uses a hardware dependent alsa - device for mmaped pcm transport .
2005-04-17 02:20:36 +04:00
Advantage achieved :
The usb_hc moves pcm data from / into memory via DMA .
That memory is mmaped by jack ' s usx2y driver .
Jack ' s usx2y driver is the first / last to read / write pcm data .
Read / write is a combination of power of 2 period shaping and
float / int conversation .
Compared to mainline alsa / jack we leave out power of 2 period shaping inside
snd - usb - usx2y which needs memcpy ( ) and additional buffers .
As a side effect possible unwanted pcm - data coruption resulting of
standard alsa ' s snd - usb - usx2y period shaping scheme falls away .
Result is sane jack operation at buffering schemes down to 128f rames ,
2 periods .
plain usx2y alsa mode is able to achieve 64f rames , 4 periods , but only at the
cost of easier triggered i . e . aeolus xruns ( 128 or 256f rames ,
2 periods works but is useless cause of crackling ) .
2010-10-16 17:19:20 +04:00
2005-04-17 02:20:36 +04:00
This is a first " proof of concept " implementation .
2011-03-31 05:57:33 +04:00
Later , functionalities should migrate to more appropriate places :
2005-04-17 02:20:36 +04:00
Userland :
- The jackd could mmap its float - pcm buffers directly from alsa - lib .
- alsa - lib could provide power of 2 period sized shaping combined with int / float
conversation .
Currently the usx2y jack driver provides above 2 services .
Kernel :
- rawusb dma pcm buffer transport should go to snd - usb - lib , so also snd - usb - audio
devices can use it .
2021-05-17 16:15:36 +03:00
Currently rawusb dma pcm buffer transport ( this file ) is only available to snd - usb - usx2y .
2005-04-17 02:20:36 +04:00
*/
2005-07-09 12:54:37 +04:00
# include <linux/delay.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
# include <linux/gfp.h>
2005-04-17 02:20:36 +04:00
# include "usbusx2yaudio.c"
2010-10-05 19:38:12 +04:00
# if defined(USX2Y_NRPACKS_VARIABLE) || USX2Y_NRPACKS == 1
2005-04-17 02:20:36 +04:00
# include <sound/hwdep.h>
2021-05-17 16:15:35 +03:00
static int usx2y_usbpcm_urb_capt_retire ( struct snd_usx2y_substream * subs )
2005-04-17 02:20:36 +04:00
{
struct urb * urb = subs - > completed_urb ;
2005-11-17 17:08:26 +03:00
struct snd_pcm_runtime * runtime = subs - > pcm_substream - > runtime ;
2021-05-17 16:15:36 +03:00
int i , lens = 0 , hwptr_done = subs - > hwptr_done ;
2021-05-17 16:15:35 +03:00
struct usx2ydev * usx2y = subs - > usx2y ;
2021-05-17 16:15:37 +03:00
int head ;
2021-05-17 16:15:36 +03:00
2021-05-17 16:15:37 +03:00
if ( usx2y - > hwdep_pcm_shm - > capture_iso_start < 0 ) { //FIXME
head = usx2y - > hwdep_pcm_shm - > captured_iso_head + 1 ;
2021-05-17 16:15:35 +03:00
if ( head > = ARRAY_SIZE ( usx2y - > hwdep_pcm_shm - > captured_iso ) )
2005-04-17 02:20:36 +04:00
head = 0 ;
2021-05-17 16:15:35 +03:00
usx2y - > hwdep_pcm_shm - > capture_iso_start = head ;
2005-04-17 02:20:36 +04:00
snd_printdd ( " cap start %i \n " , head ) ;
}
for ( i = 0 ; i < nr_of_packs ( ) ; i + + ) {
if ( urb - > iso_frame_desc [ i ] . status ) { /* active? hmm, skip this */
2021-05-17 16:15:36 +03:00
snd_printk ( KERN_ERR
" active frame status %i. Most probably some hardware problem. \n " ,
urb - > iso_frame_desc [ i ] . status ) ;
2005-04-17 02:20:36 +04:00
return urb - > iso_frame_desc [ i ] . status ;
}
2021-05-17 16:15:35 +03:00
lens + = urb - > iso_frame_desc [ i ] . actual_length / usx2y - > stride ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:37 +03:00
hwptr_done + = lens ;
if ( hwptr_done > = runtime - > buffer_size )
2005-04-17 02:20:36 +04:00
hwptr_done - = runtime - > buffer_size ;
subs - > hwptr_done = hwptr_done ;
subs - > transfer_done + = lens ;
/* update the pointer, call callback if necessary */
if ( subs - > transfer_done > = runtime - > period_size ) {
subs - > transfer_done - = runtime - > period_size ;
snd_pcm_period_elapsed ( subs - > pcm_substream ) ;
}
return 0 ;
}
2021-05-17 16:15:37 +03:00
static int usx2y_iso_frames_per_buffer ( struct snd_pcm_runtime * runtime ,
2021-05-17 16:15:36 +03:00
struct usx2ydev * usx2y )
2005-04-17 02:20:36 +04:00
{
2021-05-17 16:15:35 +03:00
return ( runtime - > buffer_size * 1000 ) / usx2y - > rate + 1 ; //FIXME: so far only correct period_size == 2^x ?
2005-04-17 02:20:36 +04:00
}
/*
* prepare urb for playback data pipe
*
* we copy the data directly from the pcm buffer .
* the current position to be copied is held in hwptr field .
* since a urb can handle only a single linear buffer , if the total
* transferred area overflows the buffer boundary , we cannot send
* it directly from the buffer . thus the data is once copied to
* a temporary buffer and urb points to that .
*/
2021-05-17 16:15:35 +03:00
static int usx2y_hwdep_urb_play_prepare ( struct snd_usx2y_substream * subs ,
2005-11-17 17:08:26 +03:00
struct urb * urb )
2005-04-17 02:20:36 +04:00
{
int count , counts , pack ;
2021-05-17 16:15:35 +03:00
struct usx2ydev * usx2y = subs - > usx2y ;
struct snd_usx2y_hwdep_pcm_shm * shm = usx2y - > hwdep_pcm_shm ;
2005-11-17 17:08:26 +03:00
struct snd_pcm_runtime * runtime = subs - > pcm_substream - > runtime ;
2005-04-17 02:20:36 +04:00
2021-05-17 16:15:37 +03:00
if ( shm - > playback_iso_start < 0 ) {
2005-04-17 02:20:36 +04:00
shm - > playback_iso_start = shm - > captured_iso_head -
2021-05-17 16:15:35 +03:00
usx2y_iso_frames_per_buffer ( runtime , usx2y ) ;
2021-05-17 16:15:37 +03:00
if ( shm - > playback_iso_start < 0 )
2005-04-17 02:20:36 +04:00
shm - > playback_iso_start + = ARRAY_SIZE ( shm - > captured_iso ) ;
shm - > playback_iso_head = shm - > playback_iso_start ;
}
count = 0 ;
for ( pack = 0 ; pack < nr_of_packs ( ) ; pack + + ) {
/* calculate the size of a packet */
2021-05-17 16:15:35 +03:00
counts = shm - > captured_iso [ shm - > playback_iso_head ] . length / usx2y - > stride ;
2005-04-17 02:20:36 +04:00
if ( counts < 43 | | counts > 50 ) {
2005-10-21 18:20:11 +04:00
snd_printk ( KERN_ERR " should not be here with counts=%i \n " , counts ) ;
2005-04-17 02:20:36 +04:00
return - EPIPE ;
}
/* set up descriptor */
urb - > iso_frame_desc [ pack ] . offset = shm - > captured_iso [ shm - > playback_iso_head ] . offset ;
urb - > iso_frame_desc [ pack ] . length = shm - > captured_iso [ shm - > playback_iso_head ] . length ;
2021-05-17 16:15:35 +03:00
if ( atomic_read ( & subs - > state ) ! = STATE_RUNNING )
2005-04-17 02:20:36 +04:00
memset ( ( char * ) urb - > transfer_buffer + urb - > iso_frame_desc [ pack ] . offset , 0 ,
urb - > iso_frame_desc [ pack ] . length ) ;
if ( + + shm - > playback_iso_head > = ARRAY_SIZE ( shm - > captured_iso ) )
shm - > playback_iso_head = 0 ;
count + = counts ;
}
2021-05-17 16:15:35 +03:00
urb - > transfer_buffer_length = count * usx2y - > stride ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
2021-05-17 16:15:37 +03:00
static void usx2y_usbpcm_urb_capt_iso_advance ( struct snd_usx2y_substream * subs ,
struct urb * urb )
2005-04-17 02:20:36 +04:00
{
2021-05-17 16:15:37 +03:00
struct usb_iso_packet_descriptor * desc ;
struct snd_usx2y_hwdep_pcm_shm * shm ;
int pack , head ;
2021-05-17 16:15:36 +03:00
2005-04-17 02:20:36 +04:00
for ( pack = 0 ; pack < nr_of_packs ( ) ; + + pack ) {
2021-05-17 16:15:37 +03:00
desc = urb - > iso_frame_desc + pack ;
if ( subs ) {
shm = subs - > usx2y - > hwdep_pcm_shm ;
head = shm - > captured_iso_head + 1 ;
2005-04-17 02:20:36 +04:00
if ( head > = ARRAY_SIZE ( shm - > captured_iso ) )
head = 0 ;
shm - > captured_iso [ head ] . frame = urb - > start_frame + pack ;
shm - > captured_iso [ head ] . offset = desc - > offset ;
shm - > captured_iso [ head ] . length = desc - > actual_length ;
shm - > captured_iso_head = head ;
shm - > captured_iso_frames + + ;
}
2021-05-17 16:15:37 +03:00
desc - > offset + = desc - > length * NRURBS * nr_of_packs ( ) ;
if ( desc - > offset + desc - > length > = SSS )
2005-04-17 02:20:36 +04:00
desc - > offset - = ( SSS - desc - > length ) ;
}
}
2021-05-17 16:15:37 +03:00
static int usx2y_usbpcm_usbframe_complete ( struct snd_usx2y_substream * capsubs ,
struct snd_usx2y_substream * capsubs2 ,
struct snd_usx2y_substream * playbacksubs ,
int frame )
2005-04-17 02:20:36 +04:00
{
int err , state ;
struct urb * urb = playbacksubs - > completed_urb ;
state = atomic_read ( & playbacksubs - > state ) ;
2021-05-17 16:15:37 +03:00
if ( urb ) {
2021-05-17 16:15:35 +03:00
if ( state = = STATE_RUNNING )
usx2y_urb_play_retire ( playbacksubs , urb ) ;
else if ( state > = STATE_PRERUNNING )
2005-11-17 12:48:52 +03:00
atomic_inc ( & playbacksubs - > state ) ;
2005-04-17 02:20:36 +04:00
} else {
switch ( state ) {
2021-05-17 16:15:35 +03:00
case STATE_STARTING1 :
2005-04-17 02:20:36 +04:00
urb = playbacksubs - > urb [ 0 ] ;
atomic_inc ( & playbacksubs - > state ) ;
break ;
2021-05-17 16:15:35 +03:00
case STATE_STARTING2 :
2005-04-17 02:20:36 +04:00
urb = playbacksubs - > urb [ 1 ] ;
atomic_inc ( & playbacksubs - > state ) ;
break ;
}
}
if ( urb ) {
2021-05-17 16:15:37 +03:00
err = usx2y_hwdep_urb_play_prepare ( playbacksubs , urb ) ;
if ( err )
return err ;
err = usx2y_hwdep_urb_play_prepare ( playbacksubs , urb ) ;
if ( err )
2005-04-17 02:20:36 +04:00
return err ;
}
2021-05-17 16:15:36 +03:00
2005-04-17 02:20:36 +04:00
playbacksubs - > completed_urb = NULL ;
state = atomic_read ( & capsubs - > state ) ;
2021-05-17 16:15:35 +03:00
if ( state > = STATE_PREPARED ) {
if ( state = = STATE_RUNNING ) {
2021-05-17 16:15:37 +03:00
err = usx2y_usbpcm_urb_capt_retire ( capsubs ) ;
if ( err )
2005-04-17 02:20:36 +04:00
return err ;
2021-05-17 16:15:37 +03:00
} else if ( state > = STATE_PRERUNNING ) {
2005-11-17 12:48:52 +03:00
atomic_inc ( & capsubs - > state ) ;
2021-05-17 16:15:37 +03:00
}
2021-05-17 16:15:35 +03:00
usx2y_usbpcm_urb_capt_iso_advance ( capsubs , capsubs - > completed_urb ) ;
2021-05-17 16:15:37 +03:00
if ( capsubs2 )
2021-05-17 16:15:35 +03:00
usx2y_usbpcm_urb_capt_iso_advance ( NULL , capsubs2 - > completed_urb ) ;
2021-05-17 16:15:37 +03:00
err = usx2y_urb_submit ( capsubs , capsubs - > completed_urb , frame ) ;
if ( err )
2005-04-17 02:20:36 +04:00
return err ;
2021-05-17 16:15:37 +03:00
if ( capsubs2 ) {
err = usx2y_urb_submit ( capsubs2 , capsubs2 - > completed_urb , frame ) ;
if ( err )
2005-04-17 02:20:36 +04:00
return err ;
2021-05-17 16:15:37 +03:00
}
2005-04-17 02:20:36 +04:00
}
capsubs - > completed_urb = NULL ;
2021-05-17 16:15:37 +03:00
if ( capsubs2 )
2005-04-17 02:20:36 +04:00
capsubs2 - > completed_urb = NULL ;
return 0 ;
}
2021-05-17 16:15:35 +03:00
static void i_usx2y_usbpcm_urb_complete ( struct urb * urb )
2005-04-17 02:20:36 +04:00
{
2021-05-17 16:15:35 +03:00
struct snd_usx2y_substream * subs = urb - > context ;
struct usx2ydev * usx2y = subs - > usx2y ;
struct snd_usx2y_substream * capsubs , * capsubs2 , * playbacksubs ;
2005-04-17 02:20:36 +04:00
2021-05-17 16:15:35 +03:00
if ( unlikely ( atomic_read ( & subs - > state ) < STATE_PREPARED ) ) {
2005-11-17 17:08:26 +03:00
snd_printdd ( " hcd_frame=%i ep=%i%s status=%i start_frame=%i \n " ,
2021-05-17 16:15:35 +03:00
usb_get_current_frame_number ( usx2y - > dev ) ,
2005-11-17 17:08:26 +03:00
subs - > endpoint , usb_pipein ( urb - > pipe ) ? " in " : " out " ,
urb - > status , urb - > start_frame ) ;
2005-04-17 02:20:36 +04:00
return ;
}
if ( unlikely ( urb - > status ) ) {
2021-05-17 16:15:35 +03:00
usx2y_error_urb_status ( usx2y , subs , urb ) ;
2005-04-17 02:20:36 +04:00
return ;
}
2013-10-02 19:49:50 +04:00
subs - > completed_urb = urb ;
2021-05-17 16:15:35 +03:00
capsubs = usx2y - > subs [ SNDRV_PCM_STREAM_CAPTURE ] ;
capsubs2 = usx2y - > subs [ SNDRV_PCM_STREAM_CAPTURE + 2 ] ;
playbacksubs = usx2y - > subs [ SNDRV_PCM_STREAM_PLAYBACK ] ;
if ( capsubs - > completed_urb & & atomic_read ( & capsubs - > state ) > = STATE_PREPARED & &
2021-05-17 16:15:37 +03:00
( ! capsubs2 | | capsubs2 - > completed_urb ) & &
2021-05-17 16:15:35 +03:00
( playbacksubs - > completed_urb | | atomic_read ( & playbacksubs - > state ) < STATE_PREPARED ) ) {
2021-05-17 16:15:37 +03:00
if ( ! usx2y_usbpcm_usbframe_complete ( capsubs , capsubs2 , playbacksubs , urb - > start_frame ) ) {
2021-05-17 16:15:35 +03:00
usx2y - > wait_iso_frame + = nr_of_packs ( ) ;
2021-05-17 16:15:37 +03:00
} else {
2005-04-17 02:20:36 +04:00
snd_printdd ( " \n " ) ;
2021-05-17 16:15:35 +03:00
usx2y_clients_stop ( usx2y ) ;
2005-04-17 02:20:36 +04:00
}
}
}
2021-05-17 16:15:35 +03:00
static void usx2y_hwdep_urb_release ( struct urb * * urb )
2005-04-17 02:20:36 +04:00
{
usb_kill_urb ( * urb ) ;
usb_free_urb ( * urb ) ;
* urb = NULL ;
}
/*
* release a substream
*/
2021-05-17 16:15:35 +03:00
static void usx2y_usbpcm_urbs_release ( struct snd_usx2y_substream * subs )
2005-04-17 02:20:36 +04:00
{
int i ;
2021-05-17 16:15:36 +03:00
2021-05-17 16:15:35 +03:00
snd_printdd ( " snd_usx2y_urbs_release() %i \n " , subs - > endpoint ) ;
2005-04-17 02:20:36 +04:00
for ( i = 0 ; i < NRURBS ; i + + )
2021-05-17 16:15:35 +03:00
usx2y_hwdep_urb_release ( subs - > urb + i ) ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:36 +03:00
static void usx2y_usbpcm_subs_startup_finish ( struct usx2ydev * usx2y )
2005-04-17 02:20:36 +04:00
{
2021-05-17 16:15:35 +03:00
usx2y_urbs_set_complete ( usx2y , i_usx2y_usbpcm_urb_complete ) ;
usx2y - > prepare_subs = NULL ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:35 +03:00
static void i_usx2y_usbpcm_subs_startup ( struct urb * urb )
2005-04-17 02:20:36 +04:00
{
2021-05-17 16:15:35 +03:00
struct snd_usx2y_substream * subs = urb - > context ;
struct usx2ydev * usx2y = subs - > usx2y ;
struct snd_usx2y_substream * prepare_subs = usx2y - > prepare_subs ;
2021-05-17 16:15:37 +03:00
struct snd_usx2y_substream * cap_subs2 ;
2021-05-17 16:15:36 +03:00
2021-05-17 16:15:37 +03:00
if ( prepare_subs & &
2005-04-17 02:20:36 +04:00
urb - > start_frame = = prepare_subs - > urb [ 0 ] - > start_frame ) {
atomic_inc ( & prepare_subs - > state ) ;
2021-05-17 16:15:35 +03:00
if ( prepare_subs = = usx2y - > subs [ SNDRV_PCM_STREAM_CAPTURE ] ) {
2021-05-17 16:15:37 +03:00
cap_subs2 = usx2y - > subs [ SNDRV_PCM_STREAM_CAPTURE + 2 ] ;
if ( cap_subs2 )
2005-04-17 02:20:36 +04:00
atomic_inc ( & cap_subs2 - > state ) ;
}
2021-05-17 16:15:35 +03:00
usx2y_usbpcm_subs_startup_finish ( usx2y ) ;
wake_up ( & usx2y - > prepare_wait_queue ) ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:35 +03:00
i_usx2y_usbpcm_urb_complete ( urb ) ;
2005-04-17 02:20:36 +04:00
}
/*
* initialize a substream ' s urbs
*/
2021-05-17 16:15:35 +03:00
static int usx2y_usbpcm_urbs_allocate ( struct snd_usx2y_substream * subs )
2005-04-17 02:20:36 +04:00
{
int i ;
unsigned int pipe ;
2021-05-17 16:15:35 +03:00
int is_playback = subs = = subs - > usx2y - > subs [ SNDRV_PCM_STREAM_PLAYBACK ] ;
struct usb_device * dev = subs - > usx2y - > dev ;
2021-05-17 16:15:37 +03:00
struct urb * * purb ;
2005-04-17 02:20:36 +04:00
pipe = is_playback ? usb_sndisocpipe ( dev , subs - > endpoint ) :
usb_rcvisocpipe ( dev , subs - > endpoint ) ;
2022-03-17 06:55:12 +03:00
subs - > maxpacksize = usb_maxpacket ( dev , pipe ) ;
2005-04-17 02:20:36 +04:00
if ( ! subs - > maxpacksize )
return - EINVAL ;
/* allocate and initialize data urbs */
for ( i = 0 ; i < NRURBS ; i + + ) {
2021-05-17 16:15:37 +03:00
purb = subs - > urb + i ;
2005-04-17 02:20:36 +04:00
if ( * purb ) {
usb_kill_urb ( * purb ) ;
continue ;
}
* purb = usb_alloc_urb ( nr_of_packs ( ) , GFP_KERNEL ) ;
2021-05-17 16:15:37 +03:00
if ( ! * purb ) {
2021-05-17 16:15:35 +03:00
usx2y_usbpcm_urbs_release ( subs ) ;
2005-04-17 02:20:36 +04:00
return - ENOMEM ;
}
( * purb ) - > transfer_buffer = is_playback ?
2021-05-17 16:15:35 +03:00
subs - > usx2y - > hwdep_pcm_shm - > playback : (
2005-04-17 02:20:36 +04:00
subs - > endpoint = = 0x8 ?
2021-05-17 16:15:35 +03:00
subs - > usx2y - > hwdep_pcm_shm - > capture0x8 :
subs - > usx2y - > hwdep_pcm_shm - > capture0xA ) ;
2005-04-17 02:20:36 +04:00
( * purb ) - > dev = dev ;
( * purb ) - > pipe = pipe ;
( * purb ) - > number_of_packets = nr_of_packs ( ) ;
( * purb ) - > context = subs ;
( * purb ) - > interval = 1 ;
2021-05-17 16:15:35 +03:00
( * purb ) - > complete = i_usx2y_usbpcm_subs_startup ;
2005-04-17 02:20:36 +04:00
}
return 0 ;
}
/*
* free the buffer
*/
2021-05-17 16:15:35 +03:00
static int snd_usx2y_usbpcm_hw_free ( struct snd_pcm_substream * substream )
2005-04-17 02:20:36 +04:00
{
2005-11-17 17:08:26 +03:00
struct snd_pcm_runtime * runtime = substream - > runtime ;
2021-05-17 16:15:37 +03:00
struct snd_usx2y_substream * subs = runtime - > private_data ;
struct snd_usx2y_substream * cap_subs ;
struct snd_usx2y_substream * playback_subs ;
struct snd_usx2y_substream * cap_subs2 ;
2021-05-17 16:15:36 +03:00
2021-05-17 16:15:35 +03:00
mutex_lock ( & subs - > usx2y - > pcm_mutex ) ;
2021-05-17 16:15:37 +03:00
snd_printdd ( " %s(%p) \n " , __func__ , substream ) ;
2021-05-17 16:15:36 +03:00
2021-05-17 16:15:37 +03:00
cap_subs2 = subs - > usx2y - > subs [ SNDRV_PCM_STREAM_CAPTURE + 2 ] ;
if ( substream - > stream = = SNDRV_PCM_STREAM_PLAYBACK ) {
cap_subs = subs - > usx2y - > subs [ SNDRV_PCM_STREAM_CAPTURE ] ;
2021-05-17 16:15:35 +03:00
atomic_set ( & subs - > state , STATE_STOPPED ) ;
usx2y_usbpcm_urbs_release ( subs ) ;
2005-04-17 02:20:36 +04:00
if ( ! cap_subs - > pcm_substream | |
! cap_subs - > pcm_substream - > runtime | |
2022-09-26 16:55:55 +03:00
cap_subs - > pcm_substream - > runtime - > state < SNDRV_PCM_STATE_PREPARED ) {
2021-05-17 16:15:35 +03:00
atomic_set ( & cap_subs - > state , STATE_STOPPED ) ;
2021-05-17 16:15:37 +03:00
if ( cap_subs2 )
2021-05-17 16:15:35 +03:00
atomic_set ( & cap_subs2 - > state , STATE_STOPPED ) ;
usx2y_usbpcm_urbs_release ( cap_subs ) ;
2021-05-17 16:15:37 +03:00
if ( cap_subs2 )
2021-05-17 16:15:35 +03:00
usx2y_usbpcm_urbs_release ( cap_subs2 ) ;
2005-04-17 02:20:36 +04:00
}
} else {
2021-05-17 16:15:37 +03:00
playback_subs = subs - > usx2y - > subs [ SNDRV_PCM_STREAM_PLAYBACK ] ;
2021-05-17 16:15:35 +03:00
if ( atomic_read ( & playback_subs - > state ) < STATE_PREPARED ) {
atomic_set ( & subs - > state , STATE_STOPPED ) ;
2021-05-17 16:15:37 +03:00
if ( cap_subs2 )
2021-05-17 16:15:35 +03:00
atomic_set ( & cap_subs2 - > state , STATE_STOPPED ) ;
usx2y_usbpcm_urbs_release ( subs ) ;
2021-05-17 16:15:37 +03:00
if ( cap_subs2 )
2021-05-17 16:15:35 +03:00
usx2y_usbpcm_urbs_release ( cap_subs2 ) ;
2005-04-17 02:20:36 +04:00
}
}
2021-05-17 16:15:35 +03:00
mutex_unlock ( & subs - > usx2y - > pcm_mutex ) ;
2019-12-09 12:49:41 +03:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:35 +03:00
static void usx2y_usbpcm_subs_startup ( struct snd_usx2y_substream * subs )
2005-04-17 02:20:36 +04:00
{
2021-05-17 16:15:36 +03:00
struct usx2ydev * usx2y = subs - > usx2y ;
2021-05-17 16:15:35 +03:00
usx2y - > prepare_subs = subs ;
2005-04-17 02:20:36 +04:00
subs - > urb [ 0 ] - > start_frame = - 1 ;
2021-05-17 16:15:35 +03:00
smp_wmb ( ) ; // Make sure above modifications are seen by i_usx2y_subs_startup()
usx2y_urbs_set_complete ( usx2y , i_usx2y_usbpcm_subs_startup ) ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:35 +03:00
static int usx2y_usbpcm_urbs_start ( struct snd_usx2y_substream * subs )
2005-04-17 02:20:36 +04:00
{
2021-05-17 16:15:36 +03:00
int p , u , err , stream = subs - > pcm_substream - > stream ;
2021-05-17 16:15:35 +03:00
struct usx2ydev * usx2y = subs - > usx2y ;
2021-05-17 16:15:37 +03:00
struct urb * urb ;
unsigned long pack ;
2005-04-17 02:20:36 +04:00
2021-05-17 16:15:37 +03:00
if ( stream = = SNDRV_PCM_STREAM_CAPTURE ) {
2021-05-17 16:15:35 +03:00
usx2y - > hwdep_pcm_shm - > captured_iso_head = - 1 ;
usx2y - > hwdep_pcm_shm - > captured_iso_frames = 0 ;
2005-04-17 02:20:36 +04:00
}
for ( p = 0 ; 3 > = ( stream + p ) ; p + = 2 ) {
2021-05-17 16:15:35 +03:00
struct snd_usx2y_substream * subs = usx2y - > subs [ stream + p ] ;
2021-05-17 16:15:37 +03:00
if ( subs ) {
err = usx2y_usbpcm_urbs_allocate ( subs ) ;
if ( err < 0 )
2005-04-17 02:20:36 +04:00
return err ;
subs - > completed_urb = NULL ;
}
}
for ( p = 0 ; p < 4 ; p + + ) {
2021-05-17 16:15:35 +03:00
struct snd_usx2y_substream * subs = usx2y - > subs [ p ] ;
2021-05-17 16:15:36 +03:00
2021-05-17 16:15:37 +03:00
if ( subs & & atomic_read ( & subs - > state ) > = STATE_PREPARED )
2005-04-17 02:20:36 +04:00
goto start ;
}
start :
2021-05-17 16:15:35 +03:00
usx2y_usbpcm_subs_startup ( subs ) ;
2005-04-17 02:20:36 +04:00
for ( u = 0 ; u < NRURBS ; u + + ) {
for ( p = 0 ; 3 > = ( stream + p ) ; p + = 2 ) {
2021-05-17 16:15:35 +03:00
struct snd_usx2y_substream * subs = usx2y - > subs [ stream + p ] ;
2021-05-17 16:15:36 +03:00
2021-05-17 16:15:37 +03:00
if ( ! subs )
continue ;
urb = subs - > urb [ u ] ;
if ( usb_pipein ( urb - > pipe ) ) {
if ( ! u )
atomic_set ( & subs - > state , STATE_STARTING3 ) ;
urb - > dev = usx2y - > dev ;
for ( pack = 0 ; pack < nr_of_packs ( ) ; pack + + ) {
urb - > iso_frame_desc [ pack ] . offset = subs - > maxpacksize * ( pack + u * nr_of_packs ( ) ) ;
urb - > iso_frame_desc [ pack ] . length = subs - > maxpacksize ;
2021-05-17 16:15:36 +03:00
}
2021-05-17 16:15:37 +03:00
urb - > transfer_buffer_length = subs - > maxpacksize * nr_of_packs ( ) ;
err = usb_submit_urb ( urb , GFP_KERNEL ) ;
if ( err < 0 ) {
snd_printk ( KERN_ERR " cannot usb_submit_urb() for urb %d, err = %d \n " , u , err ) ;
err = - EPIPE ;
goto cleanup ;
} else {
snd_printdd ( " %i \n " , urb - > start_frame ) ;
if ( ! u )
usx2y - > wait_iso_frame = urb - > start_frame ;
}
urb - > transfer_flags = 0 ;
} else {
atomic_set ( & subs - > state , STATE_STARTING1 ) ;
break ;
2005-04-17 02:20:36 +04:00
}
}
}
err = 0 ;
2021-05-17 16:15:37 +03:00
wait_event ( usx2y - > prepare_wait_queue , ! usx2y - > prepare_subs ) ;
2021-05-17 16:15:35 +03:00
if ( atomic_read ( & subs - > state ) ! = STATE_PREPARED )
2005-04-17 02:20:36 +04:00
err = - EPIPE ;
2021-05-17 16:15:36 +03:00
2005-04-17 02:20:36 +04:00
cleanup :
if ( err ) {
2021-05-17 16:15:35 +03:00
usx2y_subs_startup_finish ( usx2y ) ; // Call it now
2021-07-05 12:34:19 +03:00
usx2y_clients_stop ( usx2y ) ; // something is completely wrong > stop everything
2005-04-17 02:20:36 +04:00
}
return err ;
}
2021-05-17 16:15:38 +03:00
# define USX2Y_HWDEP_PCM_PAGES \
PAGE_ALIGN ( sizeof ( struct snd_usx2y_hwdep_pcm_shm ) )
2005-04-17 02:20:36 +04:00
/*
* prepare callback
*
* set format and initialize urbs
*/
2021-05-17 16:15:35 +03:00
static int snd_usx2y_usbpcm_prepare ( struct snd_pcm_substream * substream )
2005-04-17 02:20:36 +04:00
{
2005-11-17 17:08:26 +03:00
struct snd_pcm_runtime * runtime = substream - > runtime ;
2021-05-17 16:15:35 +03:00
struct snd_usx2y_substream * subs = runtime - > private_data ;
struct usx2ydev * usx2y = subs - > usx2y ;
struct snd_usx2y_substream * capsubs = subs - > usx2y - > subs [ SNDRV_PCM_STREAM_CAPTURE ] ;
2005-04-17 02:20:36 +04:00
int err = 0 ;
2021-05-17 16:15:36 +03:00
2021-05-17 16:15:35 +03:00
snd_printdd ( " snd_usx2y_pcm_prepare(%p) \n " , substream ) ;
2005-04-17 02:20:36 +04:00
2021-05-17 16:15:41 +03:00
mutex_lock ( & usx2y - > pcm_mutex ) ;
2021-05-17 16:15:37 +03:00
if ( ! usx2y - > hwdep_pcm_shm ) {
2021-05-17 16:15:38 +03:00
usx2y - > hwdep_pcm_shm = alloc_pages_exact ( USX2Y_HWDEP_PCM_PAGES ,
2018-11-23 21:38:13 +03:00
GFP_KERNEL ) ;
2021-05-17 16:15:41 +03:00
if ( ! usx2y - > hwdep_pcm_shm ) {
err = - ENOMEM ;
goto up_prepare_mutex ;
}
2021-05-17 16:15:38 +03:00
memset ( usx2y - > hwdep_pcm_shm , 0 , USX2Y_HWDEP_PCM_PAGES ) ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:35 +03:00
usx2y_subs_prepare ( subs ) ;
2021-05-17 16:15:36 +03:00
// Start hardware streams
// SyncStream first....
2021-05-17 16:15:35 +03:00
if ( atomic_read ( & capsubs - > state ) < STATE_PREPARED ) {
2021-05-17 16:15:37 +03:00
if ( usx2y - > format ! = runtime - > format ) {
err = usx2y_format_set ( usx2y , runtime - > format ) ;
if ( err < 0 )
2005-04-17 02:20:36 +04:00
goto up_prepare_mutex ;
2021-05-17 16:15:37 +03:00
}
if ( usx2y - > rate ! = runtime - > rate ) {
err = usx2y_rate_set ( usx2y , runtime - > rate ) ;
if ( err < 0 )
2005-04-17 02:20:36 +04:00
goto up_prepare_mutex ;
2021-05-17 16:15:37 +03:00
}
2005-11-17 17:08:26 +03:00
snd_printdd ( " starting capture pipe for %s \n " , subs = = capsubs ?
" self " : " playpipe " ) ;
2021-05-17 16:15:37 +03:00
err = usx2y_usbpcm_urbs_start ( capsubs ) ;
if ( err < 0 )
2005-04-17 02:20:36 +04:00
goto up_prepare_mutex ;
}
if ( subs ! = capsubs ) {
2021-05-17 16:15:35 +03:00
usx2y - > hwdep_pcm_shm - > playback_iso_start = - 1 ;
if ( atomic_read ( & subs - > state ) < STATE_PREPARED ) {
while ( usx2y_iso_frames_per_buffer ( runtime , usx2y ) >
usx2y - > hwdep_pcm_shm - > captured_iso_frames ) {
2021-05-17 16:15:36 +03:00
snd_printdd ( " Wait: iso_frames_per_buffer=%i,captured_iso_frames=%i \n " ,
2021-05-17 16:15:35 +03:00
usx2y_iso_frames_per_buffer ( runtime , usx2y ) ,
usx2y - > hwdep_pcm_shm - > captured_iso_frames ) ;
2005-07-09 12:54:37 +04:00
if ( msleep_interruptible ( 10 ) ) {
2005-04-17 02:20:36 +04:00
err = - ERESTARTSYS ;
goto up_prepare_mutex ;
}
2021-05-17 16:15:36 +03:00
}
2021-05-17 16:15:37 +03:00
err = usx2y_usbpcm_urbs_start ( subs ) ;
if ( err < 0 )
2005-04-17 02:20:36 +04:00
goto up_prepare_mutex ;
}
2005-11-17 17:08:26 +03:00
snd_printdd ( " Ready: iso_frames_per_buffer=%i,captured_iso_frames=%i \n " ,
2021-05-17 16:15:35 +03:00
usx2y_iso_frames_per_buffer ( runtime , usx2y ) ,
usx2y - > hwdep_pcm_shm - > captured_iso_frames ) ;
2021-05-17 16:15:37 +03:00
} else {
2021-05-17 16:15:35 +03:00
usx2y - > hwdep_pcm_shm - > capture_iso_start = - 1 ;
2021-05-17 16:15:37 +03:00
}
2005-04-17 02:20:36 +04:00
up_prepare_mutex :
2021-05-17 16:15:35 +03:00
mutex_unlock ( & usx2y - > pcm_mutex ) ;
2005-04-17 02:20:36 +04:00
return err ;
}
2021-05-17 16:15:36 +03:00
static const struct snd_pcm_hardware snd_usx2y_4c = {
2005-04-17 02:20:36 +04:00
. info = ( SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP_VALID ) ,
. formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE ,
. rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 ,
. rate_min = 44100 ,
. rate_max = 48000 ,
. channels_min = 2 ,
. channels_max = 4 ,
. buffer_bytes_max = ( 2 * 128 * 1024 ) ,
. period_bytes_min = 64 ,
. period_bytes_max = ( 128 * 1024 ) ,
. periods_min = 2 ,
. periods_max = 1024 ,
. fifo_size = 0
} ;
2021-05-17 16:15:35 +03:00
static int snd_usx2y_usbpcm_open ( struct snd_pcm_substream * substream )
2005-04-17 02:20:36 +04:00
{
2021-05-17 16:15:37 +03:00
struct snd_usx2y_substream * subs =
( ( struct snd_usx2y_substream * * )
snd_pcm_substream_chip ( substream ) ) [ substream - > stream ] ;
2005-11-17 17:08:26 +03:00
struct snd_pcm_runtime * runtime = substream - > runtime ;
2005-04-17 02:20:36 +04:00
2021-05-17 16:15:35 +03:00
if ( ! ( subs - > usx2y - > chip_status & USX2Y_STAT_CHIP_MMAP_PCM_URBS ) )
2005-04-17 02:20:36 +04:00
return - EBUSY ;
2021-05-17 16:15:37 +03:00
if ( substream - > stream = = SNDRV_PCM_STREAM_PLAYBACK )
runtime - > hw = snd_usx2y_2c ;
else
runtime - > hw = ( subs - > usx2y - > subs [ 3 ] ? snd_usx2y_4c : snd_usx2y_2c ) ;
2005-04-17 02:20:36 +04:00
runtime - > private_data = subs ;
subs - > pcm_substream = substream ;
snd_pcm_hw_constraint_minmax ( runtime , SNDRV_PCM_HW_PARAM_PERIOD_TIME , 1000 , 200000 ) ;
return 0 ;
}
2021-05-17 16:15:35 +03:00
static int snd_usx2y_usbpcm_close ( struct snd_pcm_substream * substream )
2005-04-17 02:20:36 +04:00
{
2005-11-17 17:08:26 +03:00
struct snd_pcm_runtime * runtime = substream - > runtime ;
2021-05-17 16:15:35 +03:00
struct snd_usx2y_substream * subs = runtime - > private_data ;
2005-11-17 12:48:52 +03:00
2005-04-17 02:20:36 +04:00
subs - > pcm_substream = NULL ;
2005-11-17 12:48:52 +03:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:36 +03:00
static const struct snd_pcm_ops snd_usx2y_usbpcm_ops = {
2021-05-17 16:15:35 +03:00
. open = snd_usx2y_usbpcm_open ,
. close = snd_usx2y_usbpcm_close ,
. hw_params = snd_usx2y_pcm_hw_params ,
. hw_free = snd_usx2y_usbpcm_hw_free ,
. prepare = snd_usx2y_usbpcm_prepare ,
. trigger = snd_usx2y_pcm_trigger ,
. pointer = snd_usx2y_pcm_pointer ,
2005-04-17 02:20:36 +04:00
} ;
2021-05-17 16:15:35 +03:00
static int usx2y_pcms_busy_check ( struct snd_card * card )
2005-04-17 02:20:36 +04:00
{
2021-05-17 16:15:35 +03:00
struct usx2ydev * dev = usx2y ( card ) ;
2021-05-17 16:15:37 +03:00
struct snd_usx2y_substream * subs ;
2014-02-14 12:05:47 +04:00
int i ;
2005-04-17 02:20:36 +04:00
2014-02-14 12:05:47 +04:00
for ( i = 0 ; i < dev - > pcm_devs * 2 ; i + + ) {
2021-05-17 16:15:37 +03:00
subs = dev - > subs [ i ] ;
2014-02-14 12:05:47 +04:00
if ( subs & & subs - > pcm_substream & &
SUBSTREAM_BUSY ( subs - > pcm_substream ) )
return - EBUSY ;
2005-04-17 02:20:36 +04:00
}
2014-02-14 12:05:47 +04:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:35 +03:00
static int snd_usx2y_hwdep_pcm_open ( struct snd_hwdep * hw , struct file * file )
2005-04-17 02:20:36 +04:00
{
2005-11-17 17:08:26 +03:00
struct snd_card * card = hw - > card ;
2014-02-14 12:05:47 +04:00
int err ;
2021-05-17 16:15:35 +03:00
mutex_lock ( & usx2y ( card ) - > pcm_mutex ) ;
err = usx2y_pcms_busy_check ( card ) ;
2014-02-14 12:05:47 +04:00
if ( ! err )
2021-05-17 16:15:35 +03:00
usx2y ( card ) - > chip_status | = USX2Y_STAT_CHIP_MMAP_PCM_URBS ;
mutex_unlock ( & usx2y ( card ) - > pcm_mutex ) ;
2005-04-17 02:20:36 +04:00
return err ;
}
2021-05-17 16:15:35 +03:00
static int snd_usx2y_hwdep_pcm_release ( struct snd_hwdep * hw , struct file * file )
2005-04-17 02:20:36 +04:00
{
2005-11-17 17:08:26 +03:00
struct snd_card * card = hw - > card ;
2014-02-14 12:05:47 +04:00
int err ;
2021-05-17 16:15:35 +03:00
mutex_lock ( & usx2y ( card ) - > pcm_mutex ) ;
err = usx2y_pcms_busy_check ( card ) ;
2014-02-14 12:05:47 +04:00
if ( ! err )
2021-05-17 16:15:35 +03:00
usx2y ( hw - > card ) - > chip_status & = ~ USX2Y_STAT_CHIP_MMAP_PCM_URBS ;
mutex_unlock ( & usx2y ( card ) - > pcm_mutex ) ;
2005-04-17 02:20:36 +04:00
return err ;
}
2021-05-17 16:15:35 +03:00
static void snd_usx2y_hwdep_pcm_vm_open ( struct vm_area_struct * area )
2005-04-17 02:20:36 +04:00
{
}
2021-05-17 16:15:35 +03:00
static void snd_usx2y_hwdep_pcm_vm_close ( struct vm_area_struct * area )
2005-04-17 02:20:36 +04:00
{
}
2021-05-17 16:15:35 +03:00
static vm_fault_t snd_usx2y_hwdep_pcm_vm_fault ( struct vm_fault * vmf )
2005-04-17 02:20:36 +04:00
{
unsigned long offset ;
void * vaddr ;
2007-12-13 18:16:40 +03:00
offset = vmf - > pgoff < < PAGE_SHIFT ;
2021-05-17 16:15:35 +03:00
vaddr = ( char * ) ( ( struct usx2ydev * ) vmf - > vma - > vm_private_data ) - > hwdep_pcm_shm + offset ;
2007-12-13 18:16:40 +03:00
vmf - > page = virt_to_page ( vaddr ) ;
get_page ( vmf - > page ) ;
return 0 ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:35 +03:00
static const struct vm_operations_struct snd_usx2y_hwdep_pcm_vm_ops = {
. open = snd_usx2y_hwdep_pcm_vm_open ,
. close = snd_usx2y_hwdep_pcm_vm_close ,
. fault = snd_usx2y_hwdep_pcm_vm_fault ,
2005-04-17 02:20:36 +04:00
} ;
2021-05-17 16:15:36 +03:00
static int snd_usx2y_hwdep_pcm_mmap ( struct snd_hwdep * hw , struct file * filp , struct vm_area_struct * area )
2005-04-17 02:20:36 +04:00
{
unsigned long size = ( unsigned long ) ( area - > vm_end - area - > vm_start ) ;
2021-05-17 16:15:35 +03:00
struct usx2ydev * usx2y = hw - > private_data ;
2005-04-17 02:20:36 +04:00
2021-05-17 16:15:35 +03:00
if ( ! ( usx2y - > chip_status & USX2Y_STAT_CHIP_INIT ) )
2005-04-17 02:20:36 +04:00
return - EBUSY ;
2021-05-17 16:15:36 +03:00
/* if userspace tries to mmap beyond end of our buffer, fail */
2021-05-17 16:15:38 +03:00
if ( size > USX2Y_HWDEP_PCM_PAGES ) {
snd_printd ( " %lu > %lu \n " , size , ( unsigned long ) USX2Y_HWDEP_PCM_PAGES ) ;
2005-04-17 02:20:36 +04:00
return - EINVAL ;
}
2021-05-17 16:15:37 +03:00
if ( ! usx2y - > hwdep_pcm_shm )
2005-04-17 02:20:36 +04:00
return - ENODEV ;
2021-05-17 16:15:37 +03:00
2021-05-17 16:15:35 +03:00
area - > vm_ops = & snd_usx2y_hwdep_pcm_vm_ops ;
2023-01-26 22:37:49 +03:00
vm_flags_set ( area , VM_DONTEXPAND | VM_DONTDUMP ) ;
2005-04-17 02:20:36 +04:00
area - > vm_private_data = hw - > private_data ;
return 0 ;
}
2021-05-17 16:15:35 +03:00
static void snd_usx2y_hwdep_pcm_private_free ( struct snd_hwdep * hwdep )
2005-04-17 02:20:36 +04:00
{
2021-05-17 16:15:35 +03:00
struct usx2ydev * usx2y = hwdep - > private_data ;
2021-05-17 16:15:36 +03:00
2021-05-17 16:15:37 +03:00
if ( usx2y - > hwdep_pcm_shm )
2021-05-17 16:15:38 +03:00
free_pages_exact ( usx2y - > hwdep_pcm_shm , USX2Y_HWDEP_PCM_PAGES ) ;
2005-04-17 02:20:36 +04:00
}
2021-05-17 16:15:35 +03:00
int usx2y_hwdep_pcm_new ( struct snd_card * card )
2005-04-17 02:20:36 +04:00
{
int err ;
2005-11-17 17:08:26 +03:00
struct snd_hwdep * hw ;
struct snd_pcm * pcm ;
2021-05-17 16:15:35 +03:00
struct usb_device * dev = usx2y ( card ) - > dev ;
2021-05-17 16:15:36 +03:00
2021-05-17 16:15:37 +03:00
if ( nr_of_packs ( ) ! = 1 )
2005-04-17 02:20:36 +04:00
return 0 ;
2021-05-17 16:15:37 +03:00
err = snd_hwdep_new ( card , SND_USX2Y_USBPCM_ID , 1 , & hw ) ;
if ( err < 0 )
2005-04-17 02:20:36 +04:00
return err ;
2005-11-17 12:48:52 +03:00
2005-04-17 02:20:36 +04:00
hw - > iface = SNDRV_HWDEP_IFACE_USX2Y_PCM ;
2021-05-17 16:15:35 +03:00
hw - > private_data = usx2y ( card ) ;
hw - > private_free = snd_usx2y_hwdep_pcm_private_free ;
hw - > ops . open = snd_usx2y_hwdep_pcm_open ;
hw - > ops . release = snd_usx2y_hwdep_pcm_release ;
hw - > ops . mmap = snd_usx2y_hwdep_pcm_mmap ;
2005-04-17 02:20:36 +04:00
hw - > exclusive = 1 ;
2017-04-17 03:51:11 +03:00
sprintf ( hw - > name , " /dev/bus/usb/%03d/%03d/hwdeppcm " , dev - > bus - > busnum , dev - > devnum ) ;
2005-04-17 02:20:36 +04:00
err = snd_pcm_new ( card , NAME_ALLCAPS " hwdep Audio " , 2 , 1 , 1 , & pcm ) ;
2021-05-17 16:15:37 +03:00
if ( err < 0 )
2005-04-17 02:20:36 +04:00
return err ;
2021-05-17 16:15:37 +03:00
2021-05-17 16:15:35 +03:00
snd_pcm_set_ops ( pcm , SNDRV_PCM_STREAM_PLAYBACK , & snd_usx2y_usbpcm_ops ) ;
snd_pcm_set_ops ( pcm , SNDRV_PCM_STREAM_CAPTURE , & snd_usx2y_usbpcm_ops ) ;
2005-04-17 02:20:36 +04:00
2021-05-17 16:15:35 +03:00
pcm - > private_data = usx2y ( card ) - > subs ;
2005-04-17 02:20:36 +04:00
pcm - > info_flags = 0 ;
sprintf ( pcm - > name , NAME_ALLCAPS " hwdep Audio " ) ;
2019-12-09 12:49:41 +03:00
snd_pcm_set_managed_buffer ( pcm - > streams [ SNDRV_PCM_STREAM_PLAYBACK ] . substream ,
SNDRV_DMA_TYPE_CONTINUOUS ,
NULL ,
64 * 1024 , 128 * 1024 ) ;
snd_pcm_set_managed_buffer ( pcm - > streams [ SNDRV_PCM_STREAM_CAPTURE ] . substream ,
SNDRV_DMA_TYPE_CONTINUOUS ,
NULL ,
64 * 1024 , 128 * 1024 ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
# else
2021-05-17 16:15:35 +03:00
int usx2y_hwdep_pcm_new ( struct snd_card * card )
2005-04-17 02:20:36 +04:00
{
return 0 ;
}
# endif