ipu_disp.c 36 KB

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