Received: by 2002:a05:7208:c250:b0:86:f851:443 with SMTP id w16csp939621rbd; Thu, 13 Jun 2024 01:49:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWvBUKb5I17MEzO/mE7r4IYF0l6SYVFLTw11BI8MNLrvARKfsE9ABOXyA93xqkRNHuIFboHB92uoR3nWYR5UVfY6We+Sa5192/lvrH4HQ== X-Google-Smtp-Source: AGHT+IHAauTniuIgbZWDLNQhJs0aEUdtPSV2/6DPTQNzX3BnXmO6UcV8fqvqUPvUGSD9/7q/lGs/ X-Received: by 2002:a17:90b:1c82:b0:2c4:aa69:26c5 with SMTP id 98e67ed59e1d1-2c4aa6927e4mr3733988a91.28.1718268553661; Thu, 13 Jun 2024 01:49:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718268553; cv=pass; d=google.com; s=arc-20160816; b=p17NbZ8nZ3LOuQmKGaZUAUwB3D1Ft78HtM9AloJzH7PD/FDdy5TqkqoqHJJ4t3FLmz mos2jW02roY+kFvf64tlrvhM9AogdNlSEbATVrigf4eIFf7Wo3TaHE2IhiPBQzUErUOZ Qu4Dre9p2366bngTONgkQHW4Z4q8eGZ2m2BvOC4cA6NGLeZ3QcdbzRJtBX1V5qyWgamh WFgqVbK9QfSu1O5V7sL8IB0AMTznzowa1u0hI3lxu5WOsjaYuxOznDgpmdhAJfKnJNXy gWDBr+3sW6ju5VJNAua4E3XNULKsx5qaScrwohvy6FaSxDRialcg7p3o74mjXfD9gFgA Js+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=4CEwTUZlBDBOuLF/YpPCjybp6G8vWfidbX5dtN7b7RA=; fh=QkPjM1ojHd8DJ/d4zuHXTroR4dKQTTKNFCIb7VaFacs=; b=Bn34Q80YoDgx/m/dVw31FBQbfTmFlafMlTiB7UEZxItowyda6HpKSWTBGz0UPc4vKO p66dQ4e3vyXcBrGa+AAnuLLPFCGJjsESuM7xnYAF/yW6bVSd2cR9504Kq5UuB6mYjoUC pVUznnWFoHK/TUfz4yu7XY69iPOCytkxBK9pV3peNywzyDHdaif9xkOTcblxseN8iGlJ L1c1nft9G44A+IwMzPvjAj+eeFUJShUtBXt2CvQEqsD5Gvws0hCFtjo0+0ea9akDyk6y Zr2lcW5UIBfVYZcN74W0dYpceFzZf6ciI6b99ItuDPzT+GPLJ8+nU/+yYhUDxNQ2//A0 1F9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZV4SBzjn; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-212872-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212872-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c4c4600261si1046543a91.13.2024.06.13.01.49.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 01:49:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212872-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZV4SBzjn; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-212872-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212872-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0169D281963 for ; Thu, 13 Jun 2024 08:48:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DFA6C1411F4; Thu, 13 Jun 2024 08:47:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZV4SBzjn" Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33E6113E03B; Thu, 13 Jun 2024 08:47:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268426; cv=none; b=Qt+uhucukiFTj7l8RAkPWS+ooRYFNQb2LeAi5BiMz7K1vN9KYhQtu/vys9pfuGLSvXKp05OF64wx+A3BWb90vKFTXYG9hMWWcEE3hC3qQcoV/FRSmQyyeKoUndiIF7cjV+f4qsJE6ipy4IwdCNdWZo3PAWUPP645klO+2NddlBs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718268426; c=relaxed/simple; bh=7cTfU0NzG4EQ73KLfyQ5mMxgJ/9Ax3Um1XAQjism0x0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W2epbFbzHghXCcqt23CoEWp2OWB/ngFjCh662hXf72rzbvJP/8Os5ajidRfPrbhdsGNM6aiBQbxRlVr0selyjU2LQYgGFc6GNYOIQUZY/ifNCL76BlNemiacz4pUNvBarJikwF09IP1UVLmmbEaYDFgWGGkzSzlfwdC3MDOIbII= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZV4SBzjn; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a6f253a06caso94566366b.1; Thu, 13 Jun 2024 01:47:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718268423; x=1718873223; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4CEwTUZlBDBOuLF/YpPCjybp6G8vWfidbX5dtN7b7RA=; b=ZV4SBzjnV9+AwGTakM2YDQ1Vvp9GbqH1JuPDLFEfYZg2eviAVP7YVaAUaYGW0ZRPCX WJFM1MCOZxZNVMGa0gkTlcn5hCzYUMqkFSn6/VfOc5lgSR8UnxePa6cibRy8RNkShu2T HptpuY8f+EGz4q5tVR///YWiACFaT7KtR9PjRqEyX3qORNTGCONXm7D+qEqOBwzlaAoL MjzhQy04NBBVklxJPtAxU0Ow7GSZCNJkT8jROyetAQgjoRGtWk/m8ciRmzbHjHSnp2AR vYTEkNmvzsYhkdL5rpsKRlMRlCL+gXZWYLVNoeeP3AR4WgC7G48KiocHLMxnB+Ac47kn 6sQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718268423; x=1718873223; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4CEwTUZlBDBOuLF/YpPCjybp6G8vWfidbX5dtN7b7RA=; b=GTlMKdP8oWqcZBzzEW0KonDzMkJoiTFeVE+mntad2qtZc3j6zeF/F5sFtKIMS8F3Zf ZkFlsX6Hy+EASren9xdBVhkqjlvTZnf+rzM879IJwgbLQEFbI0+YpRDmo3SZi2Ozh1So np4/onEKIW2QfMJoPnO5WyLRWv02sts4Nf4a/j5mKIXFHWWhoGzjZ+uU77i6e5tw8dkD FJui0LZC/6VUE8TbN7WelSHkucvl6m4gYuYaRSRihmFNz04FJAY731R5Xzf+pq3UTWFL NvsolZ1OioHdFSIVH74dhnyDHfzonKq2WOlLWcG2YsWLIcWCgvvsTr7RC1Oi5HCAyRpI w2Wg== X-Forwarded-Encrypted: i=1; AJvYcCUcJ0jddBWC7kgWV9aBuqm6wU3eRJoL4met+DOIj66mZ+5Qfot3pklEJrHnpcCT/SrMejdV0bHLJZezMMqeuRDaDl7UwYZCB+W3jJ3u X-Gm-Message-State: AOJu0YwfD9SkRseHpjgZZjD5qwbeD6vo+wVVlOT87jUNOw5L6lzjShB1 dbyBK08fo7YdD1O4bEymlKSnhsxNwaTgiiVsuFDeeVmetKwhgYcr X-Received: by 2002:a17:907:72cb:b0:a6f:5259:72e0 with SMTP id a640c23a62f3a-a6f525973camr208690766b.25.1718268423010; Thu, 13 Jun 2024 01:47:03 -0700 (PDT) Received: from andrejs-nb.. (31-10-206-125.static.upc.ch. [31.10.206.125]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56dd2daasm48364266b.97.2024.06.13.01.47.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 01:47:02 -0700 (PDT) From: Andrejs Cainikovs To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Andrejs Cainikovs Subject: [PATCH v2 3/3] ASoC: nau8822: add MCLK support Date: Thu, 13 Jun 2024 10:46:52 +0200 Message-Id: <20240613084652.13113-4-andrejs.cainikovs@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240613084652.13113-1-andrejs.cainikovs@gmail.com> References: <20240613084652.13113-1-andrejs.cainikovs@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrejs Cainikovs This change adds MCLK clock handling directly within driver. When used in combination with simple-audio-card, and mclk-fs is set, simple-audio-card will change MCLK frequency before configuring PLL. In some cases, however, MCLK reference clock should be static (see [1]), which means it needs to be moved away from simple-audio-card. [1]: https://lore.kernel.org/all/ZfBdxrzX3EnPuGOn@ediswmail9.ad.cirrus.com/ Signed-off-by: Andrejs Cainikovs --- sound/soc/codecs/nau8822.c | 48 ++++++++++++++++++++++++++++++++++---- sound/soc/codecs/nau8822.h | 1 + 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/nau8822.c b/sound/soc/codecs/nau8822.c index 5f9f0953aa2f..e1cbaf8a944d 100644 --- a/sound/soc/codecs/nau8822.c +++ b/sound/soc/codecs/nau8822.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -773,11 +774,26 @@ static int nau8822_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, { struct snd_soc_component *component = dai->component; struct nau8822 *nau8822 = snd_soc_component_get_drvdata(component); + unsigned long mclk_freq; nau8822->div_id = clk_id; nau8822->sysclk = freq; + + if (nau8822->mclk) { + mclk_freq = clk_get_rate(nau8822->mclk); + if (mclk_freq != freq) { + int ret = nau8822_set_pll(dai, NAU8822_CLK_MCLK, + NAU8822_CLK_MCLK, mclk_freq, freq); + if (ret) { + dev_err(component->dev, "Failed to set PLL\n"); + return ret; + } + nau8822->div_id = NAU8822_CLK_PLL; + } + } + dev_dbg(component->dev, "master sysclk %dHz, source %s\n", freq, - clk_id == NAU8822_CLK_PLL ? "PLL" : "MCLK"); + nau8822->div_id == NAU8822_CLK_PLL ? "PLL" : "MCLK"); return 0; } @@ -848,7 +864,7 @@ static int nau8822_hw_params(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct nau8822 *nau8822 = snd_soc_component_get_drvdata(component); - int val_len = 0, val_rate = 0; + int div = 0, val_len = 0, val_rate = 0; unsigned int ctrl_val, bclk_fs, bclk_div; /* make BCLK and LRC divide configuration if the codec as master. */ @@ -915,8 +931,10 @@ static int nau8822_hw_params(struct snd_pcm_substream *substream, /* If the master clock is from MCLK, provide the runtime FS for driver * to get the master clock prescaler configuration. */ - if (nau8822->div_id == NAU8822_CLK_MCLK) - nau8822_config_clkdiv(dai, 0, params_rate(params)); + if (nau8822->div_id != NAU8822_CLK_MCLK) + div = nau8822->pll.mclk_scaler; + + nau8822_config_clkdiv(dai, div, params_rate(params)); return 0; } @@ -940,17 +958,34 @@ static int nau8822_mute(struct snd_soc_dai *dai, int mute, int direction) static int nau8822_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { + struct nau8822 *nau8822 = snd_soc_component_get_drvdata(component); + switch (level) { case SND_SOC_BIAS_ON: break; case SND_SOC_BIAS_PREPARE: + if (nau8822->mclk && + snd_soc_component_get_bias_level(component) != SND_SOC_BIAS_ON) { + int ret = clk_prepare_enable(nau8822->mclk); + + if (ret) { + dev_err(component->dev, + "Failed to enable MCLK: %d\n", ret); + return ret; + } + } + snd_soc_component_update_bits(component, NAU8822_REG_POWER_MANAGEMENT_1, NAU8822_REFIMP_MASK, NAU8822_REFIMP_80K); break; case SND_SOC_BIAS_STANDBY: + if (nau8822->mclk && + snd_soc_component_get_bias_level(component) != SND_SOC_BIAS_OFF) + clk_disable_unprepare(nau8822->mclk); + snd_soc_component_update_bits(component, NAU8822_REG_POWER_MANAGEMENT_1, NAU8822_IOBUF_EN | NAU8822_ABIAS_EN, @@ -1127,6 +1162,11 @@ static int nau8822_i2c_probe(struct i2c_client *i2c) } i2c_set_clientdata(i2c, nau8822); + nau8822->mclk = devm_clk_get_optional(&i2c->dev, "mclk"); + if (IS_ERR(nau8822->mclk)) + return dev_err_probe(&i2c->dev, PTR_ERR(nau8822->mclk), + "Error getting mclk\n"); + nau8822->regmap = devm_regmap_init_i2c(i2c, &nau8822_regmap_config); if (IS_ERR(nau8822->regmap)) { ret = PTR_ERR(nau8822->regmap); diff --git a/sound/soc/codecs/nau8822.h b/sound/soc/codecs/nau8822.h index 6ecd46e45923..13fe0a091e9e 100644 --- a/sound/soc/codecs/nau8822.h +++ b/sound/soc/codecs/nau8822.h @@ -215,6 +215,7 @@ struct nau8822_pll { struct nau8822 { struct device *dev; struct regmap *regmap; + struct clk *mclk; struct nau8822_pll pll; int sysclk; int div_id; -- 2.34.1