blob: 6d254275192bda190172c6e865d0882ca98a3ffe [file] [log] [blame]
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001/*
2 * Copyright 2005-2009 Freescale Semiconductor, Inc.
3 *
4 * The code contained herein is licensed under the GNU Lesser General
5 * Public License. You may obtain a copy of the GNU Lesser General
6 * Public License Version 2.1 or later at the following locations:
7 *
8 * http://www.opensource.org/licenses/lgpl-license.html
9 * http://www.gnu.org/copyleft/lgpl.html
10 */
11
12#ifndef __DRM_IPU_H__
13#define __DRM_IPU_H__
14
15#include <linux/types.h>
16#include <linux/videodev2.h>
17#include <linux/bitmap.h>
18#include <linux/fb.h>
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -070019#include <media/v4l2-mediabus.h>
Sascha Haueraecfbdb2012-09-21 10:07:49 +020020
21struct ipu_soc;
22
23enum ipuv3_type {
24 IPUV3EX,
25 IPUV3M,
26 IPUV3H,
27};
28
Philipp Zabel7f4392a2014-02-25 12:43:41 +010029#define IPU_PIX_FMT_GBR24 v4l2_fourcc('G', 'B', 'R', '3')
30
Sascha Haueraecfbdb2012-09-21 10:07:49 +020031/*
32 * Bitfield of Display Interface signal polarities.
33 */
34struct ipu_di_signal_cfg {
35 unsigned datamask_en:1;
36 unsigned interlaced:1;
37 unsigned odd_field_first:1;
38 unsigned clksel_en:1;
39 unsigned clkidle_en:1;
40 unsigned data_pol:1; /* true = inverted */
41 unsigned clk_pol:1; /* true = rising edge */
42 unsigned enable_pol:1;
43 unsigned Hsync_pol:1; /* true = active high */
44 unsigned Vsync_pol:1;
45
46 u16 width;
47 u16 height;
48 u32 pixel_fmt;
49 u16 h_start_width;
50 u16 h_sync_width;
51 u16 h_end_width;
52 u16 v_start_width;
53 u16 v_sync_width;
54 u16 v_end_width;
55 u32 v_to_h_sync;
56 unsigned long pixelclock;
57#define IPU_DI_CLKMODE_SYNC (1 << 0)
58#define IPU_DI_CLKMODE_EXT (1 << 1)
59 unsigned long clkflags;
Philipp Zabel2ea42602013-04-08 18:04:35 +020060
61 u8 hsync_pin;
62 u8 vsync_pin;
Sascha Haueraecfbdb2012-09-21 10:07:49 +020063};
64
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -070065/*
66 * Enumeration of CSI destinations
67 */
68enum ipu_csi_dest {
69 IPU_CSI_DEST_IDMAC, /* to memory via SMFC */
70 IPU_CSI_DEST_IC, /* to Image Converter */
71 IPU_CSI_DEST_VDIC, /* to VDIC */
72};
73
Sascha Haueraecfbdb2012-09-21 10:07:49 +020074enum ipu_color_space {
75 IPUV3_COLORSPACE_RGB,
76 IPUV3_COLORSPACE_YUV,
77 IPUV3_COLORSPACE_UNKNOWN,
78};
79
80struct ipuv3_channel;
81
82enum ipu_channel_irq {
83 IPU_IRQ_EOF = 0,
84 IPU_IRQ_NFACK = 64,
85 IPU_IRQ_NFB4EOF = 128,
86 IPU_IRQ_EOS = 192,
87};
88
Philipp Zabel861a50c2014-04-14 23:53:16 +020089int ipu_map_irq(struct ipu_soc *ipu, int irq);
Sascha Haueraecfbdb2012-09-21 10:07:49 +020090int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct ipuv3_channel *channel,
91 enum ipu_channel_irq irq);
92
93#define IPU_IRQ_DP_SF_START (448 + 2)
94#define IPU_IRQ_DP_SF_END (448 + 3)
95#define IPU_IRQ_BG_SF_END IPU_IRQ_DP_SF_END,
96#define IPU_IRQ_DC_FC_0 (448 + 8)
97#define IPU_IRQ_DC_FC_1 (448 + 9)
98#define IPU_IRQ_DC_FC_2 (448 + 10)
99#define IPU_IRQ_DC_FC_3 (448 + 11)
100#define IPU_IRQ_DC_FC_4 (448 + 12)
101#define IPU_IRQ_DC_FC_6 (448 + 13)
102#define IPU_IRQ_VSYNC_PRE_0 (448 + 14)
103#define IPU_IRQ_VSYNC_PRE_1 (448 + 15)
104
105/*
Steve Longerbeamba079752014-06-25 18:05:30 -0700106 * IPU Common functions
107 */
108void ipu_set_csi_src_mux(struct ipu_soc *ipu, int csi_id, bool mipi_csi2);
109void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, bool vdi);
110
111/*
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200112 * IPU Image DMA Controller (idmac) functions
113 */
114struct ipuv3_channel *ipu_idmac_get(struct ipu_soc *ipu, unsigned channel);
115void ipu_idmac_put(struct ipuv3_channel *);
116
117int ipu_idmac_enable_channel(struct ipuv3_channel *channel);
118int ipu_idmac_disable_channel(struct ipuv3_channel *channel);
Sascha Hauerfb822a32013-10-10 16:18:41 +0200119int ipu_idmac_wait_busy(struct ipuv3_channel *channel, int ms);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200120
121void ipu_idmac_set_double_buffer(struct ipuv3_channel *channel,
122 bool doublebuffer);
Philipp Zabele9046092012-05-16 17:28:29 +0200123int ipu_idmac_get_current_buffer(struct ipuv3_channel *channel);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200124void ipu_idmac_select_buffer(struct ipuv3_channel *channel, u32 buf_num);
125
126/*
Steve Longerbeam7d2691d2014-06-25 18:05:47 -0700127 * IPU Channel Parameter Memory (cpmem) functions
128 */
129struct ipu_rgb {
130 struct fb_bitfield red;
131 struct fb_bitfield green;
132 struct fb_bitfield blue;
133 struct fb_bitfield transp;
134 int bits_per_pixel;
135};
136
137struct ipu_image {
138 struct v4l2_pix_format pix;
139 struct v4l2_rect rect;
140 dma_addr_t phys;
141};
142
143void ipu_cpmem_zero(struct ipuv3_channel *ch);
144void ipu_cpmem_set_resolution(struct ipuv3_channel *ch, int xres, int yres);
145void ipu_cpmem_set_stride(struct ipuv3_channel *ch, int stride);
146void ipu_cpmem_set_high_priority(struct ipuv3_channel *ch);
147void ipu_cpmem_set_buffer(struct ipuv3_channel *ch, int bufnum, dma_addr_t buf);
148void ipu_cpmem_interlaced_scan(struct ipuv3_channel *ch, int stride);
149void ipu_cpmem_set_burstsize(struct ipuv3_channel *ch, int burstsize);
150int ipu_cpmem_set_format_rgb(struct ipuv3_channel *ch,
151 const struct ipu_rgb *rgb);
152int ipu_cpmem_set_format_passthrough(struct ipuv3_channel *ch, int width);
153void ipu_cpmem_set_yuv_interleaved(struct ipuv3_channel *ch, u32 pixel_format);
154void ipu_cpmem_set_yuv_planar_full(struct ipuv3_channel *ch,
155 u32 pixel_format, int stride,
156 int u_offset, int v_offset);
157void ipu_cpmem_set_yuv_planar(struct ipuv3_channel *ch,
158 u32 pixel_format, int stride, int height);
159int ipu_cpmem_set_fmt(struct ipuv3_channel *ch, u32 drm_fourcc);
160int ipu_cpmem_set_image(struct ipuv3_channel *ch, struct ipu_image *image);
161
162/*
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200163 * IPU Display Controller (dc) functions
164 */
165struct ipu_dc;
166struct ipu_di;
167struct ipu_dc *ipu_dc_get(struct ipu_soc *ipu, int channel);
168void ipu_dc_put(struct ipu_dc *dc);
169int ipu_dc_init_sync(struct ipu_dc *dc, struct ipu_di *di, bool interlaced,
170 u32 pixel_fmt, u32 width);
Philipp Zabel1e6d4862014-04-14 23:53:23 +0200171void ipu_dc_enable(struct ipu_soc *ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200172void ipu_dc_enable_channel(struct ipu_dc *dc);
173void ipu_dc_disable_channel(struct ipu_dc *dc);
Philipp Zabel1e6d4862014-04-14 23:53:23 +0200174void ipu_dc_disable(struct ipu_soc *ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200175
176/*
177 * IPU Display Interface (di) functions
178 */
179struct ipu_di *ipu_di_get(struct ipu_soc *ipu, int disp);
180void ipu_di_put(struct ipu_di *);
181int ipu_di_disable(struct ipu_di *);
182int ipu_di_enable(struct ipu_di *);
183int ipu_di_get_num(struct ipu_di *);
184int ipu_di_init_sync_panel(struct ipu_di *, struct ipu_di_signal_cfg *sig);
185
186/*
187 * IPU Display Multi FIFO Controller (dmfc) functions
188 */
189struct dmfc_channel;
190int ipu_dmfc_enable_channel(struct dmfc_channel *dmfc);
191void ipu_dmfc_disable_channel(struct dmfc_channel *dmfc);
192int ipu_dmfc_alloc_bandwidth(struct dmfc_channel *dmfc,
193 unsigned long bandwidth_mbs, int burstsize);
194void ipu_dmfc_free_bandwidth(struct dmfc_channel *dmfc);
195int ipu_dmfc_init_channel(struct dmfc_channel *dmfc, int width);
196struct dmfc_channel *ipu_dmfc_get(struct ipu_soc *ipu, int ipuv3_channel);
197void ipu_dmfc_put(struct dmfc_channel *dmfc);
198
199/*
200 * IPU Display Processor (dp) functions
201 */
202#define IPU_DP_FLOW_SYNC_BG 0
203#define IPU_DP_FLOW_SYNC_FG 1
204#define IPU_DP_FLOW_ASYNC0_BG 2
205#define IPU_DP_FLOW_ASYNC0_FG 3
206#define IPU_DP_FLOW_ASYNC1_BG 4
207#define IPU_DP_FLOW_ASYNC1_FG 5
208
209struct ipu_dp *ipu_dp_get(struct ipu_soc *ipu, unsigned int flow);
210void ipu_dp_put(struct ipu_dp *);
Philipp Zabel285bbb02014-04-14 23:53:20 +0200211int ipu_dp_enable(struct ipu_soc *ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200212int ipu_dp_enable_channel(struct ipu_dp *dp);
213void ipu_dp_disable_channel(struct ipu_dp *dp);
Philipp Zabel285bbb02014-04-14 23:53:20 +0200214void ipu_dp_disable(struct ipu_soc *ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200215int ipu_dp_setup_channel(struct ipu_dp *dp,
216 enum ipu_color_space in, enum ipu_color_space out);
217int ipu_dp_set_window_pos(struct ipu_dp *, u16 x_pos, u16 y_pos);
218int ipu_dp_set_global_alpha(struct ipu_dp *dp, bool enable, u8 alpha,
219 bool bg_chan);
220
Philipp Zabel35de9252012-05-09 16:59:01 +0200221/*
Philipp Zabel3f5a8a92012-05-22 17:08:48 +0200222 * IPU CMOS Sensor Interface (csi) functions
223 */
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700224struct ipu_csi;
225int ipu_csi_init_interface(struct ipu_csi *csi,
226 struct v4l2_mbus_config *mbus_cfg,
227 struct v4l2_mbus_framefmt *mbus_fmt);
228bool ipu_csi_is_interlaced(struct ipu_csi *csi);
229void ipu_csi_get_window(struct ipu_csi *csi, struct v4l2_rect *w);
230void ipu_csi_set_window(struct ipu_csi *csi, struct v4l2_rect *w);
231void ipu_csi_set_test_generator(struct ipu_csi *csi, bool active,
232 u32 r_value, u32 g_value, u32 b_value,
233 u32 pix_clk);
234int ipu_csi_set_mipi_datatype(struct ipu_csi *csi, u32 vc,
235 struct v4l2_mbus_framefmt *mbus_fmt);
236int ipu_csi_set_skip_smfc(struct ipu_csi *csi, u32 skip,
237 u32 max_ratio, u32 id);
238int ipu_csi_set_dest(struct ipu_csi *csi, enum ipu_csi_dest csi_dest);
239int ipu_csi_enable(struct ipu_csi *csi);
240int ipu_csi_disable(struct ipu_csi *csi);
241struct ipu_csi *ipu_csi_get(struct ipu_soc *ipu, int id);
242void ipu_csi_put(struct ipu_csi *csi);
243void ipu_csi_dump(struct ipu_csi *csi);
Philipp Zabel3f5a8a92012-05-22 17:08:48 +0200244
245/*
Philipp Zabel35de9252012-05-09 16:59:01 +0200246 * IPU Sensor Multiple FIFO Controller (SMFC) functions
247 */
Philipp Zabel3f5a8a92012-05-22 17:08:48 +0200248int ipu_smfc_enable(struct ipu_soc *ipu);
249int ipu_smfc_disable(struct ipu_soc *ipu);
Philipp Zabel35de9252012-05-09 16:59:01 +0200250int ipu_smfc_map_channel(struct ipu_soc *ipu, int channel, int csi_id, int mipi_id);
251int ipu_smfc_set_burstsize(struct ipu_soc *ipu, int channel, int burstsize);
252
Philipp Zabel7cb17792013-10-10 16:18:38 +0200253enum ipu_color_space ipu_drm_fourcc_to_colorspace(u32 drm_fourcc);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200254enum ipu_color_space ipu_pixelformat_to_colorspace(u32 pixelformat);
255
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200256struct ipu_client_platformdata {
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +0200257 int csi;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200258 int di;
259 int dc;
260 int dp;
261 int dmfc;
262 int dma[2];
263};
264
265#endif /* __DRM_IPU_H__ */