From patchwork Wed Dec 19 23:45:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 10738345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 855891399 for ; Thu, 20 Dec 2018 00:22:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 718A328747 for ; Thu, 20 Dec 2018 00:22:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64E2328752; Thu, 20 Dec 2018 00:22:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DFE328747 for ; Thu, 20 Dec 2018 00:22:55 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id BA141267B39; Thu, 20 Dec 2018 00:46:58 +0100 (CET) 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 484E9267B39; Thu, 20 Dec 2018 00:46:56 +0100 (CET) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by alsa0.perex.cz (Postfix) with ESMTP id 5480E267A8E; Thu, 20 Dec 2018 00:46:53 +0100 (CET) Received: by mail-pg1-f193.google.com with SMTP id v28so10150627pgk.10; Wed, 19 Dec 2018 15:46:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:from:to:cc:subject:date:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=X/eOs0tDe+kHzgoA7kwY4KDhAdScmcgX1aceCIH48N4=; b=i+j1/lw+Wwr0H2byB6RGi5lb1TNi+A9BsSAd0XV0iTJJX5XBhqjOeevTNqMf6RGVM/ XoAXWFjJPs11eWGEkFCUW9yjJs89wf3PeQ32OWnKEtfbpElt/qunCylSG1Sa5WMEF8GL F2Bz3Fih5YfvIeHPF297/4u54pItcSyVlnahhhy6s1zX4GoakB9yZ7Yo6YyWWjbMAUHc k0pjsIyTc2MdpOBBRdCfKiFSAMOoDlbOfxf1qXFzTYaHfNayE9OoovGrhmddI8GA2clM aaVh72OwDnB0kIdUyHCpn1yF/BJmakOefEg3taop/ZLr0hgpQ0gKztbQ4Rn5UcdsgWm4 ug/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:from:to:cc:subject:date:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=X/eOs0tDe+kHzgoA7kwY4KDhAdScmcgX1aceCIH48N4=; b=Hmu/xpg288VUPJSyKV4p7+M2D9JuRnkPguzgmN9nHBcJNHW7iynybSzj1AxQeWDjBC 8yjHjldux7ydrVv+1CRqEdke+GJKvdyyjkBblZqrc6U6ROo6FeTUPdhl3vmIW0JXnbZ8 g1B/fj65F/pmHhDI9MKwwNaKAej5xKXIIZCYMby2iyGqrUwwOo0T+Kn6PpPuDeOSosUm of4Vj+Q8BSxh9SgY0W2Qxo4c90w/tQrmirbw+PTnzQpyrg6+zgTaLRTOVLu+tf3byxQ/ vYV/CPmuj7D8WoxAQvsjUy1Ok2Emau43u4RqgMEG4eAbx3iBSBuN/L/5AQKPxi9u0oe/ cK/g== X-Gm-Message-State: AA+aEWYPTjQ7noprUwWVj8nZcufdaFAYh/t3R76ujMvE4VkLM71gWrRf CktFU1bacRGdchoh8gux7P5hJcwjwKM= X-Google-Smtp-Source: AFSGD/W7cxPG2SQPhmnvzWEaBgqRd0jySvYjhjIOYyFX5m9NcBL/CotLhdWSUnybob+KgBT3H0oiGA== X-Received: by 2002:a62:5b83:: with SMTP id p125mr22588939pfb.116.1545263211757; Wed, 19 Dec 2018 15:46:51 -0800 (PST) Received: from localhost.localdomain (123202047155.ctinets.com. [123.202.47.155]) by smtp.gmail.com with ESMTPSA id y29sm27452346pga.59.2018.12.19.15.46.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 15:46:51 -0800 (PST) Message-ID: <5c1ad86b.1c69fb81.a05a6.7bf3@mx.google.com> X-Google-Original-Message-ID: <20181219234551.8244-1-me> From: tom.ty89@gmail.com X-Google-Original-From: me To: patch@alsa-project.org Date: Thu, 20 Dec 2018 07:45:51 +0800 X-Mailer: git-send-email 2.20.1 In-Reply-To: <0381895c-579e-8403-55e6-bff575957025@ladisch.de> References: <0381895c-579e-8403-55e6-bff575957025@ladisch.de> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, Tom Yan Subject: [alsa-devel] [PATCH 1/1] ALSA: virtuoso: add de-emphasis control X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: clemens@ladisch.de 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 From: Tom Yan Add control for the de-emphasis filter in the PCM179x DACs Signed-off-by: Tom Yan diff --git a/sound/pci/oxygen/pcm1796.h b/sound/pci/oxygen/pcm1796.h index 34d07dd2d22e..d5dcb09e44cd 100644 --- a/sound/pci/oxygen/pcm1796.h +++ b/sound/pci/oxygen/pcm1796.h @@ -10,7 +10,6 @@ #define PCM1796_MUTE 0x01 #define PCM1796_DME 0x02 #define PCM1796_DMF_MASK 0x0c -#define PCM1796_DMF_DISABLED 0x00 #define PCM1796_DMF_48 0x04 #define PCM1796_DMF_441 0x08 #define PCM1796_DMF_32 0x0c diff --git a/sound/pci/oxygen/xonar_pcm179x.c b/sound/pci/oxygen/xonar_pcm179x.c index 24109d37ca09..a1c6b98b191e 100644 --- a/sound/pci/oxygen/xonar_pcm179x.c +++ b/sound/pci/oxygen/xonar_pcm179x.c @@ -331,7 +331,7 @@ static void pcm1796_init(struct oxygen *chip) struct xonar_pcm179x *data = chip->model_data; data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = - PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD; + PCM1796_FMT_24_I2S | PCM1796_ATLD; if (!data->broken_i2c) data->pcm1796_regs[0][18 - PCM1796_REG_BASE] |= PCM1796_MUTE; data->pcm1796_regs[0][19 - PCM1796_REG_BASE] = @@ -621,6 +621,23 @@ static void update_pcm1796_oversampling(struct oxygen *chip) pcm1796_write_cached(chip, i, 20, reg); } +static void update_pcm1796_deemph(struct oxygen *chip) +{ + struct xonar_pcm179x *data = chip->model_data; + unsigned int i; + u8 reg; + + reg = data->pcm1796_regs[0][18 - PCM1796_REG_BASE] & ~PCM1796_DMF_MASK; + if (data->current_rate == 48000) + reg |= PCM1796_DMF_48; + else if (data->current_rate == 44100) + reg |= PCM1796_DMF_441; + else if (data->current_rate == 32000) + reg |= PCM1796_DMF_32; + for (i = 0; i < data->dacs; ++i) + pcm1796_write_cached(chip, i, 18, reg); +} + static void set_pcm1796_params(struct oxygen *chip, struct snd_pcm_hw_params *params) { @@ -629,6 +646,7 @@ static void set_pcm1796_params(struct oxygen *chip, msleep(1); data->current_rate = params_rate(params); update_pcm1796_oversampling(chip); + update_pcm1796_deemph(chip); } static void update_pcm1796_volume(struct oxygen *chip) @@ -653,9 +671,11 @@ static void update_pcm1796_mute(struct oxygen *chip) unsigned int i; u8 value; - value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD; + value = data->pcm1796_regs[0][18 - PCM1796_REG_BASE]; if (chip->dac_mute) value |= PCM1796_MUTE; + else + value &= ~PCM1796_MUTE; for (i = 0; i < data->dacs; ++i) pcm1796_write_cached(chip, i, 18, value); } @@ -777,6 +797,49 @@ static const struct snd_kcontrol_new rolloff_control = { .put = rolloff_put, }; +static int deemph_get(struct snd_kcontrol *ctl, + struct snd_ctl_elem_value *value) +{ + struct oxygen *chip = ctl->private_data; + struct xonar_pcm179x *data = chip->model_data; + + value->value.integer.value[0] = + !!(data->pcm1796_regs[0][18 - PCM1796_REG_BASE] & PCM1796_DME); + return 0; +} + +static int deemph_put(struct snd_kcontrol *ctl, + struct snd_ctl_elem_value *value) +{ + struct oxygen *chip = ctl->private_data; + struct xonar_pcm179x *data = chip->model_data; + unsigned int i; + int changed; + u8 reg; + + mutex_lock(&chip->mutex); + reg = data->pcm1796_regs[0][18 - PCM1796_REG_BASE]; + if (!value->value.integer.value[0]) + reg &= ~PCM1796_DME; + else + reg |= PCM1796_DME; + changed = reg != data->pcm1796_regs[0][18 - PCM1796_REG_BASE]; + if (changed) { + for (i = 0; i < data->dacs; ++i) + pcm1796_write(chip, i, 18, reg); + } + mutex_unlock(&chip->mutex); + return changed; +} + +static const struct snd_kcontrol_new deemph_control = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "De-emphasis Playback Switch", + .info = snd_ctl_boolean_mono_info, + .get = deemph_get, + .put = deemph_put, +}; + static const struct snd_kcontrol_new hdav_hdmi_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "HDMI Playback Switch", @@ -1011,6 +1074,10 @@ static int add_pcm1796_controls(struct oxygen *chip) snd_ctl_new1(&rolloff_control, chip)); if (err < 0) return err; + err = snd_ctl_add(chip->card, + snd_ctl_new1(&deemph_control, chip)); + if (err < 0) + return err; } return 0; }