18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/***************************************************************************
38c2ecf20Sopenharmony_ci *   Copyright (C) 2006-2010 by Marin Mitov                                *
48c2ecf20Sopenharmony_ci *   mitov@issp.bas.bg                                                     *
58c2ecf20Sopenharmony_ci *                                                                         *
68c2ecf20Sopenharmony_ci *                                                                         *
78c2ecf20Sopenharmony_ci ***************************************************************************/
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*    DT3155 header file    */
108c2ecf20Sopenharmony_ci#ifndef _DT3155_H_
118c2ecf20Sopenharmony_ci#define _DT3155_H_
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/pci.h>
148c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
158c2ecf20Sopenharmony_ci#include <media/v4l2-device.h>
168c2ecf20Sopenharmony_ci#include <media/v4l2-dev.h>
178c2ecf20Sopenharmony_ci#include <media/videobuf2-v4l2.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define DT3155_NAME "dt3155"
208c2ecf20Sopenharmony_ci#define DT3155_VER_MAJ 2
218c2ecf20Sopenharmony_ci#define DT3155_VER_MIN 0
228c2ecf20Sopenharmony_ci#define DT3155_VER_EXT 0
238c2ecf20Sopenharmony_ci#define DT3155_VERSION  __stringify(DT3155_VER_MAJ)	"."		\
248c2ecf20Sopenharmony_ci			__stringify(DT3155_VER_MIN)	"."		\
258c2ecf20Sopenharmony_ci			__stringify(DT3155_VER_EXT)
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* DT3155 Base Register offsets (memory mapped) */
288c2ecf20Sopenharmony_ci#define EVEN_DMA_START	 0x00
298c2ecf20Sopenharmony_ci#define ODD_DMA_START	 0x0C
308c2ecf20Sopenharmony_ci#define EVEN_DMA_STRIDE  0x18
318c2ecf20Sopenharmony_ci#define ODD_DMA_STRIDE	 0x24
328c2ecf20Sopenharmony_ci#define EVEN_PIXEL_FMT	 0x30
338c2ecf20Sopenharmony_ci#define ODD_PIXEL_FMT	 0x34
348c2ecf20Sopenharmony_ci#define FIFO_TRIGGER	 0x38
358c2ecf20Sopenharmony_ci#define XFER_MODE	 0x3C
368c2ecf20Sopenharmony_ci#define CSR1		 0x40
378c2ecf20Sopenharmony_ci#define RETRY_WAIT_CNT	 0x44
388c2ecf20Sopenharmony_ci#define INT_CSR		 0x48
398c2ecf20Sopenharmony_ci#define EVEN_FLD_MASK	 0x4C
408c2ecf20Sopenharmony_ci#define ODD_FLD_MASK	 0x50
418c2ecf20Sopenharmony_ci#define MASK_LENGTH	 0x54
428c2ecf20Sopenharmony_ci#define FIFO_FLAG_CNT	 0x58
438c2ecf20Sopenharmony_ci#define IIC_CLK_DUR	 0x5C
448c2ecf20Sopenharmony_ci#define IIC_CSR1	 0x60
458c2ecf20Sopenharmony_ci#define IIC_CSR2	 0x64
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/*  DT3155 Internal Registers indexes (i2c/IIC mapped) */
488c2ecf20Sopenharmony_ci#define CSR2	     0x10
498c2ecf20Sopenharmony_ci#define EVEN_CSR     0x11
508c2ecf20Sopenharmony_ci#define ODD_CSR      0x12
518c2ecf20Sopenharmony_ci#define CONFIG	     0x13
528c2ecf20Sopenharmony_ci#define DT_ID	     0x1F
538c2ecf20Sopenharmony_ci#define X_CLIP_START 0x20
548c2ecf20Sopenharmony_ci#define Y_CLIP_START 0x22
558c2ecf20Sopenharmony_ci#define X_CLIP_END   0x24
568c2ecf20Sopenharmony_ci#define Y_CLIP_END   0x26
578c2ecf20Sopenharmony_ci#define AD_ADDR      0x30
588c2ecf20Sopenharmony_ci#define AD_LUT	     0x31
598c2ecf20Sopenharmony_ci#define AD_CMD	     0x32
608c2ecf20Sopenharmony_ci#define DIG_OUT      0x40
618c2ecf20Sopenharmony_ci#define PM_LUT_ADDR  0x50
628c2ecf20Sopenharmony_ci#define PM_LUT_DATA  0x51
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* AD command register values  */
658c2ecf20Sopenharmony_ci#define AD_CMD_REG   0x00
668c2ecf20Sopenharmony_ci#define AD_POS_REF   0x01
678c2ecf20Sopenharmony_ci#define AD_NEG_REF   0x02
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* CSR1 bit masks */
708c2ecf20Sopenharmony_ci#define RANGE_EN       0x00008000
718c2ecf20Sopenharmony_ci#define CRPT_DIS       0x00004000
728c2ecf20Sopenharmony_ci#define ADDR_ERR_ODD   0x00000800
738c2ecf20Sopenharmony_ci#define ADDR_ERR_EVEN  0x00000400
748c2ecf20Sopenharmony_ci#define FLD_CRPT_ODD   0x00000200
758c2ecf20Sopenharmony_ci#define FLD_CRPT_EVEN  0x00000100
768c2ecf20Sopenharmony_ci#define FIFO_EN        0x00000080
778c2ecf20Sopenharmony_ci#define SRST	       0x00000040
788c2ecf20Sopenharmony_ci#define FLD_DN_ODD     0x00000020
798c2ecf20Sopenharmony_ci#define FLD_DN_EVEN    0x00000010
808c2ecf20Sopenharmony_ci/*   These should not be used.
818c2ecf20Sopenharmony_ci *   Use CAP_CONT_ODD/EVEN instead
828c2ecf20Sopenharmony_ci#define CAP_SNGL_ODD   0x00000008
838c2ecf20Sopenharmony_ci#define CAP_SNGL_EVEN  0x00000004
848c2ecf20Sopenharmony_ci*/
858c2ecf20Sopenharmony_ci#define CAP_CONT_ODD   0x00000002
868c2ecf20Sopenharmony_ci#define CAP_CONT_EVEN  0x00000001
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/*  INT_CSR bit masks */
898c2ecf20Sopenharmony_ci#define FLD_START_EN	 0x00000400
908c2ecf20Sopenharmony_ci#define FLD_END_ODD_EN	 0x00000200
918c2ecf20Sopenharmony_ci#define FLD_END_EVEN_EN  0x00000100
928c2ecf20Sopenharmony_ci#define FLD_START	 0x00000004
938c2ecf20Sopenharmony_ci#define FLD_END_ODD	 0x00000002
948c2ecf20Sopenharmony_ci#define FLD_END_EVEN	 0x00000001
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* IIC_CSR1 bit masks */
978c2ecf20Sopenharmony_ci#define DIRECT_ABORT	 0x00000200
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci/* IIC_CSR2 bit masks */
1008c2ecf20Sopenharmony_ci#define NEW_CYCLE   0x01000000
1018c2ecf20Sopenharmony_ci#define DIR_RD	    0x00010000
1028c2ecf20Sopenharmony_ci#define IIC_READ    0x01010000
1038c2ecf20Sopenharmony_ci#define IIC_WRITE   0x01000000
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/* CSR2 bit masks */
1068c2ecf20Sopenharmony_ci#define DISP_PASS     0x40
1078c2ecf20Sopenharmony_ci#define BUSY_ODD      0x20
1088c2ecf20Sopenharmony_ci#define BUSY_EVEN     0x10
1098c2ecf20Sopenharmony_ci#define SYNC_PRESENT  0x08
1108c2ecf20Sopenharmony_ci#define VT_50HZ       0x04
1118c2ecf20Sopenharmony_ci#define SYNC_SNTL     0x02
1128c2ecf20Sopenharmony_ci#define CHROM_FILT    0x01
1138c2ecf20Sopenharmony_ci#define VT_60HZ       0x00
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/* CSR_EVEN/ODD bit masks */
1168c2ecf20Sopenharmony_ci#define CSR_ERROR	0x04
1178c2ecf20Sopenharmony_ci#define CSR_SNGL	0x02
1188c2ecf20Sopenharmony_ci#define CSR_DONE	0x01
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/* CONFIG bit masks */
1218c2ecf20Sopenharmony_ci#define PM_LUT_PGM     0x80
1228c2ecf20Sopenharmony_ci#define PM_LUT_SEL     0x40
1238c2ecf20Sopenharmony_ci#define CLIP_EN        0x20
1248c2ecf20Sopenharmony_ci#define HSCALE_EN      0x10
1258c2ecf20Sopenharmony_ci#define EXT_TRIG_UP    0x0C
1268c2ecf20Sopenharmony_ci#define EXT_TRIG_DOWN  0x04
1278c2ecf20Sopenharmony_ci#define ACQ_MODE_NEXT  0x02
1288c2ecf20Sopenharmony_ci#define ACQ_MODE_ODD   0x01
1298c2ecf20Sopenharmony_ci#define ACQ_MODE_EVEN  0x00
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* AD_CMD bit masks */
1328c2ecf20Sopenharmony_ci#define VIDEO_CNL_1  0x00
1338c2ecf20Sopenharmony_ci#define VIDEO_CNL_2  0x40
1348c2ecf20Sopenharmony_ci#define VIDEO_CNL_3  0x80
1358c2ecf20Sopenharmony_ci#define VIDEO_CNL_4  0xC0
1368c2ecf20Sopenharmony_ci#define SYNC_CNL_1   0x00
1378c2ecf20Sopenharmony_ci#define SYNC_CNL_2   0x10
1388c2ecf20Sopenharmony_ci#define SYNC_CNL_3   0x20
1398c2ecf20Sopenharmony_ci#define SYNC_CNL_4   0x30
1408c2ecf20Sopenharmony_ci#define SYNC_LVL_1   0x00
1418c2ecf20Sopenharmony_ci#define SYNC_LVL_2   0x04
1428c2ecf20Sopenharmony_ci#define SYNC_LVL_3   0x08
1438c2ecf20Sopenharmony_ci#define SYNC_LVL_4   0x0C
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* DT3155 identificator */
1468c2ecf20Sopenharmony_ci#define DT3155_ID   0x20
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci/*    per board private data structure   */
1498c2ecf20Sopenharmony_ci/**
1508c2ecf20Sopenharmony_ci * struct dt3155_priv - private data structure
1518c2ecf20Sopenharmony_ci *
1528c2ecf20Sopenharmony_ci * @v4l2_dev:		v4l2_device structure
1538c2ecf20Sopenharmony_ci * @vdev:		video_device structure
1548c2ecf20Sopenharmony_ci * @pdev:		pointer to pci_dev structure
1558c2ecf20Sopenharmony_ci * @vidq:		vb2_queue structure
1568c2ecf20Sopenharmony_ci * @curr_buf:		pointer to curren buffer
1578c2ecf20Sopenharmony_ci * @mux:		mutex to protect the instance
1588c2ecf20Sopenharmony_ci * @dmaq:		queue for dma buffers
1598c2ecf20Sopenharmony_ci * @lock:		spinlock for dma queue
1608c2ecf20Sopenharmony_ci * @std:		input standard
1618c2ecf20Sopenharmony_ci * @width:		frame width
1628c2ecf20Sopenharmony_ci * @height:		frame height
1638c2ecf20Sopenharmony_ci * @input:		current input
1648c2ecf20Sopenharmony_ci * @sequence:		frame counter
1658c2ecf20Sopenharmony_ci * @stats:		statistics structure
1668c2ecf20Sopenharmony_ci * @regs:		local copy of mmio base register
1678c2ecf20Sopenharmony_ci * @csr2:		local copy of csr2 register
1688c2ecf20Sopenharmony_ci * @config:		local copy of config register
1698c2ecf20Sopenharmony_ci */
1708c2ecf20Sopenharmony_cistruct dt3155_priv {
1718c2ecf20Sopenharmony_ci	struct v4l2_device v4l2_dev;
1728c2ecf20Sopenharmony_ci	struct video_device vdev;
1738c2ecf20Sopenharmony_ci	struct pci_dev *pdev;
1748c2ecf20Sopenharmony_ci	struct vb2_queue vidq;
1758c2ecf20Sopenharmony_ci	struct vb2_v4l2_buffer *curr_buf;
1768c2ecf20Sopenharmony_ci	struct mutex mux;
1778c2ecf20Sopenharmony_ci	struct list_head dmaq;
1788c2ecf20Sopenharmony_ci	spinlock_t lock;
1798c2ecf20Sopenharmony_ci	v4l2_std_id std;
1808c2ecf20Sopenharmony_ci	unsigned width, height;
1818c2ecf20Sopenharmony_ci	unsigned input;
1828c2ecf20Sopenharmony_ci	unsigned int sequence;
1838c2ecf20Sopenharmony_ci	void __iomem *regs;
1848c2ecf20Sopenharmony_ci	u8 csr2, config;
1858c2ecf20Sopenharmony_ci};
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci#endif /*  _DT3155_H_  */
188