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/clk.h>
28 #include <linux/err.h>
29 #include <asm/atomic.h>
30 #include <mach/clock.h>
31 #include <mach/ipu-v3.h>
34 #include "ipu_param_mem.h"
36 struct dp_csc_param_t {
42 #define ASYNC_SER_WAVE 6
44 /* DC display ID assignments */
45 #define DC_DISP_ID_SYNC(di) (di)
46 #define DC_DISP_ID_SERIAL 2
47 #define DC_DISP_ID_ASYNC 3
49 static inline struct ipu_soc *pixelclk2ipu(struct clk *clk)
52 struct clk *base = clk - clk->id;
54 ipu = container_of(base, struct ipu_soc, pixel_clk[0]);
59 static unsigned long _ipu_pixel_clk_get_rate(struct clk *clk)
61 struct ipu_soc *ipu = pixelclk2ipu(clk);
62 u32 div = ipu_di_read(ipu, clk->id, DI_BS_CLKGEN0);
65 return (clk_get_rate(clk->parent) * 16) / div;
68 static unsigned long _ipu_pixel_clk_round_rate(struct clk *clk, unsigned long rate)
71 u32 parent_rate = clk_get_rate(clk->parent) * 16;
74 * Fractional part is 4 bits,
75 * so simply multiply by 2^4 to get fractional part.
77 div = parent_rate / rate;
79 if (div < 0x10) /* Min DI disp clock divider is 1 */
84 /* Round up divider if it gets us closer to desired pix clk */
85 if ((div & 0xC) == 0xC) {
90 return parent_rate / div;
93 static int _ipu_pixel_clk_set_rate(struct clk *clk, unsigned long rate)
95 struct ipu_soc *ipu = pixelclk2ipu(clk);
96 u32 div = (clk_get_rate(clk->parent) * 16) / rate;
98 /* Round up divider if it gets us closer to desired pix clk */
99 if ((div & 0xC) == 0xC) {
104 ipu_di_write(ipu, clk->id, div, DI_BS_CLKGEN0);
106 /* Setup pixel clock timing */
107 /* FIXME: needs to be more flexible */
108 /* Down time is half of period */
109 ipu_di_write(ipu, clk->id, (div / 16) << 16, DI_BS_CLKGEN1);
114 static int _ipu_pixel_clk_enable(struct clk *clk)
116 struct ipu_soc *ipu = pixelclk2ipu(clk);
117 u32 disp_gen = ipu_cm_read(ipu, IPU_DISP_GEN);
118 disp_gen |= clk->id ? DI1_COUNTER_RELEASE : DI0_COUNTER_RELEASE;
119 ipu_cm_write(ipu, disp_gen, IPU_DISP_GEN);
124 static void _ipu_pixel_clk_disable(struct clk *clk)
126 struct ipu_soc *ipu = pixelclk2ipu(clk);
128 u32 disp_gen = ipu_cm_read(ipu, IPU_DISP_GEN);
129 disp_gen &= clk->id ? ~DI1_COUNTER_RELEASE : ~DI0_COUNTER_RELEASE;
130 ipu_cm_write(ipu, disp_gen, IPU_DISP_GEN);
133 static int _ipu_pixel_clk_set_parent(struct clk *clk, struct clk *parent)
135 struct ipu_soc *ipu = pixelclk2ipu(clk);
138 di_gen = ipu_di_read(ipu, clk->id, DI_GENERAL);
139 if (parent == ipu->ipu_clk)
140 di_gen &= ~DI_GEN_DI_CLK_EXT;
141 else if (!IS_ERR(ipu->di_clk[clk->id]) && parent == ipu->di_clk[clk->id])
142 di_gen |= DI_GEN_DI_CLK_EXT;
147 ipu_di_write(ipu, clk->id, di_gen, DI_GENERAL);
151 #ifdef CONFIG_CLK_DEBUG
152 #define __INIT_CLK_DEBUG(n) .name = #n,
154 #define __INIT_CLK_DEBUG(n)
156 struct clk ipu_pixel_clk[] = {
158 __INIT_CLK_DEBUG(pixel_clk_0)
160 .get_rate = _ipu_pixel_clk_get_rate,
161 .set_rate = _ipu_pixel_clk_set_rate,
162 .round_rate = _ipu_pixel_clk_round_rate,
163 .set_parent = _ipu_pixel_clk_set_parent,
164 .enable = _ipu_pixel_clk_enable,
165 .disable = _ipu_pixel_clk_disable,
168 __INIT_CLK_DEBUG(pixel_clk_1)
170 .get_rate = _ipu_pixel_clk_get_rate,
171 .set_rate = _ipu_pixel_clk_set_rate,
172 .round_rate = _ipu_pixel_clk_round_rate,
173 .set_parent = _ipu_pixel_clk_set_parent,
174 .enable = _ipu_pixel_clk_enable,
175 .disable = _ipu_pixel_clk_disable,
179 struct clk_lookup ipu_lookups[MXC_IPU_MAX_NUM][2] = {
182 .con_id = "pixel_clk_0",
185 .con_id = "pixel_clk_1",
190 .con_id = "pixel_clk_0",
193 .con_id = "pixel_clk_1",
200 void _ipu_dmfc_init(struct ipu_soc *ipu, int dmfc_type, int first)
202 u32 dmfc_wr_chan, dmfc_dp_chan;
205 if (dmfc_type_setup > dmfc_type)
206 dmfc_type = dmfc_type_setup;
208 dmfc_type_setup = dmfc_type;
210 /* disable DMFC-IC channel*/
211 ipu_dmfc_write(ipu, 0x2, DMFC_IC_CTRL);
212 } else if (dmfc_type_setup >= DMFC_HIGH_RESOLUTION_DC) {
213 dev_dbg(ipu->dev, "DMFC high resolution has set, will not change\n");
216 dmfc_type_setup = dmfc_type;
218 if (dmfc_type == DMFC_HIGH_RESOLUTION_DC) {
220 * 5B - segement 4, 5;
221 * 5F - segement 6, 7;
222 * 1C, 2C and 6B, 6F unused;
224 dev_info(ipu->dev, "IPU DMFC DC HIGH RESOLUTION: 1(0~3), 5B(4,5), 5F(6,7)\n");
225 dmfc_wr_chan = 0x00000088;
226 dmfc_dp_chan = 0x00009694;
227 ipu->dmfc_size_28 = 256*4;
228 ipu->dmfc_size_29 = 0;
229 ipu->dmfc_size_24 = 0;
230 ipu->dmfc_size_27 = 128*4;
231 ipu->dmfc_size_23 = 128*4;
232 } else if (dmfc_type == DMFC_HIGH_RESOLUTION_DP) {
236 * 1C, 2C and 6B, 6F unused;
238 dev_info(ipu->dev, "IPU DMFC DP HIGH RESOLUTION: 1(0,1), 5B(2~5), 5F(6,7)\n");
239 dmfc_wr_chan = 0x00000090;
240 dmfc_dp_chan = 0x0000968a;
241 ipu->dmfc_size_28 = 128*4;
242 ipu->dmfc_size_29 = 0;
243 ipu->dmfc_size_24 = 0;
244 ipu->dmfc_size_27 = 128*4;
245 ipu->dmfc_size_23 = 256*4;
246 } else if (dmfc_type == DMFC_HIGH_RESOLUTION_ONLY_DP) {
247 /* 5B - segement 0~3;
249 * 1, 1C, 2C and 6B, 6F unused;
251 dev_info(ipu->dev, "IPU DMFC ONLY-DP HIGH RESOLUTION: 5B(0~3), 5F(4~7)\n");
252 dmfc_wr_chan = 0x00000000;
253 dmfc_dp_chan = 0x00008c88;
254 ipu->dmfc_size_28 = 0;
255 ipu->dmfc_size_29 = 0;
256 ipu->dmfc_size_24 = 0;
257 ipu->dmfc_size_27 = 256*4;
258 ipu->dmfc_size_23 = 256*4;
261 * 5B - segement 4, 5;
262 * 5F - segement 6, 7;
263 * 1C, 2C and 6B, 6F unused;
265 dev_info(ipu->dev, "IPU DMFC NORMAL mode: 1(0~1), 5B(4,5), 5F(6,7)\n");
266 dmfc_wr_chan = 0x00000090;
267 dmfc_dp_chan = 0x00009694;
268 ipu->dmfc_size_28 = 128*4;
269 ipu->dmfc_size_29 = 0;
270 ipu->dmfc_size_24 = 0;
271 ipu->dmfc_size_27 = 128*4;
272 ipu->dmfc_size_23 = 128*4;
274 ipu_dmfc_write(ipu, dmfc_wr_chan, DMFC_WR_CHAN);
275 ipu_dmfc_write(ipu, 0x202020F6, DMFC_WR_CHAN_DEF);
276 ipu_dmfc_write(ipu, dmfc_dp_chan, DMFC_DP_CHAN);
277 /* Enable chan 5 watermark set at 5 bursts and clear at 7 bursts */
278 ipu_dmfc_write(ipu, 0x2020F6F6, DMFC_DP_CHAN_DEF);
281 static int __init dmfc_setup(char *options)
283 get_option(&options, &dmfc_type_setup);
284 if (dmfc_type_setup > DMFC_HIGH_RESOLUTION_ONLY_DP)
285 dmfc_type_setup = DMFC_HIGH_RESOLUTION_ONLY_DP;
288 __setup("dmfc=", dmfc_setup);
290 void _ipu_dmfc_set_wait4eot(struct ipu_soc *ipu, int dma_chan, int width)
292 u32 dmfc_gen1 = ipu_dmfc_read(ipu, DMFC_GENERAL1);
294 if (width >= HIGH_RESOLUTION_WIDTH) {
296 _ipu_dmfc_init(ipu, DMFC_HIGH_RESOLUTION_DP, 0);
297 else if (dma_chan == 28)
298 _ipu_dmfc_init(ipu, DMFC_HIGH_RESOLUTION_DC, 0);
301 if (dma_chan == 23) { /*5B*/
302 if (ipu->dmfc_size_23/width > 3)
303 dmfc_gen1 |= 1UL << 20;
305 dmfc_gen1 &= ~(1UL << 20);
306 } else if (dma_chan == 24) { /*6B*/
307 if (ipu->dmfc_size_24/width > 1)
308 dmfc_gen1 |= 1UL << 22;
310 dmfc_gen1 &= ~(1UL << 22);
311 } else if (dma_chan == 27) { /*5F*/
312 if (ipu->dmfc_size_27/width > 2)
313 dmfc_gen1 |= 1UL << 21;
315 dmfc_gen1 &= ~(1UL << 21);
316 } else if (dma_chan == 28) { /*1*/
317 if (ipu->dmfc_size_28/width > 2)
318 dmfc_gen1 |= 1UL << 16;
320 dmfc_gen1 &= ~(1UL << 16);
321 } else if (dma_chan == 29) { /*6F*/
322 if (ipu->dmfc_size_29/width > 1)
323 dmfc_gen1 |= 1UL << 23;
325 dmfc_gen1 &= ~(1UL << 23);
328 ipu_dmfc_write(ipu, dmfc_gen1, DMFC_GENERAL1);
331 void _ipu_dmfc_set_burst_size(struct ipu_soc *ipu, int dma_chan, int burst_size)
333 u32 dmfc_wr_chan = ipu_dmfc_read(ipu, DMFC_WR_CHAN);
334 u32 dmfc_dp_chan = ipu_dmfc_read(ipu, DMFC_DP_CHAN);
337 switch (burst_size) {
349 dev_err(ipu->dev, "Unsupported burst size %d\n",
354 if (dma_chan == 23) { /*5B*/
355 dmfc_dp_chan &= ~(0xc0);
356 dmfc_dp_chan |= dmfc_bs;
357 } else if (dma_chan == 27) { /*5F*/
358 dmfc_dp_chan &= ~(0xc000);
359 dmfc_dp_chan |= (dmfc_bs << 8);
360 } else if (dma_chan == 28) { /*1*/
361 dmfc_wr_chan &= ~(0xc0);
362 dmfc_wr_chan |= dmfc_bs;
365 ipu_dmfc_write(ipu, dmfc_wr_chan, DMFC_WR_CHAN);
366 ipu_dmfc_write(ipu, dmfc_dp_chan, DMFC_DP_CHAN);
369 static void _ipu_di_data_wave_config(struct ipu_soc *ipu,
370 int di, int wave_gen,
371 int access_size, int component_size)
374 reg = (access_size << DI_DW_GEN_ACCESS_SIZE_OFFSET) |
375 (component_size << DI_DW_GEN_COMPONENT_SIZE_OFFSET);
376 ipu_di_write(ipu, di, reg, DI_DW_GEN(wave_gen));
379 static void _ipu_di_data_pin_config(struct ipu_soc *ipu,
380 int di, int wave_gen, int di_pin, int set,
385 reg = ipu_di_read(ipu, di, DI_DW_GEN(wave_gen));
386 reg &= ~(0x3 << (di_pin * 2));
387 reg |= set << (di_pin * 2);
388 ipu_di_write(ipu, di, reg, DI_DW_GEN(wave_gen));
390 ipu_di_write(ipu, di, (down << 16) | up, DI_DW_SET(wave_gen, set));
393 static void _ipu_di_sync_config(struct ipu_soc *ipu,
394 int di, int wave_gen,
395 int run_count, int run_src,
396 int offset_count, int offset_src,
397 int repeat_count, int cnt_clr_src,
398 int cnt_polarity_gen_en,
399 int cnt_polarity_clr_src,
400 int cnt_polarity_trigger_src,
401 int cnt_up, int cnt_down)
405 if ((run_count >= 0x1000) || (offset_count >= 0x1000) || (repeat_count >= 0x1000) ||
406 (cnt_up >= 0x400) || (cnt_down >= 0x400)) {
407 dev_err(ipu->dev, "DI%d counters out of range.\n", di);
411 reg = (run_count << 19) | (++run_src << 16) |
412 (offset_count << 3) | ++offset_src;
413 ipu_di_write(ipu, di, reg, DI_SW_GEN0(wave_gen));
414 reg = (cnt_polarity_gen_en << 29) | (++cnt_clr_src << 25) |
415 (++cnt_polarity_trigger_src << 12) | (++cnt_polarity_clr_src << 9);
416 reg |= (cnt_down << 16) | cnt_up;
417 if (repeat_count == 0) {
418 /* Enable auto reload */
421 ipu_di_write(ipu, di, reg, DI_SW_GEN1(wave_gen));
422 reg = ipu_di_read(ipu, di, DI_STP_REP(wave_gen));
423 reg &= ~(0xFFFF << (16 * ((wave_gen - 1) & 0x1)));
424 reg |= repeat_count << (16 * ((wave_gen - 1) & 0x1));
425 ipu_di_write(ipu, di, reg, DI_STP_REP(wave_gen));
428 static void _ipu_dc_map_link(struct ipu_soc *ipu,
430 int base_map_0, int buf_num_0,
431 int base_map_1, int buf_num_1,
432 int base_map_2, int buf_num_2)
434 int ptr_0 = base_map_0 * 3 + buf_num_0;
435 int ptr_1 = base_map_1 * 3 + buf_num_1;
436 int ptr_2 = base_map_2 * 3 + buf_num_2;
439 ptr = (ptr_2 << 10) + (ptr_1 << 5) + ptr_0;
441 reg = ipu_dc_read(ipu, DC_MAP_CONF_PTR(current_map));
442 reg &= ~(0x1F << ((16 * (current_map & 0x1))));
443 reg |= ptr << ((16 * (current_map & 0x1)));
444 ipu_dc_write(ipu, reg, DC_MAP_CONF_PTR(current_map));
447 static void _ipu_dc_map_config(struct ipu_soc *ipu,
448 int map, int byte_num, int offset, int mask)
450 int ptr = map * 3 + byte_num;
453 reg = ipu_dc_read(ipu, DC_MAP_CONF_VAL(ptr));
454 reg &= ~(0xFFFF << (16 * (ptr & 0x1)));
455 reg |= ((offset << 8) | mask) << (16 * (ptr & 0x1));
456 ipu_dc_write(ipu, reg, DC_MAP_CONF_VAL(ptr));
458 reg = ipu_dc_read(ipu, DC_MAP_CONF_PTR(map));
459 reg &= ~(0x1F << ((16 * (map & 0x1)) + (5 * byte_num)));
460 reg |= ptr << ((16 * (map & 0x1)) + (5 * byte_num));
461 ipu_dc_write(ipu, reg, DC_MAP_CONF_PTR(map));
464 static void _ipu_dc_map_clear(struct ipu_soc *ipu, int map)
466 u32 reg = ipu_dc_read(ipu, DC_MAP_CONF_PTR(map));
467 ipu_dc_write(ipu, reg & ~(0xFFFF << (16 * (map & 0x1))),
468 DC_MAP_CONF_PTR(map));
471 static void _ipu_dc_write_tmpl(struct ipu_soc *ipu,
472 int word, u32 opcode, u32 operand, int map,
473 int wave, int glue, int sync, int stop)
480 reg |= (++wave << 11);
481 reg |= ((operand & 0x1FFFF) << 15);
482 ipu_dc_tmpl_write(ipu, reg, word * 2);
484 reg = (operand >> 17);
487 ipu_dc_tmpl_write(ipu, reg, word * 2 + 1);
491 reg |= (++wave << 11);
492 reg |= (++map << 15);
493 reg |= (operand << 20) & 0xFFF00000;
494 ipu_dc_tmpl_write(ipu, reg, word * 2);
496 reg = (operand >> 12);
499 ipu_dc_tmpl_write(ipu, reg, word * 2 + 1);
503 static void _ipu_dc_link_event(struct ipu_soc *ipu,
504 int chan, int event, int addr, int priority)
508 if (event < DC_EVEN_UGDE0) {
509 reg = ipu_dc_read(ipu, DC_RL_CH(chan, event));
510 reg &= ~(0xFFFF << (16 * (event & 0x1)));
511 reg |= ((addr << 8) | priority) << (16 * (event & 0x1));
512 ipu_dc_write(ipu, reg, DC_RL_CH(chan, event));
514 reg = ipu_dc_read(ipu, DC_UGDE_0((event - DC_EVEN_UGDE0) / 2));
515 if ((event - DC_EVEN_UGDE0) & 0x1) {
516 reg &= ~(0x2FF << 16);
518 reg |= priority ? (2 << 24) : 0x0;
523 ((((chan & 0x1) + ((chan & 0x2) >> 1))) | (chan >> 3));
526 address_shift = ((event - DC_EVEN_UGDE0) >> 1) ? 7 : 8;
527 reg |= (addr << address_shift) | (priority << 3) | chan;
529 ipu_dc_write(ipu, reg, DC_UGDE_0((event - DC_EVEN_UGDE0) / 2));
533 /* Y = R * 1.200 + G * 2.343 + B * .453 + 0.250;
534 U = R * -.672 + G * -1.328 + B * 2.000 + 512.250.;
535 V = R * 2.000 + G * -1.672 + B * -.328 + 512.250.;*/
536 static const int rgb2ycbcr_coeff[5][3] = {
538 {-0x2B, -0x55, 0x80},
539 {0x80, -0x6B, -0x15},
540 {0x0000, 0x0200, 0x0200}, /* B0, B1, B2 */
541 {0x2, 0x2, 0x2}, /* S0, S1, S2 */
544 /* R = (1.164 * (Y - 16)) + (1.596 * (Cr - 128));
545 G = (1.164 * (Y - 16)) - (0.392 * (Cb - 128)) - (0.813 * (Cr - 128));
546 B = (1.164 * (Y - 16)) + (2.017 * (Cb - 128); */
547 static const int ycbcr2rgb_coeff[5][3] = {
548 {0x095, 0x000, 0x0CC},
549 {0x095, 0x3CE, 0x398},
550 {0x095, 0x0FF, 0x000},
551 {0x3E42, 0x010A, 0x3DD6}, /*B0,B1,B2 */
552 {0x1, 0x1, 0x1}, /*S0,S1,S2 */
555 #define mask_a(a) ((u32)(a) & 0x3FF)
556 #define mask_b(b) ((u32)(b) & 0x3FFF)
558 /* Pls keep S0, S1 and S2 as 0x2 by using this convertion */
559 static int _rgb_to_yuv(int n, int red, int green, int blue)
562 c = red * rgb2ycbcr_coeff[n][0];
563 c += green * rgb2ycbcr_coeff[n][1];
564 c += blue * rgb2ycbcr_coeff[n][2];
566 c += rgb2ycbcr_coeff[3][n] * 4;
577 * Row is for BG: RGB2YUV YUV2RGB RGB2RGB YUV2YUV CSC_NONE
578 * Column is for FG: RGB2YUV YUV2RGB RGB2RGB YUV2YUV CSC_NONE
580 static struct dp_csc_param_t dp_csc_array[CSC_NUM][CSC_NUM] = {
581 {{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} },
582 {{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} },
583 {{0, 0}, {DP_COM_CONF_CSC_DEF_FG, &ycbcr2rgb_coeff}, {0, 0}, {0, 0}, {0, 0} },
584 {{DP_COM_CONF_CSC_DEF_FG, &rgb2ycbcr_coeff}, {0, 0}, {0, 0}, {0, 0}, {0, 0} },
585 {{DP_COM_CONF_CSC_DEF_FG, &rgb2ycbcr_coeff}, {DP_COM_CONF_CSC_DEF_FG, &ycbcr2rgb_coeff}, {0, 0}, {0, 0}, {0, 0} }
588 void __ipu_dp_csc_setup(struct ipu_soc *ipu,
589 int dp, struct dp_csc_param_t dp_csc_param,
590 bool srm_mode_update)
593 const int (*coeff)[5][3];
595 if (dp_csc_param.mode >= 0) {
596 reg = ipu_dp_read(ipu, DP_COM_CONF(dp));
597 reg &= ~DP_COM_CONF_CSC_DEF_MASK;
598 reg |= dp_csc_param.mode;
599 ipu_dp_write(ipu, reg, DP_COM_CONF(dp));
602 coeff = dp_csc_param.coeff;
605 ipu_dp_write(ipu, mask_a((*coeff)[0][0]) |
606 (mask_a((*coeff)[0][1]) << 16), DP_CSC_A_0(dp));
607 ipu_dp_write(ipu, mask_a((*coeff)[0][2]) |
608 (mask_a((*coeff)[1][0]) << 16), DP_CSC_A_1(dp));
609 ipu_dp_write(ipu, mask_a((*coeff)[1][1]) |
610 (mask_a((*coeff)[1][2]) << 16), DP_CSC_A_2(dp));
611 ipu_dp_write(ipu, mask_a((*coeff)[2][0]) |
612 (mask_a((*coeff)[2][1]) << 16), DP_CSC_A_3(dp));
613 ipu_dp_write(ipu, mask_a((*coeff)[2][2]) |
614 (mask_b((*coeff)[3][0]) << 16) |
615 ((*coeff)[4][0] << 30), DP_CSC_0(dp));
616 ipu_dp_write(ipu, mask_b((*coeff)[3][1]) | ((*coeff)[4][1] << 14) |
617 (mask_b((*coeff)[3][2]) << 16) |
618 ((*coeff)[4][2] << 30), DP_CSC_1(dp));
621 if (srm_mode_update) {
622 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
623 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
627 int _ipu_dp_init(struct ipu_soc *ipu,
628 ipu_channel_t channel, uint32_t in_pixel_fmt,
629 uint32_t out_pixel_fmt)
636 if (channel == MEM_FG_SYNC) {
639 } else if (channel == MEM_BG_SYNC) {
642 } else if (channel == MEM_BG_ASYNC0) {
649 in_fmt = format_to_colorspace(in_pixel_fmt);
650 out_fmt = format_to_colorspace(out_pixel_fmt);
655 ipu->fg_csc_type = RGB2RGB;
657 ipu->fg_csc_type = RGB2YUV;
660 ipu->fg_csc_type = YUV2RGB;
662 ipu->fg_csc_type = YUV2YUV;
667 ipu->bg_csc_type = RGB2RGB;
669 ipu->bg_csc_type = RGB2YUV;
672 ipu->bg_csc_type = YUV2RGB;
674 ipu->bg_csc_type = YUV2YUV;
678 /* Transform color key from rgb to yuv if CSC is enabled */
679 reg = ipu_dp_read(ipu, DP_COM_CONF(dp));
680 if (ipu->color_key_4rgb && (reg & DP_COM_CONF_GWCKE) &&
681 (((ipu->fg_csc_type == RGB2YUV) && (ipu->bg_csc_type == YUV2YUV)) ||
682 ((ipu->fg_csc_type == YUV2YUV) && (ipu->bg_csc_type == RGB2YUV)) ||
683 ((ipu->fg_csc_type == YUV2YUV) && (ipu->bg_csc_type == YUV2YUV)) ||
684 ((ipu->fg_csc_type == YUV2RGB) && (ipu->bg_csc_type == YUV2RGB)))) {
685 int red, green, blue;
687 uint32_t color_key = ipu_dp_read(ipu, DP_GRAPH_WIND_CTRL(dp)) & 0xFFFFFFL;
689 dev_dbg(ipu->dev, "_ipu_dp_init color key 0x%x need change to yuv fmt!\n", color_key);
691 red = (color_key >> 16) & 0xFF;
692 green = (color_key >> 8) & 0xFF;
693 blue = color_key & 0xFF;
695 y = _rgb_to_yuv(0, red, green, blue);
696 u = _rgb_to_yuv(1, red, green, blue);
697 v = _rgb_to_yuv(2, red, green, blue);
698 color_key = (y << 16) | (u << 8) | v;
700 reg = ipu_dp_read(ipu, DP_GRAPH_WIND_CTRL(dp)) & 0xFF000000L;
701 ipu_dp_write(ipu, reg | color_key, DP_GRAPH_WIND_CTRL(dp));
702 ipu->color_key_4rgb = false;
704 dev_dbg(ipu->dev, "_ipu_dp_init color key change to yuv fmt 0x%x!\n", color_key);
707 __ipu_dp_csc_setup(ipu, dp, dp_csc_array[ipu->bg_csc_type][ipu->fg_csc_type], true);
712 void _ipu_dp_uninit(struct ipu_soc *ipu, ipu_channel_t channel)
717 if (channel == MEM_FG_SYNC) {
720 } else if (channel == MEM_BG_SYNC) {
723 } else if (channel == MEM_BG_ASYNC0) {
731 ipu->fg_csc_type = CSC_NONE;
733 ipu->bg_csc_type = CSC_NONE;
735 __ipu_dp_csc_setup(ipu, dp, dp_csc_array[ipu->bg_csc_type][ipu->fg_csc_type], false);
738 void _ipu_dc_init(struct ipu_soc *ipu, int dc_chan, int di, bool interlaced, uint32_t pixel_fmt)
742 if ((dc_chan == 1) || (dc_chan == 5)) {
744 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NL, 0, 3);
745 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOL, 0, 2);
746 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA, 0, 1);
749 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NL, 2, 3);
750 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOL, 3, 2);
751 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA, 4, 1);
752 if ((pixel_fmt == IPU_PIX_FMT_YUYV) ||
753 (pixel_fmt == IPU_PIX_FMT_UYVY) ||
754 (pixel_fmt == IPU_PIX_FMT_YVYU) ||
755 (pixel_fmt == IPU_PIX_FMT_VYUY)) {
756 _ipu_dc_link_event(ipu, dc_chan, DC_ODD_UGDE1, 9, 5);
757 _ipu_dc_link_event(ipu, dc_chan, DC_EVEN_UGDE1, 8, 5);
760 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NL, 5, 3);
761 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOL, 6, 2);
762 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA, 7, 1);
763 if ((pixel_fmt == IPU_PIX_FMT_YUYV) ||
764 (pixel_fmt == IPU_PIX_FMT_UYVY) ||
765 (pixel_fmt == IPU_PIX_FMT_YVYU) ||
766 (pixel_fmt == IPU_PIX_FMT_VYUY)) {
767 _ipu_dc_link_event(ipu, dc_chan, DC_ODD_UGDE0, 10, 5);
768 _ipu_dc_link_event(ipu, dc_chan, DC_EVEN_UGDE0, 11, 5);
772 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NF, 0, 0);
773 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NFIELD, 0, 0);
774 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOF, 0, 0);
775 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOFIELD, 0, 0);
776 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN, 0, 0);
777 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR, 0, 0);
780 reg |= DC_DISP_ID_SYNC(di) << DC_WR_CH_CONF_PROG_DISP_ID_OFFSET;
783 reg |= DC_WR_CH_CONF_FIELD_MODE;
784 } else if ((dc_chan == 8) || (dc_chan == 9)) {
786 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_W_0, 0x64, 1);
787 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_W_1, 0x64, 1);
790 reg |= DC_DISP_ID_SERIAL << DC_WR_CH_CONF_PROG_DISP_ID_OFFSET;
792 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(dc_chan));
794 ipu_dc_write(ipu, 0x00000000, DC_WR_CH_ADDR(dc_chan));
796 ipu_dc_write(ipu, 0x00000084, DC_GEN);
799 void _ipu_dc_uninit(struct ipu_soc *ipu, int dc_chan)
801 if ((dc_chan == 1) || (dc_chan == 5)) {
802 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NL, 0, 0);
803 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOL, 0, 0);
804 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA, 0, 0);
805 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NF, 0, 0);
806 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NFIELD, 0, 0);
807 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOF, 0, 0);
808 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_EOFIELD, 0, 0);
809 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN, 0, 0);
810 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR, 0, 0);
811 _ipu_dc_link_event(ipu, dc_chan, DC_ODD_UGDE0, 0, 0);
812 _ipu_dc_link_event(ipu, dc_chan, DC_EVEN_UGDE0, 0, 0);
813 _ipu_dc_link_event(ipu, dc_chan, DC_ODD_UGDE1, 0, 0);
814 _ipu_dc_link_event(ipu, dc_chan, DC_EVEN_UGDE1, 0, 0);
815 } else if ((dc_chan == 8) || (dc_chan == 9)) {
816 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR_W_0, 0, 0);
817 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR_W_1, 0, 0);
818 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN_W_0, 0, 0);
819 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN_W_1, 0, 0);
820 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_W_0, 0, 0);
821 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_W_1, 0, 0);
822 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR_R_0, 0, 0);
823 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_ADDR_R_1, 0, 0);
824 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN_R_0, 0, 0);
825 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_CHAN_R_1, 0, 0);
826 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_R_0, 0, 0);
827 _ipu_dc_link_event(ipu, dc_chan, DC_EVT_NEW_DATA_R_1, 0, 0);
831 int _ipu_disp_chan_is_interlaced(struct ipu_soc *ipu, ipu_channel_t channel)
833 if (channel == MEM_DC_SYNC)
834 return !!(ipu_dc_read(ipu, DC_WR_CH_CONF_1) &
835 DC_WR_CH_CONF_FIELD_MODE);
836 else if ((channel == MEM_BG_SYNC) || (channel == MEM_FG_SYNC))
837 return !!(ipu_dc_read(ipu, DC_WR_CH_CONF_5) &
838 DC_WR_CH_CONF_FIELD_MODE);
842 void _ipu_dp_dc_enable(struct ipu_soc *ipu, ipu_channel_t channel)
849 if (channel == MEM_FG_SYNC)
850 irq = IPU_IRQ_DP_SF_END;
851 else if (channel == MEM_DC_SYNC)
853 else if (channel == MEM_BG_SYNC)
858 if (channel == MEM_FG_SYNC) {
859 /* Enable FG channel */
860 reg = ipu_dp_read(ipu, DP_COM_CONF(DP_SYNC));
861 ipu_dp_write(ipu, reg | DP_COM_CONF_FG_EN, DP_COM_CONF(DP_SYNC));
863 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
864 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
868 di = ipu->dc_di_assignment[dc_chan];
870 /* Make sure other DC sync channel is not assigned same DI */
871 reg = ipu_dc_read(ipu, DC_WR_CH_CONF(6 - dc_chan));
872 if ((di << 2) == (reg & DC_WR_CH_CONF_PROG_DI_ID)) {
873 reg &= ~DC_WR_CH_CONF_PROG_DI_ID;
874 reg |= di ? 0 : DC_WR_CH_CONF_PROG_DI_ID;
875 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(6 - dc_chan));
878 reg = ipu_dc_read(ipu, DC_WR_CH_CONF(dc_chan));
879 reg |= 4 << DC_WR_CH_CONF_PROG_TYPE_OFFSET;
880 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(dc_chan));
882 clk_enable(&ipu->pixel_clk[di]);
885 static irqreturn_t dc_irq_handler(int irq, void *dev_id)
887 struct ipu_soc *ipu = dev_id;
888 struct completion *comp = &ipu->dc_comp;
892 if (irq == IPU_IRQ_DC_FC_1)
898 reg = ipu_dc_read(ipu, DC_WR_CH_CONF(dc_chan));
899 reg &= ~DC_WR_CH_CONF_PROG_TYPE_MASK;
900 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(dc_chan));
902 reg = ipu_cm_read(ipu, IPU_DISP_GEN);
903 if (ipu->dc_di_assignment[dc_chan])
904 reg &= ~DI1_COUNTER_RELEASE;
906 reg &= ~DI0_COUNTER_RELEASE;
907 ipu_cm_write(ipu, reg, IPU_DISP_GEN);
914 void _ipu_dp_dc_disable(struct ipu_soc *ipu, ipu_channel_t channel, bool swap)
925 if (channel == MEM_DC_SYNC) {
927 irq = IPU_IRQ_DC_FC_1;
928 } else if (channel == MEM_BG_SYNC) {
930 irq = IPU_IRQ_DP_SF_END;
931 } else if (channel == MEM_FG_SYNC) {
932 /* Disable FG channel */
935 reg = ipu_dp_read(ipu, DP_COM_CONF(DP_SYNC));
936 csc = reg & DP_COM_CONF_CSC_DEF_MASK;
937 if (csc == DP_COM_CONF_CSC_DEF_FG)
938 reg &= ~DP_COM_CONF_CSC_DEF_MASK;
940 reg &= ~DP_COM_CONF_FG_EN;
941 ipu_dp_write(ipu, reg, DP_COM_CONF(DP_SYNC));
943 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
944 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
946 if (ipu_is_channel_busy(ipu, MEM_BG_SYNC)) {
947 ipu_cm_write(ipu, IPUIRQ_2_MASK(IPU_IRQ_DP_SF_END),
948 IPUIRQ_2_STATREG(IPU_IRQ_DP_SF_END));
949 while ((ipu_cm_read(ipu, IPUIRQ_2_STATREG(IPU_IRQ_DP_SF_END)) &
950 IPUIRQ_2_MASK(IPU_IRQ_DP_SF_END)) == 0) {
962 init_completion(&ipu->dc_comp);
963 ret = ipu_request_irq(ipu, irq, dc_irq_handler, 0, NULL, ipu);
965 dev_err(ipu->dev, "DC irq %d in use\n", irq);
968 ret = wait_for_completion_timeout(&ipu->dc_comp, msecs_to_jiffies(50));
969 ipu_free_irq(ipu, irq, ipu);
970 dev_dbg(ipu->dev, "DC stop timeout - %d * 10ms\n", 5 - ret);
973 /* Swap DC channel 1 and 5 settings, and disable old dc chan */
974 reg = ipu_dc_read(ipu, DC_WR_CH_CONF(dc_chan));
975 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(6 - dc_chan));
976 reg &= ~DC_WR_CH_CONF_PROG_TYPE_MASK;
977 reg ^= DC_WR_CH_CONF_PROG_DI_ID;
978 ipu_dc_write(ipu, reg, DC_WR_CH_CONF(dc_chan));
980 /* Clock is already off because it must be done quickly, but
981 we need to fix the ref count */
982 clk_disable(&ipu->pixel_clk[ipu->dc_di_assignment[dc_chan]]);
985 void _ipu_init_dc_mappings(struct ipu_soc *ipu)
987 /* IPU_PIX_FMT_RGB24 */
988 _ipu_dc_map_clear(ipu, 0);
989 _ipu_dc_map_config(ipu, 0, 0, 7, 0xFF);
990 _ipu_dc_map_config(ipu, 0, 1, 15, 0xFF);
991 _ipu_dc_map_config(ipu, 0, 2, 23, 0xFF);
993 /* IPU_PIX_FMT_RGB666 */
994 _ipu_dc_map_clear(ipu, 1);
995 _ipu_dc_map_config(ipu, 1, 0, 5, 0xFC);
996 _ipu_dc_map_config(ipu, 1, 1, 11, 0xFC);
997 _ipu_dc_map_config(ipu, 1, 2, 17, 0xFC);
999 /* IPU_PIX_FMT_YUV444 */
1000 _ipu_dc_map_clear(ipu, 2);
1001 _ipu_dc_map_config(ipu, 2, 0, 15, 0xFF);
1002 _ipu_dc_map_config(ipu, 2, 1, 23, 0xFF);
1003 _ipu_dc_map_config(ipu, 2, 2, 7, 0xFF);
1005 /* IPU_PIX_FMT_RGB565 */
1006 _ipu_dc_map_clear(ipu, 3);
1007 _ipu_dc_map_config(ipu, 3, 0, 4, 0xF8);
1008 _ipu_dc_map_config(ipu, 3, 1, 10, 0xFC);
1009 _ipu_dc_map_config(ipu, 3, 2, 15, 0xF8);
1011 /* IPU_PIX_FMT_LVDS666 */
1012 _ipu_dc_map_clear(ipu, 4);
1013 _ipu_dc_map_config(ipu, 4, 0, 5, 0xFC);
1014 _ipu_dc_map_config(ipu, 4, 1, 13, 0xFC);
1015 _ipu_dc_map_config(ipu, 4, 2, 21, 0xFC);
1017 /* IPU_PIX_FMT_VYUY 16bit width */
1018 _ipu_dc_map_clear(ipu, 5);
1019 _ipu_dc_map_config(ipu, 5, 0, 7, 0xFF);
1020 _ipu_dc_map_config(ipu, 5, 1, 0, 0x0);
1021 _ipu_dc_map_config(ipu, 5, 2, 15, 0xFF);
1022 _ipu_dc_map_clear(ipu, 6);
1023 _ipu_dc_map_config(ipu, 6, 0, 0, 0x0);
1024 _ipu_dc_map_config(ipu, 6, 1, 7, 0xFF);
1025 _ipu_dc_map_config(ipu, 6, 2, 15, 0xFF);
1027 /* IPU_PIX_FMT_UYUV 16bit width */
1028 _ipu_dc_map_clear(ipu, 7);
1029 _ipu_dc_map_link(ipu, 7, 6, 0, 6, 1, 6, 2);
1030 _ipu_dc_map_clear(ipu, 8);
1031 _ipu_dc_map_link(ipu, 8, 5, 0, 5, 1, 5, 2);
1033 /* IPU_PIX_FMT_YUYV 16bit width */
1034 _ipu_dc_map_clear(ipu, 9);
1035 _ipu_dc_map_link(ipu, 9, 5, 2, 5, 1, 5, 0);
1036 _ipu_dc_map_clear(ipu, 10);
1037 _ipu_dc_map_link(ipu, 10, 5, 1, 5, 2, 5, 0);
1039 /* IPU_PIX_FMT_YVYU 16bit width */
1040 _ipu_dc_map_clear(ipu, 11);
1041 _ipu_dc_map_link(ipu, 11, 5, 1, 5, 2, 5, 0);
1042 _ipu_dc_map_clear(ipu, 12);
1043 _ipu_dc_map_link(ipu, 12, 5, 2, 5, 1, 5, 0);
1045 /* IPU_PIX_FMT_GBR24 */
1046 /* IPU_PIX_FMT_VYU444 */
1047 _ipu_dc_map_clear(ipu, 13);
1048 _ipu_dc_map_link(ipu, 13, 0, 2, 0, 0, 0, 1);
1050 /* IPU_PIX_FMT_BGR24 */
1051 _ipu_dc_map_clear(ipu, 14);
1052 _ipu_dc_map_link(ipu, 14, 0, 2, 0, 1, 0, 0);
1055 int _ipu_pixfmt_to_map(uint32_t fmt)
1058 case IPU_PIX_FMT_GENERIC:
1059 case IPU_PIX_FMT_RGB24:
1061 case IPU_PIX_FMT_RGB666:
1063 case IPU_PIX_FMT_YUV444:
1065 case IPU_PIX_FMT_RGB565:
1067 case IPU_PIX_FMT_LVDS666:
1069 case IPU_PIX_FMT_VYUY:
1071 case IPU_PIX_FMT_UYVY:
1073 case IPU_PIX_FMT_YUYV:
1075 case IPU_PIX_FMT_YVYU:
1077 case IPU_PIX_FMT_GBR24:
1078 case IPU_PIX_FMT_VYU444:
1080 case IPU_PIX_FMT_BGR24:
1088 * This function sets the colorspace for of dp.
1091 * @param ipu ipu handler
1092 * @param channel Input parameter for the logical channel ID.
1094 * @param param If it's not NULL, update the csc table
1095 * with this parameter.
1099 void _ipu_dp_set_csc_coefficients(struct ipu_soc *ipu, ipu_channel_t channel, int32_t param[][3])
1102 struct dp_csc_param_t dp_csc_param;
1104 if (channel == MEM_FG_SYNC)
1106 else if (channel == MEM_BG_SYNC)
1108 else if (channel == MEM_BG_ASYNC0)
1113 dp_csc_param.mode = -1;
1114 dp_csc_param.coeff = param;
1115 __ipu_dp_csc_setup(ipu, dp, dp_csc_param, true);
1118 void ipu_set_csc_coefficients(struct ipu_soc *ipu, ipu_channel_t channel, int32_t param[][3])
1120 _ipu_dp_set_csc_coefficients(ipu, channel, param);
1122 EXPORT_SYMBOL(ipu_set_csc_coefficients);
1125 * This function is called to adapt synchronous LCD panel to IPU restriction.
1128 void adapt_panel_to_ipu_restricitions(struct ipu_soc *ipu, uint16_t *v_start_width,
1129 uint16_t *v_sync_width,
1130 uint16_t *v_end_width)
1132 if (*v_end_width < 2) {
1133 uint16_t diff = 2 - *v_end_width;
1134 if (*v_start_width >= diff) {
1136 *v_start_width = *v_start_width - diff;
1137 } else if (*v_sync_width > diff) {
1139 *v_sync_width = *v_sync_width - diff;
1141 dev_err(ipu->dev, "WARNING: try to adapt timming, but failed\n");
1142 dev_err(ipu->dev, "WARNING: adapt panel end blank lines\n");
1147 * This function is called to initialize a synchronous LCD panel.
1149 * @param ipu ipu handler
1150 * @param disp The DI the panel is attached to.
1152 * @param pixel_clk Desired pixel clock frequency in Hz.
1154 * @param pixel_fmt Input parameter for pixel format of buffer.
1155 * Pixel format is a FOURCC ASCII code.
1157 * @param width The width of panel in pixels.
1159 * @param height The height of panel in pixels.
1161 * @param hStartWidth The number of pixel clocks between the HSYNC
1162 * signal pulse and the start of valid data.
1164 * @param hSyncWidth The width of the HSYNC signal in units of pixel
1167 * @param hEndWidth The number of pixel clocks between the end of
1168 * valid data and the HSYNC signal for next line.
1170 * @param vStartWidth The number of lines between the VSYNC
1171 * signal pulse and the start of valid data.
1173 * @param vSyncWidth The width of the VSYNC signal in units of lines
1175 * @param vEndWidth The number of lines between the end of valid
1176 * data and the VSYNC signal for next frame.
1178 * @param sig Bitfield of signal polarities for LCD interface.
1180 * @return This function returns 0 on success or negative error code on
1183 int32_t ipu_init_sync_panel(struct ipu_soc *ipu, int disp, uint32_t pixel_clk,
1184 uint16_t width, uint16_t height,
1186 uint16_t h_start_width, uint16_t h_sync_width,
1187 uint16_t h_end_width, uint16_t v_start_width,
1188 uint16_t v_sync_width, uint16_t v_end_width,
1189 uint32_t v_to_h_sync, ipu_di_signal_cfg_t sig)
1191 uint32_t field0_offset = 0;
1192 uint32_t field1_offset;
1194 uint32_t di_gen, vsync_cnt;
1195 uint32_t div, rounded_pixel_clk, rounded_parent_clk;
1196 uint32_t h_total, v_total;
1198 struct clk *di_parent;
1200 dev_dbg(ipu->dev, "panel size = %d x %d\n", width, height);
1202 if ((v_sync_width == 0) || (h_sync_width == 0))
1205 adapt_panel_to_ipu_restricitions(ipu, &v_start_width, &v_sync_width, &v_end_width);
1206 h_total = width + h_sync_width + h_start_width + h_end_width;
1207 v_total = height + v_sync_width + v_start_width + v_end_width;
1210 dev_dbg(ipu->dev, "pixel clk = %d\n", pixel_clk);
1212 di_parent = clk_get_parent(ipu->di_clk[disp]);
1213 if (clk_get(NULL, "tve_clk") == di_parent ||
1214 clk_get(NULL, "ldb_di0_clk") == di_parent ||
1215 clk_get(NULL, "ldb_di1_clk") == di_parent) {
1216 /* if di clk parent is tve/ldb, then keep it;*/
1217 dev_dbg(ipu->dev, "use special clk parent\n");
1218 clk_set_parent(&ipu->pixel_clk[disp], ipu->di_clk[disp]);
1220 /* try ipu clk first*/
1221 dev_dbg(ipu->dev, "try ipu internal clk\n");
1222 clk_set_parent(&ipu->pixel_clk[disp], ipu->ipu_clk);
1223 rounded_pixel_clk = clk_round_rate(&ipu->pixel_clk[disp], pixel_clk);
1225 * we will only use 1/2 fraction for ipu clk,
1226 * so if the clk rate is not fit, try ext clk.
1229 ((rounded_pixel_clk >= pixel_clk + pixel_clk/200) ||
1230 (rounded_pixel_clk <= pixel_clk - pixel_clk/200))) {
1231 dev_dbg(ipu->dev, "try ipu ext di clk\n");
1232 if (clk_get_usecount(di_parent))
1234 "ext di clk already in use, go back to internal clk\n");
1236 rounded_pixel_clk = pixel_clk * 2;
1237 rounded_parent_clk = clk_round_rate(di_parent,
1239 while (rounded_pixel_clk < rounded_parent_clk) {
1240 /* the max divider from parent to di is 8 */
1241 if (rounded_parent_clk / pixel_clk < 8)
1242 rounded_pixel_clk += pixel_clk * 2;
1244 rounded_pixel_clk *= 2;
1246 clk_set_rate(di_parent, rounded_pixel_clk);
1248 clk_round_rate(ipu->di_clk[disp], pixel_clk);
1249 clk_set_rate(ipu->di_clk[disp], rounded_pixel_clk);
1250 clk_set_parent(&ipu->pixel_clk[disp], ipu->di_clk[disp]);
1254 rounded_pixel_clk = clk_round_rate(&ipu->pixel_clk[disp], pixel_clk);
1255 clk_set_rate(&ipu->pixel_clk[disp], rounded_pixel_clk);
1257 /* Get integer portion of divider */
1258 div = clk_get_rate(clk_get_parent(&ipu->pixel_clk[disp])) / rounded_pixel_clk;
1262 _ipu_di_data_wave_config(ipu, disp, SYNC_WAVE, div - 1, div - 1);
1263 _ipu_di_data_pin_config(ipu, disp, SYNC_WAVE, DI_PIN15, 3, 0, div * 2);
1265 map = _ipu_pixfmt_to_map(pixel_fmt);
1267 dev_dbg(ipu->dev, "IPU_DISP: No MAP\n");
1273 di_gen = ipu_di_read(ipu, disp, DI_GENERAL);
1274 ipu_di_write(ipu, disp,
1275 di_gen & (0x3 << 20), DI_GENERAL);
1277 if (sig.interlaced) {
1278 if (g_ipu_hw_rev >= 2) {
1279 /* Setup internal HSYNC waveform */
1280 _ipu_di_sync_config(ipu,
1283 h_total/2 - 1, /* run count */
1284 DI_SYNC_CLK, /* run_resolution */
1286 DI_SYNC_NONE, /* offset resolution */
1287 0, /* repeat count */
1288 DI_SYNC_NONE, /* CNT_CLR_SEL */
1289 0, /* CNT_POLARITY_GEN_EN */
1290 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1291 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1296 /* Field 1 VSYNC waveform */
1297 _ipu_di_sync_config(ipu,
1300 h_total - 1, /* run count */
1301 DI_SYNC_CLK, /* run_resolution */
1303 DI_SYNC_NONE, /* offset resolution */
1304 0, /* repeat count */
1305 DI_SYNC_NONE, /* CNT_CLR_SEL */
1306 0, /* CNT_POLARITY_GEN_EN */
1307 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1308 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1310 2*div /* COUNT DOWN */
1313 /* Setup internal HSYNC waveform */
1314 _ipu_di_sync_config(ipu,
1317 v_total*2 - 1, /* run count */
1318 DI_SYNC_INT_HSYNC, /* run_resolution */
1320 DI_SYNC_INT_HSYNC, /* offset resolution */
1321 0, /* repeat count */
1322 DI_SYNC_NONE, /* CNT_CLR_SEL */
1323 0, /* CNT_POLARITY_GEN_EN */
1324 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1325 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1327 2*div /* COUNT DOWN */
1330 /* Active Field ? */
1331 _ipu_di_sync_config(ipu,
1334 v_total/2 - 1, /* run count */
1335 DI_SYNC_HSYNC, /* run_resolution */
1336 v_start_width, /* offset */
1337 DI_SYNC_HSYNC, /* offset resolution */
1338 2, /* repeat count */
1339 DI_SYNC_VSYNC, /* CNT_CLR_SEL */
1340 0, /* CNT_POLARITY_GEN_EN */
1341 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1342 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1348 _ipu_di_sync_config(ipu,
1352 DI_SYNC_HSYNC, /* run_resolution */
1354 DI_SYNC_NONE, /* offset resolution */
1355 height/2, /* repeat count */
1356 4, /* CNT_CLR_SEL */
1357 0, /* CNT_POLARITY_GEN_EN */
1358 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1359 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1364 /* Field 0 VSYNC waveform */
1365 _ipu_di_sync_config(ipu,
1368 v_total - 1, /* run count */
1369 DI_SYNC_HSYNC, /* run_resolution */
1371 DI_SYNC_NONE, /* offset resolution */
1372 0, /* repeat count */
1373 DI_SYNC_NONE, /* CNT_CLR_SEL */
1374 0, /* CNT_POLARITY_GEN_EN */
1375 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1376 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1381 /* DC VSYNC waveform */
1383 _ipu_di_sync_config(ipu,
1386 v_total/2 - 1, /* run count */
1387 DI_SYNC_HSYNC, /* run_resolution */
1389 DI_SYNC_HSYNC, /* offset resolution */
1390 2, /* repeat count */
1391 DI_SYNC_VSYNC, /* CNT_CLR_SEL */
1392 0, /* CNT_POLARITY_GEN_EN */
1393 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1394 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1399 /* active pixel waveform */
1400 _ipu_di_sync_config(ipu,
1404 DI_SYNC_CLK, /* run_resolution */
1405 h_start_width, /* offset */
1406 DI_SYNC_CLK, /* offset resolution */
1407 width, /* repeat count */
1408 5, /* CNT_CLR_SEL */
1409 0, /* CNT_POLARITY_GEN_EN */
1410 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1411 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1417 _ipu_di_sync_config(ipu,
1420 v_total - 1, /* run count */
1421 DI_SYNC_INT_HSYNC, /* run_resolution */
1422 v_total/2, /* offset */
1423 DI_SYNC_INT_HSYNC, /* offset resolution */
1424 0, /* repeat count */
1425 DI_SYNC_HSYNC, /* CNT_CLR_SEL */
1426 0, /* CNT_POLARITY_GEN_EN */
1427 DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
1428 DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
1430 2*div /* COUNT DOWN */
1433 /* set gentime select and tag sel */
1434 reg = ipu_di_read(ipu, disp, DI_SW_GEN1(9));
1436 reg |= (3-1)<<29 | 0x00008000;
1437 ipu_di_write(ipu, disp, reg, DI_SW_GEN1(9));
1439 ipu_di_write(ipu, disp, v_total / 2 - 1, DI_SCR_CONF);
1442 di_gen |= 0x10000000;
1443 di_gen |= DI_GEN_POLARITY_5;
1444 di_gen |= DI_GEN_POLARITY_8;
1446 /* Setup internal HSYNC waveform */
1447 _ipu_di_sync_config(ipu, disp, 1, h_total - 1, DI_SYNC_CLK,
1448 0, DI_SYNC_NONE, 0, DI_SYNC_NONE, 0, DI_SYNC_NONE,
1449 DI_SYNC_NONE, 0, 0);
1451 field1_offset = v_sync_width + v_start_width + height / 2 +
1453 if (sig.odd_field_first) {
1454 field0_offset = field1_offset - 1;
1457 v_total += v_start_width + v_end_width;
1459 /* Field 1 VSYNC waveform */
1460 _ipu_di_sync_config(ipu, disp, 2, v_total - 1, 1,
1462 field0_offset ? 1 : DI_SYNC_NONE,
1464 DI_SYNC_NONE, DI_SYNC_NONE, 0, 4);
1466 /* Setup internal HSYNC waveform */
1467 _ipu_di_sync_config(ipu, disp, 3, h_total - 1, DI_SYNC_CLK,
1468 0, DI_SYNC_NONE, 0, DI_SYNC_NONE, 0,
1469 DI_SYNC_NONE, DI_SYNC_NONE, 0, 4);
1471 /* Active Field ? */
1472 _ipu_di_sync_config(ipu, disp, 4,
1474 field0_offset : field1_offset - 2,
1475 1, v_start_width + v_sync_width, 1, 2, 2,
1476 0, DI_SYNC_NONE, DI_SYNC_NONE, 0, 0);
1479 _ipu_di_sync_config(ipu, disp, 5, 0, 1,
1481 height / 2, 4, 0, DI_SYNC_NONE,
1482 DI_SYNC_NONE, 0, 0);
1484 /* Field 0 VSYNC waveform */
1485 _ipu_di_sync_config(ipu, disp, 6, v_total - 1, 1,
1487 0, DI_SYNC_NONE, 0, DI_SYNC_NONE,
1488 DI_SYNC_NONE, 0, 0);
1490 /* DC VSYNC waveform */
1492 _ipu_di_sync_config(ipu, disp, 7, 0, 1,
1494 field1_offset ? 1 : DI_SYNC_NONE,
1495 1, 2, 0, DI_SYNC_NONE, DI_SYNC_NONE, 0, 0);
1497 /* active pixel waveform */
1498 _ipu_di_sync_config(ipu, disp, 8, 0, DI_SYNC_CLK,
1499 h_sync_width + h_start_width, DI_SYNC_CLK,
1500 width, 5, 0, DI_SYNC_NONE, DI_SYNC_NONE,
1504 _ipu_di_sync_config(ipu, disp, 9, v_total - 1, 2,
1506 0, DI_SYNC_NONE, 6, DI_SYNC_NONE,
1507 DI_SYNC_NONE, 0, 0);
1509 reg = ipu_di_read(ipu, disp, DI_SW_GEN1(9));
1511 ipu_di_write(ipu, disp, reg, DI_SW_GEN1(9));
1513 ipu_di_write(ipu, disp, v_sync_width + v_start_width +
1514 v_end_width + height / 2 - 1, DI_SCR_CONF);
1517 /* Init template microcode */
1518 _ipu_dc_write_tmpl(ipu, 0, WROD(0), 0, map, SYNC_WAVE, 0, 8, 1);
1521 di_gen |= DI_GEN_POLARITY_3;
1523 di_gen |= DI_GEN_POLARITY_2;
1525 /* Setup internal HSYNC waveform */
1526 _ipu_di_sync_config(ipu, disp, 1, h_total - 1, DI_SYNC_CLK,
1527 0, DI_SYNC_NONE, 0, DI_SYNC_NONE, 0, DI_SYNC_NONE,
1528 DI_SYNC_NONE, 0, 0);
1530 /* Setup external (delayed) HSYNC waveform */
1531 _ipu_di_sync_config(ipu, disp, DI_SYNC_HSYNC, h_total - 1,
1532 DI_SYNC_CLK, div * v_to_h_sync, DI_SYNC_CLK,
1533 0, DI_SYNC_NONE, 1, DI_SYNC_NONE,
1534 DI_SYNC_CLK, 0, h_sync_width * 2);
1535 /* Setup VSYNC waveform */
1536 vsync_cnt = DI_SYNC_VSYNC;
1537 _ipu_di_sync_config(ipu, disp, DI_SYNC_VSYNC, v_total - 1,
1538 DI_SYNC_INT_HSYNC, 0, DI_SYNC_NONE, 0,
1539 DI_SYNC_NONE, 1, DI_SYNC_NONE,
1540 DI_SYNC_INT_HSYNC, 0, v_sync_width * 2);
1541 ipu_di_write(ipu, disp, v_total - 1, DI_SCR_CONF);
1543 /* Setup active data waveform to sync with DC */
1544 _ipu_di_sync_config(ipu, disp, 4, 0, DI_SYNC_HSYNC,
1545 v_sync_width + v_start_width, DI_SYNC_HSYNC, height,
1546 DI_SYNC_VSYNC, 0, DI_SYNC_NONE,
1547 DI_SYNC_NONE, 0, 0);
1548 _ipu_di_sync_config(ipu, disp, 5, 0, DI_SYNC_CLK,
1549 h_sync_width + h_start_width, DI_SYNC_CLK,
1550 width, 4, 0, DI_SYNC_NONE, DI_SYNC_NONE, 0,
1553 /* set VGA delayed hsync/vsync no matter VGA enabled */
1555 /* couter 7 for VGA delay HSYNC */
1556 _ipu_di_sync_config(ipu, disp, 7,
1557 h_total - 1, DI_SYNC_CLK,
1560 1, DI_SYNC_NONE, DI_SYNC_CLK,
1561 0, h_sync_width * 2);
1563 /* couter 8 for VGA delay VSYNC */
1564 _ipu_di_sync_config(ipu, disp, 8,
1565 v_total - 1, DI_SYNC_INT_HSYNC,
1566 1, DI_SYNC_INT_HSYNC,
1568 1, DI_SYNC_NONE, DI_SYNC_INT_HSYNC,
1569 0, v_sync_width * 2);
1572 /* reset all unused counters */
1573 ipu_di_write(ipu, disp, 0, DI_SW_GEN0(6));
1574 ipu_di_write(ipu, disp, 0, DI_SW_GEN1(6));
1576 ipu_di_write(ipu, disp, 0, DI_SW_GEN0(7));
1577 ipu_di_write(ipu, disp, 0, DI_SW_GEN1(7));
1578 ipu_di_write(ipu, disp, 0, DI_STP_REP(7));
1579 ipu_di_write(ipu, disp, 0, DI_SW_GEN0(8));
1580 ipu_di_write(ipu, disp, 0, DI_SW_GEN1(8));
1581 ipu_di_write(ipu, disp, 0, DI_STP_REP(8));
1583 ipu_di_write(ipu, disp, 0, DI_SW_GEN0(9));
1584 ipu_di_write(ipu, disp, 0, DI_SW_GEN1(9));
1585 ipu_di_write(ipu, disp, 0, DI_STP_REP(9));
1587 reg = ipu_di_read(ipu, disp, DI_STP_REP(6));
1589 ipu_di_write(ipu, disp, reg, DI_STP_REP(6));
1591 /* Init template microcode */
1593 if ((pixel_fmt == IPU_PIX_FMT_YUYV) ||
1594 (pixel_fmt == IPU_PIX_FMT_UYVY) ||
1595 (pixel_fmt == IPU_PIX_FMT_YVYU) ||
1596 (pixel_fmt == IPU_PIX_FMT_VYUY)) {
1597 _ipu_dc_write_tmpl(ipu, 8, WROD(0), 0, (map - 1), SYNC_WAVE, 0, 5, 1);
1598 _ipu_dc_write_tmpl(ipu, 9, WROD(0), 0, map, SYNC_WAVE, 0, 5, 1);
1599 /* configure user events according to DISP NUM */
1600 ipu_dc_write(ipu, (width - 1), DC_UGDE_3(disp));
1602 _ipu_dc_write_tmpl(ipu, 2, WROD(0), 0, map, SYNC_WAVE, 8, 5, 1);
1603 _ipu_dc_write_tmpl(ipu, 3, WRG, 0, map, SYNC_WAVE, 4, 5, 1);
1604 _ipu_dc_write_tmpl(ipu, 4, WROD(0), 0, map, SYNC_WAVE, 0, 5, 1);
1606 if ((pixel_fmt == IPU_PIX_FMT_YUYV) ||
1607 (pixel_fmt == IPU_PIX_FMT_UYVY) ||
1608 (pixel_fmt == IPU_PIX_FMT_YVYU) ||
1609 (pixel_fmt == IPU_PIX_FMT_VYUY)) {
1610 _ipu_dc_write_tmpl(ipu, 10, WROD(0), 0, (map - 1), SYNC_WAVE, 0, 5, 1);
1611 _ipu_dc_write_tmpl(ipu, 11, WROD(0), 0, map, SYNC_WAVE, 0, 5, 1);
1612 /* configure user events according to DISP NUM */
1613 ipu_dc_write(ipu, width - 1, DC_UGDE_3(disp));
1615 _ipu_dc_write_tmpl(ipu, 5, WROD(0), 0, map, SYNC_WAVE, 8, 5, 1);
1616 _ipu_dc_write_tmpl(ipu, 6, WRG, 0, map, SYNC_WAVE, 4, 5, 1);
1617 _ipu_dc_write_tmpl(ipu, 7, WROD(0), 0, map, SYNC_WAVE, 0, 5, 1);
1620 if (sig.Hsync_pol) {
1621 di_gen |= DI_GEN_POLARITY_2;
1623 di_gen |= DI_GEN_POLARITY_7;
1625 if (sig.Vsync_pol) {
1626 di_gen |= DI_GEN_POLARITY_3;
1628 di_gen |= DI_GEN_POLARITY_8;
1631 /* changinc DISP_CLK polarity: it can be wrong for some applications */
1632 if ((pixel_fmt == IPU_PIX_FMT_YUYV) ||
1633 (pixel_fmt == IPU_PIX_FMT_UYVY) ||
1634 (pixel_fmt == IPU_PIX_FMT_YVYU) ||
1635 (pixel_fmt == IPU_PIX_FMT_VYUY))
1636 di_gen |= 0x00020000;
1639 di_gen |= DI_GEN_POLARITY_DISP_CLK;
1641 ipu_di_write(ipu, disp, di_gen, DI_GENERAL);
1643 ipu_di_write(ipu, disp, (--vsync_cnt << DI_VSYNC_SEL_OFFSET) |
1644 0x00000002, DI_SYNC_AS_GEN);
1645 reg = ipu_di_read(ipu, disp, DI_POL);
1646 reg &= ~(DI_POL_DRDY_DATA_POLARITY | DI_POL_DRDY_POLARITY_15);
1648 reg |= DI_POL_DRDY_POLARITY_15;
1650 reg |= DI_POL_DRDY_DATA_POLARITY;
1651 ipu_di_write(ipu, disp, reg, DI_POL);
1653 ipu_dc_write(ipu, width, DC_DISP_CONF2(DC_DISP_ID_SYNC(disp)));
1659 EXPORT_SYMBOL(ipu_init_sync_panel);
1661 void ipu_uninit_sync_panel(struct ipu_soc *ipu, int disp)
1666 if ((disp != 0) || (disp != 1))
1671 di_gen = ipu_di_read(ipu, disp, DI_GENERAL);
1672 di_gen |= 0x3ff | DI_GEN_POLARITY_DISP_CLK;
1673 ipu_di_write(ipu, disp, di_gen, DI_GENERAL);
1675 reg = ipu_di_read(ipu, disp, DI_POL);
1677 ipu_di_write(ipu, disp, reg, DI_POL);
1681 EXPORT_SYMBOL(ipu_uninit_sync_panel);
1683 int ipu_init_async_panel(struct ipu_soc *ipu, int disp, int type, uint32_t cycle_time,
1684 uint32_t pixel_fmt, ipu_adc_sig_cfg_t sig)
1689 u32 di_clk = clk_get_rate(ipu->ipu_clk);
1691 /* round up cycle_time, then calcalate the divider using scaled math */
1692 cycle_time += (1000000000UL / di_clk) - 1;
1693 div = (cycle_time * (di_clk / 256UL)) / (1000000000UL / 256UL);
1695 map = _ipu_pixfmt_to_map(pixel_fmt);
1701 if (type == IPU_PANEL_SERIAL) {
1702 ipu_di_write(ipu, disp, (div << 24) | ((sig.ifc_width - 1) << 4),
1703 DI_DW_GEN(ASYNC_SER_WAVE));
1705 _ipu_di_data_pin_config(ipu, disp, ASYNC_SER_WAVE, DI_PIN_CS,
1706 0, 0, (div * 2) + 1);
1707 _ipu_di_data_pin_config(ipu, disp, ASYNC_SER_WAVE, DI_PIN_SER_CLK,
1709 _ipu_di_data_pin_config(ipu, disp, ASYNC_SER_WAVE, DI_PIN_SER_RS,
1712 _ipu_dc_write_tmpl(ipu, 0x64, WROD(0), 0, map, ASYNC_SER_WAVE, 0, 0, 1);
1714 /* Configure DC for serial panel */
1715 ipu_dc_write(ipu, 0x14, DC_DISP_CONF1(DC_DISP_ID_SERIAL));
1718 ser_conf |= DI_SER_CONF_SERIAL_CLK_POL;
1720 ser_conf |= DI_SER_CONF_SERIAL_DATA_POL;
1722 ser_conf |= DI_SER_CONF_SERIAL_RS_POL;
1724 ser_conf |= DI_SER_CONF_SERIAL_CS_POL;
1725 ipu_di_write(ipu, disp, ser_conf, DI_SER_CONF);
1731 EXPORT_SYMBOL(ipu_init_async_panel);
1734 * This function sets the foreground and background plane global alpha blending
1735 * modes. This function also sets the DP graphic plane according to the
1736 * parameter of IPUv3 DP channel.
1738 * @param ipu ipu handler
1739 * @param channel IPUv3 DP channel
1741 * @param enable Boolean to enable or disable global alpha
1742 * blending. If disabled, local blending is used.
1744 * @param alpha Global alpha value.
1746 * @return Returns 0 on success or negative error code on fail
1748 int32_t ipu_disp_set_global_alpha(struct ipu_soc *ipu, ipu_channel_t channel,
1749 bool enable, uint8_t alpha)
1755 if (channel == MEM_BG_SYNC || channel == MEM_FG_SYNC)
1757 else if (channel == MEM_BG_ASYNC0 || channel == MEM_FG_ASYNC0)
1759 else if (channel == MEM_BG_ASYNC1 || channel == MEM_FG_ASYNC1)
1764 if (channel == MEM_BG_SYNC || channel == MEM_BG_ASYNC0 ||
1765 channel == MEM_BG_ASYNC1)
1775 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1776 ipu_dp_write(ipu, reg & ~DP_COM_CONF_GWSEL, DP_COM_CONF(flow));
1778 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1779 ipu_dp_write(ipu, reg | DP_COM_CONF_GWSEL, DP_COM_CONF(flow));
1783 reg = ipu_dp_read(ipu, DP_GRAPH_WIND_CTRL(flow)) & 0x00FFFFFFL;
1784 ipu_dp_write(ipu, reg | ((uint32_t) alpha << 24),
1785 DP_GRAPH_WIND_CTRL(flow));
1787 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1788 ipu_dp_write(ipu, reg | DP_COM_CONF_GWAM, DP_COM_CONF(flow));
1790 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1791 ipu_dp_write(ipu, reg & ~DP_COM_CONF_GWAM, DP_COM_CONF(flow));
1794 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
1795 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
1803 EXPORT_SYMBOL(ipu_disp_set_global_alpha);
1806 * This function sets the transparent color key for SDC graphic plane.
1808 * @param ipu ipu handler
1809 * @param channel Input parameter for the logical channel ID.
1811 * @param enable Boolean to enable or disable color key
1813 * @param colorKey 24-bit RGB color for transparent color key.
1815 * @return Returns 0 on success or negative error code on fail
1817 int32_t ipu_disp_set_color_key(struct ipu_soc *ipu, ipu_channel_t channel,
1818 bool enable, uint32_t color_key)
1822 int red, green, blue;
1824 if (channel == MEM_BG_SYNC || channel == MEM_FG_SYNC)
1826 else if (channel == MEM_BG_ASYNC0 || channel == MEM_FG_ASYNC0)
1828 else if (channel == MEM_BG_ASYNC1 || channel == MEM_FG_ASYNC1)
1837 ipu->color_key_4rgb = true;
1838 /* Transform color key from rgb to yuv if CSC is enabled */
1839 if (((ipu->fg_csc_type == RGB2YUV) && (ipu->bg_csc_type == YUV2YUV)) ||
1840 ((ipu->fg_csc_type == YUV2YUV) && (ipu->bg_csc_type == RGB2YUV)) ||
1841 ((ipu->fg_csc_type == YUV2YUV) && (ipu->bg_csc_type == YUV2YUV)) ||
1842 ((ipu->fg_csc_type == YUV2RGB) && (ipu->bg_csc_type == YUV2RGB))) {
1844 dev_dbg(ipu->dev, "color key 0x%x need change to yuv fmt\n", color_key);
1846 red = (color_key >> 16) & 0xFF;
1847 green = (color_key >> 8) & 0xFF;
1848 blue = color_key & 0xFF;
1850 y = _rgb_to_yuv(0, red, green, blue);
1851 u = _rgb_to_yuv(1, red, green, blue);
1852 v = _rgb_to_yuv(2, red, green, blue);
1853 color_key = (y << 16) | (u << 8) | v;
1855 ipu->color_key_4rgb = false;
1857 dev_dbg(ipu->dev, "color key change to yuv fmt 0x%x\n", color_key);
1861 reg = ipu_dp_read(ipu, DP_GRAPH_WIND_CTRL(flow)) & 0xFF000000L;
1862 ipu_dp_write(ipu, reg | color_key, DP_GRAPH_WIND_CTRL(flow));
1864 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1865 ipu_dp_write(ipu, reg | DP_COM_CONF_GWCKE, DP_COM_CONF(flow));
1867 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1868 ipu_dp_write(ipu, reg & ~DP_COM_CONF_GWCKE, DP_COM_CONF(flow));
1871 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
1872 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
1880 EXPORT_SYMBOL(ipu_disp_set_color_key);
1883 * This function sets the gamma correction for DP output.
1885 * @param ipu ipu handler
1886 * @param channel Input parameter for the logical channel ID.
1888 * @param enable Boolean to enable or disable gamma correction.
1890 * @param constk Gamma piecewise linear approximation constk coeff.
1892 * @param slopek Gamma piecewise linear approximation slopek coeff.
1894 * @return Returns 0 on success or negative error code on fail
1896 int32_t ipu_disp_set_gamma_correction(struct ipu_soc *ipu, ipu_channel_t channel, bool enable, int constk[], int slopek[])
1898 uint32_t reg, flow, i;
1900 if (channel == MEM_BG_SYNC || channel == MEM_FG_SYNC)
1902 else if (channel == MEM_BG_ASYNC0 || channel == MEM_FG_ASYNC0)
1904 else if (channel == MEM_BG_ASYNC1 || channel == MEM_FG_ASYNC1)
1913 for (i = 0; i < 8; i++)
1914 ipu_dp_write(ipu, (constk[2*i] & 0x1ff) | ((constk[2*i+1] & 0x1ff) << 16), DP_GAMMA_C(flow, i));
1915 for (i = 0; i < 4; i++)
1916 ipu_dp_write(ipu, (slopek[4*i] & 0xff) | ((slopek[4*i+1] & 0xff) << 8) |
1917 ((slopek[4*i+2] & 0xff) << 16) | ((slopek[4*i+3] & 0xff) << 24), DP_GAMMA_S(flow, i));
1919 reg = ipu_dp_read(ipu, DP_COM_CONF(flow));
1921 if ((ipu->bg_csc_type == RGB2YUV) || (ipu->bg_csc_type == YUV2YUV))
1922 reg |= DP_COM_CONF_GAMMA_YUV_EN;
1924 reg &= ~DP_COM_CONF_GAMMA_YUV_EN;
1925 ipu_dp_write(ipu, reg | DP_COM_CONF_GAMMA_EN, DP_COM_CONF(flow));
1927 ipu_dp_write(ipu, reg & ~DP_COM_CONF_GAMMA_EN, DP_COM_CONF(flow));
1929 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) | 0x8;
1930 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
1938 EXPORT_SYMBOL(ipu_disp_set_gamma_correction);
1941 * This function sets the window position of the foreground or background plane.
1944 * @param ipu ipu handler
1945 * @param channel Input parameter for the logical channel ID.
1947 * @param x_pos The X coordinate position to place window at.
1948 * The position is relative to the top left corner.
1950 * @param y_pos The Y coordinate position to place window at.
1951 * The position is relative to the top left corner.
1953 * @return Returns 0 on success or negative error code on fail
1955 int32_t _ipu_disp_set_window_pos(struct ipu_soc *ipu, ipu_channel_t channel,
1956 int16_t x_pos, int16_t y_pos)
1960 uint32_t dp_srm_shift;
1962 if ((channel == MEM_FG_SYNC) || (channel == MEM_BG_SYNC)) {
1965 } else if (channel == MEM_FG_ASYNC0) {
1968 } else if (channel == MEM_FG_ASYNC1) {
1974 ipu_dp_write(ipu, (x_pos << 16) | y_pos, DP_FG_POS(flow));
1976 if (ipu_is_channel_busy(ipu, channel)) {
1977 /* controled by FSU if channel enabled */
1978 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) & (~(0x3 << dp_srm_shift));
1979 reg |= (0x1 << dp_srm_shift);
1980 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
1982 /* disable auto swap, controled by MCU if channel disabled */
1983 reg = ipu_cm_read(ipu, IPU_SRM_PRI2) & (~(0x3 << dp_srm_shift));
1984 ipu_cm_write(ipu, reg, IPU_SRM_PRI2);
1990 int32_t ipu_disp_set_window_pos(struct ipu_soc *ipu, ipu_channel_t channel,
1991 int16_t x_pos, int16_t y_pos)
1997 ret = _ipu_disp_set_window_pos(ipu, channel, x_pos, y_pos);
2002 EXPORT_SYMBOL(ipu_disp_set_window_pos);
2004 int32_t _ipu_disp_get_window_pos(struct ipu_soc *ipu, ipu_channel_t channel,
2005 int16_t *x_pos, int16_t *y_pos)
2010 if (channel == MEM_FG_SYNC)
2012 else if (channel == MEM_FG_ASYNC0)
2014 else if (channel == MEM_FG_ASYNC1)
2019 reg = ipu_dp_read(ipu, DP_FG_POS(flow));
2021 *x_pos = (reg >> 16) & 0x7FF;
2022 *y_pos = reg & 0x7FF;
2026 int32_t ipu_disp_get_window_pos(struct ipu_soc *ipu, ipu_channel_t channel,
2027 int16_t *x_pos, int16_t *y_pos)
2033 ret = _ipu_disp_get_window_pos(ipu, channel, x_pos, y_pos);
2038 EXPORT_SYMBOL(ipu_disp_get_window_pos);
2040 void ipu_disp_direct_write(struct ipu_soc *ipu, ipu_channel_t channel, u32 value, u32 offset)
2042 if (channel == DIRECT_ASYNC0)
2043 writel(value, ipu->disp_base[0] + offset);
2044 else if (channel == DIRECT_ASYNC1)
2045 writel(value, ipu->disp_base[1] + offset);
2047 EXPORT_SYMBOL(ipu_disp_direct_write);
2049 void ipu_reset_disp_panel(struct ipu_soc *ipu)
2053 tmp = ipu_di_read(ipu, 1, DI_GENERAL);
2054 ipu_di_write(ipu, 1, tmp | 0x08, DI_GENERAL);
2055 msleep(10); /* tRES >= 100us */
2056 tmp = ipu_di_read(ipu, 1, DI_GENERAL);
2057 ipu_di_write(ipu, 1, tmp & ~0x08, DI_GENERAL);
2062 EXPORT_SYMBOL(ipu_reset_disp_panel);
2064 void __devinit ipu_disp_init(struct ipu_soc *ipu)
2066 ipu->fg_csc_type = ipu->bg_csc_type = CSC_NONE;
2067 ipu->color_key_4rgb = true;
2068 _ipu_init_dc_mappings(ipu);
2069 _ipu_dmfc_init(ipu, DMFC_NORMAL, 1);