* [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver
@ 2026-11-24 17:07 Anthony McGivern
2026-11-24 17:07 ` [PATCH 01/24] media: uapi: Add 24-bit Bayer media bus formats Anthony McGivern
` (23 more replies)
0 siblings, 24 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
This patchset introduces a driver for Arm's Mali-C720 Image Signal Processor.
The driver uses the V4L2 / media controller API and implements the following
ISP features:
- Input and human vision pipelines:
The ISP has numerous processing pipelines. We implement support for
the input pipeline as well as the human vision processing pipeline.
- Full resolution capture pipeline:
This capture pipeline supports both cropping and downscaling, as well
as simultaneously outputting RGB and YUV data.
- Basic statistics and parameters blocks:
We have implemented a small set of the ISP statistics, covering
pixel intensity histograms across both the input and human vision
pipelines, as well as color statistics. We also include a small set
of parameter blocks for digital gain, white balance, black level, square
and square root transforms, and lastly decompanding.
- Basic output format support:
Currently we provide support for RGB24 and NV12 output formats.
The ISP supports much more functionality than this which we wish to include
in future patch series, some of which is possible in the existing framework
while others will require further development.
Alongside this we also have a series to enable support in libcamera. Both
branches can be found on our GitLab [1]. We also have branches present for
features currently in development that are not included in this series [2].
The features we would like to implement in the future include:
- Multi-context:
The ISP supports up to 16 contexts, plus 4 additional contexts reserved
for functional safety. This series only adds support for a single
context, though infrastructure is in place to configure the ISP's
context manager unit. Please see our GitLab where we have implemented
a temporary solution for enabling multi-context by duplicating the
media device [3].
- Additional capture pipelines:
The ISP has a number of capture pipelines that can be used in parallel.
This can include up to four "full resolution" capture pipelines, a raw
pipeline for Bayer data, a "foveated" pipeline for three separate ROIs
of the same image, and lastly a Gaussian pyramid pipeline. The latter
introduces a challenge with representing the image format since the
output data is four levels, each being a quarter the resolution (half
the width and height) of the previous level.
- Dual image processing pipelines:
In addition to the human vision processing pipeline, the ISP has a
separate processing pipeline that targets computer vision applications.
This allows the same input frame to be processed for both human and
computer vision applications in parallel, and be output simultaneously
through separate capture pipelines.
- Multiple input ports:
The ISP input frontend supports up to four physical inputs and each
of these can carry up to four virtual channels, for a total of 16
inputs. This series only enables support for input 0/stream 0 until
userspace routing ioctls are enabled to configure a route from the
desired input/stream to the input source pad. You may refer to our
multi-context implementation where we must split this frontend to
provide each context its own input, which limits our flexibility.
- Additional format support:
This initial candidate supports a basic set of output formats, with
further support planned in a future series.
- Processing modes:
The ISP can operate in various modes: Streaming, TDMF fix, TDMF flex,
and memory-to-memory (M2M). This series uses TDMF flex mode with a
single context. Support for the other modes is planned for future
series.
- TDMF fix/flex: Frames are written from the input frontend to DMA
buffers. When a buffer is written, that context is
marked as schedulable. For flex mode, contexts are
then scheduled on a first-come, first-served basis.
For fix mode, the processing order is strict and
preconfigured.
- Streaming: Used for low-latency operation with a single camera.
Frames are fed directly from the input to the pipeline.
The DMA buffer is only used if internal FIFOs overflow.
- M2M: Allows frame buffers to be provided directly, bypassing the
input frontend.
The mode of operation is configurable per-context, meaning it is
possible to have one context running in TDMF flex, while another is
using M2M mode.
- Multiple exposure:
The ISP can support up to two exposures, using a pipeline frame
stitching module. This also requires input routing support, as well
as the ability for sensor subdevices to output multiple streams.
- RGB-IR support:
Our ISP can receive a 4x4 RGBIr CFA pattern and internally split this
into separate RGB and monochrome images which may be independently
processed in the pipeline. Support would require describing the RGB-IR
CFA pattern, potentially using the generic raw formats and CFA controls
proposed in Sakari's metadata series [4].
- Streaming outputs:
Alongside the traditional memory outputs, some capture pipelines have
outputs that physically connect to a downstream device. This may
already be possible with a downstream video capture device and V4L2
async notifier callbacks, but there may also be cases where the ISP is
connected to a downstream subdevice that consumes the data directly and
thus requires no capture device or any allocated buffers. In such a
case, this subdevice should be able to start the media pipeline without
a video device that traditionally exposes STREAMON/STREAMOFF ioctls.
Our ISP is also configurable at synthesis time. This means that certain ISP
features may only be present depending on the customer's implementation. Our
driver tackles this by parsing the ISP's "capability discovery" table, which
provides details about available pipelines and the presence of particular
modules within a given pipeline. Some details are not fully exposed by this
table, in which case we use hardware identification checks.
Details about the ISP can be found on Arm's support page [5].
The driver exposes 6 V4L2 subdevices:
- mali-c720 tpg X: 2 test pattern generator inputs
- mali-c720 input: Frontend for receiving sensor inputs
- mali-c720 isp: Represents the ISP input pipeline
- mali-c720 hv pipe: Vision pipeline for human vision processing
- mali-c720 fr 0 pipe: Full resolution pipeline with downscaling and cropping
Along with 4 V4L2 video devices:
- mali-c720 fr0-rgb/yuv: Separate RGB and YUV capture devices for the FR0 pipe
- mali-c720 3a stats: Capture device for statistics to support 3A algorithms
- mali-c720 3a params: Output device for parameter buffers to configure the ISP
Support is implemented in the parameters video device code for a few of the
ISP's hardware blocks, with more support planned in future patch series. The
buffer format uses the v4l2-isp extensible parameters.
Statistics support follows a similar pattern, in that we currently only
support the pixel intensity histogram present on the input and human vision
pipelines, as well as HV's color statistics. We make use of the v4l2-isp
extensible statistics here, allowing for additional blocks to be supported
in the future.
The driver exposes custom V4L2 controls to enumerate the supported statistics
and parameter block IDs. This aims to account for hardware being synthesised
with or without particular modules, as well as future revisions including new
modules or updated modules that require a different register set. Userspace
should query these to determine what algorithms it should enable based on what
statistics it will receive and what modules are programmable.
Below is the v4l2-compliance report for the driver. The failures reported
relate to width and height being set to 0 for MEDIA_BUS_FMT_METADATA_FIXED
in the ISP subdevice. This appears to be a tool limitation as seen in other
drivers.
[1] Upstream submission branches:
- https://gitlab.arm.com/media/isp/linux/-/tree/mali-c720/r0p1/v7.4-rc4/mainline-v1
- https://gitlab.arm.com/media/isp/libcamera/-/tree/mali-c720/r0p1/v7.4-rc4/mainline-v1
[2] Development branches:
- https://gitlab.arm.com/media/isp/linux/-/tree/mali-c720/r0p1/v6.18/dev-v1
- https://gitlab.arm.com/media/isp/libcamera/-/tree/mali-c720/r0p1/v6.18/dev-v1
[3] Multi-context temporary implementation:
- https://gitlab.arm.com/media/isp/linux/-/tree/mali-c720/r0p1/v6.18/dev-v2-multicontext
- https://gitlab.arm.com/media/isp/libcamera/-/tree/mali-c720/r0p1/v6.18/dev-v2-multicontext
[4] Sakari's metadata series - https://lore.kernel.org/linux-media/20261118132819.213473-1-sakari.ailus@linux.intel.com/T/
[5] Arm support page - https://support.arm.com/compute-ip/mali-c720ae
v4l2-compliance 1.33.0-5455, 64 bits, 64-bit time_t
v4l2-compliance SHA: 95ad25f6a77a 2026-03-17 13:08:36
Compliance test for mali-c720 device /dev/media0:
Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Required ioctls:
test MEDIA_IOC_DEVICE_INFO: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/media0 open: OK
test MEDIA_IOC_DEVICE_INFO: OK
test for unlimited opens: OK
Media Controller ioctls:
test MEDIA_IOC_G_TOPOLOGY: OK
Entities: 12 Interfaces: 12 Pads: 20 Links: 23
test MEDIA_IOC_ENUM_ENTITIES/LINKS: OK
test MEDIA_IOC_SETUP_LINK: OK
Total for mali-c720 device /dev/media0: 8, Succeeded: 8, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mali-c720 device /dev/video0:
Driver Info:
Driver name : mali-c720
Card type : ARM Mali-C720 ISP
Bus info : platform:60400000.isp
Driver version : 7.4.0
Capabilities : 0xa4201000
Video Capture Multiplanar
I/O MC
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x24201000
Video Capture Multiplanar
I/O MC
Streaming
Extended Pix Format
Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Interface Info:
ID : 0x03000016
Type : V4L Video
Entity Info:
ID : 0x00000014 (20)
Name : mali-c720 fr0-rgb
Function : V4L2 I/O
Pad 0x01000015 : 0: Sink, Must Connect
Link 0x0200002e: from remote pad 0x1000012 of entity 'mali-c720 fr 0
pipe' (Image Signal Processor): Data
Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported)
test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported)
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 0 Private Controls: 0
Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK
Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK
test Requests: OK
Total for mali-c720 device /dev/video0: 48, Succeeded: 48, Failed: 0, Warnings:
0
--------------------------------------------------------------------------------
Compliance test for mali-c720 device /dev/video1:
Driver Info:
Driver name : mali-c720
Card type : ARM Mali-C720 ISP
Bus info : platform:60400000.isp
Driver version : 7.4.0
Capabilities : 0xa4201000
Video Capture Multiplanar
I/O MC
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x24201000
Video Capture Multiplanar
I/O MC
Streaming
Extended Pix Format
Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Interface Info:
ID : 0x0300001a
Type : V4L Video
Entity Info:
ID : 0x00000018 (24)
Name : mali-c720 fr0-yuv
Function : V4L2 I/O
Pad 0x01000019 : 0: Sink, Must Connect
Link 0x02000030: from remote pad 0x1000013 of entity 'mali-c720 fr 0
pipe' (Image Signal Processor): Data, Enabled
Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/video1 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported)
test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported)
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 0 Private Controls: 0
Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK
Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK
test Requests: OK
Total for mali-c720 device /dev/video1: 48, Succeeded: 48, Failed: 0, Warnings:
0
--------------------------------------------------------------------------------
Compliance test for mali-c720 device /dev/video2:
Driver Info:
Driver name : mali-c720
Card type : ARM Mali-C720 ISP
Bus info : platform:60400000.isp
Driver version : 7.4.0
Capabilities : 0xa4a00000
Metadata Capture
I/O MC
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x24a00000
Metadata Capture
I/O MC
Streaming
Extended Pix Format
Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Interface Info:
ID : 0x0300001e
Type : V4L Video
Entity Info:
ID : 0x0000001c (28)
Name : mali-c720 3a stats
Function : V4L2 I/O
Pad 0x0100001d : 0: Sink, Must Connect
Link 0x02000032: from remote pad 0x100000b of entity 'mali-c720 isp'
(Image Signal Processor): Data, Enabled
Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/video2 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 0 Private Controls: 0
Standard Compound Controls: 0 Private Compound Controls: 1
Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK
test Requests: OK
Total for mali-c720 device /dev/video2: 48, Succeeded: 48, Failed: 0, Warnings:
0
--------------------------------------------------------------------------------
Compliance test for mali-c720 device /dev/video3:
Driver Info:
Driver name : mali-c720
Card type : ARM Mali-C720 ISP
Bus info : platform:60400000.isp
Driver version : 7.4.0
Capabilities : 0xac200000
Metadata Output
I/O MC
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x2c200000
Metadata Output
I/O MC
Streaming
Extended Pix Format
Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Interface Info:
ID : 0x03000022
Type : V4L Video
Entity Info:
ID : 0x00000020 (32)
Name : mali-c720 3a params
Function : V4L2 I/O
Pad 0x01000021 : 0: Source, Must Connect
Link 0x02000034: to remote pad 0x100000c of entity 'mali-c720 isp'
(Image Signal Processor): Data, Enabled
Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/video3 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 1 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Control ioctls (Output 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 0 Private Controls: 0
Standard Compound Controls: 0 Private Compound Controls: 1
Format ioctls (Output 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls (Output 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls (Output 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK
test Requests: OK
Total for mali-c720 device /dev/video3: 48, Succeeded: 48, Failed: 0, Warnings:
0
--------------------------------------------------------------------------------
Compliance test for mali-c720 device /dev/v4l-subdev0:
Driver Info:
Driver version : 7.4.0
Capabilities : 0x00000000
Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Interface Info:
ID : 0x0300003f
Type : V4L Sub-Device
Entity Info:
ID : 0x00000001 (1)
Name : mali-c720 tpg 0
Function : Camera Sensor
Pad 0x01000002 : 0: Source
Link 0x02000024: to remote pad 0x1000007 of entity 'mali-c720 input'
(Image Signal Processor): Data
Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/v4l-subdev0 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Sub-Device ioctls (Source Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 6 Private Controls: 0
Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported)
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported)
test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)
Total for mali-c720 device /dev/v4l-subdev0: 54, Succeeded: 54, Failed: 0,
Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mali-c720 device /dev/v4l-subdev1:
Driver Info:
Driver version : 7.4.0
Capabilities : 0x00000000
Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Interface Info:
ID : 0x03000041
Type : V4L Sub-Device
Entity Info:
ID : 0x00000003 (3)
Name : mali-c720 tpg 1
Function : Camera Sensor
Pad 0x01000004 : 0: Source
Link 0x02000026: to remote pad 0x1000007 of entity 'mali-c720 input'
(Image Signal Processor): Data
Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/v4l-subdev1 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Sub-Device ioctls (Source Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 6 Private Controls: 0
Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported)
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported)
test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)
Total for mali-c720 device /dev/v4l-subdev1: 54, Succeeded: 54, Failed: 0,
Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mali-c720 device /dev/v4l-subdev2:
Driver Info:
Driver version : 7.4.0
Capabilities : 0x00000000
Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Interface Info:
ID : 0x03000043
Type : V4L Sub-Device
Entity Info:
ID : 0x00000005 (5)
Name : mali-c720 input
Function : Image Signal Processor
Pad 0x01000006 : 0: Source
Link 0x02000028: to remote pad 0x1000009 of entity 'mali-c720 isp'
(Image Signal Processor): Data, Enabled
Pad 0x01000007 : 1: Sink, Must Connect
Link 0x02000024: from remote pad 0x1000002 of entity 'mali-c720 tpg 0'
(Camera Sensor): Data
Link 0x02000026: from remote pad 0x1000004 of entity 'mali-c720 tpg 1'
(Camera Sensor): Data
Link 0x02000039: from remote pad 0x1000038 of entity 'lte-csi2-rx'
(Video Interface Bridge): Data, Enabled
Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/v4l-subdev2 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Sub-Device ioctls (Source Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Sub-Device ioctls (Sink Pad 1):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported)
test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported)
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 0 Private Controls: 0
Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported)
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported)
test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)
Total for mali-c720 device /dev/v4l-subdev2: 61, Succeeded: 61, Failed: 0,
Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mali-c720 device /dev/v4l-subdev3:
Driver Info:
Driver version : 7.4.0
Capabilities : 0x00000000
Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Interface Info:
ID : 0x03000045
Type : V4L Sub-Device
Entity Info:
ID : 0x00000008 (8)
Name : mali-c720 isp
Function : Image Signal Processor
Pad 0x01000009 : 0: Sink, Must Connect
Link 0x02000028: from remote pad 0x1000006 of entity 'mali-c720 input'
(Image Signal Processor): Data, Enabled
Pad 0x0100000a : 1: Source
Link 0x0200002a: to remote pad 0x100000e of entity 'mali-c720 hv pipe'
(Image Signal Processor): Data, Enabled
Pad 0x0100000b : 2: Source
Link 0x02000032: to remote pad 0x100001d of entity 'mali-c720 3a
stats' (V4L2 I/O): Data, Enabled
Pad 0x0100000c : 3: Sink
Link 0x02000034: from remote pad 0x1000021 of entity 'mali-c720 3a
params' (V4L2 I/O): Data, Enabled
Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/v4l-subdev3 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Sub-Device ioctls (Sink Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Sub-Device ioctls (Source Pad 1):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Sub-Device ioctls (Source Pad 2):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
fail: v4l2-test-subdevs.cpp(369): fmt.width == 0 || fmt.width >
65536
fail: v4l2-test-subdevs.cpp(418): checkMBusFrameFmt(node,
fmt.format)
test Try VIDIOC_SUBDEV_G/S_FMT: FAIL
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
fail: v4l2-test-subdevs.cpp(369): fmt.width == 0 || fmt.width >
65536
fail: v4l2-test-subdevs.cpp(418): checkMBusFrameFmt(node,
fmt.format)
test Active VIDIOC_SUBDEV_G/S_FMT: FAIL
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Sub-Device ioctls (Sink Pad 3):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
fail: v4l2-test-subdevs.cpp(369): fmt.width == 0 || fmt.width >
65536
fail: v4l2-test-subdevs.cpp(418): checkMBusFrameFmt(node,
fmt.format)
test Try VIDIOC_SUBDEV_G/S_FMT: FAIL
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
fail: v4l2-test-subdevs.cpp(369): fmt.width == 0 || fmt.width >
65536
fail: v4l2-test-subdevs.cpp(418): checkMBusFrameFmt(node,
fmt.format)
test Active VIDIOC_SUBDEV_G/S_FMT: FAIL
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported)
test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported)
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 0 Private Controls: 0
Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported)
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported)
test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)
Total for mali-c720 device /dev/v4l-subdev3: 75, Succeeded: 71, Failed: 4,
Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mali-c720 device /dev/v4l-subdev4:
Driver Info:
Driver version : 7.4.0
Capabilities : 0x00000000
Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Interface Info:
ID : 0x03000047
Type : V4L Sub-Device
Entity Info:
ID : 0x0000000d (13)
Name : mali-c720 hv pipe
Function : Image Signal Processor
Pad 0x0100000e : 0: Sink, Must Connect
Link 0x0200002a: from remote pad 0x100000a of entity 'mali-c720 isp'
(Image Signal Processor): Data, Enabled
Pad 0x0100000f : 1: Source
Link 0x0200002c: to remote pad 0x1000011 of entity 'mali-c720 fr 0
pipe' (Image Signal Processor): Data, Enabled
Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/v4l-subdev4 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Sub-Device ioctls (Sink Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Sub-Device ioctls (Source Pad 1):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported)
test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported)
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 0 Private Controls: 0
Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported)
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported)
test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)
Total for mali-c720 device /dev/v4l-subdev4: 61, Succeeded: 61, Failed: 0,
Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mali-c720 device /dev/v4l-subdev5:
Driver Info:
Driver version : 7.4.0
Capabilities : 0x00000000
Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
Driver name : mali-c720
Model : ARM Mali-C720 ISP
Serial :
Bus info : platform:60400000.isp
Media version : 7.4.0
Hardware revision: 0x00000000 (0)
Driver version : 7.4.0
Interface Info:
ID : 0x03000049
Type : V4L Sub-Device
Entity Info:
ID : 0x00000010 (16)
Name : mali-c720 fr 0 pipe
Function : Image Signal Processor
Pad 0x01000011 : 0: Sink, Must Connect
Link 0x0200002c: from remote pad 0x100000f of entity 'mali-c720 hv
pipe' (Image Signal Processor): Data, Enabled
Pad 0x01000012 : 1: Source
Link 0x0200002e: to remote pad 0x1000015 of entity 'mali-c720 fr0-rgb'
(V4L2 I/O): Data
Pad 0x01000013 : 2: Source
Link 0x02000030: to remote pad 0x1000019 of entity 'mali-c720 fr0-yuv'
(V4L2 I/O): Data, Enabled
Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/v4l-subdev5 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Sub-Device ioctls (Sink Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Sub-Device ioctls (Source Pad 1):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Sub-Device ioctls (Source Pad 2):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)
Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported)
test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported)
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 0 Private Controls: 0
Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported)
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported)
test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)
Total for mali-c720 device /dev/v4l-subdev5: 68, Succeeded: 68, Failed: 0,
Warnings: 0
Grand Total for mali-c720 device /dev/media0: 573, Succeeded: 569, Failed: 4,
Warnings: 0
---
Anthony McGivern (24):
media: uapi: Add 24-bit Bayer media bus formats
dt-bindings: media: Add bindings for Arm Mali-C720
media: uapi: Add a control ID base for Mali-C720 ISP
media: mali-c720: Add register access helpers
media: mali-c720: Add hardware identification
media: mali-c720: Add format handling
media: mali-c720: Add hardware discovery support
media: mali-c720: Add context manager and interrupt handling
media: mali-c720: Add input frontend subdevice
media: mali-c720: Add ISP and human vision subdevices
media: mali-c720: Add full-resolution output subdevice
media: mali-c720: Add video capture nodes
media: mali-c720: Add Mali-C720 ISP driver
media: mali-c720: Add test pattern generator subdevices
media: Documentation: Add Mali-C720 ISP documentation
media: uapi: Add Mali-C720 statistics meta format
media: uapi: Add statistics structs to mali-c720-config.h
media: mali-c720: Add 3A statistics video node
media: Documentation: Document Mali-C720 statistics capture
media: uapi: Add Mali-C720 parameters meta format
media: uapi: Add parameter structs to mali-c720-config.h
media: mali-c720: Add parameters video node
media: Documentation: Document Mali-C720 parameter settings
MAINTAINERS: Add entry for mali-c720 driver
.../admin-guide/media/mali-c720-graph.dot | 26 +
Documentation/admin-guide/media/mali-c720.rst | 435 +++++
Documentation/admin-guide/media/v4l-drivers.rst | 1 +
.../devicetree/bindings/media/arm,mali-c720.yaml | 134 ++
.../userspace-api/media/drivers/index.rst | 1 +
.../userspace-api/media/drivers/mali-c720.rst | 47 +
.../userspace-api/media/v4l/meta-formats.rst | 1 +
.../media/v4l/metafmt-arm-mali-c720.rst | 112 ++
.../userspace-api/media/v4l/subdev-formats.rst | 289 ++-
MAINTAINERS | 13 +
drivers/media/platform/arm/Kconfig | 1 +
drivers/media/platform/arm/Makefile | 1 +
drivers/media/platform/arm/mali-c720/Kconfig | 18 +
drivers/media/platform/arm/mali-c720/Makefile | 23 +
.../platform/arm/mali-c720/mali-c720-capture.c | 775 ++++++++
.../platform/arm/mali-c720/mali-c720-common.h | 451 +++++
.../media/platform/arm/mali-c720/mali-c720-core.c | 985 ++++++++++
.../platform/arm/mali-c720/mali-c720-ctx-mgr.c | 1923 ++++++++++++++++++++
.../platform/arm/mali-c720/mali-c720-ctx-mgr.h | 327 ++++
.../platform/arm/mali-c720/mali-c720-discovery.c | 1172 ++++++++++++
.../platform/arm/mali-c720/mali-c720-discovery.h | 212 +++
.../platform/arm/mali-c720/mali-c720-formats.c | 452 +++++
.../platform/arm/mali-c720/mali-c720-formats.h | 132 ++
.../platform/arm/mali-c720/mali-c720-fr-pipe.c | 1178 ++++++++++++
.../media/platform/arm/mali-c720/mali-c720-id.c | 165 ++
.../media/platform/arm/mali-c720/mali-c720-id.h | 34 +
.../media/platform/arm/mali-c720/mali-c720-input.c | 598 ++++++
.../platform/arm/mali-c720/mali-c720-interrupts.c | 436 +++++
.../platform/arm/mali-c720/mali-c720-interrupts.h | 34 +
.../media/platform/arm/mali-c720/mali-c720-isp.c | 456 +++++
.../platform/arm/mali-c720/mali-c720-params.c | 1450 +++++++++++++++
.../arm/mali-c720/mali-c720-register-access.c | 205 +++
.../arm/mali-c720/mali-c720-register-access.h | 55 +
.../arm/mali-c720/mali-c720-registers-ctx-mgr.c | 226 +++
.../arm/mali-c720/mali-c720-registers-ctx-mgr.h | 207 +++
.../arm/mali-c720/mali-c720-registers-modules.c | 148 ++
.../arm/mali-c720/mali-c720-registers-modules.h | 136 ++
.../arm/mali-c720/mali-c720-registers-top.c | 173 ++
.../arm/mali-c720/mali-c720-registers-top.h | 228 +++
.../platform/arm/mali-c720/mali-c720-registers.c | 57 +
.../platform/arm/mali-c720/mali-c720-registers.h | 84 +
.../media/platform/arm/mali-c720/mali-c720-stats.c | 730 ++++++++
.../media/platform/arm/mali-c720/mali-c720-tpg.c | 581 ++++++
.../platform/arm/mali-c720/mali-c720-vision-pipe.c | 260 +++
drivers/media/v4l2-core/v4l2-ioctl.c | 2 +
include/uapi/linux/media-bus-format.h | 6 +-
include/uapi/linux/media/arm/mali-c720-config.h | 738 ++++++++
include/uapi/linux/v4l2-controls.h | 6 +
include/uapi/linux/videodev2.h | 4 +
49 files changed, 15724 insertions(+), 4 deletions(-)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261113-b4-initial-upstream-candidate-fce192163026
Best regards,
--
Anthony McGivern <Anthony.McGivern@arm.com>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 01/24] media: uapi: Add 24-bit Bayer media bus formats
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 02/24] dt-bindings: media: Add bindings for Arm Mali-C720 Anthony McGivern
` (22 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
The Mali-C720 ISP processes Bayer data on a 24-bit internal bus. Add
media bus format codes for all four Bayer orders and document their
data layout.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../userspace-api/media/v4l/subdev-formats.rst | 289 ++++++++++++++++++++-
include/uapi/linux/media-bus-format.h | 6 +-
2 files changed, 291 insertions(+), 4 deletions(-)
diff --git a/Documentation/userspace-api/media/v4l/subdev-formats.rst b/Documentation/userspace-api/media/v4l/subdev-formats.rst
index c9999b929773b244290b16280b180a9d4f0ff609..6190a1381a4807a7d81d7a9900ea2831606aef30 100644
--- a/Documentation/userspace-api/media/v4l/subdev-formats.rst
+++ b/Documentation/userspace-api/media/v4l/subdev-formats.rst
@@ -2821,11 +2821,11 @@ organization is given as an example for the first pixel only.
\tiny
\setlength{\tabcolsep}{2pt}
-.. tabularcolumns:: |p{6.0cm}|p{0.7cm}|p{0.3cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|
+.. tabularcolumns:: |p{6.0cm}|p{0.7cm}|p{0.3cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|
.. _v4l2-mbus-pixelcode-bayer:
-.. cssclass: longtable
+.. cssclass:: longtable
.. flat-table:: Bayer Formats
:header-rows: 2
@@ -2834,10 +2834,14 @@ organization is given as an example for the first pixel only.
* - Identifier
- Code
-
- - :cspan:`19` Data organization
+ - :cspan:`23` Data organization
* -
-
- Bit
+ - 23
+ - 22
+ - 21
+ - 20
- 19
- 18
- 17
@@ -2875,6 +2879,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`7`
- b\ :sub:`6`
- b\ :sub:`5`
@@ -2900,6 +2908,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`7`
- g\ :sub:`6`
- g\ :sub:`5`
@@ -2925,6 +2937,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`7`
- g\ :sub:`6`
- g\ :sub:`5`
@@ -2950,6 +2966,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- r\ :sub:`7`
- r\ :sub:`6`
- r\ :sub:`5`
@@ -2975,6 +2995,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`7`
- b\ :sub:`6`
- b\ :sub:`5`
@@ -3000,6 +3024,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`7`
- g\ :sub:`6`
- g\ :sub:`5`
@@ -3025,6 +3053,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`7`
- g\ :sub:`6`
- g\ :sub:`5`
@@ -3050,6 +3082,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- r\ :sub:`7`
- r\ :sub:`6`
- r\ :sub:`5`
@@ -3075,6 +3111,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`7`
- b\ :sub:`6`
- b\ :sub:`5`
@@ -3100,6 +3140,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`7`
- g\ :sub:`6`
- g\ :sub:`5`
@@ -3125,6 +3169,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`7`
- g\ :sub:`6`
- g\ :sub:`5`
@@ -3150,6 +3198,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- r\ :sub:`7`
- r\ :sub:`6`
- r\ :sub:`5`
@@ -3175,6 +3227,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- 0
- 0
- 0
@@ -3198,6 +3254,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`7`
- b\ :sub:`6`
- b\ :sub:`5`
@@ -3223,6 +3283,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`7`
- b\ :sub:`6`
- b\ :sub:`5`
@@ -3246,6 +3310,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- 0
- 0
- 0
@@ -3271,6 +3339,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`9`
- b\ :sub:`8`
- b\ :sub:`7`
@@ -3294,6 +3366,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`1`
- b\ :sub:`0`
- 0
@@ -3319,6 +3395,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`1`
- b\ :sub:`0`
- 0
@@ -3342,6 +3422,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`9`
- b\ :sub:`8`
- b\ :sub:`7`
@@ -3365,6 +3449,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`9`
- b\ :sub:`8`
- b\ :sub:`7`
@@ -3390,6 +3478,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`9`
- g\ :sub:`8`
- g\ :sub:`7`
@@ -3415,6 +3507,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`9`
- g\ :sub:`8`
- g\ :sub:`7`
@@ -3440,6 +3536,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- r\ :sub:`9`
- r\ :sub:`8`
- r\ :sub:`7`
@@ -3463,6 +3563,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`11`
- b\ :sub:`10`
- b\ :sub:`9`
@@ -3488,6 +3592,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`11`
- g\ :sub:`10`
- g\ :sub:`9`
@@ -3513,6 +3621,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`11`
- g\ :sub:`10`
- g\ :sub:`9`
@@ -3538,6 +3650,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- r\ :sub:`11`
- r\ :sub:`10`
- r\ :sub:`9`
@@ -3561,6 +3677,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`13`
- b\ :sub:`12`
- b\ :sub:`11`
@@ -3586,6 +3706,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`13`
- g\ :sub:`12`
- g\ :sub:`11`
@@ -3611,6 +3735,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`13`
- g\ :sub:`12`
- g\ :sub:`11`
@@ -3636,6 +3764,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- r\ :sub:`13`
- r\ :sub:`12`
- r\ :sub:`11`
@@ -3659,6 +3791,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- b\ :sub:`15`
- b\ :sub:`14`
- b\ :sub:`13`
@@ -3684,6 +3820,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`15`
- g\ :sub:`14`
- g\ :sub:`13`
@@ -3709,6 +3849,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- g\ :sub:`15`
- g\ :sub:`14`
- g\ :sub:`13`
@@ -3734,6 +3878,10 @@ organization is given as an example for the first pixel only.
-
-
-
+ -
+ -
+ -
+ -
- r\ :sub:`15`
- r\ :sub:`14`
- r\ :sub:`13`
@@ -3755,6 +3903,10 @@ organization is given as an example for the first pixel only.
- MEDIA_BUS_FMT_SBGGR20_1X20
- 0x3021
-
+ -
+ -
+ -
+ -
- b\ :sub:`19`
- b\ :sub:`18`
- b\ :sub:`17`
@@ -3780,6 +3932,10 @@ organization is given as an example for the first pixel only.
- MEDIA_BUS_FMT_SGBRG20_1X20
- 0x3022
-
+ -
+ -
+ -
+ -
- g\ :sub:`19`
- g\ :sub:`18`
- g\ :sub:`17`
@@ -3805,6 +3961,10 @@ organization is given as an example for the first pixel only.
- MEDIA_BUS_FMT_SGRBG20_1X20
- 0x3023
-
+ -
+ -
+ -
+ -
- g\ :sub:`19`
- g\ :sub:`18`
- g\ :sub:`17`
@@ -3830,6 +3990,129 @@ organization is given as an example for the first pixel only.
- MEDIA_BUS_FMT_SRGGB20_1X20
- 0x3024
-
+ -
+ -
+ -
+ -
+ - r\ :sub:`19`
+ - r\ :sub:`18`
+ - r\ :sub:`17`
+ - r\ :sub:`16`
+ - r\ :sub:`15`
+ - r\ :sub:`14`
+ - r\ :sub:`13`
+ - r\ :sub:`12`
+ - r\ :sub:`11`
+ - r\ :sub:`10`
+ - r\ :sub:`9`
+ - r\ :sub:`8`
+ - r\ :sub:`7`
+ - r\ :sub:`6`
+ - r\ :sub:`5`
+ - r\ :sub:`4`
+ - r\ :sub:`3`
+ - r\ :sub:`2`
+ - r\ :sub:`1`
+ - r\ :sub:`0`
+ * .. _MEDIA-BUS-FMT-SBGGR24-1X24:
+
+ - MEDIA_BUS_FMT_SBGGR24_1X24
+ - 0x3025
+ -
+ - b\ :sub:`23`
+ - b\ :sub:`22`
+ - b\ :sub:`21`
+ - b\ :sub:`20`
+ - b\ :sub:`19`
+ - b\ :sub:`18`
+ - b\ :sub:`17`
+ - b\ :sub:`16`
+ - b\ :sub:`15`
+ - b\ :sub:`14`
+ - b\ :sub:`13`
+ - b\ :sub:`12`
+ - b\ :sub:`11`
+ - b\ :sub:`10`
+ - b\ :sub:`9`
+ - b\ :sub:`8`
+ - b\ :sub:`7`
+ - b\ :sub:`6`
+ - b\ :sub:`5`
+ - b\ :sub:`4`
+ - b\ :sub:`3`
+ - b\ :sub:`2`
+ - b\ :sub:`1`
+ - b\ :sub:`0`
+
+ * .. _MEDIA-BUS-FMT-SGBRG24-1X24:
+
+ - MEDIA_BUS_FMT_SGBRG24_1X24
+ - 0x3026
+ -
+ - g\ :sub:`23`
+ - g\ :sub:`22`
+ - g\ :sub:`21`
+ - g\ :sub:`20`
+ - g\ :sub:`19`
+ - g\ :sub:`18`
+ - g\ :sub:`17`
+ - g\ :sub:`16`
+ - g\ :sub:`15`
+ - g\ :sub:`14`
+ - g\ :sub:`13`
+ - g\ :sub:`12`
+ - g\ :sub:`11`
+ - g\ :sub:`10`
+ - g\ :sub:`9`
+ - g\ :sub:`8`
+ - g\ :sub:`7`
+ - g\ :sub:`6`
+ - g\ :sub:`5`
+ - g\ :sub:`4`
+ - g\ :sub:`3`
+ - g\ :sub:`2`
+ - g\ :sub:`1`
+ - g\ :sub:`0`
+
+ * .. _MEDIA-BUS-FMT-SGRBG24-1X24:
+
+ - MEDIA_BUS_FMT_SGRBG24_1X24
+ - 0x3027
+ -
+ - g\ :sub:`23`
+ - g\ :sub:`22`
+ - g\ :sub:`21`
+ - g\ :sub:`20`
+ - g\ :sub:`19`
+ - g\ :sub:`18`
+ - g\ :sub:`17`
+ - g\ :sub:`16`
+ - g\ :sub:`15`
+ - g\ :sub:`14`
+ - g\ :sub:`13`
+ - g\ :sub:`12`
+ - g\ :sub:`11`
+ - g\ :sub:`10`
+ - g\ :sub:`9`
+ - g\ :sub:`8`
+ - g\ :sub:`7`
+ - g\ :sub:`6`
+ - g\ :sub:`5`
+ - g\ :sub:`4`
+ - g\ :sub:`3`
+ - g\ :sub:`2`
+ - g\ :sub:`1`
+ - g\ :sub:`0`
+
+ * .. _MEDIA-BUS-FMT-SRGGB24-1X24:
+
+ - MEDIA_BUS_FMT_SRGGB24_1X24
+ - 0x3028
+ -
+ - r\ :sub:`23`
+ - r\ :sub:`22`
+ - r\ :sub:`21`
+ - r\ :sub:`20`
- r\ :sub:`19`
- r\ :sub:`18`
- r\ :sub:`17`
diff --git a/include/uapi/linux/media-bus-format.h b/include/uapi/linux/media-bus-format.h
index 6005f033e62c04bdd3dff7ac905f5b921341cd47..892b8c0a945e416c242d97962b99c5673eaa3a50 100644
--- a/include/uapi/linux/media-bus-format.h
+++ b/include/uapi/linux/media-bus-format.h
@@ -124,7 +124,7 @@
#define MEDIA_BUS_FMT_YUV16_1X48 0x202a
#define MEDIA_BUS_FMT_UYYVYY16_0_5X48 0x202b
-/* Bayer - next is 0x3025 */
+/* Bayer - next is 0x3029 */
#define MEDIA_BUS_FMT_SBGGR8_1X8 0x3001
#define MEDIA_BUS_FMT_SGBRG8_1X8 0x3013
#define MEDIA_BUS_FMT_SGRBG8_1X8 0x3002
@@ -161,6 +161,10 @@
#define MEDIA_BUS_FMT_SGBRG20_1X20 0x3022
#define MEDIA_BUS_FMT_SGRBG20_1X20 0x3023
#define MEDIA_BUS_FMT_SRGGB20_1X20 0x3024
+#define MEDIA_BUS_FMT_SBGGR24_1X24 0x3025
+#define MEDIA_BUS_FMT_SGBRG24_1X24 0x3026
+#define MEDIA_BUS_FMT_SGRBG24_1X24 0x3027
+#define MEDIA_BUS_FMT_SRGGB24_1X24 0x3028
/* JPEG compressed formats - next is 0x4002 */
#define MEDIA_BUS_FMT_JPEG_1X8 0x4001
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 02/24] dt-bindings: media: Add bindings for Arm Mali-C720
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
2026-11-24 17:07 ` [PATCH 01/24] media: uapi: Add 24-bit Bayer media bus formats Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:18 ` sashiko-bot
2026-11-24 17:07 ` [PATCH 03/24] media: uapi: Add a control ID base for Mali-C720 ISP Anthony McGivern
` (21 subsequent siblings)
23 siblings, 1 reply; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add the device tree binding for the Arm Mali-C720 Image Signal
Processor.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../devicetree/bindings/media/arm,mali-c720.yaml | 134 +++++++++++++++++++++
1 file changed, 134 insertions(+)
diff --git a/Documentation/devicetree/bindings/media/arm,mali-c720.yaml b/Documentation/devicetree/bindings/media/arm,mali-c720.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..3bd261bcefbe371b7b4610afdde8e556b2a2ae22
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/arm,mali-c720.yaml
@@ -0,0 +1,134 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/arm,mali-c720.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ARM Mali-C720 Image Signal Processor
+
+maintainers:
+ - Anthony McGivern <anthony.mcgivern@arm.com>
+
+properties:
+ compatible:
+ const: arm,mali-c720
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ minItems: 1
+ items:
+ - description: ISP main interrupt
+ - description: ISP fault interrupt
+
+ interrupt-names:
+ minItems: 1
+ items:
+ - const: isp
+ - const: fault
+
+ iommus:
+ minItems: 1
+ maxItems: 3
+
+ clocks:
+ items:
+ - description: ISP main processing clock
+
+ clock-names:
+ items:
+ - const: vclk
+
+ resets:
+ items:
+ - description: ISP main processing clock domain reset
+
+ reset-names:
+ items:
+ - const: reset
+
+ memory-region:
+ maxItems: 1
+ description: Reserved memory pool for ISP DMA allocations.
+
+ power-domains:
+ description: Power domain containing the ISP.
+ maxItems: 1
+
+ ports:
+ $ref: /schemas/graph.yaml#/properties/ports
+ description: Parallel video input ports.
+
+ properties:
+ port@0:
+ $ref: /schemas/graph.yaml#/properties/port
+ description: Input port 0
+
+ properties:
+ reg:
+ const: 0
+
+ port@1:
+ $ref: /schemas/graph.yaml#/properties/port
+ description: Input port 1
+
+ properties:
+ reg:
+ const: 1
+
+ port@2:
+ $ref: /schemas/graph.yaml#/properties/port
+ description: Input port 2
+
+ properties:
+ reg:
+ const: 2
+
+ port@3:
+ $ref: /schemas/graph.yaml#/properties/port
+ description: Input port 3
+
+ properties:
+ reg:
+ const: 3
+
+required:
+ - compatible
+ - reg
+ - interrupts
+ - interrupt-names
+ - clocks
+ - clock-names
+ - resets
+ - reset-names
+
+additionalProperties: false
+
+examples:
+ - |
+ mali_c720: isp@400000 {
+ compatible = "arm,mali-c720";
+ reg = <0x400000 0x200000>;
+ clocks = <&clk 0>;
+ clock-names = "vclk";
+ resets = <&resets 0>;
+ reset-names = "reset";
+ memory-region = <&isp_reserved>;
+ interrupts = <0>;
+ interrupt-names = "isp";
+ power-domains = <&power 0>;
+
+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@0 {
+ reg = <0>;
+ isp_in: endpoint {
+ remote-endpoint = <&csi2_rx_out>;
+ };
+ };
+ };
+ };
+...
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 03/24] media: uapi: Add a control ID base for Mali-C720 ISP
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
2026-11-24 17:07 ` [PATCH 01/24] media: uapi: Add 24-bit Bayer media bus formats Anthony McGivern
2026-11-24 17:07 ` [PATCH 02/24] dt-bindings: media: Add bindings for Arm Mali-C720 Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 04/24] media: mali-c720: Add register access helpers Anthony McGivern
` (20 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add the base definition for custom controls exposed by
the Mali-C720 ISP driver.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
include/uapi/linux/v4l2-controls.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index d17e41d51d2ec1ccb9e8ceb3ccc89ebc4381a4cd..3fdc01200c8c3a41644e32ac12bfeddf330afe1a 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -255,6 +255,12 @@ enum v4l2_colorfx {
*/
#define V4L2_CID_USER_IT6625_BASE (V4L2_CID_USER_BASE + 0x1250)
+/*
+ * The base for the Arm Mali-C720 ISP driver controls.
+ * We reserve 16 controls for this driver.
+ */
+#define V4L2_CID_USER_MALI_C720_BASE (V4L2_CID_USER_BASE + 0x1260)
+
/* MPEG-class control IDs */
/* The MPEG controls are applicable to all codec controls
* and the 'MPEG' part of the define is historical */
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 04/24] media: mali-c720: Add register access helpers
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (2 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 03/24] media: uapi: Add a control ID base for Mali-C720 ISP Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 05/24] media: mali-c720: Add hardware identification Anthony McGivern
` (19 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add register-field and indexed-group definitions for the ISP registers.
Represent register layouts using structures to accommodate future
hardware revisions.
Provide access helpers for the memory-mapped global registers and the
in-memory context register image used by the ISP's configuration DMA
engine (CDMA).
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../platform/arm/mali-c720/mali-c720-common.h | 45 ++++
.../arm/mali-c720/mali-c720-register-access.c | 205 ++++++++++++++++++
.../arm/mali-c720/mali-c720-register-access.h | 55 +++++
.../arm/mali-c720/mali-c720-registers-ctx-mgr.c | 226 ++++++++++++++++++++
.../arm/mali-c720/mali-c720-registers-ctx-mgr.h | 207 +++++++++++++++++++
.../arm/mali-c720/mali-c720-registers-modules.c | 148 +++++++++++++
.../arm/mali-c720/mali-c720-registers-modules.h | 136 ++++++++++++
.../arm/mali-c720/mali-c720-registers-top.c | 173 ++++++++++++++++
.../arm/mali-c720/mali-c720-registers-top.h | 228 +++++++++++++++++++++
.../platform/arm/mali-c720/mali-c720-registers.c | 50 +++++
.../platform/arm/mali-c720/mali-c720-registers.h | 81 ++++++++
11 files changed, 1554 insertions(+)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
new file mode 100644
index 0000000000000000000000000000000000000000..7cf7380202a4587b844b66b45bfe76f6bac61635
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_COMMON_H
+#define MALI_C720_COMMON_H
+
+#include <linux/io.h>
+#include <linux/mutex.h>
+#include <linux/refcount.h>
+#include <linux/spinlock.h>
+
+#include "mali-c720-register-access.h"
+#include "mali-c720-registers.h"
+#include "mali-c720-registers-top.h"
+#include "mali-c720-registers-ctx-mgr.h"
+#include "mali-c720-registers-modules.h"
+
+struct mali_c720_context_regs {
+ dma_addr_t dma_handle;
+ u8 *base;
+ size_t size;
+
+ /* Serializes allocation, initialization and final release. */
+ struct mutex allocation_lock;
+ refcount_t users;
+};
+
+struct mali_c720_context {
+ struct mali_c720 *mali_c720;
+ struct mali_c720_context_regs regs;
+};
+
+struct mali_c720 {
+ struct device *dev;
+ u8 __iomem *base;
+ resource_size_t mmio_size;
+
+ struct mali_c720_registers registers;
+};
+
+#endif /* MALI_C720_COMMON_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-register-access.c b/drivers/media/platform/arm/mali-c720/mali-c720-register-access.c
new file mode 100644
index 0000000000000000000000000000000000000000..a7df7761be8cd5371f651fbb1753a60dd5255af3
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-register-access.c
@@ -0,0 +1,205 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/align.h>
+
+#include "mali-c720-common.h"
+
+static __le32 *mali_c720_ctx_reg_addr(struct mali_c720_context *ctx,
+ unsigned int addr)
+{
+ return (__le32 *)(ctx->regs.base + addr);
+}
+
+/*
+ * System IO
+ *
+ * The Mali-C720 has a shared global register space for settings such as
+ * context manager, faults, interrupts, etc. Each context then has a DMA
+ * allocated configuration space for pipeline registers. The ISP has a
+ * configuration DMA (CDMA) engine that will automatically load the context
+ * configuration space upon frame start. In both cases we can write to these
+ * normally, though care should be taken with the context space to ensure any
+ * access does not coincide with a frame start, causing CDMA to read a
+ * partially-applied configuration.
+ */
+
+static int mali_c720_mmio_check_addr(struct mali_c720 *mali_c720, u32 addr)
+{
+ int ret;
+
+ ret = WARN_ON_ONCE(!IS_ALIGNED(addr, sizeof(u32)));
+ if (ret)
+ return ret;
+
+ ret = WARN_ON_ONCE((u64)addr + sizeof(u32) > mali_c720->mmio_size);
+ if (ret)
+ return ret;
+
+ ret = WARN_ON_ONCE(mali_c720->registers.context_offset &&
+ (u64)addr + sizeof(u32) > mali_c720->registers.context_offset);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+u32 mali_c720_read_raw(struct mali_c720 *mali_c720, u32 addr)
+{
+ if (mali_c720_mmio_check_addr(mali_c720, addr))
+ return 0;
+
+ return readl(mali_c720->base + addr);
+}
+
+static void mali_c720_write_reg_raw(struct mali_c720 *mali_c720, u32 addr, u32 val)
+{
+ if (mali_c720_mmio_check_addr(mali_c720, addr))
+ return;
+
+ writel(val, mali_c720->base + addr);
+}
+
+u32 mali_c720_group_read(struct mali_c720 *mali_c720, u32 base,
+ const struct mali_c720_reg_field *field)
+{
+ if (WARN_ON_ONCE(field->shift > MALI_C720_REG_MAX_SHIFT))
+ return 0;
+
+ return (mali_c720_read_raw(mali_c720, base + field->offset) & field->mask) >>
+ field->shift;
+}
+
+void mali_c720_group_write(struct mali_c720 *mali_c720, u32 base,
+ const struct mali_c720_reg_field *field, u32 val)
+{
+ u32 addr = base + field->offset;
+ u32 reg;
+
+ if (WARN_ON_ONCE(field->shift > MALI_C720_REG_MAX_SHIFT))
+ return;
+ if (mali_c720_mmio_check_addr(mali_c720, addr))
+ return;
+
+ reg = readl(mali_c720->base + addr) & ~field->mask;
+ reg |= (val << field->shift) & field->mask;
+ writel(reg, mali_c720->base + addr);
+}
+
+u32 mali_c720_read(struct mali_c720 *mali_c720, const struct mali_c720_reg_field *field)
+{
+ return mali_c720_group_read(mali_c720, 0, field);
+}
+
+void mali_c720_write(struct mali_c720 *mali_c720, const struct mali_c720_reg_field *field, u32 val)
+{
+ mali_c720_group_write(mali_c720, 0, field, val);
+}
+
+void mali_c720_write_raw(struct mali_c720 *mali_c720, const struct mali_c720_reg_field *field,
+ u32 val)
+{
+ mali_c720_write_reg_raw(mali_c720, field->offset, val);
+}
+
+u32 mali_c720_irq_read(struct mali_c720 *mali_c720, const struct mali_c720_reg_field *field,
+ enum mali_c720_irq_type type)
+{
+ return mali_c720_group_read(mali_c720, type, field);
+}
+
+void mali_c720_irq_write(struct mali_c720 *mali_c720, const struct mali_c720_reg_field *field,
+ enum mali_c720_irq_type type, u32 val)
+{
+ if (WARN_ON_ONCE(field->shift > MALI_C720_REG_MAX_SHIFT))
+ return;
+
+ /* RAWSTAT is write-one-to-clear: acknowledge only the selected bits. */
+ if (type == MALI_C720_IRQ_RAWSTAT)
+ mali_c720_write_reg_raw(mali_c720, field->offset + type,
+ (val << field->shift) & field->mask);
+ else
+ mali_c720_group_write(mali_c720, type, field, val);
+}
+
+static int mali_c720_ctx_check_addr(struct mali_c720_context *ctx, u32 addr)
+{
+ int ret;
+
+ ret = WARN_ON_ONCE(!IS_ALIGNED(addr, sizeof(__le32)));
+ if (ret)
+ return ret;
+
+ ret = WARN_ON_ONCE(addr < ctx->mali_c720->registers.context_offset ||
+ (u64)addr + sizeof(__le32) > ctx->regs.size);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+u32 mali_c720_ctx_read_raw(struct mali_c720_context *ctx, u32 addr)
+{
+ __le32 *ptr;
+
+ if (mali_c720_ctx_check_addr(ctx, addr))
+ return 0;
+
+ ptr = mali_c720_ctx_reg_addr(ctx, addr);
+ return le32_to_cpu(*ptr);
+}
+
+void mali_c720_ctx_write_raw(struct mali_c720_context *ctx, u32 addr, u32 val)
+{
+ __le32 *ptr;
+
+ if (mali_c720_ctx_check_addr(ctx, addr))
+ return;
+
+ ptr = mali_c720_ctx_reg_addr(ctx, addr);
+
+ *ptr = cpu_to_le32(val);
+}
+
+u32 mali_c720_ctx_group_read(struct mali_c720_context *ctx, u32 base,
+ const struct mali_c720_reg_field *field)
+{
+ if (WARN_ON_ONCE(field->shift > MALI_C720_REG_MAX_SHIFT))
+ return 0;
+
+ return (mali_c720_ctx_read_raw(ctx, base + field->offset) & field->mask) >> field->shift;
+}
+
+void mali_c720_ctx_group_write(struct mali_c720_context *ctx, u32 base,
+ const struct mali_c720_reg_field *field, u32 val)
+{
+ u32 addr = base + field->offset;
+ __le32 *ptr;
+ u32 reg;
+
+ if (WARN_ON_ONCE(field->shift > MALI_C720_REG_MAX_SHIFT))
+ return;
+ if (mali_c720_ctx_check_addr(ctx, addr))
+ return;
+
+ ptr = mali_c720_ctx_reg_addr(ctx, addr);
+
+ reg = le32_to_cpu(*ptr) & ~field->mask;
+ reg |= (val << field->shift) & field->mask;
+ *ptr = cpu_to_le32(reg);
+}
+
+u32 mali_c720_ctx_read(struct mali_c720_context *ctx, const struct mali_c720_reg_field *field)
+{
+ return mali_c720_ctx_group_read(ctx, 0, field);
+}
+
+void mali_c720_ctx_write(struct mali_c720_context *ctx, const struct mali_c720_reg_field *field,
+ u32 val)
+{
+ mali_c720_ctx_group_write(ctx, 0, field, val);
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-register-access.h b/drivers/media/platform/arm/mali-c720/mali-c720-register-access.h
new file mode 100644
index 0000000000000000000000000000000000000000..b96d404d594290d0d61b835eede071b2d86dca4f
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-register-access.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_REGISTER_ACCESS_H
+#define MALI_C720_REGISTER_ACCESS_H
+
+#include <linux/types.h>
+
+struct mali_c720;
+struct mali_c720_context;
+struct mali_c720_reg_field;
+
+#define MALI_C720_REG_MAX_SHIFT 31
+
+enum mali_c720_irq_type {
+ MALI_C720_IRQ_RAWSTAT = 0x4,
+ MALI_C720_IRQ_MASK = 0x8,
+ MALI_C720_IRQ_STATUS = 0xc,
+};
+
+/* HW register access */
+u32 mali_c720_read_raw(struct mali_c720 *mali_c720, u32 addr);
+u32 mali_c720_read(struct mali_c720 *mali_c720, const struct mali_c720_reg_field *field);
+void mali_c720_write(struct mali_c720 *mali_c720, const struct mali_c720_reg_field *field, u32 val);
+void mali_c720_write_raw(struct mali_c720 *mali_c720, const struct mali_c720_reg_field *field,
+ u32 val);
+
+/* Group register access */
+u32 mali_c720_group_read(struct mali_c720 *mali_c720, u32 base,
+ const struct mali_c720_reg_field *field);
+void mali_c720_group_write(struct mali_c720 *mali_c720, u32 base,
+ const struct mali_c720_reg_field *field, u32 val);
+
+/* IRQ register access */
+u32 mali_c720_irq_read(struct mali_c720 *mali_c720, const struct mali_c720_reg_field *field,
+ enum mali_c720_irq_type type);
+void mali_c720_irq_write(struct mali_c720 *mali_c720, const struct mali_c720_reg_field *field,
+ enum mali_c720_irq_type type, u32 val);
+
+/* SW register access */
+u32 mali_c720_ctx_read(struct mali_c720_context *ctx, const struct mali_c720_reg_field *field);
+void mali_c720_ctx_write(struct mali_c720_context *ctx, const struct mali_c720_reg_field *field,
+ u32 val);
+u32 mali_c720_ctx_group_read(struct mali_c720_context *ctx, u32 base,
+ const struct mali_c720_reg_field *field);
+void mali_c720_ctx_group_write(struct mali_c720_context *ctx, u32 base,
+ const struct mali_c720_reg_field *field, u32 val);
+u32 mali_c720_ctx_read_raw(struct mali_c720_context *ctx, u32 addr);
+void mali_c720_ctx_write_raw(struct mali_c720_context *ctx, u32 addr, u32 val);
+
+#endif /* MALI_C720_REGISTER_ACCESS_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-registers-ctx-mgr.c b/drivers/media/platform/arm/mali-c720/mali-c720-registers-ctx-mgr.c
new file mode 100644
index 0000000000000000000000000000000000000000..79e7bf949f1c7ac35968cdcd26f2e21f8ba8f9ab
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-registers-ctx-mgr.c
@@ -0,0 +1,226 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/bits.h>
+
+#include "mali-c720-registers-ctx-mgr.h"
+
+static const struct mali_c720_cm_capabilities caps_r0 = {
+ .num_inputs = 4,
+ .num_input_streams = 4,
+ .cdma_sg_size = 32,
+ .num_raw_buffers = 64,
+ .num_slots = 20,
+ .num_out_buffers = 208,
+ .input_fifo_size = 4096,
+ .output_fifo_size = 2048,
+};
+
+static const struct mali_c720_cm_fifo_regs input_fifo_r0 = {
+ .group = { .offset = 0x6020, .size = 0x10 },
+ .base_address = { .offset = 0x0, .mask = GENMASK(15, 0), .shift = 0 },
+ .size = { .offset = 0x0, .mask = GENMASK(31, 16), .shift = 16 },
+};
+
+static const struct mali_c720_cm_temper_fifo_regs temper_fifo_r0 = {
+ .w_fifo_base_address = { .offset = 0x6140, .mask = GENMASK(15, 0), .shift = 0 },
+ .w_fifo_size = { .offset = 0x6140, .mask = GENMASK(31, 16), .shift = 16 },
+ .r_fifo_base_address = { .offset = 0x6150, .mask = GENMASK(15, 0), .shift = 0 },
+ .r_fifo_size = { .offset = 0x6150, .mask = GENMASK(31, 16), .shift = 16 },
+};
+
+static const struct mali_c720_cm_job_control_regs job_control_r0 = {
+ .sch_command = { .offset = 0x6160, .mask = GENMASK(7, 0), .shift = 0 },
+ .sch_command_slot = { .offset = 0x6160, .mask = GENMASK(15, 8), .shift = 8 },
+ .sch_status_arch = { .offset = 0x6164, .mask = GENMASK(2, 0), .shift = 0 },
+ .m2m_queue_command = { .offset = 0x616c, .mask = GENMASK(1, 0), .shift = 0 },
+ .m2m_queue_command_slot_no = { .offset = 0x616c, .mask = GENMASK(15, 8), .shift = 8 },
+};
+
+static const struct mali_c720_cm_input_regs input_r0 = {
+ .group = { .offset = 0x62fc, .size = 0x20 },
+ .command = { .offset = 0x0, .mask = GENMASK(7, 0), .shift = 0 },
+ .status_arch = { .offset = 0x4, .mask = GENMASK(2, 0), .shift = 0 },
+ .pixel_size = { .offset = 0xc, .mask = GENMASK(5, 0), .shift = 0 },
+ .data_format = { .offset = 0xc, .mask = GENMASK(9, 7), .shift = 7 },
+ .nonsecure = { .offset = 0xc, .mask = BIT(10), .shift = 10 },
+ .stream_id = { .offset = 0xc, .mask = GENMASK(15, 11), .shift = 11 },
+ .data_type1_enable = { .offset = 0xc, .mask = BIT(16), .shift = 16 },
+ .data_type2_enable = { .offset = 0xc, .mask = BIT(17), .shift = 17 },
+ .crop_enable = { .offset = 0xc, .mask = BIT(19), .shift = 19 },
+ .drop_oldest = { .offset = 0xc, .mask = BIT(20), .shift = 20 },
+ .flow_control = { .offset = 0xc, .mask = BIT(21), .shift = 21 },
+ .drop_if_error = { .offset = 0xc, .mask = BIT(22), .shift = 22 },
+ .check_parity = { .offset = 0xc, .mask = BIT(23), .shift = 23 },
+ .buffer_pool = { .offset = 0xc, .mask = GENMASK(31, 24), .shift = 24 },
+ .data_type1 = { .offset = 0x10, .mask = GENMASK(7, 0), .shift = 0 },
+ .data_type2 = { .offset = 0x10, .mask = GENMASK(15, 8), .shift = 8 },
+ .start_x = { .offset = 0x14, .mask = GENMASK(15, 0), .shift = 0 },
+ .start_y = { .offset = 0x14, .mask = GENMASK(31, 16), .shift = 16 },
+ .size_x = { .offset = 0x18, .mask = GENMASK(15, 0), .shift = 0 },
+ .size_y = { .offset = 0x18, .mask = GENMASK(31, 16), .shift = 16 },
+ .write_threshold = { .offset = 0x1c, .mask = GENMASK(15, 0), .shift = 0 },
+ .write_threshold_sec = { .offset = 0x1c, .mask = GENMASK(31, 16), .shift = 16 },
+};
+
+static const struct mali_c720_cm_slot_regs slot_r0 = {
+ .group = { .offset = 0x6500, .size = 0x40 },
+ .mode = { .offset = 0x0, .mask = GENMASK(2, 0), .shift = 0 },
+ .timeout_enable = { .offset = 0x0, .mask = BIT(3), .shift = 3 },
+ .schedule_priority = { .offset = 0x0, .mask = BIT(8), .shift = 8 },
+ .nonsecure = { .offset = 0x0, .mask = BIT(10), .shift = 10 },
+ .stream_id = { .offset = 0x0, .mask = GENMASK(15, 11), .shift = 11 },
+ .status = { .offset = 0x0, .mask = GENMASK(26, 24), .shift = 24 },
+ .delay_mant = { .offset = 0x4, .mask = GENMASK(11, 0), .shift = 0 },
+ .delay_exp = { .offset = 0x4, .mask = GENMASK(15, 12), .shift = 12 },
+ .slot_event = { .offset = 0x4, .mask = GENMASK(19, 16), .shift = 16 },
+ .slot_input_0 = { .offset = 0x8, .mask = GENMASK(7, 0), .shift = 0 },
+ .slot_input_1 = { .offset = 0x8, .mask = GENMASK(15, 8), .shift = 8 },
+ .timeout_mant = { .offset = 0xc, .mask = GENMASK(11, 0), .shift = 0 },
+ .timeout_exp = { .offset = 0xc, .mask = GENMASK(15, 12), .shift = 12 },
+ .pool_roi0 = { .offset = 0x10, .mask = GENMASK(7, 0), .shift = 0 },
+ .pool_roi1 = { .offset = 0x10, .mask = GENMASK(15, 8), .shift = 8 },
+ .pool_roi2 = { .offset = 0x10, .mask = GENMASK(23, 16), .shift = 16 },
+ .pool_raw = { .offset = 0x10, .mask = GENMASK(31, 24), .shift = 24 },
+ .pool_scaler0_rgb = { .offset = 0x14, .mask = GENMASK(7, 0), .shift = 0 },
+ .pool_scaler0_yuv = { .offset = 0x14, .mask = GENMASK(15, 8), .shift = 8 },
+ .pool_scaler1_rgb = { .offset = 0x14, .mask = GENMASK(23, 16), .shift = 16 },
+ .pool_scaler1_yuv = { .offset = 0x14, .mask = GENMASK(31, 24), .shift = 24 },
+ .pool_scaler2_rgb = { .offset = 0x18, .mask = GENMASK(7, 0), .shift = 0 },
+ .pool_scaler2_yuv = { .offset = 0x18, .mask = GENMASK(15, 8), .shift = 8 },
+ .pool_scaler3_rgb = { .offset = 0x18, .mask = GENMASK(23, 16), .shift = 16 },
+ .pool_scaler3_yuv = { .offset = 0x18, .mask = GENMASK(31, 24), .shift = 24 },
+ .pool_gdc_main = { .offset = 0x1c, .mask = GENMASK(7, 0), .shift = 0 },
+ .pool_gdc_roi0 = { .offset = 0x1c, .mask = GENMASK(15, 8), .shift = 8 },
+ .pool_gdc_roi1 = { .offset = 0x1c, .mask = GENMASK(23, 16), .shift = 16 },
+ .pool_gdc_roi2 = { .offset = 0x1c, .mask = GENMASK(31, 24), .shift = 24 },
+ .pool_pyramid = { .offset = 0x20, .mask = GENMASK(7, 0), .shift = 0 },
+ .pool_consistency = { .offset = 0x20, .mask = GENMASK(15, 8), .shift = 8 },
+ .crc = { .offset = 0x24, .mask = GENMASK(31, 0), .shift = 0 },
+};
+
+static const struct mali_c720_cm_buffer_regs buffer_r0 = {
+ .out_group = { .offset = 0x12000, .size = 0x80 },
+ .raw_group = { .offset = 0x10000, .size = 0x80 },
+ .temper_group = { .offset = 0x18800, .size = 0x80 },
+ .state = { .offset = 0x0, .mask = GENMASK(3, 0), .shift = 0 },
+ .state_request = { .offset = 0x0, .mask = GENMASK(7, 4), .shift = 4 },
+ .data_format = { .offset = 0x4, .mask = GENMASK(7, 0), .shift = 0 },
+ .data_align = { .offset = 0x4, .mask = GENMASK(9, 8), .shift = 8 },
+ .nonsecure = { .offset = 0x4, .mask = BIT(10), .shift = 10 },
+ .stream_id = { .offset = 0x4, .mask = GENMASK(15, 11), .shift = 11 },
+ .data_layout = { .offset = 0x4, .mask = BIT(16), .shift = 16 },
+ .crc_check = { .offset = 0x4, .mask = BIT(17), .shift = 17 },
+ .pool = { .offset = 0x4, .mask = BIT(18), .shift = 18 },
+ .mode = { .offset = 0x4, .mask = GENMASK(21, 19), .shift = 19 },
+ .block_size = { .offset = 0x4, .mask = GENMASK(23, 22), .shift = 22 },
+ .base_address_low = { .offset = 0x8, .mask = GENMASK(31, 0), .shift = 0 },
+ .base_address_high = { .offset = 0xc, .mask = GENMASK(31, 0), .shift = 0 },
+ .size = { .offset = 0x10, .mask = GENMASK(31, 0), .shift = 0 },
+ .plane2_offset = { .offset = 0x14, .mask = GENMASK(31, 0), .shift = 0 },
+ .plane3_offset = { .offset = 0x18, .mask = GENMASK(31, 0), .shift = 0 },
+ .plane4_offset = { .offset = 0x1c, .mask = GENMASK(31, 0), .shift = 0 },
+ .line1_offset = { .offset = 0x20, .mask = GENMASK(31, 0), .shift = 0 },
+ .line2_offset = { .offset = 0x24, .mask = GENMASK(31, 0), .shift = 0 },
+ .line3_offset = { .offset = 0x28, .mask = GENMASK(31, 0), .shift = 0 },
+ .line4_offset = { .offset = 0x2c, .mask = GENMASK(31, 0), .shift = 0 },
+ .width = { .offset = 0x30, .mask = GENMASK(15, 0), .shift = 0 },
+ .height = { .offset = 0x30, .mask = GENMASK(31, 16), .shift = 16 },
+ .colorspace = { .offset = 0x34, .mask = GENMASK(3, 0), .shift = 0 },
+ .subsampling = { .offset = 0x34, .mask = GENMASK(5, 4), .shift = 4 },
+ .component_width = { .offset = 0x34, .mask = GENMASK(10, 8), .shift = 8 },
+ .msb_align = { .offset = 0x34, .mask = BIT(11), .shift = 11 },
+ .phase = { .offset = 0x34, .mask = GENMASK(14, 12), .shift = 12 },
+ .height_modulo = { .offset = 0x34, .mask = GENMASK(31, 16), .shift = 16 },
+ .compression = { .offset = 0x38, .mask = GENMASK(31, 0), .shift = 0 },
+ .compression23 = { .offset = 0x3c, .mask = GENMASK(31, 0), .shift = 0 },
+ .descriptor_crc = { .offset = 0x40, .mask = GENMASK(15, 0), .shift = 0 },
+ .frame_no = { .offset = 0x4c, .mask = GENMASK(31, 0), .shift = 0 },
+};
+
+static const struct mali_c720_cm_cdma_slot_regs cdma_slot_r0 = {
+ .group = { .offset = 0x19200, .size = 0x40 },
+ .cdma_state = { .offset = 0x0, .mask = GENMASK(1, 0), .shift = 0 },
+ .cdma_state_request = { .offset = 0x0, .mask = GENMASK(5, 4), .shift = 4 },
+ .infinite = { .offset = 0x0, .mask = BIT(8), .shift = 8 },
+ .nonsecure = { .offset = 0x0, .mask = BIT(10), .shift = 10 },
+ .stream_id = { .offset = 0x0, .mask = GENMASK(15, 11), .shift = 11 },
+ .transfer_size = { .offset = 0x4, .mask = GENMASK(31, 0), .shift = 0 },
+ .units_low = { .offset = 0x8, .mask = GENMASK(31, 0), .shift = 0 },
+ .units_high = { .offset = 0xc, .mask = GENMASK(31, 0), .shift = 0 },
+ .base_address_low = { .offset = 0x10, .mask = GENMASK(31, 0), .shift = 0 },
+ .base_address_high = { .offset = 0x14, .mask = GENMASK(31, 0), .shift = 0 },
+ .ld_sg_count = { .offset = 0x18, .mask = GENMASK(5, 0), .shift = 0 },
+ .st_sg_count = { .offset = 0x18, .mask = GENMASK(13, 8), .shift = 8 },
+ .alt_transfer_size = { .offset = 0x1c, .mask = GENMASK(31, 0), .shift = 0 },
+ .alt_base_address_low = { .offset = 0x20, .mask = GENMASK(31, 0), .shift = 0 },
+ .alt_base_address_high = { .offset = 0x24, .mask = GENMASK(31, 0), .shift = 0 },
+ .crc = { .offset = 0x28, .mask = GENMASK(15, 0), .shift = 0 },
+};
+
+static const struct mali_c720_cm_load_out_fifo_regs load_out_fifo_r0 = {
+ .scaler_group = { .offset = 0x808a0, .size = 0x10 },
+ .roi_group = { .offset = 0x80810, .size = 0x10 },
+ .pyramid_group = { .offset = 0x80a20, .size = 0x10 },
+ .raw_group = { .offset = 0x80a60, .size = 0x10 },
+ .base_address = { .offset = 0x0, .mask = GENMASK(15, 0), .shift = 0 },
+ .size = { .offset = 0x0, .mask = GENMASK(31, 16), .shift = 16 },
+};
+
+static const struct mali_c720_cm_sg_regs load_cdma_sg_load_r0 = {
+ .group = { .offset = 0x80a80, .size = 0x8 },
+ .isp_address = { .offset = 0x0, .mask = GENMASK(19, 0), .shift = 0 },
+ .length_low = { .offset = 0x0, .mask = GENMASK(31, 20), .shift = 20 },
+ .length_high = { .offset = 0x4, .mask = GENMASK(3, 0), .shift = 0 },
+ .axi_address = { .offset = 0x4, .mask = GENMASK(23, 4), .shift = 4 },
+ .alt_address = { .offset = 0x4, .mask = BIT(31), .shift = 31 },
+};
+
+static const struct mali_c720_cm_sg_crc_regs load_cdma_sg_load_crc_r0 = {
+ .cdma_sg_crc = { .offset = 0x80b80, .mask = GENMASK(15, 0), .shift = 0 },
+};
+
+static const struct mali_c720_cm_sg_regs load_cdma_sg_store_r0 = {
+ .group = { .offset = 0x80ba0, .size = 0x8 },
+ .isp_address = { .offset = 0x0, .mask = GENMASK(19, 0), .shift = 0 },
+ .length_low = { .offset = 0x0, .mask = GENMASK(31, 20), .shift = 20 },
+ .length_high = { .offset = 0x4, .mask = GENMASK(3, 0), .shift = 0 },
+ .axi_address = { .offset = 0x4, .mask = GENMASK(23, 4), .shift = 4 },
+ .alt_address = { .offset = 0x4, .mask = BIT(31), .shift = 31 },
+};
+
+static const struct mali_c720_cm_sg_crc_regs load_cdma_sg_store_crc_r0 = {
+ .cdma_sg_crc = { .offset = 0x80ca0, .mask = GENMASK(15, 0), .shift = 0 },
+};
+
+static const struct mali_c720_cm_fifo_regs reader_fifo_r0 = {
+ .base_address = { .offset = 0x0, .mask = GENMASK(15, 0), .shift = 0 },
+ .size = { .offset = 0x0, .mask = GENMASK(31, 16), .shift = 16 },
+ .group = { .offset = 0x6120, .size = 0x10 },
+};
+
+static const struct mali_c720_ctx_mgr_regs mali_c720_ctx_mgr_regs_r0 = {
+ .caps = &caps_r0,
+ .input_fifo = &input_fifo_r0,
+ .temper_fifo = &temper_fifo_r0,
+ .job_control = &job_control_r0,
+ .input = &input_r0,
+ .slot = &slot_r0,
+ .buffer = &buffer_r0,
+ .cdma_slot = &cdma_slot_r0,
+ .load_out_fifo = &load_out_fifo_r0,
+ .load_cdma_sg_load = &load_cdma_sg_load_r0,
+ .load_cdma_sg_load_crc = &load_cdma_sg_load_crc_r0,
+ .load_cdma_sg_store = &load_cdma_sg_store_r0,
+ .load_cdma_sg_store_crc = &load_cdma_sg_store_crc_r0,
+ .reader_fifo = &reader_fifo_r0,
+};
+
+const struct mali_c720_ctx_mgr_regs *mali_c720_get_ctx_mgr_regs(void)
+{
+ return &mali_c720_ctx_mgr_regs_r0;
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-registers-ctx-mgr.h b/drivers/media/platform/arm/mali-c720/mali-c720-registers-ctx-mgr.h
new file mode 100644
index 0000000000000000000000000000000000000000..7a8100915cc9fa8666b90baf207e672867c59e5a
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-registers-ctx-mgr.h
@@ -0,0 +1,207 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_REGISTERS_CTX_MGR_H
+#define MALI_C720_REGISTERS_CTX_MGR_H
+
+#include "mali-c720-registers.h"
+
+struct mali_c720_cm_capabilities {
+ u32 num_inputs;
+ u32 num_input_streams;
+ u32 cdma_sg_size;
+ u32 num_raw_buffers;
+ u32 num_slots;
+ u32 num_out_buffers;
+ u32 input_fifo_size;
+ u32 output_fifo_size;
+};
+
+struct mali_c720_cm_fifo_regs {
+ struct mali_c720_group_regs group;
+ struct mali_c720_reg_field base_address;
+ struct mali_c720_reg_field size;
+};
+
+struct mali_c720_cm_temper_fifo_regs {
+ struct mali_c720_reg_field w_fifo_base_address;
+ struct mali_c720_reg_field w_fifo_size;
+ struct mali_c720_reg_field r_fifo_base_address;
+ struct mali_c720_reg_field r_fifo_size;
+};
+
+struct mali_c720_cm_job_control_regs {
+ struct mali_c720_reg_field sch_command;
+ struct mali_c720_reg_field sch_command_slot;
+ struct mali_c720_reg_field sch_status_arch;
+ struct mali_c720_reg_field m2m_queue_command;
+ struct mali_c720_reg_field m2m_queue_command_slot_no;
+};
+
+struct mali_c720_cm_input_regs {
+ struct mali_c720_group_regs group;
+ struct mali_c720_reg_field command;
+ struct mali_c720_reg_field status_arch;
+ struct mali_c720_reg_field pixel_size;
+ struct mali_c720_reg_field data_format;
+ struct mali_c720_reg_field nonsecure;
+ struct mali_c720_reg_field stream_id;
+ struct mali_c720_reg_field data_type1_enable;
+ struct mali_c720_reg_field data_type2_enable;
+ struct mali_c720_reg_field crop_enable;
+ struct mali_c720_reg_field drop_oldest;
+ struct mali_c720_reg_field flow_control;
+ struct mali_c720_reg_field drop_if_error;
+ struct mali_c720_reg_field check_parity;
+ struct mali_c720_reg_field buffer_pool;
+ struct mali_c720_reg_field data_type1;
+ struct mali_c720_reg_field data_type2;
+ struct mali_c720_reg_field start_x;
+ struct mali_c720_reg_field start_y;
+ struct mali_c720_reg_field size_x;
+ struct mali_c720_reg_field size_y;
+ struct mali_c720_reg_field write_threshold;
+ struct mali_c720_reg_field write_threshold_sec;
+};
+
+struct mali_c720_cm_slot_regs {
+ struct mali_c720_group_regs group;
+ struct mali_c720_reg_field mode;
+ struct mali_c720_reg_field timeout_enable;
+ struct mali_c720_reg_field schedule_priority;
+ struct mali_c720_reg_field nonsecure;
+ struct mali_c720_reg_field stream_id;
+ struct mali_c720_reg_field status;
+ struct mali_c720_reg_field delay_mant;
+ struct mali_c720_reg_field delay_exp;
+ struct mali_c720_reg_field slot_event;
+ struct mali_c720_reg_field slot_input_0;
+ struct mali_c720_reg_field slot_input_1;
+ struct mali_c720_reg_field timeout_mant;
+ struct mali_c720_reg_field timeout_exp;
+ struct mali_c720_reg_field pool_roi0;
+ struct mali_c720_reg_field pool_roi1;
+ struct mali_c720_reg_field pool_roi2;
+ struct mali_c720_reg_field pool_raw;
+ struct mali_c720_reg_field pool_scaler0_rgb;
+ struct mali_c720_reg_field pool_scaler0_yuv;
+ struct mali_c720_reg_field pool_scaler1_rgb;
+ struct mali_c720_reg_field pool_scaler1_yuv;
+ struct mali_c720_reg_field pool_scaler2_rgb;
+ struct mali_c720_reg_field pool_scaler2_yuv;
+ struct mali_c720_reg_field pool_scaler3_rgb;
+ struct mali_c720_reg_field pool_scaler3_yuv;
+ struct mali_c720_reg_field pool_gdc_main;
+ struct mali_c720_reg_field pool_gdc_roi0;
+ struct mali_c720_reg_field pool_gdc_roi1;
+ struct mali_c720_reg_field pool_gdc_roi2;
+ struct mali_c720_reg_field pool_pyramid;
+ struct mali_c720_reg_field pool_consistency;
+ struct mali_c720_reg_field crc;
+};
+
+struct mali_c720_cm_buffer_regs {
+ struct mali_c720_group_regs out_group;
+ struct mali_c720_group_regs raw_group;
+ struct mali_c720_group_regs temper_group;
+ struct mali_c720_reg_field state;
+ struct mali_c720_reg_field state_request;
+ struct mali_c720_reg_field data_format;
+ struct mali_c720_reg_field data_align;
+ struct mali_c720_reg_field nonsecure;
+ struct mali_c720_reg_field stream_id;
+ struct mali_c720_reg_field data_layout;
+ struct mali_c720_reg_field crc_check;
+ struct mali_c720_reg_field pool;
+ struct mali_c720_reg_field mode;
+ struct mali_c720_reg_field block_size;
+ struct mali_c720_reg_field base_address_low;
+ struct mali_c720_reg_field base_address_high;
+ struct mali_c720_reg_field size;
+ struct mali_c720_reg_field plane2_offset;
+ struct mali_c720_reg_field plane3_offset;
+ struct mali_c720_reg_field plane4_offset;
+ struct mali_c720_reg_field line1_offset;
+ struct mali_c720_reg_field line2_offset;
+ struct mali_c720_reg_field line3_offset;
+ struct mali_c720_reg_field line4_offset;
+ struct mali_c720_reg_field width;
+ struct mali_c720_reg_field height;
+ struct mali_c720_reg_field colorspace;
+ struct mali_c720_reg_field subsampling;
+ struct mali_c720_reg_field component_width;
+ struct mali_c720_reg_field msb_align;
+ struct mali_c720_reg_field phase;
+ struct mali_c720_reg_field height_modulo;
+ struct mali_c720_reg_field compression;
+ struct mali_c720_reg_field compression23;
+ struct mali_c720_reg_field descriptor_crc;
+ struct mali_c720_reg_field frame_no;
+};
+
+struct mali_c720_cm_cdma_slot_regs {
+ struct mali_c720_group_regs group;
+ struct mali_c720_reg_field cdma_state;
+ struct mali_c720_reg_field cdma_state_request;
+ struct mali_c720_reg_field infinite;
+ struct mali_c720_reg_field nonsecure;
+ struct mali_c720_reg_field stream_id;
+ struct mali_c720_reg_field transfer_size;
+ struct mali_c720_reg_field units_low;
+ struct mali_c720_reg_field units_high;
+ struct mali_c720_reg_field base_address_low;
+ struct mali_c720_reg_field base_address_high;
+ struct mali_c720_reg_field ld_sg_count;
+ struct mali_c720_reg_field st_sg_count;
+ struct mali_c720_reg_field alt_transfer_size;
+ struct mali_c720_reg_field alt_base_address_low;
+ struct mali_c720_reg_field alt_base_address_high;
+ struct mali_c720_reg_field crc;
+};
+
+struct mali_c720_cm_load_out_fifo_regs {
+ struct mali_c720_group_regs scaler_group;
+ struct mali_c720_group_regs roi_group;
+ struct mali_c720_group_regs pyramid_group;
+ struct mali_c720_group_regs raw_group;
+ struct mali_c720_reg_field base_address;
+ struct mali_c720_reg_field size;
+};
+
+struct mali_c720_cm_sg_regs {
+ struct mali_c720_group_regs group;
+ struct mali_c720_reg_field isp_address;
+ struct mali_c720_reg_field length_low;
+ struct mali_c720_reg_field length_high;
+ struct mali_c720_reg_field axi_address;
+ struct mali_c720_reg_field alt_address;
+};
+
+struct mali_c720_cm_sg_crc_regs {
+ struct mali_c720_reg_field cdma_sg_crc;
+};
+
+struct mali_c720_ctx_mgr_regs {
+ const struct mali_c720_cm_capabilities *caps;
+ const struct mali_c720_cm_fifo_regs *input_fifo;
+ const struct mali_c720_cm_temper_fifo_regs *temper_fifo;
+ const struct mali_c720_cm_job_control_regs *job_control;
+ const struct mali_c720_cm_input_regs *input;
+ const struct mali_c720_cm_slot_regs *slot;
+ const struct mali_c720_cm_buffer_regs *buffer;
+ const struct mali_c720_cm_cdma_slot_regs *cdma_slot;
+ const struct mali_c720_cm_load_out_fifo_regs *load_out_fifo;
+ const struct mali_c720_cm_sg_regs *load_cdma_sg_load;
+ const struct mali_c720_cm_sg_crc_regs *load_cdma_sg_load_crc;
+ const struct mali_c720_cm_sg_regs *load_cdma_sg_store;
+ const struct mali_c720_cm_sg_crc_regs *load_cdma_sg_store_crc;
+ const struct mali_c720_cm_fifo_regs *reader_fifo;
+};
+
+const struct mali_c720_ctx_mgr_regs *mali_c720_get_ctx_mgr_regs(void);
+
+#endif /* MALI_C720_REGISTERS_CTX_MGR_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-registers-modules.c b/drivers/media/platform/arm/mali-c720/mali-c720-registers-modules.c
new file mode 100644
index 0000000000000000000000000000000000000000..a33716de72f6250fe5488eb4d0ccb6ccc23ee071
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-registers-modules.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/bits.h>
+
+#include "mali-c720-registers-modules.h"
+
+static const struct mali_c720_decompander_regs decompander = {
+ .enable = { .offset = 0x0, .mask = BIT(0), .shift = 0 },
+ .lut_x = { .offset = 0x4, .mask = GENMASK(23, 0), .shift = 0 },
+ .lut_y = { .offset = 0x88, .mask = GENMASK(24, 0), .shift = 0 },
+};
+
+static const struct mali_c720_digital_gain_regs inp_dgain = {
+ .gain = { .offset = 0x0, .mask = GENMASK(19, 0), .shift = 0 },
+ .offset = { .offset = 0x4, .mask = GENMASK(23, 0), .shift = 0 },
+};
+
+static const struct mali_c720_square_root_regs square_root_a = {
+ .black_level_out = { .offset = 0x0, .mask = GENMASK(11, 0), .shift = 0 },
+ .black_level_in = { .offset = 0x4, .mask = GENMASK(23, 0), .shift = 0 },
+ .normalization = { .offset = 0x8, .mask = GENMASK(16, 0), .shift = 0 },
+};
+
+static const struct mali_c720_black_level_regs black_level = {
+ .black_00 = { .offset = 0x0, .mask = GENMASK(15, 0), .shift = 0 },
+ .black_01 = { .offset = 0x0, .mask = GENMASK(31, 16), .shift = 16 },
+ .black_10 = { .offset = 0x4, .mask = GENMASK(15, 0), .shift = 0 },
+ .black_11 = { .offset = 0x4, .mask = GENMASK(31, 16), .shift = 16 },
+};
+
+static const struct mali_c720_wb_gain_regs wb_gain = {
+ .gain_00 = { .offset = 0x0, .mask = GENMASK(11, 0), .shift = 0 },
+ .gain_01 = { .offset = 0x4, .mask = GENMASK(11, 0), .shift = 0 },
+ .gain_10 = { .offset = 0x8, .mask = GENMASK(11, 0), .shift = 0 },
+ .gain_11 = { .offset = 0xc, .mask = GENMASK(11, 0), .shift = 0 },
+};
+
+static const struct mali_c720_square_regs square_a = {
+ .black_level_in = { .offset = 0x0, .mask = GENMASK(23, 0), .shift = 0 },
+ .black_level_out = { .offset = 0x4, .mask = GENMASK(11, 0), .shift = 0 },
+ .normalization = { .offset = 0x8, .mask = GENMASK(16, 0), .shift = 0 },
+};
+
+static const struct mali_c720_square_regs square_b = {
+ .black_level_in = { .offset = 0x0, .mask = GENMASK(11, 0), .shift = 0 },
+ .black_level_out = { .offset = 0x4, .mask = GENMASK(23, 0), .shift = 0 },
+ .normalization = { .offset = 0x8, .mask = GENMASK(16, 0), .shift = 0 },
+};
+
+static const struct mali_c720_square_root_regs square_root_b = {
+ .black_level_out = { .offset = 0x0, .mask = GENMASK(11, 0), .shift = 0 },
+ .black_level_in = { .offset = 0x4, .mask = GENMASK(23, 0), .shift = 0 },
+ .normalization = { .offset = 0x8, .mask = GENMASK(16, 0), .shift = 0 },
+};
+
+static const struct mali_c720_rgb_scaler_regs rgb_scaler = {
+ .hfilt_enable = { .offset = 0x0, .mask = BIT(0), .shift = 0 },
+ .vfilt_enable = { .offset = 0x0, .mask = BIT(1), .shift = 1 },
+ .hfilt_tincr = { .offset = 0x4, .mask = GENMASK(23, 0), .shift = 0 },
+ .hfilt_start_phase = { .offset = 0x8, .mask = GENMASK(23, 0), .shift = 0 },
+ .vfilt_tincr = { .offset = 0xc, .mask = GENMASK(23, 0), .shift = 0 },
+ .vfilt_start_phase = { .offset = 0x10, .mask = GENMASK(23, 0), .shift = 0 },
+ .hmem = { .offset = 0x0, .mask = GENMASK(31, 0), .shift = 0 },
+ .vmem = { .offset = 0x0, .mask = GENMASK(31, 0), .shift = 0 },
+};
+
+static const struct mali_c720_crop_regs crop = {
+ .enable_crop = { .offset = 0x0, .mask = BIT(0), .shift = 0 },
+ .start_x = { .offset = 0x4, .mask = GENMASK(15, 0), .shift = 0 },
+ .start_y = { .offset = 0x4, .mask = GENMASK(31, 16), .shift = 16 },
+ .size_x = { .offset = 0x8, .mask = GENMASK(15, 0), .shift = 0 },
+ .size_y = { .offset = 0x8, .mask = GENMASK(31, 16), .shift = 16 },
+};
+
+static const struct mali_c720_out_format_regs out_format = {
+ .coefft_11 = { .offset = 0x0, .mask = GENMASK(15, 0), .shift = 0 },
+ .coefft_12 = { .offset = 0x0, .mask = GENMASK(31, 16), .shift = 16 },
+ .coefft_13 = { .offset = 0x4, .mask = GENMASK(15, 0), .shift = 0 },
+ .coefft_21 = { .offset = 0x4, .mask = GENMASK(31, 16), .shift = 16 },
+ .coefft_22 = { .offset = 0x8, .mask = GENMASK(15, 0), .shift = 0 },
+ .coefft_23 = { .offset = 0x8, .mask = GENMASK(31, 16), .shift = 16 },
+ .coefft_31 = { .offset = 0xc, .mask = GENMASK(15, 0), .shift = 0 },
+ .coefft_32 = { .offset = 0xc, .mask = GENMASK(31, 16), .shift = 16 },
+ .coefft_33 = { .offset = 0x10, .mask = GENMASK(15, 0), .shift = 0 },
+ .coefft_o1 = { .offset = 0x14, .mask = GENMASK(16, 0), .shift = 0 },
+ .coefft_o2 = { .offset = 0x18, .mask = GENMASK(16, 0), .shift = 0 },
+ .coefft_o3 = { .offset = 0x1c, .mask = GENMASK(16, 0), .shift = 0 },
+ .clip_min_y = { .offset = 0x20, .mask = GENMASK(15, 0), .shift = 0 },
+ .clip_max_y = { .offset = 0x20, .mask = GENMASK(31, 16), .shift = 16 },
+ .clip_min_uv = { .offset = 0x24, .mask = GENMASK(15, 0), .shift = 0 },
+ .clip_max_uv = { .offset = 0x24, .mask = GENMASK(31, 16), .shift = 16 },
+};
+
+static const struct mali_c720_stat_color_stats_regs stat_color_stats = {
+ .awb_stats_mode = { .offset = 0xc, .mask = BIT(0), .shift = 0 },
+ .white_level_awb = { .offset = 0x10, .mask = GENMASK(13, 0), .shift = 0 },
+ .black_level_awb = { .offset = 0x14, .mask = GENMASK(13, 0), .shift = 0 },
+ .cr_ref_max_awb = { .offset = 0x18, .mask = GENMASK(11, 0), .shift = 0 },
+ .cr_ref_min_awb = { .offset = 0x1c, .mask = GENMASK(11, 0), .shift = 0 },
+ .cb_ref_max_awb = { .offset = 0x20, .mask = GENMASK(11, 0), .shift = 0 },
+ .cb_ref_min_awb = { .offset = 0x24, .mask = GENMASK(11, 0), .shift = 0 },
+ .awb_nodes_used_horiz = { .offset = 0x28, .mask = GENMASK(7, 0), .shift = 0 },
+ .awb_nodes_used_vert = { .offset = 0x28, .mask = GENMASK(15, 8), .shift = 8 },
+ .cr_ref_high_awb = { .offset = 0x2c, .mask = GENMASK(11, 0), .shift = 0 },
+ .cr_ref_low_awb = { .offset = 0x30, .mask = GENMASK(11, 0), .shift = 0 },
+ .cb_ref_high_awb = { .offset = 0x34, .mask = GENMASK(11, 0), .shift = 0 },
+ .cb_ref_low_awb = { .offset = 0x38, .mask = GENMASK(11, 0), .shift = 0 },
+ .awb_weight = { .offset = 0x40, .mask = GENMASK(3, 0), .shift = 0 },
+};
+
+static const struct mali_c720_stat_histogram_regs stat_histogram = {
+ .skip_x = { .offset = 0x28, .mask = GENMASK(2, 0), .shift = 0 },
+ .skip_y = { .offset = 0x28, .mask = GENMASK(6, 4), .shift = 4 },
+ .offset_x = { .offset = 0x28, .mask = BIT(3), .shift = 3 },
+ .offset_y = { .offset = 0x28, .mask = BIT(7), .shift = 7 },
+ .scale_bottom = { .offset = 0x2c, .mask = GENMASK(3, 0), .shift = 0 },
+ .scale_top = { .offset = 0x2c, .mask = GENMASK(7, 4), .shift = 4 },
+ .plane_mode = { .offset = 0x30, .mask = GENMASK(2, 0), .shift = 0 },
+ .nodes_used_horiz = { .offset = 0x34, .mask = GENMASK(7, 0), .shift = 0 },
+ .nodes_used_vert = { .offset = 0x34, .mask = GENMASK(15, 8), .shift = 8 },
+ .weight = { .offset = 0x38, .mask = GENMASK(3, 0), .shift = 0 },
+};
+
+static const struct mali_c720_modules_regs mali_c720_modules_regs = {
+ .decompander = &decompander,
+ .inp_dgain = &inp_dgain,
+ .square_root_a = &square_root_a,
+ .black_level = &black_level,
+ .wb_gain = &wb_gain,
+ .square_a = &square_a,
+ .square_b = &square_b,
+ .square_root_b = &square_root_b,
+ .rgb_scaler = &rgb_scaler,
+ .crop = &crop,
+ .out_format = &out_format,
+ .stat_color_stats = &stat_color_stats,
+ .stat_histogram = &stat_histogram,
+};
+
+const struct mali_c720_modules_regs *mali_c720_get_modules_regs(void)
+{
+ return &mali_c720_modules_regs;
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-registers-modules.h b/drivers/media/platform/arm/mali-c720/mali-c720-registers-modules.h
new file mode 100644
index 0000000000000000000000000000000000000000..500059b1bfa299f4e15f423650826409135504a9
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-registers-modules.h
@@ -0,0 +1,136 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_REGISTERS_MODULES_H
+#define MALI_C720_REGISTERS_MODULES_H
+
+#include "mali-c720-registers.h"
+
+struct mali_c720_decompander_regs {
+ struct mali_c720_reg_field enable;
+ struct mali_c720_reg_field lut_x;
+ struct mali_c720_reg_field lut_y;
+};
+
+struct mali_c720_digital_gain_regs {
+ struct mali_c720_reg_field gain;
+ struct mali_c720_reg_field offset;
+};
+
+struct mali_c720_square_root_regs {
+ struct mali_c720_reg_field black_level_out;
+ struct mali_c720_reg_field black_level_in;
+ struct mali_c720_reg_field normalization;
+};
+
+struct mali_c720_black_level_regs {
+ struct mali_c720_reg_field black_00;
+ struct mali_c720_reg_field black_01;
+ struct mali_c720_reg_field black_10;
+ struct mali_c720_reg_field black_11;
+};
+
+struct mali_c720_wb_gain_regs {
+ struct mali_c720_reg_field gain_00;
+ struct mali_c720_reg_field gain_01;
+ struct mali_c720_reg_field gain_10;
+ struct mali_c720_reg_field gain_11;
+};
+
+struct mali_c720_square_regs {
+ struct mali_c720_reg_field black_level_in;
+ struct mali_c720_reg_field black_level_out;
+ struct mali_c720_reg_field normalization;
+};
+
+struct mali_c720_rgb_scaler_regs {
+ struct mali_c720_reg_field hfilt_enable;
+ struct mali_c720_reg_field vfilt_enable;
+ struct mali_c720_reg_field hfilt_tincr;
+ struct mali_c720_reg_field hfilt_start_phase;
+ struct mali_c720_reg_field vfilt_tincr;
+ struct mali_c720_reg_field vfilt_start_phase;
+ struct mali_c720_reg_field hmem;
+ struct mali_c720_reg_field vmem;
+};
+
+struct mali_c720_crop_regs {
+ struct mali_c720_reg_field enable_crop;
+ struct mali_c720_reg_field start_x;
+ struct mali_c720_reg_field start_y;
+ struct mali_c720_reg_field size_x;
+ struct mali_c720_reg_field size_y;
+};
+
+struct mali_c720_out_format_regs {
+ struct mali_c720_reg_field coefft_11;
+ struct mali_c720_reg_field coefft_12;
+ struct mali_c720_reg_field coefft_13;
+ struct mali_c720_reg_field coefft_21;
+ struct mali_c720_reg_field coefft_22;
+ struct mali_c720_reg_field coefft_23;
+ struct mali_c720_reg_field coefft_31;
+ struct mali_c720_reg_field coefft_32;
+ struct mali_c720_reg_field coefft_33;
+ struct mali_c720_reg_field coefft_o1;
+ struct mali_c720_reg_field coefft_o2;
+ struct mali_c720_reg_field coefft_o3;
+ struct mali_c720_reg_field clip_min_y;
+ struct mali_c720_reg_field clip_max_y;
+ struct mali_c720_reg_field clip_min_uv;
+ struct mali_c720_reg_field clip_max_uv;
+};
+
+struct mali_c720_stat_color_stats_regs {
+ struct mali_c720_reg_field awb_stats_mode;
+ struct mali_c720_reg_field white_level_awb;
+ struct mali_c720_reg_field black_level_awb;
+ struct mali_c720_reg_field cr_ref_max_awb;
+ struct mali_c720_reg_field cr_ref_min_awb;
+ struct mali_c720_reg_field cb_ref_max_awb;
+ struct mali_c720_reg_field cb_ref_min_awb;
+ struct mali_c720_reg_field awb_nodes_used_horiz;
+ struct mali_c720_reg_field awb_nodes_used_vert;
+ struct mali_c720_reg_field cr_ref_high_awb;
+ struct mali_c720_reg_field cr_ref_low_awb;
+ struct mali_c720_reg_field cb_ref_high_awb;
+ struct mali_c720_reg_field cb_ref_low_awb;
+ struct mali_c720_reg_field awb_weight;
+};
+
+struct mali_c720_stat_histogram_regs {
+ struct mali_c720_reg_field skip_x;
+ struct mali_c720_reg_field skip_y;
+ struct mali_c720_reg_field offset_x;
+ struct mali_c720_reg_field offset_y;
+ struct mali_c720_reg_field scale_bottom;
+ struct mali_c720_reg_field scale_top;
+ struct mali_c720_reg_field plane_mode;
+ struct mali_c720_reg_field nodes_used_horiz;
+ struct mali_c720_reg_field nodes_used_vert;
+ struct mali_c720_reg_field weight;
+};
+
+struct mali_c720_modules_regs {
+ const struct mali_c720_decompander_regs *decompander;
+ const struct mali_c720_digital_gain_regs *inp_dgain;
+ const struct mali_c720_square_root_regs *square_root_a;
+ const struct mali_c720_black_level_regs *black_level;
+ const struct mali_c720_wb_gain_regs *wb_gain;
+ const struct mali_c720_square_regs *square_a;
+ const struct mali_c720_square_regs *square_b;
+ const struct mali_c720_square_root_regs *square_root_b;
+ const struct mali_c720_rgb_scaler_regs *rgb_scaler;
+ const struct mali_c720_crop_regs *crop;
+ const struct mali_c720_out_format_regs *out_format;
+ const struct mali_c720_stat_color_stats_regs *stat_color_stats;
+ const struct mali_c720_stat_histogram_regs *stat_histogram;
+};
+
+const struct mali_c720_modules_regs *mali_c720_get_modules_regs(void);
+
+#endif /* MALI_C720_REGISTERS_MODULES_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-registers-top.c b/drivers/media/platform/arm/mali-c720/mali-c720-registers-top.c
new file mode 100644
index 0000000000000000000000000000000000000000..58cb63348337487fc355cc76c3cee6543021da69
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-registers-top.c
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/bits.h>
+
+#include "mali-c720-registers-top.h"
+
+static const struct mali_c720_irq_regs irq_r0 = {
+ .cm_input_0_stream_3_cmsi_active_video = { .offset = 0x1020, .mask = BIT(30), .shift = 30 },
+ .cm_input_0_stream_2_cmsi_active_video = { .offset = 0x1020, .mask = BIT(22), .shift = 22 },
+ .cm_input_0_stream_1_cmsi_active_video = { .offset = 0x1020, .mask = BIT(14), .shift = 14 },
+ .cm_input_0_stream_0_cmsi_active_video = { .offset = 0x1020, .mask = BIT(6), .shift = 6 },
+ .cm_input_1_stream_3_cmsi_active_video = { .offset = 0x1030, .mask = BIT(30), .shift = 30 },
+ .cm_input_1_stream_2_cmsi_active_video = { .offset = 0x1030, .mask = BIT(22), .shift = 22 },
+ .cm_input_1_stream_1_cmsi_active_video = { .offset = 0x1030, .mask = BIT(14), .shift = 14 },
+ .cm_input_1_stream_0_cmsi_active_video = { .offset = 0x1030, .mask = BIT(6), .shift = 6 },
+ .cm_input_2_stream_3_cmsi_active_video = { .offset = 0x1040, .mask = BIT(30), .shift = 30 },
+ .cm_input_2_stream_2_cmsi_active_video = { .offset = 0x1040, .mask = BIT(22), .shift = 22 },
+ .cm_input_2_stream_1_cmsi_active_video = { .offset = 0x1040, .mask = BIT(14), .shift = 14 },
+ .cm_input_2_stream_0_cmsi_active_video = { .offset = 0x1040, .mask = BIT(6), .shift = 6 },
+ .cm_input_3_stream_3_cmsi_active_video = { .offset = 0x1050, .mask = BIT(30), .shift = 30 },
+ .cm_input_3_stream_2_cmsi_active_video = { .offset = 0x1050, .mask = BIT(22), .shift = 22 },
+ .cm_input_3_stream_1_cmsi_active_video = { .offset = 0x1050, .mask = BIT(14), .shift = 14 },
+ .cm_input_3_stream_0_cmsi_active_video = { .offset = 0x1050, .mask = BIT(6), .shift = 6 },
+ .cm_status_slot_15 = { .offset = 0x1060, .mask = BIT(15), .shift = 15 },
+ .cm_status_slot_14 = { .offset = 0x1060, .mask = BIT(14), .shift = 14 },
+ .cm_status_slot_13 = { .offset = 0x1060, .mask = BIT(13), .shift = 13 },
+ .cm_status_slot_12 = { .offset = 0x1060, .mask = BIT(12), .shift = 12 },
+ .cm_status_slot_11 = { .offset = 0x1060, .mask = BIT(11), .shift = 11 },
+ .cm_status_slot_10 = { .offset = 0x1060, .mask = BIT(10), .shift = 10 },
+ .cm_status_slot_9 = { .offset = 0x1060, .mask = BIT(9), .shift = 9 },
+ .cm_status_slot_8 = { .offset = 0x1060, .mask = BIT(8), .shift = 8 },
+ .cm_status_slot_7 = { .offset = 0x1060, .mask = BIT(7), .shift = 7 },
+ .cm_status_slot_6 = { .offset = 0x1060, .mask = BIT(6), .shift = 6 },
+ .cm_status_slot_5 = { .offset = 0x1060, .mask = BIT(5), .shift = 5 },
+ .cm_status_slot_4 = { .offset = 0x1060, .mask = BIT(4), .shift = 4 },
+ .cm_status_slot_3 = { .offset = 0x1060, .mask = BIT(3), .shift = 3 },
+ .cm_status_slot_2 = { .offset = 0x1060, .mask = BIT(2), .shift = 2 },
+ .cm_status_slot_1 = { .offset = 0x1060, .mask = BIT(1), .shift = 1 },
+ .cm_status_slot_0 = { .offset = 0x1060, .mask = BIT(0), .shift = 0 },
+};
+
+static const struct mali_c720_pre_cm_regs pre_cm_r0 = {
+ .tpg_0_splitter_sel = { .offset = 0x3200, .mask = GENMASK(1, 0), .shift = 0 },
+ .tpg_1_splitter_sel = { .offset = 0x3200, .mask = GENMASK(9, 8), .shift = 8 },
+ .input_0_mux_sel = { .offset = 0x3200, .mask = GENMASK(17, 16), .shift = 16 },
+ .input_1_mux_sel = { .offset = 0x3200, .mask = GENMASK(21, 20), .shift = 20 },
+ .input_2_mux_sel = { .offset = 0x3200, .mask = GENMASK(25, 24), .shift = 24 },
+ .input_3_mux_sel = { .offset = 0x3200, .mask = GENMASK(29, 28), .shift = 28 },
+};
+
+static const struct mali_c720_precm_tpg_regs precm_tpgs_r0 = {
+ .group = { .offset = 0x3280, .size = 0x80 },
+ .glbl_active_width = { .offset = 0x0, .mask = GENMASK(13, 0), .shift = 0 },
+ .glbl_active_height = { .offset = 0x0, .mask = GENMASK(29, 16), .shift = 16 },
+ .glbl_rggb_start = { .offset = 0x4, .mask = GENMASK(1, 0), .shift = 0 },
+ .test_pattern_off_on = { .offset = 0x8, .mask = BIT(0), .shift = 0 },
+ .generate_mode = { .offset = 0x8, .mask = BIT(4), .shift = 4 },
+ .frame_request = { .offset = 0x8, .mask = BIT(16), .shift = 16 },
+ .pattern_type = { .offset = 0x8, .mask = GENMASK(31, 24), .shift = 24 },
+ .horizontal_blanking = { .offset = 0x38, .mask = GENMASK(13, 0), .shift = 0 },
+ .vertical_blanking = { .offset = 0x3c, .mask = GENMASK(27, 0), .shift = 0 },
+};
+
+static const struct mali_c720_pipeline_regs pipeline_r0 = {
+ .frame_count = { .offset = 0x0, .mask = GENMASK(31, 0), .shift = 0 },
+ .active_width = { .offset = 0x4, .mask = GENMASK(13, 0), .shift = 0 },
+ .active_height = { .offset = 0x4, .mask = GENMASK(29, 16), .shift = 16 },
+ .rggb_start = { .offset = 0x8, .mask = GENMASK(1, 0), .shift = 0 },
+ .inp_remosaic_cv_mux_sel = { .offset = 0x18, .mask = BIT(0), .shift = 0 },
+ .inp_remosaic_ir0_mux_sel = { .offset = 0x18, .mask = BIT(1), .shift = 1 },
+ .inp_cv_mux_sel = { .offset = 0x18, .mask = GENMASK(4, 2), .shift = 2 },
+ .fr0_hv_cv_mux_sel = { .offset = 0x1c, .mask = BIT(0), .shift = 0 },
+ .fr1_hv_cv_mux_sel = { .offset = 0x1c, .mask = BIT(1), .shift = 1 },
+ .fr2_hv_cv_mux_sel = { .offset = 0x1c, .mask = BIT(2), .shift = 2 },
+ .fr3_hv_cv_mux_sel = { .offset = 0x1c, .mask = BIT(3), .shift = 3 },
+ .pyr_hv_cv_ir0_mux_sel = { .offset = 0x20, .mask = GENMASK(1, 0), .shift = 0 },
+ .fov_fr_mux_sel = { .offset = 0x24, .mask = GENMASK(2, 0), .shift = 0 },
+ .fov_raw_fr_mux_sel = { .offset = 0x24, .mask = BIT(3), .shift = 3 },
+ .raw_input_mux_sel = { .offset = 0x28, .mask = GENMASK(2, 0), .shift = 0 },
+ .af_stats_mux_sel = { .offset = 0x2c, .mask = BIT(0), .shift = 0 },
+ .color_stats_0_mux_sel = { .offset = 0x2c, .mask = BIT(1), .shift = 1 },
+ .color_stats_1_mux_sel = { .offset = 0x2c, .mask = BIT(2), .shift = 2 },
+ .histogram_0_mux_sel = { .offset = 0x2c, .mask = BIT(3), .shift = 3 },
+ .histogram_1_stream_mux_sel = { .offset = 0x2c, .mask = BIT(4), .shift = 4 },
+ .histogram_1_mux_sel = { .offset = 0x2c, .mask = BIT(5), .shift = 5 },
+ .histogram_2_mux_sel = { .offset = 0x2c, .mask = BIT(6), .shift = 6 },
+ .histogram_3_stream_mux_sel = { .offset = 0x2c, .mask = BIT(7), .shift = 7 },
+ .histogram_3_mux_sel = { .offset = 0x2c, .mask = BIT(8), .shift = 8 },
+ .histogram_4_mux_sel = { .offset = 0x2c, .mask = BIT(9), .shift = 9 },
+ .intensity_zone_1_mux_sel = { .offset = 0x2c, .mask = BIT(10), .shift = 10 },
+ .intensity_zone_3_mux_sel = { .offset = 0x2c, .mask = BIT(11), .shift = 11 },
+ .bypass_inp_decompander = { .offset = 0x30, .mask = BIT(0), .shift = 0 },
+ .bypass_inp_frame_stitch = { .offset = 0x30, .mask = BIT(1), .shift = 1 },
+ .bypass_inp_dgain = { .offset = 0x30, .mask = BIT(2), .shift = 2 },
+ .bypass_inp_square_root_a = { .offset = 0x30, .mask = BIT(3), .shift = 3 },
+ .bypass_inp_dpc = { .offset = 0x30, .mask = BIT(4), .shift = 4 },
+ .bypass_inp_remosaic = { .offset = 0x30, .mask = BIT(5), .shift = 5 },
+ .bypass_inp_cac = { .offset = 0x30, .mask = BIT(6), .shift = 6 },
+ .bypass_inp_temper = { .offset = 0x30, .mask = BIT(7), .shift = 7 },
+ .bypass_inp_sinter = { .offset = 0x30, .mask = BIT(8), .shift = 8 },
+ .bypass_hv_black_level = { .offset = 0x34, .mask = BIT(0), .shift = 0 },
+ .bypass_hv_wb_gain = { .offset = 0x34, .mask = BIT(1), .shift = 1 },
+ .bypass_hv_smart_shading = { .offset = 0x34, .mask = BIT(2), .shift = 2 },
+ .bypass_hv_raw_to_intensity = { .offset = 0x34, .mask = BIT(3), .shift = 3 },
+ .bypass_hv_dehaze = { .offset = 0x34, .mask = BIT(4), .shift = 4 },
+ .bypass_hv_dgain_iridix = { .offset = 0x34, .mask = BIT(5), .shift = 5 },
+ .bypass_hv_iridix = { .offset = 0x34, .mask = BIT(6), .shift = 6 },
+ .bypass_hv_square_a = { .offset = 0x34, .mask = BIT(7), .shift = 7 },
+ .bypass_hv_demosaic = { .offset = 0x34, .mask = BIT(8), .shift = 8 },
+ .bypass_hv_pf_correction = { .offset = 0x34, .mask = BIT(9), .shift = 9 },
+ .bypass_hv_square_b = { .offset = 0x34, .mask = BIT(10), .shift = 10 },
+ .bypass_hv_ccm = { .offset = 0x34, .mask = BIT(11), .shift = 11 },
+ .bypass_hv_square_root_b = { .offset = 0x34, .mask = BIT(12), .shift = 12 },
+ .bypass_hv_cnr = { .offset = 0x34, .mask = BIT(13), .shift = 13 },
+ .bypass_cv_black_level = { .offset = 0x38, .mask = BIT(0), .shift = 0 },
+ .bypass_cv_wb_gain = { .offset = 0x38, .mask = BIT(1), .shift = 1 },
+ .bypass_cv_smart_shading = { .offset = 0x38, .mask = BIT(2), .shift = 2 },
+ .bypass_cv_raw_to_intensity = { .offset = 0x38, .mask = BIT(3), .shift = 3 },
+ .bypass_cv_dehaze = { .offset = 0x38, .mask = BIT(4), .shift = 4 },
+ .bypass_cv_dgain_iridix = { .offset = 0x38, .mask = BIT(5), .shift = 5 },
+ .bypass_cv_iridix = { .offset = 0x38, .mask = BIT(6), .shift = 6 },
+ .bypass_cv_square_a = { .offset = 0x38, .mask = BIT(7), .shift = 7 },
+ .bypass_cv_demosaic_dfd = { .offset = 0x38, .mask = BIT(8), .shift = 8 },
+ .bypass_cv_square_b = { .offset = 0x38, .mask = BIT(9), .shift = 9 },
+ .bypass_cv_ccm = { .offset = 0x38, .mask = BIT(10), .shift = 10 },
+ .bypass_cv_square_root_b = { .offset = 0x38, .mask = BIT(11), .shift = 11 },
+ .bypass_cv_cnr = { .offset = 0x38, .mask = BIT(12), .shift = 12 },
+ .bypass_fr0_rgb_scaler = { .offset = 0x3c, .mask = BIT(0), .shift = 0 },
+ .bypass_fr1_rgb_scaler = { .offset = 0x3c, .mask = BIT(1), .shift = 1 },
+ .bypass_fr2_rgb_scaler = { .offset = 0x3c, .mask = BIT(2), .shift = 2 },
+ .bypass_fr3_rgb_scaler = { .offset = 0x3c, .mask = BIT(3), .shift = 3 },
+ .bypass_fr0_crop = { .offset = 0x40, .mask = BIT(0), .shift = 0 },
+ .bypass_fr0_rgb_sharpening = { .offset = 0x40, .mask = BIT(1), .shift = 1 },
+ .bypass_fr0_gain_and_offset = { .offset = 0x40, .mask = BIT(2), .shift = 2 },
+ .bypass_fr0_gamma = { .offset = 0x40, .mask = BIT(3), .shift = 3 },
+ .bypass_fr1_crop = { .offset = 0x44, .mask = BIT(0), .shift = 0 },
+ .bypass_fr1_rgb_sharpening = { .offset = 0x44, .mask = BIT(1), .shift = 1 },
+ .bypass_fr1_gain_and_offset = { .offset = 0x44, .mask = BIT(2), .shift = 2 },
+ .bypass_fr1_gamma = { .offset = 0x44, .mask = BIT(3), .shift = 3 },
+ .bypass_fr2_crop = { .offset = 0x48, .mask = BIT(0), .shift = 0 },
+ .bypass_fr2_rgb_sharpening = { .offset = 0x48, .mask = BIT(1), .shift = 1 },
+ .bypass_fr2_gain_and_offset = { .offset = 0x48, .mask = BIT(2), .shift = 2 },
+ .bypass_fr2_gamma = { .offset = 0x48, .mask = BIT(3), .shift = 3 },
+ .bypass_fr3_crop = { .offset = 0x4c, .mask = BIT(0), .shift = 0 },
+ .bypass_fr3_rgb_sharpening = { .offset = 0x4c, .mask = BIT(1), .shift = 1 },
+ .bypass_fr3_gain_and_offset = { .offset = 0x4c, .mask = BIT(2), .shift = 2 },
+ .bypass_fr3_gamma = { .offset = 0x4c, .mask = BIT(3), .shift = 3 },
+ .bypass_pyr_tc_lut = { .offset = 0x50, .mask = BIT(0), .shift = 0 },
+ .bypass_fov_crop_0 = { .offset = 0x54, .mask = BIT(0), .shift = 0 },
+ .bypass_fov_crop_1 = { .offset = 0x54, .mask = BIT(1), .shift = 1 },
+ .bypass_fov_crop_2 = { .offset = 0x54, .mask = BIT(2), .shift = 2 },
+ .bypass_raw_offset = { .offset = 0x58, .mask = BIT(0), .shift = 0 },
+ .bypass_raw_dgain = { .offset = 0x58, .mask = BIT(1), .shift = 1 },
+ .bypass_raw_tc_lut = { .offset = 0x58, .mask = BIT(2), .shift = 2 },
+ .bypass_raw_crop = { .offset = 0x58, .mask = BIT(3), .shift = 3 },
+};
+
+static const struct mali_c720_top_regs mali_c720_top_regs_r0 = {
+ .irq = &irq_r0,
+ .pre_cm = &pre_cm_r0,
+ .precm_tpgs = &precm_tpgs_r0,
+ .pipeline = &pipeline_r0,
+};
+
+const struct mali_c720_top_regs *mali_c720_get_top_regs(void)
+{
+ return &mali_c720_top_regs_r0;
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-registers-top.h b/drivers/media/platform/arm/mali-c720/mali-c720-registers-top.h
new file mode 100644
index 0000000000000000000000000000000000000000..9ac853ad9eb902aead4cf551992f8f3b2ba8aa39
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-registers-top.h
@@ -0,0 +1,228 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_REGISTERS_TOP_H
+#define MALI_C720_REGISTERS_TOP_H
+
+#include "mali-c720-registers.h"
+
+struct mali_c720_irq_regs {
+ struct mali_c720_reg_field cm_input_0_stream_3_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_0_stream_2_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_0_stream_1_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_0_stream_0_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_1_stream_3_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_1_stream_2_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_1_stream_1_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_1_stream_0_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_2_stream_3_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_2_stream_2_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_2_stream_1_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_2_stream_0_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_3_stream_3_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_3_stream_2_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_3_stream_1_cmsi_active_video;
+ struct mali_c720_reg_field cm_input_3_stream_0_cmsi_active_video;
+ struct mali_c720_reg_field cm_status_slot_15;
+ struct mali_c720_reg_field cm_status_slot_14;
+ struct mali_c720_reg_field cm_status_slot_13;
+ struct mali_c720_reg_field cm_status_slot_12;
+ struct mali_c720_reg_field cm_status_slot_11;
+ struct mali_c720_reg_field cm_status_slot_10;
+ struct mali_c720_reg_field cm_status_slot_9;
+ struct mali_c720_reg_field cm_status_slot_8;
+ struct mali_c720_reg_field cm_status_slot_7;
+ struct mali_c720_reg_field cm_status_slot_6;
+ struct mali_c720_reg_field cm_status_slot_5;
+ struct mali_c720_reg_field cm_status_slot_4;
+ struct mali_c720_reg_field cm_status_slot_3;
+ struct mali_c720_reg_field cm_status_slot_2;
+ struct mali_c720_reg_field cm_status_slot_1;
+ struct mali_c720_reg_field cm_status_slot_0;
+};
+
+struct mali_c720_pre_cm_regs {
+ struct mali_c720_reg_field tpg_0_splitter_sel;
+ struct mali_c720_reg_field tpg_1_splitter_sel;
+ struct mali_c720_reg_field input_0_mux_sel;
+ struct mali_c720_reg_field input_1_mux_sel;
+ struct mali_c720_reg_field input_2_mux_sel;
+ struct mali_c720_reg_field input_3_mux_sel;
+};
+
+struct mali_c720_precm_tpg_regs {
+ struct mali_c720_group_regs group;
+ struct mali_c720_reg_field glbl_active_width;
+ struct mali_c720_reg_field glbl_active_height;
+ struct mali_c720_reg_field glbl_rggb_start;
+ struct mali_c720_reg_field test_pattern_off_on;
+ struct mali_c720_reg_field generate_mode;
+ struct mali_c720_reg_field frame_request;
+ struct mali_c720_reg_field pattern_type;
+ struct mali_c720_reg_field horizontal_blanking;
+ struct mali_c720_reg_field vertical_blanking;
+};
+
+struct mali_c720_pipeline_regs {
+ struct mali_c720_reg_field frame_count;
+ struct mali_c720_reg_field active_width;
+ struct mali_c720_reg_field active_height;
+ struct mali_c720_reg_field rggb_start;
+ struct mali_c720_reg_field inp_remosaic_cv_mux_sel;
+ struct mali_c720_reg_field inp_remosaic_ir0_mux_sel;
+ struct mali_c720_reg_field inp_cv_mux_sel;
+ struct mali_c720_reg_field fr0_hv_cv_mux_sel;
+ struct mali_c720_reg_field fr1_hv_cv_mux_sel;
+ struct mali_c720_reg_field fr2_hv_cv_mux_sel;
+ struct mali_c720_reg_field fr3_hv_cv_mux_sel;
+ struct mali_c720_reg_field pyr_hv_cv_ir0_mux_sel;
+ struct mali_c720_reg_field fov_fr_mux_sel;
+ struct mali_c720_reg_field fov_raw_fr_mux_sel;
+ struct mali_c720_reg_field raw_input_mux_sel;
+ struct mali_c720_reg_field af_stats_mux_sel;
+ struct mali_c720_reg_field color_stats_0_mux_sel;
+ struct mali_c720_reg_field color_stats_1_mux_sel;
+ struct mali_c720_reg_field histogram_0_mux_sel;
+ struct mali_c720_reg_field histogram_1_stream_mux_sel;
+ struct mali_c720_reg_field histogram_1_mux_sel;
+ struct mali_c720_reg_field histogram_2_mux_sel;
+ struct mali_c720_reg_field histogram_3_stream_mux_sel;
+ struct mali_c720_reg_field histogram_3_mux_sel;
+ struct mali_c720_reg_field histogram_4_mux_sel;
+ struct mali_c720_reg_field intensity_zone_1_mux_sel;
+ struct mali_c720_reg_field intensity_zone_3_mux_sel;
+ struct mali_c720_reg_field bypass_inp_decompander;
+ struct mali_c720_reg_field bypass_inp_frame_stitch;
+ struct mali_c720_reg_field bypass_inp_dgain;
+ struct mali_c720_reg_field bypass_inp_square_root_a;
+ struct mali_c720_reg_field bypass_inp_dpc;
+ struct mali_c720_reg_field bypass_inp_remosaic;
+ struct mali_c720_reg_field bypass_inp_cac;
+ struct mali_c720_reg_field bypass_inp_temper;
+ struct mali_c720_reg_field bypass_inp_sinter;
+ struct mali_c720_reg_field bypass_hv_black_level;
+ struct mali_c720_reg_field bypass_hv_wb_gain;
+ struct mali_c720_reg_field bypass_hv_smart_shading;
+ struct mali_c720_reg_field bypass_hv_raw_to_intensity;
+ struct mali_c720_reg_field bypass_hv_dehaze;
+ struct mali_c720_reg_field bypass_hv_dgain_iridix;
+ struct mali_c720_reg_field bypass_hv_iridix;
+ struct mali_c720_reg_field bypass_hv_square_a;
+ struct mali_c720_reg_field bypass_hv_demosaic;
+ struct mali_c720_reg_field bypass_hv_pf_correction;
+ struct mali_c720_reg_field bypass_hv_square_b;
+ struct mali_c720_reg_field bypass_hv_ccm;
+ struct mali_c720_reg_field bypass_hv_square_root_b;
+ struct mali_c720_reg_field bypass_hv_cnr;
+ struct mali_c720_reg_field bypass_cv_black_level;
+ struct mali_c720_reg_field bypass_cv_wb_gain;
+ struct mali_c720_reg_field bypass_cv_smart_shading;
+ struct mali_c720_reg_field bypass_cv_raw_to_intensity;
+ struct mali_c720_reg_field bypass_cv_dehaze;
+ struct mali_c720_reg_field bypass_cv_dgain_iridix;
+ struct mali_c720_reg_field bypass_cv_iridix;
+ struct mali_c720_reg_field bypass_cv_square_a;
+ struct mali_c720_reg_field bypass_cv_demosaic_dfd;
+ struct mali_c720_reg_field bypass_cv_square_b;
+ struct mali_c720_reg_field bypass_cv_ccm;
+ struct mali_c720_reg_field bypass_cv_square_root_b;
+ struct mali_c720_reg_field bypass_cv_cnr;
+ struct mali_c720_reg_field bypass_fr0_rgb_scaler;
+ struct mali_c720_reg_field bypass_fr1_rgb_scaler;
+ struct mali_c720_reg_field bypass_fr2_rgb_scaler;
+ struct mali_c720_reg_field bypass_fr3_rgb_scaler;
+ struct mali_c720_reg_field bypass_fr0_crop;
+ struct mali_c720_reg_field bypass_fr0_rgb_sharpening;
+ struct mali_c720_reg_field bypass_fr0_gain_and_offset;
+ struct mali_c720_reg_field bypass_fr0_gamma;
+ struct mali_c720_reg_field bypass_fr1_crop;
+ struct mali_c720_reg_field bypass_fr1_rgb_sharpening;
+ struct mali_c720_reg_field bypass_fr1_gain_and_offset;
+ struct mali_c720_reg_field bypass_fr1_gamma;
+ struct mali_c720_reg_field bypass_fr2_crop;
+ struct mali_c720_reg_field bypass_fr2_rgb_sharpening;
+ struct mali_c720_reg_field bypass_fr2_gain_and_offset;
+ struct mali_c720_reg_field bypass_fr2_gamma;
+ struct mali_c720_reg_field bypass_fr3_crop;
+ struct mali_c720_reg_field bypass_fr3_rgb_sharpening;
+ struct mali_c720_reg_field bypass_fr3_gain_and_offset;
+ struct mali_c720_reg_field bypass_fr3_gamma;
+ struct mali_c720_reg_field bypass_pyr_tc_lut;
+ struct mali_c720_reg_field bypass_fov_crop_0;
+ struct mali_c720_reg_field bypass_fov_crop_1;
+ struct mali_c720_reg_field bypass_fov_crop_2;
+ struct mali_c720_reg_field bypass_raw_offset;
+ struct mali_c720_reg_field bypass_raw_dgain;
+ struct mali_c720_reg_field bypass_raw_tc_lut;
+ struct mali_c720_reg_field bypass_raw_crop;
+};
+
+/* Register field encodings used by the R0 programming model. */
+enum mali_c720_top_fov_fr_mux_sel {
+ ISP_TOP_FOV_FR_MUX_SEL_FR0_GAMMA,
+ ISP_TOP_FOV_FR_MUX_SEL_FR0_OUT_FORMAT_444_FOV,
+ ISP_TOP_FOV_FR_MUX_SEL_FR1_GAMMA,
+ ISP_TOP_FOV_FR_MUX_SEL_FR1_OUT_FORMAT_444_FOV,
+ ISP_TOP_FOV_FR_MUX_SEL_FR2_GAMMA,
+ ISP_TOP_FOV_FR_MUX_SEL_FR2_OUT_FORMAT_444_FOV,
+ ISP_TOP_FOV_FR_MUX_SEL_FR3_GAMMA,
+ ISP_TOP_FOV_FR_MUX_SEL_FR3_OUT_FORMAT_444_FOV,
+};
+
+enum mali_c720_top_fov_raw_fr_mux_sel {
+ ISP_TOP_FOV_RAW_FR_MUX_SEL_RAW_TC_LUT,
+ ISP_TOP_FOV_RAW_FR_MUX_SEL_FOV_FR_MUX,
+};
+
+enum mali_c720_top_fr0_hv_cv_mux_sel {
+ ISP_TOP_FR0_HV_CV_MUX_SEL_HV,
+ ISP_TOP_FR0_HV_CV_MUX_SEL_CV,
+};
+
+enum mali_c720_top_inp_cv_mux_sel {
+ ISP_TOP_INP_CV_MUX_SEL_SQRT_A,
+ ISP_TOP_INP_CV_MUX_SEL_REMOSAIC_CV,
+ ISP_TOP_INP_CV_MUX_SEL_CAC,
+ ISP_TOP_INP_CV_MUX_SEL_TEMPER,
+ ISP_TOP_INP_CV_MUX_SEL_SINTER,
+};
+
+enum mali_c720_top_inp_remosaic_cv_mux_sel {
+ ISP_TOP_INP_REMOSAIC_CV_MUX_SEL_REMOSAIC_IR_FULL,
+ ISP_TOP_INP_REMOSAIC_CV_MUX_SEL_REMOSAIC_IR_QUARTER,
+};
+
+enum mali_c720_top_inp_remosaic_ir0_mux_sel {
+ ISP_TOP_INP_REMOSAIC_IR0_MUX_SEL_REMOSAIC_IR_FULL,
+ ISP_TOP_INP_REMOSAIC_IR0_MUX_SEL_REMOSAIC_IR_QUARTER,
+};
+
+enum mali_c720_top_pyr_hv_cv_ir0_mux_sel {
+ ISP_TOP_PYR_HV_CV_IR0_MUX_SEL_HV,
+ ISP_TOP_PYR_HV_CV_IR0_MUX_SEL_CV,
+ ISP_TOP_PYR_HV_CV_IR0_MUX_SEL_REMOSAIC_IR0,
+};
+
+enum mali_c720_top_raw_input_mux_sel {
+ ISP_TOP_RAW_INPUT_MUX_SEL_IN0,
+ ISP_TOP_RAW_INPUT_MUX_SEL_DECOMPANDER,
+ ISP_TOP_RAW_INPUT_MUX_SEL_SQRT_A,
+ ISP_TOP_RAW_INPUT_MUX_SEL_CV_SQUARE_A,
+ ISP_TOP_RAW_INPUT_MUX_SEL_HV_SQUARE_A,
+ ISP_TOP_RAW_INPUT_MUX_SEL_REMOSAIC_IR0,
+};
+
+struct mali_c720_top_regs {
+ const struct mali_c720_irq_regs *irq;
+ const struct mali_c720_pre_cm_regs *pre_cm;
+ const struct mali_c720_precm_tpg_regs *precm_tpgs;
+ const struct mali_c720_pipeline_regs *pipeline;
+};
+
+const struct mali_c720_top_regs *mali_c720_get_top_regs(void);
+
+#endif /* MALI_C720_REGISTERS_TOP_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-registers.c b/drivers/media/platform/arm/mali-c720/mali-c720-registers.c
new file mode 100644
index 0000000000000000000000000000000000000000..d6a731e9c1fa6e9b1579fd53a14c2eb45894f070
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-registers.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/bits.h>
+#include <linux/errno.h>
+
+#include "mali-c720-common.h"
+
+static const struct mali_c720_id_regs id_regs = {
+ .pid4 = { .offset = 0xfd0, .mask = GENMASK(31, 0), .shift = 0 },
+ .pid4_des_2 = { .offset = 0xfd0, .mask = GENMASK(3, 0), .shift = 0 },
+ .pid0 = { .offset = 0xfe0, .mask = GENMASK(31, 0), .shift = 0 },
+ .pid0_part_0 = { .offset = 0xfe0, .mask = GENMASK(7, 0), .shift = 0 },
+ .pid1 = { .offset = 0xfe4, .mask = GENMASK(31, 0), .shift = 0 },
+ .pid1_part_1 = { .offset = 0xfe4, .mask = GENMASK(3, 0), .shift = 0 },
+ .pid1_des_0 = { .offset = 0xfe4, .mask = GENMASK(7, 4), .shift = 4 },
+ .pid2 = { .offset = 0xfe8, .mask = GENMASK(31, 0), .shift = 0 },
+ .pid2_des_1 = { .offset = 0xfe8, .mask = GENMASK(2, 0), .shift = 0 },
+ .pid2_revision = { .offset = 0xfe8, .mask = GENMASK(7, 4), .shift = 4 },
+ .pid3 = { .offset = 0xfec, .mask = GENMASK(31, 0), .shift = 0 },
+ .pid3_cmod = { .offset = 0xfec, .mask = GENMASK(3, 0), .shift = 0 },
+ .pid3_revand = { .offset = 0xfec, .mask = GENMASK(7, 4), .shift = 4 },
+ .cid0_prmbl_0 = { .offset = 0xff0, .mask = GENMASK(7, 0), .shift = 0 },
+ .cid1_prmbl_1 = { .offset = 0xff4, .mask = GENMASK(3, 0), .shift = 0 },
+ .cid1_class = { .offset = 0xff4, .mask = GENMASK(7, 4), .shift = 4 },
+ .cid2_prmbl_2 = { .offset = 0xff8, .mask = GENMASK(7, 0), .shift = 0 },
+ .cid3_prmbl_3 = { .offset = 0xffc, .mask = GENMASK(7, 0), .shift = 0 },
+};
+
+const struct mali_c720_id_regs *mali_c720_get_id_regs(void)
+{
+ return &id_regs;
+}
+
+int mali_c720_get_registers(struct mali_c720_registers *regs)
+{
+ *regs = (struct mali_c720_registers) {
+ .id = &id_regs,
+ .top = mali_c720_get_top_regs(),
+ .cm = mali_c720_get_ctx_mgr_regs(),
+ .modules = mali_c720_get_modules_regs(),
+ .context_offset = 0x80000,
+ .context_size = 0x100000,
+ };
+ return 0;
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-registers.h b/drivers/media/platform/arm/mali-c720/mali-c720-registers.h
new file mode 100644
index 0000000000000000000000000000000000000000..288bd168be41c8569f79ff147c919c7daceaa039
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-registers.h
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_REGISTERS_H
+#define MALI_C720_REGISTERS_H
+
+#include <linux/types.h>
+
+struct mali_c720_top_regs;
+struct mali_c720_ctx_mgr_regs;
+struct mali_c720_modules_regs;
+
+struct mali_c720_reg_field {
+ u32 offset;
+ u32 mask;
+ u8 shift;
+};
+
+struct mali_c720_id_regs {
+ struct mali_c720_reg_field pid4;
+ struct mali_c720_reg_field pid4_des_2;
+ struct mali_c720_reg_field pid0;
+ struct mali_c720_reg_field pid0_part_0;
+ struct mali_c720_reg_field pid1;
+ struct mali_c720_reg_field pid1_part_1;
+ struct mali_c720_reg_field pid1_des_0;
+ struct mali_c720_reg_field pid2;
+ struct mali_c720_reg_field pid2_des_1;
+ struct mali_c720_reg_field pid2_revision;
+ struct mali_c720_reg_field pid3;
+ struct mali_c720_reg_field pid3_cmod;
+ struct mali_c720_reg_field pid3_revand;
+ struct mali_c720_reg_field cid0_prmbl_0;
+ struct mali_c720_reg_field cid1_prmbl_1;
+ struct mali_c720_reg_field cid1_class;
+ struct mali_c720_reg_field cid2_prmbl_2;
+ struct mali_c720_reg_field cid3_prmbl_3;
+};
+
+struct mali_c720_group_regs {
+ u32 offset;
+ u32 size;
+};
+
+struct mali_c720_registers {
+ const struct mali_c720_id_regs *id;
+ const struct mali_c720_top_regs *top;
+ const struct mali_c720_ctx_mgr_regs *cm;
+ const struct mali_c720_modules_regs *modules;
+ u32 context_offset;
+ u32 context_size;
+};
+
+const struct mali_c720_id_regs *mali_c720_get_id_regs(void);
+int mali_c720_get_registers(struct mali_c720_registers *regs);
+
+static inline u32 mali_c720_reg_addr(u32 base, const struct mali_c720_reg_field *field)
+{
+ return base + field->offset;
+}
+
+static inline u32 mali_c720_reg_mask(const struct mali_c720_reg_field *field)
+{
+ return field->mask;
+}
+
+static inline u8 mali_c720_reg_shift(const struct mali_c720_reg_field *field)
+{
+ return field->shift;
+}
+
+static inline u32 mali_c720_group_base(const struct mali_c720_group_regs *group, unsigned int index)
+{
+ return group->offset + index * group->size;
+}
+
+#endif /* MALI_C720_REGISTERS_H */
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 05/24] media: mali-c720: Add hardware identification
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (3 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 04/24] media: mali-c720: Add register access helpers Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 06/24] media: mali-c720: Add format handling Anthony McGivern
` (18 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Read the ISP identification registers and match the device against
the currently supported hardware revisions, rejecting unsupported
hardware.
Add register-map selection based on the identified hardware revision.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../platform/arm/mali-c720/mali-c720-common.h | 3 +
.../media/platform/arm/mali-c720/mali-c720-id.c | 165 +++++++++++++++++++++
.../media/platform/arm/mali-c720/mali-c720-id.h | 34 +++++
.../platform/arm/mali-c720/mali-c720-registers.c | 27 ++--
.../platform/arm/mali-c720/mali-c720-registers.h | 5 +-
5 files changed, 223 insertions(+), 11 deletions(-)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 7cf7380202a4587b844b66b45bfe76f6bac61635..0685bb7e0f5545091a022bf4ed19b3f2b249c2de 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -13,6 +13,7 @@
#include <linux/refcount.h>
#include <linux/spinlock.h>
+#include "mali-c720-id.h"
#include "mali-c720-register-access.h"
#include "mali-c720-registers.h"
#include "mali-c720-registers-top.h"
@@ -40,6 +41,8 @@ struct mali_c720 {
resource_size_t mmio_size;
struct mali_c720_registers registers;
+
+ const struct mali_c720_hw_version *hw_version;
};
#endif /* MALI_C720_COMMON_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-id.c b/drivers/media/platform/arm/mali-c720/mali-c720-id.c
new file mode 100644
index 0000000000000000000000000000000000000000..5d8dc9319e74a6e8bc96673e317a880f1fcf2b61
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-id.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/array_size.h>
+#include <linux/bitfield.h>
+#include <linux/device.h>
+
+#include "mali-c720-common.h"
+
+#define MALI_C720_ID_PART 0x560
+#define MALI_C720_ID_DESIGNER_ARM 0x43b
+#define MALI_C720_ID_PREAMBLE 0xb105000d
+#define MALI_C720_ID_CLASS 0xe
+
+struct mali_c720_id_registers {
+ u32 pid0;
+ u32 pid1;
+ u32 pid2;
+ u32 pid3;
+ u32 pid4;
+ u32 preamble;
+ u32 class;
+};
+
+static const struct mali_c720_hw_version
+mali_c720_supported_hw_versions[MALI_C720_VERSION_ID_MAX] = {
+ [MALI_C720_VERSION_ID_R0_P0] = {
+ .name = "Mali-C720 r0p0",
+ .id = MALI_C720_VERSION_ID_R0_P0,
+ .part = MALI_C720_ID_PART,
+ .revision = 0x0,
+ .revand = 0x0,
+ .cmod = 0x0,
+ },
+ [MALI_C720_VERSION_ID_R0_P1] = {
+ .name = "Mali-C720 r0p1",
+ .id = MALI_C720_VERSION_ID_R0_P1,
+ .part = MALI_C720_ID_PART,
+ .revision = 0x1,
+ .revand = 0x0,
+ .cmod = 0x0,
+ },
+};
+
+static void mali_c720_read_id_registers(struct mali_c720 *mali_c720,
+ struct mali_c720_id_registers *id)
+{
+ const struct mali_c720_id_regs *id_regs = mali_c720->registers.id;
+
+ id->pid0 = mali_c720_read(mali_c720, &id_regs->pid0);
+ id->pid1 = mali_c720_read(mali_c720, &id_regs->pid1);
+ id->pid2 = mali_c720_read(mali_c720, &id_regs->pid2);
+ id->pid3 = mali_c720_read(mali_c720, &id_regs->pid3);
+ id->pid4 = mali_c720_read(mali_c720, &id_regs->pid4);
+
+ /* Assemble the component preamble, keeping the class separate. */
+ id->preamble = mali_c720_read(mali_c720, &id_regs->cid0_prmbl_0);
+ id->preamble |= mali_c720_read(mali_c720, &id_regs->cid1_prmbl_1) << 8;
+ id->preamble |= mali_c720_read(mali_c720, &id_regs->cid2_prmbl_2) << 16;
+ id->preamble |= mali_c720_read(mali_c720, &id_regs->cid3_prmbl_3) << 24;
+ id->class = mali_c720_read(mali_c720, &id_regs->cid1_class);
+}
+
+static u16 mali_c720_id_designer(const struct mali_c720_id_regs *id_regs,
+ const struct mali_c720_id_registers *id)
+{
+ return (u16)(field_get(mali_c720_reg_mask(&id_regs->pid1_des_0), id->pid1) |
+ (field_get(mali_c720_reg_mask(&id_regs->pid2_des_1), id->pid2) << 4) |
+ (field_get(mali_c720_reg_mask(&id_regs->pid4_des_2), id->pid4) << 8));
+}
+
+static u16 mali_c720_id_part(const struct mali_c720_id_regs *id_regs,
+ const struct mali_c720_id_registers *id)
+{
+ return (u16)(field_get(mali_c720_reg_mask(&id_regs->pid0_part_0), id->pid0) |
+ (field_get(mali_c720_reg_mask(&id_regs->pid1_part_1), id->pid1) << 8));
+}
+
+static u8 mali_c720_id_revision(const struct mali_c720_id_regs *id_regs,
+ const struct mali_c720_id_registers *id)
+{
+ return (u8)field_get(mali_c720_reg_mask(&id_regs->pid2_revision), id->pid2);
+}
+
+static u8 mali_c720_id_revand(const struct mali_c720_id_regs *id_regs,
+ const struct mali_c720_id_registers *id)
+{
+ return (u8)field_get(mali_c720_reg_mask(&id_regs->pid3_revand), id->pid3);
+}
+
+static u8 mali_c720_id_cmod(const struct mali_c720_id_regs *id_regs,
+ const struct mali_c720_id_registers *id)
+{
+ return (u8)field_get(mali_c720_reg_mask(&id_regs->pid3_cmod), id->pid3);
+}
+
+static const struct mali_c720_hw_version *
+mali_c720_find_hw_version(const struct mali_c720_id_regs *id_regs,
+ const struct mali_c720_id_registers *id)
+{
+ u16 part = mali_c720_id_part(id_regs, id);
+ u8 revision = mali_c720_id_revision(id_regs, id);
+ u8 revand = mali_c720_id_revand(id_regs, id);
+ u8 cmod = mali_c720_id_cmod(id_regs, id);
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(mali_c720_supported_hw_versions); i++) {
+ const struct mali_c720_hw_version *version =
+ &mali_c720_supported_hw_versions[i];
+
+ if (version->part == part &&
+ version->revision == revision &&
+ version->revand == revand &&
+ version->cmod == cmod)
+ return version;
+ }
+
+ return NULL;
+}
+
+int mali_c720_identify_hw(struct mali_c720 *mali_c720)
+{
+ const struct mali_c720_id_regs *id_regs = mali_c720->registers.id;
+ struct mali_c720_id_registers id;
+ const struct mali_c720_hw_version *version;
+ u16 part, designer;
+ u8 revision, revand, cmod;
+
+ mali_c720_read_id_registers(mali_c720, &id);
+
+ designer = mali_c720_id_designer(id_regs, &id);
+ if (designer != MALI_C720_ID_DESIGNER_ARM)
+ return dev_err_probe(mali_c720->dev, -ENODEV,
+ "unsupported ISP designer ID: %#x\n", designer);
+
+ if (id.preamble != MALI_C720_ID_PREAMBLE)
+ return dev_err_probe(mali_c720->dev, -ENODEV,
+ "unsupported ISP component preamble: %#x\n", id.preamble);
+
+ if (id.class != MALI_C720_ID_CLASS)
+ return dev_err_probe(mali_c720->dev, -ENODEV,
+ "unsupported ISP component class: %#x\n", id.class);
+
+ version = mali_c720_find_hw_version(id_regs, &id);
+ if (!version) {
+ part = mali_c720_id_part(id_regs, &id);
+ revision = mali_c720_id_revision(id_regs, &id);
+ revand = mali_c720_id_revand(id_regs, &id);
+ cmod = mali_c720_id_cmod(id_regs, &id);
+
+ return dev_err_probe(mali_c720->dev, -ENODEV,
+ "unsupported ISP version: part=%#x revision=%u revand=%u cmod=%u\n",
+ part, revision, revand, cmod);
+ }
+
+ mali_c720->hw_version = version;
+
+ dev_info(mali_c720->dev, "detected %s\n", version->name);
+
+ return 0;
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-id.h b/drivers/media/platform/arm/mali-c720/mali-c720-id.h
new file mode 100644
index 0000000000000000000000000000000000000000..2253672a9a46ee65045a1a0c3bc08662b5309b02
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-id.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Hardware identification
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_ID_H
+#define MALI_C720_ID_H
+
+#include <linux/types.h>
+
+#define MALI_C720_ID_SIZE 0x1000
+
+struct mali_c720;
+
+enum mali_c720_version_id {
+ MALI_C720_VERSION_ID_R0_P0,
+ MALI_C720_VERSION_ID_R0_P1,
+ MALI_C720_VERSION_ID_MAX,
+};
+
+struct mali_c720_hw_version {
+ const char *name;
+ enum mali_c720_version_id id;
+ u16 part;
+ u8 revision;
+ u8 revand;
+ u8 cmod;
+};
+
+int mali_c720_identify_hw(struct mali_c720 *mali_c720);
+
+#endif /* MALI_C720_ID_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-registers.c b/drivers/media/platform/arm/mali-c720/mali-c720-registers.c
index d6a731e9c1fa6e9b1579fd53a14c2eb45894f070..1c2d0ad7948d41ebc7d9666effb881f72ce0ed43 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-registers.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-registers.c
@@ -36,15 +36,22 @@ const struct mali_c720_id_regs *mali_c720_get_id_regs(void)
return &id_regs;
}
-int mali_c720_get_registers(struct mali_c720_registers *regs)
+int mali_c720_get_registers(enum mali_c720_version_id version,
+ struct mali_c720_registers *regs)
{
- *regs = (struct mali_c720_registers) {
- .id = &id_regs,
- .top = mali_c720_get_top_regs(),
- .cm = mali_c720_get_ctx_mgr_regs(),
- .modules = mali_c720_get_modules_regs(),
- .context_offset = 0x80000,
- .context_size = 0x100000,
- };
- return 0;
+ switch (version) {
+ case MALI_C720_VERSION_ID_R0_P0:
+ case MALI_C720_VERSION_ID_R0_P1:
+ *regs = (struct mali_c720_registers) {
+ .id = &id_regs,
+ .top = mali_c720_get_top_regs(),
+ .cm = mali_c720_get_ctx_mgr_regs(),
+ .modules = mali_c720_get_modules_regs(),
+ .context_offset = 0x80000,
+ .context_size = 0x100000,
+ };
+ return 0;
+ default:
+ return -ENODEV;
+ }
}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-registers.h b/drivers/media/platform/arm/mali-c720/mali-c720-registers.h
index 288bd168be41c8569f79ff147c919c7daceaa039..c1697d19b22907a24396b6f295287919c528c72b 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-registers.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-registers.h
@@ -10,6 +10,8 @@
#include <linux/types.h>
+enum mali_c720_version_id;
+
struct mali_c720_top_regs;
struct mali_c720_ctx_mgr_regs;
struct mali_c720_modules_regs;
@@ -56,7 +58,8 @@ struct mali_c720_registers {
};
const struct mali_c720_id_regs *mali_c720_get_id_regs(void);
-int mali_c720_get_registers(struct mali_c720_registers *regs);
+int mali_c720_get_registers(enum mali_c720_version_id version,
+ struct mali_c720_registers *regs);
static inline u32 mali_c720_reg_addr(u32 base, const struct mali_c720_reg_field *field)
{
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 06/24] media: mali-c720: Add format handling
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (4 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 05/24] media: mali-c720: Add hardware identification Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 07/24] media: mali-c720: Add hardware discovery support Anthony McGivern
` (17 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Define the supported media bus and capture formats, their bit depths
and hardware buffer layouts. Add helpers to select formats and check
which capture outputs support them.
A future series may extend format enumeration to expose different sets
of supported formats depending on the hardware version.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../platform/arm/mali-c720/mali-c720-common.h | 8 +
.../platform/arm/mali-c720/mali-c720-formats.c | 452 +++++++++++++++++++++
.../platform/arm/mali-c720/mali-c720-formats.h | 132 ++++++
3 files changed, 592 insertions(+)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 0685bb7e0f5545091a022bf4ed19b3f2b249c2de..4f8e2918937c1ca212a11ccc6c4a0edb72dca72c 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -12,7 +12,9 @@
#include <linux/mutex.h>
#include <linux/refcount.h>
#include <linux/spinlock.h>
+#include <linux/videodev2.h>
+#include "mali-c720-formats.h"
#include "mali-c720-id.h"
#include "mali-c720-register-access.h"
#include "mali-c720-registers.h"
@@ -20,6 +22,12 @@
#include "mali-c720-registers-ctx-mgr.h"
#include "mali-c720-registers-modules.h"
+enum mali_c720_cap_devs {
+ MALI_C720_CAP_DEV_FR0_RGB,
+ MALI_C720_CAP_DEV_FR0_YUV,
+ MALI_C720_MAX_NUM_CAP_DEVS,
+};
+
struct mali_c720_context_regs {
dma_addr_t dma_handle;
u8 *base;
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-formats.c b/drivers/media/platform/arm/mali-c720/mali-c720-formats.c
new file mode 100644
index 0000000000000000000000000000000000000000..a4a1ae89327886fdd1d728a8b0b548dc555658ce
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-formats.c
@@ -0,0 +1,452 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/array_size.h>
+#include <linux/media-bus-format.h>
+
+#include "mali-c720-common.h"
+
+static const struct mali_c720_buffer_cfg mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_MAX] = {
+ [MALI_C720_BUFFER_CFG_BAYER24] = {
+ .data_format = 23,
+ .data_layout = MALI_C720_BUFFER_LAYOUT_NORMAL,
+ .data_align = MALI_C720_BUFFER_ALIGN_DENSE,
+ .num_fifos = 1,
+ },
+
+ [MALI_C720_BUFFER_CFG_BAYER20_DENSE] = {
+ .data_format = 19,
+ .data_layout = MALI_C720_BUFFER_LAYOUT_NORMAL,
+ .data_align = MALI_C720_BUFFER_ALIGN_DENSE,
+ .num_fifos = 1,
+ },
+
+ [MALI_C720_BUFFER_CFG_BAYER16] = {
+ .data_format = 15,
+ .data_layout = MALI_C720_BUFFER_LAYOUT_NORMAL,
+ .data_align = MALI_C720_BUFFER_ALIGN_DENSE,
+ .num_fifos = 1,
+ },
+
+ [MALI_C720_BUFFER_CFG_BAYER14_DENSE] = {
+ .data_format = 13,
+ .data_layout = MALI_C720_BUFFER_LAYOUT_NORMAL,
+ .data_align = MALI_C720_BUFFER_ALIGN_DENSE,
+ .num_fifos = 1,
+ },
+
+ [MALI_C720_BUFFER_CFG_BAYER12_DENSE] = {
+ .data_format = 11,
+ .data_layout = MALI_C720_BUFFER_LAYOUT_NORMAL,
+ .data_align = MALI_C720_BUFFER_ALIGN_DENSE,
+ .num_fifos = 1,
+ },
+
+ [MALI_C720_BUFFER_CFG_BAYER10_DENSE] = {
+ .data_format = 9,
+ .data_layout = MALI_C720_BUFFER_LAYOUT_NORMAL,
+ .data_align = MALI_C720_BUFFER_ALIGN_DENSE,
+ .num_fifos = 1,
+ },
+
+ [MALI_C720_BUFFER_CFG_BAYER8] = {
+ .data_format = 7,
+ .data_layout = MALI_C720_BUFFER_LAYOUT_NORMAL,
+ .data_align = MALI_C720_BUFFER_ALIGN_DENSE,
+ .num_fifos = 1,
+ },
+
+ [MALI_C720_BUFFER_CFG_3SEMIPLANE_24BIT] = {
+ .data_format = 48,
+ .data_layout = MALI_C720_BUFFER_LAYOUT_NORMAL,
+ .data_align = MALI_C720_BUFFER_ALIGN_DENSE,
+ .num_fifos = 1,
+ },
+
+ [MALI_C720_BUFFER_CFG_NV12] = {
+ .data_format = 144,
+ .data_layout = MALI_C720_BUFFER_LAYOUT_NORMAL,
+ .data_align = MALI_C720_BUFFER_ALIGN_DENSE,
+ .num_fifos = 2,
+ },
+};
+
+static const struct mali_c720_mbus_format_info mali_c720_mbus_fmts[] = {
+ {
+ .type = MALI_C720_FORMAT_BAYER_RGGB,
+ .depth = MALI_C720_FORMAT_24BIT,
+ .bit_depth = 24,
+ .code = MEDIA_BUS_FMT_SRGGB24_1X24,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER24],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_RGGB,
+ .depth = MALI_C720_FORMAT_20BIT,
+ .bit_depth = 20,
+ .code = MEDIA_BUS_FMT_SRGGB20_1X20,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER20_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_RGGB,
+ .depth = MALI_C720_FORMAT_16BIT,
+ .bit_depth = 16,
+ .code = MEDIA_BUS_FMT_SRGGB16_1X16,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER16],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_RGGB,
+ .depth = MALI_C720_FORMAT_14BIT,
+ .bit_depth = 14,
+ .code = MEDIA_BUS_FMT_SRGGB14_1X14,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER14_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_RGGB,
+ .depth = MALI_C720_FORMAT_12BIT,
+ .bit_depth = 12,
+ .code = MEDIA_BUS_FMT_SRGGB12_1X12,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER12_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_RGGB,
+ .depth = MALI_C720_FORMAT_10BIT,
+ .bit_depth = 10,
+ .code = MEDIA_BUS_FMT_SRGGB10_1X10,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER10_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_RGGB,
+ .depth = MALI_C720_FORMAT_8BIT,
+ .bit_depth = 8,
+ .code = MEDIA_BUS_FMT_SRGGB8_1X8,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER8],
+ },
+
+ {
+ .type = MALI_C720_FORMAT_BAYER_GRBG,
+ .depth = MALI_C720_FORMAT_24BIT,
+ .bit_depth = 24,
+ .code = MEDIA_BUS_FMT_SGRBG24_1X24,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER24],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GRBG,
+ .depth = MALI_C720_FORMAT_20BIT,
+ .bit_depth = 20,
+ .code = MEDIA_BUS_FMT_SGRBG20_1X20,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER20_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GRBG,
+ .depth = MALI_C720_FORMAT_16BIT,
+ .bit_depth = 16,
+ .code = MEDIA_BUS_FMT_SGRBG16_1X16,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER16],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GRBG,
+ .depth = MALI_C720_FORMAT_14BIT,
+ .bit_depth = 14,
+ .code = MEDIA_BUS_FMT_SGRBG14_1X14,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER14_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GRBG,
+ .depth = MALI_C720_FORMAT_12BIT,
+ .bit_depth = 12,
+ .code = MEDIA_BUS_FMT_SGRBG12_1X12,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER12_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GRBG,
+ .depth = MALI_C720_FORMAT_10BIT,
+ .bit_depth = 10,
+ .code = MEDIA_BUS_FMT_SGRBG10_1X10,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER10_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GRBG,
+ .depth = MALI_C720_FORMAT_8BIT,
+ .bit_depth = 8,
+ .code = MEDIA_BUS_FMT_SGRBG8_1X8,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER8],
+ },
+
+ {
+ .type = MALI_C720_FORMAT_BAYER_GBRG,
+ .depth = MALI_C720_FORMAT_24BIT,
+ .bit_depth = 24,
+ .code = MEDIA_BUS_FMT_SGBRG24_1X24,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER24],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GBRG,
+ .depth = MALI_C720_FORMAT_20BIT,
+ .bit_depth = 20,
+ .code = MEDIA_BUS_FMT_SGBRG20_1X20,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER20_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GBRG,
+ .depth = MALI_C720_FORMAT_16BIT,
+ .bit_depth = 16,
+ .code = MEDIA_BUS_FMT_SGBRG16_1X16,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER16],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GBRG,
+ .depth = MALI_C720_FORMAT_14BIT,
+ .bit_depth = 14,
+ .code = MEDIA_BUS_FMT_SGBRG14_1X14,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER14_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GBRG,
+ .depth = MALI_C720_FORMAT_12BIT,
+ .bit_depth = 12,
+ .code = MEDIA_BUS_FMT_SGBRG12_1X12,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER12_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GBRG,
+ .depth = MALI_C720_FORMAT_10BIT,
+ .bit_depth = 10,
+ .code = MEDIA_BUS_FMT_SGBRG10_1X10,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER10_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_GBRG,
+ .depth = MALI_C720_FORMAT_8BIT,
+ .bit_depth = 8,
+ .code = MEDIA_BUS_FMT_SGBRG8_1X8,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER8],
+ },
+
+ {
+ .type = MALI_C720_FORMAT_BAYER_BGGR,
+ .depth = MALI_C720_FORMAT_24BIT,
+ .bit_depth = 24,
+ .code = MEDIA_BUS_FMT_SBGGR24_1X24,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER24],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_BGGR,
+ .depth = MALI_C720_FORMAT_20BIT,
+ .bit_depth = 20,
+ .code = MEDIA_BUS_FMT_SBGGR20_1X20,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER20_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_BGGR,
+ .depth = MALI_C720_FORMAT_16BIT,
+ .bit_depth = 16,
+ .code = MEDIA_BUS_FMT_SBGGR16_1X16,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER16],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_BGGR,
+ .depth = MALI_C720_FORMAT_14BIT,
+ .bit_depth = 14,
+ .code = MEDIA_BUS_FMT_SBGGR14_1X14,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER14_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_BGGR,
+ .depth = MALI_C720_FORMAT_12BIT,
+ .bit_depth = 12,
+ .code = MEDIA_BUS_FMT_SBGGR12_1X12,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER12_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_BGGR,
+ .depth = MALI_C720_FORMAT_10BIT,
+ .bit_depth = 10,
+ .code = MEDIA_BUS_FMT_SBGGR10_1X10,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER10_DENSE],
+ },
+ {
+ .type = MALI_C720_FORMAT_BAYER_BGGR,
+ .depth = MALI_C720_FORMAT_8BIT,
+ .bit_depth = 8,
+ .code = MEDIA_BUS_FMT_SBGGR8_1X8,
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_BAYER8],
+ },
+
+ {
+ .type = MALI_C720_FORMAT_RGB,
+ .depth = MALI_C720_FORMAT_16BIT,
+ .bit_depth = 16,
+ .code = MEDIA_BUS_FMT_RGB161616_1X48
+ },
+ {
+ .type = MALI_C720_FORMAT_RGB,
+ .depth = MALI_C720_FORMAT_12BIT,
+ .bit_depth = 12,
+ .code = MEDIA_BUS_FMT_RGB121212_1X36
+ },
+
+ {
+ .type = MALI_C720_FORMAT_YUV,
+ .depth = MALI_C720_FORMAT_16BIT,
+ .bit_depth = 16,
+ .code = MEDIA_BUS_FMT_YUV16_1X48
+ },
+};
+
+static const struct mali_c720_v4l2_format_info mali_c720_v4l2_fmts[] = {
+ /* RGB formats */
+ {
+ .fourcc = V4L2_PIX_FMT_RGB24,
+ .mbus_code = MEDIA_BUS_FMT_RGB161616_1X48,
+
+ .comp_planes = 1,
+ .bpp = { 24, 0, 0, 0 },
+ .hdiv = 1,
+ .vdiv = 1,
+
+ .supported_mask = BIT(MALI_C720_CAP_DEV_FR0_RGB),
+
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_3SEMIPLANE_24BIT],
+ },
+
+ /* YUV formats */
+ {
+ .fourcc = V4L2_PIX_FMT_NV12,
+ .mbus_code = MEDIA_BUS_FMT_YUV16_1X48,
+
+ .comp_planes = 2,
+ .bpp = { 8, 16, 0, 0 },
+ .hdiv = 2,
+ .vdiv = 2,
+
+ .supported_mask = BIT(MALI_C720_CAP_DEV_FR0_YUV),
+
+ .buffer_cfg = &mali_c720_buffer_configs[MALI_C720_BUFFER_CFG_NV12],
+ },
+};
+
+int mali_c720_validate_mbus_format_match(const struct mali_c720_mbus_format_info *format,
+ const struct mali_c720_mbus_format_match *match)
+{
+ return (match->type_mask & format->type) &&
+ (match->depth_mask & format->depth);
+}
+
+const struct mali_c720_mbus_format_info *
+mali_c720_get_mbus_config_by_code(u32 code)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(mali_c720_mbus_fmts); i++) {
+ if (mali_c720_mbus_fmts[i].code == code)
+ return &mali_c720_mbus_fmts[i];
+ }
+
+ return NULL;
+}
+
+const struct mali_c720_mbus_format_info *
+mali_c720_get_mbus_config_by_matched_index(unsigned int index,
+ const struct mali_c720_mbus_format_match *match)
+{
+ unsigned int i;
+ unsigned int count = 0;
+
+ for (i = 0; i < ARRAY_SIZE(mali_c720_mbus_fmts); i++) {
+ if (!mali_c720_validate_mbus_format_match(&mali_c720_mbus_fmts[i],
+ match))
+ continue;
+
+ if (count++ == index)
+ return &mali_c720_mbus_fmts[i];
+ }
+
+ return NULL;
+}
+
+const struct mali_c720_mbus_format_info *
+mali_c720_shift_mbus_format(const struct mali_c720_mbus_format_info *format,
+ enum mali_c720_format_depth out_depth)
+{
+ unsigned int i;
+
+ if (format->depth == out_depth)
+ return format;
+
+ for (i = 0; i < ARRAY_SIZE(mali_c720_mbus_fmts); i++) {
+ if (mali_c720_mbus_fmts[i].type == format->type &&
+ mali_c720_mbus_fmts[i].depth == out_depth)
+ return &mali_c720_mbus_fmts[i];
+ }
+
+ return NULL;
+}
+
+bool
+mali_c720_mbus_code_supports_fmt(const struct mali_c720_v4l2_format_info *fmt,
+ u32 code)
+{
+ /* Display all formats if no code is provided */
+ if (!code)
+ return true;
+
+ return fmt->mbus_code == code;
+}
+
+bool
+mali_c720_format_supported_by_vdev(const struct mali_c720_v4l2_format_info *fmt,
+ unsigned int dev_id)
+{
+ if (fmt->supported_mask & BIT(dev_id))
+ return true;
+
+ return false;
+}
+
+static int
+mali_c720_validate_v4l2_format_match(const struct mali_c720_v4l2_format_info *format,
+ const struct mali_c720_v4l2_format_match *match)
+{
+ if (!mali_c720_mbus_code_supports_fmt(format, match->mbus_code))
+ return 0;
+
+ if (!mali_c720_format_supported_by_vdev(format, match->dev_id))
+ return 0;
+
+ return 1;
+}
+
+const struct mali_c720_v4l2_format_info *
+mali_c720_get_v4l2_config_by_fourcc(u32 fourcc)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(mali_c720_v4l2_fmts); i++) {
+ if (mali_c720_v4l2_fmts[i].fourcc == fourcc)
+ return &mali_c720_v4l2_fmts[i];
+ }
+
+ return NULL;
+}
+
+const struct mali_c720_v4l2_format_info *
+mali_c720_get_v4l2_config_by_matched_index(unsigned int index,
+ const struct mali_c720_v4l2_format_match *match)
+{
+ unsigned int i;
+ unsigned int count = 0;
+
+ for (i = 0; i < ARRAY_SIZE(mali_c720_v4l2_fmts); i++) {
+ if (!mali_c720_validate_v4l2_format_match(&mali_c720_v4l2_fmts[i], match))
+ continue;
+
+ if (count++ == index)
+ return &mali_c720_v4l2_fmts[i];
+ }
+
+ return NULL;
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-formats.h b/drivers/media/platform/arm/mali-c720/mali-c720-formats.h
new file mode 100644
index 0000000000000000000000000000000000000000..5d6f01a14296028ac69affbcbb1e7df3ea62f012
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-formats.h
@@ -0,0 +1,132 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_FORMATS_H
+#define MALI_C720_FORMATS_H
+
+#include <linux/bits.h>
+#include <linux/types.h>
+
+enum mali_c720_format_type {
+ MALI_C720_FORMAT_BAYER_RGGB = BIT(0),
+ MALI_C720_FORMAT_BAYER_GRBG = BIT(1),
+ MALI_C720_FORMAT_BAYER_GBRG = BIT(2),
+ MALI_C720_FORMAT_BAYER_BGGR = BIT(3),
+ MALI_C720_FORMAT_RGB = BIT(4),
+ MALI_C720_FORMAT_YUV = BIT(5),
+};
+
+#define MALI_C720_FORMAT_BAYER (MALI_C720_FORMAT_BAYER_RGGB | \
+ MALI_C720_FORMAT_BAYER_GRBG | \
+ MALI_C720_FORMAT_BAYER_GBRG | \
+ MALI_C720_FORMAT_BAYER_BGGR)
+
+enum mali_c720_format_depth {
+ MALI_C720_FORMAT_8BIT = BIT(0),
+ MALI_C720_FORMAT_10BIT = BIT(1),
+ MALI_C720_FORMAT_12BIT = BIT(2),
+ MALI_C720_FORMAT_14BIT = BIT(3),
+ MALI_C720_FORMAT_16BIT = BIT(4),
+ MALI_C720_FORMAT_20BIT = BIT(5),
+ MALI_C720_FORMAT_24BIT = BIT(6),
+};
+
+enum mali_c720_buffer_layout_ids {
+ MALI_C720_BUFFER_LAYOUT_NORMAL,
+ MALI_C720_BUFFER_LAYOUT_ALTERNATE,
+};
+
+enum mali_c720_buffer_align_ids {
+ MALI_C720_BUFFER_ALIGN_DENSE = 0,
+ MALI_C720_BUFFER_ALIGN_LSB = 2,
+ MALI_C720_BUFFER_ALIGN_MSB = 3,
+};
+
+enum mali_c720_buffer_cfg_ids {
+ /* Bayer */
+ MALI_C720_BUFFER_CFG_BAYER24,
+ MALI_C720_BUFFER_CFG_BAYER20_DENSE,
+ MALI_C720_BUFFER_CFG_BAYER16,
+ MALI_C720_BUFFER_CFG_BAYER14_DENSE,
+ MALI_C720_BUFFER_CFG_BAYER12_DENSE,
+ MALI_C720_BUFFER_CFG_BAYER10_DENSE,
+ MALI_C720_BUFFER_CFG_BAYER8,
+
+ /* Packed/Planar for RGB and YUV */
+ MALI_C720_BUFFER_CFG_3SEMIPLANE_24BIT,
+
+ /* YUV */
+ MALI_C720_BUFFER_CFG_NV12,
+
+ MALI_C720_BUFFER_CFG_MAX,
+};
+
+struct mali_c720_buffer_cfg {
+ unsigned int data_format;
+ unsigned int data_layout;
+ unsigned int data_align;
+ unsigned int num_fifos;
+};
+
+struct mali_c720_v4l2_format_match {
+ u32 mbus_code;
+ unsigned int dev_id;
+};
+
+struct mali_c720_v4l2_format_info {
+ u32 fourcc;
+ unsigned int mbus_code;
+
+ unsigned int comp_planes;
+ unsigned int bpp[4];
+ unsigned int hdiv;
+ unsigned int vdiv;
+
+ /* Mask designating which of the available video devs support this format. */
+ unsigned int supported_mask;
+
+ const struct mali_c720_buffer_cfg *buffer_cfg;
+};
+
+struct mali_c720_mbus_format_match {
+ unsigned int type_mask;
+ unsigned int depth_mask;
+};
+
+struct mali_c720_mbus_format_info {
+ enum mali_c720_format_type type;
+ enum mali_c720_format_depth depth;
+ unsigned int bit_depth;
+ u32 code;
+
+ const struct mali_c720_buffer_cfg *buffer_cfg;
+};
+
+int mali_c720_validate_mbus_format_match(const struct mali_c720_mbus_format_info *format,
+ const struct mali_c720_mbus_format_match *match);
+const struct mali_c720_mbus_format_info *
+mali_c720_get_mbus_config_by_code(u32 code);
+const struct mali_c720_mbus_format_info *
+mali_c720_get_mbus_config_by_matched_index(unsigned int index,
+ const struct mali_c720_mbus_format_match *match);
+const struct mali_c720_mbus_format_info *
+mali_c720_shift_mbus_format(const struct mali_c720_mbus_format_info *format,
+ enum mali_c720_format_depth out_depth);
+
+bool
+mali_c720_mbus_code_supports_fmt(const struct mali_c720_v4l2_format_info *fmt,
+ u32 code);
+bool
+mali_c720_format_supported_by_vdev(const struct mali_c720_v4l2_format_info *fmt,
+ unsigned int dev_id);
+const struct mali_c720_v4l2_format_info *
+mali_c720_get_v4l2_config_by_fourcc(u32 fourcc);
+const struct mali_c720_v4l2_format_info *
+mali_c720_get_v4l2_config_by_matched_index(unsigned int index,
+ const struct mali_c720_v4l2_format_match *match);
+
+#endif /* MALI_C720_FORMATS_H */
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 07/24] media: mali-c720: Add hardware discovery support
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (5 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 06/24] media: mali-c720: Add format handling Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 08/24] media: mali-c720: Add context manager and interrupt handling Anthony McGivern
` (16 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
The Mali-C720 can be configured at synthesis time with different
pipelines and processing modules. Its discovery table describes the
resulting hardware configuration.
Parse and validate this table during probe, cache its records and
provide helpers to locate pipelines, modules, register addresses and
memory tables.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../platform/arm/mali-c720/mali-c720-common.h | 2 +
.../platform/arm/mali-c720/mali-c720-discovery.c | 1172 ++++++++++++++++++++
.../platform/arm/mali-c720/mali-c720-discovery.h | 212 ++++
3 files changed, 1386 insertions(+)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 4f8e2918937c1ca212a11ccc6c4a0edb72dca72c..3efbf7572e5015a57124b6f623ba5e1d757bf22a 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -14,6 +14,7 @@
#include <linux/spinlock.h>
#include <linux/videodev2.h>
+#include "mali-c720-discovery.h"
#include "mali-c720-formats.h"
#include "mali-c720-id.h"
#include "mali-c720-register-access.h"
@@ -50,6 +51,7 @@ struct mali_c720 {
struct mali_c720_registers registers;
+ struct mali_c720_discovery discovery;
const struct mali_c720_hw_version *hw_version;
};
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-discovery.c b/drivers/media/platform/arm/mali-c720/mali-c720-discovery.c
new file mode 100644
index 0000000000000000000000000000000000000000..19d88481763092b5a8d8b8de58cb56f5bdacaaaf
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-discovery.c
@@ -0,0 +1,1172 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/bitfield.h>
+#include <linux/bitops.h>
+#include <linux/crc-itu-t.h>
+#include <linux/dev_printk.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include "mali-c720-common.h"
+
+#define CAPABILITY_DISCOVERY_HEADER_OFFSET 0x0
+
+#define MALI_C720_DISC_V1_FIELD_ID_MASK GENMASK(7, 0)
+#define MALI_C720_DISC_V1_LIST_VERSION_MASK GENMASK(11, 8)
+#define MALI_C720_DISC_V1_LIST_DESC_COUNT_MASK GENMASK(31, 16)
+#define MALI_C720_DISC_V1_SUBPIPE_INSTANCE_MASK GENMASK(10, 8)
+#define MALI_C720_DISC_V1_SUBPIPE_TYPE_MASK GENMASK(15, 11)
+#define MALI_C720_DISC_V1_SUBPIPE_DESC_COUNT_MASK GENMASK(31, 16)
+#define MALI_C720_DISC_V1_MODULE_INSTANCE_MASK GENMASK(10, 8)
+#define MALI_C720_DISC_V1_MODULE_REMOVED_MASK BIT(14)
+#define MALI_C720_DISC_V1_MODULE_OFFSET_MASK GENMASK(31, 16)
+#define MALI_C720_DISC_V1_MEMORY_TABLE_ID_MASK GENMASK(9, 8)
+#define MALI_C720_DISC_V1_MEMORY_SIZE_MASK GENMASK(13, 10)
+#define MALI_C720_DISC_V1_MEMORY_SCALAR_SUFFIX_MASK BIT(14)
+#define MALI_C720_DISC_V1_MEMORY_OFFSET_MASK GENMASK(31, 16)
+#define MALI_C720_DISC_V1_PARAM_ID_MASK GENMASK(15, 8)
+#define MALI_C720_DISC_V1_PARAM_VALUE_MASK GENMASK(31, 16)
+#define MALI_C720_DISC_V1_VERSION_PATCH_MASK GENMASK(15, 8)
+#define MALI_C720_DISC_V1_VERSION_MINOR_MASK GENMASK(23, 16)
+#define MALI_C720_DISC_V1_VERSION_MAJOR_MASK GENMASK(31, 24)
+#define MALI_C720_DISC_V1_FOOTER_CRC_MASK GENMASK(31, 16)
+
+#define MALI_C720_DISC_V1_FIELD_LIST_HEADER 0xf0
+#define MALI_C720_DISC_V1_FIELD_SUBPIPE_HEADER 0xf1
+#define MALI_C720_DISC_V1_FIELD_SUBPIPE_FOOTER 0xf2
+#define MALI_C720_DISC_V1_FIELD_EXT_MEMORY 0xf8
+#define MALI_C720_DISC_V1_FIELD_EXT_VERSION 0xf9
+#define MALI_C720_DISC_V1_FIELD_EXT_PARAMETER 0xfa
+#define MALI_C720_DISC_V1_FIELD_LIST_FOOTER 0xff
+
+enum mali_c720_disc_v1_subpipe_id {
+ MALI_C720_DISC_V1_SUBPIPE_ID_INPUT,
+ MALI_C720_DISC_V1_SUBPIPE_ID_HV,
+ MALI_C720_DISC_V1_SUBPIPE_ID_CV,
+ MALI_C720_DISC_V1_SUBPIPE_ID_RAW_OUTPUT,
+ MALI_C720_DISC_V1_SUBPIPE_ID_FR_OUTPUT,
+ MALI_C720_DISC_V1_SUBPIPE_ID_PYR_OUTPUT,
+ MALI_C720_DISC_V1_SUBPIPE_ID_FOV_OUTPUT,
+ MALI_C720_DISC_V1_SUBPIPE_ID_STATS,
+ MALI_C720_DISC_V1_SUBPIPE_ID_TPG,
+ MALI_C720_DISC_V1_SUBPIPE_ID_MAX,
+};
+
+enum mali_c720_disc_v1_module_id {
+ MALI_C720_DISC_V1_MODULE_ID_CM_FULL = 0x00,
+ MALI_C720_DISC_V1_MODULE_ID_GLOBAL_ISP_CONTROL = 0x01,
+ MALI_C720_DISC_V1_MODULE_ID_INTERRUPT_CONTROLLER = 0x02,
+ MALI_C720_DISC_V1_MODULE_ID_FAULT_COLLECTOR = 0x03,
+ MALI_C720_DISC_V1_MODULE_ID_MODULE_BIST_CONTROL = 0x04,
+ MALI_C720_DISC_V1_MODULE_ID_MODULE_CRC_CONTROL = 0x05,
+ MALI_C720_DISC_V1_MODULE_ID_MODULE_CG_CONTROL = 0x06,
+ MALI_C720_DISC_V1_MODULE_ID_CM_CONTROL = 0x0f,
+ MALI_C720_DISC_V1_MODULE_ID_CM_SLOT_LOADABLE = 0x10,
+ MALI_C720_DISC_V1_MODULE_ID_PIPELINE_GLOBAL_CONTROL = 0x12,
+ MALI_C720_DISC_V1_MODULE_ID_DIGITAL_GAIN = 0x18,
+ MALI_C720_DISC_V1_MODULE_ID_GAIN_AND_OFFSET = 0x19,
+ MALI_C720_DISC_V1_MODULE_ID_BLACK_LEVEL = 0x1c,
+ MALI_C720_DISC_V1_MODULE_ID_WB_GAIN = 0x1d,
+ MALI_C720_DISC_V1_MODULE_ID_OFFSET = 0x1e,
+ MALI_C720_DISC_V1_MODULE_ID_SQUARE_ROOT_RAW = 0x20,
+ MALI_C720_DISC_V1_MODULE_ID_SQUARE_RAW = 0x21,
+ MALI_C720_DISC_V1_MODULE_ID_SQUARE_ROOT_RGB = 0x24,
+ MALI_C720_DISC_V1_MODULE_ID_SQUARE_RGB = 0x25,
+ MALI_C720_DISC_V1_MODULE_ID_DECOMPANDER = 0x28,
+ MALI_C720_DISC_V1_MODULE_ID_FRAME_STITCHING = 0x29,
+ MALI_C720_DISC_V1_MODULE_ID_DEFECT_PIXEL = 0x30,
+ MALI_C720_DISC_V1_MODULE_ID_RGBIR_REMOSAIC = 0x31,
+ MALI_C720_DISC_V1_MODULE_ID_CA_CORRECTION = 0x32,
+ MALI_C720_DISC_V1_MODULE_ID_TEMPER = 0x33,
+ MALI_C720_DISC_V1_MODULE_ID_SINTER = 0x34,
+ MALI_C720_DISC_V1_MODULE_ID_SMART_SHADING = 0x40,
+ MALI_C720_DISC_V1_MODULE_ID_RAW_TO_INTENSITY = 0x41,
+ MALI_C720_DISC_V1_MODULE_ID_DEHAZE = 0x42,
+ MALI_C720_DISC_V1_MODULE_ID_IRIDIX = 0x43,
+ MALI_C720_DISC_V1_MODULE_ID_DEMOSAIC_STD = 0x44,
+ MALI_C720_DISC_V1_MODULE_ID_DEMOSAIC_DFD = 0x45,
+ MALI_C720_DISC_V1_MODULE_ID_PURPLE_FRINGE = 0x46,
+ MALI_C720_DISC_V1_MODULE_ID_CCM = 0x47,
+ MALI_C720_DISC_V1_MODULE_ID_CNR = 0x48,
+ MALI_C720_DISC_V1_MODULE_ID_SCALER_RGB = 0x50,
+ MALI_C720_DISC_V1_MODULE_ID_SCALER_RAW = 0x51,
+ MALI_C720_DISC_V1_MODULE_ID_CROP = 0x54,
+ MALI_C720_DISC_V1_MODULE_ID_SHARPENING_RGB = 0x58,
+ MALI_C720_DISC_V1_MODULE_ID_SHARPENING_RAW = 0x59,
+ MALI_C720_DISC_V1_MODULE_ID_GAMMA = 0x5c,
+ MALI_C720_DISC_V1_MODULE_ID_TC_LUT_RGB = 0x5d,
+ MALI_C720_DISC_V1_MODULE_ID_TC_LUT_RAW = 0x5e,
+ MALI_C720_DISC_V1_MODULE_ID_OUTPUT_FORMATTER = 0x60,
+ MALI_C720_DISC_V1_MODULE_ID_OUTPUT_MULTIPLEXER = 0x61,
+ MALI_C720_DISC_V1_MODULE_ID_GAUSSIAN_PYRAMID = 0x62,
+ MALI_C720_DISC_V1_MODULE_ID_RAW_STREAM_PACKER = 0x63,
+ MALI_C720_DISC_V1_MODULE_ID_TPG_RAW_MULTI = 0x67,
+ MALI_C720_DISC_V1_MODULE_ID_TPG_RAW_SINGLE = 0x68,
+ MALI_C720_DISC_V1_MODULE_ID_TPG_RAW_RGB_SINGLE = 0x69,
+ MALI_C720_DISC_V1_MODULE_ID_FGM = 0x6a,
+ MALI_C720_DISC_V1_MODULE_ID_FBIST_BRIDGE = 0x6b,
+ MALI_C720_DISC_V1_MODULE_ID_PIPELINE_CRC = 0x6c,
+ MALI_C720_DISC_V1_MODULE_ID_INPUT_CRC = 0x6d,
+ MALI_C720_DISC_V1_MODULE_ID_INTENSITY_STATS = 0x70,
+ MALI_C720_DISC_V1_MODULE_ID_HISTOGRAM_STATS = 0x71,
+ MALI_C720_DISC_V1_MODULE_ID_COLOR_STATS = 0x72,
+ MALI_C720_DISC_V1_MODULE_ID_AUTO_FOCUS_STATS = 0x73,
+};
+
+enum mali_c720_disc_v1_table_ca_correction_id {
+ MALI_C720_DISC_V1_TABLE_CA_CORRECTION_COORD_MEM_ID = 0,
+ MALI_C720_DISC_V1_TABLE_CA_CORRECTION_FILTER_MEM_ID,
+ MALI_C720_DISC_V1_TABLE_CA_CORRECTION_MAX_ID,
+};
+
+enum mali_c720_disc_v1_table_smart_shading_id {
+ MALI_C720_DISC_V1_TABLE_SMART_SHADING_MEM_ID = 0,
+ MALI_C720_DISC_V1_TABLE_SMART_SHADING_MAX_ID,
+};
+
+enum mali_c720_disc_v1_table_dehaze_id {
+ MALI_C720_DISC_V1_TABLE_DEHAZE_MEM_ID = 0,
+ MALI_C720_DISC_V1_TABLE_DEHAZE_MAX_ID,
+};
+
+enum mali_c720_disc_v1_table_scaler_rgb_id {
+ MALI_C720_DISC_V1_TABLE_SCALER_RGB_H_MEM_ID = 0,
+ MALI_C720_DISC_V1_TABLE_SCALER_RGB_V_MEM_ID,
+ MALI_C720_DISC_V1_TABLE_SCALER_RGB_MAX_ID,
+};
+
+struct mali_c720_disc_v1_subpipe_header {
+ u16 desc_count;
+ u8 type;
+ u8 instance_id;
+};
+
+static u8 mali_c720_discovery_field_id(u32 record)
+{
+ return (u8)FIELD_GET(MALI_C720_DISC_V1_FIELD_ID_MASK, record);
+}
+
+static bool mali_c720_discovery_is_module_id(u8 field_id)
+{
+ switch (field_id) {
+ case MALI_C720_DISC_V1_MODULE_ID_CM_FULL:
+ case MALI_C720_DISC_V1_MODULE_ID_GLOBAL_ISP_CONTROL:
+ case MALI_C720_DISC_V1_MODULE_ID_INTERRUPT_CONTROLLER:
+ case MALI_C720_DISC_V1_MODULE_ID_FAULT_COLLECTOR:
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_BIST_CONTROL:
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_CRC_CONTROL:
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_CG_CONTROL:
+ case MALI_C720_DISC_V1_MODULE_ID_CM_CONTROL:
+ case MALI_C720_DISC_V1_MODULE_ID_CM_SLOT_LOADABLE:
+ case MALI_C720_DISC_V1_MODULE_ID_PIPELINE_GLOBAL_CONTROL:
+ case MALI_C720_DISC_V1_MODULE_ID_DIGITAL_GAIN:
+ case MALI_C720_DISC_V1_MODULE_ID_GAIN_AND_OFFSET:
+ case MALI_C720_DISC_V1_MODULE_ID_BLACK_LEVEL:
+ case MALI_C720_DISC_V1_MODULE_ID_WB_GAIN:
+ case MALI_C720_DISC_V1_MODULE_ID_OFFSET:
+ case MALI_C720_DISC_V1_MODULE_ID_SQUARE_ROOT_RAW:
+ case MALI_C720_DISC_V1_MODULE_ID_SQUARE_RAW:
+ case MALI_C720_DISC_V1_MODULE_ID_SQUARE_ROOT_RGB:
+ case MALI_C720_DISC_V1_MODULE_ID_SQUARE_RGB:
+ case MALI_C720_DISC_V1_MODULE_ID_DECOMPANDER:
+ case MALI_C720_DISC_V1_MODULE_ID_FRAME_STITCHING:
+ case MALI_C720_DISC_V1_MODULE_ID_DEFECT_PIXEL:
+ case MALI_C720_DISC_V1_MODULE_ID_RGBIR_REMOSAIC:
+ case MALI_C720_DISC_V1_MODULE_ID_CA_CORRECTION:
+ case MALI_C720_DISC_V1_MODULE_ID_TEMPER:
+ case MALI_C720_DISC_V1_MODULE_ID_SINTER:
+ case MALI_C720_DISC_V1_MODULE_ID_SMART_SHADING:
+ case MALI_C720_DISC_V1_MODULE_ID_RAW_TO_INTENSITY:
+ case MALI_C720_DISC_V1_MODULE_ID_DEHAZE:
+ case MALI_C720_DISC_V1_MODULE_ID_IRIDIX:
+ case MALI_C720_DISC_V1_MODULE_ID_DEMOSAIC_STD:
+ case MALI_C720_DISC_V1_MODULE_ID_DEMOSAIC_DFD:
+ case MALI_C720_DISC_V1_MODULE_ID_PURPLE_FRINGE:
+ case MALI_C720_DISC_V1_MODULE_ID_CCM:
+ case MALI_C720_DISC_V1_MODULE_ID_CNR:
+ case MALI_C720_DISC_V1_MODULE_ID_SCALER_RGB:
+ case MALI_C720_DISC_V1_MODULE_ID_SCALER_RAW:
+ case MALI_C720_DISC_V1_MODULE_ID_CROP:
+ case MALI_C720_DISC_V1_MODULE_ID_SHARPENING_RGB:
+ case MALI_C720_DISC_V1_MODULE_ID_SHARPENING_RAW:
+ case MALI_C720_DISC_V1_MODULE_ID_GAMMA:
+ case MALI_C720_DISC_V1_MODULE_ID_TC_LUT_RGB:
+ case MALI_C720_DISC_V1_MODULE_ID_TC_LUT_RAW:
+ case MALI_C720_DISC_V1_MODULE_ID_OUTPUT_FORMATTER:
+ case MALI_C720_DISC_V1_MODULE_ID_OUTPUT_MULTIPLEXER:
+ case MALI_C720_DISC_V1_MODULE_ID_GAUSSIAN_PYRAMID:
+ case MALI_C720_DISC_V1_MODULE_ID_RAW_STREAM_PACKER:
+ case MALI_C720_DISC_V1_MODULE_ID_TPG_RAW_MULTI:
+ case MALI_C720_DISC_V1_MODULE_ID_TPG_RAW_SINGLE:
+ case MALI_C720_DISC_V1_MODULE_ID_TPG_RAW_RGB_SINGLE:
+ case MALI_C720_DISC_V1_MODULE_ID_FGM:
+ case MALI_C720_DISC_V1_MODULE_ID_FBIST_BRIDGE:
+ case MALI_C720_DISC_V1_MODULE_ID_PIPELINE_CRC:
+ case MALI_C720_DISC_V1_MODULE_ID_INPUT_CRC:
+ case MALI_C720_DISC_V1_MODULE_ID_INTENSITY_STATS:
+ case MALI_C720_DISC_V1_MODULE_ID_HISTOGRAM_STATS:
+ case MALI_C720_DISC_V1_MODULE_ID_COLOR_STATS:
+ case MALI_C720_DISC_V1_MODULE_ID_AUTO_FOCUS_STATS:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static enum mali_c720_discovery_module_id
+mali_c720_discovery_module_id_from_v1_id(u8 v1_module_id)
+{
+ switch (v1_module_id) {
+ case MALI_C720_DISC_V1_MODULE_ID_CM_FULL:
+ return MALI_C720_DISC_MODULE_ID_CM_FULL;
+ case MALI_C720_DISC_V1_MODULE_ID_GLOBAL_ISP_CONTROL:
+ return MALI_C720_DISC_MODULE_ID_GLOBAL_ISP_CONTROL;
+ case MALI_C720_DISC_V1_MODULE_ID_INTERRUPT_CONTROLLER:
+ return MALI_C720_DISC_MODULE_ID_INTERRUPT_CONTROLLER;
+ case MALI_C720_DISC_V1_MODULE_ID_FAULT_COLLECTOR:
+ return MALI_C720_DISC_MODULE_ID_FAULT_COLLECTOR;
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_BIST_CONTROL:
+ return MALI_C720_DISC_MODULE_ID_MODULE_BIST_CONTROL;
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_CRC_CONTROL:
+ return MALI_C720_DISC_MODULE_ID_MODULE_CRC_CONTROL;
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_CG_CONTROL:
+ return MALI_C720_DISC_MODULE_ID_MODULE_CG_CONTROL;
+ case MALI_C720_DISC_V1_MODULE_ID_CM_CONTROL:
+ return MALI_C720_DISC_MODULE_ID_CM_CONTROL;
+ case MALI_C720_DISC_V1_MODULE_ID_CM_SLOT_LOADABLE:
+ return MALI_C720_DISC_MODULE_ID_CM_SLOT_LOADABLE;
+ case MALI_C720_DISC_V1_MODULE_ID_PIPELINE_GLOBAL_CONTROL:
+ return MALI_C720_DISC_MODULE_ID_PIPELINE_GLOBAL_CONTROL;
+ case MALI_C720_DISC_V1_MODULE_ID_DIGITAL_GAIN:
+ return MALI_C720_DISC_MODULE_ID_DIGITAL_GAIN;
+ case MALI_C720_DISC_V1_MODULE_ID_GAIN_AND_OFFSET:
+ return MALI_C720_DISC_MODULE_ID_GAIN_AND_OFFSET;
+ case MALI_C720_DISC_V1_MODULE_ID_BLACK_LEVEL:
+ return MALI_C720_DISC_MODULE_ID_BLACK_LEVEL;
+ case MALI_C720_DISC_V1_MODULE_ID_WB_GAIN:
+ return MALI_C720_DISC_MODULE_ID_WB_GAIN;
+ case MALI_C720_DISC_V1_MODULE_ID_OFFSET:
+ return MALI_C720_DISC_MODULE_ID_OFFSET;
+ case MALI_C720_DISC_V1_MODULE_ID_SQUARE_ROOT_RAW:
+ return MALI_C720_DISC_MODULE_ID_SQUARE_ROOT_RAW;
+ case MALI_C720_DISC_V1_MODULE_ID_SQUARE_RAW:
+ return MALI_C720_DISC_MODULE_ID_SQUARE_RAW;
+ case MALI_C720_DISC_V1_MODULE_ID_SQUARE_ROOT_RGB:
+ return MALI_C720_DISC_MODULE_ID_SQUARE_ROOT_RGB;
+ case MALI_C720_DISC_V1_MODULE_ID_SQUARE_RGB:
+ return MALI_C720_DISC_MODULE_ID_SQUARE_RGB;
+ case MALI_C720_DISC_V1_MODULE_ID_DECOMPANDER:
+ return MALI_C720_DISC_MODULE_ID_DECOMPANDER;
+ case MALI_C720_DISC_V1_MODULE_ID_FRAME_STITCHING:
+ return MALI_C720_DISC_MODULE_ID_FRAME_STITCHING;
+ case MALI_C720_DISC_V1_MODULE_ID_DEFECT_PIXEL:
+ return MALI_C720_DISC_MODULE_ID_DEFECT_PIXEL;
+ case MALI_C720_DISC_V1_MODULE_ID_RGBIR_REMOSAIC:
+ return MALI_C720_DISC_MODULE_ID_RGBIR_REMOSAIC;
+ case MALI_C720_DISC_V1_MODULE_ID_CA_CORRECTION:
+ return MALI_C720_DISC_MODULE_ID_CA_CORRECTION;
+ case MALI_C720_DISC_V1_MODULE_ID_TEMPER:
+ return MALI_C720_DISC_MODULE_ID_TEMPER;
+ case MALI_C720_DISC_V1_MODULE_ID_SINTER:
+ return MALI_C720_DISC_MODULE_ID_SINTER;
+ case MALI_C720_DISC_V1_MODULE_ID_SMART_SHADING:
+ return MALI_C720_DISC_MODULE_ID_SMART_SHADING;
+ case MALI_C720_DISC_V1_MODULE_ID_RAW_TO_INTENSITY:
+ return MALI_C720_DISC_MODULE_ID_RAW_TO_INTENSITY;
+ case MALI_C720_DISC_V1_MODULE_ID_DEHAZE:
+ return MALI_C720_DISC_MODULE_ID_DEHAZE;
+ case MALI_C720_DISC_V1_MODULE_ID_IRIDIX:
+ return MALI_C720_DISC_MODULE_ID_IRIDIX;
+ case MALI_C720_DISC_V1_MODULE_ID_DEMOSAIC_STD:
+ return MALI_C720_DISC_MODULE_ID_DEMOSAIC_STD;
+ case MALI_C720_DISC_V1_MODULE_ID_DEMOSAIC_DFD:
+ return MALI_C720_DISC_MODULE_ID_DEMOSAIC_DFD;
+ case MALI_C720_DISC_V1_MODULE_ID_PURPLE_FRINGE:
+ return MALI_C720_DISC_MODULE_ID_PURPLE_FRINGE;
+ case MALI_C720_DISC_V1_MODULE_ID_CCM:
+ return MALI_C720_DISC_MODULE_ID_CCM;
+ case MALI_C720_DISC_V1_MODULE_ID_CNR:
+ return MALI_C720_DISC_MODULE_ID_CNR;
+ case MALI_C720_DISC_V1_MODULE_ID_SCALER_RGB:
+ return MALI_C720_DISC_MODULE_ID_SCALER_RGB;
+ case MALI_C720_DISC_V1_MODULE_ID_SCALER_RAW:
+ return MALI_C720_DISC_MODULE_ID_SCALER_RAW;
+ case MALI_C720_DISC_V1_MODULE_ID_CROP:
+ return MALI_C720_DISC_MODULE_ID_CROP;
+ case MALI_C720_DISC_V1_MODULE_ID_SHARPENING_RGB:
+ return MALI_C720_DISC_MODULE_ID_SHARPENING_RGB;
+ case MALI_C720_DISC_V1_MODULE_ID_SHARPENING_RAW:
+ return MALI_C720_DISC_MODULE_ID_SHARPENING_RAW;
+ case MALI_C720_DISC_V1_MODULE_ID_GAMMA:
+ return MALI_C720_DISC_MODULE_ID_GAMMA;
+ case MALI_C720_DISC_V1_MODULE_ID_TC_LUT_RGB:
+ return MALI_C720_DISC_MODULE_ID_TC_LUT_RGB;
+ case MALI_C720_DISC_V1_MODULE_ID_TC_LUT_RAW:
+ return MALI_C720_DISC_MODULE_ID_TC_LUT_RAW;
+ case MALI_C720_DISC_V1_MODULE_ID_OUTPUT_FORMATTER:
+ return MALI_C720_DISC_MODULE_ID_OUTPUT_FORMATTER;
+ case MALI_C720_DISC_V1_MODULE_ID_OUTPUT_MULTIPLEXER:
+ return MALI_C720_DISC_MODULE_ID_OUTPUT_MULTIPLEXER;
+ case MALI_C720_DISC_V1_MODULE_ID_GAUSSIAN_PYRAMID:
+ return MALI_C720_DISC_MODULE_ID_GAUSSIAN_PYRAMID;
+ case MALI_C720_DISC_V1_MODULE_ID_RAW_STREAM_PACKER:
+ return MALI_C720_DISC_MODULE_ID_RAW_STREAM_PACKER;
+ case MALI_C720_DISC_V1_MODULE_ID_TPG_RAW_MULTI:
+ return MALI_C720_DISC_MODULE_ID_TPG_RAW_MULTI;
+ case MALI_C720_DISC_V1_MODULE_ID_TPG_RAW_SINGLE:
+ return MALI_C720_DISC_MODULE_ID_TPG_RAW_SINGLE;
+ case MALI_C720_DISC_V1_MODULE_ID_TPG_RAW_RGB_SINGLE:
+ return MALI_C720_DISC_MODULE_ID_TPG_RAW_RGB_SINGLE;
+ case MALI_C720_DISC_V1_MODULE_ID_FGM:
+ return MALI_C720_DISC_MODULE_ID_FGM;
+ case MALI_C720_DISC_V1_MODULE_ID_FBIST_BRIDGE:
+ return MALI_C720_DISC_MODULE_ID_FBIST_BRIDGE;
+ case MALI_C720_DISC_V1_MODULE_ID_PIPELINE_CRC:
+ return MALI_C720_DISC_MODULE_ID_PIPELINE_CRC;
+ case MALI_C720_DISC_V1_MODULE_ID_INPUT_CRC:
+ return MALI_C720_DISC_MODULE_ID_INPUT_CRC;
+ case MALI_C720_DISC_V1_MODULE_ID_INTENSITY_STATS:
+ return MALI_C720_DISC_MODULE_ID_INTENSITY_STATS;
+ case MALI_C720_DISC_V1_MODULE_ID_HISTOGRAM_STATS:
+ return MALI_C720_DISC_MODULE_ID_HISTOGRAM_STATS;
+ case MALI_C720_DISC_V1_MODULE_ID_COLOR_STATS:
+ return MALI_C720_DISC_MODULE_ID_COLOR_STATS;
+ case MALI_C720_DISC_V1_MODULE_ID_AUTO_FOCUS_STATS:
+ return MALI_C720_DISC_MODULE_ID_AUTO_FOCUS_STATS;
+ default:
+ return MALI_C720_DISC_MODULE_ID_NONE;
+ }
+}
+
+static enum mali_c720_discovery_pipeline_id
+mali_c720_discovery_v1_subpipe_id_to_pipeline_id(u8 subpipe_id)
+{
+ switch (subpipe_id) {
+ case MALI_C720_DISC_V1_SUBPIPE_ID_INPUT:
+ return MALI_C720_DISC_PIPE_INPUT;
+ case MALI_C720_DISC_V1_SUBPIPE_ID_HV:
+ return MALI_C720_DISC_PIPE_HV;
+ case MALI_C720_DISC_V1_SUBPIPE_ID_CV:
+ return MALI_C720_DISC_PIPE_CV;
+ case MALI_C720_DISC_V1_SUBPIPE_ID_RAW_OUTPUT:
+ return MALI_C720_DISC_PIPE_RAW_OUTPUT;
+ case MALI_C720_DISC_V1_SUBPIPE_ID_FR_OUTPUT:
+ return MALI_C720_DISC_PIPE_FR_OUTPUT;
+ case MALI_C720_DISC_V1_SUBPIPE_ID_PYR_OUTPUT:
+ return MALI_C720_DISC_PIPE_PYR_OUTPUT;
+ case MALI_C720_DISC_V1_SUBPIPE_ID_FOV_OUTPUT:
+ return MALI_C720_DISC_PIPE_FOV_OUTPUT;
+ case MALI_C720_DISC_V1_SUBPIPE_ID_STATS:
+ return MALI_C720_DISC_PIPE_STATS;
+ case MALI_C720_DISC_V1_SUBPIPE_ID_TPG:
+ return MALI_C720_DISC_PIPE_TPG;
+ default:
+ return MALI_C720_DISC_PIPE_MAX;
+ }
+}
+
+static u16 mali_c720_discovery_crc16_ibm_3740(const __le32 *records, u16 count)
+{
+ u16 crc = 0xffff;
+ u16 i;
+
+ for (i = 0; i < count; i++) {
+ u32 v = le32_to_cpu(records[i]);
+
+ crc = crc_itu_t_byte(crc, (u8)(v >> 24));
+ crc = crc_itu_t_byte(crc, (u8)(v >> 16));
+ crc = crc_itu_t_byte(crc, (u8)(v >> 8));
+ crc = crc_itu_t_byte(crc, (u8)v);
+ }
+
+ return crc;
+}
+
+struct mali_c720_disc_v1_module_desc {
+ enum mali_c720_discovery_module_id id;
+ u32 offset;
+ u8 instance_id;
+ bool removed;
+};
+
+struct mali_c720_disc_v1_memory_desc {
+ u32 offset;
+ u32 size;
+ u8 table_id;
+};
+
+struct mali_c720_disc_v1_version_desc {
+ u8 major;
+ u8 minor;
+ u8 patch;
+};
+
+struct mali_c720_disc_v1_param_desc {
+ u8 id;
+ u16 value;
+};
+
+static struct mali_c720_discovery_pipeline *
+mali_c720_discovery_get_pipeline(struct mali_c720_discovery *discovery,
+ enum mali_c720_discovery_pipeline_id pipeline_id,
+ unsigned int instance_id)
+{
+ if (!discovery || pipeline_id >= MALI_C720_DISC_PIPE_MAX ||
+ instance_id >= MALI_C720_DISCOVERY_MAX_PIPELINE_INSTANCES)
+ return NULL;
+
+ return &discovery->pipelines[pipeline_id][instance_id];
+}
+
+static struct mali_c720_discovery_module *
+mali_c720_discovery_alloc_module(struct mali_c720 *mali_c720,
+ struct mali_c720_discovery *discovery)
+{
+ struct mali_c720_discovery_module *module;
+
+ if (discovery->next_module_id >= MALI_C720_DISCOVERY_MAX_MODULES) {
+ dev_err(mali_c720->dev, "Failed to allocate discovery module\n");
+ return NULL;
+ }
+
+ module = &discovery->modules[discovery->next_module_id++];
+ INIT_LIST_HEAD(&module->memories);
+ INIT_LIST_HEAD(&module->fbists);
+ INIT_LIST_HEAD(&module->mbists);
+ INIT_LIST_HEAD(&module->config_crcs);
+ INIT_LIST_HEAD(&module->clock_gating);
+ INIT_LIST_HEAD(&module->params);
+ INIT_LIST_HEAD(&module->node);
+
+ return module;
+}
+
+static struct mali_c720_discovery_table *
+mali_c720_discovery_alloc_memory(struct mali_c720 *mali_c720,
+ struct mali_c720_discovery *discovery)
+{
+ struct mali_c720_discovery_table *memory;
+
+ if (discovery->next_memory_id >= MALI_C720_DISCOVERY_MAX_MEMORIES) {
+ dev_err(mali_c720->dev, "Failed to allocate discovery memory\n");
+ return NULL;
+ }
+
+ memory = &discovery->memories[discovery->next_memory_id++];
+ INIT_LIST_HEAD(&memory->node);
+
+ return memory;
+}
+
+static struct mali_c720_discovery_param *
+mali_c720_discovery_alloc_param(struct mali_c720 *mali_c720,
+ struct mali_c720_discovery *discovery)
+{
+ struct mali_c720_discovery_param *param;
+
+ if (discovery->next_param_id >= MALI_C720_DISCOVERY_MAX_PARAMS) {
+ dev_err(mali_c720->dev, "Failed to allocate discovery param\n");
+ return NULL;
+ }
+
+ param = &discovery->params[discovery->next_param_id++];
+ INIT_LIST_HEAD(¶m->node);
+
+ return param;
+}
+
+static void
+mali_c720_discovery_link_pipeline_module(struct mali_c720_discovery_pipeline *pipeline,
+ struct mali_c720_discovery_module *module)
+{
+ list_add_tail(&module->node, &pipeline->modules);
+}
+
+static void
+mali_c720_discovery_link_memory(struct mali_c720_discovery_module *module,
+ struct mali_c720_discovery_table *memory)
+{
+ list_add_tail(&memory->node, &module->memories);
+ module->num_memories++;
+}
+
+static void
+mali_c720_discovery_link_param(struct mali_c720_discovery_module *module,
+ struct mali_c720_discovery_param *param)
+{
+ list_add_tail(¶m->node, &module->params);
+ module->num_params++;
+}
+
+static void
+mali_c720_discovery_link_fbist(struct mali_c720_discovery_module *module,
+ struct mali_c720_discovery_module *fbist)
+{
+ list_add_tail(&fbist->node, &module->fbists);
+ fbist->fbist_instance_id = module->num_fbists;
+ module->num_fbists++;
+}
+
+static void
+mali_c720_discovery_link_mbist(struct mali_c720_discovery_module *module,
+ struct mali_c720_discovery_module *mbist)
+{
+ list_add_tail(&mbist->node, &module->mbists);
+ mbist->mbist_instance_id = module->num_mbists;
+ module->num_mbists++;
+}
+
+static void
+mali_c720_discovery_link_config_crc(struct mali_c720_discovery_module *module,
+ struct mali_c720_discovery_module *config_crc)
+{
+ list_add_tail(&config_crc->node, &module->config_crcs);
+ config_crc->config_crc_instance_id = module->num_config_crcs;
+ module->num_config_crcs++;
+}
+
+static void
+mali_c720_discovery_link_clock_gating(struct mali_c720_discovery_module *module,
+ struct mali_c720_discovery_module *clock_gating)
+{
+ list_add_tail(&clock_gating->node, &module->clock_gating);
+ clock_gating->clock_gating_instance_id = module->num_clock_gating;
+ module->num_clock_gating++;
+}
+
+static struct mali_c720_discovery_module *
+mali_c720_discovery_find_module(struct mali_c720_discovery_pipeline *pipeline,
+ enum mali_c720_discovery_module_id module_id,
+ unsigned int module_instance)
+{
+ struct mali_c720_discovery_module *module;
+
+ if (!pipeline)
+ return NULL;
+
+ list_for_each_entry(module, &pipeline->modules, node) {
+ if (module->id == module_id &&
+ module->instance_id == module_instance)
+ return module;
+ }
+
+ return NULL;
+}
+
+static struct mali_c720_discovery_module *
+mali_c720_discovery_get_module(struct mali_c720_discovery *discovery,
+ const struct mali_c720_discovery_target *target)
+{
+ struct mali_c720_discovery_pipeline *pipeline;
+
+ if (target->module_id <= MALI_C720_DISC_MODULE_ID_NONE ||
+ target->module_id >= MALI_C720_DISC_MODULE_ID_MAX ||
+ target->module_instance >= MALI_C720_DISCOVERY_MAX_MODULE_INSTANCES)
+ return NULL;
+
+ pipeline = mali_c720_discovery_get_pipeline(discovery, target->pipeline_id,
+ target->pipeline_instance);
+ if (!pipeline || !pipeline->present)
+ return NULL;
+
+ return mali_c720_discovery_find_module(pipeline, target->module_id,
+ target->module_instance);
+}
+
+static const struct mali_c720_discovery_table *
+mali_c720_discovery_find_memory(const struct mali_c720_discovery_module *module,
+ unsigned int table_id)
+{
+ const struct mali_c720_discovery_table *memory;
+
+ list_for_each_entry(memory, &module->memories, node) {
+ if (memory->id == table_id)
+ return memory;
+ }
+
+ return NULL;
+}
+
+static int mali_c720_discovery_parse_module_record(struct mali_c720 *mali_c720,
+ u32 record,
+ struct mali_c720_disc_v1_module_desc *module)
+{
+ module->id =
+ mali_c720_discovery_module_id_from_v1_id(mali_c720_discovery_field_id(record));
+ module->instance_id =
+ FIELD_GET(MALI_C720_DISC_V1_MODULE_INSTANCE_MASK, record);
+ module->removed = !!(record & MALI_C720_DISC_V1_MODULE_REMOVED_MASK);
+ module->offset =
+ FIELD_GET(MALI_C720_DISC_V1_MODULE_OFFSET_MASK, record) << 4;
+
+ if ((u64)module->offset + sizeof(u32) > mali_c720->registers.context_size)
+ return -EINVAL;
+
+ return 0;
+}
+
+static int mali_c720_discovery_parse_memory_record(struct mali_c720 *mali_c720,
+ u32 record,
+ struct mali_c720_disc_v1_memory_desc *memory)
+{
+ u32 log2_size;
+ u64 end;
+
+ memory->table_id =
+ FIELD_GET(MALI_C720_DISC_V1_MEMORY_TABLE_ID_MASK, record);
+ memory->offset =
+ FIELD_GET(MALI_C720_DISC_V1_MEMORY_OFFSET_MASK, record) << 4;
+
+ log2_size = FIELD_GET(MALI_C720_DISC_V1_MEMORY_SIZE_MASK, record);
+ if (log2_size > 10)
+ return -EINVAL;
+
+ memory->size = 16U << log2_size;
+ if (record & MALI_C720_DISC_V1_MEMORY_SCALAR_SUFFIX_MASK)
+ memory->size += 32;
+
+ end = (u64)memory->offset + memory->size;
+ if (end > mali_c720->registers.context_size)
+ return -EINVAL;
+
+ return 0;
+}
+
+static void mali_c720_discovery_parse_version_record(u32 record,
+ struct mali_c720_disc_v1_version_desc *version)
+{
+ version->patch = FIELD_GET(MALI_C720_DISC_V1_VERSION_PATCH_MASK, record);
+ version->minor = FIELD_GET(MALI_C720_DISC_V1_VERSION_MINOR_MASK, record);
+ version->major = FIELD_GET(MALI_C720_DISC_V1_VERSION_MAJOR_MASK, record);
+}
+
+static void mali_c720_discovery_parse_param_record(u32 record,
+ struct mali_c720_disc_v1_param_desc *param)
+{
+ param->id = FIELD_GET(MALI_C720_DISC_V1_PARAM_ID_MASK, record);
+ param->value = FIELD_GET(MALI_C720_DISC_V1_PARAM_VALUE_MASK, record);
+}
+
+static int mali_c720_discovery_parse_subpipe_header(u32 record,
+ struct mali_c720_disc_v1_subpipe_header *header)
+{
+ header->type = FIELD_GET(MALI_C720_DISC_V1_SUBPIPE_TYPE_MASK, record);
+ header->instance_id =
+ FIELD_GET(MALI_C720_DISC_V1_SUBPIPE_INSTANCE_MASK, record);
+ header->desc_count =
+ FIELD_GET(MALI_C720_DISC_V1_SUBPIPE_DESC_COUNT_MASK, record);
+
+ if (header->type >= MALI_C720_DISC_V1_SUBPIPE_ID_MAX)
+ return -EINVAL;
+
+ return 0;
+}
+
+static int mali_c720_discovery_parse_v1(struct mali_c720 *mali_c720,
+ struct mali_c720_discovery *discovery,
+ const __le32 *records,
+ u16 desc_count)
+{
+ struct mali_c720_discovery_pipeline *pipeline;
+ struct mali_c720_discovery_pipeline *current_subpipe = NULL;
+ struct mali_c720_discovery_module *current_module = NULL;
+ struct mali_c720_discovery_module *last_module = NULL;
+ enum mali_c720_discovery_pipeline_id current_pipeline_id =
+ MALI_C720_DISC_PIPE_MAX;
+ unsigned int current_pipeline_instance = 0;
+ u16 subpipe_desc_count = 0;
+ unsigned int i;
+
+ pipeline = NULL;
+
+ for (i = 0; i <= desc_count; i++) {
+ struct mali_c720_discovery_module *module;
+ struct mali_c720_disc_v1_subpipe_header subpipe;
+ u32 record = le32_to_cpu(records[i]);
+ u8 field_id = mali_c720_discovery_field_id(record);
+ bool in_subpipe = current_subpipe;
+
+ switch (field_id) {
+ case MALI_C720_DISC_V1_FIELD_LIST_HEADER:
+ if (i) {
+ dev_err(mali_c720->dev,
+ "unexpected discovery list header at record %u\n", i);
+ return -EINVAL;
+ }
+
+ pipeline = mali_c720_discovery_get_pipeline(discovery,
+ MALI_C720_DISC_PIPE_GLOBAL, 0);
+ if (!pipeline) {
+ dev_err(mali_c720->dev,
+ "Failed to fetch global pipeline\n");
+ return -EINVAL;
+ }
+
+ pipeline->present = true;
+ pipeline->id = MALI_C720_DISC_PIPE_GLOBAL;
+ pipeline->instance_id = 0;
+ current_module = NULL;
+ last_module = NULL;
+ current_pipeline_id = MALI_C720_DISC_PIPE_GLOBAL;
+ current_pipeline_instance = 0;
+ break;
+ case MALI_C720_DISC_V1_FIELD_LIST_FOOTER:
+ if (i != desc_count || current_subpipe) {
+ dev_err(mali_c720->dev,
+ "unexpected discovery list footer at record %u\n", i);
+ return -EINVAL;
+ }
+ break;
+ case MALI_C720_DISC_V1_FIELD_SUBPIPE_HEADER:
+ {
+ enum mali_c720_discovery_pipeline_id pipeline_id;
+
+ if (current_subpipe) {
+ dev_err(mali_c720->dev,
+ "nested sub-pipeline header at record %u\n", i);
+ return -EINVAL;
+ }
+
+ if (mali_c720_discovery_parse_subpipe_header(record, &subpipe)) {
+ dev_err(mali_c720->dev,
+ "invalid sub-pipeline header at record %u\n", i);
+ return -EINVAL;
+ }
+
+ if (!subpipe.desc_count) {
+ dev_err(mali_c720->dev,
+ "sub-pipeline descriptor count is zero at record %u\n", i);
+ return -EINVAL;
+ }
+
+ pipeline_id =
+ mali_c720_discovery_v1_subpipe_id_to_pipeline_id(subpipe.type);
+ if (pipeline_id >= MALI_C720_DISC_PIPE_MAX) {
+ dev_err(mali_c720->dev,
+ "unsupported v1 sub-pipeline type %u at record %u\n",
+ subpipe.type, i);
+ return -EINVAL;
+ }
+
+ pipeline = mali_c720_discovery_get_pipeline(discovery, pipeline_id,
+ subpipe.instance_id);
+ if (!pipeline) {
+ dev_err(mali_c720->dev,
+ "Failed to fetch sub-pipeline type %u instance %u\n",
+ pipeline_id, subpipe.instance_id);
+ return -EINVAL;
+ }
+
+ pipeline->present = true;
+ pipeline->id = pipeline_id;
+ pipeline->instance_id = subpipe.instance_id;
+ subpipe_desc_count = subpipe.desc_count;
+ current_subpipe = pipeline;
+ current_module = NULL;
+ last_module = NULL;
+ current_pipeline_id = pipeline_id;
+ current_pipeline_instance = subpipe.instance_id;
+ break;
+ }
+ case MALI_C720_DISC_V1_FIELD_SUBPIPE_FOOTER:
+ if (!current_subpipe) {
+ dev_err(mali_c720->dev,
+ "sub-pipeline footer without matching header at record %u\n",
+ i);
+ return -EINVAL;
+ }
+
+ if (subpipe_desc_count - 1 != 0) {
+ dev_err(mali_c720->dev,
+ "sub-pipeline descriptor count mismatch at record %u\n",
+ i);
+ return -EINVAL;
+ }
+
+ current_subpipe = NULL;
+ pipeline = NULL;
+ current_module = NULL;
+ last_module = NULL;
+ current_pipeline_id = MALI_C720_DISC_PIPE_MAX;
+ current_pipeline_instance = 0;
+ break;
+ case MALI_C720_DISC_V1_FIELD_EXT_MEMORY:
+ {
+ struct mali_c720_discovery_table *memory_entry;
+ struct mali_c720_disc_v1_memory_desc memory;
+
+ if (!current_module) {
+ dev_err(mali_c720->dev,
+ "memory descriptor without active module at record %u\n",
+ i);
+ return -EINVAL;
+ }
+
+ if (mali_c720_discovery_parse_memory_record(mali_c720, record,
+ &memory)) {
+ dev_err(mali_c720->dev,
+ "invalid memory descriptor at record %u\n", i);
+ return -EINVAL;
+ }
+
+ memory_entry = mali_c720_discovery_alloc_memory(mali_c720,
+ discovery);
+ if (!memory_entry)
+ return -ENOMEM;
+
+ memory_entry->id = memory.table_id;
+ memory_entry->base = memory.offset;
+ memory_entry->size = memory.size;
+ mali_c720_discovery_link_memory(current_module, memory_entry);
+
+ break;
+ }
+ case MALI_C720_DISC_V1_FIELD_EXT_VERSION:
+ {
+ struct mali_c720_disc_v1_version_desc version_desc;
+
+ if (!last_module) {
+ dev_err(mali_c720->dev,
+ "version descriptor without preceding module at record %u\n",
+ i);
+ return -EINVAL;
+ }
+
+ mali_c720_discovery_parse_version_record(record,
+ &version_desc);
+
+ last_module->version.present = true;
+ last_module->version.major = version_desc.major;
+ last_module->version.minor = version_desc.minor;
+ last_module->version.patch = version_desc.patch;
+
+ break;
+ }
+ case MALI_C720_DISC_V1_FIELD_EXT_PARAMETER:
+ {
+ struct mali_c720_discovery_param *param_entry;
+ struct mali_c720_disc_v1_param_desc param_desc;
+
+ if (!last_module) {
+ dev_err(mali_c720->dev,
+ "parameter descriptor without preceding module at record %u\n",
+ i);
+ return -EINVAL;
+ }
+
+ param_entry = mali_c720_discovery_alloc_param(mali_c720,
+ discovery);
+ if (!param_entry)
+ return -ENOMEM;
+
+ mali_c720_discovery_parse_param_record(record, ¶m_desc);
+ param_entry->id = param_desc.id;
+ param_entry->value = param_desc.value;
+ mali_c720_discovery_link_param(last_module, param_entry);
+
+ break;
+ }
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_BIST_CONTROL:
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_CRC_CONTROL:
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_CG_CONTROL:
+ {
+ struct mali_c720_disc_v1_module_desc module_desc;
+ struct mali_c720_discovery_module *control_module;
+
+ if (!current_module) {
+ dev_err(mali_c720->dev,
+ "control descriptor without active module at record %u\n",
+ i);
+ return -EINVAL;
+ }
+
+ if (mali_c720_discovery_parse_module_record(mali_c720, record,
+ &module_desc)) {
+ dev_err(mali_c720->dev,
+ "invalid control module descriptor at record %u\n", i);
+ return -EINVAL;
+ }
+
+ control_module = mali_c720_discovery_alloc_module(mali_c720,
+ discovery);
+ if (!control_module)
+ return -ENOMEM;
+
+ control_module->id = module_desc.id;
+ control_module->instance_id = module_desc.instance_id;
+ control_module->found = true;
+ control_module->present = !module_desc.removed;
+ control_module->base = module_desc.offset;
+
+ switch (field_id) {
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_BIST_CONTROL:
+ mali_c720_discovery_link_mbist(current_module,
+ control_module);
+ break;
+ case MALI_C720_DISC_V1_MODULE_ID_MODULE_CRC_CONTROL:
+ mali_c720_discovery_link_config_crc(current_module,
+ control_module);
+ break;
+ default:
+ mali_c720_discovery_link_clock_gating(current_module,
+ control_module);
+ break;
+ }
+
+ last_module = control_module;
+
+ break;
+ }
+ default:
+ {
+ struct mali_c720_disc_v1_module_desc module_desc;
+
+ if (!mali_c720_discovery_is_module_id(field_id)) {
+ dev_err(mali_c720->dev,
+ "unknown discovery field id %u at record %u\n",
+ field_id, i);
+ return -EINVAL;
+ }
+ if (!pipeline) {
+ dev_err(mali_c720->dev,
+ "module descriptor without active pipeline at record %u\n",
+ i);
+ return -EINVAL;
+ }
+
+ if (mali_c720_discovery_parse_module_record(mali_c720, record,
+ &module_desc)) {
+ dev_err(mali_c720->dev,
+ "invalid module descriptor at record %u\n", i);
+ return -EINVAL;
+ }
+ if (module_desc.id == MALI_C720_DISC_MODULE_ID_NONE) {
+ dev_err(mali_c720->dev,
+ "unsupported module id %u at record %u\n",
+ field_id, i);
+ return -EINVAL;
+ }
+
+ if (module_desc.instance_id >=
+ MALI_C720_DISCOVERY_MAX_MODULE_INSTANCES) {
+ dev_err(mali_c720->dev,
+ "module %u instance %u exceeds supported limit %u at record %u\n",
+ module_desc.id,
+ module_desc.instance_id,
+ MALI_C720_DISCOVERY_MAX_MODULE_INSTANCES, i);
+ return -EINVAL;
+ }
+
+ module = mali_c720_discovery_alloc_module(mali_c720, discovery);
+ if (!module)
+ return -ENOMEM;
+
+ module->id = module_desc.id;
+ module->instance_id = module_desc.instance_id;
+ module->found = true;
+ module->present = !module_desc.removed;
+ module->base = module_desc.offset;
+
+ if (current_module) {
+ if (module_desc.id == MALI_C720_DISC_MODULE_ID_FBIST_BRIDGE &&
+ current_module->id != MALI_C720_DISC_MODULE_ID_FBIST_BRIDGE) {
+ mali_c720_discovery_link_fbist(current_module,
+ module);
+ } else {
+ mali_c720_discovery_link_pipeline_module(pipeline, module);
+ current_module = module;
+ }
+ } else if (list_empty(&pipeline->modules)) {
+ mali_c720_discovery_link_pipeline_module(pipeline, module);
+ current_module = module;
+ } else {
+ dev_err(mali_c720->dev,
+ "failed to link module id %u instance %u in pipeline %u instance %u\n",
+ module_desc.id, module_desc.instance_id,
+ current_pipeline_id, current_pipeline_instance);
+ return -EINVAL;
+ }
+
+ last_module = module;
+
+ break;
+ }
+ }
+
+ if (in_subpipe) {
+ if (!subpipe_desc_count) {
+ dev_err(mali_c720->dev,
+ "sub-pipeline descriptor count exhausted at record %u\n",
+ i);
+ return -EINVAL;
+ }
+
+ subpipe_desc_count--;
+ }
+ }
+
+ return 0;
+}
+
+int mali_c720_discovery_init(struct mali_c720 *mali_c720, resource_size_t reg_size)
+{
+ struct mali_c720_discovery *discovery = &mali_c720->discovery;
+ __le32 *records;
+ u32 header;
+ u32 footer;
+ u16 desc_count;
+ u16 version;
+ u16 footer_crc;
+ u16 computed_crc;
+ unsigned int pipeline_id;
+ unsigned int instance_id;
+ size_t word_count;
+ int ret;
+
+ header = mali_c720_read_raw(mali_c720, CAPABILITY_DISCOVERY_HEADER_OFFSET);
+ if (mali_c720_discovery_field_id(header) !=
+ MALI_C720_DISC_V1_FIELD_LIST_HEADER) {
+ dev_err(mali_c720->dev, "discovery header missing\n");
+ return -EINVAL;
+ }
+
+ version = FIELD_GET(MALI_C720_DISC_V1_LIST_VERSION_MASK, header);
+ if (version != 1) {
+ dev_err(mali_c720->dev, "unsupported discovery version %u\n",
+ version);
+ return -EINVAL;
+ }
+
+ desc_count = FIELD_GET(MALI_C720_DISC_V1_LIST_DESC_COUNT_MASK, header);
+ if (desc_count < 2) {
+ dev_err(mali_c720->dev, "discovery descriptor count %u is invalid\n",
+ desc_count);
+ return -EINVAL;
+ }
+
+ word_count = (size_t)desc_count + 1;
+ if (word_count > reg_size / sizeof(u32)) {
+ dev_err(mali_c720->dev,
+ "discovery table exceeds mapped register space (%zu words > %pa bytes)\n",
+ word_count, ®_size);
+ return -EINVAL;
+ }
+
+ records = kvcalloc(word_count, sizeof(*records), GFP_KERNEL);
+ if (!records)
+ return -ENOMEM;
+
+ memcpy_fromio(records, mali_c720->base, word_count * sizeof(*records));
+
+ footer = le32_to_cpu(records[desc_count]);
+ if (mali_c720_discovery_field_id(footer) !=
+ MALI_C720_DISC_V1_FIELD_LIST_FOOTER) {
+ dev_err(mali_c720->dev, "discovery footer missing\n");
+ ret = -EINVAL;
+ goto out_free_records;
+ }
+
+ footer_crc = FIELD_GET(MALI_C720_DISC_V1_FOOTER_CRC_MASK, footer);
+ computed_crc = mali_c720_discovery_crc16_ibm_3740(records, desc_count);
+ if (computed_crc != footer_crc) {
+ dev_err(mali_c720->dev,
+ "discovery CRC mismatch: computed 0x%04x expected 0x%04x\n",
+ computed_crc, footer_crc);
+ ret = -EINVAL;
+ goto out_free_records;
+ }
+
+ memset(discovery, 0, sizeof(*discovery));
+ discovery->version = MALI_C720_DISCOVERY_VERSION_1;
+ for (pipeline_id = 0; pipeline_id < MALI_C720_DISC_PIPE_MAX; pipeline_id++)
+ for (instance_id = 0;
+ instance_id < MALI_C720_DISCOVERY_MAX_PIPELINE_INSTANCES;
+ instance_id++)
+ INIT_LIST_HEAD(&discovery->pipelines[pipeline_id][instance_id].modules);
+
+ ret = mali_c720_discovery_parse_v1(mali_c720, discovery, records,
+ desc_count);
+
+out_free_records:
+ kvfree(records);
+ return ret;
+}
+
+int mali_c720_discovery_get_module_base(struct mali_c720 *mali_c720,
+ const struct mali_c720_discovery_target *target,
+ u32 *base)
+{
+ const struct mali_c720_discovery_module *module;
+
+ module = mali_c720_discovery_get_module(&mali_c720->discovery, target);
+ if (!module || !module->found) {
+ dev_warn_once(mali_c720->dev,
+ "No module found for module id %u instance %u in pipeline %u instance %u\n",
+ target->module_id, target->module_instance,
+ target->pipeline_id, target->pipeline_instance);
+ return -ENOENT;
+ }
+
+ if (!module->present) {
+ dev_warn_once(mali_c720->dev,
+ "module id %u instance %u in pipeline %u instance %u is not present\n",
+ target->module_id, target->module_instance,
+ target->pipeline_id, target->pipeline_instance);
+ return -ENODEV;
+ }
+
+ *base = module->base;
+ return 0;
+}
+
+int mali_c720_discovery_get_module_table_base(struct mali_c720 *mali_c720,
+ const struct mali_c720_discovery_target *target,
+ unsigned int table_id,
+ u32 *base)
+{
+ const struct mali_c720_discovery_module *module;
+ const struct mali_c720_discovery_table *memory;
+
+ module = mali_c720_discovery_get_module(&mali_c720->discovery, target);
+ if (!module || !module->found) {
+ dev_warn_once(mali_c720->dev,
+ "No module found for module id %u instance %u in pipeline %u instance %u\n",
+ target->module_id, target->module_instance,
+ target->pipeline_id, target->pipeline_instance);
+ return -ENOENT;
+ }
+
+ if (!module->present) {
+ dev_warn_once(mali_c720->dev,
+ "module id %u instance %u in pipeline %u instance %u is not present\n",
+ target->module_id, target->module_instance,
+ target->pipeline_id, target->pipeline_instance);
+ return -ENODEV;
+ }
+
+ memory = mali_c720_discovery_find_memory(module, table_id);
+ if (!memory)
+ return -ENOENT;
+
+ *base = memory->base;
+
+ return 0;
+}
+
+bool mali_c720_discovery_module_present(struct mali_c720 *mali_c720,
+ const struct mali_c720_discovery_target *target)
+{
+ const struct mali_c720_discovery_module *module;
+
+ module = mali_c720_discovery_get_module(&mali_c720->discovery, target);
+ if (!module || !module->found)
+ return false;
+
+ return module->present;
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-discovery.h b/drivers/media/platform/arm/mali-c720/mali-c720-discovery.h
new file mode 100644
index 0000000000000000000000000000000000000000..de52553876681feda4176682772b1432358b2bb7
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-discovery.h
@@ -0,0 +1,212 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Capability discovery
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_DISCOVERY_H
+#define MALI_C720_DISCOVERY_H
+
+#include <linux/bitops.h>
+#include <linux/list.h>
+#include <linux/types.h>
+
+/*
+ * Capability discovery describes the ISP configuration selected at hardware
+ * synthesis time, including module presence, instances, register addresses
+ * and memory tables. The driver parses it during probe and caches the
+ * configuration for runtime lookups. The hardware topology remains fixed
+ * at runtime.
+ *
+ * The discovery version refers to the format of the table. Future hardware
+ * revisions may introduce a new version.
+ */
+
+struct mali_c720;
+
+#define MALI_C720_DISCOVERY_MAX_MODULES 384
+#define MALI_C720_DISCOVERY_MAX_MEMORIES 32
+#define MALI_C720_DISCOVERY_MAX_PARAMS 32
+#define MALI_C720_DISCOVERY_MAX_PIPELINE_INSTANCES 4
+#define MALI_C720_DISCOVERY_MAX_MODULE_INSTANCES 8
+#define MALI_C720_DISCOVERY_MAX_TABLE_INSTANCES 4
+
+enum mali_c720_discovery_version_id {
+ MALI_C720_DISCOVERY_VERSION_INVALID,
+ MALI_C720_DISCOVERY_VERSION_1,
+};
+
+enum mali_c720_discovery_pipeline_id {
+ MALI_C720_DISC_PIPE_GLOBAL,
+ MALI_C720_DISC_PIPE_INPUT,
+ MALI_C720_DISC_PIPE_HV,
+ MALI_C720_DISC_PIPE_CV,
+ MALI_C720_DISC_PIPE_RAW_OUTPUT,
+ MALI_C720_DISC_PIPE_FR_OUTPUT,
+ MALI_C720_DISC_PIPE_PYR_OUTPUT,
+ MALI_C720_DISC_PIPE_FOV_OUTPUT,
+ MALI_C720_DISC_PIPE_STATS,
+ MALI_C720_DISC_PIPE_TPG,
+ MALI_C720_DISC_PIPE_MAX,
+};
+
+enum mali_c720_discovery_module_id {
+ MALI_C720_DISC_MODULE_ID_NONE = 0,
+ MALI_C720_DISC_MODULE_ID_CM_FULL,
+ MALI_C720_DISC_MODULE_ID_GLOBAL_ISP_CONTROL,
+ MALI_C720_DISC_MODULE_ID_INTERRUPT_CONTROLLER,
+ MALI_C720_DISC_MODULE_ID_FAULT_COLLECTOR,
+ MALI_C720_DISC_MODULE_ID_MODULE_BIST_CONTROL,
+ MALI_C720_DISC_MODULE_ID_MODULE_CRC_CONTROL,
+ MALI_C720_DISC_MODULE_ID_MODULE_CG_CONTROL,
+ MALI_C720_DISC_MODULE_ID_CM_CONTROL,
+ MALI_C720_DISC_MODULE_ID_CM_SLOT_LOADABLE,
+ MALI_C720_DISC_MODULE_ID_PIPELINE_GLOBAL_CONTROL,
+ MALI_C720_DISC_MODULE_ID_DIGITAL_GAIN,
+ MALI_C720_DISC_MODULE_ID_GAIN_AND_OFFSET,
+ MALI_C720_DISC_MODULE_ID_BLACK_LEVEL,
+ MALI_C720_DISC_MODULE_ID_WB_GAIN,
+ MALI_C720_DISC_MODULE_ID_OFFSET,
+ MALI_C720_DISC_MODULE_ID_SQUARE_ROOT_RAW,
+ MALI_C720_DISC_MODULE_ID_SQUARE_RAW,
+ MALI_C720_DISC_MODULE_ID_SQUARE_ROOT_RGB,
+ MALI_C720_DISC_MODULE_ID_SQUARE_RGB,
+ MALI_C720_DISC_MODULE_ID_DECOMPANDER,
+ MALI_C720_DISC_MODULE_ID_FRAME_STITCHING,
+ MALI_C720_DISC_MODULE_ID_DEFECT_PIXEL,
+ MALI_C720_DISC_MODULE_ID_RGBIR_REMOSAIC,
+ MALI_C720_DISC_MODULE_ID_CA_CORRECTION,
+ MALI_C720_DISC_MODULE_ID_TEMPER,
+ MALI_C720_DISC_MODULE_ID_SINTER,
+ MALI_C720_DISC_MODULE_ID_SMART_SHADING,
+ MALI_C720_DISC_MODULE_ID_RAW_TO_INTENSITY,
+ MALI_C720_DISC_MODULE_ID_DEHAZE,
+ MALI_C720_DISC_MODULE_ID_IRIDIX,
+ MALI_C720_DISC_MODULE_ID_DEMOSAIC_STD,
+ MALI_C720_DISC_MODULE_ID_DEMOSAIC_DFD,
+ MALI_C720_DISC_MODULE_ID_PURPLE_FRINGE,
+ MALI_C720_DISC_MODULE_ID_CCM,
+ MALI_C720_DISC_MODULE_ID_CNR,
+ MALI_C720_DISC_MODULE_ID_SCALER_RGB,
+ MALI_C720_DISC_MODULE_ID_SCALER_RAW,
+ MALI_C720_DISC_MODULE_ID_CROP,
+ MALI_C720_DISC_MODULE_ID_SHARPENING_RGB,
+ MALI_C720_DISC_MODULE_ID_SHARPENING_RAW,
+ MALI_C720_DISC_MODULE_ID_GAMMA,
+ MALI_C720_DISC_MODULE_ID_TC_LUT_RGB,
+ MALI_C720_DISC_MODULE_ID_TC_LUT_RAW,
+ MALI_C720_DISC_MODULE_ID_OUTPUT_FORMATTER,
+ MALI_C720_DISC_MODULE_ID_OUTPUT_MULTIPLEXER,
+ MALI_C720_DISC_MODULE_ID_GAUSSIAN_PYRAMID,
+ MALI_C720_DISC_MODULE_ID_RAW_STREAM_PACKER,
+ MALI_C720_DISC_MODULE_ID_TPG_RAW_MULTI,
+ MALI_C720_DISC_MODULE_ID_TPG_RAW_SINGLE,
+ MALI_C720_DISC_MODULE_ID_TPG_RAW_RGB_SINGLE,
+ MALI_C720_DISC_MODULE_ID_FGM,
+ MALI_C720_DISC_MODULE_ID_FBIST_BRIDGE,
+ MALI_C720_DISC_MODULE_ID_PIPELINE_CRC,
+ MALI_C720_DISC_MODULE_ID_INPUT_CRC,
+ MALI_C720_DISC_MODULE_ID_INTENSITY_STATS,
+ MALI_C720_DISC_MODULE_ID_HISTOGRAM_STATS,
+ MALI_C720_DISC_MODULE_ID_COLOR_STATS,
+ MALI_C720_DISC_MODULE_ID_AUTO_FOCUS_STATS,
+ MALI_C720_DISC_MODULE_ID_MAX,
+};
+
+struct mali_c720_discovery_target {
+ enum mali_c720_discovery_module_id module_id;
+ u8 module_instance;
+ enum mali_c720_discovery_pipeline_id pipeline_id;
+ u8 pipeline_instance;
+};
+
+enum mali_c720_discovery_table_scaler_rgb_id {
+ MALI_C720_DISC_TABLE_SCALER_RGB_H_MEM_ID = 0,
+ MALI_C720_DISC_TABLE_SCALER_RGB_V_MEM_ID,
+ MALI_C720_DISC_TABLE_SCALER_RGB_MAX_ID,
+};
+
+struct mali_c720_discovery_table {
+ u32 base;
+ u32 size;
+ unsigned int id;
+ struct list_head node;
+};
+
+struct mali_c720_discovery_version {
+ bool present;
+ u8 major;
+ u8 minor;
+ u8 patch;
+};
+
+struct mali_c720_discovery_param {
+ u8 id;
+ u16 value;
+ struct list_head node;
+};
+
+struct mali_c720_discovery_module {
+ enum mali_c720_discovery_module_id id;
+ unsigned int instance_id;
+ bool found;
+ bool present;
+ u32 base;
+ struct mali_c720_discovery_version version;
+ struct list_head memories;
+ struct list_head fbists;
+ struct list_head mbists;
+ struct list_head config_crcs;
+ struct list_head clock_gating;
+ struct list_head params;
+ struct list_head node;
+ unsigned int num_memories;
+ unsigned int num_params;
+ unsigned int num_fbists;
+ unsigned int num_mbists;
+ unsigned int num_config_crcs;
+ unsigned int num_clock_gating;
+ unsigned int fbist_instance_id;
+ unsigned int mbist_instance_id;
+ unsigned int config_crc_instance_id;
+ unsigned int clock_gating_instance_id;
+};
+
+struct mali_c720_discovery_pipeline {
+ bool present;
+ unsigned int instance_id;
+ enum mali_c720_discovery_pipeline_id id;
+ struct list_head modules;
+};
+
+struct mali_c720_discovery {
+ enum mali_c720_discovery_version_id version;
+ unsigned int next_module_id;
+ unsigned int next_memory_id;
+ unsigned int next_param_id;
+ struct mali_c720_discovery_module
+ modules[MALI_C720_DISCOVERY_MAX_MODULES];
+ struct mali_c720_discovery_table
+ memories[MALI_C720_DISCOVERY_MAX_MEMORIES];
+ struct mali_c720_discovery_param
+ params[MALI_C720_DISCOVERY_MAX_PARAMS];
+ struct mali_c720_discovery_pipeline
+ pipelines[MALI_C720_DISC_PIPE_MAX][MALI_C720_DISCOVERY_MAX_PIPELINE_INSTANCES];
+};
+
+int mali_c720_discovery_init(struct mali_c720 *mali_c720, resource_size_t reg_size);
+
+int mali_c720_discovery_get_module_base(struct mali_c720 *mali_c720,
+ const struct mali_c720_discovery_target *target,
+ u32 *base);
+
+int mali_c720_discovery_get_module_table_base(struct mali_c720 *mali_c720,
+ const struct mali_c720_discovery_target *target,
+ unsigned int table_id,
+ u32 *base);
+
+bool mali_c720_discovery_module_present(struct mali_c720 *mali_c720,
+ const struct mali_c720_discovery_target *target);
+
+#endif /* MALI_C720_DISCOVERY_H */
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 08/24] media: mali-c720: Add context manager and interrupt handling
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (6 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 07/24] media: mali-c720: Add hardware discovery support Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 09/24] media: mali-c720: Add input frontend subdevice Anthony McGivern
` (15 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add support for the ISP context manager unit. Once software marks a
context ready and transfers control to hardware, the unit schedules
frame processing across hardware contexts. Initial support uses a
single context.
Provide API functions for other driver components to configure, start
and stop contexts, and handle frame-completion events. These include
programming hardware descriptors for contexts, inputs, the CDMA engine
and input/output buffers. API calls may reserve resources from hardware
pools shared across all contexts, such as buffer descriptors.
Add handling for input frame-start and backend frame-completion
interrupts.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../platform/arm/mali-c720/mali-c720-common.h | 45 +
.../platform/arm/mali-c720/mali-c720-ctx-mgr.c | 1754 ++++++++++++++++++++
.../platform/arm/mali-c720/mali-c720-ctx-mgr.h | 303 ++++
.../platform/arm/mali-c720/mali-c720-interrupts.c | 432 +++++
.../platform/arm/mali-c720/mali-c720-interrupts.h | 34 +
5 files changed, 2568 insertions(+)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 3efbf7572e5015a57124b6f623ba5e1d757bf22a..1808fdef149f8035394af122b348232be1ff51dd 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -9,20 +9,25 @@
#define MALI_C720_COMMON_H
#include <linux/io.h>
+#include <linux/kfifo.h>
#include <linux/mutex.h>
#include <linux/refcount.h>
#include <linux/spinlock.h>
#include <linux/videodev2.h>
+#include "mali-c720-ctx-mgr.h"
#include "mali-c720-discovery.h"
#include "mali-c720-formats.h"
#include "mali-c720-id.h"
+#include "mali-c720-interrupts.h"
#include "mali-c720-register-access.h"
#include "mali-c720-registers.h"
#include "mali-c720-registers-top.h"
#include "mali-c720-registers-ctx-mgr.h"
#include "mali-c720-registers-modules.h"
+#define MALI_C720_FRAME_TIMESTAMP_COUNT 256
+
enum mali_c720_cap_devs {
MALI_C720_CAP_DEV_FR0_RGB,
MALI_C720_CAP_DEV_FR0_YUV,
@@ -39,20 +44,60 @@ struct mali_c720_context_regs {
refcount_t users;
};
+struct mali_c720_frame_timestamp {
+ u64 timestamp;
+ u32 sequence;
+ bool valid;
+};
+
struct mali_c720_context {
+ unsigned int id;
struct mali_c720 *mali_c720;
struct mali_c720_context_regs regs;
+ struct mali_c720_cdma_desc cdma_desc;
+ struct mali_c720_slot_desc slot_desc;
+ struct mali_c720_input_cfg input_cfg;
+ unsigned int active_fifos_by_output[MALI_C720_MAX_NUM_CAP_DEVS];
+ bool slot_desc_updated;
+
+ /* Protects request submission */
+ spinlock_t req_lock;
+ unsigned int request_sequence;
+
+ /* Protects context state and input_cfg. */
+ spinlock_t state_lock;
+ int state;
+ bool pipeline_busy;
+
+ unsigned int input_frame_sequence;
+ unsigned int frame_sequence;
+ struct mali_c720_frame_timestamp frame_timestamps[MALI_C720_FRAME_TIMESTAMP_COUNT];
+ u64 timestamp;
};
struct mali_c720 {
struct device *dev;
+ unsigned int irq;
u8 __iomem *base;
resource_size_t mmio_size;
+ u32 top_base;
struct mali_c720_registers registers;
+ u8 *default_regs;
struct mali_c720_discovery discovery;
const struct mali_c720_hw_version *hw_version;
+ struct mali_c720_context context;
+ struct mali_c720_ctx_mgr ctx_mgr;
+
+ /* Serializes media registration, start/stop and resource allocation. */
+ struct mutex device_lock;
+ u8 num_active_contexts;
+
+ DECLARE_KFIFO(irq_fifo, struct mali_c720_interrupt_data, MALI_C720_IRQ_FIFO_SIZE);
+
+ /* Spinlock to guard IRQ fifo */
+ spinlock_t irq_lock;
};
#endif /* MALI_C720_COMMON_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
new file mode 100644
index 0000000000000000000000000000000000000000..828a993c5da63619f6fbb99d28532846f969d663
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
@@ -0,0 +1,1754 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/bitmap.h>
+#include <linux/bitops.h>
+#include <linux/cleanup.h>
+#include <linux/crc-ccitt.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/timekeeping.h>
+#include <linux/wordpart.h>
+
+#include "mali-c720-common.h"
+
+#define MALI_C720_CRC16_MCRF4XX_INIT 0xffff
+
+/* Allow for a worst case of 1FPS for input enable/disable timeouts */
+#define INPUT_POLL_TIMEOUT 1000000
+#define INPUT_POLL_INTERVAL 1000
+
+struct mali_c720_context *mali_c720_get_active_context(struct mali_c720 *mali_c720)
+{
+ return &mali_c720->context;
+}
+
+static u32 mali_c720_ctx_mgr_buffer_base(const struct mali_c720_registers *regs,
+ const struct mali_c720_buffer_pool *pool,
+ unsigned int index)
+{
+ const struct mali_c720_cm_buffer_regs *buffer = regs->cm->buffer;
+ unsigned int descriptor_id = pool->pool_id + index;
+
+ if (pool->type == MALI_C720_BUF_TYPE_RAW)
+ return mali_c720_group_base(&buffer->raw_group, descriptor_id);
+
+ return mali_c720_group_base(&buffer->out_group, descriptor_id);
+}
+
+static void mali_c720_ctx_mgr_input_command(struct mali_c720 *mali_c720, u32 base,
+ u32 command)
+{
+ const struct mali_c720_cm_input_regs *input = mali_c720->registers.cm->input;
+ u32 val;
+
+ mali_c720_group_write(mali_c720, base, &input->command, command);
+ mali_c720_group_read(mali_c720, base, &input->status_arch);
+ udelay(1);
+
+ if (command != MALI_C720_INPUT_COMMAND_CANCEL)
+ return;
+
+ /* Wait for the input FIFO and writer to drain during cancellation. */
+ (void)poll_timeout_us(val = mali_c720_group_read(mali_c720, base, &input->status_arch),
+ val == MALI_C720_INPUT_DISABLED, 10, 1000, false);
+}
+
+static void mali_c720_ctx_mgr_buffer_request(struct mali_c720 *mali_c720, u32 base, u32 state)
+{
+ const struct mali_c720_cm_buffer_regs *buffer = mali_c720->registers.cm->buffer;
+ u32 val;
+
+ /* Readback and a small delay to ensure state transition completes */
+ mali_c720_group_write(mali_c720, base, &buffer->state_request, state);
+ mali_c720_group_read(mali_c720, base, &buffer->state);
+ udelay(1);
+
+ if (state != MALI_C720_BUFFER_STATE_CANCELLED)
+ return;
+
+ /* Wait for outstanding DMA transactions during cancellation */
+ (void)poll_timeout_us_atomic(val = mali_c720_group_read(mali_c720, base, &buffer->state),
+ val == MALI_C720_BUFFER_STATE_CANCELLED, 10, 1000, false);
+}
+
+static void mali_c720_ctx_mgr_set_slot_enabled(struct mali_c720_context *ctx, bool enable)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_job_control_regs *job_control =
+ mali_c720->registers.cm->job_control;
+ const struct mali_c720_cm_slot_regs *slot = mali_c720->registers.cm->slot;
+ u32 val = enable ? MALI_C720_SCH_COMMAND_ENABLE_SLOT :
+ MALI_C720_SCH_COMMAND_DISABLE_SLOT;
+ val |= ctx->id << mali_c720_reg_shift(&job_control->sch_command_slot);
+
+ mali_c720_write_raw(mali_c720, &job_control->sch_command, val);
+ mali_c720_group_read(mali_c720, mali_c720_group_base(&slot->group, ctx->id), &slot->status);
+ udelay(1);
+}
+
+static void mali_c720_ctx_mgr_cancel_slot(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_job_control_regs *job_control =
+ mali_c720->registers.cm->job_control;
+ const struct mali_c720_cm_slot_regs *slot = mali_c720->registers.cm->slot;
+ u32 val = MALI_C720_SCH_COMMAND_CANCEL_SLOT;
+
+ val |= ctx->id << mali_c720_reg_shift(&job_control->sch_command_slot);
+
+ mali_c720_write_raw(mali_c720, &job_control->sch_command, val);
+ mali_c720_group_read(mali_c720, mali_c720_group_base(&slot->group, ctx->id), &slot->status);
+ udelay(1);
+}
+
+static void mali_c720_ctx_mgr_stop_slot(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_slot_regs *slot = mali_c720->registers.cm->slot;
+ u32 slot_addr = mali_c720_group_base(&slot->group, ctx->id);
+ u32 val;
+ int ret;
+
+ mali_c720_ctx_mgr_set_slot_enabled(ctx, false);
+
+ /* Stop arbitration and allow an already selected frame to finish. */
+ ret = poll_timeout_us(val = mali_c720_group_read(mali_c720, slot_addr, &slot->status),
+ val == MALI_C720_SLOT_DISABLED || val == MALI_C720_SLOT_ERROR,
+ 5000, 1000000, false);
+ if (!ret && val == MALI_C720_SLOT_DISABLED)
+ return;
+
+ dev_warn(mali_c720->dev, "Slot %u failed to disable (state %u), cancelling\n",
+ ctx->id, val);
+ mali_c720_ctx_mgr_cancel_slot(ctx);
+
+ /* Cancellation must drain the buffer agents and CDMA before cleanup. */
+ (void)poll_timeout_us(val = mali_c720_group_read(mali_c720, slot_addr, &slot->status),
+ val == MALI_C720_SLOT_DISABLED, 100, 1000, false);
+}
+
+static void mali_c720_ctx_mgr_cdma_request(struct mali_c720 *mali_c720, u32 base, u32 state)
+{
+ const struct mali_c720_cm_cdma_slot_regs *cdma_slot = mali_c720->registers.cm->cdma_slot;
+
+ mali_c720_group_write(mali_c720, base, &cdma_slot->cdma_state_request, state);
+ mali_c720_group_read(mali_c720, base, &cdma_slot->cdma_state);
+ udelay(1);
+}
+
+static void mali_c720_ctx_mgr_set_scheduler_enabled(struct mali_c720 *mali_c720, bool enable)
+{
+ const struct mali_c720_cm_job_control_regs *job_control =
+ mali_c720->registers.cm->job_control;
+ u32 command = enable ? MALI_C720_SCH_COMMAND_ENABLE : MALI_C720_SCH_COMMAND_DISABLE;
+
+ mali_c720_write(mali_c720, &job_control->sch_command, command);
+ mali_c720_read(mali_c720, &job_control->sch_status_arch);
+ udelay(1);
+}
+
+static inline unsigned int mali_c720_reg_width(u32 mask)
+{
+ if (!mask)
+ return 0;
+
+ return __fls(mask) - __ffs(mask) + 1;
+}
+
+static u16 mali_c720_crc16_mcrf4xx_bits(u16 crc, u32 data, unsigned int bits)
+{
+ unsigned int bit;
+
+ for (bit = 0; bit + 8 <= bits; bit += 8)
+ crc = crc_ccitt_byte(crc, (data >> bit) & 0xff);
+
+ for (; bit < bits; bit++) {
+ if ((crc ^ (data >> bit)) & 0x1)
+ crc = (crc >> 1) ^ 0x8408;
+ else
+ crc >>= 1;
+ }
+
+ return crc;
+}
+
+static u16 mali_c720_crc16_mcrf4xx_reg(u16 crc, u32 data, u32 mask)
+{
+ return mali_c720_crc16_mcrf4xx_bits(crc, data,
+ mali_c720_reg_width(mask));
+}
+
+static u16 mali_c720_ctx_mgr_calc_cdma_desc_crc(struct mali_c720_context *ctx)
+{
+ const struct mali_c720_cm_cdma_slot_regs *cdma_slot =
+ ctx->mali_c720->registers.cm->cdma_slot;
+ struct mali_c720_cdma_desc *desc = &ctx->cdma_desc;
+ u16 crc = MALI_C720_CRC16_MCRF4XX_INIT;
+
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 4);
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 2);
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 2);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->infinite,
+ mali_c720_reg_mask(&cdma_slot->infinite));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 1);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->nonsecure,
+ mali_c720_reg_mask(&cdma_slot->nonsecure));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->stream_id,
+ mali_c720_reg_mask(&cdma_slot->stream_id));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 16);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->transfer_size,
+ mali_c720_reg_mask(&cdma_slot->transfer_size));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->units_low,
+ mali_c720_reg_mask(&cdma_slot->units_low));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->units_high,
+ mali_c720_reg_mask(&cdma_slot->units_high));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->base_address_low,
+ mali_c720_reg_mask(&cdma_slot->base_address_low));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->base_address_high,
+ mali_c720_reg_mask(&cdma_slot->base_address_high));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->ld_sg_count,
+ mali_c720_reg_mask(&cdma_slot->ld_sg_count));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 2);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->st_sg_count,
+ mali_c720_reg_mask(&cdma_slot->st_sg_count));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 18);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->alt_transfer_size,
+ mali_c720_reg_mask(&cdma_slot->alt_transfer_size));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->alt_base_address_low,
+ mali_c720_reg_mask(&cdma_slot->alt_base_address_low));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->alt_base_address_high,
+ mali_c720_reg_mask(&cdma_slot->alt_base_address_high));
+
+ return crc;
+}
+
+static u16 mali_c720_ctx_mgr_calc_slot_desc_crc(struct mali_c720_context *ctx)
+{
+ const struct mali_c720_cm_slot_regs *slot = ctx->mali_c720->registers.cm->slot;
+ struct mali_c720_slot_desc *desc = &ctx->slot_desc;
+ u16 crc = MALI_C720_CRC16_MCRF4XX_INIT;
+
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->mode,
+ mali_c720_reg_mask(&slot->mode));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->timeout_enable,
+ mali_c720_reg_mask(&slot->timeout_enable));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 4);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->schedule_priority,
+ mali_c720_reg_mask(&slot->schedule_priority));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 1);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->nonsecure,
+ mali_c720_reg_mask(&slot->nonsecure));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->stream_id,
+ mali_c720_reg_mask(&slot->stream_id));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 16);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->delay_mant,
+ mali_c720_reg_mask(&slot->delay_mant));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->delay_exp,
+ mali_c720_reg_mask(&slot->delay_exp));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->slot_event,
+ mali_c720_reg_mask(&slot->slot_event));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 12);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->slot_input_0,
+ mali_c720_reg_mask(&slot->slot_input_0));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->slot_input_1,
+ mali_c720_reg_mask(&slot->slot_input_1));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 16);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->timeout_mant,
+ mali_c720_reg_mask(&slot->timeout_mant));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->timeout_exp,
+ mali_c720_reg_mask(&slot->timeout_exp));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 16);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_roi0,
+ mali_c720_reg_mask(&slot->pool_roi0));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_roi1,
+ mali_c720_reg_mask(&slot->pool_roi1));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_roi2,
+ mali_c720_reg_mask(&slot->pool_roi2));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_raw,
+ mali_c720_reg_mask(&slot->pool_raw));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_scaler0_rgb,
+ mali_c720_reg_mask(&slot->pool_scaler0_rgb));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_scaler0_yuv,
+ mali_c720_reg_mask(&slot->pool_scaler0_yuv));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_scaler1_rgb,
+ mali_c720_reg_mask(&slot->pool_scaler1_rgb));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_scaler1_yuv,
+ mali_c720_reg_mask(&slot->pool_scaler1_yuv));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_scaler2_rgb,
+ mali_c720_reg_mask(&slot->pool_scaler2_rgb));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_scaler2_yuv,
+ mali_c720_reg_mask(&slot->pool_scaler2_yuv));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_scaler3_rgb,
+ mali_c720_reg_mask(&slot->pool_scaler3_rgb));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_scaler3_yuv,
+ mali_c720_reg_mask(&slot->pool_scaler3_yuv));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_gdc_main,
+ mali_c720_reg_mask(&slot->pool_gdc_main));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_gdc_roi0,
+ mali_c720_reg_mask(&slot->pool_gdc_roi0));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_gdc_roi1,
+ mali_c720_reg_mask(&slot->pool_gdc_roi1));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_gdc_roi2,
+ mali_c720_reg_mask(&slot->pool_gdc_roi2));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_pyramid,
+ mali_c720_reg_mask(&slot->pool_pyramid));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool_consistency,
+ mali_c720_reg_mask(&slot->pool_consistency));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 16);
+
+ return crc;
+}
+
+static u16 mali_c720_ctx_mgr_calc_buffer_desc_crc(const struct mali_c720_registers *regs,
+ struct mali_c720_buffer_pool *pool,
+ unsigned int index)
+{
+ const struct mali_c720_cm_buffer_regs *buffer = regs->cm->buffer;
+ struct mali_c720_buffer_desc *desc = &pool->desc[index];
+ u16 crc = MALI_C720_CRC16_MCRF4XX_INIT;
+
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 32);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->data_format,
+ mali_c720_reg_mask(&buffer->data_format));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->data_align,
+ mali_c720_reg_mask(&buffer->data_align));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->nonsecure,
+ mali_c720_reg_mask(&buffer->nonsecure));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->stream_id,
+ mali_c720_reg_mask(&buffer->stream_id));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->data_layout,
+ mali_c720_reg_mask(&buffer->data_layout));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->crc_check,
+ mali_c720_reg_mask(&buffer->crc_check));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->pool,
+ mali_c720_reg_mask(&buffer->pool));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->mode,
+ mali_c720_reg_mask(&buffer->mode));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->block_size,
+ mali_c720_reg_mask(&buffer->block_size));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 8);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->base_address_low,
+ mali_c720_reg_mask(&buffer->base_address_low));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->base_address_high,
+ mali_c720_reg_mask(&buffer->base_address_high));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->buffer_size,
+ mali_c720_reg_mask(&buffer->size));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->plane2_offset,
+ mali_c720_reg_mask(&buffer->plane2_offset));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->plane3_offset,
+ mali_c720_reg_mask(&buffer->plane3_offset));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->plane4_offset,
+ mali_c720_reg_mask(&buffer->plane4_offset));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->line1_offset,
+ mali_c720_reg_mask(&buffer->line1_offset));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->line2_offset,
+ mali_c720_reg_mask(&buffer->line2_offset));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->line3_offset,
+ mali_c720_reg_mask(&buffer->line3_offset));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->line4_offset,
+ mali_c720_reg_mask(&buffer->line4_offset));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->width,
+ mali_c720_reg_mask(&buffer->width));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->height,
+ mali_c720_reg_mask(&buffer->height));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->colorspace,
+ mali_c720_reg_mask(&buffer->colorspace));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->subsampling,
+ mali_c720_reg_mask(&buffer->subsampling));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 2);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->component_width,
+ mali_c720_reg_mask(&buffer->component_width));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->msb_align,
+ mali_c720_reg_mask(&buffer->msb_align));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->phase,
+ mali_c720_reg_mask(&buffer->phase));
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 1);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->height_modulo,
+ mali_c720_reg_mask(&buffer->height_modulo));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->compression,
+ mali_c720_reg_mask(&buffer->compression));
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->compression23,
+ mali_c720_reg_mask(&buffer->compression23));
+
+ return crc;
+}
+
+static void mali_c720_prepare_input_fifos(struct mali_c720 *mali_c720)
+{
+ const struct mali_c720_cm_fifo_regs *input_fifo = mali_c720->registers.cm->input_fifo;
+ const struct mali_c720_cm_fifo_regs *reader_fifo = mali_c720->registers.cm->reader_fifo;
+ const struct mali_c720_cm_temper_fifo_regs *temper_fifo =
+ mali_c720->registers.cm->temper_fifo;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ u32 fifo_base_addr, fifo_size;
+ unsigned int fifo_users, i;
+
+ fifo_users = ctx_mgr->num_virtual_inputs + 4; /* +4 for frame reader and temper FIFOs */
+ fifo_size = ctx_mgr->input_fifo_size / fifo_users;
+
+ fifo_base_addr = 0;
+ for (i = 0; i < ctx_mgr->num_virtual_inputs; i++) {
+ mali_c720_group_write(mali_c720, mali_c720_group_base(&input_fifo->group, i),
+ &input_fifo->base_address, fifo_base_addr);
+ mali_c720_group_write(mali_c720, mali_c720_group_base(&input_fifo->group, i),
+ &input_fifo->size, fifo_size);
+
+ fifo_base_addr += fifo_size;
+ }
+
+ mali_c720_group_write(mali_c720, mali_c720_group_base(&reader_fifo->group, 0),
+ &reader_fifo->base_address, fifo_base_addr);
+ mali_c720_group_write(mali_c720, mali_c720_group_base(&reader_fifo->group, 0),
+ &reader_fifo->size, fifo_size);
+ fifo_base_addr += fifo_size;
+
+ mali_c720_group_write(mali_c720, mali_c720_group_base(&reader_fifo->group, 1),
+ &reader_fifo->base_address, fifo_base_addr);
+ mali_c720_group_write(mali_c720, mali_c720_group_base(&reader_fifo->group, 1),
+ &reader_fifo->size, fifo_size);
+ fifo_base_addr += fifo_size;
+
+ mali_c720_write(mali_c720, &temper_fifo->w_fifo_base_address, fifo_base_addr);
+ mali_c720_write(mali_c720, &temper_fifo->w_fifo_size, fifo_size);
+ fifo_base_addr += fifo_size;
+
+ mali_c720_write(mali_c720, &temper_fifo->r_fifo_base_address, fifo_base_addr);
+ mali_c720_write(mali_c720, &temper_fifo->r_fifo_size, fifo_size);
+}
+
+static unsigned int mali_c720_ctx_mgr_get_output_max_fifos(unsigned int output)
+{
+ return output < MALI_C720_MAX_NUM_CAP_DEVS ? 3 : 0;
+}
+
+static u32 mali_c720_ctx_mgr_get_output_fifo_base(const struct mali_c720_registers *regs,
+ unsigned int output, unsigned int fifo)
+{
+ const struct mali_c720_cm_load_out_fifo_regs *load_out_fifo = regs->cm->load_out_fifo;
+
+ switch (output) {
+ case MALI_C720_CAP_DEV_FR0_RGB:
+ return mali_c720_group_base(&load_out_fifo->scaler_group, fifo);
+ case MALI_C720_CAP_DEV_FR0_YUV:
+ return mali_c720_group_base(&load_out_fifo->scaler_group, 3 + fifo);
+ default:
+ WARN_ON_ONCE(1);
+ return 0;
+ }
+}
+
+static void mali_c720_ctx_mgr_prepare_output_fifos(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ const struct mali_c720_cm_load_out_fifo_regs *load_out_fifo = regs->cm->load_out_fifo;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ unsigned int i, j;
+ u32 fifo_base_addr = 0;
+ u32 fifo_size;
+ unsigned int active_fifos[MALI_C720_MAX_NUM_CAP_DEVS];
+ unsigned int total_fifos = 0;
+
+ /*
+ * Distribute the output FIFO size among the active outputs,
+ * depending on FIFOs required by each output.
+ */
+
+ memcpy(active_fifos, ctx->active_fifos_by_output, sizeof(active_fifos));
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
+ unsigned int max_fifos = mali_c720_ctx_mgr_get_output_max_fifos(i);
+
+ if (WARN_ON_ONCE(active_fifos[i] > max_fifos))
+ active_fifos[i] = max_fifos;
+
+ total_fifos += active_fifos[i];
+ }
+
+ fifo_size = total_fifos ? ctx_mgr->output_fifo_size / total_fifos : 0;
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
+ unsigned int max_fifos = mali_c720_ctx_mgr_get_output_max_fifos(i);
+
+ for (j = 0; j < max_fifos; j++) {
+ u32 fifo_base = mali_c720_ctx_mgr_get_output_fifo_base(regs, i, j);
+ u32 base_addr = 0;
+ u32 size = 0;
+
+ if (!fifo_base)
+ continue;
+
+ if (j < active_fifos[i]) {
+ base_addr = fifo_base_addr;
+ size = fifo_size;
+ fifo_base_addr += fifo_size;
+ }
+
+ mali_c720_ctx_group_write(ctx, fifo_base,
+ &load_out_fifo->base_address,
+ base_addr);
+ mali_c720_ctx_group_write(ctx, fifo_base,
+ &load_out_fifo->size,
+ size);
+ }
+ }
+}
+
+static void mali_c720_ctx_mgr_write_buffer_desc(struct mali_c720_context *ctx,
+ struct mali_c720_buffer_pool *pool,
+ unsigned int index)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ const struct mali_c720_cm_buffer_regs *buffer = regs->cm->buffer;
+ struct mali_c720_buffer_desc *desc;
+ u32 buffer_addr = mali_c720_ctx_mgr_buffer_base(regs, pool, index);
+
+ desc = &pool->desc[index];
+ desc->crc = mali_c720_ctx_mgr_calc_buffer_desc_crc(regs, pool, index);
+
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->nonsecure, desc->nonsecure);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->stream_id, desc->stream_id);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->crc_check, desc->crc_check);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->pool, desc->pool);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->mode, desc->mode);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->block_size, desc->block_size);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->base_address_low, desc->base_address_low);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->base_address_high, desc->base_address_high);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->size, desc->buffer_size);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->plane2_offset, desc->plane2_offset);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->plane3_offset, desc->plane3_offset);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->plane4_offset, desc->plane4_offset);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->line1_offset, desc->line1_offset);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->line2_offset, desc->line2_offset);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->line3_offset, desc->line3_offset);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->line4_offset, desc->line4_offset);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->data_format, desc->data_format);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->data_align, desc->data_align);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->data_layout, desc->data_layout);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->width, desc->width);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->height, desc->height);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->colorspace, desc->colorspace);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->subsampling, desc->subsampling);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->component_width, desc->component_width);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->msb_align, desc->msb_align);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->phase, desc->phase);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->height_modulo, desc->height_modulo);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->compression, desc->compression);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->compression23, desc->compression23);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->descriptor_crc, desc->crc);
+}
+
+static void mali_c720_ctx_mgr_update_buffer_desc(struct mali_c720_context *ctx,
+ struct mali_c720_buffer_pool *pool,
+ unsigned int index)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ const struct mali_c720_cm_buffer_regs *buffer = regs->cm->buffer;
+ struct mali_c720_buffer_desc *desc;
+ u32 buffer_addr = mali_c720_ctx_mgr_buffer_base(regs, pool, index);
+
+ desc = &pool->desc[index];
+ desc->crc = mali_c720_ctx_mgr_calc_buffer_desc_crc(regs, pool, index);
+
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->base_address_low,
+ desc->base_address_low);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->base_address_high,
+ desc->base_address_high);
+
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->descriptor_crc, desc->crc);
+}
+
+static void mali_c720_ctx_mgr_write_cdma_desc(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_cdma_slot_regs *cdma_slot = mali_c720->registers.cm->cdma_slot;
+ struct mali_c720_cdma_desc *desc = &ctx->cdma_desc;
+ u32 cdma_slot_addr = mali_c720_group_base(&cdma_slot->group, ctx->id);
+
+ desc->crc = mali_c720_ctx_mgr_calc_cdma_desc_crc(ctx);
+
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->infinite, desc->infinite);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->nonsecure, desc->nonsecure);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->stream_id, desc->stream_id);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->units_low, desc->units_low);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->units_high, desc->units_high);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->ld_sg_count, desc->ld_sg_count);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->transfer_size, desc->transfer_size);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->alt_transfer_size, desc->alt_transfer_size);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->base_address_low, desc->base_address_low);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->base_address_high, desc->base_address_high);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->alt_base_address_low, desc->alt_base_address_low);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->alt_base_address_high, desc->alt_base_address_high);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->st_sg_count, desc->st_sg_count);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->crc, desc->crc);
+}
+
+static void mali_c720_ctx_mgr_write_slot_desc(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_slot_regs *slot = mali_c720->registers.cm->slot;
+ u32 slot_addr = mali_c720_group_base(&slot->group, ctx->id);
+
+ ctx->slot_desc.crc = mali_c720_ctx_mgr_calc_slot_desc_crc(ctx);
+
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->mode, ctx->slot_desc.mode);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->timeout_enable, ctx->slot_desc.timeout_enable);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->timeout_mant, ctx->slot_desc.timeout_mant);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->timeout_exp, ctx->slot_desc.timeout_exp);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->schedule_priority, ctx->slot_desc.schedule_priority);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->nonsecure, ctx->slot_desc.nonsecure);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->stream_id, ctx->slot_desc.stream_id);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->delay_mant, ctx->slot_desc.delay_mant);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->delay_exp, ctx->slot_desc.delay_exp);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->slot_event, ctx->slot_desc.slot_event);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->slot_input_0, ctx->slot_desc.slot_input_0);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->slot_input_1, ctx->slot_desc.slot_input_1);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_roi0, ctx->slot_desc.pool_roi0);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_roi1, ctx->slot_desc.pool_roi1);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_roi2, ctx->slot_desc.pool_roi2);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_raw, ctx->slot_desc.pool_raw);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler0_rgb, ctx->slot_desc.pool_scaler0_rgb);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler0_yuv, ctx->slot_desc.pool_scaler0_yuv);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler1_rgb, ctx->slot_desc.pool_scaler1_rgb);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler1_yuv, ctx->slot_desc.pool_scaler1_yuv);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler2_rgb, ctx->slot_desc.pool_scaler2_rgb);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler2_yuv, ctx->slot_desc.pool_scaler2_yuv);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler3_rgb, ctx->slot_desc.pool_scaler3_rgb);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler3_yuv, ctx->slot_desc.pool_scaler3_yuv);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_gdc_main, ctx->slot_desc.pool_gdc_main);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_gdc_roi0, ctx->slot_desc.pool_gdc_roi0);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_gdc_roi1, ctx->slot_desc.pool_gdc_roi1);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_gdc_roi2, ctx->slot_desc.pool_gdc_roi2);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_pyramid, ctx->slot_desc.pool_pyramid);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_consistency, ctx->slot_desc.pool_consistency);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->crc, ctx->slot_desc.crc);
+}
+
+static void mali_c720_ctx_mgr_update_slot_desc(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_slot_regs *slot = mali_c720->registers.cm->slot;
+ u32 slot_addr = mali_c720_group_base(&slot->group, ctx->id);
+
+ ctx->slot_desc.crc = mali_c720_ctx_mgr_calc_slot_desc_crc(ctx);
+
+ /*
+ * A running slot must be stopped before modifying descriptor fields
+ * to prevent CRC mismatch faults from being raised.
+ */
+ mali_c720_ctx_mgr_set_slot_enabled(ctx, false);
+
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_roi0, ctx->slot_desc.pool_roi0);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_roi1, ctx->slot_desc.pool_roi1);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_roi2, ctx->slot_desc.pool_roi2);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_raw, ctx->slot_desc.pool_raw);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler0_rgb, ctx->slot_desc.pool_scaler0_rgb);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler0_yuv, ctx->slot_desc.pool_scaler0_yuv);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler1_rgb, ctx->slot_desc.pool_scaler1_rgb);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler1_yuv, ctx->slot_desc.pool_scaler1_yuv);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler2_rgb, ctx->slot_desc.pool_scaler2_rgb);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler2_yuv, ctx->slot_desc.pool_scaler2_yuv);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler3_rgb, ctx->slot_desc.pool_scaler3_rgb);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_scaler3_yuv, ctx->slot_desc.pool_scaler3_yuv);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_gdc_main, ctx->slot_desc.pool_gdc_main);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_gdc_roi0, ctx->slot_desc.pool_gdc_roi0);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_gdc_roi1, ctx->slot_desc.pool_gdc_roi1);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_gdc_roi2, ctx->slot_desc.pool_gdc_roi2);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_pyramid, ctx->slot_desc.pool_pyramid);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->pool_consistency, ctx->slot_desc.pool_consistency);
+ mali_c720_group_write(mali_c720, slot_addr,
+ &slot->crc, ctx->slot_desc.crc);
+
+ mali_c720_ctx_mgr_set_slot_enabled(ctx, true);
+}
+
+static int mali_c720_ctx_mgr_start_input_port(struct mali_c720 *mali_c720,
+ struct mali_c720_input_cfg *info)
+{
+ const struct mali_c720_cm_input_regs *input = mali_c720->registers.cm->input;
+ u32 input_addr = mali_c720_group_base(&input->group, info->id);
+ u32 val;
+ int ret;
+
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->pixel_size, info->bit_depth);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->data_format, 1);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->nonsecure, 1);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->stream_id, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->data_type1_enable, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->data_type2_enable, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->crop_enable, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->drop_oldest, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->flow_control, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->drop_if_error, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->check_parity, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->buffer_pool, info->pool_id);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->data_type1, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->data_type2, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->start_x, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->start_y, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->size_x, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->size_y, 0);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->write_threshold, 65535);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->write_threshold_sec, 65535);
+
+ mali_c720_ctx_mgr_input_command(mali_c720, input_addr,
+ MALI_C720_INPUT_COMMAND_RESET_COUNTER);
+ mali_c720_ctx_mgr_input_command(mali_c720, input_addr, MALI_C720_INPUT_COMMAND_ENABLE);
+
+ ret = poll_timeout_us(val = mali_c720_group_read(mali_c720, input_addr,
+ &input->status_arch),
+ val == MALI_C720_INPUT_ENABLED,
+ INPUT_POLL_INTERVAL, INPUT_POLL_TIMEOUT, false);
+ if (ret)
+ goto err_timeout;
+
+ info->started = true;
+
+ return 0;
+
+err_timeout:
+ dev_err(mali_c720->dev, "Timed out enabling input %u (state %u)\n", info->id, val);
+ mali_c720_ctx_mgr_input_command(mali_c720, input_addr, MALI_C720_INPUT_COMMAND_CANCEL);
+ mali_c720_ctx_mgr_input_command(mali_c720, input_addr, MALI_C720_INPUT_COMMAND_FLUSH);
+ mali_c720_group_write(mali_c720, input_addr,
+ &input->buffer_pool, 0xff);
+
+ return ret;
+}
+
+static void mali_c720_ctx_mgr_stop_input_port(struct mali_c720 *mali_c720,
+ struct mali_c720_input_cfg *info)
+{
+ const struct mali_c720_cm_buffer_regs *buffer = mali_c720->registers.cm->buffer;
+ const struct mali_c720_cm_input_regs *input = mali_c720->registers.cm->input;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ u32 buffer_addr = mali_c720_group_base(&buffer->raw_group, ctx_mgr->reuse_buffer);
+ u32 input_addr = mali_c720_group_base(&input->group, info->id);
+ u32 val;
+ int ret;
+
+ if (!info->started)
+ return;
+
+ mali_c720_ctx_mgr_input_command(mali_c720, input_addr, MALI_C720_INPUT_COMMAND_DISABLE);
+ ret = poll_timeout_us(val = mali_c720_group_read(mali_c720, input_addr,
+ &input->status_arch),
+ val == MALI_C720_INPUT_DISABLED,
+ INPUT_POLL_INTERVAL, INPUT_POLL_TIMEOUT, false);
+ if (ret) {
+ /* Force the input gate closed if the source does not reach vertical blank. */
+ mali_c720_ctx_mgr_input_command(mali_c720, input_addr,
+ MALI_C720_INPUT_COMMAND_CANCEL);
+ }
+
+ mali_c720_ctx_mgr_input_command(mali_c720, input_addr, MALI_C720_INPUT_COMMAND_FLUSH);
+
+ /*
+ * The following is a workaround for a hardware bug that prevents
+ * safe reuse of raw buffer descriptors. It applies to HW versions
+ * r0p0 and r0p1.
+ */
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
+ MALI_C720_BUFFER_STATE_HW_EMPTY);
+
+ mali_c720_group_write(mali_c720, input_addr, &input->buffer_pool, ctx_mgr->reuse_buffer);
+ mali_c720_ctx_mgr_input_command(mali_c720, input_addr, MALI_C720_INPUT_COMMAND_ENABLE);
+
+ /*
+ * We require the input to fully enable to ensure proper reuse. Enablement
+ * completes once it sees vertical blanking on its source. Upon reaching
+ * this state, the reuse buffer will enter an error state which we will reset
+ * during the buffer cancel operation.
+ */
+ ret = poll_timeout_us(val = mali_c720_group_read(mali_c720, buffer_addr, &buffer->state),
+ val == MALI_C720_BUFFER_STATE_HW_ERROR,
+ INPUT_POLL_INTERVAL, INPUT_POLL_TIMEOUT, false);
+ if (ret)
+ dev_warn(mali_c720->dev,
+ "Input %u descriptor reuse workaround timed out (buffer state %u)\n",
+ info->id, val);
+
+ mali_c720_ctx_mgr_input_command(mali_c720, input_addr, MALI_C720_INPUT_COMMAND_CANCEL);
+ mali_c720_ctx_mgr_input_command(mali_c720, input_addr, MALI_C720_INPUT_COMMAND_FLUSH);
+
+ mali_c720_group_write(mali_c720, input_addr, &input->buffer_pool, 0xff);
+
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
+ MALI_C720_BUFFER_STATE_CANCELLED);
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
+ MALI_C720_BUFFER_STATE_UNINITIALIZED);
+
+ info->started = false;
+}
+
+int mali_c720_ctx_mgr_start_context_inputs(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+
+ lockdep_assert_held(&mali_c720->device_lock);
+
+ return mali_c720_ctx_mgr_start_input_port(mali_c720, &ctx->input_cfg);
+}
+
+void mali_c720_ctx_mgr_stop_context_inputs(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ struct mali_c720_input_cfg *input_cfg = &ctx->input_cfg;
+
+ lockdep_assert_held(&mali_c720->device_lock);
+
+ mali_c720_ctx_mgr_stop_input_port(mali_c720, input_cfg);
+
+ guard(spinlock)(&ctx_mgr->input_lock);
+ guard(spinlock)(&ctx->state_lock);
+
+ ctx_mgr->input_context_map[input_cfg->id] = 0xff;
+ memset(&ctx->input_cfg, 0, sizeof(ctx->input_cfg));
+ ctx->slot_desc.slot_input_0 = 255;
+ ctx->slot_desc.slot_input_1 = 255;
+}
+
+static void mali_c720_ctx_mgr_assign_context_output(struct mali_c720_context *ctx,
+ struct mali_c720_buffer_pool *pool,
+ int enable)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ unsigned int pool_id = enable ? pool->pool_id : 255;
+ u8 *slot_output = NULL;
+
+ switch (pool->sub_type) {
+ case MALI_C720_CAP_DEV_FR0_RGB:
+ slot_output = &ctx->slot_desc.pool_scaler0_rgb;
+ break;
+ case MALI_C720_CAP_DEV_FR0_YUV:
+ slot_output = &ctx->slot_desc.pool_scaler0_yuv;
+ break;
+ default:
+ dev_warn_once(mali_c720->dev,
+ "Invalid output pool subtype %u\n", pool->sub_type);
+ return;
+ }
+
+ if (slot_output && *slot_output != pool_id) {
+ *slot_output = (u8)pool_id;
+ ctx->active_fifos_by_output[pool->sub_type] =
+ enable ? pool->buffer_cfg->num_fifos : 0;
+ ctx->slot_desc_updated = true;
+ }
+}
+
+static void
+mali_c720_ctx_mgr_relinquish_buffer_control(struct mali_c720_context *ctx,
+ struct mali_c720_buffer_pool *pool,
+ unsigned int index)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ u32 buffer_addr = mali_c720_ctx_mgr_buffer_base(regs, pool, index);
+ u32 buffer_state;
+
+ /* Return control of the buffer back to HW */
+ buffer_state = MALI_C720_BUFFER_STATE_HW_EMPTY;
+
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr, buffer_state);
+}
+
+static int mali_c720_ctx_mgr_alloc_buffer_pool(unsigned long *buffers,
+ unsigned int num_buffers,
+ unsigned int num_required)
+{
+ unsigned long start;
+
+ if (num_required == 0 || num_required > num_buffers)
+ return -EINVAL;
+
+ start = bitmap_find_next_zero_area(buffers,
+ num_buffers,
+ 0,
+ num_required,
+ 0);
+
+ if (start >= num_buffers)
+ return -ENOSPC;
+
+ bitmap_set(buffers, (unsigned int)start, num_required);
+
+ return (int)start;
+}
+
+static int
+mali_c720_ctx_mgr_release_buffer_descriptors(struct mali_c720 *mali_c720,
+ struct mali_c720_buffer_pool *pool)
+{
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ unsigned int num_descriptors;
+ unsigned long *descriptors;
+
+ switch (pool->type) {
+ case MALI_C720_BUF_TYPE_RAW:
+ descriptors = ctx_mgr->raw_buffer_descriptors;
+ num_descriptors = ctx_mgr->num_raw_buffer_descriptors;
+ break;
+ case MALI_C720_BUF_TYPE_OUT:
+ descriptors = ctx_mgr->out_buffer_descriptors;
+ num_descriptors = ctx_mgr->num_out_buffer_descriptors;
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ return -EINVAL;
+ }
+
+ if (pool->pool_id >= num_descriptors ||
+ pool->num_buffers > num_descriptors - pool->pool_id) {
+ WARN_ON_ONCE(1);
+ return -EINVAL;
+ }
+
+ bitmap_clear(descriptors, pool->pool_id, pool->num_buffers);
+
+ return 0;
+}
+
+int mali_c720_ctx_mgr_request_buffer_pool(struct mali_c720_context *ctx,
+ const struct mali_c720_buffer_request_info *info,
+ struct mali_c720_buffer_pool *pool)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ const struct mali_c720_buffer_cfg *cfg = info->buffer_cfg;
+ size_t plane_offset[MALI_C720_MAX_BUFFER_PLANES] = {0};
+ u32 buffer_addr, buffer_mode;
+ unsigned int i;
+ int ret;
+
+ lockdep_assert_held(&mali_c720->device_lock);
+
+ switch (info->type) {
+ case MALI_C720_BUF_TYPE_RAW:
+ if (WARN_ONCE(info->num_raw_buffers > ARRAY_SIZE(pool->desc),
+ "Invalid raw buffer count %u\n",
+ info->num_raw_buffers))
+ return -EINVAL;
+
+ ret = mali_c720_ctx_mgr_alloc_buffer_pool(ctx_mgr->raw_buffer_descriptors,
+ ctx_mgr->num_raw_buffer_descriptors,
+ info->num_raw_buffers);
+ if (ret < 0)
+ return ret;
+
+ pool->width = info->width;
+ pool->height = info->height;
+ pool->type = info->type;
+ pool->sub_type = info->sub_type;
+ pool->num_buffers = info->num_raw_buffers;
+ pool->pool_id = (u8)ret;
+
+ buffer_mode = MALI_C720_RAW_BUFFER_MODE_NORMAL;
+
+ break;
+ case MALI_C720_BUF_TYPE_OUT:
+ if (WARN_ONCE(info->num_out_planes > ARRAY_SIZE(plane_offset),
+ "Invalid output plane count %u\n",
+ info->num_out_planes))
+ return -EINVAL;
+
+ ret = mali_c720_ctx_mgr_alloc_buffer_pool(ctx_mgr->out_buffer_descriptors,
+ ctx_mgr->num_out_buffer_descriptors,
+ 1);
+ if (ret < 0)
+ return ret;
+
+ pool->width = info->width;
+ pool->height = info->height;
+ pool->type = info->type;
+ pool->sub_type = info->sub_type;
+ pool->num_buffers = 1;
+ pool->pool_id = (u8)ret;
+
+ buffer_mode = MALI_C720_OUT_BUFFER_MODE_NORMAL;
+
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ return -EINVAL;
+ }
+
+ pool->buffer_size = 0;
+ pool->buffer_cfg = cfg;
+ memset(pool->desc, 0, sizeof(pool->desc));
+
+ if (pool->type == MALI_C720_BUF_TYPE_OUT) {
+ for (i = 0; i < info->num_out_planes; i++) {
+ plane_offset[i] = pool->buffer_size;
+ pool->buffer_size += info->plane_size[i];
+ }
+ } else {
+ pool->buffer_size = info->plane_size[0];
+ }
+
+ for (i = 0; i < pool->num_buffers; i++) {
+ buffer_addr = mali_c720_ctx_mgr_buffer_base(regs, pool, i);
+
+ /* Initialize all buffers under SW control */
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
+ MALI_C720_BUFFER_STATE_SW_EMPTY);
+
+ pool->desc[i].nonsecure = 1;
+ pool->desc[i].stream_id = 0;
+ pool->desc[i].crc_check = 0;
+ pool->desc[i].pool = (i + 1 < pool->num_buffers) ? 1 : 0;
+ pool->desc[i].mode = (u8)buffer_mode;
+ pool->desc[i].block_size = 0;
+ pool->desc[i].buffer_size = (u32)pool->buffer_size;
+ pool->desc[i].plane2_offset = (u32)plane_offset[1];
+ pool->desc[i].plane3_offset = (u32)plane_offset[2];
+ pool->desc[i].plane4_offset = (u32)plane_offset[3];
+ pool->desc[i].line1_offset = (u32)info->line_offset[0];
+ pool->desc[i].line2_offset = (u32)info->line_offset[1];
+ pool->desc[i].line3_offset = (u32)info->line_offset[2];
+ pool->desc[i].line4_offset = (u32)info->line_offset[3];
+ pool->desc[i].data_format = (u8)cfg->data_format;
+ pool->desc[i].data_align = (u8)cfg->data_align;
+ pool->desc[i].data_layout = (u8)cfg->data_layout;
+ pool->desc[i].width = (u16)info->width;
+ pool->desc[i].height = (u16)info->height;
+ pool->desc[i].height_modulo = 0;
+ pool->desc[i].compression = 0;
+ pool->desc[i].compression23 = 0;
+
+ mali_c720_ctx_mgr_write_buffer_desc(ctx, pool, i);
+ }
+
+ return 0;
+}
+
+void mali_c720_ctx_mgr_release_buffer_pool(struct mali_c720_context *ctx,
+ struct mali_c720_buffer_pool *pool)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ u32 buffer_addr;
+ unsigned int i;
+
+ lockdep_assert_held(&mali_c720->device_lock);
+
+ /*
+ * Raw buffers must be explicitly cancelled to return them to SW control
+ * before being unassigned. Output buffers should typically be under SW
+ * control at this point already, but it is safe to cancel them here as well.
+ */
+ for (i = 0; i < pool->num_buffers; i++) {
+ buffer_addr = mali_c720_ctx_mgr_buffer_base(regs, pool, i);
+
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
+ MALI_C720_BUFFER_STATE_CANCELLED);
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
+ MALI_C720_BUFFER_STATE_UNINITIALIZED);
+ }
+
+ mali_c720_ctx_mgr_release_buffer_descriptors(mali_c720, pool);
+}
+
+int mali_c720_ctx_mgr_check_output_buffer_status(struct mali_c720_context *ctx,
+ struct mali_c720_buffer_pool *pool)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ const struct mali_c720_cm_buffer_regs *buffer = regs->cm->buffer;
+ u32 buffer_addr = mali_c720_ctx_mgr_buffer_base(regs, pool, 0);
+ u32 state;
+
+ lockdep_assert_held(&ctx->state_lock);
+
+ if (ctx->state == MALI_C720_SLOT_STATE_STOPPED)
+ return 0;
+
+ state = mali_c720_group_read(mali_c720, buffer_addr, &buffer->state);
+ if (state == MALI_C720_BUFFER_STATE_SW_FULL)
+ return 0;
+
+ dev_warn_ratelimited(mali_c720->dev, "Output buffer %u failed (state %u), recovering\n",
+ pool->pool_id, state);
+
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
+ MALI_C720_BUFFER_STATE_CANCELLED);
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
+ MALI_C720_BUFFER_STATE_SW_EMPTY);
+
+ return -EIO;
+}
+
+void mali_c720_ctx_mgr_update_buffer(struct mali_c720_context *ctx,
+ struct mali_c720_buffer_pool *pool,
+ dma_addr_t *addr,
+ unsigned int index)
+{
+ /*
+ * If we don't have a new address, clear the descriptor and leave it
+ * under SW control to ensure HW cannot write to an invalid address.
+ * For output buffers we will disable that particular output.
+ */
+ if (!addr) {
+ if (WARN_ONCE(pool->type != MALI_C720_BUF_TYPE_OUT,
+ "Cannot clear non-output buffer type %u\n",
+ pool->type))
+ return;
+
+ mali_c720_ctx_mgr_assign_context_output(ctx, pool, 0);
+
+ pool->desc[index].base_address_low = 0;
+ pool->desc[index].base_address_high = 0;
+
+ mali_c720_ctx_mgr_update_buffer_desc(ctx, pool, index);
+
+ return;
+ }
+
+ /* Once the buffer is updated, return control of it to the HW */
+ if (pool->type == MALI_C720_BUF_TYPE_OUT)
+ mali_c720_ctx_mgr_assign_context_output(ctx, pool, 1);
+
+ pool->desc[index].base_address_low = lower_32_bits(*addr);
+ pool->desc[index].base_address_high = upper_32_bits(*addr);
+
+ mali_c720_ctx_mgr_update_buffer_desc(ctx, pool, index);
+ mali_c720_ctx_mgr_relinquish_buffer_control(ctx, pool, index);
+}
+
+void mali_c720_ctx_mgr_prepare_frame(struct mali_c720_context *ctx)
+{
+ lockdep_assert_held(&ctx->state_lock);
+ WARN_ON(ctx->state != MALI_C720_SLOT_STATE_STARTING &&
+ ctx->state != MALI_C720_SLOT_STATE_STARTED);
+
+ if (ctx->state == MALI_C720_SLOT_STATE_STARTING) {
+ mali_c720_ctx_mgr_prepare_output_fifos(ctx);
+ mali_c720_ctx_mgr_write_slot_desc(ctx);
+ mali_c720_ctx_mgr_set_slot_enabled(ctx, true);
+
+ ctx->state = MALI_C720_SLOT_STATE_STARTED;
+ } else if (ctx->slot_desc_updated) {
+ mali_c720_ctx_mgr_prepare_output_fifos(ctx);
+ mali_c720_ctx_mgr_update_slot_desc(ctx);
+ }
+ ctx->slot_desc_updated = false;
+}
+
+void mali_c720_ctx_mgr_buffer_done(struct mali_c720_context *ctx, bool success)
+{
+ lockdep_assert_held(&ctx->state_lock);
+}
+
+void mali_c720_ctx_mgr_handle_sw_ready(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_cdma_slot_regs *cdma_slot = mali_c720->registers.cm->cdma_slot;
+
+ mali_c720_ctx_mgr_cdma_request(mali_c720, mali_c720_group_base(&cdma_slot->group, ctx->id),
+ MALI_C720_SLOT_CDMA_STATE_HW_CONTROL);
+}
+
+void mali_c720_ctx_mgr_configure_context(struct mali_c720_context *ctx,
+ const struct mali_c720_top_cfg *cfg)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ const struct mali_c720_pipeline_regs *pipeline = regs->top->pipeline;
+ dma_addr_t ctx_regs_addr = ctx->regs.dma_handle;
+
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->active_width, cfg->width);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->active_height, cfg->height);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->rggb_start, cfg->rggb_start);
+
+ ctx->cdma_desc.infinite = 0;
+ ctx->cdma_desc.nonsecure = 1;
+ ctx->cdma_desc.stream_id = 0;
+ ctx->cdma_desc.transfer_size = regs->context_size;
+ ctx->cdma_desc.units_low = 0xfff03;
+ ctx->cdma_desc.units_high = 0;
+ ctx->cdma_desc.base_address_low = lower_32_bits(ctx_regs_addr);
+ ctx->cdma_desc.base_address_high = upper_32_bits(ctx_regs_addr);
+ ctx->cdma_desc.ld_sg_count = 0;
+ ctx->cdma_desc.st_sg_count = 0;
+ ctx->cdma_desc.alt_transfer_size = 0;
+ ctx->cdma_desc.alt_base_address_low = 0;
+ ctx->cdma_desc.alt_base_address_high = 0;
+
+ ctx->slot_desc.mode = MALI_C720_SLOT_MODE_DISABLED;
+ ctx->slot_desc.timeout_enable = 0;
+ ctx->slot_desc.schedule_priority = 0;
+ ctx->slot_desc.nonsecure = 1;
+ ctx->slot_desc.stream_id = 0;
+ ctx->slot_desc.delay_mant = 0;
+ ctx->slot_desc.delay_exp = 0;
+ ctx->slot_desc.slot_event = 0;
+ ctx->slot_desc.slot_input_0 = 255;
+ ctx->slot_desc.slot_input_1 = 255;
+ ctx->slot_desc.timeout_mant = 0;
+ ctx->slot_desc.timeout_exp = 0;
+ ctx->slot_desc.pool_roi0 = 255;
+ ctx->slot_desc.pool_roi1 = 255;
+ ctx->slot_desc.pool_roi2 = 255;
+ ctx->slot_desc.pool_raw = 255;
+ ctx->slot_desc.pool_scaler0_rgb = 255;
+ ctx->slot_desc.pool_scaler0_yuv = 255;
+ ctx->slot_desc.pool_scaler1_rgb = 255;
+ ctx->slot_desc.pool_scaler1_yuv = 255;
+ ctx->slot_desc.pool_scaler2_rgb = 255;
+ ctx->slot_desc.pool_scaler2_yuv = 255;
+ ctx->slot_desc.pool_scaler3_rgb = 255;
+ ctx->slot_desc.pool_scaler3_yuv = 255;
+ ctx->slot_desc.pool_gdc_main = 255;
+ ctx->slot_desc.pool_gdc_roi0 = 255;
+ ctx->slot_desc.pool_gdc_roi1 = 255;
+ ctx->slot_desc.pool_gdc_roi2 = 255;
+ ctx->slot_desc.pool_pyramid = 255;
+ ctx->slot_desc.pool_consistency = 255;
+ memset(ctx->active_fifos_by_output, 0, sizeof(ctx->active_fifos_by_output));
+ ctx->slot_desc_updated = false;
+
+ mali_c720_ctx_mgr_write_cdma_desc(ctx);
+}
+
+void mali_c720_ctx_mgr_prepare_context(struct mali_c720_context *ctx,
+ const struct mali_c720_input_cfg *input_cfg)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_cdma_slot_regs *cdma_slot = mali_c720->registers.cm->cdma_slot;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ u32 cdma_slot_addr = mali_c720_group_base(&cdma_slot->group, ctx->id);
+
+ lockdep_assert_held(&mali_c720->device_lock);
+
+ guard(spinlock)(&ctx_mgr->input_lock);
+ guard(spinlock)(&ctx->state_lock);
+
+ memset(ctx->frame_timestamps, 0, sizeof(ctx->frame_timestamps));
+ ctx->input_frame_sequence = 0;
+ ctx->frame_sequence = 0;
+ ctx->timestamp = ktime_get_ns();
+
+ ctx->input_cfg = *input_cfg;
+ ctx->slot_desc.slot_input_0 = (u8)input_cfg->id;
+ ctx->slot_desc.slot_input_1 = 255;
+
+ ctx->input_cfg.started = false;
+ ctx_mgr->input_context_map[input_cfg->id] = (u8)ctx->id;
+
+ ctx->slot_desc.mode = MALI_C720_SLOT_MODE_TDMF_FLEX;
+ ctx->slot_desc_updated = false;
+
+ /* Defer frame scheduling until all video devices are started. */
+ ctx->state = MALI_C720_SLOT_STATE_PREPARED;
+ ctx->pipeline_busy = false;
+
+ if (mali_c720->num_active_contexts++ == 0) {
+ mali_c720_prepare_input_fifos(mali_c720);
+
+ mali_c720_ctx_mgr_set_scheduler_enabled(mali_c720, true);
+ }
+
+ mali_c720_set_slot_interrupt(mali_c720, ctx->id, true);
+ mali_c720_set_frontend_interrupts(ctx, true);
+
+ mali_c720_ctx_mgr_cdma_request(mali_c720, cdma_slot_addr,
+ MALI_C720_SLOT_CDMA_STATE_CANCELLED);
+}
+
+void mali_c720_ctx_mgr_start_context(struct mali_c720_context *ctx)
+{
+ lockdep_assert_held(&ctx->mali_c720->device_lock);
+ lockdep_assert_held(&ctx->state_lock);
+
+ ctx->state = MALI_C720_SLOT_STATE_STARTING;
+}
+
+int mali_c720_ctx_mgr_check_context_status(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_slot_regs *slot = mali_c720->registers.cm->slot;
+ const struct mali_c720_cm_buffer_regs *buffer = mali_c720->registers.cm->buffer;
+ const struct mali_c720_cm_cdma_slot_regs *cdma_slot = mali_c720->registers.cm->cdma_slot;
+ u32 slot_addr = mali_c720_group_base(&slot->group, ctx->id);
+ u32 temper_addr = mali_c720_group_base(&buffer->temper_group, ctx->id);
+ u32 state;
+
+ lockdep_assert_held(&ctx->state_lock);
+
+ state = mali_c720_group_read(mali_c720, slot_addr, &slot->status);
+ if (state == MALI_C720_SLOT_ENABLED)
+ return 0;
+
+ dev_warn_ratelimited(mali_c720->dev, "Slot %u failed (state %u), recovering\n",
+ ctx->id, state);
+
+ /* Slot error state can only be cleared by cancelling the slot. */
+ mali_c720_ctx_mgr_cancel_slot(ctx);
+
+ mali_c720_ctx_mgr_cdma_request(mali_c720, mali_c720_group_base(&cdma_slot->group, ctx->id),
+ MALI_C720_SLOT_CDMA_STATE_CANCELLED);
+
+ if (mali_c720_group_read(mali_c720, temper_addr, &buffer->state) ==
+ MALI_C720_BUFFER_STATE_HW_ERROR) {
+ mali_c720_ctx_mgr_buffer_request(mali_c720, temper_addr,
+ MALI_C720_BUFFER_STATE_CANCELLED);
+ mali_c720_ctx_mgr_buffer_request(mali_c720, temper_addr,
+ MALI_C720_BUFFER_STATE_HW_EMPTY);
+ }
+
+ mali_c720_ctx_mgr_set_slot_enabled(ctx, true);
+
+ /* Recovery prepares the next job; the failed frame must still be returned as an error. */
+ return -EIO;
+}
+
+void mali_c720_ctx_mgr_stop_context(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_cdma_slot_regs *cdma_slot = mali_c720->registers.cm->cdma_slot;
+ u32 cdma_slot_addr = mali_c720_group_base(&cdma_slot->group, ctx->id);
+
+ lockdep_assert_held(&mali_c720->device_lock);
+
+ scoped_guard(spinlock_irq, &ctx->state_lock)
+ ctx->state = MALI_C720_SLOT_STATE_STOPPING;
+
+ mali_c720_ctx_mgr_stop_slot(ctx);
+
+ scoped_guard(spinlock_irq, &ctx->state_lock) {
+ ctx->state = MALI_C720_SLOT_STATE_STOPPED;
+ ctx->pipeline_busy = false;
+
+ mali_c720_ctx_mgr_cdma_request(mali_c720, cdma_slot_addr,
+ MALI_C720_SLOT_CDMA_STATE_DISABLED);
+
+ mali_c720_set_slot_interrupt(mali_c720, ctx->id, false);
+ mali_c720_set_frontend_interrupts(ctx, false);
+
+ if (--mali_c720->num_active_contexts == 0)
+ mali_c720_ctx_mgr_set_scheduler_enabled(mali_c720, false);
+
+ /* Retire in-flight buffers on all queues, including those still streaming. */
+ mali_c720_ctx_mgr_buffer_done(ctx, false);
+
+ ctx->slot_desc.mode = 0;
+ ctx->slot_desc.slot_input_0 = 255;
+ ctx->slot_desc.slot_input_1 = 255;
+ ctx->slot_desc.pool_scaler0_rgb = 255;
+ ctx->slot_desc.pool_scaler0_yuv = 255;
+ ctx->slot_desc.pool_scaler1_rgb = 255;
+ ctx->slot_desc.pool_scaler1_yuv = 255;
+ ctx->slot_desc.pool_scaler2_rgb = 255;
+ ctx->slot_desc.pool_scaler2_yuv = 255;
+ ctx->slot_desc.pool_scaler3_rgb = 255;
+ ctx->slot_desc.pool_scaler3_yuv = 255;
+ ctx->slot_desc.pool_roi0 = 255;
+ ctx->slot_desc.pool_roi1 = 255;
+ ctx->slot_desc.pool_roi2 = 255;
+ ctx->slot_desc.pool_raw = 255;
+ ctx->slot_desc.pool_gdc_main = 255;
+ ctx->slot_desc.pool_gdc_roi0 = 255;
+ ctx->slot_desc.pool_gdc_roi1 = 255;
+ ctx->slot_desc.pool_gdc_roi2 = 255;
+ ctx->slot_desc.pool_pyramid = 255;
+ ctx->slot_desc.pool_consistency = 255;
+ memset(ctx->active_fifos_by_output, 0, sizeof(ctx->active_fifos_by_output));
+ ctx->slot_desc_updated = false;
+ mali_c720_ctx_mgr_write_slot_desc(ctx);
+ }
+
+ /* Drain queued IRQ events before the context can be restarted. */
+ synchronize_irq(mali_c720->irq);
+}
+
+int mali_c720_alloc_context(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ const struct mali_c720_pipeline_regs *pipeline = regs->top->pipeline;
+
+ guard(mutex)(&ctx->regs.allocation_lock);
+
+ if (refcount_inc_not_zero(&ctx->regs.users))
+ return 0;
+
+ ctx->regs.size = regs->context_size;
+ ctx->regs.base = dma_alloc_coherent(mali_c720->dev,
+ ctx->regs.size,
+ &ctx->regs.dma_handle,
+ GFP_KERNEL);
+ if (!ctx->regs.base)
+ return -ENOMEM;
+
+ memcpy(ctx->regs.base,
+ mali_c720->default_regs,
+ ctx->regs.size);
+
+ /*
+ * Provide a default usecase for a reasonable ISP output without
+ * issuing any parameters buffers.
+ */
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_frame_stitch, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_decompander, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_dgain, 0);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_square_root_a, 0);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_dpc, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_remosaic, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_cac, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_temper, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_sinter, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_black_level, 0);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_wb_gain, 0);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_smart_shading, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_raw_to_intensity, 0);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_dehaze, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_dgain_iridix, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_iridix, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_square_a, 0);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_demosaic, 0);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_pf_correction, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_square_b, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_ccm, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_square_root_b, 0);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_cnr, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_fr0_rgb_sharpening, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_fr0_gain_and_offset, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_fr0_gamma, 1);
+
+ /*
+ * Bypass the FR0 crop and scaler by default. The FR0 subdevice
+ * will re-enable these as required.
+ */
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_fr0_rgb_scaler, 1);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_fr0_crop, 1);
+
+ refcount_set(&ctx->regs.users, 1);
+
+ return 0;
+}
+
+void mali_c720_free_context(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+
+ guard(mutex)(&ctx->regs.allocation_lock);
+
+ if (!refcount_dec_and_test(&ctx->regs.users))
+ return;
+
+ dma_free_coherent(mali_c720->dev, ctx->regs.size, ctx->regs.base,
+ ctx->regs.dma_handle);
+ ctx->regs.base = NULL;
+ ctx->regs.dma_handle = 0;
+}
+
+int mali_c720_init_contexts(struct mali_c720 *mali_c720)
+{
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ struct mali_c720_context *ctx;
+
+ /* Allocate a region to store ISP default registers.
+ * These will be copied into each context upon stream start.
+ */
+
+ mali_c720->default_regs = kvzalloc(regs->context_size, GFP_KERNEL);
+ if (!mali_c720->default_regs)
+ return -ENOMEM;
+
+ memcpy_fromio(mali_c720->default_regs,
+ mali_c720->base,
+ regs->context_size);
+
+ ctx = &mali_c720->context;
+ ctx->mali_c720 = mali_c720;
+ ctx->id = 0;
+ ctx->state = MALI_C720_SLOT_STATE_STOPPED;
+
+ spin_lock_init(&ctx->state_lock);
+ spin_lock_init(&ctx->req_lock);
+ mutex_init(&ctx->regs.allocation_lock);
+ ctx->request_sequence = 0;
+ refcount_set(&ctx->regs.users, 0);
+
+ return 0;
+}
+
+static void mali_c720_ctx_mgr_init_reuse_buffer(struct mali_c720 *mali_c720)
+{
+ const struct mali_c720_cm_buffer_regs *buffer = mali_c720->registers.cm->buffer;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ u32 buffer_addr;
+
+ ctx_mgr->reuse_buffer = ctx_mgr->num_raw_buffer_descriptors - 1;
+ __set_bit(ctx_mgr->reuse_buffer, ctx_mgr->raw_buffer_descriptors);
+
+ /*
+ * Keep a standalone, zero-sized descriptor for input cleanup.
+ * This is required for the workaround for a hardware bug on
+ * r0p0 and r0p1 versions.
+ */
+ buffer_addr = mali_c720_group_base(&buffer->raw_group, ctx_mgr->reuse_buffer);
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
+ MALI_C720_BUFFER_STATE_SW_EMPTY);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->nonsecure, 1);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->stream_id, 0);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->crc_check, 0);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->pool, 0);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->mode, MALI_C720_RAW_BUFFER_MODE_NORMAL);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->width, 0);
+ mali_c720_group_write(mali_c720, buffer_addr,
+ &buffer->height, 0);
+ mali_c720_ctx_mgr_buffer_request(mali_c720, buffer_addr,
+ MALI_C720_BUFFER_STATE_UNINITIALIZED);
+}
+
+int mali_c720_init_ctx_mgr(struct mali_c720 *mali_c720)
+{
+ const struct mali_c720_cm_capabilities *caps = mali_c720->registers.cm->caps;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ unsigned int num_slots;
+
+ ctx_mgr->num_raw_buffer_descriptors = caps->num_raw_buffers;
+ ctx_mgr->num_out_buffer_descriptors = caps->num_out_buffers;
+ ctx_mgr->num_inputs = caps->num_inputs;
+ ctx_mgr->num_input_streams = caps->num_input_streams;
+ ctx_mgr->num_virtual_inputs =
+ ctx_mgr->num_inputs * ctx_mgr->num_input_streams;
+ ctx_mgr->input_fifo_size = caps->input_fifo_size;
+ ctx_mgr->output_fifo_size = caps->output_fifo_size;
+
+ if (!ctx_mgr->num_raw_buffer_descriptors) {
+ dev_err(mali_c720->dev, "No raw buffer descriptors available\n");
+ return -EINVAL;
+ }
+
+ if (ctx_mgr->num_raw_buffer_descriptors > MALI_C720_MAX_RAW_BUFFERS) {
+ dev_dbg(mali_c720->dev, "RAW buffer count %u exceeds driver limit, truncating\n",
+ ctx_mgr->num_raw_buffer_descriptors);
+ ctx_mgr->num_raw_buffer_descriptors = MALI_C720_MAX_RAW_BUFFERS;
+ }
+
+ if (!ctx_mgr->num_out_buffer_descriptors) {
+ dev_err(mali_c720->dev, "No output buffer descriptors available\n");
+ return -EINVAL;
+ }
+
+ if (ctx_mgr->num_out_buffer_descriptors > MALI_C720_MAX_OUT_BUFFERS) {
+ dev_dbg(mali_c720->dev, "Output buffer count %u exceeds driver limit, truncating\n",
+ ctx_mgr->num_out_buffer_descriptors);
+ ctx_mgr->num_out_buffer_descriptors = MALI_C720_MAX_OUT_BUFFERS;
+ }
+
+ if (!ctx_mgr->num_inputs) {
+ dev_err(mali_c720->dev, "No input ports available\n");
+ return -EINVAL;
+ }
+
+ if (!ctx_mgr->num_input_streams) {
+ dev_err(mali_c720->dev, "No input streams available\n");
+ return -EINVAL;
+ }
+
+ if (ctx_mgr->num_inputs > MALI_C720_MAX_INPUTS ||
+ ctx_mgr->num_input_streams > MALI_C720_MAX_STREAMS_PER_INPUT ||
+ ctx_mgr->num_virtual_inputs > MALI_C720_MAX_VIRTUAL_INPUTS) {
+ dev_err(mali_c720->dev,
+ "Input topology exceeds driver limits: %u inputs, %u streams per input\n",
+ ctx_mgr->num_inputs, ctx_mgr->num_input_streams);
+ return -EINVAL;
+ }
+
+ num_slots = caps->num_slots;
+ if (num_slots <= MALI_C720_NUM_SAFETY_SLOTS) {
+ dev_err(mali_c720->dev,
+ "No non-safety slots available: %u slots, %u reserved\n",
+ num_slots, MALI_C720_NUM_SAFETY_SLOTS);
+ return -EINVAL;
+ }
+
+ /* Safety slots are not available for video contexts. */
+ ctx_mgr->num_contexts = num_slots - MALI_C720_NUM_SAFETY_SLOTS;
+ if (ctx_mgr->num_contexts > MALI_C720_MAX_CONTEXTS) {
+ dev_err(mali_c720->dev,
+ "Non-safety slot count %u exceeds driver limit %u\n",
+ ctx_mgr->num_contexts, MALI_C720_MAX_CONTEXTS);
+ return -EINVAL;
+ }
+
+ bitmap_zero(ctx_mgr->raw_buffer_descriptors, ctx_mgr->num_raw_buffer_descriptors);
+ bitmap_zero(ctx_mgr->out_buffer_descriptors, ctx_mgr->num_out_buffer_descriptors);
+
+ mali_c720_ctx_mgr_init_reuse_buffer(mali_c720);
+
+ spin_lock_init(&ctx_mgr->input_lock);
+ memset(ctx_mgr->input_context_map, 0xff, sizeof(ctx_mgr->input_context_map));
+
+ return 0;
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.h b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.h
new file mode 100644
index 0000000000000000000000000000000000000000..d5af820cc5527523dd42f00e849466b71871fa8b
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.h
@@ -0,0 +1,303 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_CTX_MGR_H
+#define MALI_C720_CTX_MGR_H
+
+#include <linux/bitops.h>
+#include <linux/spinlock.h>
+#include <linux/types.h>
+
+struct mali_c720;
+struct mali_c720_buffer_cfg;
+struct mali_c720_context;
+
+#define MALI_C720_MAX_BUFFER_POOL_SIZE 2
+#define MALI_C720_MAX_RAW_BUFFERS 64
+#define MALI_C720_MAX_OUT_BUFFERS 208
+#define MALI_C720_MAX_BUFFER_PLANES 4
+#define MALI_C720_MAX_INPUTS 4
+#define MALI_C720_MAX_STREAMS_PER_INPUT 4
+#define MALI_C720_MAX_VIRTUAL_INPUTS (MALI_C720_MAX_INPUTS * MALI_C720_MAX_STREAMS_PER_INPUT)
+#define MALI_C720_MAX_CONTEXTS 16
+#define MALI_C720_NUM_SAFETY_SLOTS 4
+
+enum mali_c720_input_command {
+ MALI_C720_INPUT_COMMAND_DISABLE = 1,
+ MALI_C720_INPUT_COMMAND_ENABLE,
+ MALI_C720_INPUT_COMMAND_CANCEL,
+ MALI_C720_INPUT_COMMAND_FLUSH,
+ MALI_C720_INPUT_COMMAND_RESET_COUNTER,
+};
+
+enum mali_c720_input_state {
+ MALI_C720_INPUT_DISABLED = 1,
+ MALI_C720_INPUT_ENABLED,
+ MALI_C720_INPUT_CANCELLING,
+ MALI_C720_INPUT_DISABLING = 5,
+ MALI_C720_INPUT_ENABLING = 6,
+};
+
+enum mali_c720_scheduler_command_ids {
+ MALI_C720_SCH_COMMAND_ENABLE = 0x1,
+ MALI_C720_SCH_COMMAND_DISABLE,
+ MALI_C720_SCH_COMMAND_CANCEL,
+ MALI_C720_SCH_COMMAND_BYPASS_SLOT,
+ MALI_C720_SCH_COMMAND_ENABLE_SLOT,
+ MALI_C720_SCH_COMMAND_DISABLE_SLOT,
+ MALI_C720_SCH_COMMAND_CANCEL_SLOT,
+};
+
+enum mali_c720_slot_state {
+ MALI_C720_SLOT_STATE_PREPARED,
+ MALI_C720_SLOT_STATE_STARTING,
+ MALI_C720_SLOT_STATE_STARTED,
+ MALI_C720_SLOT_STATE_STOPPING,
+ MALI_C720_SLOT_STATE_STOPPED,
+};
+
+enum mali_c720_slot_status {
+ MALI_C720_SLOT_DISABLED,
+ MALI_C720_SLOT_ENABLED,
+ MALI_C720_SLOT_CANCELLING,
+ MALI_C720_SLOT_BYPASSED,
+ MALI_C720_SLOT_ERROR,
+ MALI_C720_SLOT_DISABLING,
+};
+
+enum mali_c720_slot_mode {
+ MALI_C720_SLOT_MODE_DISABLED,
+ MALI_C720_SLOT_MODE_STREAMING,
+ MALI_C720_SLOT_MODE_TDMF_FLEX,
+ MALI_C720_SLOT_MODE_TDMF_FIX,
+ MALI_C720_SLOT_MODE_M2M,
+};
+
+enum mali_c720_slot_cdma_state {
+ MALI_C720_SLOT_CDMA_STATE_DISABLED,
+ MALI_C720_SLOT_CDMA_STATE_CANCELLED,
+ MALI_C720_SLOT_CDMA_STATE_SW_CONTROL,
+ MALI_C720_SLOT_CDMA_STATE_HW_CONTROL,
+};
+
+enum mali_c720_buffer_type_ids {
+ MALI_C720_BUF_TYPE_RAW,
+ MALI_C720_BUF_TYPE_OUT,
+ MALI_C720_BUF_NUM_TYPES,
+};
+
+enum mali_c720_buffer_state {
+ MALI_C720_BUFFER_STATE_UNINITIALIZED,
+ MALI_C720_BUFFER_STATE_CANCELLED,
+ MALI_C720_BUFFER_STATE_SW_EMPTY,
+ MALI_C720_BUFFER_STATE_SW_FULL,
+ MALI_C720_BUFFER_STATE_HW_EMPTY,
+ MALI_C720_BUFFER_STATE_HW_FULL,
+ MALI_C720_BUFFER_STATE_HW_ERROR,
+ MALI_C720_BUFFER_STATE_CANCELLING,
+ MALI_C720_BUFFER_STATE_HW_WRITING,
+ MALI_C720_BUFFER_STATE_HW_READING,
+ MALI_C720_BUFFER_STATE_HW_READING_WRITING,
+};
+
+enum mali_c720_raw_buffer_subtype {
+ MALI_C720_RAW_BUF_SUBTYPE_NORMAL,
+};
+
+enum mali_c720_raw_buffer_mode {
+ MALI_C720_RAW_BUFFER_MODE_NORMAL,
+ MALI_C720_RAW_BUFFER_MODE_INFINITE,
+ MALI_C720_RAW_BUFFER_MODE_SOFTWARE,
+ MALI_C720_RAW_BUFFER_MODE_HW_CLONED,
+ MALI_C720_RAW_BUFFER_MODE_SW_CLONED,
+};
+
+enum mali_c720_out_buffer_mode {
+ MALI_C720_OUT_BUFFER_MODE_NORMAL,
+ MALI_C720_OUT_BUFFER_MODE_INFINITE,
+};
+
+struct mali_c720_input_cfg {
+ unsigned int id;
+ unsigned int pool_id;
+ unsigned int bit_depth;
+ bool started;
+};
+
+struct mali_c720_top_cfg {
+ u32 width;
+ u32 height;
+ u32 rggb_start;
+};
+
+struct mali_c720_slot_desc {
+ u16 crc;
+ u8 mode;
+ u8 timeout_enable;
+ u8 schedule_priority;
+ u8 nonsecure;
+ u8 stream_id;
+ u16 delay_mant;
+ u8 delay_exp;
+ u8 slot_event;
+ u8 slot_input_0;
+ u8 slot_input_1;
+ u16 timeout_mant;
+ u8 timeout_exp;
+ u8 pool_roi0;
+ u8 pool_roi1;
+ u8 pool_roi2;
+ u8 pool_raw;
+ u8 pool_scaler0_rgb;
+ u8 pool_scaler0_yuv;
+ u8 pool_scaler1_rgb;
+ u8 pool_scaler1_yuv;
+ u8 pool_scaler2_rgb;
+ u8 pool_scaler2_yuv;
+ u8 pool_scaler3_rgb;
+ u8 pool_scaler3_yuv;
+ u8 pool_gdc_main;
+ u8 pool_gdc_roi0;
+ u8 pool_gdc_roi1;
+ u8 pool_gdc_roi2;
+ u8 pool_pyramid;
+ u8 pool_consistency;
+};
+
+struct mali_c720_cdma_desc {
+ u16 crc;
+ u8 infinite;
+ u8 nonsecure;
+ u8 stream_id;
+ u32 transfer_size;
+ u32 units_low;
+ u32 units_high;
+ u32 base_address_low;
+ u32 base_address_high;
+ u8 ld_sg_count;
+ u8 st_sg_count;
+ u32 alt_transfer_size;
+ u32 alt_base_address_low;
+ u32 alt_base_address_high;
+};
+
+struct mali_c720_buffer_desc {
+ u16 crc;
+ u8 data_format;
+ u8 data_align;
+ u8 nonsecure;
+ u8 stream_id;
+ u8 data_layout;
+ u8 crc_check;
+ u8 pool;
+ u8 mode;
+ u8 block_size;
+ u32 base_address_low;
+ u32 base_address_high;
+ u32 buffer_size;
+ u32 plane2_offset;
+ u32 plane3_offset;
+ u32 plane4_offset;
+ u32 line1_offset;
+ u32 line2_offset;
+ u32 line3_offset;
+ u32 line4_offset;
+ u16 width;
+ u16 height;
+ u8 colorspace;
+ u8 subsampling;
+ u8 component_width;
+ u8 msb_align;
+ u8 phase;
+ u16 height_modulo;
+ u32 compression;
+ u32 compression23;
+};
+
+struct mali_c720_buffer_request_info {
+ const struct mali_c720_buffer_cfg *buffer_cfg;
+ size_t plane_size[MALI_C720_MAX_BUFFER_PLANES];
+ unsigned int line_offset[MALI_C720_MAX_BUFFER_PLANES];
+ unsigned int width;
+ unsigned int height;
+ unsigned int type;
+ unsigned int sub_type;
+ unsigned int num_out_planes;
+ unsigned int num_raw_buffers;
+};
+
+struct mali_c720_buffer_pool {
+ struct {
+ dma_addr_t addr;
+ void *base;
+ } mem[MALI_C720_MAX_BUFFER_POOL_SIZE];
+ struct mali_c720_buffer_desc desc[MALI_C720_MAX_BUFFER_POOL_SIZE];
+ const struct mali_c720_buffer_cfg *buffer_cfg;
+
+ unsigned int width;
+ unsigned int height;
+ unsigned int type;
+ unsigned int sub_type;
+ unsigned int pool_id;
+ unsigned int num_buffers;
+ size_t buffer_size;
+};
+
+struct mali_c720_ctx_mgr {
+ /* Protects input_context_map; acquire before a context's state_lock. */
+ spinlock_t input_lock;
+ u8 input_context_map[MALI_C720_MAX_VIRTUAL_INPUTS];
+ unsigned long raw_buffer_descriptors[BITS_TO_LONGS(MALI_C720_MAX_RAW_BUFFERS)];
+ unsigned long out_buffer_descriptors[BITS_TO_LONGS(MALI_C720_MAX_OUT_BUFFERS)];
+ unsigned int num_raw_buffer_descriptors;
+ unsigned int reuse_buffer;
+ unsigned int num_out_buffer_descriptors;
+ unsigned int num_inputs;
+ unsigned int num_input_streams;
+ unsigned int num_virtual_inputs;
+ unsigned int num_contexts;
+ unsigned int input_fifo_size;
+ unsigned int output_fifo_size;
+};
+
+struct mali_c720_context *mali_c720_get_active_context(struct mali_c720 *mali_c720);
+
+int mali_c720_init_contexts(struct mali_c720 *mali_c720);
+int mali_c720_alloc_context(struct mali_c720_context *ctx);
+void mali_c720_free_context(struct mali_c720_context *ctx);
+
+int mali_c720_init_ctx_mgr(struct mali_c720 *mali_c720);
+
+int mali_c720_ctx_mgr_start_context_inputs(struct mali_c720_context *ctx);
+void mali_c720_ctx_mgr_stop_context_inputs(struct mali_c720_context *ctx);
+
+int mali_c720_ctx_mgr_request_buffer_pool(struct mali_c720_context *ctx,
+ const struct mali_c720_buffer_request_info *info,
+ struct mali_c720_buffer_pool *pool);
+void mali_c720_ctx_mgr_release_buffer_pool(struct mali_c720_context *ctx,
+ struct mali_c720_buffer_pool *pool);
+int mali_c720_ctx_mgr_check_output_buffer_status(struct mali_c720_context *ctx,
+ struct mali_c720_buffer_pool *pool);
+
+void mali_c720_ctx_mgr_update_buffer(struct mali_c720_context *ctx,
+ struct mali_c720_buffer_pool *pool,
+ dma_addr_t *addr,
+ unsigned int index);
+
+void mali_c720_ctx_mgr_configure_context(struct mali_c720_context *ctx,
+ const struct mali_c720_top_cfg *cfg);
+void mali_c720_ctx_mgr_prepare_context(struct mali_c720_context *ctx,
+ const struct mali_c720_input_cfg *input_cfg);
+void mali_c720_ctx_mgr_start_context(struct mali_c720_context *ctx);
+void mali_c720_ctx_mgr_stop_context(struct mali_c720_context *ctx);
+int mali_c720_ctx_mgr_check_context_status(struct mali_c720_context *ctx);
+
+void mali_c720_ctx_mgr_prepare_frame(struct mali_c720_context *ctx);
+void mali_c720_ctx_mgr_buffer_done(struct mali_c720_context *ctx, bool success);
+void mali_c720_ctx_mgr_handle_sw_ready(struct mali_c720_context *ctx);
+
+#endif /* MALI_C720_CTX_MGR_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c b/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
new file mode 100644
index 0000000000000000000000000000000000000000..63589989478650f65c3cc06bee0a48a53b92b051
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
@@ -0,0 +1,432 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/cleanup.h>
+#include <linux/device.h>
+#include <linux/timekeeping.h>
+
+#include "mali-c720-common.h"
+
+static void mali_c720_isr_set_frontend_bits(struct mali_c720 *mali_c720,
+ struct mali_c720_interrupt_data *irq_data)
+{
+ const struct mali_c720_irq_regs *irq = mali_c720->registers.top->irq;
+ const struct mali_c720_reg_field * const
+ fields[MALI_C720_MAX_INPUTS][MALI_C720_MAX_STREAMS_PER_INPUT] = {
+ {
+ &irq->cm_input_0_stream_0_cmsi_active_video,
+ &irq->cm_input_0_stream_1_cmsi_active_video,
+ &irq->cm_input_0_stream_2_cmsi_active_video,
+ &irq->cm_input_0_stream_3_cmsi_active_video,
+ },
+ {
+ &irq->cm_input_1_stream_0_cmsi_active_video,
+ &irq->cm_input_1_stream_1_cmsi_active_video,
+ &irq->cm_input_1_stream_2_cmsi_active_video,
+ &irq->cm_input_1_stream_3_cmsi_active_video,
+ },
+ {
+ &irq->cm_input_2_stream_0_cmsi_active_video,
+ &irq->cm_input_2_stream_1_cmsi_active_video,
+ &irq->cm_input_2_stream_2_cmsi_active_video,
+ &irq->cm_input_2_stream_3_cmsi_active_video,
+ },
+ {
+ &irq->cm_input_3_stream_0_cmsi_active_video,
+ &irq->cm_input_3_stream_1_cmsi_active_video,
+ &irq->cm_input_3_stream_2_cmsi_active_video,
+ &irq->cm_input_3_stream_3_cmsi_active_video,
+ },
+ };
+ unsigned int num_streams = mali_c720->ctx_mgr.num_input_streams;
+ unsigned int virtual_input_id;
+
+ /* Virtual input ID = physical input * num_streams + stream. */
+ for (virtual_input_id = 0; virtual_input_id < mali_c720->ctx_mgr.num_virtual_inputs;
+ virtual_input_id++) {
+ unsigned int input = virtual_input_id / num_streams;
+ unsigned int stream = virtual_input_id % num_streams;
+ const struct mali_c720_reg_field *field = fields[input][stream];
+
+ if (!mali_c720_irq_read(mali_c720, field, MALI_C720_IRQ_STATUS))
+ continue;
+
+ set_bit(virtual_input_id, &irq_data->input_frame_start);
+ mali_c720_irq_write(mali_c720, field, MALI_C720_IRQ_RAWSTAT, 1);
+ }
+}
+
+static void mali_c720_isr_set_backend_bits(struct mali_c720 *mali_c720,
+ struct mali_c720_interrupt_data *irq_data)
+{
+ const struct mali_c720_irq_regs *irq = mali_c720->registers.top->irq;
+ const struct mali_c720_reg_field * const fields[MALI_C720_MAX_CONTEXTS] = {
+ &irq->cm_status_slot_0,
+ &irq->cm_status_slot_1,
+ &irq->cm_status_slot_2,
+ &irq->cm_status_slot_3,
+ &irq->cm_status_slot_4,
+ &irq->cm_status_slot_5,
+ &irq->cm_status_slot_6,
+ &irq->cm_status_slot_7,
+ &irq->cm_status_slot_8,
+ &irq->cm_status_slot_9,
+ &irq->cm_status_slot_10,
+ &irq->cm_status_slot_11,
+ &irq->cm_status_slot_12,
+ &irq->cm_status_slot_13,
+ &irq->cm_status_slot_14,
+ &irq->cm_status_slot_15,
+ };
+ unsigned int slot;
+
+ for (slot = 0; slot < mali_c720->ctx_mgr.num_contexts; slot++) {
+ if (!mali_c720_irq_read(mali_c720, fields[slot], MALI_C720_IRQ_STATUS))
+ continue;
+
+ set_bit(slot, &irq_data->frame_end);
+ mali_c720_irq_write(mali_c720, fields[slot], MALI_C720_IRQ_RAWSTAT, 1);
+ }
+}
+
+irqreturn_t mali_c720_isr_top(int irq, void *dev_id)
+{
+ struct device *dev = dev_id;
+ struct mali_c720 *mali_c720 = dev_get_drvdata(dev);
+ struct mali_c720_interrupt_data irq_data = {
+ .timestamp = ktime_get_ns(),
+ };
+
+ mali_c720_isr_set_frontend_bits(mali_c720, &irq_data);
+
+ /* Preserve all slots which completed before the interrupt was serviced. */
+ mali_c720_isr_set_backend_bits(mali_c720, &irq_data);
+
+ if (!irq_data.input_frame_start && !irq_data.frame_end)
+ return IRQ_NONE;
+
+ if (!kfifo_in_spinlocked(&mali_c720->irq_fifo, &irq_data, 1,
+ &mali_c720->irq_lock))
+ dev_err_ratelimited(mali_c720->dev, "IRQ FIFO overflow\n");
+
+ return IRQ_WAKE_THREAD;
+}
+
+static void mali_c720_handle_input_frame_start(struct mali_c720 *mali_c720,
+ unsigned int virtual_input_id,
+ u64 timestamp)
+{
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ const struct mali_c720_input_cfg *input_cfg = &ctx->input_cfg;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ struct mali_c720_frame_timestamp *entry;
+ unsigned int ctx_id;
+ u32 sequence;
+
+ guard(spinlock)(&ctx_mgr->input_lock);
+
+ ctx_id = ctx_mgr->input_context_map[virtual_input_id];
+ if (ctx_id == 0xFF)
+ return;
+
+ /* Only context 0 is currently supported. */
+ if (WARN_ON_ONCE(ctx_id != ctx->id))
+ return;
+
+ guard(spinlock)(&ctx->state_lock);
+
+ if (ctx->state == MALI_C720_SLOT_STATE_STOPPING ||
+ ctx->state == MALI_C720_SLOT_STATE_STOPPED)
+ return;
+
+ if (input_cfg->id != virtual_input_id) {
+ dev_err(mali_c720->dev,
+ "Received unexpected frame start for virtual input %u, expected %u\n",
+ virtual_input_id, input_cfg->id);
+ return;
+ }
+
+ sequence = ctx->input_frame_sequence++;
+
+ entry = &ctx->frame_timestamps[sequence % MALI_C720_FRAME_TIMESTAMP_COUNT];
+ entry->sequence = sequence;
+ entry->timestamp = timestamp;
+ entry->valid = true;
+}
+
+static void mali_c720_update_frame_timestamp(struct mali_c720_context *ctx)
+{
+ const struct mali_c720_frame_timestamp *entry =
+ &ctx->frame_timestamps[ctx->frame_sequence % MALI_C720_FRAME_TIMESTAMP_COUNT];
+
+ if (entry->valid && entry->sequence == ctx->frame_sequence) {
+ ctx->timestamp = entry->timestamp;
+ } else {
+ dev_warn_ratelimited(ctx->mali_c720->dev,
+ "Missing frontend timestamp for frame %u\n",
+ ctx->frame_sequence);
+ }
+}
+
+static void mali_c720_handle_frame_end(struct mali_c720 *mali_c720,
+ unsigned int ctx_id)
+{
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ int ret;
+
+ /* Only context 0 is currently supported. */
+ if (WARN_ON_ONCE(ctx_id != 0))
+ return;
+
+ scoped_guard(spinlock, &ctx->state_lock) {
+ if (ctx->state != MALI_C720_SLOT_STATE_STARTED)
+ return;
+
+ ret = mali_c720_ctx_mgr_check_context_status(ctx);
+ if (!ret) {
+ ctx->frame_sequence =
+ mali_c720_ctx_group_read(ctx, mali_c720->top_base,
+ &pipeline->frame_count) - 1;
+
+ mali_c720_update_frame_timestamp(ctx);
+ }
+
+ mali_c720_ctx_mgr_buffer_done(ctx, !ret);
+
+ ctx->pipeline_busy = false;
+ }
+}
+
+irqreturn_t mali_c720_isr(int irq, void *dev_id)
+{
+ struct device *dev = dev_id;
+ struct mali_c720 *mali_c720 = dev_get_drvdata(dev);
+ struct mali_c720_interrupt_data irq_data;
+ unsigned int bit;
+
+ while (kfifo_out_spinlocked(&mali_c720->irq_fifo, &irq_data, 1,
+ &mali_c720->irq_lock)) {
+ for_each_set_bit(bit, &irq_data.input_frame_start,
+ mali_c720->ctx_mgr.num_virtual_inputs)
+ mali_c720_handle_input_frame_start(mali_c720, bit, irq_data.timestamp);
+
+ for_each_set_bit(bit, &irq_data.frame_end, MALI_C720_MAX_CONTEXTS)
+ mali_c720_handle_frame_end(mali_c720, bit);
+ }
+
+ return IRQ_HANDLED;
+}
+
+static void mali_c720_set_input_interrupt(struct mali_c720 *mali_c720,
+ unsigned int virtual_input_id, bool enable)
+{
+ const struct mali_c720_irq_regs *irq = mali_c720->registers.top->irq;
+ unsigned int input = virtual_input_id / mali_c720->ctx_mgr.num_input_streams;
+ unsigned int stream = virtual_input_id % mali_c720->ctx_mgr.num_input_streams;
+
+ /*
+ * When enabling an interrupt, we should clear any pending interrupts
+ * before enabling the mask.
+ * When disabling an interrupt, we should disable the mask, then
+ * clear any pending interrupts.
+ * Interrupts are cleared by writing a 1 to the RAWSTAT bit.
+ */
+ enum mali_c720_irq_type type0 = enable ? MALI_C720_IRQ_RAWSTAT : MALI_C720_IRQ_MASK;
+ enum mali_c720_irq_type type1 = enable ? MALI_C720_IRQ_MASK : MALI_C720_IRQ_RAWSTAT;
+
+ switch (input * MALI_C720_MAX_STREAMS_PER_INPUT + stream) {
+ case 0:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_0_stream_0_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_0_stream_0_cmsi_active_video, type1,
+ 1);
+ break;
+ case 1:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_0_stream_1_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_0_stream_1_cmsi_active_video, type1,
+ 1);
+ break;
+ case 2:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_0_stream_2_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_0_stream_2_cmsi_active_video, type1,
+ 1);
+ break;
+ case 3:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_0_stream_3_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_0_stream_3_cmsi_active_video, type1,
+ 1);
+ break;
+ case 4:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_1_stream_0_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_1_stream_0_cmsi_active_video, type1,
+ 1);
+ break;
+ case 5:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_1_stream_1_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_1_stream_1_cmsi_active_video, type1,
+ 1);
+ break;
+ case 6:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_1_stream_2_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_1_stream_2_cmsi_active_video, type1,
+ 1);
+ break;
+ case 7:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_1_stream_3_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_1_stream_3_cmsi_active_video, type1,
+ 1);
+ break;
+ case 8:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_2_stream_0_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_2_stream_0_cmsi_active_video, type1,
+ 1);
+ break;
+ case 9:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_2_stream_1_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_2_stream_1_cmsi_active_video, type1,
+ 1);
+ break;
+ case 10:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_2_stream_2_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_2_stream_2_cmsi_active_video, type1,
+ 1);
+ break;
+ case 11:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_2_stream_3_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_2_stream_3_cmsi_active_video, type1,
+ 1);
+ break;
+ case 12:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_3_stream_0_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_3_stream_0_cmsi_active_video, type1,
+ 1);
+ break;
+ case 13:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_3_stream_1_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_3_stream_1_cmsi_active_video, type1,
+ 1);
+ break;
+ case 14:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_3_stream_2_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_3_stream_2_cmsi_active_video, type1,
+ 1);
+ break;
+ case 15:
+ mali_c720_irq_write(mali_c720, &irq->cm_input_3_stream_3_cmsi_active_video, type0,
+ enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_input_3_stream_3_cmsi_active_video, type1,
+ 1);
+ break;
+ default:
+ dev_warn_once(mali_c720->dev,
+ "Invalid virtual input interrupt id %u\n",
+ virtual_input_id);
+ return;
+ }
+}
+
+void mali_c720_set_slot_interrupt(struct mali_c720 *mali_c720,
+ unsigned int slot_id, bool enable)
+{
+ const struct mali_c720_irq_regs *irq = mali_c720->registers.top->irq;
+ enum mali_c720_irq_type type0 = enable ? MALI_C720_IRQ_RAWSTAT : MALI_C720_IRQ_MASK;
+ enum mali_c720_irq_type type1 = enable ? MALI_C720_IRQ_MASK : MALI_C720_IRQ_RAWSTAT;
+
+ switch (slot_id) {
+ case 0:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_0, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_0, type1, 1);
+ break;
+ case 1:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_1, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_1, type1, 1);
+ break;
+ case 2:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_2, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_2, type1, 1);
+ break;
+ case 3:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_3, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_3, type1, 1);
+ break;
+ case 4:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_4, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_4, type1, 1);
+ break;
+ case 5:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_5, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_5, type1, 1);
+ break;
+ case 6:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_6, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_6, type1, 1);
+ break;
+ case 7:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_7, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_7, type1, 1);
+ break;
+ case 8:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_8, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_8, type1, 1);
+ break;
+ case 9:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_9, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_9, type1, 1);
+ break;
+ case 10:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_10, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_10, type1, 1);
+ break;
+ case 11:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_11, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_11, type1, 1);
+ break;
+ case 12:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_12, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_12, type1, 1);
+ break;
+ case 13:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_13, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_13, type1, 1);
+ break;
+ case 14:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_14, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_14, type1, 1);
+ break;
+ case 15:
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_15, type0, enable);
+ mali_c720_irq_write(mali_c720, &irq->cm_status_slot_15, type1, 1);
+ break;
+ default:
+ dev_warn_once(mali_c720->dev,
+ "Invalid slot interrupt id %u\n", slot_id);
+ return;
+ }
+}
+
+void mali_c720_set_frontend_interrupts(struct mali_c720_context *ctx, bool enable)
+{
+ const struct mali_c720_input_cfg *input_cfg = &ctx->input_cfg;
+
+ mali_c720_set_input_interrupt(ctx->mali_c720, input_cfg->id,
+ enable);
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.h b/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.h
new file mode 100644
index 0000000000000000000000000000000000000000..5d1b14c3e897768fd49d05b193b926e0bb71afd0
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef MALI_C720_INTERRUPTS_H
+#define MALI_C720_INTERRUPTS_H
+
+#include <linux/interrupt.h>
+#include <linux/types.h>
+
+struct mali_c720;
+struct mali_c720_context;
+
+#define MALI_C720_IRQ_FIFO_SIZE 256
+
+struct mali_c720_interrupt_data {
+ u64 timestamp;
+
+ unsigned long input_frame_start;
+
+ unsigned long frame_end;
+};
+
+irqreturn_t mali_c720_isr_top(int irq, void *dev_id);
+irqreturn_t mali_c720_isr(int irq, void *dev_id);
+
+void mali_c720_set_slot_interrupt(struct mali_c720 *mali_c720,
+ unsigned int slot_id, bool enable);
+void mali_c720_set_frontend_interrupts(struct mali_c720_context *ctx, bool enable);
+
+#endif /* MALI_C720_INTERRUPTS_H */
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 09/24] media: mali-c720: Add input frontend subdevice
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (7 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 08/24] media: mali-c720: Add context manager and interrupt handling Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 10/24] media: mali-c720: Add ISP and human vision subdevices Anthony McGivern
` (14 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add the subdevice connecting parallel input port 0 to a single context
input through a fixed route. Support for the remaining inputs is planned
when userspace routing ioctls are enabled.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../platform/arm/mali-c720/mali-c720-common.h | 49 ++
.../media/platform/arm/mali-c720/mali-c720-input.c | 598 +++++++++++++++++++++
2 files changed, 647 insertions(+)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 1808fdef149f8035394af122b348232be1ff51dd..6f5ddb94398d76888edb992000a4d6012e960675 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -15,6 +15,9 @@
#include <linux/spinlock.h>
#include <linux/videodev2.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-subdev.h>
+
#include "mali-c720-ctx-mgr.h"
#include "mali-c720-discovery.h"
#include "mali-c720-formats.h"
@@ -26,8 +29,46 @@
#include "mali-c720-registers-ctx-mgr.h"
#include "mali-c720-registers-modules.h"
+#define MALI_C720_MIN_INPUT_WIDTH 256
+#define MALI_C720_MIN_INPUT_HEIGHT 256
+#define MALI_C720_MAX_WIDTH 8192
+#define MALI_C720_MAX_HEIGHT 4608
+#define MALI_C720_DEFAULT_WIDTH 1920
+#define MALI_C720_DEFAULT_HEIGHT 1080
+
#define MALI_C720_FRAME_TIMESTAMP_COUNT 256
+struct mali_c720_subdev {
+ struct v4l2_subdev sd;
+ struct mali_c720 *mali_c720;
+};
+
+#define v4l2_sd_to_mali_c720_sd(_sd) \
+ container_of(_sd, struct mali_c720_subdev, sd)
+
+#define mali_c720_sd_to_sd(_mdev, type) \
+ container_of(_mdev, type, mdev)
+
+enum mali_c720_input_pads {
+ MALI_C720_INPUT_PAD_SOURCE_SLOT_INPUT,
+ MALI_C720_INPUT_PAD_SINK_INPUT0,
+ MALI_C720_INPUT_NUM_PADS,
+};
+
+struct mali_c720_slot_input {
+ struct mali_c720_buffer_pool raw_buffer_desc;
+ struct media_pad *sink_pad;
+ struct media_pad *src_pad;
+ u32 stream;
+ bool prepared;
+};
+
+struct mali_c720_input {
+ struct mali_c720_subdev mdev;
+ struct media_pad pads[MALI_C720_INPUT_NUM_PADS];
+ struct mali_c720_slot_input slot_input;
+};
+
enum mali_c720_cap_devs {
MALI_C720_CAP_DEV_FR0_RGB,
MALI_C720_CAP_DEV_FR0_YUV,
@@ -82,6 +123,10 @@ struct mali_c720 {
resource_size_t mmio_size;
u32 top_base;
+ struct v4l2_device v4l2_dev;
+
+ struct mali_c720_input input;
+
struct mali_c720_registers registers;
u8 *default_regs;
@@ -100,4 +145,8 @@ struct mali_c720 {
spinlock_t irq_lock;
};
+int mali_c720_register_input(struct mali_c720 *mali_c720);
+void mali_c720_unregister_input(struct mali_c720 *mali_c720);
+void mali_c720_cleanup_input(struct mali_c720 *mali_c720);
+
#endif /* MALI_C720_COMMON_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-input.c b/drivers/media/platform/arm/mali-c720/mali-c720-input.c
new file mode 100644
index 0000000000000000000000000000000000000000..b0b92e456d9b2b386c7d2c4473cb3ccdb4b819a9
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-input.c
@@ -0,0 +1,598 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/bitops.h>
+#include <linux/dma-mapping.h>
+#include <linux/minmax.h>
+#include <linux/string.h>
+
+#include <media/media-entity.h>
+#include <media/v4l2-common.h>
+
+#include "mali-c720-common.h"
+
+/*
+ * Return the active route for the provided sink pad and stream, or NULL if
+ * there is none.
+ */
+static struct v4l2_subdev_route *
+mali_c720_input_get_active_route(struct v4l2_subdev_state *state,
+ u32 sink_pad, u32 sink_stream)
+{
+ struct v4l2_subdev_krouting *routing = &state->routing;
+ struct v4l2_subdev_route *route;
+
+ for_each_active_route(routing, route) {
+ if (route->sink_pad == sink_pad &&
+ route->sink_stream == sink_stream)
+ return route;
+ }
+
+ return NULL;
+}
+
+static int mali_c720_input_enum_mbus_code(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_mbus_code_enum *code)
+{
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_mbus_format_match match;
+ struct v4l2_mbus_framefmt *sink_fmt;
+ struct v4l2_subdev_route *route;
+ bool found = false;
+
+ /*
+ * Sink pads support all bayer formats.
+ * The source format is propagated from the sink pad, shifted to 24-bit.
+ */
+ if (code->pad != MALI_C720_INPUT_PAD_SOURCE_SLOT_INPUT) {
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_8BIT | MALI_C720_FORMAT_10BIT |
+ MALI_C720_FORMAT_12BIT | MALI_C720_FORMAT_14BIT |
+ MALI_C720_FORMAT_16BIT | MALI_C720_FORMAT_20BIT |
+ MALI_C720_FORMAT_24BIT;
+
+ cfg = mali_c720_get_mbus_config_by_matched_index(code->index, &match);
+ if (!cfg)
+ return -EINVAL;
+
+ code->code = cfg->code;
+
+ return 0;
+ }
+
+ if (code->index)
+ return -EINVAL;
+
+ /*
+ * All routes from a source pad use the same format, so the first active
+ * route represents the source format.
+ */
+ for_each_active_route(&state->routing, route) {
+ if (route->source_pad == code->pad) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -EINVAL;
+
+ sink_fmt = v4l2_subdev_state_get_format(state,
+ route->sink_pad,
+ route->sink_stream);
+ if (!sink_fmt)
+ return -EINVAL;
+
+ cfg = mali_c720_get_mbus_config_by_code(sink_fmt->code);
+ if (!cfg)
+ return -EINVAL;
+
+ cfg = mali_c720_shift_mbus_format(cfg, MALI_C720_FORMAT_24BIT);
+ if (!cfg)
+ return -EINVAL;
+
+ code->code = cfg->code;
+
+ return 0;
+}
+
+static int mali_c720_input_enum_frame_size(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_frame_size_enum *fse)
+{
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_mbus_format_match match;
+ struct v4l2_mbus_framefmt *sink_fmt;
+ struct v4l2_subdev_route *route;
+ bool found = false;
+
+ if (fse->index)
+ return -EINVAL;
+
+ if (fse->pad != MALI_C720_INPUT_PAD_SOURCE_SLOT_INPUT) {
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_8BIT | MALI_C720_FORMAT_10BIT |
+ MALI_C720_FORMAT_12BIT | MALI_C720_FORMAT_14BIT |
+ MALI_C720_FORMAT_16BIT | MALI_C720_FORMAT_20BIT |
+ MALI_C720_FORMAT_24BIT;
+
+ cfg = mali_c720_get_mbus_config_by_code(fse->code);
+ if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+ return -EINVAL;
+
+ fse->min_width = MALI_C720_MIN_INPUT_WIDTH;
+ fse->min_height = MALI_C720_MIN_INPUT_HEIGHT;
+ fse->max_width = MALI_C720_MAX_WIDTH;
+ fse->max_height = MALI_C720_MAX_HEIGHT;
+
+ return 0;
+ }
+
+ for_each_active_route(&state->routing, route) {
+ if (route->source_pad == fse->pad) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -EINVAL;
+
+ sink_fmt = v4l2_subdev_state_get_format(state,
+ route->sink_pad,
+ route->sink_stream);
+ if (!sink_fmt)
+ return -EINVAL;
+
+ cfg = mali_c720_get_mbus_config_by_code(sink_fmt->code);
+ if (!cfg)
+ return -EINVAL;
+
+ cfg = mali_c720_shift_mbus_format(cfg, MALI_C720_FORMAT_24BIT);
+ if (!cfg || fse->code != cfg->code)
+ return -EINVAL;
+
+ fse->min_width = MALI_C720_MIN_INPUT_WIDTH;
+ fse->min_height = MALI_C720_MIN_INPUT_HEIGHT;
+ fse->max_width = MALI_C720_MAX_WIDTH;
+ fse->max_height = MALI_C720_MAX_HEIGHT;
+
+ return 0;
+}
+
+static int mali_c720_input_set_fmt(struct v4l2_subdev *sd,
+ const struct v4l2_subdev_client_info *ci,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_format *format)
+{
+ struct v4l2_mbus_framefmt *fmt = &format->format;
+ struct v4l2_mbus_framefmt *src_fmt, *sink_fmt;
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_mbus_format_match match;
+ struct v4l2_subdev_route *active_route;
+
+ if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+ media_entity_is_streaming(&sd->entity))
+ return -EBUSY;
+
+ /*
+ * Disallow set_fmt on the source pad; format is derived from the
+ * sink pad format.
+ */
+ if (format->pad == MALI_C720_INPUT_PAD_SOURCE_SLOT_INPUT)
+ return v4l2_subdev_get_fmt(sd, state, format);
+
+ sink_fmt = v4l2_subdev_state_get_format(state,
+ format->pad,
+ format->stream);
+ if (!sink_fmt)
+ return -EINVAL;
+
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_8BIT | MALI_C720_FORMAT_10BIT |
+ MALI_C720_FORMAT_12BIT | MALI_C720_FORMAT_14BIT |
+ MALI_C720_FORMAT_16BIT | MALI_C720_FORMAT_20BIT |
+ MALI_C720_FORMAT_24BIT;
+
+ cfg = mali_c720_get_mbus_config_by_code(fmt->code);
+ if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+ cfg = mali_c720_get_mbus_config_by_code(MEDIA_BUS_FMT_SRGGB24_1X24);
+
+ sink_fmt->code = cfg->code;
+
+ sink_fmt->width = fmt->width;
+ sink_fmt->height = fmt->height;
+ v4l_bound_align_image(&sink_fmt->width, MALI_C720_MIN_INPUT_WIDTH,
+ MALI_C720_MAX_WIDTH, 2,
+ &sink_fmt->height, MALI_C720_MIN_INPUT_HEIGHT,
+ MALI_C720_MAX_HEIGHT, 2, 0);
+
+ *fmt = *sink_fmt;
+
+ /* The sink format should be propagated to the source pad
+ * if there is an active route between them.
+ * The data is shifted to 24-bits.
+ */
+
+ active_route = mali_c720_input_get_active_route(state,
+ format->pad,
+ format->stream);
+ if (!active_route)
+ return 0;
+
+ src_fmt = v4l2_subdev_state_get_format(state, active_route->source_pad);
+ src_fmt->code = mali_c720_shift_mbus_format(cfg, MALI_C720_FORMAT_24BIT)->code;
+ src_fmt->width = sink_fmt->width;
+ src_fmt->height = sink_fmt->height;
+
+ return 0;
+}
+
+static void mali_c720_free_input_ports(struct mali_c720_input *input)
+{
+ struct mali_c720 *mali_c720 = input->mdev.mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_slot_input *slot_input = &input->slot_input;
+ struct mali_c720_buffer_pool *pool = &slot_input->raw_buffer_desc;
+ unsigned int i;
+
+ if (slot_input->prepared) {
+ mali_c720_ctx_mgr_release_buffer_pool(ctx, pool);
+
+ for (i = 0; i < pool->num_buffers; i++) {
+ dma_free_coherent(mali_c720->dev,
+ pool->buffer_size,
+ pool->mem[i].base,
+ pool->mem[i].addr);
+ }
+ }
+
+ slot_input->prepared = false;
+ slot_input->sink_pad = NULL;
+ slot_input->src_pad = NULL;
+ slot_input->stream = 0;
+}
+
+static int mali_c720_prepare_input_port(struct mali_c720_input *input,
+ struct v4l2_subdev_state *state,
+ struct mali_c720_slot_input *slot_input,
+ struct mali_c720_input_cfg *input_cfg)
+{
+ struct mali_c720 *mali_c720 = input->mdev.mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_buffer_pool *pool = &slot_input->raw_buffer_desc;
+ const struct v4l2_mbus_framefmt *fmt;
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_buffer_request_info info;
+ u32 pad = slot_input->sink_pad->index;
+ u32 stream = slot_input->stream;
+ unsigned int i;
+ int ret;
+
+ fmt = v4l2_subdev_state_get_format(state, pad, stream);
+ if (!fmt) {
+ dev_err(mali_c720->dev,
+ "Failed to get format for pad %u stream %u\n",
+ pad, stream);
+ return -EINVAL;
+ }
+
+ cfg = mali_c720_get_mbus_config_by_code(fmt->code);
+ if (!cfg) {
+ dev_err(mali_c720->dev,
+ "Failed to get mbus config for pad %u stream %u\n",
+ pad, stream);
+ return -EINVAL;
+ }
+
+ memset(&info, 0, sizeof(info));
+ info.type = MALI_C720_BUF_TYPE_RAW;
+ info.sub_type = MALI_C720_RAW_BUF_SUBTYPE_NORMAL;
+ info.width = fmt->width;
+ info.height = fmt->height;
+ info.line_offset[0] = ALIGN((fmt->width * cfg->bit_depth) / 8, 32);
+ info.plane_size[0] = info.line_offset[0] * info.height;
+ info.num_raw_buffers = 2;
+ info.buffer_cfg = cfg->buffer_cfg;
+
+ ret = mali_c720_ctx_mgr_request_buffer_pool(ctx, &info, pool);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < pool->num_buffers; i++) {
+ pool->mem[i].base = dma_alloc_coherent(mali_c720->dev,
+ pool->buffer_size,
+ &pool->mem[i].addr,
+ GFP_KERNEL);
+ if (!pool->mem[i].base) {
+ ret = -ENOMEM;
+ goto release_buf_pool;
+ }
+
+ mali_c720_ctx_mgr_update_buffer(ctx, pool, &pool->mem[i].addr, i);
+ }
+
+ input_cfg->id = 0;
+ input_cfg->bit_depth = cfg->bit_depth;
+ input_cfg->pool_id = pool->pool_id;
+
+ return 0;
+
+release_buf_pool:
+ mali_c720_ctx_mgr_release_buffer_pool(ctx, pool);
+
+ while (i--) {
+ dma_free_coherent(mali_c720->dev,
+ pool->buffer_size,
+ pool->mem[i].base,
+ pool->mem[i].addr);
+ }
+
+ return ret;
+}
+
+static void mali_c720_stop_inputs(struct mali_c720_slot_input *slot_input)
+{
+ struct v4l2_subdev *src_sd = media_entity_to_v4l2_subdev(slot_input->src_pad->entity);
+
+ v4l2_subdev_disable_streams(src_sd, slot_input->src_pad->index,
+ BIT(slot_input->stream));
+}
+
+static int mali_c720_input_enable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state, u32 pad,
+ u64 streams_mask)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720 *mali_c720 = mdev->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_input *input = mali_c720_sd_to_sd(mdev, struct mali_c720_input);
+ struct mali_c720_input_cfg input_cfg = {0};
+ struct mali_c720_slot_input *slot_input = &input->slot_input;
+ struct v4l2_subdev_route *route;
+ struct v4l2_subdev *src_sd;
+ int ret;
+
+ for_each_active_route(&state->routing, route) {
+ if (route->source_pad != pad)
+ continue;
+
+ slot_input->sink_pad = &input->pads[route->sink_pad];
+ slot_input->stream = route->sink_stream;
+ break;
+ }
+
+ if (!slot_input->sink_pad) {
+ dev_err(mali_c720->dev, "No active route for source pad %u\n", pad);
+ ret = -EINVAL;
+ goto err_free_input_ports;
+ }
+
+ slot_input->src_pad = media_pad_remote_pad_unique(slot_input->sink_pad);
+ ret = PTR_ERR_OR_ZERO(slot_input->src_pad);
+ if (ret) {
+ dev_err(mali_c720->dev, "Input pad %u not connected\n",
+ slot_input->sink_pad->index);
+ goto err_free_input_ports;
+ }
+
+ ret = mali_c720_prepare_input_port(input, state, slot_input, &input_cfg);
+ if (ret)
+ goto err_free_input_ports;
+
+ slot_input->prepared = true;
+ src_sd = media_entity_to_v4l2_subdev(slot_input->src_pad->entity);
+ ret = v4l2_subdev_enable_streams(src_sd, slot_input->src_pad->index,
+ BIT(slot_input->stream));
+ if (ret && ret != -EALREADY) {
+ dev_err(mali_c720->dev, "Failed to start input source\n");
+ goto err_stop_sources;
+ }
+
+ mali_c720_ctx_mgr_prepare_context(ctx, &input_cfg);
+
+ ret = mali_c720_ctx_mgr_start_context_inputs(ctx);
+ if (ret)
+ goto err_stop_context;
+
+ return 0;
+
+err_stop_context:
+ mali_c720_ctx_mgr_stop_context(ctx);
+ mali_c720_ctx_mgr_stop_context_inputs(ctx);
+err_stop_sources:
+ mali_c720_stop_inputs(slot_input);
+err_free_input_ports:
+ mali_c720_free_input_ports(input);
+
+ return ret;
+}
+
+static int mali_c720_input_disable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state, u32 pad,
+ u64 streams_mask)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720_input *input = mali_c720_sd_to_sd(mdev, struct mali_c720_input);
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mdev->mali_c720);
+ struct mali_c720_slot_input *slot_input = &input->slot_input;
+
+ mali_c720_ctx_mgr_stop_context_inputs(ctx);
+ mali_c720_stop_inputs(slot_input);
+ mali_c720_free_input_ports(input);
+
+ return 0;
+}
+
+static const struct v4l2_subdev_pad_ops mali_c720_input_pad_ops = {
+ .enum_mbus_code = mali_c720_input_enum_mbus_code,
+ .enum_frame_size = mali_c720_input_enum_frame_size,
+ .get_fmt = v4l2_subdev_get_fmt,
+ .set_fmt = mali_c720_input_set_fmt,
+ .link_validate = v4l2_subdev_link_validate_default,
+ .enable_streams = mali_c720_input_enable_streams,
+ .disable_streams = mali_c720_input_disable_streams,
+};
+
+static const struct v4l2_subdev_ops mali_c720_input_ops = {
+ .pad = &mali_c720_input_pad_ops,
+};
+
+static int mali_c720_input_init_state(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state)
+{
+ static const struct v4l2_mbus_framefmt format = {
+ .width = MALI_C720_DEFAULT_WIDTH,
+ .height = MALI_C720_DEFAULT_HEIGHT,
+ .field = V4L2_FIELD_NONE,
+ .code = MEDIA_BUS_FMT_SRGGB24_1X24,
+ .colorspace = V4L2_COLORSPACE_RAW,
+ .xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(V4L2_COLORSPACE_RAW),
+ .ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(V4L2_COLORSPACE_RAW),
+ .quantization = V4L2_QUANTIZATION_FULL_RANGE,
+ };
+ struct v4l2_subdev_route route = {
+ .sink_pad = MALI_C720_INPUT_PAD_SINK_INPUT0,
+ .sink_stream = 0,
+ .source_pad = MALI_C720_INPUT_PAD_SOURCE_SLOT_INPUT,
+ .source_stream = 0,
+ .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE,
+ };
+ struct v4l2_subdev_krouting routing = {
+ .num_routes = 1,
+ .routes = &route,
+ };
+
+ return v4l2_subdev_set_routing_with_fmt(sd, state, &routing, &format);
+}
+
+static const struct v4l2_subdev_internal_ops mali_c720_input_internal_ops = {
+ .init_state = mali_c720_input_init_state,
+};
+
+static int mali_c720_input_subdev_link_setup(struct media_entity *entity,
+ const struct media_pad *local,
+ const struct media_pad *remote,
+ u32 flags)
+{
+ struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+ struct mali_c720 *mali_c720 = v4l2_sd_to_mali_c720_sd(sd)->mali_c720;
+ struct media_pad *remote_src;
+
+ /*
+ * Sink and source pads support only one enabled connection.
+ */
+
+ if (flags & MEDIA_LNK_FL_ENABLED) {
+ remote_src = media_pad_remote_pad_unique(local);
+
+ /* No previous link connected */
+ if (IS_ERR(remote_src))
+ return 0;
+
+ if (remote_src != remote) {
+ dev_err(mali_c720->dev,
+ "Input pad %u is already connected to another pad\n",
+ local->index);
+ return -EBUSY;
+ }
+ }
+
+ return 0;
+}
+
+static int mali_c720_input_get_fwnode_pad(struct media_entity *entity,
+ struct fwnode_endpoint *endpoint)
+{
+ int port;
+
+ port = v4l2_subdev_get_fwnode_pad_1_to_1(entity, endpoint);
+ if (port < 0)
+ return port;
+ if (port)
+ return -EINVAL;
+
+ return MALI_C720_INPUT_PAD_SINK_INPUT0;
+}
+
+static const struct media_entity_operations mali_c720_input_media_ops = {
+ .link_setup = mali_c720_input_subdev_link_setup,
+ .link_validate = v4l2_subdev_link_validate,
+ .get_fwnode_pad = mali_c720_input_get_fwnode_pad,
+};
+
+int mali_c720_register_input(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_input *input = &mali_c720->input;
+ struct mali_c720_subdev *mdev = &input->mdev;
+ struct v4l2_subdev *sd = &mdev->sd;
+ int ret;
+
+ mdev->mali_c720 = mali_c720;
+
+ v4l2_subdev_init(sd, &mali_c720_input_ops);
+ sd->dev = mali_c720->dev;
+ sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_STREAMS;
+ sd->entity.ops = &mali_c720_input_media_ops;
+ sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_ISP;
+ sd->internal_ops = &mali_c720_input_internal_ops;
+ strscpy(sd->name, "mali-c720 input", sizeof(sd->name));
+
+ input->pads[MALI_C720_INPUT_PAD_SINK_INPUT0].flags =
+ MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
+ input->pads[MALI_C720_INPUT_PAD_SOURCE_SLOT_INPUT].flags = MEDIA_PAD_FL_SOURCE;
+
+ ret = media_entity_pads_init(&sd->entity,
+ MALI_C720_INPUT_NUM_PADS,
+ input->pads);
+ if (ret)
+ goto err_clear_parent;
+
+ ret = v4l2_subdev_init_finalize(sd);
+ if (ret)
+ goto err_cleanup_media_entity;
+
+ ret = v4l2_device_register_subdev(&mali_c720->v4l2_dev, sd);
+ if (ret)
+ goto err_cleanup_subdev;
+
+ return 0;
+
+err_cleanup_subdev:
+ v4l2_subdev_cleanup(sd);
+err_cleanup_media_entity:
+ media_entity_cleanup(&sd->entity);
+err_clear_parent:
+ mdev->mali_c720 = NULL;
+
+ return ret;
+}
+
+void mali_c720_unregister_input(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_input *input = &mali_c720->input;
+ struct mali_c720_subdev *mdev = &input->mdev;
+
+ if (!mdev->mali_c720)
+ return;
+
+ v4l2_device_unregister_subdev(&mdev->sd);
+}
+
+void mali_c720_cleanup_input(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_input *input = &mali_c720->input;
+ struct mali_c720_subdev *mdev = &input->mdev;
+
+ if (!mdev->mali_c720)
+ return;
+
+ v4l2_subdev_cleanup(&mdev->sd);
+ media_entity_cleanup(&mdev->sd.entity);
+ mdev->mali_c720 = NULL;
+}
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 10/24] media: mali-c720: Add ISP and human vision subdevices
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (8 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 09/24] media: mali-c720: Add input frontend subdevice Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 11/24] media: mali-c720: Add full-resolution output subdevice Anthony McGivern
` (13 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add subdevices for the ISP input pipeline and human vision (HV)
pipeline. HV processes images intended for human viewing, while the
computer vision (CV) pipeline targets machine-processing applications.
This initial driver supports only the HV path.
Expose frame-start events for sensor control timing.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../platform/arm/mali-c720/mali-c720-common.h | 38 ++
.../platform/arm/mali-c720/mali-c720-interrupts.c | 2 +
.../media/platform/arm/mali-c720/mali-c720-isp.c | 422 +++++++++++++++++++++
.../platform/arm/mali-c720/mali-c720-vision-pipe.c | 260 +++++++++++++
4 files changed, 722 insertions(+)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 6f5ddb94398d76888edb992000a4d6012e960675..1037949d45e4eb8520254cd9addcbfce45def92d 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -69,6 +69,30 @@ struct mali_c720_input {
struct mali_c720_slot_input slot_input;
};
+enum mali_c720_isp_pads {
+ MALI_C720_ISP_PAD_SINK_VIDEO,
+ MALI_C720_ISP_PAD_SOURCE_HV,
+ MALI_C720_ISP_NUM_PADS,
+};
+
+struct mali_c720_isp {
+ struct mali_c720_subdev mdev;
+ struct media_pad pads[MALI_C720_ISP_NUM_PADS];
+ struct media_pad *remote_src;
+ bool enabled;
+};
+
+enum mali_c720_vision_pipe_pads {
+ MALI_C720_VISION_PIPE_PAD_SINK_VIDEO,
+ MALI_C720_VISION_PIPE_PAD_SOURCE_RGB,
+ MALI_C720_VISION_PIPE_NUM_PADS,
+};
+
+struct mali_c720_vision_pipe {
+ struct mali_c720_subdev mdev;
+ struct media_pad pads[MALI_C720_VISION_PIPE_NUM_PADS];
+};
+
enum mali_c720_cap_devs {
MALI_C720_CAP_DEV_FR0_RGB,
MALI_C720_CAP_DEV_FR0_YUV,
@@ -126,6 +150,8 @@ struct mali_c720 {
struct v4l2_device v4l2_dev;
struct mali_c720_input input;
+ struct mali_c720_isp isp;
+ struct mali_c720_vision_pipe vision_pipe;
struct mali_c720_registers registers;
u8 *default_regs;
@@ -145,8 +171,20 @@ struct mali_c720 {
spinlock_t irq_lock;
};
+/* ISP subdevice registration functions */
+
int mali_c720_register_input(struct mali_c720 *mali_c720);
void mali_c720_unregister_input(struct mali_c720 *mali_c720);
void mali_c720_cleanup_input(struct mali_c720 *mali_c720);
+int mali_c720_register_isp(struct mali_c720 *mali_c720);
+void mali_c720_unregister_isp(struct mali_c720 *mali_c720);
+void mali_c720_cleanup_isp(struct mali_c720 *mali_c720);
+
+int mali_c720_register_vision_pipe(struct mali_c720 *mali_c720);
+void mali_c720_unregister_vision_pipe(struct mali_c720 *mali_c720);
+void mali_c720_cleanup_vision_pipe(struct mali_c720 *mali_c720);
+
+void mali_c720_isp_queue_event_sof(struct mali_c720 *mali_c720, u32 sequence);
+
#endif /* MALI_C720_COMMON_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c b/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
index 63589989478650f65c3cc06bee0a48a53b92b051..bd1e5189b276e59a33cda63f40ceffa3b7a2520c 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
@@ -156,6 +156,8 @@ static void mali_c720_handle_input_frame_start(struct mali_c720 *mali_c720,
entry->sequence = sequence;
entry->timestamp = timestamp;
entry->valid = true;
+
+ mali_c720_isp_queue_event_sof(mali_c720, sequence);
}
static void mali_c720_update_frame_timestamp(struct mali_c720_context *ctx)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-isp.c b/drivers/media/platform/arm/mali-c720/mali-c720-isp.c
new file mode 100644
index 0000000000000000000000000000000000000000..962a2215543b49a6f90159fcb75ac253727cf2b6
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-isp.c
@@ -0,0 +1,422 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/bitops.h>
+#include <linux/string.h>
+
+#include <media/media-entity.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-event.h>
+
+#include "mali-c720-common.h"
+
+static int mali_c720_isp_enum_mbus_code(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_mbus_code_enum *code)
+{
+ const struct mali_c720_mbus_format_info *cfg;
+ struct v4l2_mbus_framefmt *sink_fmt;
+ struct mali_c720_mbus_format_match match;
+
+ /* HV uses the sink Bayer order at the internal 16-bit precision. */
+ if (code->pad == MALI_C720_ISP_PAD_SOURCE_HV) {
+ if (code->index)
+ return -EINVAL;
+
+ sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
+ if (!sink_fmt)
+ return -EINVAL;
+
+ cfg = mali_c720_get_mbus_config_by_code(sink_fmt->code);
+ if (!cfg)
+ return -EINVAL;
+
+ cfg = mali_c720_shift_mbus_format(cfg, MALI_C720_FORMAT_16BIT);
+ if (!cfg)
+ return -EINVAL;
+
+ code->code = cfg->code;
+ } else if (code->pad == MALI_C720_ISP_PAD_SINK_VIDEO) {
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_24BIT;
+
+ cfg = mali_c720_get_mbus_config_by_matched_index(code->index, &match);
+ if (!cfg)
+ return -EINVAL;
+
+ code->code = cfg->code;
+ } else {
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int mali_c720_isp_enum_frame_size(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_frame_size_enum *fse)
+{
+ const struct mali_c720_mbus_format_info *cfg;
+ struct v4l2_mbus_framefmt *sink_fmt;
+ struct mali_c720_mbus_format_match match;
+
+ if (fse->index)
+ return -EINVAL;
+
+ switch (fse->pad) {
+ case MALI_C720_ISP_PAD_SOURCE_HV:
+ sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
+ if (!sink_fmt)
+ return -EINVAL;
+
+ cfg = mali_c720_get_mbus_config_by_code(sink_fmt->code);
+ if (!cfg)
+ return -EINVAL;
+
+ cfg = mali_c720_shift_mbus_format(cfg, MALI_C720_FORMAT_16BIT);
+ if (!cfg || fse->code != cfg->code)
+ return -EINVAL;
+ break;
+ case MALI_C720_ISP_PAD_SINK_VIDEO:
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_24BIT;
+
+ cfg = mali_c720_get_mbus_config_by_code(fse->code);
+ if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+ return -EINVAL;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ fse->min_width = MALI_C720_MIN_INPUT_WIDTH;
+ fse->min_height = MALI_C720_MIN_INPUT_HEIGHT;
+ fse->max_width = MALI_C720_MAX_WIDTH;
+ fse->max_height = MALI_C720_MAX_HEIGHT;
+
+ return 0;
+}
+
+static int mali_c720_isp_set_fmt(struct v4l2_subdev *sd,
+ const struct v4l2_subdev_client_info *ci,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_format *format)
+{
+ struct v4l2_mbus_framefmt *fmt = &format->format;
+ struct v4l2_mbus_framefmt *src_fmt, *sink_fmt;
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_mbus_format_match match;
+
+ if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+ media_entity_is_streaming(&sd->entity))
+ return -EBUSY;
+
+ /* Only the video sink pad format can be changed. */
+ if (format->pad != MALI_C720_ISP_PAD_SINK_VIDEO)
+ return v4l2_subdev_get_fmt(sd, state, format);
+
+ sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
+ if (!sink_fmt)
+ return -EINVAL;
+
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_24BIT;
+
+ cfg = mali_c720_get_mbus_config_by_code(fmt->code);
+ if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+ cfg = mali_c720_get_mbus_config_by_code(MEDIA_BUS_FMT_SRGGB24_1X24);
+
+ sink_fmt->code = cfg->code;
+
+ sink_fmt->width = fmt->width;
+ sink_fmt->height = fmt->height;
+ v4l_bound_align_image(&sink_fmt->width, MALI_C720_MIN_INPUT_WIDTH,
+ MALI_C720_MAX_WIDTH, 2,
+ &sink_fmt->height, MALI_C720_MIN_INPUT_HEIGHT,
+ MALI_C720_MAX_HEIGHT, 2, 0);
+
+ *fmt = *sink_fmt;
+
+ /* Propagate the input size and Bayer order to the HV output. */
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SOURCE_HV);
+ src_fmt->width = sink_fmt->width;
+ src_fmt->height = sink_fmt->height;
+ src_fmt->code = mali_c720_shift_mbus_format(cfg, MALI_C720_FORMAT_16BIT)->code;
+
+ return 0;
+}
+
+static void mali_c720_isp_stop(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+
+ mali_c720_ctx_mgr_stop_context(ctx);
+}
+
+static int mali_c720_isp_start(struct mali_c720_isp *isp,
+ struct v4l2_subdev_state *state)
+{
+ struct mali_c720 *mali_c720 = isp->mdev.mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ const struct mali_c720_mbus_format_info *cfg;
+ const struct v4l2_mbus_framefmt *fmt;
+ struct mali_c720_top_cfg top_cfg;
+ struct media_pad *sink_pad;
+ struct v4l2_subdev *src_sd;
+ int ret;
+
+ fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
+ cfg = mali_c720_get_mbus_config_by_code(fmt->code);
+ if (!cfg)
+ return -EINVAL;
+
+ top_cfg.width = fmt->width;
+ top_cfg.height = fmt->height;
+ top_cfg.rggb_start = (u32)__ffs(cfg->type);
+
+ mali_c720_ctx_mgr_configure_context(ctx, &top_cfg);
+
+ sink_pad = &isp->pads[MALI_C720_ISP_PAD_SINK_VIDEO];
+ isp->remote_src = media_pad_remote_pad_unique(sink_pad);
+ ret = PTR_ERR_OR_ZERO(isp->remote_src);
+ if (ret)
+ return ret;
+
+ src_sd = media_entity_to_v4l2_subdev(isp->remote_src->entity);
+ ret = v4l2_subdev_enable_streams(src_sd, isp->remote_src->index, BIT(0));
+ if (ret && ret != -EALREADY) {
+ dev_err(mali_c720->dev, "Failed to start ISP source\n");
+ return ret;
+ }
+
+ return 0;
+}
+
+static int mali_c720_isp_enable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state, u32 pad,
+ u64 streams_mask)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720_isp *isp = mali_c720_sd_to_sd(mdev, struct mali_c720_isp);
+ int ret;
+
+ /* Enable the stream but only start the ISP once. */
+ if (isp->enabled)
+ return 0;
+
+ ret = mali_c720_isp_start(isp, state);
+ if (ret)
+ return ret;
+
+ isp->enabled = true;
+
+ return 0;
+}
+
+static int mali_c720_isp_disable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state, u32 pad,
+ u64 streams_mask)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720_isp *isp = mali_c720_sd_to_sd(mdev, struct mali_c720_isp);
+ struct mali_c720 *mali_c720 = mdev->mali_c720;
+ struct v4l2_subdev *src_sd;
+
+ if (!isp->enabled)
+ return 0;
+
+ mali_c720_isp_stop(mali_c720);
+
+ if (isp->remote_src) {
+ src_sd = media_entity_to_v4l2_subdev(isp->remote_src->entity);
+ v4l2_subdev_disable_streams(src_sd, isp->remote_src->index,
+ BIT(0));
+ }
+ isp->remote_src = NULL;
+ isp->enabled = false;
+
+ return 0;
+}
+
+static const struct v4l2_subdev_pad_ops mali_c720_isp_pad_ops = {
+ .enum_mbus_code = mali_c720_isp_enum_mbus_code,
+ .enum_frame_size = mali_c720_isp_enum_frame_size,
+ .get_fmt = v4l2_subdev_get_fmt,
+ .set_fmt = mali_c720_isp_set_fmt,
+ .link_validate = v4l2_subdev_link_validate_default,
+ .enable_streams = mali_c720_isp_enable_streams,
+ .disable_streams = mali_c720_isp_disable_streams,
+};
+
+void mali_c720_isp_queue_event_sof(struct mali_c720 *mali_c720, u32 sequence)
+{
+ struct mali_c720_isp *isp = &mali_c720->isp;
+ struct mali_c720_subdev *mdev = &isp->mdev;
+
+ struct v4l2_event event = {
+ .type = V4L2_EVENT_FRAME_SYNC,
+ };
+
+ event.u.frame_sync.frame_sequence = sequence;
+ v4l2_event_queue(mdev->sd.devnode, &event);
+}
+
+static int
+mali_c720_isp_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
+ struct v4l2_event_subscription *sub)
+{
+ if (sub->type != V4L2_EVENT_FRAME_SYNC)
+ return -EINVAL;
+
+ /* V4L2_EVENT_FRAME_SYNC doesn't require an id, so zero should be set */
+ if (sub->id != 0)
+ return -EINVAL;
+
+ return v4l2_event_subscribe(fh, sub, 0, NULL);
+}
+
+static const struct v4l2_subdev_core_ops mali_c720_isp_core_ops = {
+ .subscribe_event = mali_c720_isp_subscribe_event,
+ .unsubscribe_event = v4l2_event_subdev_unsubscribe,
+};
+
+static const struct v4l2_subdev_ops mali_c720_isp_ops = {
+ .pad = &mali_c720_isp_pad_ops,
+ .core = &mali_c720_isp_core_ops,
+};
+
+static int mali_c720_isp_init_state(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state)
+{
+ struct v4l2_mbus_framefmt *sink_fmt, *src_fmt;
+
+ sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
+ sink_fmt->width = MALI_C720_DEFAULT_WIDTH;
+ sink_fmt->height = MALI_C720_DEFAULT_HEIGHT;
+ sink_fmt->field = V4L2_FIELD_NONE;
+ sink_fmt->code = MEDIA_BUS_FMT_SRGGB24_1X24;
+ sink_fmt->colorspace = V4L2_COLORSPACE_RAW;
+ sink_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(sink_fmt->colorspace);
+ sink_fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(sink_fmt->colorspace);
+ sink_fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE;
+
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SOURCE_HV);
+ *src_fmt = *sink_fmt;
+ src_fmt->code = MEDIA_BUS_FMT_SRGGB16_1X16;
+
+ return 0;
+}
+
+static const struct v4l2_subdev_internal_ops mali_c720_isp_internal_ops = {
+ .init_state = mali_c720_isp_init_state,
+};
+
+static int mali_c720_isp_subdev_link_setup(struct media_entity *entity,
+ const struct media_pad *local,
+ const struct media_pad *remote,
+ u32 flags)
+{
+ struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+ struct mali_c720 *mali_c720 = v4l2_sd_to_mali_c720_sd(sd)->mali_c720;
+ struct media_pad *remote_src;
+
+ if (local->index != MALI_C720_ISP_PAD_SINK_VIDEO)
+ return 0;
+
+ if (flags & MEDIA_LNK_FL_ENABLED) {
+ remote_src = media_pad_remote_pad_unique(local);
+
+ /* No previous link connected */
+ if (IS_ERR(remote_src))
+ return 0;
+
+ if (remote_src != remote) {
+ dev_err(mali_c720->dev,
+ "ISP sink pad %u is already connected to another source\n",
+ local->index);
+ return -EBUSY;
+ }
+ }
+
+ return 0;
+}
+
+static const struct media_entity_operations mali_c720_isp_media_ops = {
+ .link_setup = mali_c720_isp_subdev_link_setup,
+ .link_validate = v4l2_subdev_link_validate,
+};
+
+int mali_c720_register_isp(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_isp *isp = &mali_c720->isp;
+ struct mali_c720_subdev *mdev = &isp->mdev;
+ struct v4l2_subdev *sd = &mdev->sd;
+ int ret;
+
+ mdev->mali_c720 = mali_c720;
+
+ v4l2_subdev_init(sd, &mali_c720_isp_ops);
+ sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
+ V4L2_SUBDEV_FL_HAS_EVENTS;
+ sd->entity.ops = &mali_c720_isp_media_ops;
+ sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_ISP;
+ sd->internal_ops = &mali_c720_isp_internal_ops;
+ strscpy(sd->name, "mali-c720 isp", sizeof(sd->name));
+
+ isp->pads[MALI_C720_ISP_PAD_SINK_VIDEO].flags = MEDIA_PAD_FL_SINK |
+ MEDIA_PAD_FL_MUST_CONNECT;
+ isp->pads[MALI_C720_ISP_PAD_SOURCE_HV].flags = MEDIA_PAD_FL_SOURCE;
+
+ ret = media_entity_pads_init(&sd->entity,
+ MALI_C720_ISP_NUM_PADS,
+ isp->pads);
+ if (ret)
+ goto err_clear_parent;
+
+ ret = v4l2_subdev_init_finalize(sd);
+ if (ret)
+ goto err_cleanup_media_entity;
+
+ ret = v4l2_device_register_subdev(&mali_c720->v4l2_dev, sd);
+ if (ret)
+ goto err_cleanup_subdev;
+
+ return 0;
+
+err_cleanup_subdev:
+ v4l2_subdev_cleanup(sd);
+err_cleanup_media_entity:
+ media_entity_cleanup(&sd->entity);
+err_clear_parent:
+ mdev->mali_c720 = NULL;
+
+ return ret;
+}
+
+void mali_c720_unregister_isp(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_isp *isp = &mali_c720->isp;
+ struct mali_c720_subdev *mdev = &isp->mdev;
+
+ if (!mdev->mali_c720)
+ return;
+
+ v4l2_device_unregister_subdev(&mdev->sd);
+}
+
+void mali_c720_cleanup_isp(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_isp *isp = &mali_c720->isp;
+ struct mali_c720_subdev *mdev = &isp->mdev;
+
+ if (!mdev->mali_c720)
+ return;
+
+ v4l2_subdev_cleanup(&mdev->sd);
+ media_entity_cleanup(&mdev->sd.entity);
+ mdev->mali_c720 = NULL;
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-vision-pipe.c b/drivers/media/platform/arm/mali-c720/mali-c720-vision-pipe.c
new file mode 100644
index 0000000000000000000000000000000000000000..1a0ff0486dca1637fc3112009894e719312cfc82
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-vision-pipe.c
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/string.h>
+
+#include <media/media-entity.h>
+#include <media/v4l2-common.h>
+
+#include "mali-c720-common.h"
+
+static int mali_c720_vision_pipe_enum_mbus_code(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_mbus_code_enum *code)
+{
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_mbus_format_match match;
+
+ switch (code->pad) {
+ case MALI_C720_VISION_PIPE_PAD_SOURCE_RGB:
+ if (code->index)
+ return -EINVAL;
+ code->code = MEDIA_BUS_FMT_RGB121212_1X36;
+ break;
+ case MALI_C720_VISION_PIPE_PAD_SINK_VIDEO:
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_16BIT;
+
+ cfg = mali_c720_get_mbus_config_by_matched_index(code->index, &match);
+ if (!cfg)
+ return -EINVAL;
+ code->code = cfg->code;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int mali_c720_vision_pipe_enum_frame_size(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_frame_size_enum *fse)
+{
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_mbus_format_match match;
+
+ if (fse->index)
+ return -EINVAL;
+
+ switch (fse->pad) {
+ case MALI_C720_VISION_PIPE_PAD_SOURCE_RGB:
+ if (fse->code != MEDIA_BUS_FMT_RGB121212_1X36)
+ return -EINVAL;
+ break;
+ case MALI_C720_VISION_PIPE_PAD_SINK_VIDEO:
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_16BIT;
+
+ cfg = mali_c720_get_mbus_config_by_code(fse->code);
+ if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+ return -EINVAL;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ fse->min_width = MALI_C720_MIN_INPUT_WIDTH;
+ fse->min_height = MALI_C720_MIN_INPUT_HEIGHT;
+ fse->max_width = MALI_C720_MAX_WIDTH;
+ fse->max_height = MALI_C720_MAX_HEIGHT;
+
+ return 0;
+}
+
+static int mali_c720_vision_pipe_set_fmt(struct v4l2_subdev *sd,
+ const struct v4l2_subdev_client_info *ci,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_format *format)
+{
+ struct v4l2_mbus_framefmt *fmt = &format->format;
+ struct v4l2_mbus_framefmt *src_fmt, *sink_fmt;
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_mbus_format_match match;
+
+ if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+ media_entity_is_streaming(&sd->entity))
+ return -EBUSY;
+
+ /*
+ * Disallow set_fmt on the source pad; size is derived from the sink
+ * pad, while the RGB source format is fixed.
+ */
+ if (format->pad != MALI_C720_VISION_PIPE_PAD_SINK_VIDEO)
+ return v4l2_subdev_get_fmt(sd, state, format);
+
+ sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_VISION_PIPE_PAD_SINK_VIDEO);
+
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_16BIT;
+
+ cfg = mali_c720_get_mbus_config_by_code(fmt->code);
+ if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+ cfg = mali_c720_get_mbus_config_by_code(MEDIA_BUS_FMT_SRGGB16_1X16);
+
+ sink_fmt->code = cfg->code;
+
+ sink_fmt->width = fmt->width;
+ sink_fmt->height = fmt->height;
+ v4l_bound_align_image(&sink_fmt->width, MALI_C720_MIN_INPUT_WIDTH,
+ MALI_C720_MAX_WIDTH, 1,
+ &sink_fmt->height, MALI_C720_MIN_INPUT_HEIGHT,
+ MALI_C720_MAX_HEIGHT, 1, 0);
+
+ *fmt = *sink_fmt;
+
+ /* Propagate the input dimensions to the RGB output. */
+ src_fmt = v4l2_subdev_state_get_format(state,
+ MALI_C720_VISION_PIPE_PAD_SOURCE_RGB);
+ src_fmt->width = sink_fmt->width;
+ src_fmt->height = sink_fmt->height;
+
+ return 0;
+}
+
+static int mali_c720_vision_pipe_enable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ return 0;
+}
+
+static int mali_c720_vision_pipe_disable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ return 0;
+}
+
+static const struct v4l2_subdev_pad_ops mali_c720_vision_pipe_pad_ops = {
+ .enum_mbus_code = mali_c720_vision_pipe_enum_mbus_code,
+ .enum_frame_size = mali_c720_vision_pipe_enum_frame_size,
+ .get_fmt = v4l2_subdev_get_fmt,
+ .set_fmt = mali_c720_vision_pipe_set_fmt,
+ .link_validate = v4l2_subdev_link_validate_default,
+ .enable_streams = mali_c720_vision_pipe_enable_streams,
+ .disable_streams = mali_c720_vision_pipe_disable_streams,
+};
+
+static const struct v4l2_subdev_ops mali_c720_vision_pipe_ops = {
+ .pad = &mali_c720_vision_pipe_pad_ops,
+};
+
+static int mali_c720_vision_pipe_init_state(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state)
+{
+ struct v4l2_mbus_framefmt *sink_fmt, *src_fmt;
+
+ sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_VISION_PIPE_PAD_SINK_VIDEO);
+ sink_fmt->width = MALI_C720_DEFAULT_WIDTH;
+ sink_fmt->height = MALI_C720_DEFAULT_HEIGHT;
+ sink_fmt->field = V4L2_FIELD_NONE;
+ sink_fmt->code = MEDIA_BUS_FMT_SRGGB16_1X16;
+ sink_fmt->colorspace = V4L2_COLORSPACE_RAW;
+ sink_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(sink_fmt->colorspace);
+ sink_fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(sink_fmt->colorspace);
+ sink_fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE;
+
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_VISION_PIPE_PAD_SOURCE_RGB);
+ *src_fmt = *sink_fmt;
+ src_fmt->code = MEDIA_BUS_FMT_RGB121212_1X36;
+ src_fmt->colorspace = V4L2_COLORSPACE_SRGB;
+ src_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(src_fmt->colorspace);
+ src_fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(src_fmt->colorspace);
+ src_fmt->quantization =
+ V4L2_MAP_QUANTIZATION_DEFAULT(true, src_fmt->colorspace,
+ src_fmt->ycbcr_enc);
+
+ return 0;
+}
+
+static const struct v4l2_subdev_internal_ops mali_c720_vision_pipe_internal_ops = {
+ .init_state = mali_c720_vision_pipe_init_state,
+};
+
+static const struct media_entity_operations mali_c720_vision_pipe_media_ops = {
+ .link_validate = v4l2_subdev_link_validate,
+};
+
+int mali_c720_register_vision_pipe(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_vision_pipe *pipe = &mali_c720->vision_pipe;
+ struct mali_c720_subdev *mdev = &pipe->mdev;
+ struct v4l2_subdev *sd = &mdev->sd;
+ int ret;
+
+ mdev->mali_c720 = mali_c720;
+
+ v4l2_subdev_init(sd, &mali_c720_vision_pipe_ops);
+ sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+ sd->entity.ops = &mali_c720_vision_pipe_media_ops;
+ sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_ISP;
+ sd->internal_ops = &mali_c720_vision_pipe_internal_ops;
+ strscpy(sd->name, "mali-c720 hv pipe", sizeof(sd->name));
+
+ pipe->pads[MALI_C720_VISION_PIPE_PAD_SINK_VIDEO].flags = MEDIA_PAD_FL_SINK |
+ MEDIA_PAD_FL_MUST_CONNECT;
+ pipe->pads[MALI_C720_VISION_PIPE_PAD_SOURCE_RGB].flags = MEDIA_PAD_FL_SOURCE;
+ ret = media_entity_pads_init(&sd->entity,
+ MALI_C720_VISION_PIPE_NUM_PADS,
+ pipe->pads);
+ if (ret)
+ goto err_clear_parent;
+
+ ret = v4l2_subdev_init_finalize(sd);
+ if (ret)
+ goto err_cleanup_media_entity;
+
+ ret = v4l2_device_register_subdev(&mali_c720->v4l2_dev, sd);
+ if (ret)
+ goto err_cleanup_subdev;
+
+ return 0;
+
+err_cleanup_subdev:
+ v4l2_subdev_cleanup(sd);
+err_cleanup_media_entity:
+ media_entity_cleanup(&sd->entity);
+err_clear_parent:
+ mdev->mali_c720 = NULL;
+
+ return ret;
+}
+
+void mali_c720_unregister_vision_pipe(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_vision_pipe *pipe = &mali_c720->vision_pipe;
+ struct mali_c720_subdev *mdev = &pipe->mdev;
+
+ if (!mdev->mali_c720)
+ return;
+
+ v4l2_device_unregister_subdev(&mdev->sd);
+}
+
+void mali_c720_cleanup_vision_pipe(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_vision_pipe *pipe = &mali_c720->vision_pipe;
+ struct mali_c720_subdev *mdev = &pipe->mdev;
+
+ if (!mdev->mali_c720)
+ return;
+
+ v4l2_subdev_cleanup(&mdev->sd);
+ media_entity_cleanup(&mdev->sd.entity);
+ mdev->mali_c720 = NULL;
+}
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 11/24] media: mali-c720: Add full-resolution output subdevice
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (9 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 10/24] media: mali-c720: Add ISP and human vision subdevices Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:21 ` sashiko-bot
2026-11-24 17:07 ` [PATCH 12/24] media: mali-c720: Add video capture nodes Anthony McGivern
` (12 subsequent siblings)
23 siblings, 1 reply; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add the full-resolution output 0 (FR0) subdevice with RGB and YUV source
pads. It is currently connected to the human vision (HV) pipeline.
Support for additional full-resolution output pipelines and connections
to the computer vision (CV) pipeline will be added in the future.
Configure scaling through the sink-pad compose rectangle, followed by
cropping on the source pads. Both outputs share the scaling and crop
configuration.
Provide default scaler coefficients and YUV output formatter settings.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../platform/arm/mali-c720/mali-c720-common.h | 53 +
.../platform/arm/mali-c720/mali-c720-fr-pipe.c | 1178 ++++++++++++++++++++
2 files changed, 1231 insertions(+)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 1037949d45e4eb8520254cd9addcbfce45def92d..ca7e04ef27a6ae3c4b41144de579c668255bfcaa 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -31,11 +31,15 @@
#define MALI_C720_MIN_INPUT_WIDTH 256
#define MALI_C720_MIN_INPUT_HEIGHT 256
+#define MALI_C720_MIN_OUTPUT_WIDTH 64
+#define MALI_C720_MIN_OUTPUT_HEIGHT 64
#define MALI_C720_MAX_WIDTH 8192
#define MALI_C720_MAX_HEIGHT 4608
#define MALI_C720_DEFAULT_WIDTH 1920
#define MALI_C720_DEFAULT_HEIGHT 1080
+#define MALI_C720_MAX_DOWNSCALE_RATIO 0xffffff /* Q4.20 */
+
#define MALI_C720_FRAME_TIMESTAMP_COUNT 256
struct mali_c720_subdev {
@@ -93,6 +97,48 @@ struct mali_c720_vision_pipe {
struct media_pad pads[MALI_C720_VISION_PIPE_NUM_PADS];
};
+enum mali_c720_fr_pipe_pads {
+ MALI_C720_FR_PIPE_PAD_SINK_VIDEO,
+ MALI_C720_FR_PIPE_PAD_SOURCE_RGB,
+ MALI_C720_FR_PIPE_PAD_SOURCE_YUV,
+ MALI_C720_FR_PIPE_NUM_PADS,
+};
+
+struct mali_c720_crop_config {
+ u32 start_x;
+ u32 start_y;
+ u32 size_x;
+ u32 size_y;
+ bool bypass;
+};
+
+struct mali_c720_fr_resizer_config {
+ struct mali_c720_crop_config crop;
+ u32 hfilt_tincr;
+ u32 vfilt_tincr;
+ unsigned int hbank;
+ unsigned int vbank;
+ bool hfilt_enable;
+ bool vfilt_enable;
+};
+
+struct mali_c720_fr_pipe {
+ struct mali_c720_subdev mdev;
+ struct media_pad pads[MALI_C720_FR_PIPE_NUM_PADS];
+ struct media_pad *remote_src;
+ u32 crop_base;
+ u32 scaler_base;
+ u32 scaler_hmem_base;
+ u32 scaler_vmem_base;
+ u32 output_formatter_base;
+
+ /* Protect resizer_config, resizer_updated and enabled_crops. */
+ spinlock_t resizer_lock;
+ struct mali_c720_fr_resizer_config resizer_config;
+ bool resizer_updated;
+ unsigned long enabled_crops;
+};
+
enum mali_c720_cap_devs {
MALI_C720_CAP_DEV_FR0_RGB,
MALI_C720_CAP_DEV_FR0_YUV,
@@ -152,6 +198,7 @@ struct mali_c720 {
struct mali_c720_input input;
struct mali_c720_isp isp;
struct mali_c720_vision_pipe vision_pipe;
+ struct mali_c720_fr_pipe fr_pipe;
struct mali_c720_registers registers;
u8 *default_regs;
@@ -185,6 +232,12 @@ int mali_c720_register_vision_pipe(struct mali_c720 *mali_c720);
void mali_c720_unregister_vision_pipe(struct mali_c720 *mali_c720);
void mali_c720_cleanup_vision_pipe(struct mali_c720 *mali_c720);
+int mali_c720_register_fr_pipe(struct mali_c720 *mali_c720);
+void mali_c720_unregister_fr_pipe(struct mali_c720 *mali_c720);
+void mali_c720_cleanup_fr_pipe(struct mali_c720 *mali_c720);
+
+void mali_c720_fr_pipe_apply_resizer_config(struct mali_c720_fr_pipe *pipe);
+
void mali_c720_isp_queue_event_sof(struct mali_c720 *mali_c720, u32 sequence);
#endif /* MALI_C720_COMMON_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-fr-pipe.c b/drivers/media/platform/arm/mali-c720/mali-c720-fr-pipe.c
new file mode 100644
index 0000000000000000000000000000000000000000..a2f97ebce609b6d9434f942958c24aa3df40e69c
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-fr-pipe.c
@@ -0,0 +1,1178 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/bitops.h>
+#include <linux/math.h>
+#include <linux/minmax.h>
+#include <linux/string.h>
+
+#include <media/media-entity.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-rect.h>
+
+#include "mali-c720-common.h"
+
+#define MALI_C720_SCALER_FACTOR BIT(20)
+
+#define MALI_C720_RSZ_COEFS_BANKS 8
+#define MALI_C720_RSZ_COEFS_ENTRIES 64
+
+/* Set initial phase as 0.5 in Q4.20, for the best image quality */
+#define MALI_C720_SCALER_START_PHASE 0x80000
+
+/*
+ * Default coefficients for the 32-phase, 7-tap scaler filters.
+ * Eight banks are optimised for image quality at different scaling ratios,
+ * with independent bank selection for horizontal and vertical scaling.
+ * Each phase contains seven signed 8-bit coefficients packed into two
+ * 32-bit words.
+ */
+static const unsigned int
+mali_c720_rsz_filter_coeffs_h[MALI_C720_RSZ_COEFS_BANKS]
+ [MALI_C720_RSZ_COEFS_ENTRIES] = {
+ { /* Bank 0 */
+ 0x24fc0000, 0x0000fc24, 0x27fc0000, 0x0000fc21,
+ 0x28fc0000, 0x0000fd1f, 0x2cfb0000, 0x0000fd1c,
+ 0x2efb0000, 0x0000fd1a, 0x30fb0000, 0x0000fe17,
+ 0x32fb0000, 0x0000fe15, 0x35fb0000, 0x0000fe12,
+ 0x35fc0000, 0x0000ff10, 0x37fc0000, 0x0000ff0e,
+ 0x39fc0000, 0x0000ff0c, 0x3afd0000, 0x0000ff0a,
+ 0x3afe0000, 0x00000008, 0x3cfe0000, 0x00000006,
+ 0x3dff0000, 0x00000004, 0x3d000000, 0x00000003,
+ 0x3c020000, 0x00000002, 0x3d030000, 0x00000000,
+ 0x3d040000, 0x000000ff, 0x3c060000, 0x000000fe,
+ 0x3a080000, 0x000000fe, 0x3a0aff00, 0x000000fd,
+ 0x390cff00, 0x000000fc, 0x370eff00, 0x000000fc,
+ 0x3510ff00, 0x000000fc, 0x3512fe00, 0x000000fb,
+ 0x3215fe00, 0x000000fb, 0x3017fe00, 0x000000fb,
+ 0x2e1afd00, 0x000000fb, 0x2c1cfd00, 0x000000fb,
+ 0x281ffd00, 0x000000fc, 0x2721fc00, 0x000000fc,
+ },
+ { /* Bank 1 */
+ 0x25fb0000, 0x0000fb25, 0x27fb0000, 0x0000fb23,
+ 0x29fb0000, 0x0000fb21, 0x2afc0000, 0x0000fb1f,
+ 0x2cfc0000, 0x0000fb1d, 0x2efc0000, 0x0000fb1b,
+ 0x2ffd0000, 0x0000fb19, 0x2ffe0000, 0x0000fc17,
+ 0x31fe0000, 0x0000fc15, 0x32ff0000, 0x0000fc13,
+ 0x3400ff00, 0x0000fc11, 0x3301ff00, 0x0000fd10,
+ 0x3402ff00, 0x0000fd0e, 0x3503ff00, 0x0000fd0c,
+ 0x3505ff00, 0x0000fd0a, 0x3506fe00, 0x0000fe09,
+ 0x3607fe00, 0x0000fe07, 0x3509fe00, 0x0000fe06,
+ 0x350afd00, 0x0000ff05, 0x350cfd00, 0x0000ff03,
+ 0x340efd00, 0x0000ff02, 0x3310fd00, 0x0000ff01,
+ 0x3411fc00, 0x0000ff00, 0x3213fc00, 0x000000ff,
+ 0x3115fc00, 0x000000fe, 0x2f17fc00, 0x000000fe,
+ 0x2f19fb00, 0x000000fd, 0x2e1bfb00, 0x000000fc,
+ 0x2c1dfb00, 0x000000fc, 0x2a1ffb00, 0x000000fc,
+ 0x2921fb00, 0x000000fb, 0x2723fb00, 0x000000fb,
+ },
+ { /* Bank 2 */
+ 0x1f010000, 0x0000011f, 0x21010000, 0x0000001e,
+ 0x21020000, 0x0000001d, 0x22020000, 0x0000001c,
+ 0x23030000, 0x0000ff1b, 0x2404ff00, 0x0000ff1a,
+ 0x2504ff00, 0x0000ff19, 0x2505ff00, 0x0000ff18,
+ 0x2606ff00, 0x0000fe17, 0x2607ff00, 0x0000fe16,
+ 0x2708ff00, 0x0000fe14, 0x2709ff00, 0x0000fe13,
+ 0x270aff00, 0x0000fe12, 0x280bfe00, 0x0000fe11,
+ 0x280cfe00, 0x0000fe10, 0x280dfe00, 0x0000fe0f,
+ 0x280efe00, 0x0000fe0e, 0x280ffe00, 0x0000fe0d,
+ 0x2810fe00, 0x0000fe0c, 0x2811fe00, 0x0000fe0b,
+ 0x2712fe00, 0x0000ff0a, 0x2713fe00, 0x0000ff09,
+ 0x2714fe00, 0x0000ff08, 0x2616fe00, 0x0000ff07,
+ 0x2617fe00, 0x0000ff06, 0x2518ff00, 0x0000ff05,
+ 0x2519ff00, 0x0000ff04, 0x241aff00, 0x0000ff04,
+ 0x231bff00, 0x00000003, 0x221c0000, 0x00000002,
+ 0x211d0000, 0x00000002, 0x211e0000, 0x00000001,
+ },
+ { /* Bank 3 */
+ 0x1b06ff00, 0x00ff061b, 0x1b07ff00, 0x00ff061a,
+ 0x1c07ff00, 0x00ff051a, 0x1c08ff00, 0x00ff0519,
+ 0x1c09ff00, 0x00ff0419, 0x1d09ff00, 0x00ff0418,
+ 0x1e0aff00, 0x00ff0317, 0x1e0aff00, 0x00ff0317,
+ 0x1e0bff00, 0x00ff0316, 0x1f0cff00, 0x00ff0215,
+ 0x1e0cff00, 0x00000215, 0x1e0dff00, 0x00000214,
+ 0x1e0e0000, 0x00000113, 0x1e0e0000, 0x00000113,
+ 0x1e0f0000, 0x00000112, 0x1f100000, 0x00000011,
+ 0x20100000, 0x00000010, 0x1f110000, 0x00000010,
+ 0x1e120100, 0x0000000f, 0x1e130100, 0x0000000e,
+ 0x1e130100, 0x0000000e, 0x1e140200, 0x0000ff0d,
+ 0x1e150200, 0x0000ff0c, 0x1f1502ff, 0x0000ff0c,
+ 0x1e1603ff, 0x0000ff0b, 0x1e1703ff, 0x0000ff0a,
+ 0x1e1703ff, 0x0000ff0a, 0x1d1804ff, 0x0000ff09,
+ 0x1c1904ff, 0x0000ff09, 0x1c1905ff, 0x0000ff08,
+ 0x1c1a05ff, 0x0000ff07, 0x1b1a06ff, 0x0000ff07,
+ },
+ { /* Bank 4 */
+ 0x17090000, 0x00000917, 0x18090000, 0x00000916,
+ 0x170a0100, 0x00000816, 0x170a0100, 0x00000816,
+ 0x180b0100, 0x00000715, 0x180b0100, 0x00000715,
+ 0x170c0100, 0x00000715, 0x190c0100, 0x00000614,
+ 0x180d0100, 0x00000614, 0x190d0200, 0x00000513,
+ 0x180e0200, 0x00000513, 0x180e0200, 0x00000513,
+ 0x1a0e0200, 0x00000412, 0x190f0200, 0x00000412,
+ 0x190f0300, 0x00000411, 0x18100300, 0x00000411,
+ 0x1a100300, 0x00000310, 0x18110400, 0x00000310,
+ 0x19110400, 0x0000030f, 0x19120400, 0x0000020f,
+ 0x1a120400, 0x0000020e, 0x18130500, 0x0000020e,
+ 0x18130500, 0x0000020e, 0x19130500, 0x0000020d,
+ 0x18140600, 0x0000010d, 0x19140600, 0x0000010c,
+ 0x17150700, 0x0000010c, 0x18150700, 0x0000010b,
+ 0x18150700, 0x0000010b, 0x17160800, 0x0000010a,
+ 0x17160800, 0x0000010a, 0x18160900, 0x00000009,
+ },
+ { /* Bank 5 */
+ 0x120b0300, 0x00030b12, 0x120c0300, 0x00030b11,
+ 0x110c0400, 0x00030b11, 0x110c0400, 0x00030b11,
+ 0x130c0400, 0x00020a11, 0x120d0400, 0x00020a11,
+ 0x110d0500, 0x00020a11, 0x110d0500, 0x00020a11,
+ 0x130d0500, 0x00010911, 0x130e0500, 0x00010910,
+ 0x120e0600, 0x00010910, 0x120e0600, 0x00010910,
+ 0x130e0600, 0x00010810, 0x120f0600, 0x00010810,
+ 0x120f0700, 0x00000810, 0x130f0700, 0x0000080f,
+ 0x140f0700, 0x0000070f, 0x130f0800, 0x0000070f,
+ 0x12100800, 0x0000070f, 0x12100801, 0x0000060f,
+ 0x13100801, 0x0000060e, 0x12100901, 0x0000060e,
+ 0x12100901, 0x0000060e, 0x13100901, 0x0000050e,
+ 0x13110901, 0x0000050d, 0x11110a02, 0x0000050d,
+ 0x11110a02, 0x0000050d, 0x12110a02, 0x0000040d,
+ 0x13110a02, 0x0000040c, 0x11110b03, 0x0000040c,
+ 0x11110b03, 0x0000040c, 0x12110b03, 0x0000030c,
+ },
+ { /* Bank 6 */
+ 0x0b0a0805, 0x00080a0c, 0x0b0a0805, 0x00080a0c,
+ 0x0c0a0805, 0x00080a0b, 0x0c0a0805, 0x00080a0b,
+ 0x0d0a0805, 0x00070a0b, 0x0d0a0805, 0x00070a0b,
+ 0x0d0a0805, 0x00070a0b, 0x0c0a0806, 0x00070a0b,
+ 0x0b0b0806, 0x00070a0b, 0x0c0b0806, 0x0007090b,
+ 0x0b0b0906, 0x0007090b, 0x0b0b0906, 0x0007090b,
+ 0x0b0b0906, 0x0007090b, 0x0b0b0906, 0x0007090b,
+ 0x0b0b0906, 0x0007090b, 0x0c0b0906, 0x0006090b,
+ 0x0c0b0906, 0x0006090b, 0x0c0b0906, 0x0006090b,
+ 0x0b0b0907, 0x0006090b, 0x0b0b0907, 0x0006090b,
+ 0x0b0b0907, 0x0006090b, 0x0b0b0907, 0x0006090b,
+ 0x0b0b0907, 0x0006090b, 0x0c0b0907, 0x0006080b,
+ 0x0b0b0a07, 0x0006080b, 0x0c0b0a07, 0x0006080a,
+ 0x0d0b0a07, 0x0005080a, 0x0d0b0a07, 0x0005080a,
+ 0x0d0b0a07, 0x0005080a, 0x0c0b0a08, 0x0005080a,
+ 0x0c0b0a08, 0x0005080a, 0x0c0b0a08, 0x0005080a,
+ },
+ { /* Bank 7 */
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ 0x0909090a, 0x00090909, 0x0909090a, 0x00090909,
+ }
+};
+
+static const unsigned int
+mali_c720_rsz_filter_coeffs_v[MALI_C720_RSZ_COEFS_BANKS]
+ [MALI_C720_RSZ_COEFS_ENTRIES] = {
+ { /* Bank 0 */
+ 0x2424fc00, 0x000000fc, 0x2721fc00, 0x000000fc,
+ 0x281ffd00, 0x000000fc, 0x2c1cfd00, 0x000000fb,
+ 0x2e1afd00, 0x000000fb, 0x3017fe00, 0x000000fb,
+ 0x3215fe00, 0x000000fb, 0x3512fe00, 0x000000fb,
+ 0x3510ff00, 0x000000fc, 0x370eff00, 0x000000fc,
+ 0x390cff00, 0x000000fc, 0x3a0aff00, 0x000000fd,
+ 0x3a080000, 0x000000fe, 0x3c060000, 0x000000fe,
+ 0x3d040000, 0x000000ff, 0x3d030000, 0x00000000,
+ 0x3c020000, 0x00000002, 0x3d000000, 0x00000003,
+ 0x3dff0000, 0x00000004, 0x3cfe0000, 0x00000006,
+ 0x3afe0000, 0x00000008, 0x3afd0000, 0x0000ff0a,
+ 0x39fc0000, 0x0000ff0c, 0x37fc0000, 0x0000ff0e,
+ 0x35fc0000, 0x0000ff10, 0x35fb0000, 0x0000fe12,
+ 0x32fb0000, 0x0000fe15, 0x30fb0000, 0x0000fe17,
+ 0x2efb0000, 0x0000fd1a, 0x2cfb0000, 0x0000fd1c,
+ 0x28fc0000, 0x0000fd1f, 0x27fc0000, 0x0000fc21,
+ },
+ { /* Bank 1 */
+ 0x2525fb00, 0x000000fb, 0x2723fb00, 0x000000fb,
+ 0x2921fb00, 0x000000fb, 0x2a1ffb00, 0x000000fc,
+ 0x2c1dfb00, 0x000000fc, 0x2e1bfb00, 0x000000fc,
+ 0x2f19fb00, 0x000000fd, 0x2f17fc00, 0x000000fe,
+ 0x3115fc00, 0x000000fe, 0x3213fc00, 0x000000ff,
+ 0x3411fc00, 0x0000ff00, 0x3310fd00, 0x0000ff01,
+ 0x340efd00, 0x0000ff02, 0x350cfd00, 0x0000ff03,
+ 0x350afd00, 0x0000ff05, 0x3509fe00, 0x0000fe06,
+ 0x3607fe00, 0x0000fe07, 0x3506fe00, 0x0000fe09,
+ 0x3505ff00, 0x0000fd0a, 0x3503ff00, 0x0000fd0c,
+ 0x3402ff00, 0x0000fd0e, 0x3301ff00, 0x0000fd10,
+ 0x3400ff00, 0x0000fc11, 0x32ff0000, 0x0000fc13,
+ 0x31fe0000, 0x0000fc15, 0x2ffe0000, 0x0000fc17,
+ 0x2ffd0000, 0x0000fb19, 0x2efc0000, 0x0000fb1b,
+ 0x2cfc0000, 0x0000fb1d, 0x2afc0000, 0x0000fb1f,
+ 0x29fb0000, 0x0000fb21, 0x27fb0000, 0x0000fb23,
+ },
+ { /* Bank 2 */
+ 0x1f1f0100, 0x00000001, 0x211e0000, 0x00000001,
+ 0x211d0000, 0x00000002, 0x221c0000, 0x00000002,
+ 0x231bff00, 0x00000003, 0x241aff00, 0x0000ff04,
+ 0x2519ff00, 0x0000ff04, 0x2518ff00, 0x0000ff05,
+ 0x2617fe00, 0x0000ff06, 0x2616fe00, 0x0000ff07,
+ 0x2714fe00, 0x0000ff08, 0x2713fe00, 0x0000ff09,
+ 0x2712fe00, 0x0000ff0a, 0x2811fe00, 0x0000fe0b,
+ 0x2810fe00, 0x0000fe0c, 0x280ffe00, 0x0000fe0d,
+ 0x280efe00, 0x0000fe0e, 0x280dfe00, 0x0000fe0f,
+ 0x280cfe00, 0x0000fe10, 0x280bfe00, 0x0000fe11,
+ 0x270aff00, 0x0000fe12, 0x2709ff00, 0x0000fe13,
+ 0x2708ff00, 0x0000fe14, 0x2607ff00, 0x0000fe16,
+ 0x2606ff00, 0x0000fe17, 0x2505ff00, 0x0000ff18,
+ 0x2504ff00, 0x0000ff19, 0x2404ff00, 0x0000ff1a,
+ 0x23030000, 0x0000ff1b, 0x22020000, 0x0000001c,
+ 0x21020000, 0x0000001d, 0x21010000, 0x0000001e,
+ },
+ { /* Bank 3 */
+ 0x1b1b06ff, 0x0000ff06, 0x1b1a06ff, 0x0000ff07,
+ 0x1c1a05ff, 0x0000ff07, 0x1c1905ff, 0x0000ff08,
+ 0x1c1904ff, 0x0000ff09, 0x1d1804ff, 0x0000ff09,
+ 0x1e1703ff, 0x0000ff0a, 0x1e1703ff, 0x0000ff0a,
+ 0x1e1603ff, 0x0000ff0b, 0x1f1502ff, 0x0000ff0c,
+ 0x1e150200, 0x0000ff0c, 0x1e140200, 0x0000ff0d,
+ 0x1e130100, 0x0000000e, 0x1e130100, 0x0000000e,
+ 0x1e120100, 0x0000000f, 0x1f110000, 0x00000010,
+ 0x20100000, 0x00000010, 0x1f100000, 0x00000011,
+ 0x1e0f0000, 0x00000112, 0x1e0e0000, 0x00000113,
+ 0x1e0e0000, 0x00000113, 0x1e0dff00, 0x00000214,
+ 0x1e0cff00, 0x00000215, 0x1f0cff00, 0x00ff0215,
+ 0x1e0bff00, 0x00ff0316, 0x1e0aff00, 0x00ff0317,
+ 0x1e0aff00, 0x00ff0317, 0x1d09ff00, 0x00ff0418,
+ 0x1c09ff00, 0x00ff0419, 0x1c08ff00, 0x00ff0519,
+ 0x1c07ff00, 0x00ff051a, 0x1b07ff00, 0x00ff061a,
+ },
+ { /* Bank 4 */
+ 0x17170900, 0x00000009, 0x18160900, 0x00000009,
+ 0x17160800, 0x0000010a, 0x17160800, 0x0000010a,
+ 0x18150700, 0x0000010b, 0x18150700, 0x0000010b,
+ 0x17150700, 0x0000010c, 0x19140600, 0x0000010c,
+ 0x18140600, 0x0000010d, 0x19130500, 0x0000020d,
+ 0x18130500, 0x0000020e, 0x18130500, 0x0000020e,
+ 0x1a120400, 0x0000020e, 0x19120400, 0x0000020f,
+ 0x19110400, 0x0000030f, 0x18110400, 0x00000310,
+ 0x1a100300, 0x00000310, 0x18100300, 0x00000411,
+ 0x190f0300, 0x00000411, 0x190f0200, 0x00000412,
+ 0x1a0e0200, 0x00000412, 0x180e0200, 0x00000513,
+ 0x180e0200, 0x00000513, 0x190d0200, 0x00000513,
+ 0x180d0100, 0x00000614, 0x190c0100, 0x00000614,
+ 0x170c0100, 0x00000715, 0x180b0100, 0x00000715,
+ 0x180b0100, 0x00000715, 0x170a0100, 0x00000816,
+ 0x170a0100, 0x00000816, 0x18090000, 0x00000916,
+ },
+ { /* Bank 5 */
+ 0x12120b03, 0x0000030b, 0x12110b03, 0x0000030c,
+ 0x11110b03, 0x0000040c, 0x11110b03, 0x0000040c,
+ 0x13110a02, 0x0000040c, 0x12110a02, 0x0000040d,
+ 0x11110a02, 0x0000050d, 0x11110a02, 0x0000050d,
+ 0x13110901, 0x0000050d, 0x13100901, 0x0000050e,
+ 0x12100901, 0x0000060e, 0x12100901, 0x0000060e,
+ 0x13100801, 0x0000060e, 0x12100801, 0x0000060f,
+ 0x12100800, 0x0000070f, 0x130f0800, 0x0000070f,
+ 0x140f0700, 0x0000070f, 0x130f0700, 0x0000080f,
+ 0x120f0700, 0x00000810, 0x120f0600, 0x00010810,
+ 0x130e0600, 0x00010810, 0x120e0600, 0x00010910,
+ 0x120e0600, 0x00010910, 0x130e0500, 0x00010910,
+ 0x130d0500, 0x00010911, 0x110d0500, 0x00020a11,
+ 0x110d0500, 0x00020a11, 0x120d0400, 0x00020a11,
+ 0x130c0400, 0x00020a11, 0x110c0400, 0x00030b11,
+ 0x110c0400, 0x00030b11, 0x120c0300, 0x00030b11,
+ },
+ { /* Bank 6 */
+ 0x0b0c0a08, 0x0005080a, 0x0b0c0a08, 0x0005080a,
+ 0x0c0b0a08, 0x0005080a, 0x0c0b0a08, 0x0005080a,
+ 0x0d0b0a07, 0x0005080a, 0x0d0b0a07, 0x0005080a,
+ 0x0d0b0a07, 0x0005080a, 0x0c0b0a07, 0x0006080a,
+ 0x0b0b0a07, 0x0006080b, 0x0c0b0907, 0x0006080b,
+ 0x0b0b0907, 0x0006090b, 0x0b0b0907, 0x0006090b,
+ 0x0b0b0907, 0x0006090b, 0x0b0b0907, 0x0006090b,
+ 0x0b0b0907, 0x0006090b, 0x0c0b0906, 0x0006090b,
+ 0x0c0b0906, 0x0006090b, 0x0c0b0906, 0x0006090b,
+ 0x0b0b0906, 0x0007090b, 0x0b0b0906, 0x0007090b,
+ 0x0b0b0906, 0x0007090b, 0x0b0b0906, 0x0007090b,
+ 0x0b0b0906, 0x0007090b, 0x0c0b0806, 0x0007090b,
+ 0x0b0b0806, 0x00070a0b, 0x0c0a0806, 0x00070a0b,
+ 0x0d0a0805, 0x00070a0b, 0x0d0a0805, 0x00070a0b,
+ 0x0d0a0805, 0x00070a0b, 0x0c0a0805, 0x00080a0b,
+ 0x0c0a0805, 0x00080a0b, 0x0c0a0805, 0x00080a0b,
+ },
+ { /* Bank 7 */
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ 0x09090909, 0x000a0909, 0x09090909, 0x000a0909,
+ }
+};
+
+static const unsigned int mali_c720_rsz_coef_banks_range_start[] = {
+ 770, 600, 460, 354, 273, 210, 162, 125
+};
+
+/*
+ * Select the filter coefficient bank from the output/input size ratio,
+ * using the sink compose rectangle and sink format respectively.
+ */
+static unsigned int mali_c720_rsz_calculate_bank(unsigned int rsz_in,
+ unsigned int rsz_out)
+{
+ unsigned int rsz_ratio = (rsz_out * 1000U) / rsz_in;
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(mali_c720_rsz_coef_banks_range_start) - 1; i++)
+ if (rsz_ratio >= mali_c720_rsz_coef_banks_range_start[i])
+ break;
+
+ return i;
+}
+
+static u32 mali_c720_fr_pipe_calculate_scaling_factor(unsigned int input_width,
+ unsigned int output_width)
+{
+ u64 scale;
+
+ /* The scaling factor is in Q4.20 format */
+ scale = (u64)input_width * MALI_C720_SCALER_FACTOR -
+ MALI_C720_SCALER_START_PHASE - 1;
+ do_div(scale, output_width - 1);
+
+ return (u32)(scale & 0xFFFFFFFF);
+}
+
+static void mali_c720_fr_pipe_update_resizer_config(struct mali_c720_fr_pipe *pipe,
+ struct v4l2_subdev_state *state)
+{
+ struct mali_c720_fr_resizer_config *config = &pipe->resizer_config;
+ const struct v4l2_mbus_framefmt *fmt;
+ const struct v4l2_rect *scale, *crop;
+
+ fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SINK_VIDEO, 0);
+ scale = v4l2_subdev_state_get_compose(state, MALI_C720_FR_PIPE_PAD_SINK_VIDEO, 0);
+ crop = v4l2_subdev_state_get_crop(state, MALI_C720_FR_PIPE_PAD_SOURCE_RGB, 0);
+
+ guard(spinlock)(&pipe->resizer_lock);
+
+ config->crop.start_x = (u32)crop->left;
+ config->crop.start_y = (u32)crop->top;
+ config->crop.size_x = crop->width;
+ config->crop.size_y = crop->height;
+ config->crop.bypass = crop->width == scale->width && crop->height == scale->height;
+ config->hfilt_enable = fmt->width != scale->width;
+ config->vfilt_enable = fmt->height != scale->height;
+ config->hfilt_tincr = 0;
+ config->vfilt_tincr = 0;
+ if (config->hfilt_enable)
+ config->hfilt_tincr = mali_c720_fr_pipe_calculate_scaling_factor(fmt->width,
+ scale->width);
+ if (config->vfilt_enable)
+ config->vfilt_tincr = mali_c720_fr_pipe_calculate_scaling_factor(fmt->height,
+ scale->height);
+ config->hbank = mali_c720_rsz_calculate_bank(fmt->width, scale->width);
+ config->vbank = mali_c720_rsz_calculate_bank(fmt->height, scale->height);
+
+ pipe->resizer_updated = true;
+}
+
+static void mali_c720_fr_pipe_bypass_scaler(struct mali_c720_context *ctx,
+ unsigned int bypass)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_fr0_rgb_scaler, bypass);
+}
+
+static void
+mali_c720_fr_pipe_program_scaler_coefficients(struct mali_c720_fr_pipe *pipe,
+ const struct mali_c720_fr_resizer_config *config)
+{
+ struct mali_c720 *mali_c720 = pipe->mdev.mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ unsigned int i;
+ u32 haddr = pipe->scaler_hmem_base;
+ u32 vaddr = pipe->scaler_vmem_base;
+
+ for (i = 0; i < MALI_C720_RSZ_COEFS_ENTRIES; i++) {
+ mali_c720_ctx_write_raw(ctx, haddr,
+ mali_c720_rsz_filter_coeffs_h[config->hbank][i]);
+ mali_c720_ctx_write_raw(ctx, vaddr,
+ mali_c720_rsz_filter_coeffs_v[config->vbank][i]);
+
+ haddr += sizeof(u32);
+ vaddr += sizeof(u32);
+ }
+}
+
+static void mali_c720_fr_pipe_program_scaler(struct mali_c720_fr_pipe *pipe,
+ const struct mali_c720_fr_resizer_config *config)
+{
+ struct mali_c720 *mali_c720 = pipe->mdev.mali_c720;
+ const struct mali_c720_rgb_scaler_regs *rgb_scaler =
+ mali_c720->registers.modules->rgb_scaler;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+
+ if (!config->hfilt_enable && !config->vfilt_enable)
+ return mali_c720_fr_pipe_bypass_scaler(ctx, 1);
+
+ mali_c720_fr_pipe_program_scaler_coefficients(pipe, config);
+
+ if (!config->hfilt_enable) {
+ mali_c720_ctx_group_write(ctx, pipe->scaler_base,
+ &rgb_scaler->hfilt_enable, 0);
+ } else {
+ mali_c720_ctx_group_write(ctx, pipe->scaler_base,
+ &rgb_scaler->hfilt_tincr,
+ config->hfilt_tincr);
+ mali_c720_ctx_group_write(ctx, pipe->scaler_base,
+ &rgb_scaler->hfilt_start_phase,
+ MALI_C720_SCALER_START_PHASE);
+ mali_c720_ctx_group_write(ctx, pipe->scaler_base,
+ &rgb_scaler->hfilt_enable, 1);
+ }
+
+ if (!config->vfilt_enable) {
+ mali_c720_ctx_group_write(ctx, pipe->scaler_base,
+ &rgb_scaler->vfilt_enable, 0);
+ } else {
+ mali_c720_ctx_group_write(ctx, pipe->scaler_base,
+ &rgb_scaler->vfilt_tincr,
+ config->vfilt_tincr);
+ mali_c720_ctx_group_write(ctx, pipe->scaler_base,
+ &rgb_scaler->vfilt_start_phase,
+ MALI_C720_SCALER_START_PHASE);
+ mali_c720_ctx_group_write(ctx, pipe->scaler_base,
+ &rgb_scaler->vfilt_enable, 1);
+ }
+
+ mali_c720_fr_pipe_bypass_scaler(ctx, 0);
+}
+
+static void mali_c720_fr_pipe_bypass_crop(struct mali_c720_context *ctx,
+ unsigned int bypass)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->bypass_fr0_crop, bypass);
+}
+
+static void mali_c720_fr_pipe_program_crop(struct mali_c720_fr_pipe *pipe,
+ const struct mali_c720_crop_config *crop)
+{
+ struct mali_c720 *mali_c720 = pipe->mdev.mali_c720;
+ const struct mali_c720_crop_regs *crop_regs = mali_c720->registers.modules->crop;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+
+ if (crop->bypass)
+ return mali_c720_fr_pipe_bypass_crop(ctx, 1);
+
+ mali_c720_ctx_group_write(ctx, pipe->crop_base, &crop_regs->start_x, crop->start_x);
+ mali_c720_ctx_group_write(ctx, pipe->crop_base, &crop_regs->start_y, crop->start_y);
+ mali_c720_ctx_group_write(ctx, pipe->crop_base, &crop_regs->size_x, crop->size_x);
+ mali_c720_ctx_group_write(ctx, pipe->crop_base, &crop_regs->size_y, crop->size_y);
+ mali_c720_ctx_group_write(ctx, pipe->crop_base, &crop_regs->enable_crop, 1);
+
+ mali_c720_fr_pipe_bypass_crop(ctx, 0);
+}
+
+void mali_c720_fr_pipe_apply_resizer_config(struct mali_c720_fr_pipe *pipe)
+{
+ struct mali_c720_fr_resizer_config *config = &pipe->resizer_config;
+
+ if (!pipe->mdev.mali_c720)
+ return;
+
+ guard(spinlock)(&pipe->resizer_lock);
+ if (!pipe->enabled_crops || !pipe->resizer_updated)
+ return;
+
+ mali_c720_fr_pipe_program_scaler(pipe, config);
+ mali_c720_fr_pipe_program_crop(pipe, &config->crop);
+ pipe->resizer_updated = false;
+}
+
+static void mali_c720_fr_pipe_program_output_formatter(struct mali_c720_fr_pipe *pipe)
+{
+ struct mali_c720 *mali_c720 = pipe->mdev.mali_c720;
+ const struct mali_c720_out_format_regs *out_format =
+ mali_c720->registers.modules->out_format;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ u32 base = pipe->output_formatter_base;
+
+ /* Default BT.709 limited-range RGB to YUV conversion in Q8 format. */
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_11, 47);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_12, 157);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_13, 16);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_21, 32794);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_22, 32855);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_23, 112);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_31, 112);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_32, 32869);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_33, 32777);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_o1, 4129);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_o2, 32768);
+ mali_c720_ctx_group_write(ctx, base, &out_format->coefft_o3, 32768);
+ mali_c720_ctx_group_write(ctx, base, &out_format->clip_min_y, 0);
+ mali_c720_ctx_group_write(ctx, base, &out_format->clip_max_y, 65535);
+ mali_c720_ctx_group_write(ctx, base, &out_format->clip_min_uv, 0);
+ mali_c720_ctx_group_write(ctx, base, &out_format->clip_max_uv, 65535);
+}
+
+static unsigned int mali_c720_fr_pipe_min_output_size(unsigned int input_size)
+{
+ u64 size;
+
+ /* Invert the phase-increment calculation and round up to fit Q4.20. */
+ size = (u64)input_size * MALI_C720_SCALER_FACTOR -
+ MALI_C720_SCALER_START_PHASE - 1;
+
+ return (unsigned int)DIV_ROUND_UP_ULL(size, MALI_C720_MAX_DOWNSCALE_RATIO) + 1;
+}
+
+static int mali_c720_fr_pipe_enum_mbus_code(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_mbus_code_enum *code)
+{
+ if (code->index)
+ return -EINVAL;
+
+ switch (code->pad) {
+ case MALI_C720_FR_PIPE_PAD_SINK_VIDEO:
+ code->code = MEDIA_BUS_FMT_RGB121212_1X36;
+ break;
+ case MALI_C720_FR_PIPE_PAD_SOURCE_RGB:
+ code->code = MEDIA_BUS_FMT_RGB161616_1X48;
+ break;
+ case MALI_C720_FR_PIPE_PAD_SOURCE_YUV:
+ /*
+ * Chroma subsampling limits the UV planes to 12 bits of precision,
+ * although the media bus width remains 16 bits.
+ */
+ code->code = MEDIA_BUS_FMT_YUV16_1X48;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int mali_c720_fr_pipe_enum_frame_size(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_frame_size_enum *fse)
+{
+ struct v4l2_rect *crop;
+
+ if (fse->index)
+ return -EINVAL;
+
+ switch (fse->pad) {
+ case MALI_C720_FR_PIPE_PAD_SINK_VIDEO:
+ if (fse->code != MEDIA_BUS_FMT_RGB121212_1X36)
+ return -EINVAL;
+
+ fse->min_width = MALI_C720_MIN_INPUT_WIDTH;
+ fse->min_height = MALI_C720_MIN_INPUT_HEIGHT;
+ fse->max_width = MALI_C720_MAX_WIDTH;
+ fse->max_height = MALI_C720_MAX_HEIGHT;
+
+ return 0;
+ case MALI_C720_FR_PIPE_PAD_SOURCE_RGB:
+ if (fse->code != MEDIA_BUS_FMT_RGB161616_1X48)
+ return -EINVAL;
+ break;
+ case MALI_C720_FR_PIPE_PAD_SOURCE_YUV:
+ if (fse->code != MEDIA_BUS_FMT_YUV16_1X48)
+ return -EINVAL;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ crop = v4l2_subdev_state_get_crop(state, fse->pad);
+
+ fse->min_width = crop->width;
+ fse->min_height = crop->height;
+ fse->max_width = crop->width;
+ fse->max_height = crop->height;
+
+ return 0;
+}
+
+static int mali_c720_fr_pipe_set_fmt(struct v4l2_subdev *sd,
+ const struct v4l2_subdev_client_info *ci,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_format *format)
+{
+ struct v4l2_mbus_framefmt *fmt = &format->format;
+ struct v4l2_mbus_framefmt *src_fmt, *sink_fmt;
+ struct v4l2_rect *compose;
+
+ if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+ media_entity_is_streaming(&sd->entity))
+ return -EBUSY;
+
+ /*
+ * Disallow set_fmt on the source pads; format is fixed and the size
+ * is propagated from the sink pad.
+ */
+ if (format->pad != MALI_C720_FR_PIPE_PAD_SINK_VIDEO)
+ return v4l2_subdev_get_fmt(sd, state, format);
+
+ sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SINK_VIDEO);
+
+ /*
+ * Clamp to min/max and then reset crop and compose rectangles to the
+ * newly applied size.
+ */
+ sink_fmt->width = fmt->width;
+ sink_fmt->height = fmt->height;
+ v4l_bound_align_image(&sink_fmt->width, MALI_C720_MIN_INPUT_WIDTH,
+ MALI_C720_MAX_WIDTH, 1,
+ &sink_fmt->height, MALI_C720_MIN_INPUT_HEIGHT,
+ MALI_C720_MAX_HEIGHT, 1, 0);
+
+ *fmt = *sink_fmt;
+
+ compose = v4l2_subdev_state_get_compose(state, MALI_C720_FR_PIPE_PAD_SINK_VIDEO);
+ compose->left = 0;
+ compose->top = 0;
+ compose->width = sink_fmt->width;
+ compose->height = sink_fmt->height;
+
+ *v4l2_subdev_state_get_crop(state, MALI_C720_FR_PIPE_PAD_SOURCE_RGB) = *compose;
+ *v4l2_subdev_state_get_crop(state, MALI_C720_FR_PIPE_PAD_SOURCE_YUV) = *compose;
+
+ /*
+ * Propagate format to source pads. On the RGB output pad use
+ * the internal RGB processed format, and on the YUV pad use the internal
+ * YUV processed format. The sizes on both pads are the same as the shared source
+ * crop rectangle. The "code" "field" "colorspace" fields are set in
+ * .init_state() and fixed for both source pads.
+ */
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SOURCE_RGB);
+ src_fmt->width = compose->width;
+ src_fmt->height = compose->height;
+
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SOURCE_YUV);
+ src_fmt->width = compose->width;
+ src_fmt->height = compose->height;
+
+ return 0;
+}
+
+static int mali_c720_fr_pipe_get_selection(struct v4l2_subdev *sd,
+ const struct v4l2_subdev_client_info *ci,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_selection *sel)
+{
+ const struct v4l2_mbus_framefmt *sink_fmt;
+ const struct v4l2_rect *compose;
+
+ switch (sel->target) {
+ case V4L2_SEL_TGT_CROP:
+ if (sel->pad != MALI_C720_FR_PIPE_PAD_SOURCE_RGB &&
+ sel->pad != MALI_C720_FR_PIPE_PAD_SOURCE_YUV)
+ return -EINVAL;
+
+ sel->r = *v4l2_subdev_state_get_crop(state, sel->pad);
+ break;
+ case V4L2_SEL_TGT_COMPOSE:
+ if (sel->pad != MALI_C720_FR_PIPE_PAD_SINK_VIDEO)
+ return -EINVAL;
+
+ sel->r = *v4l2_subdev_state_get_compose(state, sel->pad);
+ break;
+ case V4L2_SEL_TGT_CROP_BOUNDS:
+ if (sel->pad != MALI_C720_FR_PIPE_PAD_SOURCE_RGB &&
+ sel->pad != MALI_C720_FR_PIPE_PAD_SOURCE_YUV)
+ return -EINVAL;
+
+ compose = v4l2_subdev_state_get_compose(state, MALI_C720_FR_PIPE_PAD_SINK_VIDEO);
+ sel->r = (struct v4l2_rect) {
+ .width = compose->width,
+ .height = compose->height,
+ };
+ break;
+ case V4L2_SEL_TGT_COMPOSE_BOUNDS:
+ if (sel->pad != MALI_C720_FR_PIPE_PAD_SINK_VIDEO)
+ return -EINVAL;
+
+ sink_fmt = v4l2_subdev_state_get_format(state, sel->pad);
+ sel->r = (struct v4l2_rect) {
+ .width = sink_fmt->width,
+ .height = sink_fmt->height,
+ };
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int mali_c720_fr_pipe_set_crop(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_selection *sel)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720_fr_pipe *pipe = mali_c720_sd_to_sd(mdev, struct mali_c720_fr_pipe);
+ struct v4l2_mbus_framefmt *src_fmt;
+ struct v4l2_rect *compose, *crop, adjusted_size;
+ struct v4l2_rect requested_size = {
+ .width = sel->r.width,
+ .height = sel->r.height,
+ };
+
+ crop = v4l2_subdev_state_get_crop(state, MALI_C720_FR_PIPE_PAD_SOURCE_RGB);
+ compose = v4l2_subdev_state_get_compose(state, MALI_C720_FR_PIPE_PAD_SINK_VIDEO);
+
+ adjusted_size = requested_size;
+
+ /* Streaming fixes the output size, but crop offsets may still change. */
+ if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+ media_entity_is_streaming(&sd->entity)) {
+ v4l2_rect_set_size_to(&adjusted_size, crop);
+ } else {
+ /* The alignment helper rounds odd sizes up; LE alone needs down. */
+ if ((sel->flags & V4L2_SEL_FLAG_LE) && !(sel->flags & V4L2_SEL_FLAG_GE)) {
+ adjusted_size.width &= ~1U;
+ adjusted_size.height &= ~1U;
+ }
+
+ v4l_bound_align_image(&adjusted_size.width, MALI_C720_MIN_OUTPUT_WIDTH,
+ compose->width, 1,
+ &adjusted_size.height, MALI_C720_MIN_OUTPUT_HEIGHT,
+ compose->height, 1, 0);
+ }
+
+ /* GE/LE constrain size independently of crop position. */
+ if ((sel->flags & V4L2_SEL_FLAG_GE) &&
+ !v4l2_rect_enclosed(&requested_size, &adjusted_size))
+ return -ERANGE;
+ if ((sel->flags & V4L2_SEL_FLAG_LE) &&
+ !v4l2_rect_enclosed(&adjusted_size, &requested_size))
+ return -ERANGE;
+
+ crop->left = sel->r.left;
+ crop->top = sel->r.top;
+ v4l2_rect_set_size_to(crop, &adjusted_size);
+
+ /* Constrain offsets within the compose window and align to even pixels. */
+ v4l2_rect_map_inside(crop, compose);
+ crop->left &= ~1;
+ crop->top &= ~1;
+
+ *v4l2_subdev_state_get_crop(state, MALI_C720_FR_PIPE_PAD_SOURCE_YUV) = *crop;
+
+ if (sel->which == V4L2_SUBDEV_FORMAT_TRY ||
+ !media_entity_is_streaming(&sd->entity)) {
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SOURCE_RGB);
+ src_fmt->width = crop->width;
+ src_fmt->height = crop->height;
+
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SOURCE_YUV);
+ src_fmt->width = crop->width;
+ src_fmt->height = crop->height;
+ }
+
+ if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+ v4l2_subdev_is_streaming(sd))
+ mali_c720_fr_pipe_update_resizer_config(pipe, state);
+
+ sel->r = *crop;
+ return 0;
+}
+
+static int mali_c720_fr_pipe_set_compose(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_selection *sel)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720_fr_pipe *pipe = mali_c720_sd_to_sd(mdev, struct mali_c720_fr_pipe);
+ struct v4l2_mbus_framefmt *sink_fmt, *src_fmt;
+ struct v4l2_rect *crop, *compose, adjusted_size;
+ struct v4l2_rect requested_size = {
+ .width = sel->r.width,
+ .height = sel->r.height,
+ };
+ unsigned int min_width, min_height;
+
+ sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SINK_VIDEO);
+ crop = v4l2_subdev_state_get_crop(state, MALI_C720_FR_PIPE_PAD_SOURCE_RGB);
+ compose = v4l2_subdev_state_get_compose(state, MALI_C720_FR_PIPE_PAD_SINK_VIDEO);
+
+ min_width = mali_c720_fr_pipe_min_output_size(sink_fmt->width);
+ min_height = mali_c720_fr_pipe_min_output_size(sink_fmt->height);
+
+ /* Preserve the output crop size while streaming and respect the scaler limit. */
+ if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+ media_entity_is_streaming(&sd->entity)) {
+ min_width = MAX(min_width, crop->width);
+ min_height = MAX(min_height, crop->height);
+ } else {
+ min_width = MAX(min_width, MALI_C720_MIN_OUTPUT_WIDTH);
+ min_height = MAX(min_height, MALI_C720_MIN_OUTPUT_HEIGHT);
+ }
+
+ /* The alignment helper rounds odd sizes up; LE alone needs down. */
+ adjusted_size = requested_size;
+ if ((sel->flags & V4L2_SEL_FLAG_LE) && !(sel->flags & V4L2_SEL_FLAG_GE)) {
+ adjusted_size.width &= ~1U;
+ adjusted_size.height &= ~1U;
+ }
+ v4l_bound_align_image(&adjusted_size.width, min_width, sink_fmt->width, 1,
+ &adjusted_size.height, min_height, sink_fmt->height, 1, 0);
+
+ if ((sel->flags & V4L2_SEL_FLAG_GE) &&
+ !v4l2_rect_enclosed(&requested_size, &adjusted_size))
+ return -ERANGE;
+ if ((sel->flags & V4L2_SEL_FLAG_LE) &&
+ !v4l2_rect_enclosed(&adjusted_size, &requested_size))
+ return -ERANGE;
+
+ *compose = adjusted_size;
+
+ if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+ media_entity_is_streaming(&sd->entity)) {
+ /* Keep crop offsets inside the new compose bounds without resizing. */
+ v4l2_rect_map_inside(crop, compose);
+ } else {
+ *crop = *compose;
+ }
+
+ *v4l2_subdev_state_get_crop(state, MALI_C720_FR_PIPE_PAD_SOURCE_YUV) = *crop;
+
+ if (sel->which == V4L2_SUBDEV_FORMAT_TRY ||
+ !media_entity_is_streaming(&sd->entity)) {
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SOURCE_RGB);
+ src_fmt->width = compose->width;
+ src_fmt->height = compose->height;
+
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SOURCE_YUV);
+ src_fmt->width = compose->width;
+ src_fmt->height = compose->height;
+ }
+
+ if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+ v4l2_subdev_is_streaming(sd))
+ mali_c720_fr_pipe_update_resizer_config(pipe, state);
+
+ sel->r = *compose;
+ return 0;
+}
+
+static int mali_c720_fr_pipe_set_selection(struct v4l2_subdev *sd,
+ const struct v4l2_subdev_client_info *ci,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_selection *sel)
+{
+ /*
+ * RGB and YUV share one post-scaler crop. Expose it on both source pads;
+ * changing either updates the crop and output dimensions of both pads.
+ */
+ if (sel->target == V4L2_SEL_TGT_CROP &&
+ (sel->pad == MALI_C720_FR_PIPE_PAD_SOURCE_RGB ||
+ sel->pad == MALI_C720_FR_PIPE_PAD_SOURCE_YUV))
+ return mali_c720_fr_pipe_set_crop(sd, state, sel);
+
+ if (sel->target == V4L2_SEL_TGT_COMPOSE &&
+ sel->pad == MALI_C720_FR_PIPE_PAD_SINK_VIDEO)
+ return mali_c720_fr_pipe_set_compose(sd, state, sel);
+
+ return -EINVAL;
+}
+
+static int mali_c720_fr_pipe_enable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state, u32 pad,
+ u64 streams_mask)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720 *mali_c720 = mdev->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ struct mali_c720_fr_pipe *pipe =
+ mali_c720_sd_to_sd(mdev, struct mali_c720_fr_pipe);
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct v4l2_subdev *src_sd;
+ struct media_pad *sink_pad;
+ int ret;
+
+ sink_pad = &pipe->pads[MALI_C720_FR_PIPE_PAD_SINK_VIDEO];
+ pipe->remote_src = media_pad_remote_pad_unique(sink_pad);
+ if (IS_ERR(pipe->remote_src)) {
+ dev_err(mali_c720->dev,
+ "No remote source for fr 0 pipe\n");
+ return -EINVAL;
+ }
+
+ src_sd = media_entity_to_v4l2_subdev(pipe->remote_src->entity);
+ mali_c720_ctx_group_write(ctx, mali_c720->top_base,
+ &pipeline->fr0_hv_cv_mux_sel,
+ ISP_TOP_FR0_HV_CV_MUX_SEL_HV);
+
+ /* Enable the upstream subdevice unless another output already enabled it. */
+ ret = v4l2_subdev_enable_streams(src_sd, pipe->remote_src->index, BIT(0));
+ if (ret && ret != -EALREADY)
+ return ret;
+
+ mali_c720_fr_pipe_update_resizer_config(pipe, state);
+ if (pad == MALI_C720_FR_PIPE_PAD_SOURCE_YUV)
+ mali_c720_fr_pipe_program_output_formatter(pipe);
+
+ guard(spinlock)(&pipe->resizer_lock);
+ pipe->enabled_crops |= BIT(pad);
+
+ return 0;
+}
+
+static int mali_c720_fr_pipe_disable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state, u32 pad,
+ u64 streams_mask)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720_fr_pipe *pipe =
+ mali_c720_sd_to_sd(mdev, struct mali_c720_fr_pipe);
+ struct v4l2_subdev *src_sd;
+
+ if (pipe->remote_src) {
+ src_sd = media_entity_to_v4l2_subdev(pipe->remote_src->entity);
+ v4l2_subdev_disable_streams(src_sd, pipe->remote_src->index,
+ BIT(0));
+ }
+ pipe->remote_src = NULL;
+
+ guard(spinlock)(&pipe->resizer_lock);
+ pipe->enabled_crops &= ~BIT(pad);
+
+ return 0;
+}
+
+static const struct v4l2_subdev_pad_ops mali_c720_fr_pipe_pad_ops = {
+ .enum_mbus_code = mali_c720_fr_pipe_enum_mbus_code,
+ .enum_frame_size = mali_c720_fr_pipe_enum_frame_size,
+ .get_fmt = v4l2_subdev_get_fmt,
+ .set_fmt = mali_c720_fr_pipe_set_fmt,
+ .get_selection = mali_c720_fr_pipe_get_selection,
+ .set_selection = mali_c720_fr_pipe_set_selection,
+ .link_validate = v4l2_subdev_link_validate_default,
+ .enable_streams = mali_c720_fr_pipe_enable_streams,
+ .disable_streams = mali_c720_fr_pipe_disable_streams,
+};
+
+static const struct v4l2_subdev_ops mali_c720_fr_pipe_ops = {
+ .pad = &mali_c720_fr_pipe_pad_ops,
+};
+
+static int mali_c720_fr_pipe_init_state(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state)
+{
+ struct v4l2_mbus_framefmt *sink_fmt, *src_fmt;
+ struct v4l2_rect *out_crop, *in_compose;
+
+ sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SINK_VIDEO);
+ in_compose = v4l2_subdev_state_get_compose(state, MALI_C720_FR_PIPE_PAD_SINK_VIDEO);
+ out_crop = v4l2_subdev_state_get_crop(state, MALI_C720_FR_PIPE_PAD_SOURCE_RGB);
+
+ sink_fmt->width = MALI_C720_DEFAULT_WIDTH;
+ sink_fmt->height = MALI_C720_DEFAULT_HEIGHT;
+ sink_fmt->field = V4L2_FIELD_NONE;
+ sink_fmt->code = MEDIA_BUS_FMT_RGB121212_1X36;
+ sink_fmt->colorspace = V4L2_COLORSPACE_SRGB;
+ sink_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(sink_fmt->colorspace);
+ sink_fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(sink_fmt->colorspace);
+ sink_fmt->quantization =
+ V4L2_MAP_QUANTIZATION_DEFAULT(true, sink_fmt->colorspace,
+ sink_fmt->ycbcr_enc);
+
+ in_compose->top = 0;
+ in_compose->left = 0;
+ in_compose->width = MALI_C720_DEFAULT_WIDTH;
+ in_compose->height = MALI_C720_DEFAULT_HEIGHT;
+
+ *out_crop = *in_compose;
+ *v4l2_subdev_state_get_crop(state, MALI_C720_FR_PIPE_PAD_SOURCE_YUV) = *out_crop;
+
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SOURCE_RGB);
+ src_fmt->width = MALI_C720_DEFAULT_WIDTH;
+ src_fmt->height = MALI_C720_DEFAULT_HEIGHT;
+ src_fmt->field = V4L2_FIELD_NONE;
+ src_fmt->code = MEDIA_BUS_FMT_RGB161616_1X48;
+ src_fmt->colorspace = V4L2_COLORSPACE_SRGB;
+ src_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(src_fmt->colorspace);
+ src_fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(src_fmt->colorspace);
+ src_fmt->quantization =
+ V4L2_MAP_QUANTIZATION_DEFAULT(true, src_fmt->colorspace,
+ src_fmt->ycbcr_enc);
+
+ src_fmt = v4l2_subdev_state_get_format(state, MALI_C720_FR_PIPE_PAD_SOURCE_YUV);
+ src_fmt->width = MALI_C720_DEFAULT_WIDTH;
+ src_fmt->height = MALI_C720_DEFAULT_HEIGHT;
+ src_fmt->field = V4L2_FIELD_NONE;
+ src_fmt->code = MEDIA_BUS_FMT_YUV16_1X48;
+ src_fmt->colorspace = V4L2_COLORSPACE_SRGB;
+ src_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(src_fmt->colorspace);
+ src_fmt->ycbcr_enc = V4L2_YCBCR_ENC_709;
+ src_fmt->quantization =
+ V4L2_MAP_QUANTIZATION_DEFAULT(false, src_fmt->colorspace,
+ src_fmt->ycbcr_enc);
+
+ return 0;
+}
+
+static const struct v4l2_subdev_internal_ops mali_c720_fr_pipe_internal_ops = {
+ .init_state = mali_c720_fr_pipe_init_state,
+};
+
+static int mali_c720_fr_pipe_fetch_discovery_data(struct mali_c720 *mali_c720,
+ struct mali_c720_fr_pipe *pipe)
+{
+ const struct mali_c720_discovery_target crop = {
+ .module_id = MALI_C720_DISC_MODULE_ID_CROP,
+ .pipeline_id = MALI_C720_DISC_PIPE_FR_OUTPUT,
+ };
+ const struct mali_c720_discovery_target scaler = {
+ .module_id = MALI_C720_DISC_MODULE_ID_SCALER_RGB,
+ .pipeline_id = MALI_C720_DISC_PIPE_FR_OUTPUT,
+ };
+ const struct mali_c720_discovery_target output_formatter = {
+ .module_id = MALI_C720_DISC_MODULE_ID_OUTPUT_FORMATTER,
+ .pipeline_id = MALI_C720_DISC_PIPE_FR_OUTPUT,
+ };
+ int ret;
+
+ ret = mali_c720_discovery_get_module_base(mali_c720, &crop, &pipe->crop_base);
+ if (ret)
+ return ret;
+
+ ret = mali_c720_discovery_get_module_base(mali_c720, &scaler,
+ &pipe->scaler_base);
+ if (ret)
+ return ret;
+
+ ret = mali_c720_discovery_get_module_base(mali_c720, &output_formatter,
+ &pipe->output_formatter_base);
+ if (ret)
+ return ret;
+
+ ret = mali_c720_discovery_get_module_table_base(mali_c720, &scaler,
+ MALI_C720_DISC_TABLE_SCALER_RGB_H_MEM_ID,
+ &pipe->scaler_hmem_base);
+ if (ret)
+ return ret;
+
+ ret = mali_c720_discovery_get_module_table_base(mali_c720, &scaler,
+ MALI_C720_DISC_TABLE_SCALER_RGB_V_MEM_ID,
+ &pipe->scaler_vmem_base);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static const struct media_entity_operations mali_c720_fr_pipe_media_ops = {
+ .link_validate = v4l2_subdev_link_validate,
+};
+
+int mali_c720_register_fr_pipe(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_fr_pipe *pipe = &mali_c720->fr_pipe;
+ struct mali_c720_subdev *mdev = &pipe->mdev;
+ struct v4l2_subdev *sd = &mdev->sd;
+ int ret;
+
+ ret = mali_c720_fr_pipe_fetch_discovery_data(mali_c720, pipe);
+ if (ret) {
+ dev_err(mali_c720->dev,
+ "Failed to fetch discovery data for fr 0 pipe: %d\n", ret);
+ return ret;
+ }
+
+ mdev->mali_c720 = mali_c720;
+
+ spin_lock_init(&pipe->resizer_lock);
+ v4l2_subdev_init(sd, &mali_c720_fr_pipe_ops);
+ sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+ sd->entity.ops = &mali_c720_fr_pipe_media_ops;
+ sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_ISP;
+ sd->internal_ops = &mali_c720_fr_pipe_internal_ops;
+ strscpy(sd->name, "mali-c720 fr 0 pipe", sizeof(sd->name));
+
+ pipe->pads[MALI_C720_FR_PIPE_PAD_SINK_VIDEO].flags = MEDIA_PAD_FL_SINK |
+ MEDIA_PAD_FL_MUST_CONNECT;
+ pipe->pads[MALI_C720_FR_PIPE_PAD_SOURCE_RGB].flags = MEDIA_PAD_FL_SOURCE;
+ pipe->pads[MALI_C720_FR_PIPE_PAD_SOURCE_YUV].flags = MEDIA_PAD_FL_SOURCE;
+ ret = media_entity_pads_init(&sd->entity,
+ MALI_C720_FR_PIPE_NUM_PADS,
+ pipe->pads);
+ if (ret)
+ goto err_clear_parent;
+
+ ret = v4l2_subdev_init_finalize(sd);
+ if (ret)
+ goto err_cleanup_media_entity;
+
+ ret = v4l2_device_register_subdev(&mali_c720->v4l2_dev, sd);
+ if (ret)
+ goto err_cleanup_subdev;
+
+ return 0;
+
+err_cleanup_subdev:
+ v4l2_subdev_cleanup(sd);
+err_cleanup_media_entity:
+ media_entity_cleanup(&sd->entity);
+err_clear_parent:
+ mdev->mali_c720 = NULL;
+
+ return ret;
+}
+
+void mali_c720_unregister_fr_pipe(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_fr_pipe *pipe = &mali_c720->fr_pipe;
+ struct mali_c720_subdev *mdev = &pipe->mdev;
+
+ if (!mdev->mali_c720)
+ return;
+
+ v4l2_device_unregister_subdev(&mdev->sd);
+}
+
+void mali_c720_cleanup_fr_pipe(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_fr_pipe *pipe = &mali_c720->fr_pipe;
+ struct mali_c720_subdev *mdev = &pipe->mdev;
+
+ if (!mdev->mali_c720)
+ return;
+
+ v4l2_subdev_cleanup(&mdev->sd);
+ media_entity_cleanup(&mdev->sd.entity);
+ mdev->mali_c720 = NULL;
+}
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 12/24] media: mali-c720: Add video capture nodes
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (10 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 11/24] media: mali-c720: Add full-resolution output subdevice Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 13/24] media: mali-c720: Add Mali-C720 ISP driver Anthony McGivern
` (11 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add RGB and YUV video capture nodes for the full-resolution output 0
(FR0) subdevice. The capture-node implementation can be extended to
support other subdevice outputs in the future, such as raw capture.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../platform/arm/mali-c720/mali-c720-capture.c | 747 +++++++++++++++++++++
.../platform/arm/mali-c720/mali-c720-common.h | 56 ++
.../platform/arm/mali-c720/mali-c720-ctx-mgr.c | 6 +
3 files changed, 809 insertions(+)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-capture.c b/drivers/media/platform/arm/mali-c720/mali-c720-capture.c
new file mode 100644
index 0000000000000000000000000000000000000000..78e9f5aba97d58c6e6aad5451262a34889e25624
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-capture.c
@@ -0,0 +1,747 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/align.h>
+#include <linux/cleanup.h>
+#include <linux/dev_printk.h>
+#include <linux/minmax.h>
+#include <linux/pm_runtime.h>
+#include <linux/string.h>
+
+#include <media/v4l2-common.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-fh.h>
+#include <media/v4l2-ioctl.h>
+#include <media/videobuf2-dma-contig.h>
+
+#include "mali-c720-common.h"
+
+static const char * const capture_device_names[] = {
+ "mali-c720 fr0-rgb",
+ "mali-c720 fr0-yuv",
+};
+
+static int mali_c720_link_validate(struct media_link *link)
+{
+ struct video_device *vdev =
+ media_entity_to_video_device(link->sink->entity);
+ struct mali_c720_cap_dev *cap_dev = video_get_drvdata(vdev);
+ struct v4l2_subdev *sd =
+ media_entity_to_v4l2_subdev(link->source->entity);
+ const struct v4l2_pix_format_mplane *pix_mp;
+ const struct mali_c720_v4l2_format_info *cap_fmt;
+ int ret;
+
+ struct v4l2_subdev_format sd_fmt = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ .pad = link->source->index,
+ };
+
+ ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &sd_fmt);
+ if (ret)
+ return ret;
+
+ pix_mp = &cap_dev->format.pix_mp;
+ cap_fmt = cap_dev->format.info;
+
+ if (sd_fmt.format.width != pix_mp->width ||
+ sd_fmt.format.height != pix_mp->height) {
+ dev_err(cap_dev->mali_c720->dev,
+ "link '%s':%u -> '%s':%u not valid: %ux%u != %ux%u\n",
+ link->source->entity->name, link->source->index,
+ link->sink->entity->name, link->sink->index,
+ sd_fmt.format.width, sd_fmt.format.height,
+ pix_mp->width, pix_mp->height);
+ return -EPIPE;
+ }
+
+ if (!mali_c720_mbus_code_supports_fmt(cap_fmt, sd_fmt.format.code)) {
+ dev_err(cap_dev->mali_c720->dev,
+ "link '%s':%u -> '%s':%u not valid: mbus_code 0x%04x cannot produce pixel format %p4cc\n",
+ link->source->entity->name, link->source->index,
+ link->sink->entity->name, link->sink->index,
+ sd_fmt.format.code, &pix_mp->pixelformat);
+ return -EPIPE;
+ }
+
+ return 0;
+}
+
+static const struct media_entity_operations mali_c720_media_ops = {
+ .link_validate = mali_c720_link_validate,
+};
+
+static int mali_c720_vb2_queue_setup(struct vb2_queue *q, unsigned int *num_buffers,
+ unsigned int *num_planes, unsigned int sizes[],
+ struct device *alloc_devs[])
+{
+ struct mali_c720_cap_dev *cap_dev = q->drv_priv;
+ unsigned int i;
+
+ if (*num_planes) {
+ if (*num_planes != cap_dev->format.pix_mp.num_planes)
+ return -EINVAL;
+
+ for (i = 0; i < cap_dev->format.pix_mp.num_planes; i++)
+ if (sizes[i] < cap_dev->format.pix_mp.plane_fmt[i].sizeimage)
+ return -EINVAL;
+ } else {
+ *num_planes = cap_dev->format.pix_mp.num_planes;
+ for (i = 0; i < cap_dev->format.pix_mp.num_planes; i++)
+ sizes[i] = cap_dev->format.pix_mp.plane_fmt[i].sizeimage;
+ }
+
+ return 0;
+}
+
+static void mali_c720_buf_queue(struct vb2_buffer *vb)
+{
+ struct mali_c720_cap_dev *cap_dev = vb2_get_drv_priv(vb->vb2_queue);
+ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+ struct mali_c720_cap_buffer *buf = container_of(vbuf,
+ struct mali_c720_cap_buffer, vb);
+ unsigned int i;
+
+ for (i = 0; i < cap_dev->format.pix_mp.num_planes; i++) {
+ unsigned long size = cap_dev->format.pix_mp.plane_fmt[i].sizeimage;
+
+ vb2_set_plane_payload(vb, i, size);
+ }
+
+ buf->vb.field = V4L2_FIELD_NONE;
+
+ scoped_guard(spinlock, &cap_dev->buffers.lock)
+ list_add_tail(&buf->queue, &cap_dev->buffers.input);
+}
+
+static int mali_c720_buf_init(struct vb2_buffer *vb)
+{
+ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+ struct mali_c720_cap_buffer *buf = container_of(vbuf,
+ struct mali_c720_cap_buffer, vb);
+
+ buf->addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+ if (!IS_ALIGNED(buf->addr, 32)) {
+ dev_dbg(vb->vb2_queue->dev,
+ "Capture buffer DMA address is not 32-byte aligned\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void mali_c720_buf_request_complete(struct vb2_buffer *vb)
+{
+}
+
+bool mali_c720_cap_dev_uses_requests(struct mali_c720_cap_dev *cap_dev)
+{
+ return video_is_registered(&cap_dev->vdev) &&
+ vb2_is_streaming(&cap_dev->queue) &&
+ cap_dev->queue.uses_requests;
+}
+
+struct media_request *mali_c720_cap_dev_get_request(struct mali_c720_cap_dev *cap_dev)
+{
+ struct mali_c720_cap_buffer *buf;
+
+ if (!mali_c720_cap_dev_uses_requests(cap_dev))
+ return NULL;
+
+ guard(spinlock)(&cap_dev->buffers.lock);
+
+ buf = list_first_entry_or_null(&cap_dev->buffers.input,
+ struct mali_c720_cap_buffer, queue);
+
+ return buf ? buf->vb.vb2_buf.request : NULL;
+}
+
+int mali_c720_cap_dev_is_ready(struct mali_c720_cap_dev *cap_dev)
+{
+ struct mali_c720_cap_buffer *buf;
+
+ if (!video_is_registered(&cap_dev->vdev))
+ return -ENODEV;
+
+ if (!vb2_is_streaming(&cap_dev->queue))
+ return -ENODEV;
+
+ scoped_guard(spinlock, &cap_dev->buffers.lock) {
+ buf = list_first_entry_or_null(&cap_dev->buffers.input,
+ struct mali_c720_cap_buffer, queue);
+
+ if (!buf)
+ return -ENOENT;
+ }
+
+ return 0;
+}
+
+void mali_c720_cap_dev_set_next_buffer(struct mali_c720_cap_dev *cap_dev,
+ struct media_request *req)
+{
+ struct mali_c720 *mali_c720 = cap_dev->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_buffer_pool *pool = &cap_dev->buffers.pool;
+ struct mali_c720_cap_buffer *buf;
+
+ if (!video_is_registered(&cap_dev->vdev))
+ return;
+
+ if (!vb2_is_streaming(&cap_dev->queue))
+ return;
+
+ scoped_guard(spinlock, &cap_dev->buffers.lock) {
+ buf = list_first_entry_or_null(&cap_dev->buffers.input,
+ struct mali_c720_cap_buffer, queue);
+
+ if (buf && (!buf->vb.vb2_buf.request ||
+ buf->vb.vb2_buf.request == req)) {
+ mali_c720_ctx_mgr_update_buffer(ctx, pool, &buf->addr, 0);
+ list_move_tail(&buf->queue, &cap_dev->buffers.processing);
+ return;
+ }
+ }
+
+ mali_c720_ctx_mgr_update_buffer(ctx, pool, NULL, 0);
+}
+
+void mali_c720_cap_dev_buffer_done(struct mali_c720_cap_dev *cap_dev,
+ bool success)
+{
+ struct mali_c720 *mali_c720 = cap_dev->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_cap_buffer *buf;
+
+ if (!video_is_registered(&cap_dev->vdev))
+ return;
+
+ if (!vb2_is_streaming(&cap_dev->queue))
+ return;
+
+ guard(spinlock)(&cap_dev->buffers.lock);
+
+ buf = list_first_entry_or_null(&cap_dev->buffers.processing,
+ struct mali_c720_cap_buffer, queue);
+ if (!buf)
+ return;
+
+ if (mali_c720_ctx_mgr_check_output_buffer_status(ctx, &cap_dev->buffers.pool))
+ success = false;
+
+ if (success) {
+ buf->vb.vb2_buf.timestamp = ctx->timestamp;
+ buf->vb.sequence = ctx->frame_sequence;
+ }
+
+ vb2_buffer_done(&buf->vb.vb2_buf, success ? VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR);
+ list_del(&buf->queue);
+}
+
+static void mali_c720_cap_dev_return_buffers(struct mali_c720_cap_dev *cap_dev,
+ enum vb2_buffer_state state)
+{
+ struct mali_c720_cap_buffer *buf, *tmp;
+
+ guard(spinlock)(&cap_dev->buffers.lock);
+
+ list_for_each_entry_safe(buf, tmp, &cap_dev->buffers.input, queue) {
+ list_del(&buf->queue);
+ vb2_buffer_done(&buf->vb.vb2_buf, state);
+ }
+
+ list_for_each_entry_safe(buf, tmp, &cap_dev->buffers.processing, queue) {
+ list_del(&buf->queue);
+ vb2_buffer_done(&buf->vb.vb2_buf, state);
+ }
+}
+
+static int mali_c720_cap_dev_buffer_pool_configure(struct mali_c720_cap_dev *cap_dev)
+{
+ struct mali_c720 *mali_c720 = cap_dev->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ int ret;
+
+ ret = mali_c720_ctx_mgr_request_buffer_pool(ctx,
+ &cap_dev->format.buffer_request,
+ &cap_dev->buffers.pool);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static void mali_c720_cap_dev_release_buffer_pool(struct mali_c720_cap_dev *cap_dev)
+{
+ struct mali_c720 *mali_c720 = cap_dev->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_buffer_pool *pool = &cap_dev->buffers.pool;
+
+ mali_c720_ctx_mgr_release_buffer_pool(ctx, pool);
+}
+
+static int mali_c720_vb2_start_streaming(struct vb2_queue *q, unsigned int count)
+{
+ struct mali_c720_cap_dev *cap_dev = q->drv_priv;
+ struct mali_c720 *mali_c720 = cap_dev->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ int ret;
+
+ guard(mutex)(&mali_c720->device_lock);
+
+ if (!media_devnode_is_registered(mali_c720->media_dev.devnode)) {
+ ret = -ENODEV;
+ goto err_return_buffers;
+ }
+
+ ret = pm_runtime_resume_and_get(mali_c720->dev);
+ if (ret)
+ goto err_return_buffers;
+
+ ret = video_device_pipeline_start(&cap_dev->vdev, &mali_c720->pipe);
+ if (ret) {
+ dev_err(mali_c720->dev, "%s failed to start media pipeline\n",
+ cap_dev->vdev.name);
+ goto err_pm_put;
+ }
+
+ ret = mali_c720_alloc_context(ctx);
+ if (ret)
+ goto err_stop_video_pipeline;
+
+ ret = mali_c720_cap_dev_buffer_pool_configure(cap_dev);
+ if (ret) {
+ dev_err(mali_c720->dev, "%s failed to request output buffers\n",
+ cap_dev->vdev.name);
+ goto err_free_context;
+ }
+
+ ret = v4l2_subdev_enable_streams(cap_dev->src_sd, cap_dev->src_pad,
+ BIT(0));
+ if (ret && ret != -EALREADY) {
+ dev_err(mali_c720->dev, "%s failed to start src subdev\n",
+ cap_dev->vdev.name);
+ goto err_release_buffer_pool;
+ }
+
+ return 0;
+
+err_release_buffer_pool:
+ mali_c720_cap_dev_release_buffer_pool(cap_dev);
+err_free_context:
+ mali_c720_free_context(ctx);
+err_stop_video_pipeline:
+ video_device_pipeline_stop(&cap_dev->vdev);
+err_pm_put:
+ pm_runtime_put(mali_c720->dev);
+err_return_buffers:
+ mali_c720_cap_dev_return_buffers(cap_dev, VB2_BUF_STATE_QUEUED);
+
+ return ret;
+}
+
+static void mali_c720_vb2_stop_streaming(struct vb2_queue *q)
+{
+ struct mali_c720_cap_dev *cap_dev = q->drv_priv;
+ struct mali_c720 *mali_c720 = cap_dev->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_isp *isp = &mali_c720->isp;
+ struct v4l2_subdev *isp_sd = &isp->mdev.sd;
+
+ guard(mutex)(&mali_c720->device_lock);
+
+ v4l2_subdev_disable_streams(isp_sd, MALI_C720_ISP_PAD_SOURCE_HV,
+ BIT(0));
+ v4l2_subdev_disable_streams(cap_dev->src_sd, cap_dev->src_pad,
+ BIT(0));
+ mali_c720_cap_dev_release_buffer_pool(cap_dev);
+ mali_c720_cap_dev_return_buffers(cap_dev, VB2_BUF_STATE_ERROR);
+
+ mali_c720_free_context(ctx);
+
+ video_device_pipeline_stop(&cap_dev->vdev);
+
+ pm_runtime_put_autosuspend(mali_c720->dev);
+ pm_runtime_mark_last_busy(mali_c720->dev);
+}
+
+static const struct vb2_ops mali_c720_vb2_ops = {
+ .queue_setup = &mali_c720_vb2_queue_setup,
+ .buf_queue = &mali_c720_buf_queue,
+ .buf_init = &mali_c720_buf_init,
+ .start_streaming = &mali_c720_vb2_start_streaming,
+ .stop_streaming = &mali_c720_vb2_stop_streaming,
+ .buf_request_complete = &mali_c720_buf_request_complete,
+};
+
+static const struct v4l2_file_operations mali_c720_v4l2_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = video_ioctl2,
+ .open = v4l2_fh_open,
+ .release = vb2_fop_release,
+ .poll = vb2_fop_poll,
+ .mmap = vb2_fop_mmap,
+};
+
+static void mali_c720_try_fmt(struct mali_c720_cap_dev *cap_dev,
+ struct v4l2_pix_format_mplane *pix_mp)
+{
+ const struct mali_c720_v4l2_format_info *info;
+ const struct mali_c720_mbus_format_info *cfg;
+ struct v4l2_plane_pix_format *plane, *y_plane;
+ u32 requested_stride = pix_mp->plane_fmt[0].bytesperline;
+ unsigned int i;
+
+ info = mali_c720_get_v4l2_config_by_fourcc(pix_mp->pixelformat);
+ if (!info || !mali_c720_format_supported_by_vdev(info, cap_dev->id))
+ info = mali_c720_get_v4l2_config_by_fourcc(cap_dev->format.default_format);
+
+ cfg = mali_c720_get_mbus_config_by_code(info->mbus_code);
+
+ pix_mp->pixelformat = info->fourcc;
+ v4l_bound_align_image(&pix_mp->width, MALI_C720_MIN_OUTPUT_WIDTH,
+ MALI_C720_MAX_WIDTH, 1,
+ &pix_mp->height, MALI_C720_MIN_OUTPUT_HEIGHT,
+ MALI_C720_MAX_HEIGHT, 1, 0);
+
+ pix_mp->field = V4L2_FIELD_NONE;
+ if (cfg->type & (MALI_C720_FORMAT_RGB | MALI_C720_FORMAT_YUV))
+ pix_mp->colorspace = V4L2_COLORSPACE_SRGB;
+ else
+ pix_mp->colorspace = V4L2_COLORSPACE_RAW;
+
+ pix_mp->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(pix_mp->colorspace);
+ if (cfg->type & MALI_C720_FORMAT_YUV)
+ pix_mp->ycbcr_enc = V4L2_YCBCR_ENC_709;
+ else
+ pix_mp->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(pix_mp->colorspace);
+
+ if (pix_mp->colorspace == V4L2_COLORSPACE_RAW)
+ pix_mp->quantization = V4L2_QUANTIZATION_FULL_RANGE;
+ else
+ pix_mp->quantization =
+ V4L2_MAP_QUANTIZATION_DEFAULT(cfg->type & MALI_C720_FORMAT_RGB,
+ pix_mp->colorspace,
+ pix_mp->ycbcr_enc);
+
+ /* Only contiguous multi-planar formats are supported. */
+ pix_mp->num_planes = 1;
+ memset(pix_mp->plane_fmt, 0, sizeof(pix_mp->plane_fmt));
+
+ y_plane = &pix_mp->plane_fmt[0];
+ y_plane->bytesperline = clamp(requested_stride,
+ DIV_ROUND_UP(info->bpp[0] * pix_mp->width, 8),
+ 65504U);
+ y_plane->bytesperline = ALIGN(y_plane->bytesperline, 32);
+ y_plane->sizeimage = y_plane->bytesperline * pix_mp->height;
+
+ for (i = 1; i < info->comp_planes; i++) {
+ plane = &pix_mp->plane_fmt[i];
+
+ plane->bytesperline = y_plane->bytesperline;
+ plane->sizeimage = DIV_ROUND_UP(plane->bytesperline * pix_mp->height,
+ info->vdiv);
+
+ y_plane->sizeimage += plane->sizeimage;
+ }
+}
+
+static int mali_c720_try_fmt_vid_cap_mplane(struct file *file, void *fh,
+ struct v4l2_format *f)
+{
+ struct mali_c720_cap_dev *cap_dev = video_drvdata(file);
+
+ mali_c720_try_fmt(cap_dev, &f->fmt.pix_mp);
+ return 0;
+}
+
+static void mali_c720_set_format(struct mali_c720_cap_dev *cap_dev,
+ struct v4l2_pix_format_mplane *pix_mp)
+{
+ struct mali_c720_buffer_request_info *req = &cap_dev->format.buffer_request;
+ const struct mali_c720_v4l2_format_info *info;
+ unsigned int i;
+
+ mali_c720_try_fmt(cap_dev, pix_mp);
+
+ cap_dev->format.pix_mp = *pix_mp;
+ cap_dev->format.info = mali_c720_get_v4l2_config_by_fourcc(pix_mp->pixelformat);
+ info = cap_dev->format.info;
+
+ memset(req, 0, sizeof(*req));
+ req->type = MALI_C720_BUF_TYPE_OUT;
+ req->sub_type = cap_dev->id;
+ req->width = pix_mp->width;
+ req->height = pix_mp->height;
+
+ req->line_offset[0] = pix_mp->plane_fmt[0].bytesperline;
+ req->plane_size[0] = pix_mp->plane_fmt[0].bytesperline * pix_mp->height;
+ for (i = 1; i < info->comp_planes; i++) {
+ req->line_offset[i] = pix_mp->plane_fmt[i].bytesperline;
+ req->plane_size[i] = pix_mp->plane_fmt[i].sizeimage;
+ }
+
+ req->num_out_planes = info->comp_planes;
+ req->buffer_cfg = info->buffer_cfg;
+}
+
+static int mali_c720_s_fmt_vid_cap_mplane(struct file *file, void *fh,
+ struct v4l2_format *f)
+{
+ struct mali_c720_cap_dev *cap_dev = video_drvdata(file);
+
+ if (media_entity_is_streaming(&cap_dev->vdev.entity))
+ return -EBUSY;
+
+ if (vb2_is_busy(&cap_dev->queue))
+ return -EBUSY;
+
+ mali_c720_set_format(cap_dev, &f->fmt.pix_mp);
+ return 0;
+}
+
+static int mali_c720_g_fmt_vid_cap_mplane(struct file *file, void *fh,
+ struct v4l2_format *f)
+{
+ struct mali_c720_cap_dev *cap_dev = video_drvdata(file);
+
+ f->fmt.pix_mp = cap_dev->format.pix_mp;
+
+ return 0;
+}
+
+static int mali_c720_enum_fmt_vid_cap_mplane(struct file *file, void *fh,
+ struct v4l2_fmtdesc *f)
+{
+ struct mali_c720_cap_dev *cap_dev = video_drvdata(file);
+ const struct mali_c720_v4l2_format_info *info;
+ struct mali_c720_v4l2_format_match match;
+
+ match.dev_id = cap_dev->id;
+ match.mbus_code = f->mbus_code;
+
+ info = mali_c720_get_v4l2_config_by_matched_index(f->index, &match);
+ if (info) {
+ f->pixelformat = info->fourcc;
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+static int mali_c720_enum_framesizes(struct file *file, void *fh,
+ struct v4l2_frmsizeenum *fsize)
+{
+ struct mali_c720_cap_dev *cap_dev = video_drvdata(file);
+ const struct mali_c720_v4l2_format_info *info;
+
+ if (fsize->index)
+ return -EINVAL;
+
+ info = mali_c720_get_v4l2_config_by_fourcc(fsize->pixel_format);
+ if (!info || !mali_c720_format_supported_by_vdev(info, cap_dev->id))
+ return -EINVAL;
+
+ fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
+ fsize->stepwise.min_width = MALI_C720_MIN_OUTPUT_WIDTH;
+ fsize->stepwise.max_width = MALI_C720_MAX_WIDTH;
+ fsize->stepwise.step_width = 2;
+ fsize->stepwise.min_height = MALI_C720_MIN_OUTPUT_HEIGHT;
+ fsize->stepwise.max_height = MALI_C720_MAX_HEIGHT;
+ fsize->stepwise.step_height = 2;
+
+ return 0;
+}
+
+static int mali_c720_querycap(struct file *file, void *fh,
+ struct v4l2_capability *cap)
+{
+ strscpy(cap->driver, MALI_C720_DRIVER_NAME, sizeof(cap->driver));
+ strscpy(cap->card, "ARM Mali-C720 ISP", sizeof(cap->card));
+
+ return 0;
+}
+
+static const struct v4l2_ioctl_ops mali_c720_v4l2_ioctl_ops = {
+ .vidioc_reqbufs = vb2_ioctl_reqbufs,
+ .vidioc_querybuf = vb2_ioctl_querybuf,
+ .vidioc_create_bufs = vb2_ioctl_create_bufs,
+ .vidioc_qbuf = vb2_ioctl_qbuf,
+ .vidioc_expbuf = vb2_ioctl_expbuf,
+ .vidioc_dqbuf = vb2_ioctl_dqbuf,
+ .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+ .vidioc_streamon = vb2_ioctl_streamon,
+ .vidioc_streamoff = vb2_ioctl_streamoff,
+ .vidioc_try_fmt_vid_cap_mplane = mali_c720_try_fmt_vid_cap_mplane,
+ .vidioc_s_fmt_vid_cap_mplane = mali_c720_s_fmt_vid_cap_mplane,
+ .vidioc_g_fmt_vid_cap_mplane = mali_c720_g_fmt_vid_cap_mplane,
+ .vidioc_enum_fmt_vid_cap = mali_c720_enum_fmt_vid_cap_mplane,
+ .vidioc_enum_framesizes = mali_c720_enum_framesizes,
+ .vidioc_querycap = mali_c720_querycap,
+ .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
+ .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+};
+
+static int mali_c720_register_cap_dev(struct mali_c720 *mali_c720,
+ enum mali_c720_cap_devs cap_dev_id)
+{
+ struct mali_c720_cap_dev *cap_dev = &mali_c720->cap_devs[cap_dev_id];
+ struct v4l2_pix_format_mplane pix_mp;
+ struct video_device *vdev;
+ struct vb2_queue *vb2q;
+ int ret;
+
+ vdev = &cap_dev->vdev;
+ vb2q = &cap_dev->queue;
+
+ cap_dev->id = cap_dev_id;
+ cap_dev->mali_c720 = mali_c720;
+ mutex_init(&cap_dev->lock);
+ INIT_LIST_HEAD(&cap_dev->buffers.input);
+ INIT_LIST_HEAD(&cap_dev->buffers.processing);
+ spin_lock_init(&cap_dev->buffers.lock);
+
+ memset(&pix_mp, 0, sizeof(pix_mp));
+
+ pix_mp.width = MALI_C720_DEFAULT_WIDTH;
+ pix_mp.height = MALI_C720_DEFAULT_HEIGHT;
+
+ switch (cap_dev->id) {
+ case MALI_C720_CAP_DEV_FR0_RGB:
+ cap_dev->src_sd =
+ &mali_c720->fr_pipe.mdev.sd;
+ cap_dev->src_pad = MALI_C720_FR_PIPE_PAD_SOURCE_RGB;
+ cap_dev->format.default_format = V4L2_PIX_FMT_RGB24;
+ break;
+ case MALI_C720_CAP_DEV_FR0_YUV:
+ cap_dev->src_sd =
+ &mali_c720->fr_pipe.mdev.sd;
+ cap_dev->src_pad = MALI_C720_FR_PIPE_PAD_SOURCE_YUV;
+ cap_dev->format.default_format = V4L2_PIX_FMT_NV12;
+ break;
+ default:
+ dev_warn_once(mali_c720->dev,
+ "Invalid capture device id %u\n", cap_dev->id);
+ ret = -EINVAL;
+ goto err_destroy_mutex;
+ }
+
+ cap_dev->pad.flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
+ ret = media_entity_pads_init(&cap_dev->vdev.entity, 1, &cap_dev->pad);
+ if (ret)
+ goto err_destroy_mutex;
+
+ vb2q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
+ vb2q->io_modes = VB2_MMAP | VB2_DMABUF;
+ vb2q->drv_priv = cap_dev;
+ vb2q->mem_ops = &vb2_dma_contig_memops;
+ vb2q->ops = &mali_c720_vb2_ops;
+ vb2q->buf_struct_size = sizeof(struct mali_c720_cap_buffer);
+ vb2q->min_queued_buffers = 0;
+ vb2q->supports_requests = 1;
+ vb2q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC |
+ V4L2_BUF_FLAG_TSTAMP_SRC_SOE;
+ vb2q->lock = &cap_dev->lock;
+ vb2q->dev = mali_c720->dev;
+
+ ret = vb2_queue_init(vb2q);
+ if (ret) {
+ dev_err(mali_c720->dev, "%s vb2 queue init failed\n",
+ cap_dev->vdev.name);
+ goto err_cleanup_media_entity;
+ }
+
+ strscpy(cap_dev->vdev.name, capture_device_names[cap_dev_id],
+ sizeof(cap_dev->vdev.name));
+ vdev->release = video_device_release_empty;
+ vdev->fops = &mali_c720_v4l2_fops;
+ vdev->ioctl_ops = &mali_c720_v4l2_ioctl_ops;
+ vdev->lock = &cap_dev->lock;
+ vdev->v4l2_dev = &mali_c720->v4l2_dev;
+ vdev->queue = &cap_dev->queue;
+ vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE |
+ V4L2_CAP_STREAMING | V4L2_CAP_IO_MC;
+ vdev->entity.ops = &mali_c720_media_ops;
+ video_set_drvdata(vdev, cap_dev);
+
+ pix_mp.pixelformat = cap_dev->format.default_format;
+ mali_c720_set_format(cap_dev, &pix_mp);
+
+ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
+ if (ret) {
+ dev_err(mali_c720->dev,
+ "%s failed to register video device\n",
+ cap_dev->vdev.name);
+ goto err_release_vb2q;
+ }
+
+ return 0;
+
+err_release_vb2q:
+ vb2_queue_release(vb2q);
+err_cleanup_media_entity:
+ media_entity_cleanup(&cap_dev->vdev.entity);
+err_destroy_mutex:
+ mutex_destroy(&cap_dev->lock);
+ cap_dev->mali_c720 = NULL;
+
+ return ret;
+}
+
+int mali_c720_register_capture_devs(struct mali_c720 *mali_c720)
+{
+ unsigned int i;
+ int ret;
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
+ ret = mali_c720_register_cap_dev(mali_c720, i);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static void mali_c720_unregister_cap_dev(struct mali_c720 *mali_c720,
+ enum mali_c720_cap_devs cap_dev_id)
+{
+ struct mali_c720_cap_dev *cap_dev = &mali_c720->cap_devs[cap_dev_id];
+
+ if (!video_is_registered(&cap_dev->vdev))
+ return;
+
+ vb2_video_unregister_device(&cap_dev->vdev);
+}
+
+static void mali_c720_cleanup_cap_dev(struct mali_c720 *mali_c720,
+ enum mali_c720_cap_devs cap_dev_id)
+{
+ struct mali_c720_cap_dev *cap_dev = &mali_c720->cap_devs[cap_dev_id];
+
+ if (!cap_dev->mali_c720)
+ return;
+
+ media_entity_cleanup(&cap_dev->vdev.entity);
+ mutex_destroy(&cap_dev->lock);
+ cap_dev->mali_c720 = NULL;
+}
+
+void mali_c720_unregister_capture_devs(struct mali_c720 *mali_c720)
+{
+ unsigned int i;
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++)
+ mali_c720_unregister_cap_dev(mali_c720, i);
+}
+
+void mali_c720_cleanup_capture_devs(struct mali_c720 *mali_c720)
+{
+ unsigned int i;
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++)
+ mali_c720_cleanup_cap_dev(mali_c720, i);
+}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index ca7e04ef27a6ae3c4b41144de579c668255bfcaa..30aae3d8bed8c9e80b417941e8dce5c6e7275d7d 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -10,13 +10,19 @@
#include <linux/io.h>
#include <linux/kfifo.h>
+#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/refcount.h>
#include <linux/spinlock.h>
#include <linux/videodev2.h>
+#include <media/media-device.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-dev.h>
#include <media/v4l2-device.h>
#include <media/v4l2-subdev.h>
+#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
#include "mali-c720-ctx-mgr.h"
#include "mali-c720-discovery.h"
@@ -29,6 +35,8 @@
#include "mali-c720-registers-ctx-mgr.h"
#include "mali-c720-registers-modules.h"
+#define MALI_C720_DRIVER_NAME "mali-c720"
+
#define MALI_C720_MIN_INPUT_WIDTH 256
#define MALI_C720_MIN_INPUT_HEIGHT 256
#define MALI_C720_MIN_OUTPUT_WIDTH 64
@@ -145,6 +153,39 @@ enum mali_c720_cap_devs {
MALI_C720_MAX_NUM_CAP_DEVS,
};
+struct mali_c720_cap_buffer {
+ struct vb2_v4l2_buffer vb;
+ struct list_head queue;
+ dma_addr_t addr;
+};
+
+struct mali_c720_cap_dev {
+ unsigned int id;
+ struct mali_c720 *mali_c720;
+ struct v4l2_subdev *src_sd;
+ u32 src_pad;
+ struct video_device vdev;
+ struct media_pad pad;
+ struct vb2_queue queue;
+ /* Mutex to provide to vb2 */
+ struct mutex lock;
+
+ struct {
+ const struct mali_c720_v4l2_format_info *info;
+ struct v4l2_pix_format_mplane pix_mp;
+ struct mali_c720_buffer_request_info buffer_request;
+ u32 default_format;
+ } format;
+
+ struct {
+ /* Spinlock to guard buffer queue */
+ spinlock_t lock;
+ struct list_head input;
+ struct list_head processing;
+ struct mali_c720_buffer_pool pool;
+ } buffers;
+};
+
struct mali_c720_context_regs {
dma_addr_t dma_handle;
u8 *base;
@@ -193,12 +234,15 @@ struct mali_c720 {
resource_size_t mmio_size;
u32 top_base;
+ struct media_device media_dev;
struct v4l2_device v4l2_dev;
+ struct media_pipeline pipe;
struct mali_c720_input input;
struct mali_c720_isp isp;
struct mali_c720_vision_pipe vision_pipe;
struct mali_c720_fr_pipe fr_pipe;
+ struct mali_c720_cap_dev cap_devs[MALI_C720_MAX_NUM_CAP_DEVS];
struct mali_c720_registers registers;
u8 *default_regs;
@@ -236,8 +280,20 @@ int mali_c720_register_fr_pipe(struct mali_c720 *mali_c720);
void mali_c720_unregister_fr_pipe(struct mali_c720 *mali_c720);
void mali_c720_cleanup_fr_pipe(struct mali_c720 *mali_c720);
+int mali_c720_register_capture_devs(struct mali_c720 *mali_c720);
+void mali_c720_unregister_capture_devs(struct mali_c720 *mali_c720);
+void mali_c720_cleanup_capture_devs(struct mali_c720 *mali_c720);
+
void mali_c720_fr_pipe_apply_resizer_config(struct mali_c720_fr_pipe *pipe);
+bool mali_c720_cap_dev_uses_requests(struct mali_c720_cap_dev *cap_dev);
+struct media_request *mali_c720_cap_dev_get_request(struct mali_c720_cap_dev *cap_dev);
+int mali_c720_cap_dev_is_ready(struct mali_c720_cap_dev *cap_dev);
+void mali_c720_cap_dev_set_next_buffer(struct mali_c720_cap_dev *cap_dev,
+ struct media_request *req);
+void mali_c720_cap_dev_buffer_done(struct mali_c720_cap_dev *cap_dev,
+ bool success);
+
void mali_c720_isp_queue_event_sof(struct mali_c720 *mali_c720, u32 sequence);
#endif /* MALI_C720_COMMON_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
index 828a993c5da63619f6fbb99d28532846f969d663..9391b087f74eed7dbf7f3bc1e2abbe5f8969fe86 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
@@ -1266,7 +1266,13 @@ void mali_c720_ctx_mgr_prepare_frame(struct mali_c720_context *ctx)
void mali_c720_ctx_mgr_buffer_done(struct mali_c720_context *ctx, bool success)
{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ unsigned int i;
+
lockdep_assert_held(&ctx->state_lock);
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++)
+ mali_c720_cap_dev_buffer_done(&mali_c720->cap_devs[i], success);
}
void mali_c720_ctx_mgr_handle_sw_ready(struct mali_c720_context *ctx)
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 13/24] media: mali-c720: Add Mali-C720 ISP driver
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (11 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 12/24] media: mali-c720: Add video capture nodes Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 14/24] media: mali-c720: Add test pattern generator subdevices Anthony McGivern
` (10 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Integrate hardware identification, capability discovery, context
management and the V4L2 subdevices into a functional Mali-C720 ISP
driver. Add device probing, power management, media graph registration
and frame scheduling.
Add Kconfig and Makefile integration to build the driver. The preceding
commits introduce its components but do not build them.
Initial support covers the human vision (HV) pipeline with one
full-resolution output pipeline providing RGB and YUV capture nodes.
Support for computer vision (CV) and additional output pipelines will
be added in the future.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
drivers/media/platform/arm/Kconfig | 1 +
drivers/media/platform/arm/Makefile | 1 +
drivers/media/platform/arm/mali-c720/Kconfig | 17 +
drivers/media/platform/arm/mali-c720/Makefile | 20 +
.../platform/arm/mali-c720/mali-c720-capture.c | 30 +-
.../platform/arm/mali-c720/mali-c720-common.h | 26 +
.../media/platform/arm/mali-c720/mali-c720-core.c | 873 +++++++++++++++++++++
.../platform/arm/mali-c720/mali-c720-interrupts.c | 2 +
8 files changed, 969 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/arm/Kconfig b/drivers/media/platform/arm/Kconfig
index 4f0764c329c745e01456958cdbcc65bd888dce4f..90b7818cb95bf360f8ee4ddd9815badeb1c7020e 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-c720/Kconfig"
diff --git a/drivers/media/platform/arm/Makefile b/drivers/media/platform/arm/Makefile
index 8cc4918725efae5d998d9397ac60297b1d734506..09732f2ec8f1dcf1351af123bd85cb007b3ee378 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-c720/
diff --git a/drivers/media/platform/arm/mali-c720/Kconfig b/drivers/media/platform/arm/mali-c720/Kconfig
new file mode 100644
index 0000000000000000000000000000000000000000..576b619fe06c9b96115eeb825f5e8130d9f67395
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/Kconfig
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config VIDEO_MALI_C720
+ tristate "ARM Mali-C720 Image Signal Processor driver"
+ depends on V4L_PLATFORM_DRIVERS
+ depends on VIDEO_DEV && OF
+ select CRC_CCITT
+ select CRC_ITU_T
+ select MEDIA_CONTROLLER
+ select V4L2_FWNODE
+ select VIDEO_V4L2_SUBDEV_API
+ select VIDEOBUF2_DMA_CONTIG
+ select VIDEOBUF2_VMALLOC
+ help
+ Enable this to support Arm's Mali-C720 Image Signal Processor.
+
+ To compile this driver as a module, choose M here: the module
+ will be called mali-c720.
diff --git a/drivers/media/platform/arm/mali-c720/Makefile b/drivers/media/platform/arm/mali-c720/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..31f91d2a0f747bebda2f5584282f8923d4816160
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/Makefile
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+mali-c720-y := mali-c720-capture.o \
+ mali-c720-core.o \
+ mali-c720-ctx-mgr.o \
+ mali-c720-discovery.o \
+ mali-c720-formats.o \
+ mali-c720-fr-pipe.o \
+ mali-c720-id.o \
+ mali-c720-input.o \
+ mali-c720-interrupts.o \
+ mali-c720-isp.o \
+ mali-c720-register-access.o \
+ mali-c720-registers.o \
+ mali-c720-registers-top.o \
+ mali-c720-registers-ctx-mgr.o \
+ mali-c720-registers-modules.o \
+ mali-c720-vision-pipe.o \
+
+obj-$(CONFIG_VIDEO_MALI_C720) += mali-c720.o
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-capture.c b/drivers/media/platform/arm/mali-c720/mali-c720-capture.c
index 78e9f5aba97d58c6e6aad5451262a34889e25624..ef69901730b4ec2669ed0f6c73f72eddb33390b3 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-capture.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-capture.c
@@ -101,6 +101,8 @@ static int mali_c720_vb2_queue_setup(struct vb2_queue *q, unsigned int *num_buff
static void mali_c720_buf_queue(struct vb2_buffer *vb)
{
struct mali_c720_cap_dev *cap_dev = vb2_get_drv_priv(vb->vb2_queue);
+ struct mali_c720 *mali_c720 = cap_dev->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct mali_c720_cap_buffer *buf = container_of(vbuf,
struct mali_c720_cap_buffer, vb);
@@ -116,6 +118,9 @@ static void mali_c720_buf_queue(struct vb2_buffer *vb)
scoped_guard(spinlock, &cap_dev->buffers.lock)
list_add_tail(&buf->queue, &cap_dev->buffers.input);
+
+ if (!mali_c720_cap_dev_uses_requests(cap_dev))
+ mali_c720_try_schedule_frame(ctx);
}
static int mali_c720_buf_init(struct vb2_buffer *vb)
@@ -289,6 +294,7 @@ static int mali_c720_vb2_start_streaming(struct vb2_queue *q, unsigned int count
struct mali_c720_cap_dev *cap_dev = q->drv_priv;
struct mali_c720 *mali_c720 = cap_dev->mali_c720;
struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct v4l2_subdev *isp_sd = &mali_c720->isp.mdev.sd;
int ret;
guard(mutex)(&mali_c720->device_lock);
@@ -328,8 +334,30 @@ static int mali_c720_vb2_start_streaming(struct vb2_queue *q, unsigned int count
goto err_release_buffer_pool;
}
+ /*
+ * All ISP source pads use the same start process, so the HV pad can
+ * represent the ISP when starting the pipeline.
+ */
+ ret = mali_c720_pipeline_ready(mali_c720);
+ if (ret && ret != -EAGAIN)
+ goto err_disable_src;
+
+ if (!ret) {
+ ret = v4l2_subdev_enable_streams(isp_sd,
+ MALI_C720_ISP_PAD_SOURCE_HV,
+ BIT(0));
+ if (ret) {
+ dev_err(mali_c720->dev, "%s failed to start ISP subdevice\n",
+ cap_dev->vdev.name);
+ goto err_disable_src;
+ }
+ }
+
return 0;
+err_disable_src:
+ v4l2_subdev_disable_streams(cap_dev->src_sd, cap_dev->src_pad,
+ BIT(0));
err_release_buffer_pool:
mali_c720_cap_dev_release_buffer_pool(cap_dev);
err_free_context:
@@ -574,7 +602,7 @@ static const struct v4l2_ioctl_ops mali_c720_v4l2_ioctl_ops = {
.vidioc_expbuf = vb2_ioctl_expbuf,
.vidioc_dqbuf = vb2_ioctl_dqbuf,
.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
- .vidioc_streamon = vb2_ioctl_streamon,
+ .vidioc_streamon = mali_c720_streamon,
.vidioc_streamoff = vb2_ioctl_streamoff,
.vidioc_try_fmt_vid_cap_mplane = mali_c720_try_fmt_vid_cap_mplane,
.vidioc_s_fmt_vid_cap_mplane = mali_c720_s_fmt_vid_cap_mplane,
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 30aae3d8bed8c9e80b417941e8dce5c6e7275d7d..0f0ad7d9dcccfce13f673f3602f79d5162eb04ad 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -8,15 +8,18 @@
#ifndef MALI_C720_COMMON_H
#define MALI_C720_COMMON_H
+#include <linux/clk.h>
#include <linux/io.h>
#include <linux/kfifo.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/refcount.h>
+#include <linux/reset.h>
#include <linux/spinlock.h>
#include <linux/videodev2.h>
#include <media/media-device.h>
+#include <media/v4l2-async.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-dev.h>
#include <media/v4l2-device.h>
@@ -186,6 +189,18 @@ struct mali_c720_cap_dev {
} buffers;
};
+struct mali_c720_request {
+ struct media_request req;
+ unsigned int queue_sequence;
+ bool submitted;
+};
+
+static inline struct mali_c720_request *
+to_mali_c720_request(struct media_request *req)
+{
+ return container_of(req, struct mali_c720_request, req);
+}
+
struct mali_c720_context_regs {
dma_addr_t dma_handle;
u8 *base;
@@ -233,9 +248,12 @@ struct mali_c720 {
u8 __iomem *base;
resource_size_t mmio_size;
u32 top_base;
+ struct clk *clk;
+ struct reset_control *reset;
struct media_device media_dev;
struct v4l2_device v4l2_dev;
+ struct v4l2_async_notifier notifier;
struct media_pipeline pipe;
struct mali_c720_input input;
@@ -244,6 +262,8 @@ struct mali_c720 {
struct mali_c720_fr_pipe fr_pipe;
struct mali_c720_cap_dev cap_devs[MALI_C720_MAX_NUM_CAP_DEVS];
+ unsigned int num_async_endpoints;
+
struct mali_c720_registers registers;
u8 *default_regs;
@@ -296,4 +316,10 @@ void mali_c720_cap_dev_buffer_done(struct mali_c720_cap_dev *cap_dev,
void mali_c720_isp_queue_event_sof(struct mali_c720 *mali_c720, u32 sequence);
+int mali_c720_pipeline_ready(struct mali_c720 *mali_c720);
+
+int mali_c720_streamon(struct file *file, void *priv, enum v4l2_buf_type type);
+
+void mali_c720_try_schedule_frame(struct mali_c720_context *ctx);
+
#endif /* MALI_C720_COMMON_H */
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-core.c b/drivers/media/platform/arm/mali-c720/mali-c720-core.c
new file mode 100644
index 0000000000000000000000000000000000000000..2a46e7b348910303d9284a8ce6214953993a7f81
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-core.c
@@ -0,0 +1,873 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/ioport.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/property.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include <media/media-devnode.h>
+#include <media/media-entity.h>
+#include <media/v4l2-mc.h>
+#include <media/videobuf2-dma-contig.h>
+
+#include "mali-c720-common.h"
+
+static void mali_c720_remove_links(struct mali_c720 *mali_c720)
+{
+ struct v4l2_subdev *input_sd = &mali_c720->input.mdev.sd;
+ struct v4l2_subdev *isp_sd = &mali_c720->isp.mdev.sd;
+ struct v4l2_subdev *hv_sd = &mali_c720->vision_pipe.mdev.sd;
+ struct v4l2_subdev *fr_sd = &mali_c720->fr_pipe.mdev.sd;
+ unsigned int i;
+
+ media_entity_remove_links(&input_sd->entity);
+ media_entity_remove_links(&isp_sd->entity);
+ media_entity_remove_links(&hv_sd->entity);
+ media_entity_remove_links(&fr_sd->entity);
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++)
+ media_entity_remove_links(&mali_c720->cap_devs[i].vdev.entity);
+}
+
+static int mali_c720_create_isp_input_links(struct mali_c720 *mali_c720)
+{
+ struct v4l2_subdev *input_sd = &mali_c720->input.mdev.sd;
+ struct v4l2_subdev *isp_sd = &mali_c720->isp.mdev.sd;
+ int ret;
+
+ ret = media_create_pad_link(&input_sd->entity,
+ MALI_C720_INPUT_PAD_SOURCE_SLOT_INPUT,
+ &isp_sd->entity,
+ MALI_C720_ISP_PAD_SINK_VIDEO,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret)
+ dev_err(mali_c720->dev, "failed to link input and ISP sink\n");
+
+ return ret;
+}
+
+static int mali_c720_create_vision_pipe_links(struct mali_c720 *mali_c720)
+{
+ struct v4l2_subdev *isp_sd = &mali_c720->isp.mdev.sd;
+ struct v4l2_subdev *hv_sd = &mali_c720->vision_pipe.mdev.sd;
+ int ret;
+
+ ret = media_create_pad_link(&isp_sd->entity,
+ MALI_C720_ISP_PAD_SOURCE_HV,
+ &hv_sd->entity,
+ MALI_C720_VISION_PIPE_PAD_SINK_VIDEO,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret)
+ dev_err(mali_c720->dev, "failed to link ISP and HV pipe\n");
+
+ return ret;
+}
+
+static int mali_c720_create_fr_pipe_links(struct mali_c720 *mali_c720)
+{
+ struct v4l2_subdev *hv_sd = &mali_c720->vision_pipe.mdev.sd;
+ struct v4l2_subdev *fr_sd = &mali_c720->fr_pipe.mdev.sd;
+ int ret;
+
+ ret = media_create_pad_link(&hv_sd->entity, MALI_C720_VISION_PIPE_PAD_SOURCE_RGB,
+ &fr_sd->entity, MALI_C720_FR_PIPE_PAD_SINK_VIDEO,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret) {
+ dev_err(mali_c720->dev, "failed to link HV and FR pipe\n");
+ return ret;
+ }
+
+ ret = media_create_pad_link(&fr_sd->entity,
+ MALI_C720_FR_PIPE_PAD_SOURCE_RGB,
+ &mali_c720->cap_devs[MALI_C720_CAP_DEV_FR0_RGB].vdev.entity,
+ 0, MEDIA_LNK_FL_ENABLED);
+ if (ret) {
+ dev_err(mali_c720->dev,
+ "failed to link FR RGB and video device\n");
+ return ret;
+ }
+
+ ret = media_create_pad_link(&fr_sd->entity,
+ MALI_C720_FR_PIPE_PAD_SOURCE_YUV,
+ &mali_c720->cap_devs[MALI_C720_CAP_DEV_FR0_YUV].vdev.entity,
+ 0, 0);
+ if (ret)
+ dev_err(mali_c720->dev,
+ "failed to link FR YUV and video device\n");
+
+ return ret;
+}
+
+static int mali_c720_create_links(struct mali_c720 *mali_c720)
+{
+ int ret;
+
+ ret = mali_c720_create_isp_input_links(mali_c720);
+ if (ret)
+ goto err_remove_links;
+
+ ret = mali_c720_create_vision_pipe_links(mali_c720);
+ if (ret)
+ goto err_remove_links;
+
+ ret = mali_c720_create_fr_pipe_links(mali_c720);
+ if (ret)
+ goto err_remove_links;
+
+ return 0;
+
+err_remove_links:
+ mali_c720_remove_links(mali_c720);
+ return ret;
+}
+
+static void mali_c720_unregister_video_devices(struct mali_c720 *mali_c720)
+{
+ /* Prevent request queueing from racing with video device unregistration. */
+ guard(mutex)(&mali_c720->media_dev.req_queue_mutex);
+
+ mali_c720_unregister_capture_devs(mali_c720);
+}
+
+static void mali_c720_unregister_entities(struct mali_c720 *mali_c720)
+{
+ mali_c720_remove_links(mali_c720);
+ mali_c720_unregister_fr_pipe(mali_c720);
+ mali_c720_unregister_vision_pipe(mali_c720);
+ mali_c720_unregister_isp(mali_c720);
+ mali_c720_unregister_input(mali_c720);
+}
+
+static int mali_c720_register_entities(struct mali_c720 *mali_c720)
+{
+ int ret;
+
+ ret = mali_c720_register_input(mali_c720);
+ if (ret)
+ goto err_unregister_entities;
+
+ ret = mali_c720_register_isp(mali_c720);
+ if (ret)
+ goto err_unregister_entities;
+
+ ret = mali_c720_register_vision_pipe(mali_c720);
+ if (ret)
+ goto err_unregister_entities;
+
+ ret = mali_c720_register_fr_pipe(mali_c720);
+ if (ret)
+ goto err_unregister_entities;
+
+ ret = mali_c720_register_capture_devs(mali_c720);
+ if (ret)
+ goto err_unregister_entities;
+
+ ret = mali_c720_create_links(mali_c720);
+ if (ret)
+ goto err_unregister_entities;
+
+ return 0;
+
+err_unregister_entities:
+ mali_c720_unregister_video_devices(mali_c720);
+ mali_c720_unregister_entities(mali_c720);
+
+ return ret;
+}
+
+static int mali_c720_register_media_nodes(struct mali_c720 *mali_c720)
+{
+ int ret;
+
+ /* Keep STREAMON out until media device registration completes. */
+ guard(mutex)(&mali_c720->device_lock);
+
+ ret = v4l2_device_register_subdev_nodes(&mali_c720->v4l2_dev);
+ if (ret)
+ return ret;
+
+ /* The notifier may complete again after an external subdevice rebinds. */
+ if (media_devnode_is_registered(mali_c720->media_dev.devnode))
+ return 0;
+
+ return media_device_register(&mali_c720->media_dev);
+}
+
+static int mali_c720_notifier_bound(struct v4l2_async_notifier *notifier,
+ struct v4l2_subdev *subdev,
+ struct v4l2_async_connection *asc)
+{
+ struct mali_c720 *mali_c720 = container_of(notifier,
+ struct mali_c720, notifier);
+
+ return v4l2_create_fwnode_links(subdev, &mali_c720->input.mdev.sd);
+}
+
+static int mali_c720_notifier_complete(struct v4l2_async_notifier *notifier)
+{
+ struct mali_c720 *mali_c720 = container_of(notifier,
+ struct mali_c720, notifier);
+
+ return mali_c720_register_media_nodes(mali_c720);
+}
+
+static const struct v4l2_async_notifier_operations mali_c720_notifier_ops = {
+ .bound = mali_c720_notifier_bound,
+ .complete = mali_c720_notifier_complete,
+};
+
+static int mali_c720_parse_endpoint(struct mali_c720 *mali_c720)
+{
+ struct v4l2_async_notifier *ntf = &mali_c720->notifier;
+ struct fwnode_handle *fwnode = dev_fwnode(mali_c720->dev);
+ struct fwnode_handle *ep;
+ unsigned int index = 0;
+ int ret = 0;
+
+ fwnode_graph_for_each_endpoint(fwnode, ep) {
+ struct v4l2_async_connection *asc;
+ struct fwnode_handle *port;
+ u32 input_id = 0;
+
+ port = fwnode_get_parent(ep);
+ fwnode_property_read_u32(port, "reg", &input_id);
+ fwnode_handle_put(port);
+
+ if (input_id != 0) {
+ dev_err(mali_c720->dev,
+ "endpoint %pfw has invalid input port %u\n",
+ ep, input_id);
+ ret = -EINVAL;
+ break;
+ }
+
+ asc = v4l2_async_nf_add_fwnode_remote(ntf, ep,
+ struct v4l2_async_connection);
+ ret = PTR_ERR_OR_ZERO(asc);
+ if (ret) {
+ dev_err(mali_c720->dev,
+ "failed to add remote endpoint for %pfw\n",
+ ep);
+ break;
+ }
+
+ index++;
+ }
+
+ mali_c720->num_async_endpoints = index;
+
+ if (ret) {
+ fwnode_handle_put(ep);
+ return ret;
+ }
+
+ if (!index)
+ dev_dbg(mali_c720->dev, "no remote subdevice found\n");
+
+ return 0;
+}
+
+static void mali_c720_free(struct mali_c720 *mali_c720)
+{
+ kvfree(mali_c720->default_regs);
+ if (mali_c720->context.mali_c720)
+ mutex_destroy(&mali_c720->context.regs.allocation_lock);
+ mutex_destroy(&mali_c720->device_lock);
+ put_device(mali_c720->dev);
+ kvfree(mali_c720);
+}
+
+static void mali_c720_release(struct v4l2_device *v4l2_dev)
+{
+ struct mali_c720 *mali_c720 = container_of(v4l2_dev, struct mali_c720, v4l2_dev);
+
+ mali_c720_cleanup_capture_devs(mali_c720);
+ mali_c720_cleanup_fr_pipe(mali_c720);
+ mali_c720_cleanup_vision_pipe(mali_c720);
+ mali_c720_cleanup_isp(mali_c720);
+ mali_c720_cleanup_input(mali_c720);
+ media_device_cleanup(&mali_c720->media_dev);
+ mali_c720_free(mali_c720);
+}
+
+/*
+ * Initialize the media frameworks and register the entities and links. Publish
+ * the media device once all external subdevices have bound.
+ */
+static int mali_c720_media_frameworks_init(struct mali_c720 *mali_c720)
+{
+ int ret;
+
+ strscpy(mali_c720->media_dev.model, "ARM Mali-C720 ISP",
+ sizeof(mali_c720->media_dev.model));
+
+ media_device_init(&mali_c720->media_dev);
+
+ mali_c720->v4l2_dev.mdev = &mali_c720->media_dev;
+ ret = v4l2_device_register(mali_c720->dev, &mali_c720->v4l2_dev);
+ if (ret) {
+ dev_err(mali_c720->dev, "Failed to register V4L2 device\n");
+ media_device_cleanup(&mali_c720->media_dev);
+ return ret;
+ }
+ mali_c720->v4l2_dev.release = mali_c720_release;
+
+ mali_c720->notifier.ops = &mali_c720_notifier_ops;
+ v4l2_async_nf_init(&mali_c720->notifier, &mali_c720->v4l2_dev);
+
+ ret = mali_c720_register_entities(mali_c720);
+ if (ret) {
+ dev_err(mali_c720->dev, "failed to register entities\n");
+ goto err_cleanup_nf;
+ }
+
+ ret = mali_c720_parse_endpoint(mali_c720);
+ if (ret)
+ goto err_unregister_entities;
+
+ if (mali_c720->num_async_endpoints) {
+ ret = v4l2_async_nf_register(&mali_c720->notifier);
+ if (ret) {
+ dev_err(mali_c720->dev, "failed to register notifier\n");
+ goto err_unregister_entities;
+ }
+ } else {
+ ret = mali_c720_register_media_nodes(mali_c720);
+ if (ret) {
+ dev_err(mali_c720->dev, "failed to register media nodes\n");
+ goto err_unregister_entities;
+ }
+ }
+
+ return 0;
+
+err_unregister_entities:
+ mali_c720_unregister_video_devices(mali_c720);
+ mali_c720_unregister_entities(mali_c720);
+err_cleanup_nf:
+ v4l2_async_nf_cleanup(&mali_c720->notifier);
+ v4l2_device_unregister(&mali_c720->v4l2_dev);
+
+ return ret;
+}
+
+static void mali_c720_media_frameworks_deinit(struct mali_c720 *mali_c720)
+{
+ /*
+ * We unregister video devices first to ensure streaming is stopped
+ * before subdevices are unregistered. The async notifier comes next
+ * since the .bound() callback creates media links to our subdevices.
+ */
+
+ mali_c720_unregister_video_devices(mali_c720);
+ v4l2_async_nf_unregister(&mali_c720->notifier);
+ mali_c720_unregister_entities(mali_c720);
+ v4l2_async_nf_cleanup(&mali_c720->notifier);
+ v4l2_device_unregister(&mali_c720->v4l2_dev);
+ media_device_unregister(&mali_c720->media_dev);
+}
+
+static struct media_request *mali_c720_req_alloc(struct media_device *mdev)
+{
+ struct mali_c720_request *mreq;
+
+ mreq = kzalloc_obj(*mreq, GFP_KERNEL);
+ if (!mreq)
+ return NULL;
+
+ return &mreq->req;
+}
+
+static void mali_c720_req_free(struct media_request *req)
+{
+ kfree(to_mali_c720_request(req));
+}
+
+static int mali_c720_req_validate(struct media_request *req)
+{
+ struct media_request_object *obj;
+
+ /* Request-associated controls are not supported. */
+ list_for_each_entry(obj, &req->objects, list) {
+ if (!vb2_request_object_is_buffer(obj))
+ return -EINVAL;
+ }
+
+ return vb2_request_validate(req);
+}
+
+static void mali_c720_req_queue(struct media_request *req)
+{
+ struct mali_c720 *mali_c720 = container_of(req->mdev, struct mali_c720, media_dev);
+ struct mali_c720_context *ctx = &mali_c720->context;
+ struct mali_c720_request *mreq = to_mali_c720_request(req);
+
+ scoped_guard(spinlock, &ctx->req_lock) {
+ mreq->submitted = false;
+ mreq->queue_sequence = ctx->request_sequence++;
+ }
+
+ vb2_request_queue(req);
+
+ scoped_guard(spinlock, &ctx->req_lock) {
+ mreq->submitted = true;
+ }
+
+ mali_c720_try_schedule_frame(ctx);
+}
+
+static const struct media_device_ops mali_c720_media_device_ops = {
+ .req_alloc = mali_c720_req_alloc,
+ .req_free = mali_c720_req_free,
+ .req_validate = mali_c720_req_validate,
+ .req_queue = mali_c720_req_queue,
+};
+
+int mali_c720_pipeline_ready(struct mali_c720 *mali_c720)
+{
+ struct media_pipeline_entity_iter iter;
+ struct media_entity *entity;
+ int n_video_devices = 0;
+ int ret;
+
+ ret = media_pipeline_entity_iter_init(&mali_c720->pipe, &iter);
+ if (ret)
+ return ret;
+
+ media_pipeline_for_each_entity(&mali_c720->pipe, &iter, entity) {
+ if (entity->obj_type == MEDIA_ENTITY_TYPE_VIDEO_DEVICE)
+ n_video_devices++;
+ }
+
+ media_pipeline_entity_iter_cleanup(&iter);
+
+ return n_video_devices == mali_c720->pipe.start_count ? 0 : -EAGAIN;
+}
+
+int mali_c720_streamon(struct file *file, void *priv, enum v4l2_buf_type type)
+{
+ struct video_device *vdev = video_devdata(file);
+ struct mali_c720 *mali_c720 = container_of(vdev->v4l2_dev, struct mali_c720, v4l2_dev);
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ int ret;
+
+ ret = vb2_ioctl_streamon(file, priv, type);
+ if (ret)
+ return ret;
+
+ guard(mutex)(&mali_c720->device_lock);
+
+ /*
+ * The final STREAMON prepares the context and starts its inputs. Wait
+ * until VB2 marks that queue streaming before starting the context
+ * and allowing scheduling to take place.
+ */
+ scoped_guard(spinlock, &ctx->state_lock) {
+ if (ctx->state != MALI_C720_SLOT_STATE_PREPARED)
+ return 0;
+
+ mali_c720_ctx_mgr_start_context(ctx);
+ }
+
+ mali_c720_try_schedule_frame(ctx);
+
+ return 0;
+}
+
+static bool mali_c720_has_ready_output(struct mali_c720 *mali_c720)
+{
+ unsigned int i;
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
+ if (!mali_c720_cap_dev_is_ready(&mali_c720->cap_devs[i]))
+ return true;
+ }
+
+ return false;
+}
+
+static struct media_request *
+mali_c720_oldest_request(struct media_request *oldest, struct media_request *candidate)
+{
+ struct mali_c720_request *mreq;
+
+ if (!candidate)
+ return oldest;
+
+ mreq = to_mali_c720_request(candidate);
+
+ /* Ignore partially submitted requests */
+ if (!mreq->submitted)
+ return oldest;
+
+ if (!oldest ||
+ (int)(mreq->queue_sequence - to_mali_c720_request(oldest)->queue_sequence) < 0)
+ return candidate;
+
+ return oldest;
+}
+
+static struct media_request *mali_c720_find_request(struct mali_c720 *mali_c720)
+{
+ struct media_request *candidate, *req = NULL;
+ unsigned int i;
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
+ candidate = mali_c720_cap_dev_get_request(&mali_c720->cap_devs[i]);
+ req = mali_c720_oldest_request(req, candidate);
+ }
+
+ return req;
+}
+
+static bool mali_c720_uses_requests(struct mali_c720 *mali_c720)
+{
+ unsigned int i;
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
+ if (mali_c720_cap_dev_uses_requests(&mali_c720->cap_devs[i]))
+ return true;
+ }
+
+ return false;
+}
+
+static bool mali_c720_can_schedule(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+
+ /* Ensure the first free-running frame has at least one ready output. */
+ if (ctx->state == MALI_C720_SLOT_STATE_STARTING &&
+ !mali_c720_has_ready_output(mali_c720))
+ return false;
+
+ return true;
+}
+
+static struct media_request *mali_c720_can_schedule_request(struct mali_c720_context *ctx)
+{
+ return mali_c720_find_request(ctx->mali_c720);
+}
+
+void mali_c720_try_schedule_frame(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ struct media_request *req = NULL;
+ unsigned int i;
+
+ guard(spinlock)(&ctx->state_lock);
+
+ if ((ctx->state != MALI_C720_SLOT_STATE_STARTING &&
+ ctx->state != MALI_C720_SLOT_STATE_STARTED) || ctx->pipeline_busy)
+ return;
+
+ scoped_guard(spinlock, &ctx->req_lock) {
+ if (mali_c720_uses_requests(mali_c720)) {
+ req = mali_c720_can_schedule_request(ctx);
+ if (!req)
+ return;
+ } else if (!mali_c720_can_schedule(ctx)) {
+ return;
+ }
+
+ for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++)
+ mali_c720_cap_dev_set_next_buffer(&mali_c720->cap_devs[i], req);
+ }
+
+ ctx->pipeline_busy = true;
+ mali_c720_ctx_mgr_prepare_frame(ctx);
+
+ /* Resizer configurations should be synchronised with CDMA */
+ mali_c720_fr_pipe_apply_resizer_config(&mali_c720->fr_pipe);
+
+ mali_c720_ctx_mgr_handle_sw_ready(ctx);
+}
+
+static int mali_c720_power_on(struct mali_c720 *mali_c720)
+{
+ int ret;
+
+ ret = clk_prepare_enable(mali_c720->clk);
+ if (ret) {
+ dev_err(mali_c720->dev, "failed to enable clocks\n");
+ return ret;
+ }
+
+ ret = reset_control_deassert(mali_c720->reset);
+ if (ret) {
+ dev_err(mali_c720->dev, "failed to deassert resets\n");
+ goto err_disable_clk;
+ }
+
+ return 0;
+
+err_disable_clk:
+ clk_disable_unprepare(mali_c720->clk);
+ return ret;
+}
+
+static void mali_c720_power_off(struct mali_c720 *mali_c720)
+{
+ reset_control_assert(mali_c720->reset);
+ clk_disable_unprepare(mali_c720->clk);
+}
+
+static int __maybe_unused mali_c720_runtime_resume(struct device *dev)
+{
+ struct mali_c720 *mali_c720 = dev_get_drvdata(dev);
+
+ return mali_c720_power_on(mali_c720);
+}
+
+static int __maybe_unused mali_c720_runtime_suspend(struct device *dev)
+{
+ struct mali_c720 *mali_c720 = dev_get_drvdata(dev);
+
+ mali_c720_power_off(mali_c720);
+ return 0;
+}
+
+static int __maybe_unused mali_c720_suspend(struct device *dev)
+{
+ struct mali_c720 *mali_c720 = dev_get_drvdata(dev);
+
+ guard(mutex)(&mali_c720->device_lock);
+
+ /* Active pipelines cannot survive the hardware reset during suspend. */
+ if (media_entity_is_streaming(&mali_c720->isp.mdev.sd.entity))
+ return -EBUSY;
+
+ return pm_runtime_force_suspend(dev);
+}
+
+static const struct dev_pm_ops mali_c720_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(mali_c720_suspend,
+ pm_runtime_force_resume)
+ SET_RUNTIME_PM_OPS(mali_c720_runtime_suspend, mali_c720_runtime_resume,
+ NULL)
+};
+
+static int mali_c720_probe(struct platform_device *pdev)
+{
+ const struct mali_c720_discovery_target top = {
+ .module_id = MALI_C720_DISC_MODULE_ID_PIPELINE_GLOBAL_CONTROL,
+ .pipeline_id = MALI_C720_DISC_PIPE_GLOBAL,
+ };
+ struct device *dev = &pdev->dev;
+ struct mali_c720 *mali_c720;
+ struct resource *res;
+ unsigned int irq;
+ int ret;
+
+ mali_c720 = kvzalloc_obj(*mali_c720, GFP_KERNEL);
+ if (!mali_c720)
+ return -ENOMEM;
+
+ mali_c720->dev = get_device(dev);
+ platform_set_drvdata(pdev, mali_c720);
+
+ mutex_init(&mali_c720->device_lock);
+
+ mali_c720->base = devm_platform_get_and_ioremap_resource(pdev, 0,
+ &res);
+ ret = PTR_ERR_OR_ZERO(mali_c720->base);
+ if (ret) {
+ dev_err_probe(dev, ret, "failed to map IO memory\n");
+ goto err_free;
+ }
+
+ mali_c720->mmio_size = resource_size(res);
+
+ if (resource_size(res) < MALI_C720_ID_SIZE) {
+ ret = dev_err_probe(dev, -EINVAL,
+ "IO memory resource %pR is too small (minimum %#x bytes)\n",
+ res, MALI_C720_ID_SIZE);
+ goto err_free;
+ }
+
+ mali_c720->clk = devm_clk_get(dev, "vclk");
+ ret = PTR_ERR_OR_ZERO(mali_c720->clk);
+ if (ret) {
+ dev_err_probe(dev, ret, "failed to acquire clock\n");
+ goto err_free;
+ }
+
+ mali_c720->reset = devm_reset_control_get_optional_shared(dev, "reset");
+ ret = PTR_ERR_OR_ZERO(mali_c720->reset);
+ if (ret) {
+ dev_err_probe(dev, ret, "failed to acquire reset\n");
+ goto err_free;
+ }
+
+ ret = of_reserved_mem_device_init(dev);
+ if (ret && ret != -ENODEV) {
+ dev_err_probe(dev, ret, "failed to initialize reserved memory\n");
+ goto err_free;
+ }
+
+ ret = vb2_dma_contig_set_max_seg_size(dev, UINT_MAX);
+ if (ret)
+ goto err_release_mem;
+
+ ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
+ if (ret) {
+ dev_err_probe(dev, ret, "failed to set DMA mask\n");
+ goto err_release_mem;
+ }
+
+ ret = mali_c720_power_on(mali_c720);
+ if (ret) {
+ dev_err(dev, "failed to power on: %d\n", ret);
+ goto err_release_mem;
+ }
+
+ mali_c720->registers.id = mali_c720_get_id_regs();
+ ret = mali_c720_identify_hw(mali_c720);
+ if (ret)
+ goto err_power_off;
+
+ ret = mali_c720_get_registers(mali_c720->hw_version->id, &mali_c720->registers);
+ if (ret) {
+ dev_err_probe(dev, ret, "unsupported register layout\n");
+ goto err_power_off;
+ }
+
+ if (resource_size(res) < mali_c720->registers.context_size) {
+ ret = dev_err_probe(dev, -EINVAL,
+ "IO memory resource %pR is too small (minimum %#x bytes)\n",
+ res, mali_c720->registers.context_size);
+ goto err_power_off;
+ }
+
+ ret = mali_c720_discovery_init(mali_c720, resource_size(res));
+ if (ret) {
+ dev_err(dev, "failed to parse capability discovery data\n");
+ goto err_power_off;
+ }
+
+ ret = mali_c720_discovery_get_module_base(mali_c720, &top, &mali_c720->top_base);
+ if (ret) {
+ dev_err(dev, "failed to get top base address from discovery data\n");
+ goto err_power_off;
+ }
+
+ ret = mali_c720_init_contexts(mali_c720);
+ if (ret)
+ goto err_power_off;
+
+ ret = mali_c720_init_ctx_mgr(mali_c720);
+ if (ret)
+ goto err_power_off;
+
+ pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
+ pm_runtime_use_autosuspend(&pdev->dev);
+ pm_runtime_set_active(&pdev->dev);
+ pm_runtime_enable(&pdev->dev);
+
+ ret = platform_get_irq_byname(pdev, "isp");
+ if (ret < 0) {
+ dev_err(dev, "Failed to get interrupt\n");
+ goto err_pm_runtime_disable;
+ }
+ irq = (unsigned int)ret;
+
+ spin_lock_init(&mali_c720->irq_lock);
+ INIT_KFIFO(mali_c720->irq_fifo);
+ ret = devm_request_threaded_irq(&pdev->dev, irq,
+ mali_c720_isr_top, mali_c720_isr,
+ 0,
+ dev_driver_string(&pdev->dev),
+ &pdev->dev);
+ if (ret) {
+ dev_err(dev, "Failed to request threaded IRQ\n");
+ goto err_pm_runtime_disable;
+ }
+ mali_c720->irq = irq;
+
+ mali_c720->media_dev.dev = dev;
+ mali_c720->media_dev.ops = &mali_c720_media_device_ops;
+ ret = mali_c720_media_frameworks_init(mali_c720);
+ if (ret)
+ goto err_free_irq;
+
+ pm_runtime_idle(&pdev->dev);
+
+ dev_info(&pdev->dev, "Media frameworks and entities registered successfully\n");
+
+ return 0;
+
+err_free_irq:
+ devm_free_irq(dev, mali_c720->irq, dev);
+err_pm_runtime_disable:
+ pm_runtime_disable(&pdev->dev);
+ pm_runtime_set_suspended(&pdev->dev);
+err_power_off:
+ mali_c720_power_off(mali_c720);
+err_release_mem:
+ of_reserved_mem_device_release(dev);
+err_free:
+ platform_set_drvdata(pdev, NULL);
+ if (mali_c720->v4l2_dev.release)
+ v4l2_device_put(&mali_c720->v4l2_dev);
+ else
+ mali_c720_free(mali_c720);
+
+ return ret;
+}
+
+static void mali_c720_remove(struct platform_device *pdev)
+{
+ struct mali_c720 *mali_c720 = platform_get_drvdata(pdev);
+
+ /* Keep the current power state until queues and IRQs have been drained. */
+ pm_runtime_get_noresume(&pdev->dev);
+ pm_runtime_barrier(&pdev->dev);
+
+ mali_c720_media_frameworks_deinit(mali_c720);
+ devm_free_irq(&pdev->dev, mali_c720->irq, &pdev->dev);
+
+ pm_runtime_disable(&pdev->dev);
+ if (!pm_runtime_status_suspended(&pdev->dev))
+ mali_c720_power_off(mali_c720);
+ pm_runtime_set_suspended(&pdev->dev);
+ pm_runtime_put_noidle(&pdev->dev);
+
+ of_reserved_mem_device_release(&pdev->dev);
+ platform_set_drvdata(pdev, NULL);
+ v4l2_device_put(&mali_c720->v4l2_dev);
+}
+
+static const struct of_device_id mali_c720_of_match[] = {
+ { .compatible = "arm,mali-c720" },
+ { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, mali_c720_of_match);
+
+static struct platform_driver mali_c720_driver = {
+ .driver = {
+ .name = "mali-c720",
+ .of_match_table = mali_c720_of_match,
+ .pm = &mali_c720_pm_ops,
+ },
+ .probe = mali_c720_probe,
+ .remove = mali_c720_remove,
+};
+
+module_platform_driver(mali_c720_driver);
+
+MODULE_DESCRIPTION("Mali C720 Core driver");
+MODULE_AUTHOR("Anthony McGivern <Anthony.McGivern@arm.com>");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("DMA_BUF");
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c b/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
index bd1e5189b276e59a33cda63f40ceffa3b7a2520c..43c9edc7f372a95e5e0c6256ef27f3958590891e 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-interrupts.c
@@ -202,6 +202,8 @@ static void mali_c720_handle_frame_end(struct mali_c720 *mali_c720,
ctx->pipeline_busy = false;
}
+
+ mali_c720_try_schedule_frame(ctx);
}
irqreturn_t mali_c720_isr(int irq, void *dev_id)
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 14/24] media: mali-c720: Add test pattern generator subdevices
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (12 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 13/24] media: mali-c720: Add Mali-C720 ISP driver Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 15/24] media: Documentation: Add Mali-C720 ISP documentation Anthony McGivern
` (9 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Expose the two internal test pattern generators as subdevices linked
to the input frontend when their presence is reported by hardware
discovery.
Allow pattern selection through the V4L2_CID_TEST_PATTERN control.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
drivers/media/platform/arm/mali-c720/Makefile | 1 +
.../platform/arm/mali-c720/mali-c720-common.h | 26 +
.../media/platform/arm/mali-c720/mali-c720-core.c | 48 ++
.../media/platform/arm/mali-c720/mali-c720-tpg.c | 581 +++++++++++++++++++++
4 files changed, 656 insertions(+)
diff --git a/drivers/media/platform/arm/mali-c720/Makefile b/drivers/media/platform/arm/mali-c720/Makefile
index 31f91d2a0f747bebda2f5584282f8923d4816160..b818f6c9b44ef335e78a307ccc232c134e94db61 100644
--- a/drivers/media/platform/arm/mali-c720/Makefile
+++ b/drivers/media/platform/arm/mali-c720/Makefile
@@ -15,6 +15,7 @@ mali-c720-y := mali-c720-capture.o \
mali-c720-registers-top.o \
mali-c720-registers-ctx-mgr.o \
mali-c720-registers-modules.o \
+ mali-c720-tpg.o \
mali-c720-vision-pipe.o \
obj-$(CONFIG_VIDEO_MALI_C720) += mali-c720.o
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 0f0ad7d9dcccfce13f673f3602f79d5162eb04ad..0018c7b5776f34bdd7c262c51972f619255720e2 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -64,6 +64,27 @@ struct mali_c720_subdev {
#define mali_c720_sd_to_sd(_mdev, type) \
container_of(_mdev, type, mdev)
+enum mali_c720_tpg_ids {
+ MALI_C720_TPG0,
+ MALI_C720_TPG1,
+ MALI_C720_NUM_TPGS,
+};
+
+struct mali_c720_tpg {
+ struct mali_c720_subdev mdev;
+ unsigned int id;
+ unsigned long clk_rate;
+
+ struct media_pad pad;
+ struct media_pad *remote;
+
+ struct mali_c720_tpg_ctrls {
+ struct v4l2_ctrl_handler handler;
+ struct v4l2_ctrl *pattern;
+ struct v4l2_ctrl *vblank;
+ } ctrls;
+};
+
enum mali_c720_input_pads {
MALI_C720_INPUT_PAD_SOURCE_SLOT_INPUT,
MALI_C720_INPUT_PAD_SINK_INPUT0,
@@ -256,6 +277,7 @@ struct mali_c720 {
struct v4l2_async_notifier notifier;
struct media_pipeline pipe;
+ struct mali_c720_tpg tpg[MALI_C720_NUM_TPGS];
struct mali_c720_input input;
struct mali_c720_isp isp;
struct mali_c720_vision_pipe vision_pipe;
@@ -284,6 +306,10 @@ struct mali_c720 {
/* ISP subdevice registration functions */
+int mali_c720_register_tpgs(struct mali_c720 *mali_c720);
+void mali_c720_unregister_tpgs(struct mali_c720 *mali_c720);
+void mali_c720_cleanup_tpgs(struct mali_c720 *mali_c720);
+
int mali_c720_register_input(struct mali_c720 *mali_c720);
void mali_c720_unregister_input(struct mali_c720 *mali_c720);
void mali_c720_cleanup_input(struct mali_c720 *mali_c720);
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-core.c b/drivers/media/platform/arm/mali-c720/mali-c720-core.c
index 2a46e7b348910303d9284a8ce6214953993a7f81..a6970c921ad486a41073779862bab68a22ce35f1 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-core.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-core.c
@@ -30,8 +30,14 @@ static void mali_c720_remove_links(struct mali_c720 *mali_c720)
struct v4l2_subdev *isp_sd = &mali_c720->isp.mdev.sd;
struct v4l2_subdev *hv_sd = &mali_c720->vision_pipe.mdev.sd;
struct v4l2_subdev *fr_sd = &mali_c720->fr_pipe.mdev.sd;
+ struct v4l2_subdev *sd;
unsigned int i;
+ for (i = 0; i < MALI_C720_NUM_TPGS; i++) {
+ sd = &mali_c720->tpg[i].mdev.sd;
+ media_entity_remove_links(&sd->entity);
+ }
+
media_entity_remove_links(&input_sd->entity);
media_entity_remove_links(&isp_sd->entity);
media_entity_remove_links(&hv_sd->entity);
@@ -41,6 +47,32 @@ static void mali_c720_remove_links(struct mali_c720 *mali_c720)
media_entity_remove_links(&mali_c720->cap_devs[i].vdev.entity);
}
+static int mali_c720_create_tpg_links(struct mali_c720 *mali_c720,
+ bool tpg_present)
+{
+ struct v4l2_subdev *input_sd = &mali_c720->input.mdev.sd;
+ struct v4l2_subdev *sd;
+ unsigned int i;
+ int ret;
+
+ if (!tpg_present)
+ return 0;
+
+ for (i = 0; i < MALI_C720_NUM_TPGS; i++) {
+ sd = &mali_c720->tpg[i].mdev.sd;
+
+ ret = media_create_pad_link(&sd->entity, 0, &input_sd->entity,
+ MALI_C720_INPUT_PAD_SINK_INPUT0, 0);
+ if (ret) {
+ dev_err(mali_c720->dev,
+ "failed to link TPG %u and input sink\n", i);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
static int mali_c720_create_isp_input_links(struct mali_c720 *mali_c720)
{
struct v4l2_subdev *input_sd = &mali_c720->input.mdev.sd;
@@ -112,8 +144,18 @@ static int mali_c720_create_fr_pipe_links(struct mali_c720 *mali_c720)
static int mali_c720_create_links(struct mali_c720 *mali_c720)
{
+ const struct mali_c720_discovery_target tpg = {
+ .module_id = MALI_C720_DISC_MODULE_ID_TPG_RAW_MULTI,
+ .pipeline_id = MALI_C720_DISC_PIPE_GLOBAL,
+ };
+ const bool tpg_present =
+ mali_c720_discovery_module_present(mali_c720, &tpg);
int ret;
+ ret = mali_c720_create_tpg_links(mali_c720, tpg_present);
+ if (ret)
+ goto err_remove_links;
+
ret = mali_c720_create_isp_input_links(mali_c720);
if (ret)
goto err_remove_links;
@@ -148,12 +190,17 @@ static void mali_c720_unregister_entities(struct mali_c720 *mali_c720)
mali_c720_unregister_vision_pipe(mali_c720);
mali_c720_unregister_isp(mali_c720);
mali_c720_unregister_input(mali_c720);
+ mali_c720_unregister_tpgs(mali_c720);
}
static int mali_c720_register_entities(struct mali_c720 *mali_c720)
{
int ret;
+ ret = mali_c720_register_tpgs(mali_c720);
+ if (ret)
+ goto err_unregister_entities;
+
ret = mali_c720_register_input(mali_c720);
if (ret)
goto err_unregister_entities;
@@ -298,6 +345,7 @@ static void mali_c720_release(struct v4l2_device *v4l2_dev)
mali_c720_cleanup_vision_pipe(mali_c720);
mali_c720_cleanup_isp(mali_c720);
mali_c720_cleanup_input(mali_c720);
+ mali_c720_cleanup_tpgs(mali_c720);
media_device_cleanup(&mali_c720->media_dev);
mali_c720_free(mali_c720);
}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-tpg.c b/drivers/media/platform/arm/mali-c720/mali-c720-tpg.c
new file mode 100644
index 0000000000000000000000000000000000000000..47c7783a33f226541fdb8bef1544a48f25477757
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-tpg.c
@@ -0,0 +1,581 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/math.h>
+#include <linux/minmax.h>
+#include <linux/string.h>
+
+#include <media/media-entity.h>
+#include <media/v4l2-common.h>
+
+#include "mali-c720-common.h"
+
+#define MALI_C720_TPG_SRC_PAD 0
+#define MALI_C720_TPG_DEFAULT_STREAM 0
+#define MALI_C720_TPG_FIXED_HBLANK 0x20
+#define MALI_C720_TPG_MAX_VBLANK_CYCLES 0xfffffff
+
+static const char *const mali_c720_tpg_test_pattern_menu[] = {
+ "Flat field",
+ "Horizontal gradient",
+ "Vertical gradient",
+ "Vertical bars",
+ "Arbitrary rectangle",
+ "Random data",
+ "White frame on black field",
+};
+
+static void mali_c720_tpg_start(struct mali_c720_tpg *tpg)
+{
+ struct mali_c720 *mali_c720 = tpg->mdev.mali_c720;
+ const struct mali_c720_precm_tpg_regs *precm_tpgs = mali_c720->registers.top->precm_tpgs;
+ u32 base = mali_c720_group_base(&precm_tpgs->group, tpg->id);
+
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->test_pattern_off_on, 0x01);
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->generate_mode, 0x01);
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->frame_request, 0x01);
+}
+
+static void mali_c720_tpg_stop(struct mali_c720_tpg *tpg)
+{
+ struct mali_c720 *mali_c720 = tpg->mdev.mali_c720;
+ const struct mali_c720_precm_tpg_regs *precm_tpgs = mali_c720->registers.top->precm_tpgs;
+ u32 base = mali_c720_group_base(&precm_tpgs->group, tpg->id);
+
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->test_pattern_off_on, 0x00);
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->generate_mode, 0x00);
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->frame_request, 0x00);
+}
+
+static void mali_c720_tpg_program_vertical_blank(struct mali_c720_tpg *tpg,
+ struct v4l2_subdev_state *state)
+{
+ struct mali_c720 *mali_c720 = tpg->mdev.mali_c720;
+ const struct mali_c720_precm_tpg_regs *precm_tpgs = mali_c720->registers.top->precm_tpgs;
+ struct v4l2_mbus_framefmt *format;
+ u32 vblank_cycles;
+ u32 base = mali_c720_group_base(&precm_tpgs->group, tpg->id);
+
+ format = v4l2_subdev_state_get_format(state, MALI_C720_TPG_SRC_PAD,
+ MALI_C720_TPG_DEFAULT_STREAM);
+ vblank_cycles = (u32)tpg->ctrls.vblank->cur.val *
+ (MALI_C720_TPG_FIXED_HBLANK + format->width);
+
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->vertical_blanking, vblank_cycles);
+}
+
+static void mali_c720_tpg_program_test_pattern(struct mali_c720_tpg *tpg,
+ u32 pattern)
+{
+ struct mali_c720 *mali_c720 = tpg->mdev.mali_c720;
+ const struct mali_c720_precm_tpg_regs *precm_tpgs = mali_c720->registers.top->precm_tpgs;
+ u32 base = mali_c720_group_base(&precm_tpgs->group, tpg->id);
+
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->pattern_type, pattern);
+}
+
+static void mali_c720_tpg_calculate_vblank(struct mali_c720_tpg *tpg,
+ unsigned int width, unsigned int height,
+ unsigned int *min_vblank,
+ unsigned int *max_vblank,
+ unsigned int *def_vblank)
+{
+ const unsigned long tpg_clk_rate = tpg->clk_rate;
+ unsigned int hts;
+ unsigned long tgt_fps;
+
+ hts = width + MALI_C720_TPG_FIXED_HBLANK;
+
+ /*
+ * The ISP minimum vertical blanking depends on the worst case pipeline
+ * latency, which partially overlaps with Iridix filtering. Convert the
+ * filtering time from ISP clock cycles to lines and allow one
+ * additional line for final DMA completion.
+ */
+ *min_vblank = max(31, 21 + DIV_ROUND_UP(60350U, hts)) + 1;
+
+ /*
+ * A high clock rate combined with a small frame and low frame rate can
+ * exceed the TPG vertical blanking limit.
+ */
+ *max_vblank = MALI_C720_TPG_MAX_VBLANK_CYCLES / hts;
+
+ /*
+ * Target a multiple of 15 frames per second, falling back to 5 frames
+ * per second and then to the minimum vertical blanking.
+ */
+ tgt_fps = tpg_clk_rate / hts / (height + *min_vblank);
+
+ if (tgt_fps < 5)
+ *def_vblank = *min_vblank;
+ else
+ *def_vblank = (unsigned int)((tpg_clk_rate / hts
+ / max(rounddown(tgt_fps, 15), 5)) - height);
+
+ *def_vblank = clamp(*def_vblank, *min_vblank, *max_vblank);
+}
+
+static int mali_c720_tpg_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+ struct mali_c720_tpg *tpg = container_of(ctrl->handler,
+ struct mali_c720_tpg,
+ ctrls.handler);
+ int ret = 0;
+
+ switch (ctrl->id) {
+ case V4L2_CID_TEST_PATTERN:
+ if (v4l2_subdev_is_streaming(&tpg->mdev.sd))
+ mali_c720_tpg_program_test_pattern(tpg, (u32)ctrl->val);
+ break;
+ case V4L2_CID_VBLANK:
+ if (v4l2_subdev_is_streaming(&tpg->mdev.sd))
+ ret = -EBUSY;
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+
+ return ret;
+}
+
+static const struct v4l2_ctrl_ops mali_c720_tpg_ctrl_ops = {
+ .s_ctrl = &mali_c720_tpg_s_ctrl,
+};
+
+static int mali_c720_tpg_configure(struct mali_c720_tpg *tpg,
+ struct v4l2_subdev_state *state)
+{
+ struct mali_c720 *mali_c720 = tpg->mdev.mali_c720;
+ const struct mali_c720_precm_tpg_regs *precm_tpgs = mali_c720->registers.top->precm_tpgs;
+ const struct mali_c720_pre_cm_regs *pre_cm = mali_c720->registers.top->pre_cm;
+ const struct mali_c720_mbus_format_info *cfg;
+ struct v4l2_mbus_framefmt *fmt;
+ u32 base = mali_c720_group_base(&precm_tpgs->group, tpg->id);
+ u32 bayer_order;
+
+ fmt = v4l2_subdev_state_get_format(state,
+ MALI_C720_TPG_SRC_PAD,
+ MALI_C720_TPG_DEFAULT_STREAM);
+
+ cfg = mali_c720_get_mbus_config_by_code(fmt->code);
+ if (!cfg)
+ return -EINVAL;
+
+ bayer_order = __ffs(cfg->type);
+
+ tpg->remote = media_pad_remote_pad_unique(&tpg->pad);
+ if (IS_ERR(tpg->remote))
+ return (int)PTR_ERR(tpg->remote);
+
+ if (tpg->remote->index != MALI_C720_INPUT_PAD_SINK_INPUT0)
+ return -EINVAL;
+
+ /*
+ * hblank needs setting, but is a read-only control and thus won't be
+ * called during __v4l2_ctrl_handler_setup(). Do it here instead.
+ */
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->horizontal_blanking,
+ MALI_C720_TPG_FIXED_HBLANK);
+
+ if (tpg->id == MALI_C720_TPG0)
+ mali_c720_write(mali_c720,
+ &pre_cm->tpg_0_splitter_sel,
+ 0);
+ else
+ mali_c720_write(mali_c720,
+ &pre_cm->tpg_1_splitter_sel,
+ 0);
+
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->glbl_rggb_start, bayer_order);
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->glbl_active_width, fmt->width);
+ mali_c720_group_write(mali_c720, base, &precm_tpgs->glbl_active_height, fmt->height);
+
+ mali_c720_write(mali_c720, &pre_cm->input_0_mux_sel,
+ tpg->id == MALI_C720_TPG0 ? 1 : 2);
+
+ return 0;
+}
+
+static int mali_c720_tpg_enum_mbus_code(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_mbus_code_enum *code)
+{
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_mbus_format_match match;
+
+ if (code->pad)
+ return -EINVAL;
+
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_16BIT;
+
+ cfg = mali_c720_get_mbus_config_by_matched_index(code->index, &match);
+ if (!cfg)
+ return -EINVAL;
+
+ code->code = cfg->code;
+
+ return 0;
+}
+
+static int mali_c720_tpg_enum_frame_size(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_frame_size_enum *fse)
+{
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_mbus_format_match match;
+
+ if (fse->index || fse->pad)
+ return -EINVAL;
+
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_16BIT;
+
+ cfg = mali_c720_get_mbus_config_by_code(fse->code);
+ if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+ return -EINVAL;
+
+ fse->min_width = MALI_C720_MIN_INPUT_WIDTH;
+ fse->max_width = MALI_C720_MAX_WIDTH;
+ fse->min_height = MALI_C720_MIN_INPUT_HEIGHT;
+ fse->max_height = MALI_C720_MAX_HEIGHT;
+
+ return 0;
+}
+
+static int mali_c720_tpg_set_fmt(struct v4l2_subdev *sd,
+ const struct v4l2_subdev_client_info *ci,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_format *format)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720_tpg *tpg = mali_c720_sd_to_sd(mdev, struct mali_c720_tpg);
+ struct v4l2_mbus_framefmt *fmt;
+ const struct mali_c720_mbus_format_info *cfg;
+ struct mali_c720_mbus_format_match match;
+ unsigned int min_vblank, max_vblank, def_vblank;
+
+ if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+ media_entity_is_streaming(&sd->entity))
+ return -EBUSY;
+
+ fmt = v4l2_subdev_state_get_format(state, MALI_C720_TPG_SRC_PAD);
+ fmt->code = format->format.code;
+
+ match.type_mask = MALI_C720_FORMAT_BAYER;
+ match.depth_mask = MALI_C720_FORMAT_16BIT;
+
+ cfg = mali_c720_get_mbus_config_by_code(fmt->code);
+ if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
+ cfg = mali_c720_get_mbus_config_by_code(MEDIA_BUS_FMT_SRGGB16_1X16);
+
+ fmt->code = cfg->code;
+
+ fmt->width = format->format.width;
+ fmt->height = format->format.height;
+ v4l_bound_align_image(&fmt->width, MALI_C720_MIN_INPUT_WIDTH,
+ MALI_C720_MAX_WIDTH, 2,
+ &fmt->height, MALI_C720_MIN_INPUT_HEIGHT,
+ MALI_C720_MAX_HEIGHT, 2, 0);
+
+ format->format = *fmt;
+
+ if (format->which == V4L2_SUBDEV_FORMAT_TRY)
+ return 0;
+
+ mali_c720_tpg_calculate_vblank(tpg, fmt->width, fmt->height,
+ &min_vblank, &max_vblank, &def_vblank);
+ __v4l2_ctrl_modify_range(tpg->ctrls.vblank, min_vblank,
+ max_vblank, 1, def_vblank);
+
+ return 0;
+}
+
+static int mali_c720_tpg_enable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720_tpg *tpg = mali_c720_sd_to_sd(mdev, struct mali_c720_tpg);
+ int ret;
+
+ ret = mali_c720_tpg_configure(tpg, state);
+ if (ret)
+ return ret;
+
+ mali_c720_tpg_program_vertical_blank(tpg, state);
+ mali_c720_tpg_program_test_pattern(tpg, (u32)tpg->ctrls.pattern->cur.val);
+ mali_c720_tpg_start(tpg);
+
+ return 0;
+}
+
+static int mali_c720_tpg_disable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720 *mali_c720 = mdev->mali_c720;
+ const struct mali_c720_pre_cm_regs *pre_cm = mali_c720->registers.top->pre_cm;
+ struct mali_c720_tpg *tpg = mali_c720_sd_to_sd(mdev, struct mali_c720_tpg);
+
+ mali_c720_tpg_stop(tpg);
+
+ if (tpg->id == MALI_C720_TPG0) {
+ mali_c720_write(mali_c720,
+ &pre_cm->tpg_0_splitter_sel, 0x00);
+ } else {
+ mali_c720_write(mali_c720,
+ &pre_cm->tpg_1_splitter_sel, 0x00);
+ }
+
+ mali_c720_write(mali_c720, &pre_cm->input_0_mux_sel, 0x00);
+
+ tpg->remote = NULL;
+
+ return 0;
+}
+
+static const struct v4l2_subdev_pad_ops mali_c720_tpg_pad_ops = {
+ .enum_mbus_code = mali_c720_tpg_enum_mbus_code,
+ .enum_frame_size = mali_c720_tpg_enum_frame_size,
+ .get_fmt = v4l2_subdev_get_fmt,
+ .set_fmt = mali_c720_tpg_set_fmt,
+ .enable_streams = mali_c720_tpg_enable_streams,
+ .disable_streams = mali_c720_tpg_disable_streams,
+};
+
+static const struct v4l2_subdev_ops mali_c720_tpg_ops = {
+ .pad = &mali_c720_tpg_pad_ops,
+};
+
+static int mali_c720_tpg_init_state(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state)
+{
+ struct v4l2_mbus_framefmt *fmt =
+ v4l2_subdev_state_get_format(state,
+ MALI_C720_TPG_SRC_PAD,
+ MALI_C720_TPG_DEFAULT_STREAM);
+
+ fmt->width = MALI_C720_DEFAULT_WIDTH;
+ fmt->height = MALI_C720_DEFAULT_HEIGHT;
+ fmt->field = V4L2_FIELD_NONE;
+ fmt->code = MEDIA_BUS_FMT_SRGGB16_1X16;
+ fmt->colorspace = V4L2_COLORSPACE_RAW;
+ fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace);
+ fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace);
+ fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE;
+
+ return 0;
+}
+
+static const struct v4l2_subdev_internal_ops mali_c720_tpg_internal_ops = {
+ .init_state = mali_c720_tpg_init_state,
+};
+
+static int mali_c720_tpg_init_controls(struct mali_c720_tpg *tpg)
+{
+ struct mali_c720 *mali_c720 = tpg->mdev.mali_c720;
+ struct mali_c720_tpg_ctrls *ctrls = &tpg->ctrls;
+ struct v4l2_ctrl *pixel_rate;
+ struct v4l2_ctrl *hblank;
+ const s64 tpg_clk_rate = (s64)tpg->clk_rate;
+ unsigned int min_vblank, max_vblank, def_vblank;
+ int ret;
+
+ ret = v4l2_ctrl_handler_init(&ctrls->handler, 4);
+ if (ret)
+ return ret;
+
+ ctrls->pattern =
+ v4l2_ctrl_new_std_menu_items(&ctrls->handler,
+ &mali_c720_tpg_ctrl_ops, V4L2_CID_TEST_PATTERN,
+ ARRAY_SIZE(mali_c720_tpg_test_pattern_menu) - 1,
+ 0, 3, mali_c720_tpg_test_pattern_menu);
+
+ /*
+ * We fix hblank at the minimum allowed value and control framerate
+ * solely through the vblank control.
+ */
+ hblank = v4l2_ctrl_new_std(&ctrls->handler, &mali_c720_tpg_ctrl_ops,
+ V4L2_CID_HBLANK, MALI_C720_TPG_FIXED_HBLANK,
+ MALI_C720_TPG_FIXED_HBLANK, 1,
+ MALI_C720_TPG_FIXED_HBLANK);
+ if (hblank)
+ hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
+ mali_c720_tpg_calculate_vblank(tpg, MALI_C720_DEFAULT_WIDTH, MALI_C720_DEFAULT_HEIGHT,
+ &min_vblank, &max_vblank, &def_vblank);
+
+ ctrls->vblank = v4l2_ctrl_new_std(&ctrls->handler,
+ &mali_c720_tpg_ctrl_ops,
+ V4L2_CID_VBLANK,
+ min_vblank, max_vblank, 1, def_vblank);
+
+ pixel_rate = v4l2_ctrl_new_std(&ctrls->handler, &mali_c720_tpg_ctrl_ops,
+ V4L2_CID_PIXEL_RATE,
+ tpg_clk_rate,
+ tpg_clk_rate, 1,
+ tpg_clk_rate);
+ if (pixel_rate)
+ pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
+ if (ctrls->handler.error) {
+ dev_err(mali_c720->dev, "Error during v4l2 controls init\n");
+ v4l2_ctrl_handler_free(&ctrls->handler);
+ return ctrls->handler.error;
+ }
+
+ tpg->mdev.sd.ctrl_handler = &ctrls->handler;
+ tpg->mdev.sd.state_lock = ctrls->handler.lock;
+
+ return 0;
+}
+
+static int mali_c720_tpg_subdev_link_setup(struct media_entity *entity,
+ const struct media_pad *local,
+ const struct media_pad *remote,
+ u32 flags)
+{
+ struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+ struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
+ struct mali_c720_tpg *tpg = mali_c720_sd_to_sd(mdev, struct mali_c720_tpg);
+ struct media_pad *remote_sink;
+
+ if (flags & MEDIA_LNK_FL_ENABLED) {
+ remote_sink = media_pad_remote_pad_unique(local);
+
+ /* No previous link connected */
+ if (IS_ERR(remote_sink))
+ return 0;
+
+ if (remote_sink != remote) {
+ dev_err(mdev->mali_c720->dev,
+ "tpg %d source pad is already connected to another source\n",
+ (tpg->id == MALI_C720_TPG0) ? 0 : 1);
+ return -EBUSY;
+ }
+ }
+
+ return 0;
+}
+
+static const struct media_entity_operations mali_c720_tpg_media_ops = {
+ .link_setup = mali_c720_tpg_subdev_link_setup,
+ .link_validate = v4l2_subdev_link_validate,
+};
+
+static int mali_c720_register_tpg(struct mali_c720 *mali_c720,
+ unsigned int index)
+{
+ struct mali_c720_tpg *tpg = &mali_c720->tpg[index];
+ struct mali_c720_subdev *mdev = &tpg->mdev;
+ struct v4l2_subdev *sd = &mdev->sd;
+ int ret;
+
+ mdev->mali_c720 = mali_c720;
+
+ tpg->id = index;
+ tpg->clk_rate = clk_get_rate(mali_c720->clk);
+ v4l2_subdev_init(sd, &mali_c720_tpg_ops);
+ sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+ sd->entity.ops = &mali_c720_tpg_media_ops;
+ sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
+ sd->internal_ops = &mali_c720_tpg_internal_ops;
+ scnprintf(sd->name, sizeof(sd->name), "mali-c720 tpg %u", index);
+
+ tpg->pad.flags = MEDIA_PAD_FL_SOURCE;
+ ret = media_entity_pads_init(&sd->entity, 1, &tpg->pad);
+ if (ret) {
+ dev_err(mali_c720->dev,
+ "Failed to initialize media entity pads\n");
+ goto err_clear_parent;
+ }
+
+ ret = mali_c720_tpg_init_controls(tpg);
+ if (ret) {
+ dev_err(mali_c720->dev, "Error initialising controls\n");
+ goto err_cleanup_media_entity;
+ }
+
+ ret = v4l2_subdev_init_finalize(sd);
+ if (ret)
+ goto err_free_ctrl_handler;
+
+ ret = v4l2_device_register_subdev(&mali_c720->v4l2_dev, sd);
+ if (ret) {
+ dev_err(mali_c720->dev, "Failed to register tpg subdev\n");
+ goto err_cleanup_subdev;
+ }
+
+ return 0;
+
+err_cleanup_subdev:
+ v4l2_subdev_cleanup(sd);
+err_free_ctrl_handler:
+ v4l2_ctrl_handler_free(&tpg->ctrls.handler);
+err_cleanup_media_entity:
+ media_entity_cleanup(&sd->entity);
+err_clear_parent:
+ mdev->mali_c720 = NULL;
+
+ return ret;
+}
+
+static void mali_c720_unregister_tpg(struct mali_c720_tpg *tpg)
+{
+ struct mali_c720_subdev *mdev = &tpg->mdev;
+
+ if (!mdev->mali_c720)
+ return;
+
+ v4l2_device_unregister_subdev(&mdev->sd);
+}
+
+static void mali_c720_cleanup_tpg(struct mali_c720_tpg *tpg)
+{
+ struct mali_c720_subdev *mdev = &tpg->mdev;
+
+ if (!mdev->mali_c720)
+ return;
+
+ v4l2_ctrl_handler_free(&tpg->ctrls.handler);
+ v4l2_subdev_cleanup(&mdev->sd);
+ media_entity_cleanup(&mdev->sd.entity);
+ mdev->mali_c720 = NULL;
+}
+
+int mali_c720_register_tpgs(struct mali_c720 *mali_c720)
+{
+ const struct mali_c720_discovery_target tpg = {
+ .module_id = MALI_C720_DISC_MODULE_ID_TPG_RAW_MULTI,
+ .pipeline_id = MALI_C720_DISC_PIPE_GLOBAL,
+ };
+ int ret;
+
+ if (!mali_c720_discovery_module_present(mali_c720, &tpg))
+ return 0;
+
+ ret = mali_c720_register_tpg(mali_c720, MALI_C720_TPG0);
+ if (ret)
+ return ret;
+
+ return mali_c720_register_tpg(mali_c720, MALI_C720_TPG1);
+}
+
+void mali_c720_unregister_tpgs(struct mali_c720 *mali_c720)
+{
+ for (int i = 0; i < MALI_C720_NUM_TPGS; i++)
+ mali_c720_unregister_tpg(&mali_c720->tpg[i]);
+}
+
+void mali_c720_cleanup_tpgs(struct mali_c720 *mali_c720)
+{
+ for (int i = 0; i < MALI_C720_NUM_TPGS; i++)
+ mali_c720_cleanup_tpg(&mali_c720->tpg[i]);
+}
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 15/24] media: Documentation: Add Mali-C720 ISP documentation
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (13 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 14/24] media: mali-c720: Add test pattern generator subdevices Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:20 ` sashiko-bot
2026-11-24 17:07 ` [PATCH 16/24] media: uapi: Add Mali-C720 statistics meta format Anthony McGivern
` (8 subsequent siblings)
23 siblings, 1 reply; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Document the Mali-C720 ISP hardware, configuration DMA engine and
media graph topology.
Provide examples for selecting an input source, using the internal
test pattern generators and capturing RGB and YUV images. Describe
the input and output resolution limits and how to configure scaling
and cropping.
Explain the different frame scheduling modes, including free-running
capture and the use of Media Requests for atomic buffer queuing.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../admin-guide/media/mali-c720-graph.dot | 22 ++
Documentation/admin-guide/media/mali-c720.rst | 370 +++++++++++++++++++++
Documentation/admin-guide/media/v4l-drivers.rst | 1 +
3 files changed, 393 insertions(+)
diff --git a/Documentation/admin-guide/media/mali-c720-graph.dot b/Documentation/admin-guide/media/mali-c720-graph.dot
new file mode 100644
index 0000000000000000000000000000000000000000..f1d481b98aebd6ab5424fb78331337f2d7479c1f
--- /dev/null
+++ b/Documentation/admin-guide/media/mali-c720-graph.dot
@@ -0,0 +1,22 @@
+digraph board {
+ rankdir=TB
+ n00000001 [label="{{} | mali-c720 tpg 0\n/dev/v4l-subdev0 | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green]
+ n00000001:port0 -> n00000009:port1 [style=dashed]
+ n00000003 [label="{{} | mali-c720 tpg 1\n/dev/v4l-subdev1 | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green]
+ n00000003:port0 -> n00000009:port1 [style=dashed]
+ n00000009 [label="{{<port1> 1} | mali-c720 input\n/dev/v4l-subdev2 | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green]
+ n00000009:port0 -> n0000000c:port0
+ n0000000c [label="{{<port0> 0} | mali-c720 isp\n/dev/v4l-subdev3 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
+ n0000000c:port1 -> n00000014:port0
+ n00000014 [label="{{<port0> 0} | mali-c720 hv pipe\n/dev/v4l-subdev4 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
+ n00000014:port1 -> n0000001c:port0
+ n0000001c [label="{{<port0> 0} | mali-c720 fr 0 pipe\n/dev/v4l-subdev5 | {<port1> 1 | <port2> 2}}", shape=Mrecord, style=filled, fillcolor=green]
+ n0000001c:port1 -> n00000038
+ n0000001c:port2 -> n0000003c [style=dashed]
+ n00000038 [label="mali-c720 fr0-rgb\n/dev/video0", shape=box, style=filled, fillcolor=yellow]
+ n0000003c [label="mali-c720 fr0-yuv\n/dev/video1", shape=box, style=filled, fillcolor=yellow]
+ n00000074 [label="{{<port0> 0} | csi2-rx\n/dev/v4l-subdev6 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
+ n00000074:port1 -> n00000009:port1
+ n00000079 [label="{{} | imx415 1-001a\n/dev/v4l-subdev7 | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green]
+ n00000079:port0 -> n00000074:port0 [style=bold]
+}
diff --git a/Documentation/admin-guide/media/mali-c720.rst b/Documentation/admin-guide/media/mali-c720.rst
new file mode 100644
index 0000000000000000000000000000000000000000..3ff2cb3170f257748878e78b85366b6462f76ff2
--- /dev/null
+++ b/Documentation/admin-guide/media/mali-c720.rst
@@ -0,0 +1,370 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===========================================
+Arm Mali-C720 Image Signal Processor driver
+===========================================
+
+Introduction
+============
+
+This file documents the driver for Arm's Mali-C720AE Image Signal Processor. The
+driver is located under drivers/media/platform/arm/mali-c720.
+
+The Mali-C720 ISP receives raw Bayer data from sensors through an input
+frontend. The driver uses the first of the hardware's four parallel input
+interfaces.
+The ISP features an image-processing pipeline targeting human vision (HV)
+applications.
+
+Output images are written to memory through an internal DMA engine. The
+full-resolution (FR0) output pipeline supports cropping and scaling, with
+simultaneous RGB and YUV outputs.
+
+Two independent test pattern generators feed the input frontend, allowing the
+ISP to produce images without a connected camera sensor. The driver module is
+named ``mali-c720`` and is enabled through ``CONFIG_VIDEO_MALI_C720``.
+
+The driver implements the V4L2, Media Controller and V4L2 subdevice interfaces.
+Camera sensors and receivers connected to the ISP are expected to expose V4L2
+subdevices.
+
+Mali-C720 ISP hardware
+======================
+
+The ISP exposes a set of hardware ID registers. The driver matches these
+against a set of supported hardware versions and rejects unsupported versions.
+Different hardware versions may expose different functionality, including
+available image formats, pipeline topology, and supported statistics and
+parameter modules.
+
+The ISP is also configurable at synthesis time, allowing certain pipelines and
+processing modules to be included or excluded. The ISP exposes a discovery
+table describing the resulting hardware configuration. The driver queries this
+table during initialization to register the appropriate subdevices and
+programmable blocks.
+
+A high-level functional view of the Mali-C720 ISP is shown below. Live inputs
+and the test pattern generators feed the input frontend::
+
+ +---------------------+ +---------------+
+ | 4 parallel inputs | | TPG 0 / TPG 1 |
+ +---------------------+ +---------------+
+ | |
+ +------------+----------+
+ |
+ +-------------v---------------+
+ | Input frontend |
+ +-----------------------------+
+ |
+ |
+ +-------------v---------------+
+ | Context manager |
+ +-----------------------------+
+ |
+ |
+ +-------------v---------------+
+ | Input processing |
+ +-----------------------------+
+ |
+ |
+ +--------v--------+
+ | HV processing |
+ +-----------------+
+ |
+ | RGB
+ |
+ +-------------v---------------+
+ | FR0 |
+ | Scale / crop |
+ +----+-------------------+----+
+ | |
+ | RGB | YUV
+ | |
+ v v
+ Memory Memory
+
+The FR0 pipeline has simultaneous RGB/YUV outputs. All image outputs shown
+as Memory use the internal output DMA engine.
+
+Configuration DMA engine (CDMA)
+===============================
+
+The ISP hardware includes a configuration DMA (CDMA) engine that loads ISP
+configuration from allocated memory into registers and stores computed fields,
+including statistics, back into that memory. Configuration is loaded at the
+beginning of frame processing. Computed fields are stored as they become
+available, typically around frame end.
+
+The CDMA engine also includes a scatter-gather unit that transfers ISP
+registers and internal memory tables to and from selected memory offsets,
+with configurable transfer sizes.
+
+For each context, the driver allocates a contiguous DMA region for the ISP
+configuration and initializes it for a default use case. At stream start, it
+configures additional fields such as the frame geometry and colour filter
+array (CFA) pattern.
+
+The driver uses the scatter-gather unit to store ISP statistics blocks in the
+queued videobuf2 (VB2) buffer. The UAPI structures for these blocks reflect the
+data packing produced by the CDMA engine.
+
+Media Controller Topology
+=========================
+
+An example of the ISP's topology (as implemented in a system with an IMX415
+camera sensor and generic CSI-2 receiver) is below.
+
+.. kernel-figure:: mali-c720-graph.dot
+ :alt: Mali-C720 media controller topology
+ :align: center
+
+The driver has up to six V4L2 subdevices:
+
+- ``mali-c720 tpg N``: Test pattern generator (0-1).
+- ``mali-c720 input``: Sensor input frontend.
+- ``mali-c720 isp``: ISP input pipeline.
+- ``mali-c720 hv pipe``: Human vision pipeline.
+- ``mali-c720 fr 0 pipe``: Full-resolution crop/scale pipeline.
+
+The driver has two V4L2 video devices:
+
+- ``mali-c720 fr0-rgb`` and ``mali-c720 fr0-yuv``: FR capture devices.
+
+Input formats
+-------------
+
+The ISP input is limited to resolutions between 256x256 and 8192x4608, and
+this is reflected in the ISP subdevice's .set_fmt() operations.
+With further crop and scale configurations, the minimum output from the ISP
+can be 64x64, reflected in the full-resolution output pipeline subdevice.
+
+Using the driver to capture video
+=================================
+
+Using the media controller APIs we can configure the input source and ISP to
+capture images in a variety of formats. In the examples below, configuring the
+media graph is done with the v4l-utils [1]_ package's media-ctl utility.
+Capturing the images is done with yavta [2]_.
+
+Before configuring the graph, stop any capture applications and disable the
+existing links. The driver enables an image output link by default. Resetting
+the links allows us to enable only the devices required for capture:
+
+.. code-block:: none
+
+ media-ctl -r
+
+Configuring the input source
+----------------------------
+
+To use TPG 0, enable its link to input port 0 and connect the slot input to the
+ISP.
+
+The first step is to set the input source that we wish to use by enabling the
+correct media link. Using the example topology above, we can select the
+TPG as follows:
+
+.. code-block:: none
+
+ media-ctl -l "'csi2-rx':1->'mali-c720 input':1[0]"
+ media-ctl -l "'mali-c720 tpg 0':0->'mali-c720 input':1[1]"
+ media-ctl -l "'mali-c720 input':0->'mali-c720 isp':0[1]"
+
+This links TPG-0 to the input port, and links the slot input to the ISP sink
+pad.
+
+Test pattern mode selection
+---------------------------
+
+The test pattern generator offers various patterns:
+ 0 (flat field), 1 (horizontal gradient), 2 (vertical gradient),
+ 3 (vertical bars, the default), 4 (arbitrary rectangle),
+ 5 (random data), and 6 (white frame on black field).
+
+We can select the vertical bars test pattern as follows:
+
+.. code-block:: none
+
+ v4l2-ctl -d /dev/v4l-subdev0 --set-ctrl=test_pattern=3
+
+Configuring the image processing pipeline
+-----------------------------------------
+
+The example below shows how we can route the image data through the human
+vision pipeline of the ISP, and from there to the first full resolution
+output pipe:
+
+.. code-block:: none
+
+ media-ctl -l "'mali-c720 isp':1->'mali-c720 hv pipe':0[1]"
+ media-ctl -l "'mali-c720 hv pipe':1->'mali-c720 fr 0 pipe':0[1]"
+
+Configuring which video devices will stream data
+------------------------------------------------
+
+The driver waits for all video devices connected through enabled links to have
+their VIDIOC_STREAMON ioctl called before starting the input source. Enable
+links only to the video devices that will be used. In the example below we
+enable the link to the `fr0-rgb` video device.
+
+.. code-block:: none
+
+ media-ctl -l "'mali-c720 fr 0 pipe':1->'mali-c720 fr0-rgb':0[1]"
+
+Capturing Bayer data and processing it to RGB
+--------------------------------------------
+
+To capture 1920x1080 Bayer data from the source and push it through the ISP's
+full processing pipeline, we configure formats from the input source towards
+the output.
+
+The TPG produces 16-bit Bayer data, the input subdevice outputs this as 24-bit
+Bayer. The input pipeline, represented by the ISP subdevice, transforms the
+data into the square-root domain and feeds 16-bit Bayer into HV. Within HV,
+the debayering occurs and then produces the 12-bit RGB input used by FR0.
+
+For our example, the formats are configured as follows:
+
+.. code-block:: none
+
+ media-ctl -V "'mali-c720 tpg 0':0[fmt:SRGGB16_1X16/1920x1080]"
+ media-ctl -V "'mali-c720 input':1[fmt:SRGGB16_1X16/1920x1080]"
+ media-ctl -V "'mali-c720 isp':0[fmt:SRGGB24_1X24/1920x1080]"
+ media-ctl -V "'mali-c720 hv pipe':0[fmt:SRGGB16_1X16/1920x1080]"
+ media-ctl -V "'mali-c720 fr 0 pipe':0[fmt:RGB121212_1X36/1920x1080]"
+
+Images can then be captured from the FR0-RGB video device:
+
+.. code-block:: none
+
+ yavta -f RGB24 -s 1920x1080 -c10 /dev/video0
+
+Capturing from multiple outputs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The RGB and YUV outputs can capture images at the same time. For example,
+enable both FR0 capture nodes:
+
+.. code-block:: none
+
+ media-ctl -l "'mali-c720 fr 0 pipe':1->'mali-c720 fr0-rgb':0[1]"
+ media-ctl -l "'mali-c720 fr 0 pipe':2->'mali-c720 fr0-yuv':0[1]"
+
+Starting the first video device validates the entire media pipeline and
+prevents further format changes. As such, when capturing from multiple outputs,
+formats must be configured on all enabled subdevices and linked video devices
+before starting any streams. For example, set both capture formats using v4l2-ctl:
+
+.. code-block:: none
+
+ v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=RGB3
+ v4l2-ctl -d /dev/video1 --set-fmt-video=width=1920,height=1080,pixelformat=NV12
+
+Then run the two capture processes concurrently:
+
+.. code-block:: none
+
+ yavta -c10 /dev/video0 &
+ yavta -c10 /dev/video1 &
+ wait
+
+Cropping the image
+~~~~~~~~~~~~~~~~~~
+
+The full-resolution pipeline can crop to a minimum resolution of 64x64.
+To crop the image, configure the pipe's source pad crop rectangle and set
+the format on the video device. The FR pipeline has one shared crop for
+its RGB and YUV outputs. Setting the crop on either source pad updates
+both source crops and output dimensions:
+
+.. code-block:: none
+
+ media-ctl -V "'mali-c720 fr 0 pipe':1[crop:(640,300)/640x480]"
+ yavta -f RGB24 -s 640x480 -c10 /dev/video0
+
+Downscaling the image
+~~~~~~~~~~~~~~~~~~~~~
+
+The full-resolution pipeline can produce full-size, cropped or downscaled
+images. Downscaling by up to ~16x is supported, provided the minimum 64x64
+output resolution is adhered to. For the best image result the scaling ratio
+for each direction should be the same. Scaling is configured with the compose
+rectangle on the pipe's sink pad. RGB and YUV outputs share the same
+scaling configuration:
+
+.. code-block:: none
+
+ media-ctl -V "'mali-c720 fr 0 pipe':0[compose:(0,0)/640x360]"
+ yavta -f RGB24 -s 640x360 -c10 /dev/video0
+
+Cropping is applied after scaling. To combine the two operations, set the
+compose rectangle first, then the crop rectangle.
+
+Capturing images in YUV formats
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Within the full resolution pipe there is a colour space conversion block for
+the YUV conversion, but its design permits the RGB and YUV to be output
+simultaneously. Enable the link between the pipe and the YUV video device,
+then configure a capture format like NV12:
+
+.. code-block:: none
+
+ media-ctl -l "'mali-c720 fr 0 pipe':1->'mali-c720 fr0-rgb':0[0]"
+ media-ctl -l "'mali-c720 fr 0 pipe':2->'mali-c720 fr0-yuv':0[1]"
+ yavta -f NV12 -s 1920x1080 -c10 /dev/video1
+
+.. _mali-c720-frame-scheduling:
+
+Frame scheduling and Media Requests
+===================================
+
+Frame scheduling depends on whether the streaming videobuf2 (VB2) queues use
+direct buffer queuing or Media Requests. Use of Media Requests is optional.
+
+Direct mode
+-----------
+
+When all streaming image capture queues use direct buffer queuing through
+:ref:`VIDIOC_QBUF`, the driver schedules frames in free-running mode.
+Scheduling starts only when at least one image output buffer is ready.
+Once started, it continues scheduling frames using the available buffers.
+Empty image capture queues disable their respective capture for the
+scheduled frame.
+
+Request mode
+------------
+
+If any of these streaming VB2 queues uses Media Requests, scheduling starts
+when a request is queued. Each subsequent frame also requires a queued
+request.
+
+Applications allocate a request using :ref:`MEDIA_IOC_REQUEST_ALLOC` on the
+media device.
+Image buffers are associated with it through
+:ref:`VIDIOC_QBUF`, setting ``V4L2_BUF_FLAG_REQUEST_FD`` and ``request_fd``.
+The request is then submitted using :ref:`MEDIA_REQUEST_IOC_QUEUE` on the
+request file descriptor.
+
+Controls cannot currently be associated with Media Requests. Requests
+containing controls are rejected when queued.
+
+A request does not need to include a buffer for every capture queue.
+Queues without a buffer will be disabled for the scheduled frame.
+
+All buffers associated with the request are usually applied on the same
+frame, but a request could span multiple frames if multiple buffers are
+queued for the same buffer queue. Completed buffers are returned to userspace through
+:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`.
+
+It is permitted to queue buffers directly in other VB2 queues alongside
+those operating in request mode, with requests still driving scheduling.
+Whenever a request is scheduled, available buffers from these queues can
+be used for the same frame, alongside buffers associated with the request.
+
+References
+==========
+
+.. [1] https://git.linuxtv.org/v4l-utils.git/
+.. [2] https://git.ideasonboard.org/yavta.git/
+.. [3] https://support.arm.com/compute-ip/mali-c720ae
diff --git a/Documentation/admin-guide/media/v4l-drivers.rst b/Documentation/admin-guide/media/v4l-drivers.rst
index 4621eae9fa1edf3686c2fc7228c7f4784bd79d5c..d47c3de7dbea2a42816c8de6e7544be5d681d11a 100644
--- a/Documentation/admin-guide/media/v4l-drivers.rst
+++ b/Documentation/admin-guide/media/v4l-drivers.rst
@@ -21,6 +21,7 @@ Video4Linux (V4L) driver-specific documentation
ipu6-isys
ivtv
mali-c55
+ mali-c720
mgb4
omap3isp
philips
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 16/24] media: uapi: Add Mali-C720 statistics meta format
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (14 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 15/24] media: Documentation: Add Mali-C720 ISP documentation Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 17/24] media: uapi: Add statistics structs to mali-c720-config.h Anthony McGivern
` (7 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add a new meta format for the Mali-C720 ISP's 3A statistics along
with a format description.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
drivers/media/v4l2-core/v4l2-ioctl.c | 1 +
include/uapi/linux/videodev2.h | 3 +++
2 files changed, 4 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 17ba1ae707355a134047de646f61fcc2d1512d4c..657adc0f4550e50aafc8855de524eb2e7c6297cb 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1471,6 +1471,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_META_FMT_C3ISP_STATS: descr = "Amlogic C3 ISP Statistics"; break;
case V4L2_META_FMT_MALI_C55_PARAMS: descr = "ARM Mali-C55 ISP Parameters"; break;
case V4L2_META_FMT_MALI_C55_STATS: descr = "ARM Mali-C55 ISP 3A Statistics"; break;
+ case V4L2_META_FMT_MALI_C720_STATS: descr = "ARM Mali-C720 ISP 3A Statistics"; break;
case V4L2_META_FMT_RPPX1_PARAMS: descr = "Dreamchip RPP-X1 ISP Parameters"; break;
case V4L2_META_FMT_RPPX1_STATS: descr = "Dreamchip RPP-X1 ISP Statistics"; break;
case V4L2_PIX_FMT_NV12_8L128: descr = "NV12 (8x128 Linear)"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 5373dba640fae3d19247ab1c74ba336e05dc0fe0..a59f6642ce3d120c28f395f72653137831ef09b6 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -889,6 +889,9 @@ struct v4l2_pix_format {
#define V4L2_META_FMT_MALI_C55_PARAMS v4l2_fourcc('C', '5', '5', 'P') /* ARM Mali-C55 Parameters */
#define V4L2_META_FMT_MALI_C55_STATS v4l2_fourcc('C', '5', '5', 'S') /* ARM Mali-C55 3A Statistics */
+/* Vendor specific - used for Arm Mali-C720 ISP */
+#define V4L2_META_FMT_MALI_C720_STATS v4l2_fourcc('C', '7', '2', 'S') /* ARM Mali-C720 3A Statistics */
+
/* Vendor specific - used for Dreamchip RPP-X1 ISP */
#define V4L2_META_FMT_RPPX1_PARAMS v4l2_fourcc('D', 'R', '1', 'P') /* Dreamchip RPP-X1 Parameters */
#define V4L2_META_FMT_RPPX1_STATS v4l2_fourcc('D', 'R', '1', 'S') /* Dreamchip RPP-X1 Statistics */
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 17/24] media: uapi: Add statistics structs to mali-c720-config.h
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (15 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 16/24] media: uapi: Add Mali-C720 statistics meta format Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 18/24] media: mali-c720: Add 3A statistics video node Anthony McGivern
` (6 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Describe the format of the 3A statistics buffers in the userspace API
for the Mali-C720 ISP.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
include/uapi/linux/media/arm/mali-c720-config.h | 184 ++++++++++++++++++++++++
1 file changed, 184 insertions(+)
diff --git a/include/uapi/linux/media/arm/mali-c720-config.h b/include/uapi/linux/media/arm/mali-c720-config.h
new file mode 100644
index 0000000000000000000000000000000000000000..445cae09a84cce37de9b15e051b93f96b06cbc50
--- /dev/null
+++ b/include/uapi/linux/media/arm/mali-c720-config.h
@@ -0,0 +1,184 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#ifndef __UAPI_MALI_C720_CONFIG_H
+#define __UAPI_MALI_C720_CONFIG_H
+
+#include <linux/types.h>
+#include <linux/v4l2-controls.h>
+#include <linux/media/v4l2-isp.h>
+
+#define MALI_C720_MAX_ZONES 1024
+
+/**
+ * struct mali_c720_awb_stats_nodes_used - Color statistics zone dimensions
+ * @reserved1: Undefined buffer space
+ * @nodes_used_horiz: Number of horizontal zones used for this frame
+ * @nodes_used_vert: Number of vertical zones used for this frame
+ * @reserved2: Undefined buffer space
+ *
+ * The product of the dimensions gives the number of valid zone records in
+ * &struct mali_c720_awb_statistics, up to MALI_C720_MAX_ZONES.
+ */
+struct mali_c720_awb_stats_nodes_used {
+ __u8 reserved1[8];
+ __u8 nodes_used_horiz;
+ __u8 nodes_used_vert;
+ __u8 reserved2[6];
+} __attribute__((aligned(16)));
+
+/**
+ * struct mali_c720_awb_statistics_tail - Global color statistics
+ * @global_rg: Global R/G or G/R ratio, in Q4.8 format
+ * @global_bg: Global B/G or G/B ratio, in Q4.8 format
+ * @global_num_pixels: Number of accepted pixels after zone weighting
+ * @frame_count: Frame counter
+ * @crc16: Statistics CRC
+ * @reserved: Undefined buffer space
+ *
+ * This structure contains the global color ratios and pixel count. It follows
+ * the active zone records and can be located using mali_c720_awb_stats_tail().
+ * The ratio mode is selected by awb_stats_mode in
+ * &struct mali_c720_params_color_stats. See &enum mali_c720_awb_stats_mode.
+ */
+struct mali_c720_awb_statistics_tail {
+ __le16 global_rg;
+ __le16 global_bg;
+ __le32 global_num_pixels;
+ __le32 frame_count;
+ __le16 crc16;
+ __u8 reserved[2];
+};
+
+/**
+ * struct mali_c720_awb_statistics - Per-zone and global color statistics
+ * @zones: Zone records in row-major order, starting at the top left
+ * @zones.avg_rg: R/G or G/R ratio, in Q4.8 format
+ * @zones.avg_bg: B/G or G/B ratio, in Q4.8 format
+ * @zones.num_pixels: Number of accepted pixels in the zone before weighting
+ * @tail_reserved: Undefined buffer space
+ * @nodes_used: Zone dimensions used for this frame
+ *
+ * The ISP collects average color ratios and pixel counts for each zone. The
+ * global statistics follow the last active zone and can be located using
+ * mali_c720_awb_stats_tail(). The ratio mode is selected by awb_stats_mode in
+ * &struct mali_c720_params_color_stats. See &enum mali_c720_awb_stats_mode.
+ */
+struct mali_c720_awb_statistics {
+ struct {
+ __le16 avg_rg;
+ __le16 avg_bg;
+ __le32 num_pixels;
+ } zones[MALI_C720_MAX_ZONES];
+
+ __u8 tail_reserved[sizeof(struct mali_c720_awb_statistics_tail)];
+ struct mali_c720_awb_stats_nodes_used nodes_used;
+} __attribute__((aligned(16)));
+
+static inline struct mali_c720_awb_statistics_tail *
+mali_c720_awb_stats_tail(struct mali_c720_awb_statistics *stats)
+{
+ return (struct mali_c720_awb_statistics_tail *)
+ (stats->zones + stats->nodes_used.nodes_used_horiz *
+ stats->nodes_used.nodes_used_vert);
+}
+
+/**
+ * struct mali_c720_ae_1024bin_hist - Histogram statistics
+ * @bins: 1024 compressed, weighted pixel counts
+ * @total_pixels: Number of sampled pixels before weighting
+ * @counted_pixels: Sum of weights accumulated in all histogram banks
+ * @plane_total: Sampled pixel counts for each bank before weighting
+ * @plane_counted: Sum of weights accumulated in each bank
+ * @frame_count: Frame counter
+ * @crc16: Statistics CRC
+ * @reserved: Undefined buffer space
+ *
+ * The histogram collects a zone-weighted distribution of pixel intensities.
+ * The configured plane mode selects one 1024-bin histogram, four 256-bin
+ * histograms or two 512-bin histograms, stored consecutively in @bins. The
+ * bank counters follow the same order.
+ *
+ * Each bin contains a four-bit exponent followed by a twelve-bit mantissa.
+ * An approximate weighted pixel count can be decoded as::
+ *
+ * e = bin >> 12;
+ * m = bin & 0xfff;
+ * count = (e ? (m + 4096) << (e - 1) : m) * 4;
+ */
+struct mali_c720_ae_1024bin_hist {
+ __le16 bins[1024];
+ __le32 total_pixels;
+ __le32 counted_pixels;
+ __le32 plane_total[4];
+ __le32 plane_counted[4];
+ __le32 frame_count;
+ __le16 crc16;
+ __u8 reserved[2];
+} __attribute__((aligned(16)));
+
+/**
+ * enum mali_c720_stats_type - Mali-C720 statistics block targets
+ * @MALI_C720_STATS_NOOP: No data; skip the block using its size.
+ * @MALI_C720_STATS_HISTOGRAM_INP: Input histogram statistics.
+ * @MALI_C720_STATS_HISTOGRAM_HV: HV histogram statistics (pre-Iridix).
+ * @MALI_C720_STATS_HISTOGRAM_HV_IRIDIX: HV histogram statistics (post-Iridix).
+ * @MALI_C720_STATS_COLOR_HV: HV color statistics.
+ */
+enum mali_c720_stats_type {
+ MALI_C720_STATS_NOOP,
+ MALI_C720_STATS_HISTOGRAM_INP,
+ MALI_C720_STATS_HISTOGRAM_HV,
+ MALI_C720_STATS_HISTOGRAM_HV_IRIDIX,
+ MALI_C720_STATS_COLOR_HV,
+ MALI_C720_STATS_MAX,
+};
+
+/**
+ * struct mali_c720_stats_color - Color statistics block
+ * @header: Generic V4L2 ISP block header; type identifies the color statistics
+ * target from &enum mali_c720_stats_type
+ * @reserved: Undefined buffer space
+ * @data: Color statistics payload
+ */
+struct mali_c720_stats_color {
+ struct v4l2_isp_block_header header;
+ __u8 reserved[8];
+ struct mali_c720_awb_statistics data;
+};
+
+/**
+ * struct mali_c720_stats_histogram - Histogram statistics block
+ * @header: Generic V4L2 ISP block header; type identifies the histogram target
+ * from &enum mali_c720_stats_type
+ * @reserved: Undefined buffer space
+ * @data: Histogram payload
+ */
+struct mali_c720_stats_histogram {
+ struct v4l2_isp_block_header header;
+ __u8 reserved[8];
+ struct mali_c720_ae_1024bin_hist data;
+};
+
+/**
+ * MALI_C720_STATS_MAX_SIZE - Maximum serialized statistics block size
+ *
+ * Maximum size of all statistics blocks in a full hardware configuration,
+ * including the initial NOOP block used for alignment, but excluding the
+ * struct v4l2_isp_buffer header. The actual buffer size depends on the
+ * discovered statistics blocks and is reported through the metadata format.
+ */
+#define MALI_C720_STATS_MAX_SIZE \
+ (sizeof(struct v4l2_isp_block_header) + \
+ sizeof(struct mali_c720_stats_color) + \
+ sizeof(struct mali_c720_stats_histogram) + \
+ sizeof(struct mali_c720_stats_histogram) + \
+ sizeof(struct mali_c720_stats_histogram))
+
+#define V4L2_CID_MALI_C720_STATS_CAPABILITIES (V4L2_CID_USER_MALI_C720_BASE + 0)
+
+#endif
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 18/24] media: mali-c720: Add 3A statistics video node
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (16 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 17/24] media: uapi: Add statistics structs to mali-c720-config.h Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 19/24] media: Documentation: Document Mali-C720 statistics capture Anthony McGivern
` (5 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add a metadata capture node for ISP statistics used by userspace image
processing algorithms, such as auto-exposure and auto-white-balance.
Use the ISP's configuration DMA engine (CDMA) scatter-gather unit to
transfer statistics into queued buffers and return them at frame end.
Each buffer carries the sequence number of the processed frame,
matching image buffers produced from that frame.
Initial support exposes colour statistics and pixel intensity
histograms. Available statistics blocks are reported through a read-only
capability control.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
drivers/media/platform/arm/mali-c720/Kconfig | 1 +
drivers/media/platform/arm/mali-c720/Makefile | 1 +
.../platform/arm/mali-c720/mali-c720-common.h | 51 ++
.../media/platform/arm/mali-c720/mali-c720-core.c | 43 +-
.../platform/arm/mali-c720/mali-c720-ctx-mgr.c | 166 ++++-
.../platform/arm/mali-c720/mali-c720-ctx-mgr.h | 24 +
.../media/platform/arm/mali-c720/mali-c720-isp.c | 17 +-
.../media/platform/arm/mali-c720/mali-c720-stats.c | 730 +++++++++++++++++++++
8 files changed, 1028 insertions(+), 5 deletions(-)
diff --git a/drivers/media/platform/arm/mali-c720/Kconfig b/drivers/media/platform/arm/mali-c720/Kconfig
index 576b619fe06c9b96115eeb825f5e8130d9f67395..2785631c258d3c21673d13542658d1ed587b11be 100644
--- a/drivers/media/platform/arm/mali-c720/Kconfig
+++ b/drivers/media/platform/arm/mali-c720/Kconfig
@@ -7,6 +7,7 @@ config VIDEO_MALI_C720
select CRC_ITU_T
select MEDIA_CONTROLLER
select V4L2_FWNODE
+ select V4L2_ISP
select VIDEO_V4L2_SUBDEV_API
select VIDEOBUF2_DMA_CONTIG
select VIDEOBUF2_VMALLOC
diff --git a/drivers/media/platform/arm/mali-c720/Makefile b/drivers/media/platform/arm/mali-c720/Makefile
index b818f6c9b44ef335e78a307ccc232c134e94db61..c48d54dac23a94d429349d90eaf96c19bc017468 100644
--- a/drivers/media/platform/arm/mali-c720/Makefile
+++ b/drivers/media/platform/arm/mali-c720/Makefile
@@ -15,6 +15,7 @@ mali-c720-y := mali-c720-capture.o \
mali-c720-registers-top.o \
mali-c720-registers-ctx-mgr.o \
mali-c720-registers-modules.o \
+ mali-c720-stats.o \
mali-c720-tpg.o \
mali-c720-vision-pipe.o \
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 0018c7b5776f34bdd7c262c51972f619255720e2..7a137de2e020d9de18df9918fe54519fab111a38 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -27,6 +27,8 @@
#include <media/videobuf2-core.h>
#include <media/videobuf2-v4l2.h>
+#include <linux/media/arm/mali-c720-config.h>
+
#include "mali-c720-ctx-mgr.h"
#include "mali-c720-discovery.h"
#include "mali-c720-formats.h"
@@ -108,6 +110,7 @@ struct mali_c720_input {
enum mali_c720_isp_pads {
MALI_C720_ISP_PAD_SINK_VIDEO,
MALI_C720_ISP_PAD_SOURCE_HV,
+ MALI_C720_ISP_PAD_SOURCE_STATS,
MALI_C720_ISP_NUM_PADS,
};
@@ -210,6 +213,42 @@ struct mali_c720_cap_dev {
} buffers;
};
+struct mali_c720_stats_buf {
+ struct vb2_v4l2_buffer vb;
+ struct list_head queue;
+ dma_addr_t addr;
+};
+
+struct mali_c720_stats_target {
+ struct mali_c720_cdma_sg_cfg desc[2];
+ u8 num_desc;
+ bool present;
+};
+
+struct mali_c720_stats {
+ struct mali_c720 *mali_c720;
+ unsigned int num_targets;
+ struct mali_c720_stats_target targets[MALI_C720_STATS_MAX];
+ u32 buffer_size;
+ struct video_device vdev;
+ struct vb2_queue queue;
+ struct media_pad pad;
+ /* Mutex to provide to vb2 */
+ struct mutex lock;
+
+ struct {
+ /* Spinlock to guard buffer queue */
+ spinlock_t lock;
+ struct list_head input;
+ struct list_head processing;
+ } buffers;
+
+ struct {
+ struct v4l2_ctrl_handler handler;
+ struct v4l2_ctrl *stats_capabilities;
+ } ctrls;
+};
+
struct mali_c720_request {
struct media_request req;
unsigned int queue_sequence;
@@ -283,6 +322,7 @@ struct mali_c720 {
struct mali_c720_vision_pipe vision_pipe;
struct mali_c720_fr_pipe fr_pipe;
struct mali_c720_cap_dev cap_devs[MALI_C720_MAX_NUM_CAP_DEVS];
+ struct mali_c720_stats stats;
unsigned int num_async_endpoints;
@@ -330,6 +370,10 @@ int mali_c720_register_capture_devs(struct mali_c720 *mali_c720);
void mali_c720_unregister_capture_devs(struct mali_c720 *mali_c720);
void mali_c720_cleanup_capture_devs(struct mali_c720 *mali_c720);
+int mali_c720_register_stats(struct mali_c720 *mali_c720);
+void mali_c720_unregister_stats(struct mali_c720 *mali_c720);
+void mali_c720_cleanup_stats(struct mali_c720 *mali_c720);
+
void mali_c720_fr_pipe_apply_resizer_config(struct mali_c720_fr_pipe *pipe);
bool mali_c720_cap_dev_uses_requests(struct mali_c720_cap_dev *cap_dev);
@@ -340,6 +384,13 @@ void mali_c720_cap_dev_set_next_buffer(struct mali_c720_cap_dev *cap_dev,
void mali_c720_cap_dev_buffer_done(struct mali_c720_cap_dev *cap_dev,
bool success);
+bool mali_c720_stats_uses_requests(struct mali_c720_stats *stats);
+struct media_request *mali_c720_stats_get_request(struct mali_c720_stats *stats);
+int mali_c720_stats_is_ready(struct mali_c720_stats *stats);
+void mali_c720_stats_set_next_buffer(struct mali_c720_stats *stats,
+ struct media_request *req);
+void mali_c720_stats_buffer_done(struct mali_c720_stats *stats, bool success);
+
void mali_c720_isp_queue_event_sof(struct mali_c720 *mali_c720, u32 sequence);
int mali_c720_pipeline_ready(struct mali_c720 *mali_c720);
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-core.c b/drivers/media/platform/arm/mali-c720/mali-c720-core.c
index a6970c921ad486a41073779862bab68a22ce35f1..ad768b0a2e03a0a6f38b72603ccdedaeeee42f0a 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-core.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-core.c
@@ -45,6 +45,8 @@ static void mali_c720_remove_links(struct mali_c720 *mali_c720)
for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++)
media_entity_remove_links(&mali_c720->cap_devs[i].vdev.entity);
+
+ media_entity_remove_links(&mali_c720->stats.vdev.entity);
}
static int mali_c720_create_tpg_links(struct mali_c720 *mali_c720,
@@ -142,6 +144,24 @@ static int mali_c720_create_fr_pipe_links(struct mali_c720 *mali_c720)
return ret;
}
+static int mali_c720_create_3a_links(struct mali_c720 *mali_c720)
+{
+ struct v4l2_subdev *isp_sd = &mali_c720->isp.mdev.sd;
+ int ret;
+
+ ret = media_create_pad_link(&isp_sd->entity,
+ MALI_C720_ISP_PAD_SOURCE_STATS,
+ &mali_c720->stats.vdev.entity, 0,
+ 0);
+ if (ret) {
+ dev_err(mali_c720->dev,
+ "Failed to link ISP and 3A stats node\n");
+ return ret;
+ }
+
+ return ret;
+}
+
static int mali_c720_create_links(struct mali_c720 *mali_c720)
{
const struct mali_c720_discovery_target tpg = {
@@ -168,6 +188,10 @@ static int mali_c720_create_links(struct mali_c720 *mali_c720)
if (ret)
goto err_remove_links;
+ ret = mali_c720_create_3a_links(mali_c720);
+ if (ret)
+ goto err_remove_links;
+
return 0;
err_remove_links:
@@ -181,6 +205,7 @@ static void mali_c720_unregister_video_devices(struct mali_c720 *mali_c720)
guard(mutex)(&mali_c720->media_dev.req_queue_mutex);
mali_c720_unregister_capture_devs(mali_c720);
+ mali_c720_unregister_stats(mali_c720);
}
static void mali_c720_unregister_entities(struct mali_c720 *mali_c720)
@@ -221,6 +246,10 @@ static int mali_c720_register_entities(struct mali_c720 *mali_c720)
if (ret)
goto err_unregister_entities;
+ ret = mali_c720_register_stats(mali_c720);
+ if (ret)
+ goto err_unregister_entities;
+
ret = mali_c720_create_links(mali_c720);
if (ret)
goto err_unregister_entities;
@@ -341,6 +370,7 @@ static void mali_c720_release(struct v4l2_device *v4l2_dev)
struct mali_c720 *mali_c720 = container_of(v4l2_dev, struct mali_c720, v4l2_dev);
mali_c720_cleanup_capture_devs(mali_c720);
+ mali_c720_cleanup_stats(mali_c720);
mali_c720_cleanup_fr_pipe(mali_c720);
mali_c720_cleanup_vision_pipe(mali_c720);
mali_c720_cleanup_isp(mali_c720);
@@ -538,6 +568,9 @@ static bool mali_c720_has_ready_output(struct mali_c720 *mali_c720)
{
unsigned int i;
+ if (!mali_c720_stats_is_ready(&mali_c720->stats))
+ return true;
+
for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
if (!mali_c720_cap_dev_is_ready(&mali_c720->cap_devs[i]))
return true;
@@ -569,9 +602,12 @@ mali_c720_oldest_request(struct media_request *oldest, struct media_request *can
static struct media_request *mali_c720_find_request(struct mali_c720 *mali_c720)
{
- struct media_request *candidate, *req = NULL;
+ struct media_request *candidate, *req;
unsigned int i;
+ candidate = mali_c720_stats_get_request(&mali_c720->stats);
+ req = mali_c720_oldest_request(NULL, candidate);
+
for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
candidate = mali_c720_cap_dev_get_request(&mali_c720->cap_devs[i]);
req = mali_c720_oldest_request(req, candidate);
@@ -584,6 +620,9 @@ static bool mali_c720_uses_requests(struct mali_c720 *mali_c720)
{
unsigned int i;
+ if (mali_c720_stats_uses_requests(&mali_c720->stats))
+ return true;
+
for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
if (mali_c720_cap_dev_uses_requests(&mali_c720->cap_devs[i]))
return true;
@@ -632,6 +671,8 @@ void mali_c720_try_schedule_frame(struct mali_c720_context *ctx)
for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++)
mali_c720_cap_dev_set_next_buffer(&mali_c720->cap_devs[i], req);
+
+ mali_c720_stats_set_next_buffer(&mali_c720->stats, req);
}
ctx->pipeline_busy = true;
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
index 9391b087f74eed7dbf7f3bc1e2abbe5f8969fe86..cd0cf046ac58a001ec821342b2e64e85755438f1 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
@@ -188,6 +188,35 @@ static u16 mali_c720_crc16_mcrf4xx_reg(u16 crc, u32 data, u32 mask)
mali_c720_reg_width(mask));
}
+static u16 mali_c720_ctx_mgr_calc_cdma_sg_crc(const struct mali_c720_registers *regs,
+ const struct mali_c720_cdma_sg_table *sg_table,
+ unsigned int sg_table_size)
+{
+ const struct mali_c720_cm_sg_regs *load_cdma_sg_load = regs->cm->load_cdma_sg_load;
+ u16 crc = MALI_C720_CRC16_MCRF4XX_INIT;
+ u32 mask;
+ unsigned int i;
+
+ for (i = 0; i < sg_table_size; i++) {
+ const struct mali_c720_cdma_sg_cfg *desc = &sg_table->desc[i];
+
+ /* Load and store register masks are identical */
+ mask = mali_c720_reg_mask(&load_cdma_sg_load->isp_address);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->isp_address, mask);
+ mask = mali_c720_reg_mask(&load_cdma_sg_load->length_low);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->length_low, mask);
+ mask = mali_c720_reg_mask(&load_cdma_sg_load->length_high);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->length_high, mask);
+ mask = mali_c720_reg_mask(&load_cdma_sg_load->axi_address);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->axi_address, mask);
+ crc = mali_c720_crc16_mcrf4xx_bits(crc, 0, 7);
+ mask = mali_c720_reg_mask(&load_cdma_sg_load->alt_address);
+ crc = mali_c720_crc16_mcrf4xx_reg(crc, desc->alt_address, mask);
+ }
+
+ return crc;
+}
+
static u16 mali_c720_ctx_mgr_calc_cdma_desc_crc(struct mali_c720_context *ctx)
{
const struct mali_c720_cm_cdma_slot_regs *cdma_slot =
@@ -504,6 +533,92 @@ static void mali_c720_ctx_mgr_prepare_output_fifos(struct mali_c720_context *ctx
}
}
+int mali_c720_ctx_mgr_prepare_cdma_sg_descriptors(struct mali_c720 *mali_c720)
+{
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ struct mali_c720_cdma_sg_table *store = &ctx_mgr->sg_descriptors.store;
+ unsigned int i;
+
+ memset(&ctx_mgr->sg_descriptors, 0, sizeof(ctx_mgr->sg_descriptors));
+
+ for (i = 0; i < MALI_C720_STATS_MAX; i++) {
+ const struct mali_c720_stats_target *target = &mali_c720->stats.targets[i];
+
+ if (!target->present)
+ continue;
+
+ if (target->num_desc > ctx_mgr->cdma_sg_size - store->num_desc) {
+ dev_warn_once(mali_c720->dev, "Insufficient CDMA SG descriptors\n");
+ return -ENOSPC;
+ }
+
+ memcpy(&store->desc[store->num_desc], target->desc,
+ target->num_desc * sizeof(*target->desc));
+ store->num_desc += target->num_desc;
+ }
+
+ ctx_mgr->sg_descriptors.load.crc =
+ mali_c720_ctx_mgr_calc_cdma_sg_crc(regs, &ctx_mgr->sg_descriptors.load,
+ ctx_mgr->cdma_sg_size);
+ ctx_mgr->sg_descriptors.store.crc =
+ mali_c720_ctx_mgr_calc_cdma_sg_crc(regs, &ctx_mgr->sg_descriptors.store,
+ ctx_mgr->cdma_sg_size);
+
+ return 0;
+}
+
+static void mali_c720_ctx_mgr_write_cdma_sg_descriptors(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_registers *regs = &mali_c720->registers;
+ const struct mali_c720_cm_sg_regs *load_cdma_sg_load =
+ regs->cm->load_cdma_sg_load;
+ const struct mali_c720_cm_sg_regs *load_cdma_sg_store =
+ regs->cm->load_cdma_sg_store;
+ const struct mali_c720_cm_sg_crc_regs *load_cdma_sg_load_crc =
+ regs->cm->load_cdma_sg_load_crc;
+ const struct mali_c720_cm_sg_crc_regs *load_cdma_sg_store_crc =
+ regs->cm->load_cdma_sg_store_crc;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
+ unsigned int i;
+
+ for (i = 0; i < ctx_mgr->cdma_sg_size; i++) {
+ const struct mali_c720_cdma_sg_cfg *load = &ctx_mgr->sg_descriptors.load.desc[i];
+ const struct mali_c720_cdma_sg_cfg *store = &ctx_mgr->sg_descriptors.store.desc[i];
+ u32 base;
+
+ base = mali_c720_group_base(&load_cdma_sg_load->group, i);
+ mali_c720_ctx_group_write(ctx, base, &load_cdma_sg_load->isp_address,
+ load->isp_address);
+ mali_c720_ctx_group_write(ctx, base, &load_cdma_sg_load->length_low,
+ load->length_low);
+ mali_c720_ctx_group_write(ctx, base, &load_cdma_sg_load->length_high,
+ load->length_high);
+ mali_c720_ctx_group_write(ctx, base, &load_cdma_sg_load->axi_address,
+ load->axi_address);
+ mali_c720_ctx_group_write(ctx, base, &load_cdma_sg_load->alt_address,
+ load->alt_address);
+
+ base = mali_c720_group_base(&load_cdma_sg_store->group, i);
+ mali_c720_ctx_group_write(ctx, base, &load_cdma_sg_store->isp_address,
+ store->isp_address);
+ mali_c720_ctx_group_write(ctx, base, &load_cdma_sg_store->length_low,
+ store->length_low);
+ mali_c720_ctx_group_write(ctx, base, &load_cdma_sg_store->length_high,
+ store->length_high);
+ mali_c720_ctx_group_write(ctx, base, &load_cdma_sg_store->axi_address,
+ store->axi_address);
+ mali_c720_ctx_group_write(ctx, base, &load_cdma_sg_store->alt_address,
+ store->alt_address);
+ }
+
+ mali_c720_ctx_write(ctx, &load_cdma_sg_load_crc->cdma_sg_crc,
+ ctx_mgr->sg_descriptors.load.crc);
+ mali_c720_ctx_write(ctx, &load_cdma_sg_store_crc->cdma_sg_crc,
+ ctx_mgr->sg_descriptors.store.crc);
+}
+
static void mali_c720_ctx_mgr_write_buffer_desc(struct mali_c720_context *ctx,
struct mali_c720_buffer_pool *pool,
unsigned int index)
@@ -642,6 +757,25 @@ static void mali_c720_ctx_mgr_write_cdma_desc(struct mali_c720_context *ctx)
&cdma_slot->crc, desc->crc);
}
+static void mali_c720_ctx_mgr_update_cdma_desc(struct mali_c720_context *ctx)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_cm_cdma_slot_regs *cdma_slot = mali_c720->registers.cm->cdma_slot;
+ struct mali_c720_cdma_desc *desc = &ctx->cdma_desc;
+ u32 cdma_slot_addr = mali_c720_group_base(&cdma_slot->group, ctx->id);
+
+ desc->crc = mali_c720_ctx_mgr_calc_cdma_desc_crc(ctx);
+
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->alt_base_address_low, desc->alt_base_address_low);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->alt_base_address_high, desc->alt_base_address_high);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->st_sg_count, desc->st_sg_count);
+ mali_c720_group_write(mali_c720, cdma_slot_addr,
+ &cdma_slot->crc, desc->crc);
+}
+
static void mali_c720_ctx_mgr_write_slot_desc(struct mali_c720_context *ctx)
{
struct mali_c720 *mali_c720 = ctx->mali_c720;
@@ -1245,6 +1379,23 @@ void mali_c720_ctx_mgr_update_buffer(struct mali_c720_context *ctx,
mali_c720_ctx_mgr_relinquish_buffer_control(ctx, pool, index);
}
+void mali_c720_ctx_mgr_set_stats_buffer_address(struct mali_c720_context *ctx, dma_addr_t *addr)
+{
+ struct mali_c720_ctx_mgr *ctx_mgr = &ctx->mali_c720->ctx_mgr;
+
+ if (addr) {
+ ctx->cdma_desc.alt_base_address_low = lower_32_bits(*addr);
+ ctx->cdma_desc.alt_base_address_high = upper_32_bits(*addr);
+ ctx->cdma_desc.st_sg_count = ctx_mgr->sg_descriptors.store.num_desc;
+ } else {
+ ctx->cdma_desc.alt_base_address_low = 0;
+ ctx->cdma_desc.alt_base_address_high = 0;
+ ctx->cdma_desc.st_sg_count = 0;
+ }
+
+ mali_c720_ctx_mgr_update_cdma_desc(ctx);
+}
+
void mali_c720_ctx_mgr_prepare_frame(struct mali_c720_context *ctx)
{
lockdep_assert_held(&ctx->state_lock);
@@ -1273,6 +1424,8 @@ void mali_c720_ctx_mgr_buffer_done(struct mali_c720_context *ctx, bool success)
for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++)
mali_c720_cap_dev_buffer_done(&mali_c720->cap_devs[i], success);
+
+ mali_c720_stats_buffer_done(&mali_c720->stats, success);
}
void mali_c720_ctx_mgr_handle_sw_ready(struct mali_c720_context *ctx)
@@ -1290,6 +1443,7 @@ void mali_c720_ctx_mgr_configure_context(struct mali_c720_context *ctx,
struct mali_c720 *mali_c720 = ctx->mali_c720;
const struct mali_c720_registers *regs = &mali_c720->registers;
const struct mali_c720_pipeline_regs *pipeline = regs->top->pipeline;
+ struct mali_c720_ctx_mgr *ctx_mgr = &mali_c720->ctx_mgr;
dma_addr_t ctx_regs_addr = ctx->regs.dma_handle;
mali_c720_ctx_group_write(ctx, mali_c720->top_base,
@@ -1307,9 +1461,9 @@ void mali_c720_ctx_mgr_configure_context(struct mali_c720_context *ctx,
ctx->cdma_desc.units_high = 0;
ctx->cdma_desc.base_address_low = lower_32_bits(ctx_regs_addr);
ctx->cdma_desc.base_address_high = upper_32_bits(ctx_regs_addr);
- ctx->cdma_desc.ld_sg_count = 0;
+ ctx->cdma_desc.ld_sg_count = ctx_mgr->sg_descriptors.load.num_desc;
ctx->cdma_desc.st_sg_count = 0;
- ctx->cdma_desc.alt_transfer_size = 0;
+ ctx->cdma_desc.alt_transfer_size = mali_c720->stats.buffer_size;
ctx->cdma_desc.alt_base_address_low = 0;
ctx->cdma_desc.alt_base_address_high = 0;
@@ -1347,6 +1501,7 @@ void mali_c720_ctx_mgr_configure_context(struct mali_c720_context *ctx,
ctx->slot_desc_updated = false;
mali_c720_ctx_mgr_write_cdma_desc(ctx);
+ mali_c720_ctx_mgr_write_cdma_sg_descriptors(ctx);
}
void mali_c720_ctx_mgr_prepare_context(struct mali_c720_context *ctx,
@@ -1689,6 +1844,7 @@ int mali_c720_init_ctx_mgr(struct mali_c720 *mali_c720)
ctx_mgr->num_inputs * ctx_mgr->num_input_streams;
ctx_mgr->input_fifo_size = caps->input_fifo_size;
ctx_mgr->output_fifo_size = caps->output_fifo_size;
+ ctx_mgr->cdma_sg_size = caps->cdma_sg_size;
if (!ctx_mgr->num_raw_buffer_descriptors) {
dev_err(mali_c720->dev, "No raw buffer descriptors available\n");
@@ -1731,6 +1887,12 @@ int mali_c720_init_ctx_mgr(struct mali_c720 *mali_c720)
return -EINVAL;
}
+ if (ctx_mgr->cdma_sg_size > MALI_C720_MAX_CDMA_SG_DESCRIPTORS) {
+ dev_dbg(mali_c720->dev, "CDMA SG table size %u exceeds driver limit, truncating\n",
+ ctx_mgr->cdma_sg_size);
+ ctx_mgr->cdma_sg_size = MALI_C720_MAX_CDMA_SG_DESCRIPTORS;
+ }
+
num_slots = caps->num_slots;
if (num_slots <= MALI_C720_NUM_SAFETY_SLOTS) {
dev_err(mali_c720->dev,
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.h b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.h
index d5af820cc5527523dd42f00e849466b71871fa8b..05443d91212e97421c6b0f8d7118fe7486edd338 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.h
@@ -24,6 +24,7 @@ struct mali_c720_context;
#define MALI_C720_MAX_STREAMS_PER_INPUT 4
#define MALI_C720_MAX_VIRTUAL_INPUTS (MALI_C720_MAX_INPUTS * MALI_C720_MAX_STREAMS_PER_INPUT)
#define MALI_C720_MAX_CONTEXTS 16
+#define MALI_C720_MAX_CDMA_SG_DESCRIPTORS 32
#define MALI_C720_NUM_SAFETY_SLOTS 4
enum mali_c720_input_command {
@@ -185,6 +186,20 @@ struct mali_c720_cdma_desc {
u32 alt_base_address_high;
};
+struct mali_c720_cdma_sg_cfg {
+ u32 isp_address;
+ u16 length_low;
+ u8 length_high;
+ u32 axi_address;
+ u8 alt_address;
+};
+
+struct mali_c720_cdma_sg_table {
+ struct mali_c720_cdma_sg_cfg desc[MALI_C720_MAX_CDMA_SG_DESCRIPTORS];
+ u16 crc;
+ u8 num_desc;
+};
+
struct mali_c720_buffer_desc {
u16 crc;
u8 data_format;
@@ -253,6 +268,10 @@ struct mali_c720_ctx_mgr {
u8 input_context_map[MALI_C720_MAX_VIRTUAL_INPUTS];
unsigned long raw_buffer_descriptors[BITS_TO_LONGS(MALI_C720_MAX_RAW_BUFFERS)];
unsigned long out_buffer_descriptors[BITS_TO_LONGS(MALI_C720_MAX_OUT_BUFFERS)];
+ struct {
+ struct mali_c720_cdma_sg_table load;
+ struct mali_c720_cdma_sg_table store;
+ } sg_descriptors;
unsigned int num_raw_buffer_descriptors;
unsigned int reuse_buffer;
unsigned int num_out_buffer_descriptors;
@@ -260,6 +279,7 @@ struct mali_c720_ctx_mgr {
unsigned int num_input_streams;
unsigned int num_virtual_inputs;
unsigned int num_contexts;
+ unsigned int cdma_sg_size;
unsigned int input_fifo_size;
unsigned int output_fifo_size;
};
@@ -272,6 +292,8 @@ void mali_c720_free_context(struct mali_c720_context *ctx);
int mali_c720_init_ctx_mgr(struct mali_c720 *mali_c720);
+int mali_c720_ctx_mgr_prepare_cdma_sg_descriptors(struct mali_c720 *mali_c720);
+
int mali_c720_ctx_mgr_start_context_inputs(struct mali_c720_context *ctx);
void mali_c720_ctx_mgr_stop_context_inputs(struct mali_c720_context *ctx);
@@ -287,6 +309,8 @@ void mali_c720_ctx_mgr_update_buffer(struct mali_c720_context *ctx,
struct mali_c720_buffer_pool *pool,
dma_addr_t *addr,
unsigned int index);
+void mali_c720_ctx_mgr_set_stats_buffer_address(struct mali_c720_context *ctx,
+ dma_addr_t *addr);
void mali_c720_ctx_mgr_configure_context(struct mali_c720_context *ctx,
const struct mali_c720_top_cfg *cfg);
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-isp.c b/drivers/media/platform/arm/mali-c720/mali-c720-isp.c
index 962a2215543b49a6f90159fcb75ac253727cf2b6..a6c4da686bde0b76302ee9ad4fb49a132fa82b7c 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-isp.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-isp.c
@@ -23,7 +23,11 @@ static int mali_c720_isp_enum_mbus_code(struct v4l2_subdev *sd,
struct mali_c720_mbus_format_match match;
/* HV uses the sink Bayer order at the internal 16-bit precision. */
- if (code->pad == MALI_C720_ISP_PAD_SOURCE_HV) {
+ if (code->pad == MALI_C720_ISP_PAD_SOURCE_STATS) {
+ if (code->index)
+ return -EINVAL;
+ code->code = MEDIA_BUS_FMT_METADATA_FIXED;
+ } else if (code->pad == MALI_C720_ISP_PAD_SOURCE_HV) {
if (code->index)
return -EINVAL;
@@ -89,6 +93,8 @@ static int mali_c720_isp_enum_frame_size(struct v4l2_subdev *sd,
if (!cfg || !mali_c720_validate_mbus_format_match(cfg, &match))
return -EINVAL;
break;
+ case MALI_C720_ISP_PAD_SOURCE_STATS:
+ return -ENOTTY;
default:
return -EINVAL;
}
@@ -292,7 +298,7 @@ static const struct v4l2_subdev_ops mali_c720_isp_ops = {
static int mali_c720_isp_init_state(struct v4l2_subdev *sd,
struct v4l2_subdev_state *state)
{
- struct v4l2_mbus_framefmt *sink_fmt, *src_fmt;
+ struct v4l2_mbus_framefmt *sink_fmt, *src_fmt, *stats_fmt;
sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
sink_fmt->width = MALI_C720_DEFAULT_WIDTH;
@@ -308,6 +314,12 @@ static int mali_c720_isp_init_state(struct v4l2_subdev *sd,
*src_fmt = *sink_fmt;
src_fmt->code = MEDIA_BUS_FMT_SRGGB16_1X16;
+ stats_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SOURCE_STATS);
+ stats_fmt->width = 0;
+ stats_fmt->height = 0;
+ stats_fmt->field = V4L2_FIELD_NONE;
+ stats_fmt->code = MEDIA_BUS_FMT_METADATA_FIXED;
+
return 0;
}
@@ -370,6 +382,7 @@ int mali_c720_register_isp(struct mali_c720 *mali_c720)
isp->pads[MALI_C720_ISP_PAD_SINK_VIDEO].flags = MEDIA_PAD_FL_SINK |
MEDIA_PAD_FL_MUST_CONNECT;
isp->pads[MALI_C720_ISP_PAD_SOURCE_HV].flags = MEDIA_PAD_FL_SOURCE;
+ isp->pads[MALI_C720_ISP_PAD_SOURCE_STATS].flags = MEDIA_PAD_FL_SOURCE;
ret = media_entity_pads_init(&sd->entity,
MALI_C720_ISP_NUM_PADS,
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-stats.c b/drivers/media/platform/arm/mali-c720/mali-c720-stats.c
new file mode 100644
index 0000000000000000000000000000000000000000..fdb31ef136c04923543a3ac5ba0fa6bfeaeb2ca1
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-stats.c
@@ -0,0 +1,730 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/cleanup.h>
+#include <linux/container_of.h>
+#include <linux/dev_printk.h>
+#include <linux/dma-buf.h>
+#include <linux/err.h>
+#include <linux/media-bus-format.h>
+#include <linux/pm_runtime.h>
+#include <linux/string.h>
+
+#include <media/media-entity.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-fh.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-isp.h>
+#include <media/videobuf2-dma-contig.h>
+
+#include "mali-c720-common.h"
+
+struct mali_c720_stats_discovery_info {
+ u32 data_offset;
+ u32 table_size;
+ u32 nodes_offset;
+};
+
+static const struct mali_c720_stats_discovery_info
+mali_c720_stats_discovery_info[MALI_C720_STATS_MAX] = {
+ [MALI_C720_STATS_COLOR_HV] = {
+ .data_offset = offsetof(struct mali_c720_stats_color, data),
+ .table_size = offsetof(struct mali_c720_awb_statistics, nodes_used),
+ .nodes_offset = offsetof(struct mali_c720_awb_statistics,
+ nodes_used.nodes_used_horiz),
+ },
+ [MALI_C720_STATS_HISTOGRAM_INP] = {
+ .data_offset = offsetof(struct mali_c720_stats_histogram, data),
+ .table_size = sizeof(struct mali_c720_ae_1024bin_hist),
+ },
+ [MALI_C720_STATS_HISTOGRAM_HV] = {
+ .data_offset = offsetof(struct mali_c720_stats_histogram, data),
+ .table_size = sizeof(struct mali_c720_ae_1024bin_hist),
+ },
+ [MALI_C720_STATS_HISTOGRAM_HV_IRIDIX] = {
+ .data_offset = offsetof(struct mali_c720_stats_histogram, data),
+ .table_size = sizeof(struct mali_c720_ae_1024bin_hist),
+ },
+};
+
+static const struct mali_c720_discovery_target
+mali_c720_stats_discovery_targets[MALI_C720_STATS_MAX] = {
+ [MALI_C720_STATS_COLOR_HV] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_COLOR_STATS, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_STATS, .pipeline_instance = 0 },
+ [MALI_C720_STATS_HISTOGRAM_INP] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_HISTOGRAM_STATS, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_STATS, .pipeline_instance = 0 },
+ [MALI_C720_STATS_HISTOGRAM_HV] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_HISTOGRAM_STATS, .module_instance = 1,
+ .pipeline_id = MALI_C720_DISC_PIPE_STATS, .pipeline_instance = 0 },
+ [MALI_C720_STATS_HISTOGRAM_HV_IRIDIX] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_HISTOGRAM_STATS, .module_instance = 2,
+ .pipeline_id = MALI_C720_DISC_PIPE_STATS, .pipeline_instance = 0 },
+};
+
+static const struct v4l2_isp_stats_block_type_info
+mali_c720_stats_block_types_info[MALI_C720_STATS_MAX] = {
+ [MALI_C720_STATS_COLOR_HV] = {
+ .size = sizeof(struct mali_c720_stats_color),
+ },
+ [MALI_C720_STATS_HISTOGRAM_INP] = {
+ .size = sizeof(struct mali_c720_stats_histogram),
+ },
+ [MALI_C720_STATS_HISTOGRAM_HV] = {
+ .size = sizeof(struct mali_c720_stats_histogram),
+ },
+ [MALI_C720_STATS_HISTOGRAM_HV_IRIDIX] = {
+ .size = sizeof(struct mali_c720_stats_histogram),
+ },
+ [MALI_C720_STATS_NOOP] = {
+ .size = ALIGN(sizeof(struct v4l2_isp_buffer) +
+ sizeof(struct v4l2_isp_block_header), 16) -
+ sizeof(struct v4l2_isp_buffer),
+ },
+};
+
+static int
+mali_c720_stats_fill_target(struct mali_c720 *mali_c720,
+ unsigned int block_type,
+ struct mali_c720_stats_target *target, u32 offset)
+{
+ const struct mali_c720_stats_discovery_info *info;
+ const struct mali_c720_discovery_target *discovery;
+ const struct mali_c720_stat_color_stats_regs *stat_color_stats =
+ mali_c720->registers.modules->stat_color_stats;
+ const struct mali_c720_reg_field *nodes_register = NULL;
+ u32 module_base, table_base;
+ u32 size_words;
+ int ret;
+
+ memset(target, 0, sizeof(*target));
+
+ discovery = &mali_c720_stats_discovery_targets[block_type];
+
+ if (!mali_c720_discovery_module_present(mali_c720, discovery))
+ return -ENOENT;
+
+ ret = mali_c720_discovery_get_module_table_base(mali_c720, discovery, 0,
+ &table_base);
+ if (ret)
+ return ret;
+
+ ret = mali_c720_discovery_get_module_base(mali_c720, discovery, &module_base);
+ if (ret)
+ return ret;
+
+ info = &mali_c720_stats_discovery_info[block_type];
+
+ offset += info->data_offset;
+ size_words = info->table_size / sizeof(u32);
+ /* Destination bits [3:2] are taken from the ISP address. */
+ target->desc[0] = (struct mali_c720_cdma_sg_cfg) {
+ .isp_address = table_base,
+ .axi_address = offset >> 4,
+ .length_low = (u16)(size_words & 0xfff),
+ .length_high = (u8)((size_words >> 12) & 0xf),
+ .alt_address = 1,
+ };
+ target->num_desc = 1;
+
+ if (block_type == MALI_C720_STATS_COLOR_HV) {
+ nodes_register = &stat_color_stats->awb_nodes_used_horiz;
+
+ target->desc[1] = (struct mali_c720_cdma_sg_cfg) {
+ .isp_address = mali_c720_reg_addr(module_base, nodes_register),
+ .axi_address = (offset + info->nodes_offset) >> 4,
+ .length_low = 1,
+ .alt_address = 1,
+ };
+ target->num_desc++;
+ }
+
+ target->present = true;
+
+ return 0;
+}
+
+static int mali_c720_stats_build_target_cache(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_stats *stats = &mali_c720->stats;
+ unsigned int block_type;
+ int ret;
+
+ /* The NOOP aligns the first statistics payload for the CDMA engine. */
+ stats->buffer_size =
+ v4l2_isp_buffer_size(mali_c720_stats_block_types_info[MALI_C720_STATS_NOOP].size);
+ stats->num_targets = 0;
+
+ for (block_type = 0; block_type < MALI_C720_STATS_MAX; block_type++) {
+ if (block_type == MALI_C720_STATS_NOOP)
+ continue;
+
+ ret = mali_c720_stats_fill_target(mali_c720, block_type,
+ &stats->targets[block_type], stats->buffer_size);
+ if (ret == -ENOENT)
+ continue;
+ if (ret)
+ return ret;
+
+ stats->buffer_size += (u32)mali_c720_stats_block_types_info[block_type].size;
+ stats->num_targets++;
+ }
+
+ if (stats->buffer_size > v4l2_isp_buffer_size(MALI_C720_STATS_MAX_SIZE)) {
+ dev_err(mali_c720->dev, "statistics buffer exceeds maximum size\n");
+ return -EINVAL;
+ }
+
+ if (!stats->num_targets) {
+ dev_err(mali_c720->dev, "no supported statistics blocks found\n");
+ return -ENODEV;
+ }
+
+ return 0;
+}
+
+static int mali_c720_stats_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
+{
+ struct mali_c720_stats *stats =
+ container_of(ctrl->handler, struct mali_c720_stats, ctrls.handler);
+ u16 *ids = ctrl->p_new.p_u16;
+ unsigned int block_type;
+
+ if (ctrl->id != V4L2_CID_MALI_C720_STATS_CAPABILITIES)
+ return -EINVAL;
+
+ for (block_type = 0; block_type < MALI_C720_STATS_MAX; block_type++) {
+ if (stats->targets[block_type].present)
+ *ids++ = (u16)block_type;
+ }
+
+ return 0;
+}
+
+static const struct v4l2_ctrl_ops mali_c720_stats_ctrl_ops = {
+ .g_volatile_ctrl = mali_c720_stats_g_volatile_ctrl,
+};
+
+static const struct v4l2_ctrl_config mali_c720_stats_caps_ctrl = {
+ .ops = &mali_c720_stats_ctrl_ops,
+ .id = V4L2_CID_MALI_C720_STATS_CAPABILITIES,
+ .name = "Mali-C720 Stats Capabilities",
+ .type = V4L2_CTRL_TYPE_U16,
+ .dims = { MALI_C720_STATS_MAX },
+ .min = 0,
+ .max = U16_MAX,
+ .step = 1,
+ .flags = V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_VOLATILE,
+};
+
+static int mali_c720_stats_init_buffer(struct mali_c720_stats *stats, void *vaddr)
+{
+ struct mali_c720 *mali_c720 = stats->mali_c720;
+ const unsigned int num_types = ARRAY_SIZE(mali_c720_stats_block_types_info);
+ struct v4l2_isp_buffer *buffer = vaddr;
+ struct v4l2_isp_block_header *header;
+ size_t max_size = stats->buffer_size - sizeof(*buffer);
+ unsigned int block_type;
+
+ memset(buffer, 0, stats->buffer_size);
+ v4l2_isp_stats_init_buffer(buffer, V4L2_ISP_VERSION_V1);
+
+ header = v4l2_isp_stats_init_block(mali_c720->dev, buffer,
+ mali_c720_stats_block_types_info,
+ num_types, MALI_C720_STATS_NOOP, max_size);
+ if (IS_ERR(header))
+ return (int)PTR_ERR(header);
+
+ for (block_type = 0; block_type < MALI_C720_STATS_MAX; block_type++) {
+ if (!stats->targets[block_type].present)
+ continue;
+
+ header = v4l2_isp_stats_init_block(mali_c720->dev, buffer,
+ mali_c720_stats_block_types_info,
+ num_types, block_type, max_size);
+ if (IS_ERR(header))
+ return (int)PTR_ERR(header);
+ }
+
+ return 0;
+}
+
+static int mali_c720_stats_enum_fmt_meta_cap(struct file *file, void *fh,
+ struct v4l2_fmtdesc *f)
+{
+ if (f->index)
+ return -EINVAL;
+
+ if (f->mbus_code && f->mbus_code != MEDIA_BUS_FMT_METADATA_FIXED)
+ return -EINVAL;
+
+ f->pixelformat = V4L2_META_FMT_MALI_C720_STATS;
+
+ return 0;
+}
+
+static int mali_c720_stats_g_fmt_meta_cap(struct file *file, void *fh,
+ struct v4l2_format *f)
+{
+ struct mali_c720_stats *stats = video_drvdata(file);
+
+ const struct v4l2_meta_format mfmt = {
+ .dataformat = V4L2_META_FMT_MALI_C720_STATS,
+ .buffersize = stats->buffer_size
+ };
+
+ f->fmt.meta = mfmt;
+
+ return 0;
+}
+
+static int mali_c720_stats_querycap(struct file *file,
+ void *priv, struct v4l2_capability *cap)
+{
+ strscpy(cap->driver, MALI_C720_DRIVER_NAME, sizeof(cap->driver));
+ strscpy(cap->card, "ARM Mali-C720 ISP", sizeof(cap->card));
+
+ return 0;
+}
+
+static const struct v4l2_ioctl_ops mali_c720_stats_v4l2_ioctl_ops = {
+ .vidioc_reqbufs = vb2_ioctl_reqbufs,
+ .vidioc_querybuf = vb2_ioctl_querybuf,
+ .vidioc_create_bufs = vb2_ioctl_create_bufs,
+ .vidioc_qbuf = vb2_ioctl_qbuf,
+ .vidioc_expbuf = vb2_ioctl_expbuf,
+ .vidioc_dqbuf = vb2_ioctl_dqbuf,
+ .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+ .vidioc_streamon = mali_c720_streamon,
+ .vidioc_streamoff = vb2_ioctl_streamoff,
+ .vidioc_enum_fmt_meta_cap = mali_c720_stats_enum_fmt_meta_cap,
+ .vidioc_g_fmt_meta_cap = mali_c720_stats_g_fmt_meta_cap,
+ .vidioc_s_fmt_meta_cap = mali_c720_stats_g_fmt_meta_cap,
+ .vidioc_try_fmt_meta_cap = mali_c720_stats_g_fmt_meta_cap,
+ .vidioc_querycap = mali_c720_stats_querycap,
+ .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
+ .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+};
+
+static const struct v4l2_file_operations mali_c720_stats_v4l2_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = video_ioctl2,
+ .open = v4l2_fh_open,
+ .release = vb2_fop_release,
+ .poll = vb2_fop_poll,
+ .mmap = vb2_fop_mmap,
+};
+
+static int
+mali_c720_stats_queue_setup(struct vb2_queue *q, unsigned int *num_buffers,
+ unsigned int *num_planes, unsigned int sizes[],
+ struct device *alloc_devs[])
+{
+ struct mali_c720_stats *stats = vb2_get_drv_priv(q);
+
+ if (*num_planes && *num_planes > 1)
+ return -EINVAL;
+
+ if (sizes[0] && sizes[0] < stats->buffer_size)
+ return -EINVAL;
+
+ *num_planes = 1;
+
+ if (!sizes[0])
+ sizes[0] = stats->buffer_size;
+
+ return 0;
+}
+
+static void mali_c720_stats_buf_queue(struct vb2_buffer *vb)
+{
+ struct mali_c720_stats *stats = vb2_get_drv_priv(vb->vb2_queue);
+ struct mali_c720 *mali_c720 = stats->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+ struct mali_c720_stats_buf *buf = container_of(vbuf, struct mali_c720_stats_buf, vb);
+
+ vb2_set_plane_payload(vb, 0, stats->buffer_size);
+
+ scoped_guard(spinlock, &stats->buffers.lock)
+ list_add_tail(&buf->queue, &stats->buffers.input);
+
+ if (!mali_c720_stats_uses_requests(stats))
+ mali_c720_try_schedule_frame(ctx);
+}
+
+static int mali_c720_stats_buf_init(struct vb2_buffer *vb)
+{
+ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+ struct mali_c720_stats_buf *buf = container_of(vbuf, struct mali_c720_stats_buf, vb);
+
+ buf->addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+ if (!IS_ALIGNED(buf->addr, 16)) {
+ dev_dbg(vb->vb2_queue->dev,
+ "Statistics buffer DMA address is not 16-byte aligned\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int mali_c720_stats_buf_prepare(struct vb2_buffer *vb)
+{
+ struct mali_c720_stats *stats = vb2_get_drv_priv(vb->vb2_queue);
+ struct dma_buf *dbuf = vb->planes[0].dbuf;
+ void *vaddr;
+ int ret;
+
+ vaddr = vb2_plane_vaddr(vb, 0);
+ if (!vaddr)
+ return -EFAULT;
+
+ if (dbuf) {
+ ret = dma_buf_begin_cpu_access(dbuf, DMA_BIDIRECTIONAL);
+ if (ret)
+ return ret;
+ }
+
+ ret = mali_c720_stats_init_buffer(stats, vaddr);
+
+ if (dbuf) {
+ int err = dma_buf_end_cpu_access(dbuf, DMA_BIDIRECTIONAL);
+
+ if (!ret)
+ ret = err;
+ }
+
+ return ret;
+}
+
+static void mali_c720_buf_request_complete(struct vb2_buffer *vb)
+{
+}
+
+bool mali_c720_stats_uses_requests(struct mali_c720_stats *stats)
+{
+ return video_is_registered(&stats->vdev) &&
+ vb2_is_streaming(&stats->queue) &&
+ stats->queue.uses_requests;
+}
+
+struct media_request *mali_c720_stats_get_request(struct mali_c720_stats *stats)
+{
+ struct mali_c720_stats_buf *buf;
+
+ if (!mali_c720_stats_uses_requests(stats))
+ return NULL;
+
+ guard(spinlock)(&stats->buffers.lock);
+
+ buf = list_first_entry_or_null(&stats->buffers.input,
+ struct mali_c720_stats_buf, queue);
+
+ return buf ? buf->vb.vb2_buf.request : NULL;
+}
+
+int mali_c720_stats_is_ready(struct mali_c720_stats *stats)
+{
+ struct mali_c720_stats_buf *buf;
+
+ if (!video_is_registered(&stats->vdev))
+ return -ENODEV;
+
+ if (!vb2_is_streaming(&stats->queue))
+ return -ENODEV;
+
+ scoped_guard(spinlock, &stats->buffers.lock) {
+ buf = list_first_entry_or_null(&stats->buffers.input,
+ struct mali_c720_stats_buf, queue);
+ if (!buf)
+ return -ENOENT;
+ }
+
+ return 0;
+}
+
+void mali_c720_stats_set_next_buffer(struct mali_c720_stats *stats,
+ struct media_request *req)
+{
+ struct mali_c720 *mali_c720 = stats->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_stats_buf *buf;
+
+ if (!video_is_registered(&stats->vdev))
+ return;
+
+ if (!vb2_is_streaming(&stats->queue))
+ return;
+
+ scoped_guard(spinlock, &stats->buffers.lock) {
+ buf = list_first_entry_or_null(&stats->buffers.input,
+ struct mali_c720_stats_buf, queue);
+ if (buf && (!buf->vb.vb2_buf.request ||
+ buf->vb.vb2_buf.request == req)) {
+ mali_c720_ctx_mgr_set_stats_buffer_address(ctx, &buf->addr);
+ list_move_tail(&buf->queue, &stats->buffers.processing);
+ } else {
+ mali_c720_ctx_mgr_set_stats_buffer_address(ctx, NULL);
+ }
+ }
+}
+
+void mali_c720_stats_buffer_done(struct mali_c720_stats *stats, bool success)
+{
+ struct mali_c720 *mali_c720 = stats->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_stats_buf *buf;
+
+ if (!video_is_registered(&stats->vdev))
+ return;
+
+ if (!vb2_is_streaming(&stats->queue))
+ return;
+
+ guard(spinlock)(&stats->buffers.lock);
+
+ buf = list_first_entry_or_null(&stats->buffers.processing,
+ struct mali_c720_stats_buf, queue);
+ if (!buf)
+ return;
+
+ if (success) {
+ buf->vb.vb2_buf.timestamp = ctx->timestamp;
+ buf->vb.sequence = ctx->frame_sequence;
+ }
+
+ vb2_buffer_done(&buf->vb.vb2_buf, success ? VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR);
+ list_del(&buf->queue);
+}
+
+static void mali_c720_stats_return_buffers(struct mali_c720_stats *stats,
+ enum vb2_buffer_state state)
+{
+ struct mali_c720_stats_buf *buf, *tmp;
+
+ guard(spinlock) (&stats->buffers.lock);
+
+ list_for_each_entry_safe(buf, tmp, &stats->buffers.input, queue) {
+ list_del(&buf->queue);
+ vb2_buffer_done(&buf->vb.vb2_buf, state);
+ }
+
+ list_for_each_entry_safe(buf, tmp, &stats->buffers.processing, queue) {
+ list_del(&buf->queue);
+ vb2_buffer_done(&buf->vb.vb2_buf, state);
+ }
+}
+
+static int mali_c720_stats_start_streaming(struct vb2_queue *q,
+ unsigned int count)
+{
+ struct mali_c720_stats *stats = vb2_get_drv_priv(q);
+ struct mali_c720 *mali_c720 = stats->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct v4l2_subdev *isp_sd = &mali_c720->isp.mdev.sd;
+ int ret;
+
+ guard(mutex) (&mali_c720->device_lock);
+
+ if (!media_devnode_is_registered(mali_c720->media_dev.devnode)) {
+ ret = -ENODEV;
+ goto err_return_buffers;
+ }
+
+ ret = pm_runtime_resume_and_get(mali_c720->dev);
+ if (ret)
+ goto err_return_buffers;
+
+ ret = video_device_pipeline_start(&stats->vdev, &mali_c720->pipe);
+ if (ret)
+ goto err_pm_put;
+
+ ret = mali_c720_alloc_context(ctx);
+ if (ret)
+ goto err_stop_pipeline;
+
+ ret = mali_c720_pipeline_ready(mali_c720);
+ if (ret && ret != -EAGAIN)
+ goto err_free_context;
+
+ if (!ret) {
+ ret = v4l2_subdev_enable_streams(isp_sd,
+ MALI_C720_ISP_PAD_SOURCE_HV,
+ BIT(0));
+ if (ret)
+ goto err_free_context;
+ }
+
+ return 0;
+
+err_free_context:
+ mali_c720_free_context(ctx);
+err_stop_pipeline:
+ video_device_pipeline_stop(&stats->vdev);
+err_pm_put:
+ pm_runtime_put(mali_c720->dev);
+err_return_buffers:
+ mali_c720_stats_return_buffers(stats, VB2_BUF_STATE_QUEUED);
+
+ return ret;
+}
+
+static void mali_c720_stats_stop_streaming(struct vb2_queue *q)
+{
+ struct mali_c720_stats *stats = vb2_get_drv_priv(q);
+ struct mali_c720 *mali_c720 = stats->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_isp *isp = &mali_c720->isp;
+ struct v4l2_subdev *isp_sd = &isp->mdev.sd;
+
+ guard(mutex) (&mali_c720->device_lock);
+
+ v4l2_subdev_disable_streams(isp_sd, MALI_C720_ISP_PAD_SOURCE_HV,
+ BIT(0));
+ mali_c720_stats_return_buffers(stats, VB2_BUF_STATE_ERROR);
+
+ mali_c720_free_context(ctx);
+
+ video_device_pipeline_stop(&stats->vdev);
+
+ pm_runtime_put_autosuspend(mali_c720->dev);
+}
+
+static const struct vb2_ops mali_c720_stats_vb2_ops = {
+ .queue_setup = mali_c720_stats_queue_setup,
+ .buf_queue = mali_c720_stats_buf_queue,
+ .buf_init = mali_c720_stats_buf_init,
+ .buf_prepare = mali_c720_stats_buf_prepare,
+ .buf_request_complete = mali_c720_buf_request_complete,
+ .start_streaming = mali_c720_stats_start_streaming,
+ .stop_streaming = mali_c720_stats_stop_streaming,
+};
+
+void mali_c720_unregister_stats(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_stats *stats = &mali_c720->stats;
+
+ if (!video_is_registered(&stats->vdev))
+ return;
+
+ vb2_video_unregister_device(&stats->vdev);
+}
+
+void mali_c720_cleanup_stats(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_stats *stats = &mali_c720->stats;
+
+ if (!stats->mali_c720)
+ return;
+
+ v4l2_ctrl_handler_free(&stats->ctrls.handler);
+ media_entity_cleanup(&stats->vdev.entity);
+
+ mutex_destroy(&stats->lock);
+ stats->mali_c720 = NULL;
+}
+
+int mali_c720_register_stats(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_stats *stats = &mali_c720->stats;
+ struct video_device *vdev = &stats->vdev;
+ struct vb2_queue *vb2q = &stats->queue;
+ u32 dims[V4L2_CTRL_MAX_DIMS] = { 0 };
+ int ret;
+
+ ret = mali_c720_stats_build_target_cache(mali_c720);
+ if (ret)
+ return ret;
+
+ ret = mali_c720_ctx_mgr_prepare_cdma_sg_descriptors(mali_c720);
+ if (ret)
+ return ret;
+
+ stats->mali_c720 = mali_c720;
+ mutex_init(&stats->lock);
+ INIT_LIST_HEAD(&stats->buffers.input);
+ INIT_LIST_HEAD(&stats->buffers.processing);
+ spin_lock_init(&stats->buffers.lock);
+
+ ret = v4l2_ctrl_handler_init(&stats->ctrls.handler, 1);
+ if (ret)
+ goto err_destroy_mutex;
+
+ stats->ctrls.stats_capabilities =
+ v4l2_ctrl_new_custom(&stats->ctrls.handler,
+ &mali_c720_stats_caps_ctrl, NULL);
+ if (stats->ctrls.stats_capabilities) {
+ dims[0] = stats->num_targets;
+ ret = v4l2_ctrl_modify_dimensions(stats->ctrls.stats_capabilities, dims);
+ if (ret)
+ goto err_free_ctrl_handler;
+ }
+
+ if (stats->ctrls.handler.error) {
+ ret = stats->ctrls.handler.error;
+ goto err_free_ctrl_handler;
+ }
+
+ stats->pad.flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
+ ret = media_entity_pads_init(&stats->vdev.entity, 1, &stats->pad);
+ if (ret)
+ goto err_free_ctrl_handler;
+
+ vb2q->type = V4L2_BUF_TYPE_META_CAPTURE;
+ vb2q->io_modes = VB2_MMAP | VB2_DMABUF;
+ vb2q->drv_priv = stats;
+ vb2q->mem_ops = &vb2_dma_contig_memops;
+ vb2q->bidirectional = 1;
+ vb2q->ops = &mali_c720_stats_vb2_ops;
+ vb2q->buf_struct_size = sizeof(struct mali_c720_stats_buf);
+ vb2q->min_queued_buffers = 0;
+ vb2q->supports_requests = 1;
+ vb2q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC |
+ V4L2_BUF_FLAG_TSTAMP_SRC_SOE;
+ vb2q->lock = &stats->lock;
+ vb2q->dev = mali_c720->dev;
+
+ ret = vb2_queue_init(vb2q);
+ if (ret) {
+ dev_err(mali_c720->dev, "stats vb2 queue init failed\n");
+ goto err_cleanup_entity;
+ }
+
+ strscpy(stats->vdev.name, "mali-c720 3a stats", sizeof(stats->vdev.name));
+ vdev->release = video_device_release_empty;
+ vdev->fops = &mali_c720_stats_v4l2_fops;
+ vdev->ioctl_ops = &mali_c720_stats_v4l2_ioctl_ops;
+ vdev->lock = &stats->lock;
+ vdev->v4l2_dev = &mali_c720->v4l2_dev;
+ vdev->queue = &stats->queue;
+ vdev->ctrl_handler = &stats->ctrls.handler;
+ vdev->device_caps = V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING | V4L2_CAP_IO_MC;
+ vdev->vfl_dir = VFL_DIR_RX;
+ video_set_drvdata(vdev, stats);
+
+ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
+ if (ret) {
+ dev_err(mali_c720->dev,
+ "failed to register stats video device\n");
+ goto err_release_vb2q;
+ }
+
+ return 0;
+
+err_release_vb2q:
+ vb2_queue_release(vb2q);
+err_cleanup_entity:
+ media_entity_cleanup(&stats->vdev.entity);
+err_free_ctrl_handler:
+ v4l2_ctrl_handler_free(&stats->ctrls.handler);
+err_destroy_mutex:
+ mutex_destroy(&stats->lock);
+ stats->mali_c720 = NULL;
+
+ return ret;
+}
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 19/24] media: Documentation: Document Mali-C720 statistics capture
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (17 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 18/24] media: mali-c720: Add 3A statistics video node Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 20/24] media: uapi: Add Mali-C720 parameters meta format Anthony McGivern
` (4 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Document statistics capture and querying available statistics blocks
through the capability control. Include a capture example and explain
how frame sequence numbers associate statistics with image buffers.
Describe the statistics metadata format, its use of the generic V4L2
ISP buffer layout and the Mali-C720 UAPI structures.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../admin-guide/media/mali-c720-graph.dot | 4 +-
Documentation/admin-guide/media/mali-c720.rst | 55 ++++++++++++++++++----
.../userspace-api/media/drivers/index.rst | 1 +
.../userspace-api/media/drivers/mali-c720.rst | 41 ++++++++++++++++
.../userspace-api/media/v4l/meta-formats.rst | 1 +
.../media/v4l/metafmt-arm-mali-c720.rst | 40 ++++++++++++++++
6 files changed, 132 insertions(+), 10 deletions(-)
diff --git a/Documentation/admin-guide/media/mali-c720-graph.dot b/Documentation/admin-guide/media/mali-c720-graph.dot
index f1d481b98aebd6ab5424fb78331337f2d7479c1f..c3594c525370734cca4acfb6e1bf03834b611029 100644
--- a/Documentation/admin-guide/media/mali-c720-graph.dot
+++ b/Documentation/admin-guide/media/mali-c720-graph.dot
@@ -6,8 +6,9 @@ digraph board {
n00000003:port0 -> n00000009:port1 [style=dashed]
n00000009 [label="{{<port1> 1} | mali-c720 input\n/dev/v4l-subdev2 | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green]
n00000009:port0 -> n0000000c:port0
- n0000000c [label="{{<port0> 0} | mali-c720 isp\n/dev/v4l-subdev3 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
+ n0000000c [label="{{<port0> 0} | mali-c720 isp\n/dev/v4l-subdev3 | {<port1> 1 | <port2> 2}}", shape=Mrecord, style=filled, fillcolor=green]
n0000000c:port1 -> n00000014:port0
+ n0000000c:port2 -> n0000006c [style=dashed]
n00000014 [label="{{<port0> 0} | mali-c720 hv pipe\n/dev/v4l-subdev4 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
n00000014:port1 -> n0000001c:port0
n0000001c [label="{{<port0> 0} | mali-c720 fr 0 pipe\n/dev/v4l-subdev5 | {<port1> 1 | <port2> 2}}", shape=Mrecord, style=filled, fillcolor=green]
@@ -15,6 +16,7 @@ digraph board {
n0000001c:port2 -> n0000003c [style=dashed]
n00000038 [label="mali-c720 fr0-rgb\n/dev/video0", shape=box, style=filled, fillcolor=yellow]
n0000003c [label="mali-c720 fr0-yuv\n/dev/video1", shape=box, style=filled, fillcolor=yellow]
+ n0000006c [label="mali-c720 3a stats\n/dev/video2", shape=box, style=filled, fillcolor=yellow]
n00000074 [label="{{<port0> 0} | csi2-rx\n/dev/v4l-subdev6 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
n00000074:port1 -> n00000009:port1
n00000079 [label="{{} | imx415 1-001a\n/dev/v4l-subdev7 | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green]
diff --git a/Documentation/admin-guide/media/mali-c720.rst b/Documentation/admin-guide/media/mali-c720.rst
index 3ff2cb3170f257748878e78b85366b6462f76ff2..06b97e11ee380df55d13b11706527687bb3c74e6 100644
--- a/Documentation/admin-guide/media/mali-c720.rst
+++ b/Documentation/admin-guide/media/mali-c720.rst
@@ -126,9 +126,10 @@ The driver has up to six V4L2 subdevices:
- ``mali-c720 hv pipe``: Human vision pipeline.
- ``mali-c720 fr 0 pipe``: Full-resolution crop/scale pipeline.
-The driver has two V4L2 video devices:
+The driver has three V4L2 video devices:
- ``mali-c720 fr0-rgb`` and ``mali-c720 fr0-yuv``: FR capture devices.
+- ``mali-c720 3a stats``: 3A statistics capture device.
Input formats
-------------
@@ -314,6 +315,39 @@ then configure a capture format like NV12:
media-ctl -l "'mali-c720 fr 0 pipe':2->'mali-c720 fr0-yuv':0[1]"
yavta -f NV12 -s 1920x1080 -c10 /dev/video1
+.. _mali-c720-3a-stats:
+
+Capturing ISP Statistics
+========================
+
+The ISP is capable of producing statistics for consumption by image processing
+algorithms running in userspace. These statistics can be captured by queueing
+buffers to the `mali-c720 3a stats` V4L2 device whilst the ISP is streaming.
+
+Each successfully captured statistics buffer carries the processed frame's
+sequence number in its :c:type:`v4l2_buffer` ``sequence`` field. This matches
+the sequence number of image buffers produced from the same frame.
+
+Only the :ref:`V4L2_META_FMT_MALI_C720_STATS <v4l2-meta-fmt-mali-c720-stats>`
+format is supported, so no format-setting need be done:
+
+.. code-block:: none
+
+ # We assume the media graph has been configured to support RGB24 capture
+ # from the mali-c720 fr0-rgb V4L2 Device, which is at /dev/video0. The
+ # statistics V4L2 device is at /dev/video2. Run the capture processes
+ # concurrently so that both video devices start streaming:
+
+ media-ctl -l "'mali-c720 isp':2->'mali-c720 3a stats':0[1]"
+ yavta -f RGB24 -s 1920x1080 -c10 /dev/video0
+ yavta -c10 -F /dev/video2
+
+As our hardware is configurable, the modules present can vary depending upon
+its configuration. This means that certain statistics may only be present if
+their respective pipelines are present. We expose a V4L2 control
+:ref:`V4L2_CID_MALI_C720_STATS_CAPABILITIES <mali-c720-controls>` which allows
+the userspace to query the statistics produced by the ISP.
+
.. _mali-c720-frame-scheduling:
Frame scheduling and Media Requests
@@ -325,12 +359,13 @@ direct buffer queuing or Media Requests. Use of Media Requests is optional.
Direct mode
-----------
-When all streaming image capture queues use direct buffer queuing through
-:ref:`VIDIOC_QBUF`, the driver schedules frames in free-running mode.
-Scheduling starts only when at least one image output buffer is ready.
-Once started, it continues scheduling frames using the available buffers.
-Empty image capture queues disable their respective capture for the
-scheduled frame.
+When all streaming statistics and image capture queues use direct buffer
+queuing through :ref:`VIDIOC_QBUF`, the driver schedules frames in
+free-running mode. Scheduling starts only when at least one image or
+statistics output buffer is ready. Once started, it continues scheduling
+frames using the available buffers.
+Empty statistics or image capture queues disable their respective capture
+for the scheduled frame.
Request mode
------------
@@ -341,7 +376,7 @@ request.
Applications allocate a request using :ref:`MEDIA_IOC_REQUEST_ALLOC` on the
media device.
-Image buffers are associated with it through
+Statistics and image buffers are associated with it through
:ref:`VIDIOC_QBUF`, setting ``V4L2_BUF_FLAG_REQUEST_FD`` and ``request_fd``.
The request is then submitted using :ref:`MEDIA_REQUEST_IOC_QUEUE` on the
request file descriptor.
@@ -354,7 +389,9 @@ Queues without a buffer will be disabled for the scheduled frame.
All buffers associated with the request are usually applied on the same
frame, but a request could span multiple frames if multiple buffers are
-queued for the same buffer queue. Completed buffers are returned to userspace through
+queued for the same buffer queue.
+The statistics and image buffers are filled with the results from that
+frame. Completed buffers are returned to userspace through
:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`.
It is permitted to queue buffers directly in other VB2 queues alongside
diff --git a/Documentation/userspace-api/media/drivers/index.rst b/Documentation/userspace-api/media/drivers/index.rst
index 8d2c489b8453e11b8e15ef9d9c1c0312f3da06af..ff93248d203d8b7109ff08d61a8e5121ce80c2a8 100644
--- a/Documentation/userspace-api/media/drivers/index.rst
+++ b/Documentation/userspace-api/media/drivers/index.rst
@@ -34,6 +34,7 @@ For more details see the file COPYING in the source distribution of Linux.
dw100
imx-uapi
mali-c55
+ mali-c720
max2175
npcm-video
omap3isp-uapi
diff --git a/Documentation/userspace-api/media/drivers/mali-c720.rst b/Documentation/userspace-api/media/drivers/mali-c720.rst
new file mode 100644
index 0000000000000000000000000000000000000000..306112582cd62b5c7131d8e7d8bab7ecae9f2eee
--- /dev/null
+++ b/Documentation/userspace-api/media/drivers/mali-c720.rst
@@ -0,0 +1,41 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+.. _mali-c720-controls:
+
+Arm Mali-C720 ISP driver
+========================
+
+The Arm Mali-C720 ISP driver implements the following driver-specific control:
+
+``V4L2_CID_MALI_C720_STATS_CAPABILITIES (__u16 array)``
+ Lists the statistics block types supported by the ISP. Each element is a
+ value from :c:type:`mali_c720_stats_type`.
+
+The Mali-C720 ISP can be configured to include or exclude statistics blocks.
+This control allows the driver to communicate to userspace which statistics
+block types are supported by the driver and present in the hardware.
+
+Format enumeration
+------------------
+
+The available image formats depend on the output pipeline. For example, the
+``mali-c720 fr0-rgb`` capture device supports RGB formats, while the
+``mali-c720 fr0-yuv`` capture device supports YUV formats. Future hardware
+versions may also expose different supported formats. Applications must select
+an image format compatible with the media bus format configured on the connected
+subdevice's source pad. Applications should enumerate the formats supported by
+each video device using :ref:`VIDIOC_ENUM_FMT <VIDIOC_ENUM_FMT>`.
+
+Buffer alignment
+----------------
+
+Image capture buffers require DMA base addresses aligned to 32 bytes.
+Statistics capture buffers require DMA base addresses aligned to 16 bytes.
+
+Buffers allocated by the driver using MMAP satisfy these requirements
+automatically. Imported DMA-BUFs must provide suitable alignment.
+The driver rejects buffers whose DMA base addresses do not meet these
+requirements.
+
+Image strides must also be aligned to 32 bytes. Format negotiation adjusts
+``bytesperline`` accordingly, and applications must use the returned value.
diff --git a/Documentation/userspace-api/media/v4l/meta-formats.rst b/Documentation/userspace-api/media/v4l/meta-formats.rst
index b5455229837e707c24e134438d5e2fd12cb3bf37..6d4423155fd90a9557cd744e2fc010d3e283be0c 100644
--- a/Documentation/userspace-api/media/v4l/meta-formats.rst
+++ b/Documentation/userspace-api/media/v4l/meta-formats.rst
@@ -14,6 +14,7 @@ These formats are used for the :ref:`metadata` interface only.
:maxdepth: 1
metafmt-arm-mali-c55
+ metafmt-arm-mali-c720
metafmt-c3-isp
metafmt-d4xx
metafmt-generic
diff --git a/Documentation/userspace-api/media/v4l/metafmt-arm-mali-c720.rst b/Documentation/userspace-api/media/v4l/metafmt-arm-mali-c720.rst
new file mode 100644
index 0000000000000000000000000000000000000000..1d19183cc07a81dfc95682c701a5bfc5f953a93a
--- /dev/null
+++ b/Documentation/userspace-api/media/v4l/metafmt-arm-mali-c720.rst
@@ -0,0 +1,40 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+.. _v4l2-meta-fmt-mali-c720-stats:
+
+*******************************************************************************
+V4L2_META_FMT_MALI_C720_STATS ('C72S')
+*******************************************************************************
+
+For details on queueing statistics buffers and synchronizing them with
+image buffers using Media Requests, see :ref:`mali-c720-frame-scheduling`.
+
+3A Statistics
+=============
+
+The ISP collects statistics at different stages of frame processing. These
+may describe Bayer or processed image data, depending on the statistics
+block and its configuration. Userspace can obtain these statistics from the
+:ref:`mali-c720 3a stats <mali-c720-3a-stats>` metadata capture video node, using
+the :c:type:`v4l2_meta_format` interface.
+
+Userspace may consume these statistics in 3A algorithms, including
+auto-exposure, auto-white balance and autofocus, to compute adjustments to
+sensor and ISP settings.
+
+Statistics for the Mali-C720 use the :ref:`generic V4L2 ISP format <v4l2-isp>`.
+The buffer contains a :c:type:`v4l2_isp_buffer` header followed by statistics
+blocks in its ``data`` member. Each block embeds
+:c:type:`v4l2_isp_block_header` as its first member, with the ``type`` member
+set to a value from :c:type:`mali_c720_stats_type`. The available statistics
+depend on the hardware configuration. These can be queried via the statistics
+capability control
+:ref:`V4L2_CID_MALI_C720_STATS_CAPABILITIES <mali-c720-controls>`.
+
+For details of the statistics, see the statistics blocks defined in
+``mali-c720-config.h``.
+
+Arm Mali-C720 uAPI data types
+=============================
+
+.. kernel-doc:: include/uapi/linux/media/arm/mali-c720-config.h
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 20/24] media: uapi: Add Mali-C720 parameters meta format
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (18 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 19/24] media: Documentation: Document Mali-C720 statistics capture Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 21/24] media: uapi: Add parameter structs to mali-c720-config.h Anthony McGivern
` (3 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add a new V4L2 meta format code for Mali-C720 ISP parameters.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
drivers/media/v4l2-core/v4l2-ioctl.c | 1 +
include/uapi/linux/videodev2.h | 1 +
2 files changed, 2 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 657adc0f4550e50aafc8855de524eb2e7c6297cb..60b77b18dcc402dd6f0efae8b216bf8fa8b8e6c9 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1471,6 +1471,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_META_FMT_C3ISP_STATS: descr = "Amlogic C3 ISP Statistics"; break;
case V4L2_META_FMT_MALI_C55_PARAMS: descr = "ARM Mali-C55 ISP Parameters"; break;
case V4L2_META_FMT_MALI_C55_STATS: descr = "ARM Mali-C55 ISP 3A Statistics"; break;
+ case V4L2_META_FMT_MALI_C720_PARAMS: descr = "ARM Mali-C720 ISP Parameters"; break;
case V4L2_META_FMT_MALI_C720_STATS: descr = "ARM Mali-C720 ISP 3A Statistics"; break;
case V4L2_META_FMT_RPPX1_PARAMS: descr = "Dreamchip RPP-X1 ISP Parameters"; break;
case V4L2_META_FMT_RPPX1_STATS: descr = "Dreamchip RPP-X1 ISP Statistics"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index a59f6642ce3d120c28f395f72653137831ef09b6..b8d06bac29e4bd550b332d57448cce86540e0f87 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -890,6 +890,7 @@ struct v4l2_pix_format {
#define V4L2_META_FMT_MALI_C55_STATS v4l2_fourcc('C', '5', '5', 'S') /* ARM Mali-C55 3A Statistics */
/* Vendor specific - used for Arm Mali-C720 ISP */
+#define V4L2_META_FMT_MALI_C720_PARAMS v4l2_fourcc('C', '7', '2', 'P') /* ARM Mali-C720 Parameters */
#define V4L2_META_FMT_MALI_C720_STATS v4l2_fourcc('C', '7', '2', 'S') /* ARM Mali-C720 3A Statistics */
/* Vendor specific - used for Dreamchip RPP-X1 ISP */
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 21/24] media: uapi: Add parameter structs to mali-c720-config.h
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (19 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 20/24] media: uapi: Add Mali-C720 parameters meta format Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 22/24] media: mali-c720: Add parameters video node Anthony McGivern
` (2 subsequent siblings)
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add structures defining the ISP parameters to mali-c720-config.h.
Additionally add a custom control ID for querying supported parameter
blocks.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
include/uapi/linux/media/arm/mali-c720-config.h | 554 ++++++++++++++++++++++++
1 file changed, 554 insertions(+)
diff --git a/include/uapi/linux/media/arm/mali-c720-config.h b/include/uapi/linux/media/arm/mali-c720-config.h
index 445cae09a84cce37de9b15e051b93f96b06cbc50..f200380f3c2c8df05fa81d7348300ddad342ca02 100644
--- a/include/uapi/linux/media/arm/mali-c720-config.h
+++ b/include/uapi/linux/media/arm/mali-c720-config.h
@@ -14,6 +14,8 @@
#define MALI_C720_MAX_ZONES 1024
+#define MALI_C720_NUM_DECOMPANDER_LUT_ELEMENTS 33
+
/**
* struct mali_c720_awb_stats_nodes_used - Color statistics zone dimensions
* @reserved1: Undefined buffer space
@@ -179,6 +181,558 @@ struct mali_c720_stats_histogram {
sizeof(struct mali_c720_stats_histogram) + \
sizeof(struct mali_c720_stats_histogram))
+/**
+ * enum mali_c720_param_block_type - Mali-C720 parameter block targets
+ *
+ * @MALI_C720_PARAM_BLOCK_DIGITAL_GAIN_INP: Digital gain for the input pipeline.
+ * @MALI_C720_PARAM_BLOCK_HISTOGRAM_INP: Histogram configuration for the input pipeline.
+ * @MALI_C720_PARAM_BLOCK_AWB_GAINS_HV: Auto-white balance gains for the HV pipeline.
+ * @MALI_C720_PARAM_BLOCK_HISTOGRAM_HV: HV histogram configuration (pre-Iridix).
+ * @MALI_C720_PARAM_BLOCK_HISTOGRAM_HV_IRIDIX: HV histogram configuration (post-Iridix).
+ * @MALI_C720_PARAM_BLOCK_COLOR_STATS_HV: Color stats configuration for the HV pipeline.
+ * @MALI_C720_PARAM_BLOCK_BLACK_LEVEL_HV: Black level offsets for the HV pipeline.
+ * @MALI_C720_PARAM_BLOCK_SQRT_INP: Square root configuration for the input pipeline.
+ * @MALI_C720_PARAM_BLOCK_SQUARE_A_HV: Square A configuration for the HV pipeline.
+ * @MALI_C720_PARAM_BLOCK_SQUARE_B_HV: Square B configuration for the HV pipeline.
+ * @MALI_C720_PARAM_BLOCK_SQRT_HV: Square root configuration for the HV pipeline.
+ * @MALI_C720_PARAM_BLOCK_DECOMPANDER_INP: Decompander configuration.
+ *
+ * Each identifier selects one logical module and instance. Applications can
+ * query V4L2_CID_MALI_C720_PARAM_CAPABILITIES for the targets present on the
+ * device. The control returns a read-only U16 array of supported identifiers.
+ */
+enum mali_c720_param_block_type {
+ MALI_C720_PARAM_BLOCK_DIGITAL_GAIN_INP,
+ MALI_C720_PARAM_BLOCK_HISTOGRAM_INP,
+ MALI_C720_PARAM_BLOCK_AWB_GAINS_HV,
+ MALI_C720_PARAM_BLOCK_HISTOGRAM_HV,
+ MALI_C720_PARAM_BLOCK_HISTOGRAM_HV_IRIDIX,
+ MALI_C720_PARAM_BLOCK_COLOR_STATS_HV,
+ MALI_C720_PARAM_BLOCK_BLACK_LEVEL_HV,
+ MALI_C720_PARAM_BLOCK_SQRT_INP,
+ MALI_C720_PARAM_BLOCK_SQUARE_A_HV,
+ MALI_C720_PARAM_BLOCK_SQUARE_B_HV,
+ MALI_C720_PARAM_BLOCK_SQRT_HV,
+ MALI_C720_PARAM_BLOCK_DECOMPANDER_INP,
+ MALI_C720_PARAM_BLOCK_MAX,
+};
+
#define V4L2_CID_MALI_C720_STATS_CAPABILITIES (V4L2_CID_USER_MALI_C720_BASE + 0)
+#define V4L2_CID_MALI_C720_PARAM_CAPABILITIES (V4L2_CID_USER_MALI_C720_BASE + 1)
+
+enum mali_c720_params_digital_gain_mask {
+ MALI_C720_PARAMS_DIGITAL_GAIN_MASK_GAIN,
+ MALI_C720_PARAMS_DIGITAL_GAIN_MASK_OFFSET,
+};
+
+/**
+ * struct mali_c720_params_digital_gain - Digital gain settings
+ *
+ * This struct configures the digital gain and a common black level for all
+ * color channels.
+ *
+ * Set header.type to the target from &enum mali_c720_param_block_type.
+ * See &enum mali_c720_params_digital_gain_mask for the @updated_mask bit positions.
+ * Undefined bits are reserved and must be set to zero.
+ *
+ * @header: The generic V4L2 ISP block header
+ * @updated_mask: Mask of configuration fields to update
+ * @gain: Input digital gain in unsigned Q12.8 format [0..1048575]; 256 = 1x
+ * @offset: Input black level [0..16777215]
+ */
+struct mali_c720_params_digital_gain {
+ struct v4l2_isp_block_header header;
+ __u64 updated_mask;
+ __u32 gain;
+ __u32 offset;
+};
+
+enum mali_c720_params_awb_gains_mask {
+ MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN00,
+ MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN01,
+ MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN10,
+ MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN11,
+};
+
+/**
+ * struct mali_c720_params_awb_gains - Gain settings for auto white balance
+ *
+ * There are four gain settings corresponding to the Bayer color channels.
+ * The ISP accounts for the input Bayer order, so the mapping to R, Gr, Gb
+ * and B is independent of that order. A value of 256 represents a 1x gain.
+ *
+ * Set header.type to the target from &enum mali_c720_param_block_type.
+ * See &enum mali_c720_params_awb_gains_mask for the @updated_mask bit positions.
+ * Undefined bits are reserved and must be set to zero.
+ *
+ * @header: The generic V4L2 ISP block header
+ * @updated_mask: Mask of configuration fields to update
+ * @gain00: Multiplier for color channel 00 (R), unsigned Q4.8 [0..4095]
+ * @gain01: Multiplier for color channel 01 (Gr), unsigned Q4.8 [0..4095]
+ * @gain10: Multiplier for color channel 10 (Gb), unsigned Q4.8 [0..4095]
+ * @gain11: Multiplier for color channel 11 (B), unsigned Q4.8 [0..4095]
+ */
+struct mali_c720_params_awb_gains {
+ struct v4l2_isp_block_header header;
+ __u64 updated_mask;
+ __u16 gain00;
+ __u16 gain01;
+ __u16 gain10;
+ __u16 gain11;
+};
+
+enum mali_c720_params_black_level_mask {
+ MALI_C720_PARAMS_BLACK_LEVEL_MASK_CHAN00,
+ MALI_C720_PARAMS_BLACK_LEVEL_MASK_CHAN01,
+ MALI_C720_PARAMS_BLACK_LEVEL_MASK_CHAN10,
+ MALI_C720_PARAMS_BLACK_LEVEL_MASK_CHAN11,
+};
+
+/**
+ * struct mali_c720_params_black_level - Black level for each color channel
+ *
+ * This struct configures black level subtraction from each Bayer color channel.
+ *
+ * Set header.type to the target from &enum mali_c720_param_block_type.
+ * See &enum mali_c720_params_black_level_mask for the @updated_mask bit positions.
+ * Undefined bits are reserved and must be set to zero.
+ *
+ * @header: The generic V4L2 ISP block header
+ * @updated_mask: Mask of configuration fields to update
+ * @chan00: Offset from color channel 00 (R); HV range [0..65535]
+ * @chan01: Offset from color channel 01 (Gr); HV range [0..65535]
+ * @chan10: Offset from color channel 10 (Gb); HV range [0..65535]
+ * @chan11: Offset from color channel 11 (B); HV range [0..65535]
+ */
+struct mali_c720_params_black_level {
+ struct v4l2_isp_block_header header;
+ __u64 updated_mask;
+ __u32 chan00;
+ __u32 chan01;
+ __u32 chan10;
+ __u32 chan11;
+};
+
+enum mali_c720_params_square_sqrt_mask {
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_BL_IN,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_BL_OUT,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_NORMALIZATION,
+};
+
+/**
+ * struct mali_c720_params_sqrt - Configuration for the square root module
+ *
+ * The square root module compands linear data into the square root domain,
+ * with black level correction and normalization.
+ *
+ * Set header.type to the target from &enum mali_c720_param_block_type.
+ * See &enum mali_c720_params_square_sqrt_mask for the @updated_mask bit positions.
+ * Undefined bits are reserved and must be set to zero.
+ *
+ * @header: The generic V4L2 ISP block header
+ * @updated_mask: Mask of configuration fields to update
+ * @normalization: Normalization coefficient applied before the square root,
+ * in Q1.16 format [0..131071]; 65536 = 1.0
+ * @black_level_linear: Input black level in the linear domain [0..16777215]
+ * @black_level_sqrt: Output black level in the square root domain [0..4095]
+ */
+struct mali_c720_params_sqrt {
+ struct v4l2_isp_block_header header;
+ __u64 updated_mask;
+ __u32 normalization;
+ __u32 black_level_linear;
+ __u16 black_level_sqrt;
+};
+
+/**
+ * struct mali_c720_params_square - Configuration for the square module
+ *
+ * The square module converts square root data back into the linear domain,
+ * with black level correction and normalization.
+ *
+ * Set header.type to the target from &enum mali_c720_param_block_type.
+ * See &enum mali_c720_params_square_sqrt_mask for the @updated_mask bit positions.
+ * Undefined bits are reserved and must be set to zero.
+ *
+ * @header: The generic V4L2 ISP block header
+ * @updated_mask: Mask of configuration fields to update
+ * @black_level_linear: Output black level, [0..4095] for Square-A or
+ * [0..16777215] for Square-B
+ * @black_level_sqrt: Input black level, [0..16777215] for Square-A or
+ * [0..4095] for Square-B
+ * @normalization: Normalization coefficient applied after squaring,
+ * in Q1.16 format [0..131071]; 65536 = 1.0
+ */
+struct mali_c720_params_square {
+ struct v4l2_isp_block_header header;
+ __u64 updated_mask;
+ __u32 black_level_linear;
+ __u32 black_level_sqrt;
+ __u32 normalization;
+};
+
+enum mali_c720_params_decompander_mask {
+ MALI_C720_PARAMS_DECOMPANDER_MASK_ENABLE,
+ MALI_C720_PARAMS_DECOMPANDER_MASK_LUT_X,
+ MALI_C720_PARAMS_DECOMPANDER_MASK_LUT_Y,
+};
+
+/**
+ * struct mali_c720_params_decompander - Configuration for the decompander
+ *
+ * The input decompander expands compressed sensor data using a piecewise
+ * linear curve defined by 33 points. Each X/Y pair maps an input pixel
+ * intensity to an expanded output intensity, with linear interpolation
+ * between points.
+ *
+ * The X coordinates must be in nondecreasing order and cover the input range.
+ * A nonzero difference between adjacent X coordinates must be at least 8.
+ * Repeated X coordinates must have equal Y coordinates.
+ * Both lut_x and lut_y fields must be provided together, with their respective
+ * updated_mask bits set.
+ *
+ * Y coordinates may exceed the 24-bit output range or be negative.
+ * Interpolation uses these extended values before clamping the final pixel
+ * output to the 24-bit range [0..16777215]. Nonnegative Y coordinates
+ * [0..0x17fffff] are stored directly; encodings [0x1800000..0x1ffffff]
+ * represent negative values, decoded by subtracting 0x2000000.
+ *
+ * Set header.type to the target from &enum mali_c720_param_block_type.
+ * See &enum mali_c720_params_decompander_mask for the @updated_mask bit positions.
+ * Undefined bits are reserved and must be set to zero.
+ *
+ * @header: The generic V4L2 ISP block header
+ * @updated_mask: Mask of configuration fields to update
+ * @enable: Enable decompanding: 0 = bypass, 1 = enabled
+ * @reserved: Reserved; set to zero
+ * @lut_x: 33 input pixel intensities, unsigned 24-bit [0..16777215]
+ * @lut_y: 33 corresponding output pixel intensities, using the encoding above
+ */
+struct mali_c720_params_decompander {
+ struct v4l2_isp_block_header header;
+ __u64 updated_mask;
+ __u8 enable;
+ __u8 reserved[3];
+ __u32 lut_x[MALI_C720_NUM_DECOMPANDER_LUT_ELEMENTS];
+ __u32 lut_y[MALI_C720_NUM_DECOMPANDER_LUT_ELEMENTS];
+};
+
+/**
+ * enum mali_c720_awb_stats_mode - Statistics mode for auto white balance
+ * @MALI_C720_AWB_MODE_GRGB: Green/Red and Green/Blue ratios
+ * @MALI_C720_AWB_MODE_RGBG: Red/Green and Blue/Green ratios
+ */
+enum mali_c720_awb_stats_mode {
+ MALI_C720_AWB_MODE_GRGB = 0,
+ MALI_C720_AWB_MODE_RGBG = 1,
+};
+
+enum mali_c720_params_color_stats_mask {
+ MALI_C720_PARAMS_COLOR_STATS_MASK_NODES_USED_HORIZ,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_NODES_USED_VERT,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_AWB_STATS_MODE,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_WHITE_LEVEL_AWB,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_BLACK_LEVEL_AWB,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CR_REF_MAX_AWB,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CR_REF_MIN_AWB,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CR_REF_HIGH_AWB,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CR_REF_LOW_AWB,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CB_REF_MAX_AWB,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CB_REF_MIN_AWB,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CB_REF_HIGH_AWB,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CB_REF_LOW_AWB,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_WEIGHTS,
+};
+
+/**
+ * struct mali_c720_params_color_stats - Color statistics configuration
+ *
+ * This struct configures the statistics generated for auto white balance.
+ * Pixel intensity limits exclude overly bright or dark pixels from the
+ * statistics. Color ratio minima and maxima bound a region in R/G and B/G
+ * space, while the high and low ratios trim its upper-right and lower-left
+ * corners. Only pixels whose ratios fall inside the region marked "A" are
+ * counted, independently of @awb_stats_mode::
+ *
+ * B/G
+ * ^
+ * max | +-----------------+ (high, max)
+ * | | \
+ * high| | + (max, high)
+ * | | A |
+ * low | + |
+ * | \ |
+ * min | +-----------------+
+ * +--------------------------> R/G
+ * min low high max
+ *
+ * Setting low to min and high to max selects the full rectangle.
+ *
+ * The product of @nodes_used_horiz and @nodes_used_vert must not exceed
+ * MALI_C720_MAX_ZONES (1024). Exceeding this limit produces invalid statistics
+ * that cannot be parsed reliably.
+ * When updating zone dimensions, both horizontal and vertical directions must
+ * be provided with their respective updated_mask bits set.
+ *
+ * Zone weights control each zone's contribution to the global statistics.
+ * A weight of 0 excludes the zone; values 1..14 represent weights of
+ * 1/16..14/16 and 15 applies the full weight. Per-zone results are not weighted.
+ *
+ * Set header.type to the target from &enum mali_c720_param_block_type.
+ * See &enum mali_c720_params_color_stats_mask for the @updated_mask bit positions.
+ * Undefined bits are reserved and must be set to zero.
+ *
+ * @header: The generic V4L2 ISP block header
+ * @updated_mask: Mask of configuration fields to update
+ * @nodes_used_horiz: Number of horizontal zones [3..32]
+ * @nodes_used_vert: Number of vertical zones [3..255], subject to the total
+ * zone limit above
+ * @awb_stats_mode: Ratio mode, see &enum mali_c720_awb_stats_mode
+ * @reserved: Reserved; set to zero
+ * @white_level_awb: Upper pixel intensity limit (exclusive), 14-bit [0..16383]
+ * @black_level_awb: Lower pixel intensity limit (exclusive), 14-bit [0..16383]
+ * @cr_ref_max_awb: Maximum R/G ratio, unsigned Q4.8 [0..4095]
+ * @cr_ref_min_awb: Minimum R/G ratio, unsigned Q4.8 [0..4095]
+ * @cr_ref_high_awb: R/G ratio trim high, unsigned Q4.8 [0..4095]
+ * @cr_ref_low_awb: R/G ratio trim low, unsigned Q4.8 [0..4095]
+ * @cb_ref_max_awb: Maximum B/G ratio, unsigned Q4.8 [0..4095]
+ * @cb_ref_min_awb: Minimum B/G ratio, unsigned Q4.8 [0..4095]
+ * @cb_ref_high_awb: B/G ratio trim high, unsigned Q4.8 [0..4095]
+ * @cb_ref_low_awb: B/G ratio trim low, unsigned Q4.8 [0..4095]
+ * @weights: Zone weights in row-major order from the top left, one byte per
+ * zone [0..15]. Index is y * nodes_used_horiz + x.
+ */
+struct mali_c720_params_color_stats {
+ struct v4l2_isp_block_header header;
+ __u64 updated_mask;
+ __u8 nodes_used_horiz;
+ __u8 nodes_used_vert;
+ __u8 awb_stats_mode;
+ __u8 reserved;
+ __u16 white_level_awb;
+ __u16 black_level_awb;
+ __u16 cr_ref_max_awb;
+ __u16 cr_ref_min_awb;
+ __u16 cr_ref_high_awb;
+ __u16 cr_ref_low_awb;
+ __u16 cb_ref_max_awb;
+ __u16 cb_ref_min_awb;
+ __u16 cb_ref_high_awb;
+ __u16 cb_ref_low_awb;
+ __u8 weights[MALI_C720_MAX_ZONES];
+};
+
+/**
+ * enum mali_c720_histogram_input - Input for pre-Iridix histograms
+ * @MALI_C720_HISTOGRAM_INPUT_RAW: Raw Bayer data
+ * @MALI_C720_HISTOGRAM_INPUT_LUMA: Luminance data
+ */
+enum mali_c720_histogram_input {
+ MALI_C720_HISTOGRAM_INPUT_RAW = 0,
+ MALI_C720_HISTOGRAM_INPUT_LUMA = 1,
+};
+
+/**
+ * enum mali_c720_histogram_skip_x - Horizontal pixel skipping
+ * @MALI_C720_HISTOGRAM_SKIP_X_EVERY_2ND: Collect every 2nd pixel horizontally
+ * @MALI_C720_HISTOGRAM_SKIP_X_EVERY_3RD: Collect every 3rd pixel horizontally
+ * @MALI_C720_HISTOGRAM_SKIP_X_EVERY_4TH: Collect every 4th pixel horizontally
+ * @MALI_C720_HISTOGRAM_SKIP_X_EVERY_5TH: Collect every 5th pixel horizontally
+ * @MALI_C720_HISTOGRAM_SKIP_X_EVERY_8TH: Collect every 8th pixel horizontally
+ * @MALI_C720_HISTOGRAM_SKIP_X_EVERY_9TH: Collect every 9th pixel horizontally
+ */
+enum mali_c720_histogram_skip_x {
+ MALI_C720_HISTOGRAM_SKIP_X_EVERY_2ND = 0,
+ MALI_C720_HISTOGRAM_SKIP_X_EVERY_3RD = 1,
+ MALI_C720_HISTOGRAM_SKIP_X_EVERY_4TH = 2,
+ MALI_C720_HISTOGRAM_SKIP_X_EVERY_5TH = 3,
+ MALI_C720_HISTOGRAM_SKIP_X_EVERY_8TH = 4,
+ MALI_C720_HISTOGRAM_SKIP_X_EVERY_9TH = 5,
+};
+
+/**
+ * enum mali_c720_histogram_skip_y - Vertical pixel skipping
+ * @MALI_C720_HISTOGRAM_SKIP_Y_ALL: Collect every row
+ * @MALI_C720_HISTOGRAM_SKIP_Y_EVERY_2ND: Collect every 2nd row
+ * @MALI_C720_HISTOGRAM_SKIP_Y_EVERY_3RD: Collect every 3rd row
+ * @MALI_C720_HISTOGRAM_SKIP_Y_EVERY_4TH: Collect every 4th row
+ * @MALI_C720_HISTOGRAM_SKIP_Y_EVERY_5TH: Collect every 5th row
+ * @MALI_C720_HISTOGRAM_SKIP_Y_EVERY_8TH: Collect every 8th row
+ * @MALI_C720_HISTOGRAM_SKIP_Y_EVERY_9TH: Collect every 9th row
+ */
+enum mali_c720_histogram_skip_y {
+ MALI_C720_HISTOGRAM_SKIP_Y_ALL = 0,
+ MALI_C720_HISTOGRAM_SKIP_Y_EVERY_2ND = 1,
+ MALI_C720_HISTOGRAM_SKIP_Y_EVERY_3RD = 2,
+ MALI_C720_HISTOGRAM_SKIP_Y_EVERY_4TH = 3,
+ MALI_C720_HISTOGRAM_SKIP_Y_EVERY_5TH = 4,
+ MALI_C720_HISTOGRAM_SKIP_Y_EVERY_8TH = 5,
+ MALI_C720_HISTOGRAM_SKIP_Y_EVERY_9TH = 6,
+};
+
+/**
+ * enum mali_c720_histogram_row_column_offset - Starting row or column
+ * @MALI_C720_HISTOGRAM_FIRST_ROW_OR_COL: Start from the first row or column
+ * @MALI_C720_HISTOGRAM_SECOND_ROW_OR_COL: Start from the second row or column
+ */
+enum mali_c720_histogram_row_column_offset {
+ MALI_C720_HISTOGRAM_FIRST_ROW_OR_COL = 0,
+ MALI_C720_HISTOGRAM_SECOND_ROW_OR_COL = 1,
+};
+
+/**
+ * enum mali_c720_histogram_scale - Intensity range scaling
+ * @MALI_C720_HISTOGRAM_SCALE_1X: No scaling
+ * @MALI_C720_HISTOGRAM_SCALE_2X: Scale by 2
+ * @MALI_C720_HISTOGRAM_SCALE_4X: Scale by 4
+ * @MALI_C720_HISTOGRAM_SCALE_8X: Scale by 8
+ * @MALI_C720_HISTOGRAM_SCALE_16X: Scale by 16
+ */
+enum mali_c720_histogram_scale {
+ MALI_C720_HISTOGRAM_SCALE_1X = 0,
+ MALI_C720_HISTOGRAM_SCALE_2X = 1,
+ MALI_C720_HISTOGRAM_SCALE_4X = 2,
+ MALI_C720_HISTOGRAM_SCALE_8X = 3,
+ MALI_C720_HISTOGRAM_SCALE_16X = 4,
+};
+
+/**
+ * enum mali_c720_histogram_plane_mode - Mode for histogram collection
+ * @MALI_C720_HISTOGRAM_COMBINED: All color planes in one 1024-bin histogram
+ * with a bin width of 16384
+ * @MALI_C720_HISTOGRAM_SEPARATE: Each color plane in one 256-bin histogram
+ * with a bin width of 65536
+ * @MALI_C720_HISTOGRAM_SEPARATE_ALL: As %MALI_C720_HISTOGRAM_SEPARATE, without
+ * pixel skipping; ignores skip and offset fields
+ * @MALI_C720_HISTOGRAM_FOCUS_00: Top left plane in the first bank, rest in second bank
+ * @MALI_C720_HISTOGRAM_FOCUS_01: Top right plane in the first bank, rest in second bank
+ * @MALI_C720_HISTOGRAM_FOCUS_10: Bottom left plane in the first bank, rest in second bank
+ * @MALI_C720_HISTOGRAM_FOCUS_11: Bottom right plane in the first bank, rest in second bank
+ *
+ * In the "focus" modes statistics are collected into two 512-bin histograms
+ * with a bin width of 32768. One color plane is in the first histogram with
+ * the remainder combined into the second. The four options represent which
+ * of the four positions in a Bayer pattern is the focused plane.
+ *
+ * Bin widths are expressed in 24-bit input levels with intensity scaling set
+ * to %MALI_C720_HISTOGRAM_SCALE_1X. Value 3 is reserved.
+ */
+enum mali_c720_histogram_plane_mode {
+ MALI_C720_HISTOGRAM_COMBINED = 0,
+ MALI_C720_HISTOGRAM_SEPARATE = 1,
+ MALI_C720_HISTOGRAM_SEPARATE_ALL = 2,
+ MALI_C720_HISTOGRAM_FOCUS_00 = 4,
+ MALI_C720_HISTOGRAM_FOCUS_01 = 5,
+ MALI_C720_HISTOGRAM_FOCUS_10 = 6,
+ MALI_C720_HISTOGRAM_FOCUS_11 = 7,
+};
+
+enum mali_c720_params_histogram_mask {
+ MALI_C720_PARAMS_HISTOGRAM_MASK_STREAM_MUX_SEL,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_NODES_USED_HORIZ,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_NODES_USED_VERT,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_SKIP_X,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_SKIP_Y,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_OFFSET_X,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_OFFSET_Y,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_SCALE_BOTTOM,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_SCALE_TOP,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_PLANE_MODE,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_WEIGHTS,
+};
+
+/**
+ * struct mali_c720_params_histogram - Histogram configuration
+ *
+ * This struct configures the 1024-bin histograms. The parameters allow
+ * particular regions of the image to be masked and different kinds of
+ * histogram to be selected.
+ *
+ * The @skip_x, @offset_x, @skip_y and @offset_y fields select pixels by their
+ * position relative to the top left of the image. These fields reduce the
+ * number of pixels counted, but some combinations exclude entire Bayer color
+ * components.
+ *
+ * The zone dimensions define the spatial weighting grid, whose total number
+ * of zones must not exceed MALI_C720_MAX_ZONES (1024). A zero weight
+ * excludes the zone from the histogram.
+ * When updating zone dimensions, both horizontal and vertical directions must
+ * be provided with their respective updated_mask bits set.
+ *
+ * @scale_bottom and @scale_top increase bin resolution at the dark and bright
+ * ends of the input range respectively. Samples outside the selected ranges
+ * do not contribute to the histogram.
+ *
+ * Set header.type to the target from &enum mali_c720_param_block_type.
+ * See &enum mali_c720_params_histogram_mask for the @updated_mask bit positions.
+ * Undefined bits are reserved and must be set to zero.
+ *
+ * @header: The generic V4L2 ISP block header
+ * @updated_mask: Mask of configuration fields to update
+ * @stream_mux_select: Input selection for pre-Iridix histograms. See
+ * &enum mali_c720_histogram_input. Ignored for other targets.
+ * @nodes_used_horiz: Number of active zones horizontally [1..255], subject to the total
+ * zone limit above
+ * @nodes_used_vert: Number of active zones vertically [1..255], subject to the total
+ * zone limit above
+ * @skip_x: Horizontal decimation. See &enum mali_c720_histogram_skip_x
+ * @skip_y: Vertical decimation. See &enum mali_c720_histogram_skip_y
+ * @offset_x: Skip the first column, or not. See &enum mali_c720_histogram_row_column_offset
+ * @offset_y: Skip the first row, or not. See &enum mali_c720_histogram_row_column_offset.
+ * With @skip_y set to %MALI_C720_HISTOGRAM_SKIP_Y_ALL, this selects
+ * the starting column on alternate rows instead.
+ * @scale_bottom: Scale pixels in the bottom half of the intensity range.
+ * See &enum mali_c720_histogram_scale
+ * @scale_top: Scale pixels in the top half of the intensity range.
+ * See &enum mali_c720_histogram_scale
+ * @plane_mode: Plane separation mode. See &enum mali_c720_histogram_plane_mode
+ * @reserved: Reserved; set to zero
+ * @weights: Zone weighting, one byte per zone, starting at the top left and
+ * continuing in raster order. Each zone can be weighted in [0..15].
+ * The grid has @nodes_used_horiz columns and @nodes_used_vert rows.
+ */
+struct mali_c720_params_histogram {
+ struct v4l2_isp_block_header header;
+ __u64 updated_mask;
+ __u8 stream_mux_select;
+ __u8 nodes_used_horiz;
+ __u8 nodes_used_vert;
+ __u8 skip_x;
+ __u8 skip_y;
+ __u8 offset_x;
+ __u8 offset_y;
+ __u8 scale_bottom;
+ __u8 scale_top;
+ __u8 plane_mode;
+ __u8 reserved[2];
+ __u8 weights[MALI_C720_MAX_ZONES];
+};
+
+/**
+ * MALI_C720_PARAMS_MAX_SIZE - Maximum size of all parameters for Mali-C720
+ * in a full hardware configuration.
+ *
+ * Though the parameters for the Mali-C720 are passed as optional blocks, the
+ * driver still needs to know the absolute maximum size so that it can allocate
+ * a buffer sized appropriately to accommodate userspace attempting to set all
+ * possible parameters in a single frame.
+ *
+ * Some structs are in this list multiple times. Where that's the case, it just
+ * reflects the fact that several block identifiers share the same payload
+ * structure.
+ */
+#define MALI_C720_PARAMS_MAX_SIZE \
+ (sizeof(struct mali_c720_params_digital_gain) + \
+ sizeof(struct mali_c720_params_histogram) + \
+ sizeof(struct mali_c720_params_awb_gains) + \
+ sizeof(struct mali_c720_params_histogram) + \
+ sizeof(struct mali_c720_params_histogram) + \
+ sizeof(struct mali_c720_params_color_stats) + \
+ sizeof(struct mali_c720_params_black_level) + \
+ sizeof(struct mali_c720_params_sqrt) + \
+ sizeof(struct mali_c720_params_square) + \
+ sizeof(struct mali_c720_params_square) + \
+ sizeof(struct mali_c720_params_sqrt) + \
+ sizeof(struct mali_c720_params_decompander))
#endif
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 22/24] media: mali-c720: Add parameters video node
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (20 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 21/24] media: uapi: Add parameter structs to mali-c720-config.h Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 23/24] media: Documentation: Document Mali-C720 parameter settings Anthony McGivern
2026-11-24 17:07 ` [PATCH 24/24] MAINTAINERS: Add entry for mali-c720 driver Anthony McGivern
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add a metadata output node for userspace to configure ISP processing.
Validate and copy queued parameter data before applying it to the
context register image. The ISP's configuration DMA engine (CDMA)
loads these settings before processing the frame.
Initial support includes statistics configuration, digital gain,
white balance, black level correction, square/square-root
transformations and input decompanding. Available parameter blocks
are reported through a read-only capability control.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
drivers/media/platform/arm/mali-c720/Makefile | 1 +
.../platform/arm/mali-c720/mali-c720-common.h | 49 +
.../media/platform/arm/mali-c720/mali-c720-core.c | 25 +-
.../platform/arm/mali-c720/mali-c720-ctx-mgr.c | 1 +
.../media/platform/arm/mali-c720/mali-c720-isp.c | 27 +-
.../platform/arm/mali-c720/mali-c720-params.c | 1450 ++++++++++++++++++++
6 files changed, 1549 insertions(+), 4 deletions(-)
diff --git a/drivers/media/platform/arm/mali-c720/Makefile b/drivers/media/platform/arm/mali-c720/Makefile
index c48d54dac23a94d429349d90eaf96c19bc017468..d0372f1f6f0d990215a66cba5d506b7c68f5edc7 100644
--- a/drivers/media/platform/arm/mali-c720/Makefile
+++ b/drivers/media/platform/arm/mali-c720/Makefile
@@ -10,6 +10,7 @@ mali-c720-y := mali-c720-capture.o \
mali-c720-input.o \
mali-c720-interrupts.o \
mali-c720-isp.o \
+ mali-c720-params.o \
mali-c720-register-access.o \
mali-c720-registers.o \
mali-c720-registers-top.o \
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-common.h b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
index 7a137de2e020d9de18df9918fe54519fab111a38..825f2603338ae83ce2b83e05013e21a0afc76639 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-common.h
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-common.h
@@ -111,6 +111,7 @@ enum mali_c720_isp_pads {
MALI_C720_ISP_PAD_SINK_VIDEO,
MALI_C720_ISP_PAD_SOURCE_HV,
MALI_C720_ISP_PAD_SOURCE_STATS,
+ MALI_C720_ISP_PAD_SINK_PARAMS,
MALI_C720_ISP_NUM_PADS,
};
@@ -219,6 +220,17 @@ struct mali_c720_stats_buf {
dma_addr_t addr;
};
+struct mali_c720_params_buf {
+ struct vb2_v4l2_buffer vb;
+ struct list_head queue;
+ struct v4l2_isp_params_buffer *config;
+};
+
+struct mali_c720_param_target {
+ bool present;
+ u32 base;
+};
+
struct mali_c720_stats_target {
struct mali_c720_cdma_sg_cfg desc[2];
u8 num_desc;
@@ -249,6 +261,29 @@ struct mali_c720_stats {
} ctrls;
};
+struct mali_c720_params {
+ struct mali_c720 *mali_c720;
+ struct video_device vdev;
+ struct vb2_queue queue;
+ struct media_pad pad;
+ /* Mutex to provide to vb2 */
+ struct mutex lock;
+
+ struct {
+ /* Spinlock to guard buffer queue */
+ spinlock_t lock;
+ struct list_head input;
+ struct list_head processing;
+ } buffers;
+
+ unsigned int num_targets;
+ struct mali_c720_param_target targets[MALI_C720_PARAM_BLOCK_MAX];
+ struct {
+ struct v4l2_ctrl_handler handler;
+ struct v4l2_ctrl *param_capabilities;
+ } ctrls;
+};
+
struct mali_c720_request {
struct media_request req;
unsigned int queue_sequence;
@@ -323,6 +358,7 @@ struct mali_c720 {
struct mali_c720_fr_pipe fr_pipe;
struct mali_c720_cap_dev cap_devs[MALI_C720_MAX_NUM_CAP_DEVS];
struct mali_c720_stats stats;
+ struct mali_c720_params params;
unsigned int num_async_endpoints;
@@ -374,6 +410,10 @@ int mali_c720_register_stats(struct mali_c720 *mali_c720);
void mali_c720_unregister_stats(struct mali_c720 *mali_c720);
void mali_c720_cleanup_stats(struct mali_c720 *mali_c720);
+int mali_c720_register_params(struct mali_c720 *mali_c720);
+void mali_c720_unregister_params(struct mali_c720 *mali_c720);
+void mali_c720_cleanup_params(struct mali_c720 *mali_c720);
+
void mali_c720_fr_pipe_apply_resizer_config(struct mali_c720_fr_pipe *pipe);
bool mali_c720_cap_dev_uses_requests(struct mali_c720_cap_dev *cap_dev);
@@ -391,6 +431,15 @@ void mali_c720_stats_set_next_buffer(struct mali_c720_stats *stats,
struct media_request *req);
void mali_c720_stats_buffer_done(struct mali_c720_stats *stats, bool success);
+bool mali_c720_params_uses_requests(struct mali_c720_params *params);
+struct media_request *mali_c720_params_get_request(struct mali_c720_params *params);
+struct mali_c720_params_buf *
+mali_c720_params_get_next_buffer(struct mali_c720_params *params,
+ struct media_request *req);
+void mali_c720_params_apply_config(struct mali_c720 *mali_c720,
+ struct mali_c720_params_buf *buf);
+void mali_c720_params_buffer_done(struct mali_c720_params *params, bool success);
+
void mali_c720_isp_queue_event_sof(struct mali_c720 *mali_c720, u32 sequence);
int mali_c720_pipeline_ready(struct mali_c720 *mali_c720);
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-core.c b/drivers/media/platform/arm/mali-c720/mali-c720-core.c
index ad768b0a2e03a0a6f38b72603ccdedaeeee42f0a..722778c6a31cbbd423e6be37933cb0db522d4cdc 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-core.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-core.c
@@ -47,6 +47,7 @@ static void mali_c720_remove_links(struct mali_c720 *mali_c720)
media_entity_remove_links(&mali_c720->cap_devs[i].vdev.entity);
media_entity_remove_links(&mali_c720->stats.vdev.entity);
+ media_entity_remove_links(&mali_c720->params.vdev.entity);
}
static int mali_c720_create_tpg_links(struct mali_c720 *mali_c720,
@@ -159,6 +160,13 @@ static int mali_c720_create_3a_links(struct mali_c720 *mali_c720)
return ret;
}
+ ret = media_create_pad_link(&mali_c720->params.vdev.entity, 0,
+ &isp_sd->entity,
+ MALI_C720_ISP_PAD_SINK_PARAMS,
+ 0);
+ if (ret)
+ dev_err(mali_c720->dev, "Failed to link 3A params node and ISP\n");
+
return ret;
}
@@ -206,6 +214,7 @@ static void mali_c720_unregister_video_devices(struct mali_c720 *mali_c720)
mali_c720_unregister_capture_devs(mali_c720);
mali_c720_unregister_stats(mali_c720);
+ mali_c720_unregister_params(mali_c720);
}
static void mali_c720_unregister_entities(struct mali_c720 *mali_c720)
@@ -250,6 +259,10 @@ static int mali_c720_register_entities(struct mali_c720 *mali_c720)
if (ret)
goto err_unregister_entities;
+ ret = mali_c720_register_params(mali_c720);
+ if (ret)
+ goto err_unregister_entities;
+
ret = mali_c720_create_links(mali_c720);
if (ret)
goto err_unregister_entities;
@@ -371,6 +384,7 @@ static void mali_c720_release(struct v4l2_device *v4l2_dev)
mali_c720_cleanup_capture_devs(mali_c720);
mali_c720_cleanup_stats(mali_c720);
+ mali_c720_cleanup_params(mali_c720);
mali_c720_cleanup_fr_pipe(mali_c720);
mali_c720_cleanup_vision_pipe(mali_c720);
mali_c720_cleanup_isp(mali_c720);
@@ -608,6 +622,9 @@ static struct media_request *mali_c720_find_request(struct mali_c720 *mali_c720)
candidate = mali_c720_stats_get_request(&mali_c720->stats);
req = mali_c720_oldest_request(NULL, candidate);
+ candidate = mali_c720_params_get_request(&mali_c720->params);
+ req = mali_c720_oldest_request(req, candidate);
+
for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
candidate = mali_c720_cap_dev_get_request(&mali_c720->cap_devs[i]);
req = mali_c720_oldest_request(req, candidate);
@@ -620,7 +637,8 @@ static bool mali_c720_uses_requests(struct mali_c720 *mali_c720)
{
unsigned int i;
- if (mali_c720_stats_uses_requests(&mali_c720->stats))
+ if (mali_c720_stats_uses_requests(&mali_c720->stats) ||
+ mali_c720_params_uses_requests(&mali_c720->params))
return true;
for (i = 0; i < MALI_C720_MAX_NUM_CAP_DEVS; i++) {
@@ -651,6 +669,7 @@ static struct media_request *mali_c720_can_schedule_request(struct mali_c720_con
void mali_c720_try_schedule_frame(struct mali_c720_context *ctx)
{
struct mali_c720 *mali_c720 = ctx->mali_c720;
+ struct mali_c720_params_buf *params_buf = NULL;
struct media_request *req = NULL;
unsigned int i;
@@ -673,6 +692,7 @@ void mali_c720_try_schedule_frame(struct mali_c720_context *ctx)
mali_c720_cap_dev_set_next_buffer(&mali_c720->cap_devs[i], req);
mali_c720_stats_set_next_buffer(&mali_c720->stats, req);
+ params_buf = mali_c720_params_get_next_buffer(&mali_c720->params, req);
}
ctx->pipeline_busy = true;
@@ -681,6 +701,9 @@ void mali_c720_try_schedule_frame(struct mali_c720_context *ctx)
/* Resizer configurations should be synchronised with CDMA */
mali_c720_fr_pipe_apply_resizer_config(&mali_c720->fr_pipe);
+ if (params_buf)
+ mali_c720_params_apply_config(mali_c720, params_buf);
+
mali_c720_ctx_mgr_handle_sw_ready(ctx);
}
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
index cd0cf046ac58a001ec821342b2e64e85755438f1..815ad8537312616a862ca702c6b80d0d721f22c7 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-ctx-mgr.c
@@ -1426,6 +1426,7 @@ void mali_c720_ctx_mgr_buffer_done(struct mali_c720_context *ctx, bool success)
mali_c720_cap_dev_buffer_done(&mali_c720->cap_devs[i], success);
mali_c720_stats_buffer_done(&mali_c720->stats, success);
+ mali_c720_params_buffer_done(&mali_c720->params, success);
}
void mali_c720_ctx_mgr_handle_sw_ready(struct mali_c720_context *ctx)
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-isp.c b/drivers/media/platform/arm/mali-c720/mali-c720-isp.c
index a6c4da686bde0b76302ee9ad4fb49a132fa82b7c..3e17917296ea89973fa8ba8b520d2db0b2577a4b 100644
--- a/drivers/media/platform/arm/mali-c720/mali-c720-isp.c
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-isp.c
@@ -23,7 +23,8 @@ static int mali_c720_isp_enum_mbus_code(struct v4l2_subdev *sd,
struct mali_c720_mbus_format_match match;
/* HV uses the sink Bayer order at the internal 16-bit precision. */
- if (code->pad == MALI_C720_ISP_PAD_SOURCE_STATS) {
+ if (code->pad == MALI_C720_ISP_PAD_SOURCE_STATS ||
+ code->pad == MALI_C720_ISP_PAD_SINK_PARAMS) {
if (code->index)
return -EINVAL;
code->code = MEDIA_BUS_FMT_METADATA_FIXED;
@@ -94,6 +95,7 @@ static int mali_c720_isp_enum_frame_size(struct v4l2_subdev *sd,
return -EINVAL;
break;
case MALI_C720_ISP_PAD_SOURCE_STATS:
+ case MALI_C720_ISP_PAD_SINK_PARAMS:
return -ENOTTY;
default:
return -EINVAL;
@@ -298,7 +300,7 @@ static const struct v4l2_subdev_ops mali_c720_isp_ops = {
static int mali_c720_isp_init_state(struct v4l2_subdev *sd,
struct v4l2_subdev_state *state)
{
- struct v4l2_mbus_framefmt *sink_fmt, *src_fmt, *stats_fmt;
+ struct v4l2_mbus_framefmt *sink_fmt, *src_fmt, *stats_fmt, *params_fmt;
sink_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_VIDEO);
sink_fmt->width = MALI_C720_DEFAULT_WIDTH;
@@ -320,6 +322,12 @@ static int mali_c720_isp_init_state(struct v4l2_subdev *sd,
stats_fmt->field = V4L2_FIELD_NONE;
stats_fmt->code = MEDIA_BUS_FMT_METADATA_FIXED;
+ params_fmt = v4l2_subdev_state_get_format(state, MALI_C720_ISP_PAD_SINK_PARAMS);
+ params_fmt->width = 0;
+ params_fmt->height = 0;
+ params_fmt->field = V4L2_FIELD_NONE;
+ params_fmt->code = MEDIA_BUS_FMT_METADATA_FIXED;
+
return 0;
}
@@ -357,9 +365,21 @@ static int mali_c720_isp_subdev_link_setup(struct media_entity *entity,
return 0;
}
+static int mali_c720_isp_subdev_link_validate(struct media_link *link)
+{
+ /*
+ * Skip validation for the parameters sink pad, as the source is not
+ * a subdevice.
+ */
+ if (link->sink->index == MALI_C720_ISP_PAD_SINK_PARAMS)
+ return 0;
+
+ return v4l2_subdev_link_validate(link);
+}
+
static const struct media_entity_operations mali_c720_isp_media_ops = {
.link_setup = mali_c720_isp_subdev_link_setup,
- .link_validate = v4l2_subdev_link_validate,
+ .link_validate = mali_c720_isp_subdev_link_validate,
};
int mali_c720_register_isp(struct mali_c720 *mali_c720)
@@ -383,6 +403,7 @@ int mali_c720_register_isp(struct mali_c720 *mali_c720)
MEDIA_PAD_FL_MUST_CONNECT;
isp->pads[MALI_C720_ISP_PAD_SOURCE_HV].flags = MEDIA_PAD_FL_SOURCE;
isp->pads[MALI_C720_ISP_PAD_SOURCE_STATS].flags = MEDIA_PAD_FL_SOURCE;
+ isp->pads[MALI_C720_ISP_PAD_SINK_PARAMS].flags = MEDIA_PAD_FL_SINK;
ret = media_entity_pads_init(&sd->entity,
MALI_C720_ISP_NUM_PADS,
diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-params.c b/drivers/media/platform/arm/mali-c720/mali-c720-params.c
new file mode 100644
index 0000000000000000000000000000000000000000..e6e0ca070f0ea16efbe2effd89d1fe3a92f8cb42
--- /dev/null
+++ b/drivers/media/platform/arm/mali-c720/mali-c720-params.c
@@ -0,0 +1,1450 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ARM Mali-C720 ISP Driver - Image signal processor
+ *
+ * Copyright (C) 2026 Arm Ltd
+ */
+
+#include <linux/cleanup.h>
+#include <linux/device.h>
+#include <linux/dma-buf.h>
+#include <linux/pm_runtime.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include <asm/byteorder.h>
+
+#include <media/media-entity.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-fh.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-isp.h>
+#include <media/videobuf2-vmalloc.h>
+
+#include "mali-c720-common.h"
+
+/**
+ * union mali_c720_params_block - Generalization of a parameter block
+ *
+ * This union allows the driver to treat a block as a generic pointer to this
+ * union and safely access the header and block-specific struct without having
+ * to resort to casting. The header member is accessed first, and the
+ * header->type field checked which allows the driver to determine which of
+ * other members should be used. The data member at the end allows a pointer to
+ * an address within the data member of :c:type:`v4l2_isp_params_buffer` to
+ * initialize a union variable.
+ *
+ * @header: Pointer to the shared header struct embedded as the
+ * first member of all the possible other members (except
+ * @data). This member would be accessed first and the
+ * header->type field checked to determine which of the other
+ * members should be accessed.
+ * @digital_gain: For header->type:
+ * MALI_C720_PARAM_BLOCK_DIGITAL_GAIN_INP
+ * @awb_gains: For header->type:
+ * MALI_C720_PARAM_BLOCK_AWB_GAINS_HV
+ * @black_level: For header->type:
+ * MALI_C720_PARAM_BLOCK_BLACK_LEVEL_HV
+ * @square_root: For header->type:
+ * MALI_C720_PARAM_BLOCK_SQRT_INP
+ * MALI_C720_PARAM_BLOCK_SQRT_HV
+ * @square: For header->type:
+ * MALI_C720_PARAM_BLOCK_SQUARE_A_HV
+ * MALI_C720_PARAM_BLOCK_SQUARE_B_HV
+ * @decompander: For header->type == MALI_C720_PARAM_BLOCK_DECOMPANDER_INP
+ * @color_stats: For header->type:
+ * MALI_C720_PARAM_BLOCK_COLOR_STATS_HV
+ * @histogram: For header->type:
+ * MALI_C720_PARAM_BLOCK_HISTOGRAM_INP
+ * MALI_C720_PARAM_BLOCK_HISTOGRAM_HV
+ * MALI_C720_PARAM_BLOCK_HISTOGRAM_HV_IRIDIX
+ * @data: Allows easy initialization of a union variable with a
+ * pointer into a __u8 array.
+ */
+union mali_c720_params_block {
+ struct v4l2_isp_block_header *header;
+ struct mali_c720_params_digital_gain *digital_gain;
+ struct mali_c720_params_awb_gains *awb_gains;
+ struct mali_c720_params_black_level *black_level;
+ struct mali_c720_params_sqrt *square_root;
+ struct mali_c720_params_square *square;
+ struct mali_c720_params_decompander *decompander;
+ struct mali_c720_params_color_stats *color_stats;
+ struct mali_c720_params_histogram *histogram;
+ __u8 *data;
+};
+
+typedef void (*mali_c720_params_handler)(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config);
+
+static const struct mali_c720_discovery_target
+mali_c720_params_discovery_targets[MALI_C720_PARAM_BLOCK_MAX] = {
+ [MALI_C720_PARAM_BLOCK_DIGITAL_GAIN_INP] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_DIGITAL_GAIN, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_INPUT, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_AWB_GAINS_HV] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_WB_GAIN, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_HV, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_BLACK_LEVEL_HV] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_BLACK_LEVEL, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_HV, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_SQRT_INP] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_SQUARE_ROOT_RAW, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_INPUT, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_SQRT_HV] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_SQUARE_ROOT_RGB, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_HV, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_SQUARE_A_HV] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_SQUARE_RAW, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_HV, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_SQUARE_B_HV] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_SQUARE_RGB, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_HV, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_DECOMPANDER_INP] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_DECOMPANDER, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_INPUT, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_COLOR_STATS_HV] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_COLOR_STATS, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_STATS, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_HISTOGRAM_INP] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_HISTOGRAM_STATS, .module_instance = 0,
+ .pipeline_id = MALI_C720_DISC_PIPE_STATS, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_HISTOGRAM_HV] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_HISTOGRAM_STATS, .module_instance = 1,
+ .pipeline_id = MALI_C720_DISC_PIPE_STATS, .pipeline_instance = 0 },
+ [MALI_C720_PARAM_BLOCK_HISTOGRAM_HV_IRIDIX] = {
+ .module_id = MALI_C720_DISC_MODULE_ID_HISTOGRAM_STATS, .module_instance = 2,
+ .pipeline_id = MALI_C720_DISC_PIPE_STATS, .pipeline_instance = 0 },
+};
+
+static int
+mali_c720_params_fill_target(struct mali_c720 *mali_c720, unsigned int block_type,
+ struct mali_c720_param_target *target)
+{
+ const struct mali_c720_discovery_target *discovery;
+ int ret;
+
+ discovery = &mali_c720_params_discovery_targets[block_type];
+
+ if (!mali_c720_discovery_module_present(mali_c720, discovery))
+ return -ENOENT;
+
+ ret = mali_c720_discovery_get_module_base(mali_c720, discovery,
+ &target->base);
+ if (ret)
+ return ret;
+
+ target->present = true;
+ return 0;
+}
+
+static int mali_c720_params_build_target_cache(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_params *params = &mali_c720->params;
+ unsigned int block_type;
+ int ret;
+
+ for (block_type = 0; block_type < MALI_C720_PARAM_BLOCK_MAX; block_type++) {
+ ret = mali_c720_params_fill_target(mali_c720, block_type,
+ ¶ms->targets[block_type]);
+ if (ret == -ENOENT)
+ continue;
+ if (ret)
+ return ret;
+
+ params->num_targets++;
+ }
+
+ if (!params->num_targets) {
+ dev_err(mali_c720->dev, "no configurable parameter targets discovered\n");
+ return -ENODEV;
+ }
+
+ return 0;
+}
+
+static const struct mali_c720_param_target *
+mali_c720_params_get_target(struct mali_c720_params *params, unsigned int block_type)
+{
+ if (block_type >= MALI_C720_PARAM_BLOCK_MAX || !params->targets[block_type].present)
+ return NULL;
+
+ return ¶ms->targets[block_type];
+}
+
+static int mali_c720_params_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
+{
+ struct mali_c720_params *params =
+ container_of(ctrl->handler, struct mali_c720_params, ctrls.handler);
+ u16 *ids = ctrl->p_new.p_u16;
+ unsigned int block_type;
+
+ if (ctrl->id != V4L2_CID_MALI_C720_PARAM_CAPABILITIES)
+ return -EINVAL;
+
+ for (block_type = 0; block_type < MALI_C720_PARAM_BLOCK_MAX; block_type++) {
+ if (params->targets[block_type].present)
+ *ids++ = (u16)block_type;
+ }
+
+ return 0;
+}
+
+static const struct v4l2_ctrl_ops mali_c720_params_ctrl_ops = {
+ .g_volatile_ctrl = mali_c720_params_g_volatile_ctrl,
+};
+
+static const struct v4l2_ctrl_config mali_c720_params_caps_ctrl = {
+ .ops = &mali_c720_params_ctrl_ops,
+ .id = V4L2_CID_MALI_C720_PARAM_CAPABILITIES,
+ .name = "Mali-C720 Parameter Capabilities",
+ .type = V4L2_CTRL_TYPE_U16,
+ .dims = { MALI_C720_PARAM_BLOCK_MAX },
+ .min = 0,
+ .max = U16_MAX,
+ .step = 1,
+ .flags = V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_VOLATILE,
+};
+
+#define to_mali_c720_params_buf(vbuf) \
+ container_of(vbuf, struct mali_c720_params_buf, vb)
+
+static void mali_c720_params_u8_lut_write(struct mali_c720_context *ctx,
+ u32 addr, u8 *lut, u32 size)
+{
+ unsigned int i, head_elems, tail_elems;
+ u32 data;
+
+ /*
+ * Write an array of 8-bit LUT elements to 32-bit registers.
+ * We first write 4 elements at a time until such point that doing so
+ * would exceed the array size, and then write the remaining 1-3 elements.
+ */
+
+ head_elems = size & 0xfffffffc;
+ tail_elems = size - head_elems;
+ for (i = 0; i < head_elems; i += 4, addr += 4) {
+ data = le32_to_cpup((const __le32 *)(lut + i));
+ mali_c720_ctx_write_raw(ctx, addr, data);
+ }
+
+ data = 0;
+ switch (tail_elems) {
+ case 3:
+ data |= (u32)lut[head_elems + 2] << 16;
+ fallthrough;
+ case 2:
+ data |= (u32)lut[head_elems + 1] << 8;
+ fallthrough;
+ case 1:
+ data |= lut[head_elems];
+ mali_c720_ctx_write_raw(ctx, addr, data);
+ break;
+ default:
+ break;
+ }
+}
+
+static void mali_c720_params_u32_lut_write(struct mali_c720_context *ctx,
+ u32 addr, u32 *lut, u32 size)
+{
+ unsigned int i;
+
+ for (i = 0; i < size; i++, addr += 4)
+ mali_c720_ctx_write_raw(ctx, addr, lut[i]);
+}
+
+#define mali_c720_params_updated(params, flag) \
+ (!!((params)->updated_mask & BIT_ULL(flag)))
+
+#define mali_c720_ctx_group_write_updated(ctx, group, reg, val, flag) \
+ do { \
+ if (mali_c720_params_updated(params, flag)) \
+ mali_c720_ctx_group_write(ctx, group, reg, val); \
+ } while (0)
+
+#define mali_c720_lut_u8_write_updated(ctx, addr, lut, size, flag) \
+ do { \
+ if (mali_c720_params_updated(params, flag)) { \
+ mali_c720_params_u8_lut_write(ctx, addr, lut, size); \
+ } \
+ } while (0)
+
+#define mali_c720_lut_u32_write_updated(ctx, addr, lut, size, flag) \
+ do { \
+ if (mali_c720_params_updated(params, flag)) { \
+ mali_c720_params_u32_lut_write(ctx, addr, lut, size); \
+ } \
+ } while (0)
+
+static void mali_c720_params_write_bypass(struct mali_c720_context *ctx, u32 base,
+ const struct mali_c720_reg_field *field,
+ const struct v4l2_isp_block_header *header)
+{
+ u16 flags = header->flags;
+
+ if (flags & (V4L2_ISP_PARAMS_FL_BLOCK_ENABLE | V4L2_ISP_PARAMS_FL_BLOCK_DISABLE))
+ mali_c720_ctx_group_write(ctx, base, field,
+ !!(flags & V4L2_ISP_PARAMS_FL_BLOCK_DISABLE));
+}
+
+static void mali_c720_params_input_digital_gain(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ const struct mali_c720_digital_gain_regs *inp_dgain =
+ mali_c720->registers.modules->inp_dgain;
+ struct mali_c720_params_digital_gain *params = block.digital_gain;
+
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_dgain, block.header);
+
+ if (!config || !params->updated_mask)
+ return;
+
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &inp_dgain->gain,
+ params->gain,
+ MALI_C720_PARAMS_DIGITAL_GAIN_MASK_GAIN);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &inp_dgain->offset,
+ params->offset,
+ MALI_C720_PARAMS_DIGITAL_GAIN_MASK_OFFSET);
+}
+
+static void mali_c720_params_awb_gains(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ const struct mali_c720_wb_gain_regs *wb_gain = mali_c720->registers.modules->wb_gain;
+ struct mali_c720_params_awb_gains *params = block.awb_gains;
+
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_wb_gain, block.header);
+
+ if (!config || !params->updated_mask)
+ return;
+
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &wb_gain->gain_00,
+ params->gain00,
+ MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN00);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &wb_gain->gain_01,
+ params->gain01,
+ MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN01);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &wb_gain->gain_10,
+ params->gain10,
+ MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN10);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &wb_gain->gain_11,
+ params->gain11,
+ MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN11);
+}
+
+static void mali_c720_params_black_level(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ const struct mali_c720_black_level_regs *black_level =
+ mali_c720->registers.modules->black_level;
+ struct mali_c720_params_black_level *params = block.black_level;
+
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_black_level, block.header);
+
+ if (!config || !params->updated_mask)
+ return;
+
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &black_level->black_00,
+ params->chan00,
+ MALI_C720_PARAMS_BLACK_LEVEL_MASK_CHAN00);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &black_level->black_01,
+ params->chan01,
+ MALI_C720_PARAMS_BLACK_LEVEL_MASK_CHAN01);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &black_level->black_10,
+ params->chan10,
+ MALI_C720_PARAMS_BLACK_LEVEL_MASK_CHAN10);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &black_level->black_11,
+ params->chan11,
+ MALI_C720_PARAMS_BLACK_LEVEL_MASK_CHAN11);
+}
+
+static void mali_c720_params_sqrt_a(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ const struct mali_c720_square_root_regs *square_root_a =
+ mali_c720->registers.modules->square_root_a;
+ struct mali_c720_params_sqrt *params = block.square_root;
+
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_square_root_a, block.header);
+
+ if (!config || !params->updated_mask)
+ return;
+
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_root_a->black_level_in,
+ params->black_level_linear,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_BL_IN);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_root_a->black_level_out,
+ params->black_level_sqrt,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_BL_OUT);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_root_a->normalization,
+ params->normalization,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_NORMALIZATION);
+}
+
+static void mali_c720_params_sqrt_b(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ const struct mali_c720_square_root_regs *square_root_b =
+ mali_c720->registers.modules->square_root_b;
+ struct mali_c720_params_sqrt *params = block.square_root;
+
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_square_root_b, block.header);
+
+ if (!config || !params->updated_mask)
+ return;
+
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_root_b->black_level_in,
+ params->black_level_linear,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_BL_IN);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_root_b->black_level_out,
+ params->black_level_sqrt,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_BL_OUT);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_root_b->normalization,
+ params->normalization,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_NORMALIZATION);
+}
+
+static void mali_c720_params_square_a(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ const struct mali_c720_square_regs *square_a = mali_c720->registers.modules->square_a;
+ struct mali_c720_params_square *params = block.square;
+
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_square_a, block.header);
+
+ if (!config || !params->updated_mask)
+ return;
+
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_a->black_level_in,
+ params->black_level_sqrt,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_BL_IN);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_a->black_level_out,
+ params->black_level_linear,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_BL_OUT);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_a->normalization,
+ params->normalization,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_NORMALIZATION);
+}
+
+static void mali_c720_params_square_b(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ const struct mali_c720_square_regs *square_b = mali_c720->registers.modules->square_b;
+ struct mali_c720_params_square *params = block.square;
+
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->bypass_hv_square_b, block.header);
+
+ if (!config || !params->updated_mask)
+ return;
+
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_b->black_level_in,
+ params->black_level_sqrt,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_BL_IN);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_b->black_level_out,
+ params->black_level_linear,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_BL_OUT);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &square_b->normalization,
+ params->normalization,
+ MALI_C720_PARAMS_SQUARE_SQRT_MASK_NORMALIZATION);
+}
+
+static int
+mali_c720_params_validate_decompander(struct device *dev,
+ const struct v4l2_isp_block_header *block)
+{
+ const struct mali_c720 *mali_c720 = dev_get_drvdata(dev);
+ const struct mali_c720_decompander_regs *decompander =
+ mali_c720->registers.modules->decompander;
+ const struct mali_c720_params_decompander *params =
+ (const struct mali_c720_params_decompander *)block;
+ const u64 lut_mask = BIT_ULL(MALI_C720_PARAMS_DECOMPANDER_MASK_LUT_X) |
+ BIT_ULL(MALI_C720_PARAMS_DECOMPANDER_MASK_LUT_Y);
+ u64 updated;
+ unsigned int i;
+
+ if (block->size == sizeof(*block))
+ return 0;
+
+ updated = params->updated_mask & lut_mask;
+ if (!updated)
+ return 0;
+
+ if (updated != lut_mask) {
+ dev_dbg(dev, "Decompander x/y LUTs must be updated together\n");
+ return -EINVAL;
+ }
+
+ /*
+ * Reject decreasing X coordinates.
+ * Increasing X coordinates must differ by at least 8.
+ * Equal X coordinates must have equal Y coordinates.
+ */
+ for (i = 1; i < ARRAY_SIZE(params->lut_x); i++) {
+ u32 prev_x = params->lut_x[i - 1] & mali_c720_reg_mask(&decompander->lut_x);
+ u32 prev_y = params->lut_y[i - 1] & mali_c720_reg_mask(&decompander->lut_y);
+ u32 x = params->lut_x[i] & mali_c720_reg_mask(&decompander->lut_x);
+ u32 y = params->lut_y[i] & mali_c720_reg_mask(&decompander->lut_y);
+
+ if (x < prev_x || (x != prev_x && x - prev_x < 8) ||
+ (x == prev_x && y != prev_y)) {
+ dev_dbg(dev, "Invalid decompander LUT interval at index %u\n", i);
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
+static void mali_c720_params_decompander(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ const struct mali_c720_decompander_regs *decompander =
+ mali_c720->registers.modules->decompander;
+ struct mali_c720_params_decompander *params = block.decompander;
+ u32 lut_addr;
+
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->bypass_inp_decompander, block.header);
+
+ if (!config || !params->updated_mask)
+ return;
+
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &decompander->enable,
+ params->enable,
+ MALI_C720_PARAMS_DECOMPANDER_MASK_ENABLE);
+
+ lut_addr = mali_c720_reg_addr(target->base, &decompander->lut_x);
+ mali_c720_lut_u32_write_updated(ctx, lut_addr,
+ params->lut_x,
+ ARRAY_SIZE(params->lut_x),
+ MALI_C720_PARAMS_DECOMPANDER_MASK_LUT_X);
+
+ lut_addr = mali_c720_reg_addr(target->base, &decompander->lut_y);
+ mali_c720_lut_u32_write_updated(ctx, lut_addr,
+ params->lut_y,
+ ARRAY_SIZE(params->lut_y),
+ MALI_C720_PARAMS_DECOMPANDER_MASK_LUT_Y);
+}
+
+static int
+mali_c720_params_validate_color_stats(struct device *dev,
+ const struct v4l2_isp_block_header *block)
+{
+ const struct mali_c720_params_color_stats *params =
+ (const struct mali_c720_params_color_stats *)block;
+ const u64 zone_mask = BIT_ULL(MALI_C720_PARAMS_COLOR_STATS_MASK_NODES_USED_HORIZ) |
+ BIT_ULL(MALI_C720_PARAMS_COLOR_STATS_MASK_NODES_USED_VERT);
+ u64 updated;
+
+ if (block->size == sizeof(*block))
+ return 0;
+
+ updated = params->updated_mask & zone_mask;
+ if (!updated)
+ return 0;
+
+ if (updated != zone_mask) {
+ dev_dbg(dev, "Color stats zone dimensions must be updated together\n");
+ return -EINVAL;
+ }
+
+ /*
+ * Horizontal zone count must be between 3 and 32.
+ * Vertical zone count must be between 3 and 255.
+ * The total number of zones must not exceed MALI_C720_MAX_ZONES.
+ */
+ if (params->nodes_used_horiz < 3 || params->nodes_used_horiz > 32 ||
+ params->nodes_used_vert < 3 ||
+ params->nodes_used_horiz * params->nodes_used_vert > MALI_C720_MAX_ZONES) {
+ dev_dbg(dev, "Invalid color statistics zone dimensions\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void mali_c720_params_color_stats(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ const struct mali_c720_stat_color_stats_regs *stat_color_stats =
+ mali_c720->registers.modules->stat_color_stats;
+ struct mali_c720_params_color_stats *params = block.color_stats;
+ u32 weight_addr;
+
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->color_stats_0_mux_sel, block.header);
+
+ if (!config || !params->updated_mask)
+ return;
+
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->awb_nodes_used_horiz,
+ params->nodes_used_horiz,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_NODES_USED_HORIZ);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->awb_nodes_used_vert,
+ params->nodes_used_vert,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_NODES_USED_VERT);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->awb_stats_mode,
+ params->awb_stats_mode,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_AWB_STATS_MODE);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->white_level_awb,
+ params->white_level_awb,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_WHITE_LEVEL_AWB);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->black_level_awb,
+ params->black_level_awb,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_BLACK_LEVEL_AWB);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->cr_ref_max_awb,
+ params->cr_ref_max_awb,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CR_REF_MAX_AWB);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->cr_ref_min_awb,
+ params->cr_ref_min_awb,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CR_REF_MIN_AWB);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->cr_ref_high_awb,
+ params->cr_ref_high_awb,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CR_REF_HIGH_AWB);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->cr_ref_low_awb,
+ params->cr_ref_low_awb,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CR_REF_LOW_AWB);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->cb_ref_max_awb,
+ params->cb_ref_max_awb,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CB_REF_MAX_AWB);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->cb_ref_min_awb,
+ params->cb_ref_min_awb,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CB_REF_MIN_AWB);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->cb_ref_high_awb,
+ params->cb_ref_high_awb,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CB_REF_HIGH_AWB);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_color_stats->cb_ref_low_awb,
+ params->cb_ref_low_awb,
+ MALI_C720_PARAMS_COLOR_STATS_MASK_CB_REF_LOW_AWB);
+
+ weight_addr = mali_c720_reg_addr(target->base, &stat_color_stats->awb_weight);
+ mali_c720_lut_u8_write_updated(ctx, weight_addr,
+ params->weights,
+ ARRAY_SIZE(params->weights),
+ MALI_C720_PARAMS_COLOR_STATS_MASK_WEIGHTS);
+}
+
+static int
+mali_c720_params_validate_histogram(struct device *dev,
+ const struct v4l2_isp_block_header *block)
+{
+ const struct mali_c720_params_histogram *params =
+ (const struct mali_c720_params_histogram *)block;
+ const u64 zone_mask = BIT_ULL(MALI_C720_PARAMS_HISTOGRAM_MASK_NODES_USED_HORIZ) |
+ BIT_ULL(MALI_C720_PARAMS_HISTOGRAM_MASK_NODES_USED_VERT);
+ u64 updated;
+
+ if (block->size == sizeof(*block))
+ return 0;
+
+ updated = params->updated_mask & zone_mask;
+ if (updated && updated != zone_mask) {
+ dev_dbg(dev, "Histogram zone dimensions must be updated together\n");
+ return -EINVAL;
+ }
+
+ if (updated && (!params->nodes_used_horiz || !params->nodes_used_vert ||
+ params->nodes_used_horiz * params->nodes_used_vert >
+ MALI_C720_MAX_ZONES)) {
+ dev_dbg(dev, "Invalid histogram zone dimensions\n");
+ return -EINVAL;
+ }
+
+ if (mali_c720_params_updated(params, MALI_C720_PARAMS_HISTOGRAM_MASK_SKIP_X) &&
+ params->skip_x > MALI_C720_HISTOGRAM_SKIP_X_EVERY_9TH) {
+ dev_dbg(dev, "Invalid histogram horizontal skip selection\n");
+ return -EINVAL;
+ }
+
+ if (mali_c720_params_updated(params, MALI_C720_PARAMS_HISTOGRAM_MASK_SKIP_Y) &&
+ params->skip_y > MALI_C720_HISTOGRAM_SKIP_Y_EVERY_9TH) {
+ dev_dbg(dev, "Invalid histogram vertical skip selection\n");
+ return -EINVAL;
+ }
+
+ if (mali_c720_params_updated(params, MALI_C720_PARAMS_HISTOGRAM_MASK_SCALE_BOTTOM) &&
+ params->scale_bottom > MALI_C720_HISTOGRAM_SCALE_16X) {
+ dev_dbg(dev, "Invalid histogram bottom scale selection\n");
+ return -EINVAL;
+ }
+
+ if (mali_c720_params_updated(params, MALI_C720_PARAMS_HISTOGRAM_MASK_SCALE_TOP) &&
+ params->scale_top > MALI_C720_HISTOGRAM_SCALE_16X) {
+ dev_dbg(dev, "Invalid histogram top scale selection\n");
+ return -EINVAL;
+ }
+
+ if (mali_c720_params_updated(params, MALI_C720_PARAMS_HISTOGRAM_MASK_PLANE_MODE) &&
+ (params->plane_mode == 3 || params->plane_mode > MALI_C720_HISTOGRAM_FOCUS_11)) {
+ dev_dbg(dev, "Invalid histogram plane mode\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void mali_c720_params_histogram(struct mali_c720_context *ctx,
+ const struct mali_c720_param_target *target,
+ union mali_c720_params_block block, bool config)
+{
+ struct mali_c720 *mali_c720 = ctx->mali_c720;
+ const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
+ const struct mali_c720_stat_histogram_regs *stat_histogram =
+ mali_c720->registers.modules->stat_histogram;
+ struct mali_c720_params_histogram *params = block.histogram;
+ u32 weight_addr;
+
+ switch (block.header->type) {
+ case MALI_C720_PARAM_BLOCK_HISTOGRAM_INP:
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->histogram_0_mux_sel, block.header);
+ break;
+ case MALI_C720_PARAM_BLOCK_HISTOGRAM_HV:
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->histogram_1_mux_sel, block.header);
+ break;
+ case MALI_C720_PARAM_BLOCK_HISTOGRAM_HV_IRIDIX:
+ mali_c720_params_write_bypass(ctx, mali_c720->top_base,
+ &pipeline->histogram_2_mux_sel, block.header);
+ break;
+ default:
+ return;
+ }
+
+ if (!config || !params->updated_mask)
+ return;
+
+ if (block.header->type == MALI_C720_PARAM_BLOCK_HISTOGRAM_HV) {
+ mali_c720_ctx_group_write_updated(ctx, mali_c720->top_base,
+ &pipeline->histogram_1_stream_mux_sel,
+ params->stream_mux_select,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_STREAM_MUX_SEL);
+ }
+
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_histogram->nodes_used_horiz,
+ params->nodes_used_horiz,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_NODES_USED_HORIZ);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_histogram->nodes_used_vert,
+ params->nodes_used_vert,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_NODES_USED_VERT);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_histogram->skip_x,
+ params->skip_x,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_SKIP_X);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_histogram->skip_y,
+ params->skip_y,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_SKIP_Y);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_histogram->offset_x,
+ params->offset_x,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_OFFSET_X);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_histogram->offset_y,
+ params->offset_y,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_OFFSET_Y);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_histogram->scale_bottom,
+ params->scale_bottom,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_SCALE_BOTTOM);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_histogram->scale_top,
+ params->scale_top,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_SCALE_TOP);
+ mali_c720_ctx_group_write_updated(ctx, target->base,
+ &stat_histogram->plane_mode,
+ params->plane_mode,
+ MALI_C720_PARAMS_HISTOGRAM_MASK_PLANE_MODE);
+
+ weight_addr = mali_c720_reg_addr(target->base, &stat_histogram->weight);
+ mali_c720_lut_u8_write_updated(ctx, weight_addr,
+ params->weights,
+ ARRAY_SIZE(params->weights),
+ MALI_C720_PARAMS_HISTOGRAM_MASK_WEIGHTS);
+}
+
+static const mali_c720_params_handler mali_c720_params_handlers[] = {
+ [MALI_C720_PARAM_BLOCK_DIGITAL_GAIN_INP] = &mali_c720_params_input_digital_gain,
+ [MALI_C720_PARAM_BLOCK_AWB_GAINS_HV] = &mali_c720_params_awb_gains,
+ [MALI_C720_PARAM_BLOCK_BLACK_LEVEL_HV] = &mali_c720_params_black_level,
+ [MALI_C720_PARAM_BLOCK_SQRT_INP] = &mali_c720_params_sqrt_a,
+ [MALI_C720_PARAM_BLOCK_SQRT_HV] = &mali_c720_params_sqrt_b,
+ [MALI_C720_PARAM_BLOCK_SQUARE_A_HV] = &mali_c720_params_square_a,
+ [MALI_C720_PARAM_BLOCK_SQUARE_B_HV] = &mali_c720_params_square_b,
+ [MALI_C720_PARAM_BLOCK_DECOMPANDER_INP] = &mali_c720_params_decompander,
+ [MALI_C720_PARAM_BLOCK_COLOR_STATS_HV] = &mali_c720_params_color_stats,
+ [MALI_C720_PARAM_BLOCK_HISTOGRAM_INP] = &mali_c720_params_histogram,
+ [MALI_C720_PARAM_BLOCK_HISTOGRAM_HV] = &mali_c720_params_histogram,
+ [MALI_C720_PARAM_BLOCK_HISTOGRAM_HV_IRIDIX] = &mali_c720_params_histogram,
+};
+
+static const struct v4l2_isp_params_block_type_info
+mali_c720_params_block_types_info[MALI_C720_PARAM_BLOCK_MAX] = {
+ [MALI_C720_PARAM_BLOCK_DIGITAL_GAIN_INP] = {
+ .size = sizeof(struct mali_c720_params_digital_gain),
+ },
+ [MALI_C720_PARAM_BLOCK_AWB_GAINS_HV] = {
+ .size = sizeof(struct mali_c720_params_awb_gains),
+ },
+ [MALI_C720_PARAM_BLOCK_BLACK_LEVEL_HV] = {
+ .size = sizeof(struct mali_c720_params_black_level),
+ },
+ [MALI_C720_PARAM_BLOCK_SQRT_INP] = {
+ .size = sizeof(struct mali_c720_params_sqrt),
+ },
+ [MALI_C720_PARAM_BLOCK_SQRT_HV] = {
+ .size = sizeof(struct mali_c720_params_sqrt),
+ },
+ [MALI_C720_PARAM_BLOCK_SQUARE_A_HV] = {
+ .size = sizeof(struct mali_c720_params_square),
+ },
+ [MALI_C720_PARAM_BLOCK_SQUARE_B_HV] = {
+ .size = sizeof(struct mali_c720_params_square),
+ },
+ [MALI_C720_PARAM_BLOCK_DECOMPANDER_INP] = {
+ .size = sizeof(struct mali_c720_params_decompander),
+ .block_validate = mali_c720_params_validate_decompander,
+ },
+ [MALI_C720_PARAM_BLOCK_COLOR_STATS_HV] = {
+ .size = sizeof(struct mali_c720_params_color_stats),
+ .block_validate = mali_c720_params_validate_color_stats,
+ },
+ [MALI_C720_PARAM_BLOCK_HISTOGRAM_INP] = {
+ .size = sizeof(struct mali_c720_params_histogram),
+ .block_validate = mali_c720_params_validate_histogram,
+ },
+ [MALI_C720_PARAM_BLOCK_HISTOGRAM_HV] = {
+ .size = sizeof(struct mali_c720_params_histogram),
+ .block_validate = mali_c720_params_validate_histogram,
+ },
+ [MALI_C720_PARAM_BLOCK_HISTOGRAM_HV_IRIDIX] = {
+ .size = sizeof(struct mali_c720_params_histogram),
+ .block_validate = mali_c720_params_validate_histogram,
+ },
+};
+
+static_assert(ARRAY_SIZE(mali_c720_params_handlers) ==
+ ARRAY_SIZE(mali_c720_params_block_types_info));
+
+static int
+mali_c720_params_validate_block(struct mali_c720 *mali_c720,
+ union mali_c720_params_block block)
+{
+ const struct mali_c720_param_target *target;
+
+ target = mali_c720_params_get_target(&mali_c720->params, block.header->type);
+ if (!target) {
+ dev_dbg(mali_c720->dev,
+ "Parameters block targets unavailable module\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+void mali_c720_params_apply_config(struct mali_c720 *mali_c720,
+ struct mali_c720_params_buf *buf)
+{
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_params *params = &mali_c720->params;
+ struct v4l2_isp_params_buffer *buffer;
+ size_t block_offset = 0;
+ size_t max_offset;
+
+ buffer = buf->config;
+ max_offset = buffer->data_size;
+
+ /*
+ * Walk the list of parameter blocks and process them. No validation is
+ * done here, as the contents of the config buffer are already checked
+ * in .buf_prepare().
+ */
+ while (block_offset < max_offset) {
+ mali_c720_params_handler handler;
+ const struct mali_c720_param_target *target;
+ union mali_c720_params_block block = {
+ .data = &buffer->data[block_offset],
+ };
+ bool config = true;
+
+ target = mali_c720_params_get_target(params, block.header->type);
+
+ /* We checked the array index already in .buf_prepare() */
+ handler = mali_c720_params_handlers[block.header->type];
+ if (!target) {
+ dev_warn_once(mali_c720->dev,
+ "params target unexpectedly unavailable during write\n");
+ block_offset += block.header->size;
+ continue;
+ }
+
+ if ((block.header->flags & V4L2_ISP_PARAMS_FL_BLOCK_DISABLE) &&
+ block.header->size == sizeof(*block.header))
+ config = false;
+
+ handler(ctx, target, block, config);
+
+ block_offset += block.header->size;
+ }
+}
+
+static int mali_c720_params_enum_fmt_meta_out(struct file *file, void *fh,
+ struct v4l2_fmtdesc *f)
+{
+ if (f->index)
+ return -EINVAL;
+
+ if (f->mbus_code && f->mbus_code != MEDIA_BUS_FMT_METADATA_FIXED)
+ return -EINVAL;
+
+ f->pixelformat = V4L2_META_FMT_MALI_C720_PARAMS;
+
+ return 0;
+}
+
+static int mali_c720_params_g_fmt_meta_out(struct file *file, void *fh,
+ struct v4l2_format *f)
+{
+ static const struct v4l2_meta_format mfmt = {
+ .dataformat = V4L2_META_FMT_MALI_C720_PARAMS,
+ .buffersize = v4l2_isp_buffer_size(MALI_C720_PARAMS_MAX_SIZE),
+ };
+
+ f->fmt.meta = mfmt;
+
+ return 0;
+}
+
+static int mali_c720_params_querycap(struct file *file,
+ void *priv, struct v4l2_capability *cap)
+{
+ strscpy(cap->driver, MALI_C720_DRIVER_NAME, sizeof(cap->driver));
+ strscpy(cap->card, "ARM Mali-C720 ISP", sizeof(cap->card));
+
+ return 0;
+}
+
+static const struct v4l2_ioctl_ops mali_c720_params_v4l2_ioctl_ops = {
+ .vidioc_reqbufs = vb2_ioctl_reqbufs,
+ .vidioc_querybuf = vb2_ioctl_querybuf,
+ .vidioc_create_bufs = vb2_ioctl_create_bufs,
+ .vidioc_qbuf = vb2_ioctl_qbuf,
+ .vidioc_expbuf = vb2_ioctl_expbuf,
+ .vidioc_dqbuf = vb2_ioctl_dqbuf,
+ .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+ .vidioc_streamon = mali_c720_streamon,
+ .vidioc_streamoff = vb2_ioctl_streamoff,
+ .vidioc_enum_fmt_meta_out = mali_c720_params_enum_fmt_meta_out,
+ .vidioc_g_fmt_meta_out = mali_c720_params_g_fmt_meta_out,
+ .vidioc_s_fmt_meta_out = mali_c720_params_g_fmt_meta_out,
+ .vidioc_try_fmt_meta_out = mali_c720_params_g_fmt_meta_out,
+ .vidioc_querycap = mali_c720_params_querycap,
+ .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
+ .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+};
+
+static const struct v4l2_file_operations mali_c720_params_v4l2_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = video_ioctl2,
+ .open = v4l2_fh_open,
+ .release = vb2_fop_release,
+ .poll = vb2_fop_poll,
+ .mmap = vb2_fop_mmap,
+};
+
+static int
+mali_c720_params_queue_setup(struct vb2_queue *q, unsigned int *num_buffers,
+ unsigned int *num_planes, unsigned int sizes[],
+ struct device *alloc_devs[])
+{
+ if (*num_planes && *num_planes > 1)
+ return -EINVAL;
+
+ if (sizes[0] && sizes[0] <
+ v4l2_isp_buffer_size(MALI_C720_PARAMS_MAX_SIZE))
+ return -EINVAL;
+
+ *num_planes = 1;
+
+ if (!sizes[0])
+ sizes[0] = v4l2_isp_buffer_size(MALI_C720_PARAMS_MAX_SIZE);
+
+ return 0;
+}
+
+static int mali_c720_params_buf_init(struct vb2_buffer *vb)
+{
+ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+ struct mali_c720_params_buf *buf = to_mali_c720_params_buf(vbuf);
+
+ buf->config = kvmalloc(v4l2_isp_buffer_size(MALI_C720_PARAMS_MAX_SIZE),
+ GFP_KERNEL);
+ if (!buf->config)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static void mali_c720_params_buf_cleanup(struct vb2_buffer *vb)
+{
+ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+ struct mali_c720_params_buf *buf = to_mali_c720_params_buf(vbuf);
+
+ kvfree(buf->config);
+ buf->config = NULL;
+}
+
+static int mali_c720_params_buf_prepare(struct vb2_buffer *vb)
+{
+ struct mali_c720_params *params = vb2_get_drv_priv(vb->vb2_queue);
+ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+ struct mali_c720_params_buf *buf = to_mali_c720_params_buf(vbuf);
+ struct mali_c720 *mali_c720 = params->mali_c720;
+ struct v4l2_isp_params_buffer *config = vb2_plane_vaddr(vb, 0);
+ struct dma_buf *dbuf = vb->planes[0].dbuf;
+ size_t block_offset = 0;
+ int ret;
+
+ ret = v4l2_isp_params_validate_buffer_size(mali_c720->dev,
+ vb,
+ v4l2_isp_buffer_size
+ (MALI_C720_PARAMS_MAX_SIZE));
+ if (ret)
+ return ret;
+
+ if (dbuf) {
+ ret = dma_buf_begin_cpu_access(dbuf, DMA_FROM_DEVICE);
+ if (ret)
+ return ret;
+ }
+
+ /*
+ * Copy the parameters buffer provided by userspace to the internal
+ * scratch buffer. This protects against the chance of userspace making
+ * changes to the buffer content whilst the driver processes it.
+ */
+ memcpy(buf->config, config,
+ v4l2_isp_buffer_size(MALI_C720_PARAMS_MAX_SIZE));
+
+ if (dbuf) {
+ ret = dma_buf_end_cpu_access(dbuf, DMA_FROM_DEVICE);
+ if (ret)
+ return ret;
+ }
+
+ ret = v4l2_isp_params_validate_buffer(mali_c720->dev, vb, buf->config,
+ mali_c720_params_block_types_info,
+ ARRAY_SIZE(mali_c720_params_block_types_info));
+ if (ret)
+ return ret;
+
+ while (block_offset < buf->config->data_size) {
+ union mali_c720_params_block block = {
+ .data = &buf->config->data[block_offset],
+ };
+
+ ret = mali_c720_params_validate_block(mali_c720, block);
+ if (ret)
+ return ret;
+
+ block_offset += block.header->size;
+ }
+
+ return 0;
+}
+
+static void mali_c720_params_buf_queue(struct vb2_buffer *vb)
+{
+ struct mali_c720_params *params = vb2_get_drv_priv(vb->vb2_queue);
+ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+ struct mali_c720_params_buf *buf = to_mali_c720_params_buf(vbuf);
+ struct mali_c720 *mali_c720 = params->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+
+ scoped_guard(spinlock, ¶ms->buffers.lock)
+ list_add_tail(&buf->queue, ¶ms->buffers.input);
+
+ if (!mali_c720_params_uses_requests(params))
+ mali_c720_try_schedule_frame(ctx);
+}
+
+static void mali_c720_buf_request_complete(struct vb2_buffer *vb)
+{
+}
+
+bool mali_c720_params_uses_requests(struct mali_c720_params *params)
+{
+ return video_is_registered(¶ms->vdev) &&
+ vb2_is_streaming(¶ms->queue) &&
+ params->queue.uses_requests;
+}
+
+struct media_request *mali_c720_params_get_request(struct mali_c720_params *params)
+{
+ struct mali_c720_params_buf *buf;
+
+ if (!mali_c720_params_uses_requests(params))
+ return NULL;
+
+ guard(spinlock)(¶ms->buffers.lock);
+
+ buf = list_first_entry_or_null(¶ms->buffers.input,
+ struct mali_c720_params_buf, queue);
+
+ return buf ? buf->vb.vb2_buf.request : NULL;
+}
+
+struct mali_c720_params_buf *
+mali_c720_params_get_next_buffer(struct mali_c720_params *params,
+ struct media_request *req)
+{
+ struct mali_c720_params_buf *buf;
+
+ if (!video_is_registered(¶ms->vdev))
+ return NULL;
+
+ if (!vb2_is_streaming(¶ms->queue))
+ return NULL;
+
+ scoped_guard(spinlock, ¶ms->buffers.lock) {
+ buf = list_first_entry_or_null(¶ms->buffers.input,
+ struct mali_c720_params_buf, queue);
+ if (!buf || (buf->vb.vb2_buf.request &&
+ buf->vb.vb2_buf.request != req))
+ return NULL;
+
+ list_move_tail(&buf->queue, ¶ms->buffers.processing);
+ }
+
+ return buf;
+}
+
+void mali_c720_params_buffer_done(struct mali_c720_params *params, bool success)
+{
+ struct mali_c720 *mali_c720 = params->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_params_buf *buf;
+
+ if (!video_is_registered(¶ms->vdev))
+ return;
+
+ if (!vb2_is_streaming(¶ms->queue))
+ return;
+
+ scoped_guard(spinlock, ¶ms->buffers.lock) {
+ buf = list_first_entry_or_null(¶ms->buffers.processing,
+ struct mali_c720_params_buf, queue);
+ if (!buf)
+ return;
+
+ if (success) {
+ buf->vb.vb2_buf.timestamp = ctx->timestamp;
+ buf->vb.sequence = ctx->frame_sequence;
+ }
+
+ vb2_buffer_done(&buf->vb.vb2_buf,
+ success ? VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR);
+ list_del(&buf->queue);
+ }
+}
+
+static void mali_c720_params_return_buffers(struct mali_c720_params *params,
+ enum vb2_buffer_state state)
+{
+ struct mali_c720_params_buf *buf, *tmp;
+
+ guard(spinlock) (¶ms->buffers.lock);
+
+ list_for_each_entry_safe(buf, tmp, ¶ms->buffers.input, queue) {
+ list_del(&buf->queue);
+ vb2_buffer_done(&buf->vb.vb2_buf, state);
+ }
+
+ list_for_each_entry_safe(buf, tmp, ¶ms->buffers.processing, queue) {
+ list_del(&buf->queue);
+ vb2_buffer_done(&buf->vb.vb2_buf, state);
+ }
+}
+
+static int mali_c720_params_start_streaming(struct vb2_queue *q,
+ unsigned int count)
+{
+ struct mali_c720_params *params = vb2_get_drv_priv(q);
+ struct mali_c720 *mali_c720 = params->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct v4l2_subdev *isp_sd = &mali_c720->isp.mdev.sd;
+ int ret;
+
+ guard(mutex)(&mali_c720->device_lock);
+
+ if (!media_devnode_is_registered(mali_c720->media_dev.devnode)) {
+ ret = -ENODEV;
+ goto err_return_buffers;
+ }
+
+ ret = pm_runtime_resume_and_get(mali_c720->dev);
+ if (ret)
+ goto err_return_buffers;
+
+ ret = video_device_pipeline_start(¶ms->vdev, &mali_c720->pipe);
+ if (ret)
+ goto err_pm_put;
+
+ ret = mali_c720_alloc_context(ctx);
+ if (ret)
+ goto err_stop_video_pipeline;
+
+ ret = mali_c720_pipeline_ready(mali_c720);
+ if (ret && ret != -EAGAIN)
+ goto err_free_context;
+
+ if (!ret) {
+ ret = v4l2_subdev_enable_streams(isp_sd,
+ MALI_C720_ISP_PAD_SOURCE_HV,
+ BIT(0));
+ if (ret)
+ goto err_free_context;
+ }
+
+ return 0;
+
+err_free_context:
+ mali_c720_free_context(ctx);
+err_stop_video_pipeline:
+ video_device_pipeline_stop(¶ms->vdev);
+err_pm_put:
+ pm_runtime_put(mali_c720->dev);
+err_return_buffers:
+ mali_c720_params_return_buffers(params, VB2_BUF_STATE_QUEUED);
+
+ return ret;
+}
+
+static void mali_c720_params_stop_streaming(struct vb2_queue *q)
+{
+ struct mali_c720_params *params = vb2_get_drv_priv(q);
+ struct mali_c720 *mali_c720 = params->mali_c720;
+ struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
+ struct mali_c720_isp *isp = &mali_c720->isp;
+ struct v4l2_subdev *isp_sd = &isp->mdev.sd;
+
+ guard(mutex)(&mali_c720->device_lock);
+
+ v4l2_subdev_disable_streams(isp_sd, MALI_C720_ISP_PAD_SOURCE_HV,
+ BIT(0));
+ mali_c720_free_context(ctx);
+
+ video_device_pipeline_stop(¶ms->vdev);
+ mali_c720_params_return_buffers(params, VB2_BUF_STATE_ERROR);
+
+ pm_runtime_put_autosuspend(mali_c720->dev);
+}
+
+static const struct vb2_ops mali_c720_params_vb2_ops = {
+ .queue_setup = mali_c720_params_queue_setup,
+ .buf_init = mali_c720_params_buf_init,
+ .buf_cleanup = mali_c720_params_buf_cleanup,
+ .buf_prepare = mali_c720_params_buf_prepare,
+ .buf_queue = mali_c720_params_buf_queue,
+ .buf_request_complete = mali_c720_buf_request_complete,
+ .start_streaming = mali_c720_params_start_streaming,
+ .stop_streaming = mali_c720_params_stop_streaming,
+};
+
+void mali_c720_unregister_params(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_params *params = &mali_c720->params;
+
+ if (!video_is_registered(¶ms->vdev))
+ return;
+
+ vb2_video_unregister_device(¶ms->vdev);
+}
+
+void mali_c720_cleanup_params(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_params *params = &mali_c720->params;
+
+ if (!params->mali_c720)
+ return;
+
+ v4l2_ctrl_handler_free(¶ms->ctrls.handler);
+ media_entity_cleanup(¶ms->vdev.entity);
+ mutex_destroy(¶ms->lock);
+ params->mali_c720 = NULL;
+}
+
+int mali_c720_register_params(struct mali_c720 *mali_c720)
+{
+ struct mali_c720_params *params = &mali_c720->params;
+ struct video_device *vdev = ¶ms->vdev;
+ struct vb2_queue *vb2q = ¶ms->queue;
+ u32 dims[V4L2_CTRL_MAX_DIMS] = { 0 };
+ int ret;
+
+ params->mali_c720 = mali_c720;
+ mutex_init(¶ms->lock);
+ ret = mali_c720_params_build_target_cache(mali_c720);
+ if (ret) {
+ dev_err(mali_c720->dev,
+ "failed to build params target cache\n");
+ goto err_destroy_mutex;
+ }
+
+ INIT_LIST_HEAD(¶ms->buffers.input);
+ INIT_LIST_HEAD(¶ms->buffers.processing);
+ spin_lock_init(¶ms->buffers.lock);
+
+ ret = v4l2_ctrl_handler_init(¶ms->ctrls.handler, 1);
+ if (ret)
+ goto err_destroy_mutex;
+
+ params->ctrls.param_capabilities =
+ v4l2_ctrl_new_custom(¶ms->ctrls.handler,
+ &mali_c720_params_caps_ctrl, NULL);
+ if (params->ctrls.param_capabilities) {
+ dims[0] = params->num_targets;
+ ret = v4l2_ctrl_modify_dimensions(params->ctrls.param_capabilities,
+ dims);
+ if (ret)
+ goto err_free_ctrl_handler;
+ }
+
+ if (params->ctrls.handler.error) {
+ ret = params->ctrls.handler.error;
+ goto err_free_ctrl_handler;
+ }
+
+ params->pad.flags = MEDIA_PAD_FL_SOURCE | MEDIA_PAD_FL_MUST_CONNECT;
+ ret = media_entity_pads_init(¶ms->vdev.entity, 1, ¶ms->pad);
+ if (ret)
+ goto err_free_ctrl_handler;
+
+ vb2q->type = V4L2_BUF_TYPE_META_OUTPUT;
+ vb2q->io_modes = VB2_MMAP | VB2_DMABUF;
+ vb2q->drv_priv = params;
+ vb2q->mem_ops = &vb2_vmalloc_memops;
+ vb2q->ops = &mali_c720_params_vb2_ops;
+ vb2q->buf_struct_size = sizeof(struct mali_c720_params_buf);
+ vb2q->min_queued_buffers = 0;
+ vb2q->supports_requests = 1;
+ vb2q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+ vb2q->lock = ¶ms->lock;
+ vb2q->dev = mali_c720->dev;
+
+ ret = vb2_queue_init(vb2q);
+ if (ret) {
+ dev_err(mali_c720->dev, "params vb2 queue init failed\n");
+ goto err_cleanup_entity;
+ }
+
+ strscpy(params->vdev.name, "mali-c720 3a params",
+ sizeof(params->vdev.name));
+ vdev->release = video_device_release_empty;
+ vdev->fops = &mali_c720_params_v4l2_fops;
+ vdev->ioctl_ops = &mali_c720_params_v4l2_ioctl_ops;
+ vdev->lock = ¶ms->lock;
+ vdev->v4l2_dev = &mali_c720->v4l2_dev;
+ vdev->queue = ¶ms->queue;
+ vdev->ctrl_handler = ¶ms->ctrls.handler;
+ vdev->device_caps = V4L2_CAP_META_OUTPUT |
+ V4L2_CAP_STREAMING |
+ V4L2_CAP_IO_MC;
+ vdev->vfl_dir = VFL_DIR_TX;
+ video_set_drvdata(vdev, params);
+
+ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
+ if (ret) {
+ dev_err(mali_c720->dev,
+ "failed to register params video device\n");
+ goto err_release_vb2q;
+ }
+
+ return 0;
+
+err_release_vb2q:
+ vb2_queue_release(vb2q);
+err_cleanup_entity:
+ media_entity_cleanup(¶ms->vdev.entity);
+err_free_ctrl_handler:
+ v4l2_ctrl_handler_free(¶ms->ctrls.handler);
+err_destroy_mutex:
+ mutex_destroy(¶ms->lock);
+ params->mali_c720 = NULL;
+
+ return ret;
+}
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 23/24] media: Documentation: Document Mali-C720 parameter settings
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (21 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 22/24] media: mali-c720: Add parameters video node Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
2026-11-24 17:07 ` [PATCH 24/24] MAINTAINERS: Add entry for mali-c720 driver Anthony McGivern
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Document ISP parameter configuration and querying supported parameter
blocks through the capability control. Describe the parameter buffer
layout and provide an example of populating the configuration blocks.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
.../admin-guide/media/mali-c720-graph.dot | 4 +-
Documentation/admin-guide/media/mali-c720.rst | 46 ++++++++++---
.../userspace-api/media/drivers/mali-c720.rst | 14 ++--
.../media/v4l/metafmt-arm-mali-c720.rst | 78 +++++++++++++++++++++-
4 files changed, 125 insertions(+), 17 deletions(-)
diff --git a/Documentation/admin-guide/media/mali-c720-graph.dot b/Documentation/admin-guide/media/mali-c720-graph.dot
index c3594c525370734cca4acfb6e1bf03834b611029..92e98e405c440a136f98c230b8e1fa76fb2d6e06 100644
--- a/Documentation/admin-guide/media/mali-c720-graph.dot
+++ b/Documentation/admin-guide/media/mali-c720-graph.dot
@@ -6,7 +6,7 @@ digraph board {
n00000003:port0 -> n00000009:port1 [style=dashed]
n00000009 [label="{{<port1> 1} | mali-c720 input\n/dev/v4l-subdev2 | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green]
n00000009:port0 -> n0000000c:port0
- n0000000c [label="{{<port0> 0} | mali-c720 isp\n/dev/v4l-subdev3 | {<port1> 1 | <port2> 2}}", shape=Mrecord, style=filled, fillcolor=green]
+ n0000000c [label="{{<port0> 0 | <port3> 3} | mali-c720 isp\n/dev/v4l-subdev3 | {<port1> 1 | <port2> 2}}", shape=Mrecord, style=filled, fillcolor=green]
n0000000c:port1 -> n00000014:port0
n0000000c:port2 -> n0000006c [style=dashed]
n00000014 [label="{{<port0> 0} | mali-c720 hv pipe\n/dev/v4l-subdev4 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
@@ -17,6 +17,8 @@ digraph board {
n00000038 [label="mali-c720 fr0-rgb\n/dev/video0", shape=box, style=filled, fillcolor=yellow]
n0000003c [label="mali-c720 fr0-yuv\n/dev/video1", shape=box, style=filled, fillcolor=yellow]
n0000006c [label="mali-c720 3a stats\n/dev/video2", shape=box, style=filled, fillcolor=yellow]
+ n00000070 [label="mali-c720 3a params\n/dev/video3", shape=box, style=filled, fillcolor=yellow]
+ n00000070 -> n0000000c:port3 [style=dashed]
n00000074 [label="{{<port0> 0} | csi2-rx\n/dev/v4l-subdev6 | {<port1> 1}}", shape=Mrecord, style=filled, fillcolor=green]
n00000074:port1 -> n00000009:port1
n00000079 [label="{{} | imx415 1-001a\n/dev/v4l-subdev7 | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green]
diff --git a/Documentation/admin-guide/media/mali-c720.rst b/Documentation/admin-guide/media/mali-c720.rst
index 06b97e11ee380df55d13b11706527687bb3c74e6..0008577a23af392bcf40661f417238be3df55b43 100644
--- a/Documentation/admin-guide/media/mali-c720.rst
+++ b/Documentation/admin-guide/media/mali-c720.rst
@@ -126,10 +126,11 @@ The driver has up to six V4L2 subdevices:
- ``mali-c720 hv pipe``: Human vision pipeline.
- ``mali-c720 fr 0 pipe``: Full-resolution crop/scale pipeline.
-The driver has three V4L2 video devices:
+The driver has four V4L2 video devices:
- ``mali-c720 fr0-rgb`` and ``mali-c720 fr0-yuv``: FR capture devices.
- ``mali-c720 3a stats``: 3A statistics capture device.
+- ``mali-c720 3a params``: 3A parameters output device.
Input formats
-------------
@@ -348,6 +349,32 @@ their respective pipelines are present. We expose a V4L2 control
:ref:`V4L2_CID_MALI_C720_STATS_CAPABILITIES <mali-c720-controls>` which allows
the userspace to query the statistics produced by the ISP.
+.. _mali-c720-3a-params:
+
+Programming ISP Parameters
+==========================
+
+The ISP can be programmed with various parameters from userspace to apply to
+the hardware before and during video streaming. This allows userspace to
+dynamically change values such as black level, white balance, digital gain
+and so on.
+
+Enable the parameters link before starting capture:
+
+.. code-block:: none
+
+ media-ctl -l "'mali-c720 3a params':0->'mali-c720 isp':3[1]"
+
+The buffer format and how to populate it are described by the
+:ref:`V4L2_META_FMT_MALI_C720_PARAMS <v4l2-meta-fmt-mali-c720-params>` format,
+which should be set as the data format for the `mali-c720 3a params` video node.
+
+Similar to statistics, our configurable hardware means that the modules present
+in the ISP can vary depending on its configuration. As such, we expose a V4L2
+control :ref:`V4L2_CID_MALI_C720_PARAM_CAPABILITIES <mali-c720-controls>`
+which allows the userspace to query the supported parameter blocks. The
+parameter buffer will be invalidated if any provided blocks are not present.
+
.. _mali-c720-frame-scheduling:
Frame scheduling and Media Requests
@@ -359,13 +386,14 @@ direct buffer queuing or Media Requests. Use of Media Requests is optional.
Direct mode
-----------
-When all streaming statistics and image capture queues use direct buffer
-queuing through :ref:`VIDIOC_QBUF`, the driver schedules frames in
+When all streaming parameter, statistics and image capture queues use direct
+buffer queuing through :ref:`VIDIOC_QBUF`, the driver schedules frames in
free-running mode. Scheduling starts only when at least one image or
statistics output buffer is ready. Once started, it continues scheduling
-frames using the available buffers.
+frames using the available buffers and the latest applied parameters.
Empty statistics or image capture queues disable their respective capture
-for the scheduled frame.
+for the scheduled frame, and an empty parameters queue leaves the ISP
+configuration unchanged.
Request mode
------------
@@ -376,7 +404,7 @@ request.
Applications allocate a request using :ref:`MEDIA_IOC_REQUEST_ALLOC` on the
media device.
-Statistics and image buffers are associated with it through
+Parameter, statistics and image buffers are associated with it through
:ref:`VIDIOC_QBUF`, setting ``V4L2_BUF_FLAG_REQUEST_FD`` and ``request_fd``.
The request is then submitted using :ref:`MEDIA_REQUEST_IOC_QUEUE` on the
request file descriptor.
@@ -389,9 +417,9 @@ Queues without a buffer will be disabled for the scheduled frame.
All buffers associated with the request are usually applied on the same
frame, but a request could span multiple frames if multiple buffers are
-queued for the same buffer queue.
-The statistics and image buffers are filled with the results from that
-frame. Completed buffers are returned to userspace through
+queued for the same buffer queue. The parameters are applied before
+processing, and the statistics and image buffers are filled with the results
+from that frame. Completed buffers are returned to userspace through
:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`.
It is permitted to queue buffers directly in other VB2 queues alongside
diff --git a/Documentation/userspace-api/media/drivers/mali-c720.rst b/Documentation/userspace-api/media/drivers/mali-c720.rst
index 306112582cd62b5c7131d8e7d8bab7ecae9f2eee..9aa3107cbb67ad3e92f5a8452bfddd663ad60d5c 100644
--- a/Documentation/userspace-api/media/drivers/mali-c720.rst
+++ b/Documentation/userspace-api/media/drivers/mali-c720.rst
@@ -5,15 +5,19 @@
Arm Mali-C720 ISP driver
========================
-The Arm Mali-C720 ISP driver implements the following driver-specific control:
+The Arm Mali-C720 ISP driver implements two driver-specific controls:
+
+``V4L2_CID_MALI_C720_PARAM_CAPABILITIES (__u16 array)``
+ Lists the parameter block types accepted by the ISP. Each element is a
+ value from :c:type:`mali_c720_param_block_type`.
``V4L2_CID_MALI_C720_STATS_CAPABILITIES (__u16 array)``
Lists the statistics block types supported by the ISP. Each element is a
value from :c:type:`mali_c720_stats_type`.
-The Mali-C720 ISP can be configured to include or exclude statistics blocks.
-This control allows the driver to communicate to userspace which statistics
-block types are supported by the driver and present in the hardware.
+The Mali-C720 ISP can be configured to include or exclude processing and
+statistics blocks. These controls allow the driver to communicate to userspace
+which block types are supported by the driver and present in the hardware.
Format enumeration
------------------
@@ -31,6 +35,8 @@ Buffer alignment
Image capture buffers require DMA base addresses aligned to 32 bytes.
Statistics capture buffers require DMA base addresses aligned to 16 bytes.
+Parameter buffers have no additional hardware DMA address alignment
+requirement.
Buffers allocated by the driver using MMAP satisfy these requirements
automatically. Imported DMA-BUFs must provide suitable alignment.
diff --git a/Documentation/userspace-api/media/v4l/metafmt-arm-mali-c720.rst b/Documentation/userspace-api/media/v4l/metafmt-arm-mali-c720.rst
index 1d19183cc07a81dfc95682c701a5bfc5f953a93a..0c2a427da23a7be23ca87f6b8f3d9a76d2e746af 100644
--- a/Documentation/userspace-api/media/v4l/metafmt-arm-mali-c720.rst
+++ b/Documentation/userspace-api/media/v4l/metafmt-arm-mali-c720.rst
@@ -1,13 +1,15 @@
.. SPDX-License-Identifier: GPL-2.0
+.. _v4l2-meta-fmt-mali-c720-params:
.. _v4l2-meta-fmt-mali-c720-stats:
*******************************************************************************
-V4L2_META_FMT_MALI_C720_STATS ('C72S')
+V4L2_META_FMT_MALI_C720_STATS ('C72S'), V4L2_META_FMT_MALI_C720_PARAMS ('C72P')
*******************************************************************************
-For details on queueing statistics buffers and synchronizing them with
-image buffers using Media Requests, see :ref:`mali-c720-frame-scheduling`.
+For details on queueing statistics and parameter buffers and synchronizing
+them with image buffers using Media Requests, see
+:ref:`mali-c720-frame-scheduling`.
3A Statistics
=============
@@ -34,6 +36,76 @@ capability control
For details of the statistics, see the statistics blocks defined in
``mali-c720-config.h``.
+Configuration Parameters
+========================
+
+The configuration parameters are passed to the :ref:`mali-c720 3a params
+<mali-c720-3a-params>` metadata output video node, using the
+:c:type:`v4l2_meta_format` interface. Parameters for the Mali-C720 use the
+:ref:`generic V4L2 ISP format <v4l2-isp>`, through which groups of parameters
+are defined as distinct structures or blocks in the ``data`` member of
+:c:type:`v4l2_isp_buffer`. Userspace is responsible for populating the data
+member with the blocks that need to be configured by the driver. It is also
+responsible for clearing the parameter buffer before writing new parameters.
+Each block-specific structure embeds :c:type:`v4l2_isp_block_header` as its
+first member and userspace must populate the ``type`` member with a value from
+:c:type:`mali_c720_param_block_type`, provided that type is supported based
+on querying the parameters capability control
+:ref:`V4L2_CID_MALI_C720_PARAM_CAPABILITIES <mali-c720-controls>`.
+
+Each block-specific structure embeds an ``updated_mask``. The corresponding
+``mali_c720_params_*_mask`` enum defines bit positions: set ``1ULL << value``
+for each field or group of fields to update. Other fields retain their previous
+configuration.
+
+.. code-block:: c
+
+ struct v4l2_isp_buffer *params =
+ (struct v4l2_isp_buffer *)buffer;
+
+ memset(buffer, 0, buffer_size);
+
+ params->version = V4L2_ISP_VERSION_V1;
+ params->data_size = 0;
+
+ void *data = (void *)params->data;
+
+ struct mali_c720_params_awb_gains *gains =
+ (struct mali_c720_params_awb_gains *)data;
+
+ gains->header.type = MALI_C720_PARAM_BLOCK_AWB_GAINS_HV;
+ gains->header.flags |= V4L2_ISP_PARAMS_FL_BLOCK_ENABLE;
+ gains->header.size = sizeof(struct mali_c720_params_awb_gains);
+
+ gains->gain00 = 256;
+ gains->gain01 = 256;
+ gains->gain10 = 256;
+ gains->gain11 = 256;
+
+ gains->updated_mask =
+ (1ULL << MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN00) |
+ (1ULL << MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN01) |
+ (1ULL << MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN10) |
+ (1ULL << MALI_C720_PARAMS_AWB_GAINS_MASK_GAIN11);
+
+ data += sizeof(struct mali_c720_params_awb_gains);
+ params->data_size += sizeof(struct mali_c720_params_awb_gains);
+
+ struct mali_c720_params_digital_gain *gain =
+ (struct mali_c720_params_digital_gain *)data;
+
+ gain->header.type = MALI_C720_PARAM_BLOCK_DIGITAL_GAIN_INP;
+ gain->header.flags |= V4L2_ISP_PARAMS_FL_BLOCK_ENABLE;
+ gain->header.size = sizeof(struct mali_c720_params_digital_gain);
+
+ gain->gain = 512; // 2x gain
+ gain->offset = 51200; // Black level offset
+ gain->updated_mask =
+ (1ULL << MALI_C720_PARAMS_DIGITAL_GAIN_MASK_GAIN) |
+ (1ULL << MALI_C720_PARAMS_DIGITAL_GAIN_MASK_OFFSET);
+
+ params->data_size += sizeof(struct mali_c720_params_digital_gain);
+
Arm Mali-C720 uAPI data types
=============================
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 24/24] MAINTAINERS: Add entry for mali-c720 driver
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
` (22 preceding siblings ...)
2026-11-24 17:07 ` [PATCH 23/24] media: Documentation: Document Mali-C720 parameter settings Anthony McGivern
@ 2026-11-24 17:07 ` Anthony McGivern
23 siblings, 0 replies; 28+ messages in thread
From: Anthony McGivern @ 2026-11-24 17:07 UTC (permalink / raw)
To: linux-media, devicetree, linux-kernel, linux-arm-kernel
Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
Konstantin Babin, Linus Walleij, jacopo.mondi, kieran.bingham,
laurent.pinchart, dan.scally, Sakari Ailus, Rob Herring,
Mauro Carvalho Chehab, Hans Verkuil, Krzysztof Kozlowski,
Conor Dooley, Anthony McGivern
From: Anthony McGivern <Anthony.McGivern@arm.com>
Add a MAINTAINERS entry for the mali-c720 driver and its associated
documentation.
Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
MAINTAINERS | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 44540a1eb2b8088f9da95a9b6f83b4bf05188ee1..1bf854fb64fb7fcfef50d956350df05da3b2df75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2392,6 +2392,19 @@ F: Documentation/userspace-api/media/v4l/metafmt-arm-mali-c55.rst
F: drivers/media/platform/arm/mali-c55/
F: include/uapi/linux/media/arm/mali-c55-config.h
+ARM MALI-C720 ISP DRIVER
+M: Anthony McGivern <anthony.mcgivern@arm.com>
+M: Vincenzo Frascino <vincenzo.frascino@arm.com>
+L: linux-media@vger.kernel.org
+S: Maintained
+F: Documentation/admin-guide/media/mali-c720-graph.dot
+F: Documentation/admin-guide/media/mali-c720.rst
+F: Documentation/devicetree/bindings/media/arm,mali-c720.yaml
+F: Documentation/userspace-api/media/drivers/mali-c720.rst
+F: Documentation/userspace-api/media/v4l/metafmt-arm-mali-c720.rst
+F: drivers/media/platform/arm/mali-c720/
+F: include/uapi/linux/media/arm/mali-c720-config.h
+
ARM MALI PANTHOR DRM DRIVER
M: Boris Brezillon <boris.brezillon@collabora.com>
M: Steven Price <steven.price@arm.com>
--
2.55.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 02/24] dt-bindings: media: Add bindings for Arm Mali-C720
2026-11-24 17:07 ` [PATCH 02/24] dt-bindings: media: Add bindings for Arm Mali-C720 Anthony McGivern
@ 2026-11-24 17:18 ` sashiko-bot
0 siblings, 0 replies; 28+ messages in thread
From: sashiko-bot @ 2026-11-24 17:18 UTC (permalink / raw)
To: Anthony McGivern, devicetree; +Cc: robh, conor+dt, media-ci
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] dt-bindings: media: redundant bindings word in commit subject
- [Low] dt-bindings: media: non-canonical property ordering in
arm,mali-c720.yaml
- [Low] dt-bindings: media: DTS example style violations in
arm,mali-c720.yaml
--
commit 57de6a2d5cbf4773def077645c097e562455ec9a
Author: Anthony McGivern <Anthony.McGivern@arm.com>
dt-bindings: media: Add bindings for Arm Mali-C720
This commit adds the Device Tree binding schema for the Arm Mali-C720 Image
Signal Processor.
> dt-bindings: media: Add bindings for Arm Mali-C720
[Severity: Low]
The "dt-bindings:" prefix already indicates that this adds a binding, so
"bindings for" is redundant and the subject can be "dt-bindings: media: Add
Arm Mali-C720".
> diff --git a/Documentation/devicetree/bindings/media/arm,mali-c720.yaml b/Documentation/devicetree/bindings/media/arm,mali-c720.yaml
> new file mode 100644
> index 0000000000000..3bd261bcefbe3
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/media/arm,mali-c720.yaml
> @@ -0,0 +1,134 @@
[ ... ]
> +properties:
> + compatible:
> + const: arm,mali-c720
> +
> + reg:
> + maxItems: 1
> +
> + interrupts:
> + minItems: 1
> + items:
> + - description: ISP main interrupt
> + - description: ISP fault interrupt
> +
> + interrupt-names:
> + minItems: 1
> + items:
> + - const: isp
> + - const: fault
> +
> + iommus:
> + minItems: 1
> + maxItems: 3
> +
> + clocks:
> + items:
> + - description: ISP main processing clock
> +
> + clock-names:
> + items:
> + - const: vclk
[ ... ]
> +required:
> + - compatible
> + - reg
> + - interrupts
> + - interrupt-names
> + - clocks
> + - clock-names
> + - resets
> + - reset-names
[Severity: Low]
Could the properties in "properties:" and "required:" be ordered to follow
the canonical DT schema sequence, placing clocks and clock-names before
interrupts and interrupt-names? The example node below already lists
clocks and clock-names before interrupts and interrupt-names, so aligning
"properties:" and "required:" with that order would also keep all three
sections consistent.
> +
> +additionalProperties: false
> +
> +examples:
> + - |
> + mali_c720: isp@400000 {
> + compatible = "arm,mali-c720";
> + reg = <0x400000 0x200000>;
> + clocks = <&clk 0>;
> + clock-names = "vclk";
> + resets = <&resets 0>;
> + reset-names = "reset";
> + memory-region = <&isp_reserved>;
> + interrupts = <0>;
> + interrupt-names = "isp";
> + power-domains = <&power 0>;
> +
> + ports {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + port@0 {
> + reg = <0>;
> + isp_in: endpoint {
> + remote-endpoint = <&csi2_rx_out>;
> + };
> + };
> + };
> + };
[Severity: Low]
The example node causes scripts/dtc/dt-check-style --mode=strict to report
warnings: it uses 2-space indentation instead of 4-space indentation,
defines the unused labels mali_c720 and isp_in, and omits a blank line
between "reg = <0>;" and the endpoint child node inside port@0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-b4-initial-upstream-candidate-v1-0-0cb9bde1bd30@arm.com?part=2
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 15/24] media: Documentation: Add Mali-C720 ISP documentation
2026-11-24 17:07 ` [PATCH 15/24] media: Documentation: Add Mali-C720 ISP documentation Anthony McGivern
@ 2026-11-24 17:20 ` sashiko-bot
0 siblings, 0 replies; 28+ messages in thread
From: sashiko-bot @ 2026-11-24 17:20 UTC (permalink / raw)
To: Anthony McGivern, devicetree; +Cc: robh, conor+dt, media-ci
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] media: Documentation: short title underline in mali-c720.rst
- [Low] media: Documentation: unreferenced footnote [3] in mali-c720.rst
--
commit c4c33a88cca59317f92c1365b5db2c5c6579612d
Author: Anthony McGivern <Anthony.McGivern@arm.com>
media: Documentation: Add Mali-C720 ISP documentation
This commit adds admin-guide documentation and a media graph topology
diagram for the Arm Mali-C720 ISP driver.
> diff --git a/Documentation/admin-guide/media/mali-c720.rst b/Documentation/admin-guide/media/mali-c720.rst
> new file mode 100644
> index 0000000000000..3ff2cb3170f25
> --- /dev/null
> +++ b/Documentation/admin-guide/media/mali-c720.rst
> @@ -0,0 +1,370 @@
[ ... ]
> +Capturing Bayer data and processing it to RGB
> +--------------------------------------------
[Severity: Low]
The hyphen underline here is 44 characters long for a 45-character title,
which triggers a "Title underline too short" warning during make htmldocs.
[ ... ]
> +References
> +==========
> +
> +.. [1] https://git.linuxtv.org/v4l-utils.git/
> +.. [2] https://git.ideasonboard.org/yavta.git/
> +.. [3] https://support.arm.com/compute-ip/mali-c720ae
[Severity: Low]
Is footnote [3] supposed to be referenced in the text above? Without a
corresponding [3]_ reference, Sphinx emits a "Footnote [3] is not
referenced" warning when building the documentation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-b4-initial-upstream-candidate-v1-0-0cb9bde1bd30@arm.com?part=15
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 11/24] media: mali-c720: Add full-resolution output subdevice
2026-11-24 17:07 ` [PATCH 11/24] media: mali-c720: Add full-resolution output subdevice Anthony McGivern
@ 2026-11-24 17:21 ` sashiko-bot
0 siblings, 0 replies; 28+ messages in thread
From: sashiko-bot @ 2026-11-24 17:21 UTC (permalink / raw)
To: Anthony McGivern, devicetree; +Cc: robh, conor+dt, media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] media: mali-c720: premature stream disable in
mali_c720_fr_pipe_disable_streams()
--
commit e9291c2295f3f6641b25d61f1e2d851fc6eecc95
Author: Anthony McGivern <Anthony.McGivern@arm.com>
media: mali-c720: Add full-resolution output subdevice
This commit adds the full-resolution output 0 (FR0) V4L2 subdevice with RGB
and YUV source pads, including scaler and crop configuration.
> diff --git a/drivers/media/platform/arm/mali-c720/mali-c720-fr-pipe.c b/drivers/media/platform/arm/mali-c720/mali-c720-fr-pipe.c
> new file mode 100644
> index 0000000000000..a2f97ebce609b
> --- /dev/null
> +++ b/drivers/media/platform/arm/mali-c720/mali-c720-fr-pipe.c
> @@ -0,0 +1,1178 @@
[ ... ]
> +static int mali_c720_fr_pipe_enable_streams(struct v4l2_subdev *sd,
> + struct v4l2_subdev_state *state, u32 pad,
> + u64 streams_mask)
> +{
> + struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
> + struct mali_c720 *mali_c720 = mdev->mali_c720;
> + const struct mali_c720_pipeline_regs *pipeline = mali_c720->registers.top->pipeline;
> + struct mali_c720_fr_pipe *pipe =
> + mali_c720_sd_to_sd(mdev, struct mali_c720_fr_pipe);
> + struct mali_c720_context *ctx = mali_c720_get_active_context(mali_c720);
> + struct v4l2_subdev *src_sd;
> + struct media_pad *sink_pad;
> + int ret;
> +
> + sink_pad = &pipe->pads[MALI_C720_FR_PIPE_PAD_SINK_VIDEO];
> + pipe->remote_src = media_pad_remote_pad_unique(sink_pad);
> + if (IS_ERR(pipe->remote_src)) {
> + dev_err(mali_c720->dev,
> + "No remote source for fr 0 pipe\n");
> + return -EINVAL;
> + }
> +
> + src_sd = media_entity_to_v4l2_subdev(pipe->remote_src->entity);
> + mali_c720_ctx_group_write(ctx, mali_c720->top_base,
> + &pipeline->fr0_hv_cv_mux_sel,
> + ISP_TOP_FR0_HV_CV_MUX_SEL_HV);
> +
> + /* Enable the upstream subdevice unless another output already enabled it. */
> + ret = v4l2_subdev_enable_streams(src_sd, pipe->remote_src->index, BIT(0));
> + if (ret && ret != -EALREADY)
> + return ret;
> +
> + mali_c720_fr_pipe_update_resizer_config(pipe, state);
> + if (pad == MALI_C720_FR_PIPE_PAD_SOURCE_YUV)
> + mali_c720_fr_pipe_program_output_formatter(pipe);
> +
> + guard(spinlock)(&pipe->resizer_lock);
> + pipe->enabled_crops |= BIT(pad);
> +
> + return 0;
> +}
> +
> +static int mali_c720_fr_pipe_disable_streams(struct v4l2_subdev *sd,
> + struct v4l2_subdev_state *state, u32 pad,
> + u64 streams_mask)
> +{
> + struct mali_c720_subdev *mdev = v4l2_sd_to_mali_c720_sd(sd);
> + struct mali_c720_fr_pipe *pipe =
> + mali_c720_sd_to_sd(mdev, struct mali_c720_fr_pipe);
> + struct v4l2_subdev *src_sd;
> +
> + if (pipe->remote_src) {
> + src_sd = media_entity_to_v4l2_subdev(pipe->remote_src->entity);
> + v4l2_subdev_disable_streams(src_sd, pipe->remote_src->index,
> + BIT(0));
> + }
> + pipe->remote_src = NULL;
> +
> + guard(spinlock)(&pipe->resizer_lock);
> + pipe->enabled_crops &= ~BIT(pad);
> +
> + return 0;
> +}
[Severity: Medium]
Does mali_c720_fr_pipe_disable_streams() stop the upstream subdevice while
the other source pad is still streaming?
mali_c720_fr_pipe_enable_streams() allows both the RGB and YUV source pads
to share the upstream stream by ignoring -EALREADY, and records each active
pad in pipe->enabled_crops. However, mali_c720_fr_pipe_disable_streams()
unconditionally disables the upstream stream and clears pipe->remote_src
without checking whether the other pad bit is still set in
pipe->enabled_crops.
Also, if media_pad_remote_pad_unique() fails in
mali_c720_fr_pipe_enable_streams(), pipe->remote_src is left holding an
ERR_PTR, which the truthiness check in mali_c720_fr_pipe_disable_streams()
would treat as a valid pointer.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-b4-initial-upstream-candidate-v1-0-0cb9bde1bd30@arm.com?part=11
^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2026-11-24 17:21 UTC | newest]
Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 17:07 [PATCH 00/24] Add Arm Mali-C720 Image Signal Processor Driver Anthony McGivern
2026-11-24 17:07 ` [PATCH 01/24] media: uapi: Add 24-bit Bayer media bus formats Anthony McGivern
2026-11-24 17:07 ` [PATCH 02/24] dt-bindings: media: Add bindings for Arm Mali-C720 Anthony McGivern
2026-11-24 17:18 ` sashiko-bot
2026-11-24 17:07 ` [PATCH 03/24] media: uapi: Add a control ID base for Mali-C720 ISP Anthony McGivern
2026-11-24 17:07 ` [PATCH 04/24] media: mali-c720: Add register access helpers Anthony McGivern
2026-11-24 17:07 ` [PATCH 05/24] media: mali-c720: Add hardware identification Anthony McGivern
2026-11-24 17:07 ` [PATCH 06/24] media: mali-c720: Add format handling Anthony McGivern
2026-11-24 17:07 ` [PATCH 07/24] media: mali-c720: Add hardware discovery support Anthony McGivern
2026-11-24 17:07 ` [PATCH 08/24] media: mali-c720: Add context manager and interrupt handling Anthony McGivern
2026-11-24 17:07 ` [PATCH 09/24] media: mali-c720: Add input frontend subdevice Anthony McGivern
2026-11-24 17:07 ` [PATCH 10/24] media: mali-c720: Add ISP and human vision subdevices Anthony McGivern
2026-11-24 17:07 ` [PATCH 11/24] media: mali-c720: Add full-resolution output subdevice Anthony McGivern
2026-11-24 17:21 ` sashiko-bot
2026-11-24 17:07 ` [PATCH 12/24] media: mali-c720: Add video capture nodes Anthony McGivern
2026-11-24 17:07 ` [PATCH 13/24] media: mali-c720: Add Mali-C720 ISP driver Anthony McGivern
2026-11-24 17:07 ` [PATCH 14/24] media: mali-c720: Add test pattern generator subdevices Anthony McGivern
2026-11-24 17:07 ` [PATCH 15/24] media: Documentation: Add Mali-C720 ISP documentation Anthony McGivern
2026-11-24 17:20 ` sashiko-bot
2026-11-24 17:07 ` [PATCH 16/24] media: uapi: Add Mali-C720 statistics meta format Anthony McGivern
2026-11-24 17:07 ` [PATCH 17/24] media: uapi: Add statistics structs to mali-c720-config.h Anthony McGivern
2026-11-24 17:07 ` [PATCH 18/24] media: mali-c720: Add 3A statistics video node Anthony McGivern
2026-11-24 17:07 ` [PATCH 19/24] media: Documentation: Document Mali-C720 statistics capture Anthony McGivern
2026-11-24 17:07 ` [PATCH 20/24] media: uapi: Add Mali-C720 parameters meta format Anthony McGivern
2026-11-24 17:07 ` [PATCH 21/24] media: uapi: Add parameter structs to mali-c720-config.h Anthony McGivern
2026-11-24 17:07 ` [PATCH 22/24] media: mali-c720: Add parameters video node Anthony McGivern
2026-11-24 17:07 ` [PATCH 23/24] media: Documentation: Document Mali-C720 parameter settings Anthony McGivern
2026-11-24 17:07 ` [PATCH 24/24] MAINTAINERS: Add entry for mali-c720 driver Anthony McGivern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox