xenomai.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Xenomai <xenomai@lists.linux.dev>
Subject: [PATCH] drivers: gpio: Start to switch away from gpiochip_find
Date: Sat, 9 Dec 2023 10:04:24 +0100	[thread overview]
Message-ID: <02919913-1618-423e-a7cb-43810e11a51c@siemens.com> (raw)

From: Jan Kiszka <jan.kiszka@siemens.com>

This was removed in 6.7 for the sake of safe reference counting. Do not
switch to the kernel model yet, just mitigate the API change. We will
have to rework the RTDM GPIO API later on to fully support this valid
step of the kernel.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 kernel/drivers/gpio/gpio-core.c  | 19 +++++++++++++++++++
 kernel/drivers/spi/spi-bcm2835.c | 12 ++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/kernel/drivers/gpio/gpio-core.c b/kernel/drivers/gpio/gpio-core.c
index e12733466e..e41c640504 100644
--- a/kernel/drivers/gpio/gpio-core.c
+++ b/kernel/drivers/gpio/gpio-core.c
@@ -516,16 +516,31 @@ int rtdm_gpiochip_post_event(struct rtdm_gpio_chip *rgc,
 }
 EXPORT_SYMBOL_GPL(rtdm_gpiochip_post_event);
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,7,0)
 static int gpiochip_match_name(struct gpio_chip *chip, void *data)
 {
 	const char *name = data;
 
 	return !strcmp(chip->label, name);
 }
+#endif
 
 static struct gpio_chip *find_chip_by_name(const char *name)
 {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,7,0)
+	struct gpio_device *gd;
+	struct gpio_chip *chip;
+
+	gd = gpio_device_find_by_label(name);
+	if (gd)
+		return NULL;
+
+	chip = gpio_device_get_chip(gd);
+	gpio_device_put(gd);
+	return chip;
+#else
 	return gpiochip_find((void *)name, gpiochip_match_name);
+#endif
 }
 
 int rtdm_gpiochip_add_by_name(struct rtdm_gpio_chip *rgc,
@@ -637,7 +652,11 @@ int rtdm_gpiochip_scan_of(struct device_node *from, const char *compat,
 			break;
 		match.parent = &pdev->dev;
 		INIT_LIST_HEAD(&match.list);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,7,0)
+		gpio_device_find(&match, match_gpio_chip);
+#else
 		gpiochip_find(&match, match_gpio_chip);
+#endif
 		if (!list_empty(&match.list)) {
 			ret = 0;
 			list_for_each_entry_safe(h, n, &match.list, next) {
diff --git a/kernel/drivers/spi/spi-bcm2835.c b/kernel/drivers/spi/spi-bcm2835.c
index e8df8fe7e0..2d50b86080 100644
--- a/kernel/drivers/spi/spi-bcm2835.c
+++ b/kernel/drivers/spi/spi-bcm2835.c
@@ -446,10 +446,12 @@ static void bcm2835_mmap_release(struct rtdm_spi_remote_slave *slave)
 	bcm->io_len = 0;
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,7,0)
 static int gpio_match_name(struct gpio_chip *chip, void *data)
 {
 	return !strcmp(chip->label, data);
 }
+#endif
 
 static int find_cs_gpio(struct spi_device *spi)
 {
@@ -487,9 +489,19 @@ static int find_cs_gpio(struct spi_device *spi)
 
 	/* If that failed, assume GPIOs 7-11 are used */
 	if (!gpio_is_valid(cs_gpio)) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,7,0)
+		struct gpio_device *gd;
+
+		gd = gpio_device_find_by_label("pinctrl-bcm2835");
+		if (!gd)
+			return 0;
+		chip = gpio_device_get_chip(gd);
+		gpio_device_put(gd);
+#else
 		chip = gpiochip_find("pinctrl-bcm2835", gpio_match_name);
 		if (chip == NULL)
 			return 0;
+#endif
 
 		cs_gpio = chip->base + 8 - spi->chip_select;
 	}
-- 
2.35.3

                 reply	other threads:[~2023-12-09  9:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=02919913-1618-423e-a7cb-43810e11a51c@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=xenomai@lists.linux.dev \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).