From: Guoniu Zhou <guoniu.zhou@oss.nxp.com>
To: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Frank Li <Frank.Li@nxp.com>,
Vladimir Zapolskiy <vz@mleia.com>
Cc: linux-media@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, imx@lists.linux.dev,
Guoniu Zhou <guoniu.zhou@nxp.com>
Subject: [PATCH v4 2/4] media: i2c: ds90ub953: Add back channel GPIO support
Date: Fri, 27 Feb 2026 19:21:11 +0800 [thread overview]
Message-ID: <20260227-ds90ub953-v4-2-dea596205f9e@nxp.com> (raw)
In-Reply-To: <20260227-ds90ub953-v4-0-dea596205f9e@nxp.com>
From: Guoniu Zhou <guoniu.zhou@nxp.com>
The ds90ub953 supports GPIO0 through GPIO3. When enabled as an output,
each GPIO pin can be programed to output remote data coming from the
compatible deserializer using the register LOCAL_GPIO_DATA[7:4] field.
Make GPIO range from 0-3 to 0-7 to support this case. 0-3 for local GPIO
and 4-7 for remote GPIO data.
Signed-off-by: Guoniu Zhou <guoniu.zhou@nxp.com>
---
drivers/media/i2c/ds90ub953.c | 42 ++++++++++++++++++++++++++++++++++--------
1 file changed, 34 insertions(+), 8 deletions(-)
diff --git a/drivers/media/i2c/ds90ub953.c b/drivers/media/i2c/ds90ub953.c
index daefdb108fbf402453baeaccc61d1f3530521d74..14dd0aa4cc6ceba66a8c3545c7d7d19694007431 100644
--- a/drivers/media/i2c/ds90ub953.c
+++ b/drivers/media/i2c/ds90ub953.c
@@ -32,7 +32,9 @@
#define UB953_PAD_SINK 0
#define UB953_PAD_SOURCE 1
-#define UB953_NUM_GPIOS 4
+#define UB953_NUM_LOCAL_GPIOS 4
+#define UB953_NUM_REMOTE_GPIOS 4
+#define UB953_NUM_GPIOS (UB953_NUM_LOCAL_GPIOS + UB953_NUM_REMOTE_GPIOS)
#define UB953_DEFAULT_CLKOUT_RATE 25000000UL
@@ -268,7 +270,7 @@ static int ub953_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
if (ret)
return ret;
- if (v & UB953_REG_GPIO_INPUT_CTRL_INPUT_EN(offset))
+ if (v & UB953_REG_GPIO_INPUT_CTRL_INPUT_EN((offset % UB953_NUM_LOCAL_GPIOS)))
return GPIO_LINE_DIRECTION_IN;
else
return GPIO_LINE_DIRECTION_OUT;
@@ -277,6 +279,12 @@ static int ub953_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
static int ub953_gpio_direction_in(struct gpio_chip *gc, unsigned int offset)
{
struct ub953_data *priv = gpiochip_get_data(gc);
+ struct device *dev = &priv->client->dev;
+
+ if (offset > UB953_NUM_LOCAL_GPIOS) {
+ dev_err(dev, "GPIO%u can't be programed as input\n", offset);
+ return -EINVAL;
+ }
return regmap_update_bits(priv->regmap, UB953_REG_GPIO_INPUT_CTRL,
UB953_REG_GPIO_INPUT_CTRL_INPUT_EN(offset) |
@@ -288,10 +296,14 @@ static int ub953_gpio_direction_out(struct gpio_chip *gc, unsigned int offset,
int value)
{
struct ub953_data *priv = gpiochip_get_data(gc);
+ unsigned int pin;
int ret;
+ pin = offset % UB953_NUM_LOCAL_GPIOS;
+
ret = regmap_update_bits(priv->regmap, UB953_REG_LOCAL_GPIO_DATA,
- UB953_REG_LOCAL_GPIO_DATA_GPIO_OUT_SRC(offset),
+ UB953_REG_LOCAL_GPIO_DATA_GPIO_OUT_SRC(pin) |
+ UB953_REG_LOCAL_GPIO_DATA_GPIO_RMTEN(pin),
value ? UB953_REG_LOCAL_GPIO_DATA_GPIO_OUT_SRC(offset) :
0);
@@ -299,9 +311,9 @@ static int ub953_gpio_direction_out(struct gpio_chip *gc, unsigned int offset,
return ret;
return regmap_update_bits(priv->regmap, UB953_REG_GPIO_INPUT_CTRL,
- UB953_REG_GPIO_INPUT_CTRL_INPUT_EN(offset) |
- UB953_REG_GPIO_INPUT_CTRL_OUT_EN(offset),
- UB953_REG_GPIO_INPUT_CTRL_OUT_EN(offset));
+ UB953_REG_GPIO_INPUT_CTRL_INPUT_EN(pin) |
+ UB953_REG_GPIO_INPUT_CTRL_OUT_EN(pin),
+ UB953_REG_GPIO_INPUT_CTRL_OUT_EN(pin));
}
static int ub953_gpio_get(struct gpio_chip *gc, unsigned int offset)
@@ -314,12 +326,19 @@ static int ub953_gpio_get(struct gpio_chip *gc, unsigned int offset)
if (ret)
return ret;
- return !!(v & UB953_REG_GPIO_PIN_STS_GPIO_STS(offset));
+ return !!(v & UB953_REG_GPIO_PIN_STS_GPIO_STS((offset % UB953_NUM_LOCAL_GPIOS)));
}
static int ub953_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
{
struct ub953_data *priv = gpiochip_get_data(gc);
+ struct device *dev = &priv->client->dev;
+
+ if (offset > UB953_NUM_LOCAL_GPIOS) {
+ dev_err(dev, "GPIO%u be programed to output remote data\n",
+ offset % UB953_NUM_LOCAL_GPIOS);
+ return -EINVAL;
+ }
return regmap_update_bits(priv->regmap, UB953_REG_LOCAL_GPIO_DATA,
UB953_REG_LOCAL_GPIO_DATA_GPIO_OUT_SRC(offset),
@@ -330,6 +349,9 @@ static int ub953_gpio_of_xlate(struct gpio_chip *gc,
const struct of_phandle_args *gpiospec,
u32 *flags)
{
+ if (gpiospec->args[0] >= UB953_NUM_GPIOS)
+ return -EINVAL;
+
if (flags)
*flags = gpiospec->args[1];
@@ -632,7 +654,11 @@ static int ub953_log_status(struct v4l2_subdev *sd)
if (ret)
return ret;
- for (i = 0; i < UB953_NUM_GPIOS; i++) {
+ /*
+ * Only log GPIO 0-3 state since remote GPIO 4-7 pins reuse local
+ * GPIO 0-3 when enabled as an output.
+ */
+ for (i = 0; i < UB953_NUM_LOCAL_GPIOS; i++) {
dev_info(dev,
"GPIO%u: remote: %u is_input: %u is_output: %u val: %u sts: %u\n",
i,
--
2.34.1
next prev parent reply other threads:[~2026-02-27 11:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 11:21 [PATCH v4 0/4] " Guoniu Zhou
2026-02-27 11:21 ` [PATCH v4 1/4] dt-bindings: media: ti,ds90ub953: Add new range for remote GPIO data Guoniu Zhou
2026-02-27 18:17 ` Conor Dooley
2026-02-27 18:19 ` Conor Dooley
2026-02-27 11:21 ` Guoniu Zhou [this message]
2026-02-27 11:21 ` [PATCH v4 3/4] media: i2c: ds90ub953: use devm_mutex_init() to simplify code Guoniu Zhou
2026-02-27 11:21 ` [PATCH v4 4/4] media: i2c: ds90ub953: use guard() " Guoniu Zhou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260227-ds90ub953-v4-2-dea596205f9e@nxp.com \
--to=guoniu.zhou@oss.nxp.com \
--cc=Frank.Li@nxp.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=guoniu.zhou@nxp.com \
--cc=imx@lists.linux.dev \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=robh@kernel.org \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=vz@mleia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®