From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2BCA3CA5FCB for ; Thu, 1 Oct 2026 13:44:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EDRzsdsGnuH8GVps/3FJB2r0HHrwF6zLKnDgg73z9aA=; b=uchs2kK2R5wkmF2JwgH9gY/3p4 B2QMT7LgJ/QQD5UIKL7DgHKKO3BDWZQ8YMrLynxEMD7WMcXWLJiaaT5aLo6V2XjRtgIp663McqmqV ext3H97We2+AsvYzOBPtZdFfXqqnoNeqH4nWi5N8anHh1H4TFkUGWXyec7dZ0DOr6G/eeGo51/nEV rHBL+80t+WpMPWrnsbPkyhAx9jTBBXN8WrdVtXGNmdHeJdfvLCkyLnF88JmJzYHBkbX4+/1YGmkMe LTdvxe4ivHrIQ9vMbvoYwtVxLsEdvFAEnrI6zzx/8+lQaqxs40W8upV2QJGvi7faMpNBXxLdIT50q lKgWQprw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xCG61-000000094rJ-1Vnd; Thu, 01 Oct 2026 12:41:09 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xCG5t-000000094mM-3ltG for linux-arm-kernel@lists.infradead.org; Thu, 01 Oct 2026 12:41:01 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 0076E447CD; Thu, 1 Oct 2026 12:41:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id BCD02C4DDF6; Thu, 1 Oct 2026 12:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1790858460; bh=fGVHCZe9DlwBH9noY2QTBptVI7Ljju4biYMRrsgyXHU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Uo90uNYXs8jm6uHyxxyO+mZI5ulHRvk1JK5wBxCIDtmlCMP3u1xuWlGJXLUztIE21 BddR4DyCrdlLBv9mntyEclgRux0qpb2gU4l9WDvYKHRVmuFHjZN+v2hJAjL0tpCgOx kPOydl+2SP83zsQOn6/01TSqF7niEQ9lZdseKs/m5Vq7vk4X4YEEbT1JHQ7virHAG+ 1zf4dx7r4RnKWMM3b3Qc8KQiZ7s2CTcMhHW8g0ojsTgHuiYxKPUgyVKECRXb2nsss7 rLjR14r2p6PrNWFHFszkl8o12YpdnJf8KbSG16880d8OfEmlrFV3KZ3Q+gU3Qcs+1N leMueH/+k0Fsg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A62BBCA5FCB; Thu, 1 Oct 2026 12:41:00 +0000 (UTC) From: Long Zhao via B4 Relay Date: Thu, 01 Oct 2026 20:40:56 +0800 Subject: [PATCH v9 07/15] gpiolib: regmap: add GPIO_REGMAP_QUIRK_SET_AFTER_DIR MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261001-cv75-v5-v9-7-486cc289a4b8@ambarella.com> References: <20261001-cv75-v5-v9-0-486cc289a4b8@ambarella.com> In-Reply-To: <20261001-cv75-v5-v9-0-486cc289a4b8@ambarella.com> To: Arnd Bergmann , Krzysztof Kozlowski , Alexandre Belloni , soc@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: Long Zhao , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Turquette , Stephen Boyd , Jerome Brunet , Linus Walleij , Bartosz Golaszewski , Michael Walle , Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Catalin Marinas , Will Deacon , Long Zhao , Lee Jones , mfd@lists.linux.dev, devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1790858457; l=3373; i=longzhao@ambarella.com; s=20260730; h=from:subject:message-id; bh=IBa8epd2/4YpoCQ3nIa3WOdoI+AIcLQgC3bWWH4FGyQ=; b=PZWnOerKLdbdqt73Nvu/XDtzQRIy2lsM4PdHcH8CH5y17x+sAN9UWgrUMW9kuwNW4ypkuU9KS BEbgND5KgcxA55t3qvSMiTmFLGcNrwKlfOKDK0dmsavbSpK2QeFgd1b X-Developer-Key: i=longzhao@ambarella.com; a=ed25519; pk=/xGhPTOX0/eYsyTWzyjjgAIW1Z/YD+IlnOnvcdRozow= X-Endpoint-Received: by B4 Relay for longzhao@ambarella.com/20260730 with auth_id=903 X-Original-From: Long Zhao X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: longzhao@ambarella.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Long Zhao Some controllers ignore output writes while a line is still an input. Add a behaviour flag so the output value is written after the direction change. This is a legacy quirk. New hardware must not use it. Signed-off-by: Long Zhao --- drivers/gpio/gpio-regmap.c | 15 +++++++++++++-- include/linux/gpio/regmap.h | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 51b4d69b8740..728bf3d90c48 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -31,6 +31,7 @@ struct gpio_regmap { unsigned int reg_clr_base; unsigned int reg_dir_in_base; unsigned int reg_dir_out_base; + unsigned long quirks; unsigned long *fixed_direction_mask; unsigned long *fixed_direction_output; @@ -271,9 +272,17 @@ static int gpio_regmap_direction_output(struct gpio_chip *chip, return ret; } - gpio_regmap_set(chip, offset, value); + if (!(gpio->quirks & GPIO_REGMAP_QUIRK_SET_AFTER_DIR)) + gpio_regmap_set(chip, offset, value); - return gpio_regmap_set_direction(chip, offset, true); + ret = gpio_regmap_set_direction(chip, offset, true); + if (ret) + return ret; + + if (gpio->quirks & GPIO_REGMAP_QUIRK_SET_AFTER_DIR) + gpio_regmap_set(chip, offset, value); + + return 0; } void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio) @@ -376,6 +385,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config config->fixed_direction_output, chip->ngpio); } + gpio->quirks = config->quirks; + /* if not set, assume there is only one register */ gpio->ngpio_per_reg = config->ngpio_per_reg; if (!gpio->ngpio_per_reg) diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index 06255756710d..e5a343512efb 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -3,6 +3,8 @@ #ifndef _LINUX_GPIO_REGMAP_H #define _LINUX_GPIO_REGMAP_H +#include + struct device; struct fwnode_handle; struct gpio_regmap; @@ -13,6 +15,14 @@ struct regmap; #define GPIO_REGMAP_ADDR_ZERO ((unsigned int)(-1)) #define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO) +/* + * Write the output value after the line is switched to output. + * Needed when hardware ignores output writes while the line is an input. + * This is a legacy quirk; new hardware must not use it. Direction changes + * will glitch. + */ +#define GPIO_REGMAP_QUIRK_SET_AFTER_DIR BIT(0) + /** * struct gpio_regmap_config - Description of a generic regmap gpio_chip. * @parent: The parent device @@ -24,6 +34,7 @@ struct regmap; * If not given, the name of the device is used. * @ngpio: (Optional) Number of GPIOs * @names: (Optional) Array of names for gpios + * @quirks: (Optional) Behaviour flags, OR of GPIO_REGMAP_QUIRK_*. * @reg_dat_base: (Optional) (in) register base address * @reg_set_base: (Optional) set register base address * @reg_clr_base: (Optional) clear register base address @@ -87,6 +98,9 @@ struct gpio_regmap_config { int ngpio; const char *const *names; + /* Regmap GPIO behaviour flags */ + unsigned long quirks; + unsigned int reg_dat_base; unsigned int reg_set_base; unsigned int reg_clr_base; -- 2.34.1