Commit 695d39ff authored by Julian Scheel's avatar Julian Scheel Committed by Greg Kroah-Hartman

usb: gadget: f_uac1: Support multiple sampling rates

A list of sampling rates can be specified via configfs. All enabled
sampling rates are sent to the USB host on request. When the host
selects a sampling rate the internal active rate is updated.

Config strings with single value stay compatible with the previous version.

Multiple samplerates passed as configuration arrays to g_audio module
when built for f_uac1.
Signed-off-by: default avatarJulian Scheel <julian@jusst.de>
Signed-off-by: default avatarPavel Hofman <pavel.hofman@ivitera.com>
Link: https://lore.kernel.org/r/20220121155308.48794-7-pavel.hofman@ivitera.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a7339e4f
...@@ -6,7 +6,7 @@ Description: ...@@ -6,7 +6,7 @@ Description:
===================== ======================================= ===================== =======================================
c_chmask capture channel mask c_chmask capture channel mask
c_srate capture sampling rate c_srate list of capture sampling rates (comma-separated)
c_ssize capture sample size (bytes) c_ssize capture sample size (bytes)
c_mute_present capture mute control enable c_mute_present capture mute control enable
c_volume_present capture volume control enable c_volume_present capture volume control enable
...@@ -17,7 +17,7 @@ Description: ...@@ -17,7 +17,7 @@ Description:
c_volume_res capture volume control resolution c_volume_res capture volume control resolution
(in 1/256 dB) (in 1/256 dB)
p_chmask playback channel mask p_chmask playback channel mask
p_srate playback sampling rate p_srate list of playback sampling rates (comma-separated)
p_ssize playback sample size (bytes) p_ssize playback sample size (bytes)
p_mute_present playback mute control enable p_mute_present playback mute control enable
p_volume_present playback volume control enable p_volume_present playback volume control enable
......
...@@ -916,7 +916,7 @@ The uac1 function provides these attributes in its function directory: ...@@ -916,7 +916,7 @@ The uac1 function provides these attributes in its function directory:
================ ==================================================== ================ ====================================================
c_chmask capture channel mask c_chmask capture channel mask
c_srate capture sampling rate c_srate list of capture sampling rates (comma-separated)
c_ssize capture sample size (bytes) c_ssize capture sample size (bytes)
c_mute_present capture mute control enable c_mute_present capture mute control enable
c_volume_present capture volume control enable c_volume_present capture volume control enable
...@@ -924,7 +924,7 @@ The uac1 function provides these attributes in its function directory: ...@@ -924,7 +924,7 @@ The uac1 function provides these attributes in its function directory:
c_volume_max capture volume control max value (in 1/256 dB) c_volume_max capture volume control max value (in 1/256 dB)
c_volume_res capture volume control resolution (in 1/256 dB) c_volume_res capture volume control resolution (in 1/256 dB)
p_chmask playback channel mask p_chmask playback channel mask
p_srate playback sampling rate p_srate list of playback sampling rates (comma-separated)
p_ssize playback sample size (bytes) p_ssize playback sample size (bytes)
p_mute_present playback mute control enable p_mute_present playback mute control enable
p_volume_present playback volume control enable p_volume_present playback volume control enable
......
This diff is collapsed.
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define __U_UAC1_H #define __U_UAC1_H
#include <linux/usb/composite.h> #include <linux/usb/composite.h>
#include "uac_common.h"
#define UAC1_OUT_EP_MAX_PACKET_SIZE 200 #define UAC1_OUT_EP_MAX_PACKET_SIZE 200
#define UAC1_DEF_CCHMASK 0x3 #define UAC1_DEF_CCHMASK 0x3
...@@ -30,10 +31,10 @@ ...@@ -30,10 +31,10 @@
struct f_uac1_opts { struct f_uac1_opts {
struct usb_function_instance func_inst; struct usb_function_instance func_inst;
int c_chmask; int c_chmask;
int c_srate; int c_srates[UAC_MAX_RATES];
int c_ssize; int c_ssize;
int p_chmask; int p_chmask;
int p_srate; int p_srates[UAC_MAX_RATES];
int p_ssize; int p_ssize;
bool p_mute_present; bool p_mute_present;
......
...@@ -61,9 +61,10 @@ module_param(p_chmask, uint, 0444); ...@@ -61,9 +61,10 @@ module_param(p_chmask, uint, 0444);
MODULE_PARM_DESC(p_chmask, "Playback Channel Mask"); MODULE_PARM_DESC(p_chmask, "Playback Channel Mask");
/* Playback Default 48 KHz */ /* Playback Default 48 KHz */
static int p_srate = UAC1_DEF_PSRATE; static int p_srates[UAC_MAX_RATES] = {UAC1_DEF_PSRATE};
module_param(p_srate, uint, 0444); static int p_srates_cnt = 1;
MODULE_PARM_DESC(p_srate, "Playback Sampling Rate"); module_param_array_named(p_srate, p_srates, uint, &p_srates_cnt, 0444);
MODULE_PARM_DESC(p_srate, "Playback Sampling Rates (array)");
/* Playback Default 16bits/sample */ /* Playback Default 16bits/sample */
static int p_ssize = UAC1_DEF_PSSIZE; static int p_ssize = UAC1_DEF_PSSIZE;
...@@ -76,9 +77,10 @@ module_param(c_chmask, uint, 0444); ...@@ -76,9 +77,10 @@ module_param(c_chmask, uint, 0444);
MODULE_PARM_DESC(c_chmask, "Capture Channel Mask"); MODULE_PARM_DESC(c_chmask, "Capture Channel Mask");
/* Capture Default 48 KHz */ /* Capture Default 48 KHz */
static int c_srate = UAC1_DEF_CSRATE; static int c_srates[UAC_MAX_RATES] = {UAC1_DEF_CSRATE};
module_param(c_srate, uint, 0444); static int c_srates_cnt = 1;
MODULE_PARM_DESC(c_srate, "Capture Sampling Rate"); module_param_array_named(c_srate, c_srates, uint, &c_srates_cnt, 0444);
MODULE_PARM_DESC(c_srate, "Capture Sampling Rates (array)");
/* Capture Default 16bits/sample */ /* Capture Default 16bits/sample */
static int c_ssize = UAC1_DEF_CSSIZE; static int c_ssize = UAC1_DEF_CSSIZE;
...@@ -243,6 +245,7 @@ static int audio_bind(struct usb_composite_dev *cdev) ...@@ -243,6 +245,7 @@ static int audio_bind(struct usb_composite_dev *cdev)
#else #else
#ifndef CONFIG_GADGET_UAC1_LEGACY #ifndef CONFIG_GADGET_UAC1_LEGACY
struct f_uac1_opts *uac1_opts; struct f_uac1_opts *uac1_opts;
int i;
#else #else
struct f_uac1_legacy_opts *uac1_opts; struct f_uac1_legacy_opts *uac1_opts;
#endif #endif
...@@ -282,10 +285,16 @@ static int audio_bind(struct usb_composite_dev *cdev) ...@@ -282,10 +285,16 @@ static int audio_bind(struct usb_composite_dev *cdev)
#ifndef CONFIG_GADGET_UAC1_LEGACY #ifndef CONFIG_GADGET_UAC1_LEGACY
uac1_opts = container_of(fi_uac1, struct f_uac1_opts, func_inst); uac1_opts = container_of(fi_uac1, struct f_uac1_opts, func_inst);
uac1_opts->p_chmask = p_chmask; uac1_opts->p_chmask = p_chmask;
uac1_opts->p_srate = p_srate;
for (i = 0; i < p_srates_cnt; ++i)
uac1_opts->p_srates[i] = p_srates[i];
uac1_opts->p_ssize = p_ssize; uac1_opts->p_ssize = p_ssize;
uac1_opts->c_chmask = c_chmask; uac1_opts->c_chmask = c_chmask;
uac1_opts->c_srate = c_srate;
for (i = 0; i < c_srates_cnt; ++i)
uac1_opts->c_srates[i] = c_srates[i];
uac1_opts->c_ssize = c_ssize; uac1_opts->c_ssize = c_ssize;
uac1_opts->req_number = UAC1_DEF_REQ_NUM; uac1_opts->req_number = UAC1_DEF_REQ_NUM;
#else /* CONFIG_GADGET_UAC1_LEGACY */ #else /* CONFIG_GADGET_UAC1_LEGACY */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment