dcn10_optc.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  1. /*
  2. * Copyright 2012-15 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: AMD
  23. *
  24. */
  25. #include "reg_helper.h"
  26. #include "dcn10_optc.h"
  27. #include "dc.h"
  28. #define REG(reg)\
  29. optc1->tg_regs->reg
  30. #define CTX \
  31. optc1->base.ctx
  32. #undef FN
  33. #define FN(reg_name, field_name) \
  34. optc1->tg_shift->field_name, optc1->tg_mask->field_name
  35. #define STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN 0x100
  36. /**
  37. * apply_front_porch_workaround TODO FPGA still need?
  38. *
  39. * This is a workaround for a bug that has existed since R5xx and has not been
  40. * fixed keep Front porch at minimum 2 for Interlaced mode or 1 for progressive.
  41. */
  42. static void optc1_apply_front_porch_workaround(
  43. struct timing_generator *optc,
  44. struct dc_crtc_timing *timing)
  45. {
  46. if (timing->flags.INTERLACE == 1) {
  47. if (timing->v_front_porch < 2)
  48. timing->v_front_porch = 2;
  49. } else {
  50. if (timing->v_front_porch < 1)
  51. timing->v_front_porch = 1;
  52. }
  53. }
  54. void optc1_program_global_sync(
  55. struct timing_generator *optc)
  56. {
  57. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  58. if (optc->dlg_otg_param.vstartup_start == 0) {
  59. BREAK_TO_DEBUGGER();
  60. return;
  61. }
  62. REG_SET(OTG_VSTARTUP_PARAM, 0,
  63. VSTARTUP_START, optc->dlg_otg_param.vstartup_start);
  64. REG_SET_2(OTG_VUPDATE_PARAM, 0,
  65. VUPDATE_OFFSET, optc->dlg_otg_param.vupdate_offset,
  66. VUPDATE_WIDTH, optc->dlg_otg_param.vupdate_width);
  67. REG_SET(OTG_VREADY_PARAM, 0,
  68. VREADY_OFFSET, optc->dlg_otg_param.vready_offset);
  69. }
  70. static void optc1_disable_stereo(struct timing_generator *optc)
  71. {
  72. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  73. REG_SET(OTG_STEREO_CONTROL, 0,
  74. OTG_STEREO_EN, 0);
  75. REG_SET_3(OTG_3D_STRUCTURE_CONTROL, 0,
  76. OTG_3D_STRUCTURE_EN, 0,
  77. OTG_3D_STRUCTURE_V_UPDATE_MODE, 0,
  78. OTG_3D_STRUCTURE_STEREO_SEL_OVR, 0);
  79. }
  80. static uint32_t get_start_vline(struct timing_generator *optc, const struct dc_crtc_timing *dc_crtc_timing)
  81. {
  82. struct dc_crtc_timing patched_crtc_timing;
  83. int vesa_sync_start;
  84. int asic_blank_end;
  85. int vertical_line_start;
  86. patched_crtc_timing = *dc_crtc_timing;
  87. optc1_apply_front_porch_workaround(optc, &patched_crtc_timing);
  88. vesa_sync_start = patched_crtc_timing.h_addressable +
  89. patched_crtc_timing.h_border_right +
  90. patched_crtc_timing.h_front_porch;
  91. asic_blank_end = patched_crtc_timing.h_total -
  92. vesa_sync_start -
  93. patched_crtc_timing.h_border_left;
  94. vesa_sync_start = patched_crtc_timing.v_addressable +
  95. patched_crtc_timing.v_border_bottom +
  96. patched_crtc_timing.v_front_porch;
  97. asic_blank_end = (patched_crtc_timing.v_total -
  98. vesa_sync_start -
  99. patched_crtc_timing.v_border_top);
  100. vertical_line_start = asic_blank_end - optc->dlg_otg_param.vstartup_start + 1;
  101. if (vertical_line_start < 0) {
  102. ASSERT(0);
  103. vertical_line_start = 0;
  104. }
  105. return vertical_line_start;
  106. }
  107. void optc1_program_vline_interrupt(
  108. struct timing_generator *optc,
  109. const struct dc_crtc_timing *dc_crtc_timing,
  110. unsigned long long vsync_delta)
  111. {
  112. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  113. unsigned long long req_delta_tens_of_usec = div64_u64((vsync_delta + 9999), 10000);
  114. unsigned long long pix_clk_hundreds_khz = div64_u64((dc_crtc_timing->pix_clk_khz + 99), 100);
  115. uint32_t req_delta_lines = (uint32_t) div64_u64(
  116. (req_delta_tens_of_usec * pix_clk_hundreds_khz + dc_crtc_timing->h_total - 1),
  117. dc_crtc_timing->h_total);
  118. uint32_t vsync_line = get_start_vline(optc, dc_crtc_timing);
  119. uint32_t start_line = 0;
  120. uint32_t endLine = 0;
  121. if (req_delta_lines != 0)
  122. req_delta_lines--;
  123. if (req_delta_lines > vsync_line)
  124. start_line = dc_crtc_timing->v_total - (req_delta_lines - vsync_line) + 2;
  125. else
  126. start_line = vsync_line - req_delta_lines;
  127. endLine = start_line + 2;
  128. if (endLine >= dc_crtc_timing->v_total)
  129. endLine = 2;
  130. REG_SET_2(OTG_VERTICAL_INTERRUPT0_POSITION, 0,
  131. OTG_VERTICAL_INTERRUPT0_LINE_START, start_line,
  132. OTG_VERTICAL_INTERRUPT0_LINE_END, endLine);
  133. }
  134. /**
  135. * program_timing_generator used by mode timing set
  136. * Program CRTC Timing Registers - OTG_H_*, OTG_V_*, Pixel repetition.
  137. * Including SYNC. Call BIOS command table to program Timings.
  138. */
  139. void optc1_program_timing(
  140. struct timing_generator *optc,
  141. const struct dc_crtc_timing *dc_crtc_timing,
  142. bool use_vbios)
  143. {
  144. struct dc_crtc_timing patched_crtc_timing;
  145. uint32_t vesa_sync_start;
  146. uint32_t asic_blank_end;
  147. uint32_t asic_blank_start;
  148. uint32_t v_total;
  149. uint32_t v_sync_end;
  150. uint32_t v_init, v_fp2;
  151. uint32_t h_sync_polarity, v_sync_polarity;
  152. uint32_t start_point = 0;
  153. uint32_t field_num = 0;
  154. uint32_t h_div_2;
  155. int32_t vertical_line_start;
  156. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  157. patched_crtc_timing = *dc_crtc_timing;
  158. optc1_apply_front_porch_workaround(optc, &patched_crtc_timing);
  159. /* Load horizontal timing */
  160. /* CRTC_H_TOTAL = vesa.h_total - 1 */
  161. REG_SET(OTG_H_TOTAL, 0,
  162. OTG_H_TOTAL, patched_crtc_timing.h_total - 1);
  163. /* h_sync_start = 0, h_sync_end = vesa.h_sync_width */
  164. REG_UPDATE_2(OTG_H_SYNC_A,
  165. OTG_H_SYNC_A_START, 0,
  166. OTG_H_SYNC_A_END, patched_crtc_timing.h_sync_width);
  167. /* asic_h_blank_end = HsyncWidth + HbackPorch =
  168. * vesa. usHorizontalTotal - vesa. usHorizontalSyncStart -
  169. * vesa.h_left_border
  170. */
  171. vesa_sync_start = patched_crtc_timing.h_addressable +
  172. patched_crtc_timing.h_border_right +
  173. patched_crtc_timing.h_front_porch;
  174. asic_blank_end = patched_crtc_timing.h_total -
  175. vesa_sync_start -
  176. patched_crtc_timing.h_border_left;
  177. /* h_blank_start = v_blank_end + v_active */
  178. asic_blank_start = asic_blank_end +
  179. patched_crtc_timing.h_border_left +
  180. patched_crtc_timing.h_addressable +
  181. patched_crtc_timing.h_border_right;
  182. REG_UPDATE_2(OTG_H_BLANK_START_END,
  183. OTG_H_BLANK_START, asic_blank_start,
  184. OTG_H_BLANK_END, asic_blank_end);
  185. /* h_sync polarity */
  186. h_sync_polarity = patched_crtc_timing.flags.HSYNC_POSITIVE_POLARITY ?
  187. 0 : 1;
  188. REG_UPDATE(OTG_H_SYNC_A_CNTL,
  189. OTG_H_SYNC_A_POL, h_sync_polarity);
  190. v_total = patched_crtc_timing.v_total - 1;
  191. REG_SET(OTG_V_TOTAL, 0,
  192. OTG_V_TOTAL, v_total);
  193. /* In case of V_TOTAL_CONTROL is on, make sure OTG_V_TOTAL_MAX and
  194. * OTG_V_TOTAL_MIN are equal to V_TOTAL.
  195. */
  196. REG_SET(OTG_V_TOTAL_MAX, 0,
  197. OTG_V_TOTAL_MAX, v_total);
  198. REG_SET(OTG_V_TOTAL_MIN, 0,
  199. OTG_V_TOTAL_MIN, v_total);
  200. /* v_sync_start = 0, v_sync_end = v_sync_width */
  201. v_sync_end = patched_crtc_timing.v_sync_width;
  202. REG_UPDATE_2(OTG_V_SYNC_A,
  203. OTG_V_SYNC_A_START, 0,
  204. OTG_V_SYNC_A_END, v_sync_end);
  205. vesa_sync_start = patched_crtc_timing.v_addressable +
  206. patched_crtc_timing.v_border_bottom +
  207. patched_crtc_timing.v_front_porch;
  208. asic_blank_end = (patched_crtc_timing.v_total -
  209. vesa_sync_start -
  210. patched_crtc_timing.v_border_top);
  211. /* v_blank_start = v_blank_end + v_active */
  212. asic_blank_start = asic_blank_end +
  213. (patched_crtc_timing.v_border_top +
  214. patched_crtc_timing.v_addressable +
  215. patched_crtc_timing.v_border_bottom);
  216. REG_UPDATE_2(OTG_V_BLANK_START_END,
  217. OTG_V_BLANK_START, asic_blank_start,
  218. OTG_V_BLANK_END, asic_blank_end);
  219. /* Use OTG_VERTICAL_INTERRUPT2 replace VUPDATE interrupt,
  220. * program the reg for interrupt postition.
  221. */
  222. vertical_line_start = asic_blank_end - optc->dlg_otg_param.vstartup_start + 1;
  223. if (vertical_line_start < 0) {
  224. ASSERT(0);
  225. vertical_line_start = 0;
  226. }
  227. REG_SET(OTG_VERTICAL_INTERRUPT2_POSITION, 0,
  228. OTG_VERTICAL_INTERRUPT2_LINE_START, vertical_line_start);
  229. /* v_sync polarity */
  230. v_sync_polarity = patched_crtc_timing.flags.VSYNC_POSITIVE_POLARITY ?
  231. 0 : 1;
  232. REG_UPDATE(OTG_V_SYNC_A_CNTL,
  233. OTG_V_SYNC_A_POL, v_sync_polarity);
  234. v_init = asic_blank_start;
  235. if (optc->dlg_otg_param.signal == SIGNAL_TYPE_DISPLAY_PORT ||
  236. optc->dlg_otg_param.signal == SIGNAL_TYPE_DISPLAY_PORT_MST ||
  237. optc->dlg_otg_param.signal == SIGNAL_TYPE_EDP) {
  238. start_point = 1;
  239. if (patched_crtc_timing.flags.INTERLACE == 1)
  240. field_num = 1;
  241. }
  242. v_fp2 = 0;
  243. if (optc->dlg_otg_param.vstartup_start > asic_blank_end)
  244. v_fp2 = optc->dlg_otg_param.vstartup_start > asic_blank_end;
  245. /* Interlace */
  246. if (patched_crtc_timing.flags.INTERLACE == 1) {
  247. REG_UPDATE(OTG_INTERLACE_CONTROL,
  248. OTG_INTERLACE_ENABLE, 1);
  249. v_init = v_init / 2;
  250. if ((optc->dlg_otg_param.vstartup_start/2)*2 > asic_blank_end)
  251. v_fp2 = v_fp2 / 2;
  252. } else
  253. REG_UPDATE(OTG_INTERLACE_CONTROL,
  254. OTG_INTERLACE_ENABLE, 0);
  255. /* VTG enable set to 0 first VInit */
  256. REG_UPDATE(CONTROL,
  257. VTG0_ENABLE, 0);
  258. REG_UPDATE_2(CONTROL,
  259. VTG0_FP2, v_fp2,
  260. VTG0_VCOUNT_INIT, v_init);
  261. /* original code is using VTG offset to address OTG reg, seems wrong */
  262. REG_UPDATE_2(OTG_CONTROL,
  263. OTG_START_POINT_CNTL, start_point,
  264. OTG_FIELD_NUMBER_CNTL, field_num);
  265. optc1_program_global_sync(optc);
  266. /* TODO
  267. * patched_crtc_timing.flags.HORZ_COUNT_BY_TWO == 1
  268. * program_horz_count_by_2
  269. * for DVI 30bpp mode, 0 otherwise
  270. * program_horz_count_by_2(optc, &patched_crtc_timing);
  271. */
  272. /* Enable stereo - only when we need to pack 3D frame. Other types
  273. * of stereo handled in explicit call
  274. */
  275. h_div_2 = (dc_crtc_timing->pixel_encoding == PIXEL_ENCODING_YCBCR420) ?
  276. 1 : 0;
  277. REG_UPDATE(OTG_H_TIMING_CNTL,
  278. OTG_H_TIMING_DIV_BY2, h_div_2);
  279. }
  280. void optc1_set_blank_data_double_buffer(struct timing_generator *optc, bool enable)
  281. {
  282. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  283. uint32_t blank_data_double_buffer_enable = enable ? 1 : 0;
  284. REG_UPDATE(OTG_DOUBLE_BUFFER_CONTROL,
  285. OTG_BLANK_DATA_DOUBLE_BUFFER_EN, blank_data_double_buffer_enable);
  286. }
  287. /**
  288. * unblank_crtc
  289. * Call ASIC Control Object to UnBlank CRTC.
  290. */
  291. static void optc1_unblank_crtc(struct timing_generator *optc)
  292. {
  293. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  294. uint32_t vertical_interrupt_enable = 0;
  295. REG_GET(OTG_VERTICAL_INTERRUPT2_CONTROL,
  296. OTG_VERTICAL_INTERRUPT2_INT_ENABLE, &vertical_interrupt_enable);
  297. /* temporary work around for vertical interrupt, once vertical interrupt enabled,
  298. * this check will be removed.
  299. */
  300. if (vertical_interrupt_enable)
  301. optc1_set_blank_data_double_buffer(optc, true);
  302. REG_UPDATE_2(OTG_BLANK_CONTROL,
  303. OTG_BLANK_DATA_EN, 0,
  304. OTG_BLANK_DE_MODE, 0);
  305. }
  306. /**
  307. * blank_crtc
  308. * Call ASIC Control Object to Blank CRTC.
  309. */
  310. static void optc1_blank_crtc(struct timing_generator *optc)
  311. {
  312. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  313. REG_UPDATE_2(OTG_BLANK_CONTROL,
  314. OTG_BLANK_DATA_EN, 1,
  315. OTG_BLANK_DE_MODE, 0);
  316. optc1_set_blank_data_double_buffer(optc, false);
  317. }
  318. void optc1_set_blank(struct timing_generator *optc,
  319. bool enable_blanking)
  320. {
  321. if (enable_blanking)
  322. optc1_blank_crtc(optc);
  323. else
  324. optc1_unblank_crtc(optc);
  325. }
  326. bool optc1_is_blanked(struct timing_generator *optc)
  327. {
  328. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  329. uint32_t blank_en;
  330. uint32_t blank_state;
  331. REG_GET_2(OTG_BLANK_CONTROL,
  332. OTG_BLANK_DATA_EN, &blank_en,
  333. OTG_CURRENT_BLANK_STATE, &blank_state);
  334. return blank_en && blank_state;
  335. }
  336. void optc1_enable_optc_clock(struct timing_generator *optc, bool enable)
  337. {
  338. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  339. if (enable) {
  340. REG_UPDATE_2(OPTC_INPUT_CLOCK_CONTROL,
  341. OPTC_INPUT_CLK_EN, 1,
  342. OPTC_INPUT_CLK_GATE_DIS, 1);
  343. REG_WAIT(OPTC_INPUT_CLOCK_CONTROL,
  344. OPTC_INPUT_CLK_ON, 1,
  345. 1, 1000);
  346. /* Enable clock */
  347. REG_UPDATE_2(OTG_CLOCK_CONTROL,
  348. OTG_CLOCK_EN, 1,
  349. OTG_CLOCK_GATE_DIS, 1);
  350. REG_WAIT(OTG_CLOCK_CONTROL,
  351. OTG_CLOCK_ON, 1,
  352. 1, 1000);
  353. } else {
  354. REG_UPDATE_2(OTG_CLOCK_CONTROL,
  355. OTG_CLOCK_GATE_DIS, 0,
  356. OTG_CLOCK_EN, 0);
  357. REG_UPDATE_2(OPTC_INPUT_CLOCK_CONTROL,
  358. OPTC_INPUT_CLK_GATE_DIS, 0,
  359. OPTC_INPUT_CLK_EN, 0);
  360. }
  361. }
  362. /**
  363. * Enable CRTC
  364. * Enable CRTC - call ASIC Control Object to enable Timing generator.
  365. */
  366. static bool optc1_enable_crtc(struct timing_generator *optc)
  367. {
  368. /* TODO FPGA wait for answer
  369. * OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE
  370. * OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK
  371. */
  372. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  373. /* opp instance for OTG. For DCN1.0, ODM is remoed.
  374. * OPP and OPTC should 1:1 mapping
  375. */
  376. REG_UPDATE(OPTC_DATA_SOURCE_SELECT,
  377. OPTC_SRC_SEL, optc->inst);
  378. /* VTG enable first is for HW workaround */
  379. REG_UPDATE(CONTROL,
  380. VTG0_ENABLE, 1);
  381. /* Enable CRTC */
  382. REG_UPDATE_2(OTG_CONTROL,
  383. OTG_DISABLE_POINT_CNTL, 3,
  384. OTG_MASTER_EN, 1);
  385. return true;
  386. }
  387. /* disable_crtc - call ASIC Control Object to disable Timing generator. */
  388. bool optc1_disable_crtc(struct timing_generator *optc)
  389. {
  390. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  391. /* disable otg request until end of the first line
  392. * in the vertical blank region
  393. */
  394. REG_UPDATE_2(OTG_CONTROL,
  395. OTG_DISABLE_POINT_CNTL, 3,
  396. OTG_MASTER_EN, 0);
  397. REG_UPDATE(CONTROL,
  398. VTG0_ENABLE, 0);
  399. /* CRTC disabled, so disable clock. */
  400. REG_WAIT(OTG_CLOCK_CONTROL,
  401. OTG_BUSY, 0,
  402. 1, 100000);
  403. return true;
  404. }
  405. void optc1_program_blank_color(
  406. struct timing_generator *optc,
  407. const struct tg_color *black_color)
  408. {
  409. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  410. REG_SET_3(OTG_BLACK_COLOR, 0,
  411. OTG_BLACK_COLOR_B_CB, black_color->color_b_cb,
  412. OTG_BLACK_COLOR_G_Y, black_color->color_g_y,
  413. OTG_BLACK_COLOR_R_CR, black_color->color_r_cr);
  414. }
  415. bool optc1_validate_timing(
  416. struct timing_generator *optc,
  417. const struct dc_crtc_timing *timing)
  418. {
  419. uint32_t v_blank;
  420. uint32_t h_blank;
  421. uint32_t min_v_blank;
  422. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  423. ASSERT(timing != NULL);
  424. v_blank = (timing->v_total - timing->v_addressable -
  425. timing->v_border_top - timing->v_border_bottom);
  426. h_blank = (timing->h_total - timing->h_addressable -
  427. timing->h_border_right -
  428. timing->h_border_left);
  429. if (timing->timing_3d_format != TIMING_3D_FORMAT_NONE &&
  430. timing->timing_3d_format != TIMING_3D_FORMAT_HW_FRAME_PACKING &&
  431. timing->timing_3d_format != TIMING_3D_FORMAT_TOP_AND_BOTTOM &&
  432. timing->timing_3d_format != TIMING_3D_FORMAT_SIDE_BY_SIDE &&
  433. timing->timing_3d_format != TIMING_3D_FORMAT_FRAME_ALTERNATE &&
  434. timing->timing_3d_format != TIMING_3D_FORMAT_INBAND_FA)
  435. return false;
  436. /* Temporarily blocking interlacing mode until it's supported */
  437. if (timing->flags.INTERLACE == 1)
  438. return false;
  439. /* Check maximum number of pixels supported by Timing Generator
  440. * (Currently will never fail, in order to fail needs display which
  441. * needs more than 8192 horizontal and
  442. * more than 8192 vertical total pixels)
  443. */
  444. if (timing->h_total > optc1->max_h_total ||
  445. timing->v_total > optc1->max_v_total)
  446. return false;
  447. if (h_blank < optc1->min_h_blank)
  448. return false;
  449. if (timing->h_sync_width < optc1->min_h_sync_width ||
  450. timing->v_sync_width < optc1->min_v_sync_width)
  451. return false;
  452. min_v_blank = timing->flags.INTERLACE?optc1->min_v_blank_interlace:optc1->min_v_blank;
  453. if (v_blank < min_v_blank)
  454. return false;
  455. return true;
  456. }
  457. /*
  458. * get_vblank_counter
  459. *
  460. * @brief
  461. * Get counter for vertical blanks. use register CRTC_STATUS_FRAME_COUNT which
  462. * holds the counter of frames.
  463. *
  464. * @param
  465. * struct timing_generator *optc - [in] timing generator which controls the
  466. * desired CRTC
  467. *
  468. * @return
  469. * Counter of frames, which should equal to number of vblanks.
  470. */
  471. uint32_t optc1_get_vblank_counter(struct timing_generator *optc)
  472. {
  473. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  474. uint32_t frame_count;
  475. REG_GET(OTG_STATUS_FRAME_COUNT,
  476. OTG_FRAME_COUNT, &frame_count);
  477. return frame_count;
  478. }
  479. void optc1_lock(struct timing_generator *optc)
  480. {
  481. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  482. REG_SET(OTG_GLOBAL_CONTROL0, 0,
  483. OTG_MASTER_UPDATE_LOCK_SEL, optc->inst);
  484. REG_SET(OTG_MASTER_UPDATE_LOCK, 0,
  485. OTG_MASTER_UPDATE_LOCK, 1);
  486. /* Should be fast, status does not update on maximus */
  487. if (optc->ctx->dce_environment != DCE_ENV_FPGA_MAXIMUS)
  488. REG_WAIT(OTG_MASTER_UPDATE_LOCK,
  489. UPDATE_LOCK_STATUS, 1,
  490. 1, 10);
  491. }
  492. void optc1_unlock(struct timing_generator *optc)
  493. {
  494. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  495. REG_SET(OTG_MASTER_UPDATE_LOCK, 0,
  496. OTG_MASTER_UPDATE_LOCK, 0);
  497. }
  498. void optc1_get_position(struct timing_generator *optc,
  499. struct crtc_position *position)
  500. {
  501. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  502. REG_GET_2(OTG_STATUS_POSITION,
  503. OTG_HORZ_COUNT, &position->horizontal_count,
  504. OTG_VERT_COUNT, &position->vertical_count);
  505. REG_GET(OTG_NOM_VERT_POSITION,
  506. OTG_VERT_COUNT_NOM, &position->nominal_vcount);
  507. }
  508. bool optc1_is_counter_moving(struct timing_generator *optc)
  509. {
  510. struct crtc_position position1, position2;
  511. optc->funcs->get_position(optc, &position1);
  512. optc->funcs->get_position(optc, &position2);
  513. if (position1.horizontal_count == position2.horizontal_count &&
  514. position1.vertical_count == position2.vertical_count)
  515. return false;
  516. else
  517. return true;
  518. }
  519. bool optc1_did_triggered_reset_occur(
  520. struct timing_generator *optc)
  521. {
  522. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  523. uint32_t occurred_force, occurred_vsync;
  524. REG_GET(OTG_FORCE_COUNT_NOW_CNTL,
  525. OTG_FORCE_COUNT_NOW_OCCURRED, &occurred_force);
  526. REG_GET(OTG_VERT_SYNC_CONTROL,
  527. OTG_FORCE_VSYNC_NEXT_LINE_OCCURRED, &occurred_vsync);
  528. return occurred_vsync != 0 || occurred_force != 0;
  529. }
  530. void optc1_disable_reset_trigger(struct timing_generator *optc)
  531. {
  532. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  533. REG_WRITE(OTG_TRIGA_CNTL, 0);
  534. REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
  535. OTG_FORCE_COUNT_NOW_CLEAR, 1);
  536. REG_SET(OTG_VERT_SYNC_CONTROL, 0,
  537. OTG_FORCE_VSYNC_NEXT_LINE_CLEAR, 1);
  538. }
  539. void optc1_enable_reset_trigger(struct timing_generator *optc, int source_tg_inst)
  540. {
  541. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  542. uint32_t falling_edge;
  543. REG_GET(OTG_V_SYNC_A_CNTL,
  544. OTG_V_SYNC_A_POL, &falling_edge);
  545. if (falling_edge)
  546. REG_SET_3(OTG_TRIGA_CNTL, 0,
  547. /* vsync signal from selected OTG pipe based
  548. * on OTG_TRIG_SOURCE_PIPE_SELECT setting
  549. */
  550. OTG_TRIGA_SOURCE_SELECT, 20,
  551. OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
  552. /* always detect falling edge */
  553. OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, 1);
  554. else
  555. REG_SET_3(OTG_TRIGA_CNTL, 0,
  556. /* vsync signal from selected OTG pipe based
  557. * on OTG_TRIG_SOURCE_PIPE_SELECT setting
  558. */
  559. OTG_TRIGA_SOURCE_SELECT, 20,
  560. OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
  561. /* always detect rising edge */
  562. OTG_TRIGA_RISING_EDGE_DETECT_CNTL, 1);
  563. REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
  564. /* force H count to H_TOTAL and V count to V_TOTAL in
  565. * progressive mode and V_TOTAL-1 in interlaced mode
  566. */
  567. OTG_FORCE_COUNT_NOW_MODE, 2);
  568. }
  569. void optc1_enable_crtc_reset(
  570. struct timing_generator *optc,
  571. int source_tg_inst,
  572. struct crtc_trigger_info *crtc_tp)
  573. {
  574. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  575. uint32_t falling_edge = 0;
  576. uint32_t rising_edge = 0;
  577. switch (crtc_tp->event) {
  578. case CRTC_EVENT_VSYNC_RISING:
  579. rising_edge = 1;
  580. break;
  581. case CRTC_EVENT_VSYNC_FALLING:
  582. falling_edge = 1;
  583. break;
  584. }
  585. REG_SET_4(OTG_TRIGA_CNTL, 0,
  586. /* vsync signal from selected OTG pipe based
  587. * on OTG_TRIG_SOURCE_PIPE_SELECT setting
  588. */
  589. OTG_TRIGA_SOURCE_SELECT, 20,
  590. OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
  591. /* always detect falling edge */
  592. OTG_TRIGA_RISING_EDGE_DETECT_CNTL, rising_edge,
  593. OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, falling_edge);
  594. switch (crtc_tp->delay) {
  595. case TRIGGER_DELAY_NEXT_LINE:
  596. REG_SET(OTG_VERT_SYNC_CONTROL, 0,
  597. OTG_AUTO_FORCE_VSYNC_MODE, 1);
  598. break;
  599. case TRIGGER_DELAY_NEXT_PIXEL:
  600. REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
  601. /* force H count to H_TOTAL and V count to V_TOTAL in
  602. * progressive mode and V_TOTAL-1 in interlaced mode
  603. */
  604. OTG_FORCE_COUNT_NOW_MODE, 2);
  605. break;
  606. }
  607. }
  608. void optc1_wait_for_state(struct timing_generator *optc,
  609. enum crtc_state state)
  610. {
  611. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  612. switch (state) {
  613. case CRTC_STATE_VBLANK:
  614. REG_WAIT(OTG_STATUS,
  615. OTG_V_BLANK, 1,
  616. 1, 100000); /* 1 vupdate at 10hz */
  617. break;
  618. case CRTC_STATE_VACTIVE:
  619. REG_WAIT(OTG_STATUS,
  620. OTG_V_ACTIVE_DISP, 1,
  621. 1, 100000); /* 1 vupdate at 10hz */
  622. break;
  623. default:
  624. break;
  625. }
  626. }
  627. void optc1_set_early_control(
  628. struct timing_generator *optc,
  629. uint32_t early_cntl)
  630. {
  631. /* asic design change, do not need this control
  632. * empty for share caller logic
  633. */
  634. }
  635. void optc1_set_static_screen_control(
  636. struct timing_generator *optc,
  637. uint32_t value)
  638. {
  639. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  640. /* Bit 8 is no longer applicable in RV for PSR case,
  641. * set bit 8 to 0 if given
  642. */
  643. if ((value & STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN)
  644. != 0)
  645. value = value &
  646. ~STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN;
  647. REG_SET_2(OTG_STATIC_SCREEN_CONTROL, 0,
  648. OTG_STATIC_SCREEN_EVENT_MASK, value,
  649. OTG_STATIC_SCREEN_FRAME_COUNT, 2);
  650. }
  651. /**
  652. *****************************************************************************
  653. * Function: set_drr
  654. *
  655. * @brief
  656. * Program dynamic refresh rate registers m_OTGx_OTG_V_TOTAL_*.
  657. *
  658. *****************************************************************************
  659. */
  660. void optc1_set_drr(
  661. struct timing_generator *optc,
  662. const struct drr_params *params)
  663. {
  664. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  665. if (params != NULL &&
  666. params->vertical_total_max > 0 &&
  667. params->vertical_total_min > 0) {
  668. REG_SET(OTG_V_TOTAL_MAX, 0,
  669. OTG_V_TOTAL_MAX, params->vertical_total_max - 1);
  670. REG_SET(OTG_V_TOTAL_MIN, 0,
  671. OTG_V_TOTAL_MIN, params->vertical_total_min - 1);
  672. REG_UPDATE_5(OTG_V_TOTAL_CONTROL,
  673. OTG_V_TOTAL_MIN_SEL, 1,
  674. OTG_V_TOTAL_MAX_SEL, 1,
  675. OTG_FORCE_LOCK_ON_EVENT, 0,
  676. OTG_SET_V_TOTAL_MIN_MASK_EN, 0,
  677. OTG_SET_V_TOTAL_MIN_MASK, 0);
  678. } else {
  679. REG_UPDATE_4(OTG_V_TOTAL_CONTROL,
  680. OTG_SET_V_TOTAL_MIN_MASK, 0,
  681. OTG_V_TOTAL_MIN_SEL, 0,
  682. OTG_V_TOTAL_MAX_SEL, 0,
  683. OTG_FORCE_LOCK_ON_EVENT, 0);
  684. REG_SET(OTG_V_TOTAL_MIN, 0,
  685. OTG_V_TOTAL_MIN, 0);
  686. REG_SET(OTG_V_TOTAL_MAX, 0,
  687. OTG_V_TOTAL_MAX, 0);
  688. }
  689. }
  690. static void optc1_set_test_pattern(
  691. struct timing_generator *optc,
  692. /* TODO: replace 'controller_dp_test_pattern' by 'test_pattern_mode'
  693. * because this is not DP-specific (which is probably somewhere in DP
  694. * encoder) */
  695. enum controller_dp_test_pattern test_pattern,
  696. enum dc_color_depth color_depth)
  697. {
  698. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  699. enum test_pattern_color_format bit_depth;
  700. enum test_pattern_dyn_range dyn_range;
  701. enum test_pattern_mode mode;
  702. uint32_t pattern_mask;
  703. uint32_t pattern_data;
  704. /* color ramp generator mixes 16-bits color */
  705. uint32_t src_bpc = 16;
  706. /* requested bpc */
  707. uint32_t dst_bpc;
  708. uint32_t index;
  709. /* RGB values of the color bars.
  710. * Produce two RGB colors: RGB0 - white (all Fs)
  711. * and RGB1 - black (all 0s)
  712. * (three RGB components for two colors)
  713. */
  714. uint16_t src_color[6] = {0xFFFF, 0xFFFF, 0xFFFF, 0x0000,
  715. 0x0000, 0x0000};
  716. /* dest color (converted to the specified color format) */
  717. uint16_t dst_color[6];
  718. uint32_t inc_base;
  719. /* translate to bit depth */
  720. switch (color_depth) {
  721. case COLOR_DEPTH_666:
  722. bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_6;
  723. break;
  724. case COLOR_DEPTH_888:
  725. bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_8;
  726. break;
  727. case COLOR_DEPTH_101010:
  728. bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_10;
  729. break;
  730. case COLOR_DEPTH_121212:
  731. bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_12;
  732. break;
  733. default:
  734. bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_8;
  735. break;
  736. }
  737. switch (test_pattern) {
  738. case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES:
  739. case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA:
  740. {
  741. dyn_range = (test_pattern ==
  742. CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA ?
  743. TEST_PATTERN_DYN_RANGE_CEA :
  744. TEST_PATTERN_DYN_RANGE_VESA);
  745. mode = TEST_PATTERN_MODE_COLORSQUARES_RGB;
  746. REG_UPDATE_2(OTG_TEST_PATTERN_PARAMETERS,
  747. OTG_TEST_PATTERN_VRES, 6,
  748. OTG_TEST_PATTERN_HRES, 6);
  749. REG_UPDATE_4(OTG_TEST_PATTERN_CONTROL,
  750. OTG_TEST_PATTERN_EN, 1,
  751. OTG_TEST_PATTERN_MODE, mode,
  752. OTG_TEST_PATTERN_DYNAMIC_RANGE, dyn_range,
  753. OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
  754. }
  755. break;
  756. case CONTROLLER_DP_TEST_PATTERN_VERTICALBARS:
  757. case CONTROLLER_DP_TEST_PATTERN_HORIZONTALBARS:
  758. {
  759. mode = (test_pattern ==
  760. CONTROLLER_DP_TEST_PATTERN_VERTICALBARS ?
  761. TEST_PATTERN_MODE_VERTICALBARS :
  762. TEST_PATTERN_MODE_HORIZONTALBARS);
  763. switch (bit_depth) {
  764. case TEST_PATTERN_COLOR_FORMAT_BPC_6:
  765. dst_bpc = 6;
  766. break;
  767. case TEST_PATTERN_COLOR_FORMAT_BPC_8:
  768. dst_bpc = 8;
  769. break;
  770. case TEST_PATTERN_COLOR_FORMAT_BPC_10:
  771. dst_bpc = 10;
  772. break;
  773. default:
  774. dst_bpc = 8;
  775. break;
  776. }
  777. /* adjust color to the required colorFormat */
  778. for (index = 0; index < 6; index++) {
  779. /* dst = 2^dstBpc * src / 2^srcBpc = src >>
  780. * (srcBpc - dstBpc);
  781. */
  782. dst_color[index] =
  783. src_color[index] >> (src_bpc - dst_bpc);
  784. /* CRTC_TEST_PATTERN_DATA has 16 bits,
  785. * lowest 6 are hardwired to ZERO
  786. * color bits should be left aligned aligned to MSB
  787. * XXXXXXXXXX000000 for 10 bit,
  788. * XXXXXXXX00000000 for 8 bit and XXXXXX0000000000 for 6
  789. */
  790. dst_color[index] <<= (16 - dst_bpc);
  791. }
  792. REG_WRITE(OTG_TEST_PATTERN_PARAMETERS, 0);
  793. /* We have to write the mask before data, similar to pipeline.
  794. * For example, for 8 bpc, if we want RGB0 to be magenta,
  795. * and RGB1 to be cyan,
  796. * we need to make 7 writes:
  797. * MASK DATA
  798. * 000001 00000000 00000000 set mask to R0
  799. * 000010 11111111 00000000 R0 255, 0xFF00, set mask to G0
  800. * 000100 00000000 00000000 G0 0, 0x0000, set mask to B0
  801. * 001000 11111111 00000000 B0 255, 0xFF00, set mask to R1
  802. * 010000 00000000 00000000 R1 0, 0x0000, set mask to G1
  803. * 100000 11111111 00000000 G1 255, 0xFF00, set mask to B1
  804. * 100000 11111111 00000000 B1 255, 0xFF00
  805. *
  806. * we will make a loop of 6 in which we prepare the mask,
  807. * then write, then prepare the color for next write.
  808. * first iteration will write mask only,
  809. * but each next iteration color prepared in
  810. * previous iteration will be written within new mask,
  811. * the last component will written separately,
  812. * mask is not changing between 6th and 7th write
  813. * and color will be prepared by last iteration
  814. */
  815. /* write color, color values mask in CRTC_TEST_PATTERN_MASK
  816. * is B1, G1, R1, B0, G0, R0
  817. */
  818. pattern_data = 0;
  819. for (index = 0; index < 6; index++) {
  820. /* prepare color mask, first write PATTERN_DATA
  821. * will have all zeros
  822. */
  823. pattern_mask = (1 << index);
  824. /* write color component */
  825. REG_SET_2(OTG_TEST_PATTERN_COLOR, 0,
  826. OTG_TEST_PATTERN_MASK, pattern_mask,
  827. OTG_TEST_PATTERN_DATA, pattern_data);
  828. /* prepare next color component,
  829. * will be written in the next iteration
  830. */
  831. pattern_data = dst_color[index];
  832. }
  833. /* write last color component,
  834. * it's been already prepared in the loop
  835. */
  836. REG_SET_2(OTG_TEST_PATTERN_COLOR, 0,
  837. OTG_TEST_PATTERN_MASK, pattern_mask,
  838. OTG_TEST_PATTERN_DATA, pattern_data);
  839. /* enable test pattern */
  840. REG_UPDATE_4(OTG_TEST_PATTERN_CONTROL,
  841. OTG_TEST_PATTERN_EN, 1,
  842. OTG_TEST_PATTERN_MODE, mode,
  843. OTG_TEST_PATTERN_DYNAMIC_RANGE, 0,
  844. OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
  845. }
  846. break;
  847. case CONTROLLER_DP_TEST_PATTERN_COLORRAMP:
  848. {
  849. mode = (bit_depth ==
  850. TEST_PATTERN_COLOR_FORMAT_BPC_10 ?
  851. TEST_PATTERN_MODE_DUALRAMP_RGB :
  852. TEST_PATTERN_MODE_SINGLERAMP_RGB);
  853. switch (bit_depth) {
  854. case TEST_PATTERN_COLOR_FORMAT_BPC_6:
  855. dst_bpc = 6;
  856. break;
  857. case TEST_PATTERN_COLOR_FORMAT_BPC_8:
  858. dst_bpc = 8;
  859. break;
  860. case TEST_PATTERN_COLOR_FORMAT_BPC_10:
  861. dst_bpc = 10;
  862. break;
  863. default:
  864. dst_bpc = 8;
  865. break;
  866. }
  867. /* increment for the first ramp for one color gradation
  868. * 1 gradation for 6-bit color is 2^10
  869. * gradations in 16-bit color
  870. */
  871. inc_base = (src_bpc - dst_bpc);
  872. switch (bit_depth) {
  873. case TEST_PATTERN_COLOR_FORMAT_BPC_6:
  874. {
  875. REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
  876. OTG_TEST_PATTERN_INC0, inc_base,
  877. OTG_TEST_PATTERN_INC1, 0,
  878. OTG_TEST_PATTERN_HRES, 6,
  879. OTG_TEST_PATTERN_VRES, 6,
  880. OTG_TEST_PATTERN_RAMP0_OFFSET, 0);
  881. }
  882. break;
  883. case TEST_PATTERN_COLOR_FORMAT_BPC_8:
  884. {
  885. REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
  886. OTG_TEST_PATTERN_INC0, inc_base,
  887. OTG_TEST_PATTERN_INC1, 0,
  888. OTG_TEST_PATTERN_HRES, 8,
  889. OTG_TEST_PATTERN_VRES, 6,
  890. OTG_TEST_PATTERN_RAMP0_OFFSET, 0);
  891. }
  892. break;
  893. case TEST_PATTERN_COLOR_FORMAT_BPC_10:
  894. {
  895. REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
  896. OTG_TEST_PATTERN_INC0, inc_base,
  897. OTG_TEST_PATTERN_INC1, inc_base + 2,
  898. OTG_TEST_PATTERN_HRES, 8,
  899. OTG_TEST_PATTERN_VRES, 5,
  900. OTG_TEST_PATTERN_RAMP0_OFFSET, 384 << 6);
  901. }
  902. break;
  903. default:
  904. break;
  905. }
  906. REG_WRITE(OTG_TEST_PATTERN_COLOR, 0);
  907. /* enable test pattern */
  908. REG_WRITE(OTG_TEST_PATTERN_CONTROL, 0);
  909. REG_SET_4(OTG_TEST_PATTERN_CONTROL, 0,
  910. OTG_TEST_PATTERN_EN, 1,
  911. OTG_TEST_PATTERN_MODE, mode,
  912. OTG_TEST_PATTERN_DYNAMIC_RANGE, 0,
  913. OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
  914. }
  915. break;
  916. case CONTROLLER_DP_TEST_PATTERN_VIDEOMODE:
  917. {
  918. REG_WRITE(OTG_TEST_PATTERN_CONTROL, 0);
  919. REG_WRITE(OTG_TEST_PATTERN_COLOR, 0);
  920. REG_WRITE(OTG_TEST_PATTERN_PARAMETERS, 0);
  921. }
  922. break;
  923. default:
  924. break;
  925. }
  926. }
  927. void optc1_get_crtc_scanoutpos(
  928. struct timing_generator *optc,
  929. uint32_t *v_blank_start,
  930. uint32_t *v_blank_end,
  931. uint32_t *h_position,
  932. uint32_t *v_position)
  933. {
  934. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  935. struct crtc_position position;
  936. REG_GET_2(OTG_V_BLANK_START_END,
  937. OTG_V_BLANK_START, v_blank_start,
  938. OTG_V_BLANK_END, v_blank_end);
  939. optc1_get_position(optc, &position);
  940. *h_position = position.horizontal_count;
  941. *v_position = position.vertical_count;
  942. }
  943. static void optc1_enable_stereo(struct timing_generator *optc,
  944. const struct dc_crtc_timing *timing, struct crtc_stereo_flags *flags)
  945. {
  946. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  947. if (flags) {
  948. uint32_t stereo_en;
  949. stereo_en = flags->FRAME_PACKED == 0 ? 1 : 0;
  950. if (flags->PROGRAM_STEREO)
  951. REG_UPDATE_3(OTG_STEREO_CONTROL,
  952. OTG_STEREO_EN, stereo_en,
  953. OTG_STEREO_SYNC_OUTPUT_LINE_NUM, 0,
  954. OTG_STEREO_SYNC_OUTPUT_POLARITY, 0);
  955. if (flags->PROGRAM_POLARITY)
  956. REG_UPDATE(OTG_STEREO_CONTROL,
  957. OTG_STEREO_EYE_FLAG_POLARITY,
  958. flags->RIGHT_EYE_POLARITY == 0 ? 0 : 1);
  959. if (flags->DISABLE_STEREO_DP_SYNC)
  960. REG_UPDATE(OTG_STEREO_CONTROL,
  961. OTG_DISABLE_STEREOSYNC_OUTPUT_FOR_DP, 1);
  962. if (flags->PROGRAM_STEREO)
  963. REG_UPDATE_3(OTG_3D_STRUCTURE_CONTROL,
  964. OTG_3D_STRUCTURE_EN, flags->FRAME_PACKED,
  965. OTG_3D_STRUCTURE_V_UPDATE_MODE, flags->FRAME_PACKED,
  966. OTG_3D_STRUCTURE_STEREO_SEL_OVR, flags->FRAME_PACKED);
  967. }
  968. }
  969. void optc1_program_stereo(struct timing_generator *optc,
  970. const struct dc_crtc_timing *timing, struct crtc_stereo_flags *flags)
  971. {
  972. if (flags->PROGRAM_STEREO)
  973. optc1_enable_stereo(optc, timing, flags);
  974. else
  975. optc1_disable_stereo(optc);
  976. }
  977. bool optc1_is_stereo_left_eye(struct timing_generator *optc)
  978. {
  979. bool ret = false;
  980. uint32_t left_eye = 0;
  981. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  982. REG_GET(OTG_STEREO_STATUS,
  983. OTG_STEREO_CURRENT_EYE, &left_eye);
  984. if (left_eye == 1)
  985. ret = true;
  986. else
  987. ret = false;
  988. return ret;
  989. }
  990. void optc1_read_otg_state(struct optc *optc1,
  991. struct dcn_otg_state *s)
  992. {
  993. REG_GET(OTG_CONTROL,
  994. OTG_MASTER_EN, &s->otg_enabled);
  995. REG_GET_2(OTG_V_BLANK_START_END,
  996. OTG_V_BLANK_START, &s->v_blank_start,
  997. OTG_V_BLANK_END, &s->v_blank_end);
  998. REG_GET(OTG_V_SYNC_A_CNTL,
  999. OTG_V_SYNC_A_POL, &s->v_sync_a_pol);
  1000. REG_GET(OTG_V_TOTAL,
  1001. OTG_V_TOTAL, &s->v_total);
  1002. REG_GET(OTG_V_TOTAL_MAX,
  1003. OTG_V_TOTAL_MAX, &s->v_total_max);
  1004. REG_GET(OTG_V_TOTAL_MIN,
  1005. OTG_V_TOTAL_MIN, &s->v_total_min);
  1006. REG_GET(OTG_V_TOTAL_CONTROL,
  1007. OTG_V_TOTAL_MAX_SEL, &s->v_total_max_sel);
  1008. REG_GET(OTG_V_TOTAL_CONTROL,
  1009. OTG_V_TOTAL_MIN_SEL, &s->v_total_min_sel);
  1010. REG_GET_2(OTG_V_SYNC_A,
  1011. OTG_V_SYNC_A_START, &s->v_sync_a_start,
  1012. OTG_V_SYNC_A_END, &s->v_sync_a_end);
  1013. REG_GET_2(OTG_H_BLANK_START_END,
  1014. OTG_H_BLANK_START, &s->h_blank_start,
  1015. OTG_H_BLANK_END, &s->h_blank_end);
  1016. REG_GET_2(OTG_H_SYNC_A,
  1017. OTG_H_SYNC_A_START, &s->h_sync_a_start,
  1018. OTG_H_SYNC_A_END, &s->h_sync_a_end);
  1019. REG_GET(OTG_H_SYNC_A_CNTL,
  1020. OTG_H_SYNC_A_POL, &s->h_sync_a_pol);
  1021. REG_GET(OTG_H_TOTAL,
  1022. OTG_H_TOTAL, &s->h_total);
  1023. REG_GET(OPTC_INPUT_GLOBAL_CONTROL,
  1024. OPTC_UNDERFLOW_OCCURRED_STATUS, &s->underflow_occurred_status);
  1025. }
  1026. bool optc1_get_otg_active_size(struct timing_generator *optc,
  1027. uint32_t *otg_active_width,
  1028. uint32_t *otg_active_height)
  1029. {
  1030. uint32_t otg_enabled;
  1031. uint32_t v_blank_start;
  1032. uint32_t v_blank_end;
  1033. uint32_t h_blank_start;
  1034. uint32_t h_blank_end;
  1035. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  1036. REG_GET(OTG_CONTROL,
  1037. OTG_MASTER_EN, &otg_enabled);
  1038. if (otg_enabled == 0)
  1039. return false;
  1040. REG_GET_2(OTG_V_BLANK_START_END,
  1041. OTG_V_BLANK_START, &v_blank_start,
  1042. OTG_V_BLANK_END, &v_blank_end);
  1043. REG_GET_2(OTG_H_BLANK_START_END,
  1044. OTG_H_BLANK_START, &h_blank_start,
  1045. OTG_H_BLANK_END, &h_blank_end);
  1046. *otg_active_width = v_blank_start - v_blank_end;
  1047. *otg_active_height = h_blank_start - h_blank_end;
  1048. return true;
  1049. }
  1050. void optc1_clear_optc_underflow(struct timing_generator *optc)
  1051. {
  1052. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  1053. REG_UPDATE(OPTC_INPUT_GLOBAL_CONTROL, OPTC_UNDERFLOW_CLEAR, 1);
  1054. }
  1055. void optc1_tg_init(struct timing_generator *optc)
  1056. {
  1057. optc1_set_blank_data_double_buffer(optc, true);
  1058. optc1_clear_optc_underflow(optc);
  1059. }
  1060. bool optc1_is_tg_enabled(struct timing_generator *optc)
  1061. {
  1062. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  1063. uint32_t otg_enabled = 0;
  1064. REG_GET(OTG_CONTROL, OTG_MASTER_EN, &otg_enabled);
  1065. return (otg_enabled != 0);
  1066. }
  1067. bool optc1_is_optc_underflow_occurred(struct timing_generator *optc)
  1068. {
  1069. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  1070. uint32_t underflow_occurred = 0;
  1071. REG_GET(OPTC_INPUT_GLOBAL_CONTROL,
  1072. OPTC_UNDERFLOW_OCCURRED_STATUS,
  1073. &underflow_occurred);
  1074. return (underflow_occurred == 1);
  1075. }
  1076. bool optc1_configure_crc(struct timing_generator *optc,
  1077. const struct crc_params *params)
  1078. {
  1079. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  1080. /* Cannot configure crc on a CRTC that is disabled */
  1081. if (!optc1_is_tg_enabled(optc))
  1082. return false;
  1083. REG_WRITE(OTG_CRC_CNTL, 0);
  1084. if (!params->enable)
  1085. return true;
  1086. /* Program frame boundaries */
  1087. /* Window A x axis start and end. */
  1088. REG_UPDATE_2(OTG_CRC0_WINDOWA_X_CONTROL,
  1089. OTG_CRC0_WINDOWA_X_START, params->windowa_x_start,
  1090. OTG_CRC0_WINDOWA_X_END, params->windowa_x_end);
  1091. /* Window A y axis start and end. */
  1092. REG_UPDATE_2(OTG_CRC0_WINDOWA_Y_CONTROL,
  1093. OTG_CRC0_WINDOWA_Y_START, params->windowa_y_start,
  1094. OTG_CRC0_WINDOWA_Y_END, params->windowa_y_end);
  1095. /* Window B x axis start and end. */
  1096. REG_UPDATE_2(OTG_CRC0_WINDOWB_X_CONTROL,
  1097. OTG_CRC0_WINDOWB_X_START, params->windowb_x_start,
  1098. OTG_CRC0_WINDOWB_X_END, params->windowb_x_end);
  1099. /* Window B y axis start and end. */
  1100. REG_UPDATE_2(OTG_CRC0_WINDOWB_Y_CONTROL,
  1101. OTG_CRC0_WINDOWB_Y_START, params->windowb_y_start,
  1102. OTG_CRC0_WINDOWB_Y_END, params->windowb_y_end);
  1103. /* Set crc mode and selection, and enable. Only using CRC0*/
  1104. REG_UPDATE_3(OTG_CRC_CNTL,
  1105. OTG_CRC_CONT_EN, params->continuous_mode ? 1 : 0,
  1106. OTG_CRC0_SELECT, params->selection,
  1107. OTG_CRC_EN, 1);
  1108. return true;
  1109. }
  1110. bool optc1_get_crc(struct timing_generator *optc,
  1111. uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb)
  1112. {
  1113. uint32_t field = 0;
  1114. struct optc *optc1 = DCN10TG_FROM_TG(optc);
  1115. REG_GET(OTG_CRC_CNTL, OTG_CRC_EN, &field);
  1116. /* Early return if CRC is not enabled for this CRTC */
  1117. if (!field)
  1118. return false;
  1119. REG_GET_2(OTG_CRC0_DATA_RG,
  1120. CRC0_R_CR, r_cr,
  1121. CRC0_G_Y, g_y);
  1122. REG_GET(OTG_CRC0_DATA_B,
  1123. CRC0_B_CB, b_cb);
  1124. return true;
  1125. }
  1126. static const struct timing_generator_funcs dcn10_tg_funcs = {
  1127. .validate_timing = optc1_validate_timing,
  1128. .program_timing = optc1_program_timing,
  1129. .program_vline_interrupt = optc1_program_vline_interrupt,
  1130. .program_global_sync = optc1_program_global_sync,
  1131. .enable_crtc = optc1_enable_crtc,
  1132. .disable_crtc = optc1_disable_crtc,
  1133. /* used by enable_timing_synchronization. Not need for FPGA */
  1134. .is_counter_moving = optc1_is_counter_moving,
  1135. .get_position = optc1_get_position,
  1136. .get_frame_count = optc1_get_vblank_counter,
  1137. .get_scanoutpos = optc1_get_crtc_scanoutpos,
  1138. .get_otg_active_size = optc1_get_otg_active_size,
  1139. .set_early_control = optc1_set_early_control,
  1140. /* used by enable_timing_synchronization. Not need for FPGA */
  1141. .wait_for_state = optc1_wait_for_state,
  1142. .set_blank = optc1_set_blank,
  1143. .is_blanked = optc1_is_blanked,
  1144. .set_blank_color = optc1_program_blank_color,
  1145. .did_triggered_reset_occur = optc1_did_triggered_reset_occur,
  1146. .enable_reset_trigger = optc1_enable_reset_trigger,
  1147. .enable_crtc_reset = optc1_enable_crtc_reset,
  1148. .disable_reset_trigger = optc1_disable_reset_trigger,
  1149. .lock = optc1_lock,
  1150. .unlock = optc1_unlock,
  1151. .enable_optc_clock = optc1_enable_optc_clock,
  1152. .set_drr = optc1_set_drr,
  1153. .set_static_screen_control = optc1_set_static_screen_control,
  1154. .set_test_pattern = optc1_set_test_pattern,
  1155. .program_stereo = optc1_program_stereo,
  1156. .is_stereo_left_eye = optc1_is_stereo_left_eye,
  1157. .set_blank_data_double_buffer = optc1_set_blank_data_double_buffer,
  1158. .tg_init = optc1_tg_init,
  1159. .is_tg_enabled = optc1_is_tg_enabled,
  1160. .is_optc_underflow_occurred = optc1_is_optc_underflow_occurred,
  1161. .clear_optc_underflow = optc1_clear_optc_underflow,
  1162. .get_crc = optc1_get_crc,
  1163. .configure_crc = optc1_configure_crc,
  1164. };
  1165. void dcn10_timing_generator_init(struct optc *optc1)
  1166. {
  1167. optc1->base.funcs = &dcn10_tg_funcs;
  1168. optc1->max_h_total = optc1->tg_mask->OTG_H_TOTAL + 1;
  1169. optc1->max_v_total = optc1->tg_mask->OTG_V_TOTAL + 1;
  1170. optc1->min_h_blank = 32;
  1171. optc1->min_v_blank = 3;
  1172. optc1->min_v_blank_interlace = 5;
  1173. optc1->min_h_sync_width = 8;
  1174. optc1->min_v_sync_width = 1;
  1175. }