Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp301287rdb; Thu, 21 Dec 2023 09:27:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEbmxXVAkDoGk/9jhn7OuotI+qUzeODdGbaWHw2xCRLnOY4ijwhkpc3sh6mWEpzikjlQGI X-Received: by 2002:a05:6808:f06:b0:3b9:e51b:95ee with SMTP id m6-20020a0568080f0600b003b9e51b95eemr27953oiw.42.1703179624052; Thu, 21 Dec 2023 09:27:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703179624; cv=none; d=google.com; s=arc-20160816; b=ifI3PXc6sSinUQ+pVCbdtRr/owhM60ZrxshYgndCtTq4beMHKPGgi/NpPjoQQi8cB9 tJDwdHoAxs6HcbvAb9hwTIYjkByOD5GBDSRE6pU+d7f9OgGeWEL2vD6FA1JYQ09Pz20T 5DGNRRdtBC6WzlXz067PMtbNIh5/V+ciagfNAKblzf+J6zgGpf0nJgqQ3KC5OiKIVh8v 5NSgkvT9n3Rr74ztZJIjyao2uTWavRljSPZ0l/0GgrlzfMupnvL4SZJ0uxJpxbWe4j0x BX9CI2KZ7xJREeQt21TsxlMFIYCkXWAJc/sniBvURI6tRlVFo2rvMbs7QElw0vCISW8I zdZg== ARC-Message-Signature: i=1; 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:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=GIeD6r0ggI3ADutsQNowCPQye4qk3tIekDS6OtEtvHU=; fh=XKj+edvDOm51Jmvow6Y6dusgg5VGK18ufmMK01iUsbs=; b=gobGfjI3XKer911dombGxJkHUqwlFmA6vS+ak9aYDSKQ4/wEnmXKOLGYfviOpHDVnH 6YnqTeGbA5hY1O5E6crhFL8Ndz+Qkrzg2E7fma3mUhjno6YdSSMzATQjkhy3givzac/L ZrVok8jdWanXKHqxJmZa40dXPbqa+ElrvS+xN4SWqERE19ykr7n91rBmSyfF1dS5AhpC EjNEGJly+dveVit99YMGIotPcej2n4CmPV67iMGTrCSDlcKF37ubJwVYk5Ixvkkv48vO 67lwwaLQRnZoD19CS/2886jRzBhTJQvFMaNXH5WR51fUdoCX5fOmc01beZHGP5u3GNMy UevA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8846-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8846-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d19-20020a67e413000000b00466a168b7d8si462876vsf.269.2023.12.21.09.27.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 09:27:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8846-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8846-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8846-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B477E1C2364C for ; Thu, 21 Dec 2023 17:27:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2511462805; Thu, 21 Dec 2023 17:26:53 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 62C7759910; Thu, 21 Dec 2023 17:26:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B423A2F4; Thu, 21 Dec 2023 09:27:34 -0800 (PST) Received: from donnerap.manchester.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3ED1B3F5A1; Thu, 21 Dec 2023 09:26:47 -0800 (PST) Date: Thu, 21 Dec 2023 17:26:44 +0000 From: Andre Przywara To: Brandon Cheo Fusi Cc: aou@eecs.berkeley.edu, conor+dt@kernel.org, devicetree@vger.kernel.org, jernej.skrabec@gmail.com, krzysztof.kozlowski+dt@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-sunxi@lists.linux.dev, palmer@dabbelt.com, paul.walmsley@sifive.com, rafael@kernel.org, robh+dt@kernel.org, samuel@sholland.org, sfr@canb.auug.org.au, tiny.windzz@gmail.com, viresh.kumar@linaro.org, wens@csie.org Subject: Re: [RFC PATCH v2 2/3] cpufreq: sun50i: Add support for D1's speed bin decoding Message-ID: <20231221172644.21cf3817@donnerap.manchester.arm.com> In-Reply-To: <20231221171107.85991-1-fusibrandon13@gmail.com> References: <20231221124957.27fa9922@donnerap.manchester.arm.com> <20231221171107.85991-1-fusibrandon13@gmail.com> Organization: ARM X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, 21 Dec 2023 18:11:07 +0100 Brandon Cheo Fusi wrote: Hi Brandon, > On Thu, Dec 21, 2023 at 1:50=E2=80=AFPM Andre Przywara wrote: > > > > On Thu, 21 Dec 2023 11:10:12 +0100 > > Brandon Cheo Fusi wrote: > > > > Hi Brandon, > > > > thanks for the quick turnaround, and for splitting this code up, that > > makes reasoning about this much easier! > > =20 > > > Adds support for decoding the efuse value read from D1 efuse speed > > > bins, and factors out equivalent code for sun50i. > > > > > > The algorithm is gotten from > > > > > > https://github.com/Tina-Linux/linux-5.4/blob/master/drivers/cpufreq/s= un50i-cpufreq-nvmem.c#L293-L338 > > > > > > and maps an efuse value to either 0 or 1, with 1 meaning stable at > > > a lower supply voltage for the same clock frequency. > > > > > > Signed-off-by: Brandon Cheo Fusi > > > --- > > > drivers/cpufreq/sun50i-cpufreq-nvmem.c | 34 ++++++++++++++++++++++++= ++ > > > 1 file changed, 34 insertions(+) > > > > > > diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq= /sun50i-cpufreq-nvmem.c > > > index fc509fc49..b1cb95308 100644 > > > --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c > > > +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c > > > @@ -29,6 +29,33 @@ struct sunxi_cpufreq_data { > > > u32 (*efuse_xlate)(u32 *speedbin, size_t len); > > > }; > > > > > > +static u32 sun20i_efuse_xlate(u32 *speedbin, size_t len) =20 > > > > I feel like this prototype can be shortened to: > > > > static u32 sun20i_efuse_xlate(u32 speedbin) > > > > See below. > > =20 > > > +{ > > > + u32 ret, efuse_value =3D 0; > > > + int i; > > > + > > > + for (i =3D 0; i < len; i++) > > > + efuse_value |=3D ((u32)speedbin[i] << (i * 8)); =20 > > > > The cast is not needed. Looking deeper into the original code you linked > > to, cell_value[] there is an array of u8, so they assemble a little end= ian > > 32-bit integer from *up to* four 8-bit values read from the nvmem. > > > > So I think this code here is wrong, len is the size of the nvmem cells > > holding the bin identifier, in *bytes*, so the idea here is to just read > > the (lowest) 16 bits (in the D1 case, cf. "reg =3D <0x00 0x2>;" in the = next > > patch) from this nvmem cell. Here you are combining two 32-bit words in= to =20 >=20 > This is true. Not sure though what the 'in the D1 case...' bit means. In the next patch you introduce the nvmem DT property, and set the length part to "0x2". So for the D1 we will always read two bytes. > > efuse_value. > > > > So I think this whole part above is actually not necessary: we are > > expecting maximum 32 bits, and nvmem_cell_read() should take care of > > masking off unrequested bits, so we get the correct value back already.= So > > can you try to remove the loop above, and use ... > > =20 > > > + > > > + switch (efuse_value) { =20 > > > > switch (*speedbin & 0xffff) { > > =20 >=20 > Shouldn't the bytes in *speedbin be reversed?=20 I believe they are stored as a little endian 16-bit integer in the fuses. I haven't tried a BE kernel, but I think the NVMEM framework takes care of that. If you dump the values as returned by nvmem_cell_read(), we would know for sure. > > here instead? Or drop the pointer at all, and just use one u32 value, s= ee > > the above prototype. > > =20 >=20 > I was uncomfortable dropping the len parameter, because then each > platform's efuse_xlate would ignore the number of valid bytes actually > read. Well, I am not sure either, but neither the H6, nor the H616 or the D1 apparently really need that: they all use either 4 or 2 bytes to encode the speed bin. And since the routines are SoC specific anyway, and the first 32-bit word of the buffer filled by nvmem_cell_read() should always be valid (and be it 0), I think there is little need to check that. I ported the H616 code over, and it looks somewhat similar to the D1 (with different numbers, though): it's (ab)using some die revision code (the first two bytes in the SID) to derive the speed bin. The H6 had a dedicated bin fuse. So iff we are going to see a SoC needing to check the length, we can always introduce that later: it's just an internal function. But for now I'd like to keep it simple. Cheers, Andre >=20 > > Cheers, > > Andre > > > > P.S. This is just a "peephole review" of this patch, I haven't got arou= nd > > to look at this whole scheme in whole yet, to see if we actually need t= his > > or can simplify this or clean it up. > > > > =20 > > > + case 0x5e00: > > > + /* QFN package */ > > > + ret =3D 0; > > > + break; > > > + case 0x5c00: > > > + case 0x7400: > > > + /* QFN package */ > > > + ret =3D 1; > > > + break; > > > + case 0x5000: > > > + default: > > > + /* BGA package */ > > > + ret =3D 0; > > > + } > > > + > > > + return ret; > > > +} > > > + > > > static u32 sun50i_efuse_xlate(u32 *speedbin, size_t len) > > > { > > > u32 efuse_value =3D 0; > > > @@ -46,6 +73,10 @@ static u32 sun50i_efuse_xlate(u32 *speedbin, size_= t len) > > > return 0; > > > } > > > > > > +struct sunxi_cpufreq_data sun20i_cpufreq_data =3D { > > > + .efuse_xlate =3D sun20i_efuse_xlate, > > > +}; > > > + > > > struct sunxi_cpufreq_data sun50i_cpufreq_data =3D { > > > .efuse_xlate =3D sun50i_efuse_xlate, > > > }; > > > @@ -54,6 +85,9 @@ static const struct of_device_id cpu_opp_match_list= [] =3D { > > > { .compatible =3D "allwinner,sun50i-h6-operating-points", > > > .data =3D &sun50i_cpufreq_data, > > > }, > > > + { .compatible =3D "allwinner,sun20i-d1-operating-points", > > > + .data =3D &sun20i_cpufreq_data, > > > + }, > > > {} > > > }; > > > =20 > > =20 >=20 > Thank you for reviewing. > Brandon. >=20