From: John Crispin <john@phrozen.org>
To: Lorenzo Bianconi <lorenzo@kernel.org>, Lee Jones <lee@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>
Cc: Ahmed Naseef <naseefkm@gmail.com>,
Benjamin Larsson <benjamin.larsson@genexis.eu>,
Christian Marangi <ansuelsmth@gmail.com>,
devicetree@vger.kernel.org, lei.dong@airoha.com,
Linqi.zhang@airoha.com, linux-gpio@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
mfd@lists.linux.dev,
Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>,
Rajeev.kumar@airoha.com, upstream@airoha.com,
Weifeng.xu@airoha.com, zhengping.zhang@airoha.com
Subject: [PATCH 2/7] pinctrl: airoha: add per pin mode field mux
Date: Tue, 10 Nov 2026 18:39:36 +0100 [thread overview]
Message-ID: <20261110173941.301478-3-john@phrozen.org> (raw)
In-Reply-To: <20261110173941.301478-1-john@phrozen.org>
Newer Airoha SoCs select the function of a pin through a mode field in
a dedicated IOMUX block instead of through function specific bits in
the chip SCU. The AN7589 has a 4 bit field per pin, eight pins per 32
bit register. A group can then need one register write per pin, and
the two entry regmap[] of a function group cannot carry that.
Let a function group supply a pin_modes[] array, parallel to the pins
of the group. When it is set, set_mux writes each mode into the IOMUX
regmap and then applies the regmap[] entries of the group, so a group
can combine its pin modes with a register write in the GPIO block.
A SoC with an IOMUX describes it in its match data with struct
airoha_pinctrl_iomux, which holds the width of the mode field. Probe
then takes the regmap from the airoha,iomux phandle.
No functional change for the existing SoCs.
Signed-off-by: John Crispin <john@phrozen.org>
---
drivers/pinctrl/airoha/airoha-common.h | 14 ++++++++
drivers/pinctrl/airoha/pinctrl-airoha.c | 48 +++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/drivers/pinctrl/airoha/airoha-common.h b/drivers/pinctrl/airoha/airoha-common.h
index 850e733db15a..7a0cb8924e71 100644
--- a/drivers/pinctrl/airoha/airoha-common.h
+++ b/drivers/pinctrl/airoha/airoha-common.h
@@ -49,6 +49,12 @@
.group_size = ARRAY_SIZE(table##_func_group), \
}
+#define PINCTRL_MODE_FUNC_GROUP(id, table) \
+ { \
+ .name = id, \
+ .pin_modes = table##_modes, \
+ }
+
#define PINCTRL_CONF_DESC(p, offset, mask) \
{ \
.pin = p, \
@@ -75,6 +81,7 @@ struct airoha_pinctrl_func_group {
u32 val;
} regmap[2];
int regmap_size;
+ const u8 *pin_modes;
};
struct airoha_pinctrl_func {
@@ -102,6 +109,10 @@ struct airoha_gpiochip_regs {
extern const struct airoha_gpiochip_regs airoha_gpiochip_regs_64;
+struct airoha_pinctrl_iomux {
+ u8 mode_bits;
+};
+
struct airoha_pinctrl_confs_info {
const struct airoha_pinctrl_conf *confs;
unsigned int num_confs;
@@ -126,6 +137,8 @@ struct airoha_pinctrl {
const struct airoha_pinctrl_confs_info *confs_info;
struct regmap *chip_scu;
+ struct regmap *iomux;
+ const struct airoha_pinctrl_iomux *iomux_info;
struct regmap *regmap;
struct gpio_chip gpiochip;
@@ -135,6 +148,7 @@ struct airoha_pinctrl {
struct airoha_pinctrl_match_data {
const char *chip_scu_compatible;
+ const struct airoha_pinctrl_iomux *iomux_info;
const char *pinctrl_name;
struct module *pinctrl_owner;
const struct airoha_gpiochip_regs *gpio_regs;
diff --git a/drivers/pinctrl/airoha/pinctrl-airoha.c b/drivers/pinctrl/airoha/pinctrl-airoha.c
index b50108826d8d..f9ae4020b764 100644
--- a/drivers/pinctrl/airoha/pinctrl-airoha.c
+++ b/drivers/pinctrl/airoha/pinctrl-airoha.c
@@ -401,6 +401,35 @@ static int airoha_pinctrl_add_gpiochip(struct airoha_pinctrl *pinctrl,
}
/* pinmux callbacks */
+static int airoha_pinmux_set_pin_mode(struct airoha_pinctrl *pinctrl,
+ unsigned int pin, u8 mode)
+{
+ unsigned int mode_bits = pinctrl->iomux_info->mode_bits;
+ unsigned int modes_per_reg = sizeof(u32) * BITS_PER_BYTE / mode_bits;
+ unsigned int shift = (pin % modes_per_reg) * mode_bits;
+ unsigned int reg = (pin / modes_per_reg) * sizeof(u32);
+
+ return regmap_update_bits(pinctrl->iomux, reg,
+ GENMASK(mode_bits - 1, 0) << shift,
+ mode << shift);
+}
+
+static int airoha_pinmux_set_pin_modes(struct airoha_pinctrl *pinctrl,
+ const struct group_desc *grp,
+ const u8 *modes)
+{
+ int i, err;
+
+ for (i = 0; i < grp->grp.npins; i++) {
+ err = airoha_pinmux_set_pin_mode(pinctrl, grp->grp.pins[i],
+ modes[i]);
+ if (err)
+ return err;
+ }
+
+ return 0;
+}
+
static int airoha_pinmux_set_mux(struct pinctrl_dev *pctrl_dev,
unsigned int selector,
unsigned int group)
@@ -431,6 +460,15 @@ static int airoha_pinmux_set_mux(struct pinctrl_dev *pctrl_dev,
if (strcmp(group->name, grp->grp.name))
continue;
+ if (group->pin_modes) {
+ int err;
+
+ err = airoha_pinmux_set_pin_modes(pinctrl, grp,
+ group->pin_modes);
+ if (err)
+ return err;
+ }
+
for (j = 0; j < group->regmap_size; j++) {
switch (group->regmap[j].mux) {
case AIROHA_FUNC_PWM_EXT_MUX:
@@ -824,6 +862,16 @@ int airoha_pinctrl_probe(struct platform_device *pdev)
pinctrl->chip_scu = map;
+ if (data->iomux_info) {
+ map = syscon_regmap_lookup_by_phandle(dev->of_node,
+ "airoha,iomux");
+ if (IS_ERR(map))
+ return PTR_ERR(map);
+
+ pinctrl->iomux = map;
+ pinctrl->iomux_info = data->iomux_info;
+ }
+
/* Init pinctrl desc struct */
pinctrl->desc.name = data->pinctrl_name;
pinctrl->desc.owner = data->pinctrl_owner;
--
2.34.1
next prev parent reply other threads:[~2026-11-10 17:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 17:39 [PATCH 0/7] pinctrl: airoha: add AN7589 support John Crispin
2026-11-10 17:39 ` [PATCH 1/7] pinctrl: airoha: make gpio register layout per SoC John Crispin
2026-11-10 17:39 ` John Crispin [this message]
2026-11-10 17:39 ` [PATCH 3/7] pinctrl: airoha: make the chip SCU optional John Crispin
2026-11-10 17:39 ` [PATCH 4/7] pinctrl: airoha: mux a requested GPIO through the IOMUX John Crispin
2026-11-10 17:39 ` [PATCH 5/7] dt-bindings: pinctrl: airoha: add AN7589 John Crispin
2026-11-10 18:27 ` Conor Dooley
2026-11-10 17:39 ` [PATCH 6/7] pinctrl: airoha: move the GPIO register offsets to the common header John Crispin
2026-11-10 17:39 ` [PATCH 7/7] pinctrl: airoha: add support of an7589 SoC John Crispin
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=20261110173941.301478-3-john@phrozen.org \
--to=john@phrozen.org \
--cc=Linqi.zhang@airoha.com \
--cc=Rajeev.kumar@airoha.com \
--cc=Weifeng.xu@airoha.com \
--cc=ansuelsmth@gmail.com \
--cc=benjamin.larsson@genexis.eu \
--cc=brgl@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=lei.dong@airoha.com \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=lorenzo@kernel.org \
--cc=mfd@lists.linux.dev \
--cc=mikhail.kshevetskiy@iopsys.eu \
--cc=naseefkm@gmail.com \
--cc=robh@kernel.org \
--cc=upstream@airoha.com \
--cc=zhengping.zhang@airoha.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®