From: Guoniu Zhou <guoniu.zhou@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>
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 v3 2/4] media: i2c: ds90ub953: Add back channel GPIO support
Date: Tue, 16 Sep 2025 17:43:44 +0800 [thread overview]
Message-ID: <20250916-ds90ub953-v3-2-bb7bc6545da7@nxp.com> (raw)
In-Reply-To: <20250916-ds90ub953-v3-0-bb7bc6545da7@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 | 47 +++++++++++++++++++++++++++++++++----------
1 file changed, 36 insertions(+), 11 deletions(-)
diff --git a/drivers/media/i2c/ds90ub953.c b/drivers/media/i2c/ds90ub953.c
index e3fc9d66970a762d284955f14db48d7105b4b8c4..c6b77e4982a3449896e564a288ff1562cb1dcb79 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];
@@ -633,14 +655,17 @@ static int ub953_log_status(struct v4l2_subdev *sd)
return ret;
for (i = 0; i < UB953_NUM_GPIOS; i++) {
+ unsigned int pin = i % UB953_NUM_LOCAL_GPIOS;
+ bool rmt = (i >= UB953_NUM_LOCAL_GPIOS) ? true : false;
+
dev_info(dev,
"GPIO%u: remote: %u is_input: %u is_output: %u val: %u sts: %u\n",
i,
- !!(gpio_local_data & UB953_REG_LOCAL_GPIO_DATA_GPIO_RMTEN(i)),
- !!(gpio_input_ctrl & UB953_REG_GPIO_INPUT_CTRL_INPUT_EN(i)),
- !!(gpio_input_ctrl & UB953_REG_GPIO_INPUT_CTRL_OUT_EN(i)),
+ rmt ? !!(gpio_local_data & UB953_REG_LOCAL_GPIO_DATA_GPIO_RMTEN(pin)) : 0,
+ rmt ? 0 : !!(gpio_input_ctrl & UB953_REG_GPIO_INPUT_CTRL_INPUT_EN(pin)),
+ rmt ? 1 : !!(gpio_input_ctrl & UB953_REG_GPIO_INPUT_CTRL_OUT_EN(pin)),
!!(gpio_local_data & UB953_REG_LOCAL_GPIO_DATA_GPIO_OUT_SRC(i)),
- !!(gpio_pin_sts & UB953_REG_GPIO_PIN_STS_GPIO_STS(i)));
+ !!(gpio_pin_sts & UB953_REG_GPIO_PIN_STS_GPIO_STS(pin)));
}
return 0;
--
2.34.1
next prev parent reply other threads:[~2025-09-16 9:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-16 9:43 [PATCH v3 0/4] " Guoniu Zhou
2025-09-16 9:43 ` [PATCH v3 1/4] dt-bindings: media: ti,ds90ub953: Add new range for remote GPIO data Guoniu Zhou
2025-09-16 14:23 ` Frank Li
2025-09-16 9:43 ` Guoniu Zhou [this message]
2025-09-16 9:43 ` [PATCH v3 3/4] media: i2c: ds90ub953: use devm_mutex_init() to simplify code Guoniu Zhou
2025-09-16 14:26 ` Frank Li
2025-09-16 9:43 ` [PATCH v3 4/4] media: i2c: ds90ub953: use guard() " Guoniu Zhou
2025-10-23 8:41 ` [PATCH v3 0/4] media: i2c: ds90ub953: Add back channel GPIO support G.N. 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=20250916-ds90ub953-v3-2-bb7bc6545da7@nxp.com \
--to=guoniu.zhou@nxp.com \
--cc=Frank.Li@nxp.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--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 \
/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®