mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Sam Ravnborg <sam@ravnborg.org>, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 09/11] pinctrl: at91: make deep-probe compatible
Date: Mon,  9 Jan 2023 14:08:20 +0100	[thread overview]
Message-ID: <20230109130822.1657470-10-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230109130822.1657470-1-a.fatoum@pengutronix.de>

GPIO banks are probed independently from pinctrl parent device as it's
simple-bus compatible. The pinctrl driver needs access to the GPIO
banks though for applying a pin configuration. This has two problems:

  - When we have a pinctrl hog, we can't apply it if GPIOs weren't
    probed before

  - In a deep probe system, pinctrl may be used before GPIO was probed

Fix this for deep probe systems by probing relevant GPIO banks on
demand. We wrap this in a deep_probe_is_supported() check to avoid
increasing code size for the configurations that use non-DT enabled
barebox proper as first stage bootloader.

Tested on SAMA5D4.

Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/pinctrl/pinctrl-at91.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 1f0a8fe038f3..b80fa85f829a 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -16,6 +16,7 @@
 #include <init.h>
 #include <driver.h>
 #include <getopt.h>
+#include <deep-probe.h>
 
 #include <mach/at91_pio.h>
 #include <mach/gpio.h>
@@ -47,17 +48,25 @@ struct at91_gpio_chip {
 #define DEBOUNCE_VAL_SHIFT      17
 #define DEBOUNCE_VAL    (0x3fff << DEBOUNCE_VAL_SHIFT)
 
-static int gpio_banks;
-
 static struct at91_gpio_chip gpio_chip[MAX_GPIO_BANKS];
 
 static inline struct at91_gpio_chip *pin_to_controller(unsigned pin)
 {
+	struct at91_gpio_chip *chip;
+
 	pin /= MAX_NB_GPIO_PER_BANK;
-	if (likely(pin < gpio_banks))
-		return &gpio_chip[pin];
+	if (unlikely(pin >= MAX_GPIO_BANKS))
+		return NULL;
+
+	chip = &gpio_chip[pin];
+
+	if (!chip->regbase && deep_probe_is_supported()) {
+		char alias[] = "gpioX";
+		scnprintf(alias, sizeof(alias), "gpio%u", pin);
+		of_device_ensure_probed_by_alias(alias);
+	}
 
-	return NULL;
+	return chip;
 }
 
 /**
@@ -652,7 +661,6 @@ static int at91_gpio_probe(struct device *dev)
 		return ret;
 	}
 
-	gpio_banks = max(gpio_banks, alias_idx + 1);
 	at91_gpio->regbase = dev_request_mem_region_err_null(dev, 0);
 	if (!at91_gpio->regbase)
 		return -ENOENT;
-- 
2.30.2




  parent reply	other threads:[~2023-01-09 13:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09 13:08 [PATCH v2 00/11] ARM: at91: sama5d4: add basic Wifx L1 support Ahmad Fatoum
2023-01-09 13:08 ` [PATCH v2 01/11] ARM: at91: sama5: switch to nonnaked entry functions Ahmad Fatoum
2023-01-09 13:08 ` [PATCH v2 02/11] ARM: at91: sama5d4: add entry point helpers Ahmad Fatoum
2023-01-09 13:08 ` [PATCH v2 03/11] ARM: at91: sama5d4: enable for DT use Ahmad Fatoum
2023-01-11 10:37   ` Sascha Hauer
2023-01-09 13:08 ` [PATCH v2 04/11] net: macb: match atmel,sama5d4-gem compatible Ahmad Fatoum
2023-01-09 13:08 ` [PATCH v2 05/11] i2c: at91: extend for SAMA5D4 support Ahmad Fatoum
2023-01-09 13:08 ` [PATCH v2 06/11] eeprom: at24: add 24mac402/602 support Ahmad Fatoum
2023-01-09 13:08 ` [PATCH v2 07/11] driver: always ensure probe of RAM registered with mem_platform_driver Ahmad Fatoum
2023-01-09 13:08 ` [PATCH v2 08/11] common: deep-probe: don't build without CONFIG_OFDEVICE Ahmad Fatoum
2023-01-09 13:08 ` Ahmad Fatoum [this message]
2023-01-09 13:08 ` [PATCH v2 10/11] ARM: at91: make bootsource code generic to all SAMA5 Ahmad Fatoum
2023-01-09 13:08 ` [PATCH v2 11/11] ARM: at91: SAMA5D4: add Wifx L1 support Ahmad Fatoum
2023-01-10 15:05 ` [PATCH v2 00/11] ARM: at91: sama5d4: add basic " Sascha Hauer

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=20230109130822.1657470-10-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=sam@ravnborg.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