Multi Format Codec 5.0 driver for S5PC110 SoC
Subsystems (3)
v3 cover Multi Format Codec 5.0 driver for S5PC110 SoC
Hi,
On the 13th of October I have posted the first version of the MFC 5.1 driver. The second version has been posted on the 2nd of November. Second version has addressed the issued reported in the comments to the initial patch. At that time the videobuf2 API was not final and some changes were made. The third version posted today has been changed to work with the latest videobuf2 version and some other minor improvements have been implemented.
============
Change log
============
1) Update to newest videobuf2 API
This is the major change from v2. The videobuf2 API will hopefully have no more major API changes. Buffer initialization has been moved from buf_prepare callback to buf_init to simplify the process. Locking mechanism has been modified to the requirements of new videobuf2 version.
2) Code cleanup
Removed more magic contants and replaced them with appropriate defines. Changed code to use unlocked_ioctl instead of ioctl in v4l2 file ops.
3) Allocators
All internal buffer allocations are done using the selected vb2 allocator, instead of using CMA functions directly.
I would be grateful for your comments. Original cover letter has been attached below.
Best regards,
Kamil Debski
Original cover letter:
==============
Introduction
==============
The purpose of this RFC is to discuss the driver for a hw video codec embedded in the new Samusng's SoCs. Multi Format Codec 5.0 is able to handle video decoding of in a range of formats.
So far no hardware codec was supported in V4L2 and this would be the first one. I guess there are more similar device that would benefit from a V4L2 unified interface. I suggest a separate control class for codec devices - V4L2_CTRL_CLASS_CODEC.
Internally the driver uses videobuf2 framework and CMA memory allocator. I am aware that those have not yet been merged, but I wanted to start discussion about the driver earlier so it could be merged sooner. The driver posted here is the initial version, so I suppose it will require more work.
==================
Device interface
==================
The driver principle is based on the idea of memory-to-memory devices:
it provides a single video node and each opened file handle gets its own private context with separate buffer queues. Each context consist of 2 buffer queues: OUTPUT (for source buffers, i.e. encoded video frames) and CAPTURE (for destination buffers, i.e. decoded raw video frames). The process of decoding video data from stream is a bit more complicated than typical memory-to-memory processing, that's why the m2m framework is not directly used (it is too limited for this case). The main reason for this is the fact that the CAPTURE buffers can be dequeued in a different order than they queued. The hw block decides which buffer has been completely processed. This is due to the structure of most compressed video streams - use of B frames causes that decoding and display order may be different.
==============================
Decoding initialization path
==============================
First the OUTPUT queue is initialized. With S_FMT the application chooses which video format to decode and what size should be the input buffer. Fourcc values have been defined for different codecs e.g. V4L2_PIX_FMT_H264 for h264. Then the OUTPUT buffers are requested and mmaped. The stream header frame is loaded into the first buffer, queued and streaming is enabled. At this point the hardware is able to start processing the stream header and afterwards it will have information about the video dimensions and the size of the buffers with raw video data.
The next step is setting up the CAPTURE queue and buffers. The width, height, buffer size and minimum number of buffers can be read with G_FMT call. The application can request more output buffer if necessary. After requesting and mmaping buffers the device is ready to decode video stream.
The stream frames (ES frames) are written to the OUTPUT buffers, and decoded video frames can be read from the CAPTURE buffers. When no more source frames are present a single buffer with bytesused set to 0 should be queued. This will inform the driver that processing should be finished and it can dequeue all video frames that are still left. The number of such frames is dependent on the stream and its internal structure (how many frames had to be kept as reference frames for decoding, etc).
===============
Usage summary
===============
This is a step by step summary of the video decoding (from user application point of view, with 2 treads and blocking api):
01. S_FMT(OUTPUT, V4L2_PIX_FMT_H264, ...)
02. REQ_BUFS(OUTPUT, n)
03. for i=1..n MMAP(OUTPUT, i)
04. put stream header to buffer #1
05. QBUF(OUTPUT, #1)
06. STREAM_ON(OUTPUT)
07. G_FMT(CAPTURE)
08. REQ_BUFS(CAPTURE, m)
09. for j=1..m MMAP(CAPTURE, j)
10. for j=1..m QBUF(CAPTURE, #j)
11. STREAM_ON(CAPTURE)
display thread:
12. DQBUF(CAPTURE) -> got decoded video data in buffer #j
13. display buffer #j
14. QBUF(CAPTURE, #j)
15. goto 12
parser thread:
16. put next ES frame to buffer #i
17. QBUF(OUTPUT, #i)
18. DQBUF(OUTPUT) -> get next empty buffer #i 19. goto 16
...
Similar usage sequence can be achieved with single threaded application and non-blocking api with poll() call.
Branch with MFC, CMA and videobuf2 will be soon available at
http://git.infradead.org/users/kmpark/linux-2.6-samsung/shortlog/refs/heads/vb2-mfc-fimc
This tree is based on 2.6.37 rc4.
Please have a look at the code and the idea of how to introduce codec devices to V4L2. Comments will be very much appreciated.
Patch summary:
Kamil Debski (4):
Changes in include/linux/videodev2.h for MFC
MFC: Add MFC 5.1 driver to plat-s5p
MFC: Added MFC 5.1 V4L2 driver
s5pv210: Enable MFC 5.1 on Goni
arch/arm/mach-s5pv210/Kconfig | 1 + arch/arm/mach-s5pv210/clock.c | 6 + arch/arm/mach-s5pv210/include/mach/map.h | 4 + arch/arm/mach-s5pv210/mach-goni.c | 1 + arch/arm/plat-s5p/Kconfig | 5 + arch/arm/plat-s5p/Makefile | 1 + arch/arm/plat-s5p/dev-mfc5.c | 37 + arch/arm/plat-samsung/include/plat/devs.h | 2 + drivers/media/video/Kconfig | 8 + drivers/media/video/Makefile | 1 + drivers/media/video/s5p-mfc/Makefile | 3 + drivers/media/video/s5p-mfc/regs-mfc5.h | 323 ++++ drivers/media/video/s5p-mfc/s5p_mfc.c | 2014 +++++++++++++++++++++++ drivers/media/video/s5p-mfc/s5p_mfc_common.h | 222 +++ drivers/media/video/s5p-mfc/s5p_mfc_ctrls.h | 173 ++ drivers/media/video/s5p-mfc/s5p_mfc_debug.h | 44 + drivers/media/video/s5p-mfc/s5p_mfc_intr.c | 92 + drivers/media/video/s5p-mfc/s5p_mfc_intr.h | 26 + drivers/media/video/s5p-mfc/s5p_mfc_memory.h | 43 + drivers/media/video/s5p-mfc/s5p_mfc_opr.c | 888 ++++++++++ drivers/media/video/s5p-mfc/s5p_mfc_opr.h | 131 ++ include/linux/videodev2.h | 48 + 25 files changed, 4122 insertions(+), 1 deletions(-) create mode 100644 arch/arm/plat-s5p/dev-mfc5.c create mode 100644 drivers/media/video/s5p-mfc/Makefile create mode 100644 drivers/media/video/s5p-mfc/regs-mfc5.h create mode 100644 drivers/media/video/s5p-mfc/s5p_mfc.c create mode 100644 drivers/media/video/s5p-mfc/s5p_mfc_common.h create mode 100644 drivers/media/video/s5p-mfc/s5p_mfc_ctrls.h create mode 100644 drivers/media/video/s5p-mfc/s5p_mfc_debug.h create mode 100644 drivers/media/video/s5p-mfc/s5p_mfc_intr.c create mode 100644 drivers/media/video/s5p-mfc/s5p_mfc_intr.h create mode 100644 drivers/media/video/s5p-mfc/s5p_mfc_memory.h create mode 100644 drivers/media/video/s5p-mfc/s5p_mfc_opr.c create mode 100644 drivers/media/video/s5p-mfc/s5p_mfc_opr.h
PATCH v3 1/4 Changes in include/linux/videodev2.h for MFC
Add fourcc values for compressed video stream formats and V4L2_CTRL_CLASS_CODEC. Also adds controls used by MFC driver.
--- include/linux/videodev2.h | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-)
include/linux/videodev2.h +48 -0
@@ -339,6 +339,14 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_NV16 v4l2_fourcc('N', 'V', '1', '6')/* 16 Y/CbCr 4:2:2 */ #define V4L2_PIX_FMT_NV61 v4l2_fourcc('N', 'V', '6', '1')/* 16 Y/CrCb 4:2:2 */ +/* two non contiguous planes -- one Y, one Cr + Cb interleaved */ +#define V4L2_PIX_FMT_NV12M v4l2_fourcc('N', 'M', '1', '2')/* 12 Y/CbCr 4:2:0 */ +/* 12 Y/CbCr 4:2:0 64x32 macroblocks */ +#define V4L2_PIX_FMT_NV12MT v4l2_fourcc('T', 'M', '1', '2') + +/* three non contiguous planes -- Y, Cb, Cr */ +#define V4L2_PIX_FMT_YUV420M v4l2_fourcc('Y', 'M', '1', '2')/* 12 YUV420 planar */ +/* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */ #define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B', 'A', '8', '1')/* 8 BGBG.. GRGR.. */ #define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G', 'B', 'R', 'G')/* 8 GBGB.. RGRG.. */
@@ -362,6 +370,21 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_DV v4l2_fourcc('d', 'v', 's', 'd')/* 1394 */ #define V4L2_PIX_FMT_MPEG v4l2_fourcc('M', 'P', 'E', 'G')/* MPEG-1/2/4 */ + +#define V4L2_PIX_FMT_H264 v4l2_fourcc('H', '2', '6', '4')/* H264 */ +#define V4L2_PIX_FMT_H263 v4l2_fourcc('H', '2', '6', '3')/* H263 */ +#define V4L2_PIX_FMT_MPEG12 v4l2_fourcc('M', 'P', '1', '2')/* MPEG-1/2 */ +#define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4')/* MPEG-4 */ +#define V4L2_PIX_FMT_DIVX v4l2_fourcc('D', 'I', 'V', 'X')/* DivX */ +#define V4L2_PIX_FMT_DIVX3 v4l2_fourcc('D', 'I', 'V', '3')/* DivX 3.11 */ +#define V4L2_PIX_FMT_DIVX4 v4l2_fourcc('D', 'I', 'V', '4')/* DivX 4.12 */ +#define V4L2_PIX_FMT_DIVX500 v4l2_fourcc('D', 'X', '5', '2')/* DivX 5.00 - 5.02 */ +#define V4L2_PIX_FMT_DIVX503 v4l2_fourcc('D', 'X', '5', '3')/* DivX 5.03 - x */ +#define V4L2_PIX_FMT_XVID v4l2_fourcc('X', 'V', 'I', 'D')/* Xvid */ +#define V4L2_PIX_FMT_VC1 v4l2_fourcc('V', 'C', '1', 'A')/* VC-1 */ +#define V4L2_PIX_FMT_VC1_RCV v4l2_fourcc('V', 'C', '1', 'R')/* VC-1 RCV */ + +/* Vendor-specific formats */ #define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A')/* cpia1 YUV */ #define V4L2_PIX_FMT_WNVA v4l2_fourcc('W', 'N', 'V', 'A')/* Winnov hw compress */
@@ -972,6 +995,7 @@ struct v4l2_output {#define V4L2_OUTPUT_TYPE_ANALOG 2#define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY 3 +/* capabilities flags */ #define V4L2_OUT_CAP_PRESETS 0x00000001/* Supports S_DV_PRESET */ #define V4L2_OUT_CAP_CUSTOM_TIMINGS 0x00000002/* Supports S_DV_TIMINGS */
@@ -1009,6 +1033,7 @@ struct v4l2_ext_controls {#define V4L2_CTRL_CLASS_MPEG 0x00990000/* MPEG-compression controls */ #define V4L2_CTRL_CLASS_CAMERA 0x009a0000/* Camera class controls */ #define V4L2_CTRL_CLASS_FM_TX 0x009b0000/* FM Modulator control class */ +#define V4L2_CTRL_CLASS_CODEC 0x009c0000/* Codec control class */ #define V4L2_CTRL_ID_MASK (0x0fffffff)#define V4L2_CTRL_ID2CLASS (id) ((id) & 0x0fff0000UL)
@@ -1342,6 +1367,29 @@ enum v4l2_mpeg_cx2341x_video_median_filter_type {#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+10)#define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS (V4L2_CID_MPEG_CX2341X_BASE+11) +/* For codecs */ + +#define V4L2_CID_CODEC_BASE (V4L2_CTRL_CLASS_CODEC | 0x900) +#define V4L2_CID_CODEC_CLASS (V4L2_CTRL_CLASS_CODEC | 1) + +/* For both decoding and encoding */ + +/* For encoding */ +#define V4L2_CID_CODEC_LOOP_FILTER_H264 (V4L2_CID_CODEC_BASE + 9) +enum v4l2_cid_codec_loop_filter_h264 { +V4L2_CID_CODEC_LOOP_FILTER_H264_ENABLE =0 , +V4L2_CID_CODEC_LOOP_FILTER_H264_DISABLE =1 , +V4L2_CID_CODEC_LOOP_FILTER_H264_DISABLE_AT_BOUNDARY =2 , +}; + +/* For decoding */ + +#define V4L2_CID_CODEC_LOOP_FILTER_MPEG4_ENABLE (V4L2_CID_CODEC_BASE + 110) +#define V4L2_CID_CODEC_DISPLAY_DELAY (V4L2_CID_CODEC_BASE + 137) +#define V4L2_CID_CODEC_REQ_NUM_BUFS (V4L2_CID_CODEC_BASE + 140) +#define V4L2_CID_CODEC_SLICE_INTERFACE (V4L2_CID_CODEC_BASE + 141) +#define V4L2_CID_CODEC_PACKED_PB (V4L2_CID_CODEC_BASE + 142) +/* Camera class control IDs */ #define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)#define V4L2_CID_CAMERA_CLASS (V4L2_CTRL_CLASS_CAMERA | 1)
Signature · 1 line
1.6.3.3
PATCH v3 2/4 MFC: Add MFC 5.1 driver to plat-s5p
In reply to Kamil DebskiAdd platform support for Multi Format Codec 5.1 is a module available on S5PC110 and S5PC210 Samsung SoCs. Hardware is capable of handling a range of video codecs and this driver provides V4L2 interface for video decoding.
--- arch/arm/mach-s5pv210/clock.c | 6 ++++ arch/arm/mach-s5pv210/include/mach/map.h | 4 ++ arch/arm/plat-s5p/Kconfig | 5 +++ arch/arm/plat-s5p/Makefile | 1 + arch/arm/plat-s5p/dev-mfc5.c | 37 +++++++++++++++++++++++ arch/arm/plat-samsung/include/plat/devs.h | 2 + 9 files changed, 104 insertions(+), 1 deletions(-) create mode 100644 arch/arm/plat-s5p/dev-mfc5.c
arch/arm/mach-s5pv210/clock.c +6 -0
@@ -364,6 +364,12 @@ static struct clk init_clocks_disable[] = { .enable = s5pv210_clk_ip0_ctrl, .ctrlbit = (1 << 26), }, { + .name = "mfc", + .id = -1, + .parent = &clk_pclk_psys.clk, + .enable = s5pv210_clk_ip0_ctrl, + .ctrlbit = (1 << 16), + }, { .name = "nfcon", .id = -1, .parent = &clk_hclk_psys.clk,
arch/arm/mach-s5pv210/include/mach/map.h +4 -0
@@ -107,6 +107,9 @@#define S5PV210_PA_DMC0 (0xF0000000)#define S5PV210_PA_DMC1 (0xF1400000) +/* MFC */ +#define S5PV210_PA_MFC (0xF1700000) +/* compatibiltiy defines. */ #define S3C_PA_UART S5PV210_PA_UART#define S3C_PA_HSMMC0 S5PV210_PA_HSMMC(0)
@@ -123,6 +126,7 @@#define S5P_PA_FIMC0 S5PV210_PA_FIMC0#define S5P_PA_FIMC1 S5PV210_PA_FIMC1#define S5P_PA_FIMC2 S5PV210_PA_FIMC2 +#define S5P_PA_MFC S5PV210_PA_MFC#define SAMSUNG_PA_ADC S5PV210_PA_ADC#define SAMSUNG_PA_CFCON S5PV210_PA_CFCON
arch/arm/plat-s5p/Kconfig +5 -0
@@ -5,6 +5,11 @@ # # Licensed under GPLv2 +config S5P_DEV_MFC + bool + help + Compile in platform device definitions for MFC + config PLAT_S5P bool depends on (ARCH_S5P64X0 || ARCH_S5P6442 || ARCH_S5PC100 || ARCH_S5PV210 || ARCH_S5PV310)
arch/arm/plat-s5p/Makefile +1 -0
@@ -23,6 +23,7 @@ obj-$(CONFIG_PM) += pm.o obj-$(CONFIG_PM) += irq-pm.o # devices +obj-$(CONFIG_S5P_DEV_MFC) += dev-mfc5.o obj-$(CONFIG_S5P_DEV_FIMC0) += dev-fimc0.o obj-$(CONFIG_S5P_DEV_FIMC1) += dev-fimc1.o
arch/arm/plat-s5p/dev-mfc5.c new file +37 -0
@@ -0,0 +1,37 @@ +/* Base S3C64XX mfc resource and device definitions */ + + +#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/platform_device.h> +#include <linux/ioport.h> + +#include <mach/map.h> +#include <plat/map-base.h> +#include <plat/devs.h> +#include <plat/irqs.h> + +/* MFC controller */ +static struct resource s5p_mfc_resource[] = { + [0 ] = { + .start =S5P_PA_MFC , + .end =S5P_PA_MFC +SZ_64K -1 , + .flags =IORESOURCE_MEM , + }, + [1 ] = { + .start =IRQ_MFC , + .end =IRQ_MFC , + .flags =IORESOURCE_IRQ , + } +}; + +struct platform_device s5p_device_mfc5 = { + .name ="s5p-mfc5" , + .id =-1 , + .num_resources =ARRAY_SIZE (s5p_mfc_resource), + .resource = s5p_mfc_resource, +}; + +EXPORT_SYMBOL (s5p_device_mfc5); + +
arch/arm/plat-samsung/include/plat/devs.h +2 -0
@@ -124,6 +124,8 @@ extern struct platform_device s5p_device_fimc2;extern struct platform_device s5p_device_fimc3;extern struct platform_device s5pv310_device_fb0; +extern struct platform_device s5p_device_mfc5; +/* s3c2440 specific devices */ #ifdef CONFIG_CPU_S3C2440
Signature · 1 line
1.6.3.3
PATCH v3 4/4 s5pv210: Enable MFC on Goni
In reply to Kamil DebskiMulti Format Codec 5.1 is a module available on S5PC110 and S5PC210 Samsung SoCs. Hardware is capable of handling a range of video codecs.
--- arch/arm/mach-s5pv210/Kconfig | 1 + arch/arm/mach-s5pv210/mach-goni.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/mach-s5pv210/Kconfig +1 -0
@@ -85,6 +85,7 @@ config MACH_GONI select S3C_DEV_HSMMC2 select S3C_DEV_I2C1 select S3C_DEV_I2C2 + select S5P_DEV_MFC select S3C_DEV_USB_HSOTG select S5P_DEV_ONENAND select SAMSUNG_DEV_KEYPAD
arch/arm/mach-s5pv210/mach-goni.c +1 -0
@@ -810,6 +810,7 @@ static struct platform_device *goni_devices[] __initdata = { &goni_i2c_gpio5, &mmc2_fixed_voltage, &goni_device_gpiokeys, + &s5p_device_mfc5, &s5p_device_fimc0, &s5p_device_fimc1, &s5p_device_fimc2,
Signature · 1 line
1.6.3.3