sde_encoder_phys_cmd.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  7. #include "sde_encoder_phys.h"
  8. #include "sde_hw_interrupts.h"
  9. #include "sde_core_irq.h"
  10. #include "sde_formats.h"
  11. #include "sde_trace.h"
  12. #define SDE_DEBUG_CMDENC(e, fmt, ...) SDE_DEBUG("enc%d intf%d " fmt, \
  13. (e) && (e)->base.parent ? \
  14. (e)->base.parent->base.id : -1, \
  15. (e) ? (e)->base.intf_idx - INTF_0 : -1, ##__VA_ARGS__)
  16. #define SDE_ERROR_CMDENC(e, fmt, ...) SDE_ERROR("enc%d intf%d " fmt, \
  17. (e) && (e)->base.parent ? \
  18. (e)->base.parent->base.id : -1, \
  19. (e) ? (e)->base.intf_idx - INTF_0 : -1, ##__VA_ARGS__)
  20. #define to_sde_encoder_phys_cmd(x) \
  21. container_of(x, struct sde_encoder_phys_cmd, base)
  22. /*
  23. * Tearcheck sync start and continue thresholds are empirically found
  24. * based on common panels In the future, may want to allow panels to override
  25. * these default values
  26. */
  27. #define DEFAULT_TEARCHECK_SYNC_THRESH_START 4
  28. #define DEFAULT_TEARCHECK_SYNC_THRESH_CONTINUE 4
  29. #define SDE_ENC_WR_PTR_START_TIMEOUT_US 20000
  30. #define AUTOREFRESH_SEQ1_POLL_TIME 2000
  31. #define AUTOREFRESH_SEQ2_POLL_TIME 25000
  32. #define AUTOREFRESH_SEQ2_POLL_TIMEOUT 1000000
  33. static inline int _sde_encoder_phys_cmd_get_idle_timeout(
  34. struct sde_encoder_phys *phys_enc)
  35. {
  36. u32 timeout = phys_enc->kickoff_timeout_ms;
  37. struct sde_encoder_phys_cmd *cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  38. return cmd_enc->autorefresh.cfg.frame_count ?
  39. cmd_enc->autorefresh.cfg.frame_count * timeout : timeout;
  40. }
  41. static inline bool sde_encoder_phys_cmd_is_master(
  42. struct sde_encoder_phys *phys_enc)
  43. {
  44. return (phys_enc->split_role != ENC_ROLE_SLAVE) ? true : false;
  45. }
  46. static bool sde_encoder_phys_cmd_mode_fixup(
  47. struct sde_encoder_phys *phys_enc,
  48. const struct drm_display_mode *mode,
  49. struct drm_display_mode *adj_mode)
  50. {
  51. if (phys_enc)
  52. SDE_DEBUG_CMDENC(to_sde_encoder_phys_cmd(phys_enc), "\n");
  53. return true;
  54. }
  55. static uint64_t _sde_encoder_phys_cmd_get_autorefresh_property(
  56. struct sde_encoder_phys *phys_enc)
  57. {
  58. struct drm_connector *conn = phys_enc->connector;
  59. if (!conn || !conn->state)
  60. return 0;
  61. return sde_connector_get_property(conn->state,
  62. CONNECTOR_PROP_AUTOREFRESH);
  63. }
  64. static void _sde_encoder_phys_cmd_config_autorefresh(
  65. struct sde_encoder_phys *phys_enc,
  66. u32 new_frame_count)
  67. {
  68. struct sde_encoder_phys_cmd *cmd_enc =
  69. to_sde_encoder_phys_cmd(phys_enc);
  70. struct sde_hw_pingpong *hw_pp = phys_enc->hw_pp;
  71. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  72. struct drm_connector *conn = phys_enc->connector;
  73. struct sde_hw_autorefresh *cfg_cur, cfg_nxt;
  74. if (!conn || !conn->state || !hw_pp || !hw_intf)
  75. return;
  76. cfg_cur = &cmd_enc->autorefresh.cfg;
  77. /* autorefresh property value should be validated already */
  78. memset(&cfg_nxt, 0, sizeof(cfg_nxt));
  79. cfg_nxt.frame_count = new_frame_count;
  80. cfg_nxt.enable = (cfg_nxt.frame_count != 0);
  81. SDE_DEBUG_CMDENC(cmd_enc, "autorefresh state %d->%d framecount %d\n",
  82. cfg_cur->enable, cfg_nxt.enable, cfg_nxt.frame_count);
  83. SDE_EVT32(DRMID(phys_enc->parent), hw_pp->idx, hw_intf->idx,
  84. cfg_cur->enable, cfg_nxt.enable, cfg_nxt.frame_count);
  85. /* only proceed on state changes */
  86. if (cfg_nxt.enable == cfg_cur->enable)
  87. return;
  88. memcpy(cfg_cur, &cfg_nxt, sizeof(*cfg_cur));
  89. if (phys_enc->has_intf_te && hw_intf->ops.setup_autorefresh)
  90. hw_intf->ops.setup_autorefresh(hw_intf, cfg_cur);
  91. else if (hw_pp->ops.setup_autorefresh)
  92. hw_pp->ops.setup_autorefresh(hw_pp, cfg_cur);
  93. }
  94. static void _sde_encoder_phys_cmd_update_flush_mask(
  95. struct sde_encoder_phys *phys_enc)
  96. {
  97. struct sde_encoder_phys_cmd *cmd_enc;
  98. struct sde_hw_ctl *ctl;
  99. if (!phys_enc || !phys_enc->hw_intf || !phys_enc->hw_pp)
  100. return;
  101. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  102. ctl = phys_enc->hw_ctl;
  103. if (!ctl)
  104. return;
  105. if (!ctl->ops.update_bitmask) {
  106. SDE_ERROR("invalid hw_ctl ops %d\n", ctl->idx);
  107. return;
  108. }
  109. ctl->ops.update_bitmask(ctl, SDE_HW_FLUSH_INTF, phys_enc->intf_idx, 1);
  110. if (phys_enc->hw_pp->merge_3d)
  111. ctl->ops.update_bitmask(ctl, SDE_HW_FLUSH_MERGE_3D,
  112. phys_enc->hw_pp->merge_3d->idx, 1);
  113. SDE_DEBUG_CMDENC(cmd_enc, "update pending flush ctl %d intf_idx %x\n",
  114. ctl->idx - CTL_0, phys_enc->intf_idx);
  115. }
  116. static void _sde_encoder_phys_cmd_update_intf_cfg(
  117. struct sde_encoder_phys *phys_enc)
  118. {
  119. struct sde_encoder_phys_cmd *cmd_enc =
  120. to_sde_encoder_phys_cmd(phys_enc);
  121. struct sde_hw_ctl *ctl;
  122. if (!phys_enc)
  123. return;
  124. ctl = phys_enc->hw_ctl;
  125. if (!ctl)
  126. return;
  127. if (ctl->ops.setup_intf_cfg) {
  128. struct sde_hw_intf_cfg intf_cfg = { 0 };
  129. intf_cfg.intf = phys_enc->intf_idx;
  130. intf_cfg.intf_mode_sel = SDE_CTL_MODE_SEL_CMD;
  131. intf_cfg.stream_sel = cmd_enc->stream_sel;
  132. intf_cfg.mode_3d =
  133. sde_encoder_helper_get_3d_blend_mode(phys_enc);
  134. ctl->ops.setup_intf_cfg(ctl, &intf_cfg);
  135. } else if (test_bit(SDE_CTL_ACTIVE_CFG, &ctl->caps->features)) {
  136. sde_encoder_helper_update_intf_cfg(phys_enc);
  137. }
  138. }
  139. static void _sde_encoder_phys_signal_frame_done(struct sde_encoder_phys *phys_enc)
  140. {
  141. struct sde_encoder_phys_cmd *cmd_enc;
  142. struct sde_hw_ctl *ctl;
  143. u32 scheduler_status = INVALID_CTL_STATUS, event = 0;
  144. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  145. ctl = phys_enc->hw_ctl;
  146. /* notify all synchronous clients first, then asynchronous clients */
  147. if (phys_enc->parent_ops.handle_frame_done &&
  148. atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0)) {
  149. event = SDE_ENCODER_FRAME_EVENT_DONE |
  150. SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
  151. spin_lock(phys_enc->enc_spinlock);
  152. phys_enc->parent_ops.handle_frame_done(phys_enc->parent,
  153. phys_enc, event);
  154. if (cmd_enc->frame_tx_timeout_report_cnt)
  155. phys_enc->recovered = true;
  156. spin_unlock(phys_enc->enc_spinlock);
  157. }
  158. if (ctl && ctl->ops.get_scheduler_status)
  159. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  160. SDE_EVT32_IRQ(DRMID(phys_enc->parent), ctl->idx - CTL_0,
  161. phys_enc->hw_pp->idx - PINGPONG_0, event, scheduler_status);
  162. /* Signal any waiting atomic commit thread */
  163. wake_up_all(&phys_enc->pending_kickoff_wq);
  164. }
  165. static void sde_encoder_phys_cmd_ctl_done_irq(void *arg, int irq_idx)
  166. {
  167. struct sde_encoder_phys *phys_enc = arg;
  168. if (!phys_enc)
  169. return;
  170. SDE_ATRACE_BEGIN("ctl_done_irq");
  171. _sde_encoder_phys_signal_frame_done(phys_enc);
  172. SDE_ATRACE_END("ctl_done_irq");
  173. }
  174. static void sde_encoder_phys_cmd_pp_tx_done_irq(void *arg, int irq_idx)
  175. {
  176. struct sde_encoder_phys *phys_enc = arg;
  177. if (!phys_enc || !phys_enc->hw_pp)
  178. return;
  179. SDE_ATRACE_BEGIN("pp_done_irq");
  180. _sde_encoder_phys_signal_frame_done(phys_enc);
  181. SDE_ATRACE_END("pp_done_irq");
  182. }
  183. static void sde_encoder_phys_cmd_autorefresh_done_irq(void *arg, int irq_idx)
  184. {
  185. struct sde_encoder_phys *phys_enc = arg;
  186. struct sde_encoder_phys_cmd *cmd_enc =
  187. to_sde_encoder_phys_cmd(phys_enc);
  188. unsigned long lock_flags;
  189. int new_cnt;
  190. if (!cmd_enc)
  191. return;
  192. phys_enc = &cmd_enc->base;
  193. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  194. new_cnt = atomic_add_unless(&cmd_enc->autorefresh.kickoff_cnt, -1, 0);
  195. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  196. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  197. phys_enc->hw_pp->idx - PINGPONG_0,
  198. phys_enc->hw_intf->idx - INTF_0,
  199. new_cnt);
  200. /* Signal any waiting atomic commit thread */
  201. wake_up_all(&cmd_enc->autorefresh.kickoff_wq);
  202. }
  203. static void sde_encoder_phys_cmd_te_rd_ptr_irq(void *arg, int irq_idx)
  204. {
  205. struct sde_encoder_phys *phys_enc = arg;
  206. struct sde_encoder_phys_cmd *cmd_enc;
  207. u32 scheduler_status = INVALID_CTL_STATUS;
  208. struct sde_hw_ctl *ctl;
  209. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  210. struct sde_encoder_phys_cmd_te_timestamp *te_timestamp;
  211. unsigned long lock_flags;
  212. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  213. return;
  214. SDE_ATRACE_BEGIN("rd_ptr_irq");
  215. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  216. ctl = phys_enc->hw_ctl;
  217. if (ctl && ctl->ops.get_scheduler_status)
  218. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  219. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  220. te_timestamp = list_first_entry_or_null(&cmd_enc->te_timestamp_list,
  221. struct sde_encoder_phys_cmd_te_timestamp, list);
  222. if (te_timestamp) {
  223. list_del_init(&te_timestamp->list);
  224. te_timestamp->timestamp = ktime_get();
  225. list_add_tail(&te_timestamp->list, &cmd_enc->te_timestamp_list);
  226. }
  227. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  228. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  229. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  230. info[0].pp_idx, info[0].intf_idx,
  231. info[0].wr_ptr_line_count, info[0].intf_frame_count,
  232. info[1].pp_idx, info[1].intf_idx,
  233. info[1].wr_ptr_line_count, info[1].intf_frame_count,
  234. scheduler_status);
  235. if (phys_enc->parent_ops.handle_vblank_virt)
  236. phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent,
  237. phys_enc);
  238. atomic_add_unless(&cmd_enc->pending_vblank_cnt, -1, 0);
  239. wake_up_all(&cmd_enc->pending_vblank_wq);
  240. SDE_ATRACE_END("rd_ptr_irq");
  241. }
  242. static void sde_encoder_phys_cmd_wr_ptr_irq(void *arg, int irq_idx)
  243. {
  244. struct sde_encoder_phys *phys_enc = arg;
  245. struct sde_hw_ctl *ctl;
  246. u32 event = 0;
  247. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  248. if (!phys_enc || !phys_enc->hw_ctl)
  249. return;
  250. SDE_ATRACE_BEGIN("wr_ptr_irq");
  251. ctl = phys_enc->hw_ctl;
  252. if (atomic_add_unless(&phys_enc->pending_retire_fence_cnt, -1, 0)) {
  253. event = SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE;
  254. if (phys_enc->parent_ops.handle_frame_done) {
  255. spin_lock(phys_enc->enc_spinlock);
  256. phys_enc->parent_ops.handle_frame_done(
  257. phys_enc->parent, phys_enc, event);
  258. spin_unlock(phys_enc->enc_spinlock);
  259. }
  260. }
  261. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  262. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  263. ctl->idx - CTL_0, event,
  264. info[0].pp_idx, info[0].intf_idx, info[0].wr_ptr_line_count,
  265. info[1].pp_idx, info[1].intf_idx, info[1].wr_ptr_line_count);
  266. /* Signal any waiting wr_ptr start interrupt */
  267. wake_up_all(&phys_enc->pending_kickoff_wq);
  268. SDE_ATRACE_END("wr_ptr_irq");
  269. }
  270. static void _sde_encoder_phys_cmd_setup_irq_hw_idx(
  271. struct sde_encoder_phys *phys_enc)
  272. {
  273. struct sde_encoder_irq *irq;
  274. struct sde_kms *sde_kms;
  275. if (!phys_enc->sde_kms || !phys_enc->hw_pp || !phys_enc->hw_ctl) {
  276. SDE_ERROR("invalid args %d %d %d\n", !phys_enc->sde_kms,
  277. !phys_enc->hw_pp, !phys_enc->hw_ctl);
  278. return;
  279. }
  280. if (phys_enc->has_intf_te && !phys_enc->hw_intf) {
  281. SDE_ERROR("invalid intf configuration\n");
  282. return;
  283. }
  284. sde_kms = phys_enc->sde_kms;
  285. irq = &phys_enc->irq[INTR_IDX_CTL_START];
  286. irq->hw_idx = phys_enc->hw_ctl->idx;
  287. irq = &phys_enc->irq[INTR_IDX_CTL_DONE];
  288. irq->hw_idx = phys_enc->hw_ctl->idx;
  289. irq = &phys_enc->irq[INTR_IDX_PINGPONG];
  290. irq->hw_idx = phys_enc->hw_pp->idx;
  291. irq = &phys_enc->irq[INTR_IDX_RDPTR];
  292. if (phys_enc->has_intf_te)
  293. irq->hw_idx = phys_enc->hw_intf->idx;
  294. else
  295. irq->hw_idx = phys_enc->hw_pp->idx;
  296. irq = &phys_enc->irq[INTR_IDX_AUTOREFRESH_DONE];
  297. if (phys_enc->has_intf_te)
  298. irq->hw_idx = phys_enc->hw_intf->idx;
  299. else
  300. irq->hw_idx = phys_enc->hw_pp->idx;
  301. irq = &phys_enc->irq[INTR_IDX_WRPTR];
  302. if (phys_enc->has_intf_te)
  303. irq->hw_idx = phys_enc->hw_intf->idx;
  304. else
  305. irq->hw_idx = phys_enc->hw_pp->idx;
  306. }
  307. static void sde_encoder_phys_cmd_cont_splash_mode_set(
  308. struct sde_encoder_phys *phys_enc,
  309. struct drm_display_mode *adj_mode)
  310. {
  311. struct sde_hw_intf *hw_intf;
  312. struct sde_hw_pingpong *hw_pp;
  313. struct sde_encoder_phys_cmd *cmd_enc;
  314. if (!phys_enc || !adj_mode) {
  315. SDE_ERROR("invalid args\n");
  316. return;
  317. }
  318. phys_enc->cached_mode = *adj_mode;
  319. phys_enc->enable_state = SDE_ENC_ENABLED;
  320. if (!phys_enc->hw_ctl || !phys_enc->hw_pp) {
  321. SDE_DEBUG("invalid ctl:%d pp:%d\n",
  322. (phys_enc->hw_ctl == NULL),
  323. (phys_enc->hw_pp == NULL));
  324. return;
  325. }
  326. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  327. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  328. hw_pp = phys_enc->hw_pp;
  329. hw_intf = phys_enc->hw_intf;
  330. if (phys_enc->has_intf_te && hw_intf &&
  331. hw_intf->ops.get_autorefresh) {
  332. hw_intf->ops.get_autorefresh(hw_intf,
  333. &cmd_enc->autorefresh.cfg);
  334. } else if (hw_pp && hw_pp->ops.get_autorefresh) {
  335. hw_pp->ops.get_autorefresh(hw_pp,
  336. &cmd_enc->autorefresh.cfg);
  337. }
  338. if (hw_intf && hw_intf->ops.reset_counter)
  339. hw_intf->ops.reset_counter(hw_intf);
  340. }
  341. _sde_encoder_phys_cmd_setup_irq_hw_idx(phys_enc);
  342. }
  343. static void sde_encoder_phys_cmd_mode_set(
  344. struct sde_encoder_phys *phys_enc,
  345. struct drm_display_mode *mode,
  346. struct drm_display_mode *adj_mode)
  347. {
  348. struct sde_encoder_phys_cmd *cmd_enc =
  349. to_sde_encoder_phys_cmd(phys_enc);
  350. struct sde_rm *rm = &phys_enc->sde_kms->rm;
  351. struct sde_rm_hw_iter iter;
  352. int i, instance;
  353. if (!phys_enc || !mode || !adj_mode) {
  354. SDE_ERROR("invalid args\n");
  355. return;
  356. }
  357. phys_enc->cached_mode = *adj_mode;
  358. SDE_DEBUG_CMDENC(cmd_enc, "caching mode:\n");
  359. drm_mode_debug_printmodeline(adj_mode);
  360. instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
  361. /* Retrieve previously allocated HW Resources. Shouldn't fail */
  362. sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
  363. for (i = 0; i <= instance; i++) {
  364. if (sde_rm_get_hw(rm, &iter))
  365. phys_enc->hw_ctl = to_sde_hw_ctl(iter.hw);
  366. }
  367. if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
  368. SDE_ERROR_CMDENC(cmd_enc, "failed to init ctl: %ld\n",
  369. PTR_ERR(phys_enc->hw_ctl));
  370. phys_enc->hw_ctl = NULL;
  371. return;
  372. }
  373. sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_INTF);
  374. for (i = 0; i <= instance; i++) {
  375. if (sde_rm_get_hw(rm, &iter))
  376. phys_enc->hw_intf = to_sde_hw_intf(iter.hw);
  377. }
  378. if (IS_ERR_OR_NULL(phys_enc->hw_intf)) {
  379. SDE_ERROR_CMDENC(cmd_enc, "failed to init intf: %ld\n",
  380. PTR_ERR(phys_enc->hw_intf));
  381. phys_enc->hw_intf = NULL;
  382. return;
  383. }
  384. _sde_encoder_phys_cmd_setup_irq_hw_idx(phys_enc);
  385. phys_enc->kickoff_timeout_ms =
  386. sde_encoder_helper_get_kickoff_timeout_ms(phys_enc->parent);
  387. }
  388. static int _sde_encoder_phys_cmd_handle_framedone_timeout(
  389. struct sde_encoder_phys *phys_enc)
  390. {
  391. struct sde_encoder_phys_cmd *cmd_enc =
  392. to_sde_encoder_phys_cmd(phys_enc);
  393. bool recovery_events = sde_encoder_recovery_events_enabled(
  394. phys_enc->parent);
  395. u32 frame_event = SDE_ENCODER_FRAME_EVENT_ERROR
  396. | SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
  397. struct drm_connector *conn;
  398. u32 pending_kickoff_cnt;
  399. unsigned long lock_flags;
  400. if (!phys_enc->hw_pp || !phys_enc->hw_ctl)
  401. return -EINVAL;
  402. conn = phys_enc->connector;
  403. /* decrement the kickoff_cnt before checking for ESD status */
  404. if (!atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0))
  405. return 0;
  406. cmd_enc->frame_tx_timeout_report_cnt++;
  407. pending_kickoff_cnt = atomic_read(&phys_enc->pending_kickoff_cnt) + 1;
  408. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  409. cmd_enc->frame_tx_timeout_report_cnt,
  410. pending_kickoff_cnt,
  411. frame_event);
  412. /* check if panel is still sending TE signal or not */
  413. if (sde_connector_esd_status(phys_enc->connector))
  414. goto exit;
  415. /* to avoid flooding, only log first time, and "dead" time */
  416. if (cmd_enc->frame_tx_timeout_report_cnt == 1) {
  417. SDE_ERROR_CMDENC(cmd_enc,
  418. "pp:%d kickoff timed out ctl %d koff_cnt %d\n",
  419. phys_enc->hw_pp->idx - PINGPONG_0,
  420. phys_enc->hw_ctl->idx - CTL_0,
  421. pending_kickoff_cnt);
  422. SDE_EVT32(DRMID(phys_enc->parent), SDE_EVTLOG_FATAL);
  423. mutex_lock(phys_enc->vblank_ctl_lock);
  424. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_RDPTR);
  425. if (sde_kms_is_secure_session_inprogress(phys_enc->sde_kms))
  426. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "secure");
  427. else
  428. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL);
  429. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_RDPTR);
  430. mutex_unlock(phys_enc->vblank_ctl_lock);
  431. }
  432. /*
  433. * if the recovery event is registered by user, don't panic
  434. * trigger panic on first timeout if no listener registered
  435. */
  436. if (recovery_events)
  437. sde_connector_event_notify(conn, DRM_EVENT_SDE_HW_RECOVERY,
  438. sizeof(uint8_t), SDE_RECOVERY_CAPTURE);
  439. else if (cmd_enc->frame_tx_timeout_report_cnt)
  440. SDE_DBG_DUMP(0x0, "panic");
  441. /* request a ctl reset before the next kickoff */
  442. phys_enc->enable_state = SDE_ENC_ERR_NEEDS_HW_RESET;
  443. exit:
  444. if (phys_enc->parent_ops.handle_frame_done) {
  445. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  446. phys_enc->parent_ops.handle_frame_done(
  447. phys_enc->parent, phys_enc, frame_event);
  448. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  449. }
  450. return -ETIMEDOUT;
  451. }
  452. static bool _sde_encoder_phys_is_ppsplit_slave(
  453. struct sde_encoder_phys *phys_enc)
  454. {
  455. if (!phys_enc)
  456. return false;
  457. return _sde_encoder_phys_is_ppsplit(phys_enc) &&
  458. phys_enc->split_role == ENC_ROLE_SLAVE;
  459. }
  460. static bool _sde_encoder_phys_is_disabling_ppsplit_slave(
  461. struct sde_encoder_phys *phys_enc)
  462. {
  463. enum sde_rm_topology_name old_top;
  464. if (!phys_enc || !phys_enc->connector ||
  465. phys_enc->split_role != ENC_ROLE_SLAVE)
  466. return false;
  467. old_top = sde_connector_get_old_topology_name(
  468. phys_enc->connector->state);
  469. return old_top == SDE_RM_TOPOLOGY_PPSPLIT;
  470. }
  471. static int _sde_encoder_phys_cmd_poll_write_pointer_started(
  472. struct sde_encoder_phys *phys_enc)
  473. {
  474. struct sde_encoder_phys_cmd *cmd_enc =
  475. to_sde_encoder_phys_cmd(phys_enc);
  476. struct sde_hw_pingpong *hw_pp = phys_enc->hw_pp;
  477. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  478. struct sde_hw_pp_vsync_info info;
  479. u32 timeout_us = SDE_ENC_WR_PTR_START_TIMEOUT_US;
  480. int ret = 0;
  481. if (!hw_pp || !hw_intf)
  482. return 0;
  483. if (phys_enc->has_intf_te) {
  484. if (!hw_intf->ops.get_vsync_info ||
  485. !hw_intf->ops.poll_timeout_wr_ptr)
  486. goto end;
  487. } else {
  488. if (!hw_pp->ops.get_vsync_info ||
  489. !hw_pp->ops.poll_timeout_wr_ptr)
  490. goto end;
  491. }
  492. if (phys_enc->has_intf_te)
  493. ret = hw_intf->ops.get_vsync_info(hw_intf, &info);
  494. else
  495. ret = hw_pp->ops.get_vsync_info(hw_pp, &info);
  496. if (ret)
  497. return ret;
  498. SDE_DEBUG_CMDENC(cmd_enc,
  499. "pp:%d intf:%d rd_ptr %d wr_ptr %d\n",
  500. phys_enc->hw_pp->idx - PINGPONG_0,
  501. phys_enc->hw_intf->idx - INTF_0,
  502. info.rd_ptr_line_count,
  503. info.wr_ptr_line_count);
  504. SDE_EVT32_VERBOSE(DRMID(phys_enc->parent),
  505. phys_enc->hw_pp->idx - PINGPONG_0,
  506. phys_enc->hw_intf->idx - INTF_0,
  507. info.wr_ptr_line_count);
  508. if (phys_enc->has_intf_te)
  509. ret = hw_intf->ops.poll_timeout_wr_ptr(hw_intf, timeout_us);
  510. else
  511. ret = hw_pp->ops.poll_timeout_wr_ptr(hw_pp, timeout_us);
  512. if (ret) {
  513. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  514. phys_enc->hw_intf->idx - INTF_0, timeout_us, ret);
  515. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "panic");
  516. }
  517. end:
  518. return ret;
  519. }
  520. static bool _sde_encoder_phys_cmd_is_ongoing_pptx(
  521. struct sde_encoder_phys *phys_enc)
  522. {
  523. struct sde_hw_pingpong *hw_pp;
  524. struct sde_hw_pp_vsync_info info;
  525. struct sde_hw_intf *hw_intf;
  526. if (!phys_enc)
  527. return false;
  528. if (phys_enc->has_intf_te) {
  529. hw_intf = phys_enc->hw_intf;
  530. if (!hw_intf || !hw_intf->ops.get_vsync_info)
  531. return false;
  532. hw_intf->ops.get_vsync_info(hw_intf, &info);
  533. } else {
  534. hw_pp = phys_enc->hw_pp;
  535. if (!hw_pp || !hw_pp->ops.get_vsync_info)
  536. return false;
  537. hw_pp->ops.get_vsync_info(hw_pp, &info);
  538. }
  539. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  540. phys_enc->hw_intf->idx - INTF_0, atomic_read(&phys_enc->pending_kickoff_cnt),
  541. info.wr_ptr_line_count, info.intf_frame_count, phys_enc->cached_mode.vdisplay);
  542. if (info.wr_ptr_line_count > 0 && info.wr_ptr_line_count <
  543. phys_enc->cached_mode.vdisplay)
  544. return true;
  545. return false;
  546. }
  547. static bool _sde_encoder_phys_cmd_is_scheduler_idle(
  548. struct sde_encoder_phys *phys_enc)
  549. {
  550. bool wr_ptr_wait_success = true;
  551. unsigned long lock_flags;
  552. bool ret = false;
  553. struct sde_encoder_phys_cmd *cmd_enc =
  554. to_sde_encoder_phys_cmd(phys_enc);
  555. struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
  556. enum frame_trigger_mode_type frame_trigger_mode =
  557. phys_enc->frame_trigger_mode;
  558. if (sde_encoder_phys_cmd_is_master(phys_enc))
  559. wr_ptr_wait_success = cmd_enc->wr_ptr_wait_success;
  560. /*
  561. * Handle cases where a pp-done interrupt is missed
  562. * due to irq latency with POSTED start
  563. */
  564. if (wr_ptr_wait_success &&
  565. (frame_trigger_mode == FRAME_DONE_WAIT_POSTED_START) &&
  566. ctl->ops.get_scheduler_status &&
  567. phys_enc->parent_ops.handle_frame_done &&
  568. atomic_read(&phys_enc->pending_kickoff_cnt) > 0 &&
  569. (ctl->ops.get_scheduler_status(ctl) & BIT(0)) &&
  570. atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0)) {
  571. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  572. phys_enc->parent_ops.handle_frame_done(
  573. phys_enc->parent, phys_enc,
  574. SDE_ENCODER_FRAME_EVENT_DONE |
  575. SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE);
  576. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  577. SDE_EVT32(DRMID(phys_enc->parent),
  578. phys_enc->hw_pp->idx - PINGPONG_0,
  579. phys_enc->hw_intf->idx - INTF_0,
  580. atomic_read(&phys_enc->pending_kickoff_cnt));
  581. ret = true;
  582. }
  583. return ret;
  584. }
  585. static int _sde_encoder_phys_cmd_wait_for_idle(
  586. struct sde_encoder_phys *phys_enc)
  587. {
  588. struct sde_encoder_wait_info wait_info = {0};
  589. enum sde_intr_idx intr_idx;
  590. int ret;
  591. if (!phys_enc) {
  592. SDE_ERROR("invalid encoder\n");
  593. return -EINVAL;
  594. }
  595. if (atomic_read(&phys_enc->pending_kickoff_cnt) > 1)
  596. wait_info.count_check = 1;
  597. wait_info.wq = &phys_enc->pending_kickoff_wq;
  598. wait_info.atomic_cnt = &phys_enc->pending_kickoff_cnt;
  599. wait_info.timeout_ms = phys_enc->kickoff_timeout_ms;
  600. /* slave encoder doesn't enable for ppsplit */
  601. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  602. return 0;
  603. if (_sde_encoder_phys_cmd_is_scheduler_idle(phys_enc))
  604. return 0;
  605. intr_idx = sde_encoder_check_ctl_done_support(phys_enc->parent) ?
  606. INTR_IDX_CTL_DONE : INTR_IDX_PINGPONG;
  607. ret = sde_encoder_helper_wait_for_irq(phys_enc, intr_idx, &wait_info);
  608. if (ret == -ETIMEDOUT) {
  609. if (_sde_encoder_phys_cmd_is_scheduler_idle(phys_enc))
  610. return 0;
  611. _sde_encoder_phys_cmd_handle_framedone_timeout(phys_enc);
  612. }
  613. return ret;
  614. }
  615. static int _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  616. struct sde_encoder_phys *phys_enc)
  617. {
  618. struct sde_encoder_phys_cmd *cmd_enc =
  619. to_sde_encoder_phys_cmd(phys_enc);
  620. struct sde_encoder_wait_info wait_info = {0};
  621. int ret = 0;
  622. if (!phys_enc) {
  623. SDE_ERROR("invalid encoder\n");
  624. return -EINVAL;
  625. }
  626. /* only master deals with autorefresh */
  627. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  628. return 0;
  629. wait_info.wq = &cmd_enc->autorefresh.kickoff_wq;
  630. wait_info.atomic_cnt = &cmd_enc->autorefresh.kickoff_cnt;
  631. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(phys_enc);
  632. /* wait for autorefresh kickoff to start */
  633. ret = sde_encoder_helper_wait_for_irq(phys_enc,
  634. INTR_IDX_AUTOREFRESH_DONE, &wait_info);
  635. /* double check that kickoff has started by reading write ptr reg */
  636. if (!ret)
  637. ret = _sde_encoder_phys_cmd_poll_write_pointer_started(
  638. phys_enc);
  639. else
  640. sde_encoder_helper_report_irq_timeout(phys_enc,
  641. INTR_IDX_AUTOREFRESH_DONE);
  642. return ret;
  643. }
  644. static int sde_encoder_phys_cmd_control_vblank_irq(
  645. struct sde_encoder_phys *phys_enc,
  646. bool enable)
  647. {
  648. struct sde_encoder_phys_cmd *cmd_enc =
  649. to_sde_encoder_phys_cmd(phys_enc);
  650. int ret = 0;
  651. u32 refcount;
  652. struct sde_kms *sde_kms;
  653. if (!phys_enc || !phys_enc->hw_pp) {
  654. SDE_ERROR("invalid encoder\n");
  655. return -EINVAL;
  656. }
  657. sde_kms = phys_enc->sde_kms;
  658. mutex_lock(phys_enc->vblank_ctl_lock);
  659. /* Slave encoders don't report vblank */
  660. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  661. goto end;
  662. refcount = atomic_read(&phys_enc->vblank_refcount);
  663. /* protect against negative */
  664. if (!enable && refcount == 0) {
  665. ret = -EINVAL;
  666. goto end;
  667. }
  668. SDE_DEBUG_CMDENC(cmd_enc, "[%pS] enable=%d/%d\n",
  669. __builtin_return_address(0), enable, refcount);
  670. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  671. enable, refcount);
  672. if (enable && atomic_inc_return(&phys_enc->vblank_refcount) == 1) {
  673. ret = sde_encoder_helper_register_irq(phys_enc, INTR_IDX_RDPTR);
  674. if (ret)
  675. atomic_dec_return(&phys_enc->vblank_refcount);
  676. } else if (!enable &&
  677. atomic_dec_return(&phys_enc->vblank_refcount) == 0) {
  678. ret = sde_encoder_helper_unregister_irq(phys_enc,
  679. INTR_IDX_RDPTR);
  680. if (ret)
  681. atomic_inc_return(&phys_enc->vblank_refcount);
  682. }
  683. end:
  684. mutex_unlock(phys_enc->vblank_ctl_lock);
  685. if (ret) {
  686. SDE_ERROR_CMDENC(cmd_enc,
  687. "control vblank irq error %d, enable %d, refcount %d\n",
  688. ret, enable, refcount);
  689. SDE_EVT32(DRMID(phys_enc->parent),
  690. phys_enc->hw_pp->idx - PINGPONG_0,
  691. enable, refcount, SDE_EVTLOG_ERROR);
  692. }
  693. return ret;
  694. }
  695. void sde_encoder_phys_cmd_irq_control(struct sde_encoder_phys *phys_enc,
  696. bool enable)
  697. {
  698. struct sde_encoder_phys_cmd *cmd_enc;
  699. bool ctl_done_supported = false;
  700. if (!phys_enc)
  701. return;
  702. /**
  703. * pingpong split slaves do not register for IRQs
  704. * check old and new topologies
  705. */
  706. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc) ||
  707. _sde_encoder_phys_is_disabling_ppsplit_slave(phys_enc))
  708. return;
  709. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  710. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  711. enable, atomic_read(&phys_enc->vblank_refcount));
  712. ctl_done_supported = sde_encoder_check_ctl_done_support(phys_enc->parent);
  713. if (enable) {
  714. if (!ctl_done_supported)
  715. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_PINGPONG);
  716. sde_encoder_phys_cmd_control_vblank_irq(phys_enc, true);
  717. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  718. sde_encoder_helper_register_irq(phys_enc,
  719. INTR_IDX_WRPTR);
  720. sde_encoder_helper_register_irq(phys_enc,
  721. INTR_IDX_AUTOREFRESH_DONE);
  722. if (ctl_done_supported)
  723. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_CTL_DONE);
  724. }
  725. } else {
  726. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  727. sde_encoder_helper_unregister_irq(phys_enc,
  728. INTR_IDX_WRPTR);
  729. sde_encoder_helper_unregister_irq(phys_enc,
  730. INTR_IDX_AUTOREFRESH_DONE);
  731. if (ctl_done_supported)
  732. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_CTL_DONE);
  733. }
  734. sde_encoder_phys_cmd_control_vblank_irq(phys_enc, false);
  735. if (!ctl_done_supported)
  736. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_PINGPONG);
  737. }
  738. }
  739. static int _get_tearcheck_threshold(struct sde_encoder_phys *phys_enc)
  740. {
  741. struct drm_connector *conn = phys_enc->connector;
  742. u32 qsync_mode;
  743. struct drm_display_mode *mode;
  744. u32 threshold_lines = DEFAULT_TEARCHECK_SYNC_THRESH_START;
  745. struct sde_encoder_phys_cmd *cmd_enc =
  746. to_sde_encoder_phys_cmd(phys_enc);
  747. if (!conn || !conn->state)
  748. return 0;
  749. mode = &phys_enc->cached_mode;
  750. qsync_mode = sde_connector_get_qsync_mode(conn);
  751. if (mode && (qsync_mode == SDE_RM_QSYNC_CONTINUOUS_MODE)) {
  752. u32 qsync_min_fps = 0;
  753. u32 default_fps = drm_mode_vrefresh(mode);
  754. u32 yres = mode->vtotal;
  755. u32 slow_time_ns;
  756. u32 default_time_ns;
  757. u32 extra_time_ns;
  758. u32 default_line_time_ns;
  759. if (phys_enc->parent_ops.get_qsync_fps)
  760. phys_enc->parent_ops.get_qsync_fps(
  761. phys_enc->parent, &qsync_min_fps, conn->state);
  762. if (!qsync_min_fps || !default_fps || !yres) {
  763. SDE_ERROR_CMDENC(cmd_enc,
  764. "wrong qsync params %d %d %d\n",
  765. qsync_min_fps, default_fps, yres);
  766. goto exit;
  767. }
  768. if (qsync_min_fps >= default_fps) {
  769. SDE_ERROR_CMDENC(cmd_enc,
  770. "qsync fps:%d must be less than default:%d\n",
  771. qsync_min_fps, default_fps);
  772. goto exit;
  773. }
  774. /* Calculate the number of extra lines*/
  775. slow_time_ns = DIV_ROUND_UP(1000000000, qsync_min_fps);
  776. default_time_ns = DIV_ROUND_UP(1000000000, default_fps);
  777. extra_time_ns = slow_time_ns - default_time_ns;
  778. default_line_time_ns = DIV_ROUND_UP(default_time_ns, yres);
  779. threshold_lines = extra_time_ns / default_line_time_ns;
  780. /* some DDICs express the timeout value in lines/4, round down to compensate */
  781. threshold_lines = round_down(threshold_lines, 4);
  782. /* remove 2 lines to cover for latency */
  783. if (threshold_lines - 2 > DEFAULT_TEARCHECK_SYNC_THRESH_START)
  784. threshold_lines -= 2;
  785. SDE_DEBUG_CMDENC(cmd_enc, "slow:%d default:%d extra:%d(ns)\n",
  786. slow_time_ns, default_time_ns, extra_time_ns);
  787. SDE_DEBUG_CMDENC(cmd_enc, "min_fps:%d fps:%d yres:%d lines:%d\n",
  788. qsync_min_fps, default_fps, yres, threshold_lines);
  789. SDE_EVT32(qsync_mode, qsync_min_fps, extra_time_ns, default_fps,
  790. yres, threshold_lines);
  791. }
  792. exit:
  793. return threshold_lines;
  794. }
  795. static void sde_encoder_phys_cmd_tearcheck_config(
  796. struct sde_encoder_phys *phys_enc)
  797. {
  798. struct sde_encoder_phys_cmd *cmd_enc =
  799. to_sde_encoder_phys_cmd(phys_enc);
  800. struct sde_hw_tear_check tc_cfg = { 0 };
  801. struct drm_display_mode *mode;
  802. bool tc_enable = true;
  803. u32 vsync_hz;
  804. int vrefresh;
  805. struct msm_drm_private *priv;
  806. struct sde_kms *sde_kms;
  807. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  808. SDE_ERROR("invalid encoder\n");
  809. return;
  810. }
  811. mode = &phys_enc->cached_mode;
  812. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, intf %d\n",
  813. phys_enc->hw_pp->idx - PINGPONG_0,
  814. phys_enc->hw_intf->idx - INTF_0);
  815. if (phys_enc->has_intf_te) {
  816. if (!phys_enc->hw_intf->ops.setup_tearcheck ||
  817. !phys_enc->hw_intf->ops.enable_tearcheck) {
  818. SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
  819. return;
  820. }
  821. } else {
  822. if (!phys_enc->hw_pp->ops.setup_tearcheck ||
  823. !phys_enc->hw_pp->ops.enable_tearcheck) {
  824. SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
  825. return;
  826. }
  827. }
  828. sde_kms = phys_enc->sde_kms;
  829. if (!sde_kms || !sde_kms->dev || !sde_kms->dev->dev_private) {
  830. SDE_ERROR("invalid device\n");
  831. return;
  832. }
  833. priv = sde_kms->dev->dev_private;
  834. vrefresh = drm_mode_vrefresh(mode);
  835. /*
  836. * TE default: dsi byte clock calculated base on 70 fps;
  837. * around 14 ms to complete a kickoff cycle if te disabled;
  838. * vclk_line base on 60 fps; write is faster than read;
  839. * init == start == rdptr;
  840. *
  841. * vsync_count is ratio of MDP VSYNC clock frequency to LCD panel
  842. * frequency divided by the no. of rows (lines) in the LCDpanel.
  843. */
  844. vsync_hz = sde_power_clk_get_rate(&priv->phandle, "vsync_clk");
  845. if (!vsync_hz || !mode->vtotal || !vrefresh) {
  846. SDE_DEBUG_CMDENC(cmd_enc,
  847. "invalid params - vsync_hz %u vtot %u vrefresh %u\n",
  848. vsync_hz, mode->vtotal, vrefresh);
  849. return;
  850. }
  851. tc_cfg.vsync_count = vsync_hz / (mode->vtotal * vrefresh);
  852. /* enable external TE after kickoff to avoid premature autorefresh */
  853. tc_cfg.hw_vsync_mode = 0;
  854. /*
  855. * By setting sync_cfg_height to near max register value, we essentially
  856. * disable sde hw generated TE signal, since hw TE will arrive first.
  857. * Only caveat is if due to error, we hit wrap-around.
  858. */
  859. tc_cfg.sync_cfg_height = 0xFFF0;
  860. tc_cfg.vsync_init_val = mode->vdisplay;
  861. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(phys_enc);
  862. tc_cfg.sync_threshold_continue = DEFAULT_TEARCHECK_SYNC_THRESH_CONTINUE;
  863. tc_cfg.start_pos = mode->vdisplay;
  864. tc_cfg.rd_ptr_irq = mode->vdisplay + 1;
  865. tc_cfg.wr_ptr_irq = 1;
  866. SDE_DEBUG_CMDENC(cmd_enc,
  867. "tc %d intf %d vsync_clk_speed_hz %u vtotal %u vrefresh %u\n",
  868. phys_enc->hw_pp->idx - PINGPONG_0,
  869. phys_enc->hw_intf->idx - INTF_0,
  870. vsync_hz, mode->vtotal, vrefresh);
  871. SDE_DEBUG_CMDENC(cmd_enc,
  872. "tc %d intf %d enable %u start_pos %u rd_ptr_irq %u wr_ptr_irq %u\n",
  873. phys_enc->hw_pp->idx - PINGPONG_0,
  874. phys_enc->hw_intf->idx - INTF_0,
  875. tc_enable, tc_cfg.start_pos, tc_cfg.rd_ptr_irq,
  876. tc_cfg.wr_ptr_irq);
  877. SDE_DEBUG_CMDENC(cmd_enc,
  878. "tc %d intf %d hw_vsync_mode %u vsync_count %u vsync_init_val %u\n",
  879. phys_enc->hw_pp->idx - PINGPONG_0,
  880. phys_enc->hw_intf->idx - INTF_0,
  881. tc_cfg.hw_vsync_mode, tc_cfg.vsync_count,
  882. tc_cfg.vsync_init_val);
  883. SDE_DEBUG_CMDENC(cmd_enc,
  884. "tc %d intf %d cfgheight %u thresh_start %u thresh_cont %u\n",
  885. phys_enc->hw_pp->idx - PINGPONG_0,
  886. phys_enc->hw_intf->idx - INTF_0,
  887. tc_cfg.sync_cfg_height,
  888. tc_cfg.sync_threshold_start, tc_cfg.sync_threshold_continue);
  889. if (phys_enc->has_intf_te) {
  890. phys_enc->hw_intf->ops.setup_tearcheck(phys_enc->hw_intf,
  891. &tc_cfg);
  892. phys_enc->hw_intf->ops.enable_tearcheck(phys_enc->hw_intf,
  893. tc_enable);
  894. } else {
  895. phys_enc->hw_pp->ops.setup_tearcheck(phys_enc->hw_pp, &tc_cfg);
  896. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  897. tc_enable);
  898. }
  899. }
  900. static void _sde_encoder_phys_cmd_pingpong_config(
  901. struct sde_encoder_phys *phys_enc)
  902. {
  903. struct sde_encoder_phys_cmd *cmd_enc =
  904. to_sde_encoder_phys_cmd(phys_enc);
  905. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp) {
  906. SDE_ERROR("invalid arg(s), enc %d\n", !phys_enc);
  907. return;
  908. }
  909. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, enabling mode:\n",
  910. phys_enc->hw_pp->idx - PINGPONG_0);
  911. drm_mode_debug_printmodeline(&phys_enc->cached_mode);
  912. if (!_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  913. _sde_encoder_phys_cmd_update_intf_cfg(phys_enc);
  914. sde_encoder_phys_cmd_tearcheck_config(phys_enc);
  915. }
  916. static void sde_encoder_phys_cmd_enable_helper(
  917. struct sde_encoder_phys *phys_enc)
  918. {
  919. struct sde_hw_intf *hw_intf;
  920. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp ||
  921. !phys_enc->hw_intf) {
  922. SDE_ERROR("invalid arg(s), encoder %d\n", !phys_enc);
  923. return;
  924. }
  925. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  926. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  927. hw_intf = phys_enc->hw_intf;
  928. if (hw_intf->ops.enable_compressed_input)
  929. hw_intf->ops.enable_compressed_input(phys_enc->hw_intf,
  930. (phys_enc->comp_type !=
  931. MSM_DISPLAY_COMPRESSION_NONE), false);
  932. if (hw_intf->ops.enable_wide_bus)
  933. hw_intf->ops.enable_wide_bus(hw_intf,
  934. sde_encoder_is_widebus_enabled(phys_enc->parent));
  935. /*
  936. * For pp-split, skip setting the flush bit for the slave intf, since
  937. * both intfs use same ctl and HW will only flush the master.
  938. */
  939. if (_sde_encoder_phys_is_ppsplit(phys_enc) &&
  940. !sde_encoder_phys_cmd_is_master(phys_enc))
  941. goto skip_flush;
  942. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  943. skip_flush:
  944. return;
  945. }
  946. static void sde_encoder_phys_cmd_enable(struct sde_encoder_phys *phys_enc)
  947. {
  948. struct sde_encoder_phys_cmd *cmd_enc =
  949. to_sde_encoder_phys_cmd(phys_enc);
  950. if (!phys_enc || !phys_enc->hw_pp) {
  951. SDE_ERROR("invalid phys encoder\n");
  952. return;
  953. }
  954. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  955. if (phys_enc->enable_state == SDE_ENC_ENABLED) {
  956. if (!phys_enc->cont_splash_enabled)
  957. SDE_ERROR("already enabled\n");
  958. return;
  959. }
  960. sde_encoder_phys_cmd_enable_helper(phys_enc);
  961. phys_enc->enable_state = SDE_ENC_ENABLED;
  962. }
  963. static bool sde_encoder_phys_cmd_is_autorefresh_enabled(
  964. struct sde_encoder_phys *phys_enc)
  965. {
  966. struct sde_hw_pingpong *hw_pp;
  967. struct sde_hw_intf *hw_intf;
  968. struct sde_hw_autorefresh cfg;
  969. int ret;
  970. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  971. return false;
  972. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  973. return false;
  974. if (phys_enc->has_intf_te) {
  975. hw_intf = phys_enc->hw_intf;
  976. if (!hw_intf->ops.get_autorefresh)
  977. return false;
  978. ret = hw_intf->ops.get_autorefresh(hw_intf, &cfg);
  979. } else {
  980. hw_pp = phys_enc->hw_pp;
  981. if (!hw_pp->ops.get_autorefresh)
  982. return false;
  983. ret = hw_pp->ops.get_autorefresh(hw_pp, &cfg);
  984. }
  985. return ret ? false : cfg.enable;
  986. }
  987. static void sde_encoder_phys_cmd_connect_te(
  988. struct sde_encoder_phys *phys_enc, bool enable)
  989. {
  990. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  991. return;
  992. if (phys_enc->has_intf_te &&
  993. phys_enc->hw_intf->ops.connect_external_te)
  994. phys_enc->hw_intf->ops.connect_external_te(phys_enc->hw_intf,
  995. enable);
  996. else if (phys_enc->hw_pp->ops.connect_external_te)
  997. phys_enc->hw_pp->ops.connect_external_te(phys_enc->hw_pp,
  998. enable);
  999. else
  1000. return;
  1001. SDE_EVT32(DRMID(phys_enc->parent), enable);
  1002. }
  1003. static int sde_encoder_phys_cmd_te_get_line_count(
  1004. struct sde_encoder_phys *phys_enc)
  1005. {
  1006. struct sde_hw_pingpong *hw_pp;
  1007. struct sde_hw_intf *hw_intf;
  1008. u32 line_count;
  1009. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  1010. return -EINVAL;
  1011. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1012. return -EINVAL;
  1013. if (phys_enc->has_intf_te) {
  1014. hw_intf = phys_enc->hw_intf;
  1015. if (!hw_intf->ops.get_line_count)
  1016. return -EINVAL;
  1017. line_count = hw_intf->ops.get_line_count(hw_intf);
  1018. } else {
  1019. hw_pp = phys_enc->hw_pp;
  1020. if (!hw_pp->ops.get_line_count)
  1021. return -EINVAL;
  1022. line_count = hw_pp->ops.get_line_count(hw_pp);
  1023. }
  1024. return line_count;
  1025. }
  1026. static void sde_encoder_phys_cmd_disable(struct sde_encoder_phys *phys_enc)
  1027. {
  1028. struct sde_encoder_phys_cmd *cmd_enc =
  1029. to_sde_encoder_phys_cmd(phys_enc);
  1030. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  1031. SDE_ERROR("invalid encoder\n");
  1032. return;
  1033. }
  1034. SDE_DEBUG_CMDENC(cmd_enc, "pp %d intf %d state %d\n",
  1035. phys_enc->hw_pp->idx - PINGPONG_0,
  1036. phys_enc->hw_intf->idx - INTF_0,
  1037. phys_enc->enable_state);
  1038. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1039. phys_enc->hw_intf->idx - INTF_0,
  1040. phys_enc->enable_state);
  1041. if (phys_enc->enable_state == SDE_ENC_DISABLED) {
  1042. SDE_ERROR_CMDENC(cmd_enc, "already disabled\n");
  1043. return;
  1044. }
  1045. if (!sde_in_trusted_vm(phys_enc->sde_kms)) {
  1046. if (phys_enc->has_intf_te &&
  1047. phys_enc->hw_intf->ops.enable_tearcheck)
  1048. phys_enc->hw_intf->ops.enable_tearcheck(
  1049. phys_enc->hw_intf,
  1050. false);
  1051. else if (phys_enc->hw_pp->ops.enable_tearcheck)
  1052. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  1053. false);
  1054. if (sde_encoder_phys_cmd_is_master(phys_enc))
  1055. sde_encoder_helper_phys_disable(phys_enc, NULL);
  1056. if (phys_enc->hw_intf->ops.reset_counter)
  1057. phys_enc->hw_intf->ops.reset_counter(phys_enc->hw_intf);
  1058. }
  1059. memset(&cmd_enc->autorefresh.cfg, 0, sizeof(struct sde_hw_autorefresh));
  1060. phys_enc->enable_state = SDE_ENC_DISABLED;
  1061. }
  1062. static void sde_encoder_phys_cmd_destroy(struct sde_encoder_phys *phys_enc)
  1063. {
  1064. struct sde_encoder_phys_cmd *cmd_enc =
  1065. to_sde_encoder_phys_cmd(phys_enc);
  1066. if (!phys_enc) {
  1067. SDE_ERROR("invalid encoder\n");
  1068. return;
  1069. }
  1070. kfree(cmd_enc);
  1071. }
  1072. static void sde_encoder_phys_cmd_get_hw_resources(
  1073. struct sde_encoder_phys *phys_enc,
  1074. struct sde_encoder_hw_resources *hw_res,
  1075. struct drm_connector_state *conn_state)
  1076. {
  1077. struct sde_encoder_phys_cmd *cmd_enc =
  1078. to_sde_encoder_phys_cmd(phys_enc);
  1079. if (!phys_enc) {
  1080. SDE_ERROR("invalid encoder\n");
  1081. return;
  1082. }
  1083. if ((phys_enc->intf_idx - INTF_0) >= INTF_MAX) {
  1084. SDE_ERROR("invalid intf idx:%d\n", phys_enc->intf_idx);
  1085. return;
  1086. }
  1087. SDE_DEBUG_CMDENC(cmd_enc, "\n");
  1088. hw_res->intfs[phys_enc->intf_idx - INTF_0] = INTF_MODE_CMD;
  1089. }
  1090. static int sde_encoder_phys_cmd_prepare_for_kickoff(
  1091. struct sde_encoder_phys *phys_enc,
  1092. struct sde_encoder_kickoff_params *params)
  1093. {
  1094. struct sde_hw_tear_check tc_cfg = {0};
  1095. struct sde_encoder_phys_cmd *cmd_enc =
  1096. to_sde_encoder_phys_cmd(phys_enc);
  1097. int ret = 0;
  1098. bool recovery_events;
  1099. if (!phys_enc || !phys_enc->hw_pp) {
  1100. SDE_ERROR("invalid encoder\n");
  1101. return -EINVAL;
  1102. }
  1103. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  1104. phys_enc->frame_trigger_mode = params->frame_trigger_mode;
  1105. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1106. atomic_read(&phys_enc->pending_kickoff_cnt),
  1107. atomic_read(&cmd_enc->autorefresh.kickoff_cnt),
  1108. phys_enc->frame_trigger_mode);
  1109. if (phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_DEFAULT) {
  1110. /*
  1111. * Mark kickoff request as outstanding. If there are more
  1112. * than one outstanding frame, then we have to wait for the
  1113. * previous frame to complete
  1114. */
  1115. ret = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1116. if (ret) {
  1117. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  1118. SDE_EVT32(DRMID(phys_enc->parent),
  1119. phys_enc->hw_pp->idx - PINGPONG_0);
  1120. SDE_ERROR("failed wait_for_idle: %d\n", ret);
  1121. }
  1122. }
  1123. if (phys_enc->recovered) {
  1124. recovery_events = sde_encoder_recovery_events_enabled(
  1125. phys_enc->parent);
  1126. if (cmd_enc->frame_tx_timeout_report_cnt && recovery_events)
  1127. sde_connector_event_notify(phys_enc->connector,
  1128. DRM_EVENT_SDE_HW_RECOVERY,
  1129. sizeof(uint8_t),
  1130. SDE_RECOVERY_SUCCESS);
  1131. cmd_enc->frame_tx_timeout_report_cnt = 0;
  1132. phys_enc->recovered = false;
  1133. }
  1134. if (sde_connector_is_qsync_updated(phys_enc->connector)) {
  1135. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(
  1136. phys_enc);
  1137. if (phys_enc->has_intf_te &&
  1138. phys_enc->hw_intf->ops.update_tearcheck)
  1139. phys_enc->hw_intf->ops.update_tearcheck(
  1140. phys_enc->hw_intf, &tc_cfg);
  1141. else if (phys_enc->hw_pp->ops.update_tearcheck)
  1142. phys_enc->hw_pp->ops.update_tearcheck(
  1143. phys_enc->hw_pp, &tc_cfg);
  1144. SDE_EVT32(DRMID(phys_enc->parent), tc_cfg.sync_threshold_start);
  1145. }
  1146. SDE_DEBUG_CMDENC(cmd_enc, "pp:%d pending_cnt %d\n",
  1147. phys_enc->hw_pp->idx - PINGPONG_0,
  1148. atomic_read(&phys_enc->pending_kickoff_cnt));
  1149. return ret;
  1150. }
  1151. static bool _sde_encoder_phys_cmd_needs_vsync_change(
  1152. struct sde_encoder_phys *phys_enc, ktime_t profile_timestamp)
  1153. {
  1154. struct sde_encoder_phys_cmd *cmd_enc;
  1155. struct sde_encoder_phys_cmd_te_timestamp *cur;
  1156. struct sde_encoder_phys_cmd_te_timestamp *prev = NULL;
  1157. ktime_t time_diff;
  1158. u64 l_bound = 0, u_bound = 0;
  1159. bool ret = false;
  1160. unsigned long lock_flags;
  1161. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1162. sde_encoder_helper_get_jitter_bounds_ns(phys_enc->parent,
  1163. &l_bound, &u_bound);
  1164. if (!l_bound || !u_bound) {
  1165. SDE_ERROR_CMDENC(cmd_enc, "invalid vsync jitter bounds\n");
  1166. return false;
  1167. }
  1168. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  1169. list_for_each_entry_reverse(cur, &cmd_enc->te_timestamp_list, list) {
  1170. if (prev && ktime_after(cur->timestamp, profile_timestamp)) {
  1171. time_diff = ktime_sub(prev->timestamp, cur->timestamp);
  1172. if ((time_diff < l_bound) || (time_diff > u_bound)) {
  1173. ret = true;
  1174. break;
  1175. }
  1176. }
  1177. prev = cur;
  1178. }
  1179. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  1180. if (ret) {
  1181. SDE_DEBUG_CMDENC(cmd_enc,
  1182. "time_diff:%llu, prev:%llu, cur:%llu, jitter:%llu/%llu\n",
  1183. time_diff, prev->timestamp, cur->timestamp,
  1184. l_bound, u_bound);
  1185. time_diff = div_s64(time_diff, 1000);
  1186. SDE_EVT32(DRMID(phys_enc->parent),
  1187. (u32) (do_div(l_bound, 1000)),
  1188. (u32) (do_div(u_bound, 1000)),
  1189. (u32) (time_diff), SDE_EVTLOG_ERROR);
  1190. }
  1191. return ret;
  1192. }
  1193. static int _sde_encoder_phys_cmd_wait_for_wr_ptr(
  1194. struct sde_encoder_phys *phys_enc)
  1195. {
  1196. struct sde_encoder_phys_cmd *cmd_enc =
  1197. to_sde_encoder_phys_cmd(phys_enc);
  1198. struct sde_encoder_wait_info wait_info = {0};
  1199. struct sde_connector *c_conn;
  1200. bool frame_pending = true;
  1201. struct sde_hw_ctl *ctl;
  1202. unsigned long lock_flags;
  1203. int ret, timeout_ms;
  1204. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->connector) {
  1205. SDE_ERROR("invalid argument(s)\n");
  1206. return -EINVAL;
  1207. }
  1208. ctl = phys_enc->hw_ctl;
  1209. c_conn = to_sde_connector(phys_enc->connector);
  1210. timeout_ms = phys_enc->kickoff_timeout_ms;
  1211. if (c_conn->lp_mode == SDE_MODE_DPMS_LP1 ||
  1212. c_conn->lp_mode == SDE_MODE_DPMS_LP2)
  1213. timeout_ms = timeout_ms * 2;
  1214. wait_info.wq = &phys_enc->pending_kickoff_wq;
  1215. wait_info.atomic_cnt = &phys_enc->pending_retire_fence_cnt;
  1216. wait_info.timeout_ms = timeout_ms;
  1217. /* slave encoder doesn't enable for ppsplit */
  1218. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  1219. return 0;
  1220. ret = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_WRPTR,
  1221. &wait_info);
  1222. if (ret == -ETIMEDOUT) {
  1223. struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
  1224. if (ctl && ctl->ops.get_start_state)
  1225. frame_pending = ctl->ops.get_start_state(ctl);
  1226. ret = (frame_pending || sde_connector_esd_status(phys_enc->connector)) ? ret : 0;
  1227. /*
  1228. * There can be few cases of ESD where CTL_START is cleared but
  1229. * wr_ptr irq doesn't come. Signaling retire fence in these
  1230. * cases to avoid freeze and dangling pending_retire_fence_cnt
  1231. */
  1232. if (!ret) {
  1233. SDE_EVT32(DRMID(phys_enc->parent),
  1234. SDE_EVTLOG_FUNC_CASE1);
  1235. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1236. atomic_add_unless(
  1237. &phys_enc->pending_retire_fence_cnt, -1, 0)) {
  1238. spin_lock_irqsave(phys_enc->enc_spinlock,
  1239. lock_flags);
  1240. phys_enc->parent_ops.handle_frame_done(
  1241. phys_enc->parent, phys_enc,
  1242. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1243. spin_unlock_irqrestore(phys_enc->enc_spinlock,
  1244. lock_flags);
  1245. }
  1246. }
  1247. }
  1248. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1249. return ret;
  1250. }
  1251. static int sde_encoder_phys_cmd_wait_for_tx_complete(
  1252. struct sde_encoder_phys *phys_enc)
  1253. {
  1254. int rc;
  1255. struct sde_encoder_phys_cmd *cmd_enc;
  1256. if (!phys_enc)
  1257. return -EINVAL;
  1258. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1259. if (!atomic_read(&phys_enc->pending_kickoff_cnt)) {
  1260. SDE_EVT32(DRMID(phys_enc->parent),
  1261. phys_enc->intf_idx - INTF_0,
  1262. phys_enc->enable_state);
  1263. return 0;
  1264. }
  1265. rc = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1266. if (rc) {
  1267. SDE_EVT32(DRMID(phys_enc->parent),
  1268. phys_enc->intf_idx - INTF_0);
  1269. SDE_ERROR("failed wait_for_idle: %d\n", rc);
  1270. }
  1271. return rc;
  1272. }
  1273. static int _sde_encoder_phys_cmd_handle_wr_ptr_timeout(
  1274. struct sde_encoder_phys *phys_enc,
  1275. ktime_t profile_timestamp)
  1276. {
  1277. struct sde_encoder_phys_cmd *cmd_enc =
  1278. to_sde_encoder_phys_cmd(phys_enc);
  1279. bool switch_te;
  1280. int ret = -ETIMEDOUT;
  1281. unsigned long lock_flags;
  1282. switch_te = _sde_encoder_phys_cmd_needs_vsync_change(
  1283. phys_enc, profile_timestamp);
  1284. SDE_EVT32(DRMID(phys_enc->parent), switch_te, SDE_EVTLOG_FUNC_ENTRY);
  1285. if (sde_connector_panel_dead(phys_enc->connector)) {
  1286. ret = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1287. } else if (switch_te) {
  1288. SDE_DEBUG_CMDENC(cmd_enc,
  1289. "wr_ptr_irq wait failed, retry with WD TE\n");
  1290. /* switch to watchdog TE and wait again */
  1291. sde_encoder_helper_switch_vsync(phys_enc->parent, true);
  1292. ret = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1293. /* switch back to default TE */
  1294. sde_encoder_helper_switch_vsync(phys_enc->parent, false);
  1295. }
  1296. /*
  1297. * Signaling the retire fence at wr_ptr timeout
  1298. * to allow the next commit and avoid device freeze.
  1299. */
  1300. if (ret == -ETIMEDOUT) {
  1301. SDE_ERROR_CMDENC(cmd_enc,
  1302. "wr_ptr_irq wait failed, switch_te:%d\n", switch_te);
  1303. SDE_EVT32(DRMID(phys_enc->parent), switch_te, SDE_EVTLOG_ERROR);
  1304. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1305. atomic_add_unless(
  1306. &phys_enc->pending_retire_fence_cnt, -1, 0)) {
  1307. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  1308. phys_enc->parent_ops.handle_frame_done(
  1309. phys_enc->parent, phys_enc,
  1310. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1311. spin_unlock_irqrestore(phys_enc->enc_spinlock,
  1312. lock_flags);
  1313. }
  1314. }
  1315. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1316. return ret;
  1317. }
  1318. static int sde_encoder_phys_cmd_wait_for_commit_done(
  1319. struct sde_encoder_phys *phys_enc)
  1320. {
  1321. int rc = 0, i, pending_cnt;
  1322. struct sde_encoder_phys_cmd *cmd_enc;
  1323. ktime_t profile_timestamp = ktime_get();
  1324. u32 scheduler_status = INVALID_CTL_STATUS;
  1325. struct sde_hw_ctl *ctl;
  1326. if (!phys_enc)
  1327. return -EINVAL;
  1328. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1329. /* only required for master controller */
  1330. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  1331. rc = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1332. if (rc == -ETIMEDOUT) {
  1333. /*
  1334. * Profile all the TE received after profile_timestamp
  1335. * and if the jitter is more, switch to watchdog TE
  1336. * and wait for wr_ptr again. Finally move back to
  1337. * default TE.
  1338. */
  1339. rc = _sde_encoder_phys_cmd_handle_wr_ptr_timeout(
  1340. phys_enc, profile_timestamp);
  1341. if (rc == -ETIMEDOUT)
  1342. goto wait_for_idle;
  1343. }
  1344. if (cmd_enc->autorefresh.cfg.enable)
  1345. rc = _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  1346. phys_enc);
  1347. ctl = phys_enc->hw_ctl;
  1348. if (ctl && ctl->ops.get_scheduler_status)
  1349. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  1350. }
  1351. /* wait for posted start or serialize trigger */
  1352. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1353. if ((pending_cnt > 1) ||
  1354. (pending_cnt && (scheduler_status & BIT(0))) ||
  1355. (!rc && phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_SERIALIZE))
  1356. goto wait_for_idle;
  1357. return rc;
  1358. wait_for_idle:
  1359. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1360. for (i = 0; i < pending_cnt; i++)
  1361. rc |= sde_encoder_wait_for_event(phys_enc->parent,
  1362. MSM_ENC_TX_COMPLETE);
  1363. if (rc) {
  1364. SDE_EVT32(DRMID(phys_enc->parent),
  1365. phys_enc->hw_pp->idx - PINGPONG_0,
  1366. phys_enc->frame_trigger_mode,
  1367. atomic_read(&phys_enc->pending_kickoff_cnt),
  1368. phys_enc->enable_state,
  1369. cmd_enc->wr_ptr_wait_success, scheduler_status, rc);
  1370. SDE_ERROR("pp:%d failed wait_for_idle: %d\n",
  1371. phys_enc->hw_pp->idx - PINGPONG_0, rc);
  1372. if (phys_enc->enable_state == SDE_ENC_ERR_NEEDS_HW_RESET)
  1373. sde_encoder_needs_hw_reset(phys_enc->parent);
  1374. }
  1375. return rc;
  1376. }
  1377. static int sde_encoder_phys_cmd_wait_for_vblank(
  1378. struct sde_encoder_phys *phys_enc)
  1379. {
  1380. int rc = 0;
  1381. struct sde_encoder_phys_cmd *cmd_enc;
  1382. struct sde_encoder_wait_info wait_info = {0};
  1383. if (!phys_enc)
  1384. return -EINVAL;
  1385. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1386. /* only required for master controller */
  1387. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1388. return rc;
  1389. wait_info.wq = &cmd_enc->pending_vblank_wq;
  1390. wait_info.atomic_cnt = &cmd_enc->pending_vblank_cnt;
  1391. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(phys_enc);
  1392. atomic_inc(&cmd_enc->pending_vblank_cnt);
  1393. rc = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_RDPTR,
  1394. &wait_info);
  1395. return rc;
  1396. }
  1397. static void sde_encoder_phys_cmd_update_split_role(
  1398. struct sde_encoder_phys *phys_enc,
  1399. enum sde_enc_split_role role)
  1400. {
  1401. struct sde_encoder_phys_cmd *cmd_enc;
  1402. enum sde_enc_split_role old_role;
  1403. bool is_ppsplit;
  1404. if (!phys_enc)
  1405. return;
  1406. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1407. old_role = phys_enc->split_role;
  1408. is_ppsplit = _sde_encoder_phys_is_ppsplit(phys_enc);
  1409. phys_enc->split_role = role;
  1410. SDE_DEBUG_CMDENC(cmd_enc, "old role %d new role %d\n",
  1411. old_role, role);
  1412. /*
  1413. * ppsplit solo needs to reprogram because intf may have swapped without
  1414. * role changing on left-only, right-only back-to-back commits
  1415. */
  1416. if (!(is_ppsplit && role == ENC_ROLE_SOLO) &&
  1417. (role == old_role || role == ENC_ROLE_SKIP))
  1418. return;
  1419. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  1420. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  1421. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  1422. }
  1423. static void _sde_encoder_autorefresh_disable_seq1(
  1424. struct sde_encoder_phys *phys_enc)
  1425. {
  1426. int trial = 0;
  1427. u32 timeout_ms = phys_enc->kickoff_timeout_ms;
  1428. struct sde_encoder_phys_cmd *cmd_enc =
  1429. to_sde_encoder_phys_cmd(phys_enc);
  1430. /*
  1431. * If autorefresh is enabled, disable it and make sure it is safe to
  1432. * proceed with current frame commit/push. Sequence fallowed is,
  1433. * 1. Disable TE & autorefresh - caller will take care of it
  1434. * 2. Poll for frame transfer ongoing to be false
  1435. * 3. Enable TE back - caller will take care of it
  1436. */
  1437. do {
  1438. udelay(AUTOREFRESH_SEQ1_POLL_TIME);
  1439. if ((trial * AUTOREFRESH_SEQ1_POLL_TIME)
  1440. > (timeout_ms * USEC_PER_MSEC)) {
  1441. SDE_ERROR_CMDENC(cmd_enc,
  1442. "disable autorefresh failed\n");
  1443. phys_enc->enable_state = SDE_ENC_ERR_NEEDS_HW_RESET;
  1444. break;
  1445. }
  1446. trial++;
  1447. } while (_sde_encoder_phys_cmd_is_ongoing_pptx(phys_enc));
  1448. }
  1449. static void _sde_encoder_autorefresh_disable_seq2(
  1450. struct sde_encoder_phys *phys_enc)
  1451. {
  1452. int trial = 0;
  1453. struct sde_hw_mdp *hw_mdp = phys_enc->hw_mdptop;
  1454. u32 autorefresh_status = 0;
  1455. struct sde_encoder_phys_cmd *cmd_enc =
  1456. to_sde_encoder_phys_cmd(phys_enc);
  1457. struct intf_tear_status tear_status;
  1458. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  1459. if (!hw_mdp->ops.get_autorefresh_status ||
  1460. !hw_intf->ops.check_and_reset_tearcheck) {
  1461. SDE_DEBUG_CMDENC(cmd_enc,
  1462. "autofresh disable seq2 not supported\n");
  1463. return;
  1464. }
  1465. /*
  1466. * If autorefresh is still enabled after sequence-1, proceed with
  1467. * below sequence-2.
  1468. * 1. Disable autorefresh config
  1469. * 2. Run in loop:
  1470. * 2.1 Poll for autorefresh to be disabled
  1471. * 2.2 Log read and write count status
  1472. * 2.3 Replace te write count with start_pos to meet trigger window
  1473. */
  1474. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1475. phys_enc->intf_idx);
  1476. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1477. autorefresh_status, SDE_EVTLOG_FUNC_CASE1);
  1478. if (!(autorefresh_status & BIT(7))) {
  1479. usleep_range(AUTOREFRESH_SEQ2_POLL_TIME,
  1480. AUTOREFRESH_SEQ2_POLL_TIME + 1);
  1481. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1482. phys_enc->intf_idx);
  1483. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1484. autorefresh_status, SDE_EVTLOG_FUNC_CASE2);
  1485. }
  1486. while (autorefresh_status & BIT(7)) {
  1487. if (!trial) {
  1488. pr_err("enc:%d autofresh status:0x%x intf:%d\n", DRMID(phys_enc->parent),
  1489. autorefresh_status, phys_enc->intf_idx - INTF_0);
  1490. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1491. }
  1492. usleep_range(AUTOREFRESH_SEQ2_POLL_TIME,
  1493. AUTOREFRESH_SEQ2_POLL_TIME + 1);
  1494. if ((trial * AUTOREFRESH_SEQ2_POLL_TIME)
  1495. > AUTOREFRESH_SEQ2_POLL_TIMEOUT) {
  1496. SDE_ERROR_CMDENC(cmd_enc,
  1497. "disable autorefresh failed\n");
  1498. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "panic");
  1499. break;
  1500. }
  1501. trial++;
  1502. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1503. phys_enc->intf_idx);
  1504. hw_intf->ops.check_and_reset_tearcheck(hw_intf, &tear_status);
  1505. pr_err("enc:%d autofresh status:0x%x intf:%d tear_read:0x%x tear_write:0x%x\n",
  1506. DRMID(phys_enc->parent), autorefresh_status, phys_enc->intf_idx - INTF_0,
  1507. tear_status.read_count, tear_status.write_count);
  1508. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1509. autorefresh_status, tear_status.read_count,
  1510. tear_status.write_count);
  1511. }
  1512. }
  1513. static void sde_encoder_phys_cmd_prepare_commit(
  1514. struct sde_encoder_phys *phys_enc)
  1515. {
  1516. struct sde_encoder_phys_cmd *cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1517. struct sde_kms *sde_kms = phys_enc->sde_kms;
  1518. if (!phys_enc || !sde_encoder_phys_cmd_is_master(phys_enc))
  1519. return;
  1520. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1521. cmd_enc->autorefresh.cfg.enable);
  1522. if (!sde_encoder_phys_cmd_is_autorefresh_enabled(phys_enc))
  1523. return;
  1524. sde_encoder_phys_cmd_connect_te(phys_enc, false);
  1525. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1526. if (sde_kms && sde_kms->catalog &&
  1527. (sde_kms->catalog->autorefresh_disable_seq == AUTOREFRESH_DISABLE_SEQ1)) {
  1528. _sde_encoder_autorefresh_disable_seq1(phys_enc);
  1529. _sde_encoder_autorefresh_disable_seq2(phys_enc);
  1530. }
  1531. sde_encoder_phys_cmd_connect_te(phys_enc, true);
  1532. SDE_DEBUG_CMDENC(cmd_enc, "autorefresh disabled successfully\n");
  1533. }
  1534. static void sde_encoder_phys_cmd_trigger_start(
  1535. struct sde_encoder_phys *phys_enc)
  1536. {
  1537. struct sde_encoder_phys_cmd *cmd_enc =
  1538. to_sde_encoder_phys_cmd(phys_enc);
  1539. u32 frame_cnt;
  1540. if (!phys_enc)
  1541. return;
  1542. /* we don't issue CTL_START when using autorefresh */
  1543. frame_cnt = _sde_encoder_phys_cmd_get_autorefresh_property(phys_enc);
  1544. if (frame_cnt) {
  1545. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, frame_cnt);
  1546. atomic_inc(&cmd_enc->autorefresh.kickoff_cnt);
  1547. } else {
  1548. sde_encoder_helper_trigger_start(phys_enc);
  1549. }
  1550. /* wr_ptr_wait_success is set true when wr_ptr arrives */
  1551. cmd_enc->wr_ptr_wait_success = false;
  1552. }
  1553. static void sde_encoder_phys_cmd_setup_vsync_source(struct sde_encoder_phys *phys_enc,
  1554. u32 vsync_source, struct msm_display_info *disp_info)
  1555. {
  1556. struct sde_encoder_virt *sde_enc;
  1557. struct sde_connector *sde_conn;
  1558. if (!phys_enc || !phys_enc->hw_intf)
  1559. return;
  1560. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1561. if (!sde_enc)
  1562. return;
  1563. sde_conn = to_sde_connector(phys_enc->connector);
  1564. if ((disp_info->is_te_using_watchdog_timer || sde_conn->panel_dead) &&
  1565. phys_enc->hw_intf->ops.setup_vsync_source) {
  1566. vsync_source = SDE_VSYNC_SOURCE_WD_TIMER_0;
  1567. phys_enc->hw_intf->ops.setup_vsync_source(phys_enc->hw_intf,
  1568. sde_enc->mode_info.frame_rate);
  1569. } else {
  1570. sde_encoder_helper_vsync_config(phys_enc, vsync_source);
  1571. }
  1572. if (phys_enc->has_intf_te && phys_enc->hw_intf->ops.vsync_sel)
  1573. phys_enc->hw_intf->ops.vsync_sel(phys_enc->hw_intf,
  1574. vsync_source);
  1575. }
  1576. void sde_encoder_phys_cmd_add_enc_to_minidump(struct sde_encoder_phys *phys_enc)
  1577. {
  1578. struct sde_encoder_phys_cmd *cmd_enc;
  1579. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1580. sde_mini_dump_add_va_region("sde_enc_phys_cmd", sizeof(*cmd_enc), cmd_enc);
  1581. }
  1582. static void sde_encoder_phys_cmd_init_ops(struct sde_encoder_phys_ops *ops)
  1583. {
  1584. ops->prepare_commit = sde_encoder_phys_cmd_prepare_commit;
  1585. ops->is_master = sde_encoder_phys_cmd_is_master;
  1586. ops->mode_set = sde_encoder_phys_cmd_mode_set;
  1587. ops->cont_splash_mode_set = sde_encoder_phys_cmd_cont_splash_mode_set;
  1588. ops->mode_fixup = sde_encoder_phys_cmd_mode_fixup;
  1589. ops->enable = sde_encoder_phys_cmd_enable;
  1590. ops->disable = sde_encoder_phys_cmd_disable;
  1591. ops->destroy = sde_encoder_phys_cmd_destroy;
  1592. ops->get_hw_resources = sde_encoder_phys_cmd_get_hw_resources;
  1593. ops->control_vblank_irq = sde_encoder_phys_cmd_control_vblank_irq;
  1594. ops->wait_for_commit_done = sde_encoder_phys_cmd_wait_for_commit_done;
  1595. ops->prepare_for_kickoff = sde_encoder_phys_cmd_prepare_for_kickoff;
  1596. ops->wait_for_tx_complete = sde_encoder_phys_cmd_wait_for_tx_complete;
  1597. ops->wait_for_vblank = sde_encoder_phys_cmd_wait_for_vblank;
  1598. ops->trigger_flush = sde_encoder_helper_trigger_flush;
  1599. ops->trigger_start = sde_encoder_phys_cmd_trigger_start;
  1600. ops->needs_single_flush = sde_encoder_phys_needs_single_flush;
  1601. ops->hw_reset = sde_encoder_helper_hw_reset;
  1602. ops->irq_control = sde_encoder_phys_cmd_irq_control;
  1603. ops->update_split_role = sde_encoder_phys_cmd_update_split_role;
  1604. ops->restore = sde_encoder_phys_cmd_enable_helper;
  1605. ops->control_te = sde_encoder_phys_cmd_connect_te;
  1606. ops->is_autorefresh_enabled =
  1607. sde_encoder_phys_cmd_is_autorefresh_enabled;
  1608. ops->get_line_count = sde_encoder_phys_cmd_te_get_line_count;
  1609. ops->wait_for_active = NULL;
  1610. ops->setup_vsync_source = sde_encoder_phys_cmd_setup_vsync_source;
  1611. ops->setup_misr = sde_encoder_helper_setup_misr;
  1612. ops->collect_misr = sde_encoder_helper_collect_misr;
  1613. ops->add_to_minidump = sde_encoder_phys_cmd_add_enc_to_minidump;
  1614. }
  1615. static inline bool sde_encoder_phys_cmd_intf_te_supported(
  1616. const struct sde_mdss_cfg *sde_cfg, enum sde_intf idx)
  1617. {
  1618. if (sde_cfg && ((idx - INTF_0) < sde_cfg->intf_count))
  1619. return test_bit(SDE_INTF_TE,
  1620. &(sde_cfg->intf[idx - INTF_0].features));
  1621. return false;
  1622. }
  1623. struct sde_encoder_phys *sde_encoder_phys_cmd_init(
  1624. struct sde_enc_phys_init_params *p)
  1625. {
  1626. struct sde_encoder_phys *phys_enc = NULL;
  1627. struct sde_encoder_phys_cmd *cmd_enc = NULL;
  1628. struct sde_hw_mdp *hw_mdp;
  1629. struct sde_encoder_irq *irq;
  1630. int i, ret = 0;
  1631. SDE_DEBUG("intf %d\n", p->intf_idx - INTF_0);
  1632. cmd_enc = kzalloc(sizeof(*cmd_enc), GFP_KERNEL);
  1633. if (!cmd_enc) {
  1634. ret = -ENOMEM;
  1635. SDE_ERROR("failed to allocate\n");
  1636. goto fail;
  1637. }
  1638. phys_enc = &cmd_enc->base;
  1639. hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
  1640. if (IS_ERR_OR_NULL(hw_mdp)) {
  1641. ret = PTR_ERR(hw_mdp);
  1642. SDE_ERROR("failed to get mdptop\n");
  1643. goto fail_mdp_init;
  1644. }
  1645. phys_enc->hw_mdptop = hw_mdp;
  1646. phys_enc->intf_idx = p->intf_idx;
  1647. phys_enc->parent = p->parent;
  1648. phys_enc->parent_ops = p->parent_ops;
  1649. phys_enc->sde_kms = p->sde_kms;
  1650. phys_enc->split_role = p->split_role;
  1651. phys_enc->intf_mode = INTF_MODE_CMD;
  1652. phys_enc->enc_spinlock = p->enc_spinlock;
  1653. phys_enc->vblank_ctl_lock = p->vblank_ctl_lock;
  1654. cmd_enc->stream_sel = 0;
  1655. phys_enc->enable_state = SDE_ENC_DISABLED;
  1656. phys_enc->kickoff_timeout_ms = DEFAULT_KICKOFF_TIMEOUT_MS;
  1657. sde_encoder_phys_cmd_init_ops(&phys_enc->ops);
  1658. phys_enc->comp_type = p->comp_type;
  1659. phys_enc->has_intf_te = sde_encoder_phys_cmd_intf_te_supported(
  1660. phys_enc->sde_kms->catalog, phys_enc->intf_idx);
  1661. for (i = 0; i < INTR_IDX_MAX; i++) {
  1662. irq = &phys_enc->irq[i];
  1663. INIT_LIST_HEAD(&irq->cb.list);
  1664. irq->irq_idx = -EINVAL;
  1665. irq->hw_idx = -EINVAL;
  1666. irq->cb.arg = phys_enc;
  1667. }
  1668. irq = &phys_enc->irq[INTR_IDX_CTL_START];
  1669. irq->name = "ctl_start";
  1670. irq->intr_type = SDE_IRQ_TYPE_CTL_START;
  1671. irq->intr_idx = INTR_IDX_CTL_START;
  1672. irq->cb.func = NULL;
  1673. irq = &phys_enc->irq[INTR_IDX_CTL_DONE];
  1674. irq->name = "ctl_done";
  1675. irq->intr_type = SDE_IRQ_TYPE_CTL_DONE;
  1676. irq->intr_idx = INTR_IDX_CTL_DONE;
  1677. irq->cb.func = sde_encoder_phys_cmd_ctl_done_irq;
  1678. irq = &phys_enc->irq[INTR_IDX_PINGPONG];
  1679. irq->name = "pp_done";
  1680. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_COMP;
  1681. irq->intr_idx = INTR_IDX_PINGPONG;
  1682. irq->cb.func = sde_encoder_phys_cmd_pp_tx_done_irq;
  1683. irq = &phys_enc->irq[INTR_IDX_RDPTR];
  1684. irq->intr_idx = INTR_IDX_RDPTR;
  1685. irq->name = "te_rd_ptr";
  1686. if (phys_enc->has_intf_te)
  1687. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_RD_PTR;
  1688. else
  1689. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_RD_PTR;
  1690. irq->cb.func = sde_encoder_phys_cmd_te_rd_ptr_irq;
  1691. irq = &phys_enc->irq[INTR_IDX_AUTOREFRESH_DONE];
  1692. irq->name = "autorefresh_done";
  1693. if (phys_enc->has_intf_te)
  1694. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_AUTO_REF;
  1695. else
  1696. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_AUTO_REF;
  1697. irq->intr_idx = INTR_IDX_AUTOREFRESH_DONE;
  1698. irq->cb.func = sde_encoder_phys_cmd_autorefresh_done_irq;
  1699. irq = &phys_enc->irq[INTR_IDX_WRPTR];
  1700. irq->intr_idx = INTR_IDX_WRPTR;
  1701. irq->name = "wr_ptr";
  1702. if (phys_enc->has_intf_te)
  1703. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_WR_PTR;
  1704. else
  1705. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_WR_PTR;
  1706. irq->cb.func = sde_encoder_phys_cmd_wr_ptr_irq;
  1707. atomic_set(&phys_enc->vblank_refcount, 0);
  1708. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  1709. atomic_set(&phys_enc->pending_retire_fence_cnt, 0);
  1710. atomic_set(&cmd_enc->pending_vblank_cnt, 0);
  1711. init_waitqueue_head(&phys_enc->pending_kickoff_wq);
  1712. init_waitqueue_head(&cmd_enc->pending_vblank_wq);
  1713. atomic_set(&cmd_enc->autorefresh.kickoff_cnt, 0);
  1714. init_waitqueue_head(&cmd_enc->autorefresh.kickoff_wq);
  1715. INIT_LIST_HEAD(&cmd_enc->te_timestamp_list);
  1716. for (i = 0; i < MAX_TE_PROFILE_COUNT; i++)
  1717. list_add(&cmd_enc->te_timestamp[i].list,
  1718. &cmd_enc->te_timestamp_list);
  1719. SDE_DEBUG_CMDENC(cmd_enc, "created\n");
  1720. return phys_enc;
  1721. fail_mdp_init:
  1722. kfree(cmd_enc);
  1723. fail:
  1724. return ERR_PTR(ret);
  1725. }