Skip to content

Commit 41b3e5c

Browse files
zainwangrockchipsrkhuangtao
authored andcommitted
usb: gadget: u_audio: set volume value to uevent
Different Windwos version has different volume gain range [0], set UAC_VOLUME_MAX/MIN to maximum according UAC 1.0 spec. And Windows volume slider position / Loundness is not linear [1], it's better to set c/p_volume to uevent than percentage. [0]: https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/default-audio-volume-settings [1]: https://docs.microsoft.com/en-us/windows/win32/coreaudio/audio-tapered-volume-controls Signed-off-by: Zain Wang <wzz@rock-chips.com> Change-Id: I41d03cfe1d8d348720c89083707070c68a158bcb
1 parent 71d16a0 commit 41b3e5c

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

drivers/usb/gadget/function/u_audio.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,6 @@ static void g_audio_work(struct work_struct *data)
687687
struct device *dev = &gadget->dev;
688688
char *uac_event[4] = { NULL, NULL, NULL, NULL };
689689
char str[19];
690-
signed short volume;
691690
int i;
692691

693692
for (i = 0; i < SET_USB_STATE_MAX; i++) {
@@ -736,17 +735,13 @@ static void g_audio_work(struct work_struct *data)
736735
case SET_VOLUME_OUT:
737736
uac_event[0] = "USB_STATE=SET_VOLUME";
738737
uac_event[1] = "STREAM_DIRECTION=OUT";
739-
volume = (signed short)params->c_volume;
740-
volume /= UAC_VOLUME_RES;
741-
snprintf(str, sizeof(str), "VOLUME=%d%%", volume + 50);
738+
snprintf(str, sizeof(str), "VOLUME=%6d", (int16_t)params->c_volume);
742739
uac_event[2] = str;
743740
break;
744741
case SET_VOLUME_IN:
745742
uac_event[0] = "USB_STATE=SET_VOLUME";
746743
uac_event[1] = "STREAM_DIRECTION=IN";
747-
volume = (signed short)params->p_volume;
748-
volume /= UAC_VOLUME_RES;
749-
snprintf(str, sizeof(str), "VOLUME=%d%%", volume + 50);
744+
snprintf(str, sizeof(str), "VOLUME=%6d", (int16_t)params->p_volume);
750745
uac_event[2] = str;
751746
break;
752747
default:

drivers/usb/gadget/function/u_audio.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
#include <linux/usb/composite.h>
2323

2424
#define UAC_VOLUME_CUR 0x0000
25-
#define UAC_VOLUME_RES 0x0080 /* 0.5 dB */
26-
#define UAC_VOLUME_MAX 0x1900 /* 25 dB */
27-
#define UAC_VOLUME_MIN 0xE700 /* -25 dB */
28-
#define UAC_VOLUME_NEGATIVE_INFINITY 0x8000
25+
#define UAC_VOLUME_RES 0x0001 /* 1/256 dB */
26+
#define UAC_VOLUME_MAX 0x7FFF /* +127.9961 dB */
27+
#define UAC_VOLUME_MIN 0x8001 /* -127.9961 dB */
2928
#define UAC_MAX_RATES 10
3029
struct uac_params {
3130
/* playback */

0 commit comments

Comments
 (0)