All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Rosin <peda@axentia.se>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Ludovic Desroches <ludovic.desroches@microchip.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>
Subject: [PATCH] pinctrl: at91: allow use of of gpio-line-names property
Date: Tue, 7 Dec 2021 00:32:03 +0100	[thread overview]
Message-ID: <4d17866a-d9a4-a3d7-189a-781d18dbea00@axentia.se> (raw)

If no line name is given (by not having a gpio-line-names property,
or by having empty "" strings for some lines), fall back to the
existing pioC12-style line name scheme.

It is useful to be able to explicitly name lines from the schematics
or its function, rather than having the MCU names forced upon every
user.

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/pinctrl/pinctrl-at91.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

I don't know if it's sane to fall back to the pioC12-style on empty
strings, or if someone adding a gpio-line-names property should be
responsible for filling in those names "by hand". I generally don't
care what "unused" pins are named, so either is fine by me...

Cheers,
Peter

diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 6022496bb6a9..4f108d07e6ad 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -1821,7 +1821,7 @@ static int at91_gpio_probe(struct platform_device *pdev)
 	int irq, i;
 	int alias_idx = of_alias_get_id(np, "gpio");
 	uint32_t ngpio;
-	char **names;
+	const char **names;
 
 	BUG_ON(alias_idx >= ARRAY_SIZE(gpio_chips));
 	if (gpio_chips[alias_idx]) {
@@ -1890,8 +1890,15 @@ static int at91_gpio_probe(struct platform_device *pdev)
 		goto clk_enable_err;
 	}
 
-	for (i = 0; i < chip->ngpio; i++)
-		names[i] = kasprintf(GFP_KERNEL, "pio%c%d", alias_idx + 'A', i);
+	if (of_property_read_string_array(np, "gpio-line-names",
+					  names, chip->ngpio) != chip->ngpio)
+		memset(names, 0, chip->ngpio * sizeof(char *));
+
+	for (i = 0; i < chip->ngpio; i++) {
+		if (!names[i] || !names[i][0])
+			names[i] = kasprintf(GFP_KERNEL,
+					     "pio%c%d", alias_idx + 'A', i);
+	}
 
 	chip->names = (const char *const *)names;
 
-- 
2.20.1


WARNING: multiple messages have this Message-ID (diff)
From: Peter Rosin <peda@axentia.se>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	Ludovic Desroches <ludovic.desroches@microchip.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: [PATCH] pinctrl: at91: allow use of of gpio-line-names property
Date: Tue, 7 Dec 2021 00:32:03 +0100	[thread overview]
Message-ID: <4d17866a-d9a4-a3d7-189a-781d18dbea00@axentia.se> (raw)

If no line name is given (by not having a gpio-line-names property,
or by having empty "" strings for some lines), fall back to the
existing pioC12-style line name scheme.

It is useful to be able to explicitly name lines from the schematics
or its function, rather than having the MCU names forced upon every
user.

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/pinctrl/pinctrl-at91.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

I don't know if it's sane to fall back to the pioC12-style on empty
strings, or if someone adding a gpio-line-names property should be
responsible for filling in those names "by hand". I generally don't
care what "unused" pins are named, so either is fine by me...

Cheers,
Peter

diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 6022496bb6a9..4f108d07e6ad 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -1821,7 +1821,7 @@ static int at91_gpio_probe(struct platform_device *pdev)
 	int irq, i;
 	int alias_idx = of_alias_get_id(np, "gpio");
 	uint32_t ngpio;
-	char **names;
+	const char **names;
 
 	BUG_ON(alias_idx >= ARRAY_SIZE(gpio_chips));
 	if (gpio_chips[alias_idx]) {
@@ -1890,8 +1890,15 @@ static int at91_gpio_probe(struct platform_device *pdev)
 		goto clk_enable_err;
 	}
 
-	for (i = 0; i < chip->ngpio; i++)
-		names[i] = kasprintf(GFP_KERNEL, "pio%c%d", alias_idx + 'A', i);
+	if (of_property_read_string_array(np, "gpio-line-names",
+					  names, chip->ngpio) != chip->ngpio)
+		memset(names, 0, chip->ngpio * sizeof(char *));
+
+	for (i = 0; i < chip->ngpio; i++) {
+		if (!names[i] || !names[i][0])
+			names[i] = kasprintf(GFP_KERNEL,
+					     "pio%c%d", alias_idx + 'A', i);
+	}
 
 	chip->names = (const char *const *)names;
 
-- 
2.20.1


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

             reply	other threads:[~2021-12-06 23:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 23:32 Peter Rosin [this message]
2021-12-06 23:32 ` [PATCH] pinctrl: at91: allow use of of gpio-line-names property Peter Rosin
2021-12-08 12:33 ` Alexander Dahl
2021-12-08 12:33   ` Alexander Dahl
2021-12-08 16:09   ` Peter Rosin
2021-12-08 16:09     ` Peter Rosin
2021-12-08 16:28   ` Andy Shevchenko
2021-12-08 16:28     ` Andy Shevchenko
2021-12-09 11:23     ` Peter Rosin
2021-12-09 11:23       ` Peter Rosin

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=4d17866a-d9a4-a3d7-189a-781d18dbea00@axentia.se \
    --to=peda@axentia.se \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ludovic.desroches@microchip.com \
    --cc=nicolas.ferre@microchip.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 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.