From patchwork Sun Aug 16 12:50:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anssi Hannula X-Patchwork-Id: 7022391 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2C2A39F372 for ; Sun, 16 Aug 2015 12:50:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E7B7E20676 for ; Sun, 16 Aug 2015 12:50:38 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 6D9762062C for ; Sun, 16 Aug 2015 12:50:36 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 95E77260505; Sun, 16 Aug 2015 14:50:34 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,NO_DNS_FOR_FROM, RCVD_IN_DNSWL_LOW,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 471C82604B3; Sun, 16 Aug 2015 14:50:27 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 651832604BC; Sun, 16 Aug 2015 14:50:25 +0200 (CEST) Received: from webmail.tpnet.fi (webmail.tpnet.fi [62.106.63.33]) by alsa0.perex.cz (Postfix) with ESMTP id 38FF42604A9 for ; Sun, 16 Aug 2015 14:50:18 +0200 (CEST) Received: from mail.onse.fi (host-109-204-178-176.tp-fne.tampereenpuhelin.net [109.204.178.176]) by webmail.tpnet.fi (Postfix) with ESMTP id 57C032141A; Sun, 16 Aug 2015 15:50:17 +0300 (EEST) Received: by mail.onse.fi (Postfix, from userid 501) id 40D3640B7B; Sun, 16 Aug 2015 15:50:17 +0300 (EEST) From: Anssi Hannula To: Takashi Iwai Date: Sun, 16 Aug 2015 15:50:12 +0300 Message-Id: <1439729413-30804-1-git-send-email-anssi.hannula@iki.fi> X-Mailer: git-send-email 2.3.8 Cc: alsa-devel@alsa-project.org, stable@vger.kernel.org Subject: [alsa-devel] [PATCH 1/2] ALSA: usb-audio: Add a volume scale quirk for AudioQuest DragonFly X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP AudioQuest DragonFly DAC reports a volume control range of 0..50 (0x0000..0x0032) which in USB Audio means a range of 0 .. 0.2dB, which is obviously incorrect and causes software using the dB information in e.g. volume sliders to have a massive volume difference in 100..102% range. The actual volume mapping seems to be neither linear volume nor linear dB scale, but instead quite close to the cubic mapping e.g. alsamixer uses, with a range of -53...0 dB. Add a quirk for DragonFly to use a custom dB mapping, based on my measurements, using a 10-item range TLV (so it still fits in alsa-lib MAX_TLV_RANGE_SIZE). Tested on AudioQuest DragonFly HW v1.2. The quirk is only applied if the range is 0..50, so if this gets fixed/changed in later HW revisions it will no longer be applied. Signed-off-by: Anssi Hannula Cc: --- sound/usb/mixer_quirks.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index 337c317ead6f..39d7f34e44e6 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "usbaudio.h" #include "mixer.h" @@ -1733,6 +1734,38 @@ static int snd_microii_controls_create(struct usb_mixer_interface *mixer) return 0; } +static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer) +{ + struct usb_mixer_elem_list *list; + struct usb_mixer_elem_info *cval; + static const int unit_id = 7; + + /* approximation using 10 ranges based on output measurement on hw v1.2 */ + static const DECLARE_TLV_DB_RANGE(scale, + 0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970), + 2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160), + 6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710), + 8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560), + 15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324), + 17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031), + 20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393), + 27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032), + 32, 40, TLV_DB_MINMAX_ITEM(-968, -490), + 41, 50, TLV_DB_MINMAX_ITEM(-441, 0), + ); + + for (list = mixer->id_elems[unit_id]; list; list = list->next_id_elem) { + cval = (struct usb_mixer_elem_info *)list; + if (cval->control == UAC_FU_VOLUME && + cval->min == 0 && cval->max == 50) { + usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk\n"); + list->kctl->tlv.p = scale; + list->kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; + list->kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; + } + } +} + int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) { int err = 0; @@ -1810,6 +1843,10 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */ err = snd_scarlett_controls_create(mixer); break; + + case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */ + snd_dragonfly_quirk_db_scale(mixer); + break; } return err;