Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1668590 > unrolled thread
| Started by | Ruslan Bilovol <ruslan.bilovol@gmail.com> |
|---|---|
| First post | 2017-06-18 15:30 +0200 |
| Last post | 2017-06-18 15:30 +0200 |
| Articles | 3 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH v5 0/4] USB Audio Gadget refactoring Ruslan Bilovol <ruslan.bilovol@gmail.com> - 2017-06-18 15:30 +0200
[PATCH v5 3/4] usb: gadget: function: make current f_uac1 implementation legacy Ruslan Bilovol <ruslan.bilovol@gmail.com> - 2017-06-18 15:30 +0200
[PATCH v5 1/4] usb: gadget: f_uac2: remove platform driver/device creation Ruslan Bilovol <ruslan.bilovol@gmail.com> - 2017-06-18 15:30 +0200
| From | Ruslan Bilovol <ruslan.bilovol@gmail.com> |
|---|---|
| Date | 2017-06-18 15:30 +0200 |
| Subject | [PATCH v5 0/4] USB Audio Gadget refactoring |
| Message-ID | <tTIr7-5BR-1@gated-at.bofh.it> |
Hi Felipe,
This is v5 of audio gadget refactoring.
Note, that legacy f_uac1 function is broken since v4.10
by commit 7e4da3fcf7c9 ("usb: gadget: composite: Test
get_alt() presence instead of set_alt()"). The fact that
at v4.12-rc5 time nobody cares about may be a good sign
that number of users is small if any. Thus making it
legacy makes sence.
This series depends on legacy f_uac1 fix I posted before:
http://www.spinics.net/lists/linux-usb/msg158373.html
Without this fix it's not possible to check that refactoring
didn't break legacy f_uac1 functionality
========================================
I came to this patch series when wanted to do two things:
- use UAC1 as virtual ALSA sound card on gadget side,
just like UAC2 is used so it's possible to do rate
resampling
- have both playback/capture support in UAC1
Since I wanted to have same behavior for both UAC1/UAC2,
obviously I've got an utility part (u_audio.c) for
virtual ALSA sound card handling like we have
for ethernet(u_ether) or serial(u_serial) functions.
Function-specific parts (f_uac1/f_uac2) became almost
as storage for class-specific USB descriptors, some
boilerplate for configfs, binding and few USB
config request handling.
Originally in RFC [1] I've posted before, there was
major change to f_uac1 after that it couldn't do
direct play to existing ALSA sound card anymore,
representing audio on gadget side as virtual
ALSA sound card where audio streams are simply
sinked to and sourced from it, so it may break
current usecase for some people (and that's why
it was RFC).
During RFC discussion, it was agreed to not touch
existing f_uac1 implementation and create new one
instead. At v4 patchet discussion another approach
was agreed - current f_uac1.c gets renamed to
f_uac1_legacy.c and introduced a *new* f_uac1.c
instead that is done in current patchset (v5)
Now, it's possible to use existing user-space
applications for audio routing between Audio Gadget
and real sound card. I personally use alsaloop tool
from alsautils and have ability to create PCM
loopback between two different ALSA cards using
rate resampling, which was not possible with previous
"direct play to ALSA card" approach in f_uac1.
While here, also dropped redundant platform
driver/device creation in f_uac2 driver (as well as
didn't add "never implemented" volume/mute functionality
in f_uac1_legacy to f_uac1) that made this work even
easier to do.
This series is tested with both legacy g_audio.ko and
modern configfs approaches under Ubuntu 14.04 (UAC1 and
UAC2) and under Windows7 x64 (UAC1 only) having
perfect results in all cases.
Comments, testing are welcome.
v5 changes:
- after discussion with Felipe, switched to another
approach with making current f_uac1 legacy and
introducing a new f_uac1.c instead
- addressed Jassi's copyright comments
v4 changes:
- renamed f_uac1_newapi to f_uac1_acard that is
more meaningful
- rebased on top of balbi/next
v3 changes:
- renamed u_audio exported symbols so they don't
conflict with old f_uac1 if both are built-in.
v2 changes:
- do not touch f_uac1, instead created f_uac1_newapi
- added documentation for f_uac1_newapi
- rebased on top of v4.8-rc1
[1] https://lkml.org/lkml/2016/5/23/649
Ruslan Bilovol (4):
usb: gadget: f_uac2: remove platform driver/device creation
usb: gadget: f_uac2: split out audio core
usb: gadget: function: make current f_uac1 implementation legacy
usb: gadget: add f_uac1 variant based on a new u_audio api
Documentation/ABI/testing/configfs-usb-gadget-uac1 | 18 +-
.../ABI/testing/configfs-usb-gadget-uac1_legacy | 12 +
Documentation/usb/gadget-testing.txt | 53 +-
drivers/usb/gadget/Kconfig | 29 +-
drivers/usb/gadget/function/Makefile | 5 +-
drivers/usb/gadget/function/f_uac1.c | 906 +++++++----------
drivers/usb/gadget/function/f_uac1_legacy.c | 1021 ++++++++++++++++++++
drivers/usb/gadget/function/f_uac2.c | 795 ++-------------
drivers/usb/gadget/function/u_audio.c | 662 +++++++++++++
drivers/usb/gadget/function/u_audio.h | 95 ++
drivers/usb/gadget/function/u_uac1.h | 87 +-
.../gadget/function/{u_uac1.c => u_uac1_legacy.c} | 7 +-
drivers/usb/gadget/function/u_uac1_legacy.h | 82 ++
drivers/usb/gadget/legacy/Kconfig | 15 +-
drivers/usb/gadget/legacy/audio.c | 55 +-
15 files changed, 2494 insertions(+), 1348 deletions(-)
create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-uac1_legacy
create mode 100644 drivers/usb/gadget/function/f_uac1_legacy.c
create mode 100644 drivers/usb/gadget/function/u_audio.c
create mode 100644 drivers/usb/gadget/function/u_audio.h
rename drivers/usb/gadget/function/{u_uac1.c => u_uac1_legacy.c} (98%)
create mode 100644 drivers/usb/gadget/function/u_uac1_legacy.h
--
1.9.1
[toc] | [next] | [standalone]
| From | Ruslan Bilovol <ruslan.bilovol@gmail.com> |
|---|---|
| Date | 2017-06-18 15:30 +0200 |
| Subject | [PATCH v5 3/4] usb: gadget: function: make current f_uac1 implementation legacy |
| Message-ID | <tTIr8-5BR-25@gated-at.bofh.it> |
| In reply to | #1668590 |
Before introducing new f_uac1 function (with virtual
ALSA card) make current implementation legacy.
This includes renaming of existing files, some
variables, config options and documentation
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
---
...gadget-uac1 => configfs-usb-gadget-uac1_legacy} | 2 +-
Documentation/usb/gadget-testing.txt | 9 +++--
drivers/usb/gadget/Kconfig | 8 ++--
drivers/usb/gadget/function/Makefile | 4 +-
.../gadget/function/{f_uac1.c => f_uac1_legacy.c} | 45 +++++++++++-----------
.../gadget/function/{u_uac1.c => u_uac1_legacy.c} | 7 ++--
.../gadget/function/{u_uac1.h => u_uac1_legacy.h} | 8 ++--
drivers/usb/gadget/legacy/Kconfig | 6 +--
drivers/usb/gadget/legacy/audio.c | 26 ++++++-------
9 files changed, 59 insertions(+), 56 deletions(-)
rename Documentation/ABI/testing/{configfs-usb-gadget-uac1 => configfs-usb-gadget-uac1_legacy} (84%)
rename drivers/usb/gadget/function/{f_uac1.c => f_uac1_legacy.c} (95%)
rename drivers/usb/gadget/function/{u_uac1.c => u_uac1_legacy.c} (98%)
rename drivers/usb/gadget/function/{u_uac1.h => u_uac1_legacy.h} (94%)
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-uac1 b/Documentation/ABI/testing/configfs-usb-gadget-uac1_legacy
similarity index 84%
rename from Documentation/ABI/testing/configfs-usb-gadget-uac1
rename to Documentation/ABI/testing/configfs-usb-gadget-uac1_legacy
index 8ba9a12..b2eaefd 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-uac1
+++ b/Documentation/ABI/testing/configfs-usb-gadget-uac1_legacy
@@ -1,4 +1,4 @@
-What: /config/usb-gadget/gadget/functions/uac1.name
+What: /config/usb-gadget/gadget/functions/uac1_legacy.name
Date: Sep 2014
KernelVersion: 3.18
Description:
diff --git a/Documentation/usb/gadget-testing.txt b/Documentation/usb/gadget-testing.txt
index fb0cc4d..ce51d6e 100644
--- a/Documentation/usb/gadget-testing.txt
+++ b/Documentation/usb/gadget-testing.txt
@@ -16,7 +16,7 @@ provided by gadgets.
13. RNDIS function
14. SERIAL function
15. SOURCESINK function
-16. UAC1 function
+16. UAC1 function (legacy implementation)
17. UAC2 function
18. UVC function
19. PRINTER function
@@ -589,15 +589,16 @@ device: run the gadget
host: test-usb (tools/usb/testusb.c)
-16. UAC1 function
+16. UAC1 function (legacy implementation)
=================
-The function is provided by usb_f_uac1.ko module.
+The function is provided by usb_f_uac1_legacy.ko module.
Function-specific configfs interface
------------------------------------
-The function name to use when creating the function directory is "uac1".
+The function name to use when creating the function directory
+is "uac1_legacy".
The uac1 function provides these attributes in its function directory:
audio_buf_size - audio buffer size
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 3b0ffd6..01c2e2b 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -191,7 +191,7 @@ config USB_F_MASS_STORAGE
config USB_F_FS
tristate
-config USB_F_UAC1
+config USB_F_UAC1_LEGACY
tristate
config USB_F_UAC2
@@ -365,13 +365,13 @@ config USB_CONFIGFS_F_FS
implemented in kernel space (for instance Ethernet, serial or
mass storage) and other are implemented in user space.
-config USB_CONFIGFS_F_UAC1
- bool "Audio Class 1.0"
+config USB_CONFIGFS_F_UAC1_LEGACY
+ bool "Audio Class 1.0 (legacy implementation)"
depends on USB_CONFIGFS
depends on SND
select USB_LIBCOMPOSITE
select SND_PCM
- select USB_F_UAC1
+ select USB_F_UAC1_LEGACY
help
This Audio function implements 1 AudioControl interface,
1 AudioStreaming Interface each for USB-OUT and USB-IN.
diff --git a/drivers/usb/gadget/function/Makefile b/drivers/usb/gadget/function/Makefile
index b29f2ae..50ee517 100644
--- a/drivers/usb/gadget/function/Makefile
+++ b/drivers/usb/gadget/function/Makefile
@@ -33,8 +33,8 @@ obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
usb_f_fs-y := f_fs.o
obj-$(CONFIG_USB_F_FS) += usb_f_fs.o
obj-$(CONFIG_USB_U_AUDIO) += u_audio.o
-usb_f_uac1-y := f_uac1.o u_uac1.o
-obj-$(CONFIG_USB_F_UAC1) += usb_f_uac1.o
+usb_f_uac1_legacy-y := f_uac1_legacy.o u_uac1_legacy.o
+obj-$(CONFIG_USB_F_UAC1_LEGACY) += usb_f_uac1_legacy.o
usb_f_uac2-y := f_uac2.o
obj-$(CONFIG_USB_F_UAC2) += usb_f_uac2.o
usb_f_uvc-y := f_uvc.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_configfs.o
diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1_legacy.c
similarity index 95%
rename from drivers/usb/gadget/function/f_uac1.c
rename to drivers/usb/gadget/function/f_uac1_legacy.c
index 5dfc94b..5d229e7 100644
--- a/drivers/usb/gadget/function/f_uac1.c
+++ b/drivers/usb/gadget/function/f_uac1_legacy.c
@@ -15,7 +15,7 @@
#include <linux/device.h>
#include <linux/atomic.h>
-#include "u_uac1.h"
+#include "u_uac1_legacy.h"
static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value);
static int generic_get_cmd(struct usb_audio_control *con, u8 cmd);
@@ -326,11 +326,11 @@ static int f_audio_out_ep_complete(struct usb_ep *ep, struct usb_request *req)
struct f_audio *audio = req->context;
struct usb_composite_dev *cdev = audio->card.func.config->cdev;
struct f_audio_buf *copy_buf = audio->copy_buf;
- struct f_uac1_opts *opts;
+ struct f_uac1_legacy_opts *opts;
int audio_buf_size;
int err;
- opts = container_of(audio->card.func.fi, struct f_uac1_opts,
+ opts = container_of(audio->card.func.fi, struct f_uac1_legacy_opts,
func_inst);
audio_buf_size = opts->audio_buf_size;
@@ -578,13 +578,13 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
struct usb_composite_dev *cdev = f->config->cdev;
struct usb_ep *out_ep = audio->out_ep;
struct usb_request *req;
- struct f_uac1_opts *opts;
+ struct f_uac1_legacy_opts *opts;
int req_buf_size, req_count, audio_buf_size;
int i = 0, err = 0;
DBG(cdev, "intf %d, alt %d\n", intf, alt);
- opts = container_of(f->fi, struct f_uac1_opts, func_inst);
+ opts = container_of(f->fi, struct f_uac1_legacy_opts, func_inst);
req_buf_size = opts->req_buf_size;
req_count = opts->req_count;
audio_buf_size = opts->audio_buf_size;
@@ -705,9 +705,9 @@ static void f_audio_build_desc(struct f_audio *audio)
struct usb_string *us;
int status;
struct usb_ep *ep = NULL;
- struct f_uac1_opts *audio_opts;
+ struct f_uac1_legacy_opts *audio_opts;
- audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst);
+ audio_opts = container_of(f->fi, struct f_uac1_legacy_opts, func_inst);
audio->card.gadget = c->cdev->gadget;
/* set up ASLA audio devices */
if (!audio_opts->bound) {
@@ -801,15 +801,16 @@ static int control_selector_init(struct f_audio *audio)
return 0;
}
-static inline struct f_uac1_opts *to_f_uac1_opts(struct config_item *item)
+static inline
+struct f_uac1_legacy_opts *to_f_uac1_opts(struct config_item *item)
{
- return container_of(to_config_group(item), struct f_uac1_opts,
+ return container_of(to_config_group(item), struct f_uac1_legacy_opts,
func_inst.group);
}
static void f_uac1_attr_release(struct config_item *item)
{
- struct f_uac1_opts *opts = to_f_uac1_opts(item);
+ struct f_uac1_legacy_opts *opts = to_f_uac1_opts(item);
usb_put_function_instance(&opts->func_inst);
}
@@ -822,7 +823,7 @@ static void f_uac1_attr_release(struct config_item *item)
static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \
char *page) \
{ \
- struct f_uac1_opts *opts = to_f_uac1_opts(item); \
+ struct f_uac1_legacy_opts *opts = to_f_uac1_opts(item); \
int result; \
\
mutex_lock(&opts->lock); \
@@ -835,7 +836,7 @@ static void f_uac1_attr_release(struct config_item *item)
static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \
const char *page, size_t len) \
{ \
- struct f_uac1_opts *opts = to_f_uac1_opts(item); \
+ struct f_uac1_legacy_opts *opts = to_f_uac1_opts(item); \
int ret; \
u32 num; \
\
@@ -867,7 +868,7 @@ static void f_uac1_attr_release(struct config_item *item)
static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \
char *page) \
{ \
- struct f_uac1_opts *opts = to_f_uac1_opts(item); \
+ struct f_uac1_legacy_opts *opts = to_f_uac1_opts(item); \
int result; \
\
mutex_lock(&opts->lock); \
@@ -880,7 +881,7 @@ static void f_uac1_attr_release(struct config_item *item)
static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \
const char *page, size_t len) \
{ \
- struct f_uac1_opts *opts = to_f_uac1_opts(item); \
+ struct f_uac1_legacy_opts *opts = to_f_uac1_opts(item); \
int ret = -EBUSY; \
char *tmp; \
\
@@ -928,9 +929,9 @@ static void f_uac1_attr_release(struct config_item *item)
static void f_audio_free_inst(struct usb_function_instance *f)
{
- struct f_uac1_opts *opts;
+ struct f_uac1_legacy_opts *opts;
- opts = container_of(f, struct f_uac1_opts, func_inst);
+ opts = container_of(f, struct f_uac1_legacy_opts, func_inst);
if (opts->fn_play_alloc)
kfree(opts->fn_play);
if (opts->fn_cap_alloc)
@@ -942,7 +943,7 @@ static void f_audio_free_inst(struct usb_function_instance *f)
static struct usb_function_instance *f_audio_alloc_inst(void)
{
- struct f_uac1_opts *opts;
+ struct f_uac1_legacy_opts *opts;
opts = kzalloc(sizeof(*opts), GFP_KERNEL);
if (!opts)
@@ -966,10 +967,10 @@ static struct usb_function_instance *f_audio_alloc_inst(void)
static void f_audio_free(struct usb_function *f)
{
struct f_audio *audio = func_to_audio(f);
- struct f_uac1_opts *opts;
+ struct f_uac1_legacy_opts *opts;
gaudio_cleanup(&audio->card);
- opts = container_of(f->fi, struct f_uac1_opts, func_inst);
+ opts = container_of(f->fi, struct f_uac1_legacy_opts, func_inst);
kfree(audio);
mutex_lock(&opts->lock);
--opts->refcnt;
@@ -984,7 +985,7 @@ static void f_audio_unbind(struct usb_configuration *c, struct usb_function *f)
static struct usb_function *f_audio_alloc(struct usb_function_instance *fi)
{
struct f_audio *audio;
- struct f_uac1_opts *opts;
+ struct f_uac1_legacy_opts *opts;
/* allocate and initialize one new instance */
audio = kzalloc(sizeof(*audio), GFP_KERNEL);
@@ -993,7 +994,7 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi)
audio->card.func.name = "g_audio";
- opts = container_of(fi, struct f_uac1_opts, func_inst);
+ opts = container_of(fi, struct f_uac1_legacy_opts, func_inst);
mutex_lock(&opts->lock);
++opts->refcnt;
mutex_unlock(&opts->lock);
@@ -1015,6 +1016,6 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi)
return &audio->card.func;
}
-DECLARE_USB_FUNCTION_INIT(uac1, f_audio_alloc_inst, f_audio_alloc);
+DECLARE_USB_FUNCTION_INIT(uac1_legacy, f_audio_alloc_inst, f_audio_alloc);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Bryan Wu");
diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1_legacy.c
similarity index 98%
rename from drivers/usb/gadget/function/u_uac1.c
rename to drivers/usb/gadget/function/u_uac1_legacy.c
index c78c841..8aa76b4 100644
--- a/drivers/usb/gadget/function/u_uac1.c
+++ b/drivers/usb/gadget/function/u_uac1_legacy.c
@@ -18,7 +18,7 @@
#include <linux/random.h>
#include <linux/syscalls.h>
-#include "u_uac1.h"
+#include "u_uac1_legacy.h"
/*
* This component encapsulates the ALSA devices for USB audio gadget
@@ -205,10 +205,11 @@ static int gaudio_open_snd_dev(struct gaudio *card)
{
struct snd_pcm_file *pcm_file;
struct gaudio_snd_dev *snd;
- struct f_uac1_opts *opts;
+ struct f_uac1_legacy_opts *opts;
char *fn_play, *fn_cap, *fn_cntl;
- opts = container_of(card->func.fi, struct f_uac1_opts, func_inst);
+ opts = container_of(card->func.fi, struct f_uac1_legacy_opts,
+ func_inst);
fn_play = opts->fn_play;
fn_cap = opts->fn_cap;
fn_cntl = opts->fn_cntl;
diff --git a/drivers/usb/gadget/function/u_uac1.h b/drivers/usb/gadget/function/u_uac1_legacy.h
similarity index 94%
rename from drivers/usb/gadget/function/u_uac1.h
rename to drivers/usb/gadget/function/u_uac1_legacy.h
index 5c2ac8e..d715b1a 100644
--- a/drivers/usb/gadget/function/u_uac1.h
+++ b/drivers/usb/gadget/function/u_uac1_legacy.h
@@ -9,8 +9,8 @@
* Licensed under the GPL-2 or later.
*/
-#ifndef __U_AUDIO_H
-#define __U_AUDIO_H
+#ifndef __U_UAC1_LEGACY_H
+#define __U_UAC1_LEGACY_H
#include <linux/device.h>
#include <linux/err.h>
@@ -56,7 +56,7 @@ struct gaudio {
/* TODO */
};
-struct f_uac1_opts {
+struct f_uac1_legacy_opts {
struct usb_function_instance func_inst;
int req_buf_size;
int req_count;
@@ -79,4 +79,4 @@ struct f_uac1_opts {
int u_audio_get_playback_channels(struct gaudio *card);
int u_audio_get_playback_rate(struct gaudio *card);
-#endif /* __U_AUDIO_H */
+#endif /* __U_UAC1_LEGACY_H */
diff --git a/drivers/usb/gadget/legacy/Kconfig b/drivers/usb/gadget/legacy/Kconfig
index 5344064..87bacb6 100644
--- a/drivers/usb/gadget/legacy/Kconfig
+++ b/drivers/usb/gadget/legacy/Kconfig
@@ -54,8 +54,8 @@ config USB_AUDIO
depends on SND
select USB_LIBCOMPOSITE
select SND_PCM
- select USB_F_UAC1 if GADGET_UAC1
- select USB_F_UAC2 if !GADGET_UAC1
+ select USB_F_UAC1_LEGACY if GADGET_UAC1_LEGACY
+ select USB_F_UAC2 if !GADGET_UAC1_LEGACY
select USB_U_AUDIO if USB_F_UAC2
help
This Gadget Audio driver is compatible with USB Audio Class
@@ -73,7 +73,7 @@ config USB_AUDIO
Say "y" to link the driver statically, or "m" to build a
dynamically linked module called "g_audio".
-config GADGET_UAC1
+config GADGET_UAC1_LEGACY
bool "UAC 1.0 (Legacy)"
depends on USB_AUDIO
help
diff --git a/drivers/usb/gadget/legacy/audio.c b/drivers/usb/gadget/legacy/audio.c
index 8a39f42..bf5592a 100644
--- a/drivers/usb/gadget/legacy/audio.c
+++ b/drivers/usb/gadget/legacy/audio.c
@@ -20,7 +20,7 @@
USB_GADGET_COMPOSITE_OPTIONS();
-#ifndef CONFIG_GADGET_UAC1
+#ifndef CONFIG_GADGET_UAC1_LEGACY
#include "u_uac2.h"
/* Playback(USB-IN) Default Stereo - Fl/Fr */
@@ -53,7 +53,7 @@
module_param(c_ssize, uint, S_IRUGO);
MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)");
#else
-#include "u_uac1.h"
+#include "u_uac1_legacy.h"
static char *fn_play = FILE_PCM_PLAYBACK;
module_param(fn_play, charp, S_IRUGO);
@@ -99,7 +99,7 @@
NULL,
};
-#ifndef CONFIG_GADGET_UAC1
+#ifndef CONFIG_GADGET_UAC1_LEGACY
static struct usb_function_instance *fi_uac2;
static struct usb_function *f_uac2;
#else
@@ -125,7 +125,7 @@
/* .bcdUSB = DYNAMIC */
-#ifdef CONFIG_GADGET_UAC1
+#ifdef CONFIG_GADGET_UAC1_LEGACY
.bDeviceClass = USB_CLASS_PER_INTERFACE,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
@@ -164,7 +164,7 @@ static int audio_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
-#ifdef CONFIG_GADGET_UAC1
+#ifdef CONFIG_GADGET_UAC1_LEGACY
f_uac1 = usb_get_function(fi_uac1);
if (IS_ERR(f_uac1)) {
status = PTR_ERR(f_uac1);
@@ -204,24 +204,24 @@ static int audio_do_config(struct usb_configuration *c)
static int audio_bind(struct usb_composite_dev *cdev)
{
-#ifndef CONFIG_GADGET_UAC1
+#ifndef CONFIG_GADGET_UAC1_LEGACY
struct f_uac2_opts *uac2_opts;
#else
- struct f_uac1_opts *uac1_opts;
+ struct f_uac1_legacy_opts *uac1_opts;
#endif
int status;
-#ifndef CONFIG_GADGET_UAC1
+#ifndef CONFIG_GADGET_UAC1_LEGACY
fi_uac2 = usb_get_function_instance("uac2");
if (IS_ERR(fi_uac2))
return PTR_ERR(fi_uac2);
#else
- fi_uac1 = usb_get_function_instance("uac1");
+ fi_uac1 = usb_get_function_instance("uac1_legacy");
if (IS_ERR(fi_uac1))
return PTR_ERR(fi_uac1);
#endif
-#ifndef CONFIG_GADGET_UAC1
+#ifndef CONFIG_GADGET_UAC1_LEGACY
uac2_opts = container_of(fi_uac2, struct f_uac2_opts, func_inst);
uac2_opts->p_chmask = p_chmask;
uac2_opts->p_srate = p_srate;
@@ -231,7 +231,7 @@ static int audio_bind(struct usb_composite_dev *cdev)
uac2_opts->c_ssize = c_ssize;
uac2_opts->req_number = UAC2_DEF_REQ_NUM;
#else
- uac1_opts = container_of(fi_uac1, struct f_uac1_opts, func_inst);
+ uac1_opts = container_of(fi_uac1, struct f_uac1_legacy_opts, func_inst);
uac1_opts->fn_play = fn_play;
uac1_opts->fn_cap = fn_cap;
uac1_opts->fn_cntl = fn_cntl;
@@ -269,7 +269,7 @@ static int audio_bind(struct usb_composite_dev *cdev)
kfree(otg_desc[0]);
otg_desc[0] = NULL;
fail:
-#ifndef CONFIG_GADGET_UAC1
+#ifndef CONFIG_GADGET_UAC1_LEGACY
usb_put_function_instance(fi_uac2);
#else
usb_put_function_instance(fi_uac1);
@@ -279,7 +279,7 @@ static int audio_bind(struct usb_composite_dev *cdev)
static int audio_unbind(struct usb_composite_dev *cdev)
{
-#ifdef CONFIG_GADGET_UAC1
+#ifdef CONFIG_GADGET_UAC1_LEGACY
if (!IS_ERR_OR_NULL(f_uac1))
usb_put_function(f_uac1);
if (!IS_ERR_OR_NULL(fi_uac1))
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Ruslan Bilovol <ruslan.bilovol@gmail.com> |
|---|---|
| Date | 2017-06-18 15:30 +0200 |
| Subject | [PATCH v5 1/4] usb: gadget: f_uac2: remove platform driver/device creation |
| Message-ID | <tTIr8-5BR-27@gated-at.bofh.it> |
| In reply to | #1668590 |
Simplify f_uac2 by removing platform driver/device
creation; use composite's usb_gadget device as
parent for sound card and for debug prints.
This removes extra layer of code without any functional
change.
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
---
drivers/usb/gadget/function/f_uac2.c | 107 +++++++++--------------------------
1 file changed, 28 insertions(+), 79 deletions(-)
diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index 5a7ba05..f674bae 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -13,7 +13,6 @@
#include <linux/usb/audio.h>
#include <linux/usb/audio-v2.h>
-#include <linux/platform_device.h>
#include <linux/module.h>
#include <sound/core.h>
@@ -51,8 +50,6 @@
#define UNFLW_CTRL 8
#define OVFLW_CTRL 10
-static const char *uac2_name = "snd_uac2";
-
struct uac2_req {
struct uac2_rtd_params *pp; /* parent param */
struct usb_request *req;
@@ -81,9 +78,6 @@ struct uac2_rtd_params {
};
struct snd_uac2_chip {
- struct platform_device pdev;
- struct platform_driver pdrv;
-
struct uac2_rtd_params p_prm;
struct uac2_rtd_params c_prm;
@@ -122,6 +116,7 @@ struct audio_dev {
struct usb_ep *in_ep, *out_ep;
struct usb_function func;
+ struct usb_gadget *gadget;
/* The ALSA Sound Card it represents on the USB-Client side */
struct snd_uac2_chip uac2;
@@ -140,12 +135,6 @@ struct audio_dev *uac2_to_agdev(struct snd_uac2_chip *u)
}
static inline
-struct snd_uac2_chip *pdev_to_uac2(struct platform_device *p)
-{
- return container_of(p, struct snd_uac2_chip, pdev);
-}
-
-static inline
struct f_uac2_opts *agdev_to_uac2_opts(struct audio_dev *agdev)
{
return container_of(agdev->func.fi, struct f_uac2_opts, func_inst);
@@ -254,7 +243,7 @@ uint num_channels(uint chanmask)
exit:
if (usb_ep_queue(ep, req, GFP_ATOMIC))
- dev_err(&uac2->pdev.dev, "%d Error!\n", __LINE__);
+ dev_err(uac2->card->dev, "%d Error!\n", __LINE__);
if (update_alsa)
snd_pcm_period_elapsed(substream);
@@ -440,23 +429,22 @@ static int uac2_pcm_null(struct snd_pcm_substream *substream)
.prepare = uac2_pcm_null,
};
-static int snd_uac2_probe(struct platform_device *pdev)
+static int snd_uac2_probe(struct audio_dev *audio_dev)
{
- struct snd_uac2_chip *uac2 = pdev_to_uac2(pdev);
+ struct snd_uac2_chip *uac2 = &audio_dev->uac2;
struct snd_card *card;
struct snd_pcm *pcm;
- struct audio_dev *audio_dev;
struct f_uac2_opts *opts;
int err;
int p_chmask, c_chmask;
- audio_dev = uac2_to_agdev(uac2);
opts = container_of(audio_dev->func.fi, struct f_uac2_opts, func_inst);
p_chmask = opts->p_chmask;
c_chmask = opts->c_chmask;
/* Choose any slot, with no id */
- err = snd_card_new(&pdev->dev, -1, NULL, THIS_MODULE, 0, &card);
+ err = snd_card_new(&audio_dev->gadget->dev,
+ -1, NULL, THIS_MODULE, 0, &card);
if (err < 0)
return err;
@@ -481,16 +469,15 @@ static int snd_uac2_probe(struct platform_device *pdev)
strcpy(card->driver, "UAC2_Gadget");
strcpy(card->shortname, "UAC2_Gadget");
- sprintf(card->longname, "UAC2_Gadget %i", pdev->id);
+ sprintf(card->longname, "UAC2_Gadget %i", card->dev->id);
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
snd_dma_continuous_data(GFP_KERNEL), 0, BUFF_SIZE_MAX);
err = snd_card_register(card);
- if (!err) {
- platform_set_drvdata(pdev, card);
+
+ if (!err)
return 0;
- }
snd_fail:
snd_card_free(card);
@@ -501,9 +488,9 @@ static int snd_uac2_probe(struct platform_device *pdev)
return err;
}
-static int snd_uac2_remove(struct platform_device *pdev)
+static int snd_uac2_remove(struct audio_dev *audio_dev)
{
- struct snd_card *card = platform_get_drvdata(pdev);
+ struct snd_card *card = audio_dev->uac2.card;
if (card)
return snd_card_free(card);
@@ -511,45 +498,6 @@ static int snd_uac2_remove(struct platform_device *pdev)
return 0;
}
-static void snd_uac2_release(struct device *dev)
-{
- dev_dbg(dev, "releasing '%s'\n", dev_name(dev));
-}
-
-static int alsa_uac2_init(struct audio_dev *agdev)
-{
- struct snd_uac2_chip *uac2 = &agdev->uac2;
- int err;
-
- uac2->pdrv.probe = snd_uac2_probe;
- uac2->pdrv.remove = snd_uac2_remove;
- uac2->pdrv.driver.name = uac2_name;
-
- uac2->pdev.id = 0;
- uac2->pdev.name = uac2_name;
- uac2->pdev.dev.release = snd_uac2_release;
-
- /* Register snd_uac2 driver */
- err = platform_driver_register(&uac2->pdrv);
- if (err)
- return err;
-
- /* Register snd_uac2 device */
- err = platform_device_register(&uac2->pdev);
- if (err)
- platform_driver_unregister(&uac2->pdrv);
-
- return err;
-}
-
-static void alsa_uac2_exit(struct audio_dev *agdev)
-{
- struct snd_uac2_chip *uac2 = &agdev->uac2;
-
- platform_driver_unregister(&uac2->pdrv);
- platform_device_unregister(&uac2->pdev);
-}
-
/* --------- USB Function Interface ------------- */
@@ -960,7 +908,7 @@ struct cntrl_range_lay3 {
}
if (usb_ep_disable(ep))
- dev_err(&uac2->pdev.dev,
+ dev_err(uac2->card->dev,
"%s:%d Error!\n", __func__, __LINE__);
}
@@ -994,7 +942,7 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
struct snd_uac2_chip *uac2 = &agdev->uac2;
struct usb_composite_dev *cdev = cfg->cdev;
struct usb_gadget *gadget = cdev->gadget;
- struct device *dev = &uac2->pdev.dev;
+ struct device *dev = &gadget->dev;
struct uac2_rtd_params *prm;
struct f_uac2_opts *uac2_opts;
struct usb_string *us;
@@ -1094,6 +1042,8 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
if (ret)
return ret;
+ agdev->gadget = gadget;
+
prm = &agdev->uac2.c_prm;
prm->max_psize = hs_epout_desc.wMaxPacketSize;
prm->ureq = kcalloc(uac2_opts->req_number, sizeof(struct uac2_req),
@@ -1124,7 +1074,7 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
goto err_no_memory;
}
- ret = alsa_uac2_init(agdev);
+ ret = snd_uac2_probe(agdev);
if (ret)
goto err_no_memory;
return 0;
@@ -1136,6 +1086,7 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
kfree(agdev->uac2.c_prm.rbuf);
err_free_descs:
usb_free_all_descriptors(fn);
+ agdev->gadget = NULL;
return ret;
}
@@ -1147,7 +1098,7 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
struct f_uac2_opts *opts = agdev_to_uac2_opts(agdev);
struct snd_uac2_chip *uac2 = &agdev->uac2;
struct usb_gadget *gadget = cdev->gadget;
- struct device *dev = &uac2->pdev.dev;
+ struct device *dev = &gadget->dev;
struct usb_request *req;
struct usb_ep *ep;
struct uac2_rtd_params *prm;
@@ -1247,7 +1198,6 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
afunc_get_alt(struct usb_function *fn, unsigned intf)
{
struct audio_dev *agdev = func_to_agdev(fn);
- struct snd_uac2_chip *uac2 = &agdev->uac2;
if (intf == agdev->ac_intf)
return agdev->ac_alt;
@@ -1256,7 +1206,7 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
else if (intf == agdev->as_in_intf)
return agdev->as_in_alt;
else
- dev_err(&uac2->pdev.dev,
+ dev_err(&agdev->gadget->dev,
"%s:%d Invalid Interface %d!\n",
__func__, __LINE__, intf);
@@ -1281,7 +1231,6 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
{
struct usb_request *req = fn->config->cdev->req;
struct audio_dev *agdev = func_to_agdev(fn);
- struct snd_uac2_chip *uac2 = &agdev->uac2;
struct f_uac2_opts *opts;
u16 w_length = le16_to_cpu(cr->wLength);
u16 w_index = le16_to_cpu(cr->wIndex);
@@ -1310,7 +1259,7 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
*(u8 *)req->buf = 1;
value = min_t(unsigned, w_length, 1);
} else {
- dev_err(&uac2->pdev.dev,
+ dev_err(&agdev->gadget->dev,
"%s:%d control_selector=%d TODO!\n",
__func__, __LINE__, control_selector);
}
@@ -1323,7 +1272,6 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
{
struct usb_request *req = fn->config->cdev->req;
struct audio_dev *agdev = func_to_agdev(fn);
- struct snd_uac2_chip *uac2 = &agdev->uac2;
struct f_uac2_opts *opts;
u16 w_length = le16_to_cpu(cr->wLength);
u16 w_index = le16_to_cpu(cr->wIndex);
@@ -1353,7 +1301,7 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
value = min_t(unsigned, w_length, sizeof r);
memcpy(req->buf, &r, value);
} else {
- dev_err(&uac2->pdev.dev,
+ dev_err(&agdev->gadget->dev,
"%s:%d control_selector=%d TODO!\n",
__func__, __LINE__, control_selector);
}
@@ -1389,12 +1337,11 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
setup_rq_inf(struct usb_function *fn, const struct usb_ctrlrequest *cr)
{
struct audio_dev *agdev = func_to_agdev(fn);
- struct snd_uac2_chip *uac2 = &agdev->uac2;
u16 w_index = le16_to_cpu(cr->wIndex);
u8 intf = w_index & 0xff;
if (intf != agdev->ac_intf) {
- dev_err(&uac2->pdev.dev,
+ dev_err(&agdev->gadget->dev,
"%s:%d Error!\n", __func__, __LINE__);
return -EOPNOTSUPP;
}
@@ -1412,7 +1359,6 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
{
struct usb_composite_dev *cdev = fn->config->cdev;
struct audio_dev *agdev = func_to_agdev(fn);
- struct snd_uac2_chip *uac2 = &agdev->uac2;
struct usb_request *req = cdev->req;
u16 w_length = le16_to_cpu(cr->wLength);
int value = -EOPNOTSUPP;
@@ -1424,14 +1370,15 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
if ((cr->bRequestType & USB_RECIP_MASK) == USB_RECIP_INTERFACE)
value = setup_rq_inf(fn, cr);
else
- dev_err(&uac2->pdev.dev, "%s:%d Error!\n", __func__, __LINE__);
+ dev_err(&agdev->gadget->dev, "%s:%d Error!\n",
+ __func__, __LINE__);
if (value >= 0) {
req->length = value;
req->zero = value < w_length;
value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
if (value < 0) {
- dev_err(&uac2->pdev.dev,
+ dev_err(&agdev->gadget->dev,
"%s:%d Error!\n", __func__, __LINE__);
req->status = 0;
}
@@ -1573,7 +1520,7 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)
struct audio_dev *agdev = func_to_agdev(f);
struct uac2_rtd_params *prm;
- alsa_uac2_exit(agdev);
+ snd_uac2_remove(agdev);
prm = &agdev->uac2.p_prm;
kfree(prm->rbuf);
@@ -1582,6 +1529,8 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)
kfree(prm->rbuf);
kfree(prm->ureq);
usb_free_all_descriptors(f);
+
+ agdev->gadget = NULL;
}
static struct usb_function *afunc_alloc(struct usb_function_instance *fi)
--
1.9.1
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web