Skip to contentSkip to conversation

Add driver for StarTech USB3HDCAP capture device

PATCH New Matthew Laux 1 participant 13 messages Nov 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v7 cover Add driver for StarTech USB3HDCAP capture device

Add a V4L2/ALSA driver for the StarTech USB3HDCAP (and Micomsoft XCAPTURE-1 variant), a USB 3.0 video capture device based on the MST3367 HDMI receiver, TW9900 composite decoder, and CS53L21 audio codec.

The driver supports composite, S-Video, component, and HDMI inputs, including audio capture.

Tested on all four inputs at various resolutions. All v4l2-compliance tests pass, including streaming tests, with these two v4l2-compliance bugs patched:

https://lore.kernel.org/linux-media/[email protected]/T/#u
https://lore.kernel.org/linux-media/[email protected]/T/#u

The first 10 patches are changes to the existing upstream tw9900 driver to prepare for my driver. The 11th is a driver for the MST3367 chip. The 12th is the bridge device driver and "everything else".

I tried to use patterns from existing drivers wherever possible and welcome all feedback. This is my own work. I accepted two small PRs to my out-of-tree in-development version on GitHub that were LLM-assisted. I also used LLM help to split the tw9900 fixes into logical commits, and for help understanding/fixing Sashiko feedback. I am committed to sticking around to make any improvements required.

Thanks,
Matthew

Changelog:

v7: rework ioctls to follow the API better:
- S_STD/S_DV_TIMINGS now apply immediately and update the format
- add QUERYSTD
- QUERY_DV_TIMINGS now gets the timings from the chip
detection now only happens in S_INPUT (or first open) starting streaming no longer can change the required buffer size size the parse buffer from the iso packet size
use V4L2's AVI InfoFrame parsing instead of my own report the field height in get_fmt for interlaced timings accept vtotal alternating by one line when detecting interlaced split "use runtime PM autosuspend and power down on suspend" 2 new tw9900 runtime PM fixes

v6: fix 2 possible usages of uninitialized variables (one could not
happen, one could)

v5: refactor to use subdevices, so it's no longer targeting staging.
support HDMI on the XCAPTURE-1
detect HDMI timings from the chip instead of using a fixed table fix (valid) Sashiko automated review feedback
fix composite/S-Video audio on the XCAPTURE-1

v4: add USB to Kconfig "depends on"... oops. fixes randconfig

v3: fix truncation warnings in (u8) casts >= 0x80, static-ify mode table

v2: remove unused CSC matrix control, remove version.h include,
fix all remaining check-level checkpatch issues, update TODO

v4l2-compliance 1.33.0-5524, 64 bits, 64-bit time_t v4l2-compliance SHA: 485c038f10ae 2026-10-30 13:45:36

Compliance test for usb3hdcap device /dev/video0:

Driver Info:

	Driver name      : usb3hdcap
	Card type        : StarTech USB3HDCAP
	Bus info         : usb-0000:00:14.0-2
	Driver version   : 7.0.0
	Capabilities     : 0x85200001

Video Capture
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x05200001
Video Capture
Read/Write
Streaming
Extended Pix Format

Required ioctls:
test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 4 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK
test VIDIOC_DV_TIMINGS_CAP: OK
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 8 Private Controls: 0

Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test CREATE_BUFS maximum buffers: OK test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported) test Requests: OK (Not Supported) test blocking wait: OK

Control ioctls (Input 1):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 8 Private Controls: 0

Format ioctls (Input 1):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls (Input 1):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls (Input 1):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test CREATE_BUFS maximum buffers: OK test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported) test Requests: OK (Not Supported) test blocking wait: OK

Control ioctls (Input 2):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 8 Private Controls: 0

Format ioctls (Input 2):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls (Input 2):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls (Input 2):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test CREATE_BUFS maximum buffers: OK test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported) test Requests: OK (Not Supported) test blocking wait: OK

Control ioctls (Input 3):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 8 Private Controls: 0

Format ioctls (Input 3):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls (Input 3):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls (Input 3):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test CREATE_BUFS maximum buffers: OK test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported) test Requests: OK (Not Supported) test blocking wait: OK

Test input 0:

Streaming ioctls:
test read/write: OK
test MMAP (no poll, REQBUFS): OK
test MMAP (select, REQBUFS): OK
test MMAP (epoll, REQBUFS): OK
test MMAP (no poll, CREATE_BUFS): OK
test MMAP (select, CREATE_BUFS): OK
test MMAP (epoll, CREATE_BUFS): OK
test USERPTR (no poll): OK
test USERPTR (select): OK
test DMABUF (no poll): OK (Not Supported)
test DMABUF (select): OK (Not Supported)

Test input 1:

Streaming ioctls:
test read/write: OK
test MMAP (no poll, REQBUFS): OK
test MMAP (select, REQBUFS): OK
test MMAP (epoll, REQBUFS): OK
test MMAP (no poll, CREATE_BUFS): OK
test MMAP (select, CREATE_BUFS): OK
test MMAP (epoll, CREATE_BUFS): OK
test USERPTR (no poll): OK
test USERPTR (select): OK
test DMABUF (no poll): OK (Not Supported)
test DMABUF (select): OK (Not Supported)

Test input 2:

Streaming ioctls:
test read/write: OK
test MMAP (no poll, REQBUFS): OK
test MMAP (select, REQBUFS): OK
test MMAP (epoll, REQBUFS): OK
test MMAP (no poll, CREATE_BUFS): OK
test MMAP (select, CREATE_BUFS): OK
test MMAP (epoll, CREATE_BUFS): OK
test USERPTR (no poll): OK
test USERPTR (select): OK
test DMABUF (no poll): OK (Not Supported)
test DMABUF (select): OK (Not Supported)

Test input 3:

Streaming ioctls:
test read/write: OK
test MMAP (no poll, REQBUFS): OK
test MMAP (select, REQBUFS): OK
test MMAP (epoll, REQBUFS): OK
test MMAP (no poll, CREATE_BUFS): OK
test MMAP (select, CREATE_BUFS): OK
test MMAP (epoll, CREATE_BUFS): OK
test USERPTR (no poll): OK
test USERPTR (select): OK
test DMABUF (no poll): OK (Not Supported)
test DMABUF (select): OK (Not Supported)

Total for usb3hdcap device /dev/video0: 167, Succeeded: 167, Failed: 0,
Warnings: 0

Matthew Laux (12):
media: tw9900: Disable regulator on runtime resume failure
media: tw9900: release the device when stopping the stream fails
media: tw9900: accept the TW9910 chip ID
media: tw9900: add saturation, hue and sharpness controls
media: tw9900: program all mode registers in the PAL table
media: tw9900: power off the device on remove if still active
media: tw9900: power down analog blocks in runtime suspend
media: tw9900: use runtime PM autosuspend
media: tw9900: allow board-specific register tables via platform data
media: tw9900: add S-Video input and progressive source detection
media: Add subdevice driver for the Mstar MST3367 HDMI receiver
media: add driver for StarTech USB3HDCAP

 MAINTAINERS                                   |   14 +
 drivers/media/i2c/Kconfig                     |   11 +
 drivers/media/i2c/Makefile                    |    1 +
 drivers/media/i2c/mst3367.c                   | 1134 ++++++++++++++++
 drivers/media/i2c/tw9900.c                    |  271 +++-
 drivers/media/usb/Kconfig                     |    1 +
 drivers/media/usb/Makefile                    |    1 +
 drivers/media/usb/usb3hdcap/Kconfig           |   15 +
 drivers/media/usb/usb3hdcap/Makefile          |    8 +
 drivers/media/usb/usb3hdcap/usb3hdcap-audio.c |  323 +++++
 .../media/usb/usb3hdcap/usb3hdcap-composite.c |  212 +++
 drivers/media/usb/usb3hdcap/usb3hdcap-core.c  | 1173 +++++++++++++++++
 drivers/media/usb/usb3hdcap/usb3hdcap-hdmi.c  |  200 +++
 drivers/media/usb/usb3hdcap/usb3hdcap-video.c |  499 +++++++
 drivers/media/usb/usb3hdcap/usb3hdcap.h       |  241 ++++
 include/media/i2c/mst3367.h                   |   27 +
 include/media/i2c/tw9900.h                    |   38 +
 17 files changed, 4135 insertions(+), 34 deletions(-)
 create mode 100644 drivers/media/i2c/mst3367.c
 create mode 100644 drivers/media/usb/usb3hdcap/Kconfig
 create mode 100644 drivers/media/usb/usb3hdcap/Makefile
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap-audio.c
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap-composite.c
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap-core.c
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap-hdmi.c
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap-video.c
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap.h
 create mode 100644 include/media/i2c/mst3367.h
 create mode 100644 include/media/i2c/tw9900.h

base-commit: aa0f4c41d4870a18e65772a1817af16427200371

Signature · 1 line
2.47.3
#1 lore raw

PATCH v7 1/12 media: tw9900: Disable regulator on runtime resume failure

If writing the initialization registers fails, put the chip back in reset and disable the regulator before returning the error. Fixes this warning:

WARNING: drivers/regulator/core.c:2657 at regulator_put+0x61/0x70
RIP: 0010:regulator_put+0x61/0x70
Call Trace:
 <TASK>
 release_nodes+0x46/0xd0
 devres_release_group+0x11f/0x150
 i2c_device_remove+0x41/0xb0
 device_release_driver_internal+0x19c/0x200
 bus_remove_device+0xca/0x140
 device_del+0x160/0x3e0
 device_unregister+0x17/0x70
 v4l2_device_unregister+0x9c/0xd0 [videodev]
 usb3hdcap_release+0x26/0x40 [usb3hdcap]
 v4l2_device_put+0x37/0x60 [videodev]
 release_card_device+0x51/0x90 [snd]
 device_release+0x37/0x90
 kobject_put+0x8e/0x210
 snd_card_file_remove+0x174/0x190 [snd]
 snd_ctl_release+0x14d/0x160 [snd]
 __fput+0xe6/0x2a0
 __x64_sys_close+0x3d/0x80
 do_syscall_64+0x120/0x1610
 ? do_syscall_64+0x15e/0x1610
 ? irqentry_exit+0x7b/0x590
 entry_SYSCALL_64_after_hwframe+0x76/0x7e
Fixes 918b14a26b12 ("media: i2c: Introduce a driver for the Techwell TW9900 decoder")
Cc Paul Kocialkowski <[email protected]>
---
 drivers/media/i2c/tw9900.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/media/i2c/tw9900.c +8 -1
index 60c102aba750..e07924faa84b 100644
@@ -624,13 +624,20 @@ static int tw9900_runtime_resume(struct device *dev)
 
 	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);
+		regulator_disable(tw9900->regulator);
+		mutex_unlock(&tw9900->mutex);
+		return ret;
+	}
 
 	mutex_unlock(&tw9900->mutex);
 
 	/* This sleep is needed for the Horizontal Sync PLL to lock. */
 	msleep(300);
 
-	return ret;
+	return 0;
 }
 
 static int tw9900_runtime_suspend(struct device *dev)
Signature · 1 line
2.47.3
#2 lore raw

PATCH v7 2/12 media: tw9900: release the device when stopping the stream fails

In reply to Matthew Laux

If writing the register to stop streaming fails, the error path dropped the runtime PM reference but left tw9900->streaming set. Then, s_stream(0) again would drop the reference again and unbalance the usage count. At that point any s_stream() is ignored because the driver thinks it's streaming. Always clear the streaming state and drop the reference, and only report the error.

Fixes 918b14a26b12 ("media: i2c: Introduce a driver for the Techwell TW9900 decoder")
---
 drivers/media/i2c/tw9900.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/tw9900.c +2 -2
index e07924faa84b..e9d384039b50 100644
@@ -303,14 +303,14 @@ static int tw9900_s_stream(struct v4l2_subdev *sd, int on)
 
 		ret = tw9900_write_reg(client, TW9900_REG_OUT_FMT_CTL,
 				       TW9900_REG_OUT_FMT_CTL_STANDBY);
-		if (ret)
-			goto err_unlock;
 
 		tw9900->streaming = on;
 
 		mutex_unlock(&tw9900->mutex);
 
 		pm_runtime_put(&client->dev);
+
+		return ret;
 	}
 
 	return 0;
Signature · 1 line
2.47.3
#3 lore raw

PATCH v7 3/12 media: tw9900: accept the TW9910 chip ID

In reply to Matthew Laux

Allow tw9900.c to accept the tw9910's chip ID and revision fields as well as the tw9900's. The tw9910 is a superset of the tw9900 for the functionality used by the tw9900 driver, and USB3HDCAP/XCAPTURE-1 capture devices can have either chip.

---
 drivers/media/i2c/tw9900.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/media/i2c/tw9900.c +13 -3
index e9d384039b50..df8c7b1f3450 100644
@@ -23,6 +23,8 @@
 #include <media/v4l2-subdev.h>
 
 #define TW9900_REG_CHIP_ID			0x00
+#define TW9900_REG_CHIP_ID_ID_MASK		GENMASK(7, 3)
+#define TW9900_REG_CHIP_ID_REV_MASK		GENMASK(2, 0)
 #define TW9900_REG_CHIP_STATUS			0x01
 #define TW9900_REG_CHIP_STATUS_VDLOSS		BIT(7)
 #define TW9900_REG_CHIP_STATUS_HLOCK		BIT(6)
@@ -51,6 +53,7 @@
 #define TW9900_REG_VVBI				0x55
 
 #define TW9900_CHIP_ID				0x00
+#define TW9910_CHIP_ID				0x0B
 #define TW9900_STD_NTSC_M			0
 #define TW9900_STD_PAL_BDGHI			1
 #define TW9900_STD_AUTO				7
@@ -574,6 +577,7 @@ static int tw9900_check_id(struct tw9900 *tw9900,
 			   struct i2c_client *client)
 {
 	struct device *dev = &tw9900->client->dev;
+	u8 id, rev;
 	int ret;
 
 	ret = pm_runtime_resume_and_get(&tw9900->client->dev);
@@ -581,7 +585,7 @@ static int tw9900_check_id(struct tw9900 *tw9900,
 		return ret;
 
 	mutex_lock(&tw9900->mutex);
-	ret = tw9900_read_reg(client, TW9900_CHIP_ID);
+	ret = tw9900_read_reg(client, TW9900_REG_CHIP_ID);
 	mutex_unlock(&tw9900->mutex);
 
 	pm_runtime_put(&tw9900->client->dev);
@@ -589,11 +593,17 @@ static int tw9900_check_id(struct tw9900 *tw9900,
 	if (ret < 0)
 		return ret;
 
-	if (ret != TW9900_CHIP_ID) {
-		dev_err(dev, "Unexpected decoder id %#x\n", ret);
+	id = FIELD_GET(TW9900_REG_CHIP_ID_ID_MASK, ret);
+	rev = FIELD_GET(TW9900_REG_CHIP_ID_REV_MASK, ret);
+
+	if (id != TW9900_CHIP_ID && id != TW9910_CHIP_ID) {
+		dev_err(dev, "Unexpected decoder id %#x (rev %u)\n", id, rev);
 		return -ENODEV;
 	}
 
+	dev_dbg(dev, "Found %s revision %u\n",
+		id == TW9910_CHIP_ID ? "TW9910" : "TW9900", rev);
+
 	return 0;
 }
 
Signature · 1 line
2.47.3
#4 lore raw

PATCH v7 4/12 media: tw9900: add saturation, hue and sharpness controls

In reply to Matthew Laux

Add additional V4L2 controls for the tw9900 that modify the appropriate registers for saturation, hue, and sharpness, sourced from the datasheet.

---
 drivers/media/i2c/tw9900.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
drivers/media/i2c/tw9900.c +32 -1
index df8c7b1f3450..42fc2afbbc77 100644
@@ -41,6 +41,11 @@
 #define TW9900_REG_CNTRL1			0x0C
 #define TW9900_REG_BRIGHT_CTL			0x10
 #define TW9900_REG_CONTRAST_CTL			0x11
+#define TW9900_REG_SHARPNESS			0x12
+#define TW9900_REG_SHARPNESS_MASK		GENMASK(3, 0)
+#define TW9900_REG_SAT_U			0x13
+#define TW9900_REG_SAT_V			0x14
+#define TW9900_REG_HUE				0x15
 #define TW9900_REG_VBI_CNTL			0x19
 #define TW9900_REG_ANAL_CTL_II			0x1A
 #define TW9900_REG_OUT_CTRL_II			0x1B
@@ -252,6 +257,26 @@ static int tw9900_s_ctrl(struct v4l2_ctrl *ctrl)
 		ret = tw9900_write_reg(tw9900->client, TW9900_REG_CONTRAST_CTL,
 				       (u8)ctrl->val);
 		break;
+	case V4L2_CID_SATURATION:
+		ret = tw9900_write_reg(tw9900->client, TW9900_REG_SAT_U,
+				       (u8)ctrl->val);
+		if (ret)
+			break;
+		ret = tw9900_write_reg(tw9900->client, TW9900_REG_SAT_V,
+				       (u8)ctrl->val);
+		break;
+	case V4L2_CID_HUE:
+		ret = tw9900_write_reg(tw9900->client, TW9900_REG_HUE,
+				       (u8)ctrl->val);
+		break;
+	case V4L2_CID_SHARPNESS:
+		ret = tw9900_read_reg(tw9900->client, TW9900_REG_SHARPNESS);
+		if (ret < 0)
+			break;
+		ret = tw9900_write_reg(tw9900->client, TW9900_REG_SHARPNESS,
+				       (ret & ~TW9900_REG_SHARPNESS_MASK) |
+				       ctrl->val);
+		break;
 	default:
 		ret = -EINVAL;
 		break;
@@ -701,7 +726,7 @@ static int tw9900_probe(struct i2c_client *client)
 
 	hdl = &tw9900->hdl;
 
-	ret = v4l2_ctrl_handler_init(hdl, 2);
+	ret = v4l2_ctrl_handler_init(hdl, 5);
 	if (ret)
 		goto err_destory_mutex;
 
@@ -711,6 +736,12 @@ static int tw9900_probe(struct i2c_client *client)
 			  -128, 127, 1, 0);
 	v4l2_ctrl_new_std(hdl, &tw9900_ctrl_ops, V4L2_CID_CONTRAST,
 			  0, 255, 1, 0x60);
+	v4l2_ctrl_new_std(hdl, &tw9900_ctrl_ops, V4L2_CID_SATURATION,
+			  0, 255, 1, 0x80);
+	v4l2_ctrl_new_std(hdl, &tw9900_ctrl_ops, V4L2_CID_HUE,
+			  -128, 127, 1, 0);
+	v4l2_ctrl_new_std(hdl, &tw9900_ctrl_ops, V4L2_CID_SHARPNESS,
+			  0, 15, 1, 1);
 
 	tw9900->subdev.ctrl_handler = hdl;
 	if (hdl->error) {
Signature · 1 line
2.47.3
#5 lore raw

PATCH v7 5/12 media: tw9900: program all mode registers in the PAL table

In reply to Matthew Laux

tw9900_ntsc_regs set VDELAY_LO, VACTIVE_LO, CROP_HI, HACTIVE_LO and VBI_CNTL, but tw9900_pal_regs only set the standard register. PAL capture therefore relied on a runtime resume having reset the chip and rewritten the init table since the last NTSC stream. Make the PAL table write the same registers as the NTSC table.

---
 drivers/media/i2c/tw9900.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/media/i2c/tw9900.c +6 -0
index 42fc2afbbc77..6309d9eda243 100644
@@ -112,6 +112,12 @@ static const struct regval tw9900_init_regs[] = {
 };
 
 static const struct regval tw9900_pal_regs[] = {
+	{ TW9900_REG_OUT_FMT_CTL,	0xA7 },
+	{ TW9900_REG_VDELAY_LO,		0x19 },
+	{ TW9900_REG_VACTIVE_LO,	0xF0 },
+	{ TW9900_REG_CROP_HI,		0x02 },
+	{ TW9900_REG_HACTIVE_LO,	0xD0 },
+	{ TW9900_REG_VBI_CNTL,		0x58 },
 	{ TW9900_REG_STD,		0x01 },
 };
 
Signature · 1 line
2.47.3
#6 lore raw

PATCH v7 6/12 media: tw9900: power off the device on remove if still active

In reply to Matthew Laux

tw9900_remove() and the probe error path only call pm_runtime_disable(), which does not invoke the runtime suspend callback. If the device is active at that point, e.g. when a USB bridge is unplugged while streaming, the vdd regulator is left enabled and devres then puts it, which triggers:

  WARNING: drivers/regulator/core.c:2657 at regulator_put+0x61/0x70
  ...
   release_nodes+0x46/0xd0
   devres_release_group+0x11f/0x150
   i2c_device_remove+0x41/0xb0

Suspend the device manually when it is not already suspended, then mark it suspended, following the usual pattern for sensor drivers.

Fixes 918b14a26b12 ("media: i2c: Introduce a driver for the Techwell TW9900 decoder")
---
 drivers/media/i2c/tw9900.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/media/i2c/tw9900.c +10 -2
index 6309d9eda243..585509c1b41d 100644
@@ -699,6 +699,14 @@ static int tw9900_runtime_suspend(struct device *dev)
 	return 0;
 }
 
+static void tw9900_pm_cleanup(struct device *dev)
+{
+	pm_runtime_disable(dev);
+	if (!pm_runtime_status_suspended(dev))
+		tw9900_runtime_suspend(dev);
+	pm_runtime_set_suspended(dev);
+}
+
 static int tw9900_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
@@ -778,7 +786,7 @@ static int tw9900_probe(struct i2c_client *client)
 	return 0;
 
 err_disable_pm:
-	pm_runtime_disable(dev);
+	tw9900_pm_cleanup(dev);
 	media_entity_cleanup(&tw9900->subdev.entity);
 err_free_handler:
 	v4l2_ctrl_handler_free(hdl);
@@ -797,7 +805,7 @@ static void tw9900_remove(struct i2c_client *client)
 	media_entity_cleanup(&sd->entity);
 	v4l2_ctrl_handler_free(sd->ctrl_handler);
 
-	pm_runtime_disable(&client->dev);
+	tw9900_pm_cleanup(&client->dev);
 
 	mutex_destroy(&tw9900->mutex);
 }
Signature · 1 line
2.47.3
#7 lore raw

PATCH v7 7/12 media: tw9900: power down analog blocks in runtime suspend

In reply to Matthew Laux

On boards without a controllable supply or reset GPIO, runtime suspend leaves the decoder fully powered. Set the CLK/Y/C power-down bits in ANALOG_CTL and the PLL power-down bit in ANAL_CTL_II before cutting power. Runtime resume rewrites both registers from the init table.

---
 drivers/media/i2c/tw9900.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/media/i2c/tw9900.c +11 -0
index 585509c1b41d..b2b754e898c2 100644
@@ -34,6 +34,9 @@
 #define TW9900_REG_CKHY_HSDLY			0x04
 #define TW9900_REG_OUT_CTRL_I			0x05
 #define TW9900_REG_ANALOG_CTL			0x06
+#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)
 #define TW9900_REG_CROP_HI			0x07
 #define TW9900_REG_VDELAY_LO			0x08
 #define TW9900_REG_VACTIVE_LO			0x09
@@ -48,6 +51,7 @@
 #define TW9900_REG_HUE				0x15
 #define TW9900_REG_VBI_CNTL			0x19
 #define TW9900_REG_ANAL_CTL_II			0x1A
+#define TW9900_REG_ANAL_CTL_II_PLL_PDN		BIT(6)
 #define TW9900_REG_OUT_CTRL_II			0x1B
 #define TW9900_REG_STD				0x1C
 #define TW9900_REG_STD_AUTO_PROGRESS		BIT(7)
@@ -689,6 +693,13 @@ static int tw9900_runtime_suspend(struct device *dev)
 
 	mutex_lock(&tw9900->mutex);
 
+	tw9900_write_reg(tw9900->client, TW9900_REG_ANALOG_CTL,
+			 TW9900_REG_ANALOG_CTL_CLK_PDN |
+			 TW9900_REG_ANALOG_CTL_Y_PDN |
+			 TW9900_REG_ANALOG_CTL_C_PDN);
+	tw9900_write_reg(tw9900->client, TW9900_REG_ANAL_CTL_II,
+			 TW9900_REG_ANAL_CTL_II_PLL_PDN);
+
 	if (tw9900->reset_gpio)
 		gpiod_set_value_cansleep(tw9900->reset_gpio, 1);
 
Signature · 1 line
2.47.3
#8 lore raw

PATCH v7 8/12 media: tw9900: use runtime PM autosuspend

In reply to Matthew Laux

Each runtime resume enables the supply, toggles reset, rewrites the init table and waits 300 ms for the horizontal sync PLL to lock. Without autosuspend, a typical chain of s_routing, polling g_input_status, querystd, and s_stream would suspend and repower the device each operation, which adds ~350 ms per call and discards the signal lock.

Use autosuspend with a 1sec delay so that closely spaced operations share a single power-up.

---
 drivers/media/i2c/tw9900.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/media/i2c/tw9900.c +9 -5
index b2b754e898c2..b2c30e84acb8 100644
@@ -68,6 +68,7 @@
 #define TW9900_STD_AUTO				7
 
 #define TW9900_VIDEO_POLL_TRIES			20
+#define TW9900_AUTOSUSPEND_DELAY_MS		1000
 
 struct regval {
 	u8 addr;
@@ -346,7 +347,7 @@ static int tw9900_s_stream(struct v4l2_subdev *sd, int on)
 
 		mutex_unlock(&tw9900->mutex);
 
-		pm_runtime_put(&client->dev);
+		pm_runtime_put_autosuspend(&client->dev);
 
 		return ret;
 	}
@@ -355,7 +356,7 @@ static int tw9900_s_stream(struct v4l2_subdev *sd, int on)
 
 err_unlock:
 	mutex_unlock(&tw9900->mutex);
-	pm_runtime_put(&client->dev);
+	pm_runtime_put_autosuspend(&client->dev);
 
 	return ret;
 }
@@ -532,7 +533,7 @@ static int tw9900_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
 
 out_unlock:
 	mutex_unlock(&tw9900->mutex);
-	pm_runtime_put(&tw9900->client->dev);
+	pm_runtime_put_autosuspend(&tw9900->client->dev);
 
 	return ret;
 }
@@ -568,7 +569,7 @@ static int tw9900_g_input_status(struct v4l2_subdev *sd, u32 *status)
 	ret = tw9900_read_reg(tw9900->client, TW9900_REG_CHIP_STATUS);
 	mutex_unlock(&tw9900->mutex);
 
-	pm_runtime_put(&tw9900->client->dev);
+	pm_runtime_put_autosuspend(&tw9900->client->dev);
 
 	if (ret < 0)
 		return ret;
@@ -623,7 +624,7 @@ static int tw9900_check_id(struct tw9900 *tw9900,
 	ret = tw9900_read_reg(client, TW9900_REG_CHIP_ID);
 	mutex_unlock(&tw9900->mutex);
 
-	pm_runtime_put(&tw9900->client->dev);
+	pm_runtime_put_autosuspend(&tw9900->client->dev);
 
 	if (ret < 0)
 		return ret;
@@ -712,6 +713,7 @@ static int tw9900_runtime_suspend(struct device *dev)
 
 static void tw9900_pm_cleanup(struct device *dev)
 {
+	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
 	if (!pm_runtime_status_suspended(dev))
 		tw9900_runtime_suspend(dev);
@@ -782,6 +784,8 @@ static int tw9900_probe(struct i2c_client *client)
 		goto err_free_handler;
 
 	pm_runtime_set_suspended(dev);
+	pm_runtime_set_autosuspend_delay(dev, TW9900_AUTOSUSPEND_DELAY_MS);
+	pm_runtime_use_autosuspend(dev);
 	pm_runtime_enable(dev);
 
 	ret = tw9900_check_id(tw9900, client);
Signature · 1 line
2.47.3
#9 lore raw

PATCH v7 9/12 media: tw9900: allow board-specific register tables via platform data

In reply to Matthew Laux

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.

---
 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
MAINTAINERS +1 -0
index c08aade46f61..102362c386fe 100644
@@ -27505,6 +27505,7 @@ M:	Mehdi Djait <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	drivers/media/i2c/tw9900.c
+F:	include/media/i2c/tw9900.h
 
 TECHWELL TW9910 VIDEO DECODER
 L:	[email protected]
drivers/media/i2c/tw9900.c +34 -15

117 lines not on this page · raw message

include/media/i2c/tw9900.h new file +34 -0
new file mode 100644
index 000000000000..11e3bfe38e2b
@@ -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
Signature · 1 line
2.47.3
#10 lore raw

PATCH v7 10/12 media: tw9900: add S-Video input and progressive source detection

In reply to Matthew Laux

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.

---
 drivers/media/i2c/tw9900.c | 117 +++++++++++++++++++++++++++++++++++--
 include/media/i2c/tw9900.h |   4 ++
 2 files changed, 116 insertions(+), 5 deletions(-)
drivers/media/i2c/tw9900.c +112 -5
index f4f07f060083..be939ce92c0d 100644
@@ -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);
include/media/i2c/tw9900.h +4 -0
index 11e3bfe38e2b..4de03873aeb4 100644
@@ -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;
Signature · 1 line
2.47.3
#11 lore raw

PATCH v7 11/12 media: Add subdevice driver for the Mstar MST3367 HDMI receiver

In reply to Matthew Laux

Implement a V4L2 subdevice driver for the MST3367. This was developed through reverse engineering the Windows driver, and capturing USB packets. The driver supports both HDMI and analog component inputs. YPbPr and RGB HDMI sources have been tested. I also added a couple custom DV timings for non-interlaced 240p and 288p over component, which are also tested and working with this chip.

I tested this with a ThinkPad's video output, MacBook (10-bit deep color), Nintendo Switch (both full and limited range) and PS4 720p/1080i/1080p.

---
 MAINTAINERS                 |    7 +
 drivers/media/i2c/Kconfig   |   11 +
 drivers/media/i2c/Makefile  |    1 +
 drivers/media/i2c/mst3367.c | 1134 +++++++++++++++++++++++++++++++++++
 include/media/i2c/mst3367.h |   27 +
 5 files changed, 1180 insertions(+)
 create mode 100644 drivers/media/i2c/mst3367.c
 create mode 100644 include/media/i2c/mst3367.h
MAINTAINERS +7 -0
index 102362c386fe..6cbe402ee9da 100644
@@ -19039,6 +19039,13 @@ W:	https://linuxtv.org
 Q:	http://patchwork.linuxtv.org/project/linux-media/list/
 F:	drivers/media/usb/msi2500/
 
+MSTAR MST3367 HDMI RECEIVER DRIVER
+M:	Matthew Laux <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/media/i2c/mst3367.c
+F:	include/media/i2c/mst3367.h
+
 MSTAR INTERRUPT CONTROLLER DRIVER
 M:	Mark-PK Tsai <[email protected]>
 M:	Daniel Palmer <[email protected]>
drivers/media/i2c/Kconfig +11 -0
index 9e42b380e3f2..0b04f0a2a472 100644
@@ -1456,6 +1456,17 @@ config VIDEO_ML86V7667
 	  To compile this driver as a module, choose M here: the
 	  module will be called ml86v7667.
 
+config VIDEO_MST3367
+	tristate "MStar MST3367 HDMI receiver and component ADC"
+	depends on VIDEO_DEV && I2C
+	select MEDIA_CONTROLLER
+	help
+	  Support for the MStar MST3367 HDMI receiver, component video
+	  ADC and scaler.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mst3367.
+
 config VIDEO_SAA7110
 	tristate "Philips SAA7110 video decoder"
 	depends on VIDEO_DEV && I2C
drivers/media/i2c/Makefile +1 -0
index 604b19dbc7b7..b9541ec3f823 100644
@@ -81,6 +81,7 @@ obj-$(CONFIG_VIDEO_MIRA016) += mira016.o
 obj-$(CONFIG_VIDEO_MIRA220) += mira220.o
 obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o
 obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o
+obj-$(CONFIG_VIDEO_MST3367) += mst3367.o
 obj-$(CONFIG_VIDEO_MT9M001) += mt9m001.o
 obj-$(CONFIG_VIDEO_MT9M111) += mt9m111.o
 obj-$(CONFIG_VIDEO_MT9M114) += mt9m114.o
drivers/media/i2c/mst3367.c new file +1134 -0

1,134 lines not on this page · raw message

include/media/i2c/mst3367.h new file +27 -0
new file mode 100644
index 000000000000..88d4a4874a9d
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * MStar MST3367 HDMI receiver and component ADC
+ */
+
+#ifndef _MEDIA_I2C_MST3367_H_
+#define _MEDIA_I2C_MST3367_H_
+
+enum mst3367_pads {
+	MST3367_PAD_HDMI,
+	MST3367_PAD_COMPONENT,
+	MST3367_PAD_SOURCE,
+	MST3367_NUM_PADS,
+};
+
+/* Inputs for the s_routing video op */
+#define MST3367_INPUT_HDMI	MST3367_PAD_HDMI
+#define MST3367_INPUT_COMPONENT	MST3367_PAD_COMPONENT
+#define MST3367_INPUT_NONE	MST3367_NUM_PADS
+
+/*
+ * Notification sent with v4l2_subdev_notify() before the receiver changes its
+ * hotplug detect output, for bridge devices to use. The argument is a bool *
+ */
+#define MST3367_HOTPLUG		1
+
+#endif
Signature · 1 line
2.47.3
#12 lore raw

PATCH v7 12/12 media: add driver for StarTech USB3HDCAP

In reply to Matthew Laux

Add a V4L2 driver for the StarTech USB3HDCAP video capture device. This is a popular capture card based on the MST3367 HDMI receiver and TW9900 composite video decoder. Support is included for the composite, S-Video, component, and HDMI inputs, and these inputs have been tested at various resolutions. Audio support is provided by an ALSA device.

Also includes preliminary support for the Micomsoft XCAPTURE-1 hardware variant. All inputs have been tested on that variant as well except for component.

---
 MAINTAINERS                                   |    6 +
 drivers/media/usb/Kconfig                     |    1 +
 drivers/media/usb/Makefile                    |    1 +
 drivers/media/usb/usb3hdcap/Kconfig           |   15 +
 drivers/media/usb/usb3hdcap/Makefile          |    8 +
 drivers/media/usb/usb3hdcap/usb3hdcap-audio.c |  323 +++++
 .../media/usb/usb3hdcap/usb3hdcap-composite.c |  212 +++
 drivers/media/usb/usb3hdcap/usb3hdcap-core.c  | 1173 +++++++++++++++++
 drivers/media/usb/usb3hdcap/usb3hdcap-hdmi.c  |  200 +++
 drivers/media/usb/usb3hdcap/usb3hdcap-video.c |  499 +++++++
 drivers/media/usb/usb3hdcap/usb3hdcap.h       |  241 ++++
 11 files changed, 2679 insertions(+)
 create mode 100644 drivers/media/usb/usb3hdcap/Kconfig
 create mode 100644 drivers/media/usb/usb3hdcap/Makefile
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap-audio.c
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap-composite.c
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap-core.c
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap-hdmi.c
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap-video.c
 create mode 100644 drivers/media/usb/usb3hdcap/usb3hdcap.h
MAINTAINERS +6 -0
index 6cbe402ee9da..478557056947 100644
@@ -26880,6 +26880,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/pinctrl/starfive,jhb1*.yaml
 F:	drivers/pinctrl/starfive/pinctrl-starfive-jhb1*
 
+STARTECH USB3HDCAP VIDEO CAPTURE DRIVER
+M:	Matthew Laux <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/media/usb/usb3hdcap/
+
 STATIC BRANCH/CALL
 M:	Peter Zijlstra <[email protected]>
 M:	Josh Poimboeuf <[email protected]>
drivers/media/usb/Kconfig +1 -0
index 813171d25ac5..9fd043459613 100644
@@ -16,6 +16,7 @@ if MEDIA_CAMERA_SUPPORT
 source "drivers/media/usb/gspca/Kconfig"
 source "drivers/media/usb/pwc/Kconfig"
 source "drivers/media/usb/s2255/Kconfig"
+source "drivers/media/usb/usb3hdcap/Kconfig"
 source "drivers/media/usb/usbtv/Kconfig"
 source "drivers/media/usb/uvc/Kconfig"
 
drivers/media/usb/Makefile +1 -0
index 6d171beea20d..a9b7a398addb 100644
@@ -29,4 +29,5 @@ obj-$(CONFIG_VIDEO_GO7007) += go7007/
 obj-$(CONFIG_VIDEO_HDPVR) += hdpvr/
 obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/
 obj-$(CONFIG_VIDEO_STK1160) += stk1160/
+obj-$(CONFIG_VIDEO_USB3HDCAP) += usb3hdcap/
 obj-$(CONFIG_VIDEO_USBTV) += usbtv/
drivers/media/usb/usb3hdcap/Kconfig new file +15 -0
new file mode 100644
index 000000000000..b2c841448eb1
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config VIDEO_USB3HDCAP
+	tristate "StarTech USB3HDCAP video capture support"
+	depends on VIDEO_DEV && I2C && SND
+	depends on GPIOLIB && PM
+	select SND_PCM
+	select VIDEOBUF2_VMALLOC
+	select VIDEO_MST3367
+	select VIDEO_TW9900
+	help
+	  This is a video4linux2 driver for the StarTech USB3HDCAP and
+	  Micomsoft XCAPTURE-1 USB 3.0 HD video capture devices.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called usb3hdcap
drivers/media/usb/usb3hdcap/Makefile new file +8 -0
new file mode 100644
index 000000000000..f8d833ea530a
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+usb3hdcap-y := usb3hdcap-core.o \
+	usb3hdcap-video.o \
+	usb3hdcap-composite.o \
+	usb3hdcap-hdmi.o \
+	usb3hdcap-audio.o
+
+obj-$(CONFIG_VIDEO_USB3HDCAP) += usb3hdcap.o
drivers/media/usb/usb3hdcap/usb3hdcap-audio.c new file +323 -0

323 lines not on this page · raw message

drivers/media/usb/usb3hdcap/usb3hdcap-composite.c new file +212 -0

212 lines not on this page · raw message

drivers/media/usb/usb3hdcap/usb3hdcap-core.c new file +1173 -0

1,173 lines not on this page · raw message

drivers/media/usb/usb3hdcap/usb3hdcap-hdmi.c new file +200 -0

200 lines not on this page · raw message

drivers/media/usb/usb3hdcap/usb3hdcap-video.c new file +499 -0

499 lines not on this page · raw message

drivers/media/usb/usb3hdcap/usb3hdcap.h new file +241 -0

241 lines not on this page · raw message

Signature · 1 line
2.47.3