meson_venc.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854
  1. /*
  2. * Copyright (C) 2016 BayLibre, SAS
  3. * Author: Neil Armstrong <narmstrong@baylibre.com>
  4. * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <drm/drmP.h>
  22. #include "meson_drv.h"
  23. #include "meson_venc.h"
  24. #include "meson_vpp.h"
  25. #include "meson_vclk.h"
  26. #include "meson_registers.h"
  27. /**
  28. * DOC: Video Encoder
  29. *
  30. * VENC Handle the pixels encoding to the output formats.
  31. * We handle the following encodings :
  32. *
  33. * - CVBS Encoding via the ENCI encoder and VDAC digital to analog converter
  34. * - TMDS/HDMI Encoding via ENCI_DIV and ENCP
  35. * - Setup of more clock rates for HDMI modes
  36. *
  37. * What is missing :
  38. *
  39. * - LCD Panel encoding via ENCL
  40. * - TV Panel encoding via ENCT
  41. *
  42. * VENC paths :
  43. *
  44. * .. code::
  45. *
  46. * _____ _____ ____________________
  47. * vd1---| |-| | | VENC /---------|----VDAC
  48. * vd2---| VIU |-| VPP |-|-----ENCI/-ENCI_DVI-|-|
  49. * osd1--| |-| | | \ | X--HDMI-TX
  50. * osd2--|_____|-|_____| | |\-ENCP--ENCP_DVI-|-|
  51. * | | |
  52. * | \--ENCL-----------|----LVDS
  53. * |____________________|
  54. *
  55. * The ENCI is designed for PAl or NTSC encoding and can go through the VDAC
  56. * directly for CVBS encoding or through the ENCI_DVI encoder for HDMI.
  57. * The ENCP is designed for Progressive encoding but can also generate
  58. * 1080i interlaced pixels, and was initialy desined to encode pixels for
  59. * VDAC to output RGB ou YUV analog outputs.
  60. * It's output is only used through the ENCP_DVI encoder for HDMI.
  61. * The ENCL LVDS encoder is not implemented.
  62. *
  63. * The ENCI and ENCP encoders needs specially defined parameters for each
  64. * supported mode and thus cannot be determined from standard video timings.
  65. *
  66. * The ENCI end ENCP DVI encoders are more generic and can generate any timings
  67. * from the pixel data generated by ENCI or ENCP, so can use the standard video
  68. * timings are source for HW parameters.
  69. */
  70. /* HHI Registers */
  71. #define HHI_VDAC_CNTL0 0x2F4 /* 0xbd offset in data sheet */
  72. #define HHI_VDAC_CNTL1 0x2F8 /* 0xbe offset in data sheet */
  73. #define HHI_HDMI_PHY_CNTL0 0x3a0 /* 0xe8 offset in data sheet */
  74. struct meson_cvbs_enci_mode meson_cvbs_enci_pal = {
  75. .mode_tag = MESON_VENC_MODE_CVBS_PAL,
  76. .hso_begin = 3,
  77. .hso_end = 129,
  78. .vso_even = 3,
  79. .vso_odd = 260,
  80. .macv_max_amp = 7,
  81. .video_prog_mode = 0xff,
  82. .video_mode = 0x13,
  83. .sch_adjust = 0x28,
  84. .yc_delay = 0x343,
  85. .pixel_start = 251,
  86. .pixel_end = 1691,
  87. .top_field_line_start = 22,
  88. .top_field_line_end = 310,
  89. .bottom_field_line_start = 23,
  90. .bottom_field_line_end = 311,
  91. .video_saturation = 9,
  92. .video_contrast = 0,
  93. .video_brightness = 0,
  94. .video_hue = 0,
  95. .analog_sync_adj = 0x8080,
  96. };
  97. struct meson_cvbs_enci_mode meson_cvbs_enci_ntsc = {
  98. .mode_tag = MESON_VENC_MODE_CVBS_NTSC,
  99. .hso_begin = 5,
  100. .hso_end = 129,
  101. .vso_even = 3,
  102. .vso_odd = 260,
  103. .macv_max_amp = 0xb,
  104. .video_prog_mode = 0xf0,
  105. .video_mode = 0x8,
  106. .sch_adjust = 0x20,
  107. .yc_delay = 0x333,
  108. .pixel_start = 227,
  109. .pixel_end = 1667,
  110. .top_field_line_start = 18,
  111. .top_field_line_end = 258,
  112. .bottom_field_line_start = 19,
  113. .bottom_field_line_end = 259,
  114. .video_saturation = 18,
  115. .video_contrast = 3,
  116. .video_brightness = 0,
  117. .video_hue = 0,
  118. .analog_sync_adj = 0x9c00,
  119. };
  120. union meson_hdmi_venc_mode {
  121. struct {
  122. unsigned int mode_tag;
  123. unsigned int hso_begin;
  124. unsigned int hso_end;
  125. unsigned int vso_even;
  126. unsigned int vso_odd;
  127. unsigned int macv_max_amp;
  128. unsigned int video_prog_mode;
  129. unsigned int video_mode;
  130. unsigned int sch_adjust;
  131. unsigned int yc_delay;
  132. unsigned int pixel_start;
  133. unsigned int pixel_end;
  134. unsigned int top_field_line_start;
  135. unsigned int top_field_line_end;
  136. unsigned int bottom_field_line_start;
  137. unsigned int bottom_field_line_end;
  138. } enci;
  139. struct {
  140. unsigned int dvi_settings;
  141. unsigned int video_mode;
  142. unsigned int video_mode_adv;
  143. unsigned int video_prog_mode;
  144. bool video_prog_mode_present;
  145. unsigned int video_sync_mode;
  146. bool video_sync_mode_present;
  147. unsigned int video_yc_dly;
  148. bool video_yc_dly_present;
  149. unsigned int video_rgb_ctrl;
  150. bool video_rgb_ctrl_present;
  151. unsigned int video_filt_ctrl;
  152. bool video_filt_ctrl_present;
  153. unsigned int video_ofld_voav_ofst;
  154. bool video_ofld_voav_ofst_present;
  155. unsigned int yfp1_htime;
  156. unsigned int yfp2_htime;
  157. unsigned int max_pxcnt;
  158. unsigned int hspuls_begin;
  159. unsigned int hspuls_end;
  160. unsigned int hspuls_switch;
  161. unsigned int vspuls_begin;
  162. unsigned int vspuls_end;
  163. unsigned int vspuls_bline;
  164. unsigned int vspuls_eline;
  165. unsigned int eqpuls_begin;
  166. bool eqpuls_begin_present;
  167. unsigned int eqpuls_end;
  168. bool eqpuls_end_present;
  169. unsigned int eqpuls_bline;
  170. bool eqpuls_bline_present;
  171. unsigned int eqpuls_eline;
  172. bool eqpuls_eline_present;
  173. unsigned int havon_begin;
  174. unsigned int havon_end;
  175. unsigned int vavon_bline;
  176. unsigned int vavon_eline;
  177. unsigned int hso_begin;
  178. unsigned int hso_end;
  179. unsigned int vso_begin;
  180. unsigned int vso_end;
  181. unsigned int vso_bline;
  182. unsigned int vso_eline;
  183. bool vso_eline_present;
  184. unsigned int sy_val;
  185. bool sy_val_present;
  186. unsigned int sy2_val;
  187. bool sy2_val_present;
  188. unsigned int max_lncnt;
  189. } encp;
  190. };
  191. union meson_hdmi_venc_mode meson_hdmi_enci_mode_480i = {
  192. .enci = {
  193. .hso_begin = 5,
  194. .hso_end = 129,
  195. .vso_even = 3,
  196. .vso_odd = 260,
  197. .macv_max_amp = 0x810b,
  198. .video_prog_mode = 0xf0,
  199. .video_mode = 0x8,
  200. .sch_adjust = 0x20,
  201. .yc_delay = 0,
  202. .pixel_start = 227,
  203. .pixel_end = 1667,
  204. .top_field_line_start = 18,
  205. .top_field_line_end = 258,
  206. .bottom_field_line_start = 19,
  207. .bottom_field_line_end = 259,
  208. },
  209. };
  210. union meson_hdmi_venc_mode meson_hdmi_enci_mode_576i = {
  211. .enci = {
  212. .hso_begin = 3,
  213. .hso_end = 129,
  214. .vso_even = 3,
  215. .vso_odd = 260,
  216. .macv_max_amp = 8107,
  217. .video_prog_mode = 0xff,
  218. .video_mode = 0x13,
  219. .sch_adjust = 0x28,
  220. .yc_delay = 0x333,
  221. .pixel_start = 251,
  222. .pixel_end = 1691,
  223. .top_field_line_start = 22,
  224. .top_field_line_end = 310,
  225. .bottom_field_line_start = 23,
  226. .bottom_field_line_end = 311,
  227. },
  228. };
  229. union meson_hdmi_venc_mode meson_hdmi_encp_mode_480p = {
  230. .encp = {
  231. .dvi_settings = 0x21,
  232. .video_mode = 0x4000,
  233. .video_mode_adv = 0x9,
  234. .video_prog_mode = 0,
  235. .video_prog_mode_present = true,
  236. .video_sync_mode = 7,
  237. .video_sync_mode_present = true,
  238. /* video_yc_dly */
  239. /* video_rgb_ctrl */
  240. .video_filt_ctrl = 0x2052,
  241. .video_filt_ctrl_present = true,
  242. /* video_ofld_voav_ofst */
  243. .yfp1_htime = 244,
  244. .yfp2_htime = 1630,
  245. .max_pxcnt = 1715,
  246. .hspuls_begin = 0x22,
  247. .hspuls_end = 0xa0,
  248. .hspuls_switch = 88,
  249. .vspuls_begin = 0,
  250. .vspuls_end = 1589,
  251. .vspuls_bline = 0,
  252. .vspuls_eline = 5,
  253. .havon_begin = 249,
  254. .havon_end = 1689,
  255. .vavon_bline = 42,
  256. .vavon_eline = 521,
  257. /* eqpuls_begin */
  258. /* eqpuls_end */
  259. /* eqpuls_bline */
  260. /* eqpuls_eline */
  261. .hso_begin = 3,
  262. .hso_end = 5,
  263. .vso_begin = 3,
  264. .vso_end = 5,
  265. .vso_bline = 0,
  266. /* vso_eline */
  267. .sy_val = 8,
  268. .sy_val_present = true,
  269. .sy2_val = 0x1d8,
  270. .sy2_val_present = true,
  271. .max_lncnt = 524,
  272. },
  273. };
  274. union meson_hdmi_venc_mode meson_hdmi_encp_mode_576p = {
  275. .encp = {
  276. .dvi_settings = 0x21,
  277. .video_mode = 0x4000,
  278. .video_mode_adv = 0x9,
  279. .video_prog_mode = 0,
  280. .video_prog_mode_present = true,
  281. .video_sync_mode = 7,
  282. .video_sync_mode_present = true,
  283. /* video_yc_dly */
  284. /* video_rgb_ctrl */
  285. .video_filt_ctrl = 0x52,
  286. .video_filt_ctrl_present = true,
  287. /* video_ofld_voav_ofst */
  288. .yfp1_htime = 235,
  289. .yfp2_htime = 1674,
  290. .max_pxcnt = 1727,
  291. .hspuls_begin = 0,
  292. .hspuls_end = 0x80,
  293. .hspuls_switch = 88,
  294. .vspuls_begin = 0,
  295. .vspuls_end = 1599,
  296. .vspuls_bline = 0,
  297. .vspuls_eline = 4,
  298. .havon_begin = 235,
  299. .havon_end = 1674,
  300. .vavon_bline = 44,
  301. .vavon_eline = 619,
  302. /* eqpuls_begin */
  303. /* eqpuls_end */
  304. /* eqpuls_bline */
  305. /* eqpuls_eline */
  306. .hso_begin = 0x80,
  307. .hso_end = 0,
  308. .vso_begin = 0,
  309. .vso_end = 5,
  310. .vso_bline = 0,
  311. /* vso_eline */
  312. .sy_val = 8,
  313. .sy_val_present = true,
  314. .sy2_val = 0x1d8,
  315. .sy2_val_present = true,
  316. .max_lncnt = 624,
  317. },
  318. };
  319. union meson_hdmi_venc_mode meson_hdmi_encp_mode_720p60 = {
  320. .encp = {
  321. .dvi_settings = 0x2029,
  322. .video_mode = 0x4040,
  323. .video_mode_adv = 0x19,
  324. /* video_prog_mode */
  325. /* video_sync_mode */
  326. /* video_yc_dly */
  327. /* video_rgb_ctrl */
  328. /* video_filt_ctrl */
  329. /* video_ofld_voav_ofst */
  330. .yfp1_htime = 648,
  331. .yfp2_htime = 3207,
  332. .max_pxcnt = 3299,
  333. .hspuls_begin = 80,
  334. .hspuls_end = 240,
  335. .hspuls_switch = 80,
  336. .vspuls_begin = 688,
  337. .vspuls_end = 3248,
  338. .vspuls_bline = 4,
  339. .vspuls_eline = 8,
  340. .havon_begin = 648,
  341. .havon_end = 3207,
  342. .vavon_bline = 29,
  343. .vavon_eline = 748,
  344. /* eqpuls_begin */
  345. /* eqpuls_end */
  346. /* eqpuls_bline */
  347. /* eqpuls_eline */
  348. .hso_begin = 256,
  349. .hso_end = 168,
  350. .vso_begin = 168,
  351. .vso_end = 256,
  352. .vso_bline = 0,
  353. .vso_eline = 5,
  354. .vso_eline_present = true,
  355. /* sy_val */
  356. /* sy2_val */
  357. .max_lncnt = 749,
  358. },
  359. };
  360. union meson_hdmi_venc_mode meson_hdmi_encp_mode_720p50 = {
  361. .encp = {
  362. .dvi_settings = 0x202d,
  363. .video_mode = 0x4040,
  364. .video_mode_adv = 0x19,
  365. .video_prog_mode = 0x100,
  366. .video_prog_mode_present = true,
  367. .video_sync_mode = 0x407,
  368. .video_sync_mode_present = true,
  369. .video_yc_dly = 0,
  370. .video_yc_dly_present = true,
  371. /* video_rgb_ctrl */
  372. /* video_filt_ctrl */
  373. /* video_ofld_voav_ofst */
  374. .yfp1_htime = 648,
  375. .yfp2_htime = 3207,
  376. .max_pxcnt = 3959,
  377. .hspuls_begin = 80,
  378. .hspuls_end = 240,
  379. .hspuls_switch = 80,
  380. .vspuls_begin = 688,
  381. .vspuls_end = 3248,
  382. .vspuls_bline = 4,
  383. .vspuls_eline = 8,
  384. .havon_begin = 648,
  385. .havon_end = 3207,
  386. .vavon_bline = 29,
  387. .vavon_eline = 748,
  388. /* eqpuls_begin */
  389. /* eqpuls_end */
  390. /* eqpuls_bline */
  391. /* eqpuls_eline */
  392. .hso_begin = 128,
  393. .hso_end = 208,
  394. .vso_begin = 128,
  395. .vso_end = 128,
  396. .vso_bline = 0,
  397. .vso_eline = 5,
  398. .vso_eline_present = true,
  399. /* sy_val */
  400. /* sy2_val */
  401. .max_lncnt = 749,
  402. },
  403. };
  404. union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080i60 = {
  405. .encp = {
  406. .dvi_settings = 0x2029,
  407. .video_mode = 0x5ffc,
  408. .video_mode_adv = 0x19,
  409. .video_prog_mode = 0x100,
  410. .video_prog_mode_present = true,
  411. .video_sync_mode = 0x207,
  412. .video_sync_mode_present = true,
  413. /* video_yc_dly */
  414. /* video_rgb_ctrl */
  415. /* video_filt_ctrl */
  416. .video_ofld_voav_ofst = 0x11,
  417. .video_ofld_voav_ofst_present = true,
  418. .yfp1_htime = 516,
  419. .yfp2_htime = 4355,
  420. .max_pxcnt = 4399,
  421. .hspuls_begin = 88,
  422. .hspuls_end = 264,
  423. .hspuls_switch = 88,
  424. .vspuls_begin = 440,
  425. .vspuls_end = 2200,
  426. .vspuls_bline = 0,
  427. .vspuls_eline = 4,
  428. .havon_begin = 516,
  429. .havon_end = 4355,
  430. .vavon_bline = 20,
  431. .vavon_eline = 559,
  432. .eqpuls_begin = 2288,
  433. .eqpuls_begin_present = true,
  434. .eqpuls_end = 2464,
  435. .eqpuls_end_present = true,
  436. .eqpuls_bline = 0,
  437. .eqpuls_bline_present = true,
  438. .eqpuls_eline = 4,
  439. .eqpuls_eline_present = true,
  440. .hso_begin = 264,
  441. .hso_end = 176,
  442. .vso_begin = 88,
  443. .vso_end = 88,
  444. .vso_bline = 0,
  445. .vso_eline = 5,
  446. .vso_eline_present = true,
  447. /* sy_val */
  448. /* sy2_val */
  449. .max_lncnt = 1124,
  450. },
  451. };
  452. union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080i50 = {
  453. .encp = {
  454. .dvi_settings = 0x202d,
  455. .video_mode = 0x5ffc,
  456. .video_mode_adv = 0x19,
  457. .video_prog_mode = 0x100,
  458. .video_prog_mode_present = true,
  459. .video_sync_mode = 0x7,
  460. .video_sync_mode_present = true,
  461. /* video_yc_dly */
  462. /* video_rgb_ctrl */
  463. /* video_filt_ctrl */
  464. .video_ofld_voav_ofst = 0x11,
  465. .video_ofld_voav_ofst_present = true,
  466. .yfp1_htime = 526,
  467. .yfp2_htime = 4365,
  468. .max_pxcnt = 5279,
  469. .hspuls_begin = 88,
  470. .hspuls_end = 264,
  471. .hspuls_switch = 88,
  472. .vspuls_begin = 440,
  473. .vspuls_end = 2200,
  474. .vspuls_bline = 0,
  475. .vspuls_eline = 4,
  476. .havon_begin = 526,
  477. .havon_end = 4365,
  478. .vavon_bline = 20,
  479. .vavon_eline = 559,
  480. .eqpuls_begin = 2288,
  481. .eqpuls_begin_present = true,
  482. .eqpuls_end = 2464,
  483. .eqpuls_end_present = true,
  484. .eqpuls_bline = 0,
  485. .eqpuls_bline_present = true,
  486. .eqpuls_eline = 4,
  487. .eqpuls_eline_present = true,
  488. .hso_begin = 142,
  489. .hso_end = 230,
  490. .vso_begin = 142,
  491. .vso_end = 142,
  492. .vso_bline = 0,
  493. .vso_eline = 5,
  494. .vso_eline_present = true,
  495. /* sy_val */
  496. /* sy2_val */
  497. .max_lncnt = 1124,
  498. },
  499. };
  500. union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p24 = {
  501. .encp = {
  502. .dvi_settings = 0xd,
  503. .video_mode = 0x4040,
  504. .video_mode_adv = 0x18,
  505. .video_prog_mode = 0x100,
  506. .video_prog_mode_present = true,
  507. .video_sync_mode = 0x7,
  508. .video_sync_mode_present = true,
  509. .video_yc_dly = 0,
  510. .video_yc_dly_present = true,
  511. .video_rgb_ctrl = 2,
  512. .video_rgb_ctrl_present = true,
  513. .video_filt_ctrl = 0x1052,
  514. .video_filt_ctrl_present = true,
  515. /* video_ofld_voav_ofst */
  516. .yfp1_htime = 271,
  517. .yfp2_htime = 2190,
  518. .max_pxcnt = 2749,
  519. .hspuls_begin = 44,
  520. .hspuls_end = 132,
  521. .hspuls_switch = 44,
  522. .vspuls_begin = 220,
  523. .vspuls_end = 2140,
  524. .vspuls_bline = 0,
  525. .vspuls_eline = 4,
  526. .havon_begin = 271,
  527. .havon_end = 2190,
  528. .vavon_bline = 41,
  529. .vavon_eline = 1120,
  530. /* eqpuls_begin */
  531. /* eqpuls_end */
  532. .eqpuls_bline = 0,
  533. .eqpuls_bline_present = true,
  534. .eqpuls_eline = 4,
  535. .eqpuls_eline_present = true,
  536. .hso_begin = 79,
  537. .hso_end = 123,
  538. .vso_begin = 79,
  539. .vso_end = 79,
  540. .vso_bline = 0,
  541. .vso_eline = 5,
  542. .vso_eline_present = true,
  543. /* sy_val */
  544. /* sy2_val */
  545. .max_lncnt = 1124,
  546. },
  547. };
  548. union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p30 = {
  549. .encp = {
  550. .dvi_settings = 0x1,
  551. .video_mode = 0x4040,
  552. .video_mode_adv = 0x18,
  553. .video_prog_mode = 0x100,
  554. .video_prog_mode_present = true,
  555. /* video_sync_mode */
  556. /* video_yc_dly */
  557. /* video_rgb_ctrl */
  558. .video_filt_ctrl = 0x1052,
  559. .video_filt_ctrl_present = true,
  560. /* video_ofld_voav_ofst */
  561. .yfp1_htime = 140,
  562. .yfp2_htime = 2060,
  563. .max_pxcnt = 2199,
  564. .hspuls_begin = 2156,
  565. .hspuls_end = 44,
  566. .hspuls_switch = 44,
  567. .vspuls_begin = 140,
  568. .vspuls_end = 2059,
  569. .vspuls_bline = 0,
  570. .vspuls_eline = 4,
  571. .havon_begin = 148,
  572. .havon_end = 2067,
  573. .vavon_bline = 41,
  574. .vavon_eline = 1120,
  575. /* eqpuls_begin */
  576. /* eqpuls_end */
  577. /* eqpuls_bline */
  578. /* eqpuls_eline */
  579. .hso_begin = 44,
  580. .hso_end = 2156,
  581. .vso_begin = 2100,
  582. .vso_end = 2164,
  583. .vso_bline = 0,
  584. .vso_eline = 5,
  585. .vso_eline_present = true,
  586. /* sy_val */
  587. /* sy2_val */
  588. .max_lncnt = 1124,
  589. },
  590. };
  591. union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p50 = {
  592. .encp = {
  593. .dvi_settings = 0xd,
  594. .video_mode = 0x4040,
  595. .video_mode_adv = 0x18,
  596. .video_prog_mode = 0x100,
  597. .video_prog_mode_present = true,
  598. .video_sync_mode = 0x7,
  599. .video_sync_mode_present = true,
  600. .video_yc_dly = 0,
  601. .video_yc_dly_present = true,
  602. .video_rgb_ctrl = 2,
  603. .video_rgb_ctrl_present = true,
  604. /* video_filt_ctrl */
  605. /* video_ofld_voav_ofst */
  606. .yfp1_htime = 271,
  607. .yfp2_htime = 2190,
  608. .max_pxcnt = 2639,
  609. .hspuls_begin = 44,
  610. .hspuls_end = 132,
  611. .hspuls_switch = 44,
  612. .vspuls_begin = 220,
  613. .vspuls_end = 2140,
  614. .vspuls_bline = 0,
  615. .vspuls_eline = 4,
  616. .havon_begin = 271,
  617. .havon_end = 2190,
  618. .vavon_bline = 41,
  619. .vavon_eline = 1120,
  620. /* eqpuls_begin */
  621. /* eqpuls_end */
  622. .eqpuls_bline = 0,
  623. .eqpuls_bline_present = true,
  624. .eqpuls_eline = 4,
  625. .eqpuls_eline_present = true,
  626. .hso_begin = 79,
  627. .hso_end = 123,
  628. .vso_begin = 79,
  629. .vso_end = 79,
  630. .vso_bline = 0,
  631. .vso_eline = 5,
  632. .vso_eline_present = true,
  633. /* sy_val */
  634. /* sy2_val */
  635. .max_lncnt = 1124,
  636. },
  637. };
  638. union meson_hdmi_venc_mode meson_hdmi_encp_mode_1080p60 = {
  639. .encp = {
  640. .dvi_settings = 0x1,
  641. .video_mode = 0x4040,
  642. .video_mode_adv = 0x18,
  643. .video_prog_mode = 0x100,
  644. .video_prog_mode_present = true,
  645. /* video_sync_mode */
  646. /* video_yc_dly */
  647. /* video_rgb_ctrl */
  648. .video_filt_ctrl = 0x1052,
  649. .video_filt_ctrl_present = true,
  650. /* video_ofld_voav_ofst */
  651. .yfp1_htime = 140,
  652. .yfp2_htime = 2060,
  653. .max_pxcnt = 2199,
  654. .hspuls_begin = 2156,
  655. .hspuls_end = 44,
  656. .hspuls_switch = 44,
  657. .vspuls_begin = 140,
  658. .vspuls_end = 2059,
  659. .vspuls_bline = 0,
  660. .vspuls_eline = 4,
  661. .havon_begin = 148,
  662. .havon_end = 2067,
  663. .vavon_bline = 41,
  664. .vavon_eline = 1120,
  665. /* eqpuls_begin */
  666. /* eqpuls_end */
  667. /* eqpuls_bline */
  668. /* eqpuls_eline */
  669. .hso_begin = 44,
  670. .hso_end = 2156,
  671. .vso_begin = 2100,
  672. .vso_end = 2164,
  673. .vso_bline = 0,
  674. .vso_eline = 5,
  675. .vso_eline_present = true,
  676. /* sy_val */
  677. /* sy2_val */
  678. .max_lncnt = 1124,
  679. },
  680. };
  681. union meson_hdmi_venc_mode meson_hdmi_encp_mode_640x480_60 = {
  682. .encp = {
  683. .dvi_settings = 0x21,
  684. .video_mode = 0x4040,
  685. .video_mode_adv = 0x18,
  686. /* video_prog_mode */
  687. /* video_sync_mode */
  688. /* video_yc_dly */
  689. /* video_rgb_ctrl */
  690. /* video_filt_ctrl */
  691. /* video_ofld_voav_ofst */
  692. /* yfp1_htime */
  693. /* yfp2_htime */
  694. .max_pxcnt = 0x31f,
  695. /* hspuls_begin */
  696. /* hspuls_end */
  697. /* hspuls_switch */
  698. /* vspuls_begin */
  699. /* vspuls_end */
  700. /* vspuls_bline */
  701. /* vspuls_eline */
  702. .havon_begin = 0x90,
  703. .havon_end = 0x30f,
  704. .vavon_bline = 0x23,
  705. .vavon_eline = 0x202,
  706. /* eqpuls_begin */
  707. /* eqpuls_end */
  708. /* eqpuls_bline */
  709. /* eqpuls_eline */
  710. .hso_begin = 0,
  711. .hso_end = 0x60,
  712. .vso_begin = 0x1e,
  713. .vso_end = 0x32,
  714. .vso_bline = 0,
  715. .vso_eline = 2,
  716. .vso_eline_present = true,
  717. /* sy_val */
  718. /* sy2_val */
  719. .max_lncnt = 0x20c,
  720. },
  721. };
  722. union meson_hdmi_venc_mode meson_hdmi_encp_mode_800x600_60 = {
  723. .encp = {
  724. .dvi_settings = 0x21,
  725. .video_mode = 0x4040,
  726. .video_mode_adv = 0x18,
  727. /* video_prog_mode */
  728. /* video_sync_mode */
  729. /* video_yc_dly */
  730. /* video_rgb_ctrl */
  731. /* video_filt_ctrl */
  732. /* video_ofld_voav_ofst */
  733. /* yfp1_htime */
  734. /* yfp2_htime */
  735. .max_pxcnt = 0x41f,
  736. /* hspuls_begin */
  737. /* hspuls_end */
  738. /* hspuls_switch */
  739. /* vspuls_begin */
  740. /* vspuls_end */
  741. /* vspuls_bline */
  742. /* vspuls_eline */
  743. .havon_begin = 0xD8,
  744. .havon_end = 0x3f7,
  745. .vavon_bline = 0x1b,
  746. .vavon_eline = 0x272,
  747. /* eqpuls_begin */
  748. /* eqpuls_end */
  749. /* eqpuls_bline */
  750. /* eqpuls_eline */
  751. .hso_begin = 0,
  752. .hso_end = 0x80,
  753. .vso_begin = 0x1e,
  754. .vso_end = 0x32,
  755. .vso_bline = 0,
  756. .vso_eline = 4,
  757. .vso_eline_present = true,
  758. /* sy_val */
  759. /* sy2_val */
  760. .max_lncnt = 0x273,
  761. },
  762. };
  763. union meson_hdmi_venc_mode meson_hdmi_encp_mode_1024x768_60 = {
  764. .encp = {
  765. .dvi_settings = 0x21,
  766. .video_mode = 0x4040,
  767. .video_mode_adv = 0x18,
  768. /* video_prog_mode */
  769. /* video_sync_mode */
  770. /* video_yc_dly */
  771. /* video_rgb_ctrl */
  772. /* video_filt_ctrl */
  773. /* video_ofld_voav_ofst */
  774. /* yfp1_htime */
  775. /* yfp2_htime */
  776. .max_pxcnt = 1343,
  777. /* hspuls_begin */
  778. /* hspuls_end */
  779. /* hspuls_switch */
  780. /* vspuls_begin */
  781. /* vspuls_end */
  782. /* vspuls_bline */
  783. /* vspuls_eline */
  784. .havon_begin = 296,
  785. .havon_end = 1319,
  786. .vavon_bline = 35,
  787. .vavon_eline = 802,
  788. /* eqpuls_begin */
  789. /* eqpuls_end */
  790. /* eqpuls_bline */
  791. /* eqpuls_eline */
  792. .hso_begin = 0,
  793. .hso_end = 136,
  794. .vso_begin = 30,
  795. .vso_end = 50,
  796. .vso_bline = 0,
  797. .vso_eline = 6,
  798. .vso_eline_present = true,
  799. /* sy_val */
  800. /* sy2_val */
  801. .max_lncnt = 805,
  802. },
  803. };
  804. union meson_hdmi_venc_mode meson_hdmi_encp_mode_1152x864_75 = {
  805. .encp = {
  806. .dvi_settings = 0x21,
  807. .video_mode = 0x4040,
  808. .video_mode_adv = 0x18,
  809. /* video_prog_mode */
  810. /* video_sync_mode */
  811. /* video_yc_dly */
  812. /* video_rgb_ctrl */
  813. /* video_filt_ctrl */
  814. /* video_ofld_voav_ofst */
  815. /* yfp1_htime */
  816. /* yfp2_htime */
  817. .max_pxcnt = 0x63f,
  818. /* hspuls_begin */
  819. /* hspuls_end */
  820. /* hspuls_switch */
  821. /* vspuls_begin */
  822. /* vspuls_end */
  823. /* vspuls_bline */
  824. /* vspuls_eline */
  825. .havon_begin = 0x180,
  826. .havon_end = 0x5ff,
  827. .vavon_bline = 0x23,
  828. .vavon_eline = 0x382,
  829. /* eqpuls_begin */
  830. /* eqpuls_end */
  831. /* eqpuls_bline */
  832. /* eqpuls_eline */
  833. .hso_begin = 0,
  834. .hso_end = 0x80,
  835. .vso_begin = 0x1e,
  836. .vso_end = 0x32,
  837. .vso_bline = 0,
  838. .vso_eline = 3,
  839. .vso_eline_present = true,
  840. /* sy_val */
  841. /* sy2_val */
  842. .max_lncnt = 0x383,
  843. },
  844. };
  845. union meson_hdmi_venc_mode meson_hdmi_encp_mode_1280x1024_60 = {
  846. .encp = {
  847. .dvi_settings = 0x21,
  848. .video_mode = 0x4040,
  849. .video_mode_adv = 0x18,
  850. /* video_prog_mode */
  851. /* video_sync_mode */
  852. /* video_yc_dly */
  853. /* video_rgb_ctrl */
  854. /* video_filt_ctrl */
  855. /* video_ofld_voav_ofst */
  856. /* yfp1_htime */
  857. /* yfp2_htime */
  858. .max_pxcnt = 0x697,
  859. /* hspuls_begin */
  860. /* hspuls_end */
  861. /* hspuls_switch */
  862. /* vspuls_begin */
  863. /* vspuls_end */
  864. /* vspuls_bline */
  865. /* vspuls_eline */
  866. .havon_begin = 0x168,
  867. .havon_end = 0x667,
  868. .vavon_bline = 0x29,
  869. .vavon_eline = 0x428,
  870. /* eqpuls_begin */
  871. /* eqpuls_end */
  872. /* eqpuls_bline */
  873. /* eqpuls_eline */
  874. .hso_begin = 0,
  875. .hso_end = 0x70,
  876. .vso_begin = 0x1e,
  877. .vso_end = 0x32,
  878. .vso_bline = 0,
  879. .vso_eline = 3,
  880. .vso_eline_present = true,
  881. /* sy_val */
  882. /* sy2_val */
  883. .max_lncnt = 0x429,
  884. },
  885. };
  886. union meson_hdmi_venc_mode meson_hdmi_encp_mode_1600x1200_60 = {
  887. .encp = {
  888. .dvi_settings = 0x21,
  889. .video_mode = 0x4040,
  890. .video_mode_adv = 0x18,
  891. /* video_prog_mode */
  892. /* video_sync_mode */
  893. /* video_yc_dly */
  894. /* video_rgb_ctrl */
  895. /* video_filt_ctrl */
  896. /* video_ofld_voav_ofst */
  897. /* yfp1_htime */
  898. /* yfp2_htime */
  899. .max_pxcnt = 0x86f,
  900. /* hspuls_begin */
  901. /* hspuls_end */
  902. /* hspuls_switch */
  903. /* vspuls_begin */
  904. /* vspuls_end */
  905. /* vspuls_bline */
  906. /* vspuls_eline */
  907. .havon_begin = 0x1f0,
  908. .havon_end = 0x82f,
  909. .vavon_bline = 0x31,
  910. .vavon_eline = 0x4e0,
  911. /* eqpuls_begin */
  912. /* eqpuls_end */
  913. /* eqpuls_bline */
  914. /* eqpuls_eline */
  915. .hso_begin = 0,
  916. .hso_end = 0xc0,
  917. .vso_begin = 0x1e,
  918. .vso_end = 0x32,
  919. .vso_bline = 0,
  920. .vso_eline = 3,
  921. .vso_eline_present = true,
  922. /* sy_val */
  923. /* sy2_val */
  924. .max_lncnt = 0x4e1,
  925. },
  926. };
  927. struct meson_hdmi_venc_dmt_mode {
  928. struct drm_display_mode drm_mode;
  929. union meson_hdmi_venc_mode *mode;
  930. } meson_hdmi_venc_dmt_modes[] = {
  931. /* 640x480@60Hz */
  932. {
  933. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
  934. 752, 800, 0, 480, 490, 492, 525, 0,
  935. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  936. &meson_hdmi_encp_mode_640x480_60,
  937. },
  938. /* 800x600@60Hz */
  939. {
  940. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
  941. 968, 1056, 0, 600, 601, 605, 628, 0,
  942. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  943. &meson_hdmi_encp_mode_800x600_60,
  944. },
  945. /* 1024x768@60Hz */
  946. {
  947. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024,
  948. 1048, 1184, 1344, 0, 768, 771, 777, 806, 0,
  949. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  950. &meson_hdmi_encp_mode_1024x768_60,
  951. },
  952. /* 1152x864@75Hz */
  953. {
  954. { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152,
  955. 1216, 1344, 1600, 0, 864, 865, 868, 900, 0,
  956. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  957. &meson_hdmi_encp_mode_1152x864_75,
  958. },
  959. /* 1280x1024@60Hz */
  960. {
  961. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280,
  962. 1328, 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
  963. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  964. &meson_hdmi_encp_mode_1280x1024_60,
  965. },
  966. /* 1600x1200@60Hz */
  967. {
  968. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600,
  969. 1664, 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  970. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  971. &meson_hdmi_encp_mode_1600x1200_60,
  972. },
  973. /* 1920x1080@60Hz */
  974. {
  975. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920,
  976. 2008, 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  977. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  978. &meson_hdmi_encp_mode_1080p60
  979. },
  980. { }, /* sentinel */
  981. };
  982. struct meson_hdmi_venc_vic_mode {
  983. unsigned int vic;
  984. union meson_hdmi_venc_mode *mode;
  985. } meson_hdmi_venc_vic_modes[] = {
  986. { 6, &meson_hdmi_enci_mode_480i },
  987. { 7, &meson_hdmi_enci_mode_480i },
  988. { 21, &meson_hdmi_enci_mode_576i },
  989. { 22, &meson_hdmi_enci_mode_576i },
  990. { 2, &meson_hdmi_encp_mode_480p },
  991. { 3, &meson_hdmi_encp_mode_480p },
  992. { 17, &meson_hdmi_encp_mode_576p },
  993. { 18, &meson_hdmi_encp_mode_576p },
  994. { 4, &meson_hdmi_encp_mode_720p60 },
  995. { 19, &meson_hdmi_encp_mode_720p50 },
  996. { 5, &meson_hdmi_encp_mode_1080i60 },
  997. { 20, &meson_hdmi_encp_mode_1080i50 },
  998. { 32, &meson_hdmi_encp_mode_1080p24 },
  999. { 34, &meson_hdmi_encp_mode_1080p30 },
  1000. { 31, &meson_hdmi_encp_mode_1080p50 },
  1001. { 16, &meson_hdmi_encp_mode_1080p60 },
  1002. { 0, NULL}, /* sentinel */
  1003. };
  1004. static signed int to_signed(unsigned int a)
  1005. {
  1006. if (a <= 7)
  1007. return a;
  1008. else
  1009. return a - 16;
  1010. }
  1011. static unsigned long modulo(unsigned long a, unsigned long b)
  1012. {
  1013. if (a >= b)
  1014. return a - b;
  1015. else
  1016. return a;
  1017. }
  1018. bool meson_venc_hdmi_supported_mode(const struct drm_display_mode *mode)
  1019. {
  1020. struct meson_hdmi_venc_dmt_mode *vmode = meson_hdmi_venc_dmt_modes;
  1021. while (vmode->mode) {
  1022. if (drm_mode_equal(&vmode->drm_mode, mode))
  1023. return true;
  1024. vmode++;
  1025. }
  1026. return false;
  1027. }
  1028. EXPORT_SYMBOL_GPL(meson_venc_hdmi_supported_mode);
  1029. bool meson_venc_hdmi_supported_vic(int vic)
  1030. {
  1031. struct meson_hdmi_venc_vic_mode *vmode = meson_hdmi_venc_vic_modes;
  1032. while (vmode->vic && vmode->mode) {
  1033. if (vmode->vic == vic)
  1034. return true;
  1035. vmode++;
  1036. }
  1037. return false;
  1038. }
  1039. EXPORT_SYMBOL_GPL(meson_venc_hdmi_supported_vic);
  1040. static union meson_hdmi_venc_mode
  1041. *meson_venc_hdmi_get_dmt_vmode(const struct drm_display_mode *mode)
  1042. {
  1043. struct meson_hdmi_venc_dmt_mode *vmode = meson_hdmi_venc_dmt_modes;
  1044. while (vmode->mode) {
  1045. if (drm_mode_equal(&vmode->drm_mode, mode))
  1046. return vmode->mode;
  1047. vmode++;
  1048. }
  1049. return NULL;
  1050. }
  1051. static union meson_hdmi_venc_mode *meson_venc_hdmi_get_vic_vmode(int vic)
  1052. {
  1053. struct meson_hdmi_venc_vic_mode *vmode = meson_hdmi_venc_vic_modes;
  1054. while (vmode->vic && vmode->mode) {
  1055. if (vmode->vic == vic)
  1056. return vmode->mode;
  1057. vmode++;
  1058. }
  1059. return NULL;
  1060. }
  1061. bool meson_venc_hdmi_venc_repeat(int vic)
  1062. {
  1063. /* Repeat VENC pixels for 480/576i/p, 720p50/60 and 1080p50/60 */
  1064. if (vic == 6 || vic == 7 || /* 480i */
  1065. vic == 21 || vic == 22 || /* 576i */
  1066. vic == 17 || vic == 18 || /* 576p */
  1067. vic == 2 || vic == 3 || /* 480p */
  1068. vic == 4 || /* 720p60 */
  1069. vic == 19 || /* 720p50 */
  1070. vic == 5 || /* 1080i60 */
  1071. vic == 20) /* 1080i50 */
  1072. return true;
  1073. return false;
  1074. }
  1075. EXPORT_SYMBOL_GPL(meson_venc_hdmi_venc_repeat);
  1076. void meson_venc_hdmi_mode_set(struct meson_drm *priv, int vic,
  1077. struct drm_display_mode *mode)
  1078. {
  1079. union meson_hdmi_venc_mode *vmode = NULL;
  1080. bool use_enci = false;
  1081. bool venc_repeat = false;
  1082. bool hdmi_repeat = false;
  1083. unsigned int venc_hdmi_latency = 2;
  1084. unsigned long total_pixels_venc = 0;
  1085. unsigned long active_pixels_venc = 0;
  1086. unsigned long front_porch_venc = 0;
  1087. unsigned long hsync_pixels_venc = 0;
  1088. unsigned long de_h_begin = 0;
  1089. unsigned long de_h_end = 0;
  1090. unsigned long de_v_begin_even = 0;
  1091. unsigned long de_v_end_even = 0;
  1092. unsigned long de_v_begin_odd = 0;
  1093. unsigned long de_v_end_odd = 0;
  1094. unsigned long hs_begin = 0;
  1095. unsigned long hs_end = 0;
  1096. unsigned long vs_adjust = 0;
  1097. unsigned long vs_bline_evn = 0;
  1098. unsigned long vs_eline_evn = 0;
  1099. unsigned long vs_bline_odd = 0;
  1100. unsigned long vs_eline_odd = 0;
  1101. unsigned long vso_begin_evn = 0;
  1102. unsigned long vso_begin_odd = 0;
  1103. unsigned int eof_lines;
  1104. unsigned int sof_lines;
  1105. unsigned int vsync_lines;
  1106. if (meson_venc_hdmi_supported_vic(vic))
  1107. vmode = meson_venc_hdmi_get_vic_vmode(vic);
  1108. else
  1109. vmode = meson_venc_hdmi_get_dmt_vmode(mode);
  1110. if (!vmode) {
  1111. dev_err(priv->dev, "%s: Fatal Error, unsupported mode "
  1112. DRM_MODE_FMT "\n", __func__, DRM_MODE_ARG(mode));
  1113. return;
  1114. }
  1115. /* Use VENCI for 480i and 576i and double HDMI pixels */
  1116. if (mode->flags & DRM_MODE_FLAG_DBLCLK) {
  1117. hdmi_repeat = true;
  1118. use_enci = true;
  1119. venc_hdmi_latency = 1;
  1120. }
  1121. /* Repeat VENC pixels for 480/576i/p, 720p50/60 and 1080p50/60 */
  1122. if (meson_venc_hdmi_venc_repeat(vic))
  1123. venc_repeat = true;
  1124. eof_lines = mode->vsync_start - mode->vdisplay;
  1125. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1126. eof_lines /= 2;
  1127. sof_lines = mode->vtotal - mode->vsync_end;
  1128. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1129. sof_lines /= 2;
  1130. vsync_lines = mode->vsync_end - mode->vsync_start;
  1131. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1132. vsync_lines /= 2;
  1133. total_pixels_venc = mode->htotal;
  1134. if (hdmi_repeat)
  1135. total_pixels_venc /= 2;
  1136. if (venc_repeat)
  1137. total_pixels_venc *= 2;
  1138. active_pixels_venc = mode->hdisplay;
  1139. if (hdmi_repeat)
  1140. active_pixels_venc /= 2;
  1141. if (venc_repeat)
  1142. active_pixels_venc *= 2;
  1143. front_porch_venc = (mode->hsync_start - mode->hdisplay);
  1144. if (hdmi_repeat)
  1145. front_porch_venc /= 2;
  1146. if (venc_repeat)
  1147. front_porch_venc *= 2;
  1148. hsync_pixels_venc = (mode->hsync_end - mode->hsync_start);
  1149. if (hdmi_repeat)
  1150. hsync_pixels_venc /= 2;
  1151. if (venc_repeat)
  1152. hsync_pixels_venc *= 2;
  1153. /* Disable VDACs */
  1154. writel_bits_relaxed(0xff, 0xff,
  1155. priv->io_base + _REG(VENC_VDAC_SETTING));
  1156. writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_EN));
  1157. writel_relaxed(0, priv->io_base + _REG(ENCP_VIDEO_EN));
  1158. if (use_enci) {
  1159. unsigned int lines_f0;
  1160. unsigned int lines_f1;
  1161. /* CVBS Filter settings */
  1162. writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL));
  1163. writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL2));
  1164. /* Digital Video Select : Interlace, clk27 clk, external */
  1165. writel_relaxed(0, priv->io_base + _REG(VENC_DVI_SETTING));
  1166. /* Reset Video Mode */
  1167. writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE));
  1168. writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
  1169. /* Horizontal sync signal output */
  1170. writel_relaxed(vmode->enci.hso_begin,
  1171. priv->io_base + _REG(ENCI_SYNC_HSO_BEGIN));
  1172. writel_relaxed(vmode->enci.hso_end,
  1173. priv->io_base + _REG(ENCI_SYNC_HSO_END));
  1174. /* Vertical Sync lines */
  1175. writel_relaxed(vmode->enci.vso_even,
  1176. priv->io_base + _REG(ENCI_SYNC_VSO_EVNLN));
  1177. writel_relaxed(vmode->enci.vso_odd,
  1178. priv->io_base + _REG(ENCI_SYNC_VSO_ODDLN));
  1179. /* Macrovision max amplitude change */
  1180. writel_relaxed(vmode->enci.macv_max_amp,
  1181. priv->io_base + _REG(ENCI_MACV_MAX_AMP));
  1182. /* Video mode */
  1183. writel_relaxed(vmode->enci.video_prog_mode,
  1184. priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
  1185. writel_relaxed(vmode->enci.video_mode,
  1186. priv->io_base + _REG(ENCI_VIDEO_MODE));
  1187. /* Advanced Video Mode :
  1188. * Demux shifting 0x2
  1189. * Blank line end at line17/22
  1190. * High bandwidth Luma Filter
  1191. * Low bandwidth Chroma Filter
  1192. * Bypass luma low pass filter
  1193. * No macrovision on CSYNC
  1194. */
  1195. writel_relaxed(0x26, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
  1196. writel(vmode->enci.sch_adjust,
  1197. priv->io_base + _REG(ENCI_VIDEO_SCH));
  1198. /* Sync mode : MASTER Master mode, free run, send HSO/VSO out */
  1199. writel_relaxed(0x07, priv->io_base + _REG(ENCI_SYNC_MODE));
  1200. if (vmode->enci.yc_delay)
  1201. writel_relaxed(vmode->enci.yc_delay,
  1202. priv->io_base + _REG(ENCI_YC_DELAY));
  1203. /* UNreset Interlaced TV Encoder */
  1204. writel_relaxed(0, priv->io_base + _REG(ENCI_DBG_PX_RST));
  1205. /* Enable Vfifo2vd, Y_Cb_Y_Cr select */
  1206. writel_relaxed(0x4e01, priv->io_base + _REG(ENCI_VFIFO2VD_CTL));
  1207. /* Timings */
  1208. writel_relaxed(vmode->enci.pixel_start,
  1209. priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_START));
  1210. writel_relaxed(vmode->enci.pixel_end,
  1211. priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_END));
  1212. writel_relaxed(vmode->enci.top_field_line_start,
  1213. priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_START));
  1214. writel_relaxed(vmode->enci.top_field_line_end,
  1215. priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_END));
  1216. writel_relaxed(vmode->enci.bottom_field_line_start,
  1217. priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_START));
  1218. writel_relaxed(vmode->enci.bottom_field_line_end,
  1219. priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_END));
  1220. /* Select ENCI for VIU */
  1221. meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCI);
  1222. /* Interlace video enable */
  1223. writel_relaxed(1, priv->io_base + _REG(ENCI_VIDEO_EN));
  1224. lines_f0 = mode->vtotal >> 1;
  1225. lines_f1 = lines_f0 + 1;
  1226. de_h_begin = modulo(readl_relaxed(priv->io_base +
  1227. _REG(ENCI_VFIFO2VD_PIXEL_START))
  1228. + venc_hdmi_latency,
  1229. total_pixels_venc);
  1230. de_h_end = modulo(de_h_begin + active_pixels_venc,
  1231. total_pixels_venc);
  1232. writel_relaxed(de_h_begin,
  1233. priv->io_base + _REG(ENCI_DE_H_BEGIN));
  1234. writel_relaxed(de_h_end,
  1235. priv->io_base + _REG(ENCI_DE_H_END));
  1236. de_v_begin_even = readl_relaxed(priv->io_base +
  1237. _REG(ENCI_VFIFO2VD_LINE_TOP_START));
  1238. de_v_end_even = de_v_begin_even + mode->vdisplay;
  1239. de_v_begin_odd = readl_relaxed(priv->io_base +
  1240. _REG(ENCI_VFIFO2VD_LINE_BOT_START));
  1241. de_v_end_odd = de_v_begin_odd + mode->vdisplay;
  1242. writel_relaxed(de_v_begin_even,
  1243. priv->io_base + _REG(ENCI_DE_V_BEGIN_EVEN));
  1244. writel_relaxed(de_v_end_even,
  1245. priv->io_base + _REG(ENCI_DE_V_END_EVEN));
  1246. writel_relaxed(de_v_begin_odd,
  1247. priv->io_base + _REG(ENCI_DE_V_BEGIN_ODD));
  1248. writel_relaxed(de_v_end_odd,
  1249. priv->io_base + _REG(ENCI_DE_V_END_ODD));
  1250. /* Program Hsync timing */
  1251. hs_begin = de_h_end + front_porch_venc;
  1252. if (de_h_end + front_porch_venc >= total_pixels_venc) {
  1253. hs_begin -= total_pixels_venc;
  1254. vs_adjust = 1;
  1255. } else {
  1256. hs_begin = de_h_end + front_porch_venc;
  1257. vs_adjust = 0;
  1258. }
  1259. hs_end = modulo(hs_begin + hsync_pixels_venc,
  1260. total_pixels_venc);
  1261. writel_relaxed(hs_begin,
  1262. priv->io_base + _REG(ENCI_DVI_HSO_BEGIN));
  1263. writel_relaxed(hs_end,
  1264. priv->io_base + _REG(ENCI_DVI_HSO_END));
  1265. /* Program Vsync timing for even field */
  1266. if (((de_v_end_odd - 1) + eof_lines + vs_adjust) >= lines_f1) {
  1267. vs_bline_evn = (de_v_end_odd - 1)
  1268. + eof_lines
  1269. + vs_adjust
  1270. - lines_f1;
  1271. vs_eline_evn = vs_bline_evn + vsync_lines;
  1272. writel_relaxed(vs_bline_evn,
  1273. priv->io_base + _REG(ENCI_DVI_VSO_BLINE_EVN));
  1274. writel_relaxed(vs_eline_evn,
  1275. priv->io_base + _REG(ENCI_DVI_VSO_ELINE_EVN));
  1276. writel_relaxed(hs_begin,
  1277. priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_EVN));
  1278. writel_relaxed(hs_begin,
  1279. priv->io_base + _REG(ENCI_DVI_VSO_END_EVN));
  1280. } else {
  1281. vs_bline_odd = (de_v_end_odd - 1)
  1282. + eof_lines
  1283. + vs_adjust;
  1284. writel_relaxed(vs_bline_odd,
  1285. priv->io_base + _REG(ENCI_DVI_VSO_BLINE_ODD));
  1286. writel_relaxed(hs_begin,
  1287. priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_ODD));
  1288. if ((vs_bline_odd + vsync_lines) >= lines_f1) {
  1289. vs_eline_evn = vs_bline_odd
  1290. + vsync_lines
  1291. - lines_f1;
  1292. writel_relaxed(vs_eline_evn, priv->io_base
  1293. + _REG(ENCI_DVI_VSO_ELINE_EVN));
  1294. writel_relaxed(hs_begin, priv->io_base
  1295. + _REG(ENCI_DVI_VSO_END_EVN));
  1296. } else {
  1297. vs_eline_odd = vs_bline_odd
  1298. + vsync_lines;
  1299. writel_relaxed(vs_eline_odd, priv->io_base
  1300. + _REG(ENCI_DVI_VSO_ELINE_ODD));
  1301. writel_relaxed(hs_begin, priv->io_base
  1302. + _REG(ENCI_DVI_VSO_END_ODD));
  1303. }
  1304. }
  1305. /* Program Vsync timing for odd field */
  1306. if (((de_v_end_even - 1) + (eof_lines + 1)) >= lines_f0) {
  1307. vs_bline_odd = (de_v_end_even - 1)
  1308. + (eof_lines + 1)
  1309. - lines_f0;
  1310. vs_eline_odd = vs_bline_odd + vsync_lines;
  1311. writel_relaxed(vs_bline_odd,
  1312. priv->io_base + _REG(ENCI_DVI_VSO_BLINE_ODD));
  1313. writel_relaxed(vs_eline_odd,
  1314. priv->io_base + _REG(ENCI_DVI_VSO_ELINE_ODD));
  1315. vso_begin_odd = modulo(hs_begin
  1316. + (total_pixels_venc >> 1),
  1317. total_pixels_venc);
  1318. writel_relaxed(vso_begin_odd,
  1319. priv->io_base + _REG(ENCI_DVI_VSO_BEGIN_ODD));
  1320. writel_relaxed(vso_begin_odd,
  1321. priv->io_base + _REG(ENCI_DVI_VSO_END_ODD));
  1322. } else {
  1323. vs_bline_evn = (de_v_end_even - 1)
  1324. + (eof_lines + 1);
  1325. writel_relaxed(vs_bline_evn,
  1326. priv->io_base + _REG(ENCI_DVI_VSO_BLINE_EVN));
  1327. vso_begin_evn = modulo(hs_begin
  1328. + (total_pixels_venc >> 1),
  1329. total_pixels_venc);
  1330. writel_relaxed(vso_begin_evn, priv->io_base
  1331. + _REG(ENCI_DVI_VSO_BEGIN_EVN));
  1332. if (vs_bline_evn + vsync_lines >= lines_f0) {
  1333. vs_eline_odd = vs_bline_evn
  1334. + vsync_lines
  1335. - lines_f0;
  1336. writel_relaxed(vs_eline_odd, priv->io_base
  1337. + _REG(ENCI_DVI_VSO_ELINE_ODD));
  1338. writel_relaxed(vso_begin_evn, priv->io_base
  1339. + _REG(ENCI_DVI_VSO_END_ODD));
  1340. } else {
  1341. vs_eline_evn = vs_bline_evn + vsync_lines;
  1342. writel_relaxed(vs_eline_evn, priv->io_base
  1343. + _REG(ENCI_DVI_VSO_ELINE_EVN));
  1344. writel_relaxed(vso_begin_evn, priv->io_base
  1345. + _REG(ENCI_DVI_VSO_END_EVN));
  1346. }
  1347. }
  1348. } else {
  1349. writel_relaxed(vmode->encp.dvi_settings,
  1350. priv->io_base + _REG(VENC_DVI_SETTING));
  1351. writel_relaxed(vmode->encp.video_mode,
  1352. priv->io_base + _REG(ENCP_VIDEO_MODE));
  1353. writel_relaxed(vmode->encp.video_mode_adv,
  1354. priv->io_base + _REG(ENCP_VIDEO_MODE_ADV));
  1355. if (vmode->encp.video_prog_mode_present)
  1356. writel_relaxed(vmode->encp.video_prog_mode,
  1357. priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
  1358. if (vmode->encp.video_sync_mode_present)
  1359. writel_relaxed(vmode->encp.video_sync_mode,
  1360. priv->io_base + _REG(ENCP_VIDEO_SYNC_MODE));
  1361. if (vmode->encp.video_yc_dly_present)
  1362. writel_relaxed(vmode->encp.video_yc_dly,
  1363. priv->io_base + _REG(ENCP_VIDEO_YC_DLY));
  1364. if (vmode->encp.video_rgb_ctrl_present)
  1365. writel_relaxed(vmode->encp.video_rgb_ctrl,
  1366. priv->io_base + _REG(ENCP_VIDEO_RGB_CTRL));
  1367. if (vmode->encp.video_filt_ctrl_present)
  1368. writel_relaxed(vmode->encp.video_filt_ctrl,
  1369. priv->io_base + _REG(ENCP_VIDEO_FILT_CTRL));
  1370. if (vmode->encp.video_ofld_voav_ofst_present)
  1371. writel_relaxed(vmode->encp.video_ofld_voav_ofst,
  1372. priv->io_base
  1373. + _REG(ENCP_VIDEO_OFLD_VOAV_OFST));
  1374. writel_relaxed(vmode->encp.yfp1_htime,
  1375. priv->io_base + _REG(ENCP_VIDEO_YFP1_HTIME));
  1376. writel_relaxed(vmode->encp.yfp2_htime,
  1377. priv->io_base + _REG(ENCP_VIDEO_YFP2_HTIME));
  1378. writel_relaxed(vmode->encp.max_pxcnt,
  1379. priv->io_base + _REG(ENCP_VIDEO_MAX_PXCNT));
  1380. writel_relaxed(vmode->encp.hspuls_begin,
  1381. priv->io_base + _REG(ENCP_VIDEO_HSPULS_BEGIN));
  1382. writel_relaxed(vmode->encp.hspuls_end,
  1383. priv->io_base + _REG(ENCP_VIDEO_HSPULS_END));
  1384. writel_relaxed(vmode->encp.hspuls_switch,
  1385. priv->io_base + _REG(ENCP_VIDEO_HSPULS_SWITCH));
  1386. writel_relaxed(vmode->encp.vspuls_begin,
  1387. priv->io_base + _REG(ENCP_VIDEO_VSPULS_BEGIN));
  1388. writel_relaxed(vmode->encp.vspuls_end,
  1389. priv->io_base + _REG(ENCP_VIDEO_VSPULS_END));
  1390. writel_relaxed(vmode->encp.vspuls_bline,
  1391. priv->io_base + _REG(ENCP_VIDEO_VSPULS_BLINE));
  1392. writel_relaxed(vmode->encp.vspuls_eline,
  1393. priv->io_base + _REG(ENCP_VIDEO_VSPULS_ELINE));
  1394. if (vmode->encp.eqpuls_begin_present)
  1395. writel_relaxed(vmode->encp.eqpuls_begin,
  1396. priv->io_base + _REG(ENCP_VIDEO_EQPULS_BEGIN));
  1397. if (vmode->encp.eqpuls_end_present)
  1398. writel_relaxed(vmode->encp.eqpuls_end,
  1399. priv->io_base + _REG(ENCP_VIDEO_EQPULS_END));
  1400. if (vmode->encp.eqpuls_bline_present)
  1401. writel_relaxed(vmode->encp.eqpuls_bline,
  1402. priv->io_base + _REG(ENCP_VIDEO_EQPULS_BLINE));
  1403. if (vmode->encp.eqpuls_eline_present)
  1404. writel_relaxed(vmode->encp.eqpuls_eline,
  1405. priv->io_base + _REG(ENCP_VIDEO_EQPULS_ELINE));
  1406. writel_relaxed(vmode->encp.havon_begin,
  1407. priv->io_base + _REG(ENCP_VIDEO_HAVON_BEGIN));
  1408. writel_relaxed(vmode->encp.havon_end,
  1409. priv->io_base + _REG(ENCP_VIDEO_HAVON_END));
  1410. writel_relaxed(vmode->encp.vavon_bline,
  1411. priv->io_base + _REG(ENCP_VIDEO_VAVON_BLINE));
  1412. writel_relaxed(vmode->encp.vavon_eline,
  1413. priv->io_base + _REG(ENCP_VIDEO_VAVON_ELINE));
  1414. writel_relaxed(vmode->encp.hso_begin,
  1415. priv->io_base + _REG(ENCP_VIDEO_HSO_BEGIN));
  1416. writel_relaxed(vmode->encp.hso_end,
  1417. priv->io_base + _REG(ENCP_VIDEO_HSO_END));
  1418. writel_relaxed(vmode->encp.vso_begin,
  1419. priv->io_base + _REG(ENCP_VIDEO_VSO_BEGIN));
  1420. writel_relaxed(vmode->encp.vso_end,
  1421. priv->io_base + _REG(ENCP_VIDEO_VSO_END));
  1422. writel_relaxed(vmode->encp.vso_bline,
  1423. priv->io_base + _REG(ENCP_VIDEO_VSO_BLINE));
  1424. if (vmode->encp.vso_eline_present)
  1425. writel_relaxed(vmode->encp.vso_eline,
  1426. priv->io_base + _REG(ENCP_VIDEO_VSO_ELINE));
  1427. if (vmode->encp.sy_val_present)
  1428. writel_relaxed(vmode->encp.sy_val,
  1429. priv->io_base + _REG(ENCP_VIDEO_SY_VAL));
  1430. if (vmode->encp.sy2_val_present)
  1431. writel_relaxed(vmode->encp.sy2_val,
  1432. priv->io_base + _REG(ENCP_VIDEO_SY2_VAL));
  1433. writel_relaxed(vmode->encp.max_lncnt,
  1434. priv->io_base + _REG(ENCP_VIDEO_MAX_LNCNT));
  1435. writel_relaxed(1, priv->io_base + _REG(ENCP_VIDEO_EN));
  1436. /* Set DE signal’s polarity is active high */
  1437. writel_bits_relaxed(BIT(14), BIT(14),
  1438. priv->io_base + _REG(ENCP_VIDEO_MODE));
  1439. /* Program DE timing */
  1440. de_h_begin = modulo(readl_relaxed(priv->io_base +
  1441. _REG(ENCP_VIDEO_HAVON_BEGIN))
  1442. + venc_hdmi_latency,
  1443. total_pixels_venc);
  1444. de_h_end = modulo(de_h_begin + active_pixels_venc,
  1445. total_pixels_venc);
  1446. writel_relaxed(de_h_begin,
  1447. priv->io_base + _REG(ENCP_DE_H_BEGIN));
  1448. writel_relaxed(de_h_end,
  1449. priv->io_base + _REG(ENCP_DE_H_END));
  1450. /* Program DE timing for even field */
  1451. de_v_begin_even = readl_relaxed(priv->io_base
  1452. + _REG(ENCP_VIDEO_VAVON_BLINE));
  1453. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1454. de_v_end_even = de_v_begin_even +
  1455. (mode->vdisplay / 2);
  1456. else
  1457. de_v_end_even = de_v_begin_even + mode->vdisplay;
  1458. writel_relaxed(de_v_begin_even,
  1459. priv->io_base + _REG(ENCP_DE_V_BEGIN_EVEN));
  1460. writel_relaxed(de_v_end_even,
  1461. priv->io_base + _REG(ENCP_DE_V_END_EVEN));
  1462. /* Program DE timing for odd field if needed */
  1463. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  1464. unsigned int ofld_voav_ofst =
  1465. readl_relaxed(priv->io_base +
  1466. _REG(ENCP_VIDEO_OFLD_VOAV_OFST));
  1467. de_v_begin_odd = to_signed((ofld_voav_ofst & 0xf0) >> 4)
  1468. + de_v_begin_even
  1469. + ((mode->vtotal - 1) / 2);
  1470. de_v_end_odd = de_v_begin_odd + (mode->vdisplay / 2);
  1471. writel_relaxed(de_v_begin_odd,
  1472. priv->io_base + _REG(ENCP_DE_V_BEGIN_ODD));
  1473. writel_relaxed(de_v_end_odd,
  1474. priv->io_base + _REG(ENCP_DE_V_END_ODD));
  1475. }
  1476. /* Program Hsync timing */
  1477. if ((de_h_end + front_porch_venc) >= total_pixels_venc) {
  1478. hs_begin = de_h_end
  1479. + front_porch_venc
  1480. - total_pixels_venc;
  1481. vs_adjust = 1;
  1482. } else {
  1483. hs_begin = de_h_end
  1484. + front_porch_venc;
  1485. vs_adjust = 0;
  1486. }
  1487. hs_end = modulo(hs_begin + hsync_pixels_venc,
  1488. total_pixels_venc);
  1489. writel_relaxed(hs_begin,
  1490. priv->io_base + _REG(ENCP_DVI_HSO_BEGIN));
  1491. writel_relaxed(hs_end,
  1492. priv->io_base + _REG(ENCP_DVI_HSO_END));
  1493. /* Program Vsync timing for even field */
  1494. if (de_v_begin_even >=
  1495. (sof_lines + vsync_lines + (1 - vs_adjust)))
  1496. vs_bline_evn = de_v_begin_even
  1497. - sof_lines
  1498. - vsync_lines
  1499. - (1 - vs_adjust);
  1500. else
  1501. vs_bline_evn = mode->vtotal
  1502. + de_v_begin_even
  1503. - sof_lines
  1504. - vsync_lines
  1505. - (1 - vs_adjust);
  1506. vs_eline_evn = modulo(vs_bline_evn + vsync_lines,
  1507. mode->vtotal);
  1508. writel_relaxed(vs_bline_evn,
  1509. priv->io_base + _REG(ENCP_DVI_VSO_BLINE_EVN));
  1510. writel_relaxed(vs_eline_evn,
  1511. priv->io_base + _REG(ENCP_DVI_VSO_ELINE_EVN));
  1512. vso_begin_evn = hs_begin;
  1513. writel_relaxed(vso_begin_evn,
  1514. priv->io_base + _REG(ENCP_DVI_VSO_BEGIN_EVN));
  1515. writel_relaxed(vso_begin_evn,
  1516. priv->io_base + _REG(ENCP_DVI_VSO_END_EVN));
  1517. /* Program Vsync timing for odd field if needed */
  1518. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  1519. vs_bline_odd = (de_v_begin_odd - 1)
  1520. - sof_lines
  1521. - vsync_lines;
  1522. vs_eline_odd = (de_v_begin_odd - 1)
  1523. - vsync_lines;
  1524. vso_begin_odd = modulo(hs_begin
  1525. + (total_pixels_venc >> 1),
  1526. total_pixels_venc);
  1527. writel_relaxed(vs_bline_odd,
  1528. priv->io_base + _REG(ENCP_DVI_VSO_BLINE_ODD));
  1529. writel_relaxed(vs_eline_odd,
  1530. priv->io_base + _REG(ENCP_DVI_VSO_ELINE_ODD));
  1531. writel_relaxed(vso_begin_odd,
  1532. priv->io_base + _REG(ENCP_DVI_VSO_BEGIN_ODD));
  1533. writel_relaxed(vso_begin_odd,
  1534. priv->io_base + _REG(ENCP_DVI_VSO_END_ODD));
  1535. }
  1536. /* Select ENCP for VIU */
  1537. meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCP);
  1538. }
  1539. writel_relaxed((use_enci ? 1 : 2) |
  1540. (mode->flags & DRM_MODE_FLAG_PHSYNC ? 1 << 2 : 0) |
  1541. (mode->flags & DRM_MODE_FLAG_PVSYNC ? 1 << 3 : 0) |
  1542. 4 << 5 |
  1543. (venc_repeat ? 1 << 8 : 0) |
  1544. (hdmi_repeat ? 1 << 12 : 0),
  1545. priv->io_base + _REG(VPU_HDMI_SETTING));
  1546. priv->venc.hdmi_repeat = hdmi_repeat;
  1547. priv->venc.venc_repeat = venc_repeat;
  1548. priv->venc.hdmi_use_enci = use_enci;
  1549. priv->venc.current_mode = MESON_VENC_MODE_HDMI;
  1550. }
  1551. EXPORT_SYMBOL_GPL(meson_venc_hdmi_mode_set);
  1552. void meson_venci_cvbs_mode_set(struct meson_drm *priv,
  1553. struct meson_cvbs_enci_mode *mode)
  1554. {
  1555. if (mode->mode_tag == priv->venc.current_mode)
  1556. return;
  1557. /* CVBS Filter settings */
  1558. writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL));
  1559. writel_relaxed(0x12, priv->io_base + _REG(ENCI_CFILT_CTRL2));
  1560. /* Digital Video Select : Interlace, clk27 clk, external */
  1561. writel_relaxed(0, priv->io_base + _REG(VENC_DVI_SETTING));
  1562. /* Reset Video Mode */
  1563. writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE));
  1564. writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
  1565. /* Horizontal sync signal output */
  1566. writel_relaxed(mode->hso_begin,
  1567. priv->io_base + _REG(ENCI_SYNC_HSO_BEGIN));
  1568. writel_relaxed(mode->hso_end,
  1569. priv->io_base + _REG(ENCI_SYNC_HSO_END));
  1570. /* Vertical Sync lines */
  1571. writel_relaxed(mode->vso_even,
  1572. priv->io_base + _REG(ENCI_SYNC_VSO_EVNLN));
  1573. writel_relaxed(mode->vso_odd,
  1574. priv->io_base + _REG(ENCI_SYNC_VSO_ODDLN));
  1575. /* Macrovision max amplitude change */
  1576. writel_relaxed(0x8100 + mode->macv_max_amp,
  1577. priv->io_base + _REG(ENCI_MACV_MAX_AMP));
  1578. /* Video mode */
  1579. writel_relaxed(mode->video_prog_mode,
  1580. priv->io_base + _REG(VENC_VIDEO_PROG_MODE));
  1581. writel_relaxed(mode->video_mode,
  1582. priv->io_base + _REG(ENCI_VIDEO_MODE));
  1583. /* Advanced Video Mode :
  1584. * Demux shifting 0x2
  1585. * Blank line end at line17/22
  1586. * High bandwidth Luma Filter
  1587. * Low bandwidth Chroma Filter
  1588. * Bypass luma low pass filter
  1589. * No macrovision on CSYNC
  1590. */
  1591. writel_relaxed(0x26, priv->io_base + _REG(ENCI_VIDEO_MODE_ADV));
  1592. writel(mode->sch_adjust, priv->io_base + _REG(ENCI_VIDEO_SCH));
  1593. /* Sync mode : MASTER Master mode, free run, send HSO/VSO out */
  1594. writel_relaxed(0x07, priv->io_base + _REG(ENCI_SYNC_MODE));
  1595. /* 0x3 Y, C, and Component Y delay */
  1596. writel_relaxed(mode->yc_delay, priv->io_base + _REG(ENCI_YC_DELAY));
  1597. /* Timings */
  1598. writel_relaxed(mode->pixel_start,
  1599. priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_START));
  1600. writel_relaxed(mode->pixel_end,
  1601. priv->io_base + _REG(ENCI_VFIFO2VD_PIXEL_END));
  1602. writel_relaxed(mode->top_field_line_start,
  1603. priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_START));
  1604. writel_relaxed(mode->top_field_line_end,
  1605. priv->io_base + _REG(ENCI_VFIFO2VD_LINE_TOP_END));
  1606. writel_relaxed(mode->bottom_field_line_start,
  1607. priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_START));
  1608. writel_relaxed(mode->bottom_field_line_end,
  1609. priv->io_base + _REG(ENCI_VFIFO2VD_LINE_BOT_END));
  1610. /* Internal Venc, Internal VIU Sync, Internal Vencoder */
  1611. writel_relaxed(0, priv->io_base + _REG(VENC_SYNC_ROUTE));
  1612. /* UNreset Interlaced TV Encoder */
  1613. writel_relaxed(0, priv->io_base + _REG(ENCI_DBG_PX_RST));
  1614. /* Enable Vfifo2vd, Y_Cb_Y_Cr select */
  1615. writel_relaxed(0x4e01, priv->io_base + _REG(ENCI_VFIFO2VD_CTL));
  1616. /* Power UP Dacs */
  1617. writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_SETTING));
  1618. /* Video Upsampling */
  1619. writel_relaxed(0x0061, priv->io_base + _REG(VENC_UPSAMPLE_CTRL0));
  1620. writel_relaxed(0x4061, priv->io_base + _REG(VENC_UPSAMPLE_CTRL1));
  1621. writel_relaxed(0x5061, priv->io_base + _REG(VENC_UPSAMPLE_CTRL2));
  1622. /* Select Interlace Y DACs */
  1623. writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL0));
  1624. writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL1));
  1625. writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL2));
  1626. writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL3));
  1627. writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL4));
  1628. writel_relaxed(0, priv->io_base + _REG(VENC_VDAC_DACSEL5));
  1629. /* Select ENCI for VIU */
  1630. meson_vpp_setup_mux(priv, MESON_VIU_VPP_MUX_ENCI);
  1631. /* Enable ENCI FIFO */
  1632. writel_relaxed(0x2000, priv->io_base + _REG(VENC_VDAC_FIFO_CTRL));
  1633. /* Select ENCI DACs 0, 1, 4, and 5 */
  1634. writel_relaxed(0x11, priv->io_base + _REG(ENCI_DACSEL_0));
  1635. writel_relaxed(0x11, priv->io_base + _REG(ENCI_DACSEL_1));
  1636. /* Interlace video enable */
  1637. writel_relaxed(1, priv->io_base + _REG(ENCI_VIDEO_EN));
  1638. /* Configure Video Saturation / Contrast / Brightness / Hue */
  1639. writel_relaxed(mode->video_saturation,
  1640. priv->io_base + _REG(ENCI_VIDEO_SAT));
  1641. writel_relaxed(mode->video_contrast,
  1642. priv->io_base + _REG(ENCI_VIDEO_CONT));
  1643. writel_relaxed(mode->video_brightness,
  1644. priv->io_base + _REG(ENCI_VIDEO_BRIGHT));
  1645. writel_relaxed(mode->video_hue,
  1646. priv->io_base + _REG(ENCI_VIDEO_HUE));
  1647. /* Enable DAC0 Filter */
  1648. writel_relaxed(0x1, priv->io_base + _REG(VENC_VDAC_DAC0_FILT_CTRL0));
  1649. writel_relaxed(0xfc48, priv->io_base + _REG(VENC_VDAC_DAC0_FILT_CTRL1));
  1650. /* 0 in Macrovision register 0 */
  1651. writel_relaxed(0, priv->io_base + _REG(ENCI_MACV_N0));
  1652. /* Analog Synchronization and color burst value adjust */
  1653. writel_relaxed(mode->analog_sync_adj,
  1654. priv->io_base + _REG(ENCI_SYNC_ADJ));
  1655. priv->venc.current_mode = mode->mode_tag;
  1656. }
  1657. /* Returns the current ENCI field polarity */
  1658. unsigned int meson_venci_get_field(struct meson_drm *priv)
  1659. {
  1660. return readl_relaxed(priv->io_base + _REG(ENCI_INFO_READ)) & BIT(29);
  1661. }
  1662. void meson_venc_enable_vsync(struct meson_drm *priv)
  1663. {
  1664. writel_relaxed(2, priv->io_base + _REG(VENC_INTCTRL));
  1665. }
  1666. void meson_venc_disable_vsync(struct meson_drm *priv)
  1667. {
  1668. writel_relaxed(0, priv->io_base + _REG(VENC_INTCTRL));
  1669. }
  1670. void meson_venc_init(struct meson_drm *priv)
  1671. {
  1672. /* Disable CVBS VDAC */
  1673. regmap_write(priv->hhi, HHI_VDAC_CNTL0, 0);
  1674. regmap_write(priv->hhi, HHI_VDAC_CNTL1, 8);
  1675. /* Power Down Dacs */
  1676. writel_relaxed(0xff, priv->io_base + _REG(VENC_VDAC_SETTING));
  1677. /* Disable HDMI PHY */
  1678. regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0);
  1679. /* Disable HDMI */
  1680. writel_bits_relaxed(0x3, 0,
  1681. priv->io_base + _REG(VPU_HDMI_SETTING));
  1682. /* Disable all encoders */
  1683. writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_EN));
  1684. writel_relaxed(0, priv->io_base + _REG(ENCP_VIDEO_EN));
  1685. writel_relaxed(0, priv->io_base + _REG(ENCL_VIDEO_EN));
  1686. /* Disable VSync IRQ */
  1687. meson_venc_disable_vsync(priv);
  1688. priv->venc.current_mode = MESON_VENC_MODE_NONE;
  1689. }