xref: /rk3399_rockchip-uboot/drivers/video/ipu.h (revision 92a98a4a399801ccebeece3e2f3ab83ee4efe9c7)
1575001e4SStefano Babic /*
2575001e4SStefano Babic  * Porting to u-boot:
3575001e4SStefano Babic  *
4575001e4SStefano Babic  * (C) Copyright 2010
5575001e4SStefano Babic  * Stefano Babic, DENX Software Engineering, sbabic@denx.de
6575001e4SStefano Babic  *
7575001e4SStefano Babic  * Linux IPU driver for MX51:
8575001e4SStefano Babic  *
9575001e4SStefano Babic  * (C) Copyright 2005-2010 Freescale Semiconductor, Inc.
10575001e4SStefano Babic  *
11575001e4SStefano Babic  * See file CREDITS for list of people who contributed to this
12575001e4SStefano Babic  * project.
13575001e4SStefano Babic  *
14575001e4SStefano Babic  * This program is free software; you can redistribute it and/or
15575001e4SStefano Babic  * modify it under the terms of the GNU General Public License as
16575001e4SStefano Babic  * published by the Free Software Foundation; either version 2 of
17575001e4SStefano Babic  * the License, or (at your option) any later version.
18575001e4SStefano Babic  *
19575001e4SStefano Babic  * This program is distributed in the hope that it will be useful,
20575001e4SStefano Babic  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21575001e4SStefano Babic  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22575001e4SStefano Babic  * GNU General Public License for more details.
23575001e4SStefano Babic  *
24575001e4SStefano Babic  * You should have received a copy of the GNU General Public License
25575001e4SStefano Babic  * along with this program; if not, write to the Free Software
26575001e4SStefano Babic  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27575001e4SStefano Babic  * MA 02111-1307 USA
28575001e4SStefano Babic  */
29575001e4SStefano Babic 
30575001e4SStefano Babic #ifndef __ASM_ARCH_IPU_H__
31575001e4SStefano Babic #define __ASM_ARCH_IPU_H__
32575001e4SStefano Babic 
33575001e4SStefano Babic #include <linux/types.h>
34*92a98a4aSStefano Babic #include <ipu_pixfmt.h>
35575001e4SStefano Babic 
36575001e4SStefano Babic #define IDMA_CHAN_INVALID	0xFF
37575001e4SStefano Babic #define HIGH_RESOLUTION_WIDTH	1024
38575001e4SStefano Babic 
39575001e4SStefano Babic struct clk {
40575001e4SStefano Babic 	const char *name;
41575001e4SStefano Babic 	int id;
42575001e4SStefano Babic 	/* Source clock this clk depends on */
43575001e4SStefano Babic 	struct clk *parent;
44575001e4SStefano Babic 	/* Secondary clock to enable/disable with this clock */
45575001e4SStefano Babic 	struct clk *secondary;
46575001e4SStefano Babic 	/* Current clock rate */
47575001e4SStefano Babic 	unsigned long rate;
48575001e4SStefano Babic 	/* Reference count of clock enable/disable */
49575001e4SStefano Babic 	__s8 usecount;
50575001e4SStefano Babic 	/* Register bit position for clock's enable/disable control. */
51575001e4SStefano Babic 	u8 enable_shift;
52575001e4SStefano Babic 	/* Register address for clock's enable/disable control. */
53575001e4SStefano Babic 	void *enable_reg;
54575001e4SStefano Babic 	u32 flags;
55575001e4SStefano Babic 	/*
56575001e4SStefano Babic 	 * Function ptr to recalculate the clock's rate based on parent
57575001e4SStefano Babic 	 * clock's rate
58575001e4SStefano Babic 	 */
59575001e4SStefano Babic 	void (*recalc) (struct clk *);
60575001e4SStefano Babic 	/*
61575001e4SStefano Babic 	 * Function ptr to set the clock to a new rate. The rate must match a
62575001e4SStefano Babic 	 * supported rate returned from round_rate. Leave blank if clock is not
63575001e4SStefano Babic 	* programmable
64575001e4SStefano Babic 	 */
65575001e4SStefano Babic 	int (*set_rate) (struct clk *, unsigned long);
66575001e4SStefano Babic 	/*
67575001e4SStefano Babic 	 * Function ptr to round the requested clock rate to the nearest
68575001e4SStefano Babic 	 * supported rate that is less than or equal to the requested rate.
69575001e4SStefano Babic 	 */
70575001e4SStefano Babic 	unsigned long (*round_rate) (struct clk *, unsigned long);
71575001e4SStefano Babic 	/*
72575001e4SStefano Babic 	 * Function ptr to enable the clock. Leave blank if clock can not
73575001e4SStefano Babic 	 * be gated.
74575001e4SStefano Babic 	 */
75575001e4SStefano Babic 	int (*enable) (struct clk *);
76575001e4SStefano Babic 	/*
77575001e4SStefano Babic 	 * Function ptr to disable the clock. Leave blank if clock can not
78575001e4SStefano Babic 	 * be gated.
79575001e4SStefano Babic 	 */
80575001e4SStefano Babic 	void (*disable) (struct clk *);
81575001e4SStefano Babic 	/* Function ptr to set the parent clock of the clock. */
82575001e4SStefano Babic 	int (*set_parent) (struct clk *, struct clk *);
83575001e4SStefano Babic };
84575001e4SStefano Babic 
85575001e4SStefano Babic /*
86575001e4SStefano Babic  * Enumeration of Synchronous (Memory-less) panel types
87575001e4SStefano Babic  */
88575001e4SStefano Babic typedef enum {
89575001e4SStefano Babic 	IPU_PANEL_SHARP_TFT,
90575001e4SStefano Babic 	IPU_PANEL_TFT,
91575001e4SStefano Babic } ipu_panel_t;
92575001e4SStefano Babic 
93575001e4SStefano Babic /*
94575001e4SStefano Babic  * IPU Driver channels definitions.
95575001e4SStefano Babic  * Note these are different from IDMA channels
96575001e4SStefano Babic  */
97575001e4SStefano Babic #define IPU_MAX_CH	32
98575001e4SStefano Babic #define _MAKE_CHAN(num, v_in, g_in, a_in, out) \
99575001e4SStefano Babic 	((num << 24) | (v_in << 18) | (g_in << 12) | (a_in << 6) | out)
100575001e4SStefano Babic #define _MAKE_ALT_CHAN(ch)		(ch | (IPU_MAX_CH << 24))
101575001e4SStefano Babic #define IPU_CHAN_ID(ch)			(ch >> 24)
102575001e4SStefano Babic #define IPU_CHAN_ALT(ch)		(ch & 0x02000000)
103575001e4SStefano Babic #define IPU_CHAN_ALPHA_IN_DMA(ch)	((uint32_t) (ch >> 6) & 0x3F)
104575001e4SStefano Babic #define IPU_CHAN_GRAPH_IN_DMA(ch)	((uint32_t) (ch >> 12) & 0x3F)
105575001e4SStefano Babic #define IPU_CHAN_VIDEO_IN_DMA(ch)	((uint32_t) (ch >> 18) & 0x3F)
106575001e4SStefano Babic #define IPU_CHAN_OUT_DMA(ch)		((uint32_t) (ch & 0x3F))
107575001e4SStefano Babic #define NO_DMA 0x3F
108575001e4SStefano Babic #define ALT	1
109575001e4SStefano Babic 
110575001e4SStefano Babic /*
111575001e4SStefano Babic  * Enumeration of IPU logical channels. An IPU logical channel is defined as a
112575001e4SStefano Babic  * combination of an input (memory to IPU), output (IPU to memory), and/or
113575001e4SStefano Babic  * secondary input IDMA channels and in some cases an Image Converter task.
114575001e4SStefano Babic  * Some channels consist of only an input or output.
115575001e4SStefano Babic  */
116575001e4SStefano Babic typedef enum {
117575001e4SStefano Babic 	CHAN_NONE = -1,
118575001e4SStefano Babic 
119575001e4SStefano Babic 	MEM_DC_SYNC = _MAKE_CHAN(7, 28, NO_DMA, NO_DMA, NO_DMA),
120575001e4SStefano Babic 	MEM_DC_ASYNC = _MAKE_CHAN(8, 41, NO_DMA, NO_DMA, NO_DMA),
121575001e4SStefano Babic 	MEM_BG_SYNC = _MAKE_CHAN(9, 23, NO_DMA, 51, NO_DMA),
122575001e4SStefano Babic 	MEM_FG_SYNC = _MAKE_CHAN(10, 27, NO_DMA, 31, NO_DMA),
123575001e4SStefano Babic 
124575001e4SStefano Babic 	MEM_BG_ASYNC0 = _MAKE_CHAN(11, 24, NO_DMA, 52, NO_DMA),
125575001e4SStefano Babic 	MEM_FG_ASYNC0 = _MAKE_CHAN(12, 29, NO_DMA, 33, NO_DMA),
126575001e4SStefano Babic 	MEM_BG_ASYNC1 = _MAKE_ALT_CHAN(MEM_BG_ASYNC0),
127575001e4SStefano Babic 	MEM_FG_ASYNC1 = _MAKE_ALT_CHAN(MEM_FG_ASYNC0),
128575001e4SStefano Babic 
129575001e4SStefano Babic 	DIRECT_ASYNC0 = _MAKE_CHAN(13, NO_DMA, NO_DMA, NO_DMA, NO_DMA),
130575001e4SStefano Babic 	DIRECT_ASYNC1 = _MAKE_CHAN(14, NO_DMA, NO_DMA, NO_DMA, NO_DMA),
131575001e4SStefano Babic 
132575001e4SStefano Babic } ipu_channel_t;
133575001e4SStefano Babic 
134575001e4SStefano Babic /*
135575001e4SStefano Babic  * Enumeration of types of buffers for a logical channel.
136575001e4SStefano Babic  */
137575001e4SStefano Babic typedef enum {
138575001e4SStefano Babic 	IPU_OUTPUT_BUFFER = 0,	/*< Buffer for output from IPU */
139575001e4SStefano Babic 	IPU_ALPHA_IN_BUFFER = 1,	/*< Buffer for input to IPU */
140575001e4SStefano Babic 	IPU_GRAPH_IN_BUFFER = 2,	/*< Buffer for input to IPU */
141575001e4SStefano Babic 	IPU_VIDEO_IN_BUFFER = 3,	/*< Buffer for input to IPU */
142575001e4SStefano Babic 	IPU_INPUT_BUFFER = IPU_VIDEO_IN_BUFFER,
143575001e4SStefano Babic 	IPU_SEC_INPUT_BUFFER = IPU_GRAPH_IN_BUFFER,
144575001e4SStefano Babic } ipu_buffer_t;
145575001e4SStefano Babic 
146575001e4SStefano Babic #define IPU_PANEL_SERIAL		1
147575001e4SStefano Babic #define IPU_PANEL_PARALLEL		2
148575001e4SStefano Babic 
149575001e4SStefano Babic struct ipu_channel {
150575001e4SStefano Babic 	u8 video_in_dma;
151575001e4SStefano Babic 	u8 alpha_in_dma;
152575001e4SStefano Babic 	u8 graph_in_dma;
153575001e4SStefano Babic 	u8 out_dma;
154575001e4SStefano Babic };
155575001e4SStefano Babic 
156575001e4SStefano Babic enum ipu_dmfc_type {
157575001e4SStefano Babic 	DMFC_NORMAL = 0,
158575001e4SStefano Babic 	DMFC_HIGH_RESOLUTION_DC,
159575001e4SStefano Babic 	DMFC_HIGH_RESOLUTION_DP,
160575001e4SStefano Babic 	DMFC_HIGH_RESOLUTION_ONLY_DP,
161575001e4SStefano Babic };
162575001e4SStefano Babic 
163575001e4SStefano Babic 
164575001e4SStefano Babic /*
165575001e4SStefano Babic  * Union of initialization parameters for a logical channel.
166575001e4SStefano Babic  */
167575001e4SStefano Babic typedef union {
168575001e4SStefano Babic 	struct {
169575001e4SStefano Babic 		uint32_t di;
170575001e4SStefano Babic 		unsigned char interlaced;
171575001e4SStefano Babic 	} mem_dc_sync;
172575001e4SStefano Babic 	struct {
173575001e4SStefano Babic 		uint32_t temp;
174575001e4SStefano Babic 	} mem_sdc_fg;
175575001e4SStefano Babic 	struct {
176575001e4SStefano Babic 		uint32_t di;
177575001e4SStefano Babic 		unsigned char interlaced;
178575001e4SStefano Babic 		uint32_t in_pixel_fmt;
179575001e4SStefano Babic 		uint32_t out_pixel_fmt;
180575001e4SStefano Babic 		unsigned char alpha_chan_en;
181575001e4SStefano Babic 	} mem_dp_bg_sync;
182575001e4SStefano Babic 	struct {
183575001e4SStefano Babic 		uint32_t temp;
184575001e4SStefano Babic 	} mem_sdc_bg;
185575001e4SStefano Babic 	struct {
186575001e4SStefano Babic 		uint32_t di;
187575001e4SStefano Babic 		unsigned char interlaced;
188575001e4SStefano Babic 		uint32_t in_pixel_fmt;
189575001e4SStefano Babic 		uint32_t out_pixel_fmt;
190575001e4SStefano Babic 		unsigned char alpha_chan_en;
191575001e4SStefano Babic 	} mem_dp_fg_sync;
192575001e4SStefano Babic } ipu_channel_params_t;
193575001e4SStefano Babic 
194575001e4SStefano Babic /*
195575001e4SStefano Babic  * Bitfield of Display Interface signal polarities.
196575001e4SStefano Babic  */
197575001e4SStefano Babic typedef struct {
198575001e4SStefano Babic 	unsigned datamask_en:1;
199575001e4SStefano Babic 	unsigned ext_clk:1;
200575001e4SStefano Babic 	unsigned interlaced:1;
201575001e4SStefano Babic 	unsigned odd_field_first:1;
202575001e4SStefano Babic 	unsigned clksel_en:1;
203575001e4SStefano Babic 	unsigned clkidle_en:1;
204575001e4SStefano Babic 	unsigned data_pol:1;	/* true = inverted */
205575001e4SStefano Babic 	unsigned clk_pol:1;	/* true = rising edge */
206575001e4SStefano Babic 	unsigned enable_pol:1;
207575001e4SStefano Babic 	unsigned Hsync_pol:1;	/* true = active high */
208575001e4SStefano Babic 	unsigned Vsync_pol:1;
209575001e4SStefano Babic } ipu_di_signal_cfg_t;
210575001e4SStefano Babic 
211575001e4SStefano Babic typedef enum {
212575001e4SStefano Babic 	RGB,
213575001e4SStefano Babic 	YCbCr,
214575001e4SStefano Babic 	YUV
215575001e4SStefano Babic } ipu_color_space_t;
216575001e4SStefano Babic 
217575001e4SStefano Babic /* Common IPU API */
218575001e4SStefano Babic int32_t ipu_init_channel(ipu_channel_t channel, ipu_channel_params_t *params);
219575001e4SStefano Babic void ipu_uninit_channel(ipu_channel_t channel);
220575001e4SStefano Babic 
221575001e4SStefano Babic int32_t ipu_init_channel_buffer(ipu_channel_t channel, ipu_buffer_t type,
222575001e4SStefano Babic 				uint32_t pixel_fmt,
223575001e4SStefano Babic 				uint16_t width, uint16_t height,
224575001e4SStefano Babic 				uint32_t stride,
225575001e4SStefano Babic 				dma_addr_t phyaddr_0, dma_addr_t phyaddr_1,
226575001e4SStefano Babic 				uint32_t u_offset, uint32_t v_offset);
227575001e4SStefano Babic 
228575001e4SStefano Babic int32_t ipu_update_channel_buffer(ipu_channel_t channel, ipu_buffer_t type,
229575001e4SStefano Babic 				  uint32_t bufNum, dma_addr_t phyaddr);
230575001e4SStefano Babic 
231575001e4SStefano Babic int32_t ipu_is_channel_busy(ipu_channel_t channel);
232575001e4SStefano Babic void ipu_clear_buffer_ready(ipu_channel_t channel, ipu_buffer_t type,
233575001e4SStefano Babic 		uint32_t bufNum);
234575001e4SStefano Babic int32_t ipu_enable_channel(ipu_channel_t channel);
235575001e4SStefano Babic int32_t ipu_disable_channel(ipu_channel_t channel);
236575001e4SStefano Babic 
237575001e4SStefano Babic int32_t ipu_init_sync_panel(int disp,
238575001e4SStefano Babic 			    uint32_t pixel_clk,
239575001e4SStefano Babic 			    uint16_t width, uint16_t height,
240575001e4SStefano Babic 			    uint32_t pixel_fmt,
241575001e4SStefano Babic 			    uint16_t h_start_width, uint16_t h_sync_width,
242575001e4SStefano Babic 			    uint16_t h_end_width, uint16_t v_start_width,
243575001e4SStefano Babic 			    uint16_t v_sync_width, uint16_t v_end_width,
244575001e4SStefano Babic 			    uint32_t v_to_h_sync, ipu_di_signal_cfg_t sig);
245575001e4SStefano Babic 
246575001e4SStefano Babic int32_t ipu_disp_set_global_alpha(ipu_channel_t channel, unsigned char enable,
247575001e4SStefano Babic 				  uint8_t alpha);
248575001e4SStefano Babic int32_t ipu_disp_set_color_key(ipu_channel_t channel, unsigned char enable,
249575001e4SStefano Babic 			       uint32_t colorKey);
250575001e4SStefano Babic 
251575001e4SStefano Babic uint32_t bytes_per_pixel(uint32_t fmt);
252575001e4SStefano Babic 
253575001e4SStefano Babic void clk_enable(struct clk *clk);
254575001e4SStefano Babic void clk_disable(struct clk *clk);
255575001e4SStefano Babic u32 clk_get_rate(struct clk *clk);
256575001e4SStefano Babic int clk_set_rate(struct clk *clk, unsigned long rate);
257575001e4SStefano Babic long clk_round_rate(struct clk *clk, unsigned long rate);
258575001e4SStefano Babic int clk_set_parent(struct clk *clk, struct clk *parent);
259575001e4SStefano Babic int clk_get_usecount(struct clk *clk);
260575001e4SStefano Babic struct clk *clk_get_parent(struct clk *clk);
261575001e4SStefano Babic 
262575001e4SStefano Babic void ipu_dump_registers(void);
263575001e4SStefano Babic int ipu_probe(void);
264575001e4SStefano Babic 
265575001e4SStefano Babic void ipu_dmfc_init(int dmfc_type, int first);
266575001e4SStefano Babic void ipu_init_dc_mappings(void);
267575001e4SStefano Babic void ipu_dmfc_set_wait4eot(int dma_chan, int width);
268575001e4SStefano Babic void ipu_dc_init(int dc_chan, int di, unsigned char interlaced);
269575001e4SStefano Babic void ipu_dc_uninit(int dc_chan);
270575001e4SStefano Babic void ipu_dp_dc_enable(ipu_channel_t channel);
271575001e4SStefano Babic int ipu_dp_init(ipu_channel_t channel, uint32_t in_pixel_fmt,
272575001e4SStefano Babic 		 uint32_t out_pixel_fmt);
273575001e4SStefano Babic void ipu_dp_uninit(ipu_channel_t channel);
274575001e4SStefano Babic void ipu_dp_dc_disable(ipu_channel_t channel, unsigned char swap);
275575001e4SStefano Babic ipu_color_space_t format_to_colorspace(uint32_t fmt);
276575001e4SStefano Babic 
277575001e4SStefano Babic #endif
278