sde_encoder_phys_cmd.c 48 KB

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