media: i2c: Introduce driver for the TW9900 video decoder
Subsystems (3)
Mehdi Djait
maintainerv9 cover media: i2c: Introduce driver for the TW9900 video decoder
Hello everyone,
V8 of the series adding support for the Techwell TW9900 multi standard decoder. It's a pretty simple decoder compared to the TW9910, since it doesn't have a built-in scaler/crop engine.
v8 => v9:
- added a "depends on" GPIOLIB, PM and "select" V4L2_ASYNC to Kconfig
- reworked the locking to protect the tw9900->streaming global state
- folded power_on and power_off into runtime_resume and runtime_suspend callbacks
- used pm_runtime_resume_and get instead pm_runtime_get_sync
v7 => v8:
- fixed the number of analog input ports: it is just one.
- added endpoints of the analog input port
- added vdd-supply to the required in the dt-binding documentation
- added back pm_runtime
- added a mutex to Serialize access to hardware and current mode configuration
- split get_fmt and set_fmt callbacks
- removed the tw9900_cancel_autodetect()
v6 => v7:
- added powerdown-gpios and input ports to dt-bindings
- added #include <linux/bitfield.h> to fix a Warning from the kernel robot
- removed a dev_info and replaced a dev_err by dev_err_probe
v5[1] => v6:
- dropped .skip_top and .field in the supported_modes
- added error handling for the i2c writes/reads
- added the colorimetry information to fill_fmt
- removed pm_runtime
- added the g_input_status callback
- dropped SECAM
- dropped the non-standard PAL/NTSC variants
Any feedback is appreciated,
Mehdi Djait
media_tree, base-commit: 3e238417254bfdcc23fe207780b59cbb08656762
[1] https://lore.kernel.org/linux-media/[email protected]/
Mehdi Djait (3):
dt-bindings: vendor-prefixes: Add techwell vendor prefix
media: dt-bindings: media: i2c: Add bindings for TW9900
media: i2c: Introduce a driver for the Techwell TW9900 decoder
.../bindings/media/i2c/techwell,tw9900.yaml | 137 +++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 6 + drivers/media/i2c/Kconfig | 15 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/tw9900.c | 777 ++++++++++++++++++ 6 files changed, 938 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/techwell,tw9900.yaml create mode 100644 drivers/media/i2c/tw9900.c
Signature · 1 line
2.41.0
Mehdi Djait
maintainerPATCH v9 1/3 dt-bindings: vendor-prefixes: Add techwell vendor prefix
Add prefix for Techwell, Inc.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1357,6 +1357,8 @@ patternProperties: description: Technologic Systems "^techstar,.*": description: Shenzhen Techstar Electronics Co., Ltd. + "^techwell,.*": + description: Techwell, Inc. "^teejet,.*": description: TeeJet "^teltonika,.*":
Signature · 1 line
2.41.0
Mehdi Djait
maintainerPATCH v9 2/3 media: dt-bindings: media: i2c: Add bindings for TW9900
In reply to Mehdi DjaitThe Techwell TW9900 is a video decoder supporting multiple input standards such as PAL and NTSC and has a parallel BT.656 output interface.
It's designed to be low-power, posesses some features such as a programmable comb-filter, and automatic input standard detection
--- .../bindings/media/i2c/techwell,tw9900.yaml | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/techwell,tw9900.yaml
Documentation/devicetree/bindings/media/i2c/techwell,tw9900.yaml new file +137 -0
@@ -0,0 +1,137 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/techwell,tw9900.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Techwell TW9900 NTSC/PAL video decoder + +maintainers: + - Mehdi Djait <[email protected]> + +description: + The tw9900 is a multi-standard video decoder, supporting NTSC, PAL standards + with auto-detection features. + +properties: + compatible: + const: techwell,tw9900 + + reg: + maxItems: 1 + + vdd-supply: + description: VDD power supply + + reset-gpios: + description: GPIO descriptor for the RESET input pin + maxItems: 1 + + powerdown-gpios: + description: GPIO descriptor for the POWERDOWN input pin + maxItems: 1 + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/$defs/port-base + description: Analog input port + + properties: + endpoint@0: + $ref: /schemas/graph.yaml#/properties/endpoint + description: CVBS over MUX0 + + endpoint@1: + $ref: /schemas/graph.yaml#/properties/endpoint + description: CVBS over MUX1 + + endpoint@2: + $ref: /schemas/graph.yaml#/properties/endpoint + description: Chroma over CIN0 and Y over MUX0 + + endpoint@3: + $ref: /schemas/graph.yaml#/properties/endpoint + description: Chroma over CIN0 and Y over MUX1 + + oneOf: + - required: + - endpoint@0 + - required: + - endpoint@1 + - required: + - endpoint@2 + - required: + - endpoint@3 + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: Video port for the decoder output. + + + required: + - port@0 + - port@1 + +required: + - compatible + - ports + - reg + - vdd-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/display/sdtv-standards.h> + #include <dt-bindings/gpio/gpio.h> + + composite_connector { + compatible = "composite-video-connector"; + label = "tv"; + sdtv-standards = <(SDTV_STD_PAL | SDTV_STD_NTSC)>; + + port { + composite_to_tw9900: endpoint { + remote-endpoint = <&tw9900_to_composite>; + }; + }; + }; + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + video-decoder@44 { + compatible = "techwell,tw9900"; + reg = <0x44>; + + vdd-supply = <&tw9900_supply>; + reset-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + #address-cells = <1>; + #size-cells = <0>; + + reg = <0>; + tw9900_to_composite: endpoint@0 { + reg = <0>; + remote-endpoint = <&composite_to_tw9900>; + }; + }; + + port@1 { + reg = <1>; + endpoint { + remote-endpoint = <&cif_in>; + }; + }; + }; + }; + };
Signature · 1 line
2.41.0
Re: [PATCH v9 2/3] media: dt-bindings: media: i2c: Add bindings for TW9900
Hi,
Quoted 9 lines · Mehdi Djait
The Techwell TW9900 is a video decoder supporting multiple input standards such as PAL and NTSC and has a parallel BT.656 output interface.
It's designed to be low-power, posesses some features such as a programmable comb-filter, and automatic input standard detection
Reviewed-by Rob Herring <[email protected]>Signed-off-by Mehdi Djait <[email protected]>
Cheers,
Paul
Quoted 151 lines
--- .../bindings/media/i2c/techwell,tw9900.yaml | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/techwell,tw9900.yamlDocumentation/devicetree/bindings/media/i2c/techwell,tw9900.yaml new file +137
-0@@ -0,0 +1,137 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/techwell,tw9900.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Techwell TW9900 NTSC/PAL video decoder + +maintainers: + - Mehdi Djait <[email protected]> + +description: + The tw9900 is a multi-standard video decoder, supporting NTSC, PAL standards + with auto-detection features. + +properties: + compatible: + const: techwell,tw9900 + + reg: + maxItems: 1 + + vdd-supply: + description: VDD power supply + + reset-gpios: + description: GPIO descriptor for the RESET input pin + maxItems: 1 + + powerdown-gpios: + description: GPIO descriptor for the POWERDOWN input pin + maxItems: 1 + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/$defs/port-base + description: Analog input port + + properties: + endpoint@0: + $ref: /schemas/graph.yaml#/properties/endpoint + description: CVBS over MUX0 + + endpoint@1: + $ref: /schemas/graph.yaml#/properties/endpoint + description: CVBS over MUX1 + + endpoint@2: + $ref: /schemas/graph.yaml#/properties/endpoint + description: Chroma over CIN0 and Y over MUX0 + + endpoint@3: + $ref: /schemas/graph.yaml#/properties/endpoint + description: Chroma over CIN0 and Y over MUX1 + + oneOf: + - required: + - endpoint@0 + - required: + - endpoint@1 + - required: + - endpoint@2 + - required: + - endpoint@3 + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: Video port for the decoder output. + + + required: + - port@0 + - port@1 + +required: + - compatible + - ports + - reg + - vdd-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/display/sdtv-standards.h> + #include <dt-bindings/gpio/gpio.h> + + composite_connector { + compatible = "composite-video-connector"; + label = "tv"; + sdtv-standards = <(SDTV_STD_PAL | SDTV_STD_NTSC)>; + + port { + composite_to_tw9900: endpoint { + remote-endpoint = <&tw9900_to_composite>; + }; + }; + }; + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + video-decoder@44 { + compatible = "techwell,tw9900"; + reg = <0x44>; + + vdd-supply = <&tw9900_supply>; + reset-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + #address-cells = <1>; + #size-cells = <0>; + + reg = <0>; + tw9900_to_composite: endpoint@0 { + reg = <0>; + remote-endpoint = <&composite_to_tw9900>; + }; + }; + + port@1 { + reg = <1>; + endpoint { + remote-endpoint = <&cif_in>; + }; + }; + }; + }; + };Signature · 1 line
2.41.0
Signature · 3 lines
Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Mehdi Djait
maintainerPATCH v9 3/3 media: i2c: Introduce a driver for the Techwell TW9900 decoder
In reply to Mehdi DjaitThe Techwell video decoder supports PAL, NTSC standards and has a parallel BT.656 output interface.
This commit adds support for this device, with basic support for NTSC and PAL, along with brightness and contrast controls.
The TW9900 is capable of automatic standard detection. This driver is implemented with support for PAL and NTSC autodetection.
--- MAINTAINERS | 6 + drivers/media/i2c/Kconfig | 15 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/tw9900.c | 777 +++++++++++++++++++++++++++++++++++++ 4 files changed, 799 insertions(+) create mode 100644 drivers/media/i2c/tw9900.c
MAINTAINERS +6 -0
@@ -21142,6 +21142,12 @@ L: [email protected] S: Maintained F: drivers/media/rc/ttusbir.c +TECHWELL TW9900 VIDEO DECODER +M: Mehdi Djait <[email protected]> +L: [email protected] +S: Maintained +F: drivers/media/i2c/tw9900.c + TECHWELL TW9910 VIDEO DECODER L: [email protected] S: Orphan
drivers/media/i2c/Kconfig +15 -0
@@ -1186,6 +1186,21 @@ config VIDEO_TW2804 To compile this driver as a module, choose M here: the module will be called tw2804. +config VIDEO_TW9900 + tristate "Techwell TW9900 video decoder" + depends on GPIOLIB + depends on VIDEO_DEV && I2C + depends on PM + select MEDIA_CONTROLLER + select VIDEO_V4L2_SUBDEV_API + select V4L2_ASYNC + help + Support for the Techwell TW9900 multi-standard video decoder. + It supports NTSC, PAL standards with auto-detection features. + + To compile this driver as a module, choose M here: the + module will be called tw9900. + config VIDEO_TW9903 tristate "Techwell TW9903 video decoder" depends on VIDEO_DEV && I2C
drivers/media/i2c/Makefile +1 -0
@@ -136,6 +136,7 @@ obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o obj-$(CONFIG_VIDEO_TVP7002) += tvp7002.o obj-$(CONFIG_VIDEO_TW2804) += tw2804.o +obj-$(CONFIG_VIDEO_TW9900) += tw9900.o obj-$(CONFIG_VIDEO_TW9903) += tw9903.o obj-$(CONFIG_VIDEO_TW9906) += tw9906.o obj-$(CONFIG_VIDEO_TW9910) += tw9910.o
drivers/media/i2c/tw9900.c new file +777 -0
777 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v9 3/3] media: i2c: Introduce a driver for the Techwell TW9900 decoder
Hi Mehdi,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mehdi-Djait/dt-bindings-vendor-prefixes-Add-techwell-vendor-prefix/20231117-234411 base: git://linuxtv.org/media_tree.git master patch link: https://lore.kernel.org/r/dc65a89e7803782a75bf663158e031356ef7cb1a.1700235276.git.mehdi.djait%40bootlin.com patch subject: [PATCH v9 3/3] media: i2c: Introduce a driver for the Techwell TW9900 decoder config: powerpc-randconfig-r071-20231122 (https://download.01.org/0day-ci/archive/20231122/[email protected]/config) compiler: powerpc-linux-gcc (GCC) 13.2.0 reproduce: (https://download.01.org/0day-ci/archive/20231122/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
New smatch warnings:drivers/media/i2c/tw9900.c:628 tw9900_runtime_resume() warn: inconsistent returns '&tw9900->mutex'.
Old smatch warnings:drivers/media/i2c/tw9900.c:348 tw9900_s_std() error: uninitialized symbol 'mode'.
vim +628 drivers/media/i2c/tw9900.c
cf24af11e0a74c Mehdi Djait 2023-11-17 597 static int tw9900_runtime_resume(struct device *dev)
cf24af11e0a74c Mehdi Djait 2023-11-17 598 {
cf24af11e0a74c Mehdi Djait 2023-11-17 599 struct i2c_client *client = to_i2c_client(dev);
cf24af11e0a74c Mehdi Djait 2023-11-17 600 struct v4l2_subdev *sd = i2c_get_clientdata(client);
cf24af11e0a74c Mehdi Djait 2023-11-17 601 struct tw9900 *tw9900 = to_tw9900(sd);
cf24af11e0a74c Mehdi Djait 2023-11-17 602 int ret;
cf24af11e0a74c Mehdi Djait 2023-11-17 603
cf24af11e0a74c Mehdi Djait 2023-11-17 604 mutex_lock(&tw9900->mutex);
cf24af11e0a74c Mehdi Djait 2023-11-17 605
cf24af11e0a74c Mehdi Djait 2023-11-17 606 if (tw9900->reset_gpio)
cf24af11e0a74c Mehdi Djait 2023-11-17 607 gpiod_set_value_cansleep(tw9900->reset_gpio, 1);
cf24af11e0a74c Mehdi Djait 2023-11-17 608
cf24af11e0a74c Mehdi Djait 2023-11-17 609 ret = regulator_enable(tw9900->regulator);
cf24af11e0a74c Mehdi Djait 2023-11-17 610 if (ret < 0)
cf24af11e0a74c Mehdi Djait 2023-11-17 611 return ret;mutex_unlock(&tw9900->mutex) before returning.
cf24af11e0a74c Mehdi Djait 2023-11-17 612 cf24af11e0a74c Mehdi Djait 2023-11-17 613 usleep_range(50000, 52000); cf24af11e0a74c Mehdi Djait 2023-11-17 614 cf24af11e0a74c Mehdi Djait 2023-11-17 615 if (tw9900->reset_gpio) cf24af11e0a74c Mehdi Djait 2023-11-17 616 gpiod_set_value_cansleep(tw9900->reset_gpio, 0); cf24af11e0a74c Mehdi Djait 2023-11-17 617 cf24af11e0a74c Mehdi Djait 2023-11-17 618 usleep_range(1000, 2000); cf24af11e0a74c Mehdi Djait 2023-11-17 619 cf24af11e0a74c Mehdi Djait 2023-11-17 620 ret = tw9900_write_array(tw9900->client, tw9900_init_regs, cf24af11e0a74c Mehdi Djait 2023-11-17 621 ARRAY_SIZE(tw9900_init_regs)); cf24af11e0a74c Mehdi Djait 2023-11-17 622 cf24af11e0a74c Mehdi Djait 2023-11-17 623 mutex_unlock(&tw9900->mutex); cf24af11e0a74c Mehdi Djait 2023-11-17 624 cf24af11e0a74c Mehdi Djait 2023-11-17 625 /* This sleep is needed for the Horizontal Sync PLL to lock. */ cf24af11e0a74c Mehdi Djait 2023-11-17 626 msleep(300); cf24af11e0a74c Mehdi Djait 2023-11-17 627
cf24af11e0a74c Mehdi Djait 2023-11-17 @628 return ret;cf24af11e0a74c Mehdi Djait 2023-11-17 629 }
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v9 3/3] media: i2c: Introduce a driver for the Techwell TW9900 decoder
In reply to Mehdi DjaitHi Mehdi,
Quoted 9 lines · Mehdi Djait
The Techwell video decoder supports PAL, NTSC standards and has a parallel BT.656 output interface.
This commit adds support for this device, with basic support for NTSC and PAL, along with brightness and contrast controls.
The TW9900 is capable of automatic standard detection. This driver is implemented with support for PAL and NTSC autodetection.
Very nice work on this iteration, I am quite happy with it!
There is just one cosmetic comment below. With that fixed, you can add my:
Cheers,
Paul
Quoted 8 lines
Signed-off-by Mehdi Djait <[email protected]>--- MAINTAINERS | 6 + drivers/media/i2c/Kconfig | 15 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/tw9900.c | 777 +++++++++++++++++++++++++++++++++++++ 4 files changed, 799 insertions(+) create mode 100644 drivers/media/i2c/tw9900.c
[...]
Quoted 47 lines
drivers/media/i2c/tw9900.c new file +41
-0@@ -0,0 +1,777 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for the Techwell TW9900 multi-standard video decoder. +* +* Copyright (C) 2018 Fuzhou Rockchip Electronics Co., Ltd. +* Copyright (C) 2020 Maxime Chevallier <[email protected]> +* Copyright (C) 2023 Mehdi Djait <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/gpio/consumer.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> +#include <media/media-entity.h> +#include <media/v4l2-async.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-event.h> +#include <media/v4l2-subdev.h> + +#define TW9900_REG_CHIP_ID 0x00 +#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_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_CROP_HI 0x07 +#define TW9900_REG_VDELAY_LO 0x08 +#define TW9900_REG_VACTIVE_LO 0x09 +#define TW9900_REG_HACTIVE_LO 0x0B +#define TW9900_REG_CNTRL1 0x0C +#define TW9900_REG_BRIGHT_CTL 0x10 +#define TW9900_REG_CONTRAST_CTL 0x11
drivers/media/i2c/tw9900.c line 51
Quoted 10 lines
drivers/media/i2c/tw9900.c new file +10
-0+#define TW9900_REG_VBI_CNTL 0x19 +#define TW9900_REG_ANAL_CTL_II 0x1A +#define TW9900_REG_OUT_CTRL_II 0x1B +#define TW9900_REG_STD 0x1C +#define TW9900_REG_STD_AUTO_PROGRESS BIT(7) +#define TW9900_STDNOW_MASK GENMASK(6, 4) +#define TW9900_REG_STDR 0x1D +#define TW9900_REG_MISSCNT 0x26 +#define TW9900_REG_MISC_CTL_II 0x2F +#define TW9900_REG_VVBI 0x55
Please reintroduce the newline here...
drivers/media/i2c/tw9900.c line 55
Quoted 4 lines
drivers/media/i2c/tw9900.c new file +4
-0+#define TW9900_CHIP_ID 0x00 +#define TW9900_STD_NTSC_M 0 +#define TW9900_STD_PAL_BDGHI 1 +#define TW9900_STD_AUTO 7
... and here to separate between register definitions and more general values.
Quoted 1 line
drivers/media/i2c/tw9900.c new file +1
-0+#define TW9900_VIDEO_POLL_TRIES 20
Signature · 3 lines
Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com