162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2012 Samsung Electronics Co., Ltd.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef FIMC_LITE_REG_H_
762306a36Sopenharmony_ci#define FIMC_LITE_REG_H_
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/bitops.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include "fimc-lite.h"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/* Camera Source size */
1462306a36Sopenharmony_ci#define FLITE_REG_CISRCSIZE			0x00
1562306a36Sopenharmony_ci#define FLITE_REG_CISRCSIZE_ORDER422_IN_YCBYCR	(0 << 14)
1662306a36Sopenharmony_ci#define FLITE_REG_CISRCSIZE_ORDER422_IN_YCRYCB	(1 << 14)
1762306a36Sopenharmony_ci#define FLITE_REG_CISRCSIZE_ORDER422_IN_CBYCRY	(2 << 14)
1862306a36Sopenharmony_ci#define FLITE_REG_CISRCSIZE_ORDER422_IN_CRYCBY	(3 << 14)
1962306a36Sopenharmony_ci#define FLITE_REG_CISRCSIZE_ORDER422_MASK	(0x3 << 14)
2062306a36Sopenharmony_ci#define FLITE_REG_CISRCSIZE_SIZE_CAM_MASK	(0x3fff << 16 | 0x3fff)
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/* Global control */
2362306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL			0x04
2462306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_YUV422_1P		(0x1e << 24)
2562306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_RAW8			(0x2a << 24)
2662306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_RAW10			(0x2b << 24)
2762306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_RAW12			(0x2c << 24)
2862306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_RAW14			(0x2d << 24)
2962306a36Sopenharmony_ci/* User defined formats. x = 0...15 */
3062306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_USER(x)		((0x30 + x - 1) << 24)
3162306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_FMT_MASK		(0x3f << 24)
3262306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_SHADOWMASK_DISABLE	BIT(21)
3362306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_ODMA_DISABLE		BIT(20)
3462306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_SWRST_REQ		BIT(19)
3562306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_SWRST_RDY		BIT(18)
3662306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_SWRST			BIT(17)
3762306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_TEST_PATTERN_COLORBAR	BIT(15)
3862306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_INVPOLPCLK		BIT(14)
3962306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_INVPOLVSYNC		BIT(13)
4062306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_INVPOLHREF		BIT(12)
4162306a36Sopenharmony_ci/* Interrupts mask bits (1 disables an interrupt) */
4262306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_IRQ_LASTEN		BIT(8)
4362306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_IRQ_ENDEN		BIT(7)
4462306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_IRQ_STARTEN		BIT(6)
4562306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_IRQ_OVFEN		BIT(5)
4662306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_IRQ_DISABLE_MASK	(0xf << 5)
4762306a36Sopenharmony_ci#define FLITE_REG_CIGCTRL_SELCAM_MIPI		BIT(3)
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/* Image Capture Enable */
5062306a36Sopenharmony_ci#define FLITE_REG_CIIMGCPT			0x08
5162306a36Sopenharmony_ci#define FLITE_REG_CIIMGCPT_IMGCPTEN		BIT(31)
5262306a36Sopenharmony_ci#define FLITE_REG_CIIMGCPT_CPT_FREN		BIT(25)
5362306a36Sopenharmony_ci#define FLITE_REG_CIIMGCPT_CPT_MOD_FRCNT	(1 << 18)
5462306a36Sopenharmony_ci#define FLITE_REG_CIIMGCPT_CPT_MOD_FREN		(0 << 18)
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/* Capture Sequence */
5762306a36Sopenharmony_ci#define FLITE_REG_CICPTSEQ			0x0c
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci/* Camera Window Offset */
6062306a36Sopenharmony_ci#define FLITE_REG_CIWDOFST			0x10
6162306a36Sopenharmony_ci#define FLITE_REG_CIWDOFST_WINOFSEN		BIT(31)
6262306a36Sopenharmony_ci#define FLITE_REG_CIWDOFST_CLROVIY		BIT(31)
6362306a36Sopenharmony_ci#define FLITE_REG_CIWDOFST_CLROVFICB		BIT(15)
6462306a36Sopenharmony_ci#define FLITE_REG_CIWDOFST_CLROVFICR		BIT(14)
6562306a36Sopenharmony_ci#define FLITE_REG_CIWDOFST_OFST_MASK		((0x1fff << 16) | 0x1fff)
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci/* Camera Window Offset2 */
6862306a36Sopenharmony_ci#define FLITE_REG_CIWDOFST2			0x14
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci/* Camera Output DMA Format */
7162306a36Sopenharmony_ci#define FLITE_REG_CIODMAFMT			0x18
7262306a36Sopenharmony_ci#define FLITE_REG_CIODMAFMT_RAW_CON		BIT(15)
7362306a36Sopenharmony_ci#define FLITE_REG_CIODMAFMT_PACK12		BIT(14)
7462306a36Sopenharmony_ci#define FLITE_REG_CIODMAFMT_YCBYCR		(0 << 4)
7562306a36Sopenharmony_ci#define FLITE_REG_CIODMAFMT_YCRYCB		(1 << 4)
7662306a36Sopenharmony_ci#define FLITE_REG_CIODMAFMT_CBYCRY		(2 << 4)
7762306a36Sopenharmony_ci#define FLITE_REG_CIODMAFMT_CRYCBY		(3 << 4)
7862306a36Sopenharmony_ci#define FLITE_REG_CIODMAFMT_YCBCR_ORDER_MASK	(0x3 << 4)
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci/* Camera Output Canvas */
8162306a36Sopenharmony_ci#define FLITE_REG_CIOCAN			0x20
8262306a36Sopenharmony_ci#define FLITE_REG_CIOCAN_MASK			((0x3fff << 16) | 0x3fff)
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci/* Camera Output DMA Offset */
8562306a36Sopenharmony_ci#define FLITE_REG_CIOOFF			0x24
8662306a36Sopenharmony_ci#define FLITE_REG_CIOOFF_MASK			((0x3fff << 16) | 0x3fff)
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/* Camera Output DMA Start Address */
8962306a36Sopenharmony_ci#define FLITE_REG_CIOSA				0x30
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci/* Camera Status */
9262306a36Sopenharmony_ci#define FLITE_REG_CISTATUS			0x40
9362306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_MIPI_VVALID		BIT(22)
9462306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_MIPI_HVALID		BIT(21)
9562306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_MIPI_DVALID		BIT(20)
9662306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_ITU_VSYNC		BIT(14)
9762306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_ITU_HREFF		BIT(13)
9862306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_OVFIY		BIT(10)
9962306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_OVFICB		BIT(9)
10062306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_OVFICR		BIT(8)
10162306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_IRQ_SRC_OVERFLOW	BIT(7)
10262306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_IRQ_SRC_LASTCAPEND	BIT(6)
10362306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_IRQ_SRC_FRMSTART	BIT(5)
10462306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_IRQ_SRC_FRMEND	BIT(4)
10562306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_IRQ_CAM		BIT(0)
10662306a36Sopenharmony_ci#define FLITE_REG_CISTATUS_IRQ_MASK		(0xf << 4)
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/* Camera Status2 */
10962306a36Sopenharmony_ci#define FLITE_REG_CISTATUS2			0x44
11062306a36Sopenharmony_ci#define FLITE_REG_CISTATUS2_LASTCAPEND		BIT(1)
11162306a36Sopenharmony_ci#define FLITE_REG_CISTATUS2_FRMEND		BIT(0)
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* Qos Threshold */
11462306a36Sopenharmony_ci#define FLITE_REG_CITHOLD			0xf0
11562306a36Sopenharmony_ci#define FLITE_REG_CITHOLD_W_QOS_EN		BIT(30)
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/* Camera General Purpose */
11862306a36Sopenharmony_ci#define FLITE_REG_CIGENERAL			0xfc
11962306a36Sopenharmony_ci/* b0: 1 - camera B, 0 - camera A */
12062306a36Sopenharmony_ci#define FLITE_REG_CIGENERAL_CAM_B		BIT(0)
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci#define FLITE_REG_CIFCNTSEQ			0x100
12362306a36Sopenharmony_ci#define FLITE_REG_CIOSAN(x)			(0x200 + (4 * (x)))
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/* ----------------------------------------------------------------------------
12662306a36Sopenharmony_ci * Function declarations
12762306a36Sopenharmony_ci */
12862306a36Sopenharmony_civoid flite_hw_reset(struct fimc_lite *dev);
12962306a36Sopenharmony_civoid flite_hw_clear_pending_irq(struct fimc_lite *dev);
13062306a36Sopenharmony_ciu32 flite_hw_get_interrupt_source(struct fimc_lite *dev);
13162306a36Sopenharmony_civoid flite_hw_clear_last_capture_end(struct fimc_lite *dev);
13262306a36Sopenharmony_civoid flite_hw_set_interrupt_mask(struct fimc_lite *dev);
13362306a36Sopenharmony_civoid flite_hw_capture_start(struct fimc_lite *dev);
13462306a36Sopenharmony_civoid flite_hw_capture_stop(struct fimc_lite *dev);
13562306a36Sopenharmony_civoid flite_hw_set_camera_bus(struct fimc_lite *dev,
13662306a36Sopenharmony_ci			     struct fimc_source_info *s_info);
13762306a36Sopenharmony_civoid flite_hw_set_camera_polarity(struct fimc_lite *dev,
13862306a36Sopenharmony_ci				  struct fimc_source_info *cam);
13962306a36Sopenharmony_civoid flite_hw_set_window_offset(struct fimc_lite *dev, struct flite_frame *f);
14062306a36Sopenharmony_civoid flite_hw_set_source_format(struct fimc_lite *dev, struct flite_frame *f);
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_civoid flite_hw_set_output_dma(struct fimc_lite *dev, struct flite_frame *f,
14362306a36Sopenharmony_ci			     bool enable);
14462306a36Sopenharmony_civoid flite_hw_set_dma_window(struct fimc_lite *dev, struct flite_frame *f);
14562306a36Sopenharmony_civoid flite_hw_set_test_pattern(struct fimc_lite *dev, bool on);
14662306a36Sopenharmony_civoid flite_hw_dump_regs(struct fimc_lite *dev, const char *label);
14762306a36Sopenharmony_civoid flite_hw_set_dma_buffer(struct fimc_lite *dev, struct flite_buffer *buf);
14862306a36Sopenharmony_civoid flite_hw_mask_dma_buffer(struct fimc_lite *dev, u32 index);
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_cistatic inline void flite_hw_set_dma_buf_mask(struct fimc_lite *dev, u32 mask)
15162306a36Sopenharmony_ci{
15262306a36Sopenharmony_ci	writel(mask, dev->regs + FLITE_REG_CIFCNTSEQ);
15362306a36Sopenharmony_ci}
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci#endif /* FIMC_LITE_REG_H */
156