sde_encoder_phys_cmd.c 49 KB

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