From: Charvi Mehta <charvi.mehta@arm.com>
To: linux-media@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Charvi Mehta <charvi.mehta@arm.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Philipp Zabel <p.zabel@pengutronix.de>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Rathinavel Sankaralingam <rath.sankaralingam@arm.com>,
Shobhit Pandey <shobhit.pandey@arm.com>
Subject: [RFC PATCH 02/28] media: mali-vpu: add Mali VPU platform driver
Date: Thu, 19 Nov 2026 15:37:32 +0000 [thread overview]
Message-ID: <20261119153758.1426673-3-charvi.mehta@arm.com> (raw)
In-Reply-To: <20261119153758.1426673-1-charvi.mehta@arm.com>
In preparation for adding H.264 video decode support, add the platform
driver for Arm Mali-VPU.
Add probe and remove operations to acquire and manage the MMIO region,
interrupt, clocks and reset controls. Add the variant data for Mali-V76
and validate the hardware product ID during probe.
Restrict the driver to little-endian kernels, as the firmware interface
uses little-endian shared memory structures accessed in native-byte order.
Signed-off-by: Charvi Mehta <charvi.mehta@arm.com>
---
drivers/media/platform/arm/Kconfig | 1 +
drivers/media/platform/arm/Makefile | 1 +
drivers/media/platform/arm/mali-vpu/Kconfig | 14 ++
drivers/media/platform/arm/mali-vpu/Makefile | 6 +
.../platform/arm/mali-vpu/mali-vpu-device.h | 38 ++++
.../platform/arm/mali-vpu/mali-vpu-probe.c | 215 ++++++++++++++++++
.../arm/mali-vpu/mali-vpu-registers.h | 24 ++
.../arm/mali-vpu/mali-vpu-variant-v76.c | 21 ++
.../platform/arm/mali-vpu/mali-vpu-variant.h | 25 ++
9 files changed, 345 insertions(+)
create mode 100644 drivers/media/platform/arm/mali-vpu/Kconfig
create mode 100644 drivers/media/platform/arm/mali-vpu/Makefile
create mode 100644 drivers/media/platform/arm/mali-vpu/mali-vpu-device.h
create mode 100644 drivers/media/platform/arm/mali-vpu/mali-vpu-probe.c
create mode 100644 drivers/media/platform/arm/mali-vpu/mali-vpu-registers.h
create mode 100644 drivers/media/platform/arm/mali-vpu/mali-vpu-variant-v76.c
create mode 100644 drivers/media/platform/arm/mali-vpu/mali-vpu-variant.h
diff --git a/drivers/media/platform/arm/Kconfig b/drivers/media/platform/arm/Kconfig
index 4f0764c329c74..339969d0ef4ce 100644
--- a/drivers/media/platform/arm/Kconfig
+++ b/drivers/media/platform/arm/Kconfig
@@ -3,3 +3,4 @@
comment "ARM media platform drivers"
source "drivers/media/platform/arm/mali-c55/Kconfig"
+source "drivers/media/platform/arm/mali-vpu/Kconfig"
diff --git a/drivers/media/platform/arm/Makefile b/drivers/media/platform/arm/Makefile
index 8cc4918725efa..3c38ad267e59a 100644
--- a/drivers/media/platform/arm/Makefile
+++ b/drivers/media/platform/arm/Makefile
@@ -1,2 +1,3 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-y += mali-c55/
+obj-y += mali-vpu/
diff --git a/drivers/media/platform/arm/mali-vpu/Kconfig b/drivers/media/platform/arm/mali-vpu/Kconfig
new file mode 100644
index 0000000000000..86403d7f424f9
--- /dev/null
+++ b/drivers/media/platform/arm/mali-vpu/Kconfig
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config VIDEO_MALI_VPU
+ tristate "ARM Mali VPU driver"
+ depends on VIDEO_DEV
+ depends on !CPU_BIG_ENDIAN
+ help
+ Enable this to support Arm's Mali Video hardware accelerator.
+ This is a V4L2 driver.
+
+ Only little-endian kernels are supported. The firmware interface
+ uses little-endian shared-memory structures.
+
+ To compile this driver as a module, choose M here: the module
+ will be called mali-vpu.
diff --git a/drivers/media/platform/arm/mali-vpu/Makefile b/drivers/media/platform/arm/mali-vpu/Makefile
new file mode 100644
index 0000000000000..22acf82e99a88
--- /dev/null
+++ b/drivers/media/platform/arm/mali-vpu/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+mali-vpu-objs := mali-vpu-probe.o \
+ mali-vpu-variant-v76.o
+
+obj-$(CONFIG_VIDEO_MALI_VPU) += mali-vpu.o
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-device.h b/drivers/media/platform/arm/mali-vpu/mali-vpu-device.h
new file mode 100644
index 0000000000000..04160090e64df
--- /dev/null
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-device.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2026 ARM Limited.
+ */
+
+#ifndef __MALI_VPU_DEVICE_H__
+#define __MALI_VPU_DEVICE_H__
+
+#include <linux/device.h>
+
+struct clk_bulk_data;
+struct mali_vpu_variant;
+struct reset_control_bulk_data;
+
+/**
+ * struct mali_vpu_dev - Mali VPU device
+ * @dev: Reference to device structure.
+ * @regs_base: MMIO base address for VPU registers.
+ * @clk_list: List of VPU clocks.
+ * @clk_count: Number of clocks in @clk_list.
+ * @rst_list: List of reset controls.
+ * @rst_count: Number of reset controls in @rst_list.
+ * @irq: IRQ number for VPU.
+ * @variant: Structure describing variant-specific features and capabilities.
+ */
+struct mali_vpu_dev {
+ struct device *dev;
+ void __iomem *regs_base;
+ struct clk_bulk_data *clk_list;
+ unsigned int clk_count;
+ struct reset_control_bulk_data *rst_list;
+ unsigned int rst_count;
+ int irq;
+
+ const struct mali_vpu_variant *variant;
+};
+
+#endif /* __MALI_VPU_DEVICE_H__ */
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-probe.c b/drivers/media/platform/arm/mali-vpu/mali-vpu-probe.c
new file mode 100644
index 0000000000000..49ecd6ac4554c
--- /dev/null
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-probe.c
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2026 ARM Limited.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/io.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+#include <linux/slab.h>
+
+#include "mali-vpu-device.h"
+#include "mali-vpu-registers.h"
+#include "mali-vpu-variant.h"
+
+/* VPU register access helpers */
+static u32 mali_vpu_read_reg(void __iomem *regs_base, u32 off)
+{
+ return readl(regs_base + off);
+}
+
+static void mali_vpu_read_version(struct mali_vpu_dev *vpu_dev, u32 *product_id, u32 *rev,
+ u32 *patch)
+{
+ u32 pid_prefix, pid_suffix;
+
+ u32 hwver = mali_vpu_read_reg(vpu_dev->regs_base, MALI_VPU_REG_VERSION);
+
+ pid_prefix = FIELD_GET(MALI_VPU_VERSION_PRODUCT_ID_MASK, hwver);
+ pid_suffix = FIELD_GET(MALI_VPU_PID_SUFFIX_MASK, hwver);
+
+ *product_id = (pid_prefix << 4) | pid_suffix;
+ *rev = FIELD_GET(MALI_VPU_VERSION_REVISION_MASK, hwver);
+ *patch = FIELD_GET(MALI_VPU_VERSION_PATCH_MASK, hwver);
+}
+
+static int mali_vpu_get_clocks(struct mali_vpu_dev *vpu_dev)
+{
+ int ret;
+
+ ret = devm_clk_bulk_get_all(vpu_dev->dev, &vpu_dev->clk_list);
+ if (ret < 0)
+ return dev_err_probe(vpu_dev->dev, ret, "failed to get clocks\n");
+ if (!ret)
+ return dev_err_probe(vpu_dev->dev, -EINVAL, "no clocks found\n");
+
+ vpu_dev->clk_count = ret;
+
+ return 0;
+}
+
+static int mali_vpu_get_resets(struct mali_vpu_dev *vpu_dev)
+{
+ unsigned int i;
+ int ret;
+
+ vpu_dev->rst_count = vpu_dev->variant->num_rsts;
+ if (vpu_dev->rst_count == 0)
+ return 0;
+
+ vpu_dev->rst_list = devm_kcalloc(vpu_dev->dev, vpu_dev->rst_count,
+ sizeof(*vpu_dev->rst_list), GFP_KERNEL);
+ if (!vpu_dev->rst_list)
+ return -ENOMEM;
+
+ for (i = 0; i < vpu_dev->rst_count; i++)
+ vpu_dev->rst_list[i].id = vpu_dev->variant->rst_names[i];
+
+ ret = devm_reset_control_bulk_get_optional_exclusive(vpu_dev->dev,
+ vpu_dev->rst_count,
+ vpu_dev->rst_list);
+ if (ret)
+ return dev_err_probe(vpu_dev->dev, ret, "failed to get reset controls\n");
+
+ return 0;
+}
+
+static int mali_vpu_enable_clk(struct mali_vpu_dev *vpu_dev)
+{
+ return clk_bulk_prepare_enable(vpu_dev->clk_count, vpu_dev->clk_list);
+}
+
+static void mali_vpu_disable_clk(struct mali_vpu_dev *vpu_dev)
+{
+ clk_bulk_disable_unprepare(vpu_dev->clk_count, vpu_dev->clk_list);
+}
+
+static void mali_vpu_assert_reset(struct mali_vpu_dev *vpu_dev)
+{
+ if (!vpu_dev->rst_count)
+ return;
+
+ reset_control_bulk_assert(vpu_dev->rst_count, vpu_dev->rst_list);
+}
+
+static int mali_vpu_deassert_reset(struct mali_vpu_dev *vpu_dev)
+{
+ if (!vpu_dev->rst_count)
+ return 0;
+
+ return reset_control_bulk_deassert(vpu_dev->rst_count, vpu_dev->rst_list);
+}
+
+static int mali_vpu_get_resources(struct mali_vpu_dev *vpu_dev)
+{
+ int ret;
+
+ ret = mali_vpu_get_clocks(vpu_dev);
+ if (ret)
+ return ret;
+
+ return mali_vpu_get_resets(vpu_dev);
+}
+
+static int mali_vpu_probe(struct platform_device *pdev)
+{
+ struct mali_vpu_dev *vpu_dev;
+ u32 pid, rev, patch;
+ int ret;
+
+ vpu_dev = devm_kzalloc(&pdev->dev, sizeof(*vpu_dev), GFP_KERNEL);
+ if (!vpu_dev)
+ return -ENOMEM;
+ vpu_dev->dev = &pdev->dev;
+
+ vpu_dev->variant = of_device_get_match_data(&pdev->dev);
+ if (!vpu_dev->variant)
+ return -ENODEV;
+
+ vpu_dev->regs_base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(vpu_dev->regs_base))
+ return PTR_ERR(vpu_dev->regs_base);
+
+ ret = platform_get_irq(pdev, 0);
+ if (ret < 0)
+ return ret;
+ vpu_dev->irq = ret;
+
+ ret = mali_vpu_get_resources(vpu_dev);
+ if (ret)
+ return ret;
+
+ ret = mali_vpu_enable_clk(vpu_dev);
+ if (ret) {
+ dev_err(vpu_dev->dev, "failed to enable core clock\n");
+ return ret;
+ }
+
+ ret = mali_vpu_deassert_reset(vpu_dev);
+ if (ret) {
+ dev_err(vpu_dev->dev, "failed to deassert reset\n");
+ goto err_clk;
+ }
+
+ mali_vpu_read_version(vpu_dev, &pid, &rev, &patch);
+ dev_info(&pdev->dev, "Mali VPU device product ID: %#x, revision: %#x, patch: %#x\n",
+ pid, rev, patch);
+
+ if (pid != vpu_dev->variant->expected_hw_pid) {
+ dev_err(vpu_dev->dev, "unexpected hardware product ID: %#x (expected %#x)\n",
+ pid, vpu_dev->variant->expected_hw_pid);
+ ret = -ENODEV;
+ goto err_rst_clk;
+ }
+
+ platform_set_drvdata(pdev, vpu_dev);
+
+ return 0;
+
+err_rst_clk:
+ mali_vpu_assert_reset(vpu_dev);
+err_clk:
+ mali_vpu_disable_clk(vpu_dev);
+
+ return ret;
+}
+
+static void mali_vpu_remove(struct platform_device *pdev)
+{
+ struct mali_vpu_dev *vpu_dev = platform_get_drvdata(pdev);
+
+ mali_vpu_assert_reset(vpu_dev);
+ mali_vpu_disable_clk(vpu_dev);
+
+ platform_set_drvdata(pdev, NULL);
+}
+
+static const struct of_device_id mali_vpu_dt_match[] = {
+ {
+ .compatible = "arm,mali-v76",
+ .data = &mali_vpu_v76_variant,
+ },
+ {},
+};
+MODULE_DEVICE_TABLE(of, mali_vpu_dt_match);
+
+static struct platform_driver mali_vpu_driver = {
+ .probe = mali_vpu_probe,
+ .remove = mali_vpu_remove,
+ .driver = {
+ .name = "mali-vpu",
+ .of_match_table = mali_vpu_dt_match,
+ },
+};
+
+module_platform_driver(mali_vpu_driver);
+MODULE_DESCRIPTION("Arm Mali VPU driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-registers.h b/drivers/media/platform/arm/mali-vpu/mali-vpu-registers.h
new file mode 100644
index 0000000000000..471a1f2412a7a
--- /dev/null
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-registers.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2026 ARM Limited.
+ */
+
+#ifndef __MALI_VPU_REGISTERS_H__
+#define __MALI_VPU_REGISTERS_H__
+
+#include <linux/bits.h>
+
+/*
+ * Mali VPU register offsets and bitfield definitions.
+ *
+ * Offsets are relative to the VPU MMIO base.
+ */
+#define MALI_VPU_REG_VERSION 0x00000
+
+/* Version register fields */
+#define MALI_VPU_VERSION_PRODUCT_ID_MASK GENMASK(31, 16)
+#define MALI_VPU_VERSION_REVISION_MASK GENMASK(15, 8)
+#define MALI_VPU_VERSION_PATCH_MASK GENMASK(7, 0)
+#define MALI_VPU_PID_SUFFIX_MASK GENMASK(15, 12)
+
+#endif /* __MALI_VPU_REGISTERS_H__ */
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-variant-v76.c b/drivers/media/platform/arm/mali-vpu/mali-vpu-variant-v76.c
new file mode 100644
index 0000000000000..36509d6a1c5d5
--- /dev/null
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-variant-v76.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2026 ARM Limited.
+ */
+
+#include <linux/array_size.h>
+
+#include "mali-vpu-variant.h"
+
+#define MALI_VPU_HW_PID_V76 0x56627
+
+static const char * const mali_v76_rst_names[] = {
+ "warm",
+};
+
+const struct mali_vpu_variant mali_vpu_v76_variant = {
+ .expected_hw_pid = MALI_VPU_HW_PID_V76,
+
+ .rst_names = mali_v76_rst_names,
+ .num_rsts = ARRAY_SIZE(mali_v76_rst_names),
+};
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-variant.h b/drivers/media/platform/arm/mali-vpu/mali-vpu-variant.h
new file mode 100644
index 0000000000000..dadfd686275db
--- /dev/null
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-variant.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2026 ARM Limited.
+ */
+
+#ifndef __MALI_VPU_VARIANT_H__
+#define __MALI_VPU_VARIANT_H__
+
+#include <linux/types.h>
+
+/**
+ * struct mali_vpu_variant - Variant-specific hardware capability descriptor.
+ * @rst_names: Array of reset control names for this variant.
+ * @num_rsts: Number of reset controls for this variant.
+ * @expected_hw_pid: Expected hardware product ID read from the version register.
+ */
+struct mali_vpu_variant {
+ const char * const *rst_names;
+ unsigned int num_rsts;
+ u32 expected_hw_pid;
+};
+
+extern const struct mali_vpu_variant mali_vpu_v76_variant;
+
+#endif /* __MALI_VPU_VARIANT_H__ */
--
2.43.0
next prev parent reply other threads:[~2026-11-19 15:38 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 15:37 [RFC PATCH 00/28] media: add arm Mali-V76 video decoder driver Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 01/28] dt-bindings: media: add Arm Mali-V76 VPU Charvi Mehta
2026-11-19 15:37 ` Charvi Mehta [this message]
2026-11-19 15:37 ` [RFC PATCH 03/28] media: mali-vpu: register V4L2 decoder device and add querycap ioctl Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 04/28] media: mali-vpu: initialize decoder format state Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 05/28] media: mali-vpu: add V4L2 mem2mem and VB2 queue support Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 06/28] media: mali-vpu: implement format query ioctls Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 07/28] media: mali-vpu: implement TRY_FMT and S_FMT ioctls Charvi Mehta
2026-11-19 15:55 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 08/28] media: mali-vpu: register V76 decoder controls and introduce UAPI controls Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 09/28] media: mali-vpu: add MMU software page table manager Charvi Mehta
2026-11-19 15:59 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 10/28] media: mali-vpu: add firmware cache infrastructure Charvi Mehta
2026-11-19 15:50 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 11/28] media: mali-vpu: load firmware for decoder sessions Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 12/28] media: mali-vpu: prepare firmware address space Charvi Mehta
2026-11-19 15:57 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 13/28] media: mali-vpu: add firmware message transport Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 14/28] media: mali-vpu: route decoder controls to firmware Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 15/28] media: mali-vpu: handle firmware RPC requests Charvi Mehta
2026-11-19 15:51 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 16/28] media: mali-vpu: add LSID hardware support Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 17/28] media: mali-vpu: add single session scheduler Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 18/28] media: mali-vpu: handle firmware interrupts Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 19/28] media: mali-vpu: start decoder firmware through LSID scheduling Charvi Mehta
2026-11-19 16:03 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 20/28] media: mali-vpu: implement vb2 buffer queue handling Charvi Mehta
2026-11-19 16:06 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 21/28] media: mali-vpu: handle firmware buffer exchange Charvi Mehta
2026-11-19 15:58 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 22/28] media: mali-vpu: handle fatal firmware error Charvi Mehta
2026-11-19 16:07 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 23/28] media: mali-vpu: propagate buffer metadata Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 24/28] media: mali-vpu: add decoder EOS and DRC handling Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 25/28] media: mali-vpu: handle firmware buffer parameters Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 26/28] media: mali-vpu: handle firmware event responses Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 27/28] media: mali-vpu: add stateful decoder state machine Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 28/28] media: MAINTAINERS: add Arm Mali-V76 VPU driver Charvi Mehta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119153758.1426673-3-charvi.mehta@arm.com \
--to=charvi.mehta@arm.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=rath.sankaralingam@arm.com \
--cc=robh@kernel.org \
--cc=shobhit.pandey@arm.com \
--cc=vincenzo.frascino@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox