From: Matthew Laux <matthew.laux@gmail.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil@kernel.org>,
Mehdi Djait <mehdi.djait@bootlin.com>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
Matthew Laux <matthew.laux@gmail.com>
Subject: [PATCH v7 10/12] media: tw9900: add S-Video input and progressive source detection
Date: Fri, 20 Nov 2026 21:55:21 -0600 [thread overview]
Message-ID: <20261121035523.26764-11-matthew.laux@gmail.com> (raw)
In-Reply-To: <20261121035523.26764-1-matthew.laux@gmail.com>
Add support for the S-Video Y/C input of the tw9900. Also, use the NINTL
bit of the Chip Status II register to correctly report when a source is
240p/288p instead of 480i/576i.
Signed-off-by: Matthew Laux <matthew.laux@gmail.com>
---
drivers/media/i2c/tw9900.c | 117 +++++++++++++++++++++++++++++++++++--
include/media/i2c/tw9900.h | 4 ++
2 files changed, 116 insertions(+), 5 deletions(-)
diff --git a/drivers/media/i2c/tw9900.c b/drivers/media/i2c/tw9900.c
index f4f07f060083..be939ce92c0d 100644
--- a/drivers/media/i2c/tw9900.c
+++ b/drivers/media/i2c/tw9900.c
@@ -29,12 +29,19 @@
#define TW9900_REG_CHIP_STATUS 0x01
#define TW9900_REG_CHIP_STATUS_VDLOSS BIT(7)
#define TW9900_REG_CHIP_STATUS_HLOCK BIT(6)
+#define TW9900_REG_CHIP_STATUS_VLOCK BIT(3)
+#define TW9900_REG_INFORM 0x02
+#define TW9900_REG_INFORM_IFSEL_MASK GENMASK(5, 4)
+#define TW9900_REG_INFORM_IFSEL_SVIDEO BIT(4)
+#define TW9900_REG_INFORM_YSEL_MASK GENMASK(3, 2)
+#define TW9900_REG_INFORM_YSEL_MUX1 BIT(2)
#define TW9900_REG_OUT_FMT_CTL 0x03
#define TW9900_REG_OUT_FMT_CTL_STANDBY 0xA7
#define TW9900_REG_OUT_FMT_CTL_STREAMING 0xA0
#define TW9900_REG_CKHY_HSDLY 0x04
#define TW9900_REG_OUT_CTRL_I 0x05
#define TW9900_REG_ANALOG_CTL 0x06
+#define TW9900_REG_ANALOG_CTL_SRESET BIT(7)
#define TW9900_REG_ANALOG_CTL_CLK_PDN BIT(3)
#define TW9900_REG_ANALOG_CTL_Y_PDN BIT(2)
#define TW9900_REG_ANALOG_CTL_C_PDN BIT(1)
@@ -60,6 +67,8 @@
#define TW9900_REG_STDR 0x1D
#define TW9900_REG_MISSCNT 0x26
#define TW9900_REG_MISC_CTL_II 0x2F
+#define TW9900_REG_CHIP_STATUS_II 0x31
+#define TW9900_REG_CHIP_STATUS_II_NINTL BIT(3)
#define TW9900_REG_VVBI 0x55
#define TW9900_CHIP_ID 0x00
@@ -94,6 +103,12 @@ struct tw9900 {
bool streaming;
const struct tw9900_mode *cur_mode;
const struct tw9900_platform_data *pdata;
+
+ u32 input;
+ /* Set once s_routing has been called. */
+ bool routed;
+ /* The source was 240p/288p as of the latest querystd. */
+ bool progressive;
};
#define to_tw9900(sd) container_of(sd, struct tw9900, subdev)
@@ -186,6 +201,39 @@ static int tw9900_read_reg(struct i2c_client *client, u8 reg)
return ret;
}
+static int tw9900_apply_input(struct tw9900 *tw9900)
+{
+ int ret;
+ u8 val;
+
+ lockdep_assert_held(&tw9900->mutex);
+
+ ret = tw9900_read_reg(tw9900->client, TW9900_REG_INFORM);
+ if (ret < 0)
+ return ret;
+
+ val = ret & ~(TW9900_REG_INFORM_IFSEL_MASK |
+ TW9900_REG_INFORM_YSEL_MASK);
+ if (tw9900->input == TW9900_INPUT_SVIDEO)
+ val |= TW9900_REG_INFORM_IFSEL_SVIDEO |
+ TW9900_REG_INFORM_YSEL_MUX1;
+
+ ret = tw9900_write_reg(tw9900->client, TW9900_REG_INFORM, val);
+ if (ret)
+ return ret;
+
+ ret = tw9900_read_reg(tw9900->client, TW9900_REG_ANALOG_CTL);
+ if (ret < 0)
+ return ret;
+
+ val = ret & ~(TW9900_REG_ANALOG_CTL_SRESET |
+ TW9900_REG_ANALOG_CTL_C_PDN);
+ if (tw9900->input == TW9900_INPUT_COMPOSITE)
+ val |= TW9900_REG_ANALOG_CTL_C_PDN;
+
+ return tw9900_write_reg(tw9900->client, TW9900_REG_ANALOG_CTL, val);
+}
+
static int tw9900_write_mode(struct tw9900 *tw9900)
{
const struct tw9900_platform_data *pdata = tw9900->pdata;
@@ -203,12 +251,14 @@ static int tw9900_write_mode(struct tw9900 *tw9900)
pdata->n_pal_regs);
}
-static void tw9900_fill_fmt(const struct tw9900_mode *mode,
+static void tw9900_fill_fmt(struct tw9900 *tw9900,
struct v4l2_mbus_framefmt *fmt)
{
+ const struct tw9900_mode *mode = tw9900->cur_mode;
+
fmt->code = MEDIA_BUS_FMT_UYVY8_2X8;
fmt->width = mode->width;
- fmt->height = mode->height;
+ fmt->height = tw9900->progressive ? mode->height / 2 : mode->height;
fmt->field = V4L2_FIELD_NONE;
fmt->quantization = V4L2_QUANTIZATION_DEFAULT;
fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
@@ -224,7 +274,7 @@ static int tw9900_get_fmt(struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format;
mutex_lock(&tw9900->mutex);
- tw9900_fill_fmt(tw9900->cur_mode, mbus_fmt);
+ tw9900_fill_fmt(tw9900, mbus_fmt);
mutex_unlock(&tw9900->mutex);
return 0;
@@ -245,7 +295,7 @@ static int tw9900_set_fmt(struct v4l2_subdev *sd,
return -EBUSY;
}
- tw9900_fill_fmt(tw9900->cur_mode, mbus_fmt);
+ tw9900_fill_fmt(tw9900, mbus_fmt);
mutex_unlock(&tw9900->mutex);
@@ -387,6 +437,42 @@ static int tw9900_subscribe_event(struct v4l2_subdev *sd,
}
}
+static int tw9900_s_routing(struct v4l2_subdev *sd, u32 input, u32 output,
+ u32 config)
+{
+ struct tw9900 *tw9900 = to_tw9900(sd);
+ int ret;
+
+ if (input != TW9900_INPUT_COMPOSITE && input != TW9900_INPUT_SVIDEO)
+ return -EINVAL;
+
+ mutex_lock(&tw9900->mutex);
+
+ if (tw9900->streaming) {
+ mutex_unlock(&tw9900->mutex);
+ return -EBUSY;
+ }
+
+ tw9900->input = input;
+ tw9900->routed = true;
+ /* A new input needs a new querystd to detect progressive sources. */
+ tw9900->progressive = false;
+
+ mutex_unlock(&tw9900->mutex);
+
+ ret = pm_runtime_resume_and_get(&tw9900->client->dev);
+ if (ret < 0)
+ return ret;
+
+ mutex_lock(&tw9900->mutex);
+ ret = tw9900_apply_input(tw9900);
+ mutex_unlock(&tw9900->mutex);
+
+ pm_runtime_put_autosuspend(&tw9900->client->dev);
+
+ return ret;
+}
+
static int tw9900_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
{
struct tw9900 *tw9900 = to_tw9900(sd);
@@ -513,6 +599,9 @@ static int tw9900_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
return -EBUSY;
}
+ /* Drop the previous result; it is only set again on success. */
+ tw9900->progressive = false;
+
mutex_unlock(&tw9900->mutex);
ret = pm_runtime_resume_and_get(&tw9900->client->dev);
@@ -542,6 +631,15 @@ static int tw9900_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
}
ret = tw9900_get_stream_std(tw9900, std);
+ if (ret || *std == V4L2_STD_UNKNOWN)
+ goto out_unlock;
+
+ ret = tw9900_read_reg(tw9900->client, TW9900_REG_CHIP_STATUS_II);
+ if (ret < 0)
+ goto out_unlock;
+
+ tw9900->progressive = !!(ret & TW9900_REG_CHIP_STATUS_II_NINTL);
+ ret = 0;
out_unlock:
mutex_unlock(&tw9900->mutex);
@@ -586,7 +684,12 @@ static int tw9900_g_input_status(struct v4l2_subdev *sd, u32 *status)
if (ret < 0)
return ret;
- *status = ret & TW9900_REG_CHIP_STATUS_HLOCK ? 0 : V4L2_IN_ST_NO_SIGNAL;
+ if (!(ret & TW9900_REG_CHIP_STATUS_HLOCK))
+ *status = V4L2_IN_ST_NO_SIGNAL;
+ else if (!(ret & TW9900_REG_CHIP_STATUS_VLOCK))
+ *status = V4L2_IN_ST_NO_V_LOCK;
+ else
+ *status = 0;
return 0;
}
@@ -597,6 +700,7 @@ static const struct v4l2_subdev_core_ops tw9900_core_ops = {
};
static const struct v4l2_subdev_video_ops tw9900_video_ops = {
+ .s_routing = tw9900_s_routing,
.s_std = tw9900_s_std,
.g_std = tw9900_g_std,
.querystd = tw9900_querystd,
@@ -688,6 +792,9 @@ static int tw9900_runtime_resume(struct device *dev)
ret = tw9900_write_array(tw9900->client, tw9900_init_regs,
ARRAY_SIZE(tw9900_init_regs));
+ if (!ret && tw9900->routed)
+ ret = tw9900_apply_input(tw9900);
+
if (ret) {
if (tw9900->reset_gpio)
gpiod_set_value_cansleep(tw9900->reset_gpio, 1);
diff --git a/include/media/i2c/tw9900.h b/include/media/i2c/tw9900.h
index 11e3bfe38e2b..4de03873aeb4 100644
--- a/include/media/i2c/tw9900.h
+++ b/include/media/i2c/tw9900.h
@@ -8,6 +8,10 @@
#include <linux/types.h>
+/* Inputs for the s_routing video op */
+#define TW9900_INPUT_COMPOSITE 0 /* composite on Mux0 */
+#define TW9900_INPUT_SVIDEO 1 /* Y on Mux1, C on the chroma input */
+
struct tw9900_regval {
u8 addr;
u8 val;
--
2.47.3
next prev parent reply other threads:[~2026-11-21 3:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 3:55 [PATCH v7 00/12] Add driver for StarTech USB3HDCAP capture device Matthew Laux
2026-11-21 3:55 ` [PATCH v7 01/12] media: tw9900: Disable regulator on runtime resume failure Matthew Laux
2026-11-21 3:55 ` [PATCH v7 02/12] media: tw9900: release the device when stopping the stream fails Matthew Laux
2026-11-21 3:55 ` [PATCH v7 03/12] media: tw9900: accept the TW9910 chip ID Matthew Laux
2026-11-21 3:55 ` [PATCH v7 04/12] media: tw9900: add saturation, hue and sharpness controls Matthew Laux
2026-11-21 3:55 ` [PATCH v7 05/12] media: tw9900: program all mode registers in the PAL table Matthew Laux
2026-11-21 3:55 ` [PATCH v7 06/12] media: tw9900: power off the device on remove if still active Matthew Laux
2026-11-21 3:55 ` [PATCH v7 07/12] media: tw9900: power down analog blocks in runtime suspend Matthew Laux
2026-11-21 3:55 ` [PATCH v7 08/12] media: tw9900: use runtime PM autosuspend Matthew Laux
2026-11-21 3:55 ` [PATCH v7 09/12] media: tw9900: allow board-specific register tables via platform data Matthew Laux
2026-11-21 3:55 ` Matthew Laux [this message]
2026-11-25 14:38 ` [PATCH v7 10/12] media: tw9900: add S-Video input and progressive source detection Markus Elfring
2026-11-25 19:47 ` Matthew Laux
2026-11-21 3:55 ` [PATCH v7 11/12] media: Add subdevice driver for the Mstar MST3367 HDMI receiver Matthew Laux
2026-11-25 13:17 ` Hans Verkuil
2026-11-25 19:33 ` Matthew Laux
2026-11-21 3:55 ` [PATCH v7 12/12] media: add driver for StarTech USB3HDCAP Matthew Laux
2026-11-25 13:39 ` Hans Verkuil
2026-11-25 19:45 ` Matthew Laux
2026-11-25 13:41 ` [PATCH v7 00/12] Add driver for StarTech USB3HDCAP capture device Hans Verkuil
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=20261121035523.26764-11-matthew.laux@gmail.com \
--to=matthew.laux@gmail.com \
--cc=hverkuil@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=mehdi.djait@bootlin.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.