usb: gadget: f_uac1: convert to new function interface with backward compatibility

Converting uac1 to the new function interface requires converting
the USB uac1's function code and its users.

This patch converts the f_uac1.c to the new function interface.

The file is now compiled into a separate usb_f_uac1.ko module.

The old function interface is provided by means of a preprocessor
conditional directives. After all users are converted, the old interface
can be removed.

Tested-by: Sebastian Reimers <sebastian.reimers@googlemail.com>
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
This commit is contained in:
Andrzej Pietrasiewicz
2014-07-22 19:58:38 +02:00
committed by Felipe Balbi
parent af1a58ca00
commit f3a3406b3f
6 changed files with 195 additions and 31 deletions

View File

@@ -10,6 +10,7 @@
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/delay.h>
@@ -23,6 +24,7 @@
* This component encapsulates the ALSA devices for USB audio gadget
*/
#ifdef USBF_UAC1_INCLUDED
#define FILE_PCM_PLAYBACK "/dev/snd/pcmC0D0p"
#define FILE_PCM_CAPTURE "/dev/snd/pcmC0D0c"
#define FILE_CONTROL "/dev/snd/controlC0"
@@ -38,7 +40,7 @@ MODULE_PARM_DESC(fn_cap, "Capture PCM device file name");
static char *fn_cntl = FILE_CONTROL;
module_param(fn_cntl, charp, S_IRUGO);
MODULE_PARM_DESC(fn_cntl, "Control device file name");
#endif
/*-------------------------------------------------------------------------*/
/**
@@ -167,7 +169,7 @@ static int playback_default_hw_params(struct gaudio_snd_dev *snd)
/**
* Playback audio buffer data by ALSA PCM device
*/
static size_t u_audio_playback(struct gaudio *card, void *buf, size_t count)
size_t u_audio_playback(struct gaudio *card, void *buf, size_t count)
{
struct gaudio_snd_dev *snd = &card->playback;
struct snd_pcm_substream *substream = snd->substream;
@@ -202,12 +204,12 @@ try_again:
return 0;
}
static int u_audio_get_playback_channels(struct gaudio *card)
int u_audio_get_playback_channels(struct gaudio *card)
{
return card->playback.channels;
}
static int u_audio_get_playback_rate(struct gaudio *card)
int u_audio_get_playback_rate(struct gaudio *card)
{
return card->playback.rate;
}
@@ -220,6 +222,15 @@ static int gaudio_open_snd_dev(struct gaudio *card)
{
struct snd_pcm_file *pcm_file;
struct gaudio_snd_dev *snd;
#ifndef USBF_UAC1_INCLUDED
struct f_uac1_opts *opts;
char *fn_play, *fn_cap, *fn_cntl;
opts = container_of(card->func.fi, struct f_uac1_opts, func_inst);
fn_play = opts->fn_play;
fn_cap = opts->fn_cap;
fn_cntl = opts->fn_cntl;
#endif
if (!card)
return -ENODEV;
@@ -293,7 +304,9 @@ static int gaudio_close_snd_dev(struct gaudio *gau)
return 0;
}
#ifdef USBF_UAC1_INCLUDED
static struct gaudio *the_card;
#endif
/**
* gaudio_setup - setup ALSA interface and preparing for USB transfer
*
@@ -301,15 +314,17 @@ static struct gaudio *the_card;
*
* Returns negative errno, or zero on success
*/
int __init gaudio_setup(struct gaudio *card)
int gaudio_setup(struct gaudio *card)
{
int ret;
ret = gaudio_open_snd_dev(card);
if (ret)
ERROR(card, "we need at least one control device\n");
#ifdef USBF_UAC1_INCLUDED
else if (!the_card)
the_card = card;
#endif
return ret;
@@ -320,11 +335,17 @@ int __init gaudio_setup(struct gaudio *card)
*
* This is called to free all resources allocated by @gaudio_setup().
*/
#ifdef USBF_UAC1_INCLUDED
void gaudio_cleanup(void)
#else
void gaudio_cleanup(struct gaudio *the_card)
#endif
{
if (the_card) {
gaudio_close_snd_dev(the_card);
#ifdef USBF_UAC1_INCLUDED
the_card = NULL;
#endif
}
}