2017-11-03 03:28:30 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2009-06-03 06:17:58 -07:00
|
|
|
/*
|
|
|
|
* audio.c -- Audio gadget driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Bryan Wu <cooloney@kernel.org>
|
|
|
|
* Copyright (C) 2008 Analog Devices, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #define VERBOSE_DEBUG */
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2012-09-06 11:11:27 -07:00
|
|
|
#include <linux/module.h>
|
2012-09-10 06:01:53 -07:00
|
|
|
#include <linux/usb/composite.h>
|
2009-06-03 06:17:58 -07:00
|
|
|
|
|
|
|
#define DRIVER_DESC "Linux USB Audio Gadget"
|
2012-02-02 09:31:34 -07:00
|
|
|
#define DRIVER_VERSION "Feb 2, 2012"
|
2009-06-03 06:17:58 -07:00
|
|
|
|
2012-09-10 06:01:53 -07:00
|
|
|
USB_GADGET_COMPOSITE_OPTIONS();
|
2009-06-03 06:17:58 -07:00
|
|
|
|
2017-06-18 06:23:54 -07:00
|
|
|
#ifndef CONFIG_GADGET_UAC1
|
2014-07-22 10:58:34 -07:00
|
|
|
#include "u_uac2.h"
|
|
|
|
|
2014-07-22 10:58:31 -07:00
|
|
|
/* Playback(USB-IN) Default Stereo - Fl/Fr */
|
2014-07-22 10:58:34 -07:00
|
|
|
static int p_chmask = UAC2_DEF_PCHMASK;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(p_chmask, uint, 0444);
|
2014-07-22 10:58:31 -07:00
|
|
|
MODULE_PARM_DESC(p_chmask, "Playback Channel Mask");
|
|
|
|
|
|
|
|
/* Playback Default 48 KHz */
|
2022-01-21 08:53:03 -07:00
|
|
|
static int p_srates[UAC_MAX_RATES] = {UAC2_DEF_PSRATE};
|
|
|
|
static int p_srates_cnt = 1;
|
|
|
|
module_param_array_named(p_srate, p_srates, uint, &p_srates_cnt, 0444);
|
|
|
|
MODULE_PARM_DESC(p_srate, "Playback Sampling Rates (array)");
|
2014-07-22 10:58:31 -07:00
|
|
|
|
|
|
|
/* Playback Default 16bits/sample */
|
2014-07-22 10:58:34 -07:00
|
|
|
static int p_ssize = UAC2_DEF_PSSIZE;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(p_ssize, uint, 0444);
|
2014-07-22 10:58:31 -07:00
|
|
|
MODULE_PARM_DESC(p_ssize, "Playback Sample Size(bytes)");
|
|
|
|
|
2022-01-27 04:43:29 -07:00
|
|
|
/* Playback bInterval for HS/SS (1-4: fixed, 0: auto) */
|
|
|
|
static u8 p_hs_bint = UAC2_DEF_PHSBINT;
|
|
|
|
module_param(p_hs_bint, byte, 0444);
|
|
|
|
MODULE_PARM_DESC(p_hs_bint,
|
|
|
|
"Playback bInterval for HS/SS (1-4: fixed, 0: auto)");
|
|
|
|
|
2014-07-22 10:58:31 -07:00
|
|
|
/* Capture(USB-OUT) Default Stereo - Fl/Fr */
|
2014-07-22 10:58:34 -07:00
|
|
|
static int c_chmask = UAC2_DEF_CCHMASK;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(c_chmask, uint, 0444);
|
2014-07-22 10:58:31 -07:00
|
|
|
MODULE_PARM_DESC(c_chmask, "Capture Channel Mask");
|
|
|
|
|
|
|
|
/* Capture Default 64 KHz */
|
2022-01-21 08:53:03 -07:00
|
|
|
static int c_srates[UAC_MAX_RATES] = {UAC2_DEF_CSRATE};
|
|
|
|
static int c_srates_cnt = 1;
|
|
|
|
module_param_array_named(c_srate, c_srates, uint, &c_srates_cnt, 0444);
|
|
|
|
MODULE_PARM_DESC(c_srate, "Capture Sampling Rates (array)");
|
2014-07-22 10:58:31 -07:00
|
|
|
|
|
|
|
/* Capture Default 16bits/sample */
|
2014-07-22 10:58:34 -07:00
|
|
|
static int c_ssize = UAC2_DEF_CSSIZE;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(c_ssize, uint, 0444);
|
2014-07-22 10:58:31 -07:00
|
|
|
MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)");
|
2022-01-27 04:43:29 -07:00
|
|
|
|
|
|
|
/* capture bInterval for HS/SS (1-4: fixed, 0: auto) */
|
|
|
|
static u8 c_hs_bint = UAC2_DEF_CHSBINT;
|
|
|
|
module_param(c_hs_bint, byte, 0444);
|
|
|
|
MODULE_PARM_DESC(c_hs_bint,
|
|
|
|
"Capture bInterval for HS/SS (1-4: fixed, 0: auto)");
|
|
|
|
|
2014-07-22 10:58:39 -07:00
|
|
|
#else
|
2017-06-18 06:23:54 -07:00
|
|
|
#ifndef CONFIG_GADGET_UAC1_LEGACY
|
|
|
|
#include "u_uac1.h"
|
|
|
|
|
|
|
|
/* Playback(USB-IN) Default Stereo - Fl/Fr */
|
|
|
|
static int p_chmask = UAC1_DEF_PCHMASK;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(p_chmask, uint, 0444);
|
2017-06-18 06:23:54 -07:00
|
|
|
MODULE_PARM_DESC(p_chmask, "Playback Channel Mask");
|
|
|
|
|
|
|
|
/* Playback Default 48 KHz */
|
2022-01-21 08:53:04 -07:00
|
|
|
static int p_srates[UAC_MAX_RATES] = {UAC1_DEF_PSRATE};
|
|
|
|
static int p_srates_cnt = 1;
|
|
|
|
module_param_array_named(p_srate, p_srates, uint, &p_srates_cnt, 0444);
|
|
|
|
MODULE_PARM_DESC(p_srate, "Playback Sampling Rates (array)");
|
2017-06-18 06:23:54 -07:00
|
|
|
|
|
|
|
/* Playback Default 16bits/sample */
|
|
|
|
static int p_ssize = UAC1_DEF_PSSIZE;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(p_ssize, uint, 0444);
|
2017-06-18 06:23:54 -07:00
|
|
|
MODULE_PARM_DESC(p_ssize, "Playback Sample Size(bytes)");
|
|
|
|
|
|
|
|
/* Capture(USB-OUT) Default Stereo - Fl/Fr */
|
|
|
|
static int c_chmask = UAC1_DEF_CCHMASK;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(c_chmask, uint, 0444);
|
2017-06-18 06:23:54 -07:00
|
|
|
MODULE_PARM_DESC(c_chmask, "Capture Channel Mask");
|
|
|
|
|
|
|
|
/* Capture Default 48 KHz */
|
2022-01-21 08:53:04 -07:00
|
|
|
static int c_srates[UAC_MAX_RATES] = {UAC1_DEF_CSRATE};
|
|
|
|
static int c_srates_cnt = 1;
|
|
|
|
module_param_array_named(c_srate, c_srates, uint, &c_srates_cnt, 0444);
|
|
|
|
MODULE_PARM_DESC(c_srate, "Capture Sampling Rates (array)");
|
2017-06-18 06:23:54 -07:00
|
|
|
|
|
|
|
/* Capture Default 16bits/sample */
|
|
|
|
static int c_ssize = UAC1_DEF_CSSIZE;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(c_ssize, uint, 0444);
|
2017-06-18 06:23:54 -07:00
|
|
|
MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)");
|
|
|
|
#else /* CONFIG_GADGET_UAC1_LEGACY */
|
2017-06-18 06:23:53 -07:00
|
|
|
#include "u_uac1_legacy.h"
|
2014-07-22 10:58:39 -07:00
|
|
|
|
|
|
|
static char *fn_play = FILE_PCM_PLAYBACK;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(fn_play, charp, 0444);
|
2014-07-22 10:58:39 -07:00
|
|
|
MODULE_PARM_DESC(fn_play, "Playback PCM device file name");
|
|
|
|
|
|
|
|
static char *fn_cap = FILE_PCM_CAPTURE;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(fn_cap, charp, 0444);
|
2014-07-22 10:58:39 -07:00
|
|
|
MODULE_PARM_DESC(fn_cap, "Capture PCM device file name");
|
|
|
|
|
|
|
|
static char *fn_cntl = FILE_CONTROL;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(fn_cntl, charp, 0444);
|
2014-07-22 10:58:39 -07:00
|
|
|
MODULE_PARM_DESC(fn_cntl, "Control device file name");
|
|
|
|
|
2014-07-22 10:58:42 -07:00
|
|
|
static int req_buf_size = UAC1_OUT_EP_MAX_PACKET_SIZE;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(req_buf_size, int, 0444);
|
2014-07-22 10:58:39 -07:00
|
|
|
MODULE_PARM_DESC(req_buf_size, "ISO OUT endpoint request buffer size");
|
|
|
|
|
2014-07-22 10:58:42 -07:00
|
|
|
static int req_count = UAC1_REQ_COUNT;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(req_count, int, 0444);
|
2014-07-22 10:58:39 -07:00
|
|
|
MODULE_PARM_DESC(req_count, "ISO OUT endpoint request count");
|
|
|
|
|
2014-07-22 10:58:42 -07:00
|
|
|
static int audio_buf_size = UAC1_AUDIO_BUF_SIZE;
|
2022-01-21 08:52:59 -07:00
|
|
|
module_param(audio_buf_size, int, 0444);
|
2014-07-22 10:58:39 -07:00
|
|
|
MODULE_PARM_DESC(audio_buf_size, "Audio buffer size");
|
2017-06-18 06:23:54 -07:00
|
|
|
#endif /* CONFIG_GADGET_UAC1_LEGACY */
|
2014-07-22 10:58:31 -07:00
|
|
|
#endif
|
|
|
|
|
2012-02-02 09:31:12 -07:00
|
|
|
/* string IDs are assigned dynamically */
|
|
|
|
|
|
|
|
static struct usb_string strings_dev[] = {
|
2012-09-10 06:01:58 -07:00
|
|
|
[USB_GADGET_MANUFACTURER_IDX].s = "",
|
2012-09-06 11:11:21 -07:00
|
|
|
[USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
|
|
|
|
[USB_GADGET_SERIAL_IDX].s = "",
|
2012-02-02 09:31:12 -07:00
|
|
|
{ } /* end of list */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_gadget_strings stringtab_dev = {
|
|
|
|
.language = 0x0409, /* en-us */
|
|
|
|
.strings = strings_dev,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_gadget_strings *audio_strings[] = {
|
|
|
|
&stringtab_dev,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2017-06-18 06:23:54 -07:00
|
|
|
#ifndef CONFIG_GADGET_UAC1
|
2014-07-22 10:58:31 -07:00
|
|
|
static struct usb_function_instance *fi_uac2;
|
|
|
|
static struct usb_function *f_uac2;
|
2014-07-22 10:58:39 -07:00
|
|
|
#else
|
|
|
|
static struct usb_function_instance *fi_uac1;
|
|
|
|
static struct usb_function *f_uac1;
|
2014-07-22 10:58:31 -07:00
|
|
|
#endif
|
|
|
|
|
2009-06-03 06:17:58 -07:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
|
|
|
|
* Instead: allocate your own, using normal USB-IF procedures.
|
|
|
|
*/
|
|
|
|
|
2009-06-23 16:01:06 -07:00
|
|
|
/* Thanks to Linux Foundation for donating this product ID. */
|
|
|
|
#define AUDIO_VENDOR_NUM 0x1d6b /* Linux Foundation */
|
|
|
|
#define AUDIO_PRODUCT_NUM 0x0101 /* Linux-USB Audio Gadget */
|
2009-06-03 06:17:58 -07:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static struct usb_device_descriptor device_desc = {
|
|
|
|
.bLength = sizeof device_desc,
|
|
|
|
.bDescriptorType = USB_DT_DEVICE,
|
|
|
|
|
2015-10-20 09:33:13 -07:00
|
|
|
/* .bcdUSB = DYNAMIC */
|
2009-06-03 06:17:58 -07:00
|
|
|
|
2017-06-18 06:23:53 -07:00
|
|
|
#ifdef CONFIG_GADGET_UAC1_LEGACY
|
2009-06-03 06:17:58 -07:00
|
|
|
.bDeviceClass = USB_CLASS_PER_INTERFACE,
|
|
|
|
.bDeviceSubClass = 0,
|
|
|
|
.bDeviceProtocol = 0,
|
2012-02-02 09:31:34 -07:00
|
|
|
#else
|
|
|
|
.bDeviceClass = USB_CLASS_MISC,
|
|
|
|
.bDeviceSubClass = 0x02,
|
|
|
|
.bDeviceProtocol = 0x01,
|
|
|
|
#endif
|
2009-06-03 06:17:58 -07:00
|
|
|
/* .bMaxPacketSize0 = f(hardware) */
|
|
|
|
|
|
|
|
/* Vendor and product id defaults change according to what configs
|
|
|
|
* we support. (As does bNumConfigurations.) These values can
|
|
|
|
* also be overridden by module parameters.
|
|
|
|
*/
|
2015-06-05 18:32:53 -07:00
|
|
|
.idVendor = cpu_to_le16(AUDIO_VENDOR_NUM),
|
|
|
|
.idProduct = cpu_to_le16(AUDIO_PRODUCT_NUM),
|
2009-06-03 06:17:58 -07:00
|
|
|
/* .bcdDevice = f(hardware) */
|
|
|
|
/* .iManufacturer = DYNAMIC */
|
|
|
|
/* .iProduct = DYNAMIC */
|
|
|
|
/* NO SERIAL NUMBER */
|
|
|
|
.bNumConfigurations = 1,
|
|
|
|
};
|
|
|
|
|
2015-07-09 00:18:51 -07:00
|
|
|
static const struct usb_descriptor_header *otg_desc[2];
|
2009-06-03 06:17:58 -07:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2015-04-10 15:14:21 -07:00
|
|
|
static int audio_do_config(struct usb_configuration *c)
|
2009-06-03 06:17:58 -07:00
|
|
|
{
|
2014-07-22 10:58:31 -07:00
|
|
|
int status;
|
|
|
|
|
2009-06-03 06:17:58 -07:00
|
|
|
/* FIXME alloc iConfiguration string, set it in c->strings */
|
|
|
|
|
|
|
|
if (gadget_is_otg(c->cdev->gadget)) {
|
|
|
|
c->descriptors = otg_desc;
|
|
|
|
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
|
|
|
|
}
|
|
|
|
|
2017-06-18 06:23:54 -07:00
|
|
|
#ifdef CONFIG_GADGET_UAC1
|
2014-07-22 10:58:39 -07:00
|
|
|
f_uac1 = usb_get_function(fi_uac1);
|
|
|
|
if (IS_ERR(f_uac1)) {
|
|
|
|
status = PTR_ERR(f_uac1);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = usb_add_function(c, f_uac1);
|
|
|
|
if (status < 0) {
|
|
|
|
usb_put_function(f_uac1);
|
|
|
|
return status;
|
|
|
|
}
|
2014-07-22 10:58:31 -07:00
|
|
|
#else
|
|
|
|
f_uac2 = usb_get_function(fi_uac2);
|
|
|
|
if (IS_ERR(f_uac2)) {
|
|
|
|
status = PTR_ERR(f_uac2);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = usb_add_function(c, f_uac2);
|
|
|
|
if (status < 0) {
|
|
|
|
usb_put_function(f_uac2);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
#endif
|
2009-06-03 06:17:58 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_configuration audio_config_driver = {
|
|
|
|
.label = DRIVER_DESC,
|
|
|
|
.bConfigurationValue = 1,
|
|
|
|
/* .iConfiguration = DYNAMIC */
|
|
|
|
.bmAttributes = USB_CONFIG_ATT_SELFPOWER,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2015-04-10 15:14:21 -07:00
|
|
|
static int audio_bind(struct usb_composite_dev *cdev)
|
2009-06-03 06:17:58 -07:00
|
|
|
{
|
2017-06-18 06:23:54 -07:00
|
|
|
#ifndef CONFIG_GADGET_UAC1
|
2014-07-22 10:58:31 -07:00
|
|
|
struct f_uac2_opts *uac2_opts;
|
2022-01-21 08:53:03 -07:00
|
|
|
int i;
|
2017-06-18 06:23:54 -07:00
|
|
|
#else
|
|
|
|
#ifndef CONFIG_GADGET_UAC1_LEGACY
|
|
|
|
struct f_uac1_opts *uac1_opts;
|
2022-01-21 08:53:04 -07:00
|
|
|
int i;
|
2014-07-22 10:58:39 -07:00
|
|
|
#else
|
2017-06-18 06:23:53 -07:00
|
|
|
struct f_uac1_legacy_opts *uac1_opts;
|
2017-06-18 06:23:54 -07:00
|
|
|
#endif
|
2014-07-22 10:58:31 -07:00
|
|
|
#endif
|
2009-06-03 06:17:58 -07:00
|
|
|
int status;
|
|
|
|
|
2017-06-18 06:23:54 -07:00
|
|
|
#ifndef CONFIG_GADGET_UAC1
|
2014-07-22 10:58:31 -07:00
|
|
|
fi_uac2 = usb_get_function_instance("uac2");
|
|
|
|
if (IS_ERR(fi_uac2))
|
|
|
|
return PTR_ERR(fi_uac2);
|
2017-06-18 06:23:54 -07:00
|
|
|
#else
|
|
|
|
#ifndef CONFIG_GADGET_UAC1_LEGACY
|
|
|
|
fi_uac1 = usb_get_function_instance("uac1");
|
2014-07-22 10:58:39 -07:00
|
|
|
#else
|
2017-06-18 06:23:53 -07:00
|
|
|
fi_uac1 = usb_get_function_instance("uac1_legacy");
|
2017-06-18 06:23:54 -07:00
|
|
|
#endif
|
2014-07-22 10:58:39 -07:00
|
|
|
if (IS_ERR(fi_uac1))
|
|
|
|
return PTR_ERR(fi_uac1);
|
2014-07-22 10:58:31 -07:00
|
|
|
#endif
|
|
|
|
|
2017-06-18 06:23:54 -07:00
|
|
|
#ifndef CONFIG_GADGET_UAC1
|
2014-07-22 10:58:31 -07:00
|
|
|
uac2_opts = container_of(fi_uac2, struct f_uac2_opts, func_inst);
|
|
|
|
uac2_opts->p_chmask = p_chmask;
|
2022-01-21 08:53:03 -07:00
|
|
|
|
|
|
|
for (i = 0; i < p_srates_cnt; ++i)
|
|
|
|
uac2_opts->p_srates[i] = p_srates[i];
|
|
|
|
|
2014-07-22 10:58:31 -07:00
|
|
|
uac2_opts->p_ssize = p_ssize;
|
2022-01-27 04:43:29 -07:00
|
|
|
uac2_opts->p_hs_bint = p_hs_bint;
|
2014-07-22 10:58:31 -07:00
|
|
|
uac2_opts->c_chmask = c_chmask;
|
2022-01-21 08:53:03 -07:00
|
|
|
|
|
|
|
for (i = 0; i < c_srates_cnt; ++i)
|
|
|
|
uac2_opts->c_srates[i] = c_srates[i];
|
|
|
|
|
2014-07-22 10:58:31 -07:00
|
|
|
uac2_opts->c_ssize = c_ssize;
|
2022-01-27 04:43:29 -07:00
|
|
|
uac2_opts->c_hs_bint = c_hs_bint;
|
2017-01-03 19:19:23 -07:00
|
|
|
uac2_opts->req_number = UAC2_DEF_REQ_NUM;
|
2014-07-22 10:58:39 -07:00
|
|
|
#else
|
2017-06-18 06:23:54 -07:00
|
|
|
#ifndef CONFIG_GADGET_UAC1_LEGACY
|
|
|
|
uac1_opts = container_of(fi_uac1, struct f_uac1_opts, func_inst);
|
|
|
|
uac1_opts->p_chmask = p_chmask;
|
2022-01-21 08:53:04 -07:00
|
|
|
|
|
|
|
for (i = 0; i < p_srates_cnt; ++i)
|
|
|
|
uac1_opts->p_srates[i] = p_srates[i];
|
|
|
|
|
2017-06-18 06:23:54 -07:00
|
|
|
uac1_opts->p_ssize = p_ssize;
|
|
|
|
uac1_opts->c_chmask = c_chmask;
|
2022-01-21 08:53:04 -07:00
|
|
|
|
|
|
|
for (i = 0; i < c_srates_cnt; ++i)
|
|
|
|
uac1_opts->c_srates[i] = c_srates[i];
|
|
|
|
|
2017-06-18 06:23:54 -07:00
|
|
|
uac1_opts->c_ssize = c_ssize;
|
|
|
|
uac1_opts->req_number = UAC1_DEF_REQ_NUM;
|
|
|
|
#else /* CONFIG_GADGET_UAC1_LEGACY */
|
2017-06-18 06:23:53 -07:00
|
|
|
uac1_opts = container_of(fi_uac1, struct f_uac1_legacy_opts, func_inst);
|
2014-07-22 10:58:39 -07:00
|
|
|
uac1_opts->fn_play = fn_play;
|
|
|
|
uac1_opts->fn_cap = fn_cap;
|
|
|
|
uac1_opts->fn_cntl = fn_cntl;
|
|
|
|
uac1_opts->req_buf_size = req_buf_size;
|
|
|
|
uac1_opts->req_count = req_count;
|
|
|
|
uac1_opts->audio_buf_size = audio_buf_size;
|
2017-06-18 06:23:54 -07:00
|
|
|
#endif /* CONFIG_GADGET_UAC1_LEGACY */
|
2014-07-22 10:58:31 -07:00
|
|
|
#endif
|
|
|
|
|
2012-09-06 11:11:16 -07:00
|
|
|
status = usb_string_ids_tab(cdev, strings_dev);
|
2009-06-03 06:17:58 -07:00
|
|
|
if (status < 0)
|
|
|
|
goto fail;
|
2012-09-06 11:11:21 -07:00
|
|
|
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
|
|
|
|
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
|
2009-06-03 06:17:58 -07:00
|
|
|
|
2015-07-09 00:18:51 -07:00
|
|
|
if (gadget_is_otg(cdev->gadget) && !otg_desc[0]) {
|
|
|
|
struct usb_descriptor_header *usb_desc;
|
|
|
|
|
|
|
|
usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
|
2020-05-03 03:47:07 -07:00
|
|
|
if (!usb_desc) {
|
|
|
|
status = -ENOMEM;
|
2015-07-09 00:18:51 -07:00
|
|
|
goto fail;
|
2020-05-03 03:47:07 -07:00
|
|
|
}
|
2015-07-09 00:18:51 -07:00
|
|
|
usb_otg_descriptor_init(cdev->gadget, usb_desc);
|
|
|
|
otg_desc[0] = usb_desc;
|
|
|
|
otg_desc[1] = NULL;
|
|
|
|
}
|
|
|
|
|
2010-08-12 08:43:55 -07:00
|
|
|
status = usb_add_config(cdev, &audio_config_driver, audio_do_config);
|
2009-06-03 06:17:58 -07:00
|
|
|
if (status < 0)
|
2015-07-09 00:18:51 -07:00
|
|
|
goto fail_otg_desc;
|
2012-09-10 06:01:53 -07:00
|
|
|
usb_composite_overwrite_options(cdev, &coverwrite);
|
2009-06-03 06:17:58 -07:00
|
|
|
|
|
|
|
INFO(cdev, "%s, version: %s\n", DRIVER_DESC, DRIVER_VERSION);
|
|
|
|
return 0;
|
|
|
|
|
2015-07-09 00:18:51 -07:00
|
|
|
fail_otg_desc:
|
|
|
|
kfree(otg_desc[0]);
|
|
|
|
otg_desc[0] = NULL;
|
2009-06-03 06:17:58 -07:00
|
|
|
fail:
|
2017-06-18 06:23:54 -07:00
|
|
|
#ifndef CONFIG_GADGET_UAC1
|
2014-07-22 10:58:31 -07:00
|
|
|
usb_put_function_instance(fi_uac2);
|
2014-07-22 10:58:39 -07:00
|
|
|
#else
|
|
|
|
usb_put_function_instance(fi_uac1);
|
2014-07-22 10:58:31 -07:00
|
|
|
#endif
|
2009-06-03 06:17:58 -07:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-04-10 15:14:21 -07:00
|
|
|
static int audio_unbind(struct usb_composite_dev *cdev)
|
2009-06-03 06:17:58 -07:00
|
|
|
{
|
2017-06-18 06:23:54 -07:00
|
|
|
#ifdef CONFIG_GADGET_UAC1
|
2014-07-22 10:58:39 -07:00
|
|
|
if (!IS_ERR_OR_NULL(f_uac1))
|
|
|
|
usb_put_function(f_uac1);
|
|
|
|
if (!IS_ERR_OR_NULL(fi_uac1))
|
|
|
|
usb_put_function_instance(fi_uac1);
|
2014-07-22 10:58:31 -07:00
|
|
|
#else
|
|
|
|
if (!IS_ERR_OR_NULL(f_uac2))
|
|
|
|
usb_put_function(f_uac2);
|
|
|
|
if (!IS_ERR_OR_NULL(fi_uac2))
|
|
|
|
usb_put_function_instance(fi_uac2);
|
2012-02-02 09:31:34 -07:00
|
|
|
#endif
|
2015-07-09 00:18:51 -07:00
|
|
|
kfree(otg_desc[0]);
|
|
|
|
otg_desc[0] = NULL;
|
|
|
|
|
2009-06-03 06:17:58 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-10 15:14:21 -07:00
|
|
|
static struct usb_composite_driver audio_driver = {
|
2009-06-03 06:17:58 -07:00
|
|
|
.name = "g_audio",
|
|
|
|
.dev = &device_desc,
|
|
|
|
.strings = audio_strings,
|
2011-06-29 06:41:49 -07:00
|
|
|
.max_speed = USB_SPEED_HIGH,
|
2012-09-06 11:11:04 -07:00
|
|
|
.bind = audio_bind,
|
2015-04-10 15:14:21 -07:00
|
|
|
.unbind = audio_unbind,
|
2009-06-03 06:17:58 -07:00
|
|
|
};
|
|
|
|
|
2014-07-09 09:09:56 -07:00
|
|
|
module_usb_composite_driver(audio_driver);
|
2009-06-03 06:17:58 -07:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_AUTHOR("Bryan Wu <cooloney@kernel.org>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|