Commit b2f0d272 authored by Rick Chang's avatar Rick Chang Committed by Mauro Carvalho Chehab

[media] vcodec: mediatek: Add Mediatek JPEG Decoder Driver

Add v4l2 driver for Mediatek JPEG Decoder
Signed-off-by: default avatarRick Chang <rick.chang@mediatek.com>
Signed-off-by: default avatarMinghsiu Tsai <minghsiu.tsai@mediatek.com>
Reviewed-by: default avatarRicky Liang <jcliang@chromium.org>
Tested-by: default avatarRicky Liang <jcliang@chromium.org>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 84a67742
...@@ -165,6 +165,21 @@ config VIDEO_CODA ...@@ -165,6 +165,21 @@ config VIDEO_CODA
config VIDEO_IMX_VDOA config VIDEO_IMX_VDOA
def_tristate VIDEO_CODA if SOC_IMX6Q || COMPILE_TEST def_tristate VIDEO_CODA if SOC_IMX6Q || COMPILE_TEST
config VIDEO_MEDIATEK_JPEG
tristate "Mediatek JPEG Codec driver"
depends on MTK_IOMMU_V1 || COMPILE_TEST
depends on VIDEO_DEV && VIDEO_V4L2
depends on ARCH_MEDIATEK || COMPILE_TEST
depends on HAS_DMA
select VIDEOBUF2_DMA_CONTIG
select V4L2_MEM2MEM_DEV
---help---
Mediatek jpeg codec driver provides HW capability to decode
JPEG format
To compile this driver as a module, choose M here: the
module will be called mtk-jpeg
config VIDEO_MEDIATEK_VPU config VIDEO_MEDIATEK_VPU
tristate "Mediatek Video Processor Unit" tristate "Mediatek Video Processor Unit"
depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
......
...@@ -71,3 +71,5 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VPU) += mtk-vpu/ ...@@ -71,3 +71,5 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VPU) += mtk-vpu/
obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec/ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec/
obj-$(CONFIG_VIDEO_MEDIATEK_MDP) += mtk-mdp/ obj-$(CONFIG_VIDEO_MEDIATEK_MDP) += mtk-mdp/
obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk-jpeg/
mtk_jpeg-objs := mtk_jpeg_core.o mtk_jpeg_hw.o mtk_jpeg_parse.o
obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk_jpeg.o
This diff is collapsed.
/*
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
*
* 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_JPEG_CORE_H
#define _MTK_JPEG_CORE_H
#include <linux/interrupt.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-fh.h>
#define MTK_JPEG_NAME "mtk-jpeg"
#define MTK_JPEG_FMT_FLAG_DEC_OUTPUT BIT(0)
#define MTK_JPEG_FMT_FLAG_DEC_CAPTURE BIT(1)
#define MTK_JPEG_FMT_TYPE_OUTPUT 1
#define MTK_JPEG_FMT_TYPE_CAPTURE 2
#define MTK_JPEG_MIN_WIDTH 32
#define MTK_JPEG_MIN_HEIGHT 32
#define MTK_JPEG_MAX_WIDTH 8192
#define MTK_JPEG_MAX_HEIGHT 8192
#define MTK_JPEG_DEFAULT_SIZEIMAGE (1 * 1024 * 1024)
enum mtk_jpeg_ctx_state {
MTK_JPEG_INIT = 0,
MTK_JPEG_RUNNING,
MTK_JPEG_SOURCE_CHANGE,
};
/**
* struct mt_jpeg - JPEG IP abstraction
* @lock: the mutex protecting this structure
* @hw_lock: spinlock protecting the hw device resource
* @workqueue: decode work queue
* @dev: JPEG device
* @v4l2_dev: v4l2 device for mem2mem mode
* @m2m_dev: v4l2 mem2mem device data
* @alloc_ctx: videobuf2 memory allocator's context
* @dec_vdev: video device node for decoder mem2mem mode
* @dec_reg_base: JPEG registers mapping
* @clk_jdec: JPEG hw working clock
* @clk_jdec_smi: JPEG SMI bus clock
* @larb: SMI device
*/
struct mtk_jpeg_dev {
struct mutex lock;
spinlock_t hw_lock;
struct workqueue_struct *workqueue;
struct device *dev;
struct v4l2_device v4l2_dev;
struct v4l2_m2m_dev *m2m_dev;
void *alloc_ctx;
struct video_device *dec_vdev;
void __iomem *dec_reg_base;
struct clk *clk_jdec;
struct clk *clk_jdec_smi;
struct device *larb;
};
/**
* struct jpeg_fmt - driver's internal color format data
* @fourcc: the fourcc code, 0 if not applicable
* @h_sample: horizontal sample count of plane in 4 * 4 pixel image
* @v_sample: vertical sample count of plane in 4 * 4 pixel image
* @colplanes: number of color planes (1 for packed formats)
* @h_align: horizontal alignment order (align to 2^h_align)
* @v_align: vertical alignment order (align to 2^v_align)
* @flags: flags describing format applicability
*/
struct mtk_jpeg_fmt {
u32 fourcc;
int h_sample[VIDEO_MAX_PLANES];
int v_sample[VIDEO_MAX_PLANES];
int colplanes;
int h_align;
int v_align;
u32 flags;
};
/**
* mtk_jpeg_q_data - parameters of one queue
* @fmt: driver-specific format of this queue
* @w: image width
* @h: image height
* @bytesperline: distance in bytes between the leftmost pixels in two adjacent
* lines
* @sizeimage: image buffer size in bytes
*/
struct mtk_jpeg_q_data {
struct mtk_jpeg_fmt *fmt;
u32 w;
u32 h;
u32 bytesperline[VIDEO_MAX_PLANES];
u32 sizeimage[VIDEO_MAX_PLANES];
};
/**
* mtk_jpeg_ctx - the device context data
* @jpeg: JPEG IP device for this context
* @out_q: source (output) queue information
* @cap_q: destination (capture) queue queue information
* @fh: V4L2 file handle
* @dec_param parameters for HW decoding
* @state: state of the context
* @header_valid: set if header has been parsed and valid
* @colorspace: enum v4l2_colorspace; supplemental to pixelformat
* @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
* @quantization: enum v4l2_quantization, colorspace quantization
* @xfer_func: enum v4l2_xfer_func, colorspace transfer function
*/
struct mtk_jpeg_ctx {
struct mtk_jpeg_dev *jpeg;
struct mtk_jpeg_q_data out_q;
struct mtk_jpeg_q_data cap_q;
struct v4l2_fh fh;
enum mtk_jpeg_ctx_state state;
enum v4l2_colorspace colorspace;
enum v4l2_ycbcr_encoding ycbcr_enc;
enum v4l2_quantization quantization;
enum v4l2_xfer_func xfer_func;
};
#endif /* _MTK_JPEG_CORE_H */
This diff is collapsed.
/*
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
*
* 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_JPEG_HW_H
#define _MTK_JPEG_HW_H
#include <media/videobuf2-core.h>
#include "mtk_jpeg_core.h"
#include "mtk_jpeg_reg.h"
enum {
MTK_JPEG_DEC_RESULT_EOF_DONE = 0,
MTK_JPEG_DEC_RESULT_PAUSE = 1,
MTK_JPEG_DEC_RESULT_UNDERFLOW = 2,
MTK_JPEG_DEC_RESULT_OVERFLOW = 3,
MTK_JPEG_DEC_RESULT_ERROR_BS = 4,
MTK_JPEG_DEC_RESULT_ERROR_UNKNOWN = 6
};
struct mtk_jpeg_dec_param {
u32 pic_w;
u32 pic_h;
u32 dec_w;
u32 dec_h;
u32 src_color;
u32 dst_fourcc;
u32 mcu_w;
u32 mcu_h;
u32 total_mcu;
u32 unit_num;
u32 comp_num;
u32 comp_id[MTK_JPEG_COMP_MAX];
u32 sampling_w[MTK_JPEG_COMP_MAX];
u32 sampling_h[MTK_JPEG_COMP_MAX];
u32 qtbl_num[MTK_JPEG_COMP_MAX];
u32 blk_num;
u32 blk_comp[MTK_JPEG_COMP_MAX];
u32 membership;
u32 dma_mcu;
u32 dma_group;
u32 dma_last_mcu;
u32 img_stride[MTK_JPEG_COMP_MAX];
u32 mem_stride[MTK_JPEG_COMP_MAX];
u32 comp_w[MTK_JPEG_COMP_MAX];
u32 comp_size[MTK_JPEG_COMP_MAX];
u32 y_size;
u32 uv_size;
u32 dec_size;
u8 uv_brz_w;
};
static inline u32 mtk_jpeg_align(u32 val, u32 align)
{
return (val + align - 1) & ~(align - 1);
}
struct mtk_jpeg_bs {
dma_addr_t str_addr;
dma_addr_t end_addr;
size_t size;
};
struct mtk_jpeg_fb {
dma_addr_t plane_addr[MTK_JPEG_COMP_MAX];
size_t size;
};
int mtk_jpeg_dec_fill_param(struct mtk_jpeg_dec_param *param);
u32 mtk_jpeg_dec_get_int_status(void __iomem *dec_reg_base);
u32 mtk_jpeg_dec_enum_result(u32 irq_result);
void mtk_jpeg_dec_set_config(void __iomem *base,
struct mtk_jpeg_dec_param *config,
struct mtk_jpeg_bs *bs,
struct mtk_jpeg_fb *fb);
void mtk_jpeg_dec_reset(void __iomem *dec_reg_base);
void mtk_jpeg_dec_start(void __iomem *dec_reg_base);
#endif /* _MTK_JPEG_HW_H */
/*
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
*
* 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.
*/
#include <linux/kernel.h>
#include <linux/videodev2.h>
#include "mtk_jpeg_parse.h"
#define TEM 0x01
#define SOF0 0xc0
#define RST 0xd0
#define SOI 0xd8
#define EOI 0xd9
struct mtk_jpeg_stream {
u8 *addr;
u32 size;
u32 curr;
};
static int read_byte(struct mtk_jpeg_stream *stream)
{
if (stream->curr >= stream->size)
return -1;
return stream->addr[stream->curr++];
}
static int read_word_be(struct mtk_jpeg_stream *stream, u32 *word)
{
u32 temp;
int byte;
byte = read_byte(stream);
if (byte == -1)
return -1;
temp = byte << 8;
byte = read_byte(stream);
if (byte == -1)
return -1;
*word = (u32)byte | temp;
return 0;
}
static void read_skip(struct mtk_jpeg_stream *stream, long len)
{
if (len <= 0)
return;
while (len--)
read_byte(stream);
}
static bool mtk_jpeg_do_parse(struct mtk_jpeg_dec_param *param, u8 *src_addr_va,
u32 src_size)
{
bool notfound = true;
struct mtk_jpeg_stream stream;
stream.addr = src_addr_va;
stream.size = src_size;
stream.curr = 0;
while (notfound) {
int i, length, byte;
u32 word;
byte = read_byte(&stream);
if (byte == -1)
return false;
if (byte != 0xff)
continue;
do
byte = read_byte(&stream);
while (byte == 0xff);
if (byte == -1)
return false;
if (byte == 0)
continue;
length = 0;
switch (byte) {
case SOF0:
/* length */
if (read_word_be(&stream, &word))
break;
/* precision */
if (read_byte(&stream) == -1)
break;
if (read_word_be(&stream, &word))
break;
param->pic_h = word;
if (read_word_be(&stream, &word))
break;
param->pic_w = word;
param->comp_num = read_byte(&stream);
if (param->comp_num != 1 && param->comp_num != 3)
break;
for (i = 0; i < param->comp_num; i++) {
param->comp_id[i] = read_byte(&stream);
if (param->comp_id[i] == -1)
break;
/* sampling */
byte = read_byte(&stream);
if (byte == -1)
break;
param->sampling_w[i] = (byte >> 4) & 0x0F;
param->sampling_h[i] = byte & 0x0F;
param->qtbl_num[i] = read_byte(&stream);
if (param->qtbl_num[i] == -1)
break;
}
notfound = !(i == param->comp_num);
break;
case RST ... RST + 7:
case SOI:
case EOI:
case TEM:
break;
default:
if (read_word_be(&stream, &word))
break;
length = (long)word - 2;
read_skip(&stream, length);
break;
}
}
return !notfound;
}
bool mtk_jpeg_parse(struct mtk_jpeg_dec_param *param, u8 *src_addr_va,
u32 src_size)
{
if (!mtk_jpeg_do_parse(param, src_addr_va, src_size))
return false;
if (mtk_jpeg_dec_fill_param(param))
return false;
return true;
}
/*
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
*
* 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_JPEG_PARSE_H
#define _MTK_JPEG_PARSE_H
#include "mtk_jpeg_hw.h"
bool mtk_jpeg_parse(struct mtk_jpeg_dec_param *param, u8 *src_addr_va,
u32 src_size);
#endif /* _MTK_JPEG_PARSE_H */
/*
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
*
* 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_JPEG_REG_H
#define _MTK_JPEG_REG_H
#define MTK_JPEG_COMP_MAX 3
#define MTK_JPEG_BLOCK_MAX 10
#define MTK_JPEG_DCTSIZE 8
#define BIT_INQST_MASK_ERROR_BS 0x20
#define BIT_INQST_MASK_PAUSE 0x10
#define BIT_INQST_MASK_OVERFLOW 0x04
#define BIT_INQST_MASK_UNDERFLOW 0x02
#define BIT_INQST_MASK_EOF 0x01
#define BIT_INQST_MASK_ALLIRQ 0x37
#define JPGDEC_REG_RESET 0x0090
#define JPGDEC_REG_BRZ_FACTOR 0x00F8
#define JPGDEC_REG_DU_NUM 0x00FC
#define JPGDEC_REG_DEST_ADDR0_Y 0x0140
#define JPGDEC_REG_DEST_ADDR0_U 0x0144
#define JPGDEC_REG_DEST_ADDR0_V 0x0148
#define JPGDEC_REG_DEST_ADDR1_Y 0x014C
#define JPGDEC_REG_DEST_ADDR1_U 0x0150
#define JPGDEC_REG_DEST_ADDR1_V 0x0154
#define JPGDEC_REG_STRIDE_Y 0x0158
#define JPGDEC_REG_STRIDE_UV 0x015C
#define JPGDEC_REG_IMG_STRIDE_Y 0x0160
#define JPGDEC_REG_IMG_STRIDE_UV 0x0164
#define JPGDEC_REG_WDMA_CTRL 0x016C
#define JPGDEC_REG_PAUSE_MCU_NUM 0x0170
#define JPGDEC_REG_OPERATION_MODE 0x017C
#define JPGDEC_REG_FILE_ADDR 0x0200
#define JPGDEC_REG_COMP_ID 0x020C
#define JPGDEC_REG_TOTAL_MCU_NUM 0x0210
#define JPGDEC_REG_COMP0_DATA_UNIT_NUM 0x0224
#define JPGDEC_REG_DU_CTRL 0x023C
#define JPGDEC_REG_TRIG 0x0240
#define JPGDEC_REG_FILE_BRP 0x0248
#define JPGDEC_REG_FILE_TOTAL_SIZE 0x024C
#define JPGDEC_REG_QT_ID 0x0270
#define JPGDEC_REG_INTERRUPT_STATUS 0x0274
#define JPGDEC_REG_STATUS 0x0278
#endif /* _MTK_JPEG_REG_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment