Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1183408pxk; Thu, 10 Sep 2020 09:00:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeq1eGb93B1m7AfIizxYgVzGGJIHVTHjiT7GiKUlAcwCdeGlnqeHzst9CZ93zOl/LeD3Uf X-Received: by 2002:aa7:dc16:: with SMTP id b22mr9879604edu.252.1599753626933; Thu, 10 Sep 2020 09:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599753626; cv=none; d=google.com; s=arc-20160816; b=LYsIPTNZQ555mwPgf24IKBKxKWRfBHZrjN8Lq/EYGHWsftzDf2iID/8PYoUKmTX0Sx UWV8aCSeXGb5SV8RLLzLXOCqV/3ykA7SW64nW3/0BTRGcPe41guUfvM32KXT8hh2ccnl DDZq4ewvRaXQcrQjUfhVWD9JH+DWeJ+V8sUgG3aPWjI0TW87ykRPthDQYiD30k0pll89 0NG9F6ayspJl3S80m2EVE9+IGjNVEGrJFBJrva5E0/A2oOPfyuFIRw4++XzXg0QEseaL M5Vqwrp7C9NgVF49/g0I3C8O6o+IRo6LwA+GrLd2WEqqO0chLdOvwlsDHGxO6Ns9wHgE bnGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=fXxlnm6mzZkdPNyQX2gzT9535bgLY4RyP7V7YRZOFEU=; b=V2F9avIHBOdbZPDx8/nTpf1RaZLKNygpe2HsWXSPuqlSIuQtZ5AIFVl+bJNN3z9nQP Y0SUvbTeiX/xAUcc8rSxxrTZ1g6Q2YLzJ4sTFi+xaIFi2Ok7+Qu4QskS9jAqPQ9V6Xx3 sHy6A3VWT7eBJliqnfPGV/o/3XA3Kq9sNmImYT2EC8rjMql15rR5QADhMTNZmkEyQF/P ++0na6/wHxo9gxqna3bUJ6RV6r9tHVDt4ll4YKQKRH+cUE7cU/jVVL+KbWVszl7hfkDn gQcZwhDNuZUMB1gY0TVzv3PeE9Nc0elO9h2Bt3T+zIZjVcC1KGbNwa86xLpyMWMhB2P/ lKGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=D478FXgW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si3690260edi.512.2020.09.10.09.00.03; Thu, 10 Sep 2020 09:00:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=D478FXgW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731451AbgIJP6u (ORCPT + 99 others); Thu, 10 Sep 2020 11:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731442AbgIJP5k (ORCPT ); Thu, 10 Sep 2020 11:57:40 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0334BC061757 for ; Thu, 10 Sep 2020 08:57:40 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id a15so8902154ljk.2 for ; Thu, 10 Sep 2020 08:57:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=fXxlnm6mzZkdPNyQX2gzT9535bgLY4RyP7V7YRZOFEU=; b=D478FXgW9K+R8hcKL9eH1QRG9D62zukErZ9Iu4D4TFLwDUCvtU/YO98qIh0FlU/LUr s+grxASJc2NesL23S3XIzq21tSkHX5xEIZmt+RtBx5H/ju4kmcykC9dTxGmtCl+Bk90A Fxae/aR34Hgn767VBY3XezCiGJxLBTZO5fLB1/09JZX8+OQcAXC5V9ZVTPnJCLzvvauv soD6gaHGKY6mnQzHeL4fMtCRNcmlDZE7At25OU5vxBRIsEtl032/pXx0ZEd1tybGtUMI am8Rb9K9hTP1QQt1Jn+RkWcgAeRX5k6w9NygDwDapGp2n/0aY4OwotjYbq6HQDLfuYGe GDog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=fXxlnm6mzZkdPNyQX2gzT9535bgLY4RyP7V7YRZOFEU=; b=j7h6fyipuIifPsJs6AxTYnGnYeujsxue+mfMweYJ7oQG/31UQabKgS8RHvk5nBeysc GGn4Cx4t6EZcIajBwCKmXP7pPLOG6G5HoeAbAHu1hLbtZ6VUk0l+CoA75En1eIYx9buJ HKsFCsc1z1IdvjjHbOFRmtPUYZS9XXhNBlZMjbVdZIZZEzp+FY/UNbTlCNHEfsybha7a mrjVLgjE93bfs8icCBGXmvJ6AgC5wkH35mKY6i1dxM0EYiRs7qx8v0nEsQAb1a1zIzSe +QoXsLmLXDHMF9i16azQII4mBzxgRq4MNQedc51kv8Rw03yxnqIrB8lXZ4FHkK4xLe9a +r3w== X-Gm-Message-State: AOAM5312KFRgDHkSrQtQOfFIgDuESsRyKNG8X34LPg9ICJBDwLY+f84N Jn4fWwVjP52h/OhpRYz4IFTjPA== X-Received: by 2002:a2e:800e:: with SMTP id j14mr4742770ljg.145.1599753458323; Thu, 10 Sep 2020 08:57:38 -0700 (PDT) Received: from rad-H81M-S1.semihalf.local (193-106-246-138.noc.fibertech.net.pl. [193.106.246.138]) by smtp.gmail.com with ESMTPSA id k14sm1445494lfm.90.2020.09.10.08.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 08:57:37 -0700 (PDT) From: Radoslaw Biernacki To: Pierre-Louis Bossart , Liam Girdwood , Jie Yang , Jaroslav Kysela , Takashi Iwai Cc: Ben Zhang , Marcin Wojtas , Todd Broch , Alex Levin , Vamshi Krishna , Harshapriya , michal.sienkiewicz@intel.com, Lech Betlej , Radoslaw Biernacki , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, John Hsu , Yong Zhi , Mac Chiang Subject: [PATCH V5] ASoC: Intel: boards: Use FS as nau8825 sysclk in nau88125_* machine Date: Thu, 10 Sep 2020 17:57:34 +0200 Message-Id: <20200910155734.31101-1-rad@semihalf.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since 256xFS clocks cannot be generated by SKL, the NAU8825 is configured to re-generate its system clock from the BCLK using the FLL. The link is configured to use a 48kHz frame rate, and 24 bits in 25-bit slot. The SSP configuration is extracted from NHLT settings and not dynamically changed. Listening tests and measurements do not show any distortion or issues Signed-off-by: John Hsu Signed-off-by: Yong Zhi Signed-off-by: Mac Chiang Signed-off-by: Ben Zhang Signed-off-by: Radoslaw Biernacki --- Notes: v1 -> v2: - adding same changes to skl_nau88l25_max98357a.c v2 -> v3: - removing msleep() in SNDRV_PCM_TRIGGER_RESUME as it unnecessarily increase playback/capture latency while actually FLL does not require it. - simplifing commit message v3 -> v4: - simplifing the PM resume callback code for setting the FLL - adding comment for the stream START/RESUME sequence which prevent audio pops - fixing mising var initialization in platform_clock_control() V4 -> V5: - removed stray change ~ SSP0 ops .../soc/intel/boards/skl_nau88l25_max98357a.c | 63 ++++++++++++------ sound/soc/intel/boards/skl_nau88l25_ssm4567.c | 64 +++++++++++++------ 2 files changed, 85 insertions(+), 42 deletions(-) diff --git a/sound/soc/intel/boards/skl_nau88l25_max98357a.c b/sound/soc/intel/boards/skl_nau88l25_max98357a.c index d7b8154c43a4..2f0abbd2dd8d 100644 --- a/sound/soc/intel/boards/skl_nau88l25_max98357a.c +++ b/sound/soc/intel/boards/skl_nau88l25_max98357a.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -47,12 +48,12 @@ enum { }; static int platform_clock_control(struct snd_soc_dapm_widget *w, - struct snd_kcontrol *k, int event) + struct snd_kcontrol *k, int event) { struct snd_soc_dapm_context *dapm = w->dapm; struct snd_soc_card *card = dapm->card; struct snd_soc_dai *codec_dai; - int ret; + int ret = 0; codec_dai = snd_soc_card_get_codec_dai(card, SKL_NUVOTON_CODEC_DAI); if (!codec_dai) { @@ -60,14 +61,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, return -EIO; } - if (SND_SOC_DAPM_EVENT_ON(event)) { - ret = snd_soc_dai_set_sysclk(codec_dai, - NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN); - if (ret < 0) { - dev_err(card->dev, "set sysclk err = %d\n", ret); - return -EIO; - } - } else { + if (!SND_SOC_DAPM_EVENT_ON(event)) { ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN); if (ret < 0) { @@ -292,24 +286,51 @@ static const struct snd_soc_ops skylake_nau8825_fe_ops = { .startup = skl_fe_startup, }; -static int skylake_nau8825_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *params) +static int skylake_nau8825_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); - int ret; - - ret = snd_soc_dai_set_sysclk(codec_dai, - NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN); - - if (ret < 0) - dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret); + int ret = 0; + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + /* Since 256xFS clocks cannot be generated by SKL, the NAU8825 + * is configured to re-generate its system clock from the BCLK + * using the FLL. + * We must switch system clock (FLL to use BCLK) here as it is + * not given eariler by FW (like in hw_param). We let nau8825 to + * use internal VCO clock till now which reduces the audiable + * pop's. */ + + /* fall through */ + + case SNDRV_PCM_TRIGGER_RESUME: + /* Once device resumes, the system will only enable power + * sequence for playback without doing hardware parameter, audio + * format, and PLL configure. In the mean time, the jack + * detecion sequence has changed PLL parameters and switched to + * internal clock. Thus, the playback signal distorted without + * correct PLL parameters. Therefore we need to configure PLL + * again */ + ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_FS, 0, + SND_SOC_CLOCK_IN); + if (ret < 0) { + dev_err(codec_dai->dev, "can't set FS clock %d\n", ret); + break; + } + ret = snd_soc_dai_set_pll(codec_dai, 0, 0, runtime->rate, + runtime->rate * 256); + if (ret < 0) + dev_err(codec_dai->dev, "can't set FLL: %d\n", ret); + break; + } return ret; } -static const struct snd_soc_ops skylake_nau8825_ops = { - .hw_params = skylake_nau8825_hw_params, +static struct snd_soc_ops skylake_nau8825_ops = { + .trigger = skylake_nau8825_trigger, }; static int skylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd, diff --git a/sound/soc/intel/boards/skl_nau88l25_ssm4567.c b/sound/soc/intel/boards/skl_nau88l25_ssm4567.c index 4b317bcf6ea0..6791be63c866 100644 --- a/sound/soc/intel/boards/skl_nau88l25_ssm4567.c +++ b/sound/soc/intel/boards/skl_nau88l25_ssm4567.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -57,12 +58,12 @@ static const struct snd_kcontrol_new skylake_controls[] = { }; static int platform_clock_control(struct snd_soc_dapm_widget *w, - struct snd_kcontrol *k, int event) + struct snd_kcontrol *k, int event) { struct snd_soc_dapm_context *dapm = w->dapm; struct snd_soc_card *card = dapm->card; struct snd_soc_dai *codec_dai; - int ret; + int ret = 0; codec_dai = snd_soc_card_get_codec_dai(card, SKL_NUVOTON_CODEC_DAI); if (!codec_dai) { @@ -70,14 +71,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, return -EIO; } - if (SND_SOC_DAPM_EVENT_ON(event)) { - ret = snd_soc_dai_set_sysclk(codec_dai, - NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN); - if (ret < 0) { - dev_err(card->dev, "set sysclk err = %d\n", ret); - return -EIO; - } - } else { + if (!SND_SOC_DAPM_EVENT_ON(event)) { ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN); if (ret < 0) { @@ -85,6 +79,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, return -EIO; } } + return ret; } @@ -344,24 +339,51 @@ static int skylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd, return 0; } -static int skylake_nau8825_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *params) +static int skylake_nau8825_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); - int ret; - - ret = snd_soc_dai_set_sysclk(codec_dai, - NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN); - - if (ret < 0) - dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret); + int ret = 0; + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + /* Since 256xFS clocks cannot be generated by SKL, the NAU8825 + * is configured to re-generate its system clock from the BCLK + * using the FLL. + * We must switch system clock (FLL to use BCLK) here as it is + * not given eariler by FW (like in hw_param). We let nau8825 to + * use internal VCO clock till now which reduces the audiable + * pop's. */ + + /* fall through */ + + case SNDRV_PCM_TRIGGER_RESUME: + /* Once device resumes, the system will only enable power + * sequence for playback without doing hardware parameter, audio + * format, and PLL configure. In the mean time, the jack + * detecion sequence has changed PLL parameters and switched to + * internal clock. Thus, the playback signal distorted without + * correct PLL parameters. Therefore we need to configure PLL + * again */ + ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_FS, 0, + SND_SOC_CLOCK_IN); + if (ret < 0) { + dev_err(codec_dai->dev, "can't set FS clock %d\n", ret); + break; + } + ret = snd_soc_dai_set_pll(codec_dai, 0, 0, runtime->rate, + runtime->rate * 256); + if (ret < 0) + dev_err(codec_dai->dev, "can't set FLL: %d\n", ret); + break; + } return ret; } -static const struct snd_soc_ops skylake_nau8825_ops = { - .hw_params = skylake_nau8825_hw_params, +static struct snd_soc_ops skylake_nau8825_ops = { + .trigger = skylake_nau8825_trigger, }; static const unsigned int channels_dmic[] = { -- 2.17.1