xref: /openbmc/linux/include/video/imx-ipu-v3.h (revision 762f99f4f3cb41a775b5157dd761217beba65873)
139b9004dSPhilipp Zabel /*
239b9004dSPhilipp Zabel  * Copyright 2005-2009 Freescale Semiconductor, Inc.
339b9004dSPhilipp Zabel  *
439b9004dSPhilipp Zabel  * The code contained herein is licensed under the GNU Lesser General
539b9004dSPhilipp Zabel  * Public License.  You may obtain a copy of the GNU Lesser General
639b9004dSPhilipp Zabel  * Public License Version 2.1 or later at the following locations:
739b9004dSPhilipp Zabel  *
839b9004dSPhilipp Zabel  * http://www.opensource.org/licenses/lgpl-license.html
939b9004dSPhilipp Zabel  * http://www.gnu.org/copyleft/lgpl.html
1039b9004dSPhilipp Zabel  */
1139b9004dSPhilipp Zabel 
1239b9004dSPhilipp Zabel #ifndef __DRM_IPU_H__
1339b9004dSPhilipp Zabel #define __DRM_IPU_H__
1439b9004dSPhilipp Zabel 
1539b9004dSPhilipp Zabel #include <linux/types.h>
1639b9004dSPhilipp Zabel #include <linux/videodev2.h>
1739b9004dSPhilipp Zabel #include <linux/bitmap.h>
1839b9004dSPhilipp Zabel #include <linux/fb.h>
19310944d1SPhilipp Zabel #include <linux/of.h>
20*4618cb79SPhilipp Zabel #include <drm/drm_color_mgmt.h>
212ffd48f2SSteve Longerbeam #include <media/v4l2-mediabus.h>
226541d710SJiada Wang #include <video/videomode.h>
2339b9004dSPhilipp Zabel 
2439b9004dSPhilipp Zabel struct ipu_soc;
2539b9004dSPhilipp Zabel 
2639b9004dSPhilipp Zabel enum ipuv3_type {
2739b9004dSPhilipp Zabel 	IPUV3EX,
2839b9004dSPhilipp Zabel 	IPUV3M,
2939b9004dSPhilipp Zabel 	IPUV3H,
3039b9004dSPhilipp Zabel };
3139b9004dSPhilipp Zabel 
3239b9004dSPhilipp Zabel #define IPU_PIX_FMT_GBR24	v4l2_fourcc('G', 'B', 'R', '3')
3339b9004dSPhilipp Zabel 
3439b9004dSPhilipp Zabel /*
3539b9004dSPhilipp Zabel  * Bitfield of Display Interface signal polarities.
3639b9004dSPhilipp Zabel  */
3739b9004dSPhilipp Zabel struct ipu_di_signal_cfg {
3839b9004dSPhilipp Zabel 	unsigned data_pol:1;	/* true = inverted */
3939b9004dSPhilipp Zabel 	unsigned clk_pol:1;	/* true = rising edge */
4039b9004dSPhilipp Zabel 	unsigned enable_pol:1;
4139b9004dSPhilipp Zabel 
42b6835a71SSteve Longerbeam 	struct videomode mode;
43b6835a71SSteve Longerbeam 
442872c807SPhilipp Zabel 	u32 bus_format;
4539b9004dSPhilipp Zabel 	u32 v_to_h_sync;
46b6835a71SSteve Longerbeam 
4739b9004dSPhilipp Zabel #define IPU_DI_CLKMODE_SYNC	(1 << 0)
4839b9004dSPhilipp Zabel #define IPU_DI_CLKMODE_EXT	(1 << 1)
4939b9004dSPhilipp Zabel 	unsigned long clkflags;
5039b9004dSPhilipp Zabel 
5139b9004dSPhilipp Zabel 	u8 hsync_pin;
5239b9004dSPhilipp Zabel 	u8 vsync_pin;
5339b9004dSPhilipp Zabel };
5439b9004dSPhilipp Zabel 
552ffd48f2SSteve Longerbeam /*
562ffd48f2SSteve Longerbeam  * Enumeration of CSI destinations
572ffd48f2SSteve Longerbeam  */
582ffd48f2SSteve Longerbeam enum ipu_csi_dest {
592ffd48f2SSteve Longerbeam 	IPU_CSI_DEST_IDMAC, /* to memory via SMFC */
602ffd48f2SSteve Longerbeam 	IPU_CSI_DEST_IC,	/* to Image Converter */
612ffd48f2SSteve Longerbeam 	IPU_CSI_DEST_VDIC,  /* to VDIC */
622ffd48f2SSteve Longerbeam };
632ffd48f2SSteve Longerbeam 
641aa8ea0dSSteve Longerbeam /*
651aa8ea0dSSteve Longerbeam  * Enumeration of IPU rotation modes
661aa8ea0dSSteve Longerbeam  */
678b9c3d50SSteve Longerbeam #define IPU_ROT_BIT_VFLIP (1 << 0)
688b9c3d50SSteve Longerbeam #define IPU_ROT_BIT_HFLIP (1 << 1)
698b9c3d50SSteve Longerbeam #define IPU_ROT_BIT_90    (1 << 2)
708b9c3d50SSteve Longerbeam 
711aa8ea0dSSteve Longerbeam enum ipu_rotate_mode {
721aa8ea0dSSteve Longerbeam 	IPU_ROTATE_NONE = 0,
738b9c3d50SSteve Longerbeam 	IPU_ROTATE_VERT_FLIP = IPU_ROT_BIT_VFLIP,
748b9c3d50SSteve Longerbeam 	IPU_ROTATE_HORIZ_FLIP = IPU_ROT_BIT_HFLIP,
758b9c3d50SSteve Longerbeam 	IPU_ROTATE_180 = (IPU_ROT_BIT_VFLIP | IPU_ROT_BIT_HFLIP),
768b9c3d50SSteve Longerbeam 	IPU_ROTATE_90_RIGHT = IPU_ROT_BIT_90,
778b9c3d50SSteve Longerbeam 	IPU_ROTATE_90_RIGHT_VFLIP = (IPU_ROT_BIT_90 | IPU_ROT_BIT_VFLIP),
788b9c3d50SSteve Longerbeam 	IPU_ROTATE_90_RIGHT_HFLIP = (IPU_ROT_BIT_90 | IPU_ROT_BIT_HFLIP),
798b9c3d50SSteve Longerbeam 	IPU_ROTATE_90_LEFT = (IPU_ROT_BIT_90 |
808b9c3d50SSteve Longerbeam 			      IPU_ROT_BIT_VFLIP | IPU_ROT_BIT_HFLIP),
811aa8ea0dSSteve Longerbeam };
821aa8ea0dSSteve Longerbeam 
838b9c3d50SSteve Longerbeam /* 90-degree rotations require the IRT unit */
848b9c3d50SSteve Longerbeam #define ipu_rot_mode_is_irt(m) (((m) & IPU_ROT_BIT_90) != 0)
858b9c3d50SSteve Longerbeam 
8639b9004dSPhilipp Zabel enum ipu_color_space {
8739b9004dSPhilipp Zabel 	IPUV3_COLORSPACE_RGB,
8839b9004dSPhilipp Zabel 	IPUV3_COLORSPACE_YUV,
8939b9004dSPhilipp Zabel 	IPUV3_COLORSPACE_UNKNOWN,
9039b9004dSPhilipp Zabel };
9139b9004dSPhilipp Zabel 
922d2ead45SSteve Longerbeam /*
932d2ead45SSteve Longerbeam  * Enumeration of VDI MOTION select
942d2ead45SSteve Longerbeam  */
952d2ead45SSteve Longerbeam enum ipu_motion_sel {
962d2ead45SSteve Longerbeam 	MOTION_NONE = 0,
972d2ead45SSteve Longerbeam 	LOW_MOTION,
982d2ead45SSteve Longerbeam 	MED_MOTION,
992d2ead45SSteve Longerbeam 	HIGH_MOTION,
1002d2ead45SSteve Longerbeam };
1012d2ead45SSteve Longerbeam 
10239b9004dSPhilipp Zabel struct ipuv3_channel;
10339b9004dSPhilipp Zabel 
10439b9004dSPhilipp Zabel enum ipu_channel_irq {
10539b9004dSPhilipp Zabel 	IPU_IRQ_EOF = 0,
10639b9004dSPhilipp Zabel 	IPU_IRQ_NFACK = 64,
10739b9004dSPhilipp Zabel 	IPU_IRQ_NFB4EOF = 128,
10839b9004dSPhilipp Zabel 	IPU_IRQ_EOS = 192,
10939b9004dSPhilipp Zabel };
11039b9004dSPhilipp Zabel 
111a4cd8f22SSteve Longerbeam /*
112a4cd8f22SSteve Longerbeam  * Enumeration of IDMAC channels
113a4cd8f22SSteve Longerbeam  */
114a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_CSI0			 0
115a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_CSI1			 1
116a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_CSI2			 2
117a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_CSI3			 3
118a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_VDI_MEM_IC_VF		 5
119ac4708faSSteve Longerbeam /*
120ac4708faSSteve Longerbeam  * NOTE: channels 6,7 are unused in the IPU and are not IDMAC channels,
121ac4708faSSteve Longerbeam  * but the direct CSI->VDI linking is handled the same way as IDMAC
122ac4708faSSteve Longerbeam  * channel linking in the FSU via the IPU_FS_PROC_FLOW registers, so
123ac4708faSSteve Longerbeam  * these channel names are used to support the direct CSI->VDI link.
124ac4708faSSteve Longerbeam  */
125ac4708faSSteve Longerbeam #define IPUV3_CHANNEL_CSI_DIRECT		 6
126ac4708faSSteve Longerbeam #define IPUV3_CHANNEL_CSI_VDI_PREV		 7
12797afc25cSSteve Longerbeam #define IPUV3_CHANNEL_MEM_VDI_PREV		 8
12897afc25cSSteve Longerbeam #define IPUV3_CHANNEL_MEM_VDI_CUR		 9
12997afc25cSSteve Longerbeam #define IPUV3_CHANNEL_MEM_VDI_NEXT		10
130a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_IC_PP			11
131a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_IC_PRP_VF		12
132bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_VDI_MEM_RECENT		13
133a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_G_MEM_IC_PRP_VF		14
134a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_G_MEM_IC_PP		15
135bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_G_MEM_IC_PRP_VF_ALPHA	17
136bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_G_MEM_IC_PP_ALPHA		18
137bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_MEM_VDI_PLANE1_COMB_ALPHA	19
138a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_IC_PRP_ENC_MEM		20
139a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_IC_PRP_VF_MEM		21
140a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_IC_PP_MEM			22
141a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_BG_SYNC		23
142a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_BG_ASYNC		24
143bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_MEM_VDI_PLANE1_COMB	25
144bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_MEM_VDI_PLANE3_COMB	26
145a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_FG_SYNC		27
146a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_DC_SYNC		28
147a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_FG_ASYNC		29
148a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_FG_SYNC_ALPHA		31
149bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_MEM_FG_ASYNC_ALPHA	33
150bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_DC_MEM_READ		40
151a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_DC_ASYNC		41
152bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_MEM_DC_COMMAND		42
153bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_MEM_DC_COMMAND2		43
154bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_MEM_DC_OUTPUT_MASK	44
155a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_ROT_ENC		45
156a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_ROT_VF		46
157a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_ROT_PP		47
158a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_ROT_ENC_MEM		48
159a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_ROT_VF_MEM		49
160a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_ROT_PP_MEM		50
161a4cd8f22SSteve Longerbeam #define IPUV3_CHANNEL_MEM_BG_SYNC_ALPHA		51
162bc0a3387SPhilipp Zabel #define IPUV3_CHANNEL_MEM_BG_ASYNC_ALPHA	52
163ac4708faSSteve Longerbeam #define IPUV3_NUM_CHANNELS			64
164a4cd8f22SSteve Longerbeam 
ipu_channel_alpha_channel(int ch_num)165e72db3b1SPhilipp Zabel static inline int ipu_channel_alpha_channel(int ch_num)
166e72db3b1SPhilipp Zabel {
167e72db3b1SPhilipp Zabel 	switch (ch_num) {
168e72db3b1SPhilipp Zabel 	case IPUV3_CHANNEL_G_MEM_IC_PRP_VF:
169e72db3b1SPhilipp Zabel 		return IPUV3_CHANNEL_G_MEM_IC_PRP_VF_ALPHA;
170e72db3b1SPhilipp Zabel 	case IPUV3_CHANNEL_G_MEM_IC_PP:
171e72db3b1SPhilipp Zabel 		return IPUV3_CHANNEL_G_MEM_IC_PP_ALPHA;
172e72db3b1SPhilipp Zabel 	case IPUV3_CHANNEL_MEM_FG_SYNC:
173e72db3b1SPhilipp Zabel 		return IPUV3_CHANNEL_MEM_FG_SYNC_ALPHA;
174e72db3b1SPhilipp Zabel 	case IPUV3_CHANNEL_MEM_FG_ASYNC:
175e72db3b1SPhilipp Zabel 		return IPUV3_CHANNEL_MEM_FG_ASYNC_ALPHA;
176e72db3b1SPhilipp Zabel 	case IPUV3_CHANNEL_MEM_BG_SYNC:
177e72db3b1SPhilipp Zabel 		return IPUV3_CHANNEL_MEM_BG_SYNC_ALPHA;
178e72db3b1SPhilipp Zabel 	case IPUV3_CHANNEL_MEM_BG_ASYNC:
179e72db3b1SPhilipp Zabel 		return IPUV3_CHANNEL_MEM_BG_ASYNC_ALPHA;
180e72db3b1SPhilipp Zabel 	case IPUV3_CHANNEL_MEM_VDI_PLANE1_COMB:
181e72db3b1SPhilipp Zabel 		return IPUV3_CHANNEL_MEM_VDI_PLANE1_COMB_ALPHA;
182e72db3b1SPhilipp Zabel 	default:
183e72db3b1SPhilipp Zabel 		return -EINVAL;
184e72db3b1SPhilipp Zabel 	}
185e72db3b1SPhilipp Zabel }
186e72db3b1SPhilipp Zabel 
187682b7c1cSLinus Torvalds int ipu_map_irq(struct ipu_soc *ipu, int irq);
18839b9004dSPhilipp Zabel int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct ipuv3_channel *channel,
18939b9004dSPhilipp Zabel 		enum ipu_channel_irq irq);
19039b9004dSPhilipp Zabel 
19139b9004dSPhilipp Zabel #define IPU_IRQ_DP_SF_START		(448 + 2)
19239b9004dSPhilipp Zabel #define IPU_IRQ_DP_SF_END		(448 + 3)
19339b9004dSPhilipp Zabel #define IPU_IRQ_BG_SF_END		IPU_IRQ_DP_SF_END,
19439b9004dSPhilipp Zabel #define IPU_IRQ_DC_FC_0			(448 + 8)
19539b9004dSPhilipp Zabel #define IPU_IRQ_DC_FC_1			(448 + 9)
19639b9004dSPhilipp Zabel #define IPU_IRQ_DC_FC_2			(448 + 10)
19739b9004dSPhilipp Zabel #define IPU_IRQ_DC_FC_3			(448 + 11)
19839b9004dSPhilipp Zabel #define IPU_IRQ_DC_FC_4			(448 + 12)
19939b9004dSPhilipp Zabel #define IPU_IRQ_DC_FC_6			(448 + 13)
20039b9004dSPhilipp Zabel #define IPU_IRQ_VSYNC_PRE_0		(448 + 14)
20139b9004dSPhilipp Zabel #define IPU_IRQ_VSYNC_PRE_1		(448 + 15)
20239b9004dSPhilipp Zabel 
20339b9004dSPhilipp Zabel /*
204ba07975fSSteve Longerbeam  * IPU Common functions
205ba07975fSSteve Longerbeam  */
206572a7615SSteve Longerbeam int ipu_get_num(struct ipu_soc *ipu);
207ba07975fSSteve Longerbeam void ipu_set_csi_src_mux(struct ipu_soc *ipu, int csi_id, bool mipi_csi2);
208ba07975fSSteve Longerbeam void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, bool vdi);
2093feb049fSSteve Longerbeam void ipu_dump(struct ipu_soc *ipu);
210ba07975fSSteve Longerbeam 
211ba07975fSSteve Longerbeam /*
21239b9004dSPhilipp Zabel  * IPU Image DMA Controller (idmac) functions
21339b9004dSPhilipp Zabel  */
21439b9004dSPhilipp Zabel struct ipuv3_channel *ipu_idmac_get(struct ipu_soc *ipu, unsigned channel);
21539b9004dSPhilipp Zabel void ipu_idmac_put(struct ipuv3_channel *);
21639b9004dSPhilipp Zabel 
21739b9004dSPhilipp Zabel int ipu_idmac_enable_channel(struct ipuv3_channel *channel);
21839b9004dSPhilipp Zabel int ipu_idmac_disable_channel(struct ipuv3_channel *channel);
2192bcf577eSSteve Longerbeam void ipu_idmac_enable_watermark(struct ipuv3_channel *channel, bool enable);
2204fd1a07aSSteve Longerbeam int ipu_idmac_lock_enable(struct ipuv3_channel *channel, int num_bursts);
22139b9004dSPhilipp Zabel int ipu_idmac_wait_busy(struct ipuv3_channel *channel, int ms);
22239b9004dSPhilipp Zabel 
22339b9004dSPhilipp Zabel void ipu_idmac_set_double_buffer(struct ipuv3_channel *channel,
22439b9004dSPhilipp Zabel 		bool doublebuffer);
225e9046097SPhilipp Zabel int ipu_idmac_get_current_buffer(struct ipuv3_channel *channel);
226aa52f578SSteve Longerbeam bool ipu_idmac_buffer_is_ready(struct ipuv3_channel *channel, u32 buf_num);
22739b9004dSPhilipp Zabel void ipu_idmac_select_buffer(struct ipuv3_channel *channel, u32 buf_num);
228bce6f087SSteve Longerbeam void ipu_idmac_clear_buffer(struct ipuv3_channel *channel, u32 buf_num);
229ac4708faSSteve Longerbeam int ipu_fsu_link(struct ipu_soc *ipu, int src_ch, int sink_ch);
230ac4708faSSteve Longerbeam int ipu_fsu_unlink(struct ipu_soc *ipu, int src_ch, int sink_ch);
231ac4708faSSteve Longerbeam int ipu_idmac_link(struct ipuv3_channel *src, struct ipuv3_channel *sink);
232ac4708faSSteve Longerbeam int ipu_idmac_unlink(struct ipuv3_channel *src, struct ipuv3_channel *sink);
23339b9004dSPhilipp Zabel 
23439b9004dSPhilipp Zabel /*
2357d2691daSSteve Longerbeam  * IPU Channel Parameter Memory (cpmem) functions
2367d2691daSSteve Longerbeam  */
2377d2691daSSteve Longerbeam struct ipu_rgb {
2387d2691daSSteve Longerbeam 	struct fb_bitfield      red;
2397d2691daSSteve Longerbeam 	struct fb_bitfield      green;
2407d2691daSSteve Longerbeam 	struct fb_bitfield      blue;
2417d2691daSSteve Longerbeam 	struct fb_bitfield      transp;
2427d2691daSSteve Longerbeam 	int                     bits_per_pixel;
2437d2691daSSteve Longerbeam };
2447d2691daSSteve Longerbeam 
2457d2691daSSteve Longerbeam struct ipu_image {
2467d2691daSSteve Longerbeam 	struct v4l2_pix_format pix;
2477d2691daSSteve Longerbeam 	struct v4l2_rect rect;
2482094b603SSteve Longerbeam 	dma_addr_t phys0;
2492094b603SSteve Longerbeam 	dma_addr_t phys1;
250dec408fdSSteve Longerbeam 	/* chroma plane offset overrides */
251dec408fdSSteve Longerbeam 	u32 u_offset;
252dec408fdSSteve Longerbeam 	u32 v_offset;
2537d2691daSSteve Longerbeam };
2547d2691daSSteve Longerbeam 
2557d2691daSSteve Longerbeam void ipu_cpmem_zero(struct ipuv3_channel *ch);
2567d2691daSSteve Longerbeam void ipu_cpmem_set_resolution(struct ipuv3_channel *ch, int xres, int yres);
257e1e9733cSPhilipp Zabel void ipu_cpmem_skip_odd_chroma_rows(struct ipuv3_channel *ch);
2587d2691daSSteve Longerbeam void ipu_cpmem_set_stride(struct ipuv3_channel *ch, int stride);
2597d2691daSSteve Longerbeam void ipu_cpmem_set_high_priority(struct ipuv3_channel *ch);
2607d2691daSSteve Longerbeam void ipu_cpmem_set_buffer(struct ipuv3_channel *ch, int bufnum, dma_addr_t buf);
261e5e8690fSSteve Longerbeam void ipu_cpmem_set_uv_offset(struct ipuv3_channel *ch, u32 u_off, u32 v_off);
2629b5c8d5fSSteve Longerbeam void ipu_cpmem_interlaced_scan(struct ipuv3_channel *ch, int stride,
2639b5c8d5fSSteve Longerbeam 			       u32 pixelformat);
264555f0e66SSteve Longerbeam void ipu_cpmem_set_axi_id(struct ipuv3_channel *ch, u32 id);
26503085911SSteve Longerbeam int ipu_cpmem_get_burstsize(struct ipuv3_channel *ch);
2667d2691daSSteve Longerbeam void ipu_cpmem_set_burstsize(struct ipuv3_channel *ch, int burstsize);
2679b9da0beSSteve Longerbeam void ipu_cpmem_set_block_mode(struct ipuv3_channel *ch);
268c42d37caSSteve Longerbeam void ipu_cpmem_set_rotation(struct ipuv3_channel *ch,
269c42d37caSSteve Longerbeam 			    enum ipu_rotate_mode rot);
2707d2691daSSteve Longerbeam int ipu_cpmem_set_format_rgb(struct ipuv3_channel *ch,
2717d2691daSSteve Longerbeam 			     const struct ipu_rgb *rgb);
2727d2691daSSteve Longerbeam int ipu_cpmem_set_format_passthrough(struct ipuv3_channel *ch, int width);
2737d2691daSSteve Longerbeam void ipu_cpmem_set_yuv_interleaved(struct ipuv3_channel *ch, u32 pixel_format);
2747d2691daSSteve Longerbeam void ipu_cpmem_set_yuv_planar_full(struct ipuv3_channel *ch,
27590195c36SPhilipp Zabel 				   unsigned int uv_stride,
27690195c36SPhilipp Zabel 				   unsigned int u_offset,
27790195c36SPhilipp Zabel 				   unsigned int v_offset);
2787d2691daSSteve Longerbeam int ipu_cpmem_set_fmt(struct ipuv3_channel *ch, u32 drm_fourcc);
2797d2691daSSteve Longerbeam int ipu_cpmem_set_image(struct ipuv3_channel *ch, struct ipu_image *image);
28060c04456SSteve Longerbeam void ipu_cpmem_dump(struct ipuv3_channel *ch);
2817d2691daSSteve Longerbeam 
2827d2691daSSteve Longerbeam /*
28339b9004dSPhilipp Zabel  * IPU Display Controller (dc) functions
28439b9004dSPhilipp Zabel  */
28539b9004dSPhilipp Zabel struct ipu_dc;
28639b9004dSPhilipp Zabel struct ipu_di;
28739b9004dSPhilipp Zabel struct ipu_dc *ipu_dc_get(struct ipu_soc *ipu, int channel);
28839b9004dSPhilipp Zabel void ipu_dc_put(struct ipu_dc *dc);
28939b9004dSPhilipp Zabel int ipu_dc_init_sync(struct ipu_dc *dc, struct ipu_di *di, bool interlaced,
29039b9004dSPhilipp Zabel 		u32 pixel_fmt, u32 width);
291682b7c1cSLinus Torvalds void ipu_dc_enable(struct ipu_soc *ipu);
29239b9004dSPhilipp Zabel void ipu_dc_enable_channel(struct ipu_dc *dc);
29339b9004dSPhilipp Zabel void ipu_dc_disable_channel(struct ipu_dc *dc);
294682b7c1cSLinus Torvalds void ipu_dc_disable(struct ipu_soc *ipu);
29539b9004dSPhilipp Zabel 
29639b9004dSPhilipp Zabel /*
29739b9004dSPhilipp Zabel  * IPU Display Interface (di) functions
29839b9004dSPhilipp Zabel  */
29939b9004dSPhilipp Zabel struct ipu_di *ipu_di_get(struct ipu_soc *ipu, int disp);
30039b9004dSPhilipp Zabel void ipu_di_put(struct ipu_di *);
30139b9004dSPhilipp Zabel int ipu_di_disable(struct ipu_di *);
30239b9004dSPhilipp Zabel int ipu_di_enable(struct ipu_di *);
30339b9004dSPhilipp Zabel int ipu_di_get_num(struct ipu_di *);
3046541d710SJiada Wang int ipu_di_adjust_videomode(struct ipu_di *di, struct videomode *mode);
30539b9004dSPhilipp Zabel int ipu_di_init_sync_panel(struct ipu_di *, struct ipu_di_signal_cfg *sig);
30639b9004dSPhilipp Zabel 
30739b9004dSPhilipp Zabel /*
30839b9004dSPhilipp Zabel  * IPU Display Multi FIFO Controller (dmfc) functions
30939b9004dSPhilipp Zabel  */
31039b9004dSPhilipp Zabel struct dmfc_channel;
31139b9004dSPhilipp Zabel int ipu_dmfc_enable_channel(struct dmfc_channel *dmfc);
31239b9004dSPhilipp Zabel void ipu_dmfc_disable_channel(struct dmfc_channel *dmfc);
31327630c20SLiu Ying void ipu_dmfc_config_wait4eot(struct dmfc_channel *dmfc, int width);
31439b9004dSPhilipp Zabel struct dmfc_channel *ipu_dmfc_get(struct ipu_soc *ipu, int ipuv3_channel);
31539b9004dSPhilipp Zabel void ipu_dmfc_put(struct dmfc_channel *dmfc);
31639b9004dSPhilipp Zabel 
31739b9004dSPhilipp Zabel /*
31839b9004dSPhilipp Zabel  * IPU Display Processor (dp) functions
31939b9004dSPhilipp Zabel  */
32039b9004dSPhilipp Zabel #define IPU_DP_FLOW_SYNC_BG	0
32139b9004dSPhilipp Zabel #define IPU_DP_FLOW_SYNC_FG	1
32239b9004dSPhilipp Zabel #define IPU_DP_FLOW_ASYNC0_BG	2
32339b9004dSPhilipp Zabel #define IPU_DP_FLOW_ASYNC0_FG	3
32439b9004dSPhilipp Zabel #define IPU_DP_FLOW_ASYNC1_BG	4
32539b9004dSPhilipp Zabel #define IPU_DP_FLOW_ASYNC1_FG	5
32639b9004dSPhilipp Zabel 
32739b9004dSPhilipp Zabel struct ipu_dp *ipu_dp_get(struct ipu_soc *ipu, unsigned int flow);
32839b9004dSPhilipp Zabel void ipu_dp_put(struct ipu_dp *);
329682b7c1cSLinus Torvalds int ipu_dp_enable(struct ipu_soc *ipu);
33039b9004dSPhilipp Zabel int ipu_dp_enable_channel(struct ipu_dp *dp);
331f9bb7acbSPhilipp Zabel void ipu_dp_disable_channel(struct ipu_dp *dp, bool sync);
332682b7c1cSLinus Torvalds void ipu_dp_disable(struct ipu_soc *ipu);
33339b9004dSPhilipp Zabel int ipu_dp_setup_channel(struct ipu_dp *dp,
334*4618cb79SPhilipp Zabel 		enum drm_color_encoding ycbcr_enc, enum drm_color_range range,
33539b9004dSPhilipp Zabel 		enum ipu_color_space in, enum ipu_color_space out);
33639b9004dSPhilipp Zabel int ipu_dp_set_window_pos(struct ipu_dp *, u16 x_pos, u16 y_pos);
33739b9004dSPhilipp Zabel int ipu_dp_set_global_alpha(struct ipu_dp *dp, bool enable, u8 alpha,
33839b9004dSPhilipp Zabel 		bool bg_chan);
33939b9004dSPhilipp Zabel 
34035de925fSPhilipp Zabel /*
341ea9c2605SLucas Stach  * IPU Prefetch Resolve Gasket (prg) functions
342ea9c2605SLucas Stach  */
343ea9c2605SLucas Stach int ipu_prg_max_active_channels(void);
344ea9c2605SLucas Stach bool ipu_prg_present(struct ipu_soc *ipu);
345ea9c2605SLucas Stach bool ipu_prg_format_supported(struct ipu_soc *ipu, uint32_t format,
346ea9c2605SLucas Stach 			      uint64_t modifier);
347ea9c2605SLucas Stach int ipu_prg_enable(struct ipu_soc *ipu);
348ea9c2605SLucas Stach void ipu_prg_disable(struct ipu_soc *ipu);
349ea9c2605SLucas Stach void ipu_prg_channel_disable(struct ipuv3_channel *ipu_chan);
350ea9c2605SLucas Stach int ipu_prg_channel_configure(struct ipuv3_channel *ipu_chan,
351ea9c2605SLucas Stach 			      unsigned int axi_id,  unsigned int width,
352ea9c2605SLucas Stach 			      unsigned int height, unsigned int stride,
353a2ceec52SLucas Stach 			      u32 format, uint64_t modifier, unsigned long *eba);
3544bfbd561SLucas Stach bool ipu_prg_channel_configure_pending(struct ipuv3_channel *ipu_chan);
355ea9c2605SLucas Stach 
356ea9c2605SLucas Stach /*
3573f5a8a94SPhilipp Zabel  * IPU CMOS Sensor Interface (csi) functions
3583f5a8a94SPhilipp Zabel  */
3592ffd48f2SSteve Longerbeam struct ipu_csi;
3602ffd48f2SSteve Longerbeam int ipu_csi_init_interface(struct ipu_csi *csi,
361fc8c7238SSteve Longerbeam 			   const struct v4l2_mbus_config *mbus_cfg,
362fc8c7238SSteve Longerbeam 			   const struct v4l2_mbus_framefmt *infmt,
363fc8c7238SSteve Longerbeam 			   const struct v4l2_mbus_framefmt *outfmt);
3642ffd48f2SSteve Longerbeam bool ipu_csi_is_interlaced(struct ipu_csi *csi);
3652ffd48f2SSteve Longerbeam void ipu_csi_get_window(struct ipu_csi *csi, struct v4l2_rect *w);
3662ffd48f2SSteve Longerbeam void ipu_csi_set_window(struct ipu_csi *csi, struct v4l2_rect *w);
367867341b9SPhilipp Zabel void ipu_csi_set_downsize(struct ipu_csi *csi, bool horiz, bool vert);
3682ffd48f2SSteve Longerbeam void ipu_csi_set_test_generator(struct ipu_csi *csi, bool active,
3692ffd48f2SSteve Longerbeam 				u32 r_value, u32 g_value, u32 b_value,
3702ffd48f2SSteve Longerbeam 				u32 pix_clk);
3712ffd48f2SSteve Longerbeam int ipu_csi_set_mipi_datatype(struct ipu_csi *csi, u32 vc,
3722ffd48f2SSteve Longerbeam 			      struct v4l2_mbus_framefmt *mbus_fmt);
3732ffd48f2SSteve Longerbeam int ipu_csi_set_skip_smfc(struct ipu_csi *csi, u32 skip,
3742ffd48f2SSteve Longerbeam 			  u32 max_ratio, u32 id);
3752ffd48f2SSteve Longerbeam int ipu_csi_set_dest(struct ipu_csi *csi, enum ipu_csi_dest csi_dest);
3762ffd48f2SSteve Longerbeam int ipu_csi_enable(struct ipu_csi *csi);
3772ffd48f2SSteve Longerbeam int ipu_csi_disable(struct ipu_csi *csi);
3782ffd48f2SSteve Longerbeam struct ipu_csi *ipu_csi_get(struct ipu_soc *ipu, int id);
3792ffd48f2SSteve Longerbeam void ipu_csi_put(struct ipu_csi *csi);
3802ffd48f2SSteve Longerbeam void ipu_csi_dump(struct ipu_csi *csi);
3813f5a8a94SPhilipp Zabel 
3823f5a8a94SPhilipp Zabel /*
3831aa8ea0dSSteve Longerbeam  * IPU Image Converter (ic) functions
3841aa8ea0dSSteve Longerbeam  */
3851aa8ea0dSSteve Longerbeam enum ipu_ic_task {
3861aa8ea0dSSteve Longerbeam 	IC_TASK_ENCODER,
3871aa8ea0dSSteve Longerbeam 	IC_TASK_VIEWFINDER,
3881aa8ea0dSSteve Longerbeam 	IC_TASK_POST_PROCESSOR,
3891aa8ea0dSSteve Longerbeam 	IC_NUM_TASKS,
3901aa8ea0dSSteve Longerbeam };
3911aa8ea0dSSteve Longerbeam 
392f208b26eSSteve Longerbeam /*
393f208b26eSSteve Longerbeam  * The parameters that describe a colorspace according to the
394f208b26eSSteve Longerbeam  * Image Converter:
395f208b26eSSteve Longerbeam  *    - Y'CbCr encoding
396f208b26eSSteve Longerbeam  *    - quantization
397f208b26eSSteve Longerbeam  *    - "colorspace" (RGB or YUV).
398f208b26eSSteve Longerbeam  */
399f208b26eSSteve Longerbeam struct ipu_ic_colorspace {
400f208b26eSSteve Longerbeam 	enum v4l2_ycbcr_encoding enc;
401f208b26eSSteve Longerbeam 	enum v4l2_quantization quant;
402f208b26eSSteve Longerbeam 	enum ipu_color_space cs;
403f208b26eSSteve Longerbeam };
404f208b26eSSteve Longerbeam 
405f208b26eSSteve Longerbeam static inline void
ipu_ic_fill_colorspace(struct ipu_ic_colorspace * ic_cs,enum v4l2_ycbcr_encoding enc,enum v4l2_quantization quant,enum ipu_color_space cs)406f208b26eSSteve Longerbeam ipu_ic_fill_colorspace(struct ipu_ic_colorspace *ic_cs,
407f208b26eSSteve Longerbeam 		       enum v4l2_ycbcr_encoding enc,
408f208b26eSSteve Longerbeam 		       enum v4l2_quantization quant,
409f208b26eSSteve Longerbeam 		       enum ipu_color_space cs)
410f208b26eSSteve Longerbeam {
411f208b26eSSteve Longerbeam 	ic_cs->enc = enc;
412f208b26eSSteve Longerbeam 	ic_cs->quant = quant;
413f208b26eSSteve Longerbeam 	ic_cs->cs = cs;
414f208b26eSSteve Longerbeam }
415f208b26eSSteve Longerbeam 
416f208b26eSSteve Longerbeam struct ipu_ic_csc_params {
417f208b26eSSteve Longerbeam 	s16 coeff[3][3];	/* signed 9-bit integer coefficients */
418f208b26eSSteve Longerbeam 	s16 offset[3];		/* signed 11+2-bit fixed point offset */
419f208b26eSSteve Longerbeam 	u8 scale:2;		/* scale coefficients * 2^(scale-1) */
420f208b26eSSteve Longerbeam 	bool sat:1;		/* saturate to (16, 235(Y) / 240(U, V)) */
421f208b26eSSteve Longerbeam };
422f208b26eSSteve Longerbeam 
423f208b26eSSteve Longerbeam struct ipu_ic_csc {
424f208b26eSSteve Longerbeam 	struct ipu_ic_colorspace in_cs;
425f208b26eSSteve Longerbeam 	struct ipu_ic_colorspace out_cs;
426f208b26eSSteve Longerbeam 	struct ipu_ic_csc_params params;
427f208b26eSSteve Longerbeam };
428f208b26eSSteve Longerbeam 
4291aa8ea0dSSteve Longerbeam struct ipu_ic;
430f208b26eSSteve Longerbeam 
431f208b26eSSteve Longerbeam int __ipu_ic_calc_csc(struct ipu_ic_csc *csc);
432f208b26eSSteve Longerbeam int ipu_ic_calc_csc(struct ipu_ic_csc *csc,
433f208b26eSSteve Longerbeam 		    enum v4l2_ycbcr_encoding in_enc,
434f208b26eSSteve Longerbeam 		    enum v4l2_quantization in_quant,
4351aa8ea0dSSteve Longerbeam 		    enum ipu_color_space in_cs,
436f208b26eSSteve Longerbeam 		    enum v4l2_ycbcr_encoding out_enc,
437f208b26eSSteve Longerbeam 		    enum v4l2_quantization out_quant,
4381aa8ea0dSSteve Longerbeam 		    enum ipu_color_space out_cs);
439f208b26eSSteve Longerbeam int ipu_ic_task_init(struct ipu_ic *ic,
440f208b26eSSteve Longerbeam 		     const struct ipu_ic_csc *csc,
441f208b26eSSteve Longerbeam 		     int in_width, int in_height,
442f208b26eSSteve Longerbeam 		     int out_width, int out_height);
443d0cbc93aSPhilipp Zabel int ipu_ic_task_init_rsc(struct ipu_ic *ic,
444f208b26eSSteve Longerbeam 			 const struct ipu_ic_csc *csc,
445d0cbc93aSPhilipp Zabel 			 int in_width, int in_height,
446d0cbc93aSPhilipp Zabel 			 int out_width, int out_height,
447d0cbc93aSPhilipp Zabel 			 u32 rsc);
4481aa8ea0dSSteve Longerbeam int ipu_ic_task_graphics_init(struct ipu_ic *ic,
449f208b26eSSteve Longerbeam 			      const struct ipu_ic_colorspace *g_in_cs,
4501aa8ea0dSSteve Longerbeam 			      bool galpha_en, u32 galpha,
4511aa8ea0dSSteve Longerbeam 			      bool colorkey_en, u32 colorkey);
4521aa8ea0dSSteve Longerbeam void ipu_ic_task_enable(struct ipu_ic *ic);
4531aa8ea0dSSteve Longerbeam void ipu_ic_task_disable(struct ipu_ic *ic);
4541aa8ea0dSSteve Longerbeam int ipu_ic_task_idma_init(struct ipu_ic *ic, struct ipuv3_channel *channel,
4551aa8ea0dSSteve Longerbeam 			  u32 width, u32 height, int burst_size,
4561aa8ea0dSSteve Longerbeam 			  enum ipu_rotate_mode rot);
4571aa8ea0dSSteve Longerbeam int ipu_ic_enable(struct ipu_ic *ic);
4581aa8ea0dSSteve Longerbeam int ipu_ic_disable(struct ipu_ic *ic);
4591aa8ea0dSSteve Longerbeam struct ipu_ic *ipu_ic_get(struct ipu_soc *ipu, enum ipu_ic_task task);
4601aa8ea0dSSteve Longerbeam void ipu_ic_put(struct ipu_ic *ic);
4611aa8ea0dSSteve Longerbeam void ipu_ic_dump(struct ipu_ic *ic);
4621aa8ea0dSSteve Longerbeam 
4631aa8ea0dSSteve Longerbeam /*
4642d2ead45SSteve Longerbeam  * IPU Video De-Interlacer (vdi) functions
4652d2ead45SSteve Longerbeam  */
4662d2ead45SSteve Longerbeam struct ipu_vdi;
4672d2ead45SSteve Longerbeam void ipu_vdi_set_field_order(struct ipu_vdi *vdi, v4l2_std_id std, u32 field);
4682d2ead45SSteve Longerbeam void ipu_vdi_set_motion(struct ipu_vdi *vdi, enum ipu_motion_sel motion_sel);
4692d2ead45SSteve Longerbeam void ipu_vdi_setup(struct ipu_vdi *vdi, u32 code, int xres, int yres);
4702d2ead45SSteve Longerbeam void ipu_vdi_unsetup(struct ipu_vdi *vdi);
4712d2ead45SSteve Longerbeam int ipu_vdi_enable(struct ipu_vdi *vdi);
4722d2ead45SSteve Longerbeam int ipu_vdi_disable(struct ipu_vdi *vdi);
4732d2ead45SSteve Longerbeam struct ipu_vdi *ipu_vdi_get(struct ipu_soc *ipu);
4742d2ead45SSteve Longerbeam void ipu_vdi_put(struct ipu_vdi *vdi);
4752d2ead45SSteve Longerbeam 
4762d2ead45SSteve Longerbeam /*
47735de925fSPhilipp Zabel  * IPU Sensor Multiple FIFO Controller (SMFC) functions
47835de925fSPhilipp Zabel  */
4797fafa8f0SSteve Longerbeam struct ipu_smfc *ipu_smfc_get(struct ipu_soc *ipu, unsigned int chno);
4807fafa8f0SSteve Longerbeam void ipu_smfc_put(struct ipu_smfc *smfc);
4817fafa8f0SSteve Longerbeam int ipu_smfc_enable(struct ipu_smfc *smfc);
4827fafa8f0SSteve Longerbeam int ipu_smfc_disable(struct ipu_smfc *smfc);
4837fafa8f0SSteve Longerbeam int ipu_smfc_map_channel(struct ipu_smfc *smfc, int csi_id, int mipi_id);
4847fafa8f0SSteve Longerbeam int ipu_smfc_set_burstsize(struct ipu_smfc *smfc, int burstsize);
485a2be35e3SSteve Longerbeam int ipu_smfc_set_watermark(struct ipu_smfc *smfc, u32 set_level, u32 clr_level);
48635de925fSPhilipp Zabel 
48739b9004dSPhilipp Zabel enum ipu_color_space ipu_drm_fourcc_to_colorspace(u32 drm_fourcc);
48839b9004dSPhilipp Zabel enum ipu_color_space ipu_pixelformat_to_colorspace(u32 pixelformat);
489f835f386SSteve Longerbeam int ipu_degrees_to_rot_mode(enum ipu_rotate_mode *mode, int degrees,
490f835f386SSteve Longerbeam 			    bool hflip, bool vflip);
491f835f386SSteve Longerbeam int ipu_rot_mode_to_degrees(int *degrees, enum ipu_rotate_mode mode,
492f835f386SSteve Longerbeam 			    bool hflip, bool vflip);
49339b9004dSPhilipp Zabel 
49439b9004dSPhilipp Zabel struct ipu_client_platformdata {
495d6ca8ca7SPhilipp Zabel 	int csi;
49639b9004dSPhilipp Zabel 	int di;
49739b9004dSPhilipp Zabel 	int dc;
49839b9004dSPhilipp Zabel 	int dp;
49939b9004dSPhilipp Zabel 	int dma[2];
500310944d1SPhilipp Zabel 	struct device_node *of_node;
50139b9004dSPhilipp Zabel };
50239b9004dSPhilipp Zabel 
50339b9004dSPhilipp Zabel #endif /* __DRM_IPU_H__ */
504