blob: ca2a223a0d1e0318924e39bc15df47bb0e259def [file] [log] [blame]
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001/*
2 * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>
3 * Copyright (C) 2005-2009 Freescale Semiconductor, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15#ifndef __IPU_PRV_H__
16#define __IPU_PRV_H__
17
18struct ipu_soc;
19
20#include <linux/types.h>
21#include <linux/device.h>
22#include <linux/clk.h>
23#include <linux/platform_device.h>
24
Philipp Zabel39b90042013-09-30 16:13:39 +020025#include <video/imx-ipu-v3.h>
Sascha Haueraecfbdb2012-09-21 10:07:49 +020026
Sascha Haueraecfbdb2012-09-21 10:07:49 +020027#define IPU_MCU_T_DEFAULT 8
28#define IPU_CM_IDMAC_REG_OFS 0x00008000
29#define IPU_CM_IC_REG_OFS 0x00020000
30#define IPU_CM_IRT_REG_OFS 0x00028000
31#define IPU_CM_CSI0_REG_OFS 0x00030000
32#define IPU_CM_CSI1_REG_OFS 0x00038000
33#define IPU_CM_SMFC_REG_OFS 0x00050000
34#define IPU_CM_DC_REG_OFS 0x00058000
35#define IPU_CM_DMFC_REG_OFS 0x00060000
36
37/* Register addresses */
38/* IPU Common registers */
39#define IPU_CM_REG(offset) (offset)
40
41#define IPU_CONF IPU_CM_REG(0)
42
43#define IPU_SRM_PRI1 IPU_CM_REG(0x00a0)
44#define IPU_SRM_PRI2 IPU_CM_REG(0x00a4)
45#define IPU_FS_PROC_FLOW1 IPU_CM_REG(0x00a8)
46#define IPU_FS_PROC_FLOW2 IPU_CM_REG(0x00ac)
47#define IPU_FS_PROC_FLOW3 IPU_CM_REG(0x00b0)
48#define IPU_FS_DISP_FLOW1 IPU_CM_REG(0x00b4)
49#define IPU_FS_DISP_FLOW2 IPU_CM_REG(0x00b8)
50#define IPU_SKIP IPU_CM_REG(0x00bc)
51#define IPU_DISP_ALT_CONF IPU_CM_REG(0x00c0)
52#define IPU_DISP_GEN IPU_CM_REG(0x00c4)
53#define IPU_DISP_ALT1 IPU_CM_REG(0x00c8)
54#define IPU_DISP_ALT2 IPU_CM_REG(0x00cc)
55#define IPU_DISP_ALT3 IPU_CM_REG(0x00d0)
56#define IPU_DISP_ALT4 IPU_CM_REG(0x00d4)
57#define IPU_SNOOP IPU_CM_REG(0x00d8)
58#define IPU_MEM_RST IPU_CM_REG(0x00dc)
59#define IPU_PM IPU_CM_REG(0x00e0)
60#define IPU_GPR IPU_CM_REG(0x00e4)
61#define IPU_CHA_DB_MODE_SEL(ch) IPU_CM_REG(0x0150 + 4 * ((ch) / 32))
62#define IPU_ALT_CHA_DB_MODE_SEL(ch) IPU_CM_REG(0x0168 + 4 * ((ch) / 32))
63#define IPU_CHA_CUR_BUF(ch) IPU_CM_REG(0x023C + 4 * ((ch) / 32))
64#define IPU_ALT_CUR_BUF0 IPU_CM_REG(0x0244)
65#define IPU_ALT_CUR_BUF1 IPU_CM_REG(0x0248)
66#define IPU_SRM_STAT IPU_CM_REG(0x024C)
67#define IPU_PROC_TASK_STAT IPU_CM_REG(0x0250)
68#define IPU_DISP_TASK_STAT IPU_CM_REG(0x0254)
69#define IPU_CHA_BUF0_RDY(ch) IPU_CM_REG(0x0268 + 4 * ((ch) / 32))
70#define IPU_CHA_BUF1_RDY(ch) IPU_CM_REG(0x0270 + 4 * ((ch) / 32))
Steve Longerbeamaa52f572014-06-25 18:05:40 -070071#define IPU_CHA_BUF2_RDY(ch) IPU_CM_REG(0x0288 + 4 * ((ch) / 32))
Sascha Haueraecfbdb2012-09-21 10:07:49 +020072#define IPU_ALT_CHA_BUF0_RDY(ch) IPU_CM_REG(0x0278 + 4 * ((ch) / 32))
73#define IPU_ALT_CHA_BUF1_RDY(ch) IPU_CM_REG(0x0280 + 4 * ((ch) / 32))
74
75#define IPU_INT_CTRL(n) IPU_CM_REG(0x003C + 4 * (n))
76#define IPU_INT_STAT(n) IPU_CM_REG(0x0200 + 4 * (n))
77
Philipp Zabelf9bb7ac2017-02-24 18:23:55 +010078/* SRM_PRI2 */
79#define DP_S_SRM_MODE_MASK (0x3 << 3)
80#define DP_S_SRM_MODE_NOW (0x3 << 3)
81#define DP_S_SRM_MODE_NEXT_FRAME (0x1 << 3)
82
Steve Longerbeamac4708f2016-08-17 17:50:17 -070083/* FS_PROC_FLOW1 */
84#define FS_PRPENC_ROT_SRC_SEL_MASK (0xf << 0)
85#define FS_PRPENC_ROT_SRC_SEL_ENC (0x7 << 0)
86#define FS_PRPVF_ROT_SRC_SEL_MASK (0xf << 8)
87#define FS_PRPVF_ROT_SRC_SEL_VF (0x8 << 8)
88#define FS_PP_SRC_SEL_MASK (0xf << 12)
89#define FS_PP_ROT_SRC_SEL_MASK (0xf << 16)
90#define FS_PP_ROT_SRC_SEL_PP (0x5 << 16)
91#define FS_VDI1_SRC_SEL_MASK (0x3 << 20)
92#define FS_VDI3_SRC_SEL_MASK (0x3 << 20)
93#define FS_PRP_SRC_SEL_MASK (0xf << 24)
94#define FS_VDI_SRC_SEL_MASK (0x3 << 28)
95#define FS_VDI_SRC_SEL_CSI_DIRECT (0x1 << 28)
96#define FS_VDI_SRC_SEL_VDOA (0x2 << 28)
97
98/* FS_PROC_FLOW2 */
99#define FS_PRP_ENC_DEST_SEL_MASK (0xf << 0)
100#define FS_PRP_ENC_DEST_SEL_IRT_ENC (0x1 << 0)
101#define FS_PRPVF_DEST_SEL_MASK (0xf << 4)
102#define FS_PRPVF_DEST_SEL_IRT_VF (0x1 << 4)
103#define FS_PRPVF_ROT_DEST_SEL_MASK (0xf << 8)
104#define FS_PP_DEST_SEL_MASK (0xf << 12)
105#define FS_PP_DEST_SEL_IRT_PP (0x3 << 12)
106#define FS_PP_ROT_DEST_SEL_MASK (0xf << 16)
107#define FS_PRPENC_ROT_DEST_SEL_MASK (0xf << 20)
108#define FS_PRP_DEST_SEL_MASK (0xf << 24)
109
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200110#define IPU_DI0_COUNTER_RELEASE (1 << 24)
111#define IPU_DI1_COUNTER_RELEASE (1 << 25)
112
113#define IPU_IDMAC_REG(offset) (offset)
114
115#define IDMAC_CONF IPU_IDMAC_REG(0x0000)
116#define IDMAC_CHA_EN(ch) IPU_IDMAC_REG(0x0004 + 4 * ((ch) / 32))
117#define IDMAC_SEP_ALPHA IPU_IDMAC_REG(0x000c)
118#define IDMAC_ALT_SEP_ALPHA IPU_IDMAC_REG(0x0010)
119#define IDMAC_CHA_PRI(ch) IPU_IDMAC_REG(0x0014 + 4 * ((ch) / 32))
120#define IDMAC_WM_EN(ch) IPU_IDMAC_REG(0x001c + 4 * ((ch) / 32))
121#define IDMAC_CH_LOCK_EN_1 IPU_IDMAC_REG(0x0024)
122#define IDMAC_CH_LOCK_EN_2 IPU_IDMAC_REG(0x0028)
123#define IDMAC_SUB_ADDR_0 IPU_IDMAC_REG(0x002c)
124#define IDMAC_SUB_ADDR_1 IPU_IDMAC_REG(0x0030)
125#define IDMAC_SUB_ADDR_2 IPU_IDMAC_REG(0x0034)
126#define IDMAC_BAND_EN(ch) IPU_IDMAC_REG(0x0040 + 4 * ((ch) / 32))
127#define IDMAC_CHA_BUSY(ch) IPU_IDMAC_REG(0x0100 + 4 * ((ch) / 32))
128
Philipp Zabele4f2a542013-06-21 10:27:38 +0200129#define IPU_NUM_IRQS (32 * 15)
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200130
131enum ipu_modules {
132 IPU_CONF_CSI0_EN = (1 << 0),
133 IPU_CONF_CSI1_EN = (1 << 1),
134 IPU_CONF_IC_EN = (1 << 2),
135 IPU_CONF_ROT_EN = (1 << 3),
136 IPU_CONF_ISP_EN = (1 << 4),
137 IPU_CONF_DP_EN = (1 << 5),
138 IPU_CONF_DI0_EN = (1 << 6),
139 IPU_CONF_DI1_EN = (1 << 7),
140 IPU_CONF_SMFC_EN = (1 << 8),
141 IPU_CONF_DC_EN = (1 << 9),
142 IPU_CONF_DMFC_EN = (1 << 10),
143
144 IPU_CONF_VDI_EN = (1 << 12),
145
146 IPU_CONF_IDMAC_DIS = (1 << 22),
147
148 IPU_CONF_IC_DMFC_SEL = (1 << 25),
149 IPU_CONF_IC_DMFC_SYNC = (1 << 26),
150 IPU_CONF_VDI_DMFC_SYNC = (1 << 27),
151
152 IPU_CONF_CSI0_DATA_SOURCE = (1 << 28),
153 IPU_CONF_CSI1_DATA_SOURCE = (1 << 29),
154 IPU_CONF_IC_INPUT = (1 << 30),
155 IPU_CONF_CSI_SEL = (1 << 31),
156};
157
158struct ipuv3_channel {
159 unsigned int num;
160
161 bool enabled;
162 bool busy;
163
164 struct ipu_soc *ipu;
165};
166
Steve Longerbeam7d2691d2014-06-25 18:05:47 -0700167struct ipu_cpmem;
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700168struct ipu_csi;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200169struct ipu_dc_priv;
170struct ipu_dmfc_priv;
171struct ipu_di;
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200172struct ipu_ic_priv;
Steve Longerbeam2d2ead42016-08-17 17:50:16 -0700173struct ipu_vdi;
Steve Longerbeamcd98e852016-09-17 12:33:58 -0700174struct ipu_image_convert_priv;
Philipp Zabel35de9252012-05-09 16:59:01 +0200175struct ipu_smfc_priv;
Lucas Stachd2a34232017-03-08 12:13:14 +0100176struct ipu_pre;
Lucas Stachea9c2602017-03-08 12:13:16 +0100177struct ipu_prg;
Philipp Zabel35de9252012-05-09 16:59:01 +0200178
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200179struct ipu_devtype;
180
181struct ipu_soc {
182 struct device *dev;
183 const struct ipu_devtype *devtype;
184 enum ipuv3_type ipu_type;
185 spinlock_t lock;
186 struct mutex channel_lock;
187
188 void __iomem *cm_reg;
189 void __iomem *idmac_reg;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200190
Steve Longerbeam572a7612016-07-19 18:11:02 -0700191 int id;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200192 int usecount;
193
194 struct clk *clk;
195
196 struct ipuv3_channel channel[64];
197
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200198 int irq_sync;
199 int irq_err;
Philipp Zabelb7287662013-06-21 10:27:39 +0200200 struct irq_domain *domain;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200201
Steve Longerbeam7d2691d2014-06-25 18:05:47 -0700202 struct ipu_cpmem *cpmem_priv;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200203 struct ipu_dc_priv *dc_priv;
204 struct ipu_dp_priv *dp_priv;
205 struct ipu_dmfc_priv *dmfc_priv;
206 struct ipu_di *di_priv[2];
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700207 struct ipu_csi *csi_priv[2];
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200208 struct ipu_ic_priv *ic_priv;
Steve Longerbeam2d2ead42016-08-17 17:50:16 -0700209 struct ipu_vdi *vdi_priv;
Steve Longerbeamcd98e852016-09-17 12:33:58 -0700210 struct ipu_image_convert_priv *image_convert_priv;
Philipp Zabel35de9252012-05-09 16:59:01 +0200211 struct ipu_smfc_priv *smfc_priv;
Lucas Stachea9c2602017-03-08 12:13:16 +0100212 struct ipu_prg *prg_priv;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200213};
214
Steve Longerbeam7d2691d2014-06-25 18:05:47 -0700215static inline u32 ipu_idmac_read(struct ipu_soc *ipu, unsigned offset)
216{
217 return readl(ipu->idmac_reg + offset);
218}
219
220static inline void ipu_idmac_write(struct ipu_soc *ipu, u32 value,
221 unsigned offset)
222{
223 writel(value, ipu->idmac_reg + offset);
224}
225
Philipp Zabelf9bb7ac2017-02-24 18:23:55 +0100226void ipu_srm_dp_update(struct ipu_soc *ipu, bool sync);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200227
228int ipu_module_enable(struct ipu_soc *ipu, u32 mask);
229int ipu_module_disable(struct ipu_soc *ipu, u32 mask);
230
Philipp Zabel17075502014-04-14 23:53:17 +0200231bool ipu_idmac_channel_busy(struct ipu_soc *ipu, unsigned int chno);
232int ipu_wait_interrupt(struct ipu_soc *ipu, int irq, int ms);
233
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700234int ipu_csi_init(struct ipu_soc *ipu, struct device *dev, int id,
235 unsigned long base, u32 module, struct clk *clk_ipu);
236void ipu_csi_exit(struct ipu_soc *ipu, int id);
237
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200238int ipu_ic_init(struct ipu_soc *ipu, struct device *dev,
239 unsigned long base, unsigned long tpmem_base);
240void ipu_ic_exit(struct ipu_soc *ipu);
241
Steve Longerbeam2d2ead42016-08-17 17:50:16 -0700242int ipu_vdi_init(struct ipu_soc *ipu, struct device *dev,
243 unsigned long base, u32 module);
244void ipu_vdi_exit(struct ipu_soc *ipu);
245
Steve Longerbeamcd98e852016-09-17 12:33:58 -0700246int ipu_image_convert_init(struct ipu_soc *ipu, struct device *dev);
247void ipu_image_convert_exit(struct ipu_soc *ipu);
248
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200249int ipu_di_init(struct ipu_soc *ipu, struct device *dev, int id,
250 unsigned long base, u32 module, struct clk *ipu_clk);
251void ipu_di_exit(struct ipu_soc *ipu, int id);
252
253int ipu_dmfc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base,
254 struct clk *ipu_clk);
255void ipu_dmfc_exit(struct ipu_soc *ipu);
256
257int ipu_dp_init(struct ipu_soc *ipu, struct device *dev, unsigned long base);
258void ipu_dp_exit(struct ipu_soc *ipu);
259
260int ipu_dc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base,
261 unsigned long template_base);
262void ipu_dc_exit(struct ipu_soc *ipu);
263
264int ipu_cpmem_init(struct ipu_soc *ipu, struct device *dev, unsigned long base);
265void ipu_cpmem_exit(struct ipu_soc *ipu);
266
Philipp Zabel35de9252012-05-09 16:59:01 +0200267int ipu_smfc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base);
268void ipu_smfc_exit(struct ipu_soc *ipu);
269
Lucas Stachd2a34232017-03-08 12:13:14 +0100270struct ipu_pre *ipu_pre_lookup_by_phandle(struct device *dev, const char *name,
271 int index);
272int ipu_pre_get_available_count(void);
273int ipu_pre_get(struct ipu_pre *pre);
274void ipu_pre_put(struct ipu_pre *pre);
275u32 ipu_pre_get_baddr(struct ipu_pre *pre);
276void ipu_pre_configure(struct ipu_pre *pre, unsigned int width,
277 unsigned int height,
278 unsigned int stride, u32 format, unsigned int bufaddr);
279void ipu_pre_update(struct ipu_pre *pre, unsigned int bufaddr);
280
Lucas Stachea9c2602017-03-08 12:13:16 +0100281struct ipu_prg *ipu_prg_lookup_by_phandle(struct device *dev, const char *name,
282 int ipu_id);
283
Lucas Stachd2a34232017-03-08 12:13:14 +0100284extern struct platform_driver ipu_pre_drv;
Lucas Stachea9c2602017-03-08 12:13:16 +0100285extern struct platform_driver ipu_prg_drv;
Lucas Stachd2a34232017-03-08 12:13:14 +0100286
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200287#endif /* __IPU_PRV_H__ */