ipu.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * Porting to u-boot:
  3. *
  4. * (C) Copyright 2010
  5. * Stefano Babic, DENX Software Engineering, sbabic@denx.de
  6. *
  7. * Linux IPU driver for MX51:
  8. *
  9. * (C) Copyright 2005-2010 Freescale Semiconductor, Inc.
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #ifndef __ASM_ARCH_IPU_H__
  30. #define __ASM_ARCH_IPU_H__
  31. #include <linux/types.h>
  32. #include <ipu_pixfmt.h>
  33. #define IDMA_CHAN_INVALID 0xFF
  34. #define HIGH_RESOLUTION_WIDTH 1024
  35. struct clk {
  36. const char *name;
  37. int id;
  38. /* Source clock this clk depends on */
  39. struct clk *parent;
  40. /* Secondary clock to enable/disable with this clock */
  41. struct clk *secondary;
  42. /* Current clock rate */
  43. unsigned long rate;
  44. /* Reference count of clock enable/disable */
  45. __s8 usecount;
  46. /* Register bit position for clock's enable/disable control. */
  47. u8 enable_shift;
  48. /* Register address for clock's enable/disable control. */
  49. void *enable_reg;
  50. u32 flags;
  51. /*
  52. * Function ptr to recalculate the clock's rate based on parent
  53. * clock's rate
  54. */
  55. void (*recalc) (struct clk *);
  56. /*
  57. * Function ptr to set the clock to a new rate. The rate must match a
  58. * supported rate returned from round_rate. Leave blank if clock is not
  59. * programmable
  60. */
  61. int (*set_rate) (struct clk *, unsigned long);
  62. /*
  63. * Function ptr to round the requested clock rate to the nearest
  64. * supported rate that is less than or equal to the requested rate.
  65. */
  66. unsigned long (*round_rate) (struct clk *, unsigned long);
  67. /*
  68. * Function ptr to enable the clock. Leave blank if clock can not
  69. * be gated.
  70. */
  71. int (*enable) (struct clk *);
  72. /*
  73. * Function ptr to disable the clock. Leave blank if clock can not
  74. * be gated.
  75. */
  76. void (*disable) (struct clk *);
  77. /* Function ptr to set the parent clock of the clock. */
  78. int (*set_parent) (struct clk *, struct clk *);
  79. };
  80. /*
  81. * Enumeration of Synchronous (Memory-less) panel types
  82. */
  83. typedef enum {
  84. IPU_PANEL_SHARP_TFT,
  85. IPU_PANEL_TFT,
  86. } ipu_panel_t;
  87. /*
  88. * IPU Driver channels definitions.
  89. * Note these are different from IDMA channels
  90. */
  91. #define IPU_MAX_CH 32
  92. #define _MAKE_CHAN(num, v_in, g_in, a_in, out) \
  93. ((num << 24) | (v_in << 18) | (g_in << 12) | (a_in << 6) | out)
  94. #define _MAKE_ALT_CHAN(ch) (ch | (IPU_MAX_CH << 24))
  95. #define IPU_CHAN_ID(ch) (ch >> 24)
  96. #define IPU_CHAN_ALT(ch) (ch & 0x02000000)
  97. #define IPU_CHAN_ALPHA_IN_DMA(ch) ((uint32_t) (ch >> 6) & 0x3F)
  98. #define IPU_CHAN_GRAPH_IN_DMA(ch) ((uint32_t) (ch >> 12) & 0x3F)
  99. #define IPU_CHAN_VIDEO_IN_DMA(ch) ((uint32_t) (ch >> 18) & 0x3F)
  100. #define IPU_CHAN_OUT_DMA(ch) ((uint32_t) (ch & 0x3F))
  101. #define NO_DMA 0x3F
  102. #define ALT 1
  103. /*
  104. * Enumeration of IPU logical channels. An IPU logical channel is defined as a
  105. * combination of an input (memory to IPU), output (IPU to memory), and/or
  106. * secondary input IDMA channels and in some cases an Image Converter task.
  107. * Some channels consist of only an input or output.
  108. */
  109. typedef enum {
  110. CHAN_NONE = -1,
  111. MEM_DC_SYNC = _MAKE_CHAN(7, 28, NO_DMA, NO_DMA, NO_DMA),
  112. MEM_DC_ASYNC = _MAKE_CHAN(8, 41, NO_DMA, NO_DMA, NO_DMA),
  113. MEM_BG_SYNC = _MAKE_CHAN(9, 23, NO_DMA, 51, NO_DMA),
  114. MEM_FG_SYNC = _MAKE_CHAN(10, 27, NO_DMA, 31, NO_DMA),
  115. MEM_BG_ASYNC0 = _MAKE_CHAN(11, 24, NO_DMA, 52, NO_DMA),
  116. MEM_FG_ASYNC0 = _MAKE_CHAN(12, 29, NO_DMA, 33, NO_DMA),
  117. MEM_BG_ASYNC1 = _MAKE_ALT_CHAN(MEM_BG_ASYNC0),
  118. MEM_FG_ASYNC1 = _MAKE_ALT_CHAN(MEM_FG_ASYNC0),
  119. DIRECT_ASYNC0 = _MAKE_CHAN(13, NO_DMA, NO_DMA, NO_DMA, NO_DMA),
  120. DIRECT_ASYNC1 = _MAKE_CHAN(14, NO_DMA, NO_DMA, NO_DMA, NO_DMA),
  121. } ipu_channel_t;
  122. /*
  123. * Enumeration of types of buffers for a logical channel.
  124. */
  125. typedef enum {
  126. IPU_OUTPUT_BUFFER = 0, /*< Buffer for output from IPU */
  127. IPU_ALPHA_IN_BUFFER = 1, /*< Buffer for input to IPU */
  128. IPU_GRAPH_IN_BUFFER = 2, /*< Buffer for input to IPU */
  129. IPU_VIDEO_IN_BUFFER = 3, /*< Buffer for input to IPU */
  130. IPU_INPUT_BUFFER = IPU_VIDEO_IN_BUFFER,
  131. IPU_SEC_INPUT_BUFFER = IPU_GRAPH_IN_BUFFER,
  132. } ipu_buffer_t;
  133. #define IPU_PANEL_SERIAL 1
  134. #define IPU_PANEL_PARALLEL 2
  135. struct ipu_channel {
  136. u8 video_in_dma;
  137. u8 alpha_in_dma;
  138. u8 graph_in_dma;
  139. u8 out_dma;
  140. };
  141. enum ipu_dmfc_type {
  142. DMFC_NORMAL = 0,
  143. DMFC_HIGH_RESOLUTION_DC,
  144. DMFC_HIGH_RESOLUTION_DP,
  145. DMFC_HIGH_RESOLUTION_ONLY_DP,
  146. };
  147. /*
  148. * Union of initialization parameters for a logical channel.
  149. */
  150. typedef union {
  151. struct {
  152. uint32_t di;
  153. unsigned char interlaced;
  154. } mem_dc_sync;
  155. struct {
  156. uint32_t temp;
  157. } mem_sdc_fg;
  158. struct {
  159. uint32_t di;
  160. unsigned char interlaced;
  161. uint32_t in_pixel_fmt;
  162. uint32_t out_pixel_fmt;
  163. unsigned char alpha_chan_en;
  164. } mem_dp_bg_sync;
  165. struct {
  166. uint32_t temp;
  167. } mem_sdc_bg;
  168. struct {
  169. uint32_t di;
  170. unsigned char interlaced;
  171. uint32_t in_pixel_fmt;
  172. uint32_t out_pixel_fmt;
  173. unsigned char alpha_chan_en;
  174. } mem_dp_fg_sync;
  175. } ipu_channel_params_t;
  176. /*
  177. * Bitfield of Display Interface signal polarities.
  178. */
  179. typedef struct {
  180. unsigned datamask_en:1;
  181. unsigned ext_clk:1;
  182. unsigned interlaced:1;
  183. unsigned odd_field_first:1;
  184. unsigned clksel_en:1;
  185. unsigned clkidle_en:1;
  186. unsigned data_pol:1; /* true = inverted */
  187. unsigned clk_pol:1; /* true = rising edge */
  188. unsigned enable_pol:1;
  189. unsigned Hsync_pol:1; /* true = active high */
  190. unsigned Vsync_pol:1;
  191. } ipu_di_signal_cfg_t;
  192. typedef enum {
  193. RGB,
  194. YCbCr,
  195. YUV
  196. } ipu_color_space_t;
  197. /* Common IPU API */
  198. int32_t ipu_init_channel(ipu_channel_t channel, ipu_channel_params_t *params);
  199. void ipu_uninit_channel(ipu_channel_t channel);
  200. int32_t ipu_init_channel_buffer(ipu_channel_t channel, ipu_buffer_t type,
  201. uint32_t pixel_fmt,
  202. uint16_t width, uint16_t height,
  203. uint32_t stride,
  204. dma_addr_t phyaddr_0, dma_addr_t phyaddr_1,
  205. uint32_t u_offset, uint32_t v_offset);
  206. int32_t ipu_update_channel_buffer(ipu_channel_t channel, ipu_buffer_t type,
  207. uint32_t bufNum, dma_addr_t phyaddr);
  208. int32_t ipu_is_channel_busy(ipu_channel_t channel);
  209. void ipu_clear_buffer_ready(ipu_channel_t channel, ipu_buffer_t type,
  210. uint32_t bufNum);
  211. int32_t ipu_enable_channel(ipu_channel_t channel);
  212. int32_t ipu_disable_channel(ipu_channel_t channel);
  213. int32_t ipu_init_sync_panel(int disp,
  214. uint32_t pixel_clk,
  215. uint16_t width, uint16_t height,
  216. uint32_t pixel_fmt,
  217. uint16_t h_start_width, uint16_t h_sync_width,
  218. uint16_t h_end_width, uint16_t v_start_width,
  219. uint16_t v_sync_width, uint16_t v_end_width,
  220. uint32_t v_to_h_sync, ipu_di_signal_cfg_t sig);
  221. int32_t ipu_disp_set_global_alpha(ipu_channel_t channel, unsigned char enable,
  222. uint8_t alpha);
  223. int32_t ipu_disp_set_color_key(ipu_channel_t channel, unsigned char enable,
  224. uint32_t colorKey);
  225. uint32_t bytes_per_pixel(uint32_t fmt);
  226. void clk_enable(struct clk *clk);
  227. void clk_disable(struct clk *clk);
  228. u32 clk_get_rate(struct clk *clk);
  229. int clk_set_rate(struct clk *clk, unsigned long rate);
  230. long clk_round_rate(struct clk *clk, unsigned long rate);
  231. int clk_set_parent(struct clk *clk, struct clk *parent);
  232. int clk_get_usecount(struct clk *clk);
  233. struct clk *clk_get_parent(struct clk *clk);
  234. void ipu_dump_registers(void);
  235. int ipu_probe(void);
  236. void ipu_dmfc_init(int dmfc_type, int first);
  237. void ipu_init_dc_mappings(void);
  238. void ipu_dmfc_set_wait4eot(int dma_chan, int width);
  239. void ipu_dc_init(int dc_chan, int di, unsigned char interlaced);
  240. void ipu_dc_uninit(int dc_chan);
  241. void ipu_dp_dc_enable(ipu_channel_t channel);
  242. int ipu_dp_init(ipu_channel_t channel, uint32_t in_pixel_fmt,
  243. uint32_t out_pixel_fmt);
  244. void ipu_dp_uninit(ipu_channel_t channel);
  245. void ipu_dp_dc_disable(ipu_channel_t channel, unsigned char swap);
  246. ipu_color_space_t format_to_colorspace(uint32_t fmt);
  247. #endif