ipu_disp.c 34 KB

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