Skip to contentSkip to conversation

Support Nuvoton NPCM Video Capture/Encode Engine

PATCH Superseded Marvin Lin 2 participants 12 messages Aug 28, 2023 – Sep 4, 2023

Subsystems (4)

v14 of 16 Superseded Latest is v16 →

lore
Share & tools
lore

Marvin Lin

author
#0 lore raw

v14 cover Support Nuvoton NPCM Video Capture/Encode Engine

This patch series add DTS node, dt-bindings document and drivers for Video Capture/Differentiation Engine (VCD) and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs.

As described in the datasheet NPCM750D_DS_Rev_1.0, the VCD can capture a frame from digital video input and compare two frames in memory, and then the ECE can compress the frame data into HEXTILE format which is defined in Remote Framebuffer Protocol (RFC 6143, chapter 7.7.4. Hextile Encoding).

The output of v4l2-compliance:
v4l2-compliance 1.23.0-4996, 64 bits, 64-bit time_t v4l2-compliance SHA: 9431e4b26b48 2023-02-13 14:51:47

Compliance test for npcm-video device /dev/video0:

Driver Info:

        Driver name      : npcm-video
        Card type        : NPCM Video Engine
        Bus info         : platform:npcm-video
        Driver version   : 6.1.12
        Capabilities     : 0x84200001

Video Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04200001
Video Capture
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 (Not Supported)

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: 1 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 (Not Supported) 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
warn: v4l2-test-controls.cpp(1139): V4L2_CID_DV_RX_POWER_PRESENT not found for input 0
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 1 Private Controls: 2

Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK (Not Supported) 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 VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)

Total for npcm-video device /dev/video0: 45, Succeeded: 45, Failed: 0, Warnings: 1

Changes in v14:
- Modify the flow of setting resolution and queue setup
- Correct the control type (TYPE_MENU) of selecting between two modes.
- Let ECE could be optional (only supports PIX_FMT_RGB565 if ECE is not enabled in DT).

Changes in v13:
- Modify the flow for capturing next frame
- Modify the behavior of resolution change interrupt
- Move GFXI dt-bindings document to Documentation/devicetree/bindings/soc/nuvoton/nuvoton,gfxi.yaml

Changes in v12:
- Modify the flow for detecting resolution change and raise V4L2_EVENT_SOURCE_CHANGE event.
- Add V4L2_PIX_FMT_RGB565 format support.

Changes in v11:
- Replace "u8/u16/u32" with "unsigned int" for generic local variables.
- Correct subsystem prefixes, drop redundant words in commit subject, and add more information in commit message.

Changes in v10:
- drivers/media/platform/nuvoton/npcm-video.c
* Let short functions to be inline function.
* Correct return type of some functions, and properly handle return value by callers.
* Correct the timing of removing rect_list and the flow of FIFO overrun case in irq.
* Adjust line breaks, indentations, and style of variable declarations.

Changes in v9:
- Change ECE node name to "video-codec".
- Drop redundant "bindings for" in commit subject of patch 2/7.
- Refine the format of VCD/ECE dt-binding document.

Changes in v8:
- Let VCD/ECE to be 2 separate nodes and update dt-binding documents.
- Move register definitions out to a local header file.
- Driver refinements (add error handling for memory allocation, remove unnecessary condition check and introduce "goto"s to handle similar error recovery paths).
- Correct properties and typo in GFXI dt-binding document.

Changes in v7:
- Add uapi documents for driver-specific controls.
- Implement driver-specific controls for switching capture mode and getting the count of compressed HEXTILE rectangles.
- Drop unnecessary "enum_framesizes" and "enum_frameintervals" functions.
- Include the output of v4l2-compliance in cover letter.

Changes in v6:
- Support NPCM845 and add compatible "nuvoton,npcm845-video".
- Correct pixel format to V4L2_PIX_FMT_HEXTILE which is newly added in this patch series.

Changes in v5:
- Simplify function prefix "nuvoton_" to "npcm_".
- Increase VCD_BUSY_TIMEOUT_US and ECE_POLL_TIMEOUT_US to 300ms to prevent polling timeout when ECC is enabled or system is busy.

Changes in v4:
- Fix compile warning reported by kernel test robot.

Changes in v3:
- Add video driver entry in MAINTAINERS.
- Change config name to CONFIG_VIDEO_NPCM_VCD_ECE.
- Reduce the waiting time after resetting the VCD/ECE module.
- Correct data types of some variables.

Changes in v2:
- Add Hextile document and locate with vendor formats.

Marvin Lin (7):
ARM: dts: nuvoton: Add node for NPCM VCD and ECE engine
media: dt-bindings: nuvoton: Add NPCM VCD and ECE engine
dt-bindings: soc: nuvoton: Add NPCM GFXI
media: v4l: Add HEXTILE compressed format
media: v4l2-ctrls: Add user control base for Nuvoton NPCM controls
media: uapi: Add controls for NPCM video driver
media: nuvoton: Add driver for NPCM video capture and encode engine

 .../bindings/media/nuvoton,npcm-ece.yaml      |   43 +
 .../bindings/media/nuvoton,npcm-vcd.yaml      |   72 +
 .../bindings/soc/nuvoton/nuvoton,gfxi.yaml    |   39 +
 .../userspace-api/media/drivers/index.rst     |    1 +
 .../media/drivers/npcm-video.rst              |   67 +
 .../media/v4l/pixfmt-reserved.rst             |    7 +
 MAINTAINERS                                   |   12 +
 .../dts/nuvoton/nuvoton-common-npcm7xx.dtsi   |   23 +
 drivers/media/platform/Kconfig                |    1 +
 drivers/media/platform/Makefile               |    1 +
 drivers/media/platform/nuvoton/Kconfig        |   15 +
 drivers/media/platform/nuvoton/Makefile       |    2 +
 drivers/media/platform/nuvoton/npcm-regs.h    |  152 ++
 drivers/media/platform/nuvoton/npcm-video.c   | 1840 +++++++++++++++++
 drivers/media/v4l2-core/v4l2-ioctl.c          |    1 +
 include/uapi/linux/npcm-video.h               |   41 +
 include/uapi/linux/v4l2-controls.h            |    6 +
 include/uapi/linux/videodev2.h                |    1 +
 18 files changed, 2324 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/nuvoton,npcm-ece.yaml
 create mode 100644 Documentation/devicetree/bindings/media/nuvoton,npcm-vcd.yaml
 create mode 100644 Documentation/devicetree/bindings/soc/nuvoton/nuvoton,gfxi.yaml
 create mode 100644 Documentation/userspace-api/media/drivers/npcm-video.rst
 create mode 100644 drivers/media/platform/nuvoton/Kconfig
 create mode 100644 drivers/media/platform/nuvoton/Makefile
 create mode 100644 drivers/media/platform/nuvoton/npcm-regs.h
 create mode 100644 drivers/media/platform/nuvoton/npcm-video.c
 create mode 100644 include/uapi/linux/npcm-video.h
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v14 1/7 ARM: dts: nuvoton: Add node for NPCM VCD and ECE engine

Add node for Video Capture/Differentiation Engine (VCD) and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. Tested with Nuvoton NPCM750 evaluation board.

---
 .../dts/nuvoton/nuvoton-common-npcm7xx.dtsi   | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)
arch/arm/boot/dts/nuvoton/nuvoton-common-npcm7xx.dtsi +23 -0
index c7b5ef15b716..13a76689e14a 100644
@@ -179,6 +179,24 @@ fiux: spi@fb001000 {
 			status = "disabled";
 		};
 
+		vcd: vcd@f0810000 {
+			compatible = "nuvoton,npcm750-vcd";
+			reg = <0xf0810000 0x10000>;
+			interrupts = <GIC_SPI 22 IRQ_TYPE_LEVEL_HIGH>;
+			resets = <&rstc NPCM7XX_RESET_IPSRST2 NPCM7XX_RESET_VCD>;
+			nuvoton,sysgcr = <&gcr>;
+			nuvoton,sysgfxi = <&gfxi>;
+			nuvoton,ece = <&ece>;
+			status = "disabled";
+		};
+
+		ece: video-codec@f0820000 {
+			compatible = "nuvoton,npcm750-ece";
+			reg = <0xf0820000 0x2000>;
+			resets = <&rstc NPCM7XX_RESET_IPSRST2 NPCM7XX_RESET_ECE>;
+			status = "disabled";
+		};
+
 		apb {
 			#address-cells = <1>;
 			#size-cells = <1>;
@@ -554,6 +572,11 @@ i2c15: i2c@8f000 {
 				pinctrl-0 = <&smb15_pins>;
 				status = "disabled";
 			};
+
+			gfxi: gfxi@e000 {
+				compatible = "nuvoton,npcm750-gfxi", "syscon";
+				reg = <0xe000 0x100>;
+			};
 		};
 	};
 
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v14 2/7 media: dt-bindings: nuvoton: Add NPCM VCD and ECE engine

In reply to Marvin Lin

Add dt-bindings document for Video Capture/Differentiation Engine (VCD) and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs.

---
 .../bindings/media/nuvoton,npcm-ece.yaml      | 43 +++++++++++
 .../bindings/media/nuvoton,npcm-vcd.yaml      | 72 +++++++++++++++++++
 2 files changed, 115 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/nuvoton,npcm-ece.yaml
 create mode 100644 Documentation/devicetree/bindings/media/nuvoton,npcm-vcd.yaml
Documentation/devicetree/bindings/media/nuvoton,npcm-ece.yaml new file +43 -0
new file mode 100644
index 000000000000..b47468e54504
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/nuvoton,npcm-ece.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton NPCM Encoding Compression Engine
+
+maintainers:
+  - Joseph Liu <[email protected]>
+  - Marvin Lin <[email protected]>
+
+description: |
+  Video Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs.
+
+properties:
+  compatible:
+    enum:
+      - nuvoton,npcm750-ece
+      - nuvoton,npcm845-ece
+
+  reg:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - resets
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/reset/nuvoton,npcm7xx-reset.h>
+
+    ece: video-codec@f0820000 {
+        compatible = "nuvoton,npcm750-ece";
+        reg = <0xf0820000 0x2000>;
+        resets = <&rstc NPCM7XX_RESET_IPSRST2 NPCM7XX_RESET_ECE>;
+    };
Documentation/devicetree/bindings/media/nuvoton,npcm-vcd.yaml new file +72 -0

72 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v14 3/7 dt-bindings: soc: nuvoton: Add NPCM GFXI

In reply to Marvin Lin

Add dt-bindings document for Graphics Core Information (GFXI) node. It is used by NPCM video driver to retrieve Graphics core information.

---
 .../bindings/soc/nuvoton/nuvoton,gfxi.yaml    | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/nuvoton/nuvoton,gfxi.yaml
Documentation/devicetree/bindings/soc/nuvoton/nuvoton,gfxi.yaml new file +39 -0
new file mode 100644
index 000000000000..0222a43977ab
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/nuvoton/nuvoton,gfxi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Graphics Core Information block in Nuvoton SoCs
+
+maintainers:
+  - Joseph Liu <[email protected]>
+  - Marvin Lin <[email protected]>
+
+description:
+  The Graphics Core Information (GFXI) are a block of registers in Nuvoton SoCs
+  that analyzes Graphics core behavior and provides information in registers.
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - nuvoton,npcm750-gfxi
+          - nuvoton,npcm845-gfxi
+      - const: syscon
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    gfxi: gfxi@e000 {
+      compatible = "nuvoton,npcm750-gfxi", "syscon";
+      reg = <0xe000 0x100>;
+    };
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH v14 4/7 media: v4l: Add HEXTILE compressed format

In reply to Marvin Lin

Add HEXTILE compressed format which is defined in Remote Framebuffer Protocol (RFC 6143, chapter 7.7.4 Hextile Encoding) and is used by Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs.

---
 Documentation/userspace-api/media/v4l/pixfmt-reserved.rst | 7 +++++++
 drivers/media/v4l2-core/v4l2-ioctl.c                      | 1 +
 include/uapi/linux/videodev2.h                            | 1 +
 3 files changed, 9 insertions(+)
Documentation/userspace-api/media/v4l/pixfmt-reserved.rst +7 -0
index 58f6ae25b2e7..ac52485252d9 100644
@@ -275,6 +275,13 @@ please make a proposal on the linux-media mailing list.
 
         Decoder's implementation can be found here,
         `aspeed_codec <https://github.com/AspeedTech-BMC/aspeed_codec/>`__
+    * .. _V4L2-PIX-FMT-HEXTILE:
+
+      - ``V4L2_PIX_FMT_HEXTILE``
+      - 'HXTL'
+      - Compressed format used by Nuvoton NPCM video driver. This format is
+        defined in Remote Framebuffer Protocol (RFC 6143, chapter 7.7.4 Hextile
+        Encoding).
 .. raw:: latex
 
     \normalsize
drivers/media/v4l2-core/v4l2-ioctl.c +1 -0
index 01ba27f2ef87..2197c536740d 100644
@@ -1508,6 +1508,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 		case V4L2_PIX_FMT_QC10C:	descr = "QCOM Compressed 10-bit Format"; break;
 		case V4L2_PIX_FMT_AJPG:		descr = "Aspeed JPEG"; break;
 		case V4L2_PIX_FMT_AV1_FRAME:	descr = "AV1 Frame"; break;
+		case V4L2_PIX_FMT_HEXTILE:	descr = "Hextile Compressed Format"; break;
 		default:
 			if (fmt->description[0])
 				return;
include/uapi/linux/videodev2.h +1 -0
index 3af6a82d0cad..4833addf4686 100644
@@ -802,6 +802,7 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_QC08C    v4l2_fourcc('Q', '0', '8', 'C') /* Qualcomm 8-bit compressed */
 #define V4L2_PIX_FMT_QC10C    v4l2_fourcc('Q', '1', '0', 'C') /* Qualcomm 10-bit compressed */
 #define V4L2_PIX_FMT_AJPG     v4l2_fourcc('A', 'J', 'P', 'G') /* Aspeed JPEG */
+#define V4L2_PIX_FMT_HEXTILE  v4l2_fourcc('H', 'X', 'T', 'L') /* Hextile compressed */
 
 /* 10bit raw packed, 32 bytes for every 25 pixels, last LSB 6 bits unused */
 #define V4L2_PIX_FMT_IPU3_SBGGR10	v4l2_fourcc('i', 'p', '3', 'b') /* IPU3 packed 10-bit BGGR bayer */
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH v14 5/7 media: v4l2-ctrls: Add user control base for Nuvoton NPCM controls

In reply to Marvin Lin

Add a control base for Nuvoton NPCM driver controls, and reserve 16 controls.

---
 include/uapi/linux/v4l2-controls.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/uapi/linux/v4l2-controls.h +6 -0
index c3604a0a3e30..68db66d4aae8 100644
@@ -203,6 +203,12 @@ enum v4l2_colorfx {
  */
 #define V4L2_CID_USER_ASPEED_BASE		(V4L2_CID_USER_BASE + 0x11a0)
 
+/*
+ * The base for Nuvoton NPCM driver controls.
+ * We reserve 16 controls for this driver.
+ */
+#define V4L2_CID_USER_NPCM_BASE			(V4L2_CID_USER_BASE + 0x11b0)
+
 /* MPEG-class control IDs */
 /* The MPEG controls are applicable to all codec controls
  * and the 'MPEG' part of the define is historical */
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH v14 6/7 media: uapi: Add controls for NPCM video driver

In reply to Marvin Lin

Create controls for Nuvoton NPCM video driver to support setting capture mode of Video Capture/Differentiation (VCD) engine and getting the count of HEXTILE rectangles that is compressed by Encoding Compression Engine (ECE).

---
 .../userspace-api/media/drivers/index.rst     |  1 +
 .../media/drivers/npcm-video.rst              | 67 +++++++++++++++++++
 include/uapi/linux/npcm-video.h               | 41 ++++++++++++
 3 files changed, 109 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/npcm-video.rst
 create mode 100644 include/uapi/linux/npcm-video.h
Documentation/userspace-api/media/drivers/index.rst +1 -0
index 6708d649afd7..783f92f01a4c 100644
@@ -37,6 +37,7 @@ For more details see the file COPYING in the source distribution of Linux.
 	dw100
 	imx-uapi
 	max2175
+	npcm-video
 	omap3isp-uapi
 	st-vgxy61
 	uvcvideo
Documentation/userspace-api/media/drivers/npcm-video.rst new file +67 -0

67 lines not on this page · raw message

include/uapi/linux/npcm-video.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#7 lore raw

PATCH v14 7/7 media: nuvoton: Add driver for NPCM video capture and encode engine

In reply to Marvin Lin

Add driver for Video Capture/Differentiation Engine (VCD) and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. As described in the datasheet NPCM750D_DS_Rev_1.0, the VCD can capture a frame from digital video input and compare two frames in memory, and then the ECE can compress the frame data into HEXTILE format. This driver implements V4L2 interfaces and provides user controls to support KVM feature, also tested with VNC Viewer ver.6.22.826 and openbmc/obmc-ikvm.

---
 MAINTAINERS                                 |   12 +
 drivers/media/platform/Kconfig              |    1 +
 drivers/media/platform/Makefile             |    1 +
 drivers/media/platform/nuvoton/Kconfig      |   15 +
 drivers/media/platform/nuvoton/Makefile     |    2 +
 drivers/media/platform/nuvoton/npcm-regs.h  |  152 ++
 drivers/media/platform/nuvoton/npcm-video.c | 1840 +++++++++++++++++++
 7 files changed, 2023 insertions(+)
 create mode 100644 drivers/media/platform/nuvoton/Kconfig
 create mode 100644 drivers/media/platform/nuvoton/Makefile
 create mode 100644 drivers/media/platform/nuvoton/npcm-regs.h
 create mode 100644 drivers/media/platform/nuvoton/npcm-video.c
MAINTAINERS +12 -0
index 48abe1a281f2..774f72203ec8 100644
@@ -2465,6 +2465,18 @@ F:	drivers/rtc/rtc-nct3018y.c
 F:	include/dt-bindings/clock/nuvoton,npcm7xx-clock.h
 F:	include/dt-bindings/clock/nuvoton,npcm845-clk.h
 
+ARM/NUVOTON NPCM VIDEO ENGINE DRIVER
+M:	Joseph Liu <[email protected]>
+M:	Marvin Lin <[email protected]>
+L:	[email protected]
+L:	[email protected] (moderated for non-subscribers)
+S:	Maintained
+F:	Documentation/devicetree/bindings/media/nuvoton,npcm-ece.yaml
+F:	Documentation/devicetree/bindings/media/nuvoton,npcm-vcd.yaml
+F:	Documentation/userspace-api/media/drivers/npcm-video.rst
+F:	drivers/media/platform/nuvoton/
+F:	include/uapi/linux/npcm-video.h
+
 ARM/NUVOTON WPCM450 ARCHITECTURE
 M:	Jonathan Neuschäfer <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
drivers/media/platform/Kconfig +1 -0
index ee579916f874..91e54215de3a 100644
@@ -73,6 +73,7 @@ source "drivers/media/platform/intel/Kconfig"
 source "drivers/media/platform/marvell/Kconfig"
 source "drivers/media/platform/mediatek/Kconfig"
 source "drivers/media/platform/microchip/Kconfig"
+source "drivers/media/platform/nuvoton/Kconfig"
 source "drivers/media/platform/nvidia/Kconfig"
 source "drivers/media/platform/nxp/Kconfig"
 source "drivers/media/platform/qcom/Kconfig"
drivers/media/platform/Makefile +1 -0
index 5453bb868e67..3296ec1ebe16 100644
@@ -16,6 +16,7 @@ obj-y += intel/
 obj-y += marvell/
 obj-y += mediatek/
 obj-y += microchip/
+obj-y += nuvoton/
 obj-y += nvidia/
 obj-y += nxp/
 obj-y += qcom/
drivers/media/platform/nuvoton/Kconfig new file +15 -0
new file mode 100644
index 000000000000..919d3166756c
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+comment "Nuvoton media platform drivers"
+
+config VIDEO_NPCM_VCD_ECE
+	tristate "Nuvoton NPCM Video Capture/Encode Engine driver"
+	depends on V4L_PLATFORM_DRIVERS
+	depends on VIDEO_DEV
+	select VIDEOBUF2_DMA_CONTIG
+	help
+	  Support for the Video Capture/Differentiation Engine (VCD) and
+	  Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs.
+	  The VCD can capture a frame from digital video input and compare
+	  two frames in memory, and then the ECE can compress the frame
+	  data into HEXTILE format.
drivers/media/platform/nuvoton/Makefile new file +2 -0
new file mode 100644
index 000000000000..74a4e3fc8555
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_VIDEO_NPCM_VCD_ECE) += npcm-video.o
drivers/media/platform/nuvoton/npcm-regs.h new file +152 -0

152 lines not on this page · raw message

drivers/media/platform/nuvoton/npcm-video.c new file +1840 -0

1,840 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH v14 7/7] media: nuvoton: Add driver for NPCM video capture and encode engine

Hi Marvin,

A few minor change requests, and a question w.r.t. the V4L2_CID_NPCM_RECT_COUNT control:

Quoted 23 lines · Marvin Lin

Add driver for Video Capture/Differentiation Engine (VCD) and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. As described in the datasheet NPCM750D_DS_Rev_1.0, the VCD can capture a frame from digital video input and compare two frames in memory, and then the ECE can compress the frame data into HEXTILE format. This driver implements V4L2 interfaces and provides user controls to support KVM feature, also tested with VNC Viewer ver.6.22.826 and openbmc/obmc-ikvm.

---
 MAINTAINERS                                 |   12 +
 drivers/media/platform/Kconfig              |    1 +
 drivers/media/platform/Makefile             |    1 +
 drivers/media/platform/nuvoton/Kconfig      |   15 +
 drivers/media/platform/nuvoton/Makefile     |    2 +
 drivers/media/platform/nuvoton/npcm-regs.h  |  152 ++
 drivers/media/platform/nuvoton/npcm-video.c | 1840 +++++++++++++++++++
 7 files changed, 2023 insertions(+)
 create mode 100644 drivers/media/platform/nuvoton/Kconfig
 create mode 100644 drivers/media/platform/nuvoton/Makefile
 create mode 100644 drivers/media/platform/nuvoton/npcm-regs.h
 create mode 100644 drivers/media/platform/nuvoton/npcm-video.c

<snip>

drivers/media/platform/nuvoton/npcm-video.c line 1136

Quoted 6 lines
drivers/media/platform/nuvoton/npcm-video.c new file +6 -0
+static int npcm_video_querycap(struct file *file, void *fh,
+			       struct v4l2_capability *cap)
+{
+	strscpy(cap->driver, DEVICE_NAME, sizeof(cap->driver));
+	strscpy(cap->card, "NPCM Video Engine", sizeof(cap->card));
+	snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", DEVICE_NAME);

You can drop this last line, it is already filled in by the V4L2 core for platform devices.

Quoted 241 lines
drivers/media/platform/nuvoton/npcm-video.c new file +241 -0
+
+	return 0;
+}
+
+static int npcm_video_enum_format(struct file *file, void *fh,
+				  struct v4l2_fmtdesc *f)
+{
+	struct npcm_video *video = video_drvdata(file);
+	const struct npcm_fmt *fmt;
+
+	if (f->index >= NUM_FORMATS)
+		return -EINVAL;
+
+	fmt = &npcm_fmt_list[f->index];
+	if (fmt->fourcc == V4L2_PIX_FMT_HEXTILE && !video->ece.enable)
+		return -EINVAL;
+
+	f->pixelformat = fmt->fourcc;
+	return 0;
+}
+
+static int npcm_video_try_format(struct file *file, void *fh,
+				 struct v4l2_format *f)
+{
+	struct npcm_video *video = video_drvdata(file);
+	const struct npcm_fmt *fmt;
+
+	fmt = npcm_video_find_format(f);
+
+	/* If format not found or HEXTILE not supported, use RGB565 as default */
+	if (!fmt || (fmt->fourcc == V4L2_PIX_FMT_HEXTILE && !video->ece.enable))
+		f->fmt.pix.pixelformat = npcm_fmt_list[0].fourcc;
+
+	f->fmt.pix.field = V4L2_FIELD_NONE;
+	f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
+	f->fmt.pix.quantization = V4L2_QUANTIZATION_FULL_RANGE;
+	f->fmt.pix.width = video->pix_fmt.width;
+	f->fmt.pix.height = video->pix_fmt.height;
+	f->fmt.pix.bytesperline = video->bytesperline;
+	f->fmt.pix.sizeimage = video->pix_fmt.sizeimage;
+
+	return 0;
+}
+
+static int npcm_video_get_format(struct file *file, void *fh,
+				 struct v4l2_format *f)
+{
+	struct npcm_video *video = video_drvdata(file);
+
+	f->fmt.pix = video->pix_fmt;
+	return 0;
+}
+
+static int npcm_video_set_format(struct file *file, void *fh,
+				 struct v4l2_format *f)
+{
+	struct npcm_video *video = video_drvdata(file);
+	int ret;
+
+	ret = npcm_video_try_format(file, fh, f);
+	if (ret)
+		return ret;
+
+	if (vb2_is_busy(&video->queue)) {
+		dev_err(video->dev, "%s device busy\n", __func__);
+		return -EBUSY;
+	}
+
+	video->pix_fmt.pixelformat = f->fmt.pix.pixelformat;
+	return 0;
+}
+
+static int npcm_video_enum_input(struct file *file, void *fh,
+				 struct v4l2_input *inp)
+{
+	struct npcm_video *video = video_drvdata(file);
+
+	if (inp->index)
+		return -EINVAL;
+
+	strscpy(inp->name, "Host VGA capture", sizeof(inp->name));
+	inp->type = V4L2_INPUT_TYPE_CAMERA;
+	inp->capabilities = V4L2_IN_CAP_DV_TIMINGS;
+	inp->status = video->v4l2_input_status;
+
+	return 0;
+}
+
+static int npcm_video_get_input(struct file *file, void *fh, unsigned int *i)
+{
+	*i = 0;
+
+	return 0;
+}
+
+static int npcm_video_set_input(struct file *file, void *fh, unsigned int i)
+{
+	if (i)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int npcm_video_set_dv_timings(struct file *file, void *fh,
+				     struct v4l2_dv_timings *timings)
+{
+	struct npcm_video *video = video_drvdata(file);
+	int rc;
+
+	if (timings->bt.width == video->active_timings.width &&
+	    timings->bt.height == video->active_timings.height)
+		return 0;
+
+	if (vb2_is_busy(&video->queue)) {
+		dev_err(video->dev, "%s device busy\n", __func__);
+		return -EBUSY;
+	}
+
+	rc = npcm_video_set_resolution(video, &timings->bt);
+	if (rc)
+		return rc;
+
+	timings->type = V4L2_DV_BT_656_1120;
+
+	return 0;
+}
+
+static int npcm_video_get_dv_timings(struct file *file, void *fh,
+				     struct v4l2_dv_timings *timings)
+{
+	struct npcm_video *video = video_drvdata(file);
+
+	timings->type = V4L2_DV_BT_656_1120;
+	timings->bt = video->active_timings;
+
+	return 0;
+}
+
+static int npcm_video_query_dv_timings(struct file *file, void *fh,
+				       struct v4l2_dv_timings *timings)
+{
+	struct npcm_video *video = video_drvdata(file);
+
+	npcm_video_detect_resolution(video);
+	timings->type = V4L2_DV_BT_656_1120;
+	timings->bt = video->detected_timings;
+
+	return video->v4l2_input_status ? -ENOLINK : 0;
+}
+
+static int npcm_video_enum_dv_timings(struct file *file, void *fh,
+				      struct v4l2_enum_dv_timings *timings)
+{
+	return v4l2_enum_dv_timings_cap(timings, &npcm_video_timings_cap,
+					NULL, NULL);
+}
+
+static int npcm_video_dv_timings_cap(struct file *file, void *fh,
+				     struct v4l2_dv_timings_cap *cap)
+{
+	*cap = npcm_video_timings_cap;
+
+	return 0;
+}
+
+static int npcm_video_sub_event(struct v4l2_fh *fh,
+				const struct v4l2_event_subscription *sub)
+{
+	switch (sub->type) {
+	case V4L2_EVENT_SOURCE_CHANGE:
+		return v4l2_src_change_event_subscribe(fh, sub);
+	}
+
+	return v4l2_ctrl_subscribe_event(fh, sub);
+}
+
+static const struct v4l2_ioctl_ops npcm_video_ioctls = {
+	.vidioc_querycap = npcm_video_querycap,
+
+	.vidioc_enum_fmt_vid_cap = npcm_video_enum_format,
+	.vidioc_g_fmt_vid_cap = npcm_video_get_format,
+	.vidioc_s_fmt_vid_cap = npcm_video_set_format,
+	.vidioc_try_fmt_vid_cap = npcm_video_try_format,
+
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+
+	.vidioc_enum_input = npcm_video_enum_input,
+	.vidioc_g_input = npcm_video_get_input,
+	.vidioc_s_input = npcm_video_set_input,
+
+	.vidioc_s_dv_timings = npcm_video_set_dv_timings,
+	.vidioc_g_dv_timings = npcm_video_get_dv_timings,
+	.vidioc_query_dv_timings = npcm_video_query_dv_timings,
+	.vidioc_enum_dv_timings = npcm_video_enum_dv_timings,
+	.vidioc_dv_timings_cap = npcm_video_dv_timings_cap,
+
+	.vidioc_subscribe_event = npcm_video_sub_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+};
+
+static int npcm_video_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct npcm_video *video = container_of(ctrl->handler, struct npcm_video,
+						ctrl_handler);
+
+	switch (ctrl->id) {
+	case V4L2_CID_NPCM_CAPTURE_MODE:
+		if (ctrl->val == V4L2_NPCM_CAPTURE_MODE_COMPLETE)
+			video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE;
+		else if (ctrl->val == V4L2_NPCM_CAPTURE_MODE_DIFF)
+			video->ctrl_cmd = VCD_CMD_OPERATION_COMPARE;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int npcm_video_get_volatile_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct npcm_video *video = container_of(ctrl->handler, struct npcm_video,
+						ctrl_handler);
+
+	switch (ctrl->id) {
+	case V4L2_CID_NPCM_RECT_COUNT:
+		ctrl->val = video->rect[video->vb_index];
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;

drivers/media/platform/nuvoton/npcm-video.c line 1387

Quoted 10 lines
drivers/media/platform/nuvoton/npcm-video.c new file +10 -0
+}
+
+static const struct v4l2_ctrl_ops npcm_video_ctrl_ops = {
+	.s_ctrl = npcm_video_set_ctrl,
+	.g_volatile_ctrl = npcm_video_get_volatile_ctrl,
+};
+
+static const char * const npcm_ctrl_capture_mode_menu[] = {
+	"COMPLETE mode",
+	"DIFF mode",

Hmm, I would drop the 'mode' bit, since it is already obvious that these are the modes.

Quoted 15 lines
drivers/media/platform/nuvoton/npcm-video.c new file +15 -0
+	NULL,
+};
+
+static const struct v4l2_ctrl_config npcm_ctrl_capture_mode = {
+	.ops = &npcm_video_ctrl_ops,
+	.id = V4L2_CID_NPCM_CAPTURE_MODE,
+	.name = "NPCM Video Capture Mode",
+	.type = V4L2_CTRL_TYPE_MENU,
+	.min = 0,
+	.max = V4L2_NPCM_CAPTURE_MODE_DIFF,
+	.def = 0,
+	.qmenu = npcm_ctrl_capture_mode_menu,
+};
+
+static const struct v4l2_ctrl_config npcm_ctrl_rect_count = {

drivers/media/platform/nuvoton/npcm-video.c line 1412

Quoted 10 lines
drivers/media/platform/nuvoton/npcm-video.c new file +10 -0
+	.ops = &npcm_video_ctrl_ops,
+	.id = V4L2_CID_NPCM_RECT_COUNT,
+	.name = "NPCM Compressed Hextile Rectangle Count",
+	.type = V4L2_CTRL_TYPE_INTEGER,
+	.flags = V4L2_CTRL_FLAG_VOLATILE,
+	.min = 0,
+	.max = (MAX_WIDTH / RECT_W) * (MAX_HEIGHT / RECT_H),
+	.step = 1,
+	.def = 0,
+};

Just to confirm: you decided against using an integer array control?

There is a real danger that if userspace isn't reading this control quickly enough (i.e. before the next frame arrives at the driver), then the control's value is that of that next frame instead of the current frame.

It doesn't feel robust to me.

<snip>

Regards,

Hans

author
#9 lore raw

Re: [PATCH v14 7/7] media: nuvoton: Add driver for NPCM video capture and encode engine

Hi Hans,

Thanks for the review.

Quoted 11 lines
Quoted 1 line

+ snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", DEVICE_NAME);

You can drop this last line, it is already filled in by the V4L2 core for platform devices.

drivers/media/platform/nuvoton/npcm-video.c line 1387

Quoted 3 lines
drivers/media/platform/nuvoton/npcm-video.c new file +3 -0
+static const char * const npcm_ctrl_capture_mode_menu[] = {
+     "COMPLETE mode",
+     "DIFF mode",

Hmm, I would drop the 'mode' bit, since it is already obvious that these are the modes.

OK. Will drop them in the next version.

Quoted 14 lines

drivers/media/platform/nuvoton/npcm-video.c line 1412

Quoted 11 lines
drivers/media/platform/nuvoton/npcm-video.c new file +11 -0
+static const struct v4l2_ctrl_config npcm_ctrl_rect_count = {
+     .ops = &npcm_video_ctrl_ops,
+     .id = V4L2_CID_NPCM_RECT_COUNT,
+     .name = "NPCM Compressed Hextile Rectangle Count",
+     .type = V4L2_CTRL_TYPE_INTEGER,
+     .flags = V4L2_CTRL_FLAG_VOLATILE,
+     .min = 0,
+     .max = (MAX_WIDTH / RECT_W) * (MAX_HEIGHT / RECT_H),
+     .step = 1,
+     .def = 0,
+};

Just to confirm: you decided against using an integer array control?

Quoted 6 lines

There is a real danger that if userspace isn't reading this control quickly enough (i.e. before the next frame arrives at the driver), then the control's value is that of that next frame instead of the current frame.

It doesn't feel robust to me.

Actually the driver will store the frames and counts for each buffer index till userspace dequeues them.

Ex. assume that driver has captured 3 frames:
- 1st capture (buffer index = 0):

     video->list[0] => store the list of HEXTILE rects for the 1st frame
     video->rect[0] => store the rect count of video->list[0]
- 2nd capture (buffer index = 1):
     video->list[1] => store the list of HEXTILE rects for the 2nd frame
     video->rect[1] => store the rect count of video->list[1]
- 3rd capture (buffer index = 2):
     video->list[2] => store the list of HEXTILE rects for the 3rd frame
     video->rect[2] => store the rect count of video->list[2]

When userspace dequeues the 1st buffer (video->list[0]), it needs to know the count of HEXTILE rectangles in the buffer,
so after dequeuing the buffer it will call this control to get the rect count (video->rect[0]). And when a buffer is dequeued, npcm_video_buf_finish() will be called, in which the buffer index (in this example, buffer index = 0) will be stored to video->vb_index. Then when userspace calls this control, npcm_video_get_volatile_ctrl() will return the rect count of vb_index = 0.
In this way, I think userspace is always reading the correct control's value even if userspace is slow.
Does it make sense to you or is there anything I missed?

Regards,
Marvin

#10 lore raw

Re: [PATCH v14 7/7] media: nuvoton: Add driver for NPCM video capture and encode engine

Quoted 53 lines · Kun-Fa Lin

Hi Hans,

Thanks for the review.

Quoted 11 lines
Quoted 1 line

+ snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", DEVICE_NAME);

You can drop this last line, it is already filled in by the V4L2 core for platform devices.

drivers/media/platform/nuvoton/npcm-video.c line 1387

Quoted 3 lines
drivers/media/platform/nuvoton/npcm-video.c new file +3 -0
+static const char * const npcm_ctrl_capture_mode_menu[] = {
+     "COMPLETE mode",
+     "DIFF mode",

Hmm, I would drop the 'mode' bit, since it is already obvious that these are the modes.

OK. Will drop them in the next version.

Quoted 14 lines

drivers/media/platform/nuvoton/npcm-video.c line 1412

Quoted 11 lines
drivers/media/platform/nuvoton/npcm-video.c new file +11 -0
+static const struct v4l2_ctrl_config npcm_ctrl_rect_count = {
+     .ops = &npcm_video_ctrl_ops,
+     .id = V4L2_CID_NPCM_RECT_COUNT,
+     .name = "NPCM Compressed Hextile Rectangle Count",
+     .type = V4L2_CTRL_TYPE_INTEGER,
+     .flags = V4L2_CTRL_FLAG_VOLATILE,
+     .min = 0,
+     .max = (MAX_WIDTH / RECT_W) * (MAX_HEIGHT / RECT_H),
+     .step = 1,
+     .def = 0,
+};

Just to confirm: you decided against using an integer array control?

Quoted 6 lines

There is a real danger that if userspace isn't reading this control quickly enough (i.e. before the next frame arrives at the driver), then the control's value is that of that next frame instead of the current frame.

It doesn't feel robust to me.

Actually the driver will store the frames and counts for each buffer index till userspace dequeues them.

Ex. assume that driver has captured 3 frames:
- 1st capture (buffer index = 0):

     video->list[0] => store the list of HEXTILE rects for the 1st frame
     video->rect[0] => store the rect count of video->list[0]
- 2nd capture (buffer index = 1):
     video->list[1] => store the list of HEXTILE rects for the 2nd frame
     video->rect[1] => store the rect count of video->list[1]
- 3rd capture (buffer index = 2):
     video->list[2] => store the list of HEXTILE rects for the 3rd frame
     video->rect[2] => store the rect count of video->list[2]
Quoted 11 lines

When userspace dequeues the 1st buffer (video->list[0]), it needs to know the count of HEXTILE rectangles in the buffer,
so after dequeuing the buffer it will call this control to get the rect count (video->rect[0]). And when a buffer is dequeued, npcm_video_buf_finish() will be called, in which the buffer index (in this example, buffer index = 0) will be stored to video->vb_index. Then when userspace calls this control, npcm_video_get_volatile_ctrl() will return the rect count of vb_index = 0.
In this way, I think userspace is always reading the correct control's value even if userspace is slow.
Does it make sense to you or is there anything I missed?

Ah, I don't think I have ever seen anyone use buf_finish in that way!

Very inventive, and perfectly legal. Actually a very nice idea!

So, with that in mind there are still some things that need to change.

First of all, you can drop the 'VOLATILE' flag from the control, instead just call v4l2_ctrl_s_ctrl() from buf_finish() to update the control. And in stop_streaming the control value should probably be set to 0.

The use of volatile for a control is a last resort, and in this case it is not volatile at all.

Secondly, this behavior has to be documented: in buf_finish add a comment along the lines of: "This callback is called when the buffer is dequeued, so update this control with the number of rectangles."

And where the control is defined, refer to buf_finish to explain where it is set.

Finally the user-facing documentation has to be updated (npcm-video.rst) to explain this behavior.

Regards,

Hans

author
#11 lore raw

Re: [PATCH v14 7/7] media: nuvoton: Add driver for NPCM video capture and encode engine

Hi Hans,

Thanks for the reply.

Quoted 29 lines
Quoted 11 lines

When userspace dequeues the 1st buffer (video->list[0]), it needs to know the count of HEXTILE rectangles in the buffer,
so after dequeuing the buffer it will call this control to get the rect count (video->rect[0]). And when a buffer is dequeued, npcm_video_buf_finish() will be called, in which the buffer index (in this example, buffer index = 0) will be stored to video->vb_index. Then when userspace calls this control, npcm_video_get_volatile_ctrl() will return the rect count of vb_index = 0.
In this way, I think userspace is always reading the correct control's value even if userspace is slow.
Does it make sense to you or is there anything I missed?

Ah, I don't think I have ever seen anyone use buf_finish in that way!

Very inventive, and perfectly legal. Actually a very nice idea!

So, with that in mind there are still some things that need to change.

First of all, you can drop the 'VOLATILE' flag from the control, instead just call v4l2_ctrl_s_ctrl() from buf_finish() to update the control. And in stop_streaming the control value should probably be set to 0.

The use of volatile for a control is a last resort, and in this case it is not volatile at all.

Secondly, this behavior has to be documented: in buf_finish add a comment along the lines of: "This callback is called when the buffer is dequeued, so update this control with the number of rectangles."

Quoted 5 lines

And where the control is defined, refer to buf_finish to explain where it is set.

Finally the user-facing documentation has to be updated (npcm-video.rst) to explain this behavior.

OK. Will drop the VOLATILE flag and update comment/document in the next version.

Regards,
Marvin