From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75C57394798 for ; Thu, 3 Sep 2026 07:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788422397; cv=none; b=rBtnrSAd6tFuXBJpo9oi3XJ5bNGbr4ARBbvCQ4sqOeLmyyDfCbRn5YROFKhzZ1myzGrV1GT+QN/C+Pa7TF21F00aCS7+eOjmNjkb3I4qV41rgUkSNXfpCiS1Z1a/anTVyCYWqbNcM0PscxEZmKvgHEpgGRWJZQd1zR2axLkZv9Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788422397; c=relaxed/simple; bh=HO1YpOsp7AAqKVPegRZIkVg5ChPOPjxhcr+CFObZK4M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RhNvQ69qw0o4kmkhU6xkOPxL2vhswK7TxhLEro+qklCEU3dP4hM/7DX2+6jPCyGFQDmozGSAymerPwK74Pih5btRnxNaSBHV6H2iU+uKWhMHk5JgyvUSi1vC/FTPhVH2lIuDtTnCxhKxzf9aUFFh2e4xjWcotc55sPf92Nby5iM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CUDwotpc; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CUDwotpc" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-49b0d78a801so16571065e9.2 for ; Thu, 03 Sep 2026 00:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788422394; x=1789027194; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yGVy22n2k2x8Vmi+YjiPo8Onst4nWhBMCSM53hHrhOk=; b=CUDwotpcu1rPFfd/TZDrqVUrX7I/Iwfxb6UdmdAilTqBNE8RyQczu5qUXydrbhTW7k 6ITV8aIczwx1gFf/EyyQSxucAbTDDJC6Bb6L0oIifkLqIdfRhVj6yuz9HECW4jv7WxnE MgstUSOf09EVnn5PQmOu1j8kxhTdcFR/VanOxvaL8a/VmwTkumqhx6qtHCw+UXoLttZh VRR6QAv/Zs5AUAt1GTU/yNXQheWjnvlUtCAzbkcn8Qf5jrr9C0uaimKzy4IrmYaaubsg USEYjr6LfPv7eDBe+IdN7YDTd0Oqvt/4lKjOUpDSQhttKbohhyg9f3aUB2FUuj+1S5YQ L2Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788422394; x=1789027194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=yGVy22n2k2x8Vmi+YjiPo8Onst4nWhBMCSM53hHrhOk=; b=JBguPwdZJKI0AKMp5QbnqTKchD2zkUQgt5r/pCrwcZz+1WEJWfd0u2ZXbCIugHkbos Pthe+9wZpGEa+auJAmI91W1d7T6RM+tK+rXQlYPBps1LaphQVI5jRUiaDTrq4tiX+Ocx ySyU8vwz42pRW+Gh5OOPenWcy/eb8fi/e8yhH/K+dY08+1f0XnZhV8ScCOw0A+wC5Cb3 8as9EQf6n0OKkkgPZngQhprWKHBaV+Ccd0im+l6kJWGYMINnK+eRDAwqCFNJcH1JSLSW BuOvVoB+W4do3ufLMibDqT4yQ4azQkJjJN//c/svHf6Oq9rv4sKGlOb2Nt/mn5WVecS3 htBQ== X-Forwarded-Encrypted: i=1; AKwUvBzlmpqNmlre/wbzF+PIt5OULkKibA4c00h70sA0f0+lflCe0/gBkFppvQhKtHsov2WajL0=@lists.linux.dev X-Gm-Message-State: AFuF++nwTVnfuP8AhWdq3sLpYxYmAAyXCh0dqm8vw0wkwinEpDNeItew FXkLjGfM9g6Dkqigrx0rHW3x/4B1fapWaDh9TPGllUE3mYdj24fT7kAQ X-Gm-Gg: AYBFou1IrZzi+uqV+/u6LpnnRAIp1KVvnrCrdukGISELYSBIpPre09+WGao9QELM+ij 7ibhptu7UmTf0PWv1XZqR8ELVIDeWTdEfyruRwekL3kh/Jx4aIl72F/abtO3rszSx1aStI+Fi3F 8Wh2BeErqiNR0Tbu2AyDvPKWLC96ryVX7tfZMmewogO8jX+D2lkyOzZF3blbhUvXPDjq9sPImmV hzjvjzVlWjDNVPm+RI2IN/7iqQU8lmgrl8v7RswOgF7vpPt1mFSJWY2fdXxLoTMvFSxtbqo1bTg 1Y2IOBADe/mO8Nc81UK3oYFGmKaifH+pe/I+TNDiAuLK3ypIoMwUMJoMM5Y9ZIVJe76FXE9WLgA jPokfoOS3cSXrIjfzRUh1OL4Wk9XlYr5ulzsSt/h9ZN48sRDS5hQlibHmtlXmWl32QxVBdgvvCk oKmwimLze3dmilxgE0Uburw/jHEcYGaQeOM9Mtpm87vJHt8aYiPtxFjdCg5urOch6lIA== X-Received: by 2002:a05:600c:621b:b0:499:dbae:86be with SMTP id 5b1f17b1804b1-49ce58352ccmr202005745e9.14.1788422385163; Thu, 03 Sep 2026 00:59:45 -0700 (PDT) Received: from deb05.proceq.com ([213.160.61.66]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49cee3b0af8sm52373275e9.0.2026.09.03.00.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 00:59:44 -0700 (PDT) From: Mehmet Fide To: Bartosz Golaszewski , Linus Walleij Cc: Dong Aisheng , Fabio Estevam , Frank Li , Jacky Bai , Sascha Hauer , Pengutronix Kernel Team , imx@lists.linux.dev, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mehmet Fide Subject: [PATCH v5 3/3] gpio: mmio: track the direction of chips without direction registers Date: Thu, 3 Sep 2026 09:59:40 +0200 Message-ID: <20260903075940.2089367-4-mehmet.fide@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260903075940.2089367-1-mehmet.fide@gmail.com> References: <20260903075940.2089367-1-mehmet.fide@gmail.com> Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Mehmet Fide A generic chip with GPIO_GENERIC_PINCTRL_BACKEND and no direction registers sets the direction through pinctrl but has no get_direction callback, so every gpiod_get_direction() call trips the WARN in gpiolib and the direction gpiolib reports is whatever it assumed. On a Vybrid Colibri module that is 21 backtraces per boot. Keep the direction of such a chip in the existing shadow: the direction setters update sdir under the chip lock, and get_direction() is the shadow-reading path already used for unreadable direction registers. That keeps the callback usable in atomic context, which it has to be: gpiochip_lock_as_irq() calls it for !can_sleep chips from gpiochip_irq_domain_activate(), under the irq descriptor lock. The pad's actual state is read once, in process context, when a line is requested: gpiolib calls request() right before get_direction() for a new line, so the shadow is seeded there from PIN_CONFIG_OUTPUT_ENABLE through the chip's get_config(), which is gpiochip_generic_get_config() for the pinctrl backend, and the line reports what the pin controller says. Lines pinctrl cannot answer for keep the input default, which is what gpiolib assumed before. Suggested-by: Bartosz Golaszewski Signed-off-by: Mehmet Fide --- drivers/gpio/gpio-mmio.c | 60 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c index 7e4b3e8d609f..0709ffaab4de 100644 --- a/drivers/gpio/gpio-mmio.c +++ b/drivers/gpio/gpio-mmio.c @@ -49,6 +49,7 @@ o ` ~~~~\___/~~~~ ` controller in FPGA is ,.` #include #include #include +#include #include #include #include @@ -372,7 +373,17 @@ static int gpio_mmio_dir_in_err(struct gpio_chip *gc, unsigned int gpio) static int gpio_mmio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) { - return gpio_mmio_dir_return(gc, gpio, false); + struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); + int ret; + + ret = gpio_mmio_dir_return(gc, gpio, false); + if (ret) + return ret; + + guard(raw_spinlock_irqsave)(&chip->lock); + chip->sdir &= ~gpio_mmio_line2mask(gc, gpio); + + return 0; } static int gpio_mmio_dir_out_err(struct gpio_chip *gc, unsigned int gpio, @@ -384,9 +395,19 @@ static int gpio_mmio_dir_out_err(struct gpio_chip *gc, unsigned int gpio, static int gpio_mmio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) { + struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); + int ret; + gc->set(gc, gpio, val); - return gpio_mmio_dir_return(gc, gpio, true); + ret = gpio_mmio_dir_return(gc, gpio, true); + if (ret) + return ret; + + guard(raw_spinlock_irqsave)(&chip->lock); + chip->sdir |= gpio_mmio_line2mask(gc, gpio); + + return 0; } static int gpio_mmio_dir_in(struct gpio_chip *gc, unsigned int gpio) @@ -601,20 +622,51 @@ static int gpio_mmio_setup_direction(struct gpio_generic_chip *chip, gc->direction_input = gpio_mmio_dir_in_err; else gc->direction_input = gpio_mmio_simple_dir_in; + + if (cfg->flags & GPIO_GENERIC_PINCTRL_BACKEND) { + chip->dir_unreadable = true; + gc->get_direction = gpio_mmio_get_dir; + gc->get_config = gpiochip_generic_get_config; + } } return 0; } +static void gpio_mmio_seed_dir_from_pinctrl(struct gpio_chip *gc, + unsigned int gpio) +{ + struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); + unsigned long config; + + if (!gc->get_config || chip->reg_dir_out || chip->reg_dir_in) + return; + + config = pinconf_to_config_packed(PIN_CONFIG_OUTPUT_ENABLE, 0); + if (gc->get_config(gc, gpio, &config)) + return; + + guard(raw_spinlock_irqsave)(&chip->lock); + if (config) + chip->sdir |= gpio_mmio_line2mask(gc, gpio); + else + chip->sdir &= ~gpio_mmio_line2mask(gc, gpio); +} + static int gpio_mmio_request(struct gpio_chip *gc, unsigned int gpio_pin) { struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); + int ret; if (gpio_pin >= gc->ngpio) return -EINVAL; - if (chip->pinctrl) - return gpiochip_generic_request(gc, gpio_pin); + if (chip->pinctrl) { + ret = gpiochip_generic_request(gc, gpio_pin); + if (ret) + return ret; + gpio_mmio_seed_dir_from_pinctrl(gc, gpio_pin); + } return 0; } -- 2.54.0