Skip to contentSkip to conversation

media: platform: Add support for Face Detection (FD) on mt8183 SoC

RFC PATCH Superseded Jerry-ch Chen 4 participants 21 messages Apr 23, 2019 – Jun 25, 2019

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover media: platform: Add support for Face Detection (FD) on mt8183 SoC

Hello,

This RFC patch series is adding Face Detection (FD) driver on Mediatek mt8183 SoC. It belongs to the first Mediatek's camera driver series based on V4L2 and media controller framework. I posted the main part of the FD driver as RFC to discuss first and would like some review comments.

==============
Introduction
==============

Face Detection (FD) unit provides hardware accelerated face detection feature. It can detect different sizes of faces in a given image. Furthermore, it has the capability to detect the faces of Rotation-in-Plane from -180 to +180 degrees and Rotation-off-Plane from -90 to +90 degrees.

The driver is implemented with V4L2 and media controller framework. We have the following entities describing the FD path. Since a FD frame has multiple buffers, the driver uses Request API to control the multiple buffer's enqueue flow.

1. Meta input (output video device): connects to FD sub device. It accepts the input parameter buffer from userspace. The metadata interface is only a temporary solution to kick off driver development and is not ready for reviewed yet.

2. RAW (output video device): connects to FD sub device. It accepts input image buffer from userspace.

3. FD (sub device): connects to Meta output. When processing an image, FD hardware only returns the statistics of detected faces so it needs only one capture video devices to return the streaming data to the user.

4. Meta output (capture video device): Return the result of detected faces in meta capture buffers.

The overall file structure of the FD driver is as following:

* mtk_fd-v4l2.c: implements FD V4L2 and vb2 operations.

* mtk_fd-dev.c: implements fd driver software flow. FD driver supports 2 software pipes at the same time. All the pipes share the same FD hardware to process the images.

* mtk_fd-40.c: implements the hardware driving part.

* mtk_fd-smem.c: provides the shared memory management required operation. We reserved a memory region for the co-processor and FD to exchange the tuning and hardware configuration data.

==================
Changes in v1
==================

RFC v1 includes the following modification:
1. Uses Request API instead of FD's buffer collection design

2. removed unnecessary abstraction structurally, including mtk_fd_ctx and related ops

3. removed the fd_smem node from device tree

4. Fixed the common issues Tomasz commented on Mediatek ISP Pass 1's RFC v0 patch series

==================
Dependent patch
==================

FD driver depends on MDP 3 driver and SCP driver. The patches are as following:

[1]. support mdp3 on mt8183 platform
https://patchwork.kernel.org/cover/10844219/

[2]. Add support for mt8183 SCP
https://patchwork.kernel.org/cover/10872547/

==================
Compliance test
==================

v4l2-compliance SHA: not available, 32 bits

Compliance test for mtk-fd-4.0 device /dev/media1:

Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33

Required ioctls:
test MEDIA_IOC_DEVICE_INFO: OK

Allow for multiple opens:
test second /dev/media1 open: OK
test MEDIA_IOC_DEVICE_INFO: OK
test for unlimited opens: OK

Media Controller ioctls:
test MEDIA_IOC_G_TOPOLOGY: OK
Entities: 8 Interfaces: 8 Pads: 12 Links: 14 test MEDIA_IOC_ENUM_ENTITIES/LINKS: OK test MEDIA_IOC_SETUP_LINK: OK

Total for mtk-fd-4.0 device /dev/media1: 7, Succeeded: 7, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mtk-fd-4.0 device /dev/v4l-subdev3:

Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000005
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x00000001 (1)
	Name             : MTK-FD-V4L2
	Function         : Video Pixel Formatter
	Pad 0x01000002   : 0: Sink
	  Link 0x0200000b: from remote pad 0x1000008 of entity 'MTK-FD-V4L2 FDInput': Data, Enabled
	Pad 0x01000003   : 1: Sink
	  Link 0x02000011: from remote pad 0x100000e of entity 'MTK-FD-V4L2 FDConfig': Data, Enabled
	Pad 0x01000004   : 2: Source
	  Link 0x02000017: to remote pad 0x1000014 of entity 'MTK-FD-V4L2 FDOutput': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK

Allow for multiple opens:
test second /dev/v4l-subdev3 open: 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):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Sink Pad 1):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Source Pad 2):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test 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 VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)

Total for mtk-fd-4.0 device /dev/v4l-subdev3: 62, Succeeded: 62, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2 device /dev/video12:

Driver Info:

	Driver name      : MTK-FD-V4L2
	Card type        : MTK-FD-V4L2
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84202000

Video Output Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04202000
Video Output Multiplanar
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000009
	Type             : V4L Video
Entity Info:
	ID               : 0x00000007 (7)
	Name             : MTK-FD-V4L2 FDInput
	Function         : V4L2 I/O
	Pad 0x01000008   : 0: Source
	  Link 0x0200000b: to remote pad 0x1000002 of entity 'MTK-FD-V4L2': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video12 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2 device /dev/video12: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2 device /dev/video13:

Driver Info:

	Driver name      : MTK-FD-V4L2
	Card type        : MTK-FD-V4L2
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x8c200000

Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x0c200000
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x0300000f
	Type             : V4L Video
Entity Info:
	ID               : 0x0000000d (13)
	Name             : MTK-FD-V4L2 FDConfig
	Function         : V4L2 I/O
	Pad 0x0100000e   : 0: Source
	  Link 0x02000011: to remote pad 0x1000003 of entity 'MTK-FD-V4L2': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video13 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2 device /dev/video13: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2 device /dev/video14:

Driver Info:

	Driver name      : MTK-FD-V4L2
	Card type        : MTK-FD-V4L2
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84a00000

Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04a00000
Metadata Capture
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000015
	Type             : V4L Video
Entity Info:
	ID               : 0x00000013 (19)
	Name             : MTK-FD-V4L2 FDOutput
	Function         : V4L2 I/O
	Pad 0x01000014   : 0: Sink
	  Link 0x02000017: from remote pad 0x1000004 of entity 'MTK-FD-V4L2': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video14 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2 device /dev/video14: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mtk-fd-4.0 device /dev/v4l-subdev4:

Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x0300001d
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x00000019 (25)
	Name             : MTK-FD-V4L2-STREAM-1
	Function         : Video Pixel Formatter
	Pad 0x0100001a   : 0: Sink
	  Link 0x02000023: from remote pad 0x1000020 of entity 'MTK-FD-V4L2-STREAM-1 FDInput': Data, Enabled
	Pad 0x0100001b   : 1: Sink
	  Link 0x02000029: from remote pad 0x1000026 of entity 'MTK-FD-V4L2-STREAM-1 FDConfig': Data, Enabled
	Pad 0x0100001c   : 2: Source
	  Link 0x0200002f: to remote pad 0x100002c of entity 'MTK-FD-V4L2-STREAM-1 FDOutput': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK

Allow for multiple opens:
test second /dev/v4l-subdev4 open: 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):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Sink Pad 1):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Source Pad 2):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test 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 VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)

Total for mtk-fd-4.0 device /dev/v4l-subdev4: 62, Succeeded: 62, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2-STR device /dev/video15:

Driver Info:

	Driver name      : MTK-FD-V4L2-STR
	Card type        : MTK-FD-V4L2-STREAM-1
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84202000

Video Output Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04202000
Video Output Multiplanar
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000021
	Type             : V4L Video
Entity Info:
	ID               : 0x0000001f (31)
	Name             : MTK-FD-V4L2-STREAM-1 FDInput
	Function         : V4L2 I/O
	Pad 0x01000020   : 0: Source
	  Link 0x02000023: to remote pad 0x100001a of entity 'MTK-FD-V4L2-STREAM-1': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video15 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2-STR device /dev/video15: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2-STR device /dev/video16:

Driver Info:

	Driver name      : MTK-FD-V4L2-STR
	Card type        : MTK-FD-V4L2-STREAM-1
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x8c200000

Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x0c200000
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000027
	Type             : V4L Video
Entity Info:
	ID               : 0x00000025 (37)
	Name             : MTK-FD-V4L2-STREAM-1 FDConfig
	Function         : V4L2 I/O
	Pad 0x01000026   : 0: Source
	  Link 0x02000029: to remote pad 0x100001b of entity 'MTK-FD-V4L2-STREAM-1': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video16 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2-STR device /dev/video16: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2-STR device /dev/video17:

Driver Info:

	Driver name      : MTK-FD-V4L2-STR
	Card type        : MTK-FD-V4L2-STREAM-1
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84a00000

Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04a00000
Metadata Capture
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x0300002d
	Type             : V4L Video
Entity Info:
	ID               : 0x0000002b (43)
	Name             : MTK-FD-V4L2-STREAM-1 FDOutput
	Function         : V4L2 I/O
	Pad 0x0100002c   : 0: Sink
	  Link 0x0200002f: from remote pad 0x100001c of entity 'MTK-FD-V4L2-STREAM-1': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video17 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2-STR device /dev/video17: 45, Succeeded: 45, Failed: 0, Warnings: 0

Grand Total for mtk-fd-4.0 device /dev/media1: 401, Succeeded: 401, Failed: 0, Warnings: 0

Jerry-ch Chen (6):
dt-bindings: mt8183: Add binding for FD shared memory
dts: arm64: mt8183: Add FD shared memory node
dt-bindings: mt8183: Added FD dt-bindings
dts: arm64: mt8183: Add FD nodes
media: platform: Add Mediatek FD driver KConfig
platform: mtk-isp: Add Mediatek FD driver

 .../bindings/media/mediatek,mt8183-fd.txt     |   34 +
 .../mediatek,reserve-memory-fd_smem.txt       |   44 +
 arch/arm64/boot/dts/mediatek/mt8183.dtsi      |   29 +
 drivers/media/platform/Kconfig                |    2 +
 drivers/media/platform/mtk-isp/Kconfig        |   18 +
 drivers/media/platform/mtk-isp/Makefile       |   16 +
 drivers/media/platform/mtk-isp/fd/Makefile    |   25 +
 .../media/platform/mtk-isp/fd/mtk_fd-dev.c    |  754 +++++++++++
 .../media/platform/mtk-isp/fd/mtk_fd-dev.h    |  315 +++++
 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h |  158 +++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.c   |  322 +++++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.h   |   39 +
 .../media/platform/mtk-isp/fd/mtk_fd-v4l2.c   | 1171 +++++++++++++++++
 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c |  555 ++++++++
 14 files changed, 3482 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt
 create mode 100644 drivers/media/platform/mtk-isp/Kconfig
 create mode 100644 drivers/media/platform/mtk-isp/Makefile
 create mode 100755 drivers/media/platform/mtk-isp/fd/Makefile
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.c
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-v4l2.c
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c
Signature · 1 line
2.18.0
#1 lore raw

RFC PATCH 1/6 dt-bindings: mt8183: Add binding for FD shared memory

From: Jerry-ch Chen <[email protected]>

This patch adds the binding for describing the shared memory used to exchange meta data between the co-processor and Face Detection (FD) unit of the camera system on Mediatek SoCs.

---
 .../mediatek,reserve-memory-fd_smem.txt       | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt
Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt new file +44 -0
new file mode 100644
index 000000000000..52ae5071e238
@@ -0,0 +1,44 @@
+Mediatek FD Shared Memory binding
+
+This binding describes the shared memory, which serves the purpose of
+describing the shared memory region used to exchange data between Face
+Detection hardware (FD) and co-processor in Mediatek SoCs.
+
+The co-processor doesn't have the iommu so we need to use the physical
+address to access the shared buffer in the firmware.
+
+The Face Detection hardware (FD) can access memory through mt8183 IOMMU so
+it can use dma address to access the memory region.
+(See iommu/mediatek,iommu.txt for the detailed description of Mediatek IOMMU)
+
+
+Required properties:
+
+- compatible: must be "mediatek,reserve-memory-fd_smem"
+
+- reg: required for static allocation (see reserved-memory.txt for
+  the detailed usage)
+
+- alloc-range: required for dynamic allocation. The range must
+  between 0x00000400 and 0x100000000 due to the co-processer's
+  addressing limitation
+
+- size: required for dynamic allocation. The unit is bytes.
+  for Face Detection Unit, you need 1 MB at least.
+
+
+Example:
+
+The following example shows the FD shared memory setup for MT8183.
+
+	reserved-memory {
+		#address-cells = <2>;
+		#size-cells = <2>;
+		ranges;
+		reserve-memory-fd_smem {
+			compatible = "mediatek,reserve-memory-fd_smem";
+			size = <0 0x00100000>;
+			alignment = <0 0x1000>;
+			alloc-ranges = <0 0x40000000 0 0x100000000>;
+		};
+	};
\ No newline at end of file
Signature · 1 line
2.18.0
#4 lore raw

RFC PATCH 2/6 dts: arm64: mt8183: Add FD shared memory node

In reply to Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds a shared memory region used on mt8183 for exchanging meta data between co-processor and Face Detection (FD) unit.

---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +10 -0
index c3a516e63141..dc0b4cad5200 100644
@@ -134,6 +134,16 @@
 		clock-output-names = "clk26m";
 	};
 
+	reserved-memory {
+		reserve-memory-fd_smem {
+			compatible = "mediatek,reserve-memory-fd_smem";
+			no-map;
+			size = <0 0x00100000>;  /*1 MB share mem size */
+			alignment = <0 0x1000>;
+			alloc-ranges = <0 0x40000000 0 0x10000000>;
+		};
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupt-parent = <&gic>;
Signature · 1 line
2.18.0
#5 lore raw

RFC PATCH 3/6 dt-bindings: mt8183: Added FD dt-bindings

In reply to Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds DT binding documentation for the Face Detection (FD) unit of the camera system on Mediatek's SoCs.

---
 .../bindings/media/mediatek,mt8183-fd.txt     | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt
Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt new file +34 -0
new file mode 100644
index 000000000000..97c12fd93e7e
@@ -0,0 +1,34 @@
+* Mediatek Face Detection Unit (FD)
+
+Face Detection (FD) unit is a typical memory-to-memory HW device.
+It provides hardware accelerated face detection function, and it
+is able to detect different poses of faces. FD will writre result
+of detected face into memory as output.
+
+Required properties:
+- compatible: "mediatek,mt8183-fd"
+- reg: Physical base address and length of the function block register space
+- interrupts: interrupt number to the cpu.
+- iommus: should point to the respective IOMMU block with master port as
+  argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
+  for details.
+- mediatek,larb: must contain the local arbiters in the current Socs, see
+  Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.txt
+  for details.
+- clocks : must contain the FDVT clock
+- clock-names: must contain FD_CLK_IMG_FD
+
+Example:
+	fd:fd@1502b000 {
+		compatible = "mediatek,mt8183-fd";
+		mediatek,larb = <&larb5>;
+		mediatek,scp = <&scp>;
+		iommus = <&iommu M4U_PORT_CAM_FDVT_RP>,
+			 <&iommu M4U_PORT_CAM_FDVT_WR>,
+			 <&iommu M4U_PORT_CAM_FDVT_RB>;
+		reg = <0 0x1502b000 0 0x1000>;
+		interrupts = <GIC_SPI 269 IRQ_TYPE_LEVEL_LOW>;
+		clocks = <&imgsys CLK_IMG_FDVT>;
+		clock-names = "FD_CLK_IMG_FD";
+	};
+
Signature · 1 line
2.18.0
#8 lore raw

RFC PATCH 4/6 dts: arm64: mt8183: Add FD nodes

In reply to Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds nodes for Face Detection (FD) unit. FD is embedded in Mediatek SoCs and works with the co-processor to perform face detection on the input data and image and output detected face result.

---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +13 -0
index dc0b4cad5200..04fd590c09b3 100644
@@ -442,6 +442,19 @@
 			#clock-cells = <1>;
 		};
 
+		fd:fd@1502b000 {
+			compatible = "mediatek,mt8183-fd";
+			mediatek,larb = <&larb5>;
+			mediatek,scp = <&scp>;
+			iommus = <&iommu M4U_PORT_CAM_FDVT_RP>,
+				 <&iommu M4U_PORT_CAM_FDVT_WR>,
+				 <&iommu M4U_PORT_CAM_FDVT_RB>;
+			reg = <0 0x1502b000 0 0x1000>;
+			interrupts = <GIC_SPI 269 IRQ_TYPE_LEVEL_LOW>;
+			clocks = <&imgsys CLK_IMG_FDVT>;
+			clock-names = "FD_CLK_IMG_FD";
+		};
+
 		vdecsys: syscon@16000000 {
 			compatible = "mediatek,mt8183-vdecsys", "syscon";
 			reg = <0 0x16000000 0 0x1000>;
Signature · 1 line
2.18.0
#9 lore raw

RFC PATCH 5/6 media: platform: Add Mediatek FD driver KConfig

In reply to Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds KConfig for Mediatek Face Detection driver (FD). FD is embedded in Mediatek SoCs. It can provide hardware accelerated face detection function.

---
 drivers/media/platform/Kconfig         |  2 ++
 drivers/media/platform/mtk-isp/Kconfig | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 drivers/media/platform/mtk-isp/Kconfig
drivers/media/platform/Kconfig +2 -0
index a505e9f5a1e2..ef08d48589a4 100644
@@ -32,6 +32,8 @@ source "drivers/media/platform/davinci/Kconfig"
 
 source "drivers/media/platform/omap/Kconfig"
 
+source "drivers/media/platform/mtk-isp/Kconfig"
+
 config VIDEO_ASPEED
 	tristate "Aspeed AST2400 and AST2500 Video Engine driver"
 	depends on VIDEO_V4L2
drivers/media/platform/mtk-isp/Kconfig new file +18 -0
new file mode 100644
index 000000000000..1fecbb4cbdb9
@@ -0,0 +1,18 @@
+config VIDEO_MEDIATEK_FD_SUPPORT
+	bool "Mediatek face detection processing function"
+	select DMA_SHARED_BUFFER
+	select VIDEO_V4L2_SUBDEV_API
+	select VIDEOBUF2_DMA_CONTIG
+	select VIDEOBUF2_CORE
+	select VIDEOBUF2_V4L2
+	select VIDEOBUF2_MEMOPS
+	select VIDEOBUF2_VMALLOC
+	select MEDIA_CONTROLLER
+
+	default n
+	help
+		Support the basic Face Detectioin (FD) feature.
+
+		FD driver provide face detection function, it can detect
+		faces of Rotation-in-Plane from -180 degrees to +180 degrees
+		and Rotation-off-Plane from -90 degrees to +90 degrees.
Signature · 1 line
2.18.0
#10 lore raw

RFC PATCH 6/6 platform: mtk-isp: Add Mediatek FD driver

In reply to Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds the driver of Face Detection (FD) unit in Mediatek camera system, providing face detection function.

The mtk-isp directory will contain drivers for multiple IP blocks found in Mediatek ISP system. It will include ISP Pass 1 driver (CAM), sensor interface driver, DIP driver and face detection driver.

---
 drivers/media/platform/mtk-isp/Makefile       |   16 +
 drivers/media/platform/mtk-isp/fd/Makefile    |   25 +
 .../media/platform/mtk-isp/fd/mtk_fd-dev.c    |  754 +++++++++++
 .../media/platform/mtk-isp/fd/mtk_fd-dev.h    |  315 +++++
 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h |  158 +++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.c   |  322 +++++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.h   |   39 +
 .../media/platform/mtk-isp/fd/mtk_fd-v4l2.c   | 1171 +++++++++++++++++
 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c |  555 ++++++++
 9 files changed, 3355 insertions(+)
 create mode 100644 drivers/media/platform/mtk-isp/Makefile
 create mode 100644 drivers/media/platform/mtk-isp/fd/Makefile
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-v4l2.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c
drivers/media/platform/mtk-isp/Makefile new file +16 -0
new file mode 100644
index 000000000000..5e3a9aa7f8b2
@@ -0,0 +1,16 @@
+#
+# Copyright (C) 2018 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+ifeq ($(CONFIG_VIDEO_MEDIATEK_FD_SUPPORT),y)
+obj-y += fd/
+endif
drivers/media/platform/mtk-isp/fd/Makefile new file +25 -0
new file mode 100644
index 000000000000..f2b64cf53da9
@@ -0,0 +1,25 @@
+#
+# Copyright (C) 2018 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+$(info $(srctree))
+ccflags-y += -I$(srctree)/drivers/media/platform/mtk-mdp3
+
+obj-y += mtk_fd_40.o
+obj-y += mtk_fd-v4l2.o
+
+# To provide alloc context managing memory shared
+# between CPU and camera coprocessor
+obj-y += mtk_fd-smem.o
+
+# Utilits to provide frame-based streaming model
+# with v4l2 user interfaces
+obj-y += mtk_fd-dev.o
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c new file +754 -0

754 lines not on this page · raw message

drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h new file +315 -0

315 lines not on this page · raw message

drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h new file +158 -0

158 lines not on this page · raw message

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.c new file +322 -0

322 lines not on this page · raw message

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +39 -0
new file mode 100644
index 000000000000..758a4ab68ec2
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Frederic Chen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _MTK_FD_SMEM_H_
+#define _MTK_FD_SMEM_H_
+
+#include <linux/dma-mapping.h>
+#include <linux/device.h>
+
+struct mtk_fd_smem_dev {
+	struct device dev;
+	struct sg_table sgt;
+	struct page **smem_pages;
+	int num_smem_pages;
+	phys_addr_t smem_base;
+	dma_addr_t smem_dma_base;
+	int smem_size;
+};
+
+phys_addr_t mtk_fd_smem_iova_to_phys(struct mtk_fd_smem_dev *smem_dev,
+				     dma_addr_t iova);
+int mtk_fd_smem_alloc_dev_init(struct mtk_fd_smem_dev *smem_dev,
+			       struct device *default_alloc_dev);
+void mtk_fd_smem_alloc_dev_release(struct mtk_fd_smem_dev *smem_dev);
+
+#endif /*_MTK_FD_SMEM_H_*/
+
drivers/media/platform/mtk-isp/fd/mtk_fd-v4l2.c new file +1171 -0

1,171 lines not on this page · raw message

drivers/media/platform/mtk-isp/fd/mtk_fd_40.c new file +555 -0

200 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.18.0

Part of the diff is not shown here. View the raw message.

maintainer
#2 lore raw

Re: [RFC PATCH V1 1/6] dt-bindings: mt8183: Add binding for FD shared memory

In reply to Jerry-ch Chen
Quoted 35 lines · Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds the binding for describing the shared memory used to exchange meta data between the co-processor and Face Detection (FD) unit of the camera system on Mediatek SoCs.

---
 .../mediatek,reserve-memory-fd_smem.txt       | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt
Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt new file +17 -0
new file mode 100644
index 000000000000..52ae5071e238
@@ -0,0 +1,44 @@
+Mediatek FD Shared Memory binding
+
+This binding describes the shared memory, which serves the purpose of
+describing the shared memory region used to exchange data between Face
+Detection hardware (FD) and co-processor in Mediatek SoCs.
+
+The co-processor doesn't have the iommu so we need to use the physical
+address to access the shared buffer in the firmware.
+
+The Face Detection hardware (FD) can access memory through mt8183 IOMMU so
+it can use dma address to access the memory region.
+(See iommu/mediatek,iommu.txt for the detailed description of Mediatek IOMMU)
+
+
+Required properties:
+
+- compatible: must be "mediatek,reserve-memory-fd_smem"

Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt line 27

Quoted 10 lines
Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt new file +10 -0
+
+- reg: required for static allocation (see reserved-memory.txt for
+  the detailed usage)
+
+- alloc-range: required for dynamic allocation. The range must
+  between 0x00000400 and 0x100000000 due to the co-processer's
+  addressing limitation
+
+- size: required for dynamic allocation. The unit is bytes.
+  for Face Detection Unit, you need 1 MB at least.

What's the most?

I don't think you really need reserved memory here if you don't need a fixed address. The size is not that big that a contiguous allocation shouldn't be a problem (though with IOMMU you don't even need that). 'dma-ranges' can be used to set the kernel's dma mask and ensure a range below 0x10000000.

Rob

maintainer
#6 lore raw

Re: [RFC PATCH V1 3/6] dt-bindings: mt8183: Added FD dt-bindings

In reply to Jerry-ch Chen
Quoted 21 lines · Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds DT binding documentation for the Face Detection (FD) unit of the camera system on Mediatek's SoCs.

---
 .../bindings/media/mediatek,mt8183-fd.txt     | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt
Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt new file +4 -0
new file mode 100644
index 000000000000..97c12fd93e7e
@@ -0,0 +1,34 @@
+* Mediatek Face Detection Unit (FD)
+
+Face Detection (FD) unit is a typical memory-to-memory HW device.
+It provides hardware accelerated face detection function, and it

Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt line 14

Quoted 10 lines
Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt new file +10 -0
+is able to detect different poses of faces. FD will writre result
+of detected face into memory as output.
+
+Required properties:
+- compatible: "mediatek,mt8183-fd"
+- reg: Physical base address and length of the function block register space
+- interrupts: interrupt number to the cpu.
+- iommus: should point to the respective IOMMU block with master port as
+  argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
+  for details.

How many entries? Looks like 3 from the example.

Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt line 22

Quoted 8 lines
Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt new file +8 -0
+- mediatek,larb: must contain the local arbiters in the current Socs, see
+  Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.txt
+  for details.
+- clocks : must contain the FDVT clock
+- clock-names: must contain FD_CLK_IMG_FD
+
+Example:
+	fd:fd@1502b000 {

^ space needed

Quoted 15 lines
Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt new file +12 -0
+		compatible = "mediatek,mt8183-fd";
+		mediatek,larb = <&larb5>;
+		mediatek,scp = <&scp>;
+		iommus = <&iommu M4U_PORT_CAM_FDVT_RP>,
+			 <&iommu M4U_PORT_CAM_FDVT_WR>,
+			 <&iommu M4U_PORT_CAM_FDVT_RB>;
+		reg = <0 0x1502b000 0 0x1000>;
+		interrupts = <GIC_SPI 269 IRQ_TYPE_LEVEL_LOW>;
+		clocks = <&imgsys CLK_IMG_FDVT>;
+		clock-names = "FD_CLK_IMG_FD";
+	};
+
Signature · 1 line
2.18.0
#7 lore raw

Re: [RFC PATCH V1 3/6] dt-bindings: mt8183: Added FD dt-bindings

Hi Rob,

Thank you for your comments.

Quoted 26 lines · Rob Herring
Quoted 25 lines · Jerry-ch Chen

From: Jerry-ch Chen <jerry-ch.chen-NuS5LvNUpcJWk0Htik3J/[email protected]>

This patch adds DT binding documentation for the Face Detection (FD) unit of the camera system on Mediatek's SoCs.

---
 .../bindings/media/mediatek,mt8183-fd.txt     | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt
Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt new file +8 -0
new file mode 100644
index 000000000000..97c12fd93e7e
@@ -0,0 +1,34 @@
+* Mediatek Face Detection Unit (FD)
+
+Face Detection (FD) unit is a typical memory-to-memory HW device.
+It provides hardware accelerated face detection function, and it
+is able to detect different poses of faces. FD will writre result
+of detected face into memory as output.
+
+Required properties:
Quoted 9 lines

Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt line 14

Quoted 6 lines
Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt new file +6 -0
+- compatible: "mediatek,mt8183-fd"
+- reg: Physical base address and length of the function block register space
+- interrupts: interrupt number to the cpu.
+- iommus: should point to the respective IOMMU block with master port as
+  argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
+  for details.

How many entries? Looks like 3 from the example.

Yes, we have 3 entries. I would like to update this part as following:

iommus: should point to the 3 entries: M4U_PORT_CAM_FDVT_RP, M4U_PORT_CAM_FDVT_WR and M4U_PORT_CAM_FDVT_RB. (Please see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt for details.)

Quoted 10 lines

Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt line 22

Quoted 8 lines
Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt new file +8 -0
+- mediatek,larb: must contain the local arbiters in the current Socs, see
+  Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.txt
+  for details.
+- clocks : must contain the FDVT clock
+- clock-names: must contain FD_CLK_IMG_FD
+
+Example:
+	fd:fd@1502b000 {

^ space needed

We will fix it in next version of the patch.

Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt new file +7 -0
+		compatible = "mediatek,mt8183-fd";
+		mediatek,larb = <&larb5>;
+		mediatek,scp = <&scp>;
+		iommus = <&iommu M4U_PORT_CAM_FDVT_RP>,
+			 <&iommu M4U_PORT_CAM_FDVT_WR>,
+			 <&iommu M4U_PORT_CAM_FDVT_RB>;
+		reg = <0 0x1502b000 0 0x1000>;
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt new file +5 -0
+		interrupts = <GIC_SPI 269 IRQ_TYPE_LEVEL_LOW>;
+		clocks = <&imgsys CLK_IMG_FDVT>;
+		clock-names = "FD_CLK_IMG_FD";
+	};
+
Signature · 1 line
2.18.0

Sincerely,

Jerry

#19 lore raw
In reply to Jerry-ch Chen
Quoted 29 lines · Jerry-ch Chen

Hello,

This RFC patch series is adding Face Detection (FD) driver on Mediatek mt8183 SoC. It belongs to the first Mediatek's camera driver series based on V4L2 and media controller framework. I posted the main part of the FD driver as RFC to discuss first and would like some review comments.

==============
Introduction
==============

Face Detection (FD) unit provides hardware accelerated face detection feature. It can detect different sizes of faces in a given image. Furthermore, it has the capability to detect the faces of Rotation-in-Plane from -180 to +180 degrees and Rotation-off-Plane from -90 to +90 degrees.

The driver is implemented with V4L2 and media controller framework. We have the following entities describing the FD path. Since a FD frame has multiple buffers, the driver uses Request API to control the multiple buffer's enqueue flow.

1. Meta input (output video device): connects to FD sub device. It accepts the input parameter buffer from userspace. The metadata interface is only a temporary solution to kick off driver development and is not ready for reviewed yet.

2. RAW (output video device): connects to FD sub device. It accepts input image buffer from userspace.

Quoted 6 lines

3. FD (sub device): connects to Meta output. When processing an image, FD hardware only returns the statistics of detected faces so it needs only one capture video devices to return the streaming data to the user.

4. Meta output (capture video device): Return the result of detected faces in meta capture buffers.

I'm a bit confused. What should be in a valid request? One Meta Input buffer and one RAW buffer?

Out of curiosity: is there a limit to the number of faces the HW can detect?

Regards,

Hans

Quoted 969 lines

The overall file structure of the FD driver is as following:

* mtk_fd-v4l2.c: implements FD V4L2 and vb2 operations.

* mtk_fd-dev.c: implements fd driver software flow. FD driver supports 2 software pipes at the same time. All the pipes share the same FD hardware to process the images.

* mtk_fd-40.c: implements the hardware driving part.

* mtk_fd-smem.c: provides the shared memory management required operation. We reserved a memory region for the co-processor and FD to exchange the tuning and hardware configuration data.

==================
Changes in v1
==================

RFC v1 includes the following modification:
1. Uses Request API instead of FD's buffer collection design

2. removed unnecessary abstraction structurally, including mtk_fd_ctx and related ops

3. removed the fd_smem node from device tree

4. Fixed the common issues Tomasz commented on Mediatek ISP Pass 1's RFC v0 patch series

==================
Dependent patch
==================

FD driver depends on MDP 3 driver and SCP driver. The patches are as following:

[1]. support mdp3 on mt8183 platform
https://patchwork.kernel.org/cover/10844219/

[2]. Add support for mt8183 SCP
https://patchwork.kernel.org/cover/10872547/

==================
Compliance test
==================

v4l2-compliance SHA: not available, 32 bits

Compliance test for mtk-fd-4.0 device /dev/media1:

Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33

Required ioctls:
test MEDIA_IOC_DEVICE_INFO: OK

Allow for multiple opens:
test second /dev/media1 open: OK
test MEDIA_IOC_DEVICE_INFO: OK
test for unlimited opens: OK

Media Controller ioctls:
test MEDIA_IOC_G_TOPOLOGY: OK
Entities: 8 Interfaces: 8 Pads: 12 Links: 14 test MEDIA_IOC_ENUM_ENTITIES/LINKS: OK test MEDIA_IOC_SETUP_LINK: OK

Total for mtk-fd-4.0 device /dev/media1: 7, Succeeded: 7, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mtk-fd-4.0 device /dev/v4l-subdev3:

Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000005
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x00000001 (1)
	Name             : MTK-FD-V4L2
	Function         : Video Pixel Formatter
	Pad 0x01000002   : 0: Sink
	  Link 0x0200000b: from remote pad 0x1000008 of entity 'MTK-FD-V4L2 FDInput': Data, Enabled
	Pad 0x01000003   : 1: Sink
	  Link 0x02000011: from remote pad 0x100000e of entity 'MTK-FD-V4L2 FDConfig': Data, Enabled
	Pad 0x01000004   : 2: Source
	  Link 0x02000017: to remote pad 0x1000014 of entity 'MTK-FD-V4L2 FDOutput': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK

Allow for multiple opens:
test second /dev/v4l-subdev3 open: 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):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Sink Pad 1):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Source Pad 2):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test 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 VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)

Total for mtk-fd-4.0 device /dev/v4l-subdev3: 62, Succeeded: 62, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2 device /dev/video12:

Driver Info:

	Driver name      : MTK-FD-V4L2
	Card type        : MTK-FD-V4L2
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84202000

Video Output Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04202000
Video Output Multiplanar
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000009
	Type             : V4L Video
Entity Info:
	ID               : 0x00000007 (7)
	Name             : MTK-FD-V4L2 FDInput
	Function         : V4L2 I/O
	Pad 0x01000008   : 0: Source
	  Link 0x0200000b: to remote pad 0x1000002 of entity 'MTK-FD-V4L2': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video12 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2 device /dev/video12: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2 device /dev/video13:

Driver Info:

	Driver name      : MTK-FD-V4L2
	Card type        : MTK-FD-V4L2
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x8c200000

Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x0c200000
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x0300000f
	Type             : V4L Video
Entity Info:
	ID               : 0x0000000d (13)
	Name             : MTK-FD-V4L2 FDConfig
	Function         : V4L2 I/O
	Pad 0x0100000e   : 0: Source
	  Link 0x02000011: to remote pad 0x1000003 of entity 'MTK-FD-V4L2': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video13 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2 device /dev/video13: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2 device /dev/video14:

Driver Info:

	Driver name      : MTK-FD-V4L2
	Card type        : MTK-FD-V4L2
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84a00000

Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04a00000
Metadata Capture
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000015
	Type             : V4L Video
Entity Info:
	ID               : 0x00000013 (19)
	Name             : MTK-FD-V4L2 FDOutput
	Function         : V4L2 I/O
	Pad 0x01000014   : 0: Sink
	  Link 0x02000017: from remote pad 0x1000004 of entity 'MTK-FD-V4L2': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video14 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2 device /dev/video14: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mtk-fd-4.0 device /dev/v4l-subdev4:

Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x0300001d
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x00000019 (25)
	Name             : MTK-FD-V4L2-STREAM-1
	Function         : Video Pixel Formatter
	Pad 0x0100001a   : 0: Sink
	  Link 0x02000023: from remote pad 0x1000020 of entity 'MTK-FD-V4L2-STREAM-1 FDInput': Data, Enabled
	Pad 0x0100001b   : 1: Sink
	  Link 0x02000029: from remote pad 0x1000026 of entity 'MTK-FD-V4L2-STREAM-1 FDConfig': Data, Enabled
	Pad 0x0100001c   : 2: Source
	  Link 0x0200002f: to remote pad 0x100002c of entity 'MTK-FD-V4L2-STREAM-1 FDOutput': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK

Allow for multiple opens:
test second /dev/v4l-subdev4 open: 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):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Sink Pad 1):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Source Pad 2):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test 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 VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)

Total for mtk-fd-4.0 device /dev/v4l-subdev4: 62, Succeeded: 62, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2-STR device /dev/video15:

Driver Info:

	Driver name      : MTK-FD-V4L2-STR
	Card type        : MTK-FD-V4L2-STREAM-1
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84202000

Video Output Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04202000
Video Output Multiplanar
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000021
	Type             : V4L Video
Entity Info:
	ID               : 0x0000001f (31)
	Name             : MTK-FD-V4L2-STREAM-1 FDInput
	Function         : V4L2 I/O
	Pad 0x01000020   : 0: Source
	  Link 0x02000023: to remote pad 0x100001a of entity 'MTK-FD-V4L2-STREAM-1': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video15 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2-STR device /dev/video15: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2-STR device /dev/video16:

Driver Info:

	Driver name      : MTK-FD-V4L2-STR
	Card type        : MTK-FD-V4L2-STREAM-1
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x8c200000

Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x0c200000
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000027
	Type             : V4L Video
Entity Info:
	ID               : 0x00000025 (37)
	Name             : MTK-FD-V4L2-STREAM-1 FDConfig
	Function         : V4L2 I/O
	Pad 0x01000026   : 0: Source
	  Link 0x02000029: to remote pad 0x100001b of entity 'MTK-FD-V4L2-STREAM-1': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video16 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2-STR device /dev/video16: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2-STR device /dev/video17:

Driver Info:

	Driver name      : MTK-FD-V4L2-STR
	Card type        : MTK-FD-V4L2-STREAM-1
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84a00000

Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04a00000
Metadata Capture
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x0300002d
	Type             : V4L Video
Entity Info:
	ID               : 0x0000002b (43)
	Name             : MTK-FD-V4L2-STREAM-1 FDOutput
	Function         : V4L2 I/O
	Pad 0x0100002c   : 0: Sink
	  Link 0x0200002f: from remote pad 0x100001c of entity 'MTK-FD-V4L2-STREAM-1': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video17 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2-STR device /dev/video17: 45, Succeeded: 45, Failed: 0, Warnings: 0

Grand Total for mtk-fd-4.0 device /dev/media1: 401, Succeeded: 401, Failed: 0, Warnings: 0

Jerry-ch Chen (6):
dt-bindings: mt8183: Add binding for FD shared memory
dts: arm64: mt8183: Add FD shared memory node
dt-bindings: mt8183: Added FD dt-bindings
dts: arm64: mt8183: Add FD nodes
media: platform: Add Mediatek FD driver KConfig
platform: mtk-isp: Add Mediatek FD driver

 .../bindings/media/mediatek,mt8183-fd.txt     |   34 +
 .../mediatek,reserve-memory-fd_smem.txt       |   44 +
 arch/arm64/boot/dts/mediatek/mt8183.dtsi      |   29 +
 drivers/media/platform/Kconfig                |    2 +
 drivers/media/platform/mtk-isp/Kconfig        |   18 +
 drivers/media/platform/mtk-isp/Makefile       |   16 +
 drivers/media/platform/mtk-isp/fd/Makefile    |   25 +
 .../media/platform/mtk-isp/fd/mtk_fd-dev.c    |  754 +++++++++++
 .../media/platform/mtk-isp/fd/mtk_fd-dev.h    |  315 +++++
 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h |  158 +++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.c   |  322 +++++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.h   |   39 +
 .../media/platform/mtk-isp/fd/mtk_fd-v4l2.c   | 1171 +++++++++++++++++
 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c |  555 ++++++++
 14 files changed, 3482 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt
 create mode 100644 drivers/media/platform/mtk-isp/Kconfig
 create mode 100644 drivers/media/platform/mtk-isp/Makefile
 create mode 100755 drivers/media/platform/mtk-isp/fd/Makefile
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.c
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-v4l2.c
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c
#20 lore raw

Hi Hans:

Thanks for your comments.

Quoted 34 lines · Hans Verkuil
Quoted 33 lines · Jerry-ch Chen

Hello,

This RFC patch series is adding Face Detection (FD) driver on Mediatek mt8183 SoC. It belongs to the first Mediatek's camera driver series based on V4L2 and media controller framework. I posted the main part of the FD driver as RFC to discuss first and would like some review comments.

==============
Introduction
==============

Face Detection (FD) unit provides hardware accelerated face detection feature. It can detect different sizes of faces in a given image. Furthermore, it has the capability to detect the faces of Rotation-in-Plane from -180 to +180 degrees and Rotation-off-Plane from -90 to +90 degrees.

The driver is implemented with V4L2 and media controller framework. We have the following entities describing the FD path. Since a FD frame has multiple buffers, the driver uses Request API to control the multiple buffer's enqueue flow.

1. Meta input (output video device): connects to FD sub device. It accepts the input parameter buffer from userspace. The metadata interface is only a temporary solution to kick off driver development and is not ready for reviewed yet.

2. RAW (output video device): connects to FD sub device. It accepts input image buffer from userspace.

3. FD (sub device): connects to Meta output. When processing an image, FD hardware only returns the statistics of detected faces so it needs only one capture video devices to return the streaming data to the user.

Quoted 6 lines
Quoted 2 lines

4. Meta output (capture video device): Return the result of detected faces in meta capture buffers.

I'm a bit confused. What should be in a valid request? One Meta Input buffer and one RAW buffer?

We will revise this part and add the following description. A valid request for FD driver should have one meta input buffer, one RAW buffer and one meta output buffer.

Quoted 4 lines

Out of curiosity: is there a limit to the number of faces the HW can detect?

From HW point of view, the limit to the number of faces is 1024.

Sincerely,

Jerry

Quoted 974 lines

Regards,

Hans

Quoted 969 lines

The overall file structure of the FD driver is as following:

* mtk_fd-v4l2.c: implements FD V4L2 and vb2 operations.

* mtk_fd-dev.c: implements fd driver software flow. FD driver supports 2 software pipes at the same time. All the pipes share the same FD hardware to process the images.

* mtk_fd-40.c: implements the hardware driving part.

* mtk_fd-smem.c: provides the shared memory management required operation. We reserved a memory region for the co-processor and FD to exchange the tuning and hardware configuration data.

==================
Changes in v1
==================

RFC v1 includes the following modification:
1. Uses Request API instead of FD's buffer collection design

2. removed unnecessary abstraction structurally, including mtk_fd_ctx and related ops

3. removed the fd_smem node from device tree

4. Fixed the common issues Tomasz commented on Mediatek ISP Pass 1's RFC v0 patch series

==================
Dependent patch
==================

FD driver depends on MDP 3 driver and SCP driver. The patches are as following:

[1]. support mdp3 on mt8183 platform
https://patchwork.kernel.org/cover/10844219/

[2]. Add support for mt8183 SCP
https://patchwork.kernel.org/cover/10872547/

==================
Compliance test
==================

v4l2-compliance SHA: not available, 32 bits

Compliance test for mtk-fd-4.0 device /dev/media1:

Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33

Required ioctls:
test MEDIA_IOC_DEVICE_INFO: OK

Allow for multiple opens:
test second /dev/media1 open: OK
test MEDIA_IOC_DEVICE_INFO: OK
test for unlimited opens: OK

Media Controller ioctls:
test MEDIA_IOC_G_TOPOLOGY: OK
Entities: 8 Interfaces: 8 Pads: 12 Links: 14 test MEDIA_IOC_ENUM_ENTITIES/LINKS: OK test MEDIA_IOC_SETUP_LINK: OK

Total for mtk-fd-4.0 device /dev/media1: 7, Succeeded: 7, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mtk-fd-4.0 device /dev/v4l-subdev3:

Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000005
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x00000001 (1)
	Name             : MTK-FD-V4L2
	Function         : Video Pixel Formatter
	Pad 0x01000002   : 0: Sink
	  Link 0x0200000b: from remote pad 0x1000008 of entity 'MTK-FD-V4L2 FDInput': Data, Enabled
	Pad 0x01000003   : 1: Sink
	  Link 0x02000011: from remote pad 0x100000e of entity 'MTK-FD-V4L2 FDConfig': Data, Enabled
	Pad 0x01000004   : 2: Source
	  Link 0x02000017: to remote pad 0x1000014 of entity 'MTK-FD-V4L2 FDOutput': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK

Allow for multiple opens:
test second /dev/v4l-subdev3 open: 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):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Sink Pad 1):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Source Pad 2):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test 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 VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)

Total for mtk-fd-4.0 device /dev/v4l-subdev3: 62, Succeeded: 62, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2 device /dev/video12:

Driver Info:

	Driver name      : MTK-FD-V4L2
	Card type        : MTK-FD-V4L2
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84202000

Video Output Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04202000
Video Output Multiplanar
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000009
	Type             : V4L Video
Entity Info:
	ID               : 0x00000007 (7)
	Name             : MTK-FD-V4L2 FDInput
	Function         : V4L2 I/O
	Pad 0x01000008   : 0: Source
	  Link 0x0200000b: to remote pad 0x1000002 of entity 'MTK-FD-V4L2': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video12 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2 device /dev/video12: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2 device /dev/video13:

Driver Info:

	Driver name      : MTK-FD-V4L2
	Card type        : MTK-FD-V4L2
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x8c200000

Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x0c200000
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x0300000f
	Type             : V4L Video
Entity Info:
	ID               : 0x0000000d (13)
	Name             : MTK-FD-V4L2 FDConfig
	Function         : V4L2 I/O
	Pad 0x0100000e   : 0: Source
	  Link 0x02000011: to remote pad 0x1000003 of entity 'MTK-FD-V4L2': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video13 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2 device /dev/video13: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2 device /dev/video14:

Driver Info:

	Driver name      : MTK-FD-V4L2
	Card type        : MTK-FD-V4L2
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84a00000

Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04a00000
Metadata Capture
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000015
	Type             : V4L Video
Entity Info:
	ID               : 0x00000013 (19)
	Name             : MTK-FD-V4L2 FDOutput
	Function         : V4L2 I/O
	Pad 0x01000014   : 0: Sink
	  Link 0x02000017: from remote pad 0x1000004 of entity 'MTK-FD-V4L2': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video14 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2 device /dev/video14: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for mtk-fd-4.0 device /dev/v4l-subdev4:

Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x0300001d
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x00000019 (25)
	Name             : MTK-FD-V4L2-STREAM-1
	Function         : Video Pixel Formatter
	Pad 0x0100001a   : 0: Sink
	  Link 0x02000023: from remote pad 0x1000020 of entity 'MTK-FD-V4L2-STREAM-1 FDInput': Data, Enabled
	Pad 0x0100001b   : 1: Sink
	  Link 0x02000029: from remote pad 0x1000026 of entity 'MTK-FD-V4L2-STREAM-1 FDConfig': Data, Enabled
	Pad 0x0100001c   : 2: Source
	  Link 0x0200002f: to remote pad 0x100002c of entity 'MTK-FD-V4L2-STREAM-1 FDOutput': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK

Allow for multiple opens:
test second /dev/v4l-subdev4 open: 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):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Sink Pad 1):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Sub-Device ioctls (Source Pad 2):
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Try VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK (Not Supported) test Active VIDIOC_SUBDEV_G/S_FMT: OK (Not Supported)
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK (Not Supported)
test 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 VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)

Total for mtk-fd-4.0 device /dev/v4l-subdev4: 62, Succeeded: 62, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2-STR device /dev/video15:

Driver Info:

	Driver name      : MTK-FD-V4L2-STR
	Card type        : MTK-FD-V4L2-STREAM-1
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84202000

Video Output Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04202000
Video Output Multiplanar
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000021
	Type             : V4L Video
Entity Info:
	ID               : 0x0000001f (31)
	Name             : MTK-FD-V4L2-STREAM-1 FDInput
	Function         : V4L2 I/O
	Pad 0x01000020   : 0: Source
	  Link 0x02000023: to remote pad 0x100001a of entity 'MTK-FD-V4L2-STREAM-1': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video15 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2-STR device /dev/video15: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2-STR device /dev/video16:

Driver Info:

	Driver name      : MTK-FD-V4L2-STR
	Card type        : MTK-FD-V4L2-STREAM-1
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x8c200000

Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x0c200000
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x03000027
	Type             : V4L Video
Entity Info:
	ID               : 0x00000025 (37)
	Name             : MTK-FD-V4L2-STREAM-1 FDConfig
	Function         : V4L2 I/O
	Pad 0x01000026   : 0: Source
	  Link 0x02000029: to remote pad 0x100001b of entity 'MTK-FD-V4L2-STREAM-1': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video16 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2-STR device /dev/video16: 45, Succeeded: 45, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for MTK-FD-V4L2-STR device /dev/video17:

Driver Info:

	Driver name      : MTK-FD-V4L2-STR
	Card type        : MTK-FD-V4L2-STREAM-1
	Bus info         : platform:1502b000.fd
	Driver version   : 4.19.33
	Capabilities     : 0x84a00000

Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04a00000
Metadata Capture
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mtk-fd-4.0
	Model            : MTK-FD-V4L2
	Serial           :
	Bus info         : platform:1502b000.fd
	Media version    : 4.19.33
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.19.33
Interface Info:
	ID               : 0x0300002d
	Type             : V4L Video
Entity Info:
	ID               : 0x0000002b (43)
	Name             : MTK-FD-V4L2-STREAM-1 FDOutput
	Function         : V4L2 I/O
	Pad 0x0100002c   : 0: Sink
	  Link 0x0200002f: from remote pad 0x100001c of entity 'MTK-FD-V4L2-STREAM-1': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video17 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (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)

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 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:
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 test VIDIOC_EXPBUF: OK
test Requests: OK

Total for MTK-FD-V4L2-STR device /dev/video17: 45, Succeeded: 45, Failed: 0, Warnings: 0

Grand Total for mtk-fd-4.0 device /dev/media1: 401, Succeeded: 401, Failed: 0, Warnings: 0

Jerry-ch Chen (6):
dt-bindings: mt8183: Add binding for FD shared memory
dts: arm64: mt8183: Add FD shared memory node
dt-bindings: mt8183: Added FD dt-bindings
dts: arm64: mt8183: Add FD nodes
media: platform: Add Mediatek FD driver KConfig
platform: mtk-isp: Add Mediatek FD driver

 .../bindings/media/mediatek,mt8183-fd.txt     |   34 +
 .../mediatek,reserve-memory-fd_smem.txt       |   44 +
 arch/arm64/boot/dts/mediatek/mt8183.dtsi      |   29 +
 drivers/media/platform/Kconfig                |    2 +
 drivers/media/platform/mtk-isp/Kconfig        |   18 +
 drivers/media/platform/mtk-isp/Makefile       |   16 +
 drivers/media/platform/mtk-isp/fd/Makefile    |   25 +
 .../media/platform/mtk-isp/fd/mtk_fd-dev.c    |  754 +++++++++++
 .../media/platform/mtk-isp/fd/mtk_fd-dev.h    |  315 +++++
 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h |  158 +++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.c   |  322 +++++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.h   |   39 +
 .../media/platform/mtk-isp/fd/mtk_fd-v4l2.c   | 1171 +++++++++++++++++
 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c |  555 ++++++++
 14 files changed, 3482 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8183-fd.txt
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt
 create mode 100644 drivers/media/platform/mtk-isp/Kconfig
 create mode 100644 drivers/media/platform/mtk-isp/Makefile
 create mode 100755 drivers/media/platform/mtk-isp/fd/Makefile
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.c
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd-v4l2.c
 create mode 100755 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c
#3 lore raw

Re: [RFC PATCH V1 1/6] dt-bindings: mt8183: Add binding for FD shared memory

In reply to Rob Herring

Hi Rob,

Thank you for your comments.

Quoted 40 lines · Rob Herring
Quoted 39 lines · Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds the binding for describing the shared memory used to exchange meta data between the co-processor and Face Detection (FD) unit of the camera system on Mediatek SoCs.

---
 .../mediatek,reserve-memory-fd_smem.txt       | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt
Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt new file +21 -0
new file mode 100644
index 000000000000..52ae5071e238
@@ -0,0 +1,44 @@
+Mediatek FD Shared Memory binding
+
+This binding describes the shared memory, which serves the purpose of
+describing the shared memory region used to exchange data between Face
+Detection hardware (FD) and co-processor in Mediatek SoCs.
+
+The co-processor doesn't have the iommu so we need to use the physical
+address to access the shared buffer in the firmware.
+
+The Face Detection hardware (FD) can access memory through mt8183 IOMMU so
+it can use dma address to access the memory region.
+(See iommu/mediatek,iommu.txt for the detailed description of Mediatek IOMMU)
+
+
+Required properties:
+
+- compatible: must be "mediatek,reserve-memory-fd_smem"
+
+- reg: required for static allocation (see reserved-memory.txt for
+  the detailed usage)
+
Quoted 9 lines

Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt line 27

Quoted 6 lines
Documentation/devicetree/bindings/reserved-memory/mediatek,reserve-memory-fd_smem.txt new file +6 -0
+- alloc-range: required for dynamic allocation. The range must
+  between 0x00000400 and 0x100000000 due to the co-processer's
+  addressing limitation
+
+- size: required for dynamic allocation. The unit is bytes.
+  for Face Detection Unit, you need 1 MB at least.

What's the most?

For this part, we would like to revise as following:

alloc-range: required for dynamic allocation. The range must between 0x40000000 and 0x100000000 due to the co-processor's addressing limitation

size: required for dynamic allocation. The unit is bytes. for Face Detection Unit, you need 518KB.

Quoted 6 lines

I don't think you really need reserved memory here if you don't need a fixed address. The size is not that big that a contiguous allocation shouldn't be a problem (though with IOMMU you don't even need that). 'dma-ranges' can be used to set the kernel's dma mask and ensure a range below 0x10000000.

FD driver might be able to use the FD memory pool inside the scp reserved memory instead of declaring reserved memory here. would you have any suggestion if so?

Sincerely,
Jerry

Quoted 1 line

Rob

#11 lore raw

Re: [RFC PATCH V1 6/6] platform: mtk-isp: Add Mediatek FD driver

In reply to Jerry-ch Chen

Hi Jerry,

Quoted 10 lines · Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds the driver of Face Detection (FD) unit in Mediatek camera system, providing face detection function.

The mtk-isp directory will contain drivers for multiple IP blocks found in Mediatek ISP system. It will include ISP Pass 1 driver (CAM), sensor interface driver, DIP driver and face detection driver.

Thanks for the patch.

First of all a general comment about the design:

My understanding is that this is a relatively straightforward memory-to-memory device that reads a video frame and detects faces on it. Such devices should be implemented as normal V4L2 memory-to-memory devices, with contexts (instances; pipes) represented by v4l2_fh.

Also, please replace the META_OUTPUT queue with proper V4L2 controls, as I don't think there is anything that we couldn't model using controls here.

The end result should be a V4L2 m2m driver (using the m2m helpers), where you get a new context (instance; pipe) whenever you open the video node, similar to codecs, video processors (like MTK MDP) and so on.

Also please see my comments inline.

Quoted 11 lines
---
 drivers/media/platform/mtk-isp/Makefile       |   16 +
 drivers/media/platform/mtk-isp/fd/Makefile    |   25 +
 .../media/platform/mtk-isp/fd/mtk_fd-dev.c    |  754 +++++++++++
 .../media/platform/mtk-isp/fd/mtk_fd-dev.h    |  315 +++++
 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h |  158 +++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.c   |  322 +++++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.h   |   39 +
 .../media/platform/mtk-isp/fd/mtk_fd-v4l2.c   | 1171 +++++++++++++++++
 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c |  555 ++++++++

This is a small driver. Please just put all the code in one file. (Except the smem stuff, which should go away.)

Quoted 21 lines
 9 files changed, 3355 insertions(+)
 create mode 100644 drivers/media/platform/mtk-isp/Makefile
 create mode 100644 drivers/media/platform/mtk-isp/fd/Makefile
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-v4l2.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c
drivers/media/platform/mtk-isp/Makefile new file +4 -0
new file mode 100644
index 000000000000..5e3a9aa7f8b2
@@ -0,0 +1,16 @@
+#
+# Copyright (C) 2018 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify

drivers/media/platform/mtk-isp/Makefile line 14

Quoted 10 lines
drivers/media/platform/mtk-isp/Makefile new file +10 -0
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+ifeq ($(CONFIG_VIDEO_MEDIATEK_FD_SUPPORT),y)

There is no value in having "SUPPORT" in the Kconfig symbol name. It just makes it unnecessarily long.

drivers/media/platform/mtk-isp/Makefile line 16

Quoted 2 lines
drivers/media/platform/mtk-isp/Makefile new file +2 -0
+obj-y += fd/
+endif

You can just add this directly in drivers/media/platform/Makefile. No need for this intermediate file.

Also, the driver should be compilable as a module too.

Quoted 21 lines
drivers/media/platform/mtk-isp/fd/Makefile new file +15 -0
new file mode 100644
index 000000000000..f2b64cf53da9
@@ -0,0 +1,25 @@
+#
+# Copyright (C) 2018 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+$(info $(srctree))
+ccflags-y += -I$(srctree)/drivers/media/platform/mtk-mdp3
+

drivers/media/platform/mtk-isp/fd/Makefile line 25

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/Makefile new file +10 -0
+obj-y += mtk_fd_40.o
+obj-y += mtk_fd-v4l2.o
+
+# To provide alloc context managing memory shared
+# between CPU and camera coprocessor
+obj-y += mtk_fd-smem.o
+
+# Utilits to provide frame-based streaming model
+# with v4l2 user interfaces
+obj-y += mtk_fd-dev.o

This wouldn't work if the driver is compiled as a module. Please use something like if you have more than 1 object.

	mtk-fd-objs += list of .o objects

	obj-$(CONFIG_VIDEO_MEDIATEK_FD) += mtk-fd.o

Otherwise just use the last line directly.

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c new file +4 -0
new file mode 100644
index 000000000000..207e5d20ad46
@@ -0,0 +1,754 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Frederic Chen <[email protected]>

drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c line 14

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c new file +10 -0
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */

No need for this text if there is SPDX.

[snip]

Quoted 82 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h new file +76 -0
new file mode 100644
index 000000000000..c13627f2bac4
@@ -0,0 +1,315 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Frederic Chen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _MTK_FD_DEV_H_
+#define _MTK_FD_DEV_H_
+
+#include <linux/types.h>
+#include <linux/platform_device.h>
+#include <media/v4l2-device.h>
+#include <media/videobuf2-v4l2.h>
+
+#include "mtk_fd-hw.h"
+#include "mtk_fd-smem.h"
+
+#define MTK_FD_PIPE_ID_STREAM_0				0
+#define MTK_FD_PIPE_ID_STREAM_1				1
+#define MTK_FD_PIPE_ID_TOTAL_NUM			2
+
+#define MTK_FD_VIDEO_NODE_ID_YUV_OUT			0
+#define MTK_FD_VIDEO_NODE_ID_CONFIG_OUT			1
+#define MTK_FD_VIDEO_NODE_ID_OUT_TOTAL_NUM		2
+#define MTK_FD_VIDEO_NODE_ID_CAPTURE			2
+#define MTK_FD_VIDEO_NODE_ID_CAPTURE_TOTAL_NUM		1
+#define MTK_FD_VIDEO_NODE_ID_TOTAL_NUM \
+	(MTK_FD_VIDEO_NODE_ID_OUT_TOTAL_NUM + \
+	MTK_FD_VIDEO_NODE_ID_CAPTURE_TOTAL_NUM)
+
+#define MTK_FD_VIDEO_NODE_ID_NO_MASTER			-1
+
+#define MTK_FD_OUTPUT_MIN_WIDTH				2U
+#define MTK_FD_OUTPUT_MIN_HEIGHT			2U
+#define MTK_FD_OUTPUT_MAX_WIDTH				5376U
+#define MTK_FD_OUTPUT_MAX_HEIGHT			4032U
+#define MTK_FD_CAPTURE_MIN_WIDTH			2U
+#define MTK_FD_CAPTURE_MIN_HEIGHT			2U
+#define MTK_FD_CAPTURE_MAX_WIDTH			5376U
+#define MTK_FD_CAPTURE_MAX_HEIGHT			4032U
+
+#define MTK_FD_PIPE_MEDIA_MODEL_NAME	"MTK-FD-V4L2"
+#define MTK_FD_PIPE_NAME_STREAM_0	MTK_FD_PIPE_MEDIA_MODEL_NAME
+#define MTK_FD_PIPE_NAME_STREAM_1	"MTK-FD-V4L2-STREAM-1"
+
+#define MTK_FD_DEV_META_BUF_DEFAULT_SIZE		(1110 * 1024)
+
+/*
+ * Supported format and the information used for
+ * size calculation
+ */
+struct mtk_fd_dev_meta_format {
+	u32 dataformat;
+	u32 max_buffer_size;
+	u8 flags;
+};
+
+/* MDP part private format definitation */
+struct mtk_fd_dev_mdp_format {
+	u32 pixelformat;
+	u32 mdp_color;
+	u32 colorspace;
+	u8 depth[VIDEO_MAX_PLANES];
+	u8 row_depth[VIDEO_MAX_PLANES];
+	u8 num_planes;
+	u8 walign;
+	u8 halign;

drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h line 86

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h new file +10 -0
+	u8 salign;
+	u32 flags;
+};
+
+struct mtk_fd_dev_format {
+	union {
+		struct mtk_fd_dev_meta_format meta;
+		struct mtk_fd_dev_mdp_format img;
+	} fmt;
+};

This looks like a copy/paste from the DIP driver. Please merge the 3 structures above into 1 as suggested in review of that driver.

[snip]

Quoted 46 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h new file +40 -0
new file mode 100644
index 000000000000..40e09d66c479
@@ -0,0 +1,158 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Copyright (C) 2015 MediaTek Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __MTK_FD_HW_H__
+#define __MTK_FD_HW_H__
+
+#include <linux/io.h>
+#define SIG_ERESTARTSYS 512
+
+#define FD_WR32(v, a) \
+do { \
+	__raw_writel((v), (void __force __iomem *)((a))); \
+	mb(); /* ensure written */ \
+} while (0)
+
+#define FD_RD32(addr) ioread32((void *)addr)
+
+#define FD_INT_EN		0x15c
+#define FD_INT			0x168
+#define FD_RESULT		0x178
+#define FD_IRQ_MASK		0x001
+
+#define RS_BUF_SIZE_MAX		2288788
+#define VA_OFFSET		0xffff000000000000
+
+#define MTK_FD_MAX_NO		1024
+#define MAX_FACE_SEL_NUM	(MTK_FD_MAX_NO + 2)
+
+/* The max number of face sizes could be detected, for feature scaling */
+#define FACE_SIZE_NUM_MAX	14

drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h line 50

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h new file +10 -0
+
+/* FACE_SIZE_NUM_MAX + 1, first scale for input image W/H */
+#define FD_SCALE_NUM		15
+
+/* Number of Learning data sets */
+#define LEARNDATA_NUM		18
+
+#define mtk_fd_us_to_jiffies(us) \
+	((((unsigned long)(us) / 1000) * HZ + 512) >> 10)
+

Uhm, looking at the arbitrary numbers involved in this computation I'm afraid to even ask what this macro is expected to do.

Judging by the name, why not just use usecs_to_jiffies()?

[snip]

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +0 -0
new file mode 100644
index 000000000000..758a4ab68ec2
@@ -0,0 +1,39 @@

[snip]

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+
+struct mtk_fd_smem_dev {
+	struct device dev;
+	struct sg_table sgt;
+	struct page **smem_pages;
+	int num_smem_pages;
+	phys_addr_t smem_base;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h line 37

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	dma_addr_t smem_dma_base;
+	int smem_size;
+};
+
+phys_addr_t mtk_fd_smem_iova_to_phys(struct mtk_fd_smem_dev *smem_dev,
+				     dma_addr_t iova);
+int mtk_fd_smem_alloc_dev_init(struct mtk_fd_smem_dev *smem_dev,
+			       struct device *default_alloc_dev);
+void mtk_fd_smem_alloc_dev_release(struct mtk_fd_smem_dev *smem_dev);
+

Please remove this custom smem thing as we should just use dma_alloc_*() from the right struct device attached to the right reserved memory pool.

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+static int mtk_fd_videoc_enum_fmt(struct file *file, void *fh,
+				  struct v4l2_fmtdesc *f)

It's "vidioc".

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);
+
+	if (f->index > node->desc->num_fmts ||
+	    f->type != node->dev_q.vbq.type)

No need to check the type.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 13 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +13 -0
+		return -EINVAL;
+
+	strscpy(f->description, node->desc->description,
+		sizeof(f->description));
+
+	f->pixelformat = node->desc->fmts[f->index].fmt.img.pixelformat;
+	f->flags = 0;
+
+	return 0;
+}
+
+static int mtk_fd_meta_enum_format(struct file *file,
+				   void *fh, struct v4l2_fmtdesc *f)

Please name the functions consistently. Above it has the vidioc prefix (with typo) and enum_fmt, but here it doesn't have a prefix and is enum_format.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);
+
+	if (f->index > 0 || f->type != node->dev_q.vbq.type)

There is no need to check the type, as the core should already check it for you.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+		return -EINVAL;
+
+	strscpy(f->description, node->desc->description,
+		sizeof(f->description));
+
+	f->pixelformat = node->vdev_fmt.fmt.meta.dataformat;

Also set flags to 0.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	return 0;
+}
+
+static int mtk_fd_videoc_g_meta_fmt(struct file *file,
+				    void *fh, struct v4l2_format *f)
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);

The Linux coding style requires 1 blank line between variable declarations and code.

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	*f = node->vdev_fmt;
+
+	return 0;
+}
+
+static int

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+mtk_fd_vidioc_subscribe_event(struct v4l2_fh *fh,
+			      const struct v4l2_event_subscription *sub)
+{
+	switch (sub->type) {
+	case V4L2_EVENT_CTRL:
+		return v4l2_ctrl_subscribe_event(fh, sub);
+	default:
+		return -EINVAL;
+	}
+}

This driver doesn't seem to support any controls, so there is no point in supporting the above event.

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 12 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +12 -0
+static void mtk_fd_node_to_v4l2(struct mtk_fd_pipe *fd_pipe,
+				u32 idx,
+				 struct video_device *vdev,
+				 struct v4l2_format *f)
+{
+	struct mtk_fd_video_device *node = &fd_pipe->nodes[idx];
+
+	vdev->ioctl_ops = node->desc->ops;
+	vdev->device_caps = V4L2_CAP_STREAMING | node->desc->cap;
+	f->type = node->desc->buf_type;
+	mtk_fd_pipe_load_default_fmt(fd_pipe, node, f);
+}

This function is only called once, is very short and has a very misleading name (this kind of name is used for functions that convert things). Just move the code back to the caller.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+int mtk_fd_dev_media_register(struct device *dev,
+			      struct media_device *media_dev,
+			      const char *model)
+{
+	int ret = 0;
+
+	media_dev->dev = dev;
+	dev_dbg(dev, "setup media_dev.dev: %p\n",
+		media_dev->dev);

I don't think these logs every second line are useful even for debugging. Please remove.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	strlcpy(media_dev->model, model,
+		sizeof(media_dev->model));

No need to pass model here as an argument. Just write the string here directly.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+	dev_dbg(dev, "setup media_dev.model: %s\n",
+		media_dev->model);
+
+	snprintf(media_dev->bus_info, sizeof(media_dev->bus_info),
+		 "platform:%s", dev_name(dev));
+	dev_dbg(dev, "setup media_dev.bus_info: %s\n",
+		media_dev->bus_info);
+
+	media_dev->hw_revision = 0;
+	dev_dbg(dev, "setup media_dev.hw_revision: %d\n",
+		media_dev->hw_revision);

No need to explicitly initialize to 0.

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+
+	media_dev->ops = &mtk_fd_media_req_ops;
+
+	dev_dbg(dev, "media_device_init: media_dev:%p\n",
+		media_dev);
+	media_device_init(media_dev);
+
+	pr_debug("Register media device: %s, %p",
+		 media_dev->model,
+		media_dev);
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	ret = media_device_register(media_dev);
+
+	if (ret) {
+		dev_err(dev, "failed to register media device (%d)\n", ret);
+		goto fail_media_dev;
+	}
+	return 0;
+
+fail_media_dev:
+	media_device_unregister(media_dev);

We jump here even if media_device_register() failed. Unregistering something that wasn't registered doesn't sound like a good idea.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	media_device_cleanup(media_dev);
+
+	return ret;
+}

There isn't much happening in this function. Perhaps just move the code back to the caller?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+
+int mtk_fd_dev_v4l2_register(struct device *dev,
+			     struct media_device *media_dev,
+			     struct v4l2_device *v4l2_dev)
+{
+	int ret = 0;

Add a blank line between variable declarations and code.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	/* Set up v4l2 device */
+	v4l2_dev->mdev = media_dev;
+	dev_dbg(dev, "setup v4l2_dev->mdev: %p",
+		v4l2_dev->mdev);

Please clean up such debugging messages, it makes it much harder to review the code.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 1 line
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +1 -0
+	v4l2_dev->ctrl_handler = NULL;

No need for explicit NULL assignments, as the structure was zero-filled already.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	dev_dbg(dev, "setup v4l2_dev->ctrl_handler: %p",
+		v4l2_dev->ctrl_handler);
+
+	pr_debug("Register v4l2 device: %p",
+		 v4l2_dev);

dev_dbg()? But I would still just remove it.

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+
+	ret = v4l2_device_register(dev, v4l2_dev);
+
+	if (ret) {
+		dev_err(dev, "failed to register V4L2 device (%d)\n", ret);
+		goto fail_v4l2_dev;
+	}

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+	return 0;
+
+fail_v4l2_dev:
+	media_device_unregister(media_dev);
+	media_device_cleanup(media_dev);
+
+	return ret;
+}
+

There isn't much happening in this function. Perhaps just move the code back to the caller?

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+int mtk_fd_pipe_v4l2_register(struct mtk_fd_pipe *fd_pipe,
+			      struct media_device *media_dev,
+			      struct v4l2_device *v4l2_dev)
+{
+	int i, ret;
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	/* Initialize miscellaneous variables */
+	fd_pipe->streaming = 0;
+
+	/* Initialize subdev media entity */
+	fd_pipe->subdev_pads = kcalloc(fd_pipe->num_nodes,
+				       sizeof(*fd_pipe->subdev_pads),
+					GFP_KERNEL);
+	if (!fd_pipe->subdev_pads) {
+		ret = -ENOMEM;
+		goto fail_subdev_pads;

There isn't anything to clean up at this point, so just return.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 9 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +9 -0
+	}
+
+	ret = media_entity_pads_init(&fd_pipe->subdev.entity,
+				     fd_pipe->num_nodes,
+				     fd_pipe->subdev_pads);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,
+			"failed initialize subdev media entity (%d)\n", ret);
+		goto fail_media_entity;

Please name the labels after the next cleanup step to happen after jumping to it.

Quoted 16 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +16 -0
+	}
+
+	/* Initialize subdev */
+	v4l2_subdev_init(&fd_pipe->subdev, &mtk_fd_subdev_ops);
+
+	fd_pipe->subdev.entity.function =
+		MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
+
+	fd_pipe->subdev.entity.ops = &mtk_fd_media_ops;
+
+	for (i = 0; i < fd_pipe->num_nodes; i++) {
+		struct mtk_fd_video_device_desc *desc =
+			fd_pipe->nodes[i].desc;
+
+		fd_pipe->subdev_pads[i].flags =
+			V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
+	}
+
+	fd_pipe->subdev.flags =
+		V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
+	snprintf(fd_pipe->subdev.name, sizeof(fd_pipe->subdev.name),
+		 "%s", fd_pipe->desc->name);
+	v4l2_set_subdevdata(&fd_pipe->subdev, fd_pipe);
+	fd_pipe->subdev.ctrl_handler = NULL;
+	fd_pipe->subdev.internal_ops = &mtk_fd_subdev_internal_ops;

The above code registers a subdev, so it sounds like it could be a separate function.

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	dev_dbg(&fd_pipe->fd_dev->pdev->dev,
+		"register subdev: %s, ctrl_handler %p\n",
+		 fd_pipe->subdev.name, fd_pipe->subdev.ctrl_handler);
+	ret = v4l2_device_register_subdev(&fd_pipe->fd_dev->v4l2_dev,
+					  &fd_pipe->subdev);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			"failed initialize subdev (%d)\n", ret);
+		goto fail_subdev;
+	}
+
+	ret = v4l2_device_register_subdev_nodes(&fd_pipe->fd_dev->v4l2_dev);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,
+			"failed to register subdevs (%d)\n", ret);
+		goto fail_subdevs;
+	}

This isn't per-pipe, but global for the whole v4l2_device. It should be called after all subdevs are fully initialized, to expose the device nodes to the userspace atomically.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	/* Create video nodes and links */
+	for (i = 0; i < fd_pipe->num_nodes; i++) {

Please move the contents of the loop into a separate function that handles one node.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+		struct mtk_fd_video_device *node = &fd_pipe->nodes[i];
+		struct video_device *vdev = &node->vdev;
+		struct vb2_queue *vbq = &node->dev_q.vbq;
+		struct mtk_fd_video_device_desc *desc = node->desc;
+		u32 flags;
+
+		/* Initialize miscellaneous variables */
+		mutex_init(&node->dev_q.lock);

Please just use the video_device lock for vb2 queues too. It simplifies the overall driver locking and doesn't really have any practical performance difference.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+		/* Initialize formats to default values */
+		mtk_fd_node_to_v4l2(fd_pipe, i, vdev, &node->vdev_fmt);
+
+		/* Initialize media entities */
+		ret = media_entity_pads_init(&vdev->entity, 1, &node->vdev_pad);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,

This kind of long chains of pointer dereferences signal a problem in the design of driver structures and/or function arguments.

I'd suggest passing fd_dev to this function and also storing dev instead of pdev inside fd_dev.

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+				"failed initialize media entity (%d)\n", ret);
+			goto fail_vdev_media_entity;
+		}
+
+		node->vdev_pad.flags = V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?
+			MEDIA_PAD_FL_SOURCE : MEDIA_PAD_FL_SINK;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		vdev->entity.ops = NULL;
+
+		/* Initialize vbq */
+		vbq->type = node->vdev_fmt.type;
+		vbq->io_modes = VB2_MMAP | VB2_DMABUF;
+		vbq->ops = &mtk_fd_vb2_ops;
+		vbq->mem_ops = &vb2_dma_contig_memops;
+		vbq->supports_requests = true;
+		vbq->buf_struct_size = sizeof(struct mtk_fd_dev_buffer);
+		vbq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;

This is a mem2mem device so the timestamps should be copied from OUTPUT to CAPTURE. Please set the flag appropriately.

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+		vbq->min_buffers_needed = 0;
+		/* Put the process hub sub device in the vb2 private data*/
+		vbq->drv_priv = fd_pipe;
+		vbq->lock = &node->dev_q.lock;
+		ret = vb2_queue_init(vbq);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,
+				"failed to initialize video queue (%d)\n", ret);

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			goto fail_vdev;
+		}
+
+		/* Initialize vdev */
+		snprintf(vdev->name, sizeof(vdev->name), "%s %s",
+			 fd_pipe->desc->name,
+			 node->desc->name);
+		vdev->release = video_device_release_empty;
+		vdev->fops = &mtk_fd_v4l2_fops;
+		vdev->lock = &node->dev_q.lock;

Aha, so it's in fact the same lock. Please move it to the "node" struct then.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		vdev->ctrl_handler = NULL;
+		vdev->v4l2_dev = &fd_pipe->fd_dev->v4l2_dev;
+		vdev->queue = &node->dev_q.vbq;
+		vdev->vfl_dir = V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?
+			VFL_DIR_TX : VFL_DIR_RX;
+		video_set_drvdata(vdev, fd_pipe);
+		pr_debug("register vdev: %s\n", vdev->name);

dev_dbg()?

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+		ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,
+				"failed to register video device (%d)\n", ret);
+			goto fail_vdev;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		}
+
+		/* Create link between video node and the subdev pad */
+		flags = 0;
+		if (desc->dynamic)
+			flags |= MEDIA_LNK_FL_DYNAMIC;
+		if (node->enabled)
+			flags |= MEDIA_LNK_FL_ENABLED;
+		if (node->immutable)
+			flags |= MEDIA_LNK_FL_IMMUTABLE;

Wouldn't all the nodes be always ENABLED and IMMUTABLE and not DYNAMIC for this driver?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+		if (V4L2_TYPE_IS_OUTPUT(desc->buf_type))
+			ret = media_create_pad_link(&vdev->entity, 0,
+						    &fd_pipe->subdev.entity,
+						    i, flags);
+		else
+			ret = media_create_pad_link(&fd_pipe->subdev.entity,
+						    i, &vdev->entity, 0,
+						    flags);
+

No need for this blank line.

Quoted 13 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +13 -0
+		if (ret)
+			goto fail_link;
+	}
+
+	return 0;
+
+	for (; i >= 0; i--) {
+fail_link:
+		video_unregister_device(&fd_pipe->nodes[i].vdev);
+fail_vdev:
+		vb2_queue_release(&fd_pipe->nodes[i].dev_q.vbq);
+		media_entity_cleanup(&fd_pipe->nodes[i].vdev.entity);
+fail_vdev_media_entity:

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		mutex_destroy(&fd_pipe->nodes[i].dev_q.lock);
+	}
+fail_subdevs:
+	v4l2_device_unregister_subdev(&fd_pipe->subdev);
+fail_subdev:
+	media_entity_cleanup(&fd_pipe->subdev.entity);
+fail_media_entity:
+	kfree(fd_pipe->subdev_pads);
+fail_subdev_pads:
+	v4l2_device_unregister(&fd_pipe->fd_dev->v4l2_dev);

We haven't registered the v4l2_device in this function.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	pr_err("fail_v4l2_dev: media_device_unregister and clenaup:%p",
+	       &fd_pipe->fd_dev->mdev);

Error messages should be printed at the place of the failure.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	media_device_unregister(&fd_pipe->fd_dev->mdev);
+	media_device_cleanup(&fd_pipe->fd_dev->mdev);

We haven't registered or initialized media_device in this function.

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+
+	return ret;
+}
+
+int mtk_fd_pipe_v4l2_unregister(struct mtk_fd_pipe *fd_pipe)
+{
+	unsigned int i;
+
+	for (i = 0; i < fd_pipe->num_nodes; i++) {
+		video_unregister_device(&fd_pipe->nodes[i].vdev);
+		vb2_queue_release(&fd_pipe->nodes[i].dev_q.vbq);

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		media_entity_cleanup(&fd_pipe->nodes[i].vdev.entity);
+		mutex_destroy(&fd_pipe->nodes[i].dev_q.lock);
+	}
+
+	v4l2_device_unregister_subdev(&fd_pipe->subdev);
+	media_entity_cleanup(&fd_pipe->subdev.entity);
+	kfree(fd_pipe->subdev_pads);
+	v4l2_device_unregister(&fd_pipe->fd_dev->v4l2_dev);
+	media_device_unregister(&fd_pipe->fd_dev->mdev);
+	media_device_cleanup(&fd_pipe->fd_dev->mdev);

Please make this consistent with the registration functions. For each registration function there should be a matching unregister function that cleans up only whatever was registered in that function.

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	return 0;
+}
+
+void mtk_fd_v4l2_buffer_done(struct vb2_buffer *vb,
+			     enum vb2_buffer_state state)
+{
+	struct mtk_fd_pipe *fd_pipe;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	struct mtk_fd_video_device *node;
+
+	fd_pipe = vb2_get_drv_priv(vb->vb2_queue);
+	node = mtk_fd_vbq_to_node(vb->vb2_queue);
+	dev_dbg(&fd_pipe->fd_dev->pdev->dev,
+		"%s:%s: return buf, idx(%d), state(%d)\n",
+		fd_pipe->desc->name, node->desc->name,
+		vb->index, state);
+	vb2_buffer_done(vb, state);
+}

No need for this function. Just call vb2_buffer_done() directly from the caller. (I already mentioned this in MTK DIP driver review. Please coordinate with other driver owners and make sure that similar comments are addressed in all drivers...)

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 12 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +12 -0
+
+/********************************************
+ * MTK FD V4L2 Settings *
+ ********************************************/
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_video_out_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+	.vidioc_enum_framesizes = mtk_fd_videoc_enum_framesizes,
+	.vidioc_enum_fmt_vid_cap_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_cap_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_cap_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_cap_mplane = mtk_fd_videoc_try_fmt,

No need for *cap* ops if this is only for an OUTPUT device.

Quoted 32 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +32 -0
+	.vidioc_enum_fmt_vid_out_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_out_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_out_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_out_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+	.vidioc_subscribe_event = mtk_fd_vidioc_subscribe_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+
+};
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_video_cap_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+	.vidioc_enum_framesizes = mtk_fd_videoc_enum_framesizes,
+	.vidioc_enum_fmt_vid_cap_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_cap_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_cap_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_cap_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_enum_fmt_vid_out_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_out_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_out_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_out_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+	.vidioc_subscribe_event = mtk_fd_vidioc_subscribe_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+
+};

This structure is unused.

Quoted 38 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +38 -0
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_meta_out_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+
+	.vidioc_enum_fmt_meta_cap = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_enum_fmt_meta_out = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+};
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_meta_cap_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+
+	.vidioc_enum_fmt_meta_cap = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_enum_fmt_meta_out = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+};

Aren't the 2 structures above identical? Should be merged if so.

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+int mtk_fd_dev_v4l2_init(struct mtk_fd_dev *fd_dev)
+{
+	struct media_device *media_dev;
+	struct v4l2_device *v4l2_dev;
+	struct mtk_fd_smem_dev *smem_alloc_dev = &fd_dev->smem_alloc_dev;
+	int i;
+	int ret = 0;

Please don't initialize local variables unless that's needed by the logic. It prevents the compiler from detecting missing assignments.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	media_dev = &fd_dev->mdev;
+	v4l2_dev = &fd_dev->v4l2_dev;

Just pass fd_dev to the functions below. No need to extract only some fields.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	ret = mtk_fd_dev_media_register(&fd_dev->pdev->dev,
+					media_dev,
+					 MTK_FD_PIPE_MEDIA_MODEL_NAME);

We should bail out on error.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	ret = mtk_fd_dev_v4l2_register(&fd_dev->pdev->dev,
+				       media_dev,
+					v4l2_dev);

We should clean up the previous steps and bail out on error.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	ret = mtk_fd_smem_alloc_dev_init(smem_alloc_dev, &fd_dev->pdev->dev);

Ditto.

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+	for (i = 0; i < MTK_FD_PIPE_ID_TOTAL_NUM; i++) {
+		ret = mtk_fd_pipe_init(&fd_dev->fd_pipe[i], fd_dev,
+				       &pipe_settings[i],
+					media_dev, v4l2_dev, smem_alloc_dev);
+		if (ret) {
+			dev_err(&fd_dev->pdev->dev,
+				"%s: Pipe id(%d) init failed(%d)\n",
+				fd_dev->fd_pipe[i].desc->name,
+				i, ret);

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+void mtk_fd_dev_v4l2_release(struct mtk_fd_dev *fd_dev)
+{
+	int i = 0;

No need for initialization.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	if (fd_dev)

Why could it ever be NULL?

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+		for (i = 0; i < MTK_FD_PIPE_ID_TOTAL_NUM; i++)
+			mtk_fd_pipe_release(&fd_dev->fd_pipe[i]);
+
+	mtk_fd_smem_alloc_dev_release(&fd_dev->smem_alloc_dev);
+}
+

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+static int mtk_fd_probe(struct platform_device *pdev)
+{
+	struct mtk_fd_dev *fd_dev;
+	struct mtk_fd_hw *fd_hw;
+	struct device_node *node;
+	struct platform_device *larb_pdev;
+	int irq_num;
+	int ret;
+
+	fd_dev = devm_kzalloc(&pdev->dev, sizeof(*fd_dev), GFP_KERNEL);
+

nit: No need for this blank line, because the if below is directly related.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+	if (!fd_dev)
+		return -ENOMEM;
+
+	dev_set_drvdata(&pdev->dev, fd_dev);
+	fd_hw = &fd_dev->fd_hw;
+
+	if (!fd_hw) {

How is this possible for a struct member?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		dev_err(&pdev->dev, "Unable to allocate fd_hw\n");
+		return -ENOMEM;
+	}
+
+	fd_dev->pdev = pdev;
+
+	irq_num = irq_of_parse_and_map(pdev->dev.of_node, FD_IRQ_IDX);

We should use platform_get_irq() here instead, because the IRQs were already parsed for us when the platform core created the platform_device.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	ret = request_irq(irq_num, (irq_handler_t)mtk_fd_irq,
+			  IRQF_TRIGGER_NONE, FD_DRVNAME, fd_hw);

It should be a device name, not driver name. One would normally use dev_name() here.

Also devm_request_irq() should simplify the cleanup.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+	if (ret) {
+		dev_dbg(&pdev->dev, "%s request_irq fail, irq=%d\n",
+			__func__, irq_num);

This is an error, so dev_err().

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+		return ret;
+	}
+	dev_dbg(&pdev->dev, "irq_num=%d\n", irq_num);

That's probably not very useful.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 13 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +13 -0
+
+	node = of_parse_phandle(pdev->dev.of_node, "mediatek,larb", 0);
+	if (!node) {
+		dev_err(&pdev->dev, "no mediatek, larb found");
+		return -EINVAL;
+	}
+	larb_pdev = of_find_device_by_node(node);
+	if (!larb_pdev) {
+		dev_err(&pdev->dev, "no mediatek, larb device found");
+		return -EINVAL;
+	}
+	fd_hw->larb_dev = &larb_pdev->dev;
+

LARBs are handled automatically by the IOMMU driver, no need to do anything with them explicitly anymore.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+	node = pdev->dev.of_node;
+	if (!node) {
+		dev_err(&pdev->dev, "find fd node failed!!!\n");
+		return -ENODEV;
+	}
+
+	fd_hw->fd_base = of_iomap(node, 0);

One would normally use platform_get_resource() and devm_ioremap_resource() here.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	if (!fd_hw->fd_base) {
+		dev_err(&pdev->dev, "unable to map fd node!!!\n");
+		return -ENODEV;
+	}
+
+	dev_dbg(&pdev->dev, "fd_hw->fd_base: %lx\n",
+		(unsigned long)fd_hw->fd_base);

Not very useful either.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	fd_hw->fd_clk = devm_clk_get(&pdev->dev, "FD_CLK_IMG_FD");

Clock names should be lowercase and name just inputs of the IP block, so simply "fd", should be enough.

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	if (IS_ERR(fd_hw->fd_clk)) {
+		dev_err(&pdev->dev, "cannot get FD_CLK_IMG_FD clock\n");
+		return PTR_ERR(fd_hw->fd_clk);
+	}

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+	pm_runtime_enable(&pdev->dev);
+	atomic_set(&fd_hw->fd_user_cnt, 0);
+	init_waitqueue_head(&fd_hw->wq);
+	mutex_init(&fd_hw->fd_hw_lock);
+	fd_hw->fd_irq_result = 0;
+
+	ret = mtk_fd_dev_v4l2_init(fd_dev);
+	if (ret)
+		dev_err(&pdev->dev, "v4l2 init failed: %d\n", ret);

We should clean up and return the error code, not 0.

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	dev_info(&pdev->dev, "Mediatek Camera FD driver probe.\n");
+
+	return 0;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+}
+
+static int mtk_fd_remove(struct platform_device *pdev)
+{
+	int irq_i4;
+	struct mtk_fd_dev *fd_dev = dev_get_drvdata(&pdev->dev);
+
+	if (fd_dev) {
+		mtk_fd_dev_v4l2_release(fd_dev);
+	} else {

This is impossible.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		dev_err(&pdev->dev, "Can't find fd driver data\n");
+		return -EINVAL;
+	}
+
+	mutex_destroy(&fd_dev->fd_hw.fd_hw_lock);
+	pm_runtime_disable(&pdev->dev);
+
+	irq_i4 = platform_get_irq(pdev, 0);
+	free_irq(irq_i4, NULL);
+	kfree(fd_dev);

fd_dev was allocated using devm_kzalloc(), no need to free it explicitly.

Quoted 9 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +9 -0
+
+	return 0;
+}
+
+static int mtk_fd_suspend(struct device *dev)
+{
+	struct mtk_fd_dev *fd_dev;
+	int ret;
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	fd_dev = dev_get_drvdata(dev);
+
+	if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+		ret = pm_runtime_put_sync(fd_dev->fd_hw.larb_dev);
+		clk_disable_unprepare(fd_dev->fd_hw.fd_clk);
+		return ret;
+	}

This isn't going to work, because the hardware may be still processing a frame at this point. You need a way to ensure that the hardware goes idle here first and then in resume, you need to make the hardware continue when it left before suspend.

Quoted 37 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +37 -0
+	return 0;
+}
+
+static int mtk_fd_resume(struct device *dev)
+{
+	struct mtk_fd_dev *fd_dev;
+	int ret;
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	fd_dev = dev_get_drvdata(dev);
+
+	if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+		ret = pm_runtime_get_sync(fd_dev->fd_hw.larb_dev);
+		if (ret) {
+			dev_dbg(&fd_dev->pdev->dev, "open larb clk failed\n");
+			return ret;
+		}
+
+		ret = clk_prepare_enable(fd_dev->fd_hw.fd_clk);
+		if (ret) {
+			dev_dbg(&fd_dev->pdev->dev, "open fd clk failed\n");
+			return ret;
+		}
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct dev_pm_ops mtk_fd_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(mtk_fd_suspend, mtk_fd_resume)
+	SET_RUNTIME_PM_OPS(mtk_fd_suspend, mtk_fd_resume, NULL)
+};
+
+static const struct of_device_id mtk_fd_of_ids[] = {

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	{ .compatible = "mediatek,mt8183-fd", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, mtk_fd_of_ids);
+
+static struct platform_driver mtk_fd_driver = {
+	.probe   = mtk_fd_probe,
+	.remove  = mtk_fd_remove,
+	.driver  = {
+		.name  = FD_DRVNAME,

Please just set the name explicitly here and remove the macro.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 1 line
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +1 -0
+		.of_match_table = mtk_fd_of_ids,

Please use of_match_ptr().

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		.pm = &mtk_fd_pm_ops,
+	}
+};
+module_platform_driver(mtk_fd_driver);
+
+MODULE_DESCRIPTION("Mediatek FD driver");
+MODULE_LICENSE("GPL");

GPL v2

Quoted 3 lines
Signature · 1 line
2.18.0
#12 lore raw

Re: [RFC PATCH V1 6/6] platform: mtk-isp: Add Mediatek FD driver

Hi Tomasz,

Quoted 23 lines · Tomasz Figa

Hi Jerry,

Quoted 10 lines · Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds the driver of Face Detection (FD) unit in Mediatek camera system, providing face detection function.

The mtk-isp directory will contain drivers for multiple IP blocks found in Mediatek ISP system. It will include ISP Pass 1 driver (CAM), sensor interface driver, DIP driver and face detection driver.

Thanks for the patch.

First of all a general comment about the design:

My understanding is that this is a relatively straightforward memory-to-memory device that reads a video frame and detects faces on it. Such devices should be implemented as normal V4L2 memory-to-memory devices, with contexts (instances; pipes) represented by v4l2_fh.

Quoted 9 lines

Also, please replace the META_OUTPUT queue with proper V4L2 controls, as I don't think there is anything that we couldn't model using controls here.

The end result should be a V4L2 m2m driver (using the m2m helpers), where you get a new context (instance; pipe) whenever you open the video node, similar to codecs, video processors (like MTK MDP) and so on.

Also please see my comments inline.

I appreciate your comments,

FD driver will be implemented as a normal V4L2 m2m driver which has an IMAGE_OUTPUT queue and a META_CAPTURE queue(face result).

We will use the following properties.
/* Is a video mem-to-mem device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000

The original META_OUTPUT queue contains the following structure will be replaced by V4L2 controls,

/* FD_SCALE_NUM is 15. */

struct fd_user_param {
	uint8_t rip_feature;
	uint8_t gfd_skip;
	uint8_t dynamic_change_model;
	uint8_t scale_num_from_user;
	uint16_t source_img_width[FD_SCALE_NUM];
	uint16_t source_img_height[FD_SCALE_NUM];
} __packed; //share with co-processor

However, we found that testM2MFormats in the V4L2 compliance test will assume the capture queue has the same format as output queue has, therefore, FD driver's capture queue wouldn't be able to use META format or that test case will be failed.

// m2m devices are special in that the format is often per-filehandle. // But colorspace information should be passed from output to capture, // so test that.

	if (node->is_m2m)
		return testM2MFormats(node);

May we ask for your suggestions about this part?

Quoted 12 lines
Quoted 11 lines
---
 drivers/media/platform/mtk-isp/Makefile       |   16 +
 drivers/media/platform/mtk-isp/fd/Makefile    |   25 +
 .../media/platform/mtk-isp/fd/mtk_fd-dev.c    |  754 +++++++++++
 .../media/platform/mtk-isp/fd/mtk_fd-dev.h    |  315 +++++
 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h |  158 +++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.c   |  322 +++++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.h   |   39 +
 .../media/platform/mtk-isp/fd/mtk_fd-v4l2.c   | 1171 +++++++++++++++++
 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c |  555 ++++++++
Quoted 3 lines

This is a small driver. Please just put all the code in one file. (Except the smem stuff, which should go away.)

Ok, we will fix it.

Quoted 35 lines
Quoted 21 lines
 9 files changed, 3355 insertions(+)
 create mode 100644 drivers/media/platform/mtk-isp/Makefile
 create mode 100644 drivers/media/platform/mtk-isp/fd/Makefile
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-v4l2.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c
drivers/media/platform/mtk-isp/Makefile new file +4 -0
new file mode 100644
index 000000000000..5e3a9aa7f8b2
@@ -0,0 +1,16 @@
+#
+# Copyright (C) 2018 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify

drivers/media/platform/mtk-isp/Makefile line 14

Quoted 10 lines
drivers/media/platform/mtk-isp/Makefile new file +10 -0
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+ifeq ($(CONFIG_VIDEO_MEDIATEK_FD_SUPPORT),y)

There is no value in having "SUPPORT" in the Kconfig symbol name. It just makes it unnecessarily long.

Quoted 8 lines

drivers/media/platform/mtk-isp/Makefile line 16

Quoted 2 lines
drivers/media/platform/mtk-isp/Makefile new file +2 -0
+obj-y += fd/
+endif

You can just add this directly in drivers/media/platform/Makefile. No need for this intermediate file.

Also, the driver should be compilable as a module too.

Ok, we will fix it.

Quoted 35 lines
Quoted 21 lines
drivers/media/platform/mtk-isp/fd/Makefile new file +15 -0
new file mode 100644
index 000000000000..f2b64cf53da9
@@ -0,0 +1,25 @@
+#
+# Copyright (C) 2018 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+$(info $(srctree))
+ccflags-y += -I$(srctree)/drivers/media/platform/mtk-mdp3
+

drivers/media/platform/mtk-isp/fd/Makefile line 25

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/Makefile new file +10 -0
+obj-y += mtk_fd_40.o
+obj-y += mtk_fd-v4l2.o
+
+# To provide alloc context managing memory shared
+# between CPU and camera coprocessor
+obj-y += mtk_fd-smem.o
+
+# Utilits to provide frame-based streaming model
+# with v4l2 user interfaces
+obj-y += mtk_fd-dev.o

This wouldn't work if the driver is compiled as a module. Please use something like if you have more than 1 object.

Quoted 6 lines
	mtk-fd-objs += list of .o objects

	obj-$(CONFIG_VIDEO_MEDIATEK_FD) += mtk-fd.o

Otherwise just use the last line directly.

Ok, we will fix it.

Quoted 14 lines
Quoted 14 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c new file +8 -0
new file mode 100644
index 000000000000..207e5d20ad46
@@ -0,0 +1,754 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Frederic Chen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c line 14

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c new file +6 -0
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */

No need for this text if there is SPDX.

Fixed.

Quoted 88 lines

[snip]

Quoted 87 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h new file +81 -0
new file mode 100644
index 000000000000..c13627f2bac4
@@ -0,0 +1,315 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Frederic Chen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _MTK_FD_DEV_H_
+#define _MTK_FD_DEV_H_
+
+#include <linux/types.h>
+#include <linux/platform_device.h>
+#include <media/v4l2-device.h>
+#include <media/videobuf2-v4l2.h>
+
+#include "mtk_fd-hw.h"
+#include "mtk_fd-smem.h"
+
+#define MTK_FD_PIPE_ID_STREAM_0				0
+#define MTK_FD_PIPE_ID_STREAM_1				1
+#define MTK_FD_PIPE_ID_TOTAL_NUM			2
+
+#define MTK_FD_VIDEO_NODE_ID_YUV_OUT			0
+#define MTK_FD_VIDEO_NODE_ID_CONFIG_OUT			1
+#define MTK_FD_VIDEO_NODE_ID_OUT_TOTAL_NUM		2
+#define MTK_FD_VIDEO_NODE_ID_CAPTURE			2
+#define MTK_FD_VIDEO_NODE_ID_CAPTURE_TOTAL_NUM		1
+#define MTK_FD_VIDEO_NODE_ID_TOTAL_NUM \
+	(MTK_FD_VIDEO_NODE_ID_OUT_TOTAL_NUM + \
+	MTK_FD_VIDEO_NODE_ID_CAPTURE_TOTAL_NUM)
+
+#define MTK_FD_VIDEO_NODE_ID_NO_MASTER			-1
+
+#define MTK_FD_OUTPUT_MIN_WIDTH				2U
+#define MTK_FD_OUTPUT_MIN_HEIGHT			2U
+#define MTK_FD_OUTPUT_MAX_WIDTH				5376U
+#define MTK_FD_OUTPUT_MAX_HEIGHT			4032U
+#define MTK_FD_CAPTURE_MIN_WIDTH			2U
+#define MTK_FD_CAPTURE_MIN_HEIGHT			2U
+#define MTK_FD_CAPTURE_MAX_WIDTH			5376U
+#define MTK_FD_CAPTURE_MAX_HEIGHT			4032U
+
+#define MTK_FD_PIPE_MEDIA_MODEL_NAME	"MTK-FD-V4L2"
+#define MTK_FD_PIPE_NAME_STREAM_0	MTK_FD_PIPE_MEDIA_MODEL_NAME
+#define MTK_FD_PIPE_NAME_STREAM_1	"MTK-FD-V4L2-STREAM-1"
+
+#define MTK_FD_DEV_META_BUF_DEFAULT_SIZE		(1110 * 1024)
+
+/*
+ * Supported format and the information used for
+ * size calculation
+ */
+struct mtk_fd_dev_meta_format {
+	u32 dataformat;
+	u32 max_buffer_size;
+	u8 flags;
+};
+
+/* MDP part private format definitation */
+struct mtk_fd_dev_mdp_format {
+	u32 pixelformat;
+	u32 mdp_color;
+	u32 colorspace;
+	u8 depth[VIDEO_MAX_PLANES];
+	u8 row_depth[VIDEO_MAX_PLANES];
+	u8 num_planes;
+	u8 walign;
+	u8 halign;
+	u8 salign;
+	u32 flags;
+};
+
+struct mtk_fd_dev_format {
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h line 86

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h new file +5 -0
+	union {
+		struct mtk_fd_dev_meta_format meta;
+		struct mtk_fd_dev_mdp_format img;
+	} fmt;
+};

This looks like a copy/paste from the DIP driver. Please merge the 3 structures above into 1 as suggested in review of that driver.

Ok, we will fix it.

Quoted 61 lines

[snip]

Quoted 46 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h new file +40 -0
new file mode 100644
index 000000000000..40e09d66c479
@@ -0,0 +1,158 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Copyright (C) 2015 MediaTek Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __MTK_FD_HW_H__
+#define __MTK_FD_HW_H__
+
+#include <linux/io.h>
+#define SIG_ERESTARTSYS 512
+
+#define FD_WR32(v, a) \
+do { \
+	__raw_writel((v), (void __force __iomem *)((a))); \
+	mb(); /* ensure written */ \
+} while (0)
+
+#define FD_RD32(addr) ioread32((void *)addr)
+
+#define FD_INT_EN		0x15c
+#define FD_INT			0x168
+#define FD_RESULT		0x178
+#define FD_IRQ_MASK		0x001
+
+#define RS_BUF_SIZE_MAX		2288788
+#define VA_OFFSET		0xffff000000000000
+
+#define MTK_FD_MAX_NO		1024
+#define MAX_FACE_SEL_NUM	(MTK_FD_MAX_NO + 2)
+
+/* The max number of face sizes could be detected, for feature scaling */
+#define FACE_SIZE_NUM_MAX	14

drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h line 50

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h new file +10 -0
+
+/* FACE_SIZE_NUM_MAX + 1, first scale for input image W/H */
+#define FD_SCALE_NUM		15
+
+/* Number of Learning data sets */
+#define LEARNDATA_NUM		18
+
+#define mtk_fd_us_to_jiffies(us) \
+	((((unsigned long)(us) / 1000) * HZ + 512) >> 10)
+

Uhm, looking at the arbitrary numbers involved in this computation I'm afraid to even ask what this macro is expected to do.

Quoted 2 lines

Judging by the name, why not just use usecs_to_jiffies()?

Fixed. Using usecs_to_jiffies() instead.

Quoted 20 lines

[snip]

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +0 -0
new file mode 100644
index 000000000000..758a4ab68ec2
@@ -0,0 +1,39 @@

[snip]

Quoted 12 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +12 -0
+
+struct mtk_fd_smem_dev {
+	struct device dev;
+	struct sg_table sgt;
+	struct page **smem_pages;
+	int num_smem_pages;
+	phys_addr_t smem_base;
+	dma_addr_t smem_dma_base;
+	int smem_size;
+};
+
+phys_addr_t mtk_fd_smem_iova_to_phys(struct mtk_fd_smem_dev *smem_dev,
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h line 37

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+				     dma_addr_t iova);
+int mtk_fd_smem_alloc_dev_init(struct mtk_fd_smem_dev *smem_dev,
+			       struct device *default_alloc_dev);
+void mtk_fd_smem_alloc_dev_release(struct mtk_fd_smem_dev *smem_dev);
+

Please remove this custom smem thing as we should just use dma_alloc_*() from the right struct device attached to the right reserved memory pool.

FD driver may not need smem things after we use v4l2 control to replace the META_OUTPUT queuues.

Quoted 6 lines

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+static int mtk_fd_videoc_enum_fmt(struct file *file, void *fh,
+				  struct v4l2_fmtdesc *f)

It's "vidioc".

Fixed.

Quoted 8 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);
+
+	if (f->index > node->desc->num_fmts ||
+	    f->type != node->dev_q.vbq.type)

No need to check the type.

Ok, we will fix it.

Quoted 8 lines
Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+		return -EINVAL;
+
+	strscpy(f->description, node->desc->description,
+		sizeof(f->description));
+
+	f->pixelformat = node->desc->fmts[f->index].fmt.img.pixelformat;
+	f->flags = 0;
+
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	return 0;
+}
+
+static int mtk_fd_meta_enum_format(struct file *file,
+				   void *fh, struct v4l2_fmtdesc *f)

Please name the functions consistently. Above it has the vidioc prefix (with typo) and enum_fmt, but here it doesn't have a prefix and is enum_format.

Renamed to mtk_fd_vidioc_enum_meta_format.

Quoted 8 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);
+
+	if (f->index > 0 || f->type != node->dev_q.vbq.type)

There is no need to check the type, as the core should already check it for you.

Ok, we will fix it.

Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+		return -EINVAL;
+
+	strscpy(f->description, node->desc->description,
+		sizeof(f->description));
+
+	f->pixelformat = node->vdev_fmt.fmt.meta.dataformat;

Also set flags to 0.

Fixed.

Quoted 884 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	return 0;
+}
+
+static int mtk_fd_videoc_g_meta_fmt(struct file *file,
+				    void *fh, struct v4l2_format *f)
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);

The Linux coding style requires 1 blank line between variable declarations and code.

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	*f = node->vdev_fmt;
+
+	return 0;
+}
+
+static int

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+mtk_fd_vidioc_subscribe_event(struct v4l2_fh *fh,
+			      const struct v4l2_event_subscription *sub)
+{
+	switch (sub->type) {
+	case V4L2_EVENT_CTRL:
+		return v4l2_ctrl_subscribe_event(fh, sub);
+	default:
+		return -EINVAL;
+	}
+}

This driver doesn't seem to support any controls, so there is no point in supporting the above event.

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 12 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +12 -0
+static void mtk_fd_node_to_v4l2(struct mtk_fd_pipe *fd_pipe,
+				u32 idx,
+				 struct video_device *vdev,
+				 struct v4l2_format *f)
+{
+	struct mtk_fd_video_device *node = &fd_pipe->nodes[idx];
+
+	vdev->ioctl_ops = node->desc->ops;
+	vdev->device_caps = V4L2_CAP_STREAMING | node->desc->cap;
+	f->type = node->desc->buf_type;
+	mtk_fd_pipe_load_default_fmt(fd_pipe, node, f);
+}

This function is only called once, is very short and has a very misleading name (this kind of name is used for functions that convert things). Just move the code back to the caller.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+int mtk_fd_dev_media_register(struct device *dev,
+			      struct media_device *media_dev,
+			      const char *model)
+{
+	int ret = 0;
+
+	media_dev->dev = dev;
+	dev_dbg(dev, "setup media_dev.dev: %p\n",
+		media_dev->dev);

I don't think these logs every second line are useful even for debugging. Please remove.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	strlcpy(media_dev->model, model,
+		sizeof(media_dev->model));

No need to pass model here as an argument. Just write the string here directly.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+	dev_dbg(dev, "setup media_dev.model: %s\n",
+		media_dev->model);
+
+	snprintf(media_dev->bus_info, sizeof(media_dev->bus_info),
+		 "platform:%s", dev_name(dev));
+	dev_dbg(dev, "setup media_dev.bus_info: %s\n",
+		media_dev->bus_info);
+
+	media_dev->hw_revision = 0;
+	dev_dbg(dev, "setup media_dev.hw_revision: %d\n",
+		media_dev->hw_revision);

No need to explicitly initialize to 0.

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+
+	media_dev->ops = &mtk_fd_media_req_ops;
+
+	dev_dbg(dev, "media_device_init: media_dev:%p\n",
+		media_dev);
+	media_device_init(media_dev);
+
+	pr_debug("Register media device: %s, %p",
+		 media_dev->model,
+		media_dev);
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	ret = media_device_register(media_dev);
+
+	if (ret) {
+		dev_err(dev, "failed to register media device (%d)\n", ret);
+		goto fail_media_dev;
+	}
+	return 0;
+
+fail_media_dev:
+	media_device_unregister(media_dev);

We jump here even if media_device_register() failed. Unregistering something that wasn't registered doesn't sound like a good idea.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	media_device_cleanup(media_dev);
+
+	return ret;
+}

There isn't much happening in this function. Perhaps just move the code back to the caller?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+
+int mtk_fd_dev_v4l2_register(struct device *dev,
+			     struct media_device *media_dev,
+			     struct v4l2_device *v4l2_dev)
+{
+	int ret = 0;

Add a blank line between variable declarations and code.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	/* Set up v4l2 device */
+	v4l2_dev->mdev = media_dev;
+	dev_dbg(dev, "setup v4l2_dev->mdev: %p",
+		v4l2_dev->mdev);

Please clean up such debugging messages, it makes it much harder to review the code.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 1 line
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +1 -0
+	v4l2_dev->ctrl_handler = NULL;

No need for explicit NULL assignments, as the structure was zero-filled already.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	dev_dbg(dev, "setup v4l2_dev->ctrl_handler: %p",
+		v4l2_dev->ctrl_handler);
+
+	pr_debug("Register v4l2 device: %p",
+		 v4l2_dev);

dev_dbg()? But I would still just remove it.

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+
+	ret = v4l2_device_register(dev, v4l2_dev);
+
+	if (ret) {
+		dev_err(dev, "failed to register V4L2 device (%d)\n", ret);
+		goto fail_v4l2_dev;
+	}

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+	return 0;
+
+fail_v4l2_dev:
+	media_device_unregister(media_dev);
+	media_device_cleanup(media_dev);
+
+	return ret;
+}
+

There isn't much happening in this function. Perhaps just move the code back to the caller?

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+int mtk_fd_pipe_v4l2_register(struct mtk_fd_pipe *fd_pipe,
+			      struct media_device *media_dev,
+			      struct v4l2_device *v4l2_dev)
+{
+	int i, ret;
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	/* Initialize miscellaneous variables */
+	fd_pipe->streaming = 0;
+
+	/* Initialize subdev media entity */
+	fd_pipe->subdev_pads = kcalloc(fd_pipe->num_nodes,
+				       sizeof(*fd_pipe->subdev_pads),
+					GFP_KERNEL);
+	if (!fd_pipe->subdev_pads) {
+		ret = -ENOMEM;
+		goto fail_subdev_pads;

There isn't anything to clean up at this point, so just return.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 9 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +9 -0
+	}
+
+	ret = media_entity_pads_init(&fd_pipe->subdev.entity,
+				     fd_pipe->num_nodes,
+				     fd_pipe->subdev_pads);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,
+			"failed initialize subdev media entity (%d)\n", ret);
+		goto fail_media_entity;

Please name the labels after the next cleanup step to happen after jumping to it.

Quoted 16 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +16 -0
+	}
+
+	/* Initialize subdev */
+	v4l2_subdev_init(&fd_pipe->subdev, &mtk_fd_subdev_ops);
+
+	fd_pipe->subdev.entity.function =
+		MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
+
+	fd_pipe->subdev.entity.ops = &mtk_fd_media_ops;
+
+	for (i = 0; i < fd_pipe->num_nodes; i++) {
+		struct mtk_fd_video_device_desc *desc =
+			fd_pipe->nodes[i].desc;
+
+		fd_pipe->subdev_pads[i].flags =
+			V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
+	}
+
+	fd_pipe->subdev.flags =
+		V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
+	snprintf(fd_pipe->subdev.name, sizeof(fd_pipe->subdev.name),
+		 "%s", fd_pipe->desc->name);
+	v4l2_set_subdevdata(&fd_pipe->subdev, fd_pipe);
+	fd_pipe->subdev.ctrl_handler = NULL;
+	fd_pipe->subdev.internal_ops = &mtk_fd_subdev_internal_ops;

The above code registers a subdev, so it sounds like it could be a separate function.

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	dev_dbg(&fd_pipe->fd_dev->pdev->dev,
+		"register subdev: %s, ctrl_handler %p\n",
+		 fd_pipe->subdev.name, fd_pipe->subdev.ctrl_handler);
+	ret = v4l2_device_register_subdev(&fd_pipe->fd_dev->v4l2_dev,
+					  &fd_pipe->subdev);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			"failed initialize subdev (%d)\n", ret);
+		goto fail_subdev;
+	}
+
+	ret = v4l2_device_register_subdev_nodes(&fd_pipe->fd_dev->v4l2_dev);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,
+			"failed to register subdevs (%d)\n", ret);
+		goto fail_subdevs;
+	}

This isn't per-pipe, but global for the whole v4l2_device. It should be called after all subdevs are fully initialized, to expose the device nodes to the userspace atomically.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	/* Create video nodes and links */
+	for (i = 0; i < fd_pipe->num_nodes; i++) {

Please move the contents of the loop into a separate function that handles one node.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+		struct mtk_fd_video_device *node = &fd_pipe->nodes[i];
+		struct video_device *vdev = &node->vdev;
+		struct vb2_queue *vbq = &node->dev_q.vbq;
+		struct mtk_fd_video_device_desc *desc = node->desc;
+		u32 flags;
+
+		/* Initialize miscellaneous variables */
+		mutex_init(&node->dev_q.lock);

Please just use the video_device lock for vb2 queues too. It simplifies the overall driver locking and doesn't really have any practical performance difference.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+		/* Initialize formats to default values */
+		mtk_fd_node_to_v4l2(fd_pipe, i, vdev, &node->vdev_fmt);
+
+		/* Initialize media entities */
+		ret = media_entity_pads_init(&vdev->entity, 1, &node->vdev_pad);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,

This kind of long chains of pointer dereferences signal a problem in the design of driver structures and/or function arguments.

I'd suggest passing fd_dev to this function and also storing dev instead of pdev inside fd_dev.

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+				"failed initialize media entity (%d)\n", ret);
+			goto fail_vdev_media_entity;
+		}
+
+		node->vdev_pad.flags = V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?
+			MEDIA_PAD_FL_SOURCE : MEDIA_PAD_FL_SINK;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		vdev->entity.ops = NULL;
+
+		/* Initialize vbq */
+		vbq->type = node->vdev_fmt.type;
+		vbq->io_modes = VB2_MMAP | VB2_DMABUF;
+		vbq->ops = &mtk_fd_vb2_ops;
+		vbq->mem_ops = &vb2_dma_contig_memops;
+		vbq->supports_requests = true;
+		vbq->buf_struct_size = sizeof(struct mtk_fd_dev_buffer);
+		vbq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;

This is a mem2mem device so the timestamps should be copied from OUTPUT to CAPTURE. Please set the flag appropriately.

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+		vbq->min_buffers_needed = 0;
+		/* Put the process hub sub device in the vb2 private data*/
+		vbq->drv_priv = fd_pipe;
+		vbq->lock = &node->dev_q.lock;
+		ret = vb2_queue_init(vbq);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,
+				"failed to initialize video queue (%d)\n", ret);

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			goto fail_vdev;
+		}
+
+		/* Initialize vdev */
+		snprintf(vdev->name, sizeof(vdev->name), "%s %s",
+			 fd_pipe->desc->name,
+			 node->desc->name);
+		vdev->release = video_device_release_empty;
+		vdev->fops = &mtk_fd_v4l2_fops;
+		vdev->lock = &node->dev_q.lock;

Aha, so it's in fact the same lock. Please move it to the "node" struct then.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		vdev->ctrl_handler = NULL;
+		vdev->v4l2_dev = &fd_pipe->fd_dev->v4l2_dev;
+		vdev->queue = &node->dev_q.vbq;
+		vdev->vfl_dir = V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?
+			VFL_DIR_TX : VFL_DIR_RX;
+		video_set_drvdata(vdev, fd_pipe);
+		pr_debug("register vdev: %s\n", vdev->name);

dev_dbg()?

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+		ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,
+				"failed to register video device (%d)\n", ret);
+			goto fail_vdev;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		}
+
+		/* Create link between video node and the subdev pad */
+		flags = 0;
+		if (desc->dynamic)
+			flags |= MEDIA_LNK_FL_DYNAMIC;
+		if (node->enabled)
+			flags |= MEDIA_LNK_FL_ENABLED;
+		if (node->immutable)
+			flags |= MEDIA_LNK_FL_IMMUTABLE;

Wouldn't all the nodes be always ENABLED and IMMUTABLE and not DYNAMIC for this driver?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+		if (V4L2_TYPE_IS_OUTPUT(desc->buf_type))
+			ret = media_create_pad_link(&vdev->entity, 0,
+						    &fd_pipe->subdev.entity,
+						    i, flags);
+		else
+			ret = media_create_pad_link(&fd_pipe->subdev.entity,
+						    i, &vdev->entity, 0,
+						    flags);
+

No need for this blank line.

Quoted 13 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +13 -0
+		if (ret)
+			goto fail_link;
+	}
+
+	return 0;
+
+	for (; i >= 0; i--) {
+fail_link:
+		video_unregister_device(&fd_pipe->nodes[i].vdev);
+fail_vdev:
+		vb2_queue_release(&fd_pipe->nodes[i].dev_q.vbq);
+		media_entity_cleanup(&fd_pipe->nodes[i].vdev.entity);
+fail_vdev_media_entity:

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		mutex_destroy(&fd_pipe->nodes[i].dev_q.lock);
+	}
+fail_subdevs:
+	v4l2_device_unregister_subdev(&fd_pipe->subdev);
+fail_subdev:
+	media_entity_cleanup(&fd_pipe->subdev.entity);
+fail_media_entity:
+	kfree(fd_pipe->subdev_pads);
+fail_subdev_pads:
+	v4l2_device_unregister(&fd_pipe->fd_dev->v4l2_dev);

We haven't registered the v4l2_device in this function.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	pr_err("fail_v4l2_dev: media_device_unregister and clenaup:%p",
+	       &fd_pipe->fd_dev->mdev);

Error messages should be printed at the place of the failure.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	media_device_unregister(&fd_pipe->fd_dev->mdev);
+	media_device_cleanup(&fd_pipe->fd_dev->mdev);

We haven't registered or initialized media_device in this function.

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+
+	return ret;
+}
+
+int mtk_fd_pipe_v4l2_unregister(struct mtk_fd_pipe *fd_pipe)
+{
+	unsigned int i;
+
+	for (i = 0; i < fd_pipe->num_nodes; i++) {
+		video_unregister_device(&fd_pipe->nodes[i].vdev);
+		vb2_queue_release(&fd_pipe->nodes[i].dev_q.vbq);

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		media_entity_cleanup(&fd_pipe->nodes[i].vdev.entity);
+		mutex_destroy(&fd_pipe->nodes[i].dev_q.lock);
+	}
+
+	v4l2_device_unregister_subdev(&fd_pipe->subdev);
+	media_entity_cleanup(&fd_pipe->subdev.entity);
+	kfree(fd_pipe->subdev_pads);
+	v4l2_device_unregister(&fd_pipe->fd_dev->v4l2_dev);
+	media_device_unregister(&fd_pipe->fd_dev->mdev);
+	media_device_cleanup(&fd_pipe->fd_dev->mdev);

Please make this consistent with the registration functions. For each registration function there should be a matching unregister function that cleans up only whatever was registered in that function.

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	return 0;
+}
+
+void mtk_fd_v4l2_buffer_done(struct vb2_buffer *vb,
+			     enum vb2_buffer_state state)
+{
+	struct mtk_fd_pipe *fd_pipe;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	struct mtk_fd_video_device *node;
+
+	fd_pipe = vb2_get_drv_priv(vb->vb2_queue);
+	node = mtk_fd_vbq_to_node(vb->vb2_queue);
+	dev_dbg(&fd_pipe->fd_dev->pdev->dev,
+		"%s:%s: return buf, idx(%d), state(%d)\n",
+		fd_pipe->desc->name, node->desc->name,
+		vb->index, state);
+	vb2_buffer_done(vb, state);
+}

No need for this function. Just call vb2_buffer_done() directly from the caller. (I already mentioned this in MTK DIP driver review. Please coordinate with other driver owners and make sure that similar comments are addressed in all drivers...)

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 12 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +12 -0
+
+/********************************************
+ * MTK FD V4L2 Settings *
+ ********************************************/
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_video_out_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+	.vidioc_enum_framesizes = mtk_fd_videoc_enum_framesizes,
+	.vidioc_enum_fmt_vid_cap_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_cap_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_cap_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_cap_mplane = mtk_fd_videoc_try_fmt,

No need for *cap* ops if this is only for an OUTPUT device.

Quoted 32 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +32 -0
+	.vidioc_enum_fmt_vid_out_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_out_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_out_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_out_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+	.vidioc_subscribe_event = mtk_fd_vidioc_subscribe_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+
+};
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_video_cap_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+	.vidioc_enum_framesizes = mtk_fd_videoc_enum_framesizes,
+	.vidioc_enum_fmt_vid_cap_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_cap_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_cap_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_cap_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_enum_fmt_vid_out_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_out_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_out_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_out_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+	.vidioc_subscribe_event = mtk_fd_vidioc_subscribe_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+
+};

This structure is unused.

Quoted 38 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +38 -0
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_meta_out_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+
+	.vidioc_enum_fmt_meta_cap = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_enum_fmt_meta_out = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+};
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_meta_cap_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+
+	.vidioc_enum_fmt_meta_cap = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_enum_fmt_meta_out = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+};

Aren't the 2 structures above identical? Should be merged if so.

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+int mtk_fd_dev_v4l2_init(struct mtk_fd_dev *fd_dev)
+{
+	struct media_device *media_dev;
+	struct v4l2_device *v4l2_dev;
+	struct mtk_fd_smem_dev *smem_alloc_dev = &fd_dev->smem_alloc_dev;
+	int i;
+	int ret = 0;

Please don't initialize local variables unless that's needed by the logic. It prevents the compiler from detecting missing assignments.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	media_dev = &fd_dev->mdev;
+	v4l2_dev = &fd_dev->v4l2_dev;

Just pass fd_dev to the functions below. No need to extract only some fields.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	ret = mtk_fd_dev_media_register(&fd_dev->pdev->dev,
+					media_dev,
+					 MTK_FD_PIPE_MEDIA_MODEL_NAME);

We should bail out on error.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	ret = mtk_fd_dev_v4l2_register(&fd_dev->pdev->dev,
+				       media_dev,
+					v4l2_dev);

We should clean up the previous steps and bail out on error.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	ret = mtk_fd_smem_alloc_dev_init(smem_alloc_dev, &fd_dev->pdev->dev);

Ditto.

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+	for (i = 0; i < MTK_FD_PIPE_ID_TOTAL_NUM; i++) {
+		ret = mtk_fd_pipe_init(&fd_dev->fd_pipe[i], fd_dev,
+				       &pipe_settings[i],
+					media_dev, v4l2_dev, smem_alloc_dev);
+		if (ret) {
+			dev_err(&fd_dev->pdev->dev,
+				"%s: Pipe id(%d) init failed(%d)\n",
+				fd_dev->fd_pipe[i].desc->name,
+				i, ret);

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+void mtk_fd_dev_v4l2_release(struct mtk_fd_dev *fd_dev)
+{
+	int i = 0;

No need for initialization.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	if (fd_dev)

Why could it ever be NULL?

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+		for (i = 0; i < MTK_FD_PIPE_ID_TOTAL_NUM; i++)
+			mtk_fd_pipe_release(&fd_dev->fd_pipe[i]);
+
+	mtk_fd_smem_alloc_dev_release(&fd_dev->smem_alloc_dev);
+}
+

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+static int mtk_fd_probe(struct platform_device *pdev)
+{
+	struct mtk_fd_dev *fd_dev;
+	struct mtk_fd_hw *fd_hw;
+	struct device_node *node;
+	struct platform_device *larb_pdev;
+	int irq_num;
+	int ret;
+
+	fd_dev = devm_kzalloc(&pdev->dev, sizeof(*fd_dev), GFP_KERNEL);
+

nit: No need for this blank line, because the if below is directly related.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+	if (!fd_dev)
+		return -ENOMEM;
+
+	dev_set_drvdata(&pdev->dev, fd_dev);
+	fd_hw = &fd_dev->fd_hw;
+
+	if (!fd_hw) {

How is this possible for a struct member?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		dev_err(&pdev->dev, "Unable to allocate fd_hw\n");
+		return -ENOMEM;
+	}
+
+	fd_dev->pdev = pdev;
+
+	irq_num = irq_of_parse_and_map(pdev->dev.of_node, FD_IRQ_IDX);

We should use platform_get_irq() here instead, because the IRQs were already parsed for us when the platform core created the platform_device.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	ret = request_irq(irq_num, (irq_handler_t)mtk_fd_irq,
+			  IRQF_TRIGGER_NONE, FD_DRVNAME, fd_hw);

It should be a device name, not driver name. One would normally use dev_name() here.

Also devm_request_irq() should simplify the cleanup.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+	if (ret) {
+		dev_dbg(&pdev->dev, "%s request_irq fail, irq=%d\n",
+			__func__, irq_num);

This is an error, so dev_err().

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+		return ret;
+	}
+	dev_dbg(&pdev->dev, "irq_num=%d\n", irq_num);

That's probably not very useful.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 13 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +13 -0
+
+	node = of_parse_phandle(pdev->dev.of_node, "mediatek,larb", 0);
+	if (!node) {
+		dev_err(&pdev->dev, "no mediatek, larb found");
+		return -EINVAL;
+	}
+	larb_pdev = of_find_device_by_node(node);
+	if (!larb_pdev) {
+		dev_err(&pdev->dev, "no mediatek, larb device found");
+		return -EINVAL;
+	}
+	fd_hw->larb_dev = &larb_pdev->dev;
+

LARBs are handled automatically by the IOMMU driver, no need to do anything with them explicitly anymore.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+	node = pdev->dev.of_node;
+	if (!node) {
+		dev_err(&pdev->dev, "find fd node failed!!!\n");
+		return -ENODEV;
+	}
+
+	fd_hw->fd_base = of_iomap(node, 0);

One would normally use platform_get_resource() and devm_ioremap_resource() here.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	if (!fd_hw->fd_base) {
+		dev_err(&pdev->dev, "unable to map fd node!!!\n");
+		return -ENODEV;
+	}
+
+	dev_dbg(&pdev->dev, "fd_hw->fd_base: %lx\n",
+		(unsigned long)fd_hw->fd_base);

Not very useful either.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	fd_hw->fd_clk = devm_clk_get(&pdev->dev, "FD_CLK_IMG_FD");

Clock names should be lowercase and name just inputs of the IP block, so simply "fd", should be enough.

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	if (IS_ERR(fd_hw->fd_clk)) {
+		dev_err(&pdev->dev, "cannot get FD_CLK_IMG_FD clock\n");
+		return PTR_ERR(fd_hw->fd_clk);
+	}

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+	pm_runtime_enable(&pdev->dev);
+	atomic_set(&fd_hw->fd_user_cnt, 0);
+	init_waitqueue_head(&fd_hw->wq);
+	mutex_init(&fd_hw->fd_hw_lock);
+	fd_hw->fd_irq_result = 0;
+
+	ret = mtk_fd_dev_v4l2_init(fd_dev);
+	if (ret)
+		dev_err(&pdev->dev, "v4l2 init failed: %d\n", ret);

We should clean up and return the error code, not 0.

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	dev_info(&pdev->dev, "Mediatek Camera FD driver probe.\n");
+
+	return 0;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+}
+
+static int mtk_fd_remove(struct platform_device *pdev)
+{
+	int irq_i4;
+	struct mtk_fd_dev *fd_dev = dev_get_drvdata(&pdev->dev);
+
+	if (fd_dev) {
+		mtk_fd_dev_v4l2_release(fd_dev);
+	} else {

This is impossible.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		dev_err(&pdev->dev, "Can't find fd driver data\n");
+		return -EINVAL;
+	}
+
+	mutex_destroy(&fd_dev->fd_hw.fd_hw_lock);
+	pm_runtime_disable(&pdev->dev);
+
+	irq_i4 = platform_get_irq(pdev, 0);
+	free_irq(irq_i4, NULL);
+	kfree(fd_dev);

fd_dev was allocated using devm_kzalloc(), no need to free it explicitly.

Quoted 9 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +9 -0
+
+	return 0;
+}
+
+static int mtk_fd_suspend(struct device *dev)
+{
+	struct mtk_fd_dev *fd_dev;
+	int ret;
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	fd_dev = dev_get_drvdata(dev);
+
+	if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+		ret = pm_runtime_put_sync(fd_dev->fd_hw.larb_dev);
+		clk_disable_unprepare(fd_dev->fd_hw.fd_clk);
+		return ret;
+	}

This isn't going to work, because the hardware may be still processing a frame at this point. You need a way to ensure that the hardware goes idle here first and then in resume, you need to make the hardware continue when it left before suspend.

Quoted 37 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +37 -0
+	return 0;
+}
+
+static int mtk_fd_resume(struct device *dev)
+{
+	struct mtk_fd_dev *fd_dev;
+	int ret;
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	fd_dev = dev_get_drvdata(dev);
+
+	if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+		ret = pm_runtime_get_sync(fd_dev->fd_hw.larb_dev);
+		if (ret) {
+			dev_dbg(&fd_dev->pdev->dev, "open larb clk failed\n");
+			return ret;
+		}
+
+		ret = clk_prepare_enable(fd_dev->fd_hw.fd_clk);
+		if (ret) {
+			dev_dbg(&fd_dev->pdev->dev, "open fd clk failed\n");
+			return ret;
+		}
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct dev_pm_ops mtk_fd_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(mtk_fd_suspend, mtk_fd_resume)
+	SET_RUNTIME_PM_OPS(mtk_fd_suspend, mtk_fd_resume, NULL)
+};
+
+static const struct of_device_id mtk_fd_of_ids[] = {

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	{ .compatible = "mediatek,mt8183-fd", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, mtk_fd_of_ids);
+
+static struct platform_driver mtk_fd_driver = {
+	.probe   = mtk_fd_probe,
+	.remove  = mtk_fd_remove,
+	.driver  = {
+		.name  = FD_DRVNAME,

Please just set the name explicitly here and remove the macro.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 1 line
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +1 -0
+		.of_match_table = mtk_fd_of_ids,

Please use of_match_ptr().

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		.pm = &mtk_fd_pm_ops,
+	}
+};
+module_platform_driver(mtk_fd_driver);
+
+MODULE_DESCRIPTION("Mediatek FD driver");
+MODULE_LICENSE("GPL");

GPL v2

Quoted 3 lines
Signature · 1 line
2.18.0
#13 lore raw

Re: [RFC PATCH V1 6/6] platform: mtk-isp: Add Mediatek FD driver

In reply to Tomasz Figa

Hi Tomasz,

Quoted 23 lines · Tomasz Figa

Hi Jerry,

Quoted 10 lines · Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds the driver of Face Detection (FD) unit in Mediatek camera system, providing face detection function.

The mtk-isp directory will contain drivers for multiple IP blocks found in Mediatek ISP system. It will include ISP Pass 1 driver (CAM), sensor interface driver, DIP driver and face detection driver.

Thanks for the patch.

First of all a general comment about the design:

My understanding is that this is a relatively straightforward memory-to-memory device that reads a video frame and detects faces on it. Such devices should be implemented as normal V4L2 memory-to-memory devices, with contexts (instances; pipes) represented by v4l2_fh.

Quoted 9 lines

Also, please replace the META_OUTPUT queue with proper V4L2 controls, as I don't think there is anything that we couldn't model using controls here.

The end result should be a V4L2 m2m driver (using the m2m helpers), where you get a new context (instance; pipe) whenever you open the video node, similar to codecs, video processors (like MTK MDP) and so on.

Also please see my comments inline.

I appreciate your comments,

FD driver will be implemented as a normal V4L2 m2m driver which has an IMAGE_OUTPUT queue and a META_CAPTURE queue(face result).

We will use the following properties.
/* Is a video mem-to-mem device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000

The original META_OUTPUT queue contains the following structure will be replaced by V4L2 controls,

/* FD_SCALE_NUM is 15. */

struct fd_user_param {
	uint8_t rip_feature;
	uint8_t gfd_skip;
	uint8_t dynamic_change_model;
	uint8_t scale_num_from_user;
	uint16_t source_img_width[FD_SCALE_NUM];
	uint16_t source_img_height[FD_SCALE_NUM];
} __packed; //share with co-processor

However, we found that testM2MFormats in the V4L2 compliance test will assume the capture queue has the same format as output queue has, therefore, FD driver's capture queue wouldn't be able to use META format or that test case will be failed.

// m2m devices are special in that the format is often per-filehandle. // But colorspace information should be passed from output to capture, // so test that.

	if (node->is_m2m)
		return testM2MFormats(node);

May we ask for your suggestions about this part?

Quoted 12 lines
Quoted 11 lines
---
 drivers/media/platform/mtk-isp/Makefile       |   16 +
 drivers/media/platform/mtk-isp/fd/Makefile    |   25 +
 .../media/platform/mtk-isp/fd/mtk_fd-dev.c    |  754 +++++++++++
 .../media/platform/mtk-isp/fd/mtk_fd-dev.h    |  315 +++++
 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h |  158 +++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.c   |  322 +++++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.h   |   39 +
 .../media/platform/mtk-isp/fd/mtk_fd-v4l2.c   | 1171 +++++++++++++++++
 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c |  555 ++++++++
Quoted 3 lines

This is a small driver. Please just put all the code in one file. (Except the smem stuff, which should go away.)

Ok, we will fix it.

Quoted 26 lines
Quoted 26 lines
 9 files changed, 3355 insertions(+)
 create mode 100644 drivers/media/platform/mtk-isp/Makefile
 create mode 100644 drivers/media/platform/mtk-isp/fd/Makefile
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-v4l2.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c
drivers/media/platform/mtk-isp/Makefile new file +9 -0
new file mode 100644
index 000000000000..5e3a9aa7f8b2
@@ -0,0 +1,16 @@
+#
+# Copyright (C) 2018 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
Quoted 9 lines

drivers/media/platform/mtk-isp/Makefile line 14

Quoted 5 lines
drivers/media/platform/mtk-isp/Makefile new file +5 -0
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+ifeq ($(CONFIG_VIDEO_MEDIATEK_FD_SUPPORT),y)

There is no value in having "SUPPORT" in the Kconfig symbol name. It just makes it unnecessarily long.

Ok, we will fix it.

Quoted 43 lines

drivers/media/platform/mtk-isp/Makefile line 16

Quoted 2 lines
drivers/media/platform/mtk-isp/Makefile new file +2 -0
+obj-y += fd/
+endif

You can just add this directly in drivers/media/platform/Makefile. No need for this intermediate file.

Also, the driver should be compilable as a module too.

Quoted 21 lines
drivers/media/platform/mtk-isp/fd/Makefile new file +15 -0
new file mode 100644
index 000000000000..f2b64cf53da9
@@ -0,0 +1,25 @@
+#
+# Copyright (C) 2018 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+$(info $(srctree))
+ccflags-y += -I$(srctree)/drivers/media/platform/mtk-mdp3
+

drivers/media/platform/mtk-isp/fd/Makefile line 25

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/Makefile new file +10 -0
+obj-y += mtk_fd_40.o
+obj-y += mtk_fd-v4l2.o
+
+# To provide alloc context managing memory shared
+# between CPU and camera coprocessor
+obj-y += mtk_fd-smem.o
+
+# Utilits to provide frame-based streaming model
+# with v4l2 user interfaces
+obj-y += mtk_fd-dev.o

This wouldn't work if the driver is compiled as a module. Please use something like if you have more than 1 object.

Quoted 6 lines
	mtk-fd-objs += list of .o objects

	obj-$(CONFIG_VIDEO_MEDIATEK_FD) += mtk-fd.o

Otherwise just use the last line directly.

Ok, we will fix it.

Quoted 14 lines
Quoted 14 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c new file +8 -0
new file mode 100644
index 000000000000..207e5d20ad46
@@ -0,0 +1,754 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Frederic Chen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c line 14

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c new file +6 -0
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */

No need for this text if there is SPDX.

Fixed.

Quoted 88 lines

[snip]

Quoted 87 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h new file +81 -0
new file mode 100644
index 000000000000..c13627f2bac4
@@ -0,0 +1,315 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Frederic Chen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _MTK_FD_DEV_H_
+#define _MTK_FD_DEV_H_
+
+#include <linux/types.h>
+#include <linux/platform_device.h>
+#include <media/v4l2-device.h>
+#include <media/videobuf2-v4l2.h>
+
+#include "mtk_fd-hw.h"
+#include "mtk_fd-smem.h"
+
+#define MTK_FD_PIPE_ID_STREAM_0				0
+#define MTK_FD_PIPE_ID_STREAM_1				1
+#define MTK_FD_PIPE_ID_TOTAL_NUM			2
+
+#define MTK_FD_VIDEO_NODE_ID_YUV_OUT			0
+#define MTK_FD_VIDEO_NODE_ID_CONFIG_OUT			1
+#define MTK_FD_VIDEO_NODE_ID_OUT_TOTAL_NUM		2
+#define MTK_FD_VIDEO_NODE_ID_CAPTURE			2
+#define MTK_FD_VIDEO_NODE_ID_CAPTURE_TOTAL_NUM		1
+#define MTK_FD_VIDEO_NODE_ID_TOTAL_NUM \
+	(MTK_FD_VIDEO_NODE_ID_OUT_TOTAL_NUM + \
+	MTK_FD_VIDEO_NODE_ID_CAPTURE_TOTAL_NUM)
+
+#define MTK_FD_VIDEO_NODE_ID_NO_MASTER			-1
+
+#define MTK_FD_OUTPUT_MIN_WIDTH				2U
+#define MTK_FD_OUTPUT_MIN_HEIGHT			2U
+#define MTK_FD_OUTPUT_MAX_WIDTH				5376U
+#define MTK_FD_OUTPUT_MAX_HEIGHT			4032U
+#define MTK_FD_CAPTURE_MIN_WIDTH			2U
+#define MTK_FD_CAPTURE_MIN_HEIGHT			2U
+#define MTK_FD_CAPTURE_MAX_WIDTH			5376U
+#define MTK_FD_CAPTURE_MAX_HEIGHT			4032U
+
+#define MTK_FD_PIPE_MEDIA_MODEL_NAME	"MTK-FD-V4L2"
+#define MTK_FD_PIPE_NAME_STREAM_0	MTK_FD_PIPE_MEDIA_MODEL_NAME
+#define MTK_FD_PIPE_NAME_STREAM_1	"MTK-FD-V4L2-STREAM-1"
+
+#define MTK_FD_DEV_META_BUF_DEFAULT_SIZE		(1110 * 1024)
+
+/*
+ * Supported format and the information used for
+ * size calculation
+ */
+struct mtk_fd_dev_meta_format {
+	u32 dataformat;
+	u32 max_buffer_size;
+	u8 flags;
+};
+
+/* MDP part private format definitation */
+struct mtk_fd_dev_mdp_format {
+	u32 pixelformat;
+	u32 mdp_color;
+	u32 colorspace;
+	u8 depth[VIDEO_MAX_PLANES];
+	u8 row_depth[VIDEO_MAX_PLANES];
+	u8 num_planes;
+	u8 walign;
+	u8 halign;
+	u8 salign;
+	u32 flags;
+};
+
+struct mtk_fd_dev_format {
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h line 86

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h new file +5 -0
+	union {
+		struct mtk_fd_dev_meta_format meta;
+		struct mtk_fd_dev_mdp_format img;
+	} fmt;
+};

This looks like a copy/paste from the DIP driver. Please merge the 3 structures above into 1 as suggested in review of that driver.

Ok, will be fixed in next patch.

Quoted 1,024 lines

[snip]

Quoted 46 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h new file +40 -0
new file mode 100644
index 000000000000..40e09d66c479
@@ -0,0 +1,158 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Copyright (C) 2015 MediaTek Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __MTK_FD_HW_H__
+#define __MTK_FD_HW_H__
+
+#include <linux/io.h>
+#define SIG_ERESTARTSYS 512
+
+#define FD_WR32(v, a) \
+do { \
+	__raw_writel((v), (void __force __iomem *)((a))); \
+	mb(); /* ensure written */ \
+} while (0)
+
+#define FD_RD32(addr) ioread32((void *)addr)
+
+#define FD_INT_EN		0x15c
+#define FD_INT			0x168
+#define FD_RESULT		0x178
+#define FD_IRQ_MASK		0x001
+
+#define RS_BUF_SIZE_MAX		2288788
+#define VA_OFFSET		0xffff000000000000
+
+#define MTK_FD_MAX_NO		1024
+#define MAX_FACE_SEL_NUM	(MTK_FD_MAX_NO + 2)
+
+/* The max number of face sizes could be detected, for feature scaling */
+#define FACE_SIZE_NUM_MAX	14

drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h line 50

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h new file +10 -0
+
+/* FACE_SIZE_NUM_MAX + 1, first scale for input image W/H */
+#define FD_SCALE_NUM		15
+
+/* Number of Learning data sets */
+#define LEARNDATA_NUM		18
+
+#define mtk_fd_us_to_jiffies(us) \
+	((((unsigned long)(us) / 1000) * HZ + 512) >> 10)
+

Uhm, looking at the arbitrary numbers involved in this computation I'm afraid to even ask what this macro is expected to do.

Judging by the name, why not just use usecs_to_jiffies()?

[snip]

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +0 -0
new file mode 100644
index 000000000000..758a4ab68ec2
@@ -0,0 +1,39 @@

[snip]

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+
+struct mtk_fd_smem_dev {
+	struct device dev;
+	struct sg_table sgt;
+	struct page **smem_pages;
+	int num_smem_pages;
+	phys_addr_t smem_base;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h line 37

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	dma_addr_t smem_dma_base;
+	int smem_size;
+};
+
+phys_addr_t mtk_fd_smem_iova_to_phys(struct mtk_fd_smem_dev *smem_dev,
+				     dma_addr_t iova);
+int mtk_fd_smem_alloc_dev_init(struct mtk_fd_smem_dev *smem_dev,
+			       struct device *default_alloc_dev);
+void mtk_fd_smem_alloc_dev_release(struct mtk_fd_smem_dev *smem_dev);
+

Please remove this custom smem thing as we should just use dma_alloc_*() from the right struct device attached to the right reserved memory pool.

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+static int mtk_fd_videoc_enum_fmt(struct file *file, void *fh,
+				  struct v4l2_fmtdesc *f)

It's "vidioc".

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);
+
+	if (f->index > node->desc->num_fmts ||
+	    f->type != node->dev_q.vbq.type)

No need to check the type.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 13 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +13 -0
+		return -EINVAL;
+
+	strscpy(f->description, node->desc->description,
+		sizeof(f->description));
+
+	f->pixelformat = node->desc->fmts[f->index].fmt.img.pixelformat;
+	f->flags = 0;
+
+	return 0;
+}
+
+static int mtk_fd_meta_enum_format(struct file *file,
+				   void *fh, struct v4l2_fmtdesc *f)

Please name the functions consistently. Above it has the vidioc prefix (with typo) and enum_fmt, but here it doesn't have a prefix and is enum_format.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);
+
+	if (f->index > 0 || f->type != node->dev_q.vbq.type)

There is no need to check the type, as the core should already check it for you.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+		return -EINVAL;
+
+	strscpy(f->description, node->desc->description,
+		sizeof(f->description));
+
+	f->pixelformat = node->vdev_fmt.fmt.meta.dataformat;

Also set flags to 0.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	return 0;
+}
+
+static int mtk_fd_videoc_g_meta_fmt(struct file *file,
+				    void *fh, struct v4l2_format *f)
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);

The Linux coding style requires 1 blank line between variable declarations and code.

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	*f = node->vdev_fmt;
+
+	return 0;
+}
+
+static int

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+mtk_fd_vidioc_subscribe_event(struct v4l2_fh *fh,
+			      const struct v4l2_event_subscription *sub)
+{
+	switch (sub->type) {
+	case V4L2_EVENT_CTRL:
+		return v4l2_ctrl_subscribe_event(fh, sub);
+	default:
+		return -EINVAL;
+	}
+}

This driver doesn't seem to support any controls, so there is no point in supporting the above event.

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 12 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +12 -0
+static void mtk_fd_node_to_v4l2(struct mtk_fd_pipe *fd_pipe,
+				u32 idx,
+				 struct video_device *vdev,
+				 struct v4l2_format *f)
+{
+	struct mtk_fd_video_device *node = &fd_pipe->nodes[idx];
+
+	vdev->ioctl_ops = node->desc->ops;
+	vdev->device_caps = V4L2_CAP_STREAMING | node->desc->cap;
+	f->type = node->desc->buf_type;
+	mtk_fd_pipe_load_default_fmt(fd_pipe, node, f);
+}

This function is only called once, is very short and has a very misleading name (this kind of name is used for functions that convert things). Just move the code back to the caller.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+int mtk_fd_dev_media_register(struct device *dev,
+			      struct media_device *media_dev,
+			      const char *model)
+{
+	int ret = 0;
+
+	media_dev->dev = dev;
+	dev_dbg(dev, "setup media_dev.dev: %p\n",
+		media_dev->dev);

I don't think these logs every second line are useful even for debugging. Please remove.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	strlcpy(media_dev->model, model,
+		sizeof(media_dev->model));

No need to pass model here as an argument. Just write the string here directly.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+	dev_dbg(dev, "setup media_dev.model: %s\n",
+		media_dev->model);
+
+	snprintf(media_dev->bus_info, sizeof(media_dev->bus_info),
+		 "platform:%s", dev_name(dev));
+	dev_dbg(dev, "setup media_dev.bus_info: %s\n",
+		media_dev->bus_info);
+
+	media_dev->hw_revision = 0;
+	dev_dbg(dev, "setup media_dev.hw_revision: %d\n",
+		media_dev->hw_revision);

No need to explicitly initialize to 0.

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+
+	media_dev->ops = &mtk_fd_media_req_ops;
+
+	dev_dbg(dev, "media_device_init: media_dev:%p\n",
+		media_dev);
+	media_device_init(media_dev);
+
+	pr_debug("Register media device: %s, %p",
+		 media_dev->model,
+		media_dev);
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	ret = media_device_register(media_dev);
+
+	if (ret) {
+		dev_err(dev, "failed to register media device (%d)\n", ret);
+		goto fail_media_dev;
+	}
+	return 0;
+
+fail_media_dev:
+	media_device_unregister(media_dev);

We jump here even if media_device_register() failed. Unregistering something that wasn't registered doesn't sound like a good idea.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	media_device_cleanup(media_dev);
+
+	return ret;
+}

There isn't much happening in this function. Perhaps just move the code back to the caller?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+
+int mtk_fd_dev_v4l2_register(struct device *dev,
+			     struct media_device *media_dev,
+			     struct v4l2_device *v4l2_dev)
+{
+	int ret = 0;

Add a blank line between variable declarations and code.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	/* Set up v4l2 device */
+	v4l2_dev->mdev = media_dev;
+	dev_dbg(dev, "setup v4l2_dev->mdev: %p",
+		v4l2_dev->mdev);

Please clean up such debugging messages, it makes it much harder to review the code.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 1 line
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +1 -0
+	v4l2_dev->ctrl_handler = NULL;

No need for explicit NULL assignments, as the structure was zero-filled already.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	dev_dbg(dev, "setup v4l2_dev->ctrl_handler: %p",
+		v4l2_dev->ctrl_handler);
+
+	pr_debug("Register v4l2 device: %p",
+		 v4l2_dev);

dev_dbg()? But I would still just remove it.

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+
+	ret = v4l2_device_register(dev, v4l2_dev);
+
+	if (ret) {
+		dev_err(dev, "failed to register V4L2 device (%d)\n", ret);
+		goto fail_v4l2_dev;
+	}

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+	return 0;
+
+fail_v4l2_dev:
+	media_device_unregister(media_dev);
+	media_device_cleanup(media_dev);
+
+	return ret;
+}
+

There isn't much happening in this function. Perhaps just move the code back to the caller?

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+int mtk_fd_pipe_v4l2_register(struct mtk_fd_pipe *fd_pipe,
+			      struct media_device *media_dev,
+			      struct v4l2_device *v4l2_dev)
+{
+	int i, ret;
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	/* Initialize miscellaneous variables */
+	fd_pipe->streaming = 0;
+
+	/* Initialize subdev media entity */
+	fd_pipe->subdev_pads = kcalloc(fd_pipe->num_nodes,
+				       sizeof(*fd_pipe->subdev_pads),
+					GFP_KERNEL);
+	if (!fd_pipe->subdev_pads) {
+		ret = -ENOMEM;
+		goto fail_subdev_pads;

There isn't anything to clean up at this point, so just return.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 9 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +9 -0
+	}
+
+	ret = media_entity_pads_init(&fd_pipe->subdev.entity,
+				     fd_pipe->num_nodes,
+				     fd_pipe->subdev_pads);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,
+			"failed initialize subdev media entity (%d)\n", ret);
+		goto fail_media_entity;

Please name the labels after the next cleanup step to happen after jumping to it.

Quoted 16 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +16 -0
+	}
+
+	/* Initialize subdev */
+	v4l2_subdev_init(&fd_pipe->subdev, &mtk_fd_subdev_ops);
+
+	fd_pipe->subdev.entity.function =
+		MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
+
+	fd_pipe->subdev.entity.ops = &mtk_fd_media_ops;
+
+	for (i = 0; i < fd_pipe->num_nodes; i++) {
+		struct mtk_fd_video_device_desc *desc =
+			fd_pipe->nodes[i].desc;
+
+		fd_pipe->subdev_pads[i].flags =
+			V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
+	}
+
+	fd_pipe->subdev.flags =
+		V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
+	snprintf(fd_pipe->subdev.name, sizeof(fd_pipe->subdev.name),
+		 "%s", fd_pipe->desc->name);
+	v4l2_set_subdevdata(&fd_pipe->subdev, fd_pipe);
+	fd_pipe->subdev.ctrl_handler = NULL;
+	fd_pipe->subdev.internal_ops = &mtk_fd_subdev_internal_ops;

The above code registers a subdev, so it sounds like it could be a separate function.

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	dev_dbg(&fd_pipe->fd_dev->pdev->dev,
+		"register subdev: %s, ctrl_handler %p\n",
+		 fd_pipe->subdev.name, fd_pipe->subdev.ctrl_handler);
+	ret = v4l2_device_register_subdev(&fd_pipe->fd_dev->v4l2_dev,
+					  &fd_pipe->subdev);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			"failed initialize subdev (%d)\n", ret);
+		goto fail_subdev;
+	}
+
+	ret = v4l2_device_register_subdev_nodes(&fd_pipe->fd_dev->v4l2_dev);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,
+			"failed to register subdevs (%d)\n", ret);
+		goto fail_subdevs;
+	}

This isn't per-pipe, but global for the whole v4l2_device. It should be called after all subdevs are fully initialized, to expose the device nodes to the userspace atomically.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	/* Create video nodes and links */
+	for (i = 0; i < fd_pipe->num_nodes; i++) {

Please move the contents of the loop into a separate function that handles one node.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+		struct mtk_fd_video_device *node = &fd_pipe->nodes[i];
+		struct video_device *vdev = &node->vdev;
+		struct vb2_queue *vbq = &node->dev_q.vbq;
+		struct mtk_fd_video_device_desc *desc = node->desc;
+		u32 flags;
+
+		/* Initialize miscellaneous variables */
+		mutex_init(&node->dev_q.lock);

Please just use the video_device lock for vb2 queues too. It simplifies the overall driver locking and doesn't really have any practical performance difference.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+		/* Initialize formats to default values */
+		mtk_fd_node_to_v4l2(fd_pipe, i, vdev, &node->vdev_fmt);
+
+		/* Initialize media entities */
+		ret = media_entity_pads_init(&vdev->entity, 1, &node->vdev_pad);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,

This kind of long chains of pointer dereferences signal a problem in the design of driver structures and/or function arguments.

I'd suggest passing fd_dev to this function and also storing dev instead of pdev inside fd_dev.

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+				"failed initialize media entity (%d)\n", ret);
+			goto fail_vdev_media_entity;
+		}
+
+		node->vdev_pad.flags = V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?
+			MEDIA_PAD_FL_SOURCE : MEDIA_PAD_FL_SINK;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		vdev->entity.ops = NULL;
+
+		/* Initialize vbq */
+		vbq->type = node->vdev_fmt.type;
+		vbq->io_modes = VB2_MMAP | VB2_DMABUF;
+		vbq->ops = &mtk_fd_vb2_ops;
+		vbq->mem_ops = &vb2_dma_contig_memops;
+		vbq->supports_requests = true;
+		vbq->buf_struct_size = sizeof(struct mtk_fd_dev_buffer);
+		vbq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;

This is a mem2mem device so the timestamps should be copied from OUTPUT to CAPTURE. Please set the flag appropriately.

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+		vbq->min_buffers_needed = 0;
+		/* Put the process hub sub device in the vb2 private data*/
+		vbq->drv_priv = fd_pipe;
+		vbq->lock = &node->dev_q.lock;
+		ret = vb2_queue_init(vbq);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,
+				"failed to initialize video queue (%d)\n", ret);

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			goto fail_vdev;
+		}
+
+		/* Initialize vdev */
+		snprintf(vdev->name, sizeof(vdev->name), "%s %s",
+			 fd_pipe->desc->name,
+			 node->desc->name);
+		vdev->release = video_device_release_empty;
+		vdev->fops = &mtk_fd_v4l2_fops;
+		vdev->lock = &node->dev_q.lock;

Aha, so it's in fact the same lock. Please move it to the "node" struct then.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		vdev->ctrl_handler = NULL;
+		vdev->v4l2_dev = &fd_pipe->fd_dev->v4l2_dev;
+		vdev->queue = &node->dev_q.vbq;
+		vdev->vfl_dir = V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?
+			VFL_DIR_TX : VFL_DIR_RX;
+		video_set_drvdata(vdev, fd_pipe);
+		pr_debug("register vdev: %s\n", vdev->name);

dev_dbg()?

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+		ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,
+				"failed to register video device (%d)\n", ret);
+			goto fail_vdev;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		}
+
+		/* Create link between video node and the subdev pad */
+		flags = 0;
+		if (desc->dynamic)
+			flags |= MEDIA_LNK_FL_DYNAMIC;
+		if (node->enabled)
+			flags |= MEDIA_LNK_FL_ENABLED;
+		if (node->immutable)
+			flags |= MEDIA_LNK_FL_IMMUTABLE;

Wouldn't all the nodes be always ENABLED and IMMUTABLE and not DYNAMIC for this driver?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+		if (V4L2_TYPE_IS_OUTPUT(desc->buf_type))
+			ret = media_create_pad_link(&vdev->entity, 0,
+						    &fd_pipe->subdev.entity,
+						    i, flags);
+		else
+			ret = media_create_pad_link(&fd_pipe->subdev.entity,
+						    i, &vdev->entity, 0,
+						    flags);
+

No need for this blank line.

Quoted 13 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +13 -0
+		if (ret)
+			goto fail_link;
+	}
+
+	return 0;
+
+	for (; i >= 0; i--) {
+fail_link:
+		video_unregister_device(&fd_pipe->nodes[i].vdev);
+fail_vdev:
+		vb2_queue_release(&fd_pipe->nodes[i].dev_q.vbq);
+		media_entity_cleanup(&fd_pipe->nodes[i].vdev.entity);
+fail_vdev_media_entity:

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		mutex_destroy(&fd_pipe->nodes[i].dev_q.lock);
+	}
+fail_subdevs:
+	v4l2_device_unregister_subdev(&fd_pipe->subdev);
+fail_subdev:
+	media_entity_cleanup(&fd_pipe->subdev.entity);
+fail_media_entity:
+	kfree(fd_pipe->subdev_pads);
+fail_subdev_pads:
+	v4l2_device_unregister(&fd_pipe->fd_dev->v4l2_dev);

We haven't registered the v4l2_device in this function.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	pr_err("fail_v4l2_dev: media_device_unregister and clenaup:%p",
+	       &fd_pipe->fd_dev->mdev);

Error messages should be printed at the place of the failure.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	media_device_unregister(&fd_pipe->fd_dev->mdev);
+	media_device_cleanup(&fd_pipe->fd_dev->mdev);

We haven't registered or initialized media_device in this function.

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+
+	return ret;
+}
+
+int mtk_fd_pipe_v4l2_unregister(struct mtk_fd_pipe *fd_pipe)
+{
+	unsigned int i;
+
+	for (i = 0; i < fd_pipe->num_nodes; i++) {
+		video_unregister_device(&fd_pipe->nodes[i].vdev);
+		vb2_queue_release(&fd_pipe->nodes[i].dev_q.vbq);

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		media_entity_cleanup(&fd_pipe->nodes[i].vdev.entity);
+		mutex_destroy(&fd_pipe->nodes[i].dev_q.lock);
+	}
+
+	v4l2_device_unregister_subdev(&fd_pipe->subdev);
+	media_entity_cleanup(&fd_pipe->subdev.entity);
+	kfree(fd_pipe->subdev_pads);
+	v4l2_device_unregister(&fd_pipe->fd_dev->v4l2_dev);
+	media_device_unregister(&fd_pipe->fd_dev->mdev);
+	media_device_cleanup(&fd_pipe->fd_dev->mdev);

Please make this consistent with the registration functions. For each registration function there should be a matching unregister function that cleans up only whatever was registered in that function.

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	return 0;
+}
+
+void mtk_fd_v4l2_buffer_done(struct vb2_buffer *vb,
+			     enum vb2_buffer_state state)
+{
+	struct mtk_fd_pipe *fd_pipe;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	struct mtk_fd_video_device *node;
+
+	fd_pipe = vb2_get_drv_priv(vb->vb2_queue);
+	node = mtk_fd_vbq_to_node(vb->vb2_queue);
+	dev_dbg(&fd_pipe->fd_dev->pdev->dev,
+		"%s:%s: return buf, idx(%d), state(%d)\n",
+		fd_pipe->desc->name, node->desc->name,
+		vb->index, state);
+	vb2_buffer_done(vb, state);
+}

No need for this function. Just call vb2_buffer_done() directly from the caller. (I already mentioned this in MTK DIP driver review. Please coordinate with other driver owners and make sure that similar comments are addressed in all drivers...)

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 12 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +12 -0
+
+/********************************************
+ * MTK FD V4L2 Settings *
+ ********************************************/
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_video_out_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+	.vidioc_enum_framesizes = mtk_fd_videoc_enum_framesizes,
+	.vidioc_enum_fmt_vid_cap_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_cap_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_cap_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_cap_mplane = mtk_fd_videoc_try_fmt,

No need for *cap* ops if this is only for an OUTPUT device.

Quoted 32 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +32 -0
+	.vidioc_enum_fmt_vid_out_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_out_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_out_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_out_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+	.vidioc_subscribe_event = mtk_fd_vidioc_subscribe_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+
+};
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_video_cap_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+	.vidioc_enum_framesizes = mtk_fd_videoc_enum_framesizes,
+	.vidioc_enum_fmt_vid_cap_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_cap_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_cap_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_cap_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_enum_fmt_vid_out_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_out_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_out_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_out_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+	.vidioc_subscribe_event = mtk_fd_vidioc_subscribe_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+
+};

This structure is unused.

Quoted 38 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +38 -0
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_meta_out_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+
+	.vidioc_enum_fmt_meta_cap = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_enum_fmt_meta_out = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+};
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_meta_cap_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+
+	.vidioc_enum_fmt_meta_cap = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_enum_fmt_meta_out = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+};

Aren't the 2 structures above identical? Should be merged if so.

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+int mtk_fd_dev_v4l2_init(struct mtk_fd_dev *fd_dev)
+{
+	struct media_device *media_dev;
+	struct v4l2_device *v4l2_dev;
+	struct mtk_fd_smem_dev *smem_alloc_dev = &fd_dev->smem_alloc_dev;
+	int i;
+	int ret = 0;

Please don't initialize local variables unless that's needed by the logic. It prevents the compiler from detecting missing assignments.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	media_dev = &fd_dev->mdev;
+	v4l2_dev = &fd_dev->v4l2_dev;

Just pass fd_dev to the functions below. No need to extract only some fields.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	ret = mtk_fd_dev_media_register(&fd_dev->pdev->dev,
+					media_dev,
+					 MTK_FD_PIPE_MEDIA_MODEL_NAME);

We should bail out on error.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	ret = mtk_fd_dev_v4l2_register(&fd_dev->pdev->dev,
+				       media_dev,
+					v4l2_dev);

We should clean up the previous steps and bail out on error.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	ret = mtk_fd_smem_alloc_dev_init(smem_alloc_dev, &fd_dev->pdev->dev);

Ditto.

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+	for (i = 0; i < MTK_FD_PIPE_ID_TOTAL_NUM; i++) {
+		ret = mtk_fd_pipe_init(&fd_dev->fd_pipe[i], fd_dev,
+				       &pipe_settings[i],
+					media_dev, v4l2_dev, smem_alloc_dev);
+		if (ret) {
+			dev_err(&fd_dev->pdev->dev,
+				"%s: Pipe id(%d) init failed(%d)\n",
+				fd_dev->fd_pipe[i].desc->name,
+				i, ret);

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+void mtk_fd_dev_v4l2_release(struct mtk_fd_dev *fd_dev)
+{
+	int i = 0;

No need for initialization.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	if (fd_dev)

Why could it ever be NULL?

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+		for (i = 0; i < MTK_FD_PIPE_ID_TOTAL_NUM; i++)
+			mtk_fd_pipe_release(&fd_dev->fd_pipe[i]);
+
+	mtk_fd_smem_alloc_dev_release(&fd_dev->smem_alloc_dev);
+}
+

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+static int mtk_fd_probe(struct platform_device *pdev)
+{
+	struct mtk_fd_dev *fd_dev;
+	struct mtk_fd_hw *fd_hw;
+	struct device_node *node;
+	struct platform_device *larb_pdev;
+	int irq_num;
+	int ret;
+
+	fd_dev = devm_kzalloc(&pdev->dev, sizeof(*fd_dev), GFP_KERNEL);
+

nit: No need for this blank line, because the if below is directly related.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+	if (!fd_dev)
+		return -ENOMEM;
+
+	dev_set_drvdata(&pdev->dev, fd_dev);
+	fd_hw = &fd_dev->fd_hw;
+
+	if (!fd_hw) {

How is this possible for a struct member?

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		dev_err(&pdev->dev, "Unable to allocate fd_hw\n");
+		return -ENOMEM;
+	}
+
+	fd_dev->pdev = pdev;
+
+	irq_num = irq_of_parse_and_map(pdev->dev.of_node, FD_IRQ_IDX);

We should use platform_get_irq() here instead, because the IRQs were already parsed for us when the platform core created the platform_device.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	ret = request_irq(irq_num, (irq_handler_t)mtk_fd_irq,
+			  IRQF_TRIGGER_NONE, FD_DRVNAME, fd_hw);

It should be a device name, not driver name. One would normally use dev_name() here.

Also devm_request_irq() should simplify the cleanup.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+	if (ret) {
+		dev_dbg(&pdev->dev, "%s request_irq fail, irq=%d\n",
+			__func__, irq_num);

This is an error, so dev_err().

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+		return ret;
+	}
+	dev_dbg(&pdev->dev, "irq_num=%d\n", irq_num);

That's probably not very useful.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 13 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +13 -0
+
+	node = of_parse_phandle(pdev->dev.of_node, "mediatek,larb", 0);
+	if (!node) {
+		dev_err(&pdev->dev, "no mediatek, larb found");
+		return -EINVAL;
+	}
+	larb_pdev = of_find_device_by_node(node);
+	if (!larb_pdev) {
+		dev_err(&pdev->dev, "no mediatek, larb device found");
+		return -EINVAL;
+	}
+	fd_hw->larb_dev = &larb_pdev->dev;
+

LARBs are handled automatically by the IOMMU driver, no need to do anything with them explicitly anymore.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+	node = pdev->dev.of_node;
+	if (!node) {
+		dev_err(&pdev->dev, "find fd node failed!!!\n");
+		return -ENODEV;
+	}
+
+	fd_hw->fd_base = of_iomap(node, 0);

One would normally use platform_get_resource() and devm_ioremap_resource() here.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	if (!fd_hw->fd_base) {
+		dev_err(&pdev->dev, "unable to map fd node!!!\n");
+		return -ENODEV;
+	}
+
+	dev_dbg(&pdev->dev, "fd_hw->fd_base: %lx\n",
+		(unsigned long)fd_hw->fd_base);

Not very useful either.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	fd_hw->fd_clk = devm_clk_get(&pdev->dev, "FD_CLK_IMG_FD");

Clock names should be lowercase and name just inputs of the IP block, so simply "fd", should be enough.

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	if (IS_ERR(fd_hw->fd_clk)) {
+		dev_err(&pdev->dev, "cannot get FD_CLK_IMG_FD clock\n");
+		return PTR_ERR(fd_hw->fd_clk);
+	}

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+
+	pm_runtime_enable(&pdev->dev);
+	atomic_set(&fd_hw->fd_user_cnt, 0);
+	init_waitqueue_head(&fd_hw->wq);
+	mutex_init(&fd_hw->fd_hw_lock);
+	fd_hw->fd_irq_result = 0;
+
+	ret = mtk_fd_dev_v4l2_init(fd_dev);
+	if (ret)
+		dev_err(&pdev->dev, "v4l2 init failed: %d\n", ret);

We should clean up and return the error code, not 0.

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	dev_info(&pdev->dev, "Mediatek Camera FD driver probe.\n");
+
+	return 0;

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+}
+
+static int mtk_fd_remove(struct platform_device *pdev)
+{
+	int irq_i4;
+	struct mtk_fd_dev *fd_dev = dev_get_drvdata(&pdev->dev);
+
+	if (fd_dev) {
+		mtk_fd_dev_v4l2_release(fd_dev);
+	} else {

This is impossible.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		dev_err(&pdev->dev, "Can't find fd driver data\n");
+		return -EINVAL;
+	}
+
+	mutex_destroy(&fd_dev->fd_hw.fd_hw_lock);
+	pm_runtime_disable(&pdev->dev);
+
+	irq_i4 = platform_get_irq(pdev, 0);
+	free_irq(irq_i4, NULL);
+	kfree(fd_dev);

fd_dev was allocated using devm_kzalloc(), no need to free it explicitly.

Quoted 9 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +9 -0
+
+	return 0;
+}
+
+static int mtk_fd_suspend(struct device *dev)
+{
+	struct mtk_fd_dev *fd_dev;
+	int ret;
+

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	fd_dev = dev_get_drvdata(dev);
+
+	if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+		ret = pm_runtime_put_sync(fd_dev->fd_hw.larb_dev);
+		clk_disable_unprepare(fd_dev->fd_hw.fd_clk);
+		return ret;
+	}

This isn't going to work, because the hardware may be still processing a frame at this point. You need a way to ensure that the hardware goes idle here first and then in resume, you need to make the hardware continue when it left before suspend.

Quoted 37 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +37 -0
+	return 0;
+}
+
+static int mtk_fd_resume(struct device *dev)
+{
+	struct mtk_fd_dev *fd_dev;
+	int ret;
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	fd_dev = dev_get_drvdata(dev);
+
+	if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+		ret = pm_runtime_get_sync(fd_dev->fd_hw.larb_dev);
+		if (ret) {
+			dev_dbg(&fd_dev->pdev->dev, "open larb clk failed\n");
+			return ret;
+		}
+
+		ret = clk_prepare_enable(fd_dev->fd_hw.fd_clk);
+		if (ret) {
+			dev_dbg(&fd_dev->pdev->dev, "open fd clk failed\n");
+			return ret;
+		}
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct dev_pm_ops mtk_fd_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(mtk_fd_suspend, mtk_fd_resume)
+	SET_RUNTIME_PM_OPS(mtk_fd_suspend, mtk_fd_resume, NULL)
+};
+
+static const struct of_device_id mtk_fd_of_ids[] = {

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+	{ .compatible = "mediatek,mt8183-fd", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, mtk_fd_of_ids);
+
+static struct platform_driver mtk_fd_driver = {
+	.probe   = mtk_fd_probe,
+	.remove  = mtk_fd_remove,
+	.driver  = {
+		.name  = FD_DRVNAME,

Please just set the name explicitly here and remove the macro.

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 1 line
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +1 -0
+		.of_match_table = mtk_fd_of_ids,

Please use of_match_ptr().

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		.pm = &mtk_fd_pm_ops,
+	}
+};
+module_platform_driver(mtk_fd_driver);
+
+MODULE_DESCRIPTION("Mediatek FD driver");
+MODULE_LICENSE("GPL");

GPL v2

Quoted 3 lines
Signature · 1 line
2.18.0
#14 lore raw

Re: [RFC PATCH V1 6/6] platform: mtk-isp: Add Mediatek FD driver

In reply to Tomasz Figa

Hi Tomasz,

Quoted 23 lines · Tomasz Figa

Hi Jerry,

Quoted 10 lines · Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds the driver of Face Detection (FD) unit in Mediatek camera system, providing face detection function.

The mtk-isp directory will contain drivers for multiple IP blocks found in Mediatek ISP system. It will include ISP Pass 1 driver (CAM), sensor interface driver, DIP driver and face detection driver.

Thanks for the patch.

First of all a general comment about the design:

My understanding is that this is a relatively straightforward memory-to-memory device that reads a video frame and detects faces on it. Such devices should be implemented as normal V4L2 memory-to-memory devices, with contexts (instances; pipes) represented by v4l2_fh.

Quoted 9 lines

Also, please replace the META_OUTPUT queue with proper V4L2 controls, as I don't think there is anything that we couldn't model using controls here.

The end result should be a V4L2 m2m driver (using the m2m helpers), where you get a new context (instance; pipe) whenever you open the video node, similar to codecs, video processors (like MTK MDP) and so on.

Also please see my comments inline.

I appreciate your comments,
sorry for sending the previous two unfinished mail...

FD driver will be implemented as a normal V4L2 m2m driver which has an IMAGE_OUTPUT queue and a META_CAPTURE queue(face result).

We will use the following properties.
/* Is a video mem-to-mem device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000

The original META_OUTPUT queue contains the following structure will be replaced by V4L2 controls,

/* FD_SCALE_NUM is 15. */

struct fd_user_param {
	uint8_t rip_feature;
	uint8_t gfd_skip;
	uint8_t dynamic_change_model;
	uint8_t scale_num_from_user;
	uint16_t source_img_width[FD_SCALE_NUM];
	uint16_t source_img_height[FD_SCALE_NUM];
} __packed; //share with co-processor

However, we found that testM2MFormats() in the V4L2 compliance test will assume the capture queue has the same format as output queue has, therefore, FD driver's capture queue wouldn't be able to use META format or the v4l2 test will be failed.

reference: v4l2-compliance/v4l2-test-formats.cpp
// m2m devices are special in that the format is often per-filehandle. // But colorspace information should be passed from output to capture, // so test that.

	if (node->is_m2m)
		return testM2MFormats(node);

May we ask for your suggestions about this part?

Quoted 12 lines
Quoted 11 lines
---
 drivers/media/platform/mtk-isp/Makefile       |   16 +
 drivers/media/platform/mtk-isp/fd/Makefile    |   25 +
 .../media/platform/mtk-isp/fd/mtk_fd-dev.c    |  754 +++++++++++
 .../media/platform/mtk-isp/fd/mtk_fd-dev.h    |  315 +++++
 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h |  158 +++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.c   |  322 +++++
 .../media/platform/mtk-isp/fd/mtk_fd-smem.h   |   39 +
 .../media/platform/mtk-isp/fd/mtk_fd-v4l2.c   | 1171 +++++++++++++++++
 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c |  555 ++++++++
Quoted 3 lines

This is a small driver. Please just put all the code in one file. (Except the smem stuff, which should go away.)

Ok, we will fix it.

Quoted 35 lines
Quoted 21 lines
 9 files changed, 3355 insertions(+)
 create mode 100644 drivers/media/platform/mtk-isp/Makefile
 create mode 100644 drivers/media/platform/mtk-isp/fd/Makefile
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd-v4l2.c
 create mode 100644 drivers/media/platform/mtk-isp/fd/mtk_fd_40.c
drivers/media/platform/mtk-isp/Makefile new file +4 -0
new file mode 100644
index 000000000000..5e3a9aa7f8b2
@@ -0,0 +1,16 @@
+#
+# Copyright (C) 2018 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify

drivers/media/platform/mtk-isp/Makefile line 14

Quoted 10 lines
drivers/media/platform/mtk-isp/Makefile new file +10 -0
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+ifeq ($(CONFIG_VIDEO_MEDIATEK_FD_SUPPORT),y)

There is no value in having "SUPPORT" in the Kconfig symbol name. It just makes it unnecessarily long.

Quoted 8 lines

drivers/media/platform/mtk-isp/Makefile line 16

Quoted 2 lines
drivers/media/platform/mtk-isp/Makefile new file +2 -0
+obj-y += fd/
+endif

You can just add this directly in drivers/media/platform/Makefile. No need for this intermediate file.

Also, the driver should be compilable as a module too.

Ok, we will fix it.

Quoted 35 lines
Quoted 21 lines
drivers/media/platform/mtk-isp/fd/Makefile new file +15 -0
new file mode 100644
index 000000000000..f2b64cf53da9
@@ -0,0 +1,25 @@
+#
+# Copyright (C) 2018 MediaTek Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+$(info $(srctree))
+ccflags-y += -I$(srctree)/drivers/media/platform/mtk-mdp3
+

drivers/media/platform/mtk-isp/fd/Makefile line 25

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/Makefile new file +10 -0
+obj-y += mtk_fd_40.o
+obj-y += mtk_fd-v4l2.o
+
+# To provide alloc context managing memory shared
+# between CPU and camera coprocessor
+obj-y += mtk_fd-smem.o
+
+# Utilits to provide frame-based streaming model
+# with v4l2 user interfaces
+obj-y += mtk_fd-dev.o

This wouldn't work if the driver is compiled as a module. Please use something like if you have more than 1 object.

Quoted 6 lines
	mtk-fd-objs += list of .o objects

	obj-$(CONFIG_VIDEO_MEDIATEK_FD) += mtk-fd.o

Otherwise just use the last line directly.

Ok, we will fix it.

Quoted 14 lines
Quoted 14 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c new file +8 -0
new file mode 100644
index 000000000000..207e5d20ad46
@@ -0,0 +1,754 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Frederic Chen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c line 14

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.c new file +6 -0
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */

No need for this text if there is SPDX.

Fixed.

Quoted 88 lines

[snip]

Quoted 87 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h new file +81 -0
new file mode 100644
index 000000000000..c13627f2bac4
@@ -0,0 +1,315 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ * Author: Frederic Chen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _MTK_FD_DEV_H_
+#define _MTK_FD_DEV_H_
+
+#include <linux/types.h>
+#include <linux/platform_device.h>
+#include <media/v4l2-device.h>
+#include <media/videobuf2-v4l2.h>
+
+#include "mtk_fd-hw.h"
+#include "mtk_fd-smem.h"
+
+#define MTK_FD_PIPE_ID_STREAM_0				0
+#define MTK_FD_PIPE_ID_STREAM_1				1
+#define MTK_FD_PIPE_ID_TOTAL_NUM			2
+
+#define MTK_FD_VIDEO_NODE_ID_YUV_OUT			0
+#define MTK_FD_VIDEO_NODE_ID_CONFIG_OUT			1
+#define MTK_FD_VIDEO_NODE_ID_OUT_TOTAL_NUM		2
+#define MTK_FD_VIDEO_NODE_ID_CAPTURE			2
+#define MTK_FD_VIDEO_NODE_ID_CAPTURE_TOTAL_NUM		1
+#define MTK_FD_VIDEO_NODE_ID_TOTAL_NUM \
+	(MTK_FD_VIDEO_NODE_ID_OUT_TOTAL_NUM + \
+	MTK_FD_VIDEO_NODE_ID_CAPTURE_TOTAL_NUM)
+
+#define MTK_FD_VIDEO_NODE_ID_NO_MASTER			-1
+
+#define MTK_FD_OUTPUT_MIN_WIDTH				2U
+#define MTK_FD_OUTPUT_MIN_HEIGHT			2U
+#define MTK_FD_OUTPUT_MAX_WIDTH				5376U
+#define MTK_FD_OUTPUT_MAX_HEIGHT			4032U
+#define MTK_FD_CAPTURE_MIN_WIDTH			2U
+#define MTK_FD_CAPTURE_MIN_HEIGHT			2U
+#define MTK_FD_CAPTURE_MAX_WIDTH			5376U
+#define MTK_FD_CAPTURE_MAX_HEIGHT			4032U
+
+#define MTK_FD_PIPE_MEDIA_MODEL_NAME	"MTK-FD-V4L2"
+#define MTK_FD_PIPE_NAME_STREAM_0	MTK_FD_PIPE_MEDIA_MODEL_NAME
+#define MTK_FD_PIPE_NAME_STREAM_1	"MTK-FD-V4L2-STREAM-1"
+
+#define MTK_FD_DEV_META_BUF_DEFAULT_SIZE		(1110 * 1024)
+
+/*
+ * Supported format and the information used for
+ * size calculation
+ */
+struct mtk_fd_dev_meta_format {
+	u32 dataformat;
+	u32 max_buffer_size;
+	u8 flags;
+};
+
+/* MDP part private format definitation */
+struct mtk_fd_dev_mdp_format {
+	u32 pixelformat;
+	u32 mdp_color;
+	u32 colorspace;
+	u8 depth[VIDEO_MAX_PLANES];
+	u8 row_depth[VIDEO_MAX_PLANES];
+	u8 num_planes;
+	u8 walign;
+	u8 halign;
+	u8 salign;
+	u32 flags;
+};
+
+struct mtk_fd_dev_format {
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h line 86

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-dev.h new file +5 -0
+	union {
+		struct mtk_fd_dev_meta_format meta;
+		struct mtk_fd_dev_mdp_format img;
+	} fmt;
+};

This looks like a copy/paste from the DIP driver. Please merge the 3 structures above into 1 as suggested in review of that driver.

Ok, we will fix it.

Quoted 61 lines

[snip]

Quoted 46 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h new file +40 -0
new file mode 100644
index 000000000000..40e09d66c479
@@ -0,0 +1,158 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Copyright (C) 2015 MediaTek Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __MTK_FD_HW_H__
+#define __MTK_FD_HW_H__
+
+#include <linux/io.h>
+#define SIG_ERESTARTSYS 512
+
+#define FD_WR32(v, a) \
+do { \
+	__raw_writel((v), (void __force __iomem *)((a))); \
+	mb(); /* ensure written */ \
+} while (0)
+
+#define FD_RD32(addr) ioread32((void *)addr)
+
+#define FD_INT_EN		0x15c
+#define FD_INT			0x168
+#define FD_RESULT		0x178
+#define FD_IRQ_MASK		0x001
+
+#define RS_BUF_SIZE_MAX		2288788
+#define VA_OFFSET		0xffff000000000000
+
+#define MTK_FD_MAX_NO		1024
+#define MAX_FACE_SEL_NUM	(MTK_FD_MAX_NO + 2)
+
+/* The max number of face sizes could be detected, for feature scaling */
+#define FACE_SIZE_NUM_MAX	14

drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h line 50

Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-hw.h new file +10 -0
+
+/* FACE_SIZE_NUM_MAX + 1, first scale for input image W/H */
+#define FD_SCALE_NUM		15
+
+/* Number of Learning data sets */
+#define LEARNDATA_NUM		18
+
+#define mtk_fd_us_to_jiffies(us) \
+	((((unsigned long)(us) / 1000) * HZ + 512) >> 10)
+

Uhm, looking at the arbitrary numbers involved in this computation I'm afraid to even ask what this macro is expected to do.

Quoted 2 lines

Judging by the name, why not just use usecs_to_jiffies()?

Fixed. Using usecs_to_jiffies() instead.

Quoted 20 lines

[snip]

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +0 -0
new file mode 100644
index 000000000000..758a4ab68ec2
@@ -0,0 +1,39 @@

[snip]

Quoted 12 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +12 -0
+
+struct mtk_fd_smem_dev {
+	struct device dev;
+	struct sg_table sgt;
+	struct page **smem_pages;
+	int num_smem_pages;
+	phys_addr_t smem_base;
+	dma_addr_t smem_dma_base;
+	int smem_size;
+};
+
+phys_addr_t mtk_fd_smem_iova_to_phys(struct mtk_fd_smem_dev *smem_dev,
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h line 37

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+				     dma_addr_t iova);
+int mtk_fd_smem_alloc_dev_init(struct mtk_fd_smem_dev *smem_dev,
+			       struct device *default_alloc_dev);
+void mtk_fd_smem_alloc_dev_release(struct mtk_fd_smem_dev *smem_dev);
+

Please remove this custom smem thing as we should just use dma_alloc_*() from the right struct device attached to the right reserved memory pool.

FD driver may not need smem things after we use v4l2 control to replace the META_OUTPUT queuues.

Quoted 6 lines

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+static int mtk_fd_videoc_enum_fmt(struct file *file, void *fh,
+				  struct v4l2_fmtdesc *f)

It's "vidioc".

Fixed.

Quoted 8 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);
+
+	if (f->index > node->desc->num_fmts ||
+	    f->type != node->dev_q.vbq.type)

No need to check the type.

Ok, we will fix it.

Quoted 8 lines
Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+		return -EINVAL;
+
+	strscpy(f->description, node->desc->description,
+		sizeof(f->description));
+
+	f->pixelformat = node->desc->fmts[f->index].fmt.img.pixelformat;
+	f->flags = 0;
+
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	return 0;
+}
+
+static int mtk_fd_meta_enum_format(struct file *file,
+				   void *fh, struct v4l2_fmtdesc *f)

Please name the functions consistently. Above it has the vidioc prefix (with typo) and enum_fmt, but here it doesn't have a prefix and is enum_format.

Fixed.

Quoted 8 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);
+
+	if (f->index > 0 || f->type != node->dev_q.vbq.type)

There is no need to check the type, as the core should already check it for you.

Fixed.

Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+		return -EINVAL;
+
+	strscpy(f->description, node->desc->description,
+		sizeof(f->description));
+
+	f->pixelformat = node->vdev_fmt.fmt.meta.dataformat;

Also set flags to 0.

Fixed.

Quoted 12 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	return 0;
+}
+
+static int mtk_fd_videoc_g_meta_fmt(struct file *file,
+				    void *fh, struct v4l2_format *f)
+{
+	struct mtk_fd_video_device *node = mtk_fd_file_to_node(file);

The Linux coding style requires 1 blank line between variable declarations and code.

Fixed.

Quoted 11 lines
Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+	*f = node->vdev_fmt;
+
+	return 0;
+}
+
+static int
+mtk_fd_vidioc_subscribe_event(struct v4l2_fh *fh,
+			      const struct v4l2_event_subscription *sub)
+{
+	switch (sub->type) {
+	case V4L2_EVENT_CTRL:
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+		return v4l2_ctrl_subscribe_event(fh, sub);
+	default:
+		return -EINVAL;
+	}
+}

This driver doesn't seem to support any controls, so there is no point in supporting the above event.

Ok, we will use v4l2_ctrl_subscribe_event when we replace meta output queue with v4l2 control.

Quoted 18 lines

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 12 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +12 -0
+static void mtk_fd_node_to_v4l2(struct mtk_fd_pipe *fd_pipe,
+				u32 idx,
+				 struct video_device *vdev,
+				 struct v4l2_format *f)
+{
+	struct mtk_fd_video_device *node = &fd_pipe->nodes[idx];
+
+	vdev->ioctl_ops = node->desc->ops;
+	vdev->device_caps = V4L2_CAP_STREAMING | node->desc->cap;
+	f->type = node->desc->buf_type;
+	mtk_fd_pipe_load_default_fmt(fd_pipe, node, f);
+}

This function is only called once, is very short and has a very misleading name (this kind of name is used for functions that convert things). Just move the code back to the caller.

Fixed.

Quoted 5 lines
Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+
+int mtk_fd_dev_media_register(struct device *dev,
+			      struct media_device *media_dev,
+			      const char *model)
+{
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	int ret = 0;
+
+	media_dev->dev = dev;
+	dev_dbg(dev, "setup media_dev.dev: %p\n",
+		media_dev->dev);

I don't think these logs every second line are useful even for debugging. Please remove.

Fixed.

Quoted 7 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	strlcpy(media_dev->model, model,
+		sizeof(media_dev->model));

No need to pass model here as an argument. Just write the string here directly.

Fixed.

Quoted 5 lines
Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	dev_dbg(dev, "setup media_dev.model: %s\n",
+		media_dev->model);
+
+	snprintf(media_dev->bus_info, sizeof(media_dev->bus_info),
+		 "platform:%s", dev_name(dev));
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	dev_dbg(dev, "setup media_dev.bus_info: %s\n",
+		media_dev->bus_info);
+
+	media_dev->hw_revision = 0;
+	dev_dbg(dev, "setup media_dev.hw_revision: %d\n",
+		media_dev->hw_revision);

No need to explicitly initialize to 0.

Fixed.

Quoted 16 lines
Quoted 16 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +16 -0
+
+	media_dev->ops = &mtk_fd_media_req_ops;
+
+	dev_dbg(dev, "media_device_init: media_dev:%p\n",
+		media_dev);
+	media_device_init(media_dev);
+
+	pr_debug("Register media device: %s, %p",
+		 media_dev->model,
+		media_dev);
+
+	ret = media_device_register(media_dev);
+
+	if (ret) {
+		dev_err(dev, "failed to register media device (%d)\n", ret);
+		goto fail_media_dev;
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	}
+	return 0;
+
+fail_media_dev:
+	media_device_unregister(media_dev);

We jump here even if media_device_register() failed. Unregistering something that wasn't registered doesn't sound like a good idea.

Fixed.

Quoted 8 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	media_device_cleanup(media_dev);
+
+	return ret;
+}

There isn't much happening in this function. Perhaps just move the code back to the caller?

Moved back.

Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+
+int mtk_fd_dev_v4l2_register(struct device *dev,
+			     struct media_device *media_dev,
+			     struct v4l2_device *v4l2_dev)
+{
+	int ret = 0;

Add a blank line between variable declarations and code.

Fixed.

Quoted 8 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	/* Set up v4l2 device */
+	v4l2_dev->mdev = media_dev;
+	dev_dbg(dev, "setup v4l2_dev->mdev: %p",
+		v4l2_dev->mdev);

Please clean up such debugging messages, it makes it much harder to review the code.

Fixed.

Quoted 5 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 1 line
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +1 -0
+	v4l2_dev->ctrl_handler = NULL;

No need for explicit NULL assignments, as the structure was zero-filled already.

Fixed.

Quoted 8 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	dev_dbg(dev, "setup v4l2_dev->ctrl_handler: %p",
+		v4l2_dev->ctrl_handler);
+
+	pr_debug("Register v4l2 device: %p",
+		 v4l2_dev);

dev_dbg()? But I would still just remove it.

Fixed.

Quoted 12 lines
Quoted 12 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +12 -0
+
+	ret = v4l2_device_register(dev, v4l2_dev);
+
+	if (ret) {
+		dev_err(dev, "failed to register V4L2 device (%d)\n", ret);
+		goto fail_v4l2_dev;
+	}
+
+	return 0;
+
+fail_v4l2_dev:
+	media_device_unregister(media_dev);
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	media_device_cleanup(media_dev);
+
+	return ret;
+}
+

There isn't much happening in this function. Perhaps just move the code back to the caller?

Fixed and moved back.

Quoted 10 lines
Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+int mtk_fd_pipe_v4l2_register(struct mtk_fd_pipe *fd_pipe,
+			      struct media_device *media_dev,
+			      struct v4l2_device *v4l2_dev)
+{
+	int i, ret;
+
+	/* Initialize miscellaneous variables */
+	fd_pipe->streaming = 0;
+
+	/* Initialize subdev media entity */
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	fd_pipe->subdev_pads = kcalloc(fd_pipe->num_nodes,
+				       sizeof(*fd_pipe->subdev_pads),
+					GFP_KERNEL);
+	if (!fd_pipe->subdev_pads) {
+		ret = -ENOMEM;
+		goto fail_subdev_pads;

There isn't anything to clean up at this point, so just return.

Fixed.

Quoted 4 lines
Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	}
+
+	ret = media_entity_pads_init(&fd_pipe->subdev.entity,
+				     fd_pipe->num_nodes,
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+				     fd_pipe->subdev_pads);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,
+			"failed initialize subdev media entity (%d)\n", ret);
+		goto fail_media_entity;

Please name the labels after the next cleanup step to happen after jumping to it.

Fixed.

Quoted 21 lines
Quoted 21 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +21 -0
+	}
+
+	/* Initialize subdev */
+	v4l2_subdev_init(&fd_pipe->subdev, &mtk_fd_subdev_ops);
+
+	fd_pipe->subdev.entity.function =
+		MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
+
+	fd_pipe->subdev.entity.ops = &mtk_fd_media_ops;
+
+	for (i = 0; i < fd_pipe->num_nodes; i++) {
+		struct mtk_fd_video_device_desc *desc =
+			fd_pipe->nodes[i].desc;
+
+		fd_pipe->subdev_pads[i].flags =
+			V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?
+			MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
+	}
+
+	fd_pipe->subdev.flags =
+		V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+	snprintf(fd_pipe->subdev.name, sizeof(fd_pipe->subdev.name),
+		 "%s", fd_pipe->desc->name);
+	v4l2_set_subdevdata(&fd_pipe->subdev, fd_pipe);
+	fd_pipe->subdev.ctrl_handler = NULL;
+	fd_pipe->subdev.internal_ops = &mtk_fd_subdev_internal_ops;

The above code registers a subdev, so it sounds like it could be a separate function.

This function may be removed after we make we use the v4l2 control and make it a m2m device.

Quoted 14 lines
Quoted 14 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +14 -0
+
+	dev_dbg(&fd_pipe->fd_dev->pdev->dev,
+		"register subdev: %s, ctrl_handler %p\n",
+		 fd_pipe->subdev.name, fd_pipe->subdev.ctrl_handler);
+	ret = v4l2_device_register_subdev(&fd_pipe->fd_dev->v4l2_dev,
+					  &fd_pipe->subdev);
+	if (ret) {
+		dev_err(&fd_pipe->fd_dev->pdev->dev,
+			"failed initialize subdev (%d)\n", ret);
+		goto fail_subdev;
+	}
+
+	ret = v4l2_device_register_subdev_nodes(&fd_pipe->fd_dev->v4l2_dev);
+	if (ret) {
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+		dev_err(&fd_pipe->fd_dev->pdev->dev,
+			"failed to register subdevs (%d)\n", ret);
+		goto fail_subdevs;
+	}

This isn't per-pipe, but global for the whole v4l2_device. It should be called after all subdevs are fully initialized, to expose the device nodes to the userspace atomically.

Ditto.

Quoted 7 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	/* Create video nodes and links */
+	for (i = 0; i < fd_pipe->num_nodes; i++) {

Please move the contents of the loop into a separate function that handles one node.

Ditto.

Quoted 4 lines
Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+		struct mtk_fd_video_device *node = &fd_pipe->nodes[i];
+		struct video_device *vdev = &node->vdev;
+		struct vb2_queue *vbq = &node->dev_q.vbq;
+		struct mtk_fd_video_device_desc *desc = node->desc;
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+		u32 flags;
+
+		/* Initialize miscellaneous variables */
+		mutex_init(&node->dev_q.lock);

Please just use the video_device lock for vb2 queues too. It simplifies the overall driver locking and doesn't really have any practical performance difference.

Ok, we got it.

Quoted 12 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+		/* Initialize formats to default values */
+		mtk_fd_node_to_v4l2(fd_pipe, i, vdev, &node->vdev_fmt);
+
+		/* Initialize media entities */
+		ret = media_entity_pads_init(&vdev->entity, 1, &node->vdev_pad);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,

This kind of long chains of pointer dereferences signal a problem in the design of driver structures and/or function arguments.

Quoted 3 lines

I'd suggest passing fd_dev to this function and also storing dev instead of pdev inside fd_dev.

Ok, we got it.

Quoted 11 lines
Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+				"failed initialize media entity (%d)\n", ret);
+			goto fail_vdev_media_entity;
+		}
+
+		node->vdev_pad.flags = V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?
+			MEDIA_PAD_FL_SOURCE : MEDIA_PAD_FL_SINK;
+		vdev->entity.ops = NULL;
+
+		/* Initialize vbq */
+		vbq->type = node->vdev_fmt.type;
+		vbq->io_modes = VB2_MMAP | VB2_DMABUF;
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+		vbq->ops = &mtk_fd_vb2_ops;
+		vbq->mem_ops = &vb2_dma_contig_memops;
+		vbq->supports_requests = true;
+		vbq->buf_struct_size = sizeof(struct mtk_fd_dev_buffer);
+		vbq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;

This is a mem2mem device so the timestamps should be copied from OUTPUT to CAPTURE. Please set the flag appropriately.

Ok, we will use V4L2_BUF_FLAG_TIMESTAMP_COPY.

Quoted 13 lines
Quoted 13 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +13 -0
+		vbq->min_buffers_needed = 0;
+		/* Put the process hub sub device in the vb2 private data*/
+		vbq->drv_priv = fd_pipe;
+		vbq->lock = &node->dev_q.lock;
+		ret = vb2_queue_init(vbq);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,
+				"failed to initialize video queue (%d)\n", ret);
+			goto fail_vdev;
+		}
+
+		/* Initialize vdev */
+		snprintf(vdev->name, sizeof(vdev->name), "%s %s",
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+			 fd_pipe->desc->name,
+			 node->desc->name);
+		vdev->release = video_device_release_empty;
+		vdev->fops = &mtk_fd_v4l2_fops;
+		vdev->lock = &node->dev_q.lock;

Aha, so it's in fact the same lock. Please move it to the "node" struct then.

Ok, we got it.

Quoted 10 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		vdev->ctrl_handler = NULL;
+		vdev->v4l2_dev = &fd_pipe->fd_dev->v4l2_dev;
+		vdev->queue = &node->dev_q.vbq;
+		vdev->vfl_dir = V4L2_TYPE_IS_OUTPUT(desc->buf_type) ?
+			VFL_DIR_TX : VFL_DIR_RX;
+		video_set_drvdata(vdev, fd_pipe);
+		pr_debug("register vdev: %s\n", vdev->name);

dev_dbg()?

Fixed.

Quoted 10 lines
Quoted 10 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +10 -0
+		ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
+		if (ret) {
+			dev_err(&fd_pipe->fd_dev->pdev->dev,
+				"failed to register video device (%d)\n", ret);
+			goto fail_vdev;
+		}
+
+		/* Create link between video node and the subdev pad */
+		flags = 0;
+		if (desc->dynamic)
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+			flags |= MEDIA_LNK_FL_DYNAMIC;
+		if (node->enabled)
+			flags |= MEDIA_LNK_FL_ENABLED;
+		if (node->immutable)
+			flags |= MEDIA_LNK_FL_IMMUTABLE;

Wouldn't all the nodes be always ENABLED and IMMUTABLE and not DYNAMIC for this driver?

This will be removed after FD driver become m2m device driver and use v4l2 controls.

Quoted 4 lines
Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+		if (V4L2_TYPE_IS_OUTPUT(desc->buf_type))
+			ret = media_create_pad_link(&vdev->entity, 0,
+						    &fd_pipe->subdev.entity,
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+						    i, flags);
+		else
+			ret = media_create_pad_link(&fd_pipe->subdev.entity,
+						    i, &vdev->entity, 0,
+						    flags);
+

No need for this blank line.

Fixed.

Quoted 17 lines
Quoted 17 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +17 -0
+		if (ret)
+			goto fail_link;
+	}
+
+	return 0;
+
+	for (; i >= 0; i--) {
+fail_link:
+		video_unregister_device(&fd_pipe->nodes[i].vdev);
+fail_vdev:
+		vb2_queue_release(&fd_pipe->nodes[i].dev_q.vbq);
+		media_entity_cleanup(&fd_pipe->nodes[i].vdev.entity);
+fail_vdev_media_entity:
+		mutex_destroy(&fd_pipe->nodes[i].dev_q.lock);
+	}
+fail_subdevs:
+	v4l2_device_unregister_subdev(&fd_pipe->subdev);
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+fail_subdev:
+	media_entity_cleanup(&fd_pipe->subdev.entity);
+fail_media_entity:
+	kfree(fd_pipe->subdev_pads);
+fail_subdev_pads:
+	v4l2_device_unregister(&fd_pipe->fd_dev->v4l2_dev);

We haven't registered the v4l2_device in this function.

Fixed.

Quoted 5 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	pr_err("fail_v4l2_dev: media_device_unregister and clenaup:%p",
+	       &fd_pipe->fd_dev->mdev);

Error messages should be printed at the place of the failure.

Fixed.

Quoted 5 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	media_device_unregister(&fd_pipe->fd_dev->mdev);
+	media_device_cleanup(&fd_pipe->fd_dev->mdev);

We haven't registered or initialized media_device in this function.

Fixed.

Quoted 17 lines
Quoted 17 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +17 -0
+
+	return ret;
+}
+
+int mtk_fd_pipe_v4l2_unregister(struct mtk_fd_pipe *fd_pipe)
+{
+	unsigned int i;
+
+	for (i = 0; i < fd_pipe->num_nodes; i++) {
+		video_unregister_device(&fd_pipe->nodes[i].vdev);
+		vb2_queue_release(&fd_pipe->nodes[i].dev_q.vbq);
+		media_entity_cleanup(&fd_pipe->nodes[i].vdev.entity);
+		mutex_destroy(&fd_pipe->nodes[i].dev_q.lock);
+	}
+
+	v4l2_device_unregister_subdev(&fd_pipe->subdev);
+	media_entity_cleanup(&fd_pipe->subdev.entity);
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+	kfree(fd_pipe->subdev_pads);
+	v4l2_device_unregister(&fd_pipe->fd_dev->v4l2_dev);
+	media_device_unregister(&fd_pipe->fd_dev->mdev);
+	media_device_cleanup(&fd_pipe->fd_dev->mdev);

Please make this consistent with the registration functions. For each registration function there should be a matching unregister function that cleans up only whatever was registered in that function.

Ok, I got it.

Quoted 15 lines
Quoted 15 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +15 -0
+
+	return 0;
+}
+
+void mtk_fd_v4l2_buffer_done(struct vb2_buffer *vb,
+			     enum vb2_buffer_state state)
+{
+	struct mtk_fd_pipe *fd_pipe;
+	struct mtk_fd_video_device *node;
+
+	fd_pipe = vb2_get_drv_priv(vb->vb2_queue);
+	node = mtk_fd_vbq_to_node(vb->vb2_queue);
+	dev_dbg(&fd_pipe->fd_dev->pdev->dev,
+		"%s:%s: return buf, idx(%d), state(%d)\n",
+		fd_pipe->desc->name, node->desc->name,
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+		vb->index, state);
+	vb2_buffer_done(vb, state);
+}

No need for this function. Just call vb2_buffer_done() directly from the caller. (I already mentioned this in MTK DIP driver review. Please coordinate with other driver owners and make sure that similar comments are addressed in all drivers...)

Ok, this function is removed.

Quoted 6 lines
Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+
+/********************************************
+ * MTK FD V4L2 Settings *
+ ********************************************/
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_video_out_ioctl_ops = {
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+	.vidioc_enum_framesizes = mtk_fd_videoc_enum_framesizes,
+	.vidioc_enum_fmt_vid_cap_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_cap_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_cap_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_cap_mplane = mtk_fd_videoc_try_fmt,

No need for *cap* ops if this is only for an OUTPUT device.

Ok, we will remove it.

Quoted 36 lines
Quoted 36 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +36 -0
+	.vidioc_enum_fmt_vid_out_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_out_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_out_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_out_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+	.vidioc_subscribe_event = mtk_fd_vidioc_subscribe_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+
+};
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_video_cap_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+	.vidioc_enum_framesizes = mtk_fd_videoc_enum_framesizes,
+	.vidioc_enum_fmt_vid_cap_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_cap_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_cap_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_cap_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_enum_fmt_vid_out_mplane = mtk_fd_videoc_enum_fmt,
+	.vidioc_g_fmt_vid_out_mplane = mtk_fd_videoc_g_fmt,
+	.vidioc_s_fmt_vid_out_mplane = mtk_fd_videoc_s_fmt,
+	.vidioc_try_fmt_vid_out_mplane = mtk_fd_videoc_try_fmt,
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+	.vidioc_subscribe_event = mtk_fd_vidioc_subscribe_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+
+};

This structure is unused.

Fixed.

Quoted 42 lines
Quoted 42 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +42 -0
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_meta_out_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+
+	.vidioc_enum_fmt_meta_cap = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_enum_fmt_meta_out = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+};
+
+static const struct v4l2_ioctl_ops mtk_fd_v4l2_meta_cap_ioctl_ops = {
+	.vidioc_querycap = mtk_fd_videoc_querycap,
+
+	.vidioc_enum_fmt_meta_cap = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_cap = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_enum_fmt_meta_out = mtk_fd_meta_enum_format,
+	.vidioc_g_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_s_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+	.vidioc_try_fmt_meta_out = mtk_fd_videoc_g_meta_fmt,
+
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+};

Aren't the 2 structures above identical? Should be merged if so.

Fixed.

Quoted 12 lines

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+int mtk_fd_dev_v4l2_init(struct mtk_fd_dev *fd_dev)
+{
+	struct media_device *media_dev;
+	struct v4l2_device *v4l2_dev;
+	struct mtk_fd_smem_dev *smem_alloc_dev = &fd_dev->smem_alloc_dev;
+	int i;
+	int ret = 0;

Please don't initialize local variables unless that's needed by the logic. It prevents the compiler from detecting missing assignments.

Ok, I got it.

Quoted 7 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+
+	media_dev = &fd_dev->mdev;
+	v4l2_dev = &fd_dev->v4l2_dev;

Just pass fd_dev to the functions below. No need to extract only some fields.

Fixed.

Quoted 7 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	ret = mtk_fd_dev_media_register(&fd_dev->pdev->dev,
+					media_dev,
+					 MTK_FD_PIPE_MEDIA_MODEL_NAME);

We should bail out on error.

Fixed.

Quoted 7 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+
+	ret = mtk_fd_dev_v4l2_register(&fd_dev->pdev->dev,
+				       media_dev,
+					v4l2_dev);

We should clean up the previous steps and bail out on error.

Fixed.

Quoted 5 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	ret = mtk_fd_smem_alloc_dev_init(smem_alloc_dev, &fd_dev->pdev->dev);

Ditto.

Fixed.

Quoted 14 lines
Quoted 14 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +14 -0
+
+	for (i = 0; i < MTK_FD_PIPE_ID_TOTAL_NUM; i++) {
+		ret = mtk_fd_pipe_init(&fd_dev->fd_pipe[i], fd_dev,
+				       &pipe_settings[i],
+					media_dev, v4l2_dev, smem_alloc_dev);
+		if (ret) {
+			dev_err(&fd_dev->pdev->dev,
+				"%s: Pipe id(%d) init failed(%d)\n",
+				fd_dev->fd_pipe[i].desc->name,
+				i, ret);
+			return ret;
+		}
+	}
+
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	return 0;
+}
+
+void mtk_fd_dev_v4l2_release(struct mtk_fd_dev *fd_dev)
+{
+	int i = 0;

No need for initialization.

Fixed.

Quoted 5 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	if (fd_dev)

Why could it ever be NULL?

Fixed.

Quoted 23 lines
Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+		for (i = 0; i < MTK_FD_PIPE_ID_TOTAL_NUM; i++)
+			mtk_fd_pipe_release(&fd_dev->fd_pipe[i]);
+
+	mtk_fd_smem_alloc_dev_release(&fd_dev->smem_alloc_dev);
+}
+

[snip]

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 11 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +11 -0
+static int mtk_fd_probe(struct platform_device *pdev)
+{
+	struct mtk_fd_dev *fd_dev;
+	struct mtk_fd_hw *fd_hw;
+	struct device_node *node;
+	struct platform_device *larb_pdev;
+	int irq_num;
+	int ret;
+
+	fd_dev = devm_kzalloc(&pdev->dev, sizeof(*fd_dev), GFP_KERNEL);
+

nit: No need for this blank line, because the if below is directly related.

Quoted 10 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+	if (!fd_dev)
+		return -ENOMEM;
+
+	dev_set_drvdata(&pdev->dev, fd_dev);
+	fd_hw = &fd_dev->fd_hw;
+
+	if (!fd_hw) {

How is this possible for a struct member?

Fixed.

Quoted 11 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		dev_err(&pdev->dev, "Unable to allocate fd_hw\n");
+		return -ENOMEM;
+	}
+
+	fd_dev->pdev = pdev;
+
+	irq_num = irq_of_parse_and_map(pdev->dev.of_node, FD_IRQ_IDX);

We should use platform_get_irq() here instead, because the IRQs were already parsed for us when the platform core created the platform_device.

Fixed.

Quoted 8 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+	ret = request_irq(irq_num, (irq_handler_t)mtk_fd_irq,
+			  IRQF_TRIGGER_NONE, FD_DRVNAME, fd_hw);

It should be a device name, not driver name. One would normally use dev_name() here.

Also devm_request_irq() should simplify the cleanup.

Fixed.

Quoted 6 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+	if (ret) {
+		dev_dbg(&pdev->dev, "%s request_irq fail, irq=%d\n",
+			__func__, irq_num);

This is an error, so dev_err().

Fixed.

Quoted 6 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+		return ret;
+	}
+	dev_dbg(&pdev->dev, "irq_num=%d\n", irq_num);

That's probably not very useful.

Fixed.

Quoted 8 lines
Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	node = of_parse_phandle(pdev->dev.of_node, "mediatek,larb", 0);
+	if (!node) {
+		dev_err(&pdev->dev, "no mediatek, larb found");
+		return -EINVAL;
+	}
+	larb_pdev = of_find_device_by_node(node);
+	if (!larb_pdev) {
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 5 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +5 -0
+		dev_err(&pdev->dev, "no mediatek, larb device found");
+		return -EINVAL;
+	}
+	fd_hw->larb_dev = &larb_pdev->dev;
+

LARBs are handled automatically by the IOMMU driver, no need to do anything with them explicitly anymore.

Fixed.

Quoted 11 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+	node = pdev->dev.of_node;
+	if (!node) {
+		dev_err(&pdev->dev, "find fd node failed!!!\n");
+		return -ENODEV;
+	}
+
+	fd_hw->fd_base = of_iomap(node, 0);

One would normally use platform_get_resource() and devm_ioremap_resource() here.

Fixed.

Quoted 11 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	if (!fd_hw->fd_base) {
+		dev_err(&pdev->dev, "unable to map fd node!!!\n");
+		return -ENODEV;
+	}
+
+	dev_dbg(&pdev->dev, "fd_hw->fd_base: %lx\n",
+		(unsigned long)fd_hw->fd_base);

Not very useful either.

Fixed.

Quoted 6 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 2 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +2 -0
+
+	fd_hw->fd_clk = devm_clk_get(&pdev->dev, "FD_CLK_IMG_FD");

Clock names should be lowercase and name just inputs of the IP block, so simply "fd", should be enough.

Fixed.

Quoted 8 lines
Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+	if (IS_ERR(fd_hw->fd_clk)) {
+		dev_err(&pdev->dev, "cannot get FD_CLK_IMG_FD clock\n");
+		return PTR_ERR(fd_hw->fd_clk);
+	}
+
+	pm_runtime_enable(&pdev->dev);
+	atomic_set(&fd_hw->fd_user_cnt, 0);
+	init_waitqueue_head(&fd_hw->wq);
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	mutex_init(&fd_hw->fd_hw_lock);
+	fd_hw->fd_irq_result = 0;
+
+	ret = mtk_fd_dev_v4l2_init(fd_dev);
+	if (ret)
+		dev_err(&pdev->dev, "v4l2 init failed: %d\n", ret);

We should clean up and return the error code, not 0.

Fixed.

Quoted 8 lines
Quoted 8 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +8 -0
+
+	dev_info(&pdev->dev, "Mediatek Camera FD driver probe.\n");
+
+	return 0;
+}
+
+static int mtk_fd_remove(struct platform_device *pdev)
+{
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	int irq_i4;
+	struct mtk_fd_dev *fd_dev = dev_get_drvdata(&pdev->dev);
+
+	if (fd_dev) {
+		mtk_fd_dev_v4l2_release(fd_dev);
+	} else {

This is impossible.

Fixed.

Quoted 4 lines
Quoted 4 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +4 -0
+		dev_err(&pdev->dev, "Can't find fd driver data\n");
+		return -EINVAL;
+	}
+
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+	mutex_destroy(&fd_dev->fd_hw.fd_hw_lock);
+	pm_runtime_disable(&pdev->dev);
+
+	irq_i4 = platform_get_irq(pdev, 0);
+	free_irq(irq_i4, NULL);
+	kfree(fd_dev);

fd_dev was allocated using devm_kzalloc(), no need to free it explicitly.

Fixed.

Quoted 16 lines
Quoted 16 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +16 -0
+
+	return 0;
+}
+
+static int mtk_fd_suspend(struct device *dev)
+{
+	struct mtk_fd_dev *fd_dev;
+	int ret;
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	fd_dev = dev_get_drvdata(dev);
+
+	if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+		ret = pm_runtime_put_sync(fd_dev->fd_hw.larb_dev);
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +3 -0
+		clk_disable_unprepare(fd_dev->fd_hw.fd_clk);
+		return ret;
+	}

This isn't going to work, because the hardware may be still processing a frame at this point. You need a way to ensure that the hardware goes idle here first and then in resume, you need to make the hardware continue when it left before suspend.

For this part, I would like to do as following:
when suspend, it should set the driver power state as idle or suspended to stop further enqueue jobs, should be judged in mtk_fd_hw_job_exec() or somewhere, then wait for the unfinished job return or timeout, and finally close the clock.
When resume, we set the driver power state as resumed and let the new jobs to be enqueued.

Or another way is to create a wait queue or work queue to store the jobs from user. When suspend, we change the driver status to restrict the new jobs joining to work queue and close the clock. When resume, driver continue execute the jobs from the work queue.

Quoted 41 lines
Quoted 41 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +41 -0
+	return 0;
+}
+
+static int mtk_fd_resume(struct device *dev)
+{
+	struct mtk_fd_dev *fd_dev;
+	int ret;
+
+	if (pm_runtime_suspended(dev))
+		return 0;
+
+	fd_dev = dev_get_drvdata(dev);
+
+	if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+		ret = pm_runtime_get_sync(fd_dev->fd_hw.larb_dev);
+		if (ret) {
+			dev_dbg(&fd_dev->pdev->dev, "open larb clk failed\n");
+			return ret;
+		}
+
+		ret = clk_prepare_enable(fd_dev->fd_hw.fd_clk);
+		if (ret) {
+			dev_dbg(&fd_dev->pdev->dev, "open fd clk failed\n");
+			return ret;
+		}
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct dev_pm_ops mtk_fd_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(mtk_fd_suspend, mtk_fd_resume)
+	SET_RUNTIME_PM_OPS(mtk_fd_suspend, mtk_fd_resume, NULL)
+};
+
+static const struct of_device_id mtk_fd_of_ids[] = {
+	{ .compatible = "mediatek,mt8183-fd", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, mtk_fd_of_ids);
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 6 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +6 -0
+
+static struct platform_driver mtk_fd_driver = {
+	.probe   = mtk_fd_probe,
+	.remove  = mtk_fd_remove,
+	.driver  = {
+		.name  = FD_DRVNAME,

Please just set the name explicitly here and remove the macro.

Fixed.

Quoted 4 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 1 line
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +1 -0
+		.of_match_table = mtk_fd_of_ids,

Please use of_match_ptr().

Fixed.

Quoted 13 lines

drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h

Quoted 7 lines
drivers/media/platform/mtk-isp/fd/mtk_fd-smem.h new file +7 -0
+		.pm = &mtk_fd_pm_ops,
+	}
+};
+module_platform_driver(mtk_fd_driver);
+
+MODULE_DESCRIPTION("Mediatek FD driver");
+MODULE_LICENSE("GPL");

GPL v2

Quoted 3 lines
Signature · 1 line
2.18.0

Sincerely,

Jerry

#15 lore raw

Re: [RFC PATCH V1 6/6] platform: mtk-isp: Add Mediatek FD driver

Hi Jerry,

Quoted 64 lines · Jerry-ch Chen

Hi Tomasz,

Quoted 23 lines · Tomasz Figa

Hi Jerry,

Quoted 10 lines · Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds the driver of Face Detection (FD) unit in Mediatek camera system, providing face detection function.

The mtk-isp directory will contain drivers for multiple IP blocks found in Mediatek ISP system. It will include ISP Pass 1 driver (CAM), sensor interface driver, DIP driver and face detection driver.

Thanks for the patch.

First of all a general comment about the design:

My understanding is that this is a relatively straightforward memory-to-memory device that reads a video frame and detects faces on it. Such devices should be implemented as normal V4L2 memory-to-memory devices, with contexts (instances; pipes) represented by v4l2_fh.

Quoted 9 lines

Also, please replace the META_OUTPUT queue with proper V4L2 controls, as I don't think there is anything that we couldn't model using controls here.

The end result should be a V4L2 m2m driver (using the m2m helpers), where you get a new context (instance; pipe) whenever you open the video node, similar to codecs, video processors (like MTK MDP) and so on.

Also please see my comments inline.

I appreciate your comments,
sorry for sending the previous two unfinished mail...

FD driver will be implemented as a normal V4L2 m2m driver which has an IMAGE_OUTPUT queue and a META_CAPTURE queue(face result).

We will use the following properties.
/* Is a video mem-to-mem device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000

The original META_OUTPUT queue contains the following structure will be replaced by V4L2 controls,

/* FD_SCALE_NUM is 15. */

struct fd_user_param {
        uint8_t rip_feature;
        uint8_t gfd_skip;
        uint8_t dynamic_change_model;
        uint8_t scale_num_from_user;
        uint16_t source_img_width[FD_SCALE_NUM];
        uint16_t source_img_height[FD_SCALE_NUM];
} __packed; //share with co-processor

However, we found that testM2MFormats() in the V4L2 compliance test will assume the capture queue has the same format as output queue has, therefore, FD driver's capture queue wouldn't be able to use META format or the v4l2 test will be failed.

Quoted 9 lines

reference: v4l2-compliance/v4l2-test-formats.cpp
// m2m devices are special in that the format is often per-filehandle. // But colorspace information should be passed from output to capture, // so test that.

        if (node->is_m2m)
                return testM2MFormats(node);

May we ask for your suggestions about this part?

Ah, I didn't mean mem-to-mem device specifically as per V4L2_CAP_VIDEO_M2M_MPLANE, because that one implies the regular VIDEO_OUTPUT -> VIDEO_CAPTURE processing indeed. We should expose just VIDEO_OUTPUT_MPLANE and META_CAPTURE in the capabilities, but all the rest would still behave like a mem-to-mem device, i.e. v4l2_fh for contexts/instances, v4l2_m2m helpers and so on.

[snip]

Quoted 33 lines
Quoted 16 lines
Quoted 16 lines
drivers/media/platform/mtk-isp/fd/mtk_fd_40.c new file +16 -0
+
+   return 0;
+}
+
+static int mtk_fd_suspend(struct device *dev)
+{
+   struct mtk_fd_dev *fd_dev;
+   int ret;
+
+   if (pm_runtime_suspended(dev))
+           return 0;
+
+   fd_dev = dev_get_drvdata(dev);
+
+   if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+           ret = pm_runtime_put_sync(fd_dev->fd_hw.larb_dev);
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd_40.c line 500

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd_40.c new file +3 -0
+           clk_disable_unprepare(fd_dev->fd_hw.fd_clk);
+           return ret;
+   }

This isn't going to work, because the hardware may be still processing a frame at this point. You need a way to ensure that the hardware goes idle here first and then in resume, you need to make the hardware continue when it left before suspend.

For this part, I would like to do as following:
when suspend, it should set the driver power state as idle or suspended to stop further enqueue jobs, should be judged in mtk_fd_hw_job_exec() or somewhere, then wait for the unfinished job return or timeout, and finally close the clock.
When resume, we set the driver power state as resumed and let the new jobs to be enqueued.

Quoted 5 lines

Or another way is to create a wait queue or work queue to store the jobs from user. When suspend, we change the driver status to restrict the new jobs joining to work queue and close the clock. When resume, driver continue execute the jobs from the work queue.

I wouldn't introduce a workqueue only for handling suspend/resume. If we end up in a need to use a workqueue for some other purposes too, then a freezable workqueue could work for blocking further requests during suspend indeed. If we don't need a workqueue for anything else, then a simple boolean flag set and wait for last job to finish in suspend and flag reset and call to schedule a next job in resume should be good enough.

Best regards,
Tomasz

#16 lore raw

Re: [RFC PATCH V1 6/6] platform: mtk-isp: Add Mediatek FD driver

Hi Tomasz,

Quoted 78 lines · Tomasz Figa

Hi Jerry,

Quoted 64 lines · Jerry-ch Chen

Hi Tomasz,

Quoted 23 lines · Tomasz Figa

Hi Jerry,

Quoted 10 lines · Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds the driver of Face Detection (FD) unit in Mediatek camera system, providing face detection function.

The mtk-isp directory will contain drivers for multiple IP blocks found in Mediatek ISP system. It will include ISP Pass 1 driver (CAM), sensor interface driver, DIP driver and face detection driver.

Thanks for the patch.

First of all a general comment about the design:

My understanding is that this is a relatively straightforward memory-to-memory device that reads a video frame and detects faces on it. Such devices should be implemented as normal V4L2 memory-to-memory devices, with contexts (instances; pipes) represented by v4l2_fh.

Quoted 9 lines

Also, please replace the META_OUTPUT queue with proper V4L2 controls, as I don't think there is anything that we couldn't model using controls here.

The end result should be a V4L2 m2m driver (using the m2m helpers), where you get a new context (instance; pipe) whenever you open the video node, similar to codecs, video processors (like MTK MDP) and so on.

Also please see my comments inline.

I appreciate your comments,
sorry for sending the previous two unfinished mail...

FD driver will be implemented as a normal V4L2 m2m driver which has an IMAGE_OUTPUT queue and a META_CAPTURE queue(face result).

We will use the following properties.
/* Is a video mem-to-mem device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000

The original META_OUTPUT queue contains the following structure will be replaced by V4L2 controls,

/* FD_SCALE_NUM is 15. */

struct fd_user_param {
        uint8_t rip_feature;
        uint8_t gfd_skip;
        uint8_t dynamic_change_model;
        uint8_t scale_num_from_user;
        uint16_t source_img_width[FD_SCALE_NUM];
        uint16_t source_img_height[FD_SCALE_NUM];
} __packed; //share with co-processor

However, we found that testM2MFormats() in the V4L2 compliance test will assume the capture queue has the same format as output queue has, therefore, FD driver's capture queue wouldn't be able to use META format or the v4l2 test will be failed.

Quoted 9 lines

reference: v4l2-compliance/v4l2-test-formats.cpp
// m2m devices are special in that the format is often per-filehandle. // But colorspace information should be passed from output to capture, // so test that.

        if (node->is_m2m)
                return testM2MFormats(node);

May we ask for your suggestions about this part?

Quoted 7 lines

Ah, I didn't mean mem-to-mem device specifically as per V4L2_CAP_VIDEO_M2M_MPLANE, because that one implies the regular VIDEO_OUTPUT -> VIDEO_CAPTURE processing indeed. We should expose just VIDEO_OUTPUT_MPLANE and META_CAPTURE in the capabilities, but all the rest would still behave like a mem-to-mem device, i.e. v4l2_fh for contexts/instances, v4l2_m2m helpers and so on.

I Appreciate for your reply,

Sorry I didn't mention the question clearly, we have included these two capabilities, but we get the following v4l2 test failure:
fail: v4l2-test-formats.cpp(784): fmt_cap.g_colorspace() != fmt_out.g_colorspace()

Which is caused by the following code testing the m2m buffers' capabilities, FD driver have fmt_cap with V4L2_BUF_TYPE_META_CAPTURE and fmt_out with V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, therefore, our fmt_cap won't have colorspace information.

Reference:
https://github.com/gjasny/v4l-utils/blob/master/utils/v4l2-compliance/v4l2-test-formats.cpp#L774
fail_on_test(fmt_cap.g_colorspace() != fmt_out.g_colorspace()); fail_on_test(fmt_cap.g_ycbcr_enc() != fmt_out.g_ycbcr_enc()); fail_on_test(fmt_cap.g_quantization() != fmt_out.g_quantization()); fail_on_test(fmt_cap.g_xfer_func() != fmt_out.g_xfer_func());

Not sure if the maintainer of v4l2 test would consider modifying here to allow the use case of FD driver?

Quoted 49 lines

[snip]

Quoted 33 lines
Quoted 16 lines
Quoted 16 lines
drivers/media/platform/mtk-isp/fd/mtk_fd_40.c new file +16 -0
+
+   return 0;
+}
+
+static int mtk_fd_suspend(struct device *dev)
+{
+   struct mtk_fd_dev *fd_dev;
+   int ret;
+
+   if (pm_runtime_suspended(dev))
+           return 0;
+
+   fd_dev = dev_get_drvdata(dev);
+
+   if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+           ret = pm_runtime_put_sync(fd_dev->fd_hw.larb_dev);
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd_40.c line 500

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd_40.c new file +3 -0
+           clk_disable_unprepare(fd_dev->fd_hw.fd_clk);
+           return ret;
+   }

This isn't going to work, because the hardware may be still processing a frame at this point. You need a way to ensure that the hardware goes idle here first and then in resume, you need to make the hardware continue when it left before suspend.

For this part, I would like to do as following:
when suspend, it should set the driver power state as idle or suspended to stop further enqueue jobs, should be judged in mtk_fd_hw_job_exec() or somewhere, then wait for the unfinished job return or timeout, and finally close the clock.
When resume, we set the driver power state as resumed and let the new jobs to be enqueued.

Quoted 5 lines

Or another way is to create a wait queue or work queue to store the jobs from user. When suspend, we change the driver status to restrict the new jobs joining to work queue and close the clock. When resume, driver continue execute the jobs from the work queue.

I wouldn't introduce a workqueue only for handling suspend/resume. If we end up in a need to use a workqueue for some other purposes too, then a freezable workqueue could work for blocking further requests during suspend indeed. If we don't need a workqueue for anything else, then a simple boolean flag set and wait for last job to finish in suspend and flag reset and call to schedule a next job in resume should be good enough.

Quoted 2 lines

Best regards,
Tomasz

Ok, we got it.

Sincerely,
Jerry

#17 lore raw

Re: [RFC PATCH V1 6/6] platform: mtk-isp: Add Mediatek FD driver

Quoted 89 lines · Jerry-ch Chen

Hi Tomasz,

Quoted 78 lines · Tomasz Figa

Hi Jerry,

Quoted 64 lines · Jerry-ch Chen

Hi Tomasz,

Quoted 23 lines · Tomasz Figa

Hi Jerry,

Quoted 10 lines · Jerry-ch Chen

From: Jerry-ch Chen <jerry-ch.chen-NuS5LvNUpcJWk0Htik3J/[email protected]>

This patch adds the driver of Face Detection (FD) unit in Mediatek camera system, providing face detection function.

The mtk-isp directory will contain drivers for multiple IP blocks found in Mediatek ISP system. It will include ISP Pass 1 driver (CAM), sensor interface driver, DIP driver and face detection driver.

Thanks for the patch.

First of all a general comment about the design:

My understanding is that this is a relatively straightforward memory-to-memory device that reads a video frame and detects faces on it. Such devices should be implemented as normal V4L2 memory-to-memory devices, with contexts (instances; pipes) represented by v4l2_fh.

Quoted 9 lines

Also, please replace the META_OUTPUT queue with proper V4L2 controls, as I don't think there is anything that we couldn't model using controls here.

The end result should be a V4L2 m2m driver (using the m2m helpers), where you get a new context (instance; pipe) whenever you open the video node, similar to codecs, video processors (like MTK MDP) and so on.

Also please see my comments inline.

I appreciate your comments,
sorry for sending the previous two unfinished mail...

FD driver will be implemented as a normal V4L2 m2m driver which has an IMAGE_OUTPUT queue and a META_CAPTURE queue(face result).

We will use the following properties.
/* Is a video mem-to-mem device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000

The original META_OUTPUT queue contains the following structure will be replaced by V4L2 controls,

/* FD_SCALE_NUM is 15. */

struct fd_user_param {
        uint8_t rip_feature;
        uint8_t gfd_skip;
        uint8_t dynamic_change_model;
        uint8_t scale_num_from_user;
        uint16_t source_img_width[FD_SCALE_NUM];
        uint16_t source_img_height[FD_SCALE_NUM];
} __packed; //share with co-processor

However, we found that testM2MFormats() in the V4L2 compliance test will assume the capture queue has the same format as output queue has, therefore, FD driver's capture queue wouldn't be able to use META format or the v4l2 test will be failed.

Quoted 9 lines

reference: v4l2-compliance/v4l2-test-formats.cpp
// m2m devices are special in that the format is often per-filehandle. // But colorspace information should be passed from output to capture, // so test that.

        if (node->is_m2m)
                return testM2MFormats(node);

May we ask for your suggestions about this part?

Quoted 7 lines

Ah, I didn't mean mem-to-mem device specifically as per V4L2_CAP_VIDEO_M2M_MPLANE, because that one implies the regular VIDEO_OUTPUT -> VIDEO_CAPTURE processing indeed. We should expose just VIDEO_OUTPUT_MPLANE and META_CAPTURE in the capabilities, but all the rest would still behave like a mem-to-mem device, i.e. v4l2_fh for contexts/instances, v4l2_m2m helpers and so on.

Quoted 6 lines

I Appreciate for your reply,

Sorry I didn't mention the question clearly, we have included these two capabilities, but we get the following v4l2 test failure:
fail: v4l2-test-formats.cpp(784): fmt_cap.g_colorspace() != fmt_out.g_colorspace()

My point is that we shouldn't set V4L2_CAP_VIDEO_M2M(_MPLANE) in the capabilities, because FD is mem-to-mem in terms of the mode of operation, not in terms of the definition of V4L2_CAP_VIDEO_M2M(_MPLANE). That would make testM2MFormats() not called at all.

Best regards,
Tomasz

Quoted 73 lines

Which is caused by the following code testing the m2m buffers' capabilities, FD driver have fmt_cap with V4L2_BUF_TYPE_META_CAPTURE and fmt_out with V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, therefore, our fmt_cap won't have colorspace information.

Reference:
https://github.com/gjasny/v4l-utils/blob/master/utils/v4l2-compliance/v4l2-test-formats.cpp#L774
fail_on_test(fmt_cap.g_colorspace() != fmt_out.g_colorspace()); fail_on_test(fmt_cap.g_ycbcr_enc() != fmt_out.g_ycbcr_enc()); fail_on_test(fmt_cap.g_quantization() != fmt_out.g_quantization()); fail_on_test(fmt_cap.g_xfer_func() != fmt_out.g_xfer_func());

Not sure if the maintainer of v4l2 test would consider modifying here to allow the use case of FD driver?

Quoted 49 lines

[snip]

Quoted 33 lines
Quoted 16 lines
Quoted 16 lines
drivers/media/platform/mtk-isp/fd/mtk_fd_40.c new file +16 -0
+
+   return 0;
+}
+
+static int mtk_fd_suspend(struct device *dev)
+{
+   struct mtk_fd_dev *fd_dev;
+   int ret;
+
+   if (pm_runtime_suspended(dev))
+           return 0;
+
+   fd_dev = dev_get_drvdata(dev);
+
+   if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+           ret = pm_runtime_put_sync(fd_dev->fd_hw.larb_dev);
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd_40.c line 500

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd_40.c new file +3 -0
+           clk_disable_unprepare(fd_dev->fd_hw.fd_clk);
+           return ret;
+   }

This isn't going to work, because the hardware may be still processing a frame at this point. You need a way to ensure that the hardware goes idle here first and then in resume, you need to make the hardware continue when it left before suspend.

For this part, I would like to do as following:
when suspend, it should set the driver power state as idle or suspended to stop further enqueue jobs, should be judged in mtk_fd_hw_job_exec() or somewhere, then wait for the unfinished job return or timeout, and finally close the clock.
When resume, we set the driver power state as resumed and let the new jobs to be enqueued.

Quoted 5 lines

Or another way is to create a wait queue or work queue to store the jobs from user. When suspend, we change the driver status to restrict the new jobs joining to work queue and close the clock. When resume, driver continue execute the jobs from the work queue.

I wouldn't introduce a workqueue only for handling suspend/resume. If we end up in a need to use a workqueue for some other purposes too, then a freezable workqueue could work for blocking further requests during suspend indeed. If we don't need a workqueue for anything else, then a simple boolean flag set and wait for last job to finish in suspend and flag reset and call to schedule a next job in resume should be good enough.

Quoted 2 lines

Best regards,
Tomasz

Ok, we got it.

Sincerely,
Jerry

#18 lore raw

Re: [RFC PATCH V1 6/6] platform: mtk-isp: Add Mediatek FD driver

Hi Tomasz,

Quoted 98 lines · Tomasz Figa
Quoted 89 lines · Jerry-ch Chen

Hi Tomasz,

Quoted 78 lines · Tomasz Figa

Hi Jerry,

Quoted 64 lines · Jerry-ch Chen

Hi Tomasz,

Quoted 23 lines · Tomasz Figa

Hi Jerry,

Quoted 10 lines · Jerry-ch Chen

From: Jerry-ch Chen <[email protected]>

This patch adds the driver of Face Detection (FD) unit in Mediatek camera system, providing face detection function.

The mtk-isp directory will contain drivers for multiple IP blocks found in Mediatek ISP system. It will include ISP Pass 1 driver (CAM), sensor interface driver, DIP driver and face detection driver.

Thanks for the patch.

First of all a general comment about the design:

My understanding is that this is a relatively straightforward memory-to-memory device that reads a video frame and detects faces on it. Such devices should be implemented as normal V4L2 memory-to-memory devices, with contexts (instances; pipes) represented by v4l2_fh.

Quoted 9 lines

Also, please replace the META_OUTPUT queue with proper V4L2 controls, as I don't think there is anything that we couldn't model using controls here.

The end result should be a V4L2 m2m driver (using the m2m helpers), where you get a new context (instance; pipe) whenever you open the video node, similar to codecs, video processors (like MTK MDP) and so on.

Also please see my comments inline.

I appreciate your comments,
sorry for sending the previous two unfinished mail...

FD driver will be implemented as a normal V4L2 m2m driver which has an IMAGE_OUTPUT queue and a META_CAPTURE queue(face result).

We will use the following properties.
/* Is a video mem-to-mem device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000

The original META_OUTPUT queue contains the following structure will be replaced by V4L2 controls,

/* FD_SCALE_NUM is 15. */

struct fd_user_param {
        uint8_t rip_feature;
        uint8_t gfd_skip;
        uint8_t dynamic_change_model;
        uint8_t scale_num_from_user;
        uint16_t source_img_width[FD_SCALE_NUM];
        uint16_t source_img_height[FD_SCALE_NUM];
} __packed; //share with co-processor

However, we found that testM2MFormats() in the V4L2 compliance test will assume the capture queue has the same format as output queue has, therefore, FD driver's capture queue wouldn't be able to use META format or the v4l2 test will be failed.

Quoted 9 lines

reference: v4l2-compliance/v4l2-test-formats.cpp
// m2m devices are special in that the format is often per-filehandle. // But colorspace information should be passed from output to capture, // so test that.

        if (node->is_m2m)
                return testM2MFormats(node);

May we ask for your suggestions about this part?

Quoted 7 lines

Ah, I didn't mean mem-to-mem device specifically as per V4L2_CAP_VIDEO_M2M_MPLANE, because that one implies the regular VIDEO_OUTPUT -> VIDEO_CAPTURE processing indeed. We should expose just VIDEO_OUTPUT_MPLANE and META_CAPTURE in the capabilities, but all the rest would still behave like a mem-to-mem device, i.e. v4l2_fh for contexts/instances, v4l2_m2m helpers and so on.

Quoted 6 lines

I Appreciate for your reply,

Sorry I didn't mention the question clearly, we have included these two capabilities, but we get the following v4l2 test failure:
fail: v4l2-test-formats.cpp(784): fmt_cap.g_colorspace() != fmt_out.g_colorspace()

Quoted 9 lines

My point is that we shouldn't set V4L2_CAP_VIDEO_M2M(_MPLANE) in the capabilities, because FD is mem-to-mem in terms of the mode of operation, not in terms of the definition of V4L2_CAP_VIDEO_M2M(_MPLANE). That would make testM2MFormats() not called at all.

Best regards,
Tomasz

Ok, we got your point,

Thanks and Best Regards,
Jerry

Quoted 73 lines
Quoted 73 lines

Which is caused by the following code testing the m2m buffers' capabilities, FD driver have fmt_cap with V4L2_BUF_TYPE_META_CAPTURE and fmt_out with V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, therefore, our fmt_cap won't have colorspace information.

Reference:
https://github.com/gjasny/v4l-utils/blob/master/utils/v4l2-compliance/v4l2-test-formats.cpp#L774
fail_on_test(fmt_cap.g_colorspace() != fmt_out.g_colorspace()); fail_on_test(fmt_cap.g_ycbcr_enc() != fmt_out.g_ycbcr_enc()); fail_on_test(fmt_cap.g_quantization() != fmt_out.g_quantization()); fail_on_test(fmt_cap.g_xfer_func() != fmt_out.g_xfer_func());

Not sure if the maintainer of v4l2 test would consider modifying here to allow the use case of FD driver?

Quoted 49 lines

[snip]

Quoted 33 lines
Quoted 16 lines
Quoted 16 lines
drivers/media/platform/mtk-isp/fd/mtk_fd_40.c new file +16 -0
+
+   return 0;
+}
+
+static int mtk_fd_suspend(struct device *dev)
+{
+   struct mtk_fd_dev *fd_dev;
+   int ret;
+
+   if (pm_runtime_suspended(dev))
+           return 0;
+
+   fd_dev = dev_get_drvdata(dev);
+
+   if (atomic_read(&fd_dev->fd_hw.fd_user_cnt) > 0) {
+           ret = pm_runtime_put_sync(fd_dev->fd_hw.larb_dev);
Quoted 9 lines

drivers/media/platform/mtk-isp/fd/mtk_fd_40.c line 500

Quoted 3 lines
drivers/media/platform/mtk-isp/fd/mtk_fd_40.c new file +3 -0
+           clk_disable_unprepare(fd_dev->fd_hw.fd_clk);
+           return ret;
+   }

This isn't going to work, because the hardware may be still processing a frame at this point. You need a way to ensure that the hardware goes idle here first and then in resume, you need to make the hardware continue when it left before suspend.

For this part, I would like to do as following:
when suspend, it should set the driver power state as idle or suspended to stop further enqueue jobs, should be judged in mtk_fd_hw_job_exec() or somewhere, then wait for the unfinished job return or timeout, and finally close the clock.
When resume, we set the driver power state as resumed and let the new jobs to be enqueued.

Quoted 5 lines

Or another way is to create a wait queue or work queue to store the jobs from user. When suspend, we change the driver status to restrict the new jobs joining to work queue and close the clock. When resume, driver continue execute the jobs from the work queue.

I wouldn't introduce a workqueue only for handling suspend/resume. If we end up in a need to use a workqueue for some other purposes too, then a freezable workqueue could work for blocking further requests during suspend indeed. If we don't need a workqueue for anything else, then a simple boolean flag set and wait for last job to finish in suspend and flag reset and call to schedule a next job in resume should be good enough.

Quoted 2 lines

Best regards,
Tomasz

Ok, we got it.

Sincerely,
Jerry