Commit dbc1fdcb authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

Merge tag 'br-v6.2b' of git://linuxtv.org/hverkuil/media_tree into media_stage

Tag branch

* tag 'br-v6.2b' of git://linuxtv.org/hverkuil/media_tree: (24 commits)
  media: imx-jpeg: Lock on ioctl encoder/decoder stop cmd
  media: imx-jpeg: Support contiguous and non contiguous format
  media: imx-jpeg: Implement g_selection and s_selection
  mtk-jpegdec: add stop cmd interface for jpgdec
  media: mtk-jpegdec: refactor jpegdec func interface
  media: mtk-jpegdec: add output pic reorder interface
  media: mtk-jpegdec: add jpeg decode worker interface
  media: mtk-jpegdec: add jpegdec timeout func interface
  media: mtk-jpegdec: support jpegdec multi-hardware
  media: mtk-jpegdec: export jpeg decoder functions
  dt-bindings: mediatek: Add mediatek,mt8195-jpgdec compatible
  mtk-jpegenc: add stop cmd interface for jpgenc
  mtk-jpegenc: add output pic reorder interface
  mtk-jpegenc: add jpeg encode worker interface
  mtk-jpegenc: add jpegenc timeout func interface
  mtk-jpegenc: support jpegenc multi-hardware
  mtk-jpegenc: export jpeg encoder functions
  dt-bindings: mediatek: Add mediatek, mt8195-jpgenc compatible
  media: imx-jpeg: Disable useless interrupt to avoid kernel panic
  media: imx-jpeg: Don't clear stop state in handling dynamic resolution change
  ...
parents e0eee57e df71c6e4
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/media/mediatek,mt8195-jpegdec.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: MediaTek JPEG Decoder
maintainers:
- kyrie wu <kyrie.wu@mediatek.corp-partner.google.com>
description:
MediaTek JPEG Decoder is the JPEG decode hardware present in MediaTek SoCs
properties:
compatible:
const: mediatek,mt8195-jpgdec
power-domains:
maxItems: 1
iommus:
maxItems: 6
description:
Points to the respective IOMMU block with master port as argument, see
Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml for details.
Ports are according to the HW.
dma-ranges:
maxItems: 1
description: |
Describes the physical address space of IOMMU maps to memory.
"#address-cells":
const: 2
"#size-cells":
const: 2
ranges: true
# Required child node:
patternProperties:
"^jpgdec@[0-9a-f]+$":
type: object
description:
The jpeg decoder hardware device node which should be added as subnodes to
the main jpeg node.
properties:
compatible:
const: mediatek,mt8195-jpgdec-hw
reg:
maxItems: 1
iommus:
minItems: 1
maxItems: 32
description:
List of the hardware port in respective IOMMU block for current Socs.
Refer to bindings/iommu/mediatek,iommu.yaml.
interrupts:
maxItems: 1
clocks:
maxItems: 1
clock-names:
items:
- const: jpgdec
power-domains:
maxItems: 1
required:
- compatible
- reg
- iommus
- interrupts
- clocks
- clock-names
- power-domains
additionalProperties: false
required:
- compatible
- power-domains
- iommus
- dma-ranges
- ranges
additionalProperties: false
examples:
- |
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/memory/mt8195-memory-port.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/clock/mt8195-clk.h>
#include <dt-bindings/power/mt8195-power.h>
soc {
#address-cells = <2>;
#size-cells = <2>;
jpgdec-master {
compatible = "mediatek,mt8195-jpgdec";
power-domains = <&spm MT8195_POWER_DOMAIN_VDEC1>;
iommus = <&iommu_vpp M4U_PORT_L19_JPGDEC_WDMA0>,
<&iommu_vpp M4U_PORT_L19_JPGDEC_BSDMA0>,
<&iommu_vpp M4U_PORT_L19_JPGDEC_WDMA1>,
<&iommu_vpp M4U_PORT_L19_JPGDEC_BSDMA1>,
<&iommu_vpp M4U_PORT_L19_JPGDEC_BUFF_OFFSET1>,
<&iommu_vpp M4U_PORT_L19_JPGDEC_BUFF_OFFSET0>;
dma-ranges = <0x1 0x0 0x0 0x40000000 0x0 0xfff00000>;
#address-cells = <2>;
#size-cells = <2>;
ranges;
jpgdec@1a040000 {
compatible = "mediatek,mt8195-jpgdec-hw";
reg = <0 0x1a040000 0 0x10000>;/* JPGDEC_C0 */
iommus = <&iommu_vdo M4U_PORT_L19_JPGDEC_WDMA0>,
<&iommu_vdo M4U_PORT_L19_JPGDEC_BSDMA0>,
<&iommu_vdo M4U_PORT_L19_JPGDEC_WDMA1>,
<&iommu_vdo M4U_PORT_L19_JPGDEC_BSDMA1>,
<&iommu_vdo M4U_PORT_L19_JPGDEC_BUFF_OFFSET1>,
<&iommu_vdo M4U_PORT_L19_JPGDEC_BUFF_OFFSET0>;
interrupts = <GIC_SPI 343 IRQ_TYPE_LEVEL_HIGH 0>;
clocks = <&vencsys CLK_VENC_JPGDEC>;
clock-names = "jpgdec";
power-domains = <&spm MT8195_POWER_DOMAIN_VDEC0>;
};
jpgdec@1a050000 {
compatible = "mediatek,mt8195-jpgdec-hw";
reg = <0 0x1a050000 0 0x10000>;/* JPGDEC_C1 */
iommus = <&iommu_vdo M4U_PORT_L19_JPGDEC_WDMA0>,
<&iommu_vdo M4U_PORT_L19_JPGDEC_BSDMA0>,
<&iommu_vdo M4U_PORT_L19_JPGDEC_WDMA1>,
<&iommu_vdo M4U_PORT_L19_JPGDEC_BSDMA1>,
<&iommu_vdo M4U_PORT_L19_JPGDEC_BUFF_OFFSET1>,
<&iommu_vdo M4U_PORT_L19_JPGDEC_BUFF_OFFSET0>;
interrupts = <GIC_SPI 344 IRQ_TYPE_LEVEL_HIGH 0>;
clocks = <&vencsys CLK_VENC_JPGDEC_C1>;
clock-names = "jpgdec";
power-domains = <&spm MT8195_POWER_DOMAIN_VDEC1>;
};
jpgdec@1b040000 {
compatible = "mediatek,mt8195-jpgdec-hw";
reg = <0 0x1b040000 0 0x10000>;/* JPGDEC_C2 */
iommus = <&iommu_vpp M4U_PORT_L20_JPGDEC_WDMA0>,
<&iommu_vpp M4U_PORT_L20_JPGDEC_BSDMA0>,
<&iommu_vpp M4U_PORT_L20_JPGDEC_WDMA1>,
<&iommu_vpp M4U_PORT_L20_JPGDEC_BSDMA1>,
<&iommu_vpp M4U_PORT_L20_JPGDEC_BUFF_OFFSET1>,
<&iommu_vpp M4U_PORT_L20_JPGDEC_BUFF_OFFSET0>;
interrupts = <GIC_SPI 348 IRQ_TYPE_LEVEL_HIGH 0>;
clocks = <&vencsys_core1 CLK_VENC_CORE1_JPGDEC>;
clock-names = "jpgdec";
power-domains = <&spm MT8195_POWER_DOMAIN_VDEC2>;
};
};
};
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/media/mediatek,mt8195-jpegenc.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: MediaTek JPEG Encoder
maintainers:
- kyrie wu <kyrie.wu@mediatek.corp-partner.google.com>
description:
MediaTek JPEG Encoder is the JPEG encode hardware present in MediaTek SoCs
properties:
compatible:
const: mediatek,mt8195-jpgenc
power-domains:
maxItems: 1
iommus:
maxItems: 4
description:
Points to the respective IOMMU block with master port as argument, see
Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml for details.
Ports are according to the HW.
dma-ranges:
maxItems: 1
description: |
Describes the physical address space of IOMMU maps to memory.
"#address-cells":
const: 2
"#size-cells":
const: 2
ranges: true
# Required child node:
patternProperties:
"^jpgenc@[0-9a-f]+$":
type: object
description:
The jpeg encoder hardware device node which should be added as subnodes to
the main jpeg node.
properties:
compatible:
const: mediatek,mt8195-jpgenc-hw
reg:
maxItems: 1
iommus:
minItems: 1
maxItems: 32
description:
List of the hardware port in respective IOMMU block for current Socs.
Refer to bindings/iommu/mediatek,iommu.yaml.
interrupts:
maxItems: 1
clocks:
maxItems: 1
clock-names:
items:
- const: jpgenc
power-domains:
maxItems: 1
required:
- compatible
- reg
- iommus
- interrupts
- clocks
- clock-names
- power-domains
additionalProperties: false
required:
- compatible
- power-domains
- iommus
- dma-ranges
- ranges
additionalProperties: false
examples:
- |
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/memory/mt8195-memory-port.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/clock/mt8195-clk.h>
#include <dt-bindings/power/mt8195-power.h>
soc {
#address-cells = <2>;
#size-cells = <2>;
jpgenc-master {
compatible = "mediatek,mt8195-jpgenc";
power-domains = <&spm MT8195_POWER_DOMAIN_VENC_CORE1>;
iommus = <&iommu_vpp M4U_PORT_L20_JPGENC_Y_RDMA>,
<&iommu_vpp M4U_PORT_L20_JPGENC_C_RDMA>,
<&iommu_vpp M4U_PORT_L20_JPGENC_Q_TABLE>,
<&iommu_vpp M4U_PORT_L20_JPGENC_BSDMA>;
dma-ranges = <0x1 0x0 0x0 0x40000000 0x0 0xfff00000>;
#address-cells = <2>;
#size-cells = <2>;
ranges;
jpgenc@1a030000 {
compatible = "mediatek,mt8195-jpgenc-hw";
reg = <0 0x1a030000 0 0x10000>;
iommus = <&iommu_vdo M4U_PORT_L19_JPGENC_Y_RDMA>,
<&iommu_vdo M4U_PORT_L19_JPGENC_C_RDMA>,
<&iommu_vdo M4U_PORT_L19_JPGENC_Q_TABLE>,
<&iommu_vdo M4U_PORT_L19_JPGENC_BSDMA>;
interrupts = <GIC_SPI 342 IRQ_TYPE_LEVEL_HIGH 0>;
clocks = <&vencsys CLK_VENC_JPGENC>;
clock-names = "jpgenc";
power-domains = <&spm MT8195_POWER_DOMAIN_VENC>;
};
jpgenc@1b030000 {
compatible = "mediatek,mt8195-jpgenc-hw";
reg = <0 0x1b030000 0 0x10000>;
iommus = <&iommu_vpp M4U_PORT_L20_JPGENC_Y_RDMA>,
<&iommu_vpp M4U_PORT_L20_JPGENC_C_RDMA>,
<&iommu_vpp M4U_PORT_L20_JPGENC_Q_TABLE>,
<&iommu_vpp M4U_PORT_L20_JPGENC_BSDMA>;
interrupts = <GIC_SPI 347 IRQ_TYPE_LEVEL_HIGH 0>;
clocks = <&vencsys_core1 CLK_VENC_CORE1_JPGENC>;
clock-names = "jpgenc";
power-domains = <&spm MT8195_POWER_DOMAIN_VENC_CORE1>;
};
};
};
......@@ -22,6 +22,7 @@ properties:
- items:
- enum:
- mediatek,mt7623-jpgdec
- mediatek,mt8188-jpgdec
- const: mediatek,mt2701-jpgdec
reg:
......
......@@ -19,6 +19,7 @@ properties:
- mediatek,mt2701-jpgenc
- mediatek,mt8183-jpgenc
- mediatek,mt8186-jpgenc
- mediatek,mt8188-jpgenc
- const: mediatek,mtk-jpgenc
reg:
maxItems: 1
......
# SPDX-License-Identifier: GPL-2.0-only
mtk_jpeg-objs := mtk_jpeg_core.o \
mtk_jpeg_dec_hw.o \
mtk_jpeg_dec_parse.o \
mtk_jpeg_enc_hw.o
obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk_jpeg.o
obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk_jpeg.o \
mtk-jpeg-enc-hw.o \
mtk-jpeg-dec-hw.o
mtk_jpeg-y := mtk_jpeg_core.o \
mtk_jpeg_dec_parse.o
mtk-jpeg-enc-hw-y := mtk_jpeg_enc_hw.o
mtk-jpeg-dec-hw-y := mtk_jpeg_dec_hw.o
......@@ -9,14 +9,16 @@
#ifndef _MTK_JPEG_CORE_H
#define _MTK_JPEG_CORE_H
#include <linux/clk.h>
#include <linux/interrupt.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-fh.h>
#include <media/videobuf2-v4l2.h>
#define MTK_JPEG_NAME "mtk-jpeg"
#include "mtk_jpeg_dec_hw.h"
#define MTK_JPEG_COMP_MAX 3
#define MTK_JPEG_NAME "mtk-jpeg"
#define MTK_JPEG_FMT_FLAG_OUTPUT BIT(0)
#define MTK_JPEG_FMT_FLAG_CAPTURE BIT(1)
......@@ -74,6 +76,115 @@ struct mtk_jpeg_variant {
u32 cap_q_default_fourcc;
};
struct mtk_jpeg_src_buf {
u32 frame_num;
struct vb2_v4l2_buffer b;
struct list_head list;
u32 bs_size;
struct mtk_jpeg_dec_param dec_param;
struct mtk_jpeg_ctx *curr_ctx;
};
enum mtk_jpeg_hw_state {
MTK_JPEG_HW_IDLE = 0,
MTK_JPEG_HW_BUSY = 1,
};
struct mtk_jpeg_hw_param {
struct vb2_v4l2_buffer *src_buffer;
struct vb2_v4l2_buffer *dst_buffer;
struct mtk_jpeg_ctx *curr_ctx;
};
enum mtk_jpegenc_hw_id {
MTK_JPEGENC_HW0,
MTK_JPEGENC_HW1,
MTK_JPEGENC_HW_MAX,
};
enum mtk_jpegdec_hw_id {
MTK_JPEGDEC_HW0,
MTK_JPEGDEC_HW1,
MTK_JPEGDEC_HW2,
MTK_JPEGDEC_HW_MAX,
};
/**
* struct mtk_jpegenc_clk - Structure used to store vcodec clock information
* @clks: JPEG encode clock
* @clk_num: JPEG encode clock numbers
*/
struct mtk_jpegenc_clk {
struct clk_bulk_data *clks;
int clk_num;
};
/**
* struct mtk_jpegdec_clk - Structure used to store vcodec clock information
* @clks: JPEG decode clock
* @clk_num: JPEG decode clock numbers
*/
struct mtk_jpegdec_clk {
struct clk_bulk_data *clks;
int clk_num;
};
/**
* struct mtk_jpegenc_comp_dev - JPEG COREX abstraction
* @dev: JPEG device
* @plat_dev: platform device data
* @reg_base: JPEG registers mapping
* @master_dev: mtk_jpeg_dev device
* @venc_clk: jpeg encode clock
* @jpegenc_irq: jpeg encode irq num
* @job_timeout_work: encode timeout workqueue
* @hw_param: jpeg encode hw parameters
* @hw_rdy: record hw ready
* @hw_state: record hw state
* @hw_lock: spinlock protecting the hw device resource
*/
struct mtk_jpegenc_comp_dev {
struct device *dev;
struct platform_device *plat_dev;
void __iomem *reg_base;
struct mtk_jpeg_dev *master_dev;
struct mtk_jpegenc_clk venc_clk;
int jpegenc_irq;
struct delayed_work job_timeout_work;
struct mtk_jpeg_hw_param hw_param;
enum mtk_jpeg_hw_state hw_state;
/* spinlock protecting the hw device resource */
spinlock_t hw_lock;
};
/**
* struct mtk_jpegdec_comp_dev - JPEG COREX abstraction
* @dev: JPEG device
* @plat_dev: platform device data
* @reg_base: JPEG registers mapping
* @master_dev: mtk_jpeg_dev device
* @jdec_clk: mtk_jpegdec_clk
* @jpegdec_irq: jpeg decode irq num
* @job_timeout_work: decode timeout workqueue
* @hw_param: jpeg decode hw parameters
* @hw_state: record hw state
* @hw_lock: spinlock protecting hw
*/
struct mtk_jpegdec_comp_dev {
struct device *dev;
struct platform_device *plat_dev;
void __iomem *reg_base;
struct mtk_jpeg_dev *master_dev;
struct mtk_jpegdec_clk jdec_clk;
int jpegdec_irq;
struct delayed_work job_timeout_work;
struct mtk_jpeg_hw_param hw_param;
enum mtk_jpeg_hw_state hw_state;
/* spinlock protecting the hw device resource */
spinlock_t hw_lock;
};
/**
* struct mtk_jpeg_dev - JPEG IP abstraction
* @lock: the mutex protecting this structure
......@@ -87,6 +198,17 @@ struct mtk_jpeg_variant {
* @reg_base: JPEG registers mapping
* @job_timeout_work: IRQ timeout structure
* @variant: driver variant to be used
* @reg_encbase: jpg encode register base addr
* @enc_hw_dev: jpg encode hardware device
* @is_jpgenc_multihw: the flag of multi-hw core
* @enc_hw_wq: jpg encode wait queue
* @enchw_rdy: jpg encode hw ready flag
* @reg_decbase: jpg decode register base addr
* @dec_hw_dev: jpg decode hardware device
* @is_jpgdec_multihw: the flag of dec multi-hw core
* @dec_hw_wq: jpg decode wait queue
* @dec_workqueue: jpg decode work queue
* @dechw_rdy: jpg decode hw ready flag
*/
struct mtk_jpeg_dev {
struct mutex lock;
......@@ -100,6 +222,19 @@ struct mtk_jpeg_dev {
void __iomem *reg_base;
struct delayed_work job_timeout_work;
const struct mtk_jpeg_variant *variant;
void __iomem *reg_encbase[MTK_JPEGENC_HW_MAX];
struct mtk_jpegenc_comp_dev *enc_hw_dev[MTK_JPEGENC_HW_MAX];
bool is_jpgenc_multihw;
wait_queue_head_t enc_hw_wq;
atomic_t enchw_rdy;
void __iomem *reg_decbase[MTK_JPEGDEC_HW_MAX];
struct mtk_jpegdec_comp_dev *dec_hw_dev[MTK_JPEGDEC_HW_MAX];
bool is_jpgdec_multihw;
wait_queue_head_t dec_hw_wq;
struct workqueue_struct *dec_workqueue;
atomic_t dechw_rdy;
};
/**
......@@ -138,15 +273,20 @@ struct mtk_jpeg_q_data {
/**
* struct 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
* @state: state of the context
* @enable_exif: enable exif mode of jpeg encoder
* @enc_quality: jpeg encoder quality
* @restart_interval: jpeg encoder restart interval
* @ctrl_hdl: controls handler
* @jpeg: JPEG IP device for this context
* @out_q: source (output) queue information
* @cap_q: destination queue information
* @fh: V4L2 file handle
* @state: state of the context
* @enable_exif: enable exif mode of jpeg encoder
* @enc_quality: jpeg encoder quality
* @restart_interval: jpeg encoder restart interval
* @ctrl_hdl: controls handler
* @jpeg_work: jpeg encoder workqueue
* @total_frame_num: encoded frame number
* @dst_done_queue: encoded frame buffer queue
* @done_queue_lock: encoded frame operation spinlock
* @last_done_frame_num: the last encoded frame number
*/
struct mtk_jpeg_ctx {
struct mtk_jpeg_dev *jpeg;
......@@ -158,6 +298,13 @@ struct mtk_jpeg_ctx {
u8 enc_quality;
u8 restart_interval;
struct v4l2_ctrl_handler ctrl_hdl;
struct work_struct jpeg_work;
u32 total_frame_num;
struct list_head dst_done_queue;
/* spinlock protecting the encode done buffer */
spinlock_t done_queue_lock;
u32 last_done_frame_num;
};
#endif /* _MTK_JPEG_CORE_H */
......@@ -11,9 +11,10 @@
#include <media/videobuf2-core.h>
#include "mtk_jpeg_core.h"
#include "mtk_jpeg_dec_reg.h"
#define MTK_JPEG_COMP_MAX 3
enum {
MTK_JPEG_DEC_RESULT_EOF_DONE = 0,
MTK_JPEG_DEC_RESULT_PAUSE = 1,
......@@ -70,7 +71,8 @@ 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_dec_param *cfg,
u32 bitstream_size,
struct mtk_jpeg_bs *bs,
struct mtk_jpeg_fb *fb);
void mtk_jpeg_dec_reset(void __iomem *dec_reg_base);
......
......@@ -45,5 +45,6 @@
#define JPGDEC_REG_QT_ID 0x0270
#define JPGDEC_REG_INTERRUPT_STATUS 0x0274
#define JPGDEC_REG_STATUS 0x0278
#define JPGDEC_REG_BIT_STREAM_SIZE 0x0344
#endif /* _MTK_JPEG_REG_H */
......@@ -5,11 +5,27 @@
*
*/
#include <linux/clk.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <media/media-device.h>
#include <media/videobuf2-core.h>
#include <media/videobuf2-dma-contig.h>
#include <media/videobuf2-v4l2.h>
#include <media/v4l2-mem2mem.h>
#include <media/v4l2-dev.h>
#include <media/v4l2-device.h>
#include <media/v4l2-fh.h>
#include <media/v4l2-event.h>
#include "mtk_jpeg_core.h"
#include "mtk_jpeg_enc_hw.h"
static const struct mtk_jpeg_enc_qlt mtk_jpeg_enc_quality[] = {
......@@ -30,18 +46,30 @@ static const struct mtk_jpeg_enc_qlt mtk_jpeg_enc_quality[] = {
{.quality_param = 97, .hardware_value = JPEG_ENC_QUALITY_Q97},
};
#if defined(CONFIG_OF)
static const struct of_device_id mtk_jpegenc_drv_ids[] = {
{
.compatible = "mediatek,mt8195-jpgenc-hw",
},
{},
};
MODULE_DEVICE_TABLE(of, mtk_jpegenc_drv_ids);
#endif
void mtk_jpeg_enc_reset(void __iomem *base)
{
writel(0, base + JPEG_ENC_RSTB);
writel(JPEG_ENC_RESET_BIT, base + JPEG_ENC_RSTB);
writel(0, base + JPEG_ENC_CODEC_SEL);
}
EXPORT_SYMBOL_GPL(mtk_jpeg_enc_reset);
u32 mtk_jpeg_enc_get_file_size(void __iomem *base)
{
return readl(base + JPEG_ENC_DMA_ADDR0) -
readl(base + JPEG_ENC_DST_ADDR0);
}
EXPORT_SYMBOL_GPL(mtk_jpeg_enc_get_file_size);
void mtk_jpeg_enc_start(void __iomem *base)
{
......@@ -51,6 +79,7 @@ void mtk_jpeg_enc_start(void __iomem *base)
value |= JPEG_ENC_CTRL_INT_EN_BIT | JPEG_ENC_CTRL_ENABLE_BIT;
writel(value, base + JPEG_ENC_CTRL);
}
EXPORT_SYMBOL_GPL(mtk_jpeg_enc_start);
void mtk_jpeg_set_enc_src(struct mtk_jpeg_ctx *ctx, void __iomem *base,
struct vb2_buffer *src_buf)
......@@ -67,6 +96,7 @@ void mtk_jpeg_set_enc_src(struct mtk_jpeg_ctx *ctx, void __iomem *base,
writel(dma_addr, base + JPEG_ENC_SRC_CHROMA_ADDR);
}
}
EXPORT_SYMBOL_GPL(mtk_jpeg_set_enc_src);
void mtk_jpeg_set_enc_dst(struct mtk_jpeg_ctx *ctx, void __iomem *base,
struct vb2_buffer *dst_buf)
......@@ -86,6 +116,7 @@ void mtk_jpeg_set_enc_dst(struct mtk_jpeg_ctx *ctx, void __iomem *base,
writel(dma_addr & ~0xf, base + JPEG_ENC_DST_ADDR0);
writel((dma_addr + size) & ~0xf, base + JPEG_ENC_STALL_ADDR0);
}
EXPORT_SYMBOL_GPL(mtk_jpeg_set_enc_dst);
void mtk_jpeg_set_enc_params(struct mtk_jpeg_ctx *ctx, void __iomem *base)
{
......@@ -152,3 +183,227 @@ void mtk_jpeg_set_enc_params(struct mtk_jpeg_ctx *ctx, void __iomem *base)
writel(ctx->restart_interval, base + JPEG_ENC_RST_MCU_NUM);
}
EXPORT_SYMBOL_GPL(mtk_jpeg_set_enc_params);
static void mtk_jpegenc_put_buf(struct mtk_jpegenc_comp_dev *jpeg)
{
struct mtk_jpeg_ctx *ctx;
struct vb2_v4l2_buffer *dst_buffer;
struct list_head *temp_entry;
struct list_head *pos = NULL;
struct mtk_jpeg_src_buf *dst_done_buf, *tmp_dst_done_buf;
unsigned long flags;
ctx = jpeg->hw_param.curr_ctx;
if (!ctx) {
dev_err(jpeg->dev, "comp_jpeg ctx fail !!!\n");
return;
}
dst_buffer = jpeg->hw_param.dst_buffer;
if (!dst_buffer) {
dev_err(jpeg->dev, "comp_jpeg dst_buffer fail !!!\n");
return;
}
dst_done_buf = container_of(dst_buffer,
struct mtk_jpeg_src_buf, b);
spin_lock_irqsave(&ctx->done_queue_lock, flags);
list_add_tail(&dst_done_buf->list, &ctx->dst_done_queue);
while (!list_empty(&ctx->dst_done_queue) &&
(pos != &ctx->dst_done_queue)) {
list_for_each_prev_safe(pos, temp_entry, &ctx->dst_done_queue) {
tmp_dst_done_buf = list_entry(pos,
struct mtk_jpeg_src_buf,
list);
if (tmp_dst_done_buf->frame_num ==
ctx->last_done_frame_num) {
list_del(&tmp_dst_done_buf->list);
v4l2_m2m_buf_done(&tmp_dst_done_buf->b,
VB2_BUF_STATE_DONE);
ctx->last_done_frame_num++;
}
}
}
spin_unlock_irqrestore(&ctx->done_queue_lock, flags);
}
static void mtk_jpegenc_timeout_work(struct work_struct *work)
{
struct delayed_work *dly_work = to_delayed_work(work);
struct mtk_jpegenc_comp_dev *cjpeg =
container_of(dly_work,
struct mtk_jpegenc_comp_dev,
job_timeout_work);
struct mtk_jpeg_dev *master_jpeg = cjpeg->master_dev;
enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
src_buf = cjpeg->hw_param.src_buffer;
dst_buf = cjpeg->hw_param.dst_buffer;
v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, true);
mtk_jpeg_enc_reset(cjpeg->reg_base);
clk_disable_unprepare(cjpeg->venc_clk.clks->clk);
pm_runtime_put(cjpeg->dev);
cjpeg->hw_state = MTK_JPEG_HW_IDLE;
atomic_inc(&master_jpeg->enchw_rdy);
wake_up(&master_jpeg->enc_hw_wq);
v4l2_m2m_buf_done(src_buf, buf_state);
mtk_jpegenc_put_buf(cjpeg);
}
static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)
{
struct vb2_v4l2_buffer *src_buf, *dst_buf;
enum vb2_buffer_state buf_state;
struct mtk_jpeg_ctx *ctx;
u32 result_size;
u32 irq_status;
struct mtk_jpegenc_comp_dev *jpeg = priv;
struct mtk_jpeg_dev *master_jpeg = jpeg->master_dev;
cancel_delayed_work(&jpeg->job_timeout_work);
ctx = jpeg->hw_param.curr_ctx;
src_buf = jpeg->hw_param.src_buffer;
dst_buf = jpeg->hw_param.dst_buffer;
v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, true);
irq_status = readl(jpeg->reg_base + JPEG_ENC_INT_STS) &
JPEG_ENC_INT_STATUS_MASK_ALLIRQ;
if (irq_status)
writel(0, jpeg->reg_base + JPEG_ENC_INT_STS);
if (!(irq_status & JPEG_ENC_INT_STATUS_DONE))
dev_warn(jpeg->dev, "Jpg Enc occurs unknown Err.");
result_size = mtk_jpeg_enc_get_file_size(jpeg->reg_base);
vb2_set_plane_payload(&dst_buf->vb2_buf, 0, result_size);
buf_state = VB2_BUF_STATE_DONE;
v4l2_m2m_buf_done(src_buf, buf_state);
mtk_jpegenc_put_buf(jpeg);
pm_runtime_put(ctx->jpeg->dev);
clk_disable_unprepare(jpeg->venc_clk.clks->clk);
if (!list_empty(&ctx->fh.m2m_ctx->out_q_ctx.rdy_queue) ||
!list_empty(&ctx->fh.m2m_ctx->cap_q_ctx.rdy_queue)) {
queue_work(master_jpeg->workqueue, &ctx->jpeg_work);
}
jpeg->hw_state = MTK_JPEG_HW_IDLE;
wake_up(&master_jpeg->enc_hw_wq);
atomic_inc(&master_jpeg->enchw_rdy);
return IRQ_HANDLED;
}
static int mtk_jpegenc_hw_init_irq(struct mtk_jpegenc_comp_dev *dev)
{
struct platform_device *pdev = dev->plat_dev;
int ret;
dev->jpegenc_irq = platform_get_irq(pdev, 0);
if (dev->jpegenc_irq < 0)
return dev->jpegenc_irq;
ret = devm_request_irq(&pdev->dev,
dev->jpegenc_irq,
mtk_jpegenc_hw_irq_handler,
0,
pdev->name, dev);
if (ret) {
dev_err(&pdev->dev, "Failed to devm_request_irq %d (%d)",
dev->jpegenc_irq, ret);
return ret;
}
return 0;
}
static int mtk_jpegenc_hw_probe(struct platform_device *pdev)
{
struct mtk_jpegenc_clk *jpegenc_clk;
struct mtk_jpeg_dev *master_dev;
struct mtk_jpegenc_comp_dev *dev;
int ret, i;
struct device *decs = &pdev->dev;
if (!decs->parent)
return -EPROBE_DEFER;
master_dev = dev_get_drvdata(decs->parent);
if (!master_dev)
return -EPROBE_DEFER;
dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;
dev->plat_dev = pdev;
dev->dev = &pdev->dev;
if (!master_dev->is_jpgenc_multihw) {
master_dev->is_jpgenc_multihw = true;
for (i = 0; i < MTK_JPEGENC_HW_MAX; i++)
master_dev->enc_hw_dev[i] = NULL;
init_waitqueue_head(&master_dev->enc_hw_wq);
master_dev->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
WQ_MEM_RECLAIM
| WQ_FREEZABLE);
if (!master_dev->workqueue)
return -EINVAL;
}
atomic_set(&master_dev->enchw_rdy, MTK_JPEGENC_HW_MAX);
spin_lock_init(&dev->hw_lock);
dev->hw_state = MTK_JPEG_HW_IDLE;
INIT_DELAYED_WORK(&dev->job_timeout_work,
mtk_jpegenc_timeout_work);
jpegenc_clk = &dev->venc_clk;
jpegenc_clk->clk_num = devm_clk_bulk_get_all(&pdev->dev,
&jpegenc_clk->clks);
if (jpegenc_clk->clk_num < 0)
return dev_err_probe(&pdev->dev, jpegenc_clk->clk_num,
"Failed to get jpegenc clock count\n");
dev->reg_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(dev->reg_base))
return PTR_ERR(dev->reg_base);
ret = mtk_jpegenc_hw_init_irq(dev);
if (ret)
return ret;
for (i = 0; i < MTK_JPEGENC_HW_MAX; i++) {
if (master_dev->enc_hw_dev[i])
continue;
master_dev->enc_hw_dev[i] = dev;
master_dev->reg_encbase[i] = dev->reg_base;
dev->master_dev = master_dev;
}
platform_set_drvdata(pdev, dev);
pm_runtime_enable(&pdev->dev);
return 0;
}
static struct platform_driver mtk_jpegenc_hw_driver = {
.probe = mtk_jpegenc_hw_probe,
.driver = {
.name = "mtk-jpegenc-hw",
.of_match_table = of_match_ptr(mtk_jpegenc_drv_ids),
},
};
module_platform_driver(mtk_jpegenc_hw_driver);
MODULE_DESCRIPTION("MediaTek JPEG encode HW driver");
MODULE_LICENSE("GPL");
......@@ -76,12 +76,14 @@ void print_wrapper_info(struct device *dev, void __iomem *reg)
void mxc_jpeg_enable_irq(void __iomem *reg, int slot)
{
writel(0xFFFFFFFF, reg + MXC_SLOT_OFFSET(slot, SLOT_IRQ_EN));
writel(0xFFFFFFFF, reg + MXC_SLOT_OFFSET(slot, SLOT_STATUS));
writel(0xF0C, reg + MXC_SLOT_OFFSET(slot, SLOT_IRQ_EN));
}
void mxc_jpeg_disable_irq(void __iomem *reg, int slot)
{
writel(0x0, reg + MXC_SLOT_OFFSET(slot, SLOT_IRQ_EN));
writel(0xFFFFFFFF, reg + MXC_SLOT_OFFSET(slot, SLOT_STATUS));
}
void mxc_jpeg_sw_reset(void __iomem *reg)
......
......@@ -45,11 +45,13 @@ enum mxc_jpeg_mode {
* @subsampling: subsampling of jpeg components
* @nc: number of color components
* @depth: number of bits per pixel
* @colplanes: number of color planes (1 for packed formats)
* @mem_planes: number of memory planes (1 for packed formats)
* @comp_planes:number of component planes, which includes the alpha plane (1 to 4).
* @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
* @precision: jpeg sample precision
* @is_rgb: is an RGB pixel format
*/
struct mxc_jpeg_fmt {
const char *name;
......@@ -57,11 +59,13 @@ struct mxc_jpeg_fmt {
enum v4l2_jpeg_chroma_subsampling subsampling;
int nc;
int depth;
int colplanes;
int mem_planes;
int comp_planes;
int h_align;
int v_align;
u32 flags;
u8 precision;
u8 is_rgb;
};
struct mxc_jpeg_desc {
......@@ -84,6 +88,7 @@ struct mxc_jpeg_q_data {
int h;
int h_adjusted;
unsigned int sequence;
struct v4l2_rect crop;
};
struct mxc_jpeg_ctx {
......@@ -97,6 +102,7 @@ struct mxc_jpeg_ctx {
bool header_parsed;
struct v4l2_ctrl_handler ctrl_handler;
u8 jpeg_quality;
struct delayed_work task_timer;
};
struct mxc_jpeg_slot_data {
......
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