ipu-prv.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  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. struct ipu_soc;
  18. #include <linux/types.h>
  19. #include <linux/device.h>
  20. #include <linux/clk.h>
  21. #include <linux/platform_device.h>
  22. #include <video/imx-ipu-v3.h>
  23. #define IPU_MCU_T_DEFAULT 8
  24. #define IPU_CM_IDMAC_REG_OFS 0x00008000
  25. #define IPU_CM_IC_REG_OFS 0x00020000
  26. #define IPU_CM_IRT_REG_OFS 0x00028000
  27. #define IPU_CM_CSI0_REG_OFS 0x00030000
  28. #define IPU_CM_CSI1_REG_OFS 0x00038000
  29. #define IPU_CM_SMFC_REG_OFS 0x00050000
  30. #define IPU_CM_DC_REG_OFS 0x00058000
  31. #define IPU_CM_DMFC_REG_OFS 0x00060000
  32. /* Register addresses */
  33. /* IPU Common registers */
  34. #define IPU_CM_REG(offset) (offset)
  35. #define IPU_CONF IPU_CM_REG(0)
  36. #define IPU_SRM_PRI1 IPU_CM_REG(0x00a0)
  37. #define IPU_SRM_PRI2 IPU_CM_REG(0x00a4)
  38. #define IPU_FS_PROC_FLOW1 IPU_CM_REG(0x00a8)
  39. #define IPU_FS_PROC_FLOW2 IPU_CM_REG(0x00ac)
  40. #define IPU_FS_PROC_FLOW3 IPU_CM_REG(0x00b0)
  41. #define IPU_FS_DISP_FLOW1 IPU_CM_REG(0x00b4)
  42. #define IPU_FS_DISP_FLOW2 IPU_CM_REG(0x00b8)
  43. #define IPU_SKIP IPU_CM_REG(0x00bc)
  44. #define IPU_DISP_ALT_CONF IPU_CM_REG(0x00c0)
  45. #define IPU_DISP_GEN IPU_CM_REG(0x00c4)
  46. #define IPU_DISP_ALT1 IPU_CM_REG(0x00c8)
  47. #define IPU_DISP_ALT2 IPU_CM_REG(0x00cc)
  48. #define IPU_DISP_ALT3 IPU_CM_REG(0x00d0)
  49. #define IPU_DISP_ALT4 IPU_CM_REG(0x00d4)
  50. #define IPU_SNOOP IPU_CM_REG(0x00d8)
  51. #define IPU_MEM_RST IPU_CM_REG(0x00dc)
  52. #define IPU_PM IPU_CM_REG(0x00e0)
  53. #define IPU_GPR IPU_CM_REG(0x00e4)
  54. #define IPU_CHA_DB_MODE_SEL(ch) IPU_CM_REG(0x0150 + 4 * ((ch) / 32))
  55. #define IPU_ALT_CHA_DB_MODE_SEL(ch) IPU_CM_REG(0x0168 + 4 * ((ch) / 32))
  56. #define IPU_CHA_CUR_BUF(ch) IPU_CM_REG(0x023C + 4 * ((ch) / 32))
  57. #define IPU_ALT_CUR_BUF0 IPU_CM_REG(0x0244)
  58. #define IPU_ALT_CUR_BUF1 IPU_CM_REG(0x0248)
  59. #define IPU_SRM_STAT IPU_CM_REG(0x024C)
  60. #define IPU_PROC_TASK_STAT IPU_CM_REG(0x0250)
  61. #define IPU_DISP_TASK_STAT IPU_CM_REG(0x0254)
  62. #define IPU_CHA_BUF0_RDY(ch) IPU_CM_REG(0x0268 + 4 * ((ch) / 32))
  63. #define IPU_CHA_BUF1_RDY(ch) IPU_CM_REG(0x0270 + 4 * ((ch) / 32))
  64. #define IPU_CHA_BUF2_RDY(ch) IPU_CM_REG(0x0288 + 4 * ((ch) / 32))
  65. #define IPU_ALT_CHA_BUF0_RDY(ch) IPU_CM_REG(0x0278 + 4 * ((ch) / 32))
  66. #define IPU_ALT_CHA_BUF1_RDY(ch) IPU_CM_REG(0x0280 + 4 * ((ch) / 32))
  67. #define IPU_INT_CTRL(n) IPU_CM_REG(0x003C + 4 * (n))
  68. #define IPU_INT_STAT(n) IPU_CM_REG(0x0200 + 4 * (n))
  69. #define IPU_DI0_COUNTER_RELEASE (1 << 24)
  70. #define IPU_DI1_COUNTER_RELEASE (1 << 25)
  71. #define IPU_IDMAC_REG(offset) (offset)
  72. #define IDMAC_CONF IPU_IDMAC_REG(0x0000)
  73. #define IDMAC_CHA_EN(ch) IPU_IDMAC_REG(0x0004 + 4 * ((ch) / 32))
  74. #define IDMAC_SEP_ALPHA IPU_IDMAC_REG(0x000c)
  75. #define IDMAC_ALT_SEP_ALPHA IPU_IDMAC_REG(0x0010)
  76. #define IDMAC_CHA_PRI(ch) IPU_IDMAC_REG(0x0014 + 4 * ((ch) / 32))
  77. #define IDMAC_WM_EN(ch) IPU_IDMAC_REG(0x001c + 4 * ((ch) / 32))
  78. #define IDMAC_CH_LOCK_EN_1 IPU_IDMAC_REG(0x0024)
  79. #define IDMAC_CH_LOCK_EN_2 IPU_IDMAC_REG(0x0028)
  80. #define IDMAC_SUB_ADDR_0 IPU_IDMAC_REG(0x002c)
  81. #define IDMAC_SUB_ADDR_1 IPU_IDMAC_REG(0x0030)
  82. #define IDMAC_SUB_ADDR_2 IPU_IDMAC_REG(0x0034)
  83. #define IDMAC_BAND_EN(ch) IPU_IDMAC_REG(0x0040 + 4 * ((ch) / 32))
  84. #define IDMAC_CHA_BUSY(ch) IPU_IDMAC_REG(0x0100 + 4 * ((ch) / 32))
  85. #define IPU_NUM_IRQS (32 * 15)
  86. enum ipu_modules {
  87. IPU_CONF_CSI0_EN = (1 << 0),
  88. IPU_CONF_CSI1_EN = (1 << 1),
  89. IPU_CONF_IC_EN = (1 << 2),
  90. IPU_CONF_ROT_EN = (1 << 3),
  91. IPU_CONF_ISP_EN = (1 << 4),
  92. IPU_CONF_DP_EN = (1 << 5),
  93. IPU_CONF_DI0_EN = (1 << 6),
  94. IPU_CONF_DI1_EN = (1 << 7),
  95. IPU_CONF_SMFC_EN = (1 << 8),
  96. IPU_CONF_DC_EN = (1 << 9),
  97. IPU_CONF_DMFC_EN = (1 << 10),
  98. IPU_CONF_VDI_EN = (1 << 12),
  99. IPU_CONF_IDMAC_DIS = (1 << 22),
  100. IPU_CONF_IC_DMFC_SEL = (1 << 25),
  101. IPU_CONF_IC_DMFC_SYNC = (1 << 26),
  102. IPU_CONF_VDI_DMFC_SYNC = (1 << 27),
  103. IPU_CONF_CSI0_DATA_SOURCE = (1 << 28),
  104. IPU_CONF_CSI1_DATA_SOURCE = (1 << 29),
  105. IPU_CONF_IC_INPUT = (1 << 30),
  106. IPU_CONF_CSI_SEL = (1 << 31),
  107. };
  108. struct ipuv3_channel {
  109. unsigned int num;
  110. bool enabled;
  111. bool busy;
  112. struct ipu_soc *ipu;
  113. };
  114. struct ipu_cpmem;
  115. struct ipu_csi;
  116. struct ipu_dc_priv;
  117. struct ipu_dmfc_priv;
  118. struct ipu_di;
  119. struct ipu_ic_priv;
  120. struct ipu_smfc_priv;
  121. struct ipu_devtype;
  122. struct ipu_soc {
  123. struct device *dev;
  124. const struct ipu_devtype *devtype;
  125. enum ipuv3_type ipu_type;
  126. spinlock_t lock;
  127. struct mutex channel_lock;
  128. void __iomem *cm_reg;
  129. void __iomem *idmac_reg;
  130. int usecount;
  131. struct clk *clk;
  132. struct ipuv3_channel channel[64];
  133. int irq_sync;
  134. int irq_err;
  135. struct irq_domain *domain;
  136. struct ipu_cpmem *cpmem_priv;
  137. struct ipu_dc_priv *dc_priv;
  138. struct ipu_dp_priv *dp_priv;
  139. struct ipu_dmfc_priv *dmfc_priv;
  140. struct ipu_di *di_priv[2];
  141. struct ipu_csi *csi_priv[2];
  142. struct ipu_ic_priv *ic_priv;
  143. struct ipu_smfc_priv *smfc_priv;
  144. };
  145. static inline u32 ipu_idmac_read(struct ipu_soc *ipu, unsigned offset)
  146. {
  147. return readl(ipu->idmac_reg + offset);
  148. }
  149. static inline void ipu_idmac_write(struct ipu_soc *ipu, u32 value,
  150. unsigned offset)
  151. {
  152. writel(value, ipu->idmac_reg + offset);
  153. }
  154. void ipu_srm_dp_sync_update(struct ipu_soc *ipu);
  155. int ipu_module_enable(struct ipu_soc *ipu, u32 mask);
  156. int ipu_module_disable(struct ipu_soc *ipu, u32 mask);
  157. bool ipu_idmac_channel_busy(struct ipu_soc *ipu, unsigned int chno);
  158. int ipu_wait_interrupt(struct ipu_soc *ipu, int irq, int ms);
  159. int ipu_csi_init(struct ipu_soc *ipu, struct device *dev, int id,
  160. unsigned long base, u32 module, struct clk *clk_ipu);
  161. void ipu_csi_exit(struct ipu_soc *ipu, int id);
  162. int ipu_ic_init(struct ipu_soc *ipu, struct device *dev,
  163. unsigned long base, unsigned long tpmem_base);
  164. void ipu_ic_exit(struct ipu_soc *ipu);
  165. int ipu_di_init(struct ipu_soc *ipu, struct device *dev, int id,
  166. unsigned long base, u32 module, struct clk *ipu_clk);
  167. void ipu_di_exit(struct ipu_soc *ipu, int id);
  168. int ipu_dmfc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base,
  169. struct clk *ipu_clk);
  170. void ipu_dmfc_exit(struct ipu_soc *ipu);
  171. int ipu_dp_init(struct ipu_soc *ipu, struct device *dev, unsigned long base);
  172. void ipu_dp_exit(struct ipu_soc *ipu);
  173. int ipu_dc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base,
  174. unsigned long template_base);
  175. void ipu_dc_exit(struct ipu_soc *ipu);
  176. int ipu_cpmem_init(struct ipu_soc *ipu, struct device *dev, unsigned long base);
  177. void ipu_cpmem_exit(struct ipu_soc *ipu);
  178. int ipu_smfc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base);
  179. void ipu_smfc_exit(struct ipu_soc *ipu);
  180. #endif /* __IPU_PRV_H__ */