lkml.org 
[lkml]   [2017]   [Jun]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/3] usb: gadget: f_uac*: Reduce code duplication
Date
This replaces the dedicated headers for uac1 and uac2 functions with a
shared header for both of them. Apart from unifying the struct names,
further duplicated code for configfs setup is moved out of the function
files into the shared header.

Signed-off-by: Julian Scheel <julian@jusst.de>
---
drivers/usb/gadget/function/f_uac1.c | 142 +++++++++---------------------
drivers/usb/gadget/function/f_uac2.c | 161 ++++++++++-------------------------
drivers/usb/gadget/function/u_uac.h | 115 +++++++++++++++++++++++++
drivers/usb/gadget/function/u_uac1.h | 41 ---------
drivers/usb/gadget/function/u_uac2.h | 44 ----------
5 files changed, 199 insertions(+), 304 deletions(-)
create mode 100644 drivers/usb/gadget/function/u_uac.h
delete mode 100644 drivers/usb/gadget/function/u_uac1.h
delete mode 100644 drivers/usb/gadget/function/u_uac2.h

diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
index b955913bd7ea..7e5a9bd46bcf 100644
--- a/drivers/usb/gadget/function/f_uac1.c
+++ b/drivers/usb/gadget/function/f_uac1.c
@@ -21,18 +21,9 @@
#include <linux/module.h>

#include "u_audio.h"
-#include "u_uac1.h"
+#include "u_uac.h"

-struct f_uac1 {
- struct g_audio g_audio;
- u8 ac_intf, as_in_intf, as_out_intf;
- u8 ac_alt, as_in_alt, as_out_alt; /* needed for get_alt() */
-};
-
-static inline struct f_uac1 *func_to_uac1(struct usb_function *f)
-{
- return container_of(f, struct f_uac1, g_audio.func);
-}
+#define UAC1_OUT_EP_MAX_PACKET_SIZE 200

/*
* DESCRIPTORS ... most are static, but strings and full
@@ -435,7 +426,7 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
struct usb_composite_dev *cdev = f->config->cdev;
struct usb_gadget *gadget = cdev->gadget;
struct device *dev = &gadget->dev;
- struct f_uac1 *uac1 = func_to_uac1(f);
+ struct f_uac *uac1 = func_to_uac(f);
int ret = 0;

/* No i/f has more than 2 alt settings */
@@ -480,7 +471,7 @@ static int f_audio_get_alt(struct usb_function *f, unsigned intf)
struct usb_composite_dev *cdev = f->config->cdev;
struct usb_gadget *gadget = cdev->gadget;
struct device *dev = &gadget->dev;
- struct f_uac1 *uac1 = func_to_uac1(f);
+ struct f_uac *uac1 = func_to_uac(f);

if (intf == uac1->ac_intf)
return uac1->ac_alt;
@@ -498,7 +489,7 @@ static int f_audio_get_alt(struct usb_function *f, unsigned intf)

static void f_audio_disable(struct usb_function *f)
{
- struct f_uac1 *uac1 = func_to_uac1(f);
+ struct f_uac *uac1 = func_to_uac(f);

uac1->as_out_alt = 0;
uac1->as_in_alt = 0;
@@ -513,16 +504,16 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
{
struct usb_composite_dev *cdev = c->cdev;
struct usb_gadget *gadget = cdev->gadget;
- struct f_uac1 *uac1 = func_to_uac1(f);
+ struct f_uac *uac1 = func_to_uac(f);
struct g_audio *audio = func_to_g_audio(f);
- struct f_uac1_opts *audio_opts;
+ struct f_uac_opts *audio_opts;
struct usb_ep *ep = NULL;
struct usb_string *us;
u8 *sam_freq;
int rate;
int status;

- audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst);
+ audio_opts = container_of(f->fi, struct f_uac_opts, func_inst);

us = usb_gstrings_attach(cdev, uac1_strings, ARRAY_SIZE(strings_uac1));
if (IS_ERR(us))
@@ -630,82 +621,27 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)

/*-------------------------------------------------------------------------*/

-static inline struct f_uac1_opts *to_f_uac1_opts(struct config_item *item)
-{
- return container_of(to_config_group(item), struct f_uac1_opts,
- func_inst.group);
-}
-
-static void f_uac1_attr_release(struct config_item *item)
-{
- struct f_uac1_opts *opts = to_f_uac1_opts(item);
-
- usb_put_function_instance(&opts->func_inst);
-}
-
static struct configfs_item_operations f_uac1_item_ops = {
- .release = f_uac1_attr_release,
+ .release = f_uac_attr_release,
};

-#define UAC1_ATTRIBUTE(name) \
-static ssize_t f_uac1_opts_##name##_show( \
- struct config_item *item, \
- char *page) \
-{ \
- struct f_uac1_opts *opts = to_f_uac1_opts(item); \
- int result; \
- \
- mutex_lock(&opts->lock); \
- result = sprintf(page, "%u\n", opts->name); \
- mutex_unlock(&opts->lock); \
- \
- return result; \
-} \
- \
-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); \
- int ret; \
- u32 num; \
- \
- mutex_lock(&opts->lock); \
- if (opts->refcnt) { \
- ret = -EBUSY; \
- goto end; \
- } \
- \
- ret = kstrtou32(page, 0, &num); \
- if (ret) \
- goto end; \
- \
- opts->name = num; \
- ret = len; \
- \
-end: \
- mutex_unlock(&opts->lock); \
- return ret; \
-} \
- \
-CONFIGFS_ATTR(f_uac1_opts_, name)
-
-UAC1_ATTRIBUTE(c_chmask);
-UAC1_ATTRIBUTE(c_srate);
-UAC1_ATTRIBUTE(c_ssize);
-UAC1_ATTRIBUTE(p_chmask);
-UAC1_ATTRIBUTE(p_srate);
-UAC1_ATTRIBUTE(p_ssize);
-UAC1_ATTRIBUTE(req_number);
+
+UAC_ATTRIBUTE(c_chmask);
+UAC_ATTRIBUTE(c_srate);
+UAC_ATTRIBUTE(c_ssize);
+UAC_ATTRIBUTE(p_chmask);
+UAC_ATTRIBUTE(p_srate);
+UAC_ATTRIBUTE(p_ssize);
+UAC_ATTRIBUTE(req_number);

static struct configfs_attribute *f_uac1_attrs[] = {
- &f_uac1_opts_attr_c_chmask,
- &f_uac1_opts_attr_c_srate,
- &f_uac1_opts_attr_c_ssize,
- &f_uac1_opts_attr_p_chmask,
- &f_uac1_opts_attr_p_srate,
- &f_uac1_opts_attr_p_ssize,
- &f_uac1_opts_attr_req_number,
+ &f_uac_opts_attr_c_chmask,
+ &f_uac_opts_attr_c_srate,
+ &f_uac_opts_attr_c_ssize,
+ &f_uac_opts_attr_p_chmask,
+ &f_uac_opts_attr_p_srate,
+ &f_uac_opts_attr_p_ssize,
+ &f_uac_opts_attr_req_number,
NULL,
};

@@ -717,15 +653,15 @@ static struct config_item_type f_uac1_func_type = {

static void f_audio_free_inst(struct usb_function_instance *f)
{
- struct f_uac1_opts *opts;
+ struct f_uac_opts *opts;

- opts = container_of(f, struct f_uac1_opts, func_inst);
+ opts = container_of(f, struct f_uac_opts, func_inst);
kfree(opts);
}

static struct usb_function_instance *f_audio_alloc_inst(void)
{
- struct f_uac1_opts *opts;
+ struct f_uac_opts *opts;

opts = kzalloc(sizeof(*opts), GFP_KERNEL);
if (!opts)
@@ -737,23 +673,23 @@ static struct usb_function_instance *f_audio_alloc_inst(void)
config_group_init_type_name(&opts->func_inst.group, "",
&f_uac1_func_type);

- opts->c_chmask = UAC1_DEF_CCHMASK;
- opts->c_srate = UAC1_DEF_CSRATE;
- opts->c_ssize = UAC1_DEF_CSSIZE;
- opts->p_chmask = UAC1_DEF_PCHMASK;
- opts->p_srate = UAC1_DEF_PSRATE;
- opts->p_ssize = UAC1_DEF_PSSIZE;
- opts->req_number = UAC1_DEF_REQ_NUM;
+ opts->c_chmask = UAC_DEF_CCHMASK;
+ opts->c_srate = UAC_DEF_CSRATE;
+ opts->c_ssize = UAC_DEF_CSSIZE;
+ opts->p_chmask = UAC_DEF_PCHMASK;
+ opts->p_srate = UAC_DEF_PSRATE;
+ opts->p_ssize = UAC_DEF_PSSIZE;
+ opts->req_number = UAC_DEF_REQ_NUM;
return &opts->func_inst;
}

static void f_audio_free(struct usb_function *f)
{
struct g_audio *audio;
- struct f_uac1_opts *opts;
+ struct f_uac_opts *opts;

audio = func_to_g_audio(f);
- opts = container_of(f->fi, struct f_uac1_opts, func_inst);
+ opts = container_of(f->fi, struct f_uac_opts, func_inst);
kfree(audio);
mutex_lock(&opts->lock);
--opts->refcnt;
@@ -772,15 +708,15 @@ 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_uac1 *uac1;
- struct f_uac1_opts *opts;
+ struct f_uac *uac1;
+ struct f_uac_opts *opts;

/* allocate and initialize one new instance */
uac1 = kzalloc(sizeof(*uac1), GFP_KERNEL);
if (!uac1)
return ERR_PTR(-ENOMEM);

- opts = container_of(fi, struct f_uac1_opts, func_inst);
+ opts = container_of(fi, struct f_uac_opts, func_inst);
mutex_lock(&opts->lock);
++opts->refcnt;
mutex_unlock(&opts->lock);
diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index 9082ce261e70..f5e93e168ec5 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -16,7 +16,7 @@
#include <linux/module.h>

#include "u_audio.h"
-#include "u_uac2.h"
+#include "u_uac.h"

/*
* The driver implements a simple UAC_2 topology.
@@ -47,23 +47,6 @@
#define UNFLW_CTRL 8
#define OVFLW_CTRL 10

-struct f_uac2 {
- struct g_audio g_audio;
- u8 ac_intf, as_in_intf, as_out_intf;
- u8 ac_alt, as_in_alt, as_out_alt; /* needed for get_alt() */
-};
-
-static inline struct f_uac2 *func_to_uac2(struct usb_function *f)
-{
- return container_of(f, struct f_uac2, g_audio.func);
-}
-
-static inline
-struct f_uac2_opts *g_audio_to_uac2_opts(struct g_audio *agdev)
-{
- return container_of(agdev->func.fi, struct f_uac2_opts, func_inst);
-}
-
/* --------- USB Function Interface ------------- */

enum {
@@ -451,7 +434,7 @@ struct cntrl_range_lay3 {
__u32 dRES;
} __packed;

-static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
+static void set_ep_max_packet_size(const struct f_uac_opts *uac2_opts,
struct usb_endpoint_descriptor *ep_desc,
unsigned int factor, bool is_playback)
{
@@ -477,16 +460,16 @@ static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
static int
afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
{
- struct f_uac2 *uac2 = func_to_uac2(fn);
+ struct f_uac *uac2 = func_to_uac(fn);
struct g_audio *agdev = func_to_g_audio(fn);
struct usb_composite_dev *cdev = cfg->cdev;
struct usb_gadget *gadget = cdev->gadget;
struct device *dev = &gadget->dev;
- struct f_uac2_opts *uac2_opts;
+ struct f_uac_opts *uac2_opts;
struct usb_string *us;
int ret;

- uac2_opts = container_of(fn->fi, struct f_uac2_opts, func_inst);
+ uac2_opts = container_of(fn->fi, struct f_uac_opts, func_inst);

us = usb_gstrings_attach(cdev, fn_strings, ARRAY_SIZE(strings_fn));
if (IS_ERR(us))
@@ -606,7 +589,7 @@ static int
afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt)
{
struct usb_composite_dev *cdev = fn->config->cdev;
- struct f_uac2 *uac2 = func_to_uac2(fn);
+ struct f_uac *uac2 = func_to_uac(fn);
struct usb_gadget *gadget = cdev->gadget;
struct device *dev = &gadget->dev;
int ret = 0;
@@ -651,7 +634,7 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt)
static int
afunc_get_alt(struct usb_function *fn, unsigned intf)
{
- struct f_uac2 *uac2 = func_to_uac2(fn);
+ struct f_uac *uac2 = func_to_uac(fn);
struct g_audio *agdev = func_to_g_audio(fn);

if (intf == uac2->ac_intf)
@@ -671,7 +654,7 @@ afunc_get_alt(struct usb_function *fn, unsigned intf)
static void
afunc_disable(struct usb_function *fn)
{
- struct f_uac2 *uac2 = func_to_uac2(fn);
+ struct f_uac *uac2 = func_to_uac(fn);

uac2->as_in_alt = 0;
uac2->as_out_alt = 0;
@@ -684,7 +667,7 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
{
struct usb_request *req = fn->config->cdev->req;
struct g_audio *agdev = func_to_g_audio(fn);
- struct f_uac2_opts *opts;
+ struct f_uac_opts *opts;
u16 w_length = le16_to_cpu(cr->wLength);
u16 w_index = le16_to_cpu(cr->wIndex);
u16 w_value = le16_to_cpu(cr->wValue);
@@ -693,7 +676,7 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
int value = -EOPNOTSUPP;
int p_srate, c_srate;

- opts = g_audio_to_uac2_opts(agdev);
+ opts = g_audio_to_uac_opts(agdev);
p_srate = opts->p_srate;
c_srate = opts->c_srate;

@@ -725,7 +708,7 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr)
{
struct usb_request *req = fn->config->cdev->req;
struct g_audio *agdev = func_to_g_audio(fn);
- struct f_uac2_opts *opts;
+ struct f_uac_opts *opts;
u16 w_length = le16_to_cpu(cr->wLength);
u16 w_index = le16_to_cpu(cr->wIndex);
u16 w_value = le16_to_cpu(cr->wValue);
@@ -735,7 +718,7 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr)
int value = -EOPNOTSUPP;
int p_srate, c_srate;

- opts = g_audio_to_uac2_opts(agdev);
+ opts = g_audio_to_uac_opts(agdev);
p_srate = opts->p_srate;
c_srate = opts->c_srate;

@@ -789,7 +772,7 @@ out_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
static int
setup_rq_inf(struct usb_function *fn, const struct usb_ctrlrequest *cr)
{
- struct f_uac2 *uac2 = func_to_uac2(fn);
+ struct f_uac *uac2 = func_to_uac(fn);
struct g_audio *agdev = func_to_g_audio(fn);
u16 w_index = le16_to_cpu(cr->wIndex);
u8 intf = w_index & 0xff;
@@ -841,80 +824,26 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr)
return value;
}

-static inline struct f_uac2_opts *to_f_uac2_opts(struct config_item *item)
-{
- return container_of(to_config_group(item), struct f_uac2_opts,
- func_inst.group);
-}
-
-static void f_uac2_attr_release(struct config_item *item)
-{
- struct f_uac2_opts *opts = to_f_uac2_opts(item);
-
- usb_put_function_instance(&opts->func_inst);
-}
-
static struct configfs_item_operations f_uac2_item_ops = {
- .release = f_uac2_attr_release,
-};
-
-#define UAC2_ATTRIBUTE(name) \
-static ssize_t f_uac2_opts_##name##_show(struct config_item *item, \
- char *page) \
-{ \
- struct f_uac2_opts *opts = to_f_uac2_opts(item); \
- int result; \
- \
- mutex_lock(&opts->lock); \
- result = sprintf(page, "%u\n", opts->name); \
- mutex_unlock(&opts->lock); \
- \
- return result; \
-} \
- \
-static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \
- const char *page, size_t len) \
-{ \
- struct f_uac2_opts *opts = to_f_uac2_opts(item); \
- int ret; \
- u32 num; \
- \
- mutex_lock(&opts->lock); \
- if (opts->refcnt) { \
- ret = -EBUSY; \
- goto end; \
- } \
- \
- ret = kstrtou32(page, 0, &num); \
- if (ret) \
- goto end; \
- \
- opts->name = num; \
- ret = len; \
- \
-end: \
- mutex_unlock(&opts->lock); \
- return ret; \
-} \
- \
-CONFIGFS_ATTR(f_uac2_opts_, name)
-
-UAC2_ATTRIBUTE(p_chmask);
-UAC2_ATTRIBUTE(p_srate);
-UAC2_ATTRIBUTE(p_ssize);
-UAC2_ATTRIBUTE(c_chmask);
-UAC2_ATTRIBUTE(c_srate);
-UAC2_ATTRIBUTE(c_ssize);
-UAC2_ATTRIBUTE(req_number);
+ .release = f_uac_attr_release,
+};
+
+UAC_ATTRIBUTE(p_chmask);
+UAC_ATTRIBUTE(p_srate);
+UAC_ATTRIBUTE(p_ssize);
+UAC_ATTRIBUTE(c_chmask);
+UAC_ATTRIBUTE(c_srate);
+UAC_ATTRIBUTE(c_ssize);
+UAC_ATTRIBUTE(req_number);

static struct configfs_attribute *f_uac2_attrs[] = {
- &f_uac2_opts_attr_p_chmask,
- &f_uac2_opts_attr_p_srate,
- &f_uac2_opts_attr_p_ssize,
- &f_uac2_opts_attr_c_chmask,
- &f_uac2_opts_attr_c_srate,
- &f_uac2_opts_attr_c_ssize,
- &f_uac2_opts_attr_req_number,
+ &f_uac_opts_attr_p_chmask,
+ &f_uac_opts_attr_p_srate,
+ &f_uac_opts_attr_p_ssize,
+ &f_uac_opts_attr_c_chmask,
+ &f_uac_opts_attr_c_srate,
+ &f_uac_opts_attr_c_ssize,
+ &f_uac_opts_attr_req_number,
NULL,
};

@@ -926,15 +855,15 @@ static struct config_item_type f_uac2_func_type = {

static void afunc_free_inst(struct usb_function_instance *f)
{
- struct f_uac2_opts *opts;
+ struct f_uac_opts *opts;

- opts = container_of(f, struct f_uac2_opts, func_inst);
+ opts = container_of(f, struct f_uac_opts, func_inst);
kfree(opts);
}

static struct usb_function_instance *afunc_alloc_inst(void)
{
- struct f_uac2_opts *opts;
+ struct f_uac_opts *opts;

opts = kzalloc(sizeof(*opts), GFP_KERNEL);
if (!opts)
@@ -946,23 +875,23 @@ static struct usb_function_instance *afunc_alloc_inst(void)
config_group_init_type_name(&opts->func_inst.group, "",
&f_uac2_func_type);

- opts->p_chmask = UAC2_DEF_PCHMASK;
- opts->p_srate = UAC2_DEF_PSRATE;
- opts->p_ssize = UAC2_DEF_PSSIZE;
- opts->c_chmask = UAC2_DEF_CCHMASK;
- opts->c_srate = UAC2_DEF_CSRATE;
- opts->c_ssize = UAC2_DEF_CSSIZE;
- opts->req_number = UAC2_DEF_REQ_NUM;
+ opts->p_chmask = UAC_DEF_PCHMASK;
+ opts->p_srate = UAC_DEF_PSRATE;
+ opts->p_ssize = UAC_DEF_PSSIZE;
+ opts->c_chmask = UAC_DEF_CCHMASK;
+ opts->c_srate = UAC_DEF_CSRATE;
+ opts->c_ssize = UAC_DEF_CSSIZE;
+ opts->req_number = UAC_DEF_REQ_NUM;
return &opts->func_inst;
}

static void afunc_free(struct usb_function *f)
{
struct g_audio *agdev;
- struct f_uac2_opts *opts;
+ struct f_uac_opts *opts;

agdev = func_to_g_audio(f);
- opts = container_of(f->fi, struct f_uac2_opts, func_inst);
+ opts = container_of(f->fi, struct f_uac_opts, func_inst);
kfree(agdev);
mutex_lock(&opts->lock);
--opts->refcnt;
@@ -981,14 +910,14 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)

static struct usb_function *afunc_alloc(struct usb_function_instance *fi)
{
- struct f_uac2 *uac2;
- struct f_uac2_opts *opts;
+ struct f_uac *uac2;
+ struct f_uac_opts *opts;

uac2 = kzalloc(sizeof(*uac2), GFP_KERNEL);
if (uac2 == NULL)
return ERR_PTR(-ENOMEM);

- opts = container_of(fi, struct f_uac2_opts, func_inst);
+ opts = container_of(fi, struct f_uac_opts, func_inst);
mutex_lock(&opts->lock);
++opts->refcnt;
mutex_unlock(&opts->lock);
diff --git a/drivers/usb/gadget/function/u_uac.h b/drivers/usb/gadget/function/u_uac.h
new file mode 100644
index 000000000000..d014fd117a45
--- /dev/null
+++ b/drivers/usb/gadget/function/u_uac.h
@@ -0,0 +1,115 @@
+/*
+ * u_uac1.h - Utility definitions for UAC function
+ *
+ * Copyright (C) 2016 Ruslan Bilovol <ruslan.bilovol@gmail.com>
+ * Copyright (C) 2017 Julian Scheel <julian@juss.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __U_UAC_H
+#define __U_UAC_H
+
+#include <linux/usb/composite.h>
+
+#define UAC_DEF_CCHMASK 0x3
+#define UAC_DEF_CSRATE 48000
+#define UAC_DEF_CSSIZE 2
+#define UAC_DEF_PCHMASK 0x3
+#define UAC_DEF_PSRATE 48000
+#define UAC_DEF_PSSIZE 2
+#define UAC_DEF_REQ_NUM 2
+
+
+struct f_uac_opts {
+ struct usb_function_instance func_inst;
+ int c_chmask;
+ int c_srate;
+ int c_ssize;
+ int p_chmask;
+ int p_srate;
+ int p_ssize;
+ int req_number;
+ unsigned bound:1;
+
+ struct mutex lock;
+ int refcnt;
+};
+
+#define UAC_ATTRIBUTE(name) \
+static ssize_t f_uac_opts_##name##_show( \
+ struct config_item *item, \
+ char *page) \
+{ \
+ struct f_uac_opts *opts = to_f_uac_opts(item); \
+ int result; \
+ \
+ mutex_lock(&opts->lock); \
+ result = sprintf(page, "%u\n", opts->name); \
+ mutex_unlock(&opts->lock); \
+ \
+ return result; \
+} \
+ \
+static ssize_t f_uac_opts_##name##_store( \
+ struct config_item *item, \
+ const char *page, size_t len) \
+{ \
+ struct f_uac_opts *opts = to_f_uac_opts(item); \
+ int ret; \
+ u32 num; \
+ \
+ mutex_lock(&opts->lock); \
+ if (opts->refcnt) { \
+ ret = -EBUSY; \
+ goto end; \
+ } \
+ \
+ ret = kstrtou32(page, 0, &num); \
+ if (ret) \
+ goto end; \
+ \
+ opts->name = num; \
+ ret = len; \
+ \
+end: \
+ mutex_unlock(&opts->lock); \
+ return ret; \
+} \
+ \
+CONFIGFS_ATTR(f_uac_opts_, name)
+
+struct f_uac {
+ struct g_audio g_audio;
+ u8 ac_intf, as_in_intf, as_out_intf;
+ u8 ac_alt, as_in_alt, as_out_alt; /* needed for get_alt() */
+};
+
+static inline struct f_uac *func_to_uac(struct usb_function *f)
+{
+ return container_of(f, struct f_uac, g_audio.func);
+}
+
+static inline
+struct f_uac_opts *g_audio_to_uac_opts(struct g_audio *agdev)
+{
+ return container_of(agdev->func.fi, struct f_uac_opts, func_inst);
+}
+
+static inline struct f_uac_opts *to_f_uac_opts(struct config_item *item)
+{
+ return container_of(to_config_group(item), struct f_uac_opts,
+ func_inst.group);
+}
+
+static void f_uac_attr_release(struct config_item *item)
+{
+ struct f_uac_opts *opts = to_f_uac_opts(item);
+
+ usb_put_function_instance(&opts->func_inst);
+}
+
+
+#endif /* __U_UAC_H */
diff --git a/drivers/usb/gadget/function/u_uac1.h b/drivers/usb/gadget/function/u_uac1.h
deleted file mode 100644
index 6f188fd8633f..000000000000
--- a/drivers/usb/gadget/function/u_uac1.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * u_uac1.h - Utility definitions for UAC1 function
- *
- * Copyright (C) 2016 Ruslan Bilovol <ruslan.bilovol@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef __U_UAC1_H
-#define __U_UAC1_H
-
-#include <linux/usb/composite.h>
-
-#define UAC1_OUT_EP_MAX_PACKET_SIZE 200
-#define UAC1_DEF_CCHMASK 0x3
-#define UAC1_DEF_CSRATE 48000
-#define UAC1_DEF_CSSIZE 2
-#define UAC1_DEF_PCHMASK 0x3
-#define UAC1_DEF_PSRATE 48000
-#define UAC1_DEF_PSSIZE 2
-#define UAC1_DEF_REQ_NUM 2
-
-
-struct f_uac1_opts {
- struct usb_function_instance func_inst;
- int c_chmask;
- int c_srate;
- int c_ssize;
- int p_chmask;
- int p_srate;
- int p_ssize;
- int req_number;
- unsigned bound:1;
-
- struct mutex lock;
- int refcnt;
-};
-
-#endif /* __U_UAC1_H */
diff --git a/drivers/usb/gadget/function/u_uac2.h b/drivers/usb/gadget/function/u_uac2.h
deleted file mode 100644
index 19eeb83538a5..000000000000
--- a/drivers/usb/gadget/function/u_uac2.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * u_uac2.h
- *
- * Utility definitions for UAC2 function
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- * http://www.samsung.com
- *
- * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef U_UAC2_H
-#define U_UAC2_H
-
-#include <linux/usb/composite.h>
-
-#define UAC2_DEF_PCHMASK 0x3
-#define UAC2_DEF_PSRATE 48000
-#define UAC2_DEF_PSSIZE 2
-#define UAC2_DEF_CCHMASK 0x3
-#define UAC2_DEF_CSRATE 64000
-#define UAC2_DEF_CSSIZE 2
-#define UAC2_DEF_REQ_NUM 2
-
-struct f_uac2_opts {
- struct usb_function_instance func_inst;
- int p_chmask;
- int p_srate;
- int p_ssize;
- int c_chmask;
- int c_srate;
- int c_ssize;
- int req_number;
- bool bound;
-
- struct mutex lock;
- int refcnt;
-};
-
-#endif
--
2.13.1
\
 
 \ /
  Last update: 2017-06-26 09:36    [W:0.305 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site