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=1796384803; b=JUPWdDi1IMghklOPqBwrS4uF2EhScEwdc6pB5Zax5pZs6ltIQUyRsLQ7RcQR1gTDZbXR SOkwjHrHbjf/D9jMJ8d+HAc/joIDjBI7sH05xueQZf+T0Sj0r/8TyF/47TkAZSmwEgfXL s5k4sMJFXo4WqTTt4etbUWKiV10CGajPdrgExZAguvkbhDyJIPvkLXNr7DKDhSf6yPUSx K/rvSDvp3CvptX9wI37YO+bJlNIQ1x3MeJJ0WwI3xxg8qTnGds62w/rD4lasRlA1D2x2v r0hyOI27uqL9QQrZdwnN5r7ov+bvuWMBos0lm0EHhnyopbS6Al2kHc0cHa+GHOjDZAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384803; 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=US4Kwq9h9ZnRxx/CQILk+qNJry3cXGCE0uuqCYr6MHQ=; b=UiRX05PVe9LJHLhKiZF7RD94b1NQZTw0hAkqFq9STshXODoPGz/JBTekATFAAsbRPfch c1Vhfd/cG2HKAgeacqbY/9iuV7y6Yds6GpsWwYPHxKdzxlsmNykYnvtzxxmNvpmDiZ04B XarUJN0KFaJT8v9YSYxmAgxXBg+V79qGUqttAI7OFWfT5jHeoYxIhY/1RTnwL4CgI9AYf vnn5NhH8gV6x9wR3FZgEw6dVPNNtXs61R9h0H4p6WrxA66bVwWd6Qz6Mm4VO/YgIoEVJ5 DiZywogF39dr6hS3VSZCih+sWiBxzYhuwyRgVh5drbf9fUtkBPk4HSXy/6uuRFUD4kQ== 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=SaSr0WIg; 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 2B139606A32C; Fri, 4 Dec 2026 11:46:43 +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=SaSr0WIg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9723A1F000C2; Fri, 4 Dec 2026 11:46:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384803; bh=US4Kwq9h9ZnRxx/CQILk+qNJry3cXGCE0uuqCYr6MHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SaSr0WIgHBQf0UDKilgz9C++5aLIJUauUtW8byDALQdlmjkqfWaLcyo8lcdj7fwDM Lo/qnSet+rmvj+b9e9Z4+iKXHa9vYJAd7u2Pp+GMpHRP/ahCE6AnyN0kNiplAAQou/ 7IqbYCrHyFdR7FjAeCf86TOPOwmVU/hHypw02DmE= 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.6 0300/1167] gpio: pcf857x: implement get_direction() Date: Fri, 4 Dec 2026 18:55:27 +0900 Message-ID: <20261204100709.843389277@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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: Adjusted pcf857x_set_multiple() context: this tree's function returns void with a bare gpio->write(), so only the dir update was added, and the probe() context differs (no reset_gpio line). ] Signed-off-by: Sasha Levin --- drivers/gpio/gpio-pcf857x.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c index 53b69abe67871..2c3abf576f7a2 100644 --- a/drivers/gpio/gpio-pcf857x.c +++ b/drivers/gpio/gpio-pcf857x.c @@ -68,8 +68,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 int out; /* software latch */ + unsigned int dir; /* direction latch (1 = input) */ unsigned int status; /* current status */ unsigned int irq_enabled; /* enabled irqs */ @@ -122,12 +123,21 @@ static int pcf857x_input(struct gpio_chip *chip, unsigned int 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 int offset) { struct pcf857x *gpio = gpiochip_get_data(chip); @@ -163,6 +173,7 @@ static int pcf857x_output(struct gpio_chip *chip, unsigned int offset, int value gpio->out |= bit; else gpio->out &= ~bit; + gpio->dir &= ~bit; status = gpio->write(gpio->client, gpio->out); mutex_unlock(&gpio->lock); @@ -182,6 +193,7 @@ static void pcf857x_set_multiple(struct gpio_chip *chip, unsigned long *mask, mutex_lock(&gpio->lock); gpio->out &= ~*mask; gpio->out |= *bits & *mask; + gpio->dir &= ~*mask; gpio->write(gpio->client, gpio->out); mutex_unlock(&gpio->lock); } @@ -295,6 +307,7 @@ static int pcf857x_probe(struct i2c_client *client) gpio->chip.set_multiple = pcf857x_set_multiple; gpio->chip.direction_input = pcf857x_input; gpio->chip.direction_output = pcf857x_output; + gpio->chip.get_direction = pcf857x_get_direction; gpio->chip.ngpio = (uintptr_t)i2c_get_match_data(client); /* NOTE: the OnSemi jlc1562b is also largely compatible with @@ -366,6 +379,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