From patchwork Sat May 14 21:09:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 9095631 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AA14BBF29F for ; Sat, 14 May 2016 21:16:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B7B9420272 for ; Sat, 14 May 2016 21:16:40 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 755062026F for ; Sat, 14 May 2016 21:16:39 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 543412658A6; Sat, 14 May 2016 23:16:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id ED1CD2654CE; Sat, 14 May 2016 23:15:15 +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 B35CA265795; Sat, 14 May 2016 23:15:14 +0200 (CEST) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0101.outbound.protection.outlook.com [104.47.0.101]) by alsa0.perex.cz (Postfix) with ESMTP id 484202650CC for ; Sat, 14 May 2016 23:14:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axentiatech.onmicrosoft.com; s=selector1-axentia-se; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=cABMlJP0TFDtc09zKmo9prZ+XQ5RqVJ2QEZwlyh2rzY=; b=A3gfPySaEWD/2ItdfbI3HmFxDOz2/B9XJ5w5G9M4TAmU+d3CaZ+KyHsuYZUk/V8qz+1oZ0EsxTgTLlAQYx5O8yHIeylWBSmch6c3FuYIjxdblHB0ICW6rBij89wu+ERmk37jGF/XVZ6hciol0W0lnmSfkn9w2f3Hzoo4TXoUB/o= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=axentia.se; Received: from localhost.localdomain (217.210.101.82) by VI1PR02MB1311.eurprd02.prod.outlook.com (10.165.231.153) with Microsoft SMTP Server (TLS) id 15.1.497.12; Sat, 14 May 2016 21:14:44 +0000 From: Peter Rosin To: Date: Sat, 14 May 2016 23:09:40 +0200 Message-ID: <1463260181-21344-4-git-send-email-peda@axentia.se> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1463260181-21344-1-git-send-email-peda@axentia.se> References: <1463260181-21344-1-git-send-email-peda@axentia.se> MIME-Version: 1.0 X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: DB3PR08CA0017.eurprd08.prod.outlook.com (10.161.51.155) To VI1PR02MB1311.eurprd02.prod.outlook.com (10.165.231.153) X-MS-Office365-Filtering-Correlation-Id: a67762d9-693f-4296-8b93-08d37c3cc7ae X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1311; 2:PQ0OW118rPfl7fipdWMQlM6+tlXX3axC2J+McPjg8fflMVvvnGMTKZGO10gXB9PhtiNUFO5DloNnaQd+ptoZcpwfYJywOLptvdP9MagAapmaOuYiBxo+yA+IzEffMDyoOXnPnZZZJTP2SWREJzvZ/Rv5hngBSMamRzbeyUllwWiz4lEQROLviWf8PR+sB6l4; 3:3U8vP1ZfSxOwXfLirl8NrnT3CsZZKWvZW0++ZHJG7DR5BP5FILFrf0iRItQ59G8QVTW9z9HWZnDnv4cr8O9p4j3Rq7zETnpK+dI1TR0Aqk+VA7A82o6qcVtaiWfzbELC X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB1311; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1311; 25:YqQbn8J2Nuhl/sYiaVRavZiiDew+1QUVAyoL8X5OAf9a6FUAzoEKcP49809SO2uXkw+2pjDK9NWl+T5QK1AEnOnW7QfM2fHqPBUdSqYRK9rxWOVMPjQDUE6wUhgKiODuV0Cd4+iwpMnZCYtDq+3SoWTXF1T23XpWIHjqqyh0+YfEhqwYYjyH9vLWLsftoY7kEWHs3T+cbpmrOH3Yc1nKPHg5x1NBBsXlpZZneXNitJU0+2FGpx+jJhFOMf2PVKvr1NPUx91zC8SkyPLwT8TakofmQZojlvOQ1+Txhgf+C9/1gRUc7g3UDkQKKtcFb1R2qsKuQiyT6h3AjkFfr2vkCMdC38/PYgVpxneK639BaXdmtttzdOLUiQP/mcEGa2zNSq8LdZsiAs08YKS9p8E0kLb7QVi43b+Q43uNnXm5e9KqpIXdh66wiit27xCedIv+Iwrirul3ejLdaDHdUcUCPFE7VZV3wXMouUBQhx6lTmYsIxRdL/6pLPSOqx1p0X54L4AWVFjnndywPGgI2lNZdbm5C8oPZZOd7kUs0Ra/eOPudoo/y6AoUZeuc0/Ha+cjenGKhT0Nsg8TMNqesHC/RAV5GTP3HvxnFRahqfYyij+tvVlxwU/ROYOjsLkeWKd5mKMOsVPWmfcYmXMfZL/3IClYci7jRpkgl5A8BUQxbbPlX3OJimdL94wD95gZaToYfUG4FbZJPm3G3sY3RknqxEtUzRokWtIDOgabGu86/VY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040130)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041072)(6043046); SRVR:VI1PR02MB1311; BCL:0; PCL:0; RULEID:; SRVR:VI1PR02MB1311; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1311; 4:7sDVoBAMigyijyYhhS1vtbWdtCmU/mzy9QvuhuwSD6CN2wHDF8fMknCgM4okI9rnWAZu58XXciyk+0MTVJApe5vHT8pms6j43VGfrx/Lc5GqeXIyIbPRaEyCQU2kBNiNsPDoG5BdG3peURojqsHz/tfjTPKnPH2big16dnOq3oQjsjI3Ap7f1JG/qaoE0jpFu+mY/akYy+0ncC+t0oJgV8ZfUzfuJj+8F6wqlIMI9vdI74rIBOhiM6eghRi5i2dJeJeGFCUMF5RnwuZpD+uoWeNWY1qpr6LIfaFKUQzqoIIclbeYOoJlDzCuVkYpt2fbP56XZTt2qcM2BgUQI+v0AJweH3wfpzUvzFDeHw2GI+7xFurlTjMyZP1AKFRKUcQa/H8TNCal1ADU0x1CnilmLn62bkmV1b7fFYh3szbGlBs= X-Forefront-PRVS: 094213BFEA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(19580405001)(189998001)(48376002)(586003)(6116002)(3846002)(5003940100001)(50986999)(76176999)(2950100001)(5004730100002)(77096005)(110136002)(42186005)(4326007)(33646002)(5008740100001)(50466002)(66066001)(74482002)(36756003)(47776003)(2906002)(92566002)(19580395003)(8676002)(229853001)(2351001)(81166006)(50226002)(86362001)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR02MB1311; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1311; 23:WQQbIdQcTqzbkGh5xnK6h+/cRxwNmFDouIouzYX12aHxN/Nmpa8ToPkbs99mp7rEC4cJ6KIUcb2prDdqjcKNn8LIHQfqugtjmpu3Pn17CYRWJCKJeMvSeZn1KkKt3370tkJiF+pBYC65nJdkzyzepGFELO1DP/7EEU3jqPB6Dm3DTX+Aar7/bMyTi3Y+Kg8p/wzOsgkjtIEbFfzBUSZ7wH3kPAHiCxacYkLGBIuNjBpsV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p4D5/GOdKhKsktdVaSb8nVGgBfEgMYUUbAc36Aea/RCWKx0VhxZpjwlsIzFk12sx31xQ/El6EOc/1T3ej/vX9qyvBzG/N8fcMFI5LZbt9jJS92v45oopP/Er3QueomRD+Ai791mJeKBxWBZOrhd SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2016 21:14:44.7636 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR02MB1311 Cc: Mark Rutland , devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Pawel Moll , Ian Campbell , Mark Brown , Takashi Iwai , Liam Girdwood , Rob Herring , Misbah Ullah Khan , Kumar Gala , Peter Rosin Subject: [alsa-devel] [PATCH v4 3/4] ASoC: dapm: support mixer controls with mute at non-zero value 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP The max9860 codec has a mixer control field that has its mute/disable at the wrong end of the scale. I.e. you turn the volume up and up, and then as the final step the volume is off. This does not sit well with DAPM, which assumes the mute/off is at the minimum value. Add support for such backwards controls with code that searches TLV ranges for the mute value and use that as trigger for DAPM off. Signed-off-by: Peter Rosin --- sound/soc/soc-dapm.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index c4464858bf01..8a1131781339 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -722,16 +723,46 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, return -ENODEV; } +static int dapm_find_tlv_mute(const unsigned int *tlv) +{ + int cnt; + const unsigned int *range; + + if (!tlv || tlv[0] != SNDRV_CTL_TLVT_DB_RANGE) + return 0; + + cnt = tlv[1] / sizeof(unsigned int); + + /* + * Each group of six values should be + * { start end type len min step/mute } + */ + for (range = &tlv[2]; cnt >= 6; cnt -= 6, range += 6) { + if (range[2] != SNDRV_CTL_TLVT_DB_SCALE) + return 0; /* wrong type, terminate */ + if (range[3] != 2 * sizeof(unsigned int)) + return 0; /* wrong len, terminate */ + if (!(range[5] & TLV_DB_SCALE_MUTE)) + continue; /* no mute in this range */ + return range[0]; /* start of this range is the mute value */ + } + + return 0; +} + /* set up initial codec paths */ static void dapm_set_mixer_path_status(struct snd_soc_dapm_path *p, int i) { + const struct snd_kcontrol_new *kcontrol_new + = &p->sink->kcontrol_news[i]; struct soc_mixer_control *mc = (struct soc_mixer_control *) - p->sink->kcontrol_news[i].private_value; + kcontrol_new->private_value; unsigned int reg = mc->reg; unsigned int shift = mc->shift; unsigned int max = mc->max; unsigned int mask = (1 << fls(max)) - 1; unsigned int invert = mc->invert; + int mute_value = dapm_find_tlv_mute(kcontrol_new->tlv.p); unsigned int val; if (reg != SND_SOC_NOPM) { @@ -739,7 +770,7 @@ static void dapm_set_mixer_path_status(struct snd_soc_dapm_path *p, int i) val = (val >> shift) & mask; if (invert) val = max - val; - p->connect = !!val; + p->connect = val != mute_value; } else { p->connect = 0; } @@ -3045,6 +3076,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, int max = mc->max; unsigned int mask = (1 << fls(max)) - 1; unsigned int invert = mc->invert; + int mute_value = dapm_find_tlv_mute(kcontrol->tlv.p); unsigned int val; int connect, change, reg_change = 0; struct snd_soc_dapm_update update; @@ -3056,7 +3088,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, kcontrol->id.name); val = (ucontrol->value.integer.value[0] & mask); - connect = !!val; + connect = val != mute_value; if (invert) val = max - val;