lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20221028211224.iiphmwrpqqs27jr4@notapiano>
Date:   Fri, 28 Oct 2022 17:12:24 -0400
From:   Nícolas F. R. A. Prado 
        <nfraprado@...labora.com>
To:     AngeloGioacchino Del Regno 
        <angelogioacchino.delregno@...labora.com>
Cc:     Mark Brown <broonie@...nel.org>, kernel@...labora.com,
        Derek Fang <derek.fang@...ltek.com>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
        Liam Girdwood <lgirdwood@...il.com>,
        Rob Herring <robh+dt@...nel.org>, alsa-devel@...a-project.org,
        devicetree@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/4] ASoC: dt-bindings: realtek,rt5682s: Add AVDD and
 MICVDD supplies

On Tue, Oct 25, 2022 at 12:06:23PM +0200, AngeloGioacchino Del Regno wrote:
> Il 25/10/22 00:00, Nícolas F. R. A. Prado ha scritto:
> > The rt5682s codec can have two supplies: AVDD and MICVDD. They are
> > already used by sc7180-trogdor-kingoftown.dtsi, so document them in the
> > binding.
> > 
> > Signed-off-by: Nícolas F. R. A. Prado <nfraprado@...labora.com>
> > 
> 
> I also don't like these uppercase supply names... I wonder if it's worth changing
> the driver to get "avdd" *or* "AVDD" (so, if "avdd" fails -> backwards compat)...
> 
> ...this way, we can change the devicetree to use the lowercase names without
> breaking abi.
> 
> Of course, this commit would need to be changed to document only the lowercase
> supply names.
> 
> Driver-wise, we have a rt5682s_supply_names array... we could do something like:
> 
> static const char *rt5682s_supply_names_legacy[RT5682S_NUM_SUPPLIES] = {
> 	[RT5682S_SUPPLY_AVDD] = "AVDD",
> 	[RT5682S_SUPPLY_MICVDD] = "MICVDD",
> };
> 
> static const char *rt5682s_supply_names[RT5682S_NUM_SUPPLIES] = {
> 	[RT5682S_SUPPLY_AVDD] = "avdd",
> 	[RT5682S_SUPPLY_MICVDD] = "micvdd",
> };
> 
> for (...) assign_supply_names;
> ret = devm_regulator_bulk_get(...);
> 
> if (ret) {
> 	for (...) assign_legacy_supply_names;
> 	ret = devm_regulator_bulk_get(...)
> 	if (ret)
> 		return ret;
> }
> 
> What do you think?

Hi,

I took a stab at this, but the resulting code wasn't as elegant. The default
behavior of the regulator core when a regulator is missing is to just print
a warning and give a dummy regulator in its place. A way around this is the
"optional" variant, but it doesn't have a bulk version (in fact seems like it
was added and then removed a few years back, but I haven't dug out the reason).

So the result was a code block that wasn't nearly as neat as your draft above
and it didn't seem worth it to add this complexity just to gain the usage of
lowercase properties, which is why in the end I decided to not include this in
the series I just sent [1]. 

I've included the patch below. If you do think there's a more reasonable
approach or if having the lowercase supplies is worth it, let me know.

Thanks,
Nícolas

[1] https://lore.kernel.org/all/20221028205540.3197304-1-nfraprado@collabora.com


>From 8de4a86f10ba2e13458afe63fe658df685b21b45 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?=
 <nfraprado@...labora.com>
Date: Thu, 27 Oct 2022 16:10:22 -0400
Subject: [PATCH] ASoC: rt5682s: Handle lowercase supply name and fallback if
 needed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Supply names provided by devicetree are conventionally lowercase. In
order to be able to use lowercase names without breaking existing
setups, detect if any of the older names are used and if so fallback to
them.

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@...labora.com>
---
 sound/soc/codecs/rt5682s.c | 40 ++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/rt5682s.c b/sound/soc/codecs/rt5682s.c
index 466a37f3500c..3cefa016be77 100644
--- a/sound/soc/codecs/rt5682s.c
+++ b/sound/soc/codecs/rt5682s.c
@@ -41,11 +41,16 @@ static const struct rt5682s_platform_data i2s_default_platform_data = {
 	.dai_clk_names[RT5682S_DAI_BCLK_IDX] = "rt5682-dai-bclk",
 };

-static const char *rt5682s_supply_names[RT5682S_NUM_SUPPLIES] = {
+static const char *rt5682s_legacy_supply_names[RT5682S_NUM_SUPPLIES] = {
 	[RT5682S_SUPPLY_AVDD] = "AVDD",
 	[RT5682S_SUPPLY_MICVDD] = "MICVDD",
 };

+static const char *rt5682s_supply_names[RT5682S_NUM_SUPPLIES] = {
+	[RT5682S_SUPPLY_AVDD] = "avdd",
+	[RT5682S_SUPPLY_MICVDD] = "micvdd",
+};
+
 static const struct reg_sequence patch_list[] = {
 	{RT5682S_I2C_CTRL,			0x0007},
 	{RT5682S_DIG_IN_CTRL_1,			0x0000},
@@ -3090,7 +3095,9 @@ static int rt5682s_i2c_probe(struct i2c_client *i2c)
 	struct rt5682s_platform_data *pdata = dev_get_platdata(&i2c->dev);
 	struct rt5682s_priv *rt5682s;
 	int i, ret;
+	struct regulator *reg;
 	unsigned int val;
+	bool using_legacy_supply_names = false;

 	rt5682s = devm_kzalloc(&i2c->dev, sizeof(struct rt5682s_priv), GFP_KERNEL);
 	if (!rt5682s)
@@ -3112,14 +3119,31 @@ static int rt5682s_i2c_probe(struct i2c_client *i2c)
 		return ret;
 	}

-	for (i = 0; i < ARRAY_SIZE(rt5682s->supplies); i++)
-		rt5682s->supplies[i].supply = rt5682s_supply_names[i];
+	for (i = 0; i < ARRAY_SIZE(rt5682s_supply_names); i++) {
+		reg = devm_regulator_get_optional(&i2c->dev, rt5682s_supply_names[i]);
+		if (IS_ERR(reg)) {
+			if (PTR_ERR(reg) == -ENODEV) {
+				using_legacy_supply_names = true;
+				break;
+			} else {
+				dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
+				return PTR_ERR(reg);
+			}
+		}

-	ret = devm_regulator_bulk_get(&i2c->dev,
-			ARRAY_SIZE(rt5682s->supplies), rt5682s->supplies);
-	if (ret) {
-		dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
-		return ret;
+		rt5682s->supplies[i].consumer = reg;
+	}
+
+	if (using_legacy_supply_names) {
+		for (i = 0; i < ARRAY_SIZE(rt5682s->supplies); i++)
+			rt5682s->supplies[i].supply = rt5682s_legacy_supply_names[i];
+
+		ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(rt5682s->supplies),
+					      rt5682s->supplies);
+		if (ret) {
+			dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
+			return ret;
+		}
 	}

 	ret = devm_add_action_or_reset(&i2c->dev, rt5682s_i2c_disable_regulators, rt5682s);
--
2.38.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ