linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Barker <paul.barker.ct@bp.renesas.com>
To: Geert Uytterhoeven <geert+renesas@glider.be>,
	Magnus Damm <magnus.damm@gmail.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>
Cc: Paul Barker <paul.barker.ct@bp.renesas.com>,
	linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/9] pinctrl: renesas: rzg2l: Fix variable names in OEN functions
Date: Fri, 24 May 2024 10:45:55 +0100	[thread overview]
Message-ID: <20240524094603.988-2-paul.barker.ct@bp.renesas.com> (raw)
In-Reply-To: <20240524094603.988-1-paul.barker.ct@bp.renesas.com>

The variable naming in the various OEN functions has been confusing. We
were passing the _pin variable from rzg2l_pinctrl_pinconf_get() and
rzg2l_pinctrl_pinconf_set() as the offset argument to rzg2l_read_oen()
and rzg2l_write_oen(), when this is not a register offset.

What we actually need here is the port index, so that we can compare
this to oen_max_port.

We can also clean up rzg2l_pin_to_oen_bit(), removing an unnecessary
branch and clarifying the variable naming.

Signed-off-by: Paul Barker <paul.barker.ct@bp.renesas.com>
---
 drivers/pinctrl/renesas/pinctrl-rzg2l.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/pinctrl/renesas/pinctrl-rzg2l.c b/drivers/pinctrl/renesas/pinctrl-rzg2l.c
index c3256bfde502..724308cd5a37 100644
--- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c
+++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c
@@ -1025,18 +1025,17 @@ static bool rzg2l_oen_is_supported(u32 caps, u8 pin, u8 max_pin)
 	return true;
 }
 
-static u8 rzg2l_pin_to_oen_bit(u32 offset, u8 pin, u8 max_port)
+static u8 rzg2l_pin_to_oen_bit(u32 port, u8 pin, u8 max_port)
 {
-	if (pin)
-		pin *= 2;
+	u8 bit = pin * 2;
 
-	if (offset / RZG2L_PINS_PER_PORT == max_port)
-		pin += 1;
+	if (port == max_port)
+		bit += 1;
 
-	return pin;
+	return bit;
 }
 
-static u32 rzg2l_read_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8 pin)
+static u32 rzg2l_read_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 port, u8 pin)
 {
 	u8 max_port = pctrl->data->hwcfg->oen_max_port;
 	u8 max_pin = pctrl->data->hwcfg->oen_max_pin;
@@ -1045,12 +1044,12 @@ static u32 rzg2l_read_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8
 	if (!rzg2l_oen_is_supported(caps, pin, max_pin))
 		return 0;
 
-	bit = rzg2l_pin_to_oen_bit(offset, pin, max_port);
+	bit = rzg2l_pin_to_oen_bit(port, pin, max_port);
 
 	return !(readb(pctrl->base + ETH_MODE) & BIT(bit));
 }
 
-static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8 pin, u8 oen)
+static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 port, u8 pin, u8 oen)
 {
 	u8 max_port = pctrl->data->hwcfg->oen_max_port;
 	u8 max_pin = pctrl->data->hwcfg->oen_max_pin;
@@ -1060,7 +1059,7 @@ static int rzg2l_write_oen(struct rzg2l_pinctrl *pctrl, u32 caps, u32 offset, u8
 	if (!rzg2l_oen_is_supported(caps, pin, max_pin))
 		return -EINVAL;
 
-	bit = rzg2l_pin_to_oen_bit(offset, pin, max_port);
+	bit = rzg2l_pin_to_oen_bit(port, pin, max_port);
 
 	spin_lock_irqsave(&pctrl->lock, flags);
 	val = readb(pctrl->base + ETH_MODE);
@@ -1112,7 +1111,7 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
 		break;
 
 	case PIN_CONFIG_OUTPUT_ENABLE:
-		arg = rzg2l_read_oen(pctrl, cfg, _pin, bit);
+		arg = rzg2l_read_oen(pctrl, cfg, RZG2L_PIN_ID_TO_PORT(_pin), bit);
 		if (!arg)
 			return -EINVAL;
 		break;
@@ -1220,7 +1219,8 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
 
 		case PIN_CONFIG_OUTPUT_ENABLE:
 			arg = pinconf_to_config_argument(_configs[i]);
-			ret = rzg2l_write_oen(pctrl, cfg, _pin, bit, !!arg);
+			ret = rzg2l_write_oen(pctrl, cfg,
+					      RZG2L_PIN_ID_TO_PORT(_pin), bit, !!arg);
 			if (ret)
 				return ret;
 			break;
-- 
2.39.2


  reply	other threads:[~2024-05-24  9:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-24  9:45 [PATCH 0/9] Configure GbEth for RGMII on RZ/G2L family Paul Barker
2024-05-24  9:45 ` Paul Barker [this message]
2024-05-30 12:47   ` [PATCH 1/9] pinctrl: renesas: rzg2l: Fix variable names in OEN functions Geert Uytterhoeven
2024-05-24  9:45 ` [PATCH 2/9] pinctrl: renesas: rzg2l: Refactor pin to OEN bit translation Paul Barker
2024-05-30 12:51   ` Geert Uytterhoeven
2024-05-30 13:55     ` Paul Barker
2024-05-24  9:45 ` [PATCH 3/9] pinctrl: renesas: rzg2l: Support output enable on RZ/G2L Paul Barker
2024-05-30 13:13   ` Geert Uytterhoeven
2024-05-24  9:45 ` [PATCH 4/9] arm64: dts: renesas: rzg2l: Enable Ethernet TXC output Paul Barker
2024-05-30 13:40   ` Geert Uytterhoeven
2024-05-24  9:45 ` [PATCH 5/9] arm64: dts: renesas: rzg2lc: " Paul Barker
2024-05-30 13:47   ` Geert Uytterhoeven
2024-05-24  9:46 ` [PATCH 6/9] arm64: dts: renesas: rzg2ul: " Paul Barker
2024-05-30 13:50   ` Geert Uytterhoeven
2024-05-24  9:46 ` [PATCH 7/9] arm64: dts: renesas: rzg2l: Set Ethernet PVDD to 1.8V Paul Barker
2024-05-30 13:51   ` Geert Uytterhoeven
2024-05-24  9:46 ` [PATCH 8/9] arm64: dts: renesas: rzg2lc: " Paul Barker
2024-05-30 13:51   ` Geert Uytterhoeven
2024-05-24  9:46 ` [PATCH 9/9] arm64: dts: renesas: rzg2ul: " Paul Barker
2024-05-30 13:51   ` Geert Uytterhoeven

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=20240524094603.988-2-paul.barker.ct@bp.renesas.com \
    --to=paul.barker.ct@bp.renesas.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=krzk+dt@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=robh@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).