From: Emil Renner Berthing <emil.renner.berthing@canonical.com>
To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
devicetree@vger.kernel.org, linux-riscv@lists.infradead.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
Jisheng Zhang <jszhang@kernel.org>, Guo Ren <guoren@kernel.org>,
Fu Wei <wefu@redhat.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Thomas Bonnefille <thomas.bonnefille@bootlin.com>
Subject: [PATCH v1 3/3] pinctrl: th1520: Factor out casts
Date: Fri, 11 Oct 2024 16:48:25 +0200 [thread overview]
Message-ID: <20241011144826.381104-4-emil.renner.berthing@canonical.com> (raw)
In-Reply-To: <20241011144826.381104-1-emil.renner.berthing@canonical.com>
Limit the casts to get the mux data and flags from the driver data
pointer with each pin to two inline functions as requested by Andy
during review.
Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
---
drivers/pinctrl/pinctrl-th1520.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c
index 8bd40cb2f013..7474d8da32f9 100644
--- a/drivers/pinctrl/pinctrl-th1520.c
+++ b/drivers/pinctrl/pinctrl-th1520.c
@@ -152,6 +152,16 @@ static enum th1520_muxtype th1520_muxtype_get(const char *str)
(TH1520_MUX_##m0 << 0) | (TH1520_MUX_##m1 << 5) | (TH1520_MUX_##m2 << 10) | \
(TH1520_MUX_##m3 << 15) | (TH1520_MUX_##m4 << 20) | (TH1520_MUX_##m5 << 25)) }
+static unsigned long th1520_pad_muxdata(void *drv_data)
+{
+ return (uintptr_t)drv_data & TH1520_PAD_MUXDATA;
+}
+
+static bool th1520_pad_no_padcfg(void *drv_data)
+{
+ return (uintptr_t)drv_data & TH1520_PAD_NO_PADCFG;
+}
+
static const struct pinctrl_pin_desc th1520_group1_pins[] = {
TH1520_PAD(0, OSC_CLK_IN, ____, ____, ____, ____, ____, ____, TH1520_PAD_NO_PADCFG),
TH1520_PAD(1, OSC_CLK_OUT, ____, ____, ____, ____, ____, ____, TH1520_PAD_NO_PADCFG),
@@ -590,7 +600,7 @@ static int th1520_pinconf_get(struct pinctrl_dev *pctldev,
u32 value;
u32 arg;
- if ((uintptr_t)desc->drv_data & TH1520_PAD_NO_PADCFG)
+ if (th1520_pad_no_padcfg(desc->drv_data))
return -ENOTSUPP;
value = readl_relaxed(th1520_padcfg(thp, pin));
@@ -660,7 +670,7 @@ static int th1520_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
unsigned int i;
u16 mask, value;
- if ((uintptr_t)desc->drv_data & TH1520_PAD_NO_PADCFG)
+ if (th1520_pad_no_padcfg(desc->drv_data))
return -ENOTSUPP;
mask = 0;
@@ -793,12 +803,14 @@ static int th1520_pinmux_set_mux(struct pinctrl_dev *pctldev,
{
struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev);
const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel);
+ enum th1520_muxtype muxtype = (uintptr_t)func->data;
if (!func)
return -EINVAL;
+
return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
- (uintptr_t)thp->desc.pins[gsel].drv_data & TH1520_PAD_MUXDATA,
- (uintptr_t)func->data);
+ th1520_pad_muxdata(thp->desc.pins[gsel].drv_data),
+ muxtype);
}
static int th1520_gpio_request_enable(struct pinctrl_dev *pctldev,
@@ -809,7 +821,7 @@ static int th1520_gpio_request_enable(struct pinctrl_dev *pctldev,
const struct pin_desc *desc = pin_desc_get(pctldev, offset);
return th1520_pinmux_set(thp, offset,
- (uintptr_t)desc->drv_data & TH1520_PAD_MUXDATA,
+ th1520_pad_muxdata(desc->drv_data),
TH1520_MUX_GPIO);
}
--
2.43.0
next prev parent reply other threads:[~2024-10-11 14:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-11 14:48 [PATCH v1 0/3] pinctrl: th1520: Unbreak the driver Emil Renner Berthing
2024-10-11 14:48 ` [PATCH v1 1/3] pinctrl: th1520: Fix pinconf return values Emil Renner Berthing
2024-10-11 15:29 ` Drew Fustini
2024-10-11 14:48 ` [PATCH v1 2/3] pinctrl: th1520: Update pinmux tables Emil Renner Berthing
2024-10-11 16:31 ` Drew Fustini
2024-10-11 14:48 ` Emil Renner Berthing [this message]
2024-10-11 16:35 ` [PATCH v1 3/3] pinctrl: th1520: Factor out casts Drew Fustini
2024-10-16 18:45 ` Kees Bakker
2024-10-11 16:15 ` [PATCH v1 0/3] pinctrl: th1520: Unbreak the driver Drew Fustini
2024-10-11 19:28 ` Linus Walleij
2024-10-15 16:52 ` Drew Fustini
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=20241011144826.381104-4-emil.renner.berthing@canonical.com \
--to=emil.renner.berthing@canonical.com \
--cc=devicetree@vger.kernel.org \
--cc=guoren@kernel.org \
--cc=jszhang@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=thomas.bonnefille@bootlin.com \
--cc=wefu@redhat.com \
/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
all inboxes | Powered by JetHome®