From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (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 02F68322A1F for ; Sun, 8 Mar 2026 09:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772961634; cv=none; b=i4JWaMm3CoiMvT/UqXTjUkD9iuzPYefhJL4EEs+QowAlysgp9NmkNgEA3s4RGcHL4QTPJ8kIfLSDMuDF2ZMhkFct9A0TdbMW20cJuqj2hZFOWWHQWAFuPaEFgRFJ6myCSw1ZIPUK+yjLkIlkH8hM94Olj/qrdPUtgSQZVUxPlrw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772961634; c=relaxed/simple; bh=0LZDtn8JtPRJMlCx1W8pvuWB7H8Xp1Sg7TEx3GBZpOA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hAgfApL4M6lbGsMwNEIjkOxzdaKQSAV0YZKPrCBcmIhZF9a9ldy1fU5fY/8MSmGl5l1Bmea5suF+jyCjq9LTMv7iMM3pSnK/Z8LIGwEMly5t8b+Cc5EHIZl7WSZDuihs+TJ9EtoVEh4hecqdRkdxeA8OZx00m/rtxs75XlskhvU= 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=HY+9Mjn5; arc=none smtp.client-ip=209.85.219.42 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="HY+9Mjn5" Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-89a000f5adeso128503106d6.3 for ; Sun, 08 Mar 2026 01:20:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772961631; x=1773566431; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=VCfP2n03UmP2Gyi/wszYkFcZJsFegmS+/KM+muaSkU8=; b=HY+9Mjn51AMEBiuvEjnuREtBGbYhdIqGj8zX7oXx62JGzm0EpxGAzqljmhZN49TvJ+ nDhRHA0MzMaG7IbbUKaNITJ/ngqEC+C3Q9Rjx4Zn+jDImaHTWDlRPxWMD0Rx1s9Xc1FN +UNzMqomthkCpcgUByj+cSUcacII9iCw0UYIMvUdZ9c4wQRrQuvdIOJS2Z1ZG6daUuXx quF2jcLlViFP4jkwWMYy/jgbB0WiTFGHcQvqLvQ9r0albrCjeA0mngGDFYovzX4lUUlw zO2ju9+LVo0qnMRvJizqf3uF9dLq7a2UoY47E0zdjSU4HWRK+Zf2wca/HqXKceHo5xGD pl9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772961631; x=1773566431; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VCfP2n03UmP2Gyi/wszYkFcZJsFegmS+/KM+muaSkU8=; b=QFRuCT0oT7wFn6WTUge6+TBtx8eLS047UxdD74adtY2X4TBBuJ+R2i3hLOgNAYRuUN BkKTJw92XO4XxQYPKsaukvPnaS5/vVcC8+FO7wH3DJDAipYQzgOKyMmCRGXvhGK1OZ9Q ZvHoCC24XYHDvtvb7f6EoapKT8priqrl+Ox2wsteAKZ7rA/fBzfy9lGkRlGlWheG72kX iro27E9N98joPfuRsUTmYCYqMancbhDeU9pEO4/IvBhITa+buhbEiH0KnDsSG4Yqt+VV pMLQKLfTh+hcsO6sREFbL7prJPkrEp4cFa65b4tLtxqEGeEVANWbqiTa4+wDRS5S+aeN vj4w== X-Forwarded-Encrypted: i=1; AJvYcCUQgKEmyv3OhGniqfMyrPGP85aE9hZ5U08Wfj+7Ql0ipd+2BdSU+IlC4M/xQwwLXFdrzEQeJ/XTtwQq1pc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz02EdfgE9fqzIQtOqeGKG+eqdoqaSYktqBDpll1qqnT19Ln2Vr LMq880X6FVhF/+WtrztRk6GUk4W+EjgKGzPiFSEU2pnpYiw3iZ7tv3m5tgwtAU+s X-Gm-Gg: ATEYQzxW8DKFsGdOV78L1SFfkipHpz4he4KyPbNhdBDL4cr/ETD40LsprWrTh4g2CKu KB/CuMwX+HR7AEj+rgOk6zJ5UIPmWzuBpc9KujBYzchO7HXEnBH/5xmG300GP2nWRXVDj7AborJ Pls9g+ZWSWnUUuMS8RSS1Z8om0hlVm/ewd+CpdlpMbHXySpa5vYgZRSPCG2uyAVrY5hGiJSk4IP ig62M/Cf8lYzL/I6qd4N4m+er8KR86+0XzjF9i4wtSMexNoHj2poitiYNGD8GTFGSlW6e9rHIFJ xk77S430LMnGTPIdr7Jad6l96nHBfGlLEGASCqR1tpH0O+ehHc8tYVdAxX15xZ67OSsbi7oze9/ 8WI4etxljlLxP8Ni/y+saDC6tpDxPyQq840WvLSydi3RlXleXDUFwfNlWROF13wAdZVUEHn9wqa LLVCJoW7P+FhVR9hATcSvxf2kG/DZN X-Received: by 2002:a05:6214:248b:b0:89a:929:9e4e with SMTP id 6a1803df08f44-89a30a174cbmr113884606d6.14.1772961630635; Sun, 08 Mar 2026 01:20:30 -0800 (PST) Received: from localhost ([94.19.228.143]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89a316da67esm51697736d6.25.2026.03.08.01.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Mar 2026 01:20:30 -0800 (PST) Date: Sun, 8 Mar 2026 12:20:28 +0300 From: Andrey Skvortsov To: Chen-Yu Tsai Cc: Jernej Skrabec , Samuel Holland , Linus Walleij , James Hilliard , aprizel@wens.tw, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec , Bartosz Golaszewski Subject: Re: [PATCH v2] pinctrl: sunxi: Implement gpiochip::get_direction() Message-ID: Mail-Followup-To: Andrey Skvortsov , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Linus Walleij , James Hilliard , aprizel@wens.tw, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec , Bartosz Golaszewski References: <20260224092419.1275016-1-wens@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20260224092419.1275016-1-wens@kernel.org> On 26-02-24 17:24, Chen-Yu Tsai wrote: > After commit 471e998c0e31 ("gpiolib: remove redundant callback check"), > a warning will be printed if the gpio driver does not implement this > callback. The warning was added in commit e623c4303ed1 ("gpiolib: > sanitize the return value of gpio_chip::get_direction()"), but was > masked by the "redundant" check. > > The warning can be triggered by any action that calls the callback, > such as dumping the GPIO state from /sys/kernel/debug/gpio. > > Implement it for the sunxi driver. This is simply a matter of reading > out the mux value from the registers, then checking if it is one of > the GPIO functions and which direction it is. > > Signed-off-by: Chen-Yu Tsai > Reviewed-by: Jernej Skrabec > Reviewed-by: Bartosz Golaszewski > --- > Please merge for fixes. > > Changes since v1: > - Corrected commit attribution for the warning > - Add example scenario that triggers the warning > --- > drivers/pinctrl/sunxi/pinctrl-sunxi.c | 51 +++++++++++++++++++++++++++ > 1 file changed, 51 insertions(+) > > diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c > index 0fb057a07dcc..27b2a3e9d78d 100644 > --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c > +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c > @@ -204,6 +204,32 @@ sunxi_pinctrl_desc_find_function_by_pin(struct sunxi_pinctrl *pctl, > return NULL; > } > > +static struct sunxi_desc_function * > +sunxi_pinctrl_desc_find_function_by_pin_and_mux(struct sunxi_pinctrl *pctl, > + const u16 pin_num, > + const u8 muxval) > +{ > + for (unsigned int i = 0; i < pctl->desc->npins; i++) { > + const struct sunxi_desc_pin *pin = pctl->desc->pins + i; > + struct sunxi_desc_function *func = pin->functions; > + > + if (pin->pin.number != pin_num) > + continue; > + > + if (pin->variant && !(pctl->variant & pin->variant)) > + continue; > + > + while (func->name) { > + if (func->muxval == muxval) > + return func; > + > + func++; > + } > + } > + > + return NULL; > +} > + > static int sunxi_pctrl_get_groups_count(struct pinctrl_dev *pctldev) > { > struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); > @@ -930,6 +956,30 @@ static const struct pinmux_ops sunxi_pmx_ops = { > .strict = true, > }; > > +static int sunxi_pinctrl_gpio_get_direction(struct gpio_chip *chip, > + unsigned int offset) > +{ > + struct sunxi_pinctrl *pctl = gpiochip_get_data(chip); > + const struct sunxi_desc_function *func; > + u32 pin = offset + chip->base; > + u32 reg, shift, mask; > + u8 muxval; > + > + sunxi_mux_reg(pctl, offset, ®, &shift, &mask); > + > + muxval = (readl(pctl->membase + reg) & mask) >> shift; > + > + func = sunxi_pinctrl_desc_find_function_by_pin_and_mux(pctl, pin, muxval); > + if (!func) > + return -ENODEV; This change introduces regression in linux-next. Several drivers on Allwinner A64 fail to probe. For example, gpio gpiochip1: (1c20800.pinctrl): gpiochip_lock_as_irq: cannot get GPIO direction sun50i-a64-pinctrl 1c20800.pinctrl: unable to lock HW IRQ 69 for IRQ genirq: Failed to request resources for inv_mpu (irq 163) on irqchip sunxi_pio_edge inv_mpu6050_i2c tries to get interrupt without initializing gpio before. muxval in the case of uninitialized gpio is 0x7 (IO Disable) and returned func value is NULL. Some pinctrl return error for alternate configuration. For example, pinctrl-stm32 returns -EINVAL [1]. But other drivers return one of non-error values. pinctrl-axp209 defaults to GPIO_LINE_DIRECTION_OUT [2] /* * This shouldn't really happen if the pin is in use already, * or if it's not in use yet, it doesn't matter since we're * going to change the value soon anyway. Default to output. */ if ((val & AXP20X_GPIO_FUNCTIONS) > 2) return GPIO_LINE_DIRECTION_OUT; pinctrl-upboard defaults to GPIO_LINE_DIRECTION_IN [3]. /* If the pin is in function mode or high-z, input direction is returned */ pinctrl-rza2 defaults to GPIO_LINE_DIRECTION_IN as well [4]. /* * This GPIO controller has a default Hi-Z state that is not input or * output, so force the pin to input now. */ Should default be here GPIO_LINE_DIRECTION_IN here as well instead of -ENODEV? > + if (!strcmp(func->name, "gpio_out")) > + return GPIO_LINE_DIRECTION_OUT; > + if (!strcmp(func->name, "gpio_in") || !strcmp(func->name, "irq")) > + return GPIO_LINE_DIRECTION_IN; > + return -EINVAL; Alternative solution would be converting handling of return value in gpiochip_lock_as_irq to warning level. Since the value dir isn't used. The call flushes the direction setting if something changed behind our back. [5] --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -4107,11 +4107,9 @@ int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset) if (!gc->can_sleep && gc->get_direction) { int dir = gpiod_get_direction(desc); - if (dir < 0) { - gpiochip_err(gc, "%s: cannot get GPIO direction\n", + if (dir < 0) + gpiochip_warn(gc, "%s: cannot get GPIO direction\n", __func__); - return dir; - } } 1. https://elixir.bootlin.com/linux/v7.0-rc1/source/drivers/pinctrl/stm32/pinctrl-stm32.c#L437 2. https://elixir.bootlin.com/linux/v7.0-rc1/source/drivers/pinctrl/pinctrl-axp209.c#L175 3. https://elixir.bootlin.com/linux/v7.0-rc1/source/drivers/pinctrl/pinctrl-upboard.c#L840 4. https://elixir.bootlin.com/linux/v7.0-rc1/source/drivers/pinctrl/renesas/pinctrl-rza2.c#L148 5. https://elixir.bootlin.com/linux/v7.0-rc1/source/drivers/gpio/gpiolib.c#L4084 -- Best regards, Andrey Skvortsov