From nobody Sat Sep 26 07:59:41 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 411C43B42FC for ; Thu, 3 Sep 2026 07:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788422387; cv=none; b=f9P3rL6ySW8crhoYAFrtuI16OM2ISpr2aLIWAKq402GVUFlOb1W05ZzrbbJNNTjSqaQVhppT7uCdw+4jM4Kl/+CsBVJh6l6G9ol7ap1m3Cr1SODjCfd9xq4wMI3uHUA7rd8zWbrNFtlwoDImYHTnrTjcoSihp6n1xDTu4pCQpFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788422387; c=relaxed/simple; bh=JvxmjtGbMqSyugsMBtIh4c5EAdeqEgo6V+vHxBIrxQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pZ5t0Mqx69QFK1/0OzcjAEFyJIg72b+wC7Y/SqAgAXcdjiWeOTwvawaRohf2mxPG8XJkdNLD64WJP6EncD0ynb6hq5J9mjmhySauh5CrBj9b7XZ1s/PihZRF2M7LxUJ7Pf7phZm36cSNCsWmo5ecaokzPb4qZVGSavTaxNaVIBg= 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=GiSPS1y9; arc=none smtp.client-ip=209.85.128.50 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="GiSPS1y9" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-49b8687630fso16915075e9.3 for ; Thu, 03 Sep 2026 00:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788422383; x=1789027183; darn=vger.kernel.org; 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=pbqs3+P/ZX13vEXv3N3Jwum7K59Zn0Nb5bqVSfKORxQ=; b=GiSPS1y9Q+KoYDtwcwjOiiz1IQXs8j2PWQ2M1PHFP7qMINMryT0aUZF74oV4o7Seq+ UoX8MSfYW6Jqus+5cvOjssXK4S2jFWToA5acwYtEENOXZj6/QCbeT0GaHXRAha7y43NL t/xYhtoCJl3vEaV0i0DsBeJpTZzwRDICu0VOBsA/4pIWES4IP4pVl33FOtFjRaI62TP1 ebrU/ATa+uUg8R9ynDCV4MWfoPrs4+tpWx88KyWr2jT3xYn0r4jW1yl5q8cu+hXpRhaI sD0EXH+fJQVn8S6Vs1qJ7Rxuz4mulBRqYdEBNxQV7UmTBBihdg20B6Vo4S47iXM6AkFa ZrrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788422383; x=1789027183; 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=pbqs3+P/ZX13vEXv3N3Jwum7K59Zn0Nb5bqVSfKORxQ=; b=AJJqH1p8qvjjUVcWbTWWbCrFiIlHwQFqmpimplVbvy08ZH6x5eLAIMuIRTUfrX9fH2 IyYtw9C4JBrrtCK9rYixREt92mKAaNf6w4dI6r8FE+kEBWkt9Ydin3J/cfGn40deDksj HbhDWdq3YFIxxomMVXhjEPaON5MkaU3c0wV6RYU/LHac0Jkb39VIuEXXHI8FQyivAzks ORqq65+XKkuilY02sgodUWRsFHOdS2e46T4y+z5eVAHxgcE+15Upln5OXEK0XwsFe4ij CYy7b/VKJvF4NTT9VY0CatJ1WLQbvhccLZXQdwta/zBgnRjNscOCOjt4m3hT0MwzKGnR U89g== X-Forwarded-Encrypted: i=1; AKwUvByMRKQSw4RFzKt+00CXcxJcY6QuOaiRpCyDK/D3PhGmUFgb0IOnrSGaE6eVd1Rxei1TaFuCdk2IYluo44M=@vger.kernel.org X-Gm-Message-State: AFuF++nMgjjFHq5vGWhloiLbRd7VNfN9Fvqa6w6rL87OzRQfupAN0cvg DGnsj0xa7QD7DIRId8dj95Qz/snMOoZ9d7jEpwX832vwK+ymtfmu6/Nu X-Gm-Gg: AYBFou0p70Q8OjHxPKqje0ci5LIKLkqnpQ+2uRtwqiAY18aCyZLiK2YIFFn9kz6FnUi uWOig3JQRbKcR4f/57DOkoKZQjPP61yJaCy79F+A6Y2r7/3q6Zm8kB+fKa4oFPshR1Qf5T1aRa1 Ct+wjRgQb+r0CbtN/wHd/vJ9nSBIVwaf+V5CMQpud1+wb0+5cDsblXQ08WCDe8zw+FhaqeEu6Tp pVBk6M0251dm4f93KQ2CxZEP/eMvjigdy9VNBeKDxrcxlimSX0EKK8VDDJ/nmilO2CSkHSRs0m0 yNQrDogIRG3wULqwFasHhJIjNRvzh2s6fh7AQdhaon73PQFy1pXgEk1i/InI2D/lsfEpdbN08LW o4gj5iSOwkjqmd4mRkXa5mmyW3WixBlC8tOTX6DdAnSSu/jyhtt6qGqm0stEF1DFCf5YdPES/I+ uSOEx+Z+zou1bkDFtmDfDIF63+qcSk0ABNYJmxQQS30CIeI54tJEQBOuwUT5wSjpJp/0cpfEOa4 XqV X-Received: by 2002:a05:600c:8a17:20b0:49c:d818:8771 with SMTP id 5b1f17b1804b1-49ce5808d4dmr147334595e9.7.1788422383246; Thu, 03 Sep 2026 00:59:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 00:59:42 -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 1/3] pinctrl: imx: answer OUTPUT_ENABLE/INPUT_ENABLE queries from the pad register Date: Thu, 3 Sep 2026 09:59:38 +0200 Message-ID: <20260903075940.2089367-2-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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mehmet Fide The mmio pinconf get callback ignores which parameter was requested and returns the raw conf register, so a generic query through pinctrl_gpio_get_config() gets register bits back instead of the packed parameter it asked for. Decode the requested parameter and answer PIN_CONFIG_OUTPUT_ENABLE and PIN_CONFIG_INPUT_ENABLE on SoCs that declare where those bits live in the pad register; Vybrid has OBE at bit 1 and IBE at bit 0. The answer is 0 with the bit value as the argument, which is what the pinctrl_gpio_get_config() users (gpio-by-pinctrl, and gpio-mmio in the next patch) expect. Other parameters and the SCU based SoCs, whose firmware call returns the raw pad value as well, get -ENOTSUPP; a pin the device tree never configured gets -EINVAL, as the raw helper already does, so a caller can tell "no answer for this pin" from "this controller never answers". The only in-tree user of the raw register was the debugfs group dump, which called the callback with an uninitialized config; it now reads the register through its own helper, like the single pin dump already did. The set callback is not touched: the fsl,pins binding hands it the raw pad register value and that stays the only thing it accepts. Nothing in-tree sends generic parameters to it on these SoCs; making it understand them is a separate change. This gives gpio-mmio a way to read back the line direction on chips whose direction lives in the pin controller. Suggested-by: Bartosz Golaszewski Signed-off-by: Mehmet Fide Reviewed-by: Haibo Chen Reviewed-by: Linus Walleij --- drivers/pinctrl/freescale/pinctrl-imx.c | 54 +++++++++++++++++++++-- drivers/pinctrl/freescale/pinctrl-imx.h | 4 ++ drivers/pinctrl/freescale/pinctrl-vf610.c | 2 + 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/free= scale/pinctrl-imx.c index 9a45b376d36f..f08ef52bf4f8 100644 --- a/drivers/pinctrl/freescale/pinctrl-imx.c +++ b/drivers/pinctrl/freescale/pinctrl-imx.c @@ -21,6 +21,7 @@ =20 #include #include +#include #include #include =20 @@ -291,8 +292,8 @@ struct pinmux_ops imx_pmx_ops =3D { .set_mux =3D imx_pmx_set, }; =20 -static int imx_pinconf_get_mmio(struct pinctrl_dev *pctldev, unsigned pin_= id, - unsigned long *config) +static int imx_pinconf_get_raw_mmio(struct pinctrl_dev *pctldev, + unsigned int pin_id, unsigned long *config) { struct imx_pinctrl *ipctl =3D pinctrl_dev_get_drvdata(pctldev); const struct imx_pinctrl_soc_info *info =3D ipctl->info; @@ -312,16 +313,61 @@ static int imx_pinconf_get_mmio(struct pinctrl_dev *p= ctldev, unsigned pin_id, return 0; } =20 +static int imx_pinconf_get_mmio(struct pinctrl_dev *pctldev, + unsigned int pin_id, unsigned long *config) +{ + struct imx_pinctrl *ipctl =3D pinctrl_dev_get_drvdata(pctldev); + const struct imx_pinctrl_soc_info *info =3D ipctl->info; + const struct imx_pin_reg *pin_reg =3D &ipctl->pin_regs[pin_id]; + enum pin_config_param param =3D pinconf_to_config_param(*config); + unsigned int mask; + u32 raw; + + switch (param) { + case PIN_CONFIG_OUTPUT_ENABLE: + mask =3D info->obe_mask; + break; + case PIN_CONFIG_INPUT_ENABLE: + mask =3D info->ibe_mask; + break; + default: + mask =3D 0; + break; + } + + if (!mask) + return -ENOTSUPP; + if (pin_reg->conf_reg =3D=3D -1) + return -EINVAL; + + raw =3D readl(ipctl->base + pin_reg->conf_reg); + *config =3D pinconf_to_config_packed(param, !!(raw & mask)); + + return 0; +} + static int imx_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin_id, unsigned long *config) { struct imx_pinctrl *ipctl =3D pinctrl_dev_get_drvdata(pctldev); const struct imx_pinctrl_soc_info *info =3D ipctl->info; =20 + if (info->flags & IMX_USE_SCU) + return -ENOTSUPP; + + return imx_pinconf_get_mmio(pctldev, pin_id, config); +} + +static int imx_pinconf_get_raw(struct pinctrl_dev *pctldev, + unsigned int pin_id, unsigned long *config) +{ + struct imx_pinctrl *ipctl =3D pinctrl_dev_get_drvdata(pctldev); + const struct imx_pinctrl_soc_info *info =3D ipctl->info; + if (info->flags & IMX_USE_SCU) return info->imx_pinconf_get(pctldev, pin_id, config); else - return imx_pinconf_get_mmio(pctldev, pin_id, config); + return imx_pinconf_get_raw_mmio(pctldev, pin_id, config); } =20 static int imx_pinconf_set_mmio(struct pinctrl_dev *pctldev, @@ -426,7 +472,7 @@ static void imx_pinconf_group_dbg_show(struct pinctrl_d= ev *pctldev, struct imx_pin *pin =3D &((struct imx_pin *)(grp->data))[i]; =20 name =3D pin_get_name(pctldev, pin->pin); - ret =3D imx_pinconf_get(pctldev, pin->pin, &config); + ret =3D imx_pinconf_get_raw(pctldev, pin->pin, &config); if (ret) return; seq_printf(s, " %s: 0x%lx\n", name, config); diff --git a/drivers/pinctrl/freescale/pinctrl-imx.h b/drivers/pinctrl/free= scale/pinctrl-imx.h index f65ff45b4003..8fa7e1e2521d 100644 --- a/drivers/pinctrl/freescale/pinctrl-imx.h +++ b/drivers/pinctrl/freescale/pinctrl-imx.h @@ -91,6 +91,10 @@ struct imx_pinctrl_soc_info { unsigned int mux_mask; u8 mux_shift; =20 + /* OBE/IBE bits in the conf register, 0 if the pad does not have them */ + unsigned int obe_mask; + unsigned int ibe_mask; + int (*gpio_set_direction)(struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range, unsigned offset, diff --git a/drivers/pinctrl/freescale/pinctrl-vf610.c b/drivers/pinctrl/fr= eescale/pinctrl-vf610.c index 76a4bc0181a0..77d077618782 100644 --- a/drivers/pinctrl/freescale/pinctrl-vf610.c +++ b/drivers/pinctrl/freescale/pinctrl-vf610.c @@ -319,6 +319,8 @@ static const struct imx_pinctrl_soc_info vf610_pinctrl_= info =3D { .gpio_set_direction =3D vf610_pmx_gpio_set_direction, .mux_mask =3D 0x700000, .mux_shift =3D 20, + .obe_mask =3D 0x2, + .ibe_mask =3D 0x1, }; =20 static const struct of_device_id vf610_pinctrl_of_match[] =3D { --=20 2.54.0 From nobody Sat Sep 26 07:59:41 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 1EEF3375AC6 for ; Thu, 3 Sep 2026 07:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788422389; cv=none; b=qXCzUoMPZgm1PS+ufCUya0604LMGye5xTX5QKJm4y+dWVcALoKH3FU0vTo9TMdwyL4H7yfSkQkaTJPIr/xUCxzaHfzRDHz+Fde7v0JClZSfCyzn6JFU0jxZtd+rzpVeOYec4UoNIUTlJTNZp1usQqYCbpvjdYhmPeVxXit+rrWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788422389; c=relaxed/simple; bh=vpxMREyKPKzJjjlqFAlHvba6Vo7YZEhqwIUksEjNrnE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OJsmQvBgi78Wlm/dlTPrFReg+jCtVW1VJorZLc4gwN/2rzezugwDeOztYwmMuAAf27ZqOI7m3BcbRGcBgEe64fucX6yXBY0XPpbGpzlsSr9xY4hye0vT81G7WJ1meSgVVmw3C7+B1tIf7YSmlWxTMMRLPmWdkVpsMpu7Nbr5cz0= 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=gxQoWlC+; arc=none smtp.client-ip=209.85.128.49 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="gxQoWlC+" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-49ccfbe062eso16206245e9.3 for ; Thu, 03 Sep 2026 00:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788422384; x=1789027184; darn=vger.kernel.org; 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=RRfXYK5ceQGJKTl6ugaWhRpE3JruSeXGhAudETkOsVY=; b=gxQoWlC+vARRcZtwBA1vS5rO6BP1zTBvPqmfalPFe9Ch92fDy2LV8yohy0eOdJJ/gM Bj/H3fhj83g0zOJHGHzonWcVAvIUSXOpX6mITTpx7nsW2/DT7yyRkr6w97gNhAlbM0Cj /tVr9+O4G77zrhSH54jixkdyZ81mZZLHcq+iCpxW+nxHF5oXIjr5q/69Argo6VvEsZgo R0t2JFPRdbgNbIz2HacV9CIFNVMvRcVnwM3owJWpqIwROJZtowlA8m4qRPU47T1vlXV/ UE0/fwCe0GASpaQ4fMfwuDicBP+tInD/Qx6D3yGIgM8PqF26vuhF5eQHNykhRvyf4EiP UAbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788422384; x=1789027184; 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=RRfXYK5ceQGJKTl6ugaWhRpE3JruSeXGhAudETkOsVY=; b=JcAPCy2aWsewccsfg0ugg4+9SJqUHs4uiVxcbdgjD3IvixYRaPewt0Qp4A/5U94TU1 7sydUWXlpUWDcq1jj9XZFg5eJMyzQyc67bhWiWZ9lNc3kwnXLsxfJ9yKaZUHfl5GukqR 4LWDy9bZo1WovB4PlN030nWqKCIowpsMulIWOSNXfdpwcGvQnIqJCRmgsyBgRrO30Vpr tMeXbJGOnuaa/9VrLNwvQI2n0TamltXbVBLZLQg6I9PbpDJAlz+QXdi2pP3/ppM9o+xb k/SGzdThY8zU36/YOq2p+tM8U2aJEGEkeTOPpeq3bjK7HQy2Lpw8nDLEPrn7pMmNoWGE 9KaA== X-Forwarded-Encrypted: i=1; AKwUvBxRuEzzDCBPMSDI3dCBaUyP44gOsDfo8KRM+sOYzBRnKQH8j2CGCXObv10aLHqTv5QIqbnl0pz4Wx051L4=@vger.kernel.org X-Gm-Message-State: AFuF++kCq4T1sR1a2Tl0q+jCwOc3wu+StPW2vtyCbbQvppO+8mD9iWV8 cr/X0s5eR2a7o3+IiSgLiUzjQFWokUihRI1goMViKDV2W3cyG5TPuujy X-Gm-Gg: AYBFou0b5CvTMV7txr4ZerFr4vnPyVoak6mBhnt1YUdptBii5t2JQ6nYJG4bxETFYDC HkVQincbihf53YkrxXHa07c1rNLK0PmXOGTb72jVoMeo9EluUedxRHIZ2B2iTc/U2z0J+wi9T1G yfH0xQtTZw49KsgvfChurggwGdJyT6ObdMDF5jmtu7Zlqu/bUbAzV+b22HYR341Tv8PeiSpbNbB Ed82G4ExTFHNzm9N3BxT1Z/7ldIwzikbXNmLDfucY+nm8cMjoEbDzujssKPVuVmkmTggDbymbr7 g4DkrtJ0XGdYy9O0hflCn/Ip0L6HAuSrU76CwRWZsLLGFaYVhr5uOc1aDfrmfNueYj43QeH1vLS VudxtyhlYnnEjqDjsLbEAYwniNF1vkC4hzkR7uSrtRCvpefm021yGQX1+XGgcuc7qgwo7SSnhHN 4zrWzbFhtNXd74R3s39mPhcMSnSlm7abq23zTFx6tl/DKIUpaj0xAZuWARARDo3nJHPQ== X-Received: by 2002:a05:600c:1c27:b0:49c:dcec:bd27 with SMTP id 5b1f17b1804b1-49ce57fd7bamr166027785e9.8.1788422384199; Thu, 03 Sep 2026 00:59:44 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 00:59:43 -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 2/3] gpiolib: add get_config() and gpiochip_generic_get_config() Date: Thu, 3 Sep 2026 09:59:39 +0200 Message-ID: <20260903075940.2089367-3-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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mehmet Fide A chip with a pin control backend sets a line's configuration through set_config() and gpiochip_generic_config(), but has no way to read one back. gpio-mmio needs that to learn the direction of a line whose direction lives in the pin controller. Add the optional get_config() callback, taking the packed parameter to query and returning its bare argument the way pinctrl_gpio_get_config() does, and gpiochip_generic_get_config() as the pin control backed implementation, the mirror of gpiochip_generic_config(). Without CONFIG_PINCTRL the pinctrl stub returns 0 and leaves the config alone, so the helper answers -ENOTSUPP there instead. Nothing in gpiolib calls get_config() and there is no consumer API; it is for the chip's own use. Suggested-by: Linus Walleij Signed-off-by: Mehmet Fide Reviewed-by: Linus Walleij --- Documentation/driver-api/gpio/driver.rst | 7 +++++++ drivers/gpio/gpiolib.c | 23 +++++++++++++++++++++++ include/linux/gpio/driver.h | 9 +++++++++ 3 files changed, 39 insertions(+) diff --git a/Documentation/driver-api/gpio/driver.rst b/Documentation/drive= r-api/gpio/driver.rst index a4f160b95089..3e53374c7e9f 100644 --- a/Documentation/driver-api/gpio/driver.rst +++ b/Documentation/driver-api/gpio/driver.rst @@ -134,6 +134,13 @@ ending up in the pin control back-end "behind" the GPI= O controller, usually closer to the actual pins. This way the pin controller can manage the below listed GPIO configurations. =20 +The optional .get_config() callback reads a configuration back: the packed +parameter to query goes in, its bare argument comes out, the way +pinctrl_gpio_get_config() answers. gpiochip_generic_get_config() is its pin +control backed counterpart. Nothing in gpiolib calls it; it is for the GPIO +driver's own use, for example to learn the direction of a line when the pin +controller owns it. + If a pin controller back-end is used, the GPIO controller or hardware description needs to provide "GPIO ranges" mapping the GPIO line offsets t= o pin numbers on the pin controller so they can properly cross-reference each ot= her. diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index ef8ccaf17c9c..fb3ef6754a9e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2440,6 +2440,29 @@ int gpiochip_generic_config(struct gpio_chip *gc, un= signed int offset, } EXPORT_SYMBOL_GPL(gpiochip_generic_config); =20 +/** + * gpiochip_generic_get_config() - read back the configuration of a pin + * @gc: the gpiochip owning the GPIO + * @offset: the offset of the GPIO to query + * @config: the packed parameter to query, replaced by its bare argument + * + * Returns: + * 0 on success, or negative errno on failure. + */ +int gpiochip_generic_get_config(struct gpio_chip *gc, unsigned int offset, + unsigned long *config) +{ +#ifdef CONFIG_PINCTRL + if (list_empty(&gc->gpiodev->pin_ranges)) + return -ENOTSUPP; + + return pinctrl_gpio_get_config(gc, offset, config); +#else + return -ENOTSUPP; +#endif +} +EXPORT_SYMBOL_GPL(gpiochip_generic_get_config); + #ifdef CONFIG_PINCTRL =20 /** diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 17511434ed07..4077dc678cae 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -359,6 +359,10 @@ struct gpio_irq_chip { * @set_config: optional hook for all kinds of settings. Uses the same * packed config format as generic pinconf. Must return 0 on success and * a negative error number on failure. + * @get_config: optional hook to read back a setting. Takes the packed + * generic pinconf parameter to query and returns its bare argument in + * the same variable, like pinctrl_gpio_get_config(). Must return 0 on + * success and a negative error number on failure. * @to_irq: optional hook supporting non-static gpiod_to_irq() mappings; * implementation may not sleep * @dbg_show: optional routine to show contents in debugfs; default code @@ -434,6 +438,9 @@ struct gpio_chip { int (*set_config)(struct gpio_chip *gc, unsigned int offset, unsigned long config); + int (*get_config)(struct gpio_chip *gc, + unsigned int offset, + unsigned long *config); int (*to_irq)(struct gpio_chip *gc, unsigned int offset); =20 @@ -708,6 +715,8 @@ int gpiochip_generic_request(struct gpio_chip *gc, unsi= gned int offset); void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset); int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset, unsigned long config); +int gpiochip_generic_get_config(struct gpio_chip *gc, unsigned int offset, + unsigned long *config); =20 /** * struct gpio_pin_range - pin range controlled by a gpio chip --=20 2.54.0 From nobody Sat Sep 26 07:59:41 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 7D0933A3E7E for ; Thu, 3 Sep 2026 07:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788422397; cv=none; b=eVwdoXQ8TV/ihFhSOtaBzV8mkHWy9gB+5OgoqUuxcaUM6itZz1cWCktXklPd6znDYtSXi76JKzMgD2lXSgr+hHE6zM0QXd+co72ODHCDuxuta8/w1rVyVkns1qtVRTbCyNdPexv1UUMWD/hqYYAin+5I+IgYla7u9XqBYRqw/f8= 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=GPH8m/r9; arc=none smtp.client-ip=209.85.221.46 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="GPH8m/r9" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-48444eff835so520609f8f.3 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=vger.kernel.org; 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=GPH8m/r9a6LdXc4HoKkdURGiP1TZbVE0H4PiVDrEB9D7u9GOrJj7aDYLrJiRzF9bY+ d/gDhJdYNZjAQYLKVcs4C8UKQsot0rbUHhVLGxkFBYqI6EfAKabbxqAp+v1+BW8dCkPK c3VMbxHlYKY4Xf4/0ihppQpxI1s0s7vwnsvPa1o3PZSnipGr7qziCSrqSxK121alqZ1x vVNfAepaS4Krz3GIsPSGriawZufV5/SVS6BL8qYCZ6fcau2K6+uF4Kl9LAS24pu8SxkK e2ZNYPuuifvIteg4wdTC1upRhE+2lkkxxSQEMDNxr6nEBTyU8ME82ENCSWe171yKaXcy caHQ== 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=XGRL4nn7JaIcB831xmQraIn6BSVoOLvG6ypaQ9zKOSmmJs+9KexfWEeouk5mZVjUrc dnNa5vAa1bE6LF3rBUv59kGOdIdMTa5kJS2WiAWgn+H+0lKO94UNMDEwSV/aEmgxkNlD t5K+i5gVSzeWs3WIhdr0zx8X7RHxKiBPohplzNHa7CqovEiR69jkQ26jS4H1rJXVXxxD 2uD/+ONP9/IjYQL7fpJhT4BXQG9jP7/+qOvz2Z2IW9UiO35gt8eDVLikoj6l8+Xp4eho RXRwj+12i97jJru7M2p3a1pUILZMZehIJR4wPCsBIEB4+ehpS7usInRF/wv0PYkzaf3q 78bg== X-Forwarded-Encrypted: i=1; AKwUvBx+XNtVsUvbFWaiMeWpE8on5P+qj7MqQgoJGO9jptgad0gpQFLTo4fcKzh4j72ma03qc3AVt6r+/6rMRmE=@vger.kernel.org X-Gm-Message-State: AFuF++lQU61vMtlEZH9OtGlXe4KmGHxvXyu+1aWGmZWypjKlmQHgBN3C j4ZROOIaYGFKUr87olTdT06wSCcCaxX3aJogWfCjAn5O5zyidokkUD00 X-Gm-Gg: AYBFou3f3WnhotZGwgEJgyU5kA5RGzi8oYnxbnzR7EOTyW7Q6FsWeAavmfWbZkKzyRR q6SgAHnBC5HC0pnbHGRGc442v3vIkZPtD6cP1uR0t8AHf66kqAlgOeHqHWi3pnQC+Lm7sk0KzYj fjaNoymKVbt9xVtesDsKksvdVIQ0SjHAAd0QgPFYv/2tm/mJj1eqj4blCD+MOoZtd/mZl37rKYx jYkhdExeJnB08EwvxKrwS4P2bTcKNdOitatzYKRUW9+G7vvZUgMHAg8I2pIaBHSG+suQw3L3ZId tbbLsJluIojEGet6YqiX7k0EwNcsXWz6ByLDNUibDgGTusDIyjHhhVGdbJnaR5s2g8AUm+rOQJm ri/WJM+QB3yJd9PzFE0ZpnKxM8iSORy+OkhGR5CembVrFo8rChMp+/2fmcCCTWqjXOMsv6zUMBF xrYT/s+m3a1crSIvK3EJPuA6dQaBuOVAJehVQbNRu59uRiwIEVyl1GQacpvk/NRrogUw== 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Haibo Chen --- 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 ` ~~~~\___/~~~~ ` control= ler 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) =20 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 =3D to_gpio_generic_chip(gc); + int ret; + + ret =3D gpio_mmio_dir_return(gc, gpio, false); + if (ret) + return ret; + + guard(raw_spinlock_irqsave)(&chip->lock); + chip->sdir &=3D ~gpio_mmio_line2mask(gc, gpio); + + return 0; } =20 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 gpi= o, int val) { + struct gpio_generic_chip *chip =3D to_gpio_generic_chip(gc); + int ret; + gc->set(gc, gpio, val); =20 - return gpio_mmio_dir_return(gc, gpio, true); + ret =3D gpio_mmio_dir_return(gc, gpio, true); + if (ret) + return ret; + + guard(raw_spinlock_irqsave)(&chip->lock); + chip->sdir |=3D gpio_mmio_line2mask(gc, gpio); + + return 0; } =20 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_gene= ric_chip *chip, gc->direction_input =3D gpio_mmio_dir_in_err; else gc->direction_input =3D gpio_mmio_simple_dir_in; + + if (cfg->flags & GPIO_GENERIC_PINCTRL_BACKEND) { + chip->dir_unreadable =3D true; + gc->get_direction =3D gpio_mmio_get_dir; + gc->get_config =3D gpiochip_generic_get_config; + } } =20 return 0; } =20 +static void gpio_mmio_seed_dir_from_pinctrl(struct gpio_chip *gc, + unsigned int gpio) +{ + struct gpio_generic_chip *chip =3D to_gpio_generic_chip(gc); + unsigned long config; + + if (!gc->get_config || chip->reg_dir_out || chip->reg_dir_in) + return; + + config =3D 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 |=3D gpio_mmio_line2mask(gc, gpio); + else + chip->sdir &=3D ~gpio_mmio_line2mask(gc, gpio); +} + static int gpio_mmio_request(struct gpio_chip *gc, unsigned int gpio_pin) { struct gpio_generic_chip *chip =3D to_gpio_generic_chip(gc); + int ret; =20 if (gpio_pin >=3D gc->ngpio) return -EINVAL; =20 - if (chip->pinctrl) - return gpiochip_generic_request(gc, gpio_pin); + if (chip->pinctrl) { + ret =3D gpiochip_generic_request(gc, gpio_pin); + if (ret) + return ret; + gpio_mmio_seed_dir_from_pinctrl(gc, gpio_pin); + } =20 return 0; } --=20 2.54.0