ipu_disp.c 36 KB

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