ipu_disp.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Porting to u-boot:
  4. *
  5. * (C) Copyright 2010
  6. * Stefano Babic, DENX Software Engineering, sbabic@denx.de
  7. *
  8. * Linux IPU driver for MX51:
  9. *
  10. * (C) Copyright 2005-2010 Freescale Semiconductor, Inc.
  11. */
  12. /* #define DEBUG */
  13. #include <common.h>
  14. #include <linux/types.h>
  15. #include <linux/errno.h>
  16. #include <asm/io.h>
  17. #include <asm/arch/imx-regs.h>
  18. #include <asm/arch/sys_proto.h>
  19. #include "ipu.h"
  20. #include "ipu_regs.h"
  21. enum csc_type_t {
  22. RGB2YUV = 0,
  23. YUV2RGB,
  24. RGB2RGB,
  25. YUV2YUV,
  26. CSC_NONE,
  27. CSC_NUM
  28. };
  29. struct dp_csc_param_t {
  30. int mode;
  31. const int (*coeff)[5][3];
  32. };
  33. #define SYNC_WAVE 0
  34. /* DC display ID assignments */
  35. #define DC_DISP_ID_SYNC(di) (di)
  36. #define DC_DISP_ID_SERIAL 2
  37. #define DC_DISP_ID_ASYNC 3
  38. int dmfc_type_setup;
  39. static int dmfc_size_28, dmfc_size_29, dmfc_size_24, dmfc_size_27, dmfc_size_23;
  40. int g_di1_tvout;
  41. extern struct clk *g_ipu_clk;
  42. extern struct clk *g_ldb_clk;
  43. extern struct clk *g_di_clk[2];
  44. extern struct clk *g_pixel_clk[2];
  45. extern unsigned char g_ipu_clk_enabled;
  46. extern unsigned char g_dc_di_assignment[];
  47. void ipu_dmfc_init(int dmfc_type, int first)
  48. {
  49. u32 dmfc_wr_chan, dmfc_dp_chan;
  50. if (first) {
  51. if (dmfc_type_setup > dmfc_type)
  52. dmfc_type = dmfc_type_setup;
  53. else
  54. dmfc_type_setup = dmfc_type;
  55. /* disable DMFC-IC channel*/
  56. __raw_writel(0x2, DMFC_IC_CTRL);
  57. } else if (dmfc_type_setup >= DMFC_HIGH_RESOLUTION_DC) {
  58. printf("DMFC high resolution has set, will not change\n");
  59. return;
  60. } else
  61. dmfc_type_setup = dmfc_type;
  62. if (dmfc_type == DMFC_HIGH_RESOLUTION_DC) {
  63. /* 1 - segment 0~3;
  64. * 5B - segement 4, 5;
  65. * 5F - segement 6, 7;
  66. * 1C, 2C and 6B, 6F unused;
  67. */
  68. debug("IPU DMFC DC HIGH RES: 1(0~3), 5B(4,5), 5F(6,7)\n");
  69. dmfc_wr_chan = 0x00000088;
  70. dmfc_dp_chan = 0x00009694;
  71. dmfc_size_28 = 256 * 4;
  72. dmfc_size_29 = 0;
  73. dmfc_size_24 = 0;
  74. dmfc_size_27 = 128 * 4;
  75. dmfc_size_23 = 128 * 4;
  76. } else if (dmfc_type == DMFC_HIGH_RESOLUTION_DP) {
  77. /* 1 - segment 0, 1;
  78. * 5B - segement 2~5;
  79. * 5F - segement 6,7;
  80. * 1C, 2C and 6B, 6F unused;
  81. */
  82. debug("IPU DMFC DP HIGH RES: 1(0,1), 5B(2~5), 5F(6,7)\n");
  83. dmfc_wr_chan = 0x00000090;
  84. dmfc_dp_chan = 0x0000968a;
  85. dmfc_size_28 = 128 * 4;
  86. dmfc_size_29 = 0;
  87. dmfc_size_24 = 0;
  88. dmfc_size_27 = 128 * 4;
  89. dmfc_size_23 = 256 * 4;
  90. } else if (dmfc_type == DMFC_HIGH_RESOLUTION_ONLY_DP) {
  91. /* 5B - segement 0~3;
  92. * 5F - segement 4~7;
  93. * 1, 1C, 2C and 6B, 6F unused;
  94. */
  95. debug("IPU DMFC ONLY-DP HIGH RES: 5B(0~3), 5F(4~7)\n");
  96. dmfc_wr_chan = 0x00000000;
  97. dmfc_dp_chan = 0x00008c88;
  98. dmfc_size_28 = 0;
  99. dmfc_size_29 = 0;
  100. dmfc_size_24 = 0;
  101. dmfc_size_27 = 256 * 4;
  102. dmfc_size_23 = 256 * 4;
  103. } else {
  104. /* 1 - segment 0, 1;
  105. * 5B - segement 4, 5;
  106. * 5F - segement 6, 7;
  107. * 1C, 2C and 6B, 6F unused;
  108. */
  109. debug("IPU DMFC NORMAL mode: 1(0~1), 5B(4,5), 5F(6,7)\n");
  110. dmfc_wr_chan = 0x00000090;
  111. dmfc_dp_chan = 0x00009694;
  112. dmfc_size_28 = 128 * 4;
  113. dmfc_size_29 = 0;
  114. dmfc_size_24 = 0;
  115. dmfc_size_27 = 128 * 4;
  116. dmfc_size_23 = 128 * 4;
  117. }
  118. __raw_writel(dmfc_wr_chan, DMFC_WR_CHAN);
  119. __raw_writel(0x202020F6, DMFC_WR_CHAN_DEF);
  120. __raw_writel(dmfc_dp_chan, DMFC_DP_CHAN);
  121. /* Enable chan 5 watermark set at 5 bursts and clear at 7 bursts */
  122. __raw_writel(0x2020F6F6, DMFC_DP_CHAN_DEF);
  123. }
  124. void ipu_dmfc_set_wait4eot(int dma_chan, int width)
  125. {
  126. u32 dmfc_gen1 = __raw_readl(DMFC_GENERAL1);
  127. if (width >= HIGH_RESOLUTION_WIDTH) {
  128. if (dma_chan == 23)
  129. ipu_dmfc_init(DMFC_HIGH_RESOLUTION_DP, 0);
  130. else if (dma_chan == 28)
  131. ipu_dmfc_init(DMFC_HIGH_RESOLUTION_DC, 0);
  132. }
  133. if (dma_chan == 23) { /*5B*/
  134. if (dmfc_size_23 / width > 3)
  135. dmfc_gen1 |= 1UL << 20;
  136. else
  137. dmfc_gen1 &= ~(1UL << 20);
  138. } else if (dma_chan == 24) { /*6B*/
  139. if (dmfc_size_24 / width > 1)
  140. dmfc_gen1 |= 1UL << 22;
  141. else
  142. dmfc_gen1 &= ~(1UL << 22);
  143. } else if (dma_chan == 27) { /*5F*/
  144. if (dmfc_size_27 / width > 2)
  145. dmfc_gen1 |= 1UL << 21;
  146. else
  147. dmfc_gen1 &= ~(1UL << 21);
  148. } else if (dma_chan == 28) { /*1*/
  149. if (dmfc_size_28 / width > 2)
  150. dmfc_gen1 |= 1UL << 16;
  151. else
  152. dmfc_gen1 &= ~(1UL << 16);
  153. } else if (dma_chan == 29) { /*6F*/
  154. if (dmfc_size_29 / width > 1)
  155. dmfc_gen1 |= 1UL << 23;
  156. else
  157. dmfc_gen1 &= ~(1UL << 23);
  158. }
  159. __raw_writel(dmfc_gen1, DMFC_GENERAL1);
  160. }
  161. static void ipu_di_data_wave_config(int di,
  162. int wave_gen,
  163. int access_size, int component_size)
  164. {
  165. u32 reg;
  166. reg = (access_size << DI_DW_GEN_ACCESS_SIZE_OFFSET) |
  167. (component_size << DI_DW_GEN_COMPONENT_SIZE_OFFSET);
  168. __raw_writel(reg, DI_DW_GEN(di, wave_gen));
  169. }
  170. static void ipu_di_data_pin_config(int di, int wave_gen, int di_pin, int set,
  171. int up, int down)
  172. {
  173. u32 reg;
  174. reg = __raw_readl(DI_DW_GEN(di, wave_gen));
  175. reg &= ~(0x3 << (di_pin * 2));
  176. reg |= set << (di_pin * 2);
  177. __raw_writel(reg, DI_DW_GEN(di, wave_gen));
  178. __raw_writel((down << 16) | up, DI_DW_SET(di, wave_gen, set));
  179. }
  180. static void ipu_di_sync_config(int di, int wave_gen,
  181. int run_count, int run_src,
  182. int offset_count, int offset_src,
  183. int repeat_count, int cnt_clr_src,
  184. int cnt_polarity_gen_en,
  185. int cnt_polarity_clr_src,
  186. int cnt_polarity_trigger_src,
  187. int cnt_up, int cnt_down)
  188. {
  189. u32 reg;
  190. if ((run_count >= 0x1000) || (offset_count >= 0x1000) ||
  191. (repeat_count >= 0x1000) ||
  192. (cnt_up >= 0x400) || (cnt_down >= 0x400)) {
  193. printf("DI%d counters out of range.\n", di);
  194. return;
  195. }
  196. reg = (run_count << 19) | (++run_src << 16) |
  197. (offset_count << 3) | ++offset_src;
  198. __raw_writel(reg, DI_SW_GEN0(di, wave_gen));
  199. reg = (cnt_polarity_gen_en << 29) | (++cnt_clr_src << 25) |
  200. (++cnt_polarity_trigger_src << 12) | (++cnt_polarity_clr_src << 9);
  201. reg |= (cnt_down << 16) | cnt_up;
  202. if (repeat_count == 0) {
  203. /* Enable auto reload */
  204. reg |= 0x10000000;
  205. }
  206. __raw_writel(reg, DI_SW_GEN1(di, wave_gen));
  207. reg = __raw_readl(DI_STP_REP(di, wave_gen));
  208. reg &= ~(0xFFFF << (16 * ((wave_gen - 1) & 0x1)));
  209. reg |= repeat_count << (16 * ((wave_gen - 1) & 0x1));
  210. __raw_writel(reg, DI_STP_REP(di, wave_gen));
  211. }
  212. static void ipu_dc_map_config(int map, int byte_num, int offset, int mask)
  213. {
  214. int ptr = map * 3 + byte_num;
  215. u32 reg;
  216. reg = __raw_readl(DC_MAP_CONF_VAL(ptr));
  217. reg &= ~(0xFFFF << (16 * (ptr & 0x1)));
  218. reg |= ((offset << 8) | mask) << (16 * (ptr & 0x1));
  219. __raw_writel(reg, DC_MAP_CONF_VAL(ptr));
  220. reg = __raw_readl(DC_MAP_CONF_PTR(map));
  221. reg &= ~(0x1F << ((16 * (map & 0x1)) + (5 * byte_num)));
  222. reg |= ptr << ((16 * (map & 0x1)) + (5 * byte_num));
  223. __raw_writel(reg, DC_MAP_CONF_PTR(map));
  224. }
  225. static void ipu_dc_map_clear(int map)
  226. {
  227. u32 reg = __raw_readl(DC_MAP_CONF_PTR(map));
  228. __raw_writel(reg & ~(0xFFFF << (16 * (map & 0x1))),
  229. DC_MAP_CONF_PTR(map));
  230. }
  231. static void ipu_dc_write_tmpl(int word, u32 opcode, u32 operand, int map,
  232. int wave, int glue, int sync)
  233. {
  234. u32 reg;
  235. int stop = 1;
  236. reg = sync;
  237. reg |= (glue << 4);
  238. reg |= (++wave << 11);
  239. reg |= (++map << 15);
  240. reg |= (operand << 20) & 0xFFF00000;
  241. __raw_writel(reg, ipu_dc_tmpl_reg + word * 2);
  242. reg = (operand >> 12);
  243. reg |= opcode << 4;
  244. reg |= (stop << 9);
  245. __raw_writel(reg, ipu_dc_tmpl_reg + word * 2 + 1);
  246. }
  247. static void ipu_dc_link_event(int chan, int event, int addr, int priority)
  248. {
  249. u32 reg;
  250. reg = __raw_readl(DC_RL_CH(chan, event));
  251. reg &= ~(0xFFFF << (16 * (event & 0x1)));
  252. reg |= ((addr << 8) | priority) << (16 * (event & 0x1));
  253. __raw_writel(reg, DC_RL_CH(chan, event));
  254. }
  255. /* Y = R * 1.200 + G * 2.343 + B * .453 + 0.250;
  256. * U = R * -.672 + G * -1.328 + B * 2.000 + 512.250.;
  257. * V = R * 2.000 + G * -1.672 + B * -.328 + 512.250.;
  258. */
  259. static const int rgb2ycbcr_coeff[5][3] = {
  260. {0x4D, 0x96, 0x1D},
  261. {0x3D5, 0x3AB, 0x80},
  262. {0x80, 0x395, 0x3EB},
  263. {0x0000, 0x0200, 0x0200}, /* B0, B1, B2 */
  264. {0x2, 0x2, 0x2}, /* S0, S1, S2 */
  265. };
  266. /* R = (1.164 * (Y - 16)) + (1.596 * (Cr - 128));
  267. * G = (1.164 * (Y - 16)) - (0.392 * (Cb - 128)) - (0.813 * (Cr - 128));
  268. * B = (1.164 * (Y - 16)) + (2.017 * (Cb - 128);
  269. */
  270. static const int ycbcr2rgb_coeff[5][3] = {
  271. {0x095, 0x000, 0x0CC},
  272. {0x095, 0x3CE, 0x398},
  273. {0x095, 0x0FF, 0x000},
  274. {0x3E42, 0x010A, 0x3DD6}, /*B0,B1,B2 */
  275. {0x1, 0x1, 0x1}, /*S0,S1,S2 */
  276. };
  277. #define mask_a(a) ((u32)(a) & 0x3FF)
  278. #define mask_b(b) ((u32)(b) & 0x3FFF)
  279. /* Pls keep S0, S1 and S2 as 0x2 by using this convertion */
  280. static int rgb_to_yuv(int n, int red, int green, int blue)
  281. {
  282. int c;
  283. c = red * rgb2ycbcr_coeff[n][0];
  284. c += green * rgb2ycbcr_coeff[n][1];
  285. c += blue * rgb2ycbcr_coeff[n][2];
  286. c /= 16;
  287. c += rgb2ycbcr_coeff[3][n] * 4;
  288. c += 8;
  289. c /= 16;
  290. if (c < 0)
  291. c = 0;
  292. if (c > 255)
  293. c = 255;
  294. return c;
  295. }
  296. /*
  297. * Row is for BG: RGB2YUV YUV2RGB RGB2RGB YUV2YUV CSC_NONE
  298. * Column is for FG: RGB2YUV YUV2RGB RGB2RGB YUV2YUV CSC_NONE
  299. */
  300. static struct dp_csc_param_t dp_csc_array[CSC_NUM][CSC_NUM] = {
  301. {
  302. {DP_COM_CONF_CSC_DEF_BOTH, &rgb2ycbcr_coeff},
  303. {0, 0},
  304. {0, 0},
  305. {DP_COM_CONF_CSC_DEF_BG, &rgb2ycbcr_coeff},
  306. {DP_COM_CONF_CSC_DEF_BG, &rgb2ycbcr_coeff}
  307. },
  308. {
  309. {0, 0},
  310. {DP_COM_CONF_CSC_DEF_BOTH, &ycbcr2rgb_coeff},
  311. {DP_COM_CONF_CSC_DEF_BG, &ycbcr2rgb_coeff},
  312. {0, 0},
  313. {DP_COM_CONF_CSC_DEF_BG, &ycbcr2rgb_coeff}
  314. },
  315. {
  316. {0, 0},
  317. {DP_COM_CONF_CSC_DEF_FG, &ycbcr2rgb_coeff},
  318. {0, 0},
  319. {0, 0},
  320. {0, 0}
  321. },
  322. {
  323. {DP_COM_CONF_CSC_DEF_FG, &rgb2ycbcr_coeff},
  324. {0, 0},
  325. {0, 0},
  326. {0, 0},
  327. {0, 0}
  328. },
  329. {
  330. {DP_COM_CONF_CSC_DEF_FG, &rgb2ycbcr_coeff},
  331. {DP_COM_CONF_CSC_DEF_FG, &ycbcr2rgb_coeff},
  332. {0, 0},
  333. {0, 0},
  334. {0, 0}
  335. }
  336. };
  337. static enum csc_type_t fg_csc_type = CSC_NONE, bg_csc_type = CSC_NONE;
  338. static int color_key_4rgb = 1;
  339. static void ipu_dp_csc_setup(int dp, struct dp_csc_param_t dp_csc_param,
  340. unsigned char srm_mode_update)
  341. {
  342. u32 reg;
  343. const int (*coeff)[5][3];
  344. if (dp_csc_param.mode >= 0) {
  345. reg = __raw_readl(DP_COM_CONF());
  346. reg &= ~DP_COM_CONF_CSC_DEF_MASK;
  347. reg |= dp_csc_param.mode;
  348. __raw_writel(reg, DP_COM_CONF());
  349. }
  350. coeff = dp_csc_param.coeff;
  351. if (coeff) {
  352. __raw_writel(mask_a((*coeff)[0][0]) |
  353. (mask_a((*coeff)[0][1]) << 16), DP_CSC_A_0());
  354. __raw_writel(mask_a((*coeff)[0][2]) |
  355. (mask_a((*coeff)[1][0]) << 16), DP_CSC_A_1());
  356. __raw_writel(mask_a((*coeff)[1][1]) |
  357. (mask_a((*coeff)[1][2]) << 16), DP_CSC_A_2());
  358. __raw_writel(mask_a((*coeff)[2][0]) |
  359. (mask_a((*coeff)[2][1]) << 16), DP_CSC_A_3());
  360. __raw_writel(mask_a((*coeff)[2][2]) |
  361. (mask_b((*coeff)[3][0]) << 16) |
  362. ((*coeff)[4][0] << 30), DP_CSC_0());
  363. __raw_writel(mask_b((*coeff)[3][1]) | ((*coeff)[4][1] << 14) |
  364. (mask_b((*coeff)[3][2]) << 16) |
  365. ((*coeff)[4][2] << 30), DP_CSC_1());
  366. }
  367. if (srm_mode_update) {
  368. reg = __raw_readl(IPU_SRM_PRI2) | 0x8;
  369. __raw_writel(reg, IPU_SRM_PRI2);
  370. }
  371. }
  372. int ipu_dp_init(ipu_channel_t channel, uint32_t in_pixel_fmt,
  373. uint32_t out_pixel_fmt)
  374. {
  375. int in_fmt, out_fmt;
  376. int dp;
  377. int partial = 0;
  378. uint32_t reg;
  379. if (channel == MEM_FG_SYNC) {
  380. dp = DP_SYNC;
  381. partial = 1;
  382. } else if (channel == MEM_BG_SYNC) {
  383. dp = DP_SYNC;
  384. partial = 0;
  385. } else if (channel == MEM_BG_ASYNC0) {
  386. dp = DP_ASYNC0;
  387. partial = 0;
  388. } else {
  389. return -EINVAL;
  390. }
  391. in_fmt = format_to_colorspace(in_pixel_fmt);
  392. out_fmt = format_to_colorspace(out_pixel_fmt);
  393. if (partial) {
  394. if (in_fmt == RGB) {
  395. if (out_fmt == RGB)
  396. fg_csc_type = RGB2RGB;
  397. else
  398. fg_csc_type = RGB2YUV;
  399. } else {
  400. if (out_fmt == RGB)
  401. fg_csc_type = YUV2RGB;
  402. else
  403. fg_csc_type = YUV2YUV;
  404. }
  405. } else {
  406. if (in_fmt == RGB) {
  407. if (out_fmt == RGB)
  408. bg_csc_type = RGB2RGB;
  409. else
  410. bg_csc_type = RGB2YUV;
  411. } else {
  412. if (out_fmt == RGB)
  413. bg_csc_type = YUV2RGB;
  414. else
  415. bg_csc_type = YUV2YUV;
  416. }
  417. }
  418. /* Transform color key from rgb to yuv if CSC is enabled */
  419. reg = __raw_readl(DP_COM_CONF());
  420. if (color_key_4rgb && (reg & DP_COM_CONF_GWCKE) &&
  421. (((fg_csc_type == RGB2YUV) && (bg_csc_type == YUV2YUV)) ||
  422. ((fg_csc_type == YUV2YUV) && (bg_csc_type == RGB2YUV)) ||
  423. ((fg_csc_type == YUV2YUV) && (bg_csc_type == YUV2YUV)) ||
  424. ((fg_csc_type == YUV2RGB) && (bg_csc_type == YUV2RGB)))) {
  425. int red, green, blue;
  426. int y, u, v;
  427. uint32_t color_key = __raw_readl(DP_GRAPH_WIND_CTRL()) &
  428. 0xFFFFFFL;
  429. debug("_ipu_dp_init color key 0x%x need change to yuv fmt!\n",
  430. color_key);
  431. red = (color_key >> 16) & 0xFF;
  432. green = (color_key >> 8) & 0xFF;
  433. blue = color_key & 0xFF;
  434. y = rgb_to_yuv(0, red, green, blue);
  435. u = rgb_to_yuv(1, red, green, blue);
  436. v = rgb_to_yuv(2, red, green, blue);
  437. color_key = (y << 16) | (u << 8) | v;
  438. reg = __raw_readl(DP_GRAPH_WIND_CTRL()) & 0xFF000000L;
  439. __raw_writel(reg | color_key, DP_GRAPH_WIND_CTRL());
  440. color_key_4rgb = 0;
  441. debug("_ipu_dp_init color key change to yuv fmt 0x%x!\n",
  442. color_key);
  443. }
  444. ipu_dp_csc_setup(dp, dp_csc_array[bg_csc_type][fg_csc_type], 1);
  445. return 0;
  446. }
  447. void ipu_dp_uninit(ipu_channel_t channel)
  448. {
  449. int dp;
  450. int partial = 0;
  451. if (channel == MEM_FG_SYNC) {
  452. dp = DP_SYNC;
  453. partial = 1;
  454. } else if (channel == MEM_BG_SYNC) {
  455. dp = DP_SYNC;
  456. partial = 0;
  457. } else if (channel == MEM_BG_ASYNC0) {
  458. dp = DP_ASYNC0;
  459. partial = 0;
  460. } else {
  461. return;
  462. }
  463. if (partial)
  464. fg_csc_type = CSC_NONE;
  465. else
  466. bg_csc_type = CSC_NONE;
  467. ipu_dp_csc_setup(dp, dp_csc_array[bg_csc_type][fg_csc_type], 0);
  468. }
  469. void ipu_dc_init(int dc_chan, int di, unsigned char interlaced)
  470. {
  471. u32 reg = 0;
  472. if ((dc_chan == 1) || (dc_chan == 5)) {
  473. if (interlaced) {
  474. ipu_dc_link_event(dc_chan, DC_EVT_NL, 0, 3);
  475. ipu_dc_link_event(dc_chan, DC_EVT_EOL, 0, 2);
  476. ipu_dc_link_event(dc_chan, DC_EVT_NEW_DATA, 0, 1);
  477. } else {
  478. if (di) {
  479. ipu_dc_link_event(dc_chan, DC_EVT_NL, 2, 3);
  480. ipu_dc_link_event(dc_chan, DC_EVT_EOL, 3, 2);
  481. ipu_dc_link_event(dc_chan, DC_EVT_NEW_DATA,
  482. 4, 1);
  483. } else {
  484. ipu_dc_link_event(dc_chan, DC_EVT_NL, 5, 3);
  485. ipu_dc_link_event(dc_chan, DC_EVT_EOL, 6, 2);
  486. ipu_dc_link_event(dc_chan, DC_EVT_NEW_DATA,
  487. 7, 1);
  488. }
  489. }
  490. ipu_dc_link_event(dc_chan, DC_EVT_NF, 0, 0);
  491. ipu_dc_link_event(dc_chan, DC_EVT_NFIELD, 0, 0);
  492. ipu_dc_link_event(dc_chan, DC_EVT_EOF, 0, 0);
  493. ipu_dc_link_event(dc_chan, DC_EVT_EOFIELD, 0, 0);
  494. ipu_dc_link_event(dc_chan, DC_EVT_NEW_CHAN, 0, 0);
  495. ipu_dc_link_event(dc_chan, DC_EVT_NEW_ADDR, 0, 0);
  496. reg = 0x2;
  497. reg |= DC_DISP_ID_SYNC(di) << DC_WR_CH_CONF_PROG_DISP_ID_OFFSET;
  498. reg |= di << 2;
  499. if (interlaced)
  500. reg |= DC_WR_CH_CONF_FIELD_MODE;
  501. } else if ((dc_chan == 8) || (dc_chan == 9)) {
  502. /* async channels */
  503. ipu_dc_link_event(dc_chan, DC_EVT_NEW_DATA_W_0, 0x64, 1);
  504. ipu_dc_link_event(dc_chan, DC_EVT_NEW_DATA_W_1, 0x64, 1);
  505. reg = 0x3;
  506. reg |= DC_DISP_ID_SERIAL << DC_WR_CH_CONF_PROG_DISP_ID_OFFSET;
  507. }
  508. __raw_writel(reg, DC_WR_CH_CONF(dc_chan));
  509. __raw_writel(0x00000000, DC_WR_CH_ADDR(dc_chan));
  510. __raw_writel(0x00000084, DC_GEN);
  511. }
  512. void ipu_dc_uninit(int dc_chan)
  513. {
  514. if ((dc_chan == 1) || (dc_chan == 5)) {
  515. ipu_dc_link_event(dc_chan, DC_EVT_NL, 0, 0);
  516. ipu_dc_link_event(dc_chan, DC_EVT_EOL, 0, 0);
  517. ipu_dc_link_event(dc_chan, DC_EVT_NEW_DATA, 0, 0);
  518. ipu_dc_link_event(dc_chan, DC_EVT_NF, 0, 0);
  519. ipu_dc_link_event(dc_chan, DC_EVT_NFIELD, 0, 0);
  520. ipu_dc_link_event(dc_chan, DC_EVT_EOF, 0, 0);
  521. ipu_dc_link_event(dc_chan, DC_EVT_EOFIELD, 0, 0);
  522. ipu_dc_link_event(dc_chan, DC_EVT_NEW_CHAN, 0, 0);
  523. ipu_dc_link_event(dc_chan, DC_EVT_NEW_ADDR, 0, 0);
  524. } else if ((dc_chan == 8) || (dc_chan == 9)) {
  525. ipu_dc_link_event(dc_chan, DC_EVT_NEW_ADDR_W_0, 0, 0);
  526. ipu_dc_link_event(dc_chan, DC_EVT_NEW_ADDR_W_1, 0, 0);
  527. ipu_dc_link_event(dc_chan, DC_EVT_NEW_CHAN_W_0, 0, 0);
  528. ipu_dc_link_event(dc_chan, DC_EVT_NEW_CHAN_W_1, 0, 0);
  529. ipu_dc_link_event(dc_chan, DC_EVT_NEW_DATA_W_0, 0, 0);
  530. ipu_dc_link_event(dc_chan, DC_EVT_NEW_DATA_W_1, 0, 0);
  531. ipu_dc_link_event(dc_chan, DC_EVT_NEW_ADDR_R_0, 0, 0);
  532. ipu_dc_link_event(dc_chan, DC_EVT_NEW_ADDR_R_1, 0, 0);
  533. ipu_dc_link_event(dc_chan, DC_EVT_NEW_CHAN_R_0, 0, 0);
  534. ipu_dc_link_event(dc_chan, DC_EVT_NEW_CHAN_R_1, 0, 0);
  535. ipu_dc_link_event(dc_chan, DC_EVT_NEW_DATA_R_0, 0, 0);
  536. ipu_dc_link_event(dc_chan, DC_EVT_NEW_DATA_R_1, 0, 0);
  537. }
  538. }
  539. void ipu_dp_dc_enable(ipu_channel_t channel)
  540. {
  541. int di;
  542. uint32_t reg;
  543. uint32_t dc_chan;
  544. if (channel == MEM_DC_SYNC)
  545. dc_chan = 1;
  546. else if ((channel == MEM_BG_SYNC) || (channel == MEM_FG_SYNC))
  547. dc_chan = 5;
  548. else
  549. return;
  550. if (channel == MEM_FG_SYNC) {
  551. /* Enable FG channel */
  552. reg = __raw_readl(DP_COM_CONF());
  553. __raw_writel(reg | DP_COM_CONF_FG_EN, DP_COM_CONF());
  554. reg = __raw_readl(IPU_SRM_PRI2) | 0x8;
  555. __raw_writel(reg, IPU_SRM_PRI2);
  556. return;
  557. }
  558. di = g_dc_di_assignment[dc_chan];
  559. /* Make sure other DC sync channel is not assigned same DI */
  560. reg = __raw_readl(DC_WR_CH_CONF(6 - dc_chan));
  561. if ((di << 2) == (reg & DC_WR_CH_CONF_PROG_DI_ID)) {
  562. reg &= ~DC_WR_CH_CONF_PROG_DI_ID;
  563. reg |= di ? 0 : DC_WR_CH_CONF_PROG_DI_ID;
  564. __raw_writel(reg, DC_WR_CH_CONF(6 - dc_chan));
  565. }
  566. reg = __raw_readl(DC_WR_CH_CONF(dc_chan));
  567. reg |= 4 << DC_WR_CH_CONF_PROG_TYPE_OFFSET;
  568. __raw_writel(reg, DC_WR_CH_CONF(dc_chan));
  569. clk_enable(g_pixel_clk[di]);
  570. }
  571. static unsigned char dc_swap;
  572. void ipu_dp_dc_disable(ipu_channel_t channel, unsigned char swap)
  573. {
  574. uint32_t reg;
  575. uint32_t csc;
  576. uint32_t dc_chan = 0;
  577. int timeout = 50;
  578. int irq = 0;
  579. dc_swap = swap;
  580. if (channel == MEM_DC_SYNC) {
  581. dc_chan = 1;
  582. irq = IPU_IRQ_DC_FC_1;
  583. } else if (channel == MEM_BG_SYNC) {
  584. dc_chan = 5;
  585. irq = IPU_IRQ_DP_SF_END;
  586. } else if (channel == MEM_FG_SYNC) {
  587. /* Disable FG channel */
  588. dc_chan = 5;
  589. reg = __raw_readl(DP_COM_CONF());
  590. csc = reg & DP_COM_CONF_CSC_DEF_MASK;
  591. if (csc == DP_COM_CONF_CSC_DEF_FG)
  592. reg &= ~DP_COM_CONF_CSC_DEF_MASK;
  593. reg &= ~DP_COM_CONF_FG_EN;
  594. __raw_writel(reg, DP_COM_CONF());
  595. reg = __raw_readl(IPU_SRM_PRI2) | 0x8;
  596. __raw_writel(reg, IPU_SRM_PRI2);
  597. timeout = 50;
  598. /*
  599. * Wait for DC triple buffer to empty,
  600. * this check is useful for tv overlay.
  601. */
  602. if (g_dc_di_assignment[dc_chan] == 0)
  603. while ((__raw_readl(DC_STAT) & 0x00000002)
  604. != 0x00000002) {
  605. udelay(2000);
  606. timeout -= 2;
  607. if (timeout <= 0)
  608. break;
  609. }
  610. else if (g_dc_di_assignment[dc_chan] == 1)
  611. while ((__raw_readl(DC_STAT) & 0x00000020)
  612. != 0x00000020) {
  613. udelay(2000);
  614. timeout -= 2;
  615. if (timeout <= 0)
  616. break;
  617. }
  618. return;
  619. } else {
  620. return;
  621. }
  622. if (dc_swap) {
  623. /* Swap DC channel 1 and 5 settings, and disable old dc chan */
  624. reg = __raw_readl(DC_WR_CH_CONF(dc_chan));
  625. __raw_writel(reg, DC_WR_CH_CONF(6 - dc_chan));
  626. reg &= ~DC_WR_CH_CONF_PROG_TYPE_MASK;
  627. reg ^= DC_WR_CH_CONF_PROG_DI_ID;
  628. __raw_writel(reg, DC_WR_CH_CONF(dc_chan));
  629. } else {
  630. /* Make sure that we leave at the irq starting edge */
  631. __raw_writel(IPUIRQ_2_MASK(irq), IPUIRQ_2_STATREG(irq));
  632. do {
  633. reg = __raw_readl(IPUIRQ_2_STATREG(irq));
  634. } while (!(reg & IPUIRQ_2_MASK(irq)));
  635. reg = __raw_readl(DC_WR_CH_CONF(dc_chan));
  636. reg &= ~DC_WR_CH_CONF_PROG_TYPE_MASK;
  637. __raw_writel(reg, DC_WR_CH_CONF(dc_chan));
  638. reg = __raw_readl(IPU_DISP_GEN);
  639. if (g_dc_di_assignment[dc_chan])
  640. reg &= ~DI1_COUNTER_RELEASE;
  641. else
  642. reg &= ~DI0_COUNTER_RELEASE;
  643. __raw_writel(reg, IPU_DISP_GEN);
  644. /* Clock is already off because it must be done quickly, but
  645. we need to fix the ref count */
  646. clk_disable(g_pixel_clk[g_dc_di_assignment[dc_chan]]);
  647. }
  648. }
  649. void ipu_init_dc_mappings(void)
  650. {
  651. /* IPU_PIX_FMT_RGB24 */
  652. ipu_dc_map_clear(0);
  653. ipu_dc_map_config(0, 0, 7, 0xFF);
  654. ipu_dc_map_config(0, 1, 15, 0xFF);
  655. ipu_dc_map_config(0, 2, 23, 0xFF);
  656. /* IPU_PIX_FMT_RGB666 */
  657. ipu_dc_map_clear(1);
  658. ipu_dc_map_config(1, 0, 5, 0xFC);
  659. ipu_dc_map_config(1, 1, 11, 0xFC);
  660. ipu_dc_map_config(1, 2, 17, 0xFC);
  661. /* IPU_PIX_FMT_YUV444 */
  662. ipu_dc_map_clear(2);
  663. ipu_dc_map_config(2, 0, 15, 0xFF);
  664. ipu_dc_map_config(2, 1, 23, 0xFF);
  665. ipu_dc_map_config(2, 2, 7, 0xFF);
  666. /* IPU_PIX_FMT_RGB565 */
  667. ipu_dc_map_clear(3);
  668. ipu_dc_map_config(3, 0, 4, 0xF8);
  669. ipu_dc_map_config(3, 1, 10, 0xFC);
  670. ipu_dc_map_config(3, 2, 15, 0xF8);
  671. /* IPU_PIX_FMT_LVDS666 */
  672. ipu_dc_map_clear(4);
  673. ipu_dc_map_config(4, 0, 5, 0xFC);
  674. ipu_dc_map_config(4, 1, 13, 0xFC);
  675. ipu_dc_map_config(4, 2, 21, 0xFC);
  676. }
  677. static int ipu_pixfmt_to_map(uint32_t fmt)
  678. {
  679. switch (fmt) {
  680. case IPU_PIX_FMT_GENERIC:
  681. case IPU_PIX_FMT_RGB24:
  682. return 0;
  683. case IPU_PIX_FMT_RGB666:
  684. return 1;
  685. case IPU_PIX_FMT_YUV444:
  686. return 2;
  687. case IPU_PIX_FMT_RGB565:
  688. return 3;
  689. case IPU_PIX_FMT_LVDS666:
  690. return 4;
  691. }
  692. return -1;
  693. }
  694. /*
  695. * This function is called to initialize a synchronous LCD panel.
  696. *
  697. * @param disp The DI the panel is attached to.
  698. *
  699. * @param pixel_clk Desired pixel clock frequency in Hz.
  700. *
  701. * @param pixel_fmt Input parameter for pixel format of buffer.
  702. * Pixel format is a FOURCC ASCII code.
  703. *
  704. * @param width The width of panel in pixels.
  705. *
  706. * @param height The height of panel in pixels.
  707. *
  708. * @param hStartWidth The number of pixel clocks between the HSYNC
  709. * signal pulse and the start of valid data.
  710. *
  711. * @param hSyncWidth The width of the HSYNC signal in units of pixel
  712. * clocks.
  713. *
  714. * @param hEndWidth The number of pixel clocks between the end of
  715. * valid data and the HSYNC signal for next line.
  716. *
  717. * @param vStartWidth The number of lines between the VSYNC
  718. * signal pulse and the start of valid data.
  719. *
  720. * @param vSyncWidth The width of the VSYNC signal in units of lines
  721. *
  722. * @param vEndWidth The number of lines between the end of valid
  723. * data and the VSYNC signal for next frame.
  724. *
  725. * @param sig Bitfield of signal polarities for LCD interface.
  726. *
  727. * @return This function returns 0 on success or negative error code on
  728. * fail.
  729. */
  730. int32_t ipu_init_sync_panel(int disp, uint32_t pixel_clk,
  731. uint16_t width, uint16_t height,
  732. uint32_t pixel_fmt,
  733. uint16_t h_start_width, uint16_t h_sync_width,
  734. uint16_t h_end_width, uint16_t v_start_width,
  735. uint16_t v_sync_width, uint16_t v_end_width,
  736. uint32_t v_to_h_sync, ipu_di_signal_cfg_t sig)
  737. {
  738. uint32_t reg;
  739. uint32_t di_gen, vsync_cnt;
  740. uint32_t div, rounded_pixel_clk;
  741. uint32_t h_total, v_total;
  742. int map;
  743. struct clk *di_parent;
  744. debug("panel size = %d x %d\n", width, height);
  745. if ((v_sync_width == 0) || (h_sync_width == 0))
  746. return -EINVAL;
  747. /* adapt panel to ipu restricitions */
  748. if (v_end_width < 2) {
  749. v_end_width = 2;
  750. puts("WARNING: v_end_width (lower_margin) must be >= 2, adjusted\n");
  751. }
  752. h_total = width + h_sync_width + h_start_width + h_end_width;
  753. v_total = height + v_sync_width + v_start_width + v_end_width;
  754. /* Init clocking */
  755. debug("pixel clk = %dHz\n", pixel_clk);
  756. if (sig.ext_clk) {
  757. if (!(g_di1_tvout && (disp == 1))) { /*not round div for tvout*/
  758. /*
  759. * Set the PLL to be an even multiple
  760. * of the pixel clock.
  761. */
  762. if ((clk_get_usecount(g_pixel_clk[0]) == 0) &&
  763. (clk_get_usecount(g_pixel_clk[1]) == 0)) {
  764. di_parent = clk_get_parent(g_di_clk[disp]);
  765. rounded_pixel_clk =
  766. clk_round_rate(g_pixel_clk[disp],
  767. pixel_clk);
  768. div = clk_get_rate(di_parent) /
  769. rounded_pixel_clk;
  770. if (div % 2)
  771. div++;
  772. if (clk_get_rate(di_parent) != div *
  773. rounded_pixel_clk)
  774. clk_set_rate(di_parent,
  775. div * rounded_pixel_clk);
  776. udelay(10000);
  777. clk_set_rate(g_di_clk[disp],
  778. 2 * rounded_pixel_clk);
  779. udelay(10000);
  780. }
  781. }
  782. clk_set_parent(g_pixel_clk[disp], g_ldb_clk);
  783. } else {
  784. if (clk_get_usecount(g_pixel_clk[disp]) != 0)
  785. clk_set_parent(g_pixel_clk[disp], g_ipu_clk);
  786. }
  787. rounded_pixel_clk = clk_round_rate(g_pixel_clk[disp], pixel_clk);
  788. clk_set_rate(g_pixel_clk[disp], rounded_pixel_clk);
  789. udelay(5000);
  790. /* Get integer portion of divider */
  791. div = clk_get_rate(clk_get_parent(g_pixel_clk[disp])) /
  792. rounded_pixel_clk;
  793. ipu_di_data_wave_config(disp, SYNC_WAVE, div - 1, div - 1);
  794. ipu_di_data_pin_config(disp, SYNC_WAVE, DI_PIN15, 3, 0, div * 2);
  795. map = ipu_pixfmt_to_map(pixel_fmt);
  796. if (map < 0) {
  797. debug("IPU_DISP: No MAP\n");
  798. return -EINVAL;
  799. }
  800. di_gen = __raw_readl(DI_GENERAL(disp));
  801. if (sig.interlaced) {
  802. /* Setup internal HSYNC waveform */
  803. ipu_di_sync_config(
  804. disp, /* display */
  805. 1, /* counter */
  806. h_total / 2 - 1,/* run count */
  807. DI_SYNC_CLK, /* run_resolution */
  808. 0, /* offset */
  809. DI_SYNC_NONE, /* offset resolution */
  810. 0, /* repeat count */
  811. DI_SYNC_NONE, /* CNT_CLR_SEL */
  812. 0, /* CNT_POLARITY_GEN_EN */
  813. DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
  814. DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
  815. 0, /* COUNT UP */
  816. 0 /* COUNT DOWN */
  817. );
  818. /* Field 1 VSYNC waveform */
  819. ipu_di_sync_config(
  820. disp, /* display */
  821. 2, /* counter */
  822. h_total - 1, /* run count */
  823. DI_SYNC_CLK, /* run_resolution */
  824. 0, /* offset */
  825. DI_SYNC_NONE, /* offset resolution */
  826. 0, /* repeat count */
  827. DI_SYNC_NONE, /* CNT_CLR_SEL */
  828. 0, /* CNT_POLARITY_GEN_EN */
  829. DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
  830. DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
  831. 0, /* COUNT UP */
  832. 4 /* COUNT DOWN */
  833. );
  834. /* Setup internal HSYNC waveform */
  835. ipu_di_sync_config(
  836. disp, /* display */
  837. 3, /* counter */
  838. v_total * 2 - 1,/* run count */
  839. DI_SYNC_INT_HSYNC, /* run_resolution */
  840. 1, /* offset */
  841. DI_SYNC_INT_HSYNC, /* offset resolution */
  842. 0, /* repeat count */
  843. DI_SYNC_NONE, /* CNT_CLR_SEL */
  844. 0, /* CNT_POLARITY_GEN_EN */
  845. DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
  846. DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
  847. 0, /* COUNT UP */
  848. 4 /* COUNT DOWN */
  849. );
  850. /* Active Field ? */
  851. ipu_di_sync_config(
  852. disp, /* display */
  853. 4, /* counter */
  854. v_total / 2 - 1,/* run count */
  855. DI_SYNC_HSYNC, /* run_resolution */
  856. v_start_width, /* offset */
  857. DI_SYNC_HSYNC, /* offset resolution */
  858. 2, /* repeat count */
  859. DI_SYNC_VSYNC, /* CNT_CLR_SEL */
  860. 0, /* CNT_POLARITY_GEN_EN */
  861. DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
  862. DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
  863. 0, /* COUNT UP */
  864. 0 /* COUNT DOWN */
  865. );
  866. /* Active Line */
  867. ipu_di_sync_config(
  868. disp, /* display */
  869. 5, /* counter */
  870. 0, /* run count */
  871. DI_SYNC_HSYNC, /* run_resolution */
  872. 0, /* offset */
  873. DI_SYNC_NONE, /* offset resolution */
  874. height / 2, /* repeat count */
  875. 4, /* CNT_CLR_SEL */
  876. 0, /* CNT_POLARITY_GEN_EN */
  877. DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
  878. DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
  879. 0, /* COUNT UP */
  880. 0 /* COUNT DOWN */
  881. );
  882. /* Field 0 VSYNC waveform */
  883. ipu_di_sync_config(
  884. disp, /* display */
  885. 6, /* counter */
  886. v_total - 1, /* run count */
  887. DI_SYNC_HSYNC, /* run_resolution */
  888. 0, /* offset */
  889. DI_SYNC_NONE, /* offset resolution */
  890. 0, /* repeat count */
  891. DI_SYNC_NONE, /* CNT_CLR_SEL */
  892. 0, /* CNT_POLARITY_GEN_EN */
  893. DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
  894. DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
  895. 0, /* COUNT UP */
  896. 0 /* COUNT DOWN */
  897. );
  898. /* DC VSYNC waveform */
  899. vsync_cnt = 7;
  900. ipu_di_sync_config(
  901. disp, /* display */
  902. 7, /* counter */
  903. v_total / 2 - 1,/* run count */
  904. DI_SYNC_HSYNC, /* run_resolution */
  905. 9, /* offset */
  906. DI_SYNC_HSYNC, /* offset resolution */
  907. 2, /* repeat count */
  908. DI_SYNC_VSYNC, /* CNT_CLR_SEL */
  909. 0, /* CNT_POLARITY_GEN_EN */
  910. DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
  911. DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
  912. 0, /* COUNT UP */
  913. 0 /* COUNT DOWN */
  914. );
  915. /* active pixel waveform */
  916. ipu_di_sync_config(
  917. disp, /* display */
  918. 8, /* counter */
  919. 0, /* run count */
  920. DI_SYNC_CLK, /* run_resolution */
  921. h_start_width, /* offset */
  922. DI_SYNC_CLK, /* offset resolution */
  923. width, /* repeat count */
  924. 5, /* CNT_CLR_SEL */
  925. 0, /* CNT_POLARITY_GEN_EN */
  926. DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
  927. DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
  928. 0, /* COUNT UP */
  929. 0 /* COUNT DOWN */
  930. );
  931. ipu_di_sync_config(
  932. disp, /* display */
  933. 9, /* counter */
  934. v_total - 1, /* run count */
  935. DI_SYNC_INT_HSYNC,/* run_resolution */
  936. v_total / 2, /* offset */
  937. DI_SYNC_INT_HSYNC,/* offset resolution */
  938. 0, /* repeat count */
  939. DI_SYNC_HSYNC, /* CNT_CLR_SEL */
  940. 0, /* CNT_POLARITY_GEN_EN */
  941. DI_SYNC_NONE, /* CNT_POLARITY_CLR_SEL */
  942. DI_SYNC_NONE, /* CNT_POLARITY_TRIGGER_SEL */
  943. 0, /* COUNT UP */
  944. 4 /* COUNT DOWN */
  945. );
  946. /* set gentime select and tag sel */
  947. reg = __raw_readl(DI_SW_GEN1(disp, 9));
  948. reg &= 0x1FFFFFFF;
  949. reg |= (3 - 1)<<29 | 0x00008000;
  950. __raw_writel(reg, DI_SW_GEN1(disp, 9));
  951. __raw_writel(v_total / 2 - 1, DI_SCR_CONF(disp));
  952. /* set y_sel = 1 */
  953. di_gen |= 0x10000000;
  954. di_gen |= DI_GEN_POLARITY_5;
  955. di_gen |= DI_GEN_POLARITY_8;
  956. } else {
  957. /* Setup internal HSYNC waveform */
  958. ipu_di_sync_config(disp, 1, h_total - 1, DI_SYNC_CLK,
  959. 0, DI_SYNC_NONE, 0, DI_SYNC_NONE,
  960. 0, DI_SYNC_NONE,
  961. DI_SYNC_NONE, 0, 0);
  962. /* Setup external (delayed) HSYNC waveform */
  963. ipu_di_sync_config(disp, DI_SYNC_HSYNC, h_total - 1,
  964. DI_SYNC_CLK, div * v_to_h_sync, DI_SYNC_CLK,
  965. 0, DI_SYNC_NONE, 1, DI_SYNC_NONE,
  966. DI_SYNC_CLK, 0, h_sync_width * 2);
  967. /* Setup VSYNC waveform */
  968. vsync_cnt = DI_SYNC_VSYNC;
  969. ipu_di_sync_config(disp, DI_SYNC_VSYNC, v_total - 1,
  970. DI_SYNC_INT_HSYNC, 0, DI_SYNC_NONE, 0,
  971. DI_SYNC_NONE, 1, DI_SYNC_NONE,
  972. DI_SYNC_INT_HSYNC, 0, v_sync_width * 2);
  973. __raw_writel(v_total - 1, DI_SCR_CONF(disp));
  974. /* Setup active data waveform to sync with DC */
  975. ipu_di_sync_config(disp, 4, 0, DI_SYNC_HSYNC,
  976. v_sync_width + v_start_width, DI_SYNC_HSYNC,
  977. height,
  978. DI_SYNC_VSYNC, 0, DI_SYNC_NONE,
  979. DI_SYNC_NONE, 0, 0);
  980. ipu_di_sync_config(disp, 5, 0, DI_SYNC_CLK,
  981. h_sync_width + h_start_width, DI_SYNC_CLK,
  982. width, 4, 0, DI_SYNC_NONE, DI_SYNC_NONE, 0,
  983. 0);
  984. /* reset all unused counters */
  985. __raw_writel(0, DI_SW_GEN0(disp, 6));
  986. __raw_writel(0, DI_SW_GEN1(disp, 6));
  987. __raw_writel(0, DI_SW_GEN0(disp, 7));
  988. __raw_writel(0, DI_SW_GEN1(disp, 7));
  989. __raw_writel(0, DI_SW_GEN0(disp, 8));
  990. __raw_writel(0, DI_SW_GEN1(disp, 8));
  991. __raw_writel(0, DI_SW_GEN0(disp, 9));
  992. __raw_writel(0, DI_SW_GEN1(disp, 9));
  993. reg = __raw_readl(DI_STP_REP(disp, 6));
  994. reg &= 0x0000FFFF;
  995. __raw_writel(reg, DI_STP_REP(disp, 6));
  996. __raw_writel(0, DI_STP_REP(disp, 7));
  997. __raw_writel(0, DI_STP_REP9(disp));
  998. /* Init template microcode */
  999. if (disp) {
  1000. ipu_dc_write_tmpl(2, WROD(0), 0, map, SYNC_WAVE, 8, 5);
  1001. ipu_dc_write_tmpl(3, WROD(0), 0, map, SYNC_WAVE, 4, 5);
  1002. ipu_dc_write_tmpl(4, WROD(0), 0, map, SYNC_WAVE, 0, 5);
  1003. } else {
  1004. ipu_dc_write_tmpl(5, WROD(0), 0, map, SYNC_WAVE, 8, 5);
  1005. ipu_dc_write_tmpl(6, WROD(0), 0, map, SYNC_WAVE, 4, 5);
  1006. ipu_dc_write_tmpl(7, WROD(0), 0, map, SYNC_WAVE, 0, 5);
  1007. }
  1008. if (sig.Hsync_pol)
  1009. di_gen |= DI_GEN_POLARITY_2;
  1010. if (sig.Vsync_pol)
  1011. di_gen |= DI_GEN_POLARITY_3;
  1012. if (!sig.clk_pol)
  1013. di_gen |= DI_GEN_POL_CLK;
  1014. }
  1015. __raw_writel(di_gen, DI_GENERAL(disp));
  1016. __raw_writel((--vsync_cnt << DI_VSYNC_SEL_OFFSET) |
  1017. 0x00000002, DI_SYNC_AS_GEN(disp));
  1018. reg = __raw_readl(DI_POL(disp));
  1019. reg &= ~(DI_POL_DRDY_DATA_POLARITY | DI_POL_DRDY_POLARITY_15);
  1020. if (sig.enable_pol)
  1021. reg |= DI_POL_DRDY_POLARITY_15;
  1022. if (sig.data_pol)
  1023. reg |= DI_POL_DRDY_DATA_POLARITY;
  1024. __raw_writel(reg, DI_POL(disp));
  1025. __raw_writel(width, DC_DISP_CONF2(DC_DISP_ID_SYNC(disp)));
  1026. return 0;
  1027. }
  1028. /*
  1029. * This function sets the foreground and background plane global alpha blending
  1030. * modes. This function also sets the DP graphic plane according to the
  1031. * parameter of IPUv3 DP channel.
  1032. *
  1033. * @param channel IPUv3 DP channel
  1034. *
  1035. * @param enable Boolean to enable or disable global alpha
  1036. * blending. If disabled, local blending is used.
  1037. *
  1038. * @param alpha Global alpha value.
  1039. *
  1040. * @return Returns 0 on success or negative error code on fail
  1041. */
  1042. int32_t ipu_disp_set_global_alpha(ipu_channel_t channel, unsigned char enable,
  1043. uint8_t alpha)
  1044. {
  1045. uint32_t reg;
  1046. unsigned char bg_chan;
  1047. if (!((channel == MEM_BG_SYNC || channel == MEM_FG_SYNC) ||
  1048. (channel == MEM_BG_ASYNC0 || channel == MEM_FG_ASYNC0) ||
  1049. (channel == MEM_BG_ASYNC1 || channel == MEM_FG_ASYNC1)))
  1050. return -EINVAL;
  1051. if (channel == MEM_BG_SYNC || channel == MEM_BG_ASYNC0 ||
  1052. channel == MEM_BG_ASYNC1)
  1053. bg_chan = 1;
  1054. else
  1055. bg_chan = 0;
  1056. if (!g_ipu_clk_enabled)
  1057. clk_enable(g_ipu_clk);
  1058. if (bg_chan) {
  1059. reg = __raw_readl(DP_COM_CONF());
  1060. __raw_writel(reg & ~DP_COM_CONF_GWSEL, DP_COM_CONF());
  1061. } else {
  1062. reg = __raw_readl(DP_COM_CONF());
  1063. __raw_writel(reg | DP_COM_CONF_GWSEL, DP_COM_CONF());
  1064. }
  1065. if (enable) {
  1066. reg = __raw_readl(DP_GRAPH_WIND_CTRL()) & 0x00FFFFFFL;
  1067. __raw_writel(reg | ((uint32_t) alpha << 24),
  1068. DP_GRAPH_WIND_CTRL());
  1069. reg = __raw_readl(DP_COM_CONF());
  1070. __raw_writel(reg | DP_COM_CONF_GWAM, DP_COM_CONF());
  1071. } else {
  1072. reg = __raw_readl(DP_COM_CONF());
  1073. __raw_writel(reg & ~DP_COM_CONF_GWAM, DP_COM_CONF());
  1074. }
  1075. reg = __raw_readl(IPU_SRM_PRI2) | 0x8;
  1076. __raw_writel(reg, IPU_SRM_PRI2);
  1077. if (!g_ipu_clk_enabled)
  1078. clk_disable(g_ipu_clk);
  1079. return 0;
  1080. }
  1081. /*
  1082. * This function sets the transparent color key for SDC graphic plane.
  1083. *
  1084. * @param channel Input parameter for the logical channel ID.
  1085. *
  1086. * @param enable Boolean to enable or disable color key
  1087. *
  1088. * @param colorKey 24-bit RGB color for transparent color key.
  1089. *
  1090. * @return Returns 0 on success or negative error code on fail
  1091. */
  1092. int32_t ipu_disp_set_color_key(ipu_channel_t channel, unsigned char enable,
  1093. uint32_t color_key)
  1094. {
  1095. uint32_t reg;
  1096. int y, u, v;
  1097. int red, green, blue;
  1098. if (!((channel == MEM_BG_SYNC || channel == MEM_FG_SYNC) ||
  1099. (channel == MEM_BG_ASYNC0 || channel == MEM_FG_ASYNC0) ||
  1100. (channel == MEM_BG_ASYNC1 || channel == MEM_FG_ASYNC1)))
  1101. return -EINVAL;
  1102. if (!g_ipu_clk_enabled)
  1103. clk_enable(g_ipu_clk);
  1104. color_key_4rgb = 1;
  1105. /* Transform color key from rgb to yuv if CSC is enabled */
  1106. if (((fg_csc_type == RGB2YUV) && (bg_csc_type == YUV2YUV)) ||
  1107. ((fg_csc_type == YUV2YUV) && (bg_csc_type == RGB2YUV)) ||
  1108. ((fg_csc_type == YUV2YUV) && (bg_csc_type == YUV2YUV)) ||
  1109. ((fg_csc_type == YUV2RGB) && (bg_csc_type == YUV2RGB))) {
  1110. debug("color key 0x%x need change to yuv fmt\n", color_key);
  1111. red = (color_key >> 16) & 0xFF;
  1112. green = (color_key >> 8) & 0xFF;
  1113. blue = color_key & 0xFF;
  1114. y = rgb_to_yuv(0, red, green, blue);
  1115. u = rgb_to_yuv(1, red, green, blue);
  1116. v = rgb_to_yuv(2, red, green, blue);
  1117. color_key = (y << 16) | (u << 8) | v;
  1118. color_key_4rgb = 0;
  1119. debug("color key change to yuv fmt 0x%x\n", color_key);
  1120. }
  1121. if (enable) {
  1122. reg = __raw_readl(DP_GRAPH_WIND_CTRL()) & 0xFF000000L;
  1123. __raw_writel(reg | color_key, DP_GRAPH_WIND_CTRL());
  1124. reg = __raw_readl(DP_COM_CONF());
  1125. __raw_writel(reg | DP_COM_CONF_GWCKE, DP_COM_CONF());
  1126. } else {
  1127. reg = __raw_readl(DP_COM_CONF());
  1128. __raw_writel(reg & ~DP_COM_CONF_GWCKE, DP_COM_CONF());
  1129. }
  1130. reg = __raw_readl(IPU_SRM_PRI2) | 0x8;
  1131. __raw_writel(reg, IPU_SRM_PRI2);
  1132. if (!g_ipu_clk_enabled)
  1133. clk_disable(g_ipu_clk);
  1134. return 0;
  1135. }