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 v6 5/8] media: tw9900: allow board-specific register tables via platform data
Date: Wed, 18 Nov 2026 14:43:02 -0600 [thread overview]
Message-ID: <20261118204305.28268-6-matthew.laux@gmail.com> (raw)
In-Reply-To: <20261118204305.28268-1-matthew.laux@gmail.com>
Allow bridge drivers to supply initial configuration data for the tw9900.
Behavior for the original configuration supported by the driver is
unchanged. Fall back to the existing initialization data if none is
supplied by the bridge device.
Signed-off-by: Matthew Laux <matthew.laux@gmail.com>
---
MAINTAINERS | 1 +
drivers/media/i2c/tw9900.c | 49 ++++++++++++++++++++++++++------------
include/media/i2c/tw9900.h | 34 ++++++++++++++++++++++++++
3 files changed, 69 insertions(+), 15 deletions(-)
create mode 100644 include/media/i2c/tw9900.h
diff --git a/MAINTAINERS b/MAINTAINERS
index c08aade46f61..102362c386fe 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -27505,6 +27505,7 @@ M: Mehdi Djait <mehdi.djait@bootlin.com>
L: linux-media@vger.kernel.org
S: Maintained
F: drivers/media/i2c/tw9900.c
+F: include/media/i2c/tw9900.h
TECHWELL TW9910 VIDEO DECODER
L: linux-media@vger.kernel.org
diff --git a/drivers/media/i2c/tw9900.c b/drivers/media/i2c/tw9900.c
index 4d0d437d02f3..95e8e306469f 100644
--- a/drivers/media/i2c/tw9900.c
+++ b/drivers/media/i2c/tw9900.c
@@ -16,6 +16,7 @@
#include <linux/module.h>
#include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
+#include <media/i2c/tw9900.h>
#include <media/media-entity.h>
#include <media/v4l2-async.h>
#include <media/v4l2-ctrls.h>
@@ -70,16 +71,11 @@
#define TW9900_VIDEO_POLL_TRIES 20
#define TW9900_AUTOSUSPEND_DELAY_MS 1000
-struct regval {
- u8 addr;
- u8 val;
-};
-
struct tw9900_mode {
u32 width;
u32 height;
u32 std;
- const struct regval *reg_list;
+ const struct tw9900_regval *reg_list;
int n_regs;
};
@@ -97,11 +93,12 @@ struct tw9900 {
bool streaming;
const struct tw9900_mode *cur_mode;
+ const struct tw9900_platform_data *pdata;
};
#define to_tw9900(sd) container_of(sd, struct tw9900, subdev)
-static const struct regval tw9900_init_regs[] = {
+static const struct tw9900_regval tw9900_init_regs[] = {
{ TW9900_REG_MISC_CTL_II, 0xE6 },
{ TW9900_REG_MISSCNT, 0x24 },
{ TW9900_REG_OUT_FMT_CTL, 0xA7 },
@@ -116,11 +113,11 @@ static const struct regval tw9900_init_regs[] = {
{ TW9900_REG_OUT_CTRL_I, 0x98 },
};
-static const struct regval tw9900_pal_regs[] = {
+static const struct tw9900_regval tw9900_pal_regs[] = {
{ TW9900_REG_STD, 0x01 },
};
-static const struct regval tw9900_ntsc_regs[] = {
+static const struct tw9900_regval tw9900_ntsc_regs[] = {
{ TW9900_REG_OUT_FMT_CTL, 0xA4 },
{ TW9900_REG_VDELAY_LO, 0x12 },
{ TW9900_REG_VACTIVE_LO, 0xF0 },
@@ -159,7 +156,7 @@ static int tw9900_write_reg(struct i2c_client *client, u8 reg, u8 val)
}
static int tw9900_write_array(struct i2c_client *client,
- const struct regval *regs, int n_regs)
+ const struct tw9900_regval *regs, int n_regs)
{
int i, ret = 0;
@@ -183,6 +180,23 @@ static int tw9900_read_reg(struct i2c_client *client, u8 reg)
return ret;
}
+static int tw9900_write_mode(struct tw9900 *tw9900)
+{
+ const struct tw9900_platform_data *pdata = tw9900->pdata;
+ const struct tw9900_mode *mode = tw9900->cur_mode;
+
+ if (!pdata)
+ return tw9900_write_array(tw9900->client, mode->reg_list,
+ mode->n_regs);
+
+ if (mode->std & V4L2_STD_NTSC)
+ return tw9900_write_array(tw9900->client, pdata->ntsc_regs,
+ pdata->n_ntsc_regs);
+
+ return tw9900_write_array(tw9900->client, pdata->pal_regs,
+ pdata->n_pal_regs);
+}
+
static void tw9900_fill_fmt(const struct tw9900_mode *mode,
struct v4l2_mbus_framefmt *fmt)
{
@@ -316,9 +330,7 @@ static int tw9900_s_stream(struct v4l2_subdev *sd, int on)
if (ret)
goto err_unlock;
- ret = tw9900_write_array(tw9900->client,
- tw9900->cur_mode->reg_list,
- tw9900->cur_mode->n_regs);
+ ret = tw9900_write_mode(tw9900);
if (ret)
goto err_unlock;
@@ -662,8 +674,14 @@ static int tw9900_runtime_resume(struct device *dev)
usleep_range(1000, 2000);
- ret = tw9900_write_array(tw9900->client, tw9900_init_regs,
- ARRAY_SIZE(tw9900_init_regs));
+ if (tw9900->pdata)
+ ret = tw9900_write_array(tw9900->client,
+ tw9900->pdata->init_regs,
+ tw9900->pdata->n_init_regs);
+ else
+ ret = tw9900_write_array(tw9900->client, tw9900_init_regs,
+ ARRAY_SIZE(tw9900_init_regs));
+
if (ret) {
if (tw9900->reset_gpio)
gpiod_set_value_cansleep(tw9900->reset_gpio, 1);
@@ -727,6 +745,7 @@ static int tw9900_probe(struct i2c_client *client)
tw9900->client = client;
tw9900->cur_mode = &supported_modes[0];
+ tw9900->pdata = dev_get_platdata(dev);
tw9900->reset_gpio = devm_gpiod_get_optional(dev, "reset",
GPIOD_OUT_LOW);
diff --git a/include/media/i2c/tw9900.h b/include/media/i2c/tw9900.h
new file mode 100644
index 000000000000..11e3bfe38e2b
--- /dev/null
+++ b/include/media/i2c/tw9900.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Techwell TW9900 multi-standard video decoder
+ */
+
+#ifndef _MEDIA_I2C_TW9900_H_
+#define _MEDIA_I2C_TW9900_H_
+
+#include <linux/types.h>
+
+struct tw9900_regval {
+ u8 addr;
+ u8 val;
+};
+
+/**
+ * struct tw9900_platform_data - board-specific register setup
+ * @init_regs: written each time the decoder is powered up
+ * @n_init_regs: number of entries in @init_regs
+ * @ntsc_regs: written when streaming starts with a 525-line standard
+ * @n_ntsc_regs: number of entries in @ntsc_regs
+ * @pal_regs: written when streaming starts with a 625-line standard
+ * @n_pal_regs: number of entries in @pal_regs
+ */
+struct tw9900_platform_data {
+ const struct tw9900_regval *init_regs;
+ unsigned int n_init_regs;
+ const struct tw9900_regval *ntsc_regs;
+ unsigned int n_ntsc_regs;
+ const struct tw9900_regval *pal_regs;
+ unsigned int n_pal_regs;
+};
+
+#endif
--
2.47.3
next prev parent reply other threads:[~2026-11-18 20:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 20:42 [PATCH v6 0/8] Add driver for StarTech USB3HDCAP capture device Matthew Laux
2026-11-18 20:42 ` [PATCH v6 1/8] media: tw9900: Disable regulator on runtime resume failure Matthew Laux
2026-11-18 20:42 ` [PATCH v6 2/8] media: tw9900: accept the TW9910 chip ID Matthew Laux
2026-11-18 20:43 ` [PATCH v6 3/8] media: tw9900: add saturation, hue and sharpness controls Matthew Laux
2026-11-18 20:43 ` [PATCH v6 4/8] media: tw9900: use runtime PM autosuspend and power down on suspend Matthew Laux
2026-11-18 20:43 ` Matthew Laux [this message]
2026-11-18 20:43 ` [PATCH v6 6/8] media: tw9900: add S-Video input and progressive source detection Matthew Laux
2026-11-18 20:43 ` [PATCH v6 7/8] media: Add subdevice driver for the Mstar MST3367 HDMI receiver Matthew Laux
2026-11-18 20:43 ` [PATCH v6 8/8] media: add driver for StarTech USB3HDCAP Matthew Laux
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=20261118204305.28268-6-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 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®