All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Samuel Holland <samuel@sholland.org>
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-sunxi@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	Brandon Cheo Fusi <fusibrandon13@gmail.com>,
	Martin Botka <martin.botka@somainline.org>,
	Martin Botka <martin.botka1@gmail.com>,
	Chris Morgan <macroalpha82@gmail.com>,
	Ryan Walklin <ryan@testtoast.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Yangtao Li <tiny.windzz@gmail.com>,
	Viresh Kumar <vireshk@kernel.org>, Nishanth Menon <nm@ti.com>,
	Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>, Chen-Yu Tsai <wens@csie.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>
Subject: Re: [PATCH v3 6/8] cpufreq: sun50i: Add H616 support
Date: Wed, 27 Mar 2024 11:46:08 +0000	[thread overview]
Message-ID: <20240327114608.2ffca28e@minigeek.lan> (raw)
In-Reply-To: <65e86555-761e-4e26-8778-e2452876b5e4@sholland.org>

On Tue, 26 Mar 2024 22:46:27 -0500
Samuel Holland <samuel@sholland.org> wrote:

Hi Samuel,

> On 3/26/24 06:47, Andre Przywara wrote:
> > From: Martin Botka <martin.botka@somainline.org>
> > 
> > The Allwinner H616/H618 SoCs have different OPP tables per SoC version
> > and die revision. The SoC version is stored in NVMEM, as before, though
> > encoded differently. The die revision is in a different register, in the
> > SRAM controller. Firmware already exports that value in a standardised
> > way, through the SMCCC SoCID mechanism. We need both values, as some chips
> > have the same SoC version, but they don't support the same frequencies and
> > they get differentiated by the die revision.
> > 
> > Add the new compatible string and tie the new translation function to
> > it. This mechanism not only covers the original H616 SoC, but also its
> > very close sibling SoCs H618 and H700, so add them to the list as well.
> > 
> > Signed-off-by: Martin Botka <martin.botka@somainline.org>
> > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> > ---
> >  drivers/cpufreq/sun50i-cpufreq-nvmem.c | 61 ++++++++++++++++++++++++++
> >  1 file changed, 61 insertions(+)
> > 
> > diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > index bd170611c7906..f9e9fc340f848 100644
> > --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > @@ -10,6 +10,7 @@
> >  
> >  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> >  
> > +#include <linux/arm-smccc.h>
> >  #include <linux/cpu.h>
> >  #include <linux/module.h>
> >  #include <linux/nvmem-consumer.h>
> > @@ -46,14 +47,71 @@ static u32 sun50i_h6_efuse_xlate(u32 speedbin)
> >  		return 0;
> >  }
> >  
> > +/*
> > + * Judging by the OPP tables in the vendor BSP, the quality order of the
> > + * returned speedbin index is 4 -> 0/2 -> 3 -> 1, from worst to best.
> > + * 0 and 2 seem identical from the OPP tables' point of view.
> > + */
> > +static u32 sun50i_h616_efuse_xlate(u32 speedbin)
> > +{
> > +	int ver_bits = arm_smccc_get_soc_id_revision();  
> 
> This needs a Kconfig dependency on ARM_SMCCC_SOC_ID.

That was my first impulse as well, but it's actually not true:
ARM_SMCCC_SOC_ID just protects the sysfs export code, not this function
here. That does just depend on HAVE_ARM_SMCCC_DISCOVERY, which gets
selected by ARM_GIC_V3, which gets selected by CONFIG_ARM64. So the
arm64 kernel is safe.
Now apart from ARM(32) (where the situation seems a bit more complex) I
just realise that this would torpedo Brandon's D1 efforts, so I need to
add this change I played with to provide an alternative:

static int get_soc_id_revision(void)
{
#ifdef CONFIG_HAVE_ARM_SMCCC_DISCOVERY
	return arm_smccc_get_soc_id_revision();
#else
	/* Return the value for the worse die revision, to be safe. */
	return 2;
#endif
}

Does that look acceptable, despite the #ifdef?

Cheers,
Andre


> 
> Regards,
> Samuel
> 
> > +	u32 value = 0;
> > +
> > +	switch (speedbin & 0xffff) {
> > +	case 0x2000:
> > +		value = 0;
> > +		break;
> > +	case 0x2400:
> > +	case 0x7400:
> > +	case 0x2c00:
> > +	case 0x7c00:
> > +		if (ver_bits != SMCCC_RET_NOT_SUPPORTED &&
> > ver_bits <= 1) {
> > +			/* ic version A/B */
> > +			value = 1;
> > +		} else {
> > +			/* ic version C and later version */
> > +			value = 2;
> > +		}
> > +		break;
> > +	case 0x5000:
> > +	case 0x5400:
> > +	case 0x6000:
> > +		value = 3;
> > +		break;
> > +	case 0x5c00:
> > +		value = 4;
> > +		break;
> > +	case 0x5d00:
> > +		value = 0;
> > +		break;
> > +	case 0x6c00:
> > +		value = 5;
> > +		break;
> > +	default:
> > +		pr_warn("sun50i-cpufreq-nvmem: unknown speed bin
> > 0x%x, using default bin 0\n",
> > +			speedbin & 0xffff);
> > +		value = 0;
> > +		break;
> > +	}
> > +
> > +	return value;
> > +}
> > +
> >  static struct sunxi_cpufreq_data sun50i_h6_cpufreq_data = {
> >  	.efuse_xlate = sun50i_h6_efuse_xlate,
> >  };
> >  
> > +static struct sunxi_cpufreq_data sun50i_h616_cpufreq_data = {
> > +	.efuse_xlate = sun50i_h616_efuse_xlate,
> > +};
> > +
> >  static const struct of_device_id cpu_opp_match_list[] = {
> >  	{ .compatible = "allwinner,sun50i-h6-operating-points",
> >  	  .data = &sun50i_h6_cpufreq_data,
> >  	},
> > +	{ .compatible = "allwinner,sun50i-h616-operating-points",
> > +	  .data = &sun50i_h616_cpufreq_data,
> > +	},
> >  	{}
> >  };
> >  
> > @@ -230,6 +288,9 @@ static struct platform_driver
> > sun50i_cpufreq_driver = { 
> >  static const struct of_device_id sun50i_cpufreq_match_list[] = {
> >  	{ .compatible = "allwinner,sun50i-h6" },
> > +	{ .compatible = "allwinner,sun50i-h616" },
> > +	{ .compatible = "allwinner,sun50i-h618" },
> > +	{ .compatible = "allwinner,sun50i-h700" },
> >  	{}
> >  };
> >  MODULE_DEVICE_TABLE(of, sun50i_cpufreq_match_list);  
> 
> 


WARNING: multiple messages have this Message-ID (diff)
From: Andre Przywara <andre.przywara@arm.com>
To: Samuel Holland <samuel@sholland.org>
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-sunxi@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	Brandon Cheo Fusi <fusibrandon13@gmail.com>,
	Martin Botka <martin.botka@somainline.org>,
	Martin Botka <martin.botka1@gmail.com>,
	Chris Morgan <macroalpha82@gmail.com>,
	Ryan Walklin <ryan@testtoast.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Yangtao Li <tiny.windzz@gmail.com>,
	Viresh Kumar <vireshk@kernel.org>, Nishanth Menon <nm@ti.com>,
	Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>, Chen-Yu Tsai <wens@csie.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>
Subject: Re: [PATCH v3 6/8] cpufreq: sun50i: Add H616 support
Date: Wed, 27 Mar 2024 11:46:08 +0000	[thread overview]
Message-ID: <20240327114608.2ffca28e@minigeek.lan> (raw)
In-Reply-To: <65e86555-761e-4e26-8778-e2452876b5e4@sholland.org>

On Tue, 26 Mar 2024 22:46:27 -0500
Samuel Holland <samuel@sholland.org> wrote:

Hi Samuel,

> On 3/26/24 06:47, Andre Przywara wrote:
> > From: Martin Botka <martin.botka@somainline.org>
> > 
> > The Allwinner H616/H618 SoCs have different OPP tables per SoC version
> > and die revision. The SoC version is stored in NVMEM, as before, though
> > encoded differently. The die revision is in a different register, in the
> > SRAM controller. Firmware already exports that value in a standardised
> > way, through the SMCCC SoCID mechanism. We need both values, as some chips
> > have the same SoC version, but they don't support the same frequencies and
> > they get differentiated by the die revision.
> > 
> > Add the new compatible string and tie the new translation function to
> > it. This mechanism not only covers the original H616 SoC, but also its
> > very close sibling SoCs H618 and H700, so add them to the list as well.
> > 
> > Signed-off-by: Martin Botka <martin.botka@somainline.org>
> > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> > ---
> >  drivers/cpufreq/sun50i-cpufreq-nvmem.c | 61 ++++++++++++++++++++++++++
> >  1 file changed, 61 insertions(+)
> > 
> > diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > index bd170611c7906..f9e9fc340f848 100644
> > --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > @@ -10,6 +10,7 @@
> >  
> >  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> >  
> > +#include <linux/arm-smccc.h>
> >  #include <linux/cpu.h>
> >  #include <linux/module.h>
> >  #include <linux/nvmem-consumer.h>
> > @@ -46,14 +47,71 @@ static u32 sun50i_h6_efuse_xlate(u32 speedbin)
> >  		return 0;
> >  }
> >  
> > +/*
> > + * Judging by the OPP tables in the vendor BSP, the quality order of the
> > + * returned speedbin index is 4 -> 0/2 -> 3 -> 1, from worst to best.
> > + * 0 and 2 seem identical from the OPP tables' point of view.
> > + */
> > +static u32 sun50i_h616_efuse_xlate(u32 speedbin)
> > +{
> > +	int ver_bits = arm_smccc_get_soc_id_revision();  
> 
> This needs a Kconfig dependency on ARM_SMCCC_SOC_ID.

That was my first impulse as well, but it's actually not true:
ARM_SMCCC_SOC_ID just protects the sysfs export code, not this function
here. That does just depend on HAVE_ARM_SMCCC_DISCOVERY, which gets
selected by ARM_GIC_V3, which gets selected by CONFIG_ARM64. So the
arm64 kernel is safe.
Now apart from ARM(32) (where the situation seems a bit more complex) I
just realise that this would torpedo Brandon's D1 efforts, so I need to
add this change I played with to provide an alternative:

static int get_soc_id_revision(void)
{
#ifdef CONFIG_HAVE_ARM_SMCCC_DISCOVERY
	return arm_smccc_get_soc_id_revision();
#else
	/* Return the value for the worse die revision, to be safe. */
	return 2;
#endif
}

Does that look acceptable, despite the #ifdef?

Cheers,
Andre


> 
> Regards,
> Samuel
> 
> > +	u32 value = 0;
> > +
> > +	switch (speedbin & 0xffff) {
> > +	case 0x2000:
> > +		value = 0;
> > +		break;
> > +	case 0x2400:
> > +	case 0x7400:
> > +	case 0x2c00:
> > +	case 0x7c00:
> > +		if (ver_bits != SMCCC_RET_NOT_SUPPORTED &&
> > ver_bits <= 1) {
> > +			/* ic version A/B */
> > +			value = 1;
> > +		} else {
> > +			/* ic version C and later version */
> > +			value = 2;
> > +		}
> > +		break;
> > +	case 0x5000:
> > +	case 0x5400:
> > +	case 0x6000:
> > +		value = 3;
> > +		break;
> > +	case 0x5c00:
> > +		value = 4;
> > +		break;
> > +	case 0x5d00:
> > +		value = 0;
> > +		break;
> > +	case 0x6c00:
> > +		value = 5;
> > +		break;
> > +	default:
> > +		pr_warn("sun50i-cpufreq-nvmem: unknown speed bin
> > 0x%x, using default bin 0\n",
> > +			speedbin & 0xffff);
> > +		value = 0;
> > +		break;
> > +	}
> > +
> > +	return value;
> > +}
> > +
> >  static struct sunxi_cpufreq_data sun50i_h6_cpufreq_data = {
> >  	.efuse_xlate = sun50i_h6_efuse_xlate,
> >  };
> >  
> > +static struct sunxi_cpufreq_data sun50i_h616_cpufreq_data = {
> > +	.efuse_xlate = sun50i_h616_efuse_xlate,
> > +};
> > +
> >  static const struct of_device_id cpu_opp_match_list[] = {
> >  	{ .compatible = "allwinner,sun50i-h6-operating-points",
> >  	  .data = &sun50i_h6_cpufreq_data,
> >  	},
> > +	{ .compatible = "allwinner,sun50i-h616-operating-points",
> > +	  .data = &sun50i_h616_cpufreq_data,
> > +	},
> >  	{}
> >  };
> >  
> > @@ -230,6 +288,9 @@ static struct platform_driver
> > sun50i_cpufreq_driver = { 
> >  static const struct of_device_id sun50i_cpufreq_match_list[] = {
> >  	{ .compatible = "allwinner,sun50i-h6" },
> > +	{ .compatible = "allwinner,sun50i-h616" },
> > +	{ .compatible = "allwinner,sun50i-h618" },
> > +	{ .compatible = "allwinner,sun50i-h700" },
> >  	{}
> >  };
> >  MODULE_DEVICE_TABLE(of, sun50i_cpufreq_match_list);  
> 
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2024-03-27 11:46 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26 11:47 [PATCH v3 0/8] cpufreq: sun50i: Add Allwinner H616 support Andre Przywara
2024-03-26 11:47 ` Andre Przywara
2024-03-26 11:47 ` [PATCH v3 1/8] firmware: smccc: Export revision soc_id function Andre Przywara
2024-03-26 11:47   ` Andre Przywara
2024-03-26 13:18   ` Sudeep Holla
2024-03-26 13:18     ` Sudeep Holla
2024-03-26 11:47 ` [PATCH v3 2/8] cpufreq: dt-platdev: Blocklist Allwinner H616/618 SoCs Andre Przywara
2024-03-26 11:47   ` Andre Przywara
2024-03-27 20:57   ` Jernej Škrabec
2024-03-27 20:57     ` Jernej Škrabec
2024-03-26 11:47 ` [PATCH v3 3/8] dt-bindings: opp: Describe H616 OPPs and opp-supported-hw Andre Przywara
2024-03-26 11:47   ` Andre Przywara
2024-03-26 21:37   ` Rob Herring
2024-03-26 21:37     ` Rob Herring
2024-03-26 11:47 ` [PATCH v3 4/8] cpufreq: sun50i: Refactor speed bin decoding Andre Przywara
2024-03-26 11:47   ` Andre Przywara
2024-03-27 21:19   ` Jernej Škrabec
2024-03-27 21:19     ` Jernej Škrabec
2024-03-26 11:47 ` [PATCH v3 5/8] cpufreq: sun50i: Add support for opp_supported_hw Andre Przywara
2024-03-26 11:47   ` Andre Przywara
2024-03-27 21:20   ` Jernej Škrabec
2024-03-27 21:20     ` Jernej Škrabec
2024-03-26 11:47 ` [PATCH v3 6/8] cpufreq: sun50i: Add H616 support Andre Przywara
2024-03-26 11:47   ` Andre Przywara
2024-03-27  3:46   ` Samuel Holland
2024-03-27  3:46     ` Samuel Holland
2024-03-27 11:46     ` Andre Przywara [this message]
2024-03-27 11:46       ` Andre Przywara
2024-03-27 11:58       ` Sudeep Holla
2024-03-27 11:58         ` Sudeep Holla
2024-03-27 12:01         ` Sudeep Holla
2024-03-27 12:01           ` Sudeep Holla
2024-03-27 12:16         ` Andre Przywara
2024-03-27 12:16           ` Andre Przywara
2024-03-26 11:47 ` [PATCH v3 7/8] arm64: dts: allwinner: h616: Add CPU OPPs table Andre Przywara
2024-03-26 11:47   ` Andre Przywara
2024-03-27 21:24   ` Jernej Škrabec
2024-03-27 21:24     ` Jernej Škrabec
2024-03-26 11:47 ` [PATCH v3 8/8] arm64: dts: allwinner: h616: enable DVFS for all boards Andre Przywara
2024-03-26 11:47   ` Andre Przywara
2024-03-27 21:25   ` Jernej Škrabec
2024-03-27 21:25     ` Jernej Škrabec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240327114608.2ffca28e@minigeek.lan \
    --to=andre.przywara@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fusibrandon13@gmail.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=lpieralisi@kernel.org \
    --cc=macroalpha82@gmail.com \
    --cc=mark.rutland@arm.com \
    --cc=martin.botka1@gmail.com \
    --cc=martin.botka@somainline.org \
    --cc=nm@ti.com \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=ryan@testtoast.com \
    --cc=samuel@sholland.org \
    --cc=sboyd@kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=tiny.windzz@gmail.com \
    --cc=vireshk@kernel.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.