Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1663220ybx; Thu, 7 Nov 2019 15:17:24 -0800 (PST) X-Google-Smtp-Source: APXvYqyf65nxsLxVdFDKNptmx4eDpTAnaqdU26YiR+uynaDC+9N6cQGUkYFZZH6wnNG8MeMcNZ7h X-Received: by 2002:a17:906:751:: with SMTP id z17mr5594069ejb.313.1573168644200; Thu, 07 Nov 2019 15:17:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573168644; cv=none; d=google.com; s=arc-20160816; b=lDtj+smve6gNd2MX2Wajqdulmw8C9Q0sagonsuWUA4EX6bG1Ht5x1N+zcDcYHAsN66 XiboluPIgBHs7mXDGxr1JFschtzo1LDNANnREqwV/P7sGnT3B5JWk3K4BZZQY/3QIMJU NOpKDX2DfbeGBv4fM4jheIahHru6VtD+VjqlvkAzk1wCCB+f+OAL+5EeFCNvZo8/BPu4 W0MjA8tsGCXGmdEshWx8tAUa0Wo6pZtQcK059h5wnyN3h7LdTiZjGfu75iXRiPhcSzaZ sJtJxNeUvZ/nLDnGH3wM1Q2YMQv8UmIxUrCxQn/FkM48u3eUfbztyXXIOwgdqKspMHg2 GPKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3QkA7fpgg84g1/OjnwpVpOMBMUXMQKKIxrO3kIEdhKM=; b=Nxy6YGH28rGEPuRz7objdIjcMTPrT4S+yFLLRB0YajEvJ8PDh6LIe+s3nluhRRyIO2 ZCDcx33qTkY2rS2ByQ6ynOxn+Kb5nTyZrWi5eWXaS3Um4RfNCdF8JZBXQo7YgKgzMo50 nIG+vOFddUTncFK8a4uSJX+mKMbBJmAZGkOXIsSmiz8n23Pv+1lwob3NSf/kzB86It0x 65+qvvL3qyGt7OJGfo67Q93MINR9rzHrUsImWHZQgRZbvQ2f1T6f9F8aKy7j/noq9htQ AORrUDLs+HlNSAPOGbkpBzxtNyhk8LkKIHdsRwJ1cvd7LO1SQ55Z7GQ5zZd5CaWgB6HR DBVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=jrvjIlQw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k11si2479609ejv.152.2019.11.07.15.17.00; Thu, 07 Nov 2019 15:17:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=jrvjIlQw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727606AbfKGXQU (ORCPT + 99 others); Thu, 7 Nov 2019 18:16:20 -0500 Received: from ssl.serverraum.org ([176.9.125.105]:45281 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbfKGXQU (ORCPT ); Thu, 7 Nov 2019 18:16:20 -0500 Received: from apollo.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:6257:18ff:fec4:ca34]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 1652E23E23; Fri, 8 Nov 2019 00:16:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1573168576; bh=3QkA7fpgg84g1/OjnwpVpOMBMUXMQKKIxrO3kIEdhKM=; h=From:To:Cc:Subject:Date:From; b=jrvjIlQwgiKG2vNPYy4NoV61k6XP/VM39t578SoTDO4Rut4Zns+IhCirGvlk7yYk7 k05I346rQTqeApSM1RWfhkwf1aqE11kx0naQKHf6LBoo9XJ4kx5s6qIjn4gtkByCxv 9+AKh23qR8Xk5j2J/64s8D+vwcnN3+mCT/Vc0Q0c= From: Michael Walle To: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Cc: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , patches@opensource.cirrus.com, Michael Walle Subject: [PATCH] ASoC: wm8904: configure sysclk/FLL automatically Date: Fri, 8 Nov 2019 00:15:48 +0100 Message-Id: <20191107231548.17454-1-michael@walle.cc> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: clamav-milter 0.101.4 at web X-Virus-Status: Clean Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds a new mode WM8904_CLK_AUTO which automatically enables the FLL if a frequency different than the MCLK is set. These additions make the codec work with the simple-card driver in general and especially in systems where the MCLK doesn't match the requested clock. Signed-off-by: Michael Walle --- Unfortunately, I had to move wm8904_sys_sysclk() below wm8904_set_fll(). So that makes this patch a bit ugly. The added part is the WM8904_CLK_AUTO branch. sound/soc/codecs/wm8904.c | 72 ++++++++++++++++++++++++--------------- sound/soc/codecs/wm8904.h | 1 + 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c index bcb3c9d5abf0..2dd7addfd1a8 100644 --- a/sound/soc/codecs/wm8904.c +++ b/sound/soc/codecs/wm8904.c @@ -1410,34 +1410,6 @@ static int wm8904_hw_params(struct snd_pcm_substream *substream, return 0; } - -static int wm8904_set_sysclk(struct snd_soc_dai *dai, int clk_id, - unsigned int freq, int dir) -{ - struct snd_soc_component *component = dai->component; - struct wm8904_priv *priv = snd_soc_component_get_drvdata(component); - - switch (clk_id) { - case WM8904_CLK_MCLK: - priv->sysclk_src = clk_id; - priv->mclk_rate = freq; - break; - - case WM8904_CLK_FLL: - priv->sysclk_src = clk_id; - break; - - default: - return -EINVAL; - } - - dev_dbg(dai->dev, "Clock source is %d at %uHz\n", clk_id, freq); - - wm8904_configure_clocking(component); - - return 0; -} - static int wm8904_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) { struct snd_soc_component *component = dai->component; @@ -1824,6 +1796,50 @@ static int wm8904_set_fll(struct snd_soc_dai *dai, int fll_id, int source, return 0; } +static int wm8904_set_sysclk(struct snd_soc_dai *dai, int clk_id, + unsigned int freq, int dir) +{ + struct snd_soc_component *component = dai->component; + struct wm8904_priv *priv = snd_soc_component_get_drvdata(component); + unsigned long mclk_freq; + int ret; + + switch (clk_id) { + case WM8904_CLK_AUTO: + mclk_freq = clk_get_rate(priv->mclk); + /* enable FLL if a different sysclk is desired */ + if (mclk_freq != freq) { + priv->sysclk_src = WM8904_CLK_FLL; + ret = wm8904_set_fll(dai, WM8904_FLL_MCLK, + WM8904_FLL_MCLK, + clk_get_rate(priv->mclk), freq); + if (ret) + return ret; + break; + } + clk_id = WM8904_CLK_MCLK; + /* fallthrough */ + + case WM8904_CLK_MCLK: + priv->sysclk_src = clk_id; + priv->mclk_rate = freq; + break; + + case WM8904_CLK_FLL: + priv->sysclk_src = clk_id; + break; + + default: + return -EINVAL; + } + + dev_dbg(dai->dev, "Clock source is %d at %uHz\n", clk_id, freq); + + wm8904_configure_clocking(component); + + return 0; +} + static int wm8904_digital_mute(struct snd_soc_dai *codec_dai, int mute) { struct snd_soc_component *component = codec_dai->component; diff --git a/sound/soc/codecs/wm8904.h b/sound/soc/codecs/wm8904.h index c1bca52f9927..de6340446b1f 100644 --- a/sound/soc/codecs/wm8904.h +++ b/sound/soc/codecs/wm8904.h @@ -10,6 +10,7 @@ #ifndef _WM8904_H #define _WM8904_H +#define WM8904_CLK_AUTO 0 #define WM8904_CLK_MCLK 1 #define WM8904_CLK_FLL 2 -- 2.20.1