139b9004dSPhilipp Zabel /* 239b9004dSPhilipp Zabel * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de> 339b9004dSPhilipp Zabel * Copyright (C) 2005-2009 Freescale Semiconductor, Inc. 439b9004dSPhilipp Zabel * 539b9004dSPhilipp Zabel * This program is free software; you can redistribute it and/or modify it 639b9004dSPhilipp Zabel * under the terms of the GNU General Public License as published by the 739b9004dSPhilipp Zabel * Free Software Foundation; either version 2 of the License, or (at your 839b9004dSPhilipp Zabel * option) any later version. 939b9004dSPhilipp Zabel * 1039b9004dSPhilipp Zabel * This program is distributed in the hope that it will be useful, but 1139b9004dSPhilipp Zabel * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 1239b9004dSPhilipp Zabel * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1339b9004dSPhilipp Zabel * for more details. 1439b9004dSPhilipp Zabel */ 1539b9004dSPhilipp Zabel #ifndef __IPU_PRV_H__ 1639b9004dSPhilipp Zabel #define __IPU_PRV_H__ 1739b9004dSPhilipp Zabel 1839b9004dSPhilipp Zabel struct ipu_soc; 1939b9004dSPhilipp Zabel 2039b9004dSPhilipp Zabel #include <linux/types.h> 2139b9004dSPhilipp Zabel #include <linux/device.h> 2239b9004dSPhilipp Zabel #include <linux/clk.h> 2339b9004dSPhilipp Zabel #include <linux/platform_device.h> 2439b9004dSPhilipp Zabel 2539b9004dSPhilipp Zabel #include <video/imx-ipu-v3.h> 2639b9004dSPhilipp Zabel 2739b9004dSPhilipp Zabel #define IPU_MCU_T_DEFAULT 8 2839b9004dSPhilipp Zabel #define IPU_CM_IDMAC_REG_OFS 0x00008000 2939b9004dSPhilipp Zabel #define IPU_CM_IC_REG_OFS 0x00020000 3039b9004dSPhilipp Zabel #define IPU_CM_IRT_REG_OFS 0x00028000 3139b9004dSPhilipp Zabel #define IPU_CM_CSI0_REG_OFS 0x00030000 3239b9004dSPhilipp Zabel #define IPU_CM_CSI1_REG_OFS 0x00038000 3339b9004dSPhilipp Zabel #define IPU_CM_SMFC_REG_OFS 0x00050000 3439b9004dSPhilipp Zabel #define IPU_CM_DC_REG_OFS 0x00058000 3539b9004dSPhilipp Zabel #define IPU_CM_DMFC_REG_OFS 0x00060000 3639b9004dSPhilipp Zabel 3739b9004dSPhilipp Zabel /* Register addresses */ 3839b9004dSPhilipp Zabel /* IPU Common registers */ 3939b9004dSPhilipp Zabel #define IPU_CM_REG(offset) (offset) 4039b9004dSPhilipp Zabel 4139b9004dSPhilipp Zabel #define IPU_CONF IPU_CM_REG(0) 4239b9004dSPhilipp Zabel 4339b9004dSPhilipp Zabel #define IPU_SRM_PRI1 IPU_CM_REG(0x00a0) 4439b9004dSPhilipp Zabel #define IPU_SRM_PRI2 IPU_CM_REG(0x00a4) 4539b9004dSPhilipp Zabel #define IPU_FS_PROC_FLOW1 IPU_CM_REG(0x00a8) 4639b9004dSPhilipp Zabel #define IPU_FS_PROC_FLOW2 IPU_CM_REG(0x00ac) 4739b9004dSPhilipp Zabel #define IPU_FS_PROC_FLOW3 IPU_CM_REG(0x00b0) 4839b9004dSPhilipp Zabel #define IPU_FS_DISP_FLOW1 IPU_CM_REG(0x00b4) 4939b9004dSPhilipp Zabel #define IPU_FS_DISP_FLOW2 IPU_CM_REG(0x00b8) 5039b9004dSPhilipp Zabel #define IPU_SKIP IPU_CM_REG(0x00bc) 5139b9004dSPhilipp Zabel #define IPU_DISP_ALT_CONF IPU_CM_REG(0x00c0) 5239b9004dSPhilipp Zabel #define IPU_DISP_GEN IPU_CM_REG(0x00c4) 5339b9004dSPhilipp Zabel #define IPU_DISP_ALT1 IPU_CM_REG(0x00c8) 5439b9004dSPhilipp Zabel #define IPU_DISP_ALT2 IPU_CM_REG(0x00cc) 5539b9004dSPhilipp Zabel #define IPU_DISP_ALT3 IPU_CM_REG(0x00d0) 5639b9004dSPhilipp Zabel #define IPU_DISP_ALT4 IPU_CM_REG(0x00d4) 5739b9004dSPhilipp Zabel #define IPU_SNOOP IPU_CM_REG(0x00d8) 5839b9004dSPhilipp Zabel #define IPU_MEM_RST IPU_CM_REG(0x00dc) 5939b9004dSPhilipp Zabel #define IPU_PM IPU_CM_REG(0x00e0) 6039b9004dSPhilipp Zabel #define IPU_GPR IPU_CM_REG(0x00e4) 6139b9004dSPhilipp Zabel #define IPU_CHA_DB_MODE_SEL(ch) IPU_CM_REG(0x0150 + 4 * ((ch) / 32)) 6239b9004dSPhilipp Zabel #define IPU_ALT_CHA_DB_MODE_SEL(ch) IPU_CM_REG(0x0168 + 4 * ((ch) / 32)) 6339b9004dSPhilipp Zabel #define IPU_CHA_CUR_BUF(ch) IPU_CM_REG(0x023C + 4 * ((ch) / 32)) 6439b9004dSPhilipp Zabel #define IPU_ALT_CUR_BUF0 IPU_CM_REG(0x0244) 6539b9004dSPhilipp Zabel #define IPU_ALT_CUR_BUF1 IPU_CM_REG(0x0248) 6639b9004dSPhilipp Zabel #define IPU_SRM_STAT IPU_CM_REG(0x024C) 6739b9004dSPhilipp Zabel #define IPU_PROC_TASK_STAT IPU_CM_REG(0x0250) 6839b9004dSPhilipp Zabel #define IPU_DISP_TASK_STAT IPU_CM_REG(0x0254) 6939b9004dSPhilipp Zabel #define IPU_CHA_BUF0_RDY(ch) IPU_CM_REG(0x0268 + 4 * ((ch) / 32)) 7039b9004dSPhilipp Zabel #define IPU_CHA_BUF1_RDY(ch) IPU_CM_REG(0x0270 + 4 * ((ch) / 32)) 71aa52f578SSteve Longerbeam #define IPU_CHA_BUF2_RDY(ch) IPU_CM_REG(0x0288 + 4 * ((ch) / 32)) 7239b9004dSPhilipp Zabel #define IPU_ALT_CHA_BUF0_RDY(ch) IPU_CM_REG(0x0278 + 4 * ((ch) / 32)) 7339b9004dSPhilipp Zabel #define IPU_ALT_CHA_BUF1_RDY(ch) IPU_CM_REG(0x0280 + 4 * ((ch) / 32)) 7439b9004dSPhilipp Zabel 7539b9004dSPhilipp Zabel #define IPU_INT_CTRL(n) IPU_CM_REG(0x003C + 4 * (n)) 7639b9004dSPhilipp Zabel #define IPU_INT_STAT(n) IPU_CM_REG(0x0200 + 4 * (n)) 7739b9004dSPhilipp Zabel 7839b9004dSPhilipp Zabel #define IPU_DI0_COUNTER_RELEASE (1 << 24) 7939b9004dSPhilipp Zabel #define IPU_DI1_COUNTER_RELEASE (1 << 25) 8039b9004dSPhilipp Zabel 8139b9004dSPhilipp Zabel #define IPU_IDMAC_REG(offset) (offset) 8239b9004dSPhilipp Zabel 8339b9004dSPhilipp Zabel #define IDMAC_CONF IPU_IDMAC_REG(0x0000) 8439b9004dSPhilipp Zabel #define IDMAC_CHA_EN(ch) IPU_IDMAC_REG(0x0004 + 4 * ((ch) / 32)) 8539b9004dSPhilipp Zabel #define IDMAC_SEP_ALPHA IPU_IDMAC_REG(0x000c) 8639b9004dSPhilipp Zabel #define IDMAC_ALT_SEP_ALPHA IPU_IDMAC_REG(0x0010) 8739b9004dSPhilipp Zabel #define IDMAC_CHA_PRI(ch) IPU_IDMAC_REG(0x0014 + 4 * ((ch) / 32)) 8839b9004dSPhilipp Zabel #define IDMAC_WM_EN(ch) IPU_IDMAC_REG(0x001c + 4 * ((ch) / 32)) 8939b9004dSPhilipp Zabel #define IDMAC_CH_LOCK_EN_1 IPU_IDMAC_REG(0x0024) 9039b9004dSPhilipp Zabel #define IDMAC_CH_LOCK_EN_2 IPU_IDMAC_REG(0x0028) 9139b9004dSPhilipp Zabel #define IDMAC_SUB_ADDR_0 IPU_IDMAC_REG(0x002c) 9239b9004dSPhilipp Zabel #define IDMAC_SUB_ADDR_1 IPU_IDMAC_REG(0x0030) 9339b9004dSPhilipp Zabel #define IDMAC_SUB_ADDR_2 IPU_IDMAC_REG(0x0034) 9439b9004dSPhilipp Zabel #define IDMAC_BAND_EN(ch) IPU_IDMAC_REG(0x0040 + 4 * ((ch) / 32)) 9539b9004dSPhilipp Zabel #define IDMAC_CHA_BUSY(ch) IPU_IDMAC_REG(0x0100 + 4 * ((ch) / 32)) 9639b9004dSPhilipp Zabel 9739b9004dSPhilipp Zabel #define IPU_NUM_IRQS (32 * 15) 9839b9004dSPhilipp Zabel 9939b9004dSPhilipp Zabel enum ipu_modules { 10039b9004dSPhilipp Zabel IPU_CONF_CSI0_EN = (1 << 0), 10139b9004dSPhilipp Zabel IPU_CONF_CSI1_EN = (1 << 1), 10239b9004dSPhilipp Zabel IPU_CONF_IC_EN = (1 << 2), 10339b9004dSPhilipp Zabel IPU_CONF_ROT_EN = (1 << 3), 10439b9004dSPhilipp Zabel IPU_CONF_ISP_EN = (1 << 4), 10539b9004dSPhilipp Zabel IPU_CONF_DP_EN = (1 << 5), 10639b9004dSPhilipp Zabel IPU_CONF_DI0_EN = (1 << 6), 10739b9004dSPhilipp Zabel IPU_CONF_DI1_EN = (1 << 7), 10839b9004dSPhilipp Zabel IPU_CONF_SMFC_EN = (1 << 8), 10939b9004dSPhilipp Zabel IPU_CONF_DC_EN = (1 << 9), 11039b9004dSPhilipp Zabel IPU_CONF_DMFC_EN = (1 << 10), 11139b9004dSPhilipp Zabel 11239b9004dSPhilipp Zabel IPU_CONF_VDI_EN = (1 << 12), 11339b9004dSPhilipp Zabel 11439b9004dSPhilipp Zabel IPU_CONF_IDMAC_DIS = (1 << 22), 11539b9004dSPhilipp Zabel 11639b9004dSPhilipp Zabel IPU_CONF_IC_DMFC_SEL = (1 << 25), 11739b9004dSPhilipp Zabel IPU_CONF_IC_DMFC_SYNC = (1 << 26), 11839b9004dSPhilipp Zabel IPU_CONF_VDI_DMFC_SYNC = (1 << 27), 11939b9004dSPhilipp Zabel 12039b9004dSPhilipp Zabel IPU_CONF_CSI0_DATA_SOURCE = (1 << 28), 12139b9004dSPhilipp Zabel IPU_CONF_CSI1_DATA_SOURCE = (1 << 29), 12239b9004dSPhilipp Zabel IPU_CONF_IC_INPUT = (1 << 30), 12339b9004dSPhilipp Zabel IPU_CONF_CSI_SEL = (1 << 31), 12439b9004dSPhilipp Zabel }; 12539b9004dSPhilipp Zabel 12639b9004dSPhilipp Zabel struct ipuv3_channel { 12739b9004dSPhilipp Zabel unsigned int num; 12839b9004dSPhilipp Zabel 12939b9004dSPhilipp Zabel bool enabled; 13039b9004dSPhilipp Zabel bool busy; 13139b9004dSPhilipp Zabel 13239b9004dSPhilipp Zabel struct ipu_soc *ipu; 13339b9004dSPhilipp Zabel }; 13439b9004dSPhilipp Zabel 1357d2691daSSteve Longerbeam struct ipu_cpmem; 1362ffd48f2SSteve Longerbeam struct ipu_csi; 13739b9004dSPhilipp Zabel struct ipu_dc_priv; 13839b9004dSPhilipp Zabel struct ipu_dmfc_priv; 13939b9004dSPhilipp Zabel struct ipu_di; 1401aa8ea0dSSteve Longerbeam struct ipu_ic_priv; 141*2d2ead45SSteve Longerbeam struct ipu_vdi; 14235de925fSPhilipp Zabel struct ipu_smfc_priv; 14335de925fSPhilipp Zabel 14439b9004dSPhilipp Zabel struct ipu_devtype; 14539b9004dSPhilipp Zabel 14639b9004dSPhilipp Zabel struct ipu_soc { 14739b9004dSPhilipp Zabel struct device *dev; 14839b9004dSPhilipp Zabel const struct ipu_devtype *devtype; 14939b9004dSPhilipp Zabel enum ipuv3_type ipu_type; 15039b9004dSPhilipp Zabel spinlock_t lock; 15139b9004dSPhilipp Zabel struct mutex channel_lock; 15239b9004dSPhilipp Zabel 15339b9004dSPhilipp Zabel void __iomem *cm_reg; 15439b9004dSPhilipp Zabel void __iomem *idmac_reg; 15539b9004dSPhilipp Zabel 156572a7615SSteve Longerbeam int id; 15739b9004dSPhilipp Zabel int usecount; 15839b9004dSPhilipp Zabel 15939b9004dSPhilipp Zabel struct clk *clk; 16039b9004dSPhilipp Zabel 16139b9004dSPhilipp Zabel struct ipuv3_channel channel[64]; 16239b9004dSPhilipp Zabel 16339b9004dSPhilipp Zabel int irq_sync; 16439b9004dSPhilipp Zabel int irq_err; 16539b9004dSPhilipp Zabel struct irq_domain *domain; 16639b9004dSPhilipp Zabel 1677d2691daSSteve Longerbeam struct ipu_cpmem *cpmem_priv; 16839b9004dSPhilipp Zabel struct ipu_dc_priv *dc_priv; 16939b9004dSPhilipp Zabel struct ipu_dp_priv *dp_priv; 17039b9004dSPhilipp Zabel struct ipu_dmfc_priv *dmfc_priv; 17139b9004dSPhilipp Zabel struct ipu_di *di_priv[2]; 1722ffd48f2SSteve Longerbeam struct ipu_csi *csi_priv[2]; 1731aa8ea0dSSteve Longerbeam struct ipu_ic_priv *ic_priv; 174*2d2ead45SSteve Longerbeam struct ipu_vdi *vdi_priv; 17535de925fSPhilipp Zabel struct ipu_smfc_priv *smfc_priv; 17639b9004dSPhilipp Zabel }; 17739b9004dSPhilipp Zabel 1787d2691daSSteve Longerbeam static inline u32 ipu_idmac_read(struct ipu_soc *ipu, unsigned offset) 1797d2691daSSteve Longerbeam { 1807d2691daSSteve Longerbeam return readl(ipu->idmac_reg + offset); 1817d2691daSSteve Longerbeam } 1827d2691daSSteve Longerbeam 1837d2691daSSteve Longerbeam static inline void ipu_idmac_write(struct ipu_soc *ipu, u32 value, 1847d2691daSSteve Longerbeam unsigned offset) 1857d2691daSSteve Longerbeam { 1867d2691daSSteve Longerbeam writel(value, ipu->idmac_reg + offset); 1877d2691daSSteve Longerbeam } 1887d2691daSSteve Longerbeam 18939b9004dSPhilipp Zabel void ipu_srm_dp_sync_update(struct ipu_soc *ipu); 19039b9004dSPhilipp Zabel 19139b9004dSPhilipp Zabel int ipu_module_enable(struct ipu_soc *ipu, u32 mask); 19239b9004dSPhilipp Zabel int ipu_module_disable(struct ipu_soc *ipu, u32 mask); 19339b9004dSPhilipp Zabel 194682b7c1cSLinus Torvalds bool ipu_idmac_channel_busy(struct ipu_soc *ipu, unsigned int chno); 195682b7c1cSLinus Torvalds int ipu_wait_interrupt(struct ipu_soc *ipu, int irq, int ms); 196682b7c1cSLinus Torvalds 1972ffd48f2SSteve Longerbeam int ipu_csi_init(struct ipu_soc *ipu, struct device *dev, int id, 1982ffd48f2SSteve Longerbeam unsigned long base, u32 module, struct clk *clk_ipu); 1992ffd48f2SSteve Longerbeam void ipu_csi_exit(struct ipu_soc *ipu, int id); 2002ffd48f2SSteve Longerbeam 2011aa8ea0dSSteve Longerbeam int ipu_ic_init(struct ipu_soc *ipu, struct device *dev, 2021aa8ea0dSSteve Longerbeam unsigned long base, unsigned long tpmem_base); 2031aa8ea0dSSteve Longerbeam void ipu_ic_exit(struct ipu_soc *ipu); 2041aa8ea0dSSteve Longerbeam 205*2d2ead45SSteve Longerbeam int ipu_vdi_init(struct ipu_soc *ipu, struct device *dev, 206*2d2ead45SSteve Longerbeam unsigned long base, u32 module); 207*2d2ead45SSteve Longerbeam void ipu_vdi_exit(struct ipu_soc *ipu); 208*2d2ead45SSteve Longerbeam 20939b9004dSPhilipp Zabel int ipu_di_init(struct ipu_soc *ipu, struct device *dev, int id, 21039b9004dSPhilipp Zabel unsigned long base, u32 module, struct clk *ipu_clk); 21139b9004dSPhilipp Zabel void ipu_di_exit(struct ipu_soc *ipu, int id); 21239b9004dSPhilipp Zabel 21339b9004dSPhilipp Zabel int ipu_dmfc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base, 21439b9004dSPhilipp Zabel struct clk *ipu_clk); 21539b9004dSPhilipp Zabel void ipu_dmfc_exit(struct ipu_soc *ipu); 21639b9004dSPhilipp Zabel 21739b9004dSPhilipp Zabel int ipu_dp_init(struct ipu_soc *ipu, struct device *dev, unsigned long base); 21839b9004dSPhilipp Zabel void ipu_dp_exit(struct ipu_soc *ipu); 21939b9004dSPhilipp Zabel 22039b9004dSPhilipp Zabel int ipu_dc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base, 22139b9004dSPhilipp Zabel unsigned long template_base); 22239b9004dSPhilipp Zabel void ipu_dc_exit(struct ipu_soc *ipu); 22339b9004dSPhilipp Zabel 22439b9004dSPhilipp Zabel int ipu_cpmem_init(struct ipu_soc *ipu, struct device *dev, unsigned long base); 22539b9004dSPhilipp Zabel void ipu_cpmem_exit(struct ipu_soc *ipu); 22639b9004dSPhilipp Zabel 22735de925fSPhilipp Zabel int ipu_smfc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base); 22835de925fSPhilipp Zabel void ipu_smfc_exit(struct ipu_soc *ipu); 22935de925fSPhilipp Zabel 23039b9004dSPhilipp Zabel #endif /* __IPU_PRV_H__ */ 231