Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4189951pxk; Tue, 8 Sep 2020 13:04:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeel2ErrIXaeRVbD29Ol+h8+zxTlHPh4nLdc4QovMA67B50GRhBnHP9M1nvaka7zMoPiw7 X-Received: by 2002:a17:907:2105:: with SMTP id qn5mr142689ejb.238.1599595465502; Tue, 08 Sep 2020 13:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599595465; cv=none; d=google.com; s=arc-20160816; b=yEkFMr85/V4D6S2XxWVNGKYuRp/pgayxhIrHCGTSRwPA3kIR5Au66LMBIkt2fLRJJi VwLTpiRQ0Ai2G5oFU50j4/PGq5iVt+acMmwOH45IT7baJ6ser8Wl9J2YjL+J6nvC+sJa FKM4b8oEOwr7crK09tQXB3CmvVH7oFFJaBlvTjUTXTrrfYb69DliyBK6Wu1r+blQ77+g syrpdRdDaPSqY1AEsQ1ndGRx9n/LHFCrW6HfyDGvfA+i+QhDE0T2G4qS8V65AeAGWo80 b4rtPHyj4mQTg7jzemMubi1p76No+rRYIJftXmypgrCvMc3BMWLAyoU4KMcV1Aq/nS7F fIvw== 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=jzVNvMdkmIaUsZ7x+JjELSUeNQhOKHrsly0M9gLXpdM=; b=TmPf38c8djrRzV2GA5/OiknyXUTjXzlDE6oRYXsZzUXxSHVThFsiG08k2T6QZwTHCv depBBCdjL/8davtro13e05pohHUhRBjWaAFX+L9STlNJWanrKxAs8/9o6ZpC5Px2KiOM wNRmob2gSH7IpQKL/fiSwKY3zL6xi7VNFfbL22S9c9vKGfcwXU6ceMp4bR0nNMVpGMA9 PixscTannvKYgt5lLYyOkPvnovqEN9ZXZtUXtyvfY1m7AK3zxyibJpGPN29eWQarU+SE +UiYkke5iiW0HIMCgWv+30dEJ/eVVN1WldDeA5RAks/nvgKb9FoMVNUWLOk/DV4C8Cgd USOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=ahmixS3N; 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 sa19si35177ejb.506.2020.09.08.13.04.02; Tue, 08 Sep 2020 13:04:25 -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=ahmixS3N; 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 S1730984AbgIHUDa (ORCPT + 99 others); Tue, 8 Sep 2020 16:03:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbgIHUDU (ORCPT ); Tue, 8 Sep 2020 16:03:20 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B858C061573 for ; Tue, 8 Sep 2020 13:03:19 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id v23so544985ljd.1 for ; Tue, 08 Sep 2020 13:03:19 -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=jzVNvMdkmIaUsZ7x+JjELSUeNQhOKHrsly0M9gLXpdM=; b=ahmixS3N+X/i3O8WKjTcnPnFsLBqx7VJEkf8zXHgRxatUbO+TEtkUPe2PR87WdGxe8 zQyD84XLJ2xj8S0hpl4tPTcwlPQbm5Eik2mAt0FfnYjTd9/TddmWkCbcSDEyrWI3loYD UrBg8z2bHSsFGFoyX7gH9j6Eamihifqu1Rw2pYLshzyMEkKXSO1H9aC5Z2onYhoPqtvV BNUEGSMFRWn2/o7rjddFU2sHIFyvqY/mA5VQ5u3txpr8TbdFL9R9CE0bZUgpRBeCVJ/J N+ThhRm1d2RljFLnRCJu8dnoWj31B8HEeXuCV6TO0XSuYJIKufD76Lc5AsTjdA8V6yCK njwA== 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=jzVNvMdkmIaUsZ7x+JjELSUeNQhOKHrsly0M9gLXpdM=; b=LQbOrEH4dhLWCIiYrXanNWs7IFW+1OpumBnMvNQvyNHIjI03WXQeF1z7bnCADYcSGB 2iae2EYnRn2FdBZL3pP2EZi8gwWhvjwwTOtdXdh8Dg+G883DazgSGqjuDkPFSD2vZIKq XbnpZZ2uUhEDD7Xn2/eYQW99S8QfFI+xBOot4A2QrNhSFvR15ERzRDpS9tu5tRsYSJah i4+h0zI0EDYiVJpcNqsrMHm/jZk/GQmAtGr9/aS2Dj4oiV80d4ma3hs6VBdQmIJpyK4v AqS1cKhr7YsbGCVe6hfWJu2UWL8k2cSfx8x6Pq7BDBR17bJQh0A3mbbwoOf6UEpHz8aT odbw== X-Gm-Message-State: AOAM533wCA2d6rBPWfmFZdWWpTggjGMUBJlS3GR8kowhK9HsxhyEqAQN GJGH3Nnuv+ROFNxkZ/fnilgYpg== X-Received: by 2002:a2e:5c5:: with SMTP id 188mr80229ljf.375.1599595397984; Tue, 08 Sep 2020 13:03:17 -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 c17sm115715lfs.62.2020.09.08.13.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 13:03:17 -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 V3] ASoC: Intel: boards: Use FS as nau8825 sysclk in nau88125_* machine Date: Tue, 8 Sep 2020 22:03:14 +0200 Message-Id: <20200908200314.22771-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 .../soc/intel/boards/skl_nau88l25_max98357a.c | 71 +++++++++++++----- sound/soc/intel/boards/skl_nau88l25_ssm4567.c | 72 ++++++++++++++----- 2 files changed, 105 insertions(+), 38 deletions(-) diff --git a/sound/soc/intel/boards/skl_nau88l25_max98357a.c b/sound/soc/intel/boards/skl_nau88l25_max98357a.c index d7b8154c43a4..75976aad0366 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,7 +48,7 @@ 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; @@ -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,39 @@ 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); + int ret = 0; - if (ret < 0) - dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret); + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + 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; + case SNDRV_PCM_TRIGGER_RESUME: + 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, @@ -630,10 +639,34 @@ static int skylake_card_late_probe(struct snd_soc_card *card) return hdac_hdmi_jack_port_init(component, &card->dapm); } +static int __maybe_unused skylake_nau8825_resume_post(struct snd_soc_card *card) +{ + struct snd_soc_dai *codec_dai; + + codec_dai = snd_soc_card_get_codec_dai(card, SKL_NUVOTON_CODEC_DAI); + if (!codec_dai) { + dev_err(card->dev, "Codec dai not found\n"); + return -EIO; + } + + dev_dbg(codec_dai->dev, "playback_active:%d playback_widget->active:%d codec_dai->rate:%d\n", + codec_dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK], + codec_dai->playback_widget->active, + codec_dai->rate); + + if (codec_dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK] && + codec_dai->playback_widget->active) + snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_FS, 0, + SND_SOC_CLOCK_IN); + + return 0; +} + /* skylake audio machine driver for SPT + NAU88L25 */ static struct snd_soc_card skylake_audio_card = { .name = "sklnau8825max", .owner = THIS_MODULE, + .resume_post = skylake_nau8825_resume_post, .dai_link = skylake_dais, .num_links = ARRAY_SIZE(skylake_dais), .controls = skylake_controls, diff --git a/sound/soc/intel/boards/skl_nau88l25_ssm4567.c b/sound/soc/intel/boards/skl_nau88l25_ssm4567.c index 4b317bcf6ea0..09f090ba7fec 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,7 +58,7 @@ 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; @@ -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,39 @@ 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); + int ret = 0; - if (ret < 0) - dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret); + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + 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; + case SNDRV_PCM_TRIGGER_RESUME: + 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[] = { @@ -671,10 +681,34 @@ static int skylake_card_late_probe(struct snd_soc_card *card) return hdac_hdmi_jack_port_init(component, &card->dapm); } +static int __maybe_unused skylake_nau8825_resume_post(struct snd_soc_card *card) +{ + struct snd_soc_dai *codec_dai; + + codec_dai = snd_soc_card_get_codec_dai(card, SKL_NUVOTON_CODEC_DAI); + if (!codec_dai) { + dev_err(card->dev, "Codec dai not found\n"); + return -EIO; + } + + dev_dbg(codec_dai->dev, "playback_active:%d playback_widget->active:%d codec_dai->rate:%d\n", + codec_dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK], + codec_dai->playback_widget->active, + codec_dai->rate); + + if (codec_dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK] && + codec_dai->playback_widget->active) + snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_FS, 0, + SND_SOC_CLOCK_IN); + + return 0; +} + /* skylake audio machine driver for SPT + NAU88L25 */ static struct snd_soc_card skylake_audio_card = { .name = "sklnau8825adi", .owner = THIS_MODULE, + .resume_post = skylake_nau8825_resume_post, .dai_link = skylake_dais, .num_links = ARRAY_SIZE(skylake_dais), .controls = skylake_controls, -- 2.17.1