From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387450; b=Rwar61VhQ/23tzBis+PjD4SOaD1xGBPIJy7w4c23cWmILmJkRcjX6Ndr2ZhNAaxTisPA 92d30tsya0sZzRuQ2y+hHIq+vf/h/XuZfCtXM4YMQHd/OC4sKKMMLZGjCUEvF2W8pYdCF wt69gj/iGyapJSL0IjWVVVfS8BLi44upCIQDdplrPf+7+iYhiW0m879P5+56T7sPZhNFf XlJkCn777vAsRXuHihPL6oNG6x2eg0xcr9vYk3FJust5dsBXKekUAKz9SHCxD19/Cbsbd t2SqYPqf/tU2yGtbwO9I+/i7g6bJW0WrlCKtYKkK02CAq/uVeKYphbZEe1tb5RxiUcg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387450; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=RwpKkYPJO+QWiM1MY03ddMMxL2hF/vanxqC0SUDfRIc=; b=QDHx8CK43wu1fH8P8/FPWWboygEL2BvliBx5XrLIVT/D84c/F4Fb9stAJBFzf2kB9DDo B8zZMwbfk0NmwxlL/s85UTx2rA299X3zSEYFo0BOJfsVLseN39XJ6unngRwvewUXBbvC6 8krlIVCIGFIXiivZCxcxkO8llpkdOF16RnuT4nuom1/xpzMhCSWLAHqkO19Ebxyvfg8xd KfMLMN3rWTY+QC+ngVRHLbNV9+3hwSpopV7pjdWoQOIQPc6Emt0N15YIVrXGr9VGf6BrM OJQdT1Ux61MZZ+LtW4pFyVZU85xR/YfC5PUZBWuRzcB8f5Lhwgi+Iu9tcCxTgL4mWew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=JzmenYTy; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A825606A32C; Fri, 4 Dec 2026 12:30:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=JzmenYTy Received: by smtp.kernel.org (Postfix) with ESMTPSA id 415F31F000C2; Fri, 4 Dec 2026 12:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387449; bh=RwpKkYPJO+QWiM1MY03ddMMxL2hF/vanxqC0SUDfRIc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JzmenYTyjm8bE+ZpF1txaJRUQgp3hP9YuCBngHD204fYvO/zfX9ZPnktowwmAwbV9 rVy7BozQJiOvsxvIB2FKyCJV85pswqQ6nETR8UDLpQEeLN+OHOi0dao7IBSUelPVAF Cge4JLnvSQX0JwnL4/ivHmp3Wu3yHVkrAF7fCNJ4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tapio Reijonen , Linus Walleij , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 6.1 0249/1059] gpio: pcf857x: implement get_direction() Date: Fri, 4 Dec 2026 18:56:20 +0900 Message-ID: <20261204100650.721719469@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tapio Reijonen [ Upstream commit ed14364ae8c310cc3f3f649ffcbc7f82befe1579 ] The GPIO core warns (and taints the kernel) when a gpiochip lacks .get_direction() and a consumer queries a line's direction, for example via /sys/kernel/debug/gpio. pcf857x provided direction_input/output but no get_direction. These quasi-bidirectional expanders cannot report direction in hardware, and the 'out' software latch alone is ambiguous - a released (input) line and an output driven high both read back as a set bit. Track the direction explicitly in a 'dir' latch updated by the direction_input(), direction_output() and set_multiple() paths, and return it from get_direction(). Initialise it from the same reset state as 'out': released lines are inputs, lines flagged in the power-on latch are driven-low outputs. Fixes: 15fae37d9f5f ("gpiolib: pcf857x i2c gpio expander support") Signed-off-by: Tapio Reijonen Reviewed-by: Linus Walleij Link: https://patch.msgid.link/20260825-b4-gpio-pcf857x-get-direction-v1-1-de15996ae354@vaisala.com Signed-off-by: Bartosz Golaszewski [ sashal: Omitted the pcf857x_set_multiple() hunk since this driver has no .set_multiple, and adapted context to older unsigned types and the pcf857x_probe() signature using id->driver_data. ] Signed-off-by: Sasha Levin --- drivers/gpio/gpio-pcf857x.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c index e98ea47d72379..c6ad3b916bb8a 100644 --- a/drivers/gpio/gpio-pcf857x.c +++ b/drivers/gpio/gpio-pcf857x.c @@ -72,8 +72,9 @@ MODULE_DEVICE_TABLE(of, pcf857x_of_table); struct pcf857x { struct gpio_chip chip; struct i2c_client *client; - struct mutex lock; /* protect 'out' */ + struct mutex lock; /* protect 'out' and 'dir' */ unsigned out; /* software latch */ + unsigned dir; /* direction latch (1 = input) */ unsigned status; /* current status */ unsigned irq_enabled; /* enabled irqs */ @@ -126,12 +127,21 @@ static int pcf857x_input(struct gpio_chip *chip, unsigned offset) mutex_lock(&gpio->lock); gpio->out |= (1 << offset); + gpio->dir |= (1 << offset); status = gpio->write(gpio->client, gpio->out); mutex_unlock(&gpio->lock); return status; } +static int pcf857x_get_direction(struct gpio_chip *chip, unsigned int offset) +{ + struct pcf857x *gpio = gpiochip_get_data(chip); + + return (gpio->dir & (1 << offset)) ? GPIO_LINE_DIRECTION_IN + : GPIO_LINE_DIRECTION_OUT; +} + static int pcf857x_get(struct gpio_chip *chip, unsigned offset) { struct pcf857x *gpio = gpiochip_get_data(chip); @@ -152,6 +162,7 @@ static int pcf857x_output(struct gpio_chip *chip, unsigned offset, int value) gpio->out |= bit; else gpio->out &= ~bit; + gpio->dir &= ~bit; status = gpio->write(gpio->client, gpio->out); mutex_unlock(&gpio->lock); @@ -278,6 +289,7 @@ static int pcf857x_probe(struct i2c_client *client, gpio->chip.set = pcf857x_set; gpio->chip.direction_input = pcf857x_input; gpio->chip.direction_output = pcf857x_output; + gpio->chip.get_direction = pcf857x_get_direction; gpio->chip.ngpio = id->driver_data; /* NOTE: the OnSemi jlc1562b is also largely compatible with @@ -349,6 +361,7 @@ static int pcf857x_probe(struct i2c_client *client, * reset state. Otherwise it flags pins to be driven low. */ gpio->out = ~n_latch; + gpio->dir = ~n_latch; gpio->status = gpio->read(gpio->client); /* Enable irqchip if we have an interrupt */ -- 2.53.0