sde_encoder_phys_cmd.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  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;
  527. bool recovery_events;
  528. int ret;
  529. struct sde_hw_ctl *ctl;
  530. if (!phys_enc) {
  531. SDE_ERROR("invalid encoder\n");
  532. return -EINVAL;
  533. }
  534. ctl = phys_enc->hw_ctl;
  535. if (cmd_enc->wr_ptr_wait_success &&
  536. (phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_POSTED_START) &&
  537. ctl->ops.get_scheduler_status &&
  538. (ctl->ops.get_scheduler_status(ctl) & BIT(0)) &&
  539. atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0) &&
  540. phys_enc->parent_ops.handle_frame_done) {
  541. phys_enc->parent_ops.handle_frame_done(
  542. phys_enc->parent, phys_enc,
  543. SDE_ENCODER_FRAME_EVENT_DONE |
  544. SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE);
  545. return 0;
  546. }
  547. wait_info.wq = &phys_enc->pending_kickoff_wq;
  548. wait_info.atomic_cnt = &phys_enc->pending_kickoff_cnt;
  549. wait_info.timeout_ms = KICKOFF_TIMEOUT_MS;
  550. recovery_events = sde_encoder_recovery_events_enabled(
  551. phys_enc->parent);
  552. /* slave encoder doesn't enable for ppsplit */
  553. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  554. return 0;
  555. ret = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_PINGPONG,
  556. &wait_info);
  557. if (ret == -ETIMEDOUT) {
  558. _sde_encoder_phys_cmd_handle_ppdone_timeout(phys_enc,
  559. recovery_events);
  560. } else if (!ret) {
  561. if (cmd_enc->pp_timeout_report_cnt && recovery_events) {
  562. struct drm_connector *conn = phys_enc->connector;
  563. sde_connector_event_notify(conn,
  564. DRM_EVENT_SDE_HW_RECOVERY,
  565. sizeof(uint8_t),
  566. SDE_RECOVERY_SUCCESS);
  567. }
  568. cmd_enc->pp_timeout_report_cnt = 0;
  569. }
  570. return ret;
  571. }
  572. static int _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  573. struct sde_encoder_phys *phys_enc)
  574. {
  575. struct sde_encoder_phys_cmd *cmd_enc =
  576. to_sde_encoder_phys_cmd(phys_enc);
  577. struct sde_encoder_wait_info wait_info;
  578. int ret = 0;
  579. if (!phys_enc) {
  580. SDE_ERROR("invalid encoder\n");
  581. return -EINVAL;
  582. }
  583. /* only master deals with autorefresh */
  584. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  585. return 0;
  586. wait_info.wq = &cmd_enc->autorefresh.kickoff_wq;
  587. wait_info.atomic_cnt = &cmd_enc->autorefresh.kickoff_cnt;
  588. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(cmd_enc);
  589. /* wait for autorefresh kickoff to start */
  590. ret = sde_encoder_helper_wait_for_irq(phys_enc,
  591. INTR_IDX_AUTOREFRESH_DONE, &wait_info);
  592. /* double check that kickoff has started by reading write ptr reg */
  593. if (!ret)
  594. ret = _sde_encoder_phys_cmd_poll_write_pointer_started(
  595. phys_enc);
  596. else
  597. sde_encoder_helper_report_irq_timeout(phys_enc,
  598. INTR_IDX_AUTOREFRESH_DONE);
  599. return ret;
  600. }
  601. static int sde_encoder_phys_cmd_control_vblank_irq(
  602. struct sde_encoder_phys *phys_enc,
  603. bool enable)
  604. {
  605. struct sde_encoder_phys_cmd *cmd_enc =
  606. to_sde_encoder_phys_cmd(phys_enc);
  607. int ret = 0;
  608. int refcount;
  609. if (!phys_enc || !phys_enc->hw_pp) {
  610. SDE_ERROR("invalid encoder\n");
  611. return -EINVAL;
  612. }
  613. mutex_lock(phys_enc->vblank_ctl_lock);
  614. refcount = atomic_read(&phys_enc->vblank_refcount);
  615. /* Slave encoders don't report vblank */
  616. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  617. goto end;
  618. /* protect against negative */
  619. if (!enable && refcount == 0) {
  620. ret = -EINVAL;
  621. goto end;
  622. }
  623. SDE_DEBUG_CMDENC(cmd_enc, "[%pS] enable=%d/%d\n",
  624. __builtin_return_address(0), enable, refcount);
  625. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  626. enable, refcount);
  627. if (enable && atomic_inc_return(&phys_enc->vblank_refcount) == 1)
  628. ret = sde_encoder_helper_register_irq(phys_enc, INTR_IDX_RDPTR);
  629. else if (!enable && atomic_dec_return(&phys_enc->vblank_refcount) == 0)
  630. ret = sde_encoder_helper_unregister_irq(phys_enc,
  631. INTR_IDX_RDPTR);
  632. end:
  633. if (ret) {
  634. SDE_ERROR_CMDENC(cmd_enc,
  635. "control vblank irq error %d, enable %d, refcount %d\n",
  636. ret, enable, refcount);
  637. SDE_EVT32(DRMID(phys_enc->parent),
  638. phys_enc->hw_pp->idx - PINGPONG_0,
  639. enable, refcount, SDE_EVTLOG_ERROR);
  640. }
  641. mutex_unlock(phys_enc->vblank_ctl_lock);
  642. return ret;
  643. }
  644. void sde_encoder_phys_cmd_irq_control(struct sde_encoder_phys *phys_enc,
  645. bool enable)
  646. {
  647. struct sde_encoder_phys_cmd *cmd_enc;
  648. if (!phys_enc)
  649. return;
  650. /**
  651. * pingpong split slaves do not register for IRQs
  652. * check old and new topologies
  653. */
  654. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc) ||
  655. _sde_encoder_phys_is_disabling_ppsplit_slave(phys_enc))
  656. return;
  657. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  658. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  659. enable, atomic_read(&phys_enc->vblank_refcount));
  660. if (enable) {
  661. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_PINGPONG);
  662. sde_encoder_phys_cmd_control_vblank_irq(phys_enc, true);
  663. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  664. sde_encoder_helper_register_irq(phys_enc,
  665. INTR_IDX_WRPTR);
  666. sde_encoder_helper_register_irq(phys_enc,
  667. INTR_IDX_AUTOREFRESH_DONE);
  668. }
  669. } else {
  670. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  671. sde_encoder_helper_unregister_irq(phys_enc,
  672. INTR_IDX_WRPTR);
  673. sde_encoder_helper_unregister_irq(phys_enc,
  674. INTR_IDX_AUTOREFRESH_DONE);
  675. }
  676. sde_encoder_phys_cmd_control_vblank_irq(phys_enc, false);
  677. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_PINGPONG);
  678. }
  679. }
  680. static int _get_tearcheck_threshold(struct sde_encoder_phys *phys_enc,
  681. u32 *extra_frame_trigger_time)
  682. {
  683. struct drm_connector *conn = phys_enc->connector;
  684. u32 qsync_mode;
  685. struct drm_display_mode *mode;
  686. u32 threshold_lines = 0;
  687. struct sde_encoder_phys_cmd *cmd_enc =
  688. to_sde_encoder_phys_cmd(phys_enc);
  689. *extra_frame_trigger_time = 0;
  690. if (!conn || !conn->state)
  691. return 0;
  692. mode = &phys_enc->cached_mode;
  693. qsync_mode = sde_connector_get_qsync_mode(conn);
  694. if (mode && (qsync_mode == SDE_RM_QSYNC_CONTINUOUS_MODE)) {
  695. u32 qsync_min_fps = 0;
  696. u32 default_fps = mode->vrefresh;
  697. u32 yres = mode->vtotal;
  698. u32 slow_time_ns;
  699. u32 default_time_ns;
  700. u32 extra_time_ns;
  701. u32 total_extra_lines;
  702. u32 default_line_time_ns;
  703. if (phys_enc->parent_ops.get_qsync_fps)
  704. phys_enc->parent_ops.get_qsync_fps(
  705. phys_enc->parent, &qsync_min_fps);
  706. if (!qsync_min_fps || !default_fps || !yres) {
  707. SDE_ERROR_CMDENC(cmd_enc,
  708. "wrong qsync params %d %d %d\n",
  709. qsync_min_fps, default_fps, yres);
  710. goto exit;
  711. }
  712. if (qsync_min_fps >= default_fps) {
  713. SDE_ERROR_CMDENC(cmd_enc,
  714. "qsync fps:%d must be less than default:%d\n",
  715. qsync_min_fps, default_fps);
  716. goto exit;
  717. }
  718. /* Calculate the number of extra lines*/
  719. slow_time_ns = (1 * 1000000000) / qsync_min_fps;
  720. default_time_ns = (1 * 1000000000) / default_fps;
  721. extra_time_ns = slow_time_ns - default_time_ns;
  722. default_line_time_ns = (1 * 1000000000) / (default_fps * yres);
  723. total_extra_lines = extra_time_ns / default_line_time_ns;
  724. threshold_lines += total_extra_lines;
  725. SDE_DEBUG_CMDENC(cmd_enc, "slow:%d default:%d extra:%d(ns)\n",
  726. slow_time_ns, default_time_ns, extra_time_ns);
  727. SDE_DEBUG_CMDENC(cmd_enc, "extra_lines:%d threshold:%d\n",
  728. total_extra_lines, threshold_lines);
  729. SDE_DEBUG_CMDENC(cmd_enc, "min_fps:%d fps:%d yres:%d\n",
  730. qsync_min_fps, default_fps, yres);
  731. SDE_EVT32(qsync_mode, qsync_min_fps, extra_time_ns, default_fps,
  732. yres, threshold_lines);
  733. *extra_frame_trigger_time = extra_time_ns;
  734. }
  735. exit:
  736. threshold_lines += DEFAULT_TEARCHECK_SYNC_THRESH_START;
  737. return threshold_lines;
  738. }
  739. static void sde_encoder_phys_cmd_tearcheck_config(
  740. struct sde_encoder_phys *phys_enc)
  741. {
  742. struct sde_encoder_phys_cmd *cmd_enc =
  743. to_sde_encoder_phys_cmd(phys_enc);
  744. struct sde_hw_tear_check tc_cfg = { 0 };
  745. struct drm_display_mode *mode;
  746. bool tc_enable = true;
  747. u32 vsync_hz, extra_frame_trigger_time;
  748. struct msm_drm_private *priv;
  749. struct sde_kms *sde_kms;
  750. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  751. SDE_ERROR("invalid encoder\n");
  752. return;
  753. }
  754. mode = &phys_enc->cached_mode;
  755. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, intf %d\n",
  756. phys_enc->hw_pp->idx - PINGPONG_0,
  757. phys_enc->hw_intf->idx - INTF_0);
  758. if (phys_enc->has_intf_te) {
  759. if (!phys_enc->hw_intf->ops.setup_tearcheck ||
  760. !phys_enc->hw_intf->ops.enable_tearcheck) {
  761. SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
  762. return;
  763. }
  764. } else {
  765. if (!phys_enc->hw_pp->ops.setup_tearcheck ||
  766. !phys_enc->hw_pp->ops.enable_tearcheck) {
  767. SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
  768. return;
  769. }
  770. }
  771. sde_kms = phys_enc->sde_kms;
  772. if (!sde_kms || !sde_kms->dev || !sde_kms->dev->dev_private) {
  773. SDE_ERROR("invalid device\n");
  774. return;
  775. }
  776. priv = sde_kms->dev->dev_private;
  777. /*
  778. * TE default: dsi byte clock calculated base on 70 fps;
  779. * around 14 ms to complete a kickoff cycle if te disabled;
  780. * vclk_line base on 60 fps; write is faster than read;
  781. * init == start == rdptr;
  782. *
  783. * vsync_count is ratio of MDP VSYNC clock frequency to LCD panel
  784. * frequency divided by the no. of rows (lines) in the LCDpanel.
  785. */
  786. vsync_hz = sde_power_clk_get_rate(&priv->phandle, "vsync_clk");
  787. if (!vsync_hz || !mode->vtotal || !mode->vrefresh) {
  788. SDE_DEBUG_CMDENC(cmd_enc,
  789. "invalid params - vsync_hz %u vtot %u vrefresh %u\n",
  790. vsync_hz, mode->vtotal, mode->vrefresh);
  791. return;
  792. }
  793. tc_cfg.vsync_count = vsync_hz / (mode->vtotal * mode->vrefresh);
  794. /* enable external TE after kickoff to avoid premature autorefresh */
  795. tc_cfg.hw_vsync_mode = 0;
  796. /*
  797. * By setting sync_cfg_height to near max register value, we essentially
  798. * disable sde hw generated TE signal, since hw TE will arrive first.
  799. * Only caveat is if due to error, we hit wrap-around.
  800. */
  801. tc_cfg.sync_cfg_height = 0xFFF0;
  802. tc_cfg.vsync_init_val = mode->vdisplay;
  803. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(phys_enc,
  804. &extra_frame_trigger_time);
  805. tc_cfg.sync_threshold_continue = DEFAULT_TEARCHECK_SYNC_THRESH_CONTINUE;
  806. tc_cfg.start_pos = mode->vdisplay;
  807. tc_cfg.rd_ptr_irq = mode->vdisplay + 1;
  808. tc_cfg.wr_ptr_irq = 1;
  809. SDE_DEBUG_CMDENC(cmd_enc,
  810. "tc %d intf %d vsync_clk_speed_hz %u vtotal %u vrefresh %u\n",
  811. phys_enc->hw_pp->idx - PINGPONG_0,
  812. phys_enc->hw_intf->idx - INTF_0,
  813. vsync_hz, mode->vtotal, mode->vrefresh);
  814. SDE_DEBUG_CMDENC(cmd_enc,
  815. "tc %d intf %d enable %u start_pos %u rd_ptr_irq %u wr_ptr_irq %u\n",
  816. phys_enc->hw_pp->idx - PINGPONG_0,
  817. phys_enc->hw_intf->idx - INTF_0,
  818. tc_enable, tc_cfg.start_pos, tc_cfg.rd_ptr_irq,
  819. tc_cfg.wr_ptr_irq);
  820. SDE_DEBUG_CMDENC(cmd_enc,
  821. "tc %d intf %d hw_vsync_mode %u vsync_count %u vsync_init_val %u\n",
  822. phys_enc->hw_pp->idx - PINGPONG_0,
  823. phys_enc->hw_intf->idx - INTF_0,
  824. tc_cfg.hw_vsync_mode, tc_cfg.vsync_count,
  825. tc_cfg.vsync_init_val);
  826. SDE_DEBUG_CMDENC(cmd_enc,
  827. "tc %d intf %d cfgheight %u thresh_start %u thresh_cont %u\n",
  828. phys_enc->hw_pp->idx - PINGPONG_0,
  829. phys_enc->hw_intf->idx - INTF_0,
  830. tc_cfg.sync_cfg_height,
  831. tc_cfg.sync_threshold_start, tc_cfg.sync_threshold_continue);
  832. if (phys_enc->has_intf_te) {
  833. phys_enc->hw_intf->ops.setup_tearcheck(phys_enc->hw_intf,
  834. &tc_cfg);
  835. phys_enc->hw_intf->ops.enable_tearcheck(phys_enc->hw_intf,
  836. tc_enable);
  837. } else {
  838. phys_enc->hw_pp->ops.setup_tearcheck(phys_enc->hw_pp, &tc_cfg);
  839. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  840. tc_enable);
  841. }
  842. }
  843. static void _sde_encoder_phys_cmd_pingpong_config(
  844. struct sde_encoder_phys *phys_enc)
  845. {
  846. struct sde_encoder_phys_cmd *cmd_enc =
  847. to_sde_encoder_phys_cmd(phys_enc);
  848. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp) {
  849. SDE_ERROR("invalid arg(s), enc %d\n", !phys_enc);
  850. return;
  851. }
  852. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, enabling mode:\n",
  853. phys_enc->hw_pp->idx - PINGPONG_0);
  854. drm_mode_debug_printmodeline(&phys_enc->cached_mode);
  855. if (!_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  856. _sde_encoder_phys_cmd_update_intf_cfg(phys_enc);
  857. sde_encoder_phys_cmd_tearcheck_config(phys_enc);
  858. }
  859. static void sde_encoder_phys_cmd_enable_helper(
  860. struct sde_encoder_phys *phys_enc)
  861. {
  862. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp) {
  863. SDE_ERROR("invalid arg(s), encoder %d\n", !phys_enc);
  864. return;
  865. }
  866. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  867. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  868. /*
  869. * For pp-split, skip setting the flush bit for the slave intf, since
  870. * both intfs use same ctl and HW will only flush the master.
  871. */
  872. if (_sde_encoder_phys_is_ppsplit(phys_enc) &&
  873. !sde_encoder_phys_cmd_is_master(phys_enc))
  874. goto skip_flush;
  875. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  876. skip_flush:
  877. return;
  878. }
  879. static void sde_encoder_phys_cmd_enable(struct sde_encoder_phys *phys_enc)
  880. {
  881. struct sde_encoder_phys_cmd *cmd_enc =
  882. to_sde_encoder_phys_cmd(phys_enc);
  883. if (!phys_enc || !phys_enc->hw_pp) {
  884. SDE_ERROR("invalid phys encoder\n");
  885. return;
  886. }
  887. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  888. if (phys_enc->enable_state == SDE_ENC_ENABLED) {
  889. if (!phys_enc->cont_splash_enabled)
  890. SDE_ERROR("already enabled\n");
  891. return;
  892. }
  893. sde_encoder_phys_cmd_enable_helper(phys_enc);
  894. phys_enc->enable_state = SDE_ENC_ENABLED;
  895. }
  896. static bool sde_encoder_phys_cmd_is_autorefresh_enabled(
  897. struct sde_encoder_phys *phys_enc)
  898. {
  899. struct sde_hw_pingpong *hw_pp;
  900. struct sde_hw_intf *hw_intf;
  901. struct sde_hw_autorefresh cfg;
  902. int ret;
  903. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  904. return false;
  905. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  906. return false;
  907. if (phys_enc->has_intf_te) {
  908. hw_intf = phys_enc->hw_intf;
  909. if (!hw_intf->ops.get_autorefresh)
  910. return false;
  911. ret = hw_intf->ops.get_autorefresh(hw_intf, &cfg);
  912. } else {
  913. hw_pp = phys_enc->hw_pp;
  914. if (!hw_pp->ops.get_autorefresh)
  915. return false;
  916. ret = hw_pp->ops.get_autorefresh(hw_pp, &cfg);
  917. }
  918. if (ret)
  919. return false;
  920. return cfg.enable;
  921. }
  922. static void sde_encoder_phys_cmd_connect_te(
  923. struct sde_encoder_phys *phys_enc, bool enable)
  924. {
  925. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  926. return;
  927. if (phys_enc->has_intf_te &&
  928. phys_enc->hw_intf->ops.connect_external_te)
  929. phys_enc->hw_intf->ops.connect_external_te(phys_enc->hw_intf,
  930. enable);
  931. else if (phys_enc->hw_pp->ops.connect_external_te)
  932. phys_enc->hw_pp->ops.connect_external_te(phys_enc->hw_pp,
  933. enable);
  934. else
  935. return;
  936. SDE_EVT32(DRMID(phys_enc->parent), enable);
  937. }
  938. static int sde_encoder_phys_cmd_te_get_line_count(
  939. struct sde_encoder_phys *phys_enc)
  940. {
  941. struct sde_hw_pingpong *hw_pp;
  942. struct sde_hw_intf *hw_intf;
  943. u32 line_count;
  944. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  945. return -EINVAL;
  946. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  947. return -EINVAL;
  948. if (phys_enc->has_intf_te) {
  949. hw_intf = phys_enc->hw_intf;
  950. if (!hw_intf->ops.get_line_count)
  951. return -EINVAL;
  952. line_count = hw_intf->ops.get_line_count(hw_intf);
  953. } else {
  954. hw_pp = phys_enc->hw_pp;
  955. if (!hw_pp->ops.get_line_count)
  956. return -EINVAL;
  957. line_count = hw_pp->ops.get_line_count(hw_pp);
  958. }
  959. return line_count;
  960. }
  961. static int sde_encoder_phys_cmd_get_write_line_count(
  962. struct sde_encoder_phys *phys_enc)
  963. {
  964. struct sde_hw_pingpong *hw_pp;
  965. struct sde_hw_intf *hw_intf;
  966. struct sde_hw_pp_vsync_info info;
  967. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  968. return -EINVAL;
  969. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  970. return -EINVAL;
  971. if (phys_enc->has_intf_te) {
  972. hw_intf = phys_enc->hw_intf;
  973. if (!hw_intf->ops.get_vsync_info)
  974. return -EINVAL;
  975. if (hw_intf->ops.get_vsync_info(hw_intf, &info))
  976. return -EINVAL;
  977. } else {
  978. hw_pp = phys_enc->hw_pp;
  979. if (!hw_pp->ops.get_vsync_info)
  980. return -EINVAL;
  981. if (hw_pp->ops.get_vsync_info(hw_pp, &info))
  982. return -EINVAL;
  983. }
  984. return (int)info.wr_ptr_line_count;
  985. }
  986. static void sde_encoder_phys_cmd_disable(struct sde_encoder_phys *phys_enc)
  987. {
  988. struct sde_encoder_phys_cmd *cmd_enc =
  989. to_sde_encoder_phys_cmd(phys_enc);
  990. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  991. SDE_ERROR("invalid encoder\n");
  992. return;
  993. }
  994. SDE_DEBUG_CMDENC(cmd_enc, "pp %d intf %d state %d\n",
  995. phys_enc->hw_pp->idx - PINGPONG_0,
  996. phys_enc->hw_intf->idx - INTF_0,
  997. phys_enc->enable_state);
  998. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  999. phys_enc->hw_intf->idx - INTF_0,
  1000. phys_enc->enable_state);
  1001. if (phys_enc->enable_state == SDE_ENC_DISABLED) {
  1002. SDE_ERROR_CMDENC(cmd_enc, "already disabled\n");
  1003. return;
  1004. }
  1005. if (phys_enc->has_intf_te && phys_enc->hw_intf->ops.enable_tearcheck)
  1006. phys_enc->hw_intf->ops.enable_tearcheck(
  1007. phys_enc->hw_intf,
  1008. false);
  1009. else if (phys_enc->hw_pp->ops.enable_tearcheck)
  1010. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  1011. false);
  1012. phys_enc->enable_state = SDE_ENC_DISABLED;
  1013. }
  1014. static void sde_encoder_phys_cmd_destroy(struct sde_encoder_phys *phys_enc)
  1015. {
  1016. struct sde_encoder_phys_cmd *cmd_enc =
  1017. to_sde_encoder_phys_cmd(phys_enc);
  1018. if (!phys_enc) {
  1019. SDE_ERROR("invalid encoder\n");
  1020. return;
  1021. }
  1022. kfree(cmd_enc);
  1023. }
  1024. static void sde_encoder_phys_cmd_get_hw_resources(
  1025. struct sde_encoder_phys *phys_enc,
  1026. struct sde_encoder_hw_resources *hw_res,
  1027. struct drm_connector_state *conn_state)
  1028. {
  1029. struct sde_encoder_phys_cmd *cmd_enc =
  1030. to_sde_encoder_phys_cmd(phys_enc);
  1031. if (!phys_enc) {
  1032. SDE_ERROR("invalid encoder\n");
  1033. return;
  1034. }
  1035. if ((phys_enc->intf_idx - INTF_0) >= INTF_MAX) {
  1036. SDE_ERROR("invalid intf idx:%d\n", phys_enc->intf_idx);
  1037. return;
  1038. }
  1039. SDE_DEBUG_CMDENC(cmd_enc, "\n");
  1040. hw_res->intfs[phys_enc->intf_idx - INTF_0] = INTF_MODE_CMD;
  1041. }
  1042. static int sde_encoder_phys_cmd_prepare_for_kickoff(
  1043. struct sde_encoder_phys *phys_enc,
  1044. struct sde_encoder_kickoff_params *params)
  1045. {
  1046. struct sde_hw_tear_check tc_cfg = {0};
  1047. struct sde_encoder_phys_cmd *cmd_enc =
  1048. to_sde_encoder_phys_cmd(phys_enc);
  1049. int ret = 0;
  1050. u32 extra_frame_trigger_time;
  1051. if (!phys_enc || !phys_enc->hw_pp) {
  1052. SDE_ERROR("invalid encoder\n");
  1053. return -EINVAL;
  1054. }
  1055. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  1056. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1057. atomic_read(&phys_enc->pending_kickoff_cnt),
  1058. atomic_read(&cmd_enc->autorefresh.kickoff_cnt));
  1059. phys_enc->frame_trigger_mode = params->frame_trigger_mode;
  1060. if (phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_DEFAULT) {
  1061. /*
  1062. * Mark kickoff request as outstanding. If there are more
  1063. * than one outstanding frame, then we have to wait for the
  1064. * previous frame to complete
  1065. */
  1066. ret = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1067. if (ret) {
  1068. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  1069. SDE_EVT32(DRMID(phys_enc->parent),
  1070. phys_enc->hw_pp->idx - PINGPONG_0);
  1071. SDE_ERROR("failed wait_for_idle: %d\n", ret);
  1072. }
  1073. }
  1074. if (sde_connector_is_qsync_updated(phys_enc->connector)) {
  1075. tc_cfg.sync_threshold_start =
  1076. _get_tearcheck_threshold(phys_enc,
  1077. &extra_frame_trigger_time);
  1078. if (phys_enc->has_intf_te &&
  1079. phys_enc->hw_intf->ops.update_tearcheck)
  1080. phys_enc->hw_intf->ops.update_tearcheck(
  1081. phys_enc->hw_intf, &tc_cfg);
  1082. else if (phys_enc->hw_pp->ops.update_tearcheck)
  1083. phys_enc->hw_pp->ops.update_tearcheck(
  1084. phys_enc->hw_pp, &tc_cfg);
  1085. SDE_EVT32(DRMID(phys_enc->parent), tc_cfg.sync_threshold_start);
  1086. }
  1087. SDE_DEBUG_CMDENC(cmd_enc, "pp:%d pending_cnt %d\n",
  1088. phys_enc->hw_pp->idx - PINGPONG_0,
  1089. atomic_read(&phys_enc->pending_kickoff_cnt));
  1090. return ret;
  1091. }
  1092. static int _sde_encoder_phys_cmd_wait_for_wr_ptr(
  1093. struct sde_encoder_phys *phys_enc)
  1094. {
  1095. struct sde_encoder_phys_cmd *cmd_enc =
  1096. to_sde_encoder_phys_cmd(phys_enc);
  1097. struct sde_encoder_wait_info wait_info;
  1098. int ret;
  1099. bool frame_pending = true;
  1100. struct sde_hw_ctl *ctl;
  1101. if (!phys_enc || !phys_enc->hw_ctl) {
  1102. SDE_ERROR("invalid argument(s)\n");
  1103. return -EINVAL;
  1104. }
  1105. ctl = phys_enc->hw_ctl;
  1106. wait_info.wq = &phys_enc->pending_kickoff_wq;
  1107. wait_info.atomic_cnt = &phys_enc->pending_retire_fence_cnt;
  1108. wait_info.timeout_ms = KICKOFF_TIMEOUT_MS;
  1109. /* slave encoder doesn't enable for ppsplit */
  1110. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  1111. return 0;
  1112. ret = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_WRPTR,
  1113. &wait_info);
  1114. if (ret == -ETIMEDOUT) {
  1115. struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
  1116. if (ctl && ctl->ops.get_start_state)
  1117. frame_pending = ctl->ops.get_start_state(ctl);
  1118. if (frame_pending)
  1119. SDE_ERROR_CMDENC(cmd_enc,
  1120. "wr_ptrt start interrupt wait failed\n");
  1121. else
  1122. ret = 0;
  1123. /*
  1124. * Signaling the retire fence at wr_ptr timeout
  1125. * to allow the next commit and avoid device freeze.
  1126. * As wr_ptr timeout can occurs due to no read ptr,
  1127. * updating pending_rd_ptr_cnt here may not cover all
  1128. * cases. Hence signaling the retire fence.
  1129. */
  1130. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1131. atomic_add_unless(&phys_enc->pending_retire_fence_cnt,
  1132. -1, 0))
  1133. phys_enc->parent_ops.handle_frame_done(
  1134. phys_enc->parent, phys_enc,
  1135. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1136. }
  1137. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1138. return ret;
  1139. }
  1140. static int sde_encoder_phys_cmd_wait_for_tx_complete(
  1141. struct sde_encoder_phys *phys_enc)
  1142. {
  1143. int rc;
  1144. struct sde_encoder_phys_cmd *cmd_enc;
  1145. if (!phys_enc)
  1146. return -EINVAL;
  1147. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1148. rc = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1149. if (rc) {
  1150. SDE_EVT32(DRMID(phys_enc->parent),
  1151. phys_enc->intf_idx - INTF_0);
  1152. SDE_ERROR("failed wait_for_idle: %d\n", rc);
  1153. }
  1154. return rc;
  1155. }
  1156. static int sde_encoder_phys_cmd_wait_for_commit_done(
  1157. struct sde_encoder_phys *phys_enc)
  1158. {
  1159. int rc = 0, i, pending_cnt;
  1160. struct sde_encoder_phys_cmd *cmd_enc;
  1161. if (!phys_enc)
  1162. return -EINVAL;
  1163. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1164. /* only required for master controller */
  1165. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  1166. rc = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1167. if (rc == -ETIMEDOUT)
  1168. goto wait_for_idle;
  1169. if (cmd_enc->autorefresh.cfg.enable)
  1170. rc = _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  1171. phys_enc);
  1172. }
  1173. /* wait for posted start or serialize trigger */
  1174. if ((atomic_read(&phys_enc->pending_kickoff_cnt) > 1) ||
  1175. (!rc && phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_SERIALIZE))
  1176. goto wait_for_idle;
  1177. return rc;
  1178. wait_for_idle:
  1179. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1180. for (i = 0; i < pending_cnt; i++)
  1181. rc |= sde_encoder_wait_for_event(phys_enc->parent,
  1182. MSM_ENC_TX_COMPLETE);
  1183. if (rc) {
  1184. SDE_EVT32(DRMID(phys_enc->parent),
  1185. phys_enc->hw_pp->idx - PINGPONG_0,
  1186. phys_enc->frame_trigger_mode,
  1187. atomic_read(&phys_enc->pending_kickoff_cnt),
  1188. phys_enc->enable_state, rc);
  1189. SDE_ERROR("pp:%d failed wait_for_idle: %d\n",
  1190. phys_enc->hw_pp->idx - PINGPONG_0, rc);
  1191. if (phys_enc->enable_state == SDE_ENC_ERR_NEEDS_HW_RESET)
  1192. sde_encoder_helper_needs_hw_reset(phys_enc->parent);
  1193. }
  1194. return rc;
  1195. }
  1196. static int sde_encoder_phys_cmd_wait_for_vblank(
  1197. struct sde_encoder_phys *phys_enc)
  1198. {
  1199. int rc = 0;
  1200. struct sde_encoder_phys_cmd *cmd_enc;
  1201. struct sde_encoder_wait_info wait_info;
  1202. if (!phys_enc)
  1203. return -EINVAL;
  1204. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1205. /* only required for master controller */
  1206. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1207. return rc;
  1208. wait_info.wq = &cmd_enc->pending_vblank_wq;
  1209. wait_info.atomic_cnt = &cmd_enc->pending_vblank_cnt;
  1210. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(cmd_enc);
  1211. atomic_inc(&cmd_enc->pending_vblank_cnt);
  1212. rc = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_RDPTR,
  1213. &wait_info);
  1214. return rc;
  1215. }
  1216. static void sde_encoder_phys_cmd_update_split_role(
  1217. struct sde_encoder_phys *phys_enc,
  1218. enum sde_enc_split_role role)
  1219. {
  1220. struct sde_encoder_phys_cmd *cmd_enc;
  1221. enum sde_enc_split_role old_role;
  1222. bool is_ppsplit;
  1223. if (!phys_enc)
  1224. return;
  1225. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1226. old_role = phys_enc->split_role;
  1227. is_ppsplit = _sde_encoder_phys_is_ppsplit(phys_enc);
  1228. phys_enc->split_role = role;
  1229. SDE_DEBUG_CMDENC(cmd_enc, "old role %d new role %d\n",
  1230. old_role, role);
  1231. /*
  1232. * ppsplit solo needs to reprogram because intf may have swapped without
  1233. * role changing on left-only, right-only back-to-back commits
  1234. */
  1235. if (!(is_ppsplit && role == ENC_ROLE_SOLO) &&
  1236. (role == old_role || role == ENC_ROLE_SKIP))
  1237. return;
  1238. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  1239. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  1240. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  1241. }
  1242. static void sde_encoder_phys_cmd_prepare_commit(
  1243. struct sde_encoder_phys *phys_enc)
  1244. {
  1245. struct sde_encoder_phys_cmd *cmd_enc =
  1246. to_sde_encoder_phys_cmd(phys_enc);
  1247. int trial = 0;
  1248. if (!phys_enc)
  1249. return;
  1250. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1251. return;
  1252. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1253. cmd_enc->autorefresh.cfg.enable);
  1254. if (!sde_encoder_phys_cmd_is_autorefresh_enabled(phys_enc))
  1255. return;
  1256. /*
  1257. * If autorefresh is enabled, disable it and make sure it is safe to
  1258. * proceed with current frame commit/push. Sequence fallowed is,
  1259. * 1. Disable TE
  1260. * 2. Disable autorefresh config
  1261. * 4. Poll for frame transfer ongoing to be false
  1262. * 5. Enable TE back
  1263. */
  1264. sde_encoder_phys_cmd_connect_te(phys_enc, false);
  1265. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1266. do {
  1267. udelay(SDE_ENC_MAX_POLL_TIMEOUT_US);
  1268. if ((trial * SDE_ENC_MAX_POLL_TIMEOUT_US)
  1269. > (KICKOFF_TIMEOUT_MS * USEC_PER_MSEC)) {
  1270. SDE_ERROR_CMDENC(cmd_enc,
  1271. "disable autorefresh failed\n");
  1272. break;
  1273. }
  1274. trial++;
  1275. } while (_sde_encoder_phys_cmd_is_ongoing_pptx(phys_enc));
  1276. sde_encoder_phys_cmd_connect_te(phys_enc, true);
  1277. SDE_DEBUG_CMDENC(cmd_enc, "disabled autorefresh\n");
  1278. }
  1279. static void sde_encoder_phys_cmd_trigger_start(
  1280. struct sde_encoder_phys *phys_enc)
  1281. {
  1282. struct sde_encoder_phys_cmd *cmd_enc =
  1283. to_sde_encoder_phys_cmd(phys_enc);
  1284. u32 frame_cnt;
  1285. if (!phys_enc)
  1286. return;
  1287. /* we don't issue CTL_START when using autorefresh */
  1288. frame_cnt = _sde_encoder_phys_cmd_get_autorefresh_property(phys_enc);
  1289. if (frame_cnt) {
  1290. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, frame_cnt);
  1291. atomic_inc(&cmd_enc->autorefresh.kickoff_cnt);
  1292. } else {
  1293. sde_encoder_helper_trigger_start(phys_enc);
  1294. }
  1295. }
  1296. static void sde_encoder_phys_cmd_setup_vsync_source(
  1297. struct sde_encoder_phys *phys_enc,
  1298. u32 vsync_source, bool is_dummy)
  1299. {
  1300. if (!phys_enc || !phys_enc->hw_intf)
  1301. return;
  1302. sde_encoder_helper_vsync_config(phys_enc, vsync_source, is_dummy);
  1303. if (phys_enc->has_intf_te && phys_enc->hw_intf->ops.vsync_sel)
  1304. phys_enc->hw_intf->ops.vsync_sel(phys_enc->hw_intf,
  1305. vsync_source);
  1306. }
  1307. static void sde_encoder_phys_cmd_init_ops(struct sde_encoder_phys_ops *ops)
  1308. {
  1309. ops->prepare_commit = sde_encoder_phys_cmd_prepare_commit;
  1310. ops->is_master = sde_encoder_phys_cmd_is_master;
  1311. ops->mode_set = sde_encoder_phys_cmd_mode_set;
  1312. ops->cont_splash_mode_set = sde_encoder_phys_cmd_cont_splash_mode_set;
  1313. ops->mode_fixup = sde_encoder_phys_cmd_mode_fixup;
  1314. ops->enable = sde_encoder_phys_cmd_enable;
  1315. ops->disable = sde_encoder_phys_cmd_disable;
  1316. ops->destroy = sde_encoder_phys_cmd_destroy;
  1317. ops->get_hw_resources = sde_encoder_phys_cmd_get_hw_resources;
  1318. ops->control_vblank_irq = sde_encoder_phys_cmd_control_vblank_irq;
  1319. ops->wait_for_commit_done = sde_encoder_phys_cmd_wait_for_commit_done;
  1320. ops->prepare_for_kickoff = sde_encoder_phys_cmd_prepare_for_kickoff;
  1321. ops->wait_for_tx_complete = sde_encoder_phys_cmd_wait_for_tx_complete;
  1322. ops->wait_for_vblank = sde_encoder_phys_cmd_wait_for_vblank;
  1323. ops->trigger_flush = sde_encoder_helper_trigger_flush;
  1324. ops->trigger_start = sde_encoder_phys_cmd_trigger_start;
  1325. ops->needs_single_flush = sde_encoder_phys_needs_single_flush;
  1326. ops->hw_reset = sde_encoder_helper_hw_reset;
  1327. ops->irq_control = sde_encoder_phys_cmd_irq_control;
  1328. ops->update_split_role = sde_encoder_phys_cmd_update_split_role;
  1329. ops->restore = sde_encoder_phys_cmd_enable_helper;
  1330. ops->control_te = sde_encoder_phys_cmd_connect_te;
  1331. ops->is_autorefresh_enabled =
  1332. sde_encoder_phys_cmd_is_autorefresh_enabled;
  1333. ops->get_line_count = sde_encoder_phys_cmd_te_get_line_count;
  1334. ops->get_wr_line_count = sde_encoder_phys_cmd_get_write_line_count;
  1335. ops->wait_for_active = NULL;
  1336. ops->setup_vsync_source = sde_encoder_phys_cmd_setup_vsync_source;
  1337. ops->setup_misr = sde_encoder_helper_setup_misr;
  1338. ops->collect_misr = sde_encoder_helper_collect_misr;
  1339. }
  1340. struct sde_encoder_phys *sde_encoder_phys_cmd_init(
  1341. struct sde_enc_phys_init_params *p)
  1342. {
  1343. struct sde_encoder_phys *phys_enc = NULL;
  1344. struct sde_encoder_phys_cmd *cmd_enc = NULL;
  1345. struct sde_hw_mdp *hw_mdp;
  1346. struct sde_encoder_irq *irq;
  1347. int i, ret = 0;
  1348. SDE_DEBUG("intf %d\n", p->intf_idx - INTF_0);
  1349. cmd_enc = kzalloc(sizeof(*cmd_enc), GFP_KERNEL);
  1350. if (!cmd_enc) {
  1351. ret = -ENOMEM;
  1352. SDE_ERROR("failed to allocate\n");
  1353. goto fail;
  1354. }
  1355. phys_enc = &cmd_enc->base;
  1356. hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
  1357. if (IS_ERR_OR_NULL(hw_mdp)) {
  1358. ret = PTR_ERR(hw_mdp);
  1359. SDE_ERROR("failed to get mdptop\n");
  1360. goto fail_mdp_init;
  1361. }
  1362. phys_enc->hw_mdptop = hw_mdp;
  1363. phys_enc->intf_idx = p->intf_idx;
  1364. phys_enc->parent = p->parent;
  1365. phys_enc->parent_ops = p->parent_ops;
  1366. phys_enc->sde_kms = p->sde_kms;
  1367. phys_enc->split_role = p->split_role;
  1368. phys_enc->intf_mode = INTF_MODE_CMD;
  1369. phys_enc->enc_spinlock = p->enc_spinlock;
  1370. phys_enc->vblank_ctl_lock = p->vblank_ctl_lock;
  1371. cmd_enc->stream_sel = 0;
  1372. phys_enc->enable_state = SDE_ENC_DISABLED;
  1373. sde_encoder_phys_cmd_init_ops(&phys_enc->ops);
  1374. phys_enc->comp_type = p->comp_type;
  1375. if (sde_hw_intf_te_supported(phys_enc->sde_kms->catalog))
  1376. phys_enc->has_intf_te = true;
  1377. else
  1378. phys_enc->has_intf_te = false;
  1379. for (i = 0; i < INTR_IDX_MAX; i++) {
  1380. irq = &phys_enc->irq[i];
  1381. INIT_LIST_HEAD(&irq->cb.list);
  1382. irq->irq_idx = -EINVAL;
  1383. irq->hw_idx = -EINVAL;
  1384. irq->cb.arg = phys_enc;
  1385. }
  1386. irq = &phys_enc->irq[INTR_IDX_CTL_START];
  1387. irq->name = "ctl_start";
  1388. irq->intr_type = SDE_IRQ_TYPE_CTL_START;
  1389. irq->intr_idx = INTR_IDX_CTL_START;
  1390. irq->cb.func = NULL;
  1391. irq = &phys_enc->irq[INTR_IDX_PINGPONG];
  1392. irq->name = "pp_done";
  1393. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_COMP;
  1394. irq->intr_idx = INTR_IDX_PINGPONG;
  1395. irq->cb.func = sde_encoder_phys_cmd_pp_tx_done_irq;
  1396. irq = &phys_enc->irq[INTR_IDX_RDPTR];
  1397. irq->intr_idx = INTR_IDX_RDPTR;
  1398. irq->name = "te_rd_ptr";
  1399. if (phys_enc->has_intf_te)
  1400. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_RD_PTR;
  1401. else
  1402. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_RD_PTR;
  1403. irq->cb.func = sde_encoder_phys_cmd_te_rd_ptr_irq;
  1404. irq = &phys_enc->irq[INTR_IDX_UNDERRUN];
  1405. irq->name = "underrun";
  1406. irq->intr_type = SDE_IRQ_TYPE_INTF_UNDER_RUN;
  1407. irq->intr_idx = INTR_IDX_UNDERRUN;
  1408. irq->cb.func = sde_encoder_phys_cmd_underrun_irq;
  1409. irq = &phys_enc->irq[INTR_IDX_AUTOREFRESH_DONE];
  1410. irq->name = "autorefresh_done";
  1411. if (phys_enc->has_intf_te)
  1412. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_AUTO_REF;
  1413. else
  1414. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_AUTO_REF;
  1415. irq->intr_idx = INTR_IDX_AUTOREFRESH_DONE;
  1416. irq->cb.func = sde_encoder_phys_cmd_autorefresh_done_irq;
  1417. irq = &phys_enc->irq[INTR_IDX_WRPTR];
  1418. irq->intr_idx = INTR_IDX_WRPTR;
  1419. irq->name = "wr_ptr";
  1420. if (phys_enc->has_intf_te)
  1421. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_WR_PTR;
  1422. else
  1423. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_WR_PTR;
  1424. irq->cb.func = sde_encoder_phys_cmd_wr_ptr_irq;
  1425. atomic_set(&phys_enc->vblank_refcount, 0);
  1426. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  1427. atomic_set(&phys_enc->pending_retire_fence_cnt, 0);
  1428. atomic_set(&cmd_enc->pending_vblank_cnt, 0);
  1429. init_waitqueue_head(&phys_enc->pending_kickoff_wq);
  1430. init_waitqueue_head(&cmd_enc->pending_vblank_wq);
  1431. atomic_set(&cmd_enc->autorefresh.kickoff_cnt, 0);
  1432. init_waitqueue_head(&cmd_enc->autorefresh.kickoff_wq);
  1433. SDE_DEBUG_CMDENC(cmd_enc, "created\n");
  1434. return phys_enc;
  1435. fail_mdp_init:
  1436. kfree(cmd_enc);
  1437. fail:
  1438. return ERR_PTR(ret);
  1439. }