162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>
462306a36Sopenharmony_ci * Copyright (C) 2005-2009 Freescale Semiconductor, Inc.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef __IPU_PRV_H__
762306a36Sopenharmony_ci#define __IPU_PRV_H__
862306a36Sopenharmony_ci
962306a36Sopenharmony_cistruct ipu_soc;
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <linux/io.h>
1262306a36Sopenharmony_ci#include <linux/types.h>
1362306a36Sopenharmony_ci#include <linux/device.h>
1462306a36Sopenharmony_ci#include <linux/clk.h>
1562306a36Sopenharmony_ci#include <linux/platform_device.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#include <video/imx-ipu-v3.h>
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define IPU_MCU_T_DEFAULT	8
2062306a36Sopenharmony_ci#define IPU_CM_IDMAC_REG_OFS	0x00008000
2162306a36Sopenharmony_ci#define IPU_CM_IC_REG_OFS	0x00020000
2262306a36Sopenharmony_ci#define IPU_CM_IRT_REG_OFS	0x00028000
2362306a36Sopenharmony_ci#define IPU_CM_CSI0_REG_OFS	0x00030000
2462306a36Sopenharmony_ci#define IPU_CM_CSI1_REG_OFS	0x00038000
2562306a36Sopenharmony_ci#define IPU_CM_SMFC_REG_OFS	0x00050000
2662306a36Sopenharmony_ci#define IPU_CM_DC_REG_OFS	0x00058000
2762306a36Sopenharmony_ci#define IPU_CM_DMFC_REG_OFS	0x00060000
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci/* Register addresses */
3062306a36Sopenharmony_ci/* IPU Common registers */
3162306a36Sopenharmony_ci#define IPU_CM_REG(offset)	(offset)
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define IPU_CONF			IPU_CM_REG(0)
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define IPU_SRM_PRI1			IPU_CM_REG(0x00a0)
3662306a36Sopenharmony_ci#define IPU_SRM_PRI2			IPU_CM_REG(0x00a4)
3762306a36Sopenharmony_ci#define IPU_FS_PROC_FLOW1		IPU_CM_REG(0x00a8)
3862306a36Sopenharmony_ci#define IPU_FS_PROC_FLOW2		IPU_CM_REG(0x00ac)
3962306a36Sopenharmony_ci#define IPU_FS_PROC_FLOW3		IPU_CM_REG(0x00b0)
4062306a36Sopenharmony_ci#define IPU_FS_DISP_FLOW1		IPU_CM_REG(0x00b4)
4162306a36Sopenharmony_ci#define IPU_FS_DISP_FLOW2		IPU_CM_REG(0x00b8)
4262306a36Sopenharmony_ci#define IPU_SKIP			IPU_CM_REG(0x00bc)
4362306a36Sopenharmony_ci#define IPU_DISP_ALT_CONF		IPU_CM_REG(0x00c0)
4462306a36Sopenharmony_ci#define IPU_DISP_GEN			IPU_CM_REG(0x00c4)
4562306a36Sopenharmony_ci#define IPU_DISP_ALT1			IPU_CM_REG(0x00c8)
4662306a36Sopenharmony_ci#define IPU_DISP_ALT2			IPU_CM_REG(0x00cc)
4762306a36Sopenharmony_ci#define IPU_DISP_ALT3			IPU_CM_REG(0x00d0)
4862306a36Sopenharmony_ci#define IPU_DISP_ALT4			IPU_CM_REG(0x00d4)
4962306a36Sopenharmony_ci#define IPU_SNOOP			IPU_CM_REG(0x00d8)
5062306a36Sopenharmony_ci#define IPU_MEM_RST			IPU_CM_REG(0x00dc)
5162306a36Sopenharmony_ci#define IPU_PM				IPU_CM_REG(0x00e0)
5262306a36Sopenharmony_ci#define IPU_GPR				IPU_CM_REG(0x00e4)
5362306a36Sopenharmony_ci#define IPU_CHA_DB_MODE_SEL(ch)		IPU_CM_REG(0x0150 + 4 * ((ch) / 32))
5462306a36Sopenharmony_ci#define IPU_ALT_CHA_DB_MODE_SEL(ch)	IPU_CM_REG(0x0168 + 4 * ((ch) / 32))
5562306a36Sopenharmony_ci#define IPU_CHA_CUR_BUF(ch)		IPU_CM_REG(0x023C + 4 * ((ch) / 32))
5662306a36Sopenharmony_ci#define IPU_ALT_CUR_BUF0		IPU_CM_REG(0x0244)
5762306a36Sopenharmony_ci#define IPU_ALT_CUR_BUF1		IPU_CM_REG(0x0248)
5862306a36Sopenharmony_ci#define IPU_SRM_STAT			IPU_CM_REG(0x024C)
5962306a36Sopenharmony_ci#define IPU_PROC_TASK_STAT		IPU_CM_REG(0x0250)
6062306a36Sopenharmony_ci#define IPU_DISP_TASK_STAT		IPU_CM_REG(0x0254)
6162306a36Sopenharmony_ci#define IPU_CHA_BUF0_RDY(ch)		IPU_CM_REG(0x0268 + 4 * ((ch) / 32))
6262306a36Sopenharmony_ci#define IPU_CHA_BUF1_RDY(ch)		IPU_CM_REG(0x0270 + 4 * ((ch) / 32))
6362306a36Sopenharmony_ci#define IPU_CHA_BUF2_RDY(ch)		IPU_CM_REG(0x0288 + 4 * ((ch) / 32))
6462306a36Sopenharmony_ci#define IPU_ALT_CHA_BUF0_RDY(ch)	IPU_CM_REG(0x0278 + 4 * ((ch) / 32))
6562306a36Sopenharmony_ci#define IPU_ALT_CHA_BUF1_RDY(ch)	IPU_CM_REG(0x0280 + 4 * ((ch) / 32))
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#define IPU_INT_CTRL(n)		IPU_CM_REG(0x003C + 4 * (n))
6862306a36Sopenharmony_ci#define IPU_INT_STAT(n)		IPU_CM_REG(0x0200 + 4 * (n))
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci/* SRM_PRI2 */
7162306a36Sopenharmony_ci#define DP_S_SRM_MODE_MASK		(0x3 << 3)
7262306a36Sopenharmony_ci#define DP_S_SRM_MODE_NOW		(0x3 << 3)
7362306a36Sopenharmony_ci#define DP_S_SRM_MODE_NEXT_FRAME	(0x1 << 3)
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci/* FS_PROC_FLOW1 */
7662306a36Sopenharmony_ci#define FS_PRPENC_ROT_SRC_SEL_MASK	(0xf << 0)
7762306a36Sopenharmony_ci#define FS_PRPENC_ROT_SRC_SEL_ENC		(0x7 << 0)
7862306a36Sopenharmony_ci#define FS_PRPVF_ROT_SRC_SEL_MASK	(0xf << 8)
7962306a36Sopenharmony_ci#define FS_PRPVF_ROT_SRC_SEL_VF			(0x8 << 8)
8062306a36Sopenharmony_ci#define FS_PP_SRC_SEL_MASK		(0xf << 12)
8162306a36Sopenharmony_ci#define FS_PP_ROT_SRC_SEL_MASK		(0xf << 16)
8262306a36Sopenharmony_ci#define FS_PP_ROT_SRC_SEL_PP			(0x5 << 16)
8362306a36Sopenharmony_ci#define FS_VDI1_SRC_SEL_MASK		(0x3 << 20)
8462306a36Sopenharmony_ci#define FS_VDI3_SRC_SEL_MASK		(0x3 << 20)
8562306a36Sopenharmony_ci#define FS_PRP_SRC_SEL_MASK		(0xf << 24)
8662306a36Sopenharmony_ci#define FS_VDI_SRC_SEL_MASK		(0x3 << 28)
8762306a36Sopenharmony_ci#define FS_VDI_SRC_SEL_CSI_DIRECT		(0x1 << 28)
8862306a36Sopenharmony_ci#define FS_VDI_SRC_SEL_VDOA			(0x2 << 28)
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci/* FS_PROC_FLOW2 */
9162306a36Sopenharmony_ci#define FS_PRP_ENC_DEST_SEL_MASK	(0xf << 0)
9262306a36Sopenharmony_ci#define FS_PRP_ENC_DEST_SEL_IRT_ENC		(0x1 << 0)
9362306a36Sopenharmony_ci#define FS_PRPVF_DEST_SEL_MASK		(0xf << 4)
9462306a36Sopenharmony_ci#define FS_PRPVF_DEST_SEL_IRT_VF		(0x1 << 4)
9562306a36Sopenharmony_ci#define FS_PRPVF_ROT_DEST_SEL_MASK	(0xf << 8)
9662306a36Sopenharmony_ci#define FS_PP_DEST_SEL_MASK		(0xf << 12)
9762306a36Sopenharmony_ci#define FS_PP_DEST_SEL_IRT_PP			(0x3 << 12)
9862306a36Sopenharmony_ci#define FS_PP_ROT_DEST_SEL_MASK		(0xf << 16)
9962306a36Sopenharmony_ci#define FS_PRPENC_ROT_DEST_SEL_MASK	(0xf << 20)
10062306a36Sopenharmony_ci#define FS_PRP_DEST_SEL_MASK		(0xf << 24)
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci#define IPU_DI0_COUNTER_RELEASE			(1 << 24)
10362306a36Sopenharmony_ci#define IPU_DI1_COUNTER_RELEASE			(1 << 25)
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci#define IPU_IDMAC_REG(offset)	(offset)
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci#define IDMAC_CONF			IPU_IDMAC_REG(0x0000)
10862306a36Sopenharmony_ci#define IDMAC_CHA_EN(ch)		IPU_IDMAC_REG(0x0004 + 4 * ((ch) / 32))
10962306a36Sopenharmony_ci#define IDMAC_SEP_ALPHA			IPU_IDMAC_REG(0x000c)
11062306a36Sopenharmony_ci#define IDMAC_ALT_SEP_ALPHA		IPU_IDMAC_REG(0x0010)
11162306a36Sopenharmony_ci#define IDMAC_CHA_PRI(ch)		IPU_IDMAC_REG(0x0014 + 4 * ((ch) / 32))
11262306a36Sopenharmony_ci#define IDMAC_WM_EN(ch)			IPU_IDMAC_REG(0x001c + 4 * ((ch) / 32))
11362306a36Sopenharmony_ci#define IDMAC_CH_LOCK_EN_1		IPU_IDMAC_REG(0x0024)
11462306a36Sopenharmony_ci#define IDMAC_CH_LOCK_EN_2		IPU_IDMAC_REG(0x0028)
11562306a36Sopenharmony_ci#define IDMAC_SUB_ADDR_0		IPU_IDMAC_REG(0x002c)
11662306a36Sopenharmony_ci#define IDMAC_SUB_ADDR_1		IPU_IDMAC_REG(0x0030)
11762306a36Sopenharmony_ci#define IDMAC_SUB_ADDR_2		IPU_IDMAC_REG(0x0034)
11862306a36Sopenharmony_ci#define IDMAC_BAND_EN(ch)		IPU_IDMAC_REG(0x0040 + 4 * ((ch) / 32))
11962306a36Sopenharmony_ci#define IDMAC_CHA_BUSY(ch)		IPU_IDMAC_REG(0x0100 + 4 * ((ch) / 32))
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci#define IPU_NUM_IRQS	(32 * 15)
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_cienum ipu_modules {
12462306a36Sopenharmony_ci	IPU_CONF_CSI0_EN		= (1 << 0),
12562306a36Sopenharmony_ci	IPU_CONF_CSI1_EN		= (1 << 1),
12662306a36Sopenharmony_ci	IPU_CONF_IC_EN			= (1 << 2),
12762306a36Sopenharmony_ci	IPU_CONF_ROT_EN			= (1 << 3),
12862306a36Sopenharmony_ci	IPU_CONF_ISP_EN			= (1 << 4),
12962306a36Sopenharmony_ci	IPU_CONF_DP_EN			= (1 << 5),
13062306a36Sopenharmony_ci	IPU_CONF_DI0_EN			= (1 << 6),
13162306a36Sopenharmony_ci	IPU_CONF_DI1_EN			= (1 << 7),
13262306a36Sopenharmony_ci	IPU_CONF_SMFC_EN		= (1 << 8),
13362306a36Sopenharmony_ci	IPU_CONF_DC_EN			= (1 << 9),
13462306a36Sopenharmony_ci	IPU_CONF_DMFC_EN		= (1 << 10),
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci	IPU_CONF_VDI_EN			= (1 << 12),
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci	IPU_CONF_IDMAC_DIS		= (1 << 22),
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci	IPU_CONF_IC_DMFC_SEL		= (1 << 25),
14162306a36Sopenharmony_ci	IPU_CONF_IC_DMFC_SYNC		= (1 << 26),
14262306a36Sopenharmony_ci	IPU_CONF_VDI_DMFC_SYNC		= (1 << 27),
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci	IPU_CONF_CSI0_DATA_SOURCE	= (1 << 28),
14562306a36Sopenharmony_ci	IPU_CONF_CSI1_DATA_SOURCE	= (1 << 29),
14662306a36Sopenharmony_ci	IPU_CONF_IC_INPUT		= (1 << 30),
14762306a36Sopenharmony_ci	IPU_CONF_CSI_SEL		= (1 << 31),
14862306a36Sopenharmony_ci};
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_cistruct ipuv3_channel {
15162306a36Sopenharmony_ci	unsigned int num;
15262306a36Sopenharmony_ci	struct ipu_soc *ipu;
15362306a36Sopenharmony_ci	struct list_head list;
15462306a36Sopenharmony_ci};
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_cistruct ipu_cpmem;
15762306a36Sopenharmony_cistruct ipu_csi;
15862306a36Sopenharmony_cistruct ipu_dc_priv;
15962306a36Sopenharmony_cistruct ipu_dmfc_priv;
16062306a36Sopenharmony_cistruct ipu_di;
16162306a36Sopenharmony_cistruct ipu_ic_priv;
16262306a36Sopenharmony_cistruct ipu_vdi;
16362306a36Sopenharmony_cistruct ipu_image_convert_priv;
16462306a36Sopenharmony_cistruct ipu_smfc_priv;
16562306a36Sopenharmony_cistruct ipu_pre;
16662306a36Sopenharmony_cistruct ipu_prg;
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_cistruct ipu_devtype;
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_cistruct ipu_soc {
17162306a36Sopenharmony_ci	struct device		*dev;
17262306a36Sopenharmony_ci	const struct ipu_devtype	*devtype;
17362306a36Sopenharmony_ci	enum ipuv3_type		ipu_type;
17462306a36Sopenharmony_ci	spinlock_t		lock;
17562306a36Sopenharmony_ci	struct mutex		channel_lock;
17662306a36Sopenharmony_ci	struct list_head	channels;
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci	void __iomem		*cm_reg;
17962306a36Sopenharmony_ci	void __iomem		*idmac_reg;
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci	int			id;
18262306a36Sopenharmony_ci	int			usecount;
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci	struct clk		*clk;
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci	int			irq_sync;
18762306a36Sopenharmony_ci	int			irq_err;
18862306a36Sopenharmony_ci	struct irq_domain	*domain;
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci	struct ipu_cpmem	*cpmem_priv;
19162306a36Sopenharmony_ci	struct ipu_dc_priv	*dc_priv;
19262306a36Sopenharmony_ci	struct ipu_dp_priv	*dp_priv;
19362306a36Sopenharmony_ci	struct ipu_dmfc_priv	*dmfc_priv;
19462306a36Sopenharmony_ci	struct ipu_di		*di_priv[2];
19562306a36Sopenharmony_ci	struct ipu_csi		*csi_priv[2];
19662306a36Sopenharmony_ci	struct ipu_ic_priv	*ic_priv;
19762306a36Sopenharmony_ci	struct ipu_vdi          *vdi_priv;
19862306a36Sopenharmony_ci	struct ipu_image_convert_priv *image_convert_priv;
19962306a36Sopenharmony_ci	struct ipu_smfc_priv	*smfc_priv;
20062306a36Sopenharmony_ci	struct ipu_prg		*prg_priv;
20162306a36Sopenharmony_ci};
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_cistatic inline u32 ipu_idmac_read(struct ipu_soc *ipu, unsigned offset)
20462306a36Sopenharmony_ci{
20562306a36Sopenharmony_ci	return readl(ipu->idmac_reg + offset);
20662306a36Sopenharmony_ci}
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_cistatic inline void ipu_idmac_write(struct ipu_soc *ipu, u32 value,
20962306a36Sopenharmony_ci				   unsigned offset)
21062306a36Sopenharmony_ci{
21162306a36Sopenharmony_ci	writel(value, ipu->idmac_reg + offset);
21262306a36Sopenharmony_ci}
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_civoid ipu_srm_dp_update(struct ipu_soc *ipu, bool sync);
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ciint ipu_module_enable(struct ipu_soc *ipu, u32 mask);
21762306a36Sopenharmony_ciint ipu_module_disable(struct ipu_soc *ipu, u32 mask);
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_cibool ipu_idmac_channel_busy(struct ipu_soc *ipu, unsigned int chno);
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ciint ipu_csi_init(struct ipu_soc *ipu, struct device *dev, int id,
22262306a36Sopenharmony_ci		 unsigned long base, u32 module, struct clk *clk_ipu);
22362306a36Sopenharmony_civoid ipu_csi_exit(struct ipu_soc *ipu, int id);
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ciint ipu_ic_init(struct ipu_soc *ipu, struct device *dev,
22662306a36Sopenharmony_ci		unsigned long base, unsigned long tpmem_base);
22762306a36Sopenharmony_civoid ipu_ic_exit(struct ipu_soc *ipu);
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ciint ipu_vdi_init(struct ipu_soc *ipu, struct device *dev,
23062306a36Sopenharmony_ci		 unsigned long base, u32 module);
23162306a36Sopenharmony_civoid ipu_vdi_exit(struct ipu_soc *ipu);
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ciint ipu_image_convert_init(struct ipu_soc *ipu, struct device *dev);
23462306a36Sopenharmony_civoid ipu_image_convert_exit(struct ipu_soc *ipu);
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ciint ipu_di_init(struct ipu_soc *ipu, struct device *dev, int id,
23762306a36Sopenharmony_ci		unsigned long base, u32 module, struct clk *ipu_clk);
23862306a36Sopenharmony_civoid ipu_di_exit(struct ipu_soc *ipu, int id);
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ciint ipu_dmfc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base,
24162306a36Sopenharmony_ci		struct clk *ipu_clk);
24262306a36Sopenharmony_civoid ipu_dmfc_exit(struct ipu_soc *ipu);
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ciint ipu_dp_init(struct ipu_soc *ipu, struct device *dev, unsigned long base);
24562306a36Sopenharmony_civoid ipu_dp_exit(struct ipu_soc *ipu);
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_ciint ipu_dc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base,
24862306a36Sopenharmony_ci		unsigned long template_base);
24962306a36Sopenharmony_civoid ipu_dc_exit(struct ipu_soc *ipu);
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ciint ipu_cpmem_init(struct ipu_soc *ipu, struct device *dev, unsigned long base);
25262306a36Sopenharmony_civoid ipu_cpmem_exit(struct ipu_soc *ipu);
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ciint ipu_smfc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base);
25562306a36Sopenharmony_civoid ipu_smfc_exit(struct ipu_soc *ipu);
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_cistruct ipu_pre *ipu_pre_lookup_by_phandle(struct device *dev, const char *name,
25862306a36Sopenharmony_ci					  int index);
25962306a36Sopenharmony_ciint ipu_pre_get_available_count(void);
26062306a36Sopenharmony_ciint ipu_pre_get(struct ipu_pre *pre);
26162306a36Sopenharmony_civoid ipu_pre_put(struct ipu_pre *pre);
26262306a36Sopenharmony_ciu32 ipu_pre_get_baddr(struct ipu_pre *pre);
26362306a36Sopenharmony_civoid ipu_pre_configure(struct ipu_pre *pre, unsigned int width,
26462306a36Sopenharmony_ci		       unsigned int height, unsigned int stride, u32 format,
26562306a36Sopenharmony_ci		       uint64_t modifier, unsigned int bufaddr);
26662306a36Sopenharmony_civoid ipu_pre_update(struct ipu_pre *pre, unsigned int bufaddr);
26762306a36Sopenharmony_cibool ipu_pre_update_pending(struct ipu_pre *pre);
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_cistruct ipu_prg *ipu_prg_lookup_by_phandle(struct device *dev, const char *name,
27062306a36Sopenharmony_ci					  int ipu_id);
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_ciextern struct platform_driver ipu_pre_drv;
27362306a36Sopenharmony_ciextern struct platform_driver ipu_prg_drv;
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci#endif				/* __IPU_PRV_H__ */
276