[PATCH v8 02/11] media: chips-media: wave6: Add Wave6 control driver

Frank Li Frank.li at oss.nxp.com
Thu Nov 19 12:07:55 PST 2026


On Thu, Nov 19, 2026 at 05:59:56PM +0900, Nas Chung wrote:
> Add 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.
>
> Tested-by: Ming Qian <ming.qian at oss.nxp.com>
> Tested-by: Marek Vasut <marek.vasut at mailbox.org>
> Signed-off-by: Nas Chung <nas.chung at chipsnmedia.com>
> ---
...
> +
> +static inline int wave6_vdi_alloc_dma(struct device *dev, struct vpu_buf *vb)
> +{
> +	void *vaddr;
> +	dma_addr_t daddr;

Nit try keep revise christmas order, check others

dma_addr_t daddr;
void *vaddr;

> +
> +	if (!vb || !vb->size)
> +		return -EINVAL;
> +
> +	vaddr = dma_alloc_coherent(dev, vb->size, &daddr, GFP_KERNEL);
> +	if (!vaddr)
> +		return -ENOMEM;
> +
> +	vb->vaddr = vaddr;
> +	vb->daddr = daddr;
> +	vb->dev = dev;
> +
> +	return 0;
> +}
> +
...
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/clk.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/property.h>
> +#include <linux/of_irq.h>
> +#include <linux/firmware.h>
> +#include <linux/interrupt.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/pm_domain.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/iopoll.h>
> +#include <linux/genalloc.h>

order by alpabet.

> +
> +#include "wave6-vpuconfig.h"
> +#include "wave6-regdefine.h"
> +#include "wave6-vpu.h"
> +
> +static const struct wave6_vpu_resource wave633c_data = {
> +	.fw_name = "cnm/wave633c_imx9_codec_fw.bin",
> +	/* For HEVC, AVC, 4096x4096, 8bit */
> +	.sram_size = 0x14800,
> +};
> +
...
> +
> +static u32 wave6_vpu_get_code_buf_size(struct wave6_vpu_device *vpu)
> +{
> +	return min_t(u32, vpu->code_buf.size, W6_MAX_CODE_BUF_SIZE);

now use min()

> +}
> +
...
> +
> +static int wave6_vpu_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np;
> +	struct wave6_vpu_device *vpu;
> +	const struct wave6_vpu_resource *res;
> +	int ret;
> +
> +	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;
> +	}

Needn't check when mask > 32, if check,

	return dev_err_probe()

> +
> +	res = device_get_match_data(&pdev->dev);
> +	if (!res)
> +		return -ENODEV;
> +
...
> +
> +	wave6_vpu_allocate_work_buffers(vpu);
> +
> +	pm_runtime_enable(&pdev->dev);

devm_pm_runtime_enable();

you have not enable clock here, so you need select PM at Kconfig, otherwise
if !CONFIG_PM, other register access will be hang because stub do nothing
of runtime pm when !CONFIG_PM

> +
> +	init_completion(&vpu->fw_done);
> +	ret = firmware_request_nowait_nowarn(THIS_MODULE,
> +					     vpu->res->fw_name,
> +					     &pdev->dev,
> +					     GFP_KERNEL,
> +					     vpu,
> +					     wave6_vpu_load_firmware);
> +	if (ret) {
> +		dev_err(&pdev->dev, "request firmware fail, ret = %d\n", ret);
> +		goto error;
> +	}
> +
> +	return 0;
> +
> +error:
> +	wave6_vpu_release(vpu);
> +	pm_runtime_disable(&pdev->dev);
> +error_detach_pm_domains:
> +	wave6_vpu_detach_pm_domains(vpu);

use devm_add_action_or_reset() to avoid goto in probe()

> +
> +	return ret;
> +}
> +
...
> +
> +module_platform_driver(wave6_vpu_driver);
> +MODULE_DESCRIPTION("chips&media Wave6 VPU driver");
> +MODULE_AUTHOR("CHIPS&MEDIA INC");
> +MODULE_FIRMWARE("cnm/wave633c_imx9_codec_fw.bin");
> +MODULE_LICENSE("Dual BSD/GPL");
> diff --git a/drivers/media/platform/chips-media/wave6/wave6-vpu.h b/drivers/media/platform/chips-media/wave6/wave6-vpu.h
> new file mode 100644
> index 000000000000..96d67e931e71
> --- /dev/null
> +++ b/drivers/media/platform/chips-media/wave6/wave6-vpu.h
> @@ -0,0 +1,137 @@
> +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
> +/*
> + * Wave6 series multi-standard codec IP - wave6 driver
> + *
> + * Copyright (C) 2026 CHIPS&MEDIA INC
> + */
> +
> +#ifndef __WAVE6_VPU_H__
> +#define __WAVE6_VPU_H__
> +
> +#include <linux/completion.h>
> +#include <linux/device.h>
> +
> +#include "wave6-vpuconfig.h"
> +#include "wave6-vdi.h"
> +
> +#define WAVE6_VPU_PLATFORM_DRIVER_NAME "wave6-vpu"
> +#define WAVE6_VPU_CORE_PLATFORM_DRIVER_NAME "wave6-vpu-core"

If only use once, needn't define macro.

> +
> +struct wave6_vpu_device;
> +
> +/**
> + * enum wave6_vpu_state - VPU states
> + * @WAVE6_VPU_STATE_OFF:	VPU is powered off
> + * @WAVE6_VPU_STATE_PREPARE:	VPU is booting
> + * @WAVE6_VPU_STATE_ON:		VPU is running
> + * @WAVE6_VPU_STATE_SLEEP:	VPU is in a sleep mode
> + */
...
> +
> +#define W6_VPU_MAX_NUM_CORE		4
> +#define MAX_NUM_INSTANCE		32
> +
> +#define W6_VPU_POLL_DELAY_US		10
> +#define W6_VPU_POLL_TIMEOUT		300000

Need unit surfix

Frank

> +
> +#define W6_MAX_REMAP_PAGE_SIZE		(1024 * 1024)
> +#define W6_MAX_CODE_BUF_SIZE		(4 * 1024 * 1024)
> +#define W6_CODE_BUF_SIZE		(1 * 1024 * 1024)
> +#define W6_EXTRA_CODE_BUF_SIZE		(256 * 1024)
> +#define W637DEC_WORKBUF_SIZE_FOR_CQ	(3 * 512 * 1024)
> +
> +static inline bool wave6_is_product_w_series(u32 code)
> +{
> +	return code == WAVE617_CODE || code == WAVE627_CODE ||
> +	       code == WAVE633_CODE || code == WAVE637_CODE ||
> +	       code == WAVE663_CODE || code == WAVE677_CODE;
> +}
> +
> +#endif /* __WAVE6_VPUCONFIG_H__ */
> --
> 2.41.0.windows.3
>
>



More information about the linux-arm-kernel mailing list