Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp465421iol; Thu, 9 Jun 2022 07:20:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFKmhUp17ewJBUhhb/jeISZbAJVhIGlPymB0YE4ztkhnwhGbKdVTAYIc1MxXcvnUGOp+gf X-Received: by 2002:a17:90a:9741:b0:1e8:a001:5caa with SMTP id i1-20020a17090a974100b001e8a0015caamr3676082pjw.231.1654784445478; Thu, 09 Jun 2022 07:20:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654784445; cv=none; d=google.com; s=arc-20160816; b=tRgxBSQUBUa+sktXra5RgZN0JdtYUGJcw1fMko5UQoH3BTmzC8/61YNM/2Um9hdFvY /mgOlN5cTAPUpnJ30HRSAjlF+Y0kQ9NnI6t9Usc93tyshuVCzvqAr/UONT9ZV4BNDZP+ Pu6I4/kNA0etWAwFVHSkP0vTYF6Zea5vNrR/6CgVTMP3QgakDnEuEl9ksNL7+FQx3Xzp OVpvFDltWViD8vcv0DAcJrX/6H2vpb9q4dJcL6Rc5fZVDD+VcNBz0aUIpNOmY/GaeaD/ tBzaxMDE7ceTknApCwYW3wrMS+OWSqE/gNSQVMB6XEj6tjWrggseaD+mFdMI7GJAO2ha vYJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=jHH7bIr15k6Wcan9xWpb2RIAAbwJZGEkdGwUmeH+pik=; b=bT25EThcbbw3f5uxaQH80rTk97qOVzNErpV+PMXDHRD9X4+JEWysVc/qmGXLpza+xH lLvECpmHAKuc2UYaToYoZ+PnPXS8do8Rm9SivTMEzpl2zJJvN/pqAr8SB7fkm/CVu3LP 1kfAGSkifsEF8yYwOrEdI8Rg70qFV15DbnPGGHcw4IhvMjs0Ef1OiwbYc86d1JNmRVgl JTB2176mkY2Ks/xXE3fMZjb7OoHkdETJLqU7aTQSAu8jCmKJXcIKlPG3U3KS92VKC5Ix EXXfY8gRRf9RVUqadh5fUu8Cc5n/2tAODa2bUdITrDfSIbflkCwym+eYOo/v6IK3p6n/ QCkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cutebit.org header.s=mail header.b=XgcTXKYM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cutebit.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bk11-20020a056a02028b00b004019bf283d2si2003484pgb.554.2022.06.09.07.20.32; Thu, 09 Jun 2022 07:20:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cutebit.org header.s=mail header.b=XgcTXKYM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cutebit.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244795AbiFIOKE (ORCPT + 99 others); Thu, 9 Jun 2022 10:10:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241162AbiFIOKD (ORCPT ); Thu, 9 Jun 2022 10:10:03 -0400 Received: from hutie.ust.cz (hutie.ust.cz [185.8.165.127]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53DF94D6A2; Thu, 9 Jun 2022 07:10:00 -0700 (PDT) Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cutebit.org; s=mail; t=1654783798; bh=jHH7bIr15k6Wcan9xWpb2RIAAbwJZGEkdGwUmeH+pik=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=XgcTXKYMtUhTeQO6Ro1EGyNKeIdpm0Get6FyG9/ernuBm5uxzfpY+RZ9qbFfzUG1G nMiPvNPkxTi2YsD4gN8kt2FdsXeBxGW8VWayv/7YVxVlJvWox68X2g88mudvm7kW4o c6vIcj42mzRKd6BBqt19kf6BscBM7EdFKysHPiD8= Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Subject: Re: [RFC PATCH v2 5/5] ASoC: apple: Add macaudio machine driver From: =?utf-8?Q?Martin_Povi=C5=A1er?= In-Reply-To: Date: Thu, 9 Jun 2022 16:09:57 +0200 Cc: Liam Girdwood , Rob Herring , Krzysztof Kozlowski , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Kettenis , Hector Martin , Sven Peter , asahi@lists.linux.dev Content-Transfer-Encoding: quoted-printable Message-Id: <8961DDD2-93FF-4A18-BCA2-90FCE298F517@cutebit.org> References: <20220606191910.16580-1-povik+lin@cutebit.org> <20220606191910.16580-6-povik+lin@cutebit.org> To: Mark Brown X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On 9. 6. 2022, at 15:33, Mark Brown wrote: >=20 > On Mon, Jun 06, 2022 at 09:19:10PM +0200, Martin Povi=C5=A1er wrote: >=20 >> + /* >> + * Primary FE >> + * >> + * The mclk/fs ratio at 64 for the primary frontend is = important >> + * to ensure that the headphones codec's idea of left = and right >> + * in a stereo stream over I2S fits in nicely with = everyone else's. >> + * (This is until the headphones codec's driver supports >> + * set_tdm_slot.) >> + * >> + * The low mclk/fs ratio precludes transmitting more = than two >> + * channels over I2S, but that's okay since there is the = secondary >> + * FE for speaker arrays anyway. >> + */ >> + .mclk_fs =3D 64, >> + }, >=20 > This seems weird - it looks like it's confusing MCLK and the bit clock > for the audio bus. These are two different clocks. Note that it's = very > common for devices to require a higher MCLK/fs ratio to deliver the = best > audio performance, 256fs is standard. On these machines we are not producing any other clock for the codecs besides the bit clock, so I am using MCLK interchangeably for it. (It is what the sample rate is derived from after all.) One of the codec drivers this is to be used with (cs42l42) expects to be given the I2S bit clock with snd_soc_dai_set_sysclk(dai, 0, mclk, SND_SOC_CLOCK_IN); I can rename mclk to bclk in all of the code to make it clearer maybe. Also the platform driver can take the bit clock value from = set_bclk_ratio, instead of set_sysclk from where it takes it now. The cs42l42 driver I = can patch too to accept set_bclk_ratio. >> + { >> + /* >> + * Secondary FE >> + * >> + * Here we want frames plenty long to be able to drive = all >> + * those fancy speaker arrays. >> + */ >> + .mclk_fs =3D 256, >> + } >=20 > Same thing here - this is at least confusing MCLK and the bit clock. >=20 >> +static bool macaudio_match_kctl_name(const char *pattern, const char = *name) >> +{ >> + if (pattern[0] =3D=3D '*') { >> + int namelen, patternlen; >> + >> + pattern++; >> + if (pattern[0] =3D=3D ' ') >> + pattern++; >> + >> + namelen =3D strlen(name); >> + patternlen =3D strlen(pattern); >> + >> + if (namelen > patternlen) >> + name +=3D (namelen - patternlen); >> + } >> + >> + return !strcmp(name, pattern); >> +} >> + >> +static int macaudio_limit_volume(struct snd_soc_card *card, >> + const char *pattern, int max) >> +{ >> + struct snd_kcontrol *kctl; >> + struct soc_mixer_control *mc; >> + int found =3D 0; >> + >> + list_for_each_entry(kctl, &card->snd_card->controls, list) { >> + if (!macaudio_match_kctl_name(pattern, kctl->id.name)) >> + continue; >> + >> + found++; >> + dev_dbg(card->dev, "limiting volume on '%s'\n", = kctl->id.name); >> + >> + /* >> + * TODO: This doesn't decrease the volume if it's = already >> + * above the limit! >> + */ >> + mc =3D (struct soc_mixer_control *)kctl->private_value; >> + if (max <=3D mc->max) >> + mc->platform_max =3D max; >> + >> + } >> + >> + return found; >> +} >=20 > This shouldn't be open coded in a driver, please factor it out into = the > core so we've got an API for "set limit X on control Y" then call = that. There=E2=80=99s already snd_soc_limit_volume, but it takes a fixed = control name. Can I extend it to understand patterns beginning with a wildcard, like '* Amp Gain Volume=E2=80=99?