Add support for Wave6 video codec driver
Subsystems (4)
v5 cover Add support for Wave6 video codec driver
This RFC primarily asks for feedback on the devicetree representation for the Chips&Media Wave6 codec block on NXP i.MX95. It only includes DT-driven changes. Non-DT driver feedback and cleanups will be addressed once the DT structure is agreed.
On i.MX95 the Wave6 hardware exposes one control register region and four interface register regions for one shared video processing engine. In this RFC, the control region is described by the parent node and the interface regions by child nodes. The control and interface regions are distinct DMA requesters and can be associated with separate IOMMU stream IDs, allowing DMA isolation between them. The control region has its own MMIO range, and each interface region has its own MMIO range and interrupt.
I also evaluated folding all resources into a single parent node, but in that model all stream IDs end up attached to the same IOMMU domain and we observed loss of DMA isolation. Alternatives such as iommu-map or a vendor-specific stream ID property were considered, but they do not seem to fit this use case.
Thanks for your time and feedback.
RFC v5:
- Move all shared resources to the parent node
- Drop child compatible and use data-only interface child nodes
- Update the VPU driver to create child devices and load the core driver
v4:
- Fixed build issues reported by CI tools
- Updated commit messages to use imperative mood
- Avoided using the same name for both nodes and labels in devicetree
- Removed unused labels from YAML examples
- Added description for child(vpu-core) node
- Added iommus property to both parent(vpu) and child(vpu-core) nodes
- Updated probe() functions to use dev_err_probe() when returning -EPROBE_DEFER
- Added wave6_vpu prefix to trace functions
- Updated HEVC decoder profile control to report MAIN_STILL profile
- Fixed bug in multiple instance creation by pre-allocating work buffer
- Fixed interrupt handling by checking INSTANCE_INFO register and instance list
v3:
- Removed ambiguous SUPPORT_FOLLOWER feature
- Used WARN_ON() for unexpected programming errors
- Split thermal device code into wave6-vpu-thermal.c/h
- Dropped wave6_cooling_disable module parameter
- Replaced mutex_lock() with guard()
- Added lockdep_assert_held() to clarify locking regions
- Removed exported function due to dual-license and used function pointer
- Added documentation and validation for state transitions
- Added documentation for device structures
- Added patch to enable VPU device in imx95 DTS
- Updated DT bindings and driver to align with parent(vpu) and child(vpu-core)
- Replaced magic numbers with mask and offset macros when accessing registers
- Placed goto statements after an empty line
- Printed HW info (e.g. product_code) via dev_dbg() for debugging
- Replaced wave6_vpu_dec_give_command() with dedicated functions
v2:
- Refined DT bindings to better represent the hardware
- Reworked driver to align with the parent(VPU) and child(CTRL, CORE)
- Fixed build issues reported by CI tools (Smatch, Sparse, TRACE)
- Improved commit messages with clearer descriptions
- Added kernel-doc for exported functions
- Removed redundant print statements and unused code
- Reordered patches to prevent build failures
Nas Chung (9):
media: v4l2-common: Add YUV24 format info
dt-bindings: media: nxp: Add Wave6 video codec device
media: chips-media: wave6: Add Wave6 VPU interface
media: chips-media: wave6: Add v4l2 m2m driver support
media: chips-media: wave6: Add Wave6 core driver
media: chips-media: wave6: Improve debugging capabilities
media: chips-media: wave6: Add Wave6 thermal cooling device
media: chips-media: wave6: Add Wave6 control driver
arm64: dts: freescale: imx95: Add video codec node
.../bindings/media/nxp,imx95-vpu.yaml | 163 + MAINTAINERS | 8 + .../boot/dts/freescale/imx95-15x15-evk.dts | 7 +- .../boot/dts/freescale/imx95-15x15-frdm.dts | 5 + .../boot/dts/freescale/imx95-19x19-evk.dts | 10 + .../dts/freescale/imx95-19x19-verdin-evk.dts | 10 + .../dts/freescale/imx95-phycore-fpsc.dtsi | 10 + .../dts/freescale/imx95-toradex-smarc-dev.dts | 5 + .../dts/freescale/imx95-toradex-smarc.dtsi | 5 + .../boot/dts/freescale/imx95-tqma9596sa.dtsi | 7 +- arch/arm64/boot/dts/freescale/imx95.dtsi | 35 + drivers/media/platform/chips-media/Kconfig | 1 + drivers/media/platform/chips-media/Makefile | 1 + .../media/platform/chips-media/wave6/Kconfig | 17 + .../media/platform/chips-media/wave6/Makefile | 17 + .../platform/chips-media/wave6/wave6-hw.c | 2929 +++++++++++++++++ .../platform/chips-media/wave6/wave6-hw.h | 73 + .../chips-media/wave6/wave6-regdefine.h | 641 ++++ .../platform/chips-media/wave6/wave6-trace.h | 289 ++ .../platform/chips-media/wave6/wave6-vdi.h | 92 + .../chips-media/wave6/wave6-vpu-core.c | 397 +++ .../chips-media/wave6/wave6-vpu-core.h | 123 + .../chips-media/wave6/wave6-vpu-dbg.c | 225 ++ .../chips-media/wave6/wave6-vpu-dbg.h | 14 + .../chips-media/wave6/wave6-vpu-dec.c | 1867 +++++++++++ .../chips-media/wave6/wave6-vpu-enc.c | 2691 +++++++++++++++ .../chips-media/wave6/wave6-vpu-thermal.c | 141 + .../chips-media/wave6/wave6-vpu-thermal.h | 26 + .../chips-media/wave6/wave6-vpu-v4l2.c | 507 +++ .../platform/chips-media/wave6/wave6-vpu.c | 816 +++++ .../platform/chips-media/wave6/wave6-vpu.h | 143 + .../platform/chips-media/wave6/wave6-vpuapi.c | 725 ++++ .../platform/chips-media/wave6/wave6-vpuapi.h | 1026 ++++++ .../chips-media/wave6/wave6-vpuconfig.h | 72 + .../chips-media/wave6/wave6-vpuerror.h | 262 ++ drivers/media/v4l2-core/v4l2-common.c | 1 + 36 files changed, 13359 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/media/nxp,imx95-vpu.yaml create mode 100644 drivers/media/platform/chips-media/wave6/Kconfig create mode 100644 drivers/media/platform/chips-media/wave6/Makefile create mode 100644 drivers/media/platform/chips-media/wave6/wave6-hw.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-hw.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-regdefine.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-trace.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vdi.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-core.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-core.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-dbg.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-dbg.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-dec.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-enc.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-v4l2.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpuapi.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpuapi.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpuconfig.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpuerror.h
Signature · 1 line
2.31.1
RFC PATCH v5 1/9 media: v4l2-common: Add YUV24 format info
The YUV24 format is missing an entry in the v4l2_format_info(). The YUV24 format is the packed YUV 4:4:4 formats with 8 bits per component.
--- drivers/media/v4l2-core/v4l2-common.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/v4l2-core/v4l2-common.c +1 -0
@@ -281,6 +281,7 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_Y212, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 }, { .format = V4L2_PIX_FMT_Y216, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 }, { .format = V4L2_PIX_FMT_YUV48_12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 6, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_YUV24, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_MT2110T, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2, .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }}, { .format = V4L2_PIX_FMT_MT2110R, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2,
Signature · 1 line
2.31.1
Re: [RFC PATCH v5 1/9] media: v4l2-common: Add YUV24 format info
Le mercredi 15 avril 2026 à 18:25 +0900, Nas Chung a écrit :
Quoted 7 lines
The YUV24 format is missing an entry in the
v4l2_format_info(). The YUV24 format is the packed YUV 4:4:4 formats with 8 bits per component.Fixes 0376a51fbe5e ("media: v4l: Add packed YUV444 24bpp pixel format")Signed-off-by Nas Chung <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>
Unless you disagree, I might cherry-pick this one. Would it be ok with you ?
Nicolas
Quoted 16 lines
---
drivers/media/v4l2-core/v4l2-common.c | 1 +1 file changed, 1 insertion(+)drivers/media/v4l2-core/v4l2-common.c +1
-0@@ -281,6 +281,7 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_Y212, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 }, { .format = V4L2_PIX_FMT_Y216, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 }, { .format = V4L2_PIX_FMT_YUV48_12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 6, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_YUV24, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_MT2110T, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2, .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }}, { .format = V4L2_PIX_FMT_MT2110R, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2,
RE: [RFC PATCH v5 1/9] media: v4l2-common: Add YUV24 format info
Hi, Nicolas.
Quoted 16 lines
-----Original Message-----
From: Nicolas Dufresne <[email protected]>
Sent: Tuesday, April 21, 2026 12:40 AM
To: Nas Chung <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH v5 1/9] media: v4l2-common: Add YUV24 format infoLe mercredi 15 avril 2026 à 18:25 +0900, Nas Chung a écrit :
Quoted 4 lines
The YUV24 format is missing an entry in the
v4l2_format_info(). The YUV24 format is the packed YUV 4:4:4 formats with 8 bits per component.
Quoted 5 lines
Quoted 3 lines
Fixes 0376a51fbe5e ("media: v4l: Add packed YUV444 24bpp pixel format")Signed-off-by Nas Chung <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>Unless you disagree, I might cherry-pick this one. Would it be ok with you ?
Sure, that's fine with me.
Thanks.
Nas.
Quoted 33 lines
Nicolas
drivers/media/v4l2-
Quoted 5 lines
---
drivers/media/v4l2-core/v4l2-common.c | 1 +1 file changed, 1 insertion(+)drivers/media/v4l2- renamed from drivers/media/v4l2-core/v4l2-common.c +0
-0
core/v4l2-common.cdrivers/media/v4l2-core/v4l2-common.c const struct v4l2_format_info *v4l2_format_info(u32
Quoted 4 lines
index
554c591e1113..55bcd5975d9f100644drivers/media/v4l2-core/v4l2-common.c +0
-0@@ -281,6 +281,7 @@ const struct v4l2_format_info *v4l2_format_info(u32format)
Quoted 1 line
{ .format = V4L2_PIX_FMT_Y212, .pixel_enc =
V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 },Quoted 1 line
{ .format = V4L2_PIX_FMT_Y216, .pixel_enc =
V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 1 },Quoted 1 line
{ .format =
V4L2_PIX_FMT_YUV48_12, .pixel_enc =
V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 6, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },drivers/media/v4l2-core/v4l2-common.c
Quoted 1 line
drivers/media/v4l2-core/v4l2-common.c +1
-0+ { .format = V4L2_PIX_FMT_YUV24, .pixel_enc =
V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },Quoted 1 line
{ .format =
V4L2_PIX_FMT_MT2110T, .pixel_enc =
V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2,Quoted 2 lines
.block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }}, { .format =
V4L2_PIX_FMT_MT2110R, .pixel_enc =
V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2,
RFC PATCH v5 2/9 dt-bindings: media: nxp: Add Wave6 video codec device
In reply to Nas ChungAdd documentation for the Chips&Media Wave6 video codec on NXP i.MX SoCs.
The hardware contains one control register region and four interface register regions for a shared video processing engine. The control region manages shared resources such as firmware memory, while each interface region has its own MMIO range and interrupt.
The control region and each interface region are distinct DMA requesters and can be associated with separate IOMMU stream IDs. Represent the control region as the parent node and the interface register regions as child nodes to describe these resources.
--- .../bindings/media/nxp,imx95-vpu.yaml | 163 ++++++++++++++++++ MAINTAINERS | 7 + 2 files changed, 170 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/nxp,imx95-vpu.yaml
Documentation/devicetree/bindings/media/nxp,imx95-vpu.yaml new file +163 -0
@@ -0,0 +1,163 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/nxp,imx95-vpu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Chips&Media Wave6 Series multi-standard codec IP on NXP i.MX SoCs + +maintainers: + - Nas Chung <[email protected]> + - Jackson Lee <[email protected]> + +description: + The Chips&Media Wave6 codec IP is a multi-standard video encoder/decoder. + On NXP i.MX SoCs, the Wave6 codec IP exposes one control register region and + four interface register regions for a shared video processing engine. + The parent node describes the control region, which has its own MMIO range and + manages shared resources such as firmware memory. The child nodes describe the + interface register regions. Each interface region has its own MMIO range and + interrupt. + The control region and the interface regions are distinct DMA requesters. + The control region and each interface region can be associated with separate + IOMMU stream IDs, allowing DMA isolation between them. + +properties: + compatible: + enum: + - nxp,imx95-vpu + + reg: + maxItems: 1 + + clocks: + items: + - description: VPU core clock + - description: VPU associated block clock + + clock-names: + items: + - const: core + - const: vpublk + + power-domains: + items: + - description: Main VPU power domain + - description: Performance power domain + + power-domain-names: + items: + - const: vpu + - const: perf + + memory-region: + maxItems: 1 + + sram: + $ref: /schemas/types.yaml#/definitions/phandle + description: + phandle to the SRAM node used to store reference data, reducing DMA + memory bandwidth. + + iommus: + maxItems: 1 + + "#cooling-cells": + const: 2 + + "#address-cells": + const: 2 + + "#size-cells": + const: 2 + + ranges: true + +patternProperties: + "^interface@[0-9a-f]+$": + type: object + description: + An interface register region within the Chips&Media Wave6 codec IP. + Each region has its own MMIO range and interrupt and can be associated + with a separate IOMMU stream ID for DMA isolation. + additionalProperties: false + + properties: + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + iommus: + maxItems: 1 + + required: + - reg + - interrupts + +required: + - compatible + - reg + - clocks + - clock-names + - power-domains + - power-domain-names + - memory-region + - "#address-cells" + - "#size-cells" + - ranges + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/clock/nxp,imx95-clock.h> + + soc { + #address-cells = <2>; + #size-cells = <2>; + + video-codec@4c4c0000 { + compatible = "nxp,imx95-vpu"; + reg = <0x0 0x4c4c0000 0x0 0x10000>; + clocks = <&scmi_clk 115>, + <&vpu_blk_ctrl IMX95_CLK_VPUBLK_WAVE>; + clock-names = "core", "vpublk"; + power-domains = <&scmi_devpd 21>, + <&scmi_perf 10>; + power-domain-names = "vpu", "perf"; + memory-region = <&vpu_boot>; + sram = <&sram1>; + iommus = <&smmu 0x32>; + #cooling-cells = <2>; + #address-cells = <2>; + #size-cells = <2>; + ranges; + + interface@4c480000 { + reg = <0x0 0x4c480000 0x0 0x10000>; + interrupts = <GIC_SPI 299 IRQ_TYPE_LEVEL_HIGH>; + iommus = <&smmu 0x33>; + }; + + interface@4c490000 { + reg = <0x0 0x4c490000 0x0 0x10000>; + interrupts = <GIC_SPI 300 IRQ_TYPE_LEVEL_HIGH>; + iommus = <&smmu 0x34>; + }; + + interface@4c4a0000 { + reg = <0x0 0x4c4a0000 0x0 0x10000>; + interrupts = <GIC_SPI 301 IRQ_TYPE_LEVEL_HIGH>; + iommus = <&smmu 0x35>; + }; + + interface@4c4b0000 { + reg = <0x0 0x4c4b0000 0x0 0x10000>; + interrupts = <GIC_SPI 302 IRQ_TYPE_LEVEL_HIGH>; + iommus = <&smmu 0x36>; + }; + }; + };
MAINTAINERS +7 -0
@@ -28393,6 +28393,13 @@ S: Maintained F: Documentation/devicetree/bindings/media/cnm,wave521c.yaml F: drivers/media/platform/chips-media/wave5/ +WAVE6 VPU CODEC DRIVER +M: Nas Chung <[email protected]> +M: Jackson Lee <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/media/nxp,imx95-vpu.yaml + WHISKEYCOVE PMIC GPIO DRIVER M: Kuppuswamy Sathyanarayanan <[email protected]> L: [email protected]
Signature · 1 line
2.31.1
RFC PATCH v5 3/9 media: chips-media: wave6: Add Wave6 VPU interface
In reply to Nas ChungAdd an interface layer to manage hardware register configuration and communication with the Chips&Media Wave6 video codec IP.
The interface provides low-level helper functions used by the Wave6 core driver to implement video encoding and decoding operations. It handles command submission to the firmware via MMIO registers, and waits for a response by polling the firmware busy flag.
--- MAINTAINERS | 1 + .../platform/chips-media/wave6/wave6-hw.c | 2929 +++++++++++++++++ .../platform/chips-media/wave6/wave6-hw.h | 73 + .../chips-media/wave6/wave6-regdefine.h | 641 ++++ .../platform/chips-media/wave6/wave6-vdi.h | 92 + .../platform/chips-media/wave6/wave6-vpuapi.c | 725 ++++ .../platform/chips-media/wave6/wave6-vpuapi.h | 1026 ++++++ .../chips-media/wave6/wave6-vpuconfig.h | 72 + .../chips-media/wave6/wave6-vpuerror.h | 262 ++ 9 files changed, 5821 insertions(+) create mode 100644 drivers/media/platform/chips-media/wave6/wave6-hw.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-hw.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-regdefine.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vdi.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpuapi.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpuapi.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpuconfig.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpuerror.h
MAINTAINERS +1 -0
@@ -28399,6 +28399,7 @@ M: Jackson Lee <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/media/nxp,imx95-vpu.yaml +F: drivers/media/platform/chips-media/wave6/ WHISKEYCOVE PMIC GPIO DRIVER M: Kuppuswamy Sathyanarayanan <[email protected]>
drivers/media/platform/chips-media/wave6/wave6-hw.c new file +2929 -0
2,929 lines not on this page · raw message
drivers/media/platform/chips-media/wave6/wave6-hw.h new file +73 -0
64 lines not on this page · raw message
drivers/media/platform/chips-media/wave6/wave6-regdefine.h new file +641 -0
641 lines not on this page · raw message
drivers/media/platform/chips-media/wave6/wave6-vdi.h new file +92 -0
92 lines not on this page · raw message
drivers/media/platform/chips-media/wave6/wave6-vpuapi.c new file +725 -0
725 lines not on this page · raw message
drivers/media/platform/chips-media/wave6/wave6-vpuapi.h new file +1026 -0
1,026 lines not on this page · raw message
drivers/media/platform/chips-media/wave6/wave6-vpuconfig.h new file +72 -0
72 lines not on this page · raw message
drivers/media/platform/chips-media/wave6/wave6-vpuerror.h new file +262 -0
262 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.31.1
Part of the diff is not shown here. View the raw message.
RFC PATCH v5 4/9 media: chips-media: wave6: Add v4l2 m2m driver support
In reply to Nas ChungAdd v4l2 m2m stateful driver support for the
Chips&Media Wave6 video codec IP, including both encoder and decoder.
The following features and formats are supported:
Encoder (8bit only):
- Supported codecs: AVC, HEVC
- Supported input formats:
* V4L2_PIX_FMT_YUV420/NV12/NV21
* V4L2_PIX_FMT_YUV422P/NV16/NV61
* V4L2_PIX_FMT_YUYV
* V4L2_PIX_FMT_YUV24/NV24/NV42
* V4L2_PIX_FMT_RGB24
* V4L2_PIX_FMT_P010
* V4L2_PIX_FMT_ARGB32
* V4L2_PIX_FMT_RGBA32
* V4L2_PIX_FMT_XRGB32
* V4L2_PIX_FMT_ARGB2101010
- Supports multiplanar format
- Although 10-bit input formats are supported (e.g., P010, ARGB2101010), encoded output is limited to 8-bit streams
- Supports crop
- Supports extensive v4l2 encoder control
Decoder (8bit only):
- Supported codecs: AVC, HEVC (8bit only)
- Supported output formats: V4L2_PIX_FMT_YUV420/NV12/NV21
- Supports multiplanar format
- Supports scale down
- Supports dynamic resolution change
Note: While other versions of the Wave6 IP may support VP9 decoding and AV1 decoding and encoding those formats are not implemented or validated in this driver at this time.
--- .../chips-media/wave6/wave6-vpu-dec.c | 1867 ++++++++++++ .../chips-media/wave6/wave6-vpu-enc.c | 2691 +++++++++++++++++ .../chips-media/wave6/wave6-vpu-v4l2.c | 507 ++++ 3 files changed, 5065 insertions(+) create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-dec.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-enc.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-v4l2.c
drivers/media/platform/chips-media/wave6/wave6-vpu-dec.c new file +1867 -0
@@ -0,0 +1,1867 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +/* +* Wave6 series multi-standard codec IP - v4l2 stateful decoder interface +* +* Copyright (C) 2025 CHIPS&MEDIA INC +*/ + +#include <linux/pm_runtime.h> +#include <linux/delay.h> +#include "wave6-vpu-core.h" +#include "wave6-vpu-dbg.h" +#include "wave6-trace.h" + +#define VPU_DEC_DEV_NAME "C&M Wave6 VPU decoder" +#define VPU_DEC_DRV_NAME "wave6-dec" + +static const struct vpu_format wave6_vpu_dec_fmt_list[2 ][6 ] = { + [VPU_FMT_TYPE_CODEC ] = { + { + .v4l2_pix_fmt =V4L2_PIX_FMT_HEVC , + .max_width =W6_MAX_DEC_PIC_WIDTH , + .min_width =W6_MIN_DEC_PIC_WIDTH , + .max_height =W6_MAX_DEC_PIC_HEIGHT , + .min_height =W6_MIN_DEC_PIC_HEIGHT , + .num_planes =1 , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_H264 , + .max_width =W6_MAX_DEC_PIC_WIDTH , + .min_width =W6_MIN_DEC_PIC_WIDTH , + .max_height =W6_MAX_DEC_PIC_HEIGHT , + .min_height =W6_MIN_DEC_PIC_HEIGHT , + .num_planes =1 , + }, + }, + [VPU_FMT_TYPE_RAW ] = { + { + .v4l2_pix_fmt =V4L2_PIX_FMT_YUV420 , + .max_width =W6_MAX_DEC_PIC_WIDTH , + .min_width =W6_MIN_DEC_PIC_WIDTH , + .max_height =W6_MAX_DEC_PIC_HEIGHT , + .min_height =W6_MIN_DEC_PIC_HEIGHT , + .num_planes =1 , + .fb_fmt =FORMAT_420 , + .endian =VPU_SOURCE_ENDIAN , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV12 , + .max_width =W6_MAX_DEC_PIC_WIDTH , + .min_width =W6_MIN_DEC_PIC_WIDTH , + .max_height =W6_MAX_DEC_PIC_HEIGHT , + .min_height =W6_MIN_DEC_PIC_HEIGHT , + .num_planes =1 , + .fb_fmt =FORMAT_420 , + .endian =VPU_SOURCE_ENDIAN , + .flags =VPU_FMT_FLAG_CBCR_INTERLEAVED , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV21 , + .max_width =W6_MAX_DEC_PIC_WIDTH , + .min_width =W6_MIN_DEC_PIC_WIDTH , + .max_height =W6_MAX_DEC_PIC_HEIGHT , + .min_height =W6_MIN_DEC_PIC_HEIGHT , + .num_planes =1 , + .fb_fmt =FORMAT_420 , + .endian =VPU_SOURCE_ENDIAN , + .flags =VPU_FMT_FLAG_CBCR_INTERLEAVED | +VPU_FMT_FLAG_CRCB_ORDER , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_YUV420M , + .max_width =W6_MAX_DEC_PIC_WIDTH , + .min_width =W6_MIN_DEC_PIC_WIDTH , + .max_height =W6_MAX_DEC_PIC_HEIGHT , + .min_height =W6_MIN_DEC_PIC_HEIGHT , + .num_planes =3 , + .fb_fmt =FORMAT_420 , + .endian =VPU_SOURCE_ENDIAN , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV12M , + .max_width =W6_MAX_DEC_PIC_WIDTH , + .min_width =W6_MIN_DEC_PIC_WIDTH , + .max_height =W6_MAX_DEC_PIC_HEIGHT , + .min_height =W6_MIN_DEC_PIC_HEIGHT , + .num_planes =2 , + .fb_fmt =FORMAT_420 , + .endian =VPU_SOURCE_ENDIAN , + .flags =VPU_FMT_FLAG_CBCR_INTERLEAVED , + }, + { + .v4l2_pix_fmt =V4L2_PIX_FMT_NV21M , + .max_width =W6_MAX_DEC_PIC_WIDTH , + .min_width =W6_MIN_DEC_PIC_WIDTH , + .max_height =W6_MAX_DEC_PIC_HEIGHT , + .min_height =W6_MIN_DEC_PIC_HEIGHT , + .num_planes =2 , + .fb_fmt =FORMAT_420 , + .endian =VPU_SOURCE_ENDIAN , + .flags =VPU_FMT_FLAG_CBCR_INTERLEAVED | +VPU_FMT_FLAG_CRCB_ORDER , + }, + } +}; + +static const struct vpu_format *wave6_find_vpu_fmt (unsigned int v4l2_pix_fmt, +enum vpu_fmt_type type) +{ +unsigned int index; + +for (index =0 ; index <ARRAY_SIZE (wave6_vpu_dec_fmt_list[type]); index++) { +if (wave6_vpu_dec_fmt_list[type][index].v4l2_pix_fmt == v4l2_pix_fmt) +return &wave6_vpu_dec_fmt_list[type][index]; + } + +return NULL ; +} + +static const struct vpu_format *wave6_find_vpu_fmt_by_idx (unsigned int idx, +enum vpu_fmt_type type) +{ +if (idx >=ARRAY_SIZE (wave6_vpu_dec_fmt_list[type])) +return NULL ; + +if (!wave6_vpu_dec_fmt_list[type][idx].v4l2_pix_fmt) +return NULL ; + +return &wave6_vpu_dec_fmt_list[type][idx]; +} + +static void wave6_vpu_dec_release_fb (struct vpu_instance *inst) +{ +int i; + +for (i =0 ; i <WAVE6_MAX_FBS ; i++) { +wave6_vdi_free_dma (&inst->frame_vbuf[i]); +memset (&inst->frame_buf[i],0 ,sizeof (struct frame_buffer )); +wave6_vdi_free_dma (&inst->aux_vbuf[AUX_BUF_FBC_Y_TBL ][i]); +wave6_vdi_free_dma (&inst->aux_vbuf[AUX_BUF_FBC_C_TBL ][i]); +wave6_vdi_free_dma (&inst->aux_vbuf[AUX_BUF_MV_COL ][i]); + } +} + +static void wave6_vpu_dec_destroy_instance (struct vpu_instance *inst) +{ +u32 fail_res =0 ; +int ret; + +wave6_vpu_remove_dbgfs_file (inst); + + ret =wave6_vpu_dec_close (inst, &fail_res); +if (ret) { +dev_err (inst->dev->dev,"failed destroy instance: %d (%d)\n" , + ret, fail_res); + } + + scoped_guard(spinlock, &inst->dev->inst_lock) +list_del_init (&inst->list); +wave6_vpu_dec_release_fb (inst); +wave6_vpu_set_instance_state (inst,VPU_INST_STATE_NONE ); + +if (!pm_runtime_suspended (inst->dev->dev)) +pm_runtime_put_sync (inst->dev->dev); +} + +static void wave6_handle_bitstream_buffer (struct vpu_instance *inst) +{ +struct vb2_v4l2_buffer *src_buf; +u32 src_size =0 ; +int ret; + + src_buf =v4l2_m2m_next_src_buf (inst->v4l2_fh.m2m_ctx); +if (src_buf) { +struct vpu_buffer *vpu_buf =wave6_to_vpu_buf (src_buf); +dma_addr_t rd_ptr =wave6_get_dma_addr (src_buf,0 ); + +if (vpu_buf->consumed) { +dev_dbg (inst->dev->dev,"%s: Already consumed buffer\n" , + __func__); +return ; + } + + vpu_buf->ts_start =ktime_get_raw (); + vpu_buf->consumed = true; +wave6_vpu_dec_set_rd_ptr (inst, rd_ptr, true); + + src_size =vb2_get_plane_payload (&src_buf->vb2_buf,0 ); + } + +if (!src_size) { +dma_addr_t rd =0 , wr =0 ; + +wave6_vpu_dec_get_bitstream_buffer (inst, &rd, &wr); +wave6_vpu_dec_set_rd_ptr (inst, wr, true); + } + +trace_wave6_vpu_dec_pic (inst, src_buf ? src_buf->vb2_buf.index :-1 , src_size); + + ret =wave6_vpu_dec_update_bitstream_buffer (inst, src_size); +if (ret) { +dev_dbg (inst->dev->dev,"%s: Update bitstream buffer fail %d\n" , + __func__, ret); +return ; + } +} + +static void wave6_update_pix_fmt_cap (struct v4l2_pix_format_mplane *pix_mp, +unsigned int width, +unsigned int height, +bool new_resolution) +{ +unsigned int aligned_width; + +if (new_resolution) + pix_mp->plane_fmt[0 ].bytesperline =0 ; + + aligned_width =round_up (width,W6_DEC_BUF_ALIGNMENT ); +wave6_update_pix_fmt (pix_mp, aligned_width, height); +} + +static int wave6_allocate_aux_buffer (struct vpu_instance *inst, +enum aux_buffer_type type, +int num) +{ +struct aux_buffer buf[WAVE6_MAX_FBS ]; +struct aux_buffer_info buf_info; +struct dec_aux_buffer_size_info size_info; +unsigned int size; +int i, ret; + +memset (buf,0 ,sizeof (buf)); + + size_info.width = inst->src_fmt.width; + size_info.height = inst->src_fmt.height; + size_info.type = type; + + ret =wave6_vpu_dec_get_aux_buffer_size (inst, size_info, &size); +if (ret) { +dev_dbg (inst->dev->dev,"%s: Get size fail (type %d)\n" , __func__, type); +return ret; + } + + num =min_t (u32, num,WAVE6_MAX_FBS ); +for (i =0 ; i < num; i++) { + inst->aux_vbuf[type][i].size = size; + ret =wave6_vdi_alloc_dma (inst->dev->dev, &inst->aux_vbuf[type][i]); +if (ret) { +dev_dbg (inst->dev->dev,"%s: Alloc fail (type %d)\n" , __func__, type); +return ret; + } + + buf[i].index = i; + buf[i].addr = inst->aux_vbuf[type][i].daddr; + buf[i].size = inst->aux_vbuf[type][i].size; + } + + buf_info.type = type; + buf_info.num = num; + buf_info.buf_array = buf; + + ret =wave6_vpu_dec_register_aux_buffer (inst, buf_info); +if (ret) { +dev_dbg (inst->dev->dev,"%s: Register fail (type %d)\n" , __func__, type); +return ret; + } + +return 0 ; +} + +static void wave6_vpu_dec_handle_dst_buffer (struct vpu_instance *inst) +{ +struct vb2_v4l2_buffer *dst_buf; +struct v4l2_m2m_buffer *v4l2_m2m_buf; +struct vpu_buffer *vpu_buf; +u32 fb_stride = inst->dst_fmt.plane_fmt[0 ].bytesperline; +u32 luma_size = fb_stride * inst->dst_fmt.height; +u32 chroma_size = (fb_stride /2 ) * (inst->dst_fmt.height /2 ); +struct frame_buffer disp_buffer = {0 }; +struct dec_seq_info *seq_info = &inst->codec_info->dec_info.seq_info; +int consumed_num =wave6_vpu_get_consumed_fb_num (inst); +int ret; + +v4l2_m2m_for_each_dst_buf (inst->v4l2_fh.m2m_ctx, v4l2_m2m_buf) { + dst_buf = &v4l2_m2m_buf->vb; + vpu_buf =wave6_to_vpu_buf (dst_buf); + +if (vpu_buf->consumed) +continue ; + +if (consumed_num >=WAVE6_MAX_FBS ) +break ; + +if (inst->dst_fmt.num_planes ==1 ) { + disp_buffer.buf_y =wave6_get_dma_addr (dst_buf,0 ); + disp_buffer.buf_cb = disp_buffer.buf_y + luma_size; + disp_buffer.buf_cr = disp_buffer.buf_cb + chroma_size; + }else if (inst->dst_fmt.num_planes ==2 ) { + disp_buffer.buf_y =wave6_get_dma_addr (dst_buf,0 ); + disp_buffer.buf_cb =wave6_get_dma_addr (dst_buf,1 ); + disp_buffer.buf_cr = disp_buffer.buf_cb + chroma_size; + }else if (inst->dst_fmt.num_planes ==3 ) { + disp_buffer.buf_y =wave6_get_dma_addr (dst_buf,0 ); + disp_buffer.buf_cb =wave6_get_dma_addr (dst_buf,1 ); + disp_buffer.buf_cr =wave6_get_dma_addr (dst_buf,2 ); + } + disp_buffer.width = inst->src_fmt.width; + disp_buffer.height = inst->src_fmt.height; + disp_buffer.stride = fb_stride; + disp_buffer.map_type =LINEAR_FRAME_MAP ; + disp_buffer.luma_bit_depth = seq_info->luma_bit_depth; + disp_buffer.chroma_bit_depth = seq_info->chroma_bit_depth; + disp_buffer.c_fmt_idc = seq_info->c_fmt_idc; + + ret =wave6_vpu_dec_register_display_buffer_ex (inst, disp_buffer); +if (ret) { +dev_err (inst->dev->dev,"fail register display buffer %d" , ret); +break ; + } + + vpu_buf->consumed = true; + consumed_num++; + } + +if (!inst->fbc_buf_registered) { +unsigned int fb_num = seq_info->min_frame_buffer_count; +unsigned int fb_stride =ALIGN (inst->src_fmt.width,W6_FBC_BUF_ALIGNMENT ); +unsigned int fb_height =ALIGN (inst->src_fmt.height,W6_FBC_BUF_ALIGNMENT ); + + ret =wave6_vpu_dec_register_frame_buffer_ex (inst, fb_num, fb_stride, + fb_height,COMPRESSED_FRAME_MAP ); +if (ret) +dev_err (inst->dev->dev,"register frame buffer fail %d\n" , ret); +else + inst->fbc_buf_registered = fb_num; + } +} + +static enum v4l2_quantization to_v4l2_quantization (u32 video_full_range_flag) +{ +switch (video_full_range_flag) { +case 0 : +return V4L2_QUANTIZATION_LIM_RANGE ; +case 1 : +return V4L2_QUANTIZATION_FULL_RANGE ; +default : +return V4L2_QUANTIZATION_DEFAULT ; + } +} + +static enum v4l2_colorspace to_v4l2_colorspace (u32 colour_primaries) +{ +switch (colour_primaries) { +case 1 : +return V4L2_COLORSPACE_REC709 ; +case 4 : +return V4L2_COLORSPACE_470_SYSTEM_M ; +case 5 : +return V4L2_COLORSPACE_470_SYSTEM_BG ; +case 6 : +return V4L2_COLORSPACE_SMPTE170M ; +case 7 : +return V4L2_COLORSPACE_SMPTE240M ; +case 9 : +return V4L2_COLORSPACE_BT2020 ; +case 11 : +return V4L2_COLORSPACE_DCI_P3 ; +default : +return V4L2_COLORSPACE_DEFAULT ; + } +} + +static enum v4l2_xfer_func to_v4l2_xfer_func (u32 transfer_characteristics) +{ +switch (transfer_characteristics) { +case 1 : +return V4L2_XFER_FUNC_709 ; +case 6 : +return V4L2_XFER_FUNC_709 ; +case 7 : +return V4L2_XFER_FUNC_SMPTE240M ; +case 8 : +return V4L2_XFER_FUNC_NONE ; +case 13 : +return V4L2_XFER_FUNC_SRGB ; +case 14 : +return V4L2_XFER_FUNC_709 ; +case 16 : +return V4L2_XFER_FUNC_SMPTE2084 ; +default : +return V4L2_XFER_FUNC_DEFAULT ; + } +} + +static enum v4l2_ycbcr_encoding to_v4l2_ycbcr_encoding (u32 matrix_coeffs) +{ +switch (matrix_coeffs) { +case 1 : +return V4L2_YCBCR_ENC_709 ; +case 5 : +return V4L2_YCBCR_ENC_601 ; +case 6 : +return V4L2_YCBCR_ENC_601 ; +case 7 : +return V4L2_YCBCR_ENC_SMPTE240M ; +case 9 : +return V4L2_YCBCR_ENC_BT2020 ; +case 10 : +return V4L2_YCBCR_ENC_BT2020_CONST_LUM ; +default : +return V4L2_YCBCR_ENC_DEFAULT ; + } +} + +static void wave6_update_color_info (struct vpu_instance *inst, +struct dec_seq_info *seq_info) +{ +struct color_param *color = &seq_info->color; + +if (!color->video_signal_type_present) + goto set_default_all; + + inst->quantization =to_v4l2_quantization (color->color_range); + +if (!color->color_description_present) + goto set_default_color; + + inst->colorspace =to_v4l2_colorspace (color->color_primaries); + inst->xfer_func =to_v4l2_xfer_func (color->transfer_characteristics); + inst->ycbcr_enc =to_v4l2_ycbcr_encoding (color->matrix_coefficients); + +return ; + +set_default_all: + inst->quantization =V4L2_QUANTIZATION_DEFAULT ; +set_default_color: + inst->colorspace =V4L2_COLORSPACE_DEFAULT ; + inst->ycbcr_enc =V4L2_YCBCR_ENC_DEFAULT ; + inst->xfer_func =V4L2_XFER_FUNC_DEFAULT ; +} + +static enum v4l2_mpeg_video_hevc_profile to_v4l2_hevc_profile (u32 profile) +{ +switch (profile) { +case HEVC_PROFILE_MAIN : +return V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN ; +case HEVC_PROFILE_STILLPICTURE : +return V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE ; +default : +return V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN ; + } +} + +static enum v4l2_mpeg_video_h264_profile to_v4l2_h264_profile (u32 profile) +{ +switch (profile) { +case H264_PROFILE_BP : +return V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE ; +case H264_PROFILE_MP : +return V4L2_MPEG_VIDEO_H264_PROFILE_MAIN ; +case H264_PROFILE_EXTENDED : +return V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED ; +case H264_PROFILE_HP : +return V4L2_MPEG_VIDEO_H264_PROFILE_HIGH ; +default : +return V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE ; + } +} + +static void wave6_update_v4l2_ctrls (struct vpu_instance *inst, +struct dec_seq_info *info) +{ +struct v4l2_ctrl *ctrl; +u32 min_disp_cnt; + + min_disp_cnt = info->frame_buf_delay +1 ; + ctrl =v4l2_ctrl_find (&inst->v4l2_ctrl_hdl, +V4L2_CID_MIN_BUFFERS_FOR_CAPTURE ); +if (ctrl) +v4l2_ctrl_s_ctrl (ctrl, min_disp_cnt); + +if (inst->src_fmt.pixelformat ==V4L2_PIX_FMT_HEVC ) { + ctrl =v4l2_ctrl_find (&inst->v4l2_ctrl_hdl, +V4L2_CID_MPEG_VIDEO_HEVC_PROFILE ); +if (ctrl) +v4l2_ctrl_s_ctrl (ctrl,to_v4l2_hevc_profile (info->profile)); + }else if (inst->src_fmt.pixelformat ==V4L2_PIX_FMT_H264 ) { + ctrl =v4l2_ctrl_find (&inst->v4l2_ctrl_hdl, +V4L2_CID_MPEG_VIDEO_H264_PROFILE ); +if (ctrl) +v4l2_ctrl_s_ctrl (ctrl,to_v4l2_h264_profile (info->profile)); + } +} + +static int wave6_vpu_dec_start_decode (struct vpu_instance *inst) +{ +struct dec_param pic_param; +int ret; +u32 fail_res =0 ; + +memset (&pic_param,0 ,sizeof (struct dec_param )); + +wave6_handle_bitstream_buffer (inst); +wave6_vpu_dec_handle_dst_buffer (inst); + + ret =wave6_vpu_dec_start_one_frame (inst, &pic_param, &fail_res); +if (ret) { +struct vb2_v4l2_buffer *src_buf =NULL ; + +dev_err (inst->dev->dev,"[%d] %s: fail %d\n" , inst->id, __func__, ret); +wave6_vpu_set_instance_state (inst,VPU_INST_STATE_STOP ); + + src_buf =v4l2_m2m_src_buf_remove (inst->v4l2_fh.m2m_ctx); +if (src_buf) { +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); + inst->sequence++; + inst->processed_buf_num++; + inst->error_buf_num++; + } + } + +return ret; +} + +static void wave6_handle_decoded_frame (struct vpu_instance *inst, +struct dec_output_info *info) +{ +struct vb2_v4l2_buffer *src_buf; +struct vb2_v4l2_buffer *dst_buf; +struct vpu_buffer *vpu_buf; +enum vb2_buffer_state state; + + state = info->decoding_success ?VB2_BUF_STATE_DONE :VB2_BUF_STATE_ERROR ; + + src_buf =v4l2_m2m_next_src_buf (inst->v4l2_fh.m2m_ctx); +if (!src_buf) { +dev_err (inst->dev->dev,"[%d] decoder can't find src buffer\n" , inst->id); +return ; + } + + vpu_buf =wave6_to_vpu_buf (src_buf); +if (!vpu_buf || !vpu_buf->consumed) { +dev_err (inst->dev->dev,"[%d] src buffer is not consumed\n" , inst->id); +return ; + } + + dst_buf =wave6_get_dst_buf_by_addr (inst, info->frame_decoded_addr); +if (dst_buf) { +struct vpu_buffer *dst_vpu_buf =wave6_to_vpu_buf (dst_buf); + +if (wave6_to_vpu_buf (dst_buf)->used) { +dev_warn (inst->dev->dev,"[%d] duplication frame buffer\n" , inst->id); + inst->sequence++; + } +v4l2_m2m_buf_copy_metadata (src_buf, dst_buf); + dst_vpu_buf->used = true; +if (state ==VB2_BUF_STATE_ERROR ) + dst_vpu_buf->error = true; + dst_vpu_buf->ts_input = vpu_buf->ts_input; + dst_vpu_buf->ts_start = vpu_buf->ts_start; + dst_vpu_buf->ts_finish =ktime_get_raw (); + dst_vpu_buf->hw_time =wave6_vpu_cycle_to_ns (inst->dev, info->cycle.frame_cycle); + } + +v4l2_m2m_src_buf_remove_by_buf (inst->v4l2_fh.m2m_ctx, src_buf); +if (state ==VB2_BUF_STATE_ERROR ) { +dev_dbg (inst->dev->dev,"[%d] error frame %d\n" , inst->id, inst->sequence); + inst->error_buf_num++; + } +v4l2_m2m_buf_done (src_buf, state); + inst->processed_buf_num++; +} + +static void wave6_handle_skipped_frame (struct vpu_instance *inst) +{ +struct vb2_v4l2_buffer *src_buf; +struct vpu_buffer *vpu_buf; + + src_buf =v4l2_m2m_next_src_buf (inst->v4l2_fh.m2m_ctx); +if (!src_buf) +return ; + + vpu_buf =wave6_to_vpu_buf (src_buf); +if (!vpu_buf || !vpu_buf->consumed) +return ; + +dev_dbg (inst->dev->dev,"[%d] skip frame %d\n" , inst->id, inst->sequence); + + inst->sequence++; + inst->processed_buf_num++; + inst->error_buf_num++; +v4l2_m2m_src_buf_remove_by_buf (inst->v4l2_fh.m2m_ctx, src_buf); +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); +} + +static void wave6_handle_display_frame (struct vpu_instance *inst, +dma_addr_t addr,enum vb2_buffer_state state) +{ +struct vb2_v4l2_buffer *dst_buf; +struct vpu_buffer *vpu_buf; + + dst_buf =wave6_get_dst_buf_by_addr (inst, addr); +if (!dst_buf) +return ; + + vpu_buf =wave6_to_vpu_buf (dst_buf); +if (!vpu_buf->used) { +dev_dbg (inst->dev->dev,"[%d] recycle display buffer\n" , inst->id); + vpu_buf->consumed = false; +return ; + } + +if (inst->dst_fmt.num_planes ==1 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , + inst->dst_fmt.plane_fmt[0 ].sizeimage); + }else if (inst->dst_fmt.num_planes ==2 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , + inst->dst_fmt.plane_fmt[0 ].sizeimage); +vb2_set_plane_payload (&dst_buf->vb2_buf,1 , + inst->dst_fmt.plane_fmt[1 ].sizeimage); + }else if (inst->dst_fmt.num_planes ==3 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , + inst->dst_fmt.plane_fmt[0 ].sizeimage); +vb2_set_plane_payload (&dst_buf->vb2_buf,1 , + inst->dst_fmt.plane_fmt[1 ].sizeimage); +vb2_set_plane_payload (&dst_buf->vb2_buf,2 , + inst->dst_fmt.plane_fmt[2 ].sizeimage); + } + + vpu_buf->ts_output =ktime_get_raw (); +wave6_vpu_handle_performance (inst, vpu_buf); + +if (vpu_buf->error) + state =VB2_BUF_STATE_ERROR ; + dst_buf->sequence = inst->sequence++; + dst_buf->field =V4L2_FIELD_NONE ; +if (state ==VB2_BUF_STATE_ERROR ) +dev_dbg (inst->dev->dev,"[%d] discard frame %d\n" , inst->id, dst_buf->sequence); +v4l2_m2m_dst_buf_remove_by_buf (inst->v4l2_fh.m2m_ctx, dst_buf); +v4l2_m2m_buf_done (dst_buf, state); +} + +static void wave6_handle_display_frames (struct vpu_instance *inst, +struct dec_output_info *info) +{ +int i; + +for (i =0 ; i < info->disp_frame_num; i++) +wave6_handle_display_frame (inst, + info->disp_frame_addr[i], +VB2_BUF_STATE_DONE ); +} + +static void wave6_handle_discard_frames (struct vpu_instance *inst, +struct dec_output_info *info) +{ +int i; + +for (i =0 ; i < info->release_disp_frame_num; i++) +wave6_handle_display_frame (inst, + info->release_disp_frame_addr[i], +VB2_BUF_STATE_ERROR ); +} + +static void wave6_handle_last_frame (struct vpu_instance *inst, +struct vb2_v4l2_buffer *dst_buf) +{ +if (!dst_buf) { + dst_buf =v4l2_m2m_dst_buf_remove (inst->v4l2_fh.m2m_ctx); +if (!dst_buf) { + inst->next_buf_last = true; +return ; + } + } + +if (inst->dst_fmt.num_planes ==1 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 ,0 ); + }else if (inst->dst_fmt.num_planes ==2 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 ,0 ); +vb2_set_plane_payload (&dst_buf->vb2_buf,1 ,0 ); + }else if (inst->dst_fmt.num_planes ==3 ) { +vb2_set_plane_payload (&dst_buf->vb2_buf,0 ,0 ); +vb2_set_plane_payload (&dst_buf->vb2_buf,1 ,0 ); +vb2_set_plane_payload (&dst_buf->vb2_buf,2 ,0 ); + } + + dst_buf->flags |=V4L2_BUF_FLAG_LAST ; + dst_buf->field =V4L2_FIELD_NONE ; +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_DONE ); + +if (inst->state !=VPU_INST_STATE_INIT_SEQ ) { +dev_dbg (inst->dev->dev,"[%d] eos\n" , inst->id); + inst->eos = true; +v4l2_m2m_set_src_buffered (inst->v4l2_fh.m2m_ctx, false); + } +} + +static void wave6_vpu_dec_retry_one_frame (struct vpu_instance *inst) +{ +struct vb2_v4l2_buffer *src_buf; +struct vpu_buffer *vpu_buf; + + src_buf =v4l2_m2m_next_src_buf (inst->v4l2_fh.m2m_ctx); +if (!src_buf) +return ; + + vpu_buf =wave6_to_vpu_buf (src_buf); + vpu_buf->consumed = false; +} + +static void wave6_vpu_dec_handle_source_change (struct vpu_instance *inst) +{ +static const struct v4l2_event vpu_event_src_ch = { + .type =V4L2_EVENT_SOURCE_CHANGE , + .u.src_change.changes =V4L2_EVENT_SRC_CH_RESOLUTION , + }; +struct dec_seq_info *info = &inst->codec_info->dec_info.seq_info; + +dev_dbg (inst->dev->dev,"pic size %dx%d profile %d, min_fb_cnt : %d | min_disp_cnt : %d\n" , + info->pic_width, info->pic_height, + info->profile, info->min_frame_buffer_count, info->frame_buf_delay); + +wave6_vpu_dec_retry_one_frame (inst); +wave6_vpu_dec_reset_frame_buffer_info (inst); + inst->fbc_buf_registered =0 ; + +wave6_vpu_set_instance_state (inst,VPU_INST_STATE_INIT_SEQ ); + + inst->crop.left = info->pic_crop_rect.left; + inst->crop.top = info->pic_crop_rect.top; + inst->crop.width = info->pic_crop_rect.right - inst->crop.left; + inst->crop.height = info->pic_crop_rect.bottom - inst->crop.top; + +wave6_update_v4l2_ctrls (inst, info); +wave6_update_color_info (inst, info); +wave6_update_pix_fmt (&inst->src_fmt, info->pic_width, info->pic_height); +wave6_update_pix_fmt_cap (&inst->dst_fmt, + info->pic_width, info->pic_height, + true); + +trace_wave6_vpu_source_change (inst, info); + +v4l2_event_queue_fh (&inst->v4l2_fh, &vpu_event_src_ch); +} + +static void wave6_vpu_dec_handle_decoding_warn_error (struct vpu_instance *inst, +struct dec_output_info *info) +{ +if (info->warn_info) +dev_dbg (inst->dev->dev,"[%d] decoding %d warning 0x%x\n" , + inst->id, inst->processed_buf_num, info->warn_info); + +if (info->error_reason) +dev_dbg (inst->dev->dev,"[%d] decoding %d error 0x%x\n" , + inst->id, inst->processed_buf_num, info->error_reason); +} + +static void wave6_vpu_dec_finish_decode (struct vpu_instance *inst,bool error) +{ +struct dec_output_info info; +struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; +int ret; + +memset (&info,0 ,sizeof (info)); + + ret =wave6_vpu_dec_get_output_info (inst, &info); +if (ret) + goto finish_decode; + +trace_wave6_vpu_dec_done (inst, &info); + +dev_dbg (inst->dev->dev,"dec %d dis %d noti_flag %d stream_end %d\n" , + info.frame_decoded, info.frame_display, + info.notification_flags, info.stream_end); + +if (info.notification_flags &DEC_NOTI_FLAG_NO_FB ) { +wave6_vpu_dec_retry_one_frame (inst); + goto finish_decode; + } + +if (info.notification_flags &DEC_NOTI_FLAG_SEQ_CHANGE ) { +v4l2_m2m_mark_stopped (m2m_ctx); + +if (info.frame_display) +wave6_handle_display_frames (inst, &info); + +if (info.release_disp_frame_num) +wave6_handle_discard_frames (inst, &info); + +wave6_vpu_dec_handle_source_change (inst); + +wave6_handle_last_frame (inst,NULL ); + + goto finish_decode; + } + +wave6_vpu_dec_handle_decoding_warn_error (inst, &info); + +if (info.frame_decoded) +wave6_handle_decoded_frame (inst, &info); +else +wave6_handle_skipped_frame (inst); + +if (info.frame_display) +wave6_handle_display_frames (inst, &info); + +if (info.release_disp_frame_num) +wave6_handle_discard_frames (inst, &info); + +if (info.stream_end && !inst->eos) +wave6_handle_last_frame (inst,NULL ); + +finish_decode: +wave6_vpu_finish_job (inst); +} + +static int wave6_vpu_dec_querycap (struct file *file,void *fh,struct v4l2_capability *cap) +{ +strscpy (cap->driver,VPU_DEC_DRV_NAME ,sizeof (cap->driver)); +strscpy (cap->card,VPU_DEC_DRV_NAME ,sizeof (cap->card)); +strscpy (cap->bus_info,"platform:" VPU_DEC_DRV_NAME ,sizeof (cap->bus_info)); + +return 0 ; +} + +static int wave6_vpu_dec_enum_framesizes (struct file *f,void *fh,struct v4l2_frmsizeenum *fsize) +{ +const struct vpu_format *vpu_fmt; + +if (fsize->index) +return -EINVAL ; + + vpu_fmt =wave6_find_vpu_fmt (fsize->pixel_format,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) { + vpu_fmt =wave6_find_vpu_fmt (fsize->pixel_format,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + } + + fsize->type =V4L2_FRMSIZE_TYPE_CONTINUOUS ; + fsize->stepwise.min_width = vpu_fmt->min_width; + fsize->stepwise.max_width = vpu_fmt->max_width; + fsize->stepwise.step_width =W6_DEC_PIC_SIZE_STEP ; + fsize->stepwise.min_height = vpu_fmt->min_height; + fsize->stepwise.max_height = vpu_fmt->max_height; + fsize->stepwise.step_height =W6_DEC_PIC_SIZE_STEP ; + +return 0 ; +} + +static int wave6_vpu_dec_enum_fmt_cap (struct file *file,void *fh,struct v4l2_fmtdesc *f) +{ +const struct vpu_format *vpu_fmt; + + vpu_fmt =wave6_find_vpu_fmt_by_idx (f->index,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + + f->pixelformat = vpu_fmt->v4l2_pix_fmt; + f->flags =0 ; + +return 0 ; +} + +static int wave6_vpu_dec_try_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (file); +struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; +const struct vpu_format *vpu_fmt; +int width, height; + +dev_dbg (inst->dev->dev,"%s: 4cc %d w %d h %d plane %d colorspace %d\n" , + __func__, pix_mp->pixelformat, pix_mp->width, pix_mp->height, + pix_mp->num_planes, pix_mp->colorspace); + +if (!V4L2_TYPE_IS_CAPTURE (f->type)) +return -EINVAL ; + + vpu_fmt =wave6_find_vpu_fmt (pix_mp->pixelformat,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) { + width = inst->dst_fmt.width; + height = inst->dst_fmt.height; + pix_mp->pixelformat = inst->dst_fmt.pixelformat; + pix_mp->num_planes = inst->dst_fmt.num_planes; + }else { + width =clamp (pix_mp->width, + vpu_fmt->min_width, +round_up (inst->src_fmt.width,W6_DEC_BUF_ALIGNMENT )); + height =clamp (pix_mp->height, + vpu_fmt->min_height, inst->src_fmt.height); + pix_mp->pixelformat = vpu_fmt->v4l2_pix_fmt; + pix_mp->num_planes = vpu_fmt->num_planes; + } + +if (inst->state >=VPU_INST_STATE_INIT_SEQ ) { + width = inst->dst_fmt.width; + height = inst->dst_fmt.height; + } + +wave6_update_pix_fmt_cap (pix_mp, width, height, false); + pix_mp->colorspace = inst->colorspace; + pix_mp->ycbcr_enc = inst->ycbcr_enc; + pix_mp->quantization = inst->quantization; + pix_mp->xfer_func = inst->xfer_func; + +return 0 ; +} + +static int wave6_vpu_dec_s_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (file); +struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; +const struct vpu_format *vpu_fmt; +int i, ret; + +dev_dbg (inst->dev->dev,"%s: 4cc %d w %d h %d plane %d colorspace %d\n" , + __func__, pix_mp->pixelformat, pix_mp->width, pix_mp->height, + pix_mp->num_planes, pix_mp->colorspace); + + ret =wave6_vpu_dec_try_fmt_cap (file, fh, f); +if (ret) +return ret; + + vpu_fmt =wave6_find_vpu_fmt (pix_mp->pixelformat,VPU_FMT_TYPE_RAW ); +if (!vpu_fmt) +return -EINVAL ; + + inst->dst_fmt.width = pix_mp->width; + inst->dst_fmt.height = pix_mp->height; + inst->dst_fmt.pixelformat = pix_mp->pixelformat; + inst->dst_fmt.field = pix_mp->field; + inst->dst_fmt.flags = pix_mp->flags; + inst->dst_fmt.num_planes = pix_mp->num_planes; +for (i =0 ; i < inst->dst_fmt.num_planes; i++) { + inst->dst_fmt.plane_fmt[i].bytesperline = pix_mp->plane_fmt[i].bytesperline; + inst->dst_fmt.plane_fmt[i].sizeimage = pix_mp->plane_fmt[i].sizeimage; + } + + inst->cbcr_interleave = !!(vpu_fmt->flags &VPU_FMT_FLAG_CBCR_INTERLEAVED ); + inst->nv21 = !!(vpu_fmt->flags &VPU_FMT_FLAG_CRCB_ORDER ); + +return 0 ; +} + +static int wave6_vpu_dec_g_fmt_cap (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (file); +struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; +int i; + + pix_mp->width = inst->dst_fmt.width; + pix_mp->height = inst->dst_fmt.height; + pix_mp->pixelformat = inst->dst_fmt.pixelformat; + pix_mp->field = inst->dst_fmt.field; + pix_mp->flags = inst->dst_fmt.flags; + pix_mp->num_planes = inst->dst_fmt.num_planes; +for (i =0 ; i < pix_mp->num_planes; i++) { + pix_mp->plane_fmt[i].bytesperline = inst->dst_fmt.plane_fmt[i].bytesperline; + pix_mp->plane_fmt[i].sizeimage = inst->dst_fmt.plane_fmt[i].sizeimage; + } + + pix_mp->colorspace = inst->colorspace; + pix_mp->ycbcr_enc = inst->ycbcr_enc; + pix_mp->quantization = inst->quantization; + pix_mp->xfer_func = inst->xfer_func; + +return 0 ; +} + +static int wave6_vpu_dec_enum_fmt_out (struct file *file,void *fh,struct v4l2_fmtdesc *f) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (file); +const struct vpu_format *vpu_fmt; + +dev_dbg (inst->dev->dev,"%s: index %d\n" , __func__, f->index); + + vpu_fmt =wave6_find_vpu_fmt_by_idx (f->index,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) +return -EINVAL ; + + f->pixelformat = vpu_fmt->v4l2_pix_fmt; + f->flags =0 ; + f->flags =V4L2_FMT_FLAG_DYN_RESOLUTION |V4L2_FMT_FLAG_COMPRESSED ; + +return 0 ; +} + +static int wave6_vpu_dec_try_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (file); +struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; +const struct vpu_format *vpu_fmt; +int width, height; + +dev_dbg (inst->dev->dev,"%s: 4cc %d w %d h %d plane %d colorspace %d\n" , + __func__, pix_mp->pixelformat, pix_mp->width, pix_mp->height, + pix_mp->num_planes, pix_mp->colorspace); + +if (!V4L2_TYPE_IS_OUTPUT (f->type)) +return -EINVAL ; + + vpu_fmt =wave6_find_vpu_fmt (pix_mp->pixelformat,VPU_FMT_TYPE_CODEC ); +if (!vpu_fmt) { + width = inst->src_fmt.width; + height = inst->src_fmt.height; + pix_mp->pixelformat = inst->src_fmt.pixelformat; + pix_mp->num_planes = inst->src_fmt.num_planes; + }else { + width = pix_mp->width; + height = pix_mp->height; + pix_mp->pixelformat = vpu_fmt->v4l2_pix_fmt; + pix_mp->num_planes = vpu_fmt->num_planes; + } + +wave6_update_pix_fmt (pix_mp, width, height); + pix_mp->colorspace = inst->colorspace; + pix_mp->ycbcr_enc = inst->ycbcr_enc; + pix_mp->quantization = inst->quantization; + pix_mp->xfer_func = inst->xfer_func; + +return 0 ; +} + +static int wave6_vpu_dec_s_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (file); +struct v4l2_pix_format_mplane in_pix_mp = f->fmt.pix_mp; +struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; +int i, ret; + +dev_dbg (inst->dev->dev,"%s: 4cc %d w %d h %d plane %d colorspace %d\n" , + __func__, pix_mp->pixelformat, pix_mp->width, pix_mp->height, + pix_mp->num_planes, pix_mp->colorspace); + + ret =wave6_vpu_dec_try_fmt_out (file, fh, f); +if (ret) +return ret; + + pix_mp->colorspace = in_pix_mp.colorspace; + pix_mp->ycbcr_enc = in_pix_mp.ycbcr_enc; + pix_mp->quantization = in_pix_mp.quantization; + pix_mp->xfer_func = in_pix_mp.xfer_func; + + inst->src_fmt.width = pix_mp->width; + inst->src_fmt.height = pix_mp->height; + inst->src_fmt.pixelformat = pix_mp->pixelformat; + inst->src_fmt.field = pix_mp->field; + inst->src_fmt.flags = pix_mp->flags; + inst->src_fmt.num_planes = pix_mp->num_planes; +for (i =0 ; i < inst->src_fmt.num_planes; i++) { + inst->src_fmt.plane_fmt[i].bytesperline = pix_mp->plane_fmt[i].bytesperline; + inst->src_fmt.plane_fmt[i].sizeimage = pix_mp->plane_fmt[i].sizeimage; + } + + inst->colorspace = pix_mp->colorspace; + inst->ycbcr_enc = pix_mp->ycbcr_enc; + inst->quantization = pix_mp->quantization; + inst->xfer_func = pix_mp->xfer_func; + +wave6_update_pix_fmt_cap (&inst->dst_fmt, + pix_mp->width, pix_mp->height, + true); + +return 0 ; +} + +static int wave6_vpu_dec_g_fmt_out (struct file *file,void *fh,struct v4l2_format *f) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (file); +struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; +int i; + + pix_mp->width = inst->src_fmt.width; + pix_mp->height = inst->src_fmt.height; + pix_mp->pixelformat = inst->src_fmt.pixelformat; + pix_mp->field = inst->src_fmt.field; + pix_mp->flags = inst->src_fmt.flags; + pix_mp->num_planes = inst->src_fmt.num_planes; +for (i =0 ; i < pix_mp->num_planes; i++) { + pix_mp->plane_fmt[i].bytesperline = inst->src_fmt.plane_fmt[i].bytesperline; + pix_mp->plane_fmt[i].sizeimage = inst->src_fmt.plane_fmt[i].sizeimage; + } + + pix_mp->colorspace = inst->colorspace; + pix_mp->ycbcr_enc = inst->ycbcr_enc; + pix_mp->quantization = inst->quantization; + pix_mp->xfer_func = inst->xfer_func; + +return 0 ; +} + +static int wave6_vpu_dec_g_selection (struct file *file,void *fh,struct v4l2_selection *s) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (file); + +dev_dbg (inst->dev->dev,"%s: type %d target %d\n" , + __func__, s->type, s->target); + +if (s->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE && + s->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) +return -EINVAL ; + +switch (s->target) { +case V4L2_SEL_TGT_COMPOSE_BOUNDS : + s->r.left =0 ; + s->r.top =0 ; + s->r.width = inst->dst_fmt.width; + s->r.height = inst->dst_fmt.height; +break ; +case V4L2_SEL_TGT_COMPOSE_PADDED : +case V4L2_SEL_TGT_COMPOSE : + s->r.left =0 ; + s->r.top =0 ; +if (inst->scaler_info.enable) { + s->r.width = inst->scaler_info.width; + s->r.height = inst->scaler_info.height; + }else if (inst->crop.width && inst->crop.height) { + s->r = inst->crop; + }else { + s->r.width = inst->src_fmt.width; + s->r.height = inst->src_fmt.height; + } +break ; +case V4L2_SEL_TGT_CROP : +case V4L2_SEL_TGT_CROP_DEFAULT : +case V4L2_SEL_TGT_CROP_BOUNDS : +case V4L2_SEL_TGT_COMPOSE_DEFAULT : + s->r.left =0 ; + s->r.top =0 ; + s->r.width = inst->src_fmt.width; + s->r.height = inst->src_fmt.height; +if (inst->crop.width && inst->crop.height) + s->r = inst->crop; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int wave6_vpu_dec_s_selection (struct file *file,void *fh,struct v4l2_selection *s) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (file); +int step =4 ; +int scale_width, scale_height; +int min_scale_width, min_scale_height; + +if (s->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE && + s->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) +return -EINVAL ; + +if (s->target !=V4L2_SEL_TGT_COMPOSE ) +return -EINVAL ; + +if (!(s->flags & (V4L2_SEL_FLAG_GE |V4L2_SEL_FLAG_LE ))) + s->flags |=V4L2_SEL_FLAG_LE ; + + scale_width =clamp (s->r.width,W6_MIN_DEC_PIC_WIDTH , +round_up (inst->src_fmt.width,W6_DEC_BUF_ALIGNMENT )); + scale_height =clamp (s->r.height,W6_MIN_DEC_PIC_HEIGHT , + inst->src_fmt.height); +if (s->flags &V4L2_SEL_FLAG_GE ) { + scale_width =round_up (scale_width, step); + scale_height =round_up (scale_height, step); + } +if (s->flags &V4L2_SEL_FLAG_LE ) { + scale_width =round_down (scale_width, step); + scale_height =round_down (scale_height, step); + } + +if (scale_width < inst->src_fmt.width || + scale_height < inst->src_fmt.height) + inst->scaler_info.enable = true; + +if (inst->scaler_info.enable) { + min_scale_width =ALIGN ((inst->src_fmt.width /8 ), step); + min_scale_height =ALIGN ((inst->src_fmt.height /8 ), step); + +if (scale_width <W6_MIN_DEC_PIC_WIDTH ) + scale_width =W6_MIN_DEC_PIC_WIDTH ; +if (scale_width < min_scale_width) + scale_width = min_scale_width; +if (scale_height <W6_MIN_DEC_PIC_HEIGHT ) + scale_height =W6_MIN_DEC_PIC_HEIGHT ; +if (scale_height < min_scale_height) + scale_height = min_scale_height; + + inst->scaler_info.width = scale_width; + inst->scaler_info.height = scale_height; + } + + s->r.left =0 ; + s->r.top =0 ; + s->r.width = scale_width; + s->r.height = scale_height; + +return 0 ; +} + +static int wave6_vpu_dec_decoder_cmd (struct file *file,void *fh,struct v4l2_decoder_cmd *dc) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (file); +int ret; + +dev_dbg (inst->dev->dev,"%s: cmd %d\n" , __func__, dc->cmd); + + ret =v4l2_m2m_ioctl_try_decoder_cmd (file, fh, dc); +if (ret) +return ret; + +switch (dc->cmd) { +case V4L2_DEC_CMD_STOP : +v4l2_m2m_set_src_buffered (inst->v4l2_fh.m2m_ctx, true); +v4l2_m2m_try_schedule (inst->v4l2_fh.m2m_ctx); +break ; +case V4L2_DEC_CMD_START : +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct v4l2_ioctl_ops wave6_vpu_dec_ioctl_ops = { + .vidioc_querycap = wave6_vpu_dec_querycap, + .vidioc_enum_framesizes = wave6_vpu_dec_enum_framesizes, + + .vidioc_enum_fmt_vid_cap = wave6_vpu_dec_enum_fmt_cap, + .vidioc_s_fmt_vid_cap_mplane = wave6_vpu_dec_s_fmt_cap, + .vidioc_g_fmt_vid_cap_mplane = wave6_vpu_dec_g_fmt_cap, + .vidioc_try_fmt_vid_cap_mplane = wave6_vpu_dec_try_fmt_cap, + + .vidioc_enum_fmt_vid_out = wave6_vpu_dec_enum_fmt_out, + .vidioc_s_fmt_vid_out_mplane = wave6_vpu_dec_s_fmt_out, + .vidioc_g_fmt_vid_out_mplane = wave6_vpu_dec_g_fmt_out, + .vidioc_try_fmt_vid_out_mplane = wave6_vpu_dec_try_fmt_out, + + .vidioc_g_selection = wave6_vpu_dec_g_selection, + .vidioc_s_selection = wave6_vpu_dec_s_selection, + + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, + .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, + .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, + .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, + .vidioc_streamon = v4l2_m2m_ioctl_streamon, + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, + + .vidioc_try_decoder_cmd = v4l2_m2m_ioctl_try_decoder_cmd, + .vidioc_decoder_cmd = wave6_vpu_dec_decoder_cmd, + + .vidioc_subscribe_event = wave6_vpu_subscribe_event, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, +}; + +static int wave6_vpu_dec_s_ctrl (struct v4l2_ctrl *ctrl) +{ +struct vpu_instance *inst =wave6_ctrl_to_vpu_inst (ctrl); + +trace_wave6_vpu_s_ctrl (inst, ctrl); + +dev_dbg (inst->dev->dev,"%s: name %s value %d\n" , + __func__, ctrl->name, ctrl->val); + +switch (ctrl->id) { +case V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE : + inst->disp_mode = ctrl->val; +break ; +case V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY : +case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE : +case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE : +case V4L2_CID_MPEG_VIDEO_H264_PROFILE : +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct v4l2_ctrl_ops wave6_vpu_dec_ctrl_ops = { + .s_ctrl = wave6_vpu_dec_s_ctrl, +}; + +static void wave6_set_dec_openparam (struct dec_open_param *open_param, +struct vpu_instance *inst) +{ + open_param->inst_buffer.temp_base = inst->dev->temp_vbuf.daddr; + open_param->inst_buffer.temp_size = inst->dev->temp_vbuf.size; + open_param->disp_mode = inst->disp_mode; +} + +static int wave6_vpu_dec_create_instance (struct vpu_instance *inst) +{ +int ret; +struct dec_open_param open_param; + +memset (&open_param,0 ,sizeof (struct dec_open_param )); + +wave6_vpu_record_performance_timestamps (inst); + +wave6_vpu_core_activate (inst->dev); + ret =pm_runtime_resume_and_get (inst->dev->dev); +if (ret) { +dev_err (inst->dev->dev,"runtime_resume failed %d\n" , ret); +return ret; + } + + inst->std =wave6_to_codec_std (inst->type, inst->src_fmt.pixelformat); +if (inst->std ==STD_UNKNOWN ) { +dev_err (inst->dev->dev,"unsupported pixelformat: %.4s\n" , + (char *)&inst->src_fmt.pixelformat); + ret = -EINVAL ; + goto error_pm; + } + +wave6_set_dec_openparam (&open_param, inst); + + ret =wave6_vpu_dec_open (inst, &open_param); +if (ret) { +dev_err (inst->dev->dev,"failed create instance : %d\n" , ret); + goto error_pm; + } + +dev_dbg (inst->dev->dev,"[%d] decoder\n" , inst->id); + + scoped_guard(spinlock, &inst->dev->inst_lock) +list_add_tail (&inst->list, &inst->dev->instances); +wave6_vpu_create_dbgfs_file (inst); +wave6_vpu_set_instance_state (inst,VPU_INST_STATE_OPEN ); + +return 0 ; + +error_pm: +pm_runtime_put_sync (inst->dev->dev); + +return ret; +} + +static int wave6_vpu_dec_prepare_fb (struct vpu_instance *inst) +{ +int ret; +unsigned int i; +unsigned int fb_num; +unsigned int mv_num; +unsigned int fb_stride; +unsigned int fb_height; +unsigned int luma_size; +unsigned int chroma_size; +struct dec_seq_info *seq_info = &inst->codec_info->dec_info.seq_info; + + fb_num = seq_info->min_frame_buffer_count; + mv_num = seq_info->req_mv_buffer_count; + + fb_stride =ALIGN (inst->src_fmt.width,W6_FBC_BUF_ALIGNMENT ); + fb_height =ALIGN (inst->src_fmt.height,W6_FBC_BUF_ALIGNMENT ); + + luma_size = fb_stride * fb_height; + chroma_size =ALIGN (fb_stride /2 ,W6_FBC_BUF_ALIGNMENT ) * fb_height; + +for (i =0 ; i < fb_num; i++) { +struct frame_buffer *frame = &inst->frame_buf[i]; +struct vpu_buf *vframe = &inst->frame_vbuf[i]; + + vframe->size = luma_size + chroma_size; + ret =wave6_vdi_alloc_dma (inst->dev->dev, vframe); +if (ret) { +dev_err (inst->dev->dev,"alloc FBC buffer fail : %zu\n" , + vframe->size); + goto error; + } + + frame->buf_y = vframe->daddr; + frame->buf_cb = vframe->daddr + luma_size; + frame->buf_cr = (dma_addr_t)-1 ; + frame->width = inst->src_fmt.width; + frame->stride = fb_stride; + frame->height = fb_height; + frame->map_type =COMPRESSED_FRAME_MAP ; + } + + ret =wave6_allocate_aux_buffer (inst,AUX_BUF_FBC_Y_TBL , fb_num); +if (ret) + goto error; + + ret =wave6_allocate_aux_buffer (inst,AUX_BUF_FBC_C_TBL , fb_num); +if (ret) + goto error; + + ret =wave6_allocate_aux_buffer (inst,AUX_BUF_MV_COL , mv_num); +if (ret) + goto error; + +wave6_vpu_set_instance_state (inst,VPU_INST_STATE_PIC_RUN ); + +wave6_vpu_record_performance_timestamps (inst); + +return 0 ; + +error: +wave6_vpu_dec_release_fb (inst); + +return ret; +} + +static int wave6_vpu_dec_queue_setup (struct vb2_queue *q,unsigned int *num_buffers, +unsigned int *num_planes,unsigned int sizes[], +struct device *alloc_devs[]) +{ +struct vpu_instance *inst =vb2_get_drv_priv (q); +struct v4l2_pix_format_mplane inst_format = + (V4L2_TYPE_IS_OUTPUT (q->type)) ? inst->src_fmt : inst->dst_fmt; +unsigned int i; + +dev_dbg (inst->dev->dev,"%s: num_buffers %d num_planes %d type %d\n" , + __func__, *num_buffers, *num_planes, q->type); + +if (*num_planes) { +if (inst_format.num_planes != *num_planes) +return -EINVAL ; + +for (i =0 ; i < *num_planes; i++) { +if (sizes[i] < inst_format.plane_fmt[i].sizeimage) +return -EINVAL ; + } + }else { + *num_planes = inst_format.num_planes; +for (i =0 ; i < *num_planes; i++) { + sizes[i] = inst_format.plane_fmt[i].sizeimage; +dev_dbg (inst->dev->dev,"size[%d] : %d\n" , i, sizes[i]); + } + +if (V4L2_TYPE_IS_CAPTURE (q->type)) { +struct v4l2_ctrl *ctrl; +unsigned int min_disp_cnt =0 ; + + ctrl =v4l2_ctrl_find (&inst->v4l2_ctrl_hdl, +V4L2_CID_MIN_BUFFERS_FOR_CAPTURE ); +if (ctrl) + min_disp_cnt =v4l2_ctrl_g_ctrl (ctrl); + + *num_buffers =max (*num_buffers, min_disp_cnt); + +if (*num_buffers >WAVE6_MAX_FBS ) + *num_buffers = min_disp_cnt; + } + } + +if (V4L2_TYPE_IS_OUTPUT (q->type) && inst->state ==VPU_INST_STATE_SEEK ) +wave6_vpu_dec_destroy_instance (inst); + +return 0 ; +} + +static int wave6_vpu_dec_seek_header (struct vpu_instance *inst) +{ +struct dec_seq_info seq_info; +int ret; + +memset (&seq_info,0 ,sizeof (struct dec_seq_info )); + + ret =wave6_vpu_dec_issue_seq_init (inst); +if (ret) { +dev_err (inst->dev->dev,"failed wave6_vpu_dec_issue_seq_init %d\n" , ret); +return ret; + } + + ret =wave6_vpu_wait_interrupt (inst,W6_VPU_TIMEOUT ); +if (ret) { +dev_err (inst->dev->dev,"failed to call vpu_wait_interrupt()\n" ); +return ret; + } + + ret =wave6_vpu_dec_complete_seq_init (inst, &seq_info); +if (ret) { +dev_err (inst->dev->dev,"vpu_dec_complete_seq_init: %d, reason : 0x%x\n" , + ret, seq_info.err_reason); +if ((seq_info.err_reason &WAVE6_SYSERR_NOT_SUPPORT ) || + (seq_info.err_reason &WAVE6_SYSERR_NOT_SUPPORT_PROFILE )) { + ret = -EINVAL ; + }else if ((seq_info.err_reason &HEVC_ETCERR_INIT_SEQ_SPS_NOT_FOUND ) || + (seq_info.err_reason &AVC_ETCERR_INIT_SEQ_SPS_NOT_FOUND )) { +wave6_handle_skipped_frame (inst); + ret =0 ; + } + }else { +wave6_vpu_dec_handle_source_change (inst); + inst->v4l2_fh.m2m_ctx->ignore_cap_streaming = false; +v4l2_m2m_set_dst_buffered (inst->v4l2_fh.m2m_ctx, false); +if (vb2_is_streaming (v4l2_m2m_get_dst_vq (inst->v4l2_fh.m2m_ctx))) +wave6_handle_last_frame (inst,NULL ); + } + +return ret; +} + +static int wave6_vpu_dec_prepare_decode (struct vpu_instance *inst) +{ +int ret =0 ; + +wave6_handle_bitstream_buffer (inst); +if (inst->state ==VPU_INST_STATE_OPEN ) { + ret =wave6_vpu_dec_seek_header (inst); +if (ret) { +vb2_queue_error (v4l2_m2m_get_src_vq (inst->v4l2_fh.m2m_ctx)); +vb2_queue_error (v4l2_m2m_get_dst_vq (inst->v4l2_fh.m2m_ctx)); + } + } + +return ret; +} + +static void wave6_vpu_dec_buf_queue_src (struct vb2_buffer *vb) +{ +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); +struct vpu_buffer *vpu_buf =wave6_to_vpu_buf (vbuf); +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); + +dev_dbg (inst->dev->dev,"type %4d index %4d size[0] %4ld size[1] : %4ld | size[2] : %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); + + vbuf->sequence = inst->queued_src_buf_num++; + vpu_buf->ts_input =ktime_get_raw (); + +v4l2_m2m_buf_queue (inst->v4l2_fh.m2m_ctx, vbuf); +} + +static void wave6_vpu_dec_buf_queue_dst (struct vb2_buffer *vb) +{ +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); + +dev_dbg (inst->dev->dev,"type %4d index %4d size[0] %4ld size[1] : %4ld | size[2] : %4ld\n" , + vb->type, vb->index,vb2_plane_size (&vbuf->vb2_buf,0 ), +vb2_plane_size (&vbuf->vb2_buf,1 ),vb2_plane_size (&vbuf->vb2_buf,2 )); + + inst->queued_dst_buf_num++; +if (inst->next_buf_last) { +wave6_handle_last_frame (inst, vbuf); + inst->next_buf_last = false; + }else { +v4l2_m2m_buf_queue (inst->v4l2_fh.m2m_ctx, vbuf); + } +} + +static void wave6_vpu_dec_buf_queue (struct vb2_buffer *vb) +{ +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); +struct vpu_buffer *vpu_buf =wave6_to_vpu_buf (vbuf); + + vpu_buf->consumed = false; + vpu_buf->used = false; + vpu_buf->error = false; +if (V4L2_TYPE_IS_OUTPUT (vb->type)) +wave6_vpu_dec_buf_queue_src (vb); +else +wave6_vpu_dec_buf_queue_dst (vb); +} + +static int wave6_vpu_dec_start_streaming (struct vb2_queue *q,unsigned int count) +{ +struct vpu_instance *inst =vb2_get_drv_priv (q); +struct v4l2_pix_format_mplane *fmt; +int ret =0 ; + +trace_wave6_vpu_start_streaming (inst,V4L2_TYPE_IS_OUTPUT (q->type)); + +if (V4L2_TYPE_IS_OUTPUT (q->type)) { + fmt = &inst->src_fmt; +if (inst->state ==VPU_INST_STATE_NONE ) { + ret =wave6_vpu_dec_create_instance (inst); +if (!ret) { + inst->v4l2_fh.m2m_ctx->ignore_cap_streaming = true; +v4l2_m2m_set_dst_buffered (inst->v4l2_fh.m2m_ctx, true); + } + } +if (inst->state ==VPU_INST_STATE_SEEK ) +wave6_vpu_set_instance_state (inst, inst->state_in_seek); + }else { + fmt = &inst->dst_fmt; +if (inst->state ==VPU_INST_STATE_INIT_SEQ ) { + ret =wave6_vpu_dec_prepare_fb (inst); +if (ret) + goto exit; + } + } + +exit: +if (ret) +wave6_vpu_return_buffers (inst, q->type,VB2_BUF_STATE_QUEUED ); + +dev_dbg (inst->dev->dev,"[%d] %s %c%c%c%c %dx%d, %d buffers, ret = %d\n" , + inst->id,V4L2_TYPE_IS_OUTPUT (q->type) ?"output" :"capture" , + fmt->pixelformat, + fmt->pixelformat >>8 , + fmt->pixelformat >>16 , + fmt->pixelformat >>24 , + fmt->width, fmt->height,vb2_get_num_buffers (q), ret); + +return ret; +} + +static void wave6_vpu_dec_stop_streaming (struct vb2_queue *q) +{ +struct vpu_instance *inst =vb2_get_drv_priv (q); +struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; + +trace_wave6_vpu_stop_streaming (inst,V4L2_TYPE_IS_OUTPUT (q->type)); + +dev_dbg (inst->dev->dev,"[%d] %s, input %d, decode %d error %d\n" , + inst->id,V4L2_TYPE_IS_OUTPUT (q->type) ?"output" :"capture" , + inst->queued_src_buf_num, inst->processed_buf_num, inst->error_buf_num); + +if (inst->state ==VPU_INST_STATE_NONE ) + goto exit; + +if (V4L2_TYPE_IS_OUTPUT (q->type)) { +wave6_vpu_reset_performance (inst); + inst->queued_src_buf_num =0 ; + inst->processed_buf_num =0 ; + inst->error_buf_num =0 ; + inst->state_in_seek = inst->state; +v4l2_m2m_set_src_buffered (inst->v4l2_fh.m2m_ctx, false); +wave6_vpu_set_instance_state (inst,VPU_INST_STATE_SEEK ); + inst->sequence =0 ; + }else { +if (v4l2_m2m_has_stopped (m2m_ctx)) +v4l2_m2m_clear_state (m2m_ctx); + + inst->eos = false; + inst->queued_dst_buf_num =0 ; + inst->sequence =0 ; +wave6_vpu_dec_flush_instance (inst); + } + +exit: +wave6_vpu_return_buffers (inst, q->type,VB2_BUF_STATE_ERROR ); +} + +static int wave6_vpu_dec_buf_init (struct vb2_buffer *vb) +{ +struct vpu_instance *inst =vb2_get_drv_priv (vb->vb2_queue); +struct dec_seq_info *seq_info; +int i; + +if (V4L2_TYPE_IS_OUTPUT (vb->type)) +return 0 ; + +if (inst->state ==VPU_INST_STATE_NONE ) +return 0 ; + + seq_info = &inst->codec_info->dec_info.seq_info; +if (seq_info->c_fmt_idc !=C_FMT_IDC_YUV400 ) +return 0 ; + +for (i =0 ; i < inst->dst_fmt.num_planes; i++) { +void *vaddr =vb2_plane_vaddr (vb, i); + +if (vaddr) +memset (vaddr,0x80 ,vb2_plane_size (vb, i)); + } + +return 0 ; +} + +static const struct vb2_ops wave6_vpu_dec_vb2_ops = { + .queue_setup = wave6_vpu_dec_queue_setup, + .buf_queue = wave6_vpu_dec_buf_queue, + .start_streaming = wave6_vpu_dec_start_streaming, + .stop_streaming = wave6_vpu_dec_stop_streaming, + .buf_init = wave6_vpu_dec_buf_init, +}; + +static void wave6_set_default_format (struct v4l2_pix_format_mplane *src_fmt, +struct v4l2_pix_format_mplane *dst_fmt) +{ +const struct vpu_format *vpu_fmt; + + vpu_fmt =wave6_find_vpu_fmt_by_idx (0 ,VPU_FMT_TYPE_CODEC ); +if (vpu_fmt) { + src_fmt->pixelformat = vpu_fmt->v4l2_pix_fmt; + src_fmt->num_planes = vpu_fmt->num_planes; +wave6_update_pix_fmt (src_fmt, +W6_DEF_DEC_PIC_WIDTH ,W6_DEF_DEC_PIC_HEIGHT ); + } + + vpu_fmt =wave6_find_vpu_fmt_by_idx (0 ,VPU_FMT_TYPE_RAW ); +if (vpu_fmt) { + dst_fmt->pixelformat = vpu_fmt->v4l2_pix_fmt; + dst_fmt->num_planes = vpu_fmt->num_planes; +wave6_update_pix_fmt_cap (dst_fmt, +W6_DEF_DEC_PIC_WIDTH ,W6_DEF_DEC_PIC_HEIGHT , + true); + } +} + +static int wave6_vpu_dec_queue_init (void *priv,struct vb2_queue *src_vq,struct vb2_queue *dst_vq) +{ +struct vpu_instance *inst = priv; +int ret; + + src_vq->type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ; + src_vq->io_modes =VB2_MMAP |VB2_DMABUF ; + src_vq->mem_ops = &vb2_dma_contig_memops; + src_vq->ops = &wave6_vpu_dec_vb2_ops; + src_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; + src_vq->buf_struct_size =sizeof (struct vpu_buffer ); + src_vq->drv_priv = inst; + src_vq->lock = &inst->dev->dev_lock; + src_vq->dev = inst->dev->v4l2_dev.dev; + ret =vb2_queue_init (src_vq); +if (ret) +return ret; + + dst_vq->type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ; + dst_vq->io_modes =VB2_MMAP |VB2_DMABUF ; + dst_vq->mem_ops = &vb2_dma_contig_memops; + dst_vq->ops = &wave6_vpu_dec_vb2_ops; + dst_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; + dst_vq->buf_struct_size =sizeof (struct vpu_buffer ); + dst_vq->drv_priv = inst; + dst_vq->lock = &inst->dev->dev_lock; + dst_vq->dev = inst->dev->v4l2_dev.dev; + ret =vb2_queue_init (dst_vq); +if (ret) +return ret; + +return 0 ; +} + +static const struct vpu_instance_ops wave6_vpu_dec_inst_ops = { + .prepare_process = wave6_vpu_dec_prepare_decode, + .start_process = wave6_vpu_dec_start_decode, + .finish_process = wave6_vpu_dec_finish_decode, +}; + +static int wave6_vpu_open_dec (struct file *filp) +{ +struct video_device *vdev =video_devdata (filp); +struct vpu_core_device *core =video_drvdata (filp); +struct vpu_instance *inst =NULL ; +int ret; + + inst =kzalloc_obj (*inst); +if (!inst) +return -ENOMEM ; + +init_completion (&inst->irq_done); + inst->dev = core; + inst->type =VPU_INST_TYPE_DEC ; + inst->ops = &wave6_vpu_dec_inst_ops; + +v4l2_fh_init (&inst->v4l2_fh, vdev); + filp->private_data = &inst->v4l2_fh; +v4l2_fh_add (&inst->v4l2_fh, filp); + + inst->v4l2_fh.m2m_ctx = +v4l2_m2m_ctx_init (core->m2m_dev, inst, wave6_vpu_dec_queue_init); +if (IS_ERR (inst->v4l2_fh.m2m_ctx)) { + ret =PTR_ERR (inst->v4l2_fh.m2m_ctx); + goto free_inst; + } + +v4l2_ctrl_handler_init (&inst->v4l2_ctrl_hdl,10 ); +v4l2_ctrl_new_std (&inst->v4l2_ctrl_hdl, &wave6_vpu_dec_ctrl_ops, +V4L2_CID_MIN_BUFFERS_FOR_CAPTURE ,1 ,32 ,1 ,1 ); +v4l2_ctrl_new_std (&inst->v4l2_ctrl_hdl, &wave6_vpu_dec_ctrl_ops, +V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY , +0 ,0 ,1 ,0 ); +v4l2_ctrl_new_std (&inst->v4l2_ctrl_hdl, &wave6_vpu_dec_ctrl_ops, +V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE , +0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std_menu (&inst->v4l2_ctrl_hdl, &wave6_vpu_dec_ctrl_ops, +V4L2_CID_MPEG_VIDEO_HEVC_PROFILE , +V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE , +0 ,V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN ); +v4l2_ctrl_new_std_menu (&inst->v4l2_ctrl_hdl, &wave6_vpu_dec_ctrl_ops, +V4L2_CID_MPEG_VIDEO_H264_PROFILE , +V4L2_MPEG_VIDEO_H264_PROFILE_HIGH ,0 , +V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE ); + +if (inst->v4l2_ctrl_hdl.error) { + ret = -ENODEV ; + goto err_m2m_release; + } + + inst->v4l2_fh.ctrl_handler = &inst->v4l2_ctrl_hdl; +v4l2_ctrl_handler_setup (&inst->v4l2_ctrl_hdl); + +wave6_set_default_format (&inst->src_fmt, &inst->dst_fmt); + inst->colorspace =V4L2_COLORSPACE_DEFAULT ; + inst->ycbcr_enc =V4L2_YCBCR_ENC_DEFAULT ; + inst->quantization =V4L2_QUANTIZATION_DEFAULT ; + inst->xfer_func =V4L2_XFER_FUNC_DEFAULT ; + +return 0 ; + +err_m2m_release: +v4l2_m2m_ctx_release (inst->v4l2_fh.m2m_ctx); +free_inst: +kfree (inst); + +return ret; +} + +static int wave6_vpu_dec_release (struct file *filp) +{ +struct vpu_instance *inst =wave6_file_to_vpu_inst (filp); + +v4l2_m2m_ctx_release (inst->v4l2_fh.m2m_ctx); + +if (inst->state !=VPU_INST_STATE_NONE ) +wave6_vpu_dec_destroy_instance (inst); + +v4l2_ctrl_handler_free (&inst->v4l2_ctrl_hdl); +v4l2_fh_del (&inst->v4l2_fh, filp); +v4l2_fh_exit (&inst->v4l2_fh); +kfree (inst); + +return 0 ; +} + +static const struct v4l2_file_operations wave6_vpu_dec_fops = { + .owner =THIS_MODULE , + .open = wave6_vpu_open_dec, + .release = wave6_vpu_dec_release, + .unlocked_ioctl = video_ioctl2, + .poll = v4l2_m2m_fop_poll, + .mmap = v4l2_m2m_fop_mmap, +}; + +int wave6_vpu_dec_register_device (struct vpu_core_device *core) +{ +struct video_device *vdev_dec; +int ret; + + vdev_dec =devm_kzalloc (core->v4l2_dev.dev,sizeof (*vdev_dec),GFP_KERNEL ); +if (!vdev_dec) +return -ENOMEM ; + + core->video_dev_dec = vdev_dec; + +strscpy (vdev_dec->name,VPU_DEC_DEV_NAME ,sizeof (vdev_dec->name)); + vdev_dec->fops = &wave6_vpu_dec_fops; + vdev_dec->ioctl_ops = &wave6_vpu_dec_ioctl_ops; + vdev_dec->release = video_device_release_empty; + vdev_dec->v4l2_dev = &core->v4l2_dev; + vdev_dec->vfl_dir =VFL_DIR_M2M ; + vdev_dec->device_caps =V4L2_CAP_VIDEO_M2M_MPLANE |V4L2_CAP_STREAMING ; + vdev_dec->lock = &core->dev_lock; +video_set_drvdata (vdev_dec, core); + + ret =video_register_device (vdev_dec,VFL_TYPE_VIDEO ,-1 ); +if (ret) +return ret; + +return 0 ; +} + +void wave6_vpu_dec_unregister_device (struct vpu_core_device *core) +{ +video_unregister_device (core->video_dev_dec); +}
drivers/media/platform/chips-media/wave6/wave6-vpu-enc.c new file +2691 -0
1,133 lines not on this page · raw message
drivers/media/platform/chips-media/wave6/wave6-vpu-v4l2.c new file +507 -0
507 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.31.1
Part of the diff is not shown here. View the raw message.
RFC PATCH v5 5/9 media: chips-media: wave6: Add Wave6 core driver
In reply to Nas ChungAdd the core driver for the Chips&Media Wave6 video codec IP.
The hardware contains one control register region and four interface register regions for a shared video processing engine. This driver handles the interface register regions, each with its own MMIO range and interrupt, while relying on the control driver for firmware loading and shared resource management.
It configures the V4L2 mem2mem devices and communicates with the Wave6 hardware to perform video processing tasks.
--- .../chips-media/wave6/wave6-vpu-core.c | 397 ++++++++++++++++++ .../chips-media/wave6/wave6-vpu-core.h | 123 ++++++ 2 files changed, 520 insertions(+) create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-core.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-core.h
drivers/media/platform/chips-media/wave6/wave6-vpu-core.c new file +397 -0
@@ -0,0 +1,397 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +/* +* Wave6 series multi-standard codec IP - wave6 core driver +* +* Copyright (C) 2025 CHIPS&MEDIA INC +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/clk.h> +#include <linux/firmware.h> +#include <linux/interrupt.h> +#include <linux/pm_runtime.h> +#include <linux/debugfs.h> +#include <linux/iopoll.h> +#include "wave6-vpu-core.h" +#include "wave6-regdefine.h" +#include "wave6-vpuconfig.h" +#include "wave6-hw.h" +#include "wave6-vpu-dbg.h" + +#define CREATE_TRACE_POINTS +#include "wave6-trace.h" + +#define WAVE6_VPU_DEBUGFS_DIR "wave6" + +static irqreturn_t wave6_vpu_core_irq (int irq,void *dev_id) +{ +struct vpu_core_device *core = dev_id; +struct vpu_irq irq_info; + +if (!vpu_read_reg (core,W6_VPU_VPU_INT_STS )) +return IRQ_NONE ; + + irq_info.status =vpu_read_reg (core,W6_VPU_VINT_REASON ); + irq_info.inst_idc =vpu_read_reg (core,W6_RET_INT_INSTANCE_INFO ); + +vpu_write_reg (core,W6_RET_INT_INSTANCE_INFO ,INT_INSTANCE_INFO_CLEAR ); +vpu_write_reg (core,W6_VPU_VINT_REASON_CLEAR , irq_info.status); +vpu_write_reg (core,W6_VPU_VINT_CLEAR ,VINT_CLEAR ); + +trace_wave6_vpu_irq (core, irq_info.status, irq_info.inst_idc); + +if (irq_info.status &BIT (W6_INT_BIT_REQ_WORK_BUF )) { +if (core->vpu) + core->vpu->req_work_buffer (core->vpu, core); + +return IRQ_HANDLED ; + } + +kfifo_in (&core->irq_fifo, &irq_info,sizeof (struct vpu_irq )); + +return IRQ_WAKE_THREAD ; +} + +static struct vpu_instance *wave6_vpu_core_get_instance (struct vpu_core_device *core, +u32 inst_idc) +{ +struct vpu_instance *inst; + +guard (spinlock)(&core->inst_lock); + +list_for_each_entry (inst, &core->instances, list) { +if (BIT (inst->id) & inst_idc) +return inst; + } + +return NULL ; +} + +static irqreturn_t wave6_vpu_core_irq_thread (int irq,void *dev_id) +{ +struct vpu_core_device *core = dev_id; +struct vpu_instance *inst; +struct vpu_irq irq_info; + +while (kfifo_len (&core->irq_fifo)) { +bool error = false; + +if (!kfifo_out (&core->irq_fifo, &irq_info,sizeof (struct vpu_irq ))) +break ; + + inst =wave6_vpu_core_get_instance (core, irq_info.inst_idc); +if (!inst) +break ; + +if ((irq_info.status &BIT (W6_INT_BIT_INIT_SEQ )) || + (irq_info.status &BIT (W6_INT_BIT_ENC_SET_PARAM ))) { +complete (&inst->irq_done); +continue ; + } + +if (irq_info.status &BIT (W6_INT_BIT_BSBUF_ERROR )) + error = true; + +if (inst->ops && inst->ops->finish_process) + inst->ops->finish_process (inst, error); + } + +return IRQ_HANDLED ; +} + +static void wave6_vpu_core_check_state (struct vpu_core_device *core) +{ +u32 val; +int ret; + +guard (mutex)(&core->hw_lock); + + ret =read_poll_timeout (vpu_read_reg, val, val !=0 , +W6_VPU_POLL_DELAY_US ,W6_VPU_POLL_TIMEOUT , + false, core,W6_VPU_VCPU_CUR_PC ); +if (ret) +return ; + +wave6_vpu_enable_interrupt (core); + ret =wave6_vpu_get_version (core); +if (ret) { +dev_err (core->dev,"wave6_vpu_get_version fail\n" ); +return ; + } + +dev_dbg (core->dev,"product 0x%x, fw_ver %d.%d.%d(r%d), hw_ver 0x%x\n" , + core->attr.product_code, +FW_VERSION_MAJOR (core->attr.fw_version), +FW_VERSION_MINOR (core->attr.fw_version), +FW_VERSION_REL (core->attr.fw_version), + core->attr.fw_revision, + core->attr.hw_version); + +if (core->attr.fw_version < core->res->compatible_fw_version) +dev_err (core->dev,"fw version is too low (< v%d.%d.%d)\n" , +FW_VERSION_MAJOR (core->res->compatible_fw_version), +FW_VERSION_MINOR (core->res->compatible_fw_version), +FW_VERSION_REL (core->res->compatible_fw_version)); +} + +void wave6_vpu_core_activate (struct vpu_core_device *core) +{ + core->active = true; +} + +static void wave6_vpu_core_wait_activated (struct vpu_core_device *core) +{ +if (core->active) +wave6_vpu_core_check_state (core); +} + +static int wave6_vpu_core_probe (struct platform_device *pdev) +{ +struct vpu_core_device *core; +const struct wave6_vpu_core_resource *res; +int ret; +int irq; + + res =dev_get_platdata (&pdev->dev); +if (!res) { +dev_err (&pdev->dev,"There is no platform data\n" ); +return -ENODEV ; + } + + ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to set DMA mask: %d\n" , ret); +return ret; + } + + core =devm_kzalloc (&pdev->dev,sizeof (*core),GFP_KERNEL ); +if (!core) +return -ENOMEM ; + + ret =devm_mutex_init (&pdev->dev, &core->dev_lock); +if (ret) +return ret; + + ret =devm_mutex_init (&pdev->dev, &core->hw_lock); +if (ret) +return ret; + +spin_lock_init (&core->inst_lock); +INIT_LIST_HEAD (&core->instances); +dev_set_drvdata (&pdev->dev, core); + core->dev = &pdev->dev; + core->res = res; + +if (pdev->dev.parent->driver && pdev->dev.parent->driver->name && + !strcmp (pdev->dev.parent->driver->name,WAVE6_VPU_PLATFORM_DRIVER_NAME )) + core->vpu =dev_get_drvdata (pdev->dev.parent); + + core->reg_base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (core->reg_base)) +return PTR_ERR (core->reg_base); + + ret =devm_clk_bulk_get_all (&pdev->dev, &core->clks); +if (ret <0 ) +return dev_err_probe (&pdev->dev, ret,"failed to get clocks\n" ); + + core->num_clks = ret; + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + ret =devm_request_threaded_irq (&pdev->dev, irq, + wave6_vpu_core_irq, + wave6_vpu_core_irq_thread, +0 ,"vpu_irq" , core); +if (ret) { +dev_err (&pdev->dev,"failed to request IRQ: %d\n" , ret); +return ret; + } + + ret =v4l2_device_register (&pdev->dev, &core->v4l2_dev); +if (ret) { +dev_err (&pdev->dev,"failed to register v4l2_dev: %d\n" , ret); +return ret; + } + + ret =wave6_vpu_init_m2m_dev (core); +if (ret) + goto err_v4l2_unregister; + + ret =kfifo_alloc (&core->irq_fifo, +MAX_NUM_INSTANCE *sizeof (struct vpu_irq ), +GFP_KERNEL ); +if (ret) { +dev_err (&pdev->dev,"failed to allocate fifo\n" ); + goto err_m2m_dev_release; + } + + core->temp_vbuf.size =ALIGN (W6_TEMPBUF_SIZE ,4096 ); + ret =wave6_vdi_alloc_dma (core->dev, &core->temp_vbuf); +if (ret) { +dev_err (&pdev->dev,"failed to allocate temp_vbuf: %d\n" , ret); + goto err_kfifo_free; + } + + core->debugfs =debugfs_lookup (WAVE6_VPU_DEBUGFS_DIR ,NULL ); +if (IS_ERR_OR_NULL (core->debugfs)) + core->debugfs =debugfs_create_dir (WAVE6_VPU_DEBUGFS_DIR ,NULL ); + +pm_runtime_enable (&pdev->dev); + +if (core->res->codec_types &WAVE6_IS_DEC ) { + ret =wave6_vpu_dec_register_device (core); +if (ret) { +dev_err (&pdev->dev, +"failed to register video_dev_dec: %d\n" , ret); + goto err_temp_vbuf_free; + } + } +if (core->res->codec_types &WAVE6_IS_ENC ) { + ret =wave6_vpu_enc_register_device (core); +if (ret) { +dev_err (&pdev->dev, +"failed to register video_dev_enc: %d\n" , ret); + goto err_dec_unreg; + } + } + +dev_dbg (&pdev->dev,"Added wave6 driver with caps %s %s\n" , + core->res->codec_types &WAVE6_IS_ENC ?"'ENCODE'" :"" , + core->res->codec_types &WAVE6_IS_DEC ?"'DECODE'" :"" ); + +return 0 ; + +err_dec_unreg: +if (core->res->codec_types &WAVE6_IS_DEC ) +wave6_vpu_dec_unregister_device (core); +err_temp_vbuf_free: +wave6_vdi_free_dma (&core->temp_vbuf); +err_kfifo_free: +kfifo_free (&core->irq_fifo); +err_m2m_dev_release: +wave6_vpu_release_m2m_dev (core); +err_v4l2_unregister: +v4l2_device_unregister (&core->v4l2_dev); + +return ret; +} + +static void wave6_vpu_core_remove (struct platform_device *pdev) +{ +struct vpu_core_device *core =dev_get_drvdata (&pdev->dev); + +pm_runtime_disable (&pdev->dev); + +wave6_vpu_enc_unregister_device (core); +wave6_vpu_dec_unregister_device (core); +wave6_vdi_free_dma (&core->temp_vbuf); +kfifo_free (&core->irq_fifo); +wave6_vpu_release_m2m_dev (core); +v4l2_device_unregister (&core->v4l2_dev); +} + +static int __maybe_unused wave6_vpu_core_runtime_suspend (struct device *dev) +{ +struct vpu_core_device *core =dev_get_drvdata (dev); + +if (WARN_ON (!core)) +return -ENODEV ; + +/* +* Only call parent VPU put_vpu if the core has a parent and is active. +* - core->vpu: prevent access in core without parent VPU. +* - core->active: execute sleep only after m2m streaming is started. +*/ +if (core->vpu && core->active) + core->vpu->put_vpu (core->vpu, core); + +if (core->num_clks) +clk_bulk_disable_unprepare (core->num_clks, core->clks); + +return 0 ; +} + +static int __maybe_unused wave6_vpu_core_runtime_resume (struct device *dev) +{ +struct vpu_core_device *core =dev_get_drvdata (dev); +int ret =0 ; + +if (WARN_ON (!core)) +return -ENODEV ; + +if (core->num_clks) { + ret =clk_bulk_prepare_enable (core->num_clks, core->clks); +if (ret) { +dev_err (dev,"failed to enable clocks: %d\n" , ret); +return ret; + } + } + +/* +* Only call parent VPU get_vpu if the core has a parent and is active. +* - core->vpu: prevent access in core without parent VPU. +* - core->active: execute boot only after m2m streaming is started. +*/ +if (core->vpu && core->active) + ret = core->vpu->get_vpu (core->vpu, core); + +if (!ret) +wave6_vpu_core_wait_activated (core); +else if (core->num_clks) +clk_bulk_disable_unprepare (core->num_clks, core->clks); + +return ret; +} + +static int __maybe_unused wave6_vpu_core_suspend (struct device *dev) +{ +struct vpu_core_device *core =dev_get_drvdata (dev); +int ret; + +v4l2_m2m_suspend (core->m2m_dev); + + ret =pm_runtime_force_suspend (dev); +if (ret) +v4l2_m2m_resume (core->m2m_dev); + +return ret; +} + +static int __maybe_unused wave6_vpu_core_resume (struct device *dev) +{ +struct vpu_core_device *core =dev_get_drvdata (dev); +int ret; + + ret =pm_runtime_force_resume (dev); +if (ret) +return ret; + +v4l2_m2m_resume (core->m2m_dev); + +return 0 ; +} + +static const struct dev_pm_ops wave6_vpu_core_pm_ops = { + SET_RUNTIME_PM_OPS(wave6_vpu_core_runtime_suspend, + wave6_vpu_core_runtime_resume, NULL) +SET_SYSTEM_SLEEP_PM_OPS (wave6_vpu_core_suspend, + wave6_vpu_core_resume) +}; + +static struct platform_driver wave6_vpu_core_driver = { + .driver = { + .name =WAVE6_VPU_CORE_PLATFORM_DRIVER_NAME , + .pm = &wave6_vpu_core_pm_ops, + }, + .probe = wave6_vpu_core_probe, + .remove = wave6_vpu_core_remove, +}; + +module_platform_driver (wave6_vpu_core_driver); +MODULE_ALIAS ("platform:" WAVE6_VPU_CORE_PLATFORM_DRIVER_NAME ); +MODULE_DESCRIPTION ("chips&media Wave6 VPU CORE V4L2 driver" ); +MODULE_LICENSE ("Dual BSD/GPL" );
drivers/media/platform/chips-media/wave6/wave6-vpu-core.h new file +123 -0
123 lines not on this page · raw message
Signature · 1 line
2.31.1
RFC PATCH v5 6/9 media: chips-media: wave6: Improve debugging capabilities
In reply to Nas ChungAdd debugfs entries and trace events to provide detailed debugging information.
These enhancements help diagnose issues and improve debugging capabilities for the Wave6 core driver.
--- .../platform/chips-media/wave6/wave6-trace.h | 289 ++++++++++++++++++ .../chips-media/wave6/wave6-vpu-dbg.c | 225 ++++++++++++++ .../chips-media/wave6/wave6-vpu-dbg.h | 14 + 3 files changed, 528 insertions(+) create mode 100644 drivers/media/platform/chips-media/wave6/wave6-trace.h create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-dbg.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-dbg.h
drivers/media/platform/chips-media/wave6/wave6-trace.h new file +289 -0
@@ -0,0 +1,289 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ +/* +* Wave6 series multi-standard codec IP - wave6 driver tracer +* +* Copyright (C) 2025 CHIPS&MEDIA INC +*/ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM wave6 + +#if !defined(__WAVE6_TRACE_H__) || defined(TRACE_HEADER_MULTI_READ ) +#define __WAVE6_TRACE_H__ + +#include <linux/tracepoint.h> +#include <media/videobuf2-v4l2.h> + +DECLARE_EVENT_CLASS (wave6_vpu_register_access, + TP_PROTO(struct device *dev, u32 addr, u32 value), +TP_ARGS (dev, addr, value), + TP_STRUCT__entry(__string(name, dev_name(dev)) + __field(u32, addr) +__field (u32, value)), + TP_fast_assign(__assign_str(name); + __entry->addr = addr; + __entry->value = value;), +TP_printk ("%s:0x%03x 0x%08x" , +__get_str (name), __entry->addr, __entry->value)); + +DEFINE_EVENT (wave6_vpu_register_access, wave6_vpu_writel, + TP_PROTO(struct device *dev, u32 addr, u32 value), +TP_ARGS (dev, addr, value)); +DEFINE_EVENT (wave6_vpu_register_access, wave6_vpu_readl, + TP_PROTO(struct device *dev, u32 addr, u32 value), +TP_ARGS (dev, addr, value)); + +TRACE_EVENT (wave6_vpu_send_command, + TP_PROTO(struct vpu_core_device *core, u32 id, u32 std, u32 cmd), +TP_ARGS (core, id, std, cmd), + TP_STRUCT__entry(__string(name, dev_name(core->dev)) + __field(u32, id) + __field(u32, std) +__field (u32, cmd)), + TP_fast_assign(__assign_str(name); + __entry->id = id; + __entry->std = std; + __entry->cmd = cmd;), +TP_printk ("%s: inst id %d, std 0x%x, cmd 0x%x" , +__get_str (name), __entry->id, + __entry->std, __entry->cmd)); + +TRACE_EVENT (wave6_vpu_irq, + TP_PROTO(struct vpu_core_device *core, u32 irq, u32 idc), +TP_ARGS (core, irq, idc), + TP_STRUCT__entry(__string(name, dev_name(core->dev)) + __field(u32, irq) +__field (u32, idc)), + TP_fast_assign(__assign_str(name); + __entry->irq = irq; + __entry->idc = idc;), +TP_printk ("%s: irq 0x%x, idc 0x%x" , +__get_str (name), __entry->irq, __entry->idc)); + +TRACE_EVENT (wave6_vpu_set_state, + TP_PROTO(struct vpu_instance *inst, u32 state), +TP_ARGS (inst, state), + TP_STRUCT__entry(__string(name, dev_name(inst->dev->dev)) + __field(u32, id) + __string(cur_state, wave6_vpu_instance_state_name(inst->state)) +__string (nxt_state,wave6_vpu_instance_state_name (state))), + TP_fast_assign(__assign_str(name); + __entry->id = inst->id; + __assign_str(cur_state); + __assign_str(nxt_state);), +TP_printk ("%s: inst[%d] set state %s -> %s" , +__get_str (name), __entry->id, +__get_str (cur_state),__get_str (nxt_state))); + +DECLARE_EVENT_CLASS (wave6_vpu_inst_internal, + TP_PROTO(struct vpu_instance *inst, bool is_out), +TP_ARGS (inst, is_out), + TP_STRUCT__entry(__string(name, dev_name(inst->dev->dev)) + __field(u32, id) + __string(type, is_out ? "output" : "capture") + __field(u32, pixelformat) + __field(u32, width) + __field(u32, height) + __field(u32, buf_cnt_src) + __field(u32, buf_cnt_dst) + __field(u32, processed_cnt) +__field (u32, error_cnt)), + TP_fast_assign(__assign_str(name); + __entry->id = inst->id; + __assign_str(type); + __entry->pixelformat = is_out ? inst->src_fmt.pixelformat : + inst->dst_fmt.pixelformat; + __entry->width = is_out ? inst->src_fmt.width : + inst->dst_fmt.width; + __entry->height = is_out ? inst->src_fmt.height : + inst->dst_fmt.height; + __entry->buf_cnt_src = inst->queued_src_buf_num; + __entry->buf_cnt_dst = inst->queued_dst_buf_num; + __entry->processed_cnt = inst->processed_buf_num; + __entry->error_cnt = inst->error_buf_num;), +TP_printk ("%s: inst[%d] %s %c%c%c%c %dx%d, input %d, %d, process %d, error %d" , +__get_str (name), __entry->id,__get_str (type), + __entry->pixelformat, + __entry->pixelformat >>8 , + __entry->pixelformat >>16 , + __entry->pixelformat >>24 , + __entry->width, __entry->height, + __entry->buf_cnt_src, __entry->buf_cnt_dst, + __entry->processed_cnt, __entry->error_cnt)); + +DEFINE_EVENT (wave6_vpu_inst_internal, wave6_vpu_start_streaming, + TP_PROTO(struct vpu_instance *inst, bool is_out), +TP_ARGS (inst, is_out)); + +DEFINE_EVENT (wave6_vpu_inst_internal, wave6_vpu_stop_streaming, + TP_PROTO(struct vpu_instance *inst, bool is_out), +TP_ARGS (inst, is_out)); + +TRACE_EVENT (wave6_vpu_dec_pic, + TP_PROTO(struct vpu_instance *inst, u32 srcidx, u32 size), +TP_ARGS (inst, srcidx, size), + TP_STRUCT__entry(__string(name, dev_name(inst->dev->dev)) + __field(u32, id) + __field(u32, srcidx) + __field(u32, start) +__field (u32, size)), + TP_fast_assign(__assign_str(name); + __entry->id = inst->id; + __entry->srcidx = srcidx; + __entry->start = inst->codec_info->dec_info.stream_rd_ptr; + __entry->size = size;), +TP_printk ("%s: inst[%d] src[%2d] %8x, %d" , +__get_str (name), __entry->id, + __entry->srcidx, __entry->start, __entry->size)); + +TRACE_EVENT (wave6_vpu_source_change, + TP_PROTO(struct vpu_instance *inst, struct dec_seq_info *info), +TP_ARGS (inst, info), + TP_STRUCT__entry(__string(name, dev_name(inst->dev->dev)) + __field(u32, id) + __field(u32, width) + __field(u32, height) + __field(u32, profile) + __field(u32, level) + __field(u32, tier) + __field(u32, min_fb_cnt) + __field(u32, disp_delay) + __field(u32, quantization) + __field(u32, colorspace) + __field(u32, xfer_func) +__field (u32, ycbcr_enc)), + TP_fast_assign(__assign_str(name); + __entry->id = inst->id; + __entry->width = info->pic_width, + __entry->height = info->pic_height, + __entry->profile = info->profile, + __entry->level = info->level; + __entry->tier = info->tier; + __entry->min_fb_cnt = info->min_frame_buffer_count; + __entry->disp_delay = info->frame_buf_delay; + __entry->quantization = inst->quantization; + __entry->colorspace = inst->colorspace; + __entry->xfer_func = inst->xfer_func; + __entry->ycbcr_enc = inst->ycbcr_enc;), +TP_printk ("%s: inst[%d] %dx%d profile %d %d %d min_fb %d delay %d color %d %d %d %d" , +__get_str (name), __entry->id, + __entry->width, __entry->height, + __entry->profile, __entry->level, __entry->tier, + __entry->min_fb_cnt, __entry->disp_delay, + __entry->quantization, __entry->colorspace, + __entry->xfer_func, __entry->ycbcr_enc)); + +TRACE_EVENT (wave6_vpu_dec_done, + TP_PROTO(struct vpu_instance *inst, struct dec_output_info *info), +TP_ARGS (inst, info), + TP_STRUCT__entry(__string(name, dev_name(inst->dev->dev)) + __field(u32, id) + __field(u32, dec_flag) + __field(u32, dec_poc) + __field(u32, disp_flag) + __field(u32, disp_cnt) + __field(u32, rel_cnt) + __field(u32, src_ch) + __field(u32, eos) + __field(u32, error) +__field (u32, warn)), + TP_fast_assign(__assign_str(name); + __entry->id = inst->id; + __entry->dec_flag = info->frame_decoded; + __entry->dec_poc = info->decoded_poc; + __entry->disp_flag = info->frame_display; + __entry->disp_cnt = info->disp_frame_num; + __entry->rel_cnt = info->release_disp_frame_num; + __entry->src_ch = info->notification_flags & DEC_NOTI_FLAG_SEQ_CHANGE; + __entry->eos = info->stream_end; + __entry->error = info->error_reason; + __entry->warn = info->warn_info;), +TP_printk ("%s: inst[%d] dec %d %d disp %d(%d) rel %d src_ch %d eos %d error 0x%x 0x%x" , +__get_str (name), __entry->id, + __entry->dec_flag, __entry->dec_poc, + __entry->disp_flag, __entry->disp_cnt, + __entry->rel_cnt, + __entry->src_ch, __entry->eos, + __entry->error, __entry->warn)); + +TRACE_EVENT (wave6_vpu_enc_pic, + TP_PROTO(struct vpu_instance *inst, struct enc_param *param), +TP_ARGS (inst, param), + TP_STRUCT__entry(__string(name, dev_name(inst->dev->dev)) + __field(u32, id) + __field(u32, srcidx) + __field(u32, buf_y) + __field(u32, buf_cb) + __field(u32, buf_cr) + __field(u32, stride) + __field(u32, buf_strm) + __field(u32, size_strm) + __field(u32, force_type_enable) + __field(u32, force_type) +__field (u32, end_flag)), + TP_fast_assign(__assign_str(name); + __entry->id = inst->id; + __entry->srcidx = param->src_idx; + __entry->buf_y = param->source_frame->buf_y; + __entry->buf_cb = param->source_frame->buf_cb; + __entry->buf_cr = param->source_frame->buf_cr; + __entry->stride = param->source_frame->stride; + __entry->buf_strm = param->pic_stream_buffer_addr; + __entry->size_strm = param->pic_stream_buffer_size; + __entry->force_type_enable = param->force_pic; + __entry->force_type = param->force_pic_type; + __entry->end_flag = param->src_end;), +TP_printk ("%s: inst[%d] src[%2d] %8x %8x %8x(%d) dst %8x(%d) force type %d(%d) end %d" , +__get_str (name), __entry->id, __entry->srcidx, + __entry->buf_y, __entry->buf_cb, __entry->buf_cr, + __entry->stride, __entry->buf_strm, __entry->size_strm, + __entry->force_type_enable, __entry->force_type, + __entry->end_flag)); + +TRACE_EVENT (wave6_vpu_enc_done, + TP_PROTO(struct vpu_instance *inst, struct enc_output_info *info), +TP_ARGS (inst, info), + TP_STRUCT__entry(__string(name, dev_name(inst->dev->dev)) + __field(u32, id) + __field(u32, srcidx) + __field(u32, frmidx) + __field(u32, size) + __field(u32, type) +__field (u32, avg_qp)), + TP_fast_assign(__assign_str(name); + __entry->id = inst->id; + __entry->srcidx = info->enc_src_idx; + __entry->frmidx = info->recon_frame_index; + __entry->size = info->bitstream_size; + __entry->type = info->pic_type; + __entry->avg_qp = info->avg_ctu_qp;), +TP_printk ("%s: inst[%d] src %d, frame %d, size %d, type %d, qp %d, eos %d" , +__get_str (name), __entry->id, + __entry->srcidx, __entry->frmidx, + __entry->size, __entry->type, __entry->avg_qp, + __entry->frmidx ==RECON_IDX_FLAG_ENC_END )); + +TRACE_EVENT (wave6_vpu_s_ctrl, + TP_PROTO(struct vpu_instance *inst, struct v4l2_ctrl *ctrl), +TP_ARGS (inst, ctrl), + TP_STRUCT__entry(__string(name, dev_name(inst->dev->dev)) + __field(u32, id) + __string(ctrl_name, ctrl->name) +__field (u32, val)), + TP_fast_assign(__assign_str(name); + __entry->id = inst->id; + __assign_str(ctrl_name); + __entry->val = ctrl->val;), +TP_printk ("%s: inst[%d] %s = %d" , +__get_str (name), __entry->id, +__get_str (ctrl_name), __entry->val)); + +#endif /* __WAVE6_TRACE_H__ */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE wave6-trace + +/* This part must be outside protection */ +#include <trace/define_trace.h>
drivers/media/platform/chips-media/wave6/wave6-vpu-dbg.c new file +225 -0
225 lines not on this page · raw message
drivers/media/platform/chips-media/wave6/wave6-vpu-dbg.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ +/* +* Wave6 series multi-standard codec IP - debug interface +* +* Copyright (C) 2025 CHIPS&MEDIA INC +*/ + +#ifndef __WAVE6_VPU_DBG_H__ +#define __WAVE6_VPU_DBG_H__ + +int wave6_vpu_create_dbgfs_file (struct vpu_instance *inst); +void wave6_vpu_remove_dbgfs_file (struct vpu_instance *inst); + +#endif /* __WAVE6_VPU_DBG_H__ */
Signature · 1 line
2.31.1
RFC PATCH v5 7/9 media: chips-media: wave6: Add Wave6 thermal cooling device
In reply to Nas ChungAdd a thermal cooling device for the Wave6 VPU.
The device operates within the Linux thermal framework, adjusting the VPU performance state based on thermal conditions.
--- .../chips-media/wave6/wave6-vpu-thermal.c | 141 ++++++++++++++++++ .../chips-media/wave6/wave6-vpu-thermal.h | 26 ++++ 2 files changed, 167 insertions(+) create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.h
drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.c new file +141 -0
@@ -0,0 +1,141 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +/* +* Wave6 series multi-standard codec IP - wave6 thermal cooling interface +* +* Copyright (C) 2025 CHIPS&MEDIA INC +* +*/ + +#include <linux/pm_domain.h> +#include <linux/pm_opp.h> +#include <linux/units.h> +#include <linux/slab.h> +#include "wave6-vpu-thermal.h" + +static int wave6_vpu_thermal_cooling_update (struct vpu_thermal_cooling *thermal, +int state) +{ +unsigned long new_clock_rate; +int ret; + +if (state > thermal->thermal_max || !thermal->cooling) +return 0 ; + + new_clock_rate =DIV_ROUND_UP (thermal->freq_table[state],HZ_PER_KHZ ); +dev_dbg (thermal->dev,"receive cooling state: %d, new clock rate %ld\n" , + state, new_clock_rate); + + ret =dev_pm_genpd_set_performance_state (thermal->dev, new_clock_rate); +if (ret && !((ret == -ENODEV ) || (ret == -EOPNOTSUPP ))) { +dev_err (thermal->dev,"failed to set perf to %lu, ret = %d\n" , + new_clock_rate, ret); +return ret; + } + +return 0 ; +} + +static int wave6_vpu_cooling_get_max_state (struct thermal_cooling_device *cdev, +unsigned long *state) +{ +struct vpu_thermal_cooling *thermal = cdev->devdata; + + *state = thermal->thermal_max; + +return 0 ; +} + +static int wave6_vpu_cooling_get_cur_state (struct thermal_cooling_device *cdev, +unsigned long *state) +{ +struct vpu_thermal_cooling *thermal = cdev->devdata; + + *state = thermal->thermal_event; + +return 0 ; +} + +static int wave6_vpu_cooling_set_cur_state (struct thermal_cooling_device *cdev, +unsigned long state) +{ +struct vpu_thermal_cooling *thermal = cdev->devdata; + + thermal->thermal_event = state; +wave6_vpu_thermal_cooling_update (thermal, state); + +return 0 ; +} + +static struct thermal_cooling_device_ops wave6_cooling_ops = { + .get_max_state = wave6_vpu_cooling_get_max_state, + .get_cur_state = wave6_vpu_cooling_get_cur_state, + .set_cur_state = wave6_vpu_cooling_set_cur_state, +}; + +int wave6_vpu_cooling_init (struct vpu_thermal_cooling *thermal) +{ +int i; +int num_opps; +unsigned long freq; + +if (WARN_ON (!thermal || !thermal->dev)) +return -EINVAL ; + + num_opps =dev_pm_opp_get_opp_count (thermal->dev); +if (num_opps <0 ) { +dev_err (thermal->dev,"fail to get pm opp count, ret = %d\n" , num_opps); +return num_opps; + } +if (num_opps ==0 ) { +dev_err (thermal->dev,"no OPP entries found\n" ); +return -ENODEV ; + } + + thermal->freq_table =kcalloc (num_opps,sizeof (*thermal->freq_table),GFP_KERNEL ); +if (!thermal->freq_table) + goto error; + +for (i =0 , freq =ULONG_MAX ; i < num_opps; i++, freq--) { +struct dev_pm_opp *opp; + + opp =dev_pm_opp_find_freq_floor (thermal->dev, &freq); +if (IS_ERR (opp)) +break ; + +dev_pm_opp_put (opp); + +dev_dbg (thermal->dev,"[%d] = %lu\n" , i, freq); +if (freq <100 *HZ_PER_MHZ ) +break ; + + thermal->freq_table[i] = freq; + thermal->thermal_max = i; + } + +if (!thermal->thermal_max) + goto error; + + thermal->thermal_event =0 ; + thermal->cooling =thermal_of_cooling_device_register (thermal->dev->of_node, +dev_name (thermal->dev), + thermal, + &wave6_cooling_ops); +if (IS_ERR (thermal->cooling)) { +dev_err (thermal->dev,"register cooling device failed\n" ); + goto error; + } + +return 0 ; + +error: +wave6_vpu_cooling_remove (thermal); + +return -EINVAL ; +} + +void wave6_vpu_cooling_remove (struct vpu_thermal_cooling *thermal) +{ +thermal_cooling_device_unregister (thermal->cooling); +kfree (thermal->freq_table); + thermal->freq_table =NULL ; +}
drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ +/* +* Wave6 series multi-standard codec IP - wave6 thermal cooling interface +* +* Copyright (C) 2025 CHIPS&MEDIA INC +* +*/ + +#ifndef __WAVE6_VPU_THERMAL_H__ +#define __WAVE6_VPU_THERMAL_H__ + +#include <linux/thermal.h> + +struct vpu_thermal_cooling { +struct device *dev; +struct device_node *of_node; +int thermal_event; +int thermal_max; +struct thermal_cooling_device *cooling; +unsigned long *freq_table; +}; + +int wave6_vpu_cooling_init (struct vpu_thermal_cooling *thermal); +void wave6_vpu_cooling_remove (struct vpu_thermal_cooling *thermal); + +#endif /* __WAVE6_VPU_THERMAL_H__ */
Signature · 1 line
2.31.1
RFC PATCH v5 8/9 media: chips-media: wave6: Add Wave6 control driver
In reply to Nas ChungAdd the control driver for the Chips&Media Wave6 video codec IP.
The hardware contains one control register region and four interface register regions for a shared video processing engine.
This driver handles the control region and manages shared resources such as firmware loading, firmware memory allocation, and coordination required by the interface register regions.
It also instantiates and coordinates with the wave6-core child devices for firmware and power state management.
--- drivers/media/platform/chips-media/Kconfig | 1 + drivers/media/platform/chips-media/Makefile | 1 + .../media/platform/chips-media/wave6/Kconfig | 17 + .../media/platform/chips-media/wave6/Makefile | 17 + .../platform/chips-media/wave6/wave6-vpu.c | 816 ++++++++++++++++++ .../platform/chips-media/wave6/wave6-vpu.h | 143 +++ 6 files changed, 995 insertions(+) create mode 100644 drivers/media/platform/chips-media/wave6/Kconfig create mode 100644 drivers/media/platform/chips-media/wave6/Makefile create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu.c create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu.h
drivers/media/platform/chips-media/Kconfig +1 -0
@@ -4,3 +4,4 @@ comment "Chips&Media media platform drivers" source "drivers/media/platform/chips-media/coda/Kconfig" source "drivers/media/platform/chips-media/wave5/Kconfig" +source "drivers/media/platform/chips-media/wave6/Kconfig"
drivers/media/platform/chips-media/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-y += coda/ obj-y += wave5/ +obj-y += wave6/
drivers/media/platform/chips-media/wave6/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 + +config VIDEO_WAVE6_VPU + tristate "Chips&Media Wave6 Codec Driver" + depends on V4L_MEM2MEM_DRIVERS + depends on VIDEO_DEV && OF + depends on ARCH_MXC || COMPILE_TEST + select VIDEOBUF2_DMA_CONTIG + select V4L2_MEM2MEM_DEV + select GENERIC_ALLOCATOR + help + Chips&Media Wave6 stateful codec driver. + The wave6 driver manages shared resources such as firmware memory. + The wave6-core driver provides encoding and decoding capabilities + for H.264, HEVC, and other video formats. + To compile this driver as modules, choose M here: the + modules will be called wave6 and wave6-core.
drivers/media/platform/chips-media/wave6/Makefile new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 + +# tell define_trace.h where to find the trace header +CFLAGS_wave6-vpu-core.o := -I$(src) + +wave6-objs += wave6-vpu.o \ + wave6-vpu-thermal.o +obj-$(CONFIG_VIDEO_WAVE6_VPU) += wave6.o + +wave6-core-objs += wave6-vpu-core.o \ + wave6-vpu-v4l2.o \ + wave6-vpu-dbg.o \ + wave6-vpuapi.o \ + wave6-vpu-dec.o \ + wave6-vpu-enc.o \ + wave6-hw.o +obj-$(CONFIG_VIDEO_WAVE6_VPU) += wave6-core.o
drivers/media/platform/chips-media/wave6/wave6-vpu.c new file +816 -0
816 lines not on this page · raw message
drivers/media/platform/chips-media/wave6/wave6-vpu.h new file +143 -0
143 lines not on this page · raw message
Signature · 1 line
2.31.1
RFC PATCH v5 9/9 arm64: dts: freescale: imx95: Add video codec node
In reply to Nas ChungAdd the Chips and Media wave633 video codec node on IMX95 SoCs.
--- .../boot/dts/freescale/imx95-15x15-evk.dts | 7 +++- .../boot/dts/freescale/imx95-15x15-frdm.dts | 5 +++ .../boot/dts/freescale/imx95-19x19-evk.dts | 10 ++++++ .../dts/freescale/imx95-19x19-verdin-evk.dts | 10 ++++++ .../dts/freescale/imx95-phycore-fpsc.dtsi | 10 ++++++ .../dts/freescale/imx95-toradex-smarc-dev.dts | 5 +++ .../dts/freescale/imx95-toradex-smarc.dtsi | 5 +++ .../boot/dts/freescale/imx95-tqma9596sa.dtsi | 7 +++- arch/arm64/boot/dts/freescale/imx95.dtsi | 35 +++++++++++++++++++ 9 files changed, 92 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/freescale/imx95-15x15-evk.dts +6 -1
@@ -215,7 +215,7 @@ rsc_table: rsc-table@88220000 { no-map; }; - vpu_boot: vpu-boot@a0000000 { + vpu_boot: memory@a0000000 { reg = <0 0xa0000000 0 0x100000>; no-map; };
@@ -1157,6 +1157,11 @@ &wdog3 { status = "okay"; }; +&vpu { + memory-region = <&vpu_boot>; + sram = <&sram1>; +}; + &xcvr { clocks = <&scmi_clk IMX95_CLK_BUSWAKEUP>, <&scmi_clk IMX95_CLK_SPDIF>,
arch/arm64/boot/dts/freescale/imx95-15x15-frdm.dts +5 -0
@@ -962,3 +962,8 @@ &usdhc3 { &wdog3 { status = "okay"; }; + +&vpu { + memory-region = <&vpu_boot>; + sram = <&sram1>; +};
arch/arm64/boot/dts/freescale/imx95-19x19-evk.dts +10 -0
@@ -76,6 +76,11 @@ linux_cma: linux,cma { linux,cma-default; reusable; }; + + vpu_boot: memory@a0000000 { + reg = <0 0xa0000000 0 0x100000>; + no-map; + }; }; flexcan1_phy: can-phy0 {
@@ -1142,3 +1147,8 @@ &tpm6 { pinctrl-0 = <&pinctrl_tpm6>; status = "okay"; }; + +&vpu { + memory-region = <&vpu_boot>; + sram = <&sram1>; +};
arch/arm64/boot/dts/freescale/imx95-19x19-verdin-evk.dts +10 -0
@@ -65,6 +65,11 @@ linux_cma: linux,cma { linux,cma-default; reusable; }; + + vpu_boot: memory@a0000000 { + reg = <0 0xa0000000 0 0x100000>; + no-map; + }; }; reg_1p8v: regulator-1p8v {
@@ -693,3 +698,8 @@ pinctrl_usdhc3: usdhc3grp { <IMX95_PAD_SD3_DATA3__USDHC3_DATA3 0x138e>; }; }; + +&vpu { + memory-region = <&vpu_boot>; + sram = <&sram1>; +};
arch/arm64/boot/dts/freescale/imx95-phycore-fpsc.dtsi +10 -0
@@ -59,6 +59,11 @@ linux,cma { size = <0 0x3c000000>; linux,cma-default; }; + + vpu_boot: memory@a0000000 { + reg = <0 0xa0000000 0 0x100000>; + no-map; + }; }; };
@@ -654,3 +659,8 @@ &usdhc3 { /* FPSC SDIO */ pinctrl-0 = <&pinctrl_usdhc3>; pinctrl-names = "default"; }; + +&vpu { + memory-region = <&vpu_boot>; + sram = <&sram1>; +};
arch/arm64/boot/dts/freescale/imx95-toradex-smarc-dev.dts +5 -0
@@ -275,3 +275,8 @@ &usb3_phy { &usdhc2 { status = "okay"; }; + +&vpu { + memory-region = <&vpu_boot>; + sram = <&sram1>; +};
arch/arm64/boot/dts/freescale/imx95-toradex-smarc.dtsi +5 -0
@@ -156,6 +156,11 @@ linux_cma: linux,cma { alloc-ranges = <0 0x80000000 0 0x7f000000>; linux,cma-default; }; + + vpu_boot: memory@a0000000 { + reg = <0 0xa0000000 0 0x100000>; + no-map; + }; }; };
arch/arm64/boot/dts/freescale/imx95-tqma9596sa.dtsi +6 -1
@@ -40,7 +40,7 @@ linux_cma: linux,cma { linux,cma-default; }; - vpu_boot: vpu-boot@a0000000 { + vpu_boot: memory@a0000000 { reg = <0 0xa0000000 0 0x100000>; no-map; };
@@ -801,3 +801,8 @@ pinctrl_usdhc2_200mhz: usdhc2-200mhzgrp { <IMX95_PAD_SD2_VSELECT__USDHC2_VSELECT 0x51e>; }; }; + +&vpu { + memory-region = <&vpu_boot>; + sram = <&sram1>; +};
arch/arm64/boot/dts/freescale/imx95.dtsi +35 -0
@@ -2005,6 +2005,41 @@ vpu_blk_ctrl: clock-controller@4c410000 { assigned-clock-rates = <133333333>, <667000000>, <500000000>; }; + vpu: video-codec@4c4c0000 { + compatible = "nxp,imx95-vpu"; + reg = <0x0 0x4c4c0000 0x0 0x10000>; + clocks = <&scmi_clk IMX95_CLK_VPU>, + <&vpu_blk_ctrl IMX95_CLK_VPUBLK_WAVE>; + clock-names = "core", "vpublk"; + power-domains = <&scmi_devpd IMX95_PD_VPU>, + <&scmi_perf IMX95_PERF_VPU>; + power-domain-names = "vpu", "perf"; + #cooling-cells = <2>; + #address-cells = <2>; + #size-cells = <2>; + ranges; + + interface@4c480000 { + reg = <0x0 0x4c480000 0x0 0x10000>; + interrupts = <GIC_SPI 299 IRQ_TYPE_LEVEL_HIGH>; + }; + + interface@4c490000 { + reg = <0x0 0x4c490000 0x0 0x10000>; + interrupts = <GIC_SPI 300 IRQ_TYPE_LEVEL_HIGH>; + }; + + interface@4c4a0000 { + reg = <0x0 0x4c4a0000 0x0 0x10000>; + interrupts = <GIC_SPI 301 IRQ_TYPE_LEVEL_HIGH>; + }; + + interface@4c4b0000 { + reg = <0x0 0x4c4b0000 0x0 0x10000>; + interrupts = <GIC_SPI 302 IRQ_TYPE_LEVEL_HIGH>; + }; + }; + jpegdec: jpegdec@4c500000 { compatible = "nxp,imx95-jpgdec", "nxp,imx8qxp-jpgdec"; reg = <0x0 0x4C500000 0x0 0x00050000>;
Signature · 1 line
2.31.1