162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright 2005-2009 Freescale Semiconductor, Inc.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * The code contained herein is licensed under the GNU Lesser General
562306a36Sopenharmony_ci * Public License.  You may obtain a copy of the GNU Lesser General
662306a36Sopenharmony_ci * Public License Version 2.1 or later at the following locations:
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * http://www.opensource.org/licenses/lgpl-license.html
962306a36Sopenharmony_ci * http://www.gnu.org/copyleft/lgpl.html
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#ifndef __DRM_IPU_H__
1362306a36Sopenharmony_ci#define __DRM_IPU_H__
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include <linux/types.h>
1662306a36Sopenharmony_ci#include <linux/videodev2.h>
1762306a36Sopenharmony_ci#include <linux/bitmap.h>
1862306a36Sopenharmony_ci#include <linux/fb.h>
1962306a36Sopenharmony_ci#include <linux/of.h>
2062306a36Sopenharmony_ci#include <drm/drm_color_mgmt.h>
2162306a36Sopenharmony_ci#include <media/v4l2-mediabus.h>
2262306a36Sopenharmony_ci#include <video/videomode.h>
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_cistruct ipu_soc;
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_cienum ipuv3_type {
2762306a36Sopenharmony_ci	IPUV3EX,
2862306a36Sopenharmony_ci	IPUV3M,
2962306a36Sopenharmony_ci	IPUV3H,
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define IPU_PIX_FMT_GBR24	v4l2_fourcc('G', 'B', 'R', '3')
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/*
3562306a36Sopenharmony_ci * Bitfield of Display Interface signal polarities.
3662306a36Sopenharmony_ci */
3762306a36Sopenharmony_cistruct ipu_di_signal_cfg {
3862306a36Sopenharmony_ci	unsigned data_pol:1;	/* true = inverted */
3962306a36Sopenharmony_ci	unsigned clk_pol:1;	/* true = rising edge */
4062306a36Sopenharmony_ci	unsigned enable_pol:1;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	struct videomode mode;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	u32 bus_format;
4562306a36Sopenharmony_ci	u32 v_to_h_sync;
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define IPU_DI_CLKMODE_SYNC	(1 << 0)
4862306a36Sopenharmony_ci#define IPU_DI_CLKMODE_EXT	(1 << 1)
4962306a36Sopenharmony_ci	unsigned long clkflags;
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci	u8 hsync_pin;
5262306a36Sopenharmony_ci	u8 vsync_pin;
5362306a36Sopenharmony_ci};
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/*
5662306a36Sopenharmony_ci * Enumeration of CSI destinations
5762306a36Sopenharmony_ci */
5862306a36Sopenharmony_cienum ipu_csi_dest {
5962306a36Sopenharmony_ci	IPU_CSI_DEST_IDMAC, /* to memory via SMFC */
6062306a36Sopenharmony_ci	IPU_CSI_DEST_IC,	/* to Image Converter */
6162306a36Sopenharmony_ci	IPU_CSI_DEST_VDIC,  /* to VDIC */
6262306a36Sopenharmony_ci};
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci/*
6562306a36Sopenharmony_ci * Enumeration of IPU rotation modes
6662306a36Sopenharmony_ci */
6762306a36Sopenharmony_ci#define IPU_ROT_BIT_VFLIP (1 << 0)
6862306a36Sopenharmony_ci#define IPU_ROT_BIT_HFLIP (1 << 1)
6962306a36Sopenharmony_ci#define IPU_ROT_BIT_90    (1 << 2)
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_cienum ipu_rotate_mode {
7262306a36Sopenharmony_ci	IPU_ROTATE_NONE = 0,
7362306a36Sopenharmony_ci	IPU_ROTATE_VERT_FLIP = IPU_ROT_BIT_VFLIP,
7462306a36Sopenharmony_ci	IPU_ROTATE_HORIZ_FLIP = IPU_ROT_BIT_HFLIP,
7562306a36Sopenharmony_ci	IPU_ROTATE_180 = (IPU_ROT_BIT_VFLIP | IPU_ROT_BIT_HFLIP),
7662306a36Sopenharmony_ci	IPU_ROTATE_90_RIGHT = IPU_ROT_BIT_90,
7762306a36Sopenharmony_ci	IPU_ROTATE_90_RIGHT_VFLIP = (IPU_ROT_BIT_90 | IPU_ROT_BIT_VFLIP),
7862306a36Sopenharmony_ci	IPU_ROTATE_90_RIGHT_HFLIP = (IPU_ROT_BIT_90 | IPU_ROT_BIT_HFLIP),
7962306a36Sopenharmony_ci	IPU_ROTATE_90_LEFT = (IPU_ROT_BIT_90 |
8062306a36Sopenharmony_ci			      IPU_ROT_BIT_VFLIP | IPU_ROT_BIT_HFLIP),
8162306a36Sopenharmony_ci};
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci/* 90-degree rotations require the IRT unit */
8462306a36Sopenharmony_ci#define ipu_rot_mode_is_irt(m) (((m) & IPU_ROT_BIT_90) != 0)
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_cienum ipu_color_space {
8762306a36Sopenharmony_ci	IPUV3_COLORSPACE_RGB,
8862306a36Sopenharmony_ci	IPUV3_COLORSPACE_YUV,
8962306a36Sopenharmony_ci	IPUV3_COLORSPACE_UNKNOWN,
9062306a36Sopenharmony_ci};
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci/*
9362306a36Sopenharmony_ci * Enumeration of VDI MOTION select
9462306a36Sopenharmony_ci */
9562306a36Sopenharmony_cienum ipu_motion_sel {
9662306a36Sopenharmony_ci	MOTION_NONE = 0,
9762306a36Sopenharmony_ci	LOW_MOTION,
9862306a36Sopenharmony_ci	MED_MOTION,
9962306a36Sopenharmony_ci	HIGH_MOTION,
10062306a36Sopenharmony_ci};
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_cistruct ipuv3_channel;
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_cienum ipu_channel_irq {
10562306a36Sopenharmony_ci	IPU_IRQ_EOF = 0,
10662306a36Sopenharmony_ci	IPU_IRQ_NFACK = 64,
10762306a36Sopenharmony_ci	IPU_IRQ_NFB4EOF = 128,
10862306a36Sopenharmony_ci	IPU_IRQ_EOS = 192,
10962306a36Sopenharmony_ci};
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci/*
11262306a36Sopenharmony_ci * Enumeration of IDMAC channels
11362306a36Sopenharmony_ci */
11462306a36Sopenharmony_ci#define IPUV3_CHANNEL_CSI0			 0
11562306a36Sopenharmony_ci#define IPUV3_CHANNEL_CSI1			 1
11662306a36Sopenharmony_ci#define IPUV3_CHANNEL_CSI2			 2
11762306a36Sopenharmony_ci#define IPUV3_CHANNEL_CSI3			 3
11862306a36Sopenharmony_ci#define IPUV3_CHANNEL_VDI_MEM_IC_VF		 5
11962306a36Sopenharmony_ci/*
12062306a36Sopenharmony_ci * NOTE: channels 6,7 are unused in the IPU and are not IDMAC channels,
12162306a36Sopenharmony_ci * but the direct CSI->VDI linking is handled the same way as IDMAC
12262306a36Sopenharmony_ci * channel linking in the FSU via the IPU_FS_PROC_FLOW registers, so
12362306a36Sopenharmony_ci * these channel names are used to support the direct CSI->VDI link.
12462306a36Sopenharmony_ci */
12562306a36Sopenharmony_ci#define IPUV3_CHANNEL_CSI_DIRECT		 6
12662306a36Sopenharmony_ci#define IPUV3_CHANNEL_CSI_VDI_PREV		 7
12762306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_VDI_PREV		 8
12862306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_VDI_CUR		 9
12962306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_VDI_NEXT		10
13062306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_IC_PP			11
13162306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_IC_PRP_VF		12
13262306a36Sopenharmony_ci#define IPUV3_CHANNEL_VDI_MEM_RECENT		13
13362306a36Sopenharmony_ci#define IPUV3_CHANNEL_G_MEM_IC_PRP_VF		14
13462306a36Sopenharmony_ci#define IPUV3_CHANNEL_G_MEM_IC_PP		15
13562306a36Sopenharmony_ci#define IPUV3_CHANNEL_G_MEM_IC_PRP_VF_ALPHA	17
13662306a36Sopenharmony_ci#define IPUV3_CHANNEL_G_MEM_IC_PP_ALPHA		18
13762306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_VDI_PLANE1_COMB_ALPHA	19
13862306a36Sopenharmony_ci#define IPUV3_CHANNEL_IC_PRP_ENC_MEM		20
13962306a36Sopenharmony_ci#define IPUV3_CHANNEL_IC_PRP_VF_MEM		21
14062306a36Sopenharmony_ci#define IPUV3_CHANNEL_IC_PP_MEM			22
14162306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_BG_SYNC		23
14262306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_BG_ASYNC		24
14362306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_VDI_PLANE1_COMB	25
14462306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_VDI_PLANE3_COMB	26
14562306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_FG_SYNC		27
14662306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_DC_SYNC		28
14762306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_FG_ASYNC		29
14862306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_FG_SYNC_ALPHA		31
14962306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_FG_ASYNC_ALPHA	33
15062306a36Sopenharmony_ci#define IPUV3_CHANNEL_DC_MEM_READ		40
15162306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_DC_ASYNC		41
15262306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_DC_COMMAND		42
15362306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_DC_COMMAND2		43
15462306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_DC_OUTPUT_MASK	44
15562306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_ROT_ENC		45
15662306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_ROT_VF		46
15762306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_ROT_PP		47
15862306a36Sopenharmony_ci#define IPUV3_CHANNEL_ROT_ENC_MEM		48
15962306a36Sopenharmony_ci#define IPUV3_CHANNEL_ROT_VF_MEM		49
16062306a36Sopenharmony_ci#define IPUV3_CHANNEL_ROT_PP_MEM		50
16162306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_BG_SYNC_ALPHA		51
16262306a36Sopenharmony_ci#define IPUV3_CHANNEL_MEM_BG_ASYNC_ALPHA	52
16362306a36Sopenharmony_ci#define IPUV3_NUM_CHANNELS			64
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_cistatic inline int ipu_channel_alpha_channel(int ch_num)
16662306a36Sopenharmony_ci{
16762306a36Sopenharmony_ci	switch (ch_num) {
16862306a36Sopenharmony_ci	case IPUV3_CHANNEL_G_MEM_IC_PRP_VF:
16962306a36Sopenharmony_ci		return IPUV3_CHANNEL_G_MEM_IC_PRP_VF_ALPHA;
17062306a36Sopenharmony_ci	case IPUV3_CHANNEL_G_MEM_IC_PP:
17162306a36Sopenharmony_ci		return IPUV3_CHANNEL_G_MEM_IC_PP_ALPHA;
17262306a36Sopenharmony_ci	case IPUV3_CHANNEL_MEM_FG_SYNC:
17362306a36Sopenharmony_ci		return IPUV3_CHANNEL_MEM_FG_SYNC_ALPHA;
17462306a36Sopenharmony_ci	case IPUV3_CHANNEL_MEM_FG_ASYNC:
17562306a36Sopenharmony_ci		return IPUV3_CHANNEL_MEM_FG_ASYNC_ALPHA;
17662306a36Sopenharmony_ci	case IPUV3_CHANNEL_MEM_BG_SYNC:
17762306a36Sopenharmony_ci		return IPUV3_CHANNEL_MEM_BG_SYNC_ALPHA;
17862306a36Sopenharmony_ci	case IPUV3_CHANNEL_MEM_BG_ASYNC:
17962306a36Sopenharmony_ci		return IPUV3_CHANNEL_MEM_BG_ASYNC_ALPHA;
18062306a36Sopenharmony_ci	case IPUV3_CHANNEL_MEM_VDI_PLANE1_COMB:
18162306a36Sopenharmony_ci		return IPUV3_CHANNEL_MEM_VDI_PLANE1_COMB_ALPHA;
18262306a36Sopenharmony_ci	default:
18362306a36Sopenharmony_ci		return -EINVAL;
18462306a36Sopenharmony_ci	}
18562306a36Sopenharmony_ci}
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ciint ipu_map_irq(struct ipu_soc *ipu, int irq);
18862306a36Sopenharmony_ciint ipu_idmac_channel_irq(struct ipu_soc *ipu, struct ipuv3_channel *channel,
18962306a36Sopenharmony_ci		enum ipu_channel_irq irq);
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci#define IPU_IRQ_DP_SF_START		(448 + 2)
19262306a36Sopenharmony_ci#define IPU_IRQ_DP_SF_END		(448 + 3)
19362306a36Sopenharmony_ci#define IPU_IRQ_BG_SF_END		IPU_IRQ_DP_SF_END,
19462306a36Sopenharmony_ci#define IPU_IRQ_DC_FC_0			(448 + 8)
19562306a36Sopenharmony_ci#define IPU_IRQ_DC_FC_1			(448 + 9)
19662306a36Sopenharmony_ci#define IPU_IRQ_DC_FC_2			(448 + 10)
19762306a36Sopenharmony_ci#define IPU_IRQ_DC_FC_3			(448 + 11)
19862306a36Sopenharmony_ci#define IPU_IRQ_DC_FC_4			(448 + 12)
19962306a36Sopenharmony_ci#define IPU_IRQ_DC_FC_6			(448 + 13)
20062306a36Sopenharmony_ci#define IPU_IRQ_VSYNC_PRE_0		(448 + 14)
20162306a36Sopenharmony_ci#define IPU_IRQ_VSYNC_PRE_1		(448 + 15)
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci/*
20462306a36Sopenharmony_ci * IPU Common functions
20562306a36Sopenharmony_ci */
20662306a36Sopenharmony_ciint ipu_get_num(struct ipu_soc *ipu);
20762306a36Sopenharmony_civoid ipu_set_csi_src_mux(struct ipu_soc *ipu, int csi_id, bool mipi_csi2);
20862306a36Sopenharmony_civoid ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, bool vdi);
20962306a36Sopenharmony_civoid ipu_dump(struct ipu_soc *ipu);
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci/*
21262306a36Sopenharmony_ci * IPU Image DMA Controller (idmac) functions
21362306a36Sopenharmony_ci */
21462306a36Sopenharmony_cistruct ipuv3_channel *ipu_idmac_get(struct ipu_soc *ipu, unsigned channel);
21562306a36Sopenharmony_civoid ipu_idmac_put(struct ipuv3_channel *);
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ciint ipu_idmac_enable_channel(struct ipuv3_channel *channel);
21862306a36Sopenharmony_ciint ipu_idmac_disable_channel(struct ipuv3_channel *channel);
21962306a36Sopenharmony_civoid ipu_idmac_enable_watermark(struct ipuv3_channel *channel, bool enable);
22062306a36Sopenharmony_ciint ipu_idmac_lock_enable(struct ipuv3_channel *channel, int num_bursts);
22162306a36Sopenharmony_ciint ipu_idmac_wait_busy(struct ipuv3_channel *channel, int ms);
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_civoid ipu_idmac_set_double_buffer(struct ipuv3_channel *channel,
22462306a36Sopenharmony_ci		bool doublebuffer);
22562306a36Sopenharmony_ciint ipu_idmac_get_current_buffer(struct ipuv3_channel *channel);
22662306a36Sopenharmony_cibool ipu_idmac_buffer_is_ready(struct ipuv3_channel *channel, u32 buf_num);
22762306a36Sopenharmony_civoid ipu_idmac_select_buffer(struct ipuv3_channel *channel, u32 buf_num);
22862306a36Sopenharmony_civoid ipu_idmac_clear_buffer(struct ipuv3_channel *channel, u32 buf_num);
22962306a36Sopenharmony_ciint ipu_fsu_link(struct ipu_soc *ipu, int src_ch, int sink_ch);
23062306a36Sopenharmony_ciint ipu_fsu_unlink(struct ipu_soc *ipu, int src_ch, int sink_ch);
23162306a36Sopenharmony_ciint ipu_idmac_link(struct ipuv3_channel *src, struct ipuv3_channel *sink);
23262306a36Sopenharmony_ciint ipu_idmac_unlink(struct ipuv3_channel *src, struct ipuv3_channel *sink);
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci/*
23562306a36Sopenharmony_ci * IPU Channel Parameter Memory (cpmem) functions
23662306a36Sopenharmony_ci */
23762306a36Sopenharmony_cistruct ipu_rgb {
23862306a36Sopenharmony_ci	struct fb_bitfield      red;
23962306a36Sopenharmony_ci	struct fb_bitfield      green;
24062306a36Sopenharmony_ci	struct fb_bitfield      blue;
24162306a36Sopenharmony_ci	struct fb_bitfield      transp;
24262306a36Sopenharmony_ci	int                     bits_per_pixel;
24362306a36Sopenharmony_ci};
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_cistruct ipu_image {
24662306a36Sopenharmony_ci	struct v4l2_pix_format pix;
24762306a36Sopenharmony_ci	struct v4l2_rect rect;
24862306a36Sopenharmony_ci	dma_addr_t phys0;
24962306a36Sopenharmony_ci	dma_addr_t phys1;
25062306a36Sopenharmony_ci	/* chroma plane offset overrides */
25162306a36Sopenharmony_ci	u32 u_offset;
25262306a36Sopenharmony_ci	u32 v_offset;
25362306a36Sopenharmony_ci};
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_civoid ipu_cpmem_zero(struct ipuv3_channel *ch);
25662306a36Sopenharmony_civoid ipu_cpmem_set_resolution(struct ipuv3_channel *ch, int xres, int yres);
25762306a36Sopenharmony_civoid ipu_cpmem_skip_odd_chroma_rows(struct ipuv3_channel *ch);
25862306a36Sopenharmony_civoid ipu_cpmem_set_stride(struct ipuv3_channel *ch, int stride);
25962306a36Sopenharmony_civoid ipu_cpmem_set_high_priority(struct ipuv3_channel *ch);
26062306a36Sopenharmony_civoid ipu_cpmem_set_buffer(struct ipuv3_channel *ch, int bufnum, dma_addr_t buf);
26162306a36Sopenharmony_civoid ipu_cpmem_set_uv_offset(struct ipuv3_channel *ch, u32 u_off, u32 v_off);
26262306a36Sopenharmony_civoid ipu_cpmem_interlaced_scan(struct ipuv3_channel *ch, int stride,
26362306a36Sopenharmony_ci			       u32 pixelformat);
26462306a36Sopenharmony_civoid ipu_cpmem_set_axi_id(struct ipuv3_channel *ch, u32 id);
26562306a36Sopenharmony_ciint ipu_cpmem_get_burstsize(struct ipuv3_channel *ch);
26662306a36Sopenharmony_civoid ipu_cpmem_set_burstsize(struct ipuv3_channel *ch, int burstsize);
26762306a36Sopenharmony_civoid ipu_cpmem_set_block_mode(struct ipuv3_channel *ch);
26862306a36Sopenharmony_civoid ipu_cpmem_set_rotation(struct ipuv3_channel *ch,
26962306a36Sopenharmony_ci			    enum ipu_rotate_mode rot);
27062306a36Sopenharmony_ciint ipu_cpmem_set_format_rgb(struct ipuv3_channel *ch,
27162306a36Sopenharmony_ci			     const struct ipu_rgb *rgb);
27262306a36Sopenharmony_ciint ipu_cpmem_set_format_passthrough(struct ipuv3_channel *ch, int width);
27362306a36Sopenharmony_civoid ipu_cpmem_set_yuv_interleaved(struct ipuv3_channel *ch, u32 pixel_format);
27462306a36Sopenharmony_civoid ipu_cpmem_set_yuv_planar_full(struct ipuv3_channel *ch,
27562306a36Sopenharmony_ci				   unsigned int uv_stride,
27662306a36Sopenharmony_ci				   unsigned int u_offset,
27762306a36Sopenharmony_ci				   unsigned int v_offset);
27862306a36Sopenharmony_ciint ipu_cpmem_set_fmt(struct ipuv3_channel *ch, u32 drm_fourcc);
27962306a36Sopenharmony_ciint ipu_cpmem_set_image(struct ipuv3_channel *ch, struct ipu_image *image);
28062306a36Sopenharmony_civoid ipu_cpmem_dump(struct ipuv3_channel *ch);
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci/*
28362306a36Sopenharmony_ci * IPU Display Controller (dc) functions
28462306a36Sopenharmony_ci */
28562306a36Sopenharmony_cistruct ipu_dc;
28662306a36Sopenharmony_cistruct ipu_di;
28762306a36Sopenharmony_cistruct ipu_dc *ipu_dc_get(struct ipu_soc *ipu, int channel);
28862306a36Sopenharmony_civoid ipu_dc_put(struct ipu_dc *dc);
28962306a36Sopenharmony_ciint ipu_dc_init_sync(struct ipu_dc *dc, struct ipu_di *di, bool interlaced,
29062306a36Sopenharmony_ci		u32 pixel_fmt, u32 width);
29162306a36Sopenharmony_civoid ipu_dc_enable(struct ipu_soc *ipu);
29262306a36Sopenharmony_civoid ipu_dc_enable_channel(struct ipu_dc *dc);
29362306a36Sopenharmony_civoid ipu_dc_disable_channel(struct ipu_dc *dc);
29462306a36Sopenharmony_civoid ipu_dc_disable(struct ipu_soc *ipu);
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_ci/*
29762306a36Sopenharmony_ci * IPU Display Interface (di) functions
29862306a36Sopenharmony_ci */
29962306a36Sopenharmony_cistruct ipu_di *ipu_di_get(struct ipu_soc *ipu, int disp);
30062306a36Sopenharmony_civoid ipu_di_put(struct ipu_di *);
30162306a36Sopenharmony_ciint ipu_di_disable(struct ipu_di *);
30262306a36Sopenharmony_ciint ipu_di_enable(struct ipu_di *);
30362306a36Sopenharmony_ciint ipu_di_get_num(struct ipu_di *);
30462306a36Sopenharmony_ciint ipu_di_adjust_videomode(struct ipu_di *di, struct videomode *mode);
30562306a36Sopenharmony_ciint ipu_di_init_sync_panel(struct ipu_di *, struct ipu_di_signal_cfg *sig);
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci/*
30862306a36Sopenharmony_ci * IPU Display Multi FIFO Controller (dmfc) functions
30962306a36Sopenharmony_ci */
31062306a36Sopenharmony_cistruct dmfc_channel;
31162306a36Sopenharmony_ciint ipu_dmfc_enable_channel(struct dmfc_channel *dmfc);
31262306a36Sopenharmony_civoid ipu_dmfc_disable_channel(struct dmfc_channel *dmfc);
31362306a36Sopenharmony_civoid ipu_dmfc_config_wait4eot(struct dmfc_channel *dmfc, int width);
31462306a36Sopenharmony_cistruct dmfc_channel *ipu_dmfc_get(struct ipu_soc *ipu, int ipuv3_channel);
31562306a36Sopenharmony_civoid ipu_dmfc_put(struct dmfc_channel *dmfc);
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci/*
31862306a36Sopenharmony_ci * IPU Display Processor (dp) functions
31962306a36Sopenharmony_ci */
32062306a36Sopenharmony_ci#define IPU_DP_FLOW_SYNC_BG	0
32162306a36Sopenharmony_ci#define IPU_DP_FLOW_SYNC_FG	1
32262306a36Sopenharmony_ci#define IPU_DP_FLOW_ASYNC0_BG	2
32362306a36Sopenharmony_ci#define IPU_DP_FLOW_ASYNC0_FG	3
32462306a36Sopenharmony_ci#define IPU_DP_FLOW_ASYNC1_BG	4
32562306a36Sopenharmony_ci#define IPU_DP_FLOW_ASYNC1_FG	5
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_cistruct ipu_dp *ipu_dp_get(struct ipu_soc *ipu, unsigned int flow);
32862306a36Sopenharmony_civoid ipu_dp_put(struct ipu_dp *);
32962306a36Sopenharmony_ciint ipu_dp_enable(struct ipu_soc *ipu);
33062306a36Sopenharmony_ciint ipu_dp_enable_channel(struct ipu_dp *dp);
33162306a36Sopenharmony_civoid ipu_dp_disable_channel(struct ipu_dp *dp, bool sync);
33262306a36Sopenharmony_civoid ipu_dp_disable(struct ipu_soc *ipu);
33362306a36Sopenharmony_ciint ipu_dp_setup_channel(struct ipu_dp *dp,
33462306a36Sopenharmony_ci		enum drm_color_encoding ycbcr_enc, enum drm_color_range range,
33562306a36Sopenharmony_ci		enum ipu_color_space in, enum ipu_color_space out);
33662306a36Sopenharmony_ciint ipu_dp_set_window_pos(struct ipu_dp *, u16 x_pos, u16 y_pos);
33762306a36Sopenharmony_ciint ipu_dp_set_global_alpha(struct ipu_dp *dp, bool enable, u8 alpha,
33862306a36Sopenharmony_ci		bool bg_chan);
33962306a36Sopenharmony_ci
34062306a36Sopenharmony_ci/*
34162306a36Sopenharmony_ci * IPU Prefetch Resolve Gasket (prg) functions
34262306a36Sopenharmony_ci */
34362306a36Sopenharmony_ciint ipu_prg_max_active_channels(void);
34462306a36Sopenharmony_cibool ipu_prg_present(struct ipu_soc *ipu);
34562306a36Sopenharmony_cibool ipu_prg_format_supported(struct ipu_soc *ipu, uint32_t format,
34662306a36Sopenharmony_ci			      uint64_t modifier);
34762306a36Sopenharmony_ciint ipu_prg_enable(struct ipu_soc *ipu);
34862306a36Sopenharmony_civoid ipu_prg_disable(struct ipu_soc *ipu);
34962306a36Sopenharmony_civoid ipu_prg_channel_disable(struct ipuv3_channel *ipu_chan);
35062306a36Sopenharmony_ciint ipu_prg_channel_configure(struct ipuv3_channel *ipu_chan,
35162306a36Sopenharmony_ci			      unsigned int axi_id,  unsigned int width,
35262306a36Sopenharmony_ci			      unsigned int height, unsigned int stride,
35362306a36Sopenharmony_ci			      u32 format, uint64_t modifier, unsigned long *eba);
35462306a36Sopenharmony_cibool ipu_prg_channel_configure_pending(struct ipuv3_channel *ipu_chan);
35562306a36Sopenharmony_ci
35662306a36Sopenharmony_ci/*
35762306a36Sopenharmony_ci * IPU CMOS Sensor Interface (csi) functions
35862306a36Sopenharmony_ci */
35962306a36Sopenharmony_cistruct ipu_csi;
36062306a36Sopenharmony_ciint ipu_csi_init_interface(struct ipu_csi *csi,
36162306a36Sopenharmony_ci			   const struct v4l2_mbus_config *mbus_cfg,
36262306a36Sopenharmony_ci			   const struct v4l2_mbus_framefmt *infmt,
36362306a36Sopenharmony_ci			   const struct v4l2_mbus_framefmt *outfmt);
36462306a36Sopenharmony_cibool ipu_csi_is_interlaced(struct ipu_csi *csi);
36562306a36Sopenharmony_civoid ipu_csi_get_window(struct ipu_csi *csi, struct v4l2_rect *w);
36662306a36Sopenharmony_civoid ipu_csi_set_window(struct ipu_csi *csi, struct v4l2_rect *w);
36762306a36Sopenharmony_civoid ipu_csi_set_downsize(struct ipu_csi *csi, bool horiz, bool vert);
36862306a36Sopenharmony_civoid ipu_csi_set_test_generator(struct ipu_csi *csi, bool active,
36962306a36Sopenharmony_ci				u32 r_value, u32 g_value, u32 b_value,
37062306a36Sopenharmony_ci				u32 pix_clk);
37162306a36Sopenharmony_ciint ipu_csi_set_mipi_datatype(struct ipu_csi *csi, u32 vc,
37262306a36Sopenharmony_ci			      struct v4l2_mbus_framefmt *mbus_fmt);
37362306a36Sopenharmony_ciint ipu_csi_set_skip_smfc(struct ipu_csi *csi, u32 skip,
37462306a36Sopenharmony_ci			  u32 max_ratio, u32 id);
37562306a36Sopenharmony_ciint ipu_csi_set_dest(struct ipu_csi *csi, enum ipu_csi_dest csi_dest);
37662306a36Sopenharmony_ciint ipu_csi_enable(struct ipu_csi *csi);
37762306a36Sopenharmony_ciint ipu_csi_disable(struct ipu_csi *csi);
37862306a36Sopenharmony_cistruct ipu_csi *ipu_csi_get(struct ipu_soc *ipu, int id);
37962306a36Sopenharmony_civoid ipu_csi_put(struct ipu_csi *csi);
38062306a36Sopenharmony_civoid ipu_csi_dump(struct ipu_csi *csi);
38162306a36Sopenharmony_ci
38262306a36Sopenharmony_ci/*
38362306a36Sopenharmony_ci * IPU Image Converter (ic) functions
38462306a36Sopenharmony_ci */
38562306a36Sopenharmony_cienum ipu_ic_task {
38662306a36Sopenharmony_ci	IC_TASK_ENCODER,
38762306a36Sopenharmony_ci	IC_TASK_VIEWFINDER,
38862306a36Sopenharmony_ci	IC_TASK_POST_PROCESSOR,
38962306a36Sopenharmony_ci	IC_NUM_TASKS,
39062306a36Sopenharmony_ci};
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_ci/*
39362306a36Sopenharmony_ci * The parameters that describe a colorspace according to the
39462306a36Sopenharmony_ci * Image Converter:
39562306a36Sopenharmony_ci *    - Y'CbCr encoding
39662306a36Sopenharmony_ci *    - quantization
39762306a36Sopenharmony_ci *    - "colorspace" (RGB or YUV).
39862306a36Sopenharmony_ci */
39962306a36Sopenharmony_cistruct ipu_ic_colorspace {
40062306a36Sopenharmony_ci	enum v4l2_ycbcr_encoding enc;
40162306a36Sopenharmony_ci	enum v4l2_quantization quant;
40262306a36Sopenharmony_ci	enum ipu_color_space cs;
40362306a36Sopenharmony_ci};
40462306a36Sopenharmony_ci
40562306a36Sopenharmony_cistatic inline void
40662306a36Sopenharmony_ciipu_ic_fill_colorspace(struct ipu_ic_colorspace *ic_cs,
40762306a36Sopenharmony_ci		       enum v4l2_ycbcr_encoding enc,
40862306a36Sopenharmony_ci		       enum v4l2_quantization quant,
40962306a36Sopenharmony_ci		       enum ipu_color_space cs)
41062306a36Sopenharmony_ci{
41162306a36Sopenharmony_ci	ic_cs->enc = enc;
41262306a36Sopenharmony_ci	ic_cs->quant = quant;
41362306a36Sopenharmony_ci	ic_cs->cs = cs;
41462306a36Sopenharmony_ci}
41562306a36Sopenharmony_ci
41662306a36Sopenharmony_cistruct ipu_ic_csc_params {
41762306a36Sopenharmony_ci	s16 coeff[3][3];	/* signed 9-bit integer coefficients */
41862306a36Sopenharmony_ci	s16 offset[3];		/* signed 11+2-bit fixed point offset */
41962306a36Sopenharmony_ci	u8 scale:2;		/* scale coefficients * 2^(scale-1) */
42062306a36Sopenharmony_ci	bool sat:1;		/* saturate to (16, 235(Y) / 240(U, V)) */
42162306a36Sopenharmony_ci};
42262306a36Sopenharmony_ci
42362306a36Sopenharmony_cistruct ipu_ic_csc {
42462306a36Sopenharmony_ci	struct ipu_ic_colorspace in_cs;
42562306a36Sopenharmony_ci	struct ipu_ic_colorspace out_cs;
42662306a36Sopenharmony_ci	struct ipu_ic_csc_params params;
42762306a36Sopenharmony_ci};
42862306a36Sopenharmony_ci
42962306a36Sopenharmony_cistruct ipu_ic;
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ciint __ipu_ic_calc_csc(struct ipu_ic_csc *csc);
43262306a36Sopenharmony_ciint ipu_ic_calc_csc(struct ipu_ic_csc *csc,
43362306a36Sopenharmony_ci		    enum v4l2_ycbcr_encoding in_enc,
43462306a36Sopenharmony_ci		    enum v4l2_quantization in_quant,
43562306a36Sopenharmony_ci		    enum ipu_color_space in_cs,
43662306a36Sopenharmony_ci		    enum v4l2_ycbcr_encoding out_enc,
43762306a36Sopenharmony_ci		    enum v4l2_quantization out_quant,
43862306a36Sopenharmony_ci		    enum ipu_color_space out_cs);
43962306a36Sopenharmony_ciint ipu_ic_task_init(struct ipu_ic *ic,
44062306a36Sopenharmony_ci		     const struct ipu_ic_csc *csc,
44162306a36Sopenharmony_ci		     int in_width, int in_height,
44262306a36Sopenharmony_ci		     int out_width, int out_height);
44362306a36Sopenharmony_ciint ipu_ic_task_init_rsc(struct ipu_ic *ic,
44462306a36Sopenharmony_ci			 const struct ipu_ic_csc *csc,
44562306a36Sopenharmony_ci			 int in_width, int in_height,
44662306a36Sopenharmony_ci			 int out_width, int out_height,
44762306a36Sopenharmony_ci			 u32 rsc);
44862306a36Sopenharmony_ciint ipu_ic_task_graphics_init(struct ipu_ic *ic,
44962306a36Sopenharmony_ci			      const struct ipu_ic_colorspace *g_in_cs,
45062306a36Sopenharmony_ci			      bool galpha_en, u32 galpha,
45162306a36Sopenharmony_ci			      bool colorkey_en, u32 colorkey);
45262306a36Sopenharmony_civoid ipu_ic_task_enable(struct ipu_ic *ic);
45362306a36Sopenharmony_civoid ipu_ic_task_disable(struct ipu_ic *ic);
45462306a36Sopenharmony_ciint ipu_ic_task_idma_init(struct ipu_ic *ic, struct ipuv3_channel *channel,
45562306a36Sopenharmony_ci			  u32 width, u32 height, int burst_size,
45662306a36Sopenharmony_ci			  enum ipu_rotate_mode rot);
45762306a36Sopenharmony_ciint ipu_ic_enable(struct ipu_ic *ic);
45862306a36Sopenharmony_ciint ipu_ic_disable(struct ipu_ic *ic);
45962306a36Sopenharmony_cistruct ipu_ic *ipu_ic_get(struct ipu_soc *ipu, enum ipu_ic_task task);
46062306a36Sopenharmony_civoid ipu_ic_put(struct ipu_ic *ic);
46162306a36Sopenharmony_civoid ipu_ic_dump(struct ipu_ic *ic);
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_ci/*
46462306a36Sopenharmony_ci * IPU Video De-Interlacer (vdi) functions
46562306a36Sopenharmony_ci */
46662306a36Sopenharmony_cistruct ipu_vdi;
46762306a36Sopenharmony_civoid ipu_vdi_set_field_order(struct ipu_vdi *vdi, v4l2_std_id std, u32 field);
46862306a36Sopenharmony_civoid ipu_vdi_set_motion(struct ipu_vdi *vdi, enum ipu_motion_sel motion_sel);
46962306a36Sopenharmony_civoid ipu_vdi_setup(struct ipu_vdi *vdi, u32 code, int xres, int yres);
47062306a36Sopenharmony_civoid ipu_vdi_unsetup(struct ipu_vdi *vdi);
47162306a36Sopenharmony_ciint ipu_vdi_enable(struct ipu_vdi *vdi);
47262306a36Sopenharmony_ciint ipu_vdi_disable(struct ipu_vdi *vdi);
47362306a36Sopenharmony_cistruct ipu_vdi *ipu_vdi_get(struct ipu_soc *ipu);
47462306a36Sopenharmony_civoid ipu_vdi_put(struct ipu_vdi *vdi);
47562306a36Sopenharmony_ci
47662306a36Sopenharmony_ci/*
47762306a36Sopenharmony_ci * IPU Sensor Multiple FIFO Controller (SMFC) functions
47862306a36Sopenharmony_ci */
47962306a36Sopenharmony_cistruct ipu_smfc *ipu_smfc_get(struct ipu_soc *ipu, unsigned int chno);
48062306a36Sopenharmony_civoid ipu_smfc_put(struct ipu_smfc *smfc);
48162306a36Sopenharmony_ciint ipu_smfc_enable(struct ipu_smfc *smfc);
48262306a36Sopenharmony_ciint ipu_smfc_disable(struct ipu_smfc *smfc);
48362306a36Sopenharmony_ciint ipu_smfc_map_channel(struct ipu_smfc *smfc, int csi_id, int mipi_id);
48462306a36Sopenharmony_ciint ipu_smfc_set_burstsize(struct ipu_smfc *smfc, int burstsize);
48562306a36Sopenharmony_ciint ipu_smfc_set_watermark(struct ipu_smfc *smfc, u32 set_level, u32 clr_level);
48662306a36Sopenharmony_ci
48762306a36Sopenharmony_cienum ipu_color_space ipu_drm_fourcc_to_colorspace(u32 drm_fourcc);
48862306a36Sopenharmony_cienum ipu_color_space ipu_pixelformat_to_colorspace(u32 pixelformat);
48962306a36Sopenharmony_ciint ipu_degrees_to_rot_mode(enum ipu_rotate_mode *mode, int degrees,
49062306a36Sopenharmony_ci			    bool hflip, bool vflip);
49162306a36Sopenharmony_ciint ipu_rot_mode_to_degrees(int *degrees, enum ipu_rotate_mode mode,
49262306a36Sopenharmony_ci			    bool hflip, bool vflip);
49362306a36Sopenharmony_ci
49462306a36Sopenharmony_cistruct ipu_client_platformdata {
49562306a36Sopenharmony_ci	int csi;
49662306a36Sopenharmony_ci	int di;
49762306a36Sopenharmony_ci	int dc;
49862306a36Sopenharmony_ci	int dp;
49962306a36Sopenharmony_ci	int dma[2];
50062306a36Sopenharmony_ci	struct device_node *of_node;
50162306a36Sopenharmony_ci};
50262306a36Sopenharmony_ci
50362306a36Sopenharmony_ci#endif /* __DRM_IPU_H__ */
504