18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Allwinner Deinterlace driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2019 Jernej Skrabec <jernej.skrabec@siol.net> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _SUN8I_DEINTERLACE_H_ 98c2ecf20Sopenharmony_ci#define _SUN8I_DEINTERLACE_H_ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <media/v4l2-device.h> 128c2ecf20Sopenharmony_ci#include <media/v4l2-mem2mem.h> 138c2ecf20Sopenharmony_ci#include <media/videobuf2-v4l2.h> 148c2ecf20Sopenharmony_ci#include <media/videobuf2-dma-contig.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define DEINTERLACE_NAME "sun8i-di" 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define DEINTERLACE_MOD_ENABLE 0x00 218c2ecf20Sopenharmony_ci#define DEINTERLACE_MOD_ENABLE_EN BIT(0) 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define DEINTERLACE_FRM_CTRL 0x04 248c2ecf20Sopenharmony_ci#define DEINTERLACE_FRM_CTRL_REG_READY BIT(0) 258c2ecf20Sopenharmony_ci#define DEINTERLACE_FRM_CTRL_WB_EN BIT(2) 268c2ecf20Sopenharmony_ci#define DEINTERLACE_FRM_CTRL_OUT_CTRL BIT(11) 278c2ecf20Sopenharmony_ci#define DEINTERLACE_FRM_CTRL_START BIT(16) 288c2ecf20Sopenharmony_ci#define DEINTERLACE_FRM_CTRL_COEF_ACCESS BIT(23) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define DEINTERLACE_BYPASS 0x08 318c2ecf20Sopenharmony_ci#define DEINTERLACE_BYPASS_CSC BIT(1) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define DEINTERLACE_AGTH_SEL 0x0c 348c2ecf20Sopenharmony_ci#define DEINTERLACE_AGTH_SEL_LINEBUF BIT(8) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define DEINTERLACE_LINT_CTRL 0x10 378c2ecf20Sopenharmony_ci#define DEINTERLACE_TRD_PRELUMA 0x1c 388c2ecf20Sopenharmony_ci#define DEINTERLACE_BUF_ADDR0 0x20 398c2ecf20Sopenharmony_ci#define DEINTERLACE_BUF_ADDR1 0x24 408c2ecf20Sopenharmony_ci#define DEINTERLACE_BUF_ADDR2 0x28 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define DEINTERLACE_FIELD_CTRL 0x2c 438c2ecf20Sopenharmony_ci#define DEINTERLACE_FIELD_CTRL_FIELD_CNT(v) ((v) & 0xff) 448c2ecf20Sopenharmony_ci#define DEINTERLACE_FIELD_CTRL_FIELD_CNT_MSK (0xff) 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define DEINTERLACE_TB_OFFSET0 0x30 478c2ecf20Sopenharmony_ci#define DEINTERLACE_TB_OFFSET1 0x34 488c2ecf20Sopenharmony_ci#define DEINTERLACE_TB_OFFSET2 0x38 498c2ecf20Sopenharmony_ci#define DEINTERLACE_TRD_PRECHROMA 0x3c 508c2ecf20Sopenharmony_ci#define DEINTERLACE_LINE_STRIDE0 0x40 518c2ecf20Sopenharmony_ci#define DEINTERLACE_LINE_STRIDE1 0x44 528c2ecf20Sopenharmony_ci#define DEINTERLACE_LINE_STRIDE2 0x48 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define DEINTERLACE_IN_FMT 0x4c 558c2ecf20Sopenharmony_ci#define DEINTERLACE_IN_FMT_PS(v) ((v) & 3) 568c2ecf20Sopenharmony_ci#define DEINTERLACE_IN_FMT_FMT(v) (((v) & 7) << 4) 578c2ecf20Sopenharmony_ci#define DEINTERLACE_IN_FMT_MOD(v) (((v) & 7) << 8) 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define DEINTERLACE_WB_ADDR0 0x50 608c2ecf20Sopenharmony_ci#define DEINTERLACE_WB_ADDR1 0x54 618c2ecf20Sopenharmony_ci#define DEINTERLACE_WB_ADDR2 0x58 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define DEINTERLACE_OUT_FMT 0x5c 648c2ecf20Sopenharmony_ci#define DEINTERLACE_OUT_FMT_FMT(v) ((v) & 0xf) 658c2ecf20Sopenharmony_ci#define DEINTERLACE_OUT_FMT_PS(v) (((v) & 3) << 5) 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define DEINTERLACE_INT_ENABLE 0x60 688c2ecf20Sopenharmony_ci#define DEINTERLACE_INT_ENABLE_WB_EN BIT(7) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define DEINTERLACE_INT_STATUS 0x64 718c2ecf20Sopenharmony_ci#define DEINTERLACE_INT_STATUS_WRITEBACK BIT(7) 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define DEINTERLACE_STATUS 0x68 748c2ecf20Sopenharmony_ci#define DEINTERLACE_STATUS_COEF_STATUS BIT(11) 758c2ecf20Sopenharmony_ci#define DEINTERLACE_STATUS_WB_ERROR BIT(12) 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci#define DEINTERLACE_CSC_COEF 0x70 /* 12 registers */ 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#define DEINTERLACE_CTRL 0xa0 808c2ecf20Sopenharmony_ci#define DEINTERLACE_CTRL_EN BIT(0) 818c2ecf20Sopenharmony_ci#define DEINTERLACE_CTRL_FLAG_OUT_EN BIT(8) 828c2ecf20Sopenharmony_ci#define DEINTERLACE_CTRL_MODE_PASSTROUGH (0 << 16) 838c2ecf20Sopenharmony_ci#define DEINTERLACE_CTRL_MODE_WEAVE (1 << 16) 848c2ecf20Sopenharmony_ci#define DEINTERLACE_CTRL_MODE_BOB (2 << 16) 858c2ecf20Sopenharmony_ci#define DEINTERLACE_CTRL_MODE_MIXED (3 << 16) 868c2ecf20Sopenharmony_ci#define DEINTERLACE_CTRL_DIAG_INTP_EN BIT(24) 878c2ecf20Sopenharmony_ci#define DEINTERLACE_CTRL_TEMP_DIFF_EN BIT(25) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#define DEINTERLACE_DIAG_INTP 0xa4 908c2ecf20Sopenharmony_ci#define DEINTERLACE_DIAG_INTP_TH0(v) ((v) & 0x7f) 918c2ecf20Sopenharmony_ci#define DEINTERLACE_DIAG_INTP_TH0_MSK (0x7f) 928c2ecf20Sopenharmony_ci#define DEINTERLACE_DIAG_INTP_TH1(v) (((v) & 0x7f) << 8) 938c2ecf20Sopenharmony_ci#define DEINTERLACE_DIAG_INTP_TH1_MSK (0x7f << 8) 948c2ecf20Sopenharmony_ci#define DEINTERLACE_DIAG_INTP_TH3(v) (((v) & 0xff) << 24) 958c2ecf20Sopenharmony_ci#define DEINTERLACE_DIAG_INTP_TH3_MSK (0xff << 24) 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#define DEINTERLACE_TEMP_DIFF 0xa8 988c2ecf20Sopenharmony_ci#define DEINTERLACE_TEMP_DIFF_SAD_CENTRAL_TH(v) ((v) & 0x7f) 998c2ecf20Sopenharmony_ci#define DEINTERLACE_TEMP_DIFF_SAD_CENTRAL_TH_MSK (0x7f) 1008c2ecf20Sopenharmony_ci#define DEINTERLACE_TEMP_DIFF_AMBIGUITY_TH(v) (((v) & 0x7f) << 8) 1018c2ecf20Sopenharmony_ci#define DEINTERLACE_TEMP_DIFF_AMBIGUITY_TH_MSK (0x7f << 8) 1028c2ecf20Sopenharmony_ci#define DEINTERLACE_TEMP_DIFF_DIRECT_DITHER_TH(v) (((v) & 0x7ff) << 16) 1038c2ecf20Sopenharmony_ci#define DEINTERLACE_TEMP_DIFF_DIRECT_DITHER_TH_MSK (0x7ff << 16) 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#define DEINTERLACE_LUMA_TH 0xac 1068c2ecf20Sopenharmony_ci#define DEINTERLACE_LUMA_TH_MIN_LUMA(v) ((v) & 0xff) 1078c2ecf20Sopenharmony_ci#define DEINTERLACE_LUMA_TH_MIN_LUMA_MSK (0xff) 1088c2ecf20Sopenharmony_ci#define DEINTERLACE_LUMA_TH_MAX_LUMA(v) (((v) & 0xff) << 8) 1098c2ecf20Sopenharmony_ci#define DEINTERLACE_LUMA_TH_MAX_LUMA_MSK (0xff << 8) 1108c2ecf20Sopenharmony_ci#define DEINTERLACE_LUMA_TH_AVG_LUMA_SHIFT(v) (((v) & 0xff) << 16) 1118c2ecf20Sopenharmony_ci#define DEINTERLACE_LUMA_TH_AVG_LUMA_SHIFT_MSK (0xff << 16) 1128c2ecf20Sopenharmony_ci#define DEINTERLACE_LUMA_TH_PIXEL_STATIC(v) (((v) & 3) << 24) 1138c2ecf20Sopenharmony_ci#define DEINTERLACE_LUMA_TH_PIXEL_STATIC_MSK (3 << 24) 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#define DEINTERLACE_SPAT_COMP 0xb0 1168c2ecf20Sopenharmony_ci#define DEINTERLACE_SPAT_COMP_TH2(v) ((v) & 0xff) 1178c2ecf20Sopenharmony_ci#define DEINTERLACE_SPAT_COMP_TH2_MSK (0xff) 1188c2ecf20Sopenharmony_ci#define DEINTERLACE_SPAT_COMP_TH3(v) (((v) & 0xff) << 16) 1198c2ecf20Sopenharmony_ci#define DEINTERLACE_SPAT_COMP_TH3_MSK (0xff << 16) 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#define DEINTERLACE_CHROMA_DIFF 0xb4 1228c2ecf20Sopenharmony_ci#define DEINTERLACE_CHROMA_DIFF_TH(v) ((v) & 0xff) 1238c2ecf20Sopenharmony_ci#define DEINTERLACE_CHROMA_DIFF_TH_MSK (0xff) 1248c2ecf20Sopenharmony_ci#define DEINTERLACE_CHROMA_DIFF_LUMA(v) (((v) & 0x3f) << 16) 1258c2ecf20Sopenharmony_ci#define DEINTERLACE_CHROMA_DIFF_LUMA_MSK (0x3f << 16) 1268c2ecf20Sopenharmony_ci#define DEINTERLACE_CHROMA_DIFF_CHROMA(v) (((v) & 0x3f) << 24) 1278c2ecf20Sopenharmony_ci#define DEINTERLACE_CHROMA_DIFF_CHROMA_MSK (0x3f << 24) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#define DEINTERLACE_PRELUMA 0xb8 1308c2ecf20Sopenharmony_ci#define DEINTERLACE_PRECHROMA 0xbc 1318c2ecf20Sopenharmony_ci#define DEINTERLACE_TILE_FLAG0 0xc0 1328c2ecf20Sopenharmony_ci#define DEINTERLACE_TILE_FLAG1 0xc4 1338c2ecf20Sopenharmony_ci#define DEINTERLACE_FLAG_LINE_STRIDE 0xc8 1348c2ecf20Sopenharmony_ci#define DEINTERLACE_FLAG_SEQ 0xcc 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#define DEINTERLACE_WB_LINE_STRIDE_CTRL 0xd0 1378c2ecf20Sopenharmony_ci#define DEINTERLACE_WB_LINE_STRIDE_CTRL_EN BIT(0) 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define DEINTERLACE_WB_LINE_STRIDE0 0xd4 1408c2ecf20Sopenharmony_ci#define DEINTERLACE_WB_LINE_STRIDE1 0xd8 1418c2ecf20Sopenharmony_ci#define DEINTERLACE_WB_LINE_STRIDE2 0xdc 1428c2ecf20Sopenharmony_ci#define DEINTERLACE_TRD_CTRL 0xe0 1438c2ecf20Sopenharmony_ci#define DEINTERLACE_TRD_BUF_ADDR0 0xe4 1448c2ecf20Sopenharmony_ci#define DEINTERLACE_TRD_BUF_ADDR1 0xe8 1458c2ecf20Sopenharmony_ci#define DEINTERLACE_TRD_BUF_ADDR2 0xec 1468c2ecf20Sopenharmony_ci#define DEINTERLACE_TRD_TB_OFF0 0xf0 1478c2ecf20Sopenharmony_ci#define DEINTERLACE_TRD_TB_OFF1 0xf4 1488c2ecf20Sopenharmony_ci#define DEINTERLACE_TRD_TB_OFF2 0xf8 1498c2ecf20Sopenharmony_ci#define DEINTERLACE_TRD_WB_STRIDE 0xfc 1508c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_IN_SIZE 0x100 1518c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_OUT_SIZE 0x104 1528c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_HORZ_FACT 0x108 1538c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_VERT_FACT 0x10c 1548c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_HORZ_PHASE 0x110 1558c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_VERT_PHASE0 0x114 1568c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_VERT_PHASE1 0x118 1578c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_HORZ_TAP0 0x120 1588c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_HORZ_TAP1 0x124 1598c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_VERT_TAP 0x128 1608c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_IN_SIZE 0x200 1618c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_OUT_SIZE 0x204 1628c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_HORZ_FACT 0x208 1638c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_VERT_FACT 0x20c 1648c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_HORZ_PHASE 0x210 1658c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_VERT_PHASE0 0x214 1668c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_VERT_PHASE1 0x218 1678c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_HORZ_TAP0 0x220 1688c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_HORZ_TAP1 0x224 1698c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_VERT_TAP 0x228 1708c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_HORZ_COEF0 0x400 /* 32 registers */ 1718c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_HORZ_COEF1 0x480 /* 32 registers */ 1728c2ecf20Sopenharmony_ci#define DEINTERLACE_CH0_VERT_COEF 0x500 /* 32 registers */ 1738c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_HORZ_COEF0 0x600 /* 32 registers */ 1748c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_HORZ_COEF1 0x680 /* 32 registers */ 1758c2ecf20Sopenharmony_ci#define DEINTERLACE_CH1_VERT_COEF 0x700 /* 32 registers */ 1768c2ecf20Sopenharmony_ci#define DEINTERLACE_CH3_HORZ_COEF0 0x800 /* 32 registers */ 1778c2ecf20Sopenharmony_ci#define DEINTERLACE_CH3_HORZ_COEF1 0x880 /* 32 registers */ 1788c2ecf20Sopenharmony_ci#define DEINTERLACE_CH3_VERT_COEF 0x900 /* 32 registers */ 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci#define DEINTERLACE_MIN_WIDTH 2U 1818c2ecf20Sopenharmony_ci#define DEINTERLACE_MIN_HEIGHT 2U 1828c2ecf20Sopenharmony_ci#define DEINTERLACE_MAX_WIDTH 2048U 1838c2ecf20Sopenharmony_ci#define DEINTERLACE_MAX_HEIGHT 1100U 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci#define DEINTERLACE_MODE_UV_COMBINED 2 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci#define DEINTERLACE_IN_FMT_YUV420 2 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci#define DEINTERLACE_OUT_FMT_YUV420SP 13 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci#define DEINTERLACE_PS_UVUV 0 1928c2ecf20Sopenharmony_ci#define DEINTERLACE_PS_VUVU 1 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci#define DEINTERLACE_IDENTITY_COEF 0x4000 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci#define DEINTERLACE_SIZE(w, h) (((h) - 1) << 16 | ((w) - 1)) 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_cistruct deinterlace_ctx { 1998c2ecf20Sopenharmony_ci struct v4l2_fh fh; 2008c2ecf20Sopenharmony_ci struct deinterlace_dev *dev; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci struct v4l2_pix_format src_fmt; 2038c2ecf20Sopenharmony_ci struct v4l2_pix_format dst_fmt; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci void *flag1_buf; 2068c2ecf20Sopenharmony_ci dma_addr_t flag1_buf_dma; 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci void *flag2_buf; 2098c2ecf20Sopenharmony_ci dma_addr_t flag2_buf_dma; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci struct vb2_v4l2_buffer *prev; 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci unsigned int first_field; 2148c2ecf20Sopenharmony_ci unsigned int field; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci int aborting; 2178c2ecf20Sopenharmony_ci}; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistruct deinterlace_dev { 2208c2ecf20Sopenharmony_ci struct v4l2_device v4l2_dev; 2218c2ecf20Sopenharmony_ci struct video_device vfd; 2228c2ecf20Sopenharmony_ci struct device *dev; 2238c2ecf20Sopenharmony_ci struct v4l2_m2m_dev *m2m_dev; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci /* Device file mutex */ 2268c2ecf20Sopenharmony_ci struct mutex dev_mutex; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci void __iomem *base; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci struct clk *bus_clk; 2318c2ecf20Sopenharmony_ci struct clk *mod_clk; 2328c2ecf20Sopenharmony_ci struct clk *ram_clk; 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci struct reset_control *rstc; 2358c2ecf20Sopenharmony_ci}; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci#endif 238