2 * Copyright 2005-2011 Freescale Semiconductor, Inc. All Rights Reserved.
6 * The code contained herein is licensed under the GNU General Public
7 * License. You may obtain a copy of the GNU General Public License
8 * Version 2 or later at the following locations:
10 * http://www.opensource.org/licenses/gpl-license.html
11 * http://www.gnu.org/copyleft/gpl.html
17 * @brief IPU display submodule API functions
22 #include <linux/types.h>
23 #include <linux/errno.h>
24 #include <linux/delay.h>
25 #include <linux/spinlock.h>
27 #include <linux/ipu.h>
28 #include <linux/clk.h>
29 #include <asm/atomic.h>
30 #include <mach/clock.h>
33 #include "ipu_param_mem.h"
35 struct dp_csc_param_t {
41 #define ASYNC_SER_WAVE 6
43 /* DC display ID assignments */
44 #define DC_DISP_ID_SYNC(di) (di)
45 #define DC_DISP_ID_SERIAL 2
46 #define DC_DISP_ID_ASYNC 3
50 void _ipu_dmfc_init(struct ipu_soc *ipu, int dmfc_type, int first)
52 u32 dmfc_wr_chan, dmfc_dp_chan;
55 if (dmfc_type_setup > dmfc_type)
56 dmfc_type = dmfc_type_setup;
58 dmfc_type_setup = dmfc_type;
60 /* disable DMFC-IC channel*/
61 ipu_dmfc_write(ipu, 0x2, DMFC_IC_CTRL);
62 } else if (dmfc_type_setup >= DMFC_HIGH_RESOLUTION_DC) {
63 dev_dbg(ipu->dev, "DMFC high resolution has set, will not change\n");
66 dmfc_type_setup = dmfc_type;
68 if (dmfc_type == DMFC_HIGH_RESOLUTION_DC) {
72 * 1C, 2C and 6B, 6F unused;
74 dev_info(ipu->dev, "IPU DMFC DC HIGH RESOLUTION: 1(0~3), 5B(4,5), 5F(6,7)\n");
75 dmfc_wr_chan = 0x00000088;
76 dmfc_dp_chan = 0x00009694;
77 ipu->dmfc_size_28 = 256*4;
78 ipu->dmfc_size_29 = 0;
79 ipu->dmfc_size_24 = 0;
80 ipu->dmfc_size_27 = 128*4;
81 ipu->dmfc_size_23 = 128*4;
82 } else if (dmfc_type == DMFC_HIGH_RESOLUTION_DP) {
86 * 1C, 2C and 6B, 6F unused;
88 dev_info(ipu->dev, "IPU DMFC DP HIGH RESOLUTION: 1(0,1), 5B(2~5), 5F(6,7)\n");
89 dmfc_wr_chan = 0x00000090;
90 dmfc_dp_chan = 0x0000968a;
91 ipu->dmfc_size_28 = 128*4;
92 ipu->dmfc_size_29 = 0;
93 ipu->dmfc_size_24 = 0;
94 ipu->dmfc_size_27 = 128*4;
95 ipu->dmfc_size_23 = 256*4;
96 } else if (dmfc_type == DMFC_HIGH_RESOLUTION_ONLY_DP) {
99 * 1, 1C, 2C and 6B, 6F unused;
101 dev_info(ipu->dev, "IPU DMFC ONLY-DP HIGH RESOLUTION: 5B(0~3), 5F(4~7)\n");
102 dmfc_wr_chan = 0x00000000;
103 dmfc_dp_chan = 0x00008c88;
104 ipu->dmfc_size_28 = 0;
105 ipu->dmfc_size_29 = 0;
106 ipu->dmfc_size_24 = 0;
107 ipu->dmfc_size_27 = 256*4;
108 ipu->dmfc_size_23 = 256*4;
111 * 5B - segement 4, 5;
112 * 5F - segement 6, 7;
113 * 1C, 2C and 6B, 6F unused;
115 dev_info(ipu->dev, "IPU DMFC NORMAL mode: 1(0~1), 5B(4,5), 5F(6,7)\n");
116 dmfc_wr_chan = 0x00000090;
117 dmfc_dp_chan = 0x00009694;
118 ipu->dmfc_size_28 = 128*4;
119 ipu->dmfc_size_29 = 0;
120 ipu->dmfc_size_24 = 0;
121 ipu->dmfc_size_27 = 128*4;
122 ipu->dmfc_size_23 = 128*4;
124 ipu_dmfc_write(ipu, dmfc_wr_chan, DMFC_WR_CHAN);
125 ipu_dmfc_write(ipu, 0x202020F6, DMFC_WR_CHAN_DEF);
126 ipu_dmfc_write(ipu, dmfc_dp_chan, DMFC_DP_CHAN);
127 /* Enable chan 5 watermark set at 5 bursts and clear at 7 bursts */
128 ipu_dmfc_write(ipu, 0x2020F6F6, DMFC_DP_CHAN_DEF);
131 static int __init dmfc_setup(char *options)
133 get_option(&options, &dmfc_type_setup);
134 if (dmfc_type_setup > DMFC_HIGH_RESOLUTION_ONLY_DP)
135 dmfc_type_setup = DMFC_HIGH_RESOLUTION_ONLY_DP;
138 __setup("dmfc=", dmfc_setup);
140 void _ipu_dmfc_set_wait4eot(struct ipu_soc *ipu, int dma_chan, int width)
142 u32 dmfc_gen1 = ipu_dmfc_read(ipu, DMFC_GENERAL1);
144 if (width >= HIGH_RESOLUTION_WIDTH) {
146 _ipu_dmfc_init(ipu, DMFC_HIGH_RESOLUTION_DP, 0);
147 else if (dma_chan == 28)
148 _ipu_dmfc_init(ipu, DMFC_HIGH_RESOLUTION_DC, 0);
151 if (dma_chan == 23) { /*5B*/
152 if (ipu->dmfc_size_23/width > 3)
153 dmfc_gen1 |= 1UL << 20;
155 dmfc_gen1 &= ~(1UL << 20);
156 } else if (dma_chan == 24) { /*6B*/
157 if (ipu->dmfc_size_24/width > 1)
158 dmfc_gen1 |= 1UL << 22;
160 dmfc_gen1 &= ~(1UL << 22);
161 } else if (dma_chan == 27) { /*5F*/
162 if (ipu->dmfc_size_27/width > 2)
163 dmfc_gen1 |= 1UL << 21;
165 dmfc_gen1 &= ~(1UL << 21);
166 } else if (dma_chan == 28) { /*1*/
167 if (ipu->dmfc_size_28/width > 2)
168 dmfc_gen1 |= 1UL << 16;
170 dmfc_gen1 &= ~(1UL << 16);
171 } else if (dma_chan == 29) { /*6F*/
172 if (ipu->dmfc_size_29/width > 1)
173 dmfc_gen1 |= 1UL << 23;
175 dmfc_gen1 &= ~(1UL << 23);
178 ipu_dmfc_write(ipu, dmfc_gen1, DMFC_GENERAL1);
181 void _ipu_dmfc_set_burst_size(struct ipu_soc *ipu, int dma_chan, int burst_size)
183 u32 dmfc_wr_chan = ipu_dmfc_read(ipu, DMFC_WR_CHAN);
184 u32 dmfc_dp_chan = ipu_dmfc_read(ipu, DMFC_DP_CHAN);
187 switch (burst_size) {
199 dev_err(ipu->dev, "Unsupported burst size %d\n",
204 if (dma_chan == 23) { /*5B*/
205 dmfc_dp_chan &= ~(0xc0);
206 dmfc_dp_chan |= dmfc_bs;
207 } else if (dma_chan == 27) { /*5F*/
208 dmfc_dp_chan &= ~(0xc000);
209 dmfc_dp_chan |= (dmfc_bs << 8);
210 } else if (dma_chan == 28) { /*1*/
211 dmfc_wr_chan &= ~(0xc0);
212 dmfc_wr_chan |= dmfc_bs;
215 ipu_dmfc_write(ipu, dmfc_wr_chan, DMFC_WR_CHAN);
216 ipu_dmfc_write(ipu, dmfc_dp_chan, DMFC_DP_CHAN);
219 static void _ipu_di_data_wave_config(struct ipu_soc *ipu,
220 int di, int wave_gen,
221 int access_size, int component_size)
224 reg = (access_size << DI_DW_GEN_ACCESS_SIZE_OFFSET) |
225 (component_size << DI_DW_GEN_COMPONENT_SIZE_OFFSET);
226 ipu_di_write(ipu, di, reg, DI_DW_GEN(wave_gen));
229 static void _ipu_di_data_pin_config(struct ipu_soc *ipu,
230 int di, int wave_gen, int di_pin, int set,
235 reg = ipu_di_read(ipu, di, DI_DW_GEN(wave_gen));
236 reg &= ~(0x3 << (di_pin * 2));
237 reg |= set << (di_pin * 2);
238 ipu_di_write(ipu, di, reg, DI_DW_GEN(wave_gen));
240 ipu_di_write(ipu, di, (down << 16) | up, DI_DW_SET(wave_gen, set));
243 static void _ipu_di_sync_config(struct ipu_soc *ipu,
244 int di, int wave_gen,
245 int run_count, int run_src,
246 int offset_count, int offset_src,
247 int repeat_count, int cnt_clr_src,
248 int cnt_polarity_gen_en,
249 int cnt_polarity_clr_src,
250 int cnt_polarity_trigger_src,
251 int cnt_up, int cnt_down)
255 if ((run_count >= 0x1000) || (offset_count >= 0x1000) || (repeat_count >= 0x1000) ||
256 (cnt_up >= 0x400) || (cnt_down >= 0x400)) {
257 dev_err(ipu->dev, "DI%d counters out of range.\n", di);
261 reg = (run_count << 19) | (++run_src << 16) |
262 (offset_count << 3) | ++offset_src;
263 ipu_di_write(ipu, di, reg, DI_SW_GEN0(wave_gen));
264 reg = (cnt_polarity_gen_en << 29) | (++cnt_clr_src << 25) |
265 (++cnt_polarity_trigger_src << 12) | (++cnt_polarity_clr_src << 9);
266 reg |= (cnt_down << 16) | cnt_up;
267 if (repeat_count == 0) {
268 /* Enable auto reload */
271 ipu_di_write(ipu, di, reg, DI_SW_GEN1(wave_gen));
272 reg = ipu_di_read(ipu, di, DI_STP_REP(wave_gen));
273 reg &= ~(0xFFFF << (16 * ((wave_gen - 1) & 0x1)));
274 reg |= repeat_count << (16 * ((wave_gen - 1) & 0x1));
275 ipu_di_write(ipu, di, reg, DI_STP_REP(wave_gen));
278 static void _ipu_dc_map_link(struct ipu_soc *ipu,
280 int base_map_0, int buf_num_0,
281 int base_map_1, int buf_num_1,
282 int base_map_2, int buf_num_2)
284 int ptr_0 = base_map_0 * 3 + buf_num_0;
285 int ptr_1 = base_map_1 * 3 + buf_num_1;
286 int ptr_2 = base_map_2 * 3 + buf_num_2;
289 ptr = (ptr_2 << 10) + (ptr_1 << 5) + ptr_0;
291 reg = ipu_dc_read(ipu, DC_MAP_CONF_PTR(current_map));
292 reg &= ~(0x1F << ((16 * (current_map & 0x1))));
293 reg |= ptr << ((16 * (current_map & 0x1)));
294 ipu_dc_write(ipu, reg, DC_MAP_CONF_PTR(current_map));
297 static void _ipu_dc_map_config(struct ipu_soc *ipu,
298 int map, int byte_num, int offset, int mask)
300 int ptr = map * 3 + byte_num;
303 reg = ipu_dc_read(ipu, DC_MAP_CONF_VAL(ptr));
304 reg &= ~(0xFFFF << (16 * (ptr & 0x1)));
305 reg |= ((offset << 8) | mask) << (16 * (ptr & 0x1));
306 ipu_dc_write(ipu, reg, DC_MAP_CONF_VAL(ptr));
308 reg = ipu_dc_read(ipu, DC_MAP_CONF_PTR(map));
309 reg &= ~(0x1F << ((16 * (map & 0x1)) + (5 * byte_num)));
310 reg |= ptr << ((16 * (map & 0x1)) + (5 * byte_num));
311 ipu_dc_write(ipu, reg, DC_MAP_CONF_PTR(map));
314 static void _ipu_dc_map_clear(struct ipu_soc *ipu, int map)
316 u32 reg = ipu_dc_read(ipu, DC_MAP_CONF_PTR(map));
317 ipu_dc_write(ipu, reg & ~(0xFFFF << (16 * (map & 0x1))),
318 DC_MAP_CONF_PTR(map));
321 static void _ipu_dc_write_tmpl(struct ipu_soc *ipu,
322 int word, u32 opcode, u32 operand, int map,
323 int wave, int glue, int sync, int stop)
330 reg |= (++wave << 11);
331 reg |= ((operand & 0x1FFFF) << 15);
332 ipu_dc_tmpl_write(ipu, reg, word * 2);
334 reg = (operand >> 17);
337 ipu_dc_tmpl_write(ipu, reg, word * 2 + 1);
341 reg |= (++wave << 11);
342 reg |= (++map << 15);
343 reg |= (operand << 20) & 0xFFF00000;
344 ipu_dc_tmpl_write(ipu, reg, word * 2);
346 reg = (operand >> 12);
349 ipu_dc_tmpl_write(ipu, reg, word * 2 + 1);
353 static void _ipu_dc_link_event(struct ipu_soc *ipu,
354 int chan, int event, int addr, int priority)
358 if (event < DC_EVEN_UGDE0) {
359 reg = ipu_dc_read(ipu, DC_RL_CH(chan, event));
360 reg &= ~(0xFFFF << (16 * (event & 0x1)));
361 reg |= ((addr << 8) | priority) << (16 * (event & 0x1));
362 ipu_dc_write(ipu, reg, DC_RL_CH(chan, event));
364 reg = ipu_dc_read(ipu, DC_UGDE_0((event - DC_EVEN_UGDE0) / 2));
365 if ((event - DC_EVEN_UGDE0) & 0x1) {
366 reg &= ~(0x2FF << 16);
368 reg |= priority ? (2 << 24) : 0x0;
373 ((((chan & 0x1) + ((chan & 0x2) >> 1))) | (chan >> 3));
376 address_shift = ((event - DC_EVEN_UGDE0) >> 1) ? 7 : 8;
377 reg |= (addr << address_shift) | (priority << 3) | chan;
379 ipu_dc_write(ipu, reg, DC_UGDE_0((event - DC_EVEN_UGDE0) / 2));
383 /* Y = R * 1.200 + G * 2.343 + B * .453 + 0.250;
384 U = R * -.672 + G * -1.328 + B * 2.000 + 512.250.;
385 V = R * 2.000 + G * -1.672 + B * -.328 + 512.250.;*/
386 static const int rgb2ycbcr_coeff[5][3] = {
388 {-0x2B, -0x55, 0x80},
389 {0x80, -0x6B, -0x15},
390 {0x0000, 0x0200, 0x0200}, /* B0, B1, B2 */
391 {0x2, 0x2, 0x2}, /* S0, S1, S2 */
394 /* R = (1.164 * (Y - 16)) + (1.596 * (Cr - 128));
395 G = (1.164 * (Y - 16)) - (0.392 * (Cb - 128)) - (0.813 * (Cr - 128));
396 B = (1.164 * (Y - 16)) + (2.017 * (Cb - 128); */
397 static const int ycbcr2rgb_coeff[5][3] = {
398 {0x095, 0x000, 0x0CC},
399 {0x095, 0x3CE, 0x398},
400 {0x095, 0x0FF, 0x000},
401 {0x3E42, 0x010A, 0x3DD6}, /*B0,B1,B2 */
402 {0x1, 0x1, 0x1}, /*S0,S1,S2 */
405 #define mask_a(a) ((u32)(a) & 0x3FF)
406 #define mask_b(b) ((u32)(b) & 0x3FFF)
408 /* Pls keep S0, S1 and S2 as 0x2 by using this convertion */
409 static int _rgb_to_yuv(int n, int red, int green, int blue)
412 c = red * rgb2ycbcr_coeff[n][0];
413 c += green * rgb2ycbcr_coeff[n][1];
414 c += blue * rgb2ycbcr_coeff[n][2];
416 c += rgb2ycbcr_coeff[3][n] * 4;
427 * Row is for BG: RGB2YUV YUV2RGB RGB2RGB YUV2YUV CSC_NONE
428 * Column is for FG: RGB2YUV YUV2RGB RGB2RGB YUV2YUV CSC_NONE
430 static struct dp_csc_param_t dp_csc_array[CSC_NUM][CSC_NUM] = {
431 {{DP_COM_CONF_CSC_DEF_BOTH, &rgb2ycbcr_coeff}, {0, 0}, {0, 0}, {DP_COM_CONF_CSC_DEF_BG, &rgb2ycbcr_coeff}, {DP_COM_CONF_CSC_DEF_BG, &rgb2ycbcr_coeff} },
432 {{0, 0}, {DP_COM_CONF_CSC_DEF_BOTH, &ycbcr2rgb_coeff}, {DP_COM_CONF_CSC_DEF_BG, &ycbcr2rgb_coeff}, {0, 0}, {DP_COM_CONF_CSC_DEF_BG, &ycbcr2rgb_coeff} },
433 {{0, 0}, {DP_COM_CONF_CSC_DEF_FG, &ycbcr2rgb_coeff}, {0, 0}, {0, 0}, {0, 0} },
434 {{DP_COM_CONF_CSC_DEF_FG, &rgb2ycbcr_coeff}, {0, 0}, {0, 0}, {0, 0}, {0, 0} },
435 {{DP_COM_CONF_CSC_DEF_FG, &rgb2ycbcr_coeff}, {DP_COM_CONF_CSC_DEF_FG, &ycbcr2rgb_coeff}, {0, 0}, {0, 0}, {0, 0} }
438 void __ipu_dp_csc_setup(struct ipu_soc *ipu,
439 int dp, struct dp_csc_param_t dp_csc_param,
440 bool srm_mode_update)
443 const int (*coeff)[5][3];
445 if (dp_csc_param.mode >= 0) {
446 reg = ipu_dp_read(ipu, DP_COM_CONF(dp));
447 reg &= ~DP_COM_CONF_CSC_DEF_MASK;
448 reg |= dp_csc_param.mode;
449 ipu_dp_write(ipu, reg, DP_COM_CONF(dp));
452 coeff = dp_csc_param.coeff;
455 ipu_dp_write(ipu, mask_a((*coeff)[0][0]) |
456 (mask_a((*coeff)[0][1]) << 16), DP_CSC_A_0(dp));
457 ipu_dp_write(ipu, mask_a((*coeff)[0][2]) |
458 (mask_a((*coeff)[1][0]) << 16), DP_CSC_A_1(dp));
459 ipu_dp_write(ipu, mask_a((*coeff)[1][1]) |
460 (mask_a((*coeff)[1][2]) << 16), DP_CSC_A_2(dp));
461 ipu_dp_write(ipu, mask_a((*coeff)[2][0]) |
462 (mask_a((*coeff)[2][1]) << 16), DP_CSC_A_3(dp));
463 ipu_dp_write(ipu, mask_a((*coeff)[2][2]) |
464 (mask_b((*coeff)[3][0]) << 16) |
465 ((*coeff)[4][0] << 30), DP_CSC_0(dp));
466 ipu_dp_write(ipu, mask_b((*coeff)[3][1]) | ((*coeff)[4][1] << 14) |
467 (mask_b((*coeff)[3][2]) << 16) |
468 ((*coeff)[4][2] << 30), DP_CSC_1(dp));
471 if (srm_mode_update) {
472 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
473 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
477 int _ipu_dp_init(struct ipu_soc *ipu,
478 ipu_channel_t channel, uint32_t in_pixel_fmt,
479 uint32_t out_pixel_fmt)
486 if (channel == MEM_FG_SYNC) {
489 } else if (channel == MEM_BG_SYNC) {
492 } else if (channel == MEM_BG_ASYNC0) {
499 in_fmt = format_to_colorspace(in_pixel_fmt);
500 out_fmt = format_to_colorspace(out_pixel_fmt);
505 ipu->fg_csc_type = RGB2RGB;
507 ipu->fg_csc_type = RGB2YUV;
510 ipu->fg_csc_type = YUV2RGB;
512 ipu->fg_csc_type = YUV2YUV;
517 ipu->bg_csc_type = RGB2RGB;
519 ipu->bg_csc_type = RGB2YUV;
522 ipu->bg_csc_type = YUV2RGB;
524 ipu->bg_csc_type = YUV2YUV;
528 /* Transform color key from rgb to yuv if CSC is enabled */
529 reg = ipu_dp_read(ipu, DP_COM_CONF(dp));
530 if (ipu->color_key_4rgb && (reg & DP_COM_CONF_GWCKE) &&
531 (((ipu->fg_csc_type == RGB2YUV) && (ipu->bg_csc_type == YUV2YUV)) ||
532 ((ipu->fg_csc_type == YUV2YUV) && (ipu->bg_csc_type == RGB2YUV)) ||
533 ((ipu->fg_csc_type == YUV2YUV) && (ipu->bg_csc_type == YUV2YUV)) ||
534 ((ipu->fg_csc_type == YUV2RGB) && (ipu->bg_csc_type == YUV2RGB)))) {
535 int red, green, blue;
537 uint32_t color_key = ipu_dp_read(ipu, DP_GRAPH_WIND_CTRL(dp)) & 0xFFFFFFL;
539 dev_dbg(ipu->dev, "_ipu_dp_init color key 0x%x need change to yuv fmt!\n", color_key);
541 red = (color_key >> 16) & 0xFF;
542 green = (color_key >> 8) & 0xFF;
543 blue = color_key & 0xFF;
545 y = _rgb_to_yuv(0, red, green, blue);
546 u = _rgb_to_yuv(1, red, green, blue);
547 v = _rgb_to_yuv(2, red, green, blue);
548 color_key = (y << 16) | (u << 8) | v;
550 reg = ipu_dp_read(ipu, DP_GRAPH_WIND_CTRL(dp)) & 0xFF000000L;
551 ipu_dp_write(ipu, reg | color_key, DP_GRAPH_WIND_CTRL(dp));
552 ipu->color_key_4rgb = false;
554 dev_dbg(ipu->dev, "_ipu_dp_init color key change to yuv fmt 0x%x!\n", color_key);
557 __ipu_dp_csc_setup(ipu, dp, dp_csc_array[ipu->bg_csc_type][ipu->fg_csc_type], true);
562 void _ipu_dp_uninit(struct ipu_soc *ipu, ipu_channel_t channel)
567 if (channel == MEM_FG_SYNC) {
570 } else if (channel == MEM_BG_SYNC) {
573 } else if (channel == MEM_BG_ASYNC0) {
581 ipu->fg_csc_type = CSC_NONE;
583 ipu->bg_csc_type = CSC_NONE;
585 __ipu_dp_csc_setup(ipu, dp, dp_csc_array[ipu->bg_csc_type][ipu->fg_csc_type], false);
588 void _ipu_dc_init(struct ipu_soc *ipu, int dc_chan, int di, bool interlaced, uint32_t pixel_fmt)
592 if ((dc_chan == 1) || (dc_chan == 5)) {
594 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NL, 0, 3);
595 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOL, 0, 2);
596 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA, 0, 1);
599 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NL, 2, 3);
600 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOL, 3, 2);
601 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA, 4, 1);
602 if ((pixel_fmt == IPU_PIX_FMT_YUYV) ||
603 (pixel_fmt == IPU_PIX_FMT_UYVY) ||
604 (pixel_fmt == IPU_PIX_FMT_YVYU) ||
605 (pixel_fmt == IPU_PIX_FMT_VYUY)) {
606 _ipu_dc_link_event(ipu, dc_chan, DC_ODD_UGDE1, 9, 5);
607 _ipu_dc_link_event(ipu, dc_chan, DC_EVEN_UGDE1, 8, 5);
610 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NL, 5, 3);
611 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOL, 6, 2);
612 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA, 7, 1);
613 if ((pixel_fmt == IPU_PIX_FMT_YUYV) ||
614 (pixel_fmt == IPU_PIX_FMT_UYVY) ||
615 (pixel_fmt == IPU_PIX_FMT_YVYU) ||
616 (pixel_fmt == IPU_PIX_FMT_VYUY)) {
617 _ipu_dc_link_event(ipu, dc_chan, DC_ODD_UGDE0, 10, 5);
618 _ipu_dc_link_event(ipu, dc_chan, DC_EVEN_UGDE0, 11, 5);
622 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NF, 0, 0);
623 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NFIELD, 0, 0);
624 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOF, 0, 0);
625 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOFIELD, 0, 0);
626 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN, 0, 0);
627 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR, 0, 0);
630 reg |= DC_DISP_ID_SYNC(di) << DC_WR_CH_CONF_PROG_DISP_ID_OFFSET;
633 reg |= DC_WR_CH_CONF_FIELD_MODE;
634 } else if ((dc_chan == 8) || (dc_chan == 9)) {
636 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_W_0, 0x64, 1);
637 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_W_1, 0x64, 1);
640 reg |= DC_DISP_ID_SERIAL << DC_WR_CH_CONF_PROG_DISP_ID_OFFSET;
642 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(dc_chan));
644 ipu_dc_write(ipu, 0x00000000, DC_WR_CH_ADDR(dc_chan));
646 ipu_dc_write(ipu, 0x00000084, DC_GEN);
649 void _ipu_dc_uninit(struct ipu_soc *ipu, int dc_chan)
651 if ((dc_chan == 1) || (dc_chan == 5)) {
652 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NL, 0, 0);
653 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOL, 0, 0);
654 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA, 0, 0);
655 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NF, 0, 0);
656 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NFIELD, 0, 0);
657 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOF, 0, 0);
658 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOFIELD, 0, 0);
659 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN, 0, 0);
660 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR, 0, 0);
661 _ipu_dc_link_event(ipu, dc_chan, DC_ODD_UGDE0, 0, 0);
662 _ipu_dc_link_event(ipu, dc_chan, DC_EVEN_UGDE0, 0, 0);
663 _ipu_dc_link_event(ipu, dc_chan, DC_ODD_UGDE1, 0, 0);
664 _ipu_dc_link_event(ipu, dc_chan, DC_EVEN_UGDE1, 0, 0);
665 } else if ((dc_chan == 8) || (dc_chan == 9)) {
666 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR_W_0, 0, 0);
667 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR_W_1, 0, 0);
668 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN_W_0, 0, 0);
669 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN_W_1, 0, 0);
670 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_W_0, 0, 0);
671 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_W_1, 0, 0);
672 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR_R_0, 0, 0);
673 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR_R_1, 0, 0);
674 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN_R_0, 0, 0);
675 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN_R_1, 0, 0);
676 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_R_0, 0, 0);
677 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_R_1, 0, 0);
681 int _ipu_disp_chan_is_interlaced(struct ipu_soc *ipu, ipu_channel_t channel)
683 if (channel == MEM_DC_SYNC)
684 return !!(ipu_dc_read(ipu, DC_WR_CH_CONF_1) &
685 DC_WR_CH_CONF_FIELD_MODE);
686 else if ((channel == MEM_BG_SYNC) || (channel == MEM_FG_SYNC))
687 return !!(ipu_dc_read(ipu, DC_WR_CH_CONF_5) &
688 DC_WR_CH_CONF_FIELD_MODE);
692 void _ipu_dp_dc_enable(struct ipu_soc *ipu, ipu_channel_t channel)
699 if (channel == MEM_FG_SYNC)
700 irq = IPU_IRQ_DP_SF_END;
701 else if (channel == MEM_DC_SYNC)
703 else if (channel == MEM_BG_SYNC)
708 if (channel == MEM_FG_SYNC) {
709 /* Enable FG channel */
710 reg = ipu_dp_read(ipu, DP_COM_CONF(DP_SYNC));
711 ipu_dp_write(ipu, reg | DP_COM_CONF_FG_EN, DP_COM_CONF(DP_SYNC));
713 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
714 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
718 di = ipu->dc_di_assignment[dc_chan];
720 /* Make sure other DC sync channel is not assigned same DI */
721 reg = ipu_dc_read(ipu, DC_WR_CH_CONF(6 - dc_chan));
722 if ((di << 2) == (reg & DC_WR_CH_CONF_PROG_DI_ID)) {
723 reg &= ~DC_WR_CH_CONF_PROG_DI_ID;
724 reg |= di ? 0 : DC_WR_CH_CONF_PROG_DI_ID;
725 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(6 - dc_chan));
728 reg = ipu_dc_read(ipu, DC_WR_CH_CONF(dc_chan));
729 reg |= 4 << DC_WR_CH_CONF_PROG_TYPE_OFFSET;
730 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(dc_chan));
732 clk_enable(&ipu->pixel_clk[di]);
735 static irqreturn_t dc_irq_handler(int irq, void *dev_id)
737 struct ipu_soc *ipu = dev_id;
738 struct completion *comp = &ipu->dc_comp;
742 if (irq == IPU_IRQ_DC_FC_1)
748 reg = ipu_dc_read(ipu, DC_WR_CH_CONF(dc_chan));
749 reg &= ~DC_WR_CH_CONF_PROG_TYPE_MASK;
750 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(dc_chan));
752 reg = ipu_cm_read(ipu, IPU_DISP_GEN);
753 if (ipu->dc_di_assignment[dc_chan])
754 reg &= ~DI1_COUNTER_RELEASE;
756 reg &= ~DI0_COUNTER_RELEASE;
757 ipu_cm_write(ipu, reg, IPU_DISP_GEN);
764 void _ipu_dp_dc_disable(struct ipu_soc *ipu, ipu_channel_t channel, bool swap)
767 unsigned long lock_flags;
776 if (channel == MEM_DC_SYNC) {
778 irq = IPU_IRQ_DC_FC_1;
779 } else if (channel == MEM_BG_SYNC) {
781 irq = IPU_IRQ_DP_SF_END;
782 } else if (channel == MEM_FG_SYNC) {
783 /* Disable FG channel */
786 spin_lock_irqsave(&ipu->ipu_lock, lock_flags);
788 reg = ipu_dp_read(ipu, DP_COM_CONF(DP_SYNC));
789 csc = reg & DP_COM_CONF_CSC_DEF_MASK;
790 if (csc == DP_COM_CONF_CSC_DEF_FG)
791 reg &= ~DP_COM_CONF_CSC_DEF_MASK;
793 reg &= ~DP_COM_CONF_FG_EN;
794 ipu_dp_write(ipu, reg, DP_COM_CONF(DP_SYNC));
796 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
797 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
799 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
801 ipu_cm_write(ipu, IPUIRQ_2_MASK(IPU_IRQ_DP_SF_END),
802 IPUIRQ_2_STATREG(IPU_IRQ_DP_SF_END));
803 while ((ipu_cm_read(ipu, IPUIRQ_2_STATREG(IPU_IRQ_DP_SF_END)) &
804 IPUIRQ_2_MASK(IPU_IRQ_DP_SF_END)) == 0) {
815 init_completion(&ipu->dc_comp);
816 ipu_clear_irq(ipu, irq);
817 ret = ipu_request_irq(ipu, irq, dc_irq_handler, 0, NULL, ipu);
819 dev_err(ipu->dev, "DC irq %d in use\n", irq);
822 ret = wait_for_completion_timeout(&ipu->dc_comp, msecs_to_jiffies(50));
823 ipu_free_irq(ipu, irq, ipu);
824 dev_dbg(ipu->dev, "DC stop timeout - %d * 10ms\n", 5 - ret);
827 spin_lock_irqsave(&ipu->ipu_lock, lock_flags);
828 /* Swap DC channel 1 and 5 settings, and disable old dc chan */
829 reg = ipu_dc_read(ipu, DC_WR_CH_CONF(dc_chan));
830 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(6 - dc_chan));
831 reg &= ~DC_WR_CH_CONF_PROG_TYPE_MASK;
832 reg ^= DC_WR_CH_CONF_PROG_DI_ID;
833 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(dc_chan));
834 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
836 /* Clock is already off because it must be done quickly, but
837 we need to fix the ref count */
838 clk_disable(&ipu->pixel_clk[ipu->dc_di_assignment[dc_chan]]);
841 void _ipu_init_dc_mappings(struct ipu_soc *ipu)
843 /* IPU_PIX_FMT_RGB24 */
844 _ipu_dc_map_clear(ipu, 0);
845 _ipu_dc_map_config(ipu, 0, 0, 7, 0xFF);
846 _ipu_dc_map_config(ipu, 0, 1, 15, 0xFF);
847 _ipu_dc_map_config(ipu, 0, 2, 23, 0xFF);
849 /* IPU_PIX_FMT_RGB666 */
850 _ipu_dc_map_clear(ipu, 1);
851 _ipu_dc_map_config(ipu, 1, 0, 5, 0xFC);
852 _ipu_dc_map_config(ipu, 1, 1, 11, 0xFC);
853 _ipu_dc_map_config(ipu, 1, 2, 17, 0xFC);
855 /* IPU_PIX_FMT_YUV444 */
856 _ipu_dc_map_clear(ipu, 2);
857 _ipu_dc_map_config(ipu, 2, 0, 15, 0xFF);
858 _ipu_dc_map_config(ipu, 2, 1, 23, 0xFF);
859 _ipu_dc_map_config(ipu, 2, 2, 7, 0xFF);
861 /* IPU_PIX_FMT_RGB565 */
862 _ipu_dc_map_clear(ipu, 3);
863 _ipu_dc_map_config(ipu, 3, 0, 4, 0xF8);
864 _ipu_dc_map_config(ipu, 3, 1, 10, 0xFC);
865 _ipu_dc_map_config(ipu, 3, 2, 15, 0xF8);
867 /* IPU_PIX_FMT_LVDS666 */
868 _ipu_dc_map_clear(ipu, 4);
869 _ipu_dc_map_config(ipu, 4, 0, 5, 0xFC);
870 _ipu_dc_map_config(ipu, 4, 1, 13, 0xFC);
871 _ipu_dc_map_config(ipu, 4, 2, 21, 0xFC);
873 /* IPU_PIX_FMT_VYUY 16bit width */
874 _ipu_dc_map_clear(ipu, 5);
875 _ipu_dc_map_config(ipu, 5, 0, 7, 0xFF);
876 _ipu_dc_map_config(ipu, 5, 1, 0, 0x0);
877 _ipu_dc_map_config(ipu, 5, 2, 15, 0xFF);
878 _ipu_dc_map_clear(ipu, 6);
879 _ipu_dc_map_config(ipu, 6, 0, 0, 0x0);
880 _ipu_dc_map_config(ipu, 6, 1, 7, 0xFF);
881 _ipu_dc_map_config(ipu, 6, 2, 15, 0xFF);
883 /* IPU_PIX_FMT_UYUV 16bit width */
884 _ipu_dc_map_clear(ipu, 7);
885 _ipu_dc_map_link(ipu, 7, 6, 0, 6, 1, 6, 2);
886 _ipu_dc_map_clear(ipu, 8);
887 _ipu_dc_map_link(ipu, 8, 5, 0, 5, 1, 5, 2);
889 /* IPU_PIX_FMT_YUYV 16bit width */
890 _ipu_dc_map_clear(ipu, 9);
891 _ipu_dc_map_link(ipu, 9, 5, 2, 5, 1, 5, 0);
892 _ipu_dc_map_clear(ipu, 10);
893 _ipu_dc_map_link(ipu, 10, 5, 1, 5, 2, 5, 0);
895 /* IPU_PIX_FMT_YVYU 16bit width */
896 _ipu_dc_map_clear(ipu, 11);
897 _ipu_dc_map_link(ipu, 11, 5, 1, 5, 2, 5, 0);
898 _ipu_dc_map_clear(ipu, 12);
899 _ipu_dc_map_link(ipu, 12, 5, 2, 5, 1, 5, 0);
901 /* IPU_PIX_FMT_GBR24 */
902 /* IPU_PIX_FMT_VYU444 */
903 _ipu_dc_map_clear(ipu, 13);
904 _ipu_dc_map_link(ipu, 13, 0, 2, 0, 0, 0, 1);
906 /* IPU_PIX_FMT_BGR24 */
907 _ipu_dc_map_clear(ipu, 14);
908 _ipu_dc_map_link(ipu, 14, 0, 2, 0, 1, 0, 0);
911 int _ipu_pixfmt_to_map(uint32_t fmt)
914 case IPU_PIX_FMT_GENERIC:
915 case IPU_PIX_FMT_RGB24:
917 case IPU_PIX_FMT_RGB666:
919 case IPU_PIX_FMT_YUV444:
921 case IPU_PIX_FMT_RGB565:
923 case IPU_PIX_FMT_LVDS666:
925 case IPU_PIX_FMT_VYUY:
927 case IPU_PIX_FMT_UYVY:
929 case IPU_PIX_FMT_YUYV:
931 case IPU_PIX_FMT_YVYU:
933 case IPU_PIX_FMT_GBR24:
934 case IPU_PIX_FMT_VYU444:
936 case IPU_PIX_FMT_BGR24:
944 * This function sets the colorspace for of dp.
947 * @param ipu ipu handler
948 * @param channel Input parameter for the logical channel ID.
950 * @param param If it's not NULL, update the csc table
951 * with this parameter.
955 void _ipu_dp_set_csc_coefficients(struct ipu_soc *ipu, ipu_channel_t channel, int32_t param[][3])
958 struct dp_csc_param_t dp_csc_param;
960 if (channel == MEM_FG_SYNC)
962 else if (channel == MEM_BG_SYNC)
964 else if (channel == MEM_BG_ASYNC0)
969 dp_csc_param.mode = -1;
970 dp_csc_param.coeff = param;
971 __ipu_dp_csc_setup(ipu, dp, dp_csc_param, true);
975 * This function is called to adapt synchronous LCD panel to IPU restriction.
978 void adapt_panel_to_ipu_restricitions(struct ipu_soc *ipu, uint16_t *v_start_width,
979 uint16_t *v_sync_width,
980 uint16_t *v_end_width)
982 if (*v_end_width < 2) {
983 uint16_t diff = 2 - *v_end_width;
984 if (*v_start_width >= diff) {
986 *v_start_width = *v_start_width - diff;
987 } else if (*v_sync_width > diff) {
989 *v_sync_width = *v_sync_width - diff;
991 dev_err(ipu->dev, "WARNING: try to adapt timming, but failed\n");
992 dev_err(ipu->dev, "WARNING: adapt panel end blank lines\n");
997 * This function is called to initialize a synchronous LCD panel.
999 * @param ipu ipu handler
1000 * @param disp The DI the panel is attached to.
1002 * @param pixel_clk Desired pixel clock frequency in Hz.
1004 * @param pixel_fmt Input parameter for pixel format of buffer.
1005 * Pixel format is a FOURCC ASCII code.
1007 * @param width The width of panel in pixels.
1009 * @param height The height of panel in pixels.
1011 * @param hStartWidth The number of pixel clocks between the HSYNC
1012 * signal pulse and the start of valid data.
1014 * @param hSyncWidth The width of the HSYNC signal in units of pixel
1017 * @param hEndWidth The number of pixel clocks between the end of
1018 * valid data and the HSYNC signal for next line.
1020 * @param vStartWidth The number of lines between the VSYNC
1021 * signal pulse and the start of valid data.
1023 * @param vSyncWidth The width of the VSYNC signal in units of lines
1025 * @param vEndWidth The number of lines between the end of valid
1026 * data and the VSYNC signal for next frame.
1028 * @param sig Bitfield of signal polarities for LCD interface.
1030 * @return This function returns 0 on success or negative error code on
1033 int32_t ipu_init_sync_panel(struct ipu_soc *ipu, int disp, uint32_t pixel_clk,
1034 uint16_t width, uint16_t height,
1036 uint16_t h_start_width, uint16_t h_sync_width,
1037 uint16_t h_end_width, uint16_t v_start_width,
1038 uint16_t v_sync_width, uint16_t v_end_width,
1039 uint32_t v_to_h_sync, ipu_di_signal_cfg_t sig)
1041 unsigned long lock_flags;
1042 uint32_t field0_offset = 0;
1043 uint32_t field1_offset;
1045 uint32_t di_gen, vsync_cnt;
1046 uint32_t div, rounded_pixel_clk, rounded_parent_clk;
1047 uint32_t h_total, v_total;
1049 struct clk *di_parent;
1051 dev_dbg(ipu->dev, "panel size = %d x %d\n", width, height);
1053 if ((v_sync_width == 0) || (h_sync_width == 0))
1056 adapt_panel_to_ipu_restricitions(ipu, &v_start_width, &v_sync_width, &v_end_width);
1057 h_total = width + h_sync_width + h_start_width + h_end_width;
1058 v_total = height + v_sync_width + v_start_width + v_end_width;
1061 dev_dbg(ipu->dev, "pixel clk = %d\n", pixel_clk);
1063 di_parent = clk_get_parent(ipu->di_clk[disp]);
1064 if (clk_get(NULL, "tve_clk") == di_parent ||
1065 clk_get(NULL, "ldb_di0_clk") == di_parent ||
1066 clk_get(NULL, "ldb_di1_clk") == di_parent) {
1067 /* if di clk parent is tve/ldb, then keep it;*/
1068 dev_dbg(ipu->dev, "use special clk parent\n");
1069 clk_set_parent(&ipu->pixel_clk[disp], ipu->di_clk[disp]);
1071 /* try ipu clk first*/
1072 dev_dbg(ipu->dev, "try ipu internal clk\n");
1073 clk_set_parent(&ipu->pixel_clk[disp], ipu->ipu_clk);
1074 rounded_pixel_clk = clk_round_rate(&ipu->pixel_clk[disp], pixel_clk);
1076 * we will only use 1/2 fraction for ipu clk,
1077 * so if the clk rate is not fit, try ext clk.
1080 ((rounded_pixel_clk >= pixel_clk + pixel_clk/200) ||
1081 (rounded_pixel_clk <= pixel_clk - pixel_clk/200))) {
1082 dev_dbg(ipu->dev, "try ipu ext di clk\n");
1083 if (clk_get_usecount(di_parent))
1085 "ext di clk already in use, go back to internal clk\n");
1087 rounded_pixel_clk = pixel_clk * 2;
1088 rounded_parent_clk = clk_round_rate(di_parent,
1090 while (rounded_pixel_clk < rounded_parent_clk) {
1091 /* the max divider from parent to di is 8 */
1092 if (rounded_parent_clk / pixel_clk < 8)
1093 rounded_pixel_clk += pixel_clk * 2;
1095 rounded_pixel_clk *= 2;
1097 clk_set_rate(di_parent, rounded_pixel_clk);
1099 clk_round_rate(ipu->di_clk[disp], pixel_clk);
1100 clk_set_rate(ipu->di_clk[disp], rounded_pixel_clk);
1101 clk_set_parent(&ipu->pixel_clk[disp], ipu->di_clk[disp]);
1105 rounded_pixel_clk = clk_round_rate(&ipu->pixel_clk[disp], pixel_clk);
1106 clk_set_rate(&ipu->pixel_clk[disp], rounded_pixel_clk);
1108 /* Get integer portion of divider */
1109 div = clk_get_rate(clk_get_parent(&ipu->pixel_clk[disp])) / rounded_pixel_clk;
1111 spin_lock_irqsave(&ipu->ipu_lock, lock_flags);
1113 _ipu_di_data_wave_config(ipu, disp, SYNC_WAVE, div - 1, div - 1);
1114 _ipu_di_data_pin_config(ipu, disp, SYNC_WAVE, DI_PIN15, 3, 0, div * 2);
1116 map = _ipu_pixfmt_to_map(pixel_fmt);
1118 dev_dbg(ipu->dev, "IPU_DISP: No MAP\n");
1119 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
1124 di_gen = ipu_di_read(ipu, disp, DI_GENERAL);
1125 ipu_di_write(ipu, disp,
1126 di_gen & (0x3 << 20), DI_GENERAL);
1128 if (sig.interlaced) {
1129 if (g_ipu_hw_rev >= 2) {
1130 /* Setup internal HSYNC waveform */
1131 _ipu_di_sync_config(ipu,
1134 h_total/2 - 1, /* run count */
1135 DI_SYNC_CLK, /* run_resolution */
1137 DI_SYNC_NONE, /* offset resolution */
1138 0, /* repeat count */
1139 DI_SYNC_NONE, /* CNT_CLR_SEL */
1140 0, /* CNT_POLARITY_GEN_EN */
1141 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1142 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1147 /* Field 1 VSYNC waveform */
1148 _ipu_di_sync_config(ipu,
1151 h_total - 1, /* run count */
1152 DI_SYNC_CLK, /* run_resolution */
1154 DI_SYNC_NONE, /* offset resolution */
1155 0, /* repeat count */
1156 DI_SYNC_NONE, /* CNT_CLR_SEL */
1157 0, /* CNT_POLARITY_GEN_EN */
1158 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1159 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1161 2*div /* COUNT DOWN */
1164 /* Setup internal HSYNC waveform */
1165 _ipu_di_sync_config(ipu,
1168 v_total*2 - 1, /* run count */
1169 DI_SYNC_INT_HSYNC, /* run_resolution */
1171 DI_SYNC_INT_HSYNC, /* offset resolution */
1172 0, /* repeat count */
1173 DI_SYNC_NONE, /* CNT_CLR_SEL */
1174 0, /* CNT_POLARITY_GEN_EN */
1175 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1176 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1178 2*div /* COUNT DOWN */
1181 /* Active Field ? */
1182 _ipu_di_sync_config(ipu,
1185 v_total/2 - 1, /* run count */
1186 DI_SYNC_HSYNC, /* run_resolution */
1187 v_start_width, /* offset */
1188 DI_SYNC_HSYNC, /* offset resolution */
1189 2, /* repeat count */
1190 DI_SYNC_VSYNC, /* CNT_CLR_SEL */
1191 0, /* CNT_POLARITY_GEN_EN */
1192 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1193 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1199 _ipu_di_sync_config(ipu,
1203 DI_SYNC_HSYNC, /* run_resolution */
1205 DI_SYNC_NONE, /* offset resolution */
1206 height/2, /* repeat count */
1207 4, /* CNT_CLR_SEL */
1208 0, /* CNT_POLARITY_GEN_EN */
1209 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1210 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1215 /* Field 0 VSYNC waveform */
1216 _ipu_di_sync_config(ipu,
1219 v_total - 1, /* run count */
1220 DI_SYNC_HSYNC, /* run_resolution */
1222 DI_SYNC_NONE, /* offset resolution */
1223 0, /* repeat count */
1224 DI_SYNC_NONE, /* CNT_CLR_SEL */
1225 0, /* CNT_POLARITY_GEN_EN */
1226 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1227 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1232 /* DC VSYNC waveform */
1234 _ipu_di_sync_config(ipu,
1237 v_total/2 - 1, /* run count */
1238 DI_SYNC_HSYNC, /* run_resolution */
1240 DI_SYNC_HSYNC, /* offset resolution */
1241 2, /* repeat count */
1242 DI_SYNC_VSYNC, /* CNT_CLR_SEL */
1243 0, /* CNT_POLARITY_GEN_EN */
1244 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1245 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1250 /* active pixel waveform */
1251 _ipu_di_sync_config(ipu,
1255 DI_SYNC_CLK, /* run_resolution */
1256 h_start_width, /* offset */
1257 DI_SYNC_CLK, /* offset resolution */
1258 width, /* repeat count */
1259 5, /* CNT_CLR_SEL */
1260 0, /* CNT_POLARITY_GEN_EN */
1261 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1262 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1268 _ipu_di_sync_config(ipu,
1271 v_total - 1, /* run count */
1272 DI_SYNC_INT_HSYNC, /* run_resolution */
1273 v_total/2, /* offset */
1274 DI_SYNC_INT_HSYNC, /* offset resolution */
1275 0, /* repeat count */
1276 DI_SYNC_HSYNC, /* CNT_CLR_SEL */
1277 0, /* CNT_POLARITY_GEN_EN */
1278 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1279 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1281 2*div /* COUNT DOWN */
1284 /* set gentime select and tag sel */
1285 reg = ipu_di_read(ipu, disp, DI_SW_GEN1(9));
1287 reg |= (3-1)<<29 | 0x00008000;
1288 ipu_di_write(ipu, disp, reg, DI_SW_GEN1(9));
1290 ipu_di_write(ipu, disp, v_total / 2 - 1, DI_SCR_CONF);
1293 di_gen |= 0x10000000;
1294 di_gen |= DI_GEN_POLARITY_5;
1295 di_gen |= DI_GEN_POLARITY_8;
1297 /* Setup internal HSYNC waveform */
1298 _ipu_di_sync_config(ipu, disp, 1, h_total - 1, DI_SYNC_CLK,
1299 0, DI_SYNC_NONE, 0, DI_SYNC_NONE, 0, DI_SYNC_NONE,
1300 DI_SYNC_NONE, 0, 0);
1302 field1_offset = v_sync_width + v_start_width + height / 2 +
1304 if (sig.odd_field_first) {
1305 field0_offset = field1_offset - 1;
1308 v_total += v_start_width + v_end_width;
1310 /* Field 1 VSYNC waveform */
1311 _ipu_di_sync_config(ipu, disp, 2, v_total - 1, 1,
1313 field0_offset ? 1 : DI_SYNC_NONE,
1315 DI_SYNC_NONE, DI_SYNC_NONE, 0, 4);
1317 /* Setup internal HSYNC waveform */
1318 _ipu_di_sync_config(ipu, disp, 3, h_total - 1, DI_SYNC_CLK,
1319 0, DI_SYNC_NONE, 0, DI_SYNC_NONE, 0,
1320 DI_SYNC_NONE, DI_SYNC_NONE, 0, 4);
1322 /* Active Field ? */
1323 _ipu_di_sync_config(ipu, disp, 4,
1325 field0_offset : field1_offset - 2,
1326 1, v_start_width + v_sync_width, 1, 2, 2,
1327 0, DI_SYNC_NONE, DI_SYNC_NONE, 0, 0);
1330 _ipu_di_sync_config(ipu, disp, 5, 0, 1,
1332 height / 2, 4, 0, DI_SYNC_NONE,
1333 DI_SYNC_NONE, 0, 0);
1335 /* Field 0 VSYNC waveform */
1336 _ipu_di_sync_config(ipu, disp, 6, v_total - 1, 1,
1338 0, DI_SYNC_NONE, 0, DI_SYNC_NONE,
1339 DI_SYNC_NONE, 0, 0);
1341 /* DC VSYNC waveform */
1343 _ipu_di_sync_config(ipu, disp, 7, 0, 1,
1345 field1_offset ? 1 : DI_SYNC_NONE,
1346 1, 2, 0, DI_SYNC_NONE, DI_SYNC_NONE, 0, 0);
1348 /* active pixel waveform */
1349 _ipu_di_sync_config(ipu, disp, 8, 0, DI_SYNC_CLK,
1350 h_sync_width + h_start_width, DI_SYNC_CLK,
1351 width, 5, 0, DI_SYNC_NONE, DI_SYNC_NONE,
1355 _ipu_di_sync_config(ipu, disp, 9, v_total - 1, 2,
1357 0, DI_SYNC_NONE, 6, DI_SYNC_NONE,
1358 DI_SYNC_NONE, 0, 0);
1360 reg = ipu_di_read(ipu, disp, DI_SW_GEN1(9));
1362 ipu_di_write(ipu, disp, reg, DI_SW_GEN1(9));
1364 ipu_di_write(ipu, disp, v_sync_width + v_start_width +
1365 v_end_width + height / 2 - 1, DI_SCR_CONF);
1368 /* Init template microcode */
1369 _ipu_dc_write_tmpl(ipu, 0, WROD(0), 0, map, SYNC_WAVE, 0, 8, 1);
1372 di_gen |= DI_GEN_POLARITY_3;
1374 di_gen |= DI_GEN_POLARITY_2;
1376 /* Setup internal HSYNC waveform */
1377 _ipu_di_sync_config(ipu, disp, 1, h_total - 1, DI_SYNC_CLK,
1378 0, DI_SYNC_NONE, 0, DI_SYNC_NONE, 0, DI_SYNC_NONE,
1379 DI_SYNC_NONE, 0, 0);
1381 /* Setup external (delayed) HSYNC waveform */
1382 _ipu_di_sync_config(ipu, disp, DI_SYNC_HSYNC, h_total - 1,
1383 DI_SYNC_CLK, div * v_to_h_sync, DI_SYNC_CLK,
1384 0, DI_SYNC_NONE, 1, DI_SYNC_NONE,
1385 DI_SYNC_CLK, 0, h_sync_width * 2);
1386 /* Setup VSYNC waveform */
1387 vsync_cnt = DI_SYNC_VSYNC;
1388 _ipu_di_sync_config(ipu, disp, DI_SYNC_VSYNC, v_total - 1,
1389 DI_SYNC_INT_HSYNC, 0, DI_SYNC_NONE, 0,
1390 DI_SYNC_NONE, 1, DI_SYNC_NONE,
1391 DI_SYNC_INT_HSYNC, 0, v_sync_width * 2);
1392 ipu_di_write(ipu, disp, v_total - 1, DI_SCR_CONF);
1394 /* Setup active data waveform to sync with DC */
1395 _ipu_di_sync_config(ipu, disp, 4, 0, DI_SYNC_HSYNC,
1396 v_sync_width + v_start_width, DI_SYNC_HSYNC, height,
1397 DI_SYNC_VSYNC, 0, DI_SYNC_NONE,
1398 DI_SYNC_NONE, 0, 0);
1399 _ipu_di_sync_config(ipu, disp, 5, 0, DI_SYNC_CLK,
1400 h_sync_width + h_start_width, DI_SYNC_CLK,
1401 width, 4, 0, DI_SYNC_NONE, DI_SYNC_NONE, 0,
1404 /* set VGA delayed hsync/vsync no matter VGA enabled */
1406 /* couter 7 for VGA delay HSYNC */
1407 _ipu_di_sync_config(ipu, disp, 7,
1408 h_total - 1, DI_SYNC_CLK,
1411 1, DI_SYNC_NONE, DI_SYNC_CLK,
1412 0, h_sync_width * 2);
1414 /* couter 8 for VGA delay VSYNC */
1415 _ipu_di_sync_config(ipu, disp, 8,
1416 v_total - 1, DI_SYNC_INT_HSYNC,
1417 1, DI_SYNC_INT_HSYNC,
1419 1, DI_SYNC_NONE, DI_SYNC_INT_HSYNC,
1420 0, v_sync_width * 2);
1423 /* reset all unused counters */
1424 ipu_di_write(ipu, disp, 0, DI_SW_GEN0(6));
1425 ipu_di_write(ipu, disp, 0, DI_SW_GEN1(6));
1427 ipu_di_write(ipu, disp, 0, DI_SW_GEN0(7));
1428 ipu_di_write(ipu, disp, 0, DI_SW_GEN1(7));
1429 ipu_di_write(ipu, disp, 0, DI_STP_REP(7));
1430 ipu_di_write(ipu, disp, 0, DI_SW_GEN0(8));
1431 ipu_di_write(ipu, disp, 0, DI_SW_GEN1(8));
1432 ipu_di_write(ipu, disp, 0, DI_STP_REP(8));
1434 ipu_di_write(ipu, disp, 0, DI_SW_GEN0(9));
1435 ipu_di_write(ipu, disp, 0, DI_SW_GEN1(9));
1436 ipu_di_write(ipu, disp, 0, DI_STP_REP(9));
1438 reg = ipu_di_read(ipu, disp, DI_STP_REP(6));
1440 ipu_di_write(ipu, disp, reg, DI_STP_REP(6));
1442 /* Init template microcode */
1444 if ((pixel_fmt == IPU_PIX_FMT_YUYV) ||
1445 (pixel_fmt == IPU_PIX_FMT_UYVY) ||
1446 (pixel_fmt == IPU_PIX_FMT_YVYU) ||
1447 (pixel_fmt == IPU_PIX_FMT_VYUY)) {
1448 _ipu_dc_write_tmpl(ipu, 8, WROD(0), 0, (map - 1), SYNC_WAVE, 0, 5, 1);
1449 _ipu_dc_write_tmpl(ipu, 9, WROD(0), 0, map, SYNC_WAVE, 0, 5, 1);
1450 /* configure user events according to DISP NUM */
1451 ipu_dc_write(ipu, (width - 1), DC_UGDE_3(disp));
1453 _ipu_dc_write_tmpl(ipu, 2, WROD(0), 0, map, SYNC_WAVE, 8, 5, 1);
1454 _ipu_dc_write_tmpl(ipu, 3, WRG, 0, map, SYNC_WAVE, 4, 5, 1);
1455 _ipu_dc_write_tmpl(ipu, 4, WROD(0), 0, map, SYNC_WAVE, 0, 5, 1);
1457 if ((pixel_fmt == IPU_PIX_FMT_YUYV) ||
1458 (pixel_fmt == IPU_PIX_FMT_UYVY) ||
1459 (pixel_fmt == IPU_PIX_FMT_YVYU) ||
1460 (pixel_fmt == IPU_PIX_FMT_VYUY)) {
1461 _ipu_dc_write_tmpl(ipu, 10, WROD(0), 0, (map - 1), SYNC_WAVE, 0, 5, 1);
1462 _ipu_dc_write_tmpl(ipu, 11, WROD(0), 0, map, SYNC_WAVE, 0, 5, 1);
1463 /* configure user events according to DISP NUM */
1464 ipu_dc_write(ipu, width - 1, DC_UGDE_3(disp));
1466 _ipu_dc_write_tmpl(ipu, 5, WROD(0), 0, map, SYNC_WAVE, 8, 5, 1);
1467 _ipu_dc_write_tmpl(ipu, 6, WRG, 0, map, SYNC_WAVE, 4, 5, 1);
1468 _ipu_dc_write_tmpl(ipu, 7, WROD(0), 0, map, SYNC_WAVE, 0, 5, 1);
1471 if (sig.Hsync_pol) {
1472 di_gen |= DI_GEN_POLARITY_2;
1474 di_gen |= DI_GEN_POLARITY_7;
1476 if (sig.Vsync_pol) {
1477 di_gen |= DI_GEN_POLARITY_3;
1479 di_gen |= DI_GEN_POLARITY_8;
1482 /* changinc DISP_CLK polarity: it can be wrong for some applications */
1483 if ((pixel_fmt == IPU_PIX_FMT_YUYV) ||
1484 (pixel_fmt == IPU_PIX_FMT_UYVY) ||
1485 (pixel_fmt == IPU_PIX_FMT_YVYU) ||
1486 (pixel_fmt == IPU_PIX_FMT_VYUY))
1487 di_gen |= 0x00020000;
1490 di_gen |= DI_GEN_POLARITY_DISP_CLK;
1492 ipu_di_write(ipu, disp, di_gen, DI_GENERAL);
1494 ipu_di_write(ipu, disp, (--vsync_cnt << DI_VSYNC_SEL_OFFSET) |
1495 0x00000002, DI_SYNC_AS_GEN);
1496 reg = ipu_di_read(ipu, disp, DI_POL);
1497 reg &= ~(DI_POL_DRDY_DATA_POLARITY | DI_POL_DRDY_POLARITY_15);
1499 reg |= DI_POL_DRDY_POLARITY_15;
1501 reg |= DI_POL_DRDY_DATA_POLARITY;
1502 ipu_di_write(ipu, disp, reg, DI_POL);
1504 ipu_dc_write(ipu, width, DC_DISP_CONF2(DC_DISP_ID_SYNC(disp)));
1506 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
1510 EXPORT_SYMBOL(ipu_init_sync_panel);
1512 void ipu_uninit_sync_panel(struct ipu_soc *ipu, int disp)
1514 unsigned long lock_flags;
1518 if ((disp != 0) || (disp != 1))
1521 spin_lock_irqsave(&ipu->ipu_lock, lock_flags);
1523 di_gen = ipu_di_read(ipu, disp, DI_GENERAL);
1524 di_gen |= 0x3ff | DI_GEN_POLARITY_DISP_CLK;
1525 ipu_di_write(ipu, disp, di_gen, DI_GENERAL);
1527 reg = ipu_di_read(ipu, disp, DI_POL);
1529 ipu_di_write(ipu, disp, reg, DI_POL);
1531 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
1533 EXPORT_SYMBOL(ipu_uninit_sync_panel);
1535 int ipu_init_async_panel(struct ipu_soc *ipu, int disp, int type, uint32_t cycle_time,
1536 uint32_t pixel_fmt, ipu_adc_sig_cfg_t sig)
1538 unsigned long lock_flags;
1542 u32 di_clk = clk_get_rate(ipu->ipu_clk);
1544 /* round up cycle_time, then calcalate the divider using scaled math */
1545 cycle_time += (1000000000UL / di_clk) - 1;
1546 div = (cycle_time * (di_clk / 256UL)) / (1000000000UL / 256UL);
1548 map = _ipu_pixfmt_to_map(pixel_fmt);
1552 spin_lock_irqsave(&ipu->ipu_lock, lock_flags);
1554 if (type == IPU_PANEL_SERIAL) {
1555 ipu_di_write(ipu, disp, (div << 24) | ((sig.ifc_width - 1) << 4),
1556 DI_DW_GEN(ASYNC_SER_WAVE));
1558 _ipu_di_data_pin_config(ipu, disp, ASYNC_SER_WAVE, DI_PIN_CS,
1559 0, 0, (div * 2) + 1);
1560 _ipu_di_data_pin_config(ipu, disp, ASYNC_SER_WAVE, DI_PIN_SER_CLK,
1562 _ipu_di_data_pin_config(ipu, disp, ASYNC_SER_WAVE, DI_PIN_SER_RS,
1565 _ipu_dc_write_tmpl(ipu, 0x64, WROD(0), 0, map, ASYNC_SER_WAVE, 0, 0, 1);
1567 /* Configure DC for serial panel */
1568 ipu_dc_write(ipu, 0x14, DC_DISP_CONF1(DC_DISP_ID_SERIAL));
1571 ser_conf |= DI_SER_CONF_SERIAL_CLK_POL;
1573 ser_conf |= DI_SER_CONF_SERIAL_DATA_POL;
1575 ser_conf |= DI_SER_CONF_SERIAL_RS_POL;
1577 ser_conf |= DI_SER_CONF_SERIAL_CS_POL;
1578 ipu_di_write(ipu, disp, ser_conf, DI_SER_CONF);
1581 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
1584 EXPORT_SYMBOL(ipu_init_async_panel);
1587 * This function sets the foreground and background plane global alpha blending
1588 * modes. This function also sets the DP graphic plane according to the
1589 * parameter of IPUv3 DP channel.
1591 * @param ipu ipu handler
1592 * @param channel IPUv3 DP channel
1594 * @param enable Boolean to enable or disable global alpha
1595 * blending. If disabled, local blending is used.
1597 * @param alpha Global alpha value.
1599 * @return Returns 0 on success or negative error code on fail
1601 int32_t ipu_disp_set_global_alpha(struct ipu_soc *ipu, ipu_channel_t channel,
1602 bool enable, uint8_t alpha)
1606 unsigned long lock_flags;
1609 if (channel == MEM_BG_SYNC || channel == MEM_FG_SYNC)
1611 else if (channel == MEM_BG_ASYNC0 || channel == MEM_FG_ASYNC0)
1613 else if (channel == MEM_BG_ASYNC1 || channel == MEM_FG_ASYNC1)
1618 if (channel == MEM_BG_SYNC || channel == MEM_BG_ASYNC0 ||
1619 channel == MEM_BG_ASYNC1)
1624 if (!ipu->clk_enabled)
1625 clk_enable(ipu->ipu_clk);
1626 spin_lock_irqsave(&ipu->ipu_lock, lock_flags);
1629 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1630 ipu_dp_write(ipu, reg & ~DP_COM_CONF_GWSEL, DP_COM_CONF(flow));
1632 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1633 ipu_dp_write(ipu, reg | DP_COM_CONF_GWSEL, DP_COM_CONF(flow));
1637 reg = ipu_dp_read(ipu, DP_GRAPH_WIND_CTRL(flow)) & 0x00FFFFFFL;
1638 ipu_dp_write(ipu, reg | ((uint32_t) alpha << 24),
1639 DP_GRAPH_WIND_CTRL(flow));
1641 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1642 ipu_dp_write(ipu, reg | DP_COM_CONF_GWAM, DP_COM_CONF(flow));
1644 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1645 ipu_dp_write(ipu, reg & ~DP_COM_CONF_GWAM, DP_COM_CONF(flow));
1648 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
1649 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
1651 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
1652 if (!ipu->clk_enabled)
1653 clk_disable(ipu->ipu_clk);
1657 EXPORT_SYMBOL(ipu_disp_set_global_alpha);
1660 * This function sets the transparent color key for SDC graphic plane.
1662 * @param ipu ipu handler
1663 * @param channel Input parameter for the logical channel ID.
1665 * @param enable Boolean to enable or disable color key
1667 * @param colorKey 24-bit RGB color for transparent color key.
1669 * @return Returns 0 on success or negative error code on fail
1671 int32_t ipu_disp_set_color_key(struct ipu_soc *ipu, ipu_channel_t channel,
1672 bool enable, uint32_t color_key)
1676 int red, green, blue;
1677 unsigned long lock_flags;
1679 if (channel == MEM_BG_SYNC || channel == MEM_FG_SYNC)
1681 else if (channel == MEM_BG_ASYNC0 || channel == MEM_FG_ASYNC0)
1683 else if (channel == MEM_BG_ASYNC1 || channel == MEM_FG_ASYNC1)
1688 if (!ipu->clk_enabled)
1689 clk_enable(ipu->ipu_clk);
1691 spin_lock_irqsave(&ipu->ipu_lock, lock_flags);
1693 ipu->color_key_4rgb = true;
1694 /* Transform color key from rgb to yuv if CSC is enabled */
1695 if (((ipu->fg_csc_type == RGB2YUV) && (ipu->bg_csc_type == YUV2YUV)) ||
1696 ((ipu->fg_csc_type == YUV2YUV) && (ipu->bg_csc_type == RGB2YUV)) ||
1697 ((ipu->fg_csc_type == YUV2YUV) && (ipu->bg_csc_type == YUV2YUV)) ||
1698 ((ipu->fg_csc_type == YUV2RGB) && (ipu->bg_csc_type == YUV2RGB))) {
1700 dev_dbg(ipu->dev, "color key 0x%x need change to yuv fmt\n", color_key);
1702 red = (color_key >> 16) & 0xFF;
1703 green = (color_key >> 8) & 0xFF;
1704 blue = color_key & 0xFF;
1706 y = _rgb_to_yuv(0, red, green, blue);
1707 u = _rgb_to_yuv(1, red, green, blue);
1708 v = _rgb_to_yuv(2, red, green, blue);
1709 color_key = (y << 16) | (u << 8) | v;
1711 ipu->color_key_4rgb = false;
1713 dev_dbg(ipu->dev, "color key change to yuv fmt 0x%x\n", color_key);
1717 reg = ipu_dp_read(ipu, DP_GRAPH_WIND_CTRL(flow)) & 0xFF000000L;
1718 ipu_dp_write(ipu, reg | color_key, DP_GRAPH_WIND_CTRL(flow));
1720 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1721 ipu_dp_write(ipu, reg | DP_COM_CONF_GWCKE, DP_COM_CONF(flow));
1723 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1724 ipu_dp_write(ipu, reg & ~DP_COM_CONF_GWCKE, DP_COM_CONF(flow));
1727 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
1728 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
1730 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
1731 if (!ipu->clk_enabled)
1732 clk_disable(ipu->ipu_clk);
1736 EXPORT_SYMBOL(ipu_disp_set_color_key);
1739 * This function sets the gamma correction for DP output.
1741 * @param ipu ipu handler
1742 * @param channel Input parameter for the logical channel ID.
1744 * @param enable Boolean to enable or disable gamma correction.
1746 * @param constk Gamma piecewise linear approximation constk coeff.
1748 * @param slopek Gamma piecewise linear approximation slopek coeff.
1750 * @return Returns 0 on success or negative error code on fail
1752 int32_t ipu_disp_set_gamma_correction(struct ipu_soc *ipu, ipu_channel_t channel, bool enable, int constk[], int slopek[])
1754 uint32_t reg, flow, i;
1755 unsigned long lock_flags;
1757 if (channel == MEM_BG_SYNC || channel == MEM_FG_SYNC)
1759 else if (channel == MEM_BG_ASYNC0 || channel == MEM_FG_ASYNC0)
1761 else if (channel == MEM_BG_ASYNC1 || channel == MEM_FG_ASYNC1)
1766 if (!ipu->clk_enabled)
1767 clk_enable(ipu->ipu_clk);
1768 spin_lock_irqsave(&ipu->ipu_lock, lock_flags);
1770 for (i = 0; i < 8; i++)
1771 ipu_dp_write(ipu, (constk[2*i] & 0x1ff) | ((constk[2*i+1] & 0x1ff) << 16), DP_GAMMA_C(flow, i));
1772 for (i = 0; i < 4; i++)
1773 ipu_dp_write(ipu, (slopek[4*i] & 0xff) | ((slopek[4*i+1] & 0xff) << 8) |
1774 ((slopek[4*i+2] & 0xff) << 16) | ((slopek[4*i+3] & 0xff) << 24), DP_GAMMA_S(flow, i));
1776 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1778 if ((ipu->bg_csc_type == RGB2YUV) || (ipu->bg_csc_type == YUV2YUV))
1779 reg |= DP_COM_CONF_GAMMA_YUV_EN;
1781 reg &= ~DP_COM_CONF_GAMMA_YUV_EN;
1782 ipu_dp_write(ipu, reg | DP_COM_CONF_GAMMA_EN, DP_COM_CONF(flow));
1784 ipu_dp_write(ipu, reg & ~DP_COM_CONF_GAMMA_EN, DP_COM_CONF(flow));
1786 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
1787 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
1789 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
1790 if (!ipu->clk_enabled)
1791 clk_disable(ipu->ipu_clk);
1795 EXPORT_SYMBOL(ipu_disp_set_gamma_correction);
1798 * This function sets the window position of the foreground or background plane.
1801 * @param ipu ipu handler
1802 * @param channel Input parameter for the logical channel ID.
1804 * @param x_pos The X coordinate position to place window at.
1805 * The position is relative to the top left corner.
1807 * @param y_pos The Y coordinate position to place window at.
1808 * The position is relative to the top left corner.
1810 * @return Returns 0 on success or negative error code on fail
1812 int32_t ipu_disp_set_window_pos(struct ipu_soc *ipu, ipu_channel_t channel,
1813 int16_t x_pos, int16_t y_pos)
1816 unsigned long lock_flags;
1818 uint32_t dp_srm_shift;
1820 if ((channel == MEM_FG_SYNC) || (channel == MEM_BG_SYNC)) {
1823 } else if (channel == MEM_FG_ASYNC0) {
1826 } else if (channel == MEM_FG_ASYNC1) {
1832 if (!ipu->clk_enabled)
1833 clk_enable(ipu->ipu_clk);
1835 spin_lock_irqsave(&ipu->ipu_lock, lock_flags);
1837 ipu_dp_write(ipu, (x_pos << 16) | y_pos, DP_FG_POS(flow));
1839 if (ipu_is_channel_busy(ipu, channel)) {
1840 /* controled by FSU if channel enabled */
1841 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) & (~(0x3 << dp_srm_shift));
1842 reg |= (0x1 << dp_srm_shift);
1843 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
1845 /* disable auto swap, controled by MCU if channel disabled */
1846 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) & (~(0x3 << dp_srm_shift));
1847 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
1850 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
1851 if (!ipu->clk_enabled)
1852 clk_disable(ipu->ipu_clk);
1856 EXPORT_SYMBOL(ipu_disp_set_window_pos);
1858 int32_t ipu_disp_get_window_pos(struct ipu_soc *ipu, ipu_channel_t channel,
1859 int16_t *x_pos, int16_t *y_pos)
1862 unsigned long lock_flags;
1865 if (channel == MEM_FG_SYNC)
1867 else if (channel == MEM_FG_ASYNC0)
1869 else if (channel == MEM_FG_ASYNC1)
1874 if (!ipu->clk_enabled)
1875 clk_enable(ipu->ipu_clk);
1876 spin_lock_irqsave(&ipu->ipu_lock, lock_flags);
1878 reg = ipu_dp_read(ipu, DP_FG_POS(flow));
1880 *x_pos = (reg >> 16) & 0x7FF;
1881 *y_pos = reg & 0x7FF;
1883 spin_unlock_irqrestore(&ipu->ipu_lock, lock_flags);
1884 if (!ipu->clk_enabled)
1885 clk_disable(ipu->ipu_clk);
1889 EXPORT_SYMBOL(ipu_disp_get_window_pos);
1891 void ipu_disp_direct_write(struct ipu_soc *ipu, ipu_channel_t channel, u32 value, u32 offset)
1893 if (channel == DIRECT_ASYNC0)
1894 writel(value, ipu->disp_base[0] + offset);
1895 else if (channel == DIRECT_ASYNC1)
1896 writel(value, ipu->disp_base[1] + offset);
1898 EXPORT_SYMBOL(ipu_disp_direct_write);
1900 void ipu_reset_disp_panel(struct ipu_soc *ipu)
1904 tmp = ipu_di_read(ipu, 1, DI_GENERAL);
1905 ipu_di_write(ipu, 1, tmp | 0x08, DI_GENERAL);
1906 msleep(10); /* tRES >= 100us */
1907 tmp = ipu_di_read(ipu, 1, DI_GENERAL);
1908 ipu_di_write(ipu, 1, tmp & ~0x08, DI_GENERAL);
1913 EXPORT_SYMBOL(ipu_reset_disp_panel);
1915 void __devinit ipu_disp_init(struct ipu_soc *ipu)
1917 ipu->fg_csc_type = ipu->bg_csc_type = CSC_NONE;
1918 ipu->color_key_4rgb = true;
1919 _ipu_init_dc_mappings(ipu);
1920 _ipu_dmfc_init(ipu, DMFC_NORMAL, 1);