dp_display.c 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/slab.h>
  7. #include <linux/uaccess.h>
  8. #include <linux/debugfs.h>
  9. #include <linux/component.h>
  10. #include <linux/of_irq.h>
  11. #include <linux/soc/qcom/fsa4480-i2c.h>
  12. #include <linux/usb/phy.h>
  13. #include "sde_connector.h"
  14. #include "msm_drv.h"
  15. #include "dp_hpd.h"
  16. #include "dp_parser.h"
  17. #include "dp_power.h"
  18. #include "dp_catalog.h"
  19. #include "dp_aux.h"
  20. #include "dp_link.h"
  21. #include "dp_panel.h"
  22. #include "dp_ctrl.h"
  23. #include "dp_audio.h"
  24. #include "dp_display.h"
  25. #include "sde_hdcp.h"
  26. #include "dp_debug.h"
  27. #include "dp_pll.h"
  28. #include "sde_dbg.h"
  29. #define DP_MST_DEBUG(fmt, ...) DP_DEBUG(fmt, ##__VA_ARGS__)
  30. #define dp_display_state_show(x) { \
  31. DP_ERR("%s: state (0x%x): %s\n", x, dp->state, \
  32. dp_display_state_name(dp->state)); \
  33. SDE_EVT32_EXTERNAL(dp->state); }
  34. #define dp_display_state_log(x) { \
  35. DP_DEBUG("%s: state (0x%x): %s\n", x, dp->state, \
  36. dp_display_state_name(dp->state)); \
  37. SDE_EVT32_EXTERNAL(dp->state); }
  38. #define dp_display_state_is(x) (dp->state & (x))
  39. #define dp_display_state_add(x) { \
  40. (dp->state |= (x)); \
  41. dp_display_state_log("add "#x); }
  42. #define dp_display_state_remove(x) { \
  43. (dp->state &= ~(x)); \
  44. dp_display_state_log("remove "#x); }
  45. enum dp_display_states {
  46. DP_STATE_DISCONNECTED = 0,
  47. DP_STATE_CONFIGURED = BIT(0),
  48. DP_STATE_INITIALIZED = BIT(1),
  49. DP_STATE_READY = BIT(2),
  50. DP_STATE_CONNECTED = BIT(3),
  51. DP_STATE_CONNECT_NOTIFIED = BIT(4),
  52. DP_STATE_DISCONNECT_NOTIFIED = BIT(5),
  53. DP_STATE_ENABLED = BIT(6),
  54. DP_STATE_SUSPENDED = BIT(7),
  55. DP_STATE_ABORTED = BIT(8),
  56. DP_STATE_HDCP_ABORTED = BIT(9),
  57. DP_STATE_SRC_PWRDN = BIT(10),
  58. DP_STATE_TUI_ACTIVE = BIT(11),
  59. };
  60. static char *dp_display_state_name(enum dp_display_states state)
  61. {
  62. static char buf[SZ_1K];
  63. u32 len = 0;
  64. memset(buf, 0, SZ_1K);
  65. if (state & DP_STATE_CONFIGURED)
  66. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  67. "CONFIGURED");
  68. if (state & DP_STATE_INITIALIZED)
  69. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  70. "INITIALIZED");
  71. if (state & DP_STATE_READY)
  72. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  73. "READY");
  74. if (state & DP_STATE_CONNECTED)
  75. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  76. "CONNECTED");
  77. if (state & DP_STATE_CONNECT_NOTIFIED)
  78. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  79. "CONNECT_NOTIFIED");
  80. if (state & DP_STATE_DISCONNECT_NOTIFIED)
  81. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  82. "DISCONNECT_NOTIFIED");
  83. if (state & DP_STATE_ENABLED)
  84. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  85. "ENABLED");
  86. if (state & DP_STATE_SUSPENDED)
  87. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  88. "SUSPENDED");
  89. if (state & DP_STATE_ABORTED)
  90. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  91. "ABORTED");
  92. if (state & DP_STATE_HDCP_ABORTED)
  93. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  94. "HDCP_ABORTED");
  95. if (state & DP_STATE_SRC_PWRDN)
  96. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  97. "SRC_PWRDN");
  98. if (state & DP_STATE_TUI_ACTIVE)
  99. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  100. "TUI_ACTIVE");
  101. if (!strlen(buf))
  102. return "DISCONNECTED";
  103. return buf;
  104. }
  105. static struct dp_display *g_dp_display;
  106. #define HPD_STRING_SIZE 30
  107. struct dp_hdcp_dev {
  108. void *fd;
  109. struct sde_hdcp_ops *ops;
  110. enum sde_hdcp_version ver;
  111. };
  112. struct dp_hdcp {
  113. void *data;
  114. struct sde_hdcp_ops *ops;
  115. u32 source_cap;
  116. struct dp_hdcp_dev dev[HDCP_VERSION_MAX];
  117. };
  118. struct dp_mst {
  119. bool mst_active;
  120. bool drm_registered;
  121. struct dp_mst_drm_cbs cbs;
  122. };
  123. struct dp_display_private {
  124. char *name;
  125. int irq;
  126. enum drm_connector_status cached_connector_status;
  127. enum dp_display_states state;
  128. struct platform_device *pdev;
  129. struct device_node *aux_switch_node;
  130. struct dentry *root;
  131. struct completion notification_comp;
  132. struct dp_hpd *hpd;
  133. struct dp_parser *parser;
  134. struct dp_power *power;
  135. struct dp_catalog *catalog;
  136. struct dp_aux *aux;
  137. struct dp_link *link;
  138. struct dp_panel *panel;
  139. struct dp_ctrl *ctrl;
  140. struct dp_debug *debug;
  141. struct dp_pll *pll;
  142. struct dp_panel *active_panels[DP_STREAM_MAX];
  143. struct dp_hdcp hdcp;
  144. struct dp_hpd_cb hpd_cb;
  145. struct dp_display_mode mode;
  146. struct dp_display dp_display;
  147. struct msm_drm_private *priv;
  148. struct workqueue_struct *wq;
  149. struct delayed_work hdcp_cb_work;
  150. struct work_struct connect_work;
  151. struct work_struct attention_work;
  152. struct mutex session_lock;
  153. bool hdcp_delayed_off;
  154. u32 active_stream_cnt;
  155. struct dp_mst mst;
  156. u32 tot_dsc_blks_in_use;
  157. bool process_hpd_connect;
  158. struct notifier_block usb_nb;
  159. };
  160. static const struct of_device_id dp_dt_match[] = {
  161. {.compatible = "qcom,dp-display"},
  162. {}
  163. };
  164. static inline bool dp_display_is_hdcp_enabled(struct dp_display_private *dp)
  165. {
  166. return dp->link->hdcp_status.hdcp_version && dp->hdcp.ops;
  167. }
  168. static irqreturn_t dp_display_irq(int irq, void *dev_id)
  169. {
  170. struct dp_display_private *dp = dev_id;
  171. if (!dp) {
  172. DP_ERR("invalid data\n");
  173. return IRQ_NONE;
  174. }
  175. /* DP HPD isr */
  176. if (dp->hpd->type == DP_HPD_LPHW)
  177. dp->hpd->isr(dp->hpd);
  178. /* DP controller isr */
  179. dp->ctrl->isr(dp->ctrl);
  180. /* DP aux isr */
  181. dp->aux->isr(dp->aux);
  182. /* HDCP isr */
  183. if (dp_display_is_hdcp_enabled(dp) && dp->hdcp.ops->isr) {
  184. if (dp->hdcp.ops->isr(dp->hdcp.data))
  185. DP_ERR("dp_hdcp_isr failed\n");
  186. }
  187. return IRQ_HANDLED;
  188. }
  189. static bool dp_display_is_ds_bridge(struct dp_panel *panel)
  190. {
  191. return (panel->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  192. DP_DWN_STRM_PORT_PRESENT);
  193. }
  194. static bool dp_display_is_sink_count_zero(struct dp_display_private *dp)
  195. {
  196. return dp_display_is_ds_bridge(dp->panel) &&
  197. (dp->link->sink_count.count == 0);
  198. }
  199. static bool dp_display_is_ready(struct dp_display_private *dp)
  200. {
  201. return dp->hpd->hpd_high && dp_display_state_is(DP_STATE_CONNECTED) &&
  202. !dp_display_is_sink_count_zero(dp) &&
  203. dp->hpd->alt_mode_cfg_done;
  204. }
  205. static void dp_audio_enable(struct dp_display_private *dp, bool enable)
  206. {
  207. struct dp_panel *dp_panel;
  208. int idx;
  209. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  210. if (!dp->active_panels[idx])
  211. continue;
  212. dp_panel = dp->active_panels[idx];
  213. if (dp_panel->audio_supported) {
  214. if (enable) {
  215. dp_panel->audio->bw_code =
  216. dp->link->link_params.bw_code;
  217. dp_panel->audio->lane_count =
  218. dp->link->link_params.lane_count;
  219. dp_panel->audio->on(dp_panel->audio);
  220. } else {
  221. dp_panel->audio->off(dp_panel->audio);
  222. }
  223. }
  224. }
  225. }
  226. static void dp_display_update_hdcp_status(struct dp_display_private *dp,
  227. bool reset)
  228. {
  229. if (reset) {
  230. dp->link->hdcp_status.hdcp_state = HDCP_STATE_INACTIVE;
  231. dp->link->hdcp_status.hdcp_version = HDCP_VERSION_NONE;
  232. }
  233. memset(dp->debug->hdcp_status, 0, sizeof(dp->debug->hdcp_status));
  234. snprintf(dp->debug->hdcp_status, sizeof(dp->debug->hdcp_status),
  235. "%s: %s\ncaps: %d\n",
  236. sde_hdcp_version(dp->link->hdcp_status.hdcp_version),
  237. sde_hdcp_state_name(dp->link->hdcp_status.hdcp_state),
  238. dp->hdcp.source_cap);
  239. }
  240. static void dp_display_update_hdcp_info(struct dp_display_private *dp)
  241. {
  242. void *fd = NULL;
  243. struct dp_hdcp_dev *dev = NULL;
  244. struct sde_hdcp_ops *ops = NULL;
  245. int i = HDCP_VERSION_2P2;
  246. dp_display_update_hdcp_status(dp, true);
  247. dp->hdcp.data = NULL;
  248. dp->hdcp.ops = NULL;
  249. if (dp->debug->hdcp_disabled || dp->debug->sim_mode)
  250. return;
  251. while (i) {
  252. dev = &dp->hdcp.dev[i];
  253. ops = dev->ops;
  254. fd = dev->fd;
  255. i >>= 1;
  256. if (!(dp->hdcp.source_cap & dev->ver))
  257. continue;
  258. if (ops->sink_support(fd)) {
  259. dp->hdcp.data = fd;
  260. dp->hdcp.ops = ops;
  261. dp->link->hdcp_status.hdcp_version = dev->ver;
  262. break;
  263. }
  264. }
  265. DP_DEBUG("HDCP version supported: %s\n",
  266. sde_hdcp_version(dp->link->hdcp_status.hdcp_version));
  267. }
  268. static void dp_display_check_source_hdcp_caps(struct dp_display_private *dp)
  269. {
  270. int i;
  271. struct dp_hdcp_dev *hdcp_dev = dp->hdcp.dev;
  272. if (dp->debug->hdcp_disabled) {
  273. DP_DEBUG("hdcp disabled\n");
  274. return;
  275. }
  276. for (i = 0; i < HDCP_VERSION_MAX; i++) {
  277. struct dp_hdcp_dev *dev = &hdcp_dev[i];
  278. struct sde_hdcp_ops *ops = dev->ops;
  279. void *fd = dev->fd;
  280. if (!fd || !ops)
  281. continue;
  282. if (ops->set_mode && ops->set_mode(fd, dp->mst.mst_active))
  283. continue;
  284. if (!(dp->hdcp.source_cap & dev->ver) &&
  285. ops->feature_supported &&
  286. ops->feature_supported(fd))
  287. dp->hdcp.source_cap |= dev->ver;
  288. }
  289. dp_display_update_hdcp_status(dp, false);
  290. }
  291. static void dp_display_hdcp_register_streams(struct dp_display_private *dp)
  292. {
  293. int rc;
  294. size_t i;
  295. struct sde_hdcp_ops *ops = dp->hdcp.ops;
  296. void *data = dp->hdcp.data;
  297. if (dp_display_is_ready(dp) && dp->mst.mst_active && ops &&
  298. ops->register_streams){
  299. struct stream_info streams[DP_STREAM_MAX];
  300. int index = 0;
  301. DP_DEBUG("Registering all active panel streams with HDCP\n");
  302. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  303. if (!dp->active_panels[i])
  304. continue;
  305. streams[index].stream_id = i;
  306. streams[index].virtual_channel =
  307. dp->active_panels[i]->vcpi;
  308. index++;
  309. }
  310. if (index > 0) {
  311. rc = ops->register_streams(data, index, streams);
  312. if (rc)
  313. DP_ERR("failed to register streams. rc = %d\n",
  314. rc);
  315. }
  316. }
  317. }
  318. static void dp_display_hdcp_deregister_stream(struct dp_display_private *dp,
  319. enum dp_stream_id stream_id)
  320. {
  321. if (dp->hdcp.ops->deregister_streams) {
  322. struct stream_info stream = {stream_id,
  323. dp->active_panels[stream_id]->vcpi};
  324. DP_DEBUG("Deregistering stream within HDCP library\n");
  325. dp->hdcp.ops->deregister_streams(dp->hdcp.data, 1, &stream);
  326. }
  327. }
  328. static void dp_display_hdcp_process_delayed_off(struct dp_display_private *dp)
  329. {
  330. if (dp->hdcp_delayed_off) {
  331. if (dp->hdcp.ops && dp->hdcp.ops->off)
  332. dp->hdcp.ops->off(dp->hdcp.data);
  333. dp_display_update_hdcp_status(dp, true);
  334. dp->hdcp_delayed_off = false;
  335. }
  336. }
  337. static int dp_display_hdcp_process_sink_sync(struct dp_display_private *dp)
  338. {
  339. u8 sink_status = 0;
  340. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  341. if (dp->debug->hdcp_wait_sink_sync) {
  342. drm_dp_dpcd_readb(dp->aux->drm_aux, DP_SINK_STATUS,
  343. &sink_status);
  344. sink_status &= (DP_RECEIVE_PORT_0_STATUS |
  345. DP_RECEIVE_PORT_1_STATUS);
  346. if (sink_status < 1) {
  347. DP_DEBUG("Sink not synchronized. Queuing again then exiting\n");
  348. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  349. return -EAGAIN;
  350. }
  351. /*
  352. * Some sinks need more time to stabilize after synchronization
  353. * and before it can handle an HDCP authentication request.
  354. * Adding the delay for better interoperability.
  355. */
  356. msleep(6000);
  357. }
  358. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT);
  359. return 0;
  360. }
  361. static int dp_display_hdcp_start(struct dp_display_private *dp)
  362. {
  363. if (dp->link->hdcp_status.hdcp_state != HDCP_STATE_INACTIVE)
  364. return -EINVAL;
  365. dp_display_check_source_hdcp_caps(dp);
  366. dp_display_update_hdcp_info(dp);
  367. if (dp_display_is_hdcp_enabled(dp)) {
  368. if (dp->hdcp.ops && dp->hdcp.ops->on &&
  369. dp->hdcp.ops->on(dp->hdcp.data)) {
  370. dp_display_update_hdcp_status(dp, true);
  371. return 0;
  372. }
  373. } else {
  374. dp_display_update_hdcp_status(dp, true);
  375. return 0;
  376. }
  377. return -EINVAL;
  378. }
  379. static void dp_display_hdcp_print_auth_state(struct dp_display_private *dp)
  380. {
  381. u32 hdcp_auth_state;
  382. int rc;
  383. rc = dp->catalog->ctrl.read_hdcp_status(&dp->catalog->ctrl);
  384. if (rc >= 0) {
  385. hdcp_auth_state = (rc >> 20) & 0x3;
  386. DP_DEBUG("hdcp auth state %d\n", hdcp_auth_state);
  387. }
  388. }
  389. static void dp_display_hdcp_process_state(struct dp_display_private *dp)
  390. {
  391. struct dp_link_hdcp_status *status;
  392. struct sde_hdcp_ops *ops;
  393. void *data;
  394. int rc = 0;
  395. status = &dp->link->hdcp_status;
  396. ops = dp->hdcp.ops;
  397. data = dp->hdcp.data;
  398. if (status->hdcp_state != HDCP_STATE_AUTHENTICATED &&
  399. dp->debug->force_encryption && ops && ops->force_encryption)
  400. ops->force_encryption(data, dp->debug->force_encryption);
  401. switch (status->hdcp_state) {
  402. case HDCP_STATE_INACTIVE:
  403. dp_display_hdcp_register_streams(dp);
  404. if (dp->hdcp.ops && dp->hdcp.ops->authenticate)
  405. rc = dp->hdcp.ops->authenticate(data);
  406. if (!rc)
  407. status->hdcp_state = HDCP_STATE_AUTHENTICATING;
  408. break;
  409. case HDCP_STATE_AUTH_FAIL:
  410. if (dp_display_is_ready(dp) &&
  411. dp_display_state_is(DP_STATE_ENABLED)) {
  412. if (ops && ops->on && ops->on(data)) {
  413. dp_display_update_hdcp_status(dp, true);
  414. return;
  415. }
  416. dp_display_hdcp_register_streams(dp);
  417. if (ops && ops->reauthenticate) {
  418. rc = ops->reauthenticate(data);
  419. if (rc)
  420. DP_ERR("failed rc=%d\n", rc);
  421. }
  422. status->hdcp_state = HDCP_STATE_AUTHENTICATING;
  423. } else {
  424. DP_DEBUG("not reauthenticating, cable disconnected\n");
  425. }
  426. break;
  427. default:
  428. dp_display_hdcp_register_streams(dp);
  429. break;
  430. }
  431. }
  432. static void dp_display_abort_hdcp(struct dp_display_private *dp,
  433. bool abort)
  434. {
  435. u8 i = HDCP_VERSION_2P2;
  436. struct dp_hdcp_dev *dev = NULL;
  437. while (i) {
  438. dev = &dp->hdcp.dev[i];
  439. i >>= 1;
  440. if (!(dp->hdcp.source_cap & dev->ver))
  441. continue;
  442. dev->ops->abort(dev->fd, abort);
  443. }
  444. }
  445. static void dp_display_hdcp_cb_work(struct work_struct *work)
  446. {
  447. struct dp_display_private *dp;
  448. struct delayed_work *dw = to_delayed_work(work);
  449. struct dp_link_hdcp_status *status;
  450. int rc = 0;
  451. dp = container_of(dw, struct dp_display_private, hdcp_cb_work);
  452. if (!dp_display_state_is(DP_STATE_ENABLED | DP_STATE_CONNECTED) ||
  453. dp_display_state_is(DP_STATE_ABORTED | DP_STATE_HDCP_ABORTED))
  454. return;
  455. if (dp_display_state_is(DP_STATE_SUSPENDED)) {
  456. DP_DEBUG("System suspending. Delay HDCP operations\n");
  457. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  458. return;
  459. }
  460. dp_display_hdcp_process_delayed_off(dp);
  461. rc = dp_display_hdcp_process_sink_sync(dp);
  462. if (rc)
  463. return;
  464. rc = dp_display_hdcp_start(dp);
  465. if (!rc)
  466. return;
  467. dp_display_hdcp_print_auth_state(dp);
  468. status = &dp->link->hdcp_status;
  469. DP_DEBUG("%s: %s\n", sde_hdcp_version(status->hdcp_version),
  470. sde_hdcp_state_name(status->hdcp_state));
  471. dp_display_update_hdcp_status(dp, false);
  472. dp_display_hdcp_process_state(dp);
  473. }
  474. static void dp_display_notify_hdcp_status_cb(void *ptr,
  475. enum sde_hdcp_state state)
  476. {
  477. struct dp_display_private *dp = ptr;
  478. if (!dp) {
  479. DP_ERR("invalid input\n");
  480. return;
  481. }
  482. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY,
  483. dp->link->hdcp_status.hdcp_state);
  484. dp->link->hdcp_status.hdcp_state = state;
  485. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ/4);
  486. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT,
  487. dp->link->hdcp_status.hdcp_state);
  488. }
  489. static void dp_display_deinitialize_hdcp(struct dp_display_private *dp)
  490. {
  491. if (!dp) {
  492. DP_ERR("invalid input\n");
  493. return;
  494. }
  495. sde_hdcp_1x_deinit(dp->hdcp.dev[HDCP_VERSION_1X].fd);
  496. sde_dp_hdcp2p2_deinit(dp->hdcp.dev[HDCP_VERSION_2P2].fd);
  497. }
  498. static int dp_display_initialize_hdcp(struct dp_display_private *dp)
  499. {
  500. struct sde_hdcp_init_data hdcp_init_data;
  501. struct dp_parser *parser;
  502. void *fd;
  503. int rc = 0;
  504. if (!dp) {
  505. DP_ERR("invalid input\n");
  506. return -EINVAL;
  507. }
  508. parser = dp->parser;
  509. hdcp_init_data.client_id = HDCP_CLIENT_DP;
  510. hdcp_init_data.drm_aux = dp->aux->drm_aux;
  511. hdcp_init_data.cb_data = (void *)dp;
  512. hdcp_init_data.workq = dp->wq;
  513. hdcp_init_data.sec_access = true;
  514. hdcp_init_data.notify_status = dp_display_notify_hdcp_status_cb;
  515. hdcp_init_data.dp_ahb = &parser->get_io(parser, "dp_ahb")->io;
  516. hdcp_init_data.dp_aux = &parser->get_io(parser, "dp_aux")->io;
  517. hdcp_init_data.dp_link = &parser->get_io(parser, "dp_link")->io;
  518. hdcp_init_data.dp_p0 = &parser->get_io(parser, "dp_p0")->io;
  519. hdcp_init_data.hdcp_io = &parser->get_io(parser,
  520. "hdcp_physical")->io;
  521. hdcp_init_data.revision = &dp->panel->link_info.revision;
  522. hdcp_init_data.msm_hdcp_dev = dp->parser->msm_hdcp_dev;
  523. fd = sde_hdcp_1x_init(&hdcp_init_data);
  524. if (IS_ERR_OR_NULL(fd)) {
  525. DP_DEBUG("Error initializing HDCP 1.x\n");
  526. return -EINVAL;
  527. }
  528. dp->hdcp.dev[HDCP_VERSION_1X].fd = fd;
  529. dp->hdcp.dev[HDCP_VERSION_1X].ops = sde_hdcp_1x_get(fd);
  530. dp->hdcp.dev[HDCP_VERSION_1X].ver = HDCP_VERSION_1X;
  531. DP_INFO("HDCP 1.3 initialized\n");
  532. fd = sde_dp_hdcp2p2_init(&hdcp_init_data);
  533. if (IS_ERR_OR_NULL(fd)) {
  534. DP_DEBUG("Error initializing HDCP 2.x\n");
  535. rc = -EINVAL;
  536. goto error;
  537. }
  538. dp->hdcp.dev[HDCP_VERSION_2P2].fd = fd;
  539. dp->hdcp.dev[HDCP_VERSION_2P2].ops = sde_dp_hdcp2p2_get(fd);
  540. dp->hdcp.dev[HDCP_VERSION_2P2].ver = HDCP_VERSION_2P2;
  541. DP_INFO("HDCP 2.2 initialized\n");
  542. return 0;
  543. error:
  544. sde_hdcp_1x_deinit(dp->hdcp.dev[HDCP_VERSION_1X].fd);
  545. return rc;
  546. }
  547. static void dp_display_pause_audio(struct dp_display_private *dp, bool pause)
  548. {
  549. struct dp_panel *dp_panel;
  550. int idx;
  551. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  552. if (!dp->active_panels[idx])
  553. continue;
  554. dp_panel = dp->active_panels[idx];
  555. if (dp_panel->audio_supported)
  556. dp_panel->audio->tui_active = pause;
  557. }
  558. }
  559. static int dp_display_pre_hw_release(void *data)
  560. {
  561. struct dp_display_private *dp;
  562. struct dp_display *dp_display = data;
  563. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  564. if (!dp_display)
  565. return -EINVAL;
  566. dp = container_of(dp_display, struct dp_display_private, dp_display);
  567. mutex_lock(&dp->session_lock);
  568. dp_display_state_add(DP_STATE_TUI_ACTIVE);
  569. cancel_work_sync(&dp->connect_work);
  570. cancel_work_sync(&dp->attention_work);
  571. flush_workqueue(dp->wq);
  572. dp_display_pause_audio(dp, true);
  573. disable_irq(dp->irq);
  574. mutex_unlock(&dp->session_lock);
  575. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT);
  576. return 0;
  577. }
  578. static int dp_display_post_hw_acquire(void *data)
  579. {
  580. struct dp_display_private *dp;
  581. struct dp_display *dp_display = data;
  582. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  583. if (!dp_display)
  584. return -EINVAL;
  585. dp = container_of(dp_display, struct dp_display_private, dp_display);
  586. mutex_lock(&dp->session_lock);
  587. dp_display_state_remove(DP_STATE_TUI_ACTIVE);
  588. dp_display_pause_audio(dp, false);
  589. enable_irq(dp->irq);
  590. mutex_unlock(&dp->session_lock);
  591. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT);
  592. return 0;
  593. }
  594. static int dp_display_bind(struct device *dev, struct device *master,
  595. void *data)
  596. {
  597. int rc = 0;
  598. struct dp_display_private *dp;
  599. struct drm_device *drm;
  600. struct platform_device *pdev = to_platform_device(dev);
  601. struct msm_vm_ops vm_event_ops = {
  602. .vm_pre_hw_release = dp_display_pre_hw_release,
  603. .vm_post_hw_acquire = dp_display_post_hw_acquire,
  604. };
  605. if (!dev || !pdev || !master) {
  606. DP_ERR("invalid param(s), dev %pK, pdev %pK, master %pK\n",
  607. dev, pdev, master);
  608. rc = -EINVAL;
  609. goto end;
  610. }
  611. drm = dev_get_drvdata(master);
  612. dp = platform_get_drvdata(pdev);
  613. if (!drm || !dp) {
  614. DP_ERR("invalid param(s), drm %pK, dp %pK\n",
  615. drm, dp);
  616. rc = -EINVAL;
  617. goto end;
  618. }
  619. dp->dp_display.drm_dev = drm;
  620. dp->priv = drm->dev_private;
  621. msm_register_vm_event(master, dev, &vm_event_ops,
  622. (void *)&dp->dp_display);
  623. end:
  624. return rc;
  625. }
  626. static void dp_display_unbind(struct device *dev, struct device *master,
  627. void *data)
  628. {
  629. struct dp_display_private *dp;
  630. struct platform_device *pdev = to_platform_device(dev);
  631. if (!dev || !pdev) {
  632. DP_ERR("invalid param(s)\n");
  633. return;
  634. }
  635. dp = platform_get_drvdata(pdev);
  636. if (!dp) {
  637. DP_ERR("Invalid params\n");
  638. return;
  639. }
  640. if (dp->power)
  641. (void)dp->power->power_client_deinit(dp->power);
  642. if (dp->aux)
  643. (void)dp->aux->drm_aux_deregister(dp->aux);
  644. dp_display_deinitialize_hdcp(dp);
  645. }
  646. static const struct component_ops dp_display_comp_ops = {
  647. .bind = dp_display_bind,
  648. .unbind = dp_display_unbind,
  649. };
  650. static void dp_display_send_hpd_event(struct dp_display_private *dp)
  651. {
  652. struct drm_device *dev = NULL;
  653. struct drm_connector *connector;
  654. char name[HPD_STRING_SIZE], status[HPD_STRING_SIZE],
  655. bpp[HPD_STRING_SIZE], pattern[HPD_STRING_SIZE];
  656. char *envp[5];
  657. int rc = 0;
  658. if (dp->mst.mst_active) {
  659. DP_DEBUG("skip notification for mst mode\n");
  660. dp_display_state_remove(DP_STATE_DISCONNECT_NOTIFIED);
  661. return;
  662. }
  663. connector = dp->dp_display.base_connector;
  664. if (!connector) {
  665. DP_ERR("connector not set\n");
  666. return;
  667. }
  668. connector->status = connector->funcs->detect(connector, false);
  669. if (dp->cached_connector_status == connector->status) {
  670. DP_DEBUG("connector status (%d) unchanged, skipping uevent\n",
  671. dp->cached_connector_status);
  672. return;
  673. }
  674. dp->cached_connector_status = connector->status;
  675. dev = connector->dev;
  676. if (dp->debug->skip_uevent) {
  677. DP_INFO("skipping uevent\n");
  678. goto update_state;
  679. }
  680. snprintf(name, HPD_STRING_SIZE, "name=%s", connector->name);
  681. snprintf(status, HPD_STRING_SIZE, "status=%s",
  682. drm_get_connector_status_name(connector->status));
  683. snprintf(bpp, HPD_STRING_SIZE, "bpp=%d",
  684. dp_link_bit_depth_to_bpp(
  685. dp->link->test_video.test_bit_depth));
  686. snprintf(pattern, HPD_STRING_SIZE, "pattern=%d",
  687. dp->link->test_video.test_video_pattern);
  688. DP_INFO("[%s]:[%s] [%s] [%s]\n", name, status, bpp, pattern);
  689. envp[0] = name;
  690. envp[1] = status;
  691. envp[2] = bpp;
  692. envp[3] = pattern;
  693. envp[4] = NULL;
  694. rc = kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, envp);
  695. DP_INFO("uevent %s: %d\n", rc ? "failure" : "success", rc);
  696. update_state:
  697. if (connector->status == connector_status_connected) {
  698. dp_display_state_add(DP_STATE_CONNECT_NOTIFIED);
  699. dp_display_state_remove(DP_STATE_DISCONNECT_NOTIFIED);
  700. } else {
  701. dp_display_state_add(DP_STATE_DISCONNECT_NOTIFIED);
  702. dp_display_state_remove(DP_STATE_CONNECT_NOTIFIED);
  703. }
  704. }
  705. static int dp_display_send_hpd_notification(struct dp_display_private *dp)
  706. {
  707. int ret = 0;
  708. bool hpd = !!dp_display_state_is(DP_STATE_CONNECTED);
  709. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state, hpd);
  710. /*
  711. * Send the notification only if there is any change. This check is
  712. * necessary since it is possible that the connect_work may or may not
  713. * skip sending the notification in order to respond to a pending
  714. * attention message. Attention work thread will always attempt to
  715. * send the notification after successfully handling the attention
  716. * message. This check here will avoid any unintended duplicate
  717. * notifications.
  718. */
  719. if (dp_display_state_is(DP_STATE_CONNECT_NOTIFIED) && hpd) {
  720. DP_DEBUG("connection notified already, skip notification\n");
  721. goto skip_wait;
  722. } else if (dp_display_state_is(DP_STATE_DISCONNECT_NOTIFIED) && !hpd) {
  723. DP_DEBUG("disonnect notified already, skip notification\n");
  724. goto skip_wait;
  725. }
  726. dp->aux->state |= DP_STATE_NOTIFICATION_SENT;
  727. if (!dp->mst.mst_active)
  728. dp->dp_display.is_sst_connected = hpd;
  729. else
  730. dp->dp_display.is_sst_connected = false;
  731. reinit_completion(&dp->notification_comp);
  732. dp_display_send_hpd_event(dp);
  733. /*
  734. * Skip the wait if TUI is active considering that the user mode will
  735. * not act on the notification until after the TUI session is over.
  736. */
  737. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  738. dp_display_state_log("[TUI is active, skipping wait]");
  739. goto skip_wait;
  740. }
  741. if (hpd && dp->mst.mst_active)
  742. goto skip_wait;
  743. if (!dp->mst.mst_active &&
  744. (!!dp_display_state_is(DP_STATE_ENABLED) == hpd))
  745. goto skip_wait;
  746. if (!wait_for_completion_timeout(&dp->notification_comp,
  747. HZ * 5)) {
  748. DP_WARN("%s timeout\n", hpd ? "connect" : "disconnect");
  749. ret = -EINVAL;
  750. }
  751. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, hpd, ret);
  752. return ret;
  753. skip_wait:
  754. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, hpd, ret);
  755. return 0;
  756. }
  757. static void dp_display_update_mst_state(struct dp_display_private *dp,
  758. bool state)
  759. {
  760. dp->mst.mst_active = state;
  761. dp->panel->mst_state = state;
  762. }
  763. static void dp_display_process_mst_hpd_high(struct dp_display_private *dp,
  764. bool mst_probe)
  765. {
  766. bool is_mst_receiver;
  767. struct dp_mst_hpd_info info;
  768. const unsigned long clear_mstm_ctrl_timeout_us = 100000;
  769. u8 old_mstm_ctrl;
  770. int ret;
  771. if (!dp->parser->has_mst || !dp->mst.drm_registered) {
  772. DP_MST_DEBUG("mst not enabled. has_mst:%d, registered:%d\n",
  773. dp->parser->has_mst, dp->mst.drm_registered);
  774. return;
  775. }
  776. DP_MST_DEBUG("mst_hpd_high work. mst_probe:%d\n", mst_probe);
  777. if (!dp->mst.mst_active) {
  778. is_mst_receiver = dp->panel->read_mst_cap(dp->panel);
  779. if (!is_mst_receiver) {
  780. DP_MST_DEBUG("sink doesn't support mst\n");
  781. return;
  782. }
  783. /* clear sink mst state */
  784. drm_dp_dpcd_readb(dp->aux->drm_aux, DP_MSTM_CTRL,
  785. &old_mstm_ctrl);
  786. drm_dp_dpcd_writeb(dp->aux->drm_aux, DP_MSTM_CTRL, 0);
  787. /* add extra delay if MST state is not cleared */
  788. if (old_mstm_ctrl) {
  789. DP_MST_DEBUG("MSTM_CTRL is not cleared, wait %dus\n",
  790. clear_mstm_ctrl_timeout_us);
  791. usleep_range(clear_mstm_ctrl_timeout_us,
  792. clear_mstm_ctrl_timeout_us + 1000);
  793. }
  794. ret = drm_dp_dpcd_writeb(dp->aux->drm_aux, DP_MSTM_CTRL,
  795. DP_MST_EN | DP_UP_REQ_EN | DP_UPSTREAM_IS_SRC);
  796. if (ret < 0) {
  797. DP_ERR("sink mst enablement failed\n");
  798. return;
  799. }
  800. dp_display_update_mst_state(dp, true);
  801. } else if (dp->mst.mst_active && mst_probe) {
  802. info.mst_protocol = dp->parser->has_mst_sideband;
  803. info.mst_port_cnt = dp->debug->mst_port_cnt;
  804. info.edid = dp->debug->get_edid(dp->debug);
  805. if (dp->mst.cbs.set_mgr_state)
  806. dp->mst.cbs.set_mgr_state(&dp->dp_display, true, &info);
  807. if (dp->mst.cbs.hpd)
  808. dp->mst.cbs.hpd(&dp->dp_display, true);
  809. }
  810. DP_MST_DEBUG("mst_hpd_high. mst_active:%d\n", dp->mst.mst_active);
  811. }
  812. static void dp_display_host_init(struct dp_display_private *dp)
  813. {
  814. bool flip = false;
  815. bool reset;
  816. if (dp_display_state_is(DP_STATE_INITIALIZED)) {
  817. dp_display_state_log("[already initialized]");
  818. return;
  819. }
  820. if (dp->hpd->orientation == ORIENTATION_CC2)
  821. flip = true;
  822. reset = dp->debug->sim_mode ? false : !dp->hpd->multi_func;
  823. dp->power->init(dp->power, flip);
  824. dp->hpd->host_init(dp->hpd, &dp->catalog->hpd);
  825. dp->ctrl->init(dp->ctrl, flip, reset);
  826. enable_irq(dp->irq);
  827. dp_display_abort_hdcp(dp, false);
  828. dp_display_state_add(DP_STATE_INITIALIZED);
  829. /* log this as it results from user action of cable connection */
  830. DP_INFO("[OK]\n");
  831. }
  832. static void dp_display_host_ready(struct dp_display_private *dp)
  833. {
  834. if (!dp_display_state_is(DP_STATE_INITIALIZED)) {
  835. dp_display_state_show("[not initialized]");
  836. return;
  837. }
  838. if (dp_display_state_is(DP_STATE_READY)) {
  839. dp_display_state_log("[already ready]");
  840. return;
  841. }
  842. /*
  843. * Reset the aborted state for AUX and CTRL modules. This will
  844. * allow these modules to execute normally in response to the
  845. * cable connection event.
  846. *
  847. * One corner case still exists. While the execution flow ensures
  848. * that cable disconnection flushes all pending work items on the DP
  849. * workqueue, and waits for the user module to clean up the DP
  850. * connection session, it is possible that the system delays can
  851. * lead to timeouts in the connect path. As a result, the actual
  852. * connection callback from user modules can come in late and can
  853. * race against a subsequent connection event here which would have
  854. * reset the aborted flags. There is no clear solution for this since
  855. * the connect/disconnect notifications do not currently have any
  856. * sessions IDs.
  857. */
  858. dp->aux->abort(dp->aux, false);
  859. dp->ctrl->abort(dp->ctrl, false);
  860. dp->aux->init(dp->aux, dp->parser->aux_cfg);
  861. dp->panel->init(dp->panel);
  862. dp_display_state_add(DP_STATE_READY);
  863. /* log this as it results from user action of cable connection */
  864. DP_INFO("[OK]\n");
  865. }
  866. static void dp_display_host_unready(struct dp_display_private *dp)
  867. {
  868. if (!dp_display_state_is(DP_STATE_INITIALIZED)) {
  869. dp_display_state_show("[not initialized]");
  870. return;
  871. }
  872. if (!dp_display_state_is(DP_STATE_READY)) {
  873. dp_display_state_show("[not ready]");
  874. return;
  875. }
  876. dp_display_state_remove(DP_STATE_READY);
  877. dp->aux->deinit(dp->aux);
  878. /* log this as it results from user action of cable disconnection */
  879. DP_INFO("[OK]\n");
  880. }
  881. static void dp_display_host_deinit(struct dp_display_private *dp)
  882. {
  883. if (dp->active_stream_cnt) {
  884. SDE_EVT32_EXTERNAL(dp->state, dp->active_stream_cnt);
  885. DP_DEBUG("active stream present\n");
  886. return;
  887. }
  888. if (!dp_display_state_is(DP_STATE_INITIALIZED)) {
  889. dp_display_state_show("[not initialized]");
  890. return;
  891. }
  892. dp_display_abort_hdcp(dp, true);
  893. dp->ctrl->deinit(dp->ctrl);
  894. dp->hpd->host_deinit(dp->hpd, &dp->catalog->hpd);
  895. dp->power->deinit(dp->power);
  896. disable_irq(dp->irq);
  897. dp->aux->state = 0;
  898. dp_display_state_remove(DP_STATE_INITIALIZED);
  899. /* log this as it results from user action of cable dis-connection */
  900. DP_INFO("[OK]\n");
  901. }
  902. static int dp_display_process_hpd_high(struct dp_display_private *dp)
  903. {
  904. int rc = -EINVAL;
  905. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  906. mutex_lock(&dp->session_lock);
  907. if (dp_display_state_is(DP_STATE_CONNECTED)) {
  908. DP_DEBUG("dp already connected, skipping hpd high\n");
  909. mutex_unlock(&dp->session_lock);
  910. return -EISCONN;
  911. }
  912. dp_display_state_add(DP_STATE_CONNECTED);
  913. dp->dp_display.max_pclk_khz = min(dp->parser->max_pclk_khz,
  914. dp->debug->max_pclk_khz);
  915. /*
  916. * If dp video session is not restored from a previous session teardown
  917. * by userspace, ensure the host_init is executed, in such a scenario,
  918. * so that all the required DP resources are enabled.
  919. *
  920. * Below is one of the sequences of events which describe the above
  921. * scenario:
  922. * a. Source initiated power down resulting in host_deinit.
  923. * b. Sink issues hpd low attention without physical cable disconnect.
  924. * c. Source initiated power up sequence returns early because hpd is
  925. * not high.
  926. * d. Sink issues a hpd high attention event.
  927. */
  928. if (dp_display_state_is(DP_STATE_SRC_PWRDN) &&
  929. dp_display_state_is(DP_STATE_CONFIGURED)) {
  930. dp_display_host_init(dp);
  931. dp_display_state_remove(DP_STATE_SRC_PWRDN);
  932. }
  933. dp_display_host_ready(dp);
  934. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  935. dp->debug->psm_enabled = false;
  936. if (!dp->dp_display.base_connector)
  937. goto end;
  938. rc = dp->panel->read_sink_caps(dp->panel,
  939. dp->dp_display.base_connector, dp->hpd->multi_func);
  940. /*
  941. * ETIMEDOUT --> cable may have been removed
  942. * ENOTCONN --> no downstream device connected
  943. */
  944. if (rc == -ETIMEDOUT || rc == -ENOTCONN) {
  945. dp_display_state_remove(DP_STATE_CONNECTED);
  946. goto end;
  947. }
  948. dp->link->process_request(dp->link);
  949. dp->panel->handle_sink_request(dp->panel);
  950. dp_display_process_mst_hpd_high(dp, false);
  951. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active,
  952. dp->panel->fec_en, dp->panel->dsc_en, false);
  953. if (rc) {
  954. dp_display_state_remove(DP_STATE_CONNECTED);
  955. goto end;
  956. }
  957. dp->process_hpd_connect = false;
  958. dp_display_process_mst_hpd_high(dp, true);
  959. end:
  960. mutex_unlock(&dp->session_lock);
  961. /*
  962. * Delay the HPD connect notification to see if sink generates any
  963. * IRQ HPDs immediately after the HPD high.
  964. */
  965. usleep_range(10000, 10100);
  966. /*
  967. * If an IRQ HPD is pending, then do not send a connect notification.
  968. * Once this work returns, the IRQ HPD would be processed and any
  969. * required actions (such as link maintenance) would be done which
  970. * will subsequently send the HPD notification. To keep things simple,
  971. * do this only for SST use-cases. MST use cases require additional
  972. * care in order to handle the side-band communications as well.
  973. *
  974. * One of the main motivations for this is DP LL 1.4 CTS use case
  975. * where it is possible that we could get a test request right after
  976. * a connection, and the strict timing requriements of the test can
  977. * only be met if we do not wait for the e2e connection to be set up.
  978. */
  979. if (!dp->mst.mst_active &&
  980. (work_busy(&dp->attention_work) == WORK_BUSY_PENDING)) {
  981. SDE_EVT32_EXTERNAL(dp->state, 99);
  982. DP_DEBUG("Attention pending, skip HPD notification\n");
  983. goto skip_notify;
  984. }
  985. if (!rc && !dp_display_state_is(DP_STATE_ABORTED))
  986. dp_display_send_hpd_notification(dp);
  987. skip_notify:
  988. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  989. return rc;
  990. }
  991. static void dp_display_process_mst_hpd_low(struct dp_display_private *dp)
  992. {
  993. int rc = 0;
  994. struct dp_mst_hpd_info info = {0};
  995. if (dp->mst.mst_active) {
  996. DP_MST_DEBUG("mst_hpd_low work\n");
  997. /*
  998. * HPD unplug callflow:
  999. * 1. send hpd unplug event with status=disconnected
  1000. * 2. send hpd unplug on base connector so usermode can disable
  1001. * all external displays.
  1002. * 3. unset mst state in the topology mgr so the branch device
  1003. * can be cleaned up.
  1004. */
  1005. if (dp->mst.cbs.hpd)
  1006. dp->mst.cbs.hpd(&dp->dp_display, false);
  1007. dp_display_update_mst_state(dp, false);
  1008. if ((dp_display_state_is(DP_STATE_CONNECT_NOTIFIED) ||
  1009. dp_display_state_is(DP_STATE_ENABLED)))
  1010. rc = dp_display_send_hpd_notification(dp);
  1011. if (dp->mst.cbs.set_mgr_state) {
  1012. info.mst_protocol = dp->parser->has_mst_sideband;
  1013. dp->mst.cbs.set_mgr_state(&dp->dp_display, false,
  1014. &info);
  1015. }
  1016. }
  1017. DP_MST_DEBUG("mst_hpd_low. mst_active:%d\n", dp->mst.mst_active);
  1018. }
  1019. static int dp_display_process_hpd_low(struct dp_display_private *dp)
  1020. {
  1021. int rc = 0;
  1022. dp_display_state_remove(DP_STATE_CONNECTED);
  1023. dp->process_hpd_connect = false;
  1024. dp_audio_enable(dp, false);
  1025. if (dp->mst.mst_active) {
  1026. dp_display_process_mst_hpd_low(dp);
  1027. } else {
  1028. if ((dp_display_state_is(DP_STATE_CONNECT_NOTIFIED) ||
  1029. dp_display_state_is(DP_STATE_ENABLED)))
  1030. rc = dp_display_send_hpd_notification(dp);
  1031. }
  1032. mutex_lock(&dp->session_lock);
  1033. if (!dp->active_stream_cnt)
  1034. dp->ctrl->off(dp->ctrl);
  1035. mutex_unlock(&dp->session_lock);
  1036. dp->panel->video_test = false;
  1037. return rc;
  1038. }
  1039. static int dp_display_usbpd_configure_cb(struct device *dev)
  1040. {
  1041. int rc = 0;
  1042. struct dp_display_private *dp;
  1043. if (!dev) {
  1044. DP_ERR("invalid dev\n");
  1045. return -EINVAL;
  1046. }
  1047. dp = dev_get_drvdata(dev);
  1048. if (!dp) {
  1049. DP_ERR("no driver data found\n");
  1050. return -ENODEV;
  1051. }
  1052. if (!dp->debug->sim_mode && !dp->parser->no_aux_switch
  1053. && !dp->parser->gpio_aux_switch) {
  1054. rc = dp->aux->aux_switch(dp->aux, true, dp->hpd->orientation);
  1055. if (rc)
  1056. return rc;
  1057. }
  1058. mutex_lock(&dp->session_lock);
  1059. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1060. dp_display_state_log("[TUI is active]");
  1061. mutex_unlock(&dp->session_lock);
  1062. return 0;
  1063. }
  1064. dp_display_state_remove(DP_STATE_ABORTED);
  1065. dp_display_state_add(DP_STATE_CONFIGURED);
  1066. dp_display_host_init(dp);
  1067. /* check for hpd high */
  1068. if (dp->hpd->hpd_high)
  1069. queue_work(dp->wq, &dp->connect_work);
  1070. else
  1071. dp->process_hpd_connect = true;
  1072. mutex_unlock(&dp->session_lock);
  1073. return 0;
  1074. }
  1075. static int dp_display_stream_pre_disable(struct dp_display_private *dp,
  1076. struct dp_panel *dp_panel)
  1077. {
  1078. dp->ctrl->stream_pre_off(dp->ctrl, dp_panel);
  1079. return 0;
  1080. }
  1081. static void dp_display_stream_disable(struct dp_display_private *dp,
  1082. struct dp_panel *dp_panel)
  1083. {
  1084. if (!dp->active_stream_cnt) {
  1085. DP_ERR("invalid active_stream_cnt (%d)\n",
  1086. dp->active_stream_cnt);
  1087. return;
  1088. }
  1089. DP_DEBUG("stream_id=%d, active_stream_cnt=%d\n",
  1090. dp_panel->stream_id, dp->active_stream_cnt);
  1091. dp->ctrl->stream_off(dp->ctrl, dp_panel);
  1092. dp->active_panels[dp_panel->stream_id] = NULL;
  1093. dp->active_stream_cnt--;
  1094. }
  1095. static void dp_display_clean(struct dp_display_private *dp)
  1096. {
  1097. int idx;
  1098. struct dp_panel *dp_panel;
  1099. struct dp_link_hdcp_status *status = &dp->link->hdcp_status;
  1100. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1101. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1102. DP_WARN("TUI is active\n");
  1103. return;
  1104. }
  1105. if (dp_display_is_hdcp_enabled(dp) &&
  1106. status->hdcp_state != HDCP_STATE_INACTIVE) {
  1107. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  1108. if (dp->hdcp.ops->off)
  1109. dp->hdcp.ops->off(dp->hdcp.data);
  1110. dp_display_update_hdcp_status(dp, true);
  1111. }
  1112. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  1113. if (!dp->active_panels[idx])
  1114. continue;
  1115. dp_panel = dp->active_panels[idx];
  1116. if (dp_panel->audio_supported)
  1117. dp_panel->audio->off(dp_panel->audio);
  1118. dp_display_stream_pre_disable(dp, dp_panel);
  1119. dp_display_stream_disable(dp, dp_panel);
  1120. dp_panel->deinit(dp_panel, 0);
  1121. }
  1122. dp_display_state_remove(DP_STATE_ENABLED | DP_STATE_CONNECTED);
  1123. dp->ctrl->off(dp->ctrl);
  1124. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1125. }
  1126. static int dp_display_handle_disconnect(struct dp_display_private *dp)
  1127. {
  1128. int rc;
  1129. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1130. rc = dp_display_process_hpd_low(dp);
  1131. if (rc) {
  1132. /* cancel any pending request */
  1133. dp->ctrl->abort(dp->ctrl, true);
  1134. dp->aux->abort(dp->aux, true);
  1135. }
  1136. mutex_lock(&dp->session_lock);
  1137. if (dp_display_state_is(DP_STATE_ENABLED))
  1138. dp_display_clean(dp);
  1139. dp_display_host_unready(dp);
  1140. mutex_unlock(&dp->session_lock);
  1141. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1142. return rc;
  1143. }
  1144. static void dp_display_disconnect_sync(struct dp_display_private *dp)
  1145. {
  1146. /* cancel any pending request */
  1147. dp_display_state_add(DP_STATE_ABORTED);
  1148. dp->ctrl->abort(dp->ctrl, true);
  1149. dp->aux->abort(dp->aux, true);
  1150. /* wait for idle state */
  1151. cancel_work_sync(&dp->connect_work);
  1152. cancel_work_sync(&dp->attention_work);
  1153. flush_workqueue(dp->wq);
  1154. dp_display_handle_disconnect(dp);
  1155. }
  1156. static int dp_display_usbpd_disconnect_cb(struct device *dev)
  1157. {
  1158. int rc = 0;
  1159. struct dp_display_private *dp;
  1160. if (!dev) {
  1161. DP_ERR("invalid dev\n");
  1162. rc = -EINVAL;
  1163. goto end;
  1164. }
  1165. dp = dev_get_drvdata(dev);
  1166. if (!dp) {
  1167. DP_ERR("no driver data found\n");
  1168. rc = -ENODEV;
  1169. goto end;
  1170. }
  1171. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state,
  1172. dp->debug->psm_enabled);
  1173. /* skip if a disconnect is already in progress */
  1174. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1175. DP_DEBUG("disconnect already in progress\n");
  1176. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_CASE1, dp->state);
  1177. return 0;
  1178. }
  1179. if (dp->debug->psm_enabled && dp_display_state_is(DP_STATE_READY))
  1180. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  1181. dp_display_disconnect_sync(dp);
  1182. mutex_lock(&dp->session_lock);
  1183. dp_display_host_deinit(dp);
  1184. dp_display_state_remove(DP_STATE_CONFIGURED);
  1185. mutex_unlock(&dp->session_lock);
  1186. if (!dp->debug->sim_mode && !dp->parser->no_aux_switch
  1187. && !dp->parser->gpio_aux_switch)
  1188. dp->aux->aux_switch(dp->aux, false, ORIENTATION_NONE);
  1189. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1190. end:
  1191. return rc;
  1192. }
  1193. static int dp_display_stream_enable(struct dp_display_private *dp,
  1194. struct dp_panel *dp_panel)
  1195. {
  1196. int rc = 0;
  1197. rc = dp->ctrl->stream_on(dp->ctrl, dp_panel);
  1198. if (dp->debug->tpg_state)
  1199. dp_panel->tpg_config(dp_panel, true);
  1200. if (!rc) {
  1201. dp->active_panels[dp_panel->stream_id] = dp_panel;
  1202. dp->active_stream_cnt++;
  1203. }
  1204. DP_DEBUG("dp active_stream_cnt:%d\n", dp->active_stream_cnt);
  1205. return rc;
  1206. }
  1207. static void dp_display_mst_attention(struct dp_display_private *dp)
  1208. {
  1209. struct dp_mst_hpd_info hpd_irq = {0};
  1210. if (dp->mst.mst_active && dp->mst.cbs.hpd_irq) {
  1211. hpd_irq.mst_hpd_sim = dp->debug->mst_hpd_sim;
  1212. hpd_irq.mst_sim_add_con = dp->debug->mst_sim_add_con;
  1213. hpd_irq.mst_sim_remove_con = dp->debug->mst_sim_remove_con;
  1214. hpd_irq.mst_sim_remove_con_id = dp->debug->mst_sim_remove_con_id;
  1215. hpd_irq.edid = dp->debug->get_edid(dp->debug);
  1216. dp->mst.cbs.hpd_irq(&dp->dp_display, &hpd_irq);
  1217. dp->debug->mst_hpd_sim = false;
  1218. dp->debug->mst_sim_add_con = false;
  1219. dp->debug->mst_sim_remove_con = false;
  1220. }
  1221. DP_MST_DEBUG("mst_attention_work. mst_active:%d\n", dp->mst.mst_active);
  1222. }
  1223. static void dp_display_attention_work(struct work_struct *work)
  1224. {
  1225. struct dp_display_private *dp = container_of(work,
  1226. struct dp_display_private, attention_work);
  1227. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1228. mutex_lock(&dp->session_lock);
  1229. SDE_EVT32_EXTERNAL(dp->state);
  1230. if (dp->debug->mst_hpd_sim || !dp_display_state_is(DP_STATE_READY)) {
  1231. mutex_unlock(&dp->session_lock);
  1232. goto mst_attention;
  1233. }
  1234. if (dp->link->process_request(dp->link)) {
  1235. mutex_unlock(&dp->session_lock);
  1236. goto cp_irq;
  1237. }
  1238. mutex_unlock(&dp->session_lock);
  1239. SDE_EVT32_EXTERNAL(dp->state, dp->link->sink_request);
  1240. if (dp->link->sink_request & DS_PORT_STATUS_CHANGED) {
  1241. SDE_EVT32_EXTERNAL(dp->state, DS_PORT_STATUS_CHANGED);
  1242. if (dp_display_is_sink_count_zero(dp)) {
  1243. dp_display_handle_disconnect(dp);
  1244. } else {
  1245. /*
  1246. * connect work should take care of sending
  1247. * the HPD notification.
  1248. */
  1249. if (!dp->mst.mst_active)
  1250. queue_work(dp->wq, &dp->connect_work);
  1251. }
  1252. goto mst_attention;
  1253. }
  1254. if (dp->link->sink_request & DP_TEST_LINK_VIDEO_PATTERN) {
  1255. SDE_EVT32_EXTERNAL(dp->state, DP_TEST_LINK_VIDEO_PATTERN);
  1256. dp_display_handle_disconnect(dp);
  1257. dp->panel->video_test = true;
  1258. /*
  1259. * connect work should take care of sending
  1260. * the HPD notification.
  1261. */
  1262. queue_work(dp->wq, &dp->connect_work);
  1263. goto mst_attention;
  1264. }
  1265. if (dp->link->sink_request & (DP_TEST_LINK_PHY_TEST_PATTERN |
  1266. DP_TEST_LINK_TRAINING | DP_LINK_STATUS_UPDATED)) {
  1267. mutex_lock(&dp->session_lock);
  1268. dp_audio_enable(dp, false);
  1269. if (dp->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) {
  1270. SDE_EVT32_EXTERNAL(dp->state,
  1271. DP_TEST_LINK_PHY_TEST_PATTERN);
  1272. dp->ctrl->process_phy_test_request(dp->ctrl);
  1273. }
  1274. if (dp->link->sink_request & DP_TEST_LINK_TRAINING) {
  1275. SDE_EVT32_EXTERNAL(dp->state, DP_TEST_LINK_TRAINING);
  1276. dp->link->send_test_response(dp->link);
  1277. dp->ctrl->link_maintenance(dp->ctrl);
  1278. }
  1279. if (dp->link->sink_request & DP_LINK_STATUS_UPDATED) {
  1280. SDE_EVT32_EXTERNAL(dp->state, DP_LINK_STATUS_UPDATED);
  1281. dp->ctrl->link_maintenance(dp->ctrl);
  1282. }
  1283. dp_audio_enable(dp, true);
  1284. mutex_unlock(&dp->session_lock);
  1285. if (dp->link->sink_request & (DP_TEST_LINK_PHY_TEST_PATTERN |
  1286. DP_TEST_LINK_TRAINING))
  1287. goto mst_attention;
  1288. }
  1289. cp_irq:
  1290. if (dp_display_is_hdcp_enabled(dp) && dp->hdcp.ops->cp_irq)
  1291. dp->hdcp.ops->cp_irq(dp->hdcp.data);
  1292. if (!dp->mst.mst_active) {
  1293. /*
  1294. * It is possible that the connect_work skipped sending
  1295. * the HPD notification if the attention message was
  1296. * already pending. Send the notification here to
  1297. * account for that. This is not needed if this
  1298. * attention work was handling a test request
  1299. */
  1300. dp_display_send_hpd_notification(dp);
  1301. }
  1302. mst_attention:
  1303. dp_display_mst_attention(dp);
  1304. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1305. }
  1306. static int dp_display_usbpd_attention_cb(struct device *dev)
  1307. {
  1308. struct dp_display_private *dp;
  1309. if (!dev) {
  1310. DP_ERR("invalid dev\n");
  1311. return -EINVAL;
  1312. }
  1313. dp = dev_get_drvdata(dev);
  1314. if (!dp) {
  1315. DP_ERR("no driver data found\n");
  1316. return -ENODEV;
  1317. }
  1318. DP_DEBUG("hpd_irq:%d, hpd_high:%d, power_on:%d, is_connected:%d\n",
  1319. dp->hpd->hpd_irq, dp->hpd->hpd_high,
  1320. !!dp_display_state_is(DP_STATE_ENABLED),
  1321. !!dp_display_state_is(DP_STATE_CONNECTED));
  1322. SDE_EVT32_EXTERNAL(dp->state, dp->hpd->hpd_irq, dp->hpd->hpd_high,
  1323. !!dp_display_state_is(DP_STATE_ENABLED),
  1324. !!dp_display_state_is(DP_STATE_CONNECTED));
  1325. if (!dp->hpd->hpd_high) {
  1326. dp_display_disconnect_sync(dp);
  1327. return 0;
  1328. }
  1329. /*
  1330. * Ignore all the attention messages except HPD LOW when TUI is
  1331. * active, so user mode can be notified of the disconnect event. This
  1332. * allows user mode to tear down the control path after the TUI
  1333. * session is over. Ideally this should never happen, but on the off
  1334. * chance that there is a race condition in which there is a IRQ HPD
  1335. * during tear down of DP at TUI start then this check might help avoid
  1336. * a potential issue accessing registers in attention processing.
  1337. */
  1338. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1339. DP_WARN("TUI is active\n");
  1340. return 0;
  1341. }
  1342. if ((dp->hpd->hpd_irq && dp_display_state_is(DP_STATE_READY)) ||
  1343. dp->debug->mst_hpd_sim) {
  1344. queue_work(dp->wq, &dp->attention_work);
  1345. } else if (dp->process_hpd_connect ||
  1346. !dp_display_state_is(DP_STATE_CONNECTED)) {
  1347. dp_display_state_remove(DP_STATE_ABORTED);
  1348. queue_work(dp->wq, &dp->connect_work);
  1349. } else {
  1350. DP_DEBUG("ignored\n");
  1351. }
  1352. return 0;
  1353. }
  1354. static void dp_display_connect_work(struct work_struct *work)
  1355. {
  1356. int rc = 0;
  1357. struct dp_display_private *dp = container_of(work,
  1358. struct dp_display_private, connect_work);
  1359. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1360. dp_display_state_log("[TUI is active]");
  1361. return;
  1362. }
  1363. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1364. DP_WARN("HPD off requested\n");
  1365. return;
  1366. }
  1367. if (!dp->hpd->hpd_high) {
  1368. DP_WARN("Sink disconnected\n");
  1369. return;
  1370. }
  1371. rc = dp_display_process_hpd_high(dp);
  1372. if (!rc && dp->panel->video_test)
  1373. dp->link->send_test_response(dp->link);
  1374. }
  1375. static int dp_display_usb_notifier(struct notifier_block *nb,
  1376. unsigned long action, void *data)
  1377. {
  1378. struct dp_display_private *dp = container_of(nb,
  1379. struct dp_display_private, usb_nb);
  1380. SDE_EVT32_EXTERNAL(dp->state, dp->debug->sim_mode, action);
  1381. if (!action && dp->debug->sim_mode) {
  1382. DP_WARN("usb disconnected during simulation\n");
  1383. dp_display_disconnect_sync(dp);
  1384. dp->debug->abort(dp->debug);
  1385. }
  1386. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, NOTIFY_DONE);
  1387. return NOTIFY_DONE;
  1388. }
  1389. static void dp_display_register_usb_notifier(struct dp_display_private *dp)
  1390. {
  1391. int rc = 0;
  1392. const char *phandle = "usb-phy";
  1393. struct usb_phy *usbphy;
  1394. usbphy = devm_usb_get_phy_by_phandle(&dp->pdev->dev, phandle, 0);
  1395. if (IS_ERR_OR_NULL(usbphy)) {
  1396. DP_DEBUG("unable to get usbphy\n");
  1397. return;
  1398. }
  1399. dp->usb_nb.notifier_call = dp_display_usb_notifier;
  1400. dp->usb_nb.priority = 2;
  1401. rc = usb_register_notifier(usbphy, &dp->usb_nb);
  1402. if (rc)
  1403. DP_DEBUG("failed to register for usb event: %d\n", rc);
  1404. }
  1405. static void dp_display_deinit_sub_modules(struct dp_display_private *dp)
  1406. {
  1407. dp_debug_put(dp->debug);
  1408. dp_hpd_put(dp->hpd);
  1409. if (dp->panel)
  1410. dp_audio_put(dp->panel->audio);
  1411. dp_ctrl_put(dp->ctrl);
  1412. dp_panel_put(dp->panel);
  1413. dp_link_put(dp->link);
  1414. dp_power_put(dp->power);
  1415. dp_pll_put(dp->pll);
  1416. dp_aux_put(dp->aux);
  1417. dp_catalog_put(dp->catalog);
  1418. dp_parser_put(dp->parser);
  1419. mutex_destroy(&dp->session_lock);
  1420. }
  1421. static int dp_init_sub_modules(struct dp_display_private *dp)
  1422. {
  1423. int rc = 0;
  1424. bool hdcp_disabled;
  1425. struct device *dev = &dp->pdev->dev;
  1426. struct dp_hpd_cb *cb = &dp->hpd_cb;
  1427. struct dp_ctrl_in ctrl_in = {
  1428. .dev = dev,
  1429. };
  1430. struct dp_panel_in panel_in = {
  1431. .dev = dev,
  1432. };
  1433. struct dp_debug_in debug_in = {
  1434. .dev = dev,
  1435. };
  1436. struct dp_pll_in pll_in = {
  1437. .pdev = dp->pdev,
  1438. };
  1439. mutex_init(&dp->session_lock);
  1440. dp->parser = dp_parser_get(dp->pdev);
  1441. if (IS_ERR(dp->parser)) {
  1442. rc = PTR_ERR(dp->parser);
  1443. DP_ERR("failed to initialize parser, rc = %d\n", rc);
  1444. dp->parser = NULL;
  1445. goto error;
  1446. }
  1447. rc = dp->parser->parse(dp->parser);
  1448. if (rc) {
  1449. DP_ERR("device tree parsing failed\n");
  1450. goto error_catalog;
  1451. }
  1452. g_dp_display->is_mst_supported = dp->parser->has_mst;
  1453. dp->catalog = dp_catalog_get(dev, dp->parser);
  1454. if (IS_ERR(dp->catalog)) {
  1455. rc = PTR_ERR(dp->catalog);
  1456. DP_ERR("failed to initialize catalog, rc = %d\n", rc);
  1457. dp->catalog = NULL;
  1458. goto error_catalog;
  1459. }
  1460. dp->aux = dp_aux_get(dev, &dp->catalog->aux, dp->parser,
  1461. dp->aux_switch_node);
  1462. if (IS_ERR(dp->aux)) {
  1463. rc = PTR_ERR(dp->aux);
  1464. DP_ERR("failed to initialize aux, rc = %d\n", rc);
  1465. dp->aux = NULL;
  1466. goto error_aux;
  1467. }
  1468. rc = dp->aux->drm_aux_register(dp->aux);
  1469. if (rc) {
  1470. DP_ERR("DRM DP AUX register failed\n");
  1471. goto error_pll;
  1472. }
  1473. pll_in.aux = dp->aux;
  1474. pll_in.parser = dp->parser;
  1475. dp->pll = dp_pll_get(&pll_in);
  1476. if (IS_ERR(dp->pll)) {
  1477. rc = PTR_ERR(dp->pll);
  1478. DP_ERR("failed to initialize pll, rc = %d\n", rc);
  1479. dp->pll = NULL;
  1480. goto error_pll;
  1481. }
  1482. dp->power = dp_power_get(dp->parser, dp->pll);
  1483. if (IS_ERR(dp->power)) {
  1484. rc = PTR_ERR(dp->power);
  1485. DP_ERR("failed to initialize power, rc = %d\n", rc);
  1486. dp->power = NULL;
  1487. goto error_power;
  1488. }
  1489. rc = dp->power->power_client_init(dp->power, &dp->priv->phandle,
  1490. dp->dp_display.drm_dev);
  1491. if (rc) {
  1492. DP_ERR("Power client create failed\n");
  1493. goto error_link;
  1494. }
  1495. dp->link = dp_link_get(dev, dp->aux);
  1496. if (IS_ERR(dp->link)) {
  1497. rc = PTR_ERR(dp->link);
  1498. DP_ERR("failed to initialize link, rc = %d\n", rc);
  1499. dp->link = NULL;
  1500. goto error_link;
  1501. }
  1502. panel_in.aux = dp->aux;
  1503. panel_in.catalog = &dp->catalog->panel;
  1504. panel_in.link = dp->link;
  1505. panel_in.connector = dp->dp_display.base_connector;
  1506. panel_in.base_panel = NULL;
  1507. panel_in.parser = dp->parser;
  1508. dp->panel = dp_panel_get(&panel_in);
  1509. if (IS_ERR(dp->panel)) {
  1510. rc = PTR_ERR(dp->panel);
  1511. DP_ERR("failed to initialize panel, rc = %d\n", rc);
  1512. dp->panel = NULL;
  1513. goto error_panel;
  1514. }
  1515. ctrl_in.link = dp->link;
  1516. ctrl_in.panel = dp->panel;
  1517. ctrl_in.aux = dp->aux;
  1518. ctrl_in.power = dp->power;
  1519. ctrl_in.catalog = &dp->catalog->ctrl;
  1520. ctrl_in.parser = dp->parser;
  1521. dp->ctrl = dp_ctrl_get(&ctrl_in);
  1522. if (IS_ERR(dp->ctrl)) {
  1523. rc = PTR_ERR(dp->ctrl);
  1524. DP_ERR("failed to initialize ctrl, rc = %d\n", rc);
  1525. dp->ctrl = NULL;
  1526. goto error_ctrl;
  1527. }
  1528. dp->panel->audio = dp_audio_get(dp->pdev, dp->panel,
  1529. &dp->catalog->audio);
  1530. if (IS_ERR(dp->panel->audio)) {
  1531. rc = PTR_ERR(dp->panel->audio);
  1532. DP_ERR("failed to initialize audio, rc = %d\n", rc);
  1533. dp->panel->audio = NULL;
  1534. goto error_audio;
  1535. }
  1536. memset(&dp->mst, 0, sizeof(dp->mst));
  1537. dp->active_stream_cnt = 0;
  1538. cb->configure = dp_display_usbpd_configure_cb;
  1539. cb->disconnect = dp_display_usbpd_disconnect_cb;
  1540. cb->attention = dp_display_usbpd_attention_cb;
  1541. dp->hpd = dp_hpd_get(dev, dp->parser, &dp->catalog->hpd, cb);
  1542. if (IS_ERR(dp->hpd)) {
  1543. rc = PTR_ERR(dp->hpd);
  1544. DP_ERR("failed to initialize hpd, rc = %d\n", rc);
  1545. dp->hpd = NULL;
  1546. goto error_hpd;
  1547. }
  1548. hdcp_disabled = !!dp_display_initialize_hdcp(dp);
  1549. debug_in.panel = dp->panel;
  1550. debug_in.hpd = dp->hpd;
  1551. debug_in.link = dp->link;
  1552. debug_in.aux = dp->aux;
  1553. debug_in.connector = &dp->dp_display.base_connector;
  1554. debug_in.catalog = dp->catalog;
  1555. debug_in.parser = dp->parser;
  1556. debug_in.ctrl = dp->ctrl;
  1557. debug_in.pll = dp->pll;
  1558. dp->debug = dp_debug_get(&debug_in);
  1559. if (IS_ERR(dp->debug)) {
  1560. rc = PTR_ERR(dp->debug);
  1561. DP_ERR("failed to initialize debug, rc = %d\n", rc);
  1562. dp->debug = NULL;
  1563. goto error_debug;
  1564. }
  1565. dp->cached_connector_status = connector_status_disconnected;
  1566. dp->tot_dsc_blks_in_use = 0;
  1567. dp->debug->hdcp_disabled = hdcp_disabled;
  1568. dp_display_update_hdcp_status(dp, true);
  1569. dp_display_register_usb_notifier(dp);
  1570. if (dp->hpd->register_hpd) {
  1571. rc = dp->hpd->register_hpd(dp->hpd);
  1572. if (rc) {
  1573. DP_ERR("failed register hpd\n");
  1574. goto error_hpd_reg;
  1575. }
  1576. }
  1577. return rc;
  1578. error_hpd_reg:
  1579. dp_debug_put(dp->debug);
  1580. error_debug:
  1581. dp_hpd_put(dp->hpd);
  1582. error_hpd:
  1583. dp_audio_put(dp->panel->audio);
  1584. error_audio:
  1585. dp_ctrl_put(dp->ctrl);
  1586. error_ctrl:
  1587. dp_panel_put(dp->panel);
  1588. error_panel:
  1589. dp_link_put(dp->link);
  1590. error_link:
  1591. dp_power_put(dp->power);
  1592. error_power:
  1593. dp_pll_put(dp->pll);
  1594. error_pll:
  1595. dp_aux_put(dp->aux);
  1596. error_aux:
  1597. dp_catalog_put(dp->catalog);
  1598. error_catalog:
  1599. dp_parser_put(dp->parser);
  1600. error:
  1601. mutex_destroy(&dp->session_lock);
  1602. return rc;
  1603. }
  1604. static int dp_display_post_init(struct dp_display *dp_display)
  1605. {
  1606. int rc = 0;
  1607. struct dp_display_private *dp;
  1608. if (!dp_display) {
  1609. DP_ERR("invalid input\n");
  1610. rc = -EINVAL;
  1611. goto end;
  1612. }
  1613. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1614. if (IS_ERR_OR_NULL(dp)) {
  1615. DP_ERR("invalid params\n");
  1616. rc = -EINVAL;
  1617. goto end;
  1618. }
  1619. rc = dp_init_sub_modules(dp);
  1620. if (rc)
  1621. goto end;
  1622. dp_display->post_init = NULL;
  1623. end:
  1624. DP_DEBUG("%s\n", rc ? "failed" : "success");
  1625. return rc;
  1626. }
  1627. static int dp_display_set_mode(struct dp_display *dp_display, void *panel,
  1628. struct dp_display_mode *mode)
  1629. {
  1630. const u32 num_components = 3, default_bpp = 24;
  1631. struct dp_display_private *dp;
  1632. struct dp_panel *dp_panel;
  1633. if (!dp_display || !panel) {
  1634. DP_ERR("invalid input\n");
  1635. return -EINVAL;
  1636. }
  1637. dp_panel = panel;
  1638. if (!dp_panel->connector) {
  1639. DP_ERR("invalid connector input\n");
  1640. return -EINVAL;
  1641. }
  1642. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1643. mutex_lock(&dp->session_lock);
  1644. mode->timing.bpp =
  1645. dp_panel->connector->display_info.bpc * num_components;
  1646. if (!mode->timing.bpp)
  1647. mode->timing.bpp = default_bpp;
  1648. mode->timing.bpp = dp->panel->get_mode_bpp(dp->panel,
  1649. mode->timing.bpp, mode->timing.pixel_clk_khz);
  1650. dp_panel->pinfo = mode->timing;
  1651. mutex_unlock(&dp->session_lock);
  1652. return 0;
  1653. }
  1654. static int dp_display_prepare(struct dp_display *dp_display, void *panel)
  1655. {
  1656. struct dp_display_private *dp;
  1657. struct dp_panel *dp_panel;
  1658. int rc = 0;
  1659. if (!dp_display || !panel) {
  1660. DP_ERR("invalid input\n");
  1661. return -EINVAL;
  1662. }
  1663. dp_panel = panel;
  1664. if (!dp_panel->connector) {
  1665. DP_ERR("invalid connector input\n");
  1666. return -EINVAL;
  1667. }
  1668. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1669. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1670. mutex_lock(&dp->session_lock);
  1671. /*
  1672. * If DP video session is restored by the userspace after display
  1673. * disconnect notification from dongle i.e. typeC cable connected to
  1674. * source but disconnected at the display side, the DP controller is
  1675. * not restored to the desired configured state. So, ensure host_init
  1676. * is executed in such a scenario so that all the DP controller
  1677. * resources are enabled for the next connection event.
  1678. */
  1679. if (dp_display_state_is(DP_STATE_SRC_PWRDN) &&
  1680. dp_display_state_is(DP_STATE_CONFIGURED)) {
  1681. dp_display_host_init(dp);
  1682. dp_display_state_remove(DP_STATE_SRC_PWRDN);
  1683. }
  1684. /*
  1685. * If the physical connection to the sink is already lost by the time
  1686. * we try to set up the connection, we can just skip all the steps
  1687. * here safely.
  1688. */
  1689. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1690. dp_display_state_log("[aborted]");
  1691. goto end;
  1692. }
  1693. /*
  1694. * If DP_STATE_ENABLED, there is nothing left to do.
  1695. * However, this should not happen ideally. So, log this.
  1696. */
  1697. if (dp_display_state_is(DP_STATE_ENABLED)) {
  1698. dp_display_state_show("[already enabled]");
  1699. goto end;
  1700. }
  1701. if (!dp_display_is_ready(dp)) {
  1702. dp_display_state_show("[not ready]");
  1703. goto end;
  1704. }
  1705. /* For supporting DP_PANEL_SRC_INITIATED_POWER_DOWN case */
  1706. dp_display_host_ready(dp);
  1707. if (dp->debug->psm_enabled) {
  1708. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  1709. dp->debug->psm_enabled = false;
  1710. }
  1711. /*
  1712. * Execute the dp controller power on in shallow mode here.
  1713. * In normal cases, controller should have been powered on
  1714. * by now. In some cases like suspend/resume or framework
  1715. * reboot, we end up here without a powered on controller.
  1716. * Cable may have been removed in suspended state. In that
  1717. * case, link training is bound to fail on system resume.
  1718. * So, we execute in shallow mode here to do only minimal
  1719. * and required things.
  1720. */
  1721. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active, dp_panel->fec_en,
  1722. dp_panel->dsc_en, true);
  1723. if (rc)
  1724. goto end;
  1725. end:
  1726. mutex_unlock(&dp->session_lock);
  1727. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  1728. return rc;
  1729. }
  1730. static int dp_display_set_stream_info(struct dp_display *dp_display,
  1731. void *panel, u32 strm_id, u32 start_slot,
  1732. u32 num_slots, u32 pbn, int vcpi)
  1733. {
  1734. int rc = 0;
  1735. struct dp_panel *dp_panel;
  1736. struct dp_display_private *dp;
  1737. const int max_slots = 64;
  1738. if (!dp_display) {
  1739. DP_ERR("invalid input\n");
  1740. return -EINVAL;
  1741. }
  1742. if (strm_id >= DP_STREAM_MAX) {
  1743. DP_ERR("invalid stream id:%d\n", strm_id);
  1744. return -EINVAL;
  1745. }
  1746. if (start_slot + num_slots > max_slots) {
  1747. DP_ERR("invalid channel info received. start:%d, slots:%d\n",
  1748. start_slot, num_slots);
  1749. return -EINVAL;
  1750. }
  1751. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1752. mutex_lock(&dp->session_lock);
  1753. dp->ctrl->set_mst_channel_info(dp->ctrl, strm_id,
  1754. start_slot, num_slots);
  1755. if (panel) {
  1756. dp_panel = panel;
  1757. dp_panel->set_stream_info(dp_panel, strm_id, start_slot,
  1758. num_slots, pbn, vcpi);
  1759. }
  1760. mutex_unlock(&dp->session_lock);
  1761. return rc;
  1762. }
  1763. static void dp_display_update_dsc_resources(struct dp_display_private *dp,
  1764. struct dp_panel *panel, bool enable)
  1765. {
  1766. int rc;
  1767. u32 dsc_blk_cnt = 0;
  1768. struct msm_drm_private *priv = dp->priv;
  1769. if (panel->pinfo.comp_info.comp_type == MSM_DISPLAY_COMPRESSION_DSC &&
  1770. (panel->pinfo.comp_info.comp_ratio > 1)) {
  1771. rc = msm_get_dsc_count(priv, panel->pinfo.h_active,
  1772. &dsc_blk_cnt);
  1773. if (rc) {
  1774. DP_ERR("error getting dsc count. rc:%d\n", rc);
  1775. return;
  1776. }
  1777. }
  1778. if (enable) {
  1779. dp->tot_dsc_blks_in_use += dsc_blk_cnt;
  1780. panel->tot_dsc_blks_in_use += dsc_blk_cnt;
  1781. } else {
  1782. dp->tot_dsc_blks_in_use -= dsc_blk_cnt;
  1783. panel->tot_dsc_blks_in_use -= dsc_blk_cnt;
  1784. }
  1785. }
  1786. static int dp_display_enable(struct dp_display *dp_display, void *panel)
  1787. {
  1788. int rc = 0;
  1789. struct dp_display_private *dp;
  1790. if (!dp_display || !panel) {
  1791. DP_ERR("invalid input\n");
  1792. return -EINVAL;
  1793. }
  1794. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1795. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1796. mutex_lock(&dp->session_lock);
  1797. /*
  1798. * If DP_STATE_READY is not set, we should not do any HW
  1799. * programming.
  1800. */
  1801. if (!dp_display_state_is(DP_STATE_READY)) {
  1802. dp_display_state_show("[host not ready]");
  1803. goto end;
  1804. }
  1805. /*
  1806. * It is possible that by the time we get call back to establish
  1807. * the DP pipeline e2e, the physical DP connection to the sink is
  1808. * already lost. In such cases, the DP_STATE_ABORTED would be set.
  1809. * However, it is necessary to NOT abort the display setup here so as
  1810. * to ensure that the rest of the system is in a stable state prior to
  1811. * handling the disconnect notification.
  1812. */
  1813. if (dp_display_state_is(DP_STATE_ABORTED))
  1814. dp_display_state_log("[aborted, but continue on]");
  1815. rc = dp_display_stream_enable(dp, panel);
  1816. if (rc)
  1817. goto end;
  1818. dp_display_update_dsc_resources(dp, panel, true);
  1819. dp_display_state_add(DP_STATE_ENABLED);
  1820. end:
  1821. mutex_unlock(&dp->session_lock);
  1822. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  1823. return rc;
  1824. }
  1825. static void dp_display_stream_post_enable(struct dp_display_private *dp,
  1826. struct dp_panel *dp_panel)
  1827. {
  1828. dp_panel->spd_config(dp_panel);
  1829. dp_panel->setup_hdr(dp_panel, NULL, false, 0, true);
  1830. }
  1831. static int dp_display_post_enable(struct dp_display *dp_display, void *panel)
  1832. {
  1833. struct dp_display_private *dp;
  1834. struct dp_panel *dp_panel;
  1835. if (!dp_display || !panel) {
  1836. DP_ERR("invalid input\n");
  1837. return -EINVAL;
  1838. }
  1839. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1840. dp_panel = panel;
  1841. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1842. mutex_lock(&dp->session_lock);
  1843. /*
  1844. * If DP_STATE_READY is not set, we should not do any HW
  1845. * programming.
  1846. */
  1847. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  1848. dp_display_state_show("[not enabled]");
  1849. goto end;
  1850. }
  1851. /*
  1852. * If the physical connection to the sink is already lost by the time
  1853. * we try to set up the connection, we can just skip all the steps
  1854. * here safely.
  1855. */
  1856. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1857. dp_display_state_log("[aborted]");
  1858. goto end;
  1859. }
  1860. if (!dp_display_is_ready(dp) || !dp_display_state_is(DP_STATE_READY)) {
  1861. dp_display_state_show("[not ready]");
  1862. goto end;
  1863. }
  1864. dp_display_stream_post_enable(dp, dp_panel);
  1865. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  1866. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  1867. if (dp_panel->audio_supported) {
  1868. dp_panel->audio->bw_code = dp->link->link_params.bw_code;
  1869. dp_panel->audio->lane_count = dp->link->link_params.lane_count;
  1870. dp_panel->audio->on(dp_panel->audio);
  1871. }
  1872. end:
  1873. dp->aux->state |= DP_STATE_CTRL_POWERED_ON;
  1874. complete_all(&dp->notification_comp);
  1875. mutex_unlock(&dp->session_lock);
  1876. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1877. return 0;
  1878. }
  1879. static void dp_display_clear_colorspaces(struct dp_display *dp_display)
  1880. {
  1881. struct drm_connector *connector;
  1882. struct sde_connector *sde_conn;
  1883. connector = dp_display->base_connector;
  1884. sde_conn = to_sde_connector(connector);
  1885. sde_conn->color_enc_fmt = 0;
  1886. }
  1887. static int dp_display_pre_disable(struct dp_display *dp_display, void *panel)
  1888. {
  1889. struct dp_display_private *dp;
  1890. struct dp_panel *dp_panel = panel;
  1891. struct dp_link_hdcp_status *status;
  1892. int rc = 0;
  1893. size_t i;
  1894. if (!dp_display || !panel) {
  1895. DP_ERR("invalid input\n");
  1896. return -EINVAL;
  1897. }
  1898. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1899. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1900. mutex_lock(&dp->session_lock);
  1901. status = &dp->link->hdcp_status;
  1902. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  1903. dp_display_state_show("[not enabled]");
  1904. goto end;
  1905. }
  1906. dp_display_state_add(DP_STATE_HDCP_ABORTED);
  1907. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  1908. if (dp_display_is_hdcp_enabled(dp) &&
  1909. status->hdcp_state != HDCP_STATE_INACTIVE) {
  1910. bool off = true;
  1911. if (dp_display_state_is(DP_STATE_SUSPENDED)) {
  1912. DP_DEBUG("Can't perform HDCP cleanup while suspended. Defer\n");
  1913. dp->hdcp_delayed_off = true;
  1914. goto clean;
  1915. }
  1916. flush_delayed_work(&dp->hdcp_cb_work);
  1917. if (dp->mst.mst_active) {
  1918. dp_display_hdcp_deregister_stream(dp,
  1919. dp_panel->stream_id);
  1920. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  1921. if (i != dp_panel->stream_id &&
  1922. dp->active_panels[i]) {
  1923. DP_DEBUG("Streams are still active. Skip disabling HDCP\n");
  1924. off = false;
  1925. }
  1926. }
  1927. }
  1928. if (off) {
  1929. if (dp->hdcp.ops->off)
  1930. dp->hdcp.ops->off(dp->hdcp.data);
  1931. dp_display_update_hdcp_status(dp, true);
  1932. }
  1933. }
  1934. dp_display_clear_colorspaces(dp_display);
  1935. clean:
  1936. if (dp_panel->audio_supported)
  1937. dp_panel->audio->off(dp_panel->audio);
  1938. rc = dp_display_stream_pre_disable(dp, dp_panel);
  1939. end:
  1940. mutex_unlock(&dp->session_lock);
  1941. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1942. return 0;
  1943. }
  1944. static int dp_display_disable(struct dp_display *dp_display, void *panel)
  1945. {
  1946. int i;
  1947. struct dp_display_private *dp = NULL;
  1948. struct dp_panel *dp_panel = NULL;
  1949. struct dp_link_hdcp_status *status;
  1950. if (!dp_display || !panel) {
  1951. DP_ERR("invalid input\n");
  1952. return -EINVAL;
  1953. }
  1954. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1955. dp_panel = panel;
  1956. status = &dp->link->hdcp_status;
  1957. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1958. mutex_lock(&dp->session_lock);
  1959. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  1960. dp_display_state_show("[not enabled]");
  1961. goto end;
  1962. }
  1963. if (!dp_display_state_is(DP_STATE_READY)) {
  1964. dp_display_state_show("[not ready]");
  1965. goto end;
  1966. }
  1967. dp_display_stream_disable(dp, dp_panel);
  1968. dp_display_update_dsc_resources(dp, dp_panel, false);
  1969. dp_display_state_remove(DP_STATE_HDCP_ABORTED);
  1970. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  1971. if (dp->active_panels[i]) {
  1972. if (status->hdcp_state != HDCP_STATE_AUTHENTICATED)
  1973. queue_delayed_work(dp->wq, &dp->hdcp_cb_work,
  1974. HZ/4);
  1975. break;
  1976. }
  1977. }
  1978. end:
  1979. mutex_unlock(&dp->session_lock);
  1980. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1981. return 0;
  1982. }
  1983. static int dp_request_irq(struct dp_display *dp_display)
  1984. {
  1985. int rc = 0;
  1986. struct dp_display_private *dp;
  1987. if (!dp_display) {
  1988. DP_ERR("invalid input\n");
  1989. return -EINVAL;
  1990. }
  1991. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1992. dp->irq = irq_of_parse_and_map(dp->pdev->dev.of_node, 0);
  1993. if (dp->irq < 0) {
  1994. rc = dp->irq;
  1995. DP_ERR("failed to get irq: %d\n", rc);
  1996. return rc;
  1997. }
  1998. rc = devm_request_irq(&dp->pdev->dev, dp->irq, dp_display_irq,
  1999. IRQF_TRIGGER_HIGH, "dp_display_isr", dp);
  2000. if (rc < 0) {
  2001. DP_ERR("failed to request IRQ%u: %d\n",
  2002. dp->irq, rc);
  2003. return rc;
  2004. }
  2005. disable_irq(dp->irq);
  2006. return 0;
  2007. }
  2008. static struct dp_debug *dp_get_debug(struct dp_display *dp_display)
  2009. {
  2010. struct dp_display_private *dp;
  2011. if (!dp_display) {
  2012. DP_ERR("invalid input\n");
  2013. return ERR_PTR(-EINVAL);
  2014. }
  2015. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2016. return dp->debug;
  2017. }
  2018. static int dp_display_unprepare(struct dp_display *dp_display, void *panel)
  2019. {
  2020. struct dp_display_private *dp;
  2021. struct dp_panel *dp_panel = panel;
  2022. u32 flags = 0;
  2023. if (!dp_display || !panel) {
  2024. DP_ERR("invalid input\n");
  2025. return -EINVAL;
  2026. }
  2027. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2028. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2029. mutex_lock(&dp->session_lock);
  2030. /*
  2031. * Check if the power off sequence was triggered
  2032. * by a source initialated action like framework
  2033. * reboot or suspend-resume but not from normal
  2034. * hot plug. If connector is in MST mode, skip
  2035. * powering down host as aux needs to be kept
  2036. * alive to handle hot-plug sideband message.
  2037. */
  2038. if (dp_display_is_ready(dp) &&
  2039. (dp_display_state_is(DP_STATE_SUSPENDED) ||
  2040. !dp->mst.mst_active))
  2041. flags |= DP_PANEL_SRC_INITIATED_POWER_DOWN;
  2042. if (dp->active_stream_cnt)
  2043. goto end;
  2044. if (flags & DP_PANEL_SRC_INITIATED_POWER_DOWN) {
  2045. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  2046. dp->debug->psm_enabled = true;
  2047. dp->ctrl->off(dp->ctrl);
  2048. dp_display_host_unready(dp);
  2049. dp_display_host_deinit(dp);
  2050. dp_display_state_add(DP_STATE_SRC_PWRDN);
  2051. }
  2052. dp_display_state_remove(DP_STATE_ENABLED);
  2053. dp->aux->state = DP_STATE_CTRL_POWERED_OFF;
  2054. complete_all(&dp->notification_comp);
  2055. /* log this as it results from user action of cable dis-connection */
  2056. DP_INFO("[OK]\n");
  2057. end:
  2058. dp_panel->deinit(dp_panel, flags);
  2059. mutex_unlock(&dp->session_lock);
  2060. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2061. return 0;
  2062. }
  2063. static int dp_display_validate_link_clock(struct dp_display_private *dp,
  2064. struct drm_display_mode *mode, struct dp_display_mode dp_mode)
  2065. {
  2066. struct drm_dp_link *link_info;
  2067. u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
  2068. bool dsc_en;
  2069. int rate;
  2070. link_info = &dp->panel->link_info;
  2071. dsc_en = (dp_mode.timing.comp_info.comp_ratio > 1) ? true : false;
  2072. mode_bpp = dsc_en ?
  2073. DSC_BPP(dp_mode.timing.comp_info.dsc_info.config)
  2074. : dp_mode.timing.bpp;
  2075. mode_rate_khz = mode->clock * mode_bpp;
  2076. rate = drm_dp_bw_code_to_link_rate(dp->link->link_params.bw_code);
  2077. supported_rate_khz = link_info->num_lanes * rate * 8;
  2078. if (mode_rate_khz > supported_rate_khz) {
  2079. DP_DEBUG("mode_rate: %d kHz, supported_rate: %d kHz\n",
  2080. mode_rate_khz, supported_rate_khz);
  2081. return -EPERM;
  2082. }
  2083. return 0;
  2084. }
  2085. static int dp_display_validate_pixel_clock(struct dp_display_mode dp_mode,
  2086. u32 max_pclk_khz)
  2087. {
  2088. u32 pclk_khz = dp_mode.timing.widebus_en ?
  2089. (dp_mode.timing.pixel_clk_khz >> 1) :
  2090. dp_mode.timing.pixel_clk_khz;
  2091. if (pclk_khz > max_pclk_khz) {
  2092. DP_DEBUG("clk: %d kHz, max: %d kHz\n", pclk_khz, max_pclk_khz);
  2093. return -EPERM;
  2094. }
  2095. return 0;
  2096. }
  2097. static int dp_display_validate_mixers(struct msm_drm_private *priv,
  2098. struct drm_display_mode *mode,
  2099. const struct msm_resource_caps_info *avail_res)
  2100. {
  2101. int rc;
  2102. u32 num_lm = 0;
  2103. rc = msm_get_mixer_count(priv, mode, avail_res, &num_lm);
  2104. if (rc) {
  2105. DP_ERR("error getting mixer count. rc:%d\n", rc);
  2106. return rc;
  2107. }
  2108. if (num_lm > avail_res->num_lm) {
  2109. DP_DEBUG("num lm:%d > available lm:%d\n", num_lm,
  2110. avail_res->num_lm);
  2111. return -EPERM;
  2112. }
  2113. return 0;
  2114. }
  2115. static int dp_display_validate_dscs(struct msm_drm_private *priv,
  2116. struct dp_panel *dp_panel, struct drm_display_mode *mode,
  2117. struct dp_display_mode *dp_mode,
  2118. const struct msm_resource_caps_info *avail_res)
  2119. {
  2120. int rc;
  2121. u32 num_dsc = 0;
  2122. bool dsc_capable = dp_mode->capabilities & DP_PANEL_CAPS_DSC;
  2123. if (!dp_panel->dsc_en || !dsc_capable)
  2124. return 0;
  2125. rc = msm_get_dsc_count(priv, mode->hdisplay, &num_dsc);
  2126. if (rc) {
  2127. DP_ERR("error getting dsc count. rc:%d\n", rc);
  2128. return rc;
  2129. }
  2130. if (num_dsc > avail_res->num_dsc) {
  2131. DP_DEBUG("num dsc:%d > available dsc:%d\n", num_dsc,
  2132. avail_res->num_dsc);
  2133. return -EPERM;
  2134. }
  2135. return 0;
  2136. }
  2137. static int dp_display_validate_topology(struct dp_display_private *dp,
  2138. struct dp_panel *dp_panel, struct drm_display_mode *mode,
  2139. struct dp_display_mode *dp_mode,
  2140. const struct msm_resource_caps_info *avail_res)
  2141. {
  2142. int rc;
  2143. struct msm_drm_private *priv = dp->priv;
  2144. const u32 dual_lm = 2, quad_lm = 4;
  2145. u32 num_lm = 0, num_dsc = 0, num_3dmux = 0;
  2146. bool dsc_capable = dp_mode->capabilities & DP_PANEL_CAPS_DSC;
  2147. rc = msm_get_mixer_count(priv, mode, avail_res, &num_lm);
  2148. if (rc) {
  2149. DP_ERR("error getting mixer count. rc:%d\n", rc);
  2150. return rc;
  2151. }
  2152. num_3dmux = avail_res->num_3dmux;
  2153. if (dp_panel->dsc_en && dsc_capable) {
  2154. rc = msm_get_dsc_count(priv, mode->hdisplay, &num_dsc);
  2155. if (rc) {
  2156. DP_ERR("error getting dsc count. rc:%d\n", rc);
  2157. return rc;
  2158. }
  2159. }
  2160. /* filter out unsupported DP topologies */
  2161. if ((num_lm == dual_lm && (!num_3dmux && !num_dsc)) ||
  2162. (num_lm == quad_lm && (num_dsc != 4))) {
  2163. DP_DEBUG("invalid topology lm:%d dsc:%d 3dmux:%d intf:1\n",
  2164. num_lm, num_dsc, num_3dmux);
  2165. return -EPERM;
  2166. }
  2167. return 0;
  2168. }
  2169. static void dp_display_validate_mst_connectors(struct dp_debug *debug,
  2170. struct dp_panel *dp_panel, struct drm_display_mode *mode,
  2171. enum drm_mode_status *mode_status, bool *use_default)
  2172. {
  2173. struct dp_mst_connector *mst_connector;
  2174. int hdis, vdis, vref, ar, _hdis, _vdis, _vref, _ar;
  2175. bool in_list = false;
  2176. /*
  2177. * If the connector exists in the mst connector list and if debug is
  2178. * enabled for that connector, use the mst connector settings from the
  2179. * list for validation. Otherwise, use non-mst default settings.
  2180. */
  2181. mutex_lock(&debug->dp_mst_connector_list.lock);
  2182. if (list_empty(&debug->dp_mst_connector_list.list)) {
  2183. mutex_unlock(&debug->dp_mst_connector_list.lock);
  2184. *use_default = true;
  2185. return;
  2186. }
  2187. list_for_each_entry(mst_connector, &debug->dp_mst_connector_list.list,
  2188. list) {
  2189. if (mst_connector->con_id != dp_panel->connector->base.id)
  2190. continue;
  2191. in_list = true;
  2192. if (!mst_connector->debug_en) {
  2193. mutex_unlock(&debug->dp_mst_connector_list.lock);
  2194. *use_default = false;
  2195. *mode_status = MODE_OK;
  2196. return;
  2197. }
  2198. hdis = mst_connector->hdisplay;
  2199. vdis = mst_connector->vdisplay;
  2200. vref = mst_connector->vrefresh;
  2201. ar = mst_connector->aspect_ratio;
  2202. _hdis = mode->hdisplay;
  2203. _vdis = mode->vdisplay;
  2204. _vref = mode->vrefresh;
  2205. _ar = mode->picture_aspect_ratio;
  2206. if (hdis == _hdis && vdis == _vdis && vref == _vref &&
  2207. ar == _ar) {
  2208. mutex_unlock(&debug->dp_mst_connector_list.lock);
  2209. *use_default = false;
  2210. *mode_status = MODE_OK;
  2211. return;
  2212. }
  2213. break;
  2214. }
  2215. mutex_unlock(&debug->dp_mst_connector_list.lock);
  2216. if (in_list) {
  2217. *use_default = false;
  2218. return;
  2219. }
  2220. *use_default = true;
  2221. }
  2222. static enum drm_mode_status dp_display_validate_mode(
  2223. struct dp_display *dp_display,
  2224. void *panel, struct drm_display_mode *mode,
  2225. const struct msm_resource_caps_info *avail_res)
  2226. {
  2227. struct dp_display_private *dp;
  2228. struct dp_panel *dp_panel;
  2229. struct dp_debug *debug;
  2230. enum drm_mode_status mode_status = MODE_BAD;
  2231. struct dp_display_mode dp_mode;
  2232. int rc = 0;
  2233. bool use_default = true;
  2234. if (!dp_display || !mode || !panel ||
  2235. !avail_res || !avail_res->max_mixer_width) {
  2236. DP_ERR("invalid params\n");
  2237. return mode_status;
  2238. }
  2239. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2240. mutex_lock(&dp->session_lock);
  2241. dp_panel = panel;
  2242. if (!dp_panel->connector) {
  2243. DP_ERR("invalid connector\n");
  2244. goto end;
  2245. }
  2246. debug = dp->debug;
  2247. if (!debug)
  2248. goto end;
  2249. dp_display->convert_to_dp_mode(dp_display, panel, mode, &dp_mode);
  2250. rc = dp_display_validate_link_clock(dp, mode, dp_mode);
  2251. if (rc)
  2252. goto end;
  2253. rc = dp_display_validate_pixel_clock(dp_mode, dp_display->max_pclk_khz);
  2254. if (rc)
  2255. goto end;
  2256. rc = dp_display_validate_mixers(dp->priv, mode, avail_res);
  2257. if (rc)
  2258. goto end;
  2259. rc = dp_display_validate_dscs(dp->priv, panel, mode, &dp_mode,
  2260. avail_res);
  2261. if (rc)
  2262. goto end;
  2263. rc = dp_display_validate_topology(dp, dp_panel, mode,
  2264. &dp_mode, avail_res);
  2265. if (rc)
  2266. goto end;
  2267. dp_display_validate_mst_connectors(debug, dp_panel, mode, &mode_status,
  2268. &use_default);
  2269. if (!use_default)
  2270. goto end;
  2271. if (debug->debug_en && (mode->hdisplay != debug->hdisplay ||
  2272. mode->vdisplay != debug->vdisplay ||
  2273. mode->vrefresh != debug->vrefresh ||
  2274. mode->picture_aspect_ratio != debug->aspect_ratio))
  2275. goto end;
  2276. mode_status = MODE_OK;
  2277. end:
  2278. mutex_unlock(&dp->session_lock);
  2279. DP_DEBUG("[%s] mode is %s\n", mode->name,
  2280. (mode_status == MODE_OK) ? "valid" : "invalid");
  2281. return mode_status;
  2282. }
  2283. static int dp_display_get_available_dp_resources(struct dp_display *dp_display,
  2284. const struct msm_resource_caps_info *avail_res,
  2285. struct msm_resource_caps_info *max_dp_avail_res)
  2286. {
  2287. if (!dp_display || !avail_res || !max_dp_avail_res) {
  2288. DP_ERR("invalid arguments\n");
  2289. return -EINVAL;
  2290. }
  2291. memcpy(max_dp_avail_res, avail_res,
  2292. sizeof(struct msm_resource_caps_info));
  2293. max_dp_avail_res->num_lm = min(avail_res->num_lm,
  2294. dp_display->max_mixer_count);
  2295. max_dp_avail_res->num_dsc = min(avail_res->num_dsc,
  2296. dp_display->max_dsc_count);
  2297. DP_DEBUG("max_lm:%d, avail_lm:%d, dp_avail_lm:%d\n",
  2298. dp_display->max_mixer_count, avail_res->num_lm,
  2299. max_dp_avail_res->num_lm);
  2300. DP_DEBUG("max_dsc:%d, avail_dsc:%d, dp_avail_dsc:%d\n",
  2301. dp_display->max_dsc_count, avail_res->num_dsc,
  2302. max_dp_avail_res->num_dsc);
  2303. return 0;
  2304. }
  2305. static int dp_display_get_modes(struct dp_display *dp, void *panel,
  2306. struct dp_display_mode *dp_mode)
  2307. {
  2308. struct dp_display_private *dp_display;
  2309. struct dp_panel *dp_panel;
  2310. int ret = 0;
  2311. if (!dp || !panel) {
  2312. DP_ERR("invalid params\n");
  2313. return 0;
  2314. }
  2315. dp_panel = panel;
  2316. if (!dp_panel->connector) {
  2317. DP_ERR("invalid connector\n");
  2318. return 0;
  2319. }
  2320. dp_display = container_of(dp, struct dp_display_private, dp_display);
  2321. ret = dp_panel->get_modes(dp_panel, dp_panel->connector, dp_mode);
  2322. if (dp_mode->timing.pixel_clk_khz)
  2323. dp->max_pclk_khz = dp_mode->timing.pixel_clk_khz;
  2324. return ret;
  2325. }
  2326. static void dp_display_convert_to_dp_mode(struct dp_display *dp_display,
  2327. void *panel,
  2328. const struct drm_display_mode *drm_mode,
  2329. struct dp_display_mode *dp_mode)
  2330. {
  2331. int rc;
  2332. struct dp_display_private *dp;
  2333. struct dp_panel *dp_panel;
  2334. u32 free_dsc_blks = 0, required_dsc_blks = 0;
  2335. if (!dp_display || !drm_mode || !dp_mode || !panel) {
  2336. DP_ERR("invalid input\n");
  2337. return;
  2338. }
  2339. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2340. dp_panel = panel;
  2341. memset(dp_mode, 0, sizeof(*dp_mode));
  2342. free_dsc_blks = dp_display->max_dsc_count -
  2343. dp->tot_dsc_blks_in_use +
  2344. dp_panel->tot_dsc_blks_in_use;
  2345. rc = msm_get_dsc_count(dp->priv, drm_mode->hdisplay,
  2346. &required_dsc_blks);
  2347. if (rc) {
  2348. DP_ERR("error getting dsc count. rc:%d\n", rc);
  2349. return;
  2350. }
  2351. if (free_dsc_blks >= required_dsc_blks)
  2352. dp_mode->capabilities |= DP_PANEL_CAPS_DSC;
  2353. if (dp_mode->capabilities & DP_PANEL_CAPS_DSC)
  2354. DP_DEBUG("in_use:%d, max:%d, free:%d, req:%d, caps:0x%x\n",
  2355. dp->tot_dsc_blks_in_use,
  2356. dp_display->max_dsc_count,
  2357. free_dsc_blks, required_dsc_blks,
  2358. dp_mode->capabilities);
  2359. dp_panel->convert_to_dp_mode(dp_panel, drm_mode, dp_mode);
  2360. }
  2361. static int dp_display_config_hdr(struct dp_display *dp_display, void *panel,
  2362. struct drm_msm_ext_hdr_metadata *hdr, bool dhdr_update)
  2363. {
  2364. struct dp_panel *dp_panel;
  2365. struct sde_connector *sde_conn;
  2366. struct dp_display_private *dp;
  2367. u64 core_clk_rate;
  2368. bool flush_hdr;
  2369. if (!dp_display || !panel) {
  2370. DP_ERR("invalid input\n");
  2371. return -EINVAL;
  2372. }
  2373. dp_panel = panel;
  2374. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2375. sde_conn = to_sde_connector(dp_panel->connector);
  2376. core_clk_rate = dp->power->clk_get_rate(dp->power, "core_clk");
  2377. if (!core_clk_rate) {
  2378. DP_ERR("invalid rate for core_clk\n");
  2379. return -EINVAL;
  2380. }
  2381. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2382. dp_display_state_show("[not enabled]");
  2383. return 0;
  2384. }
  2385. /*
  2386. * In rare cases where HDR metadata is updated independently
  2387. * flush the HDR metadata immediately instead of relying on
  2388. * the colorspace
  2389. */
  2390. flush_hdr = !sde_conn->colorspace_updated;
  2391. if (flush_hdr)
  2392. DP_DEBUG("flushing the HDR metadata\n");
  2393. else
  2394. DP_DEBUG("piggy-backing with colorspace\n");
  2395. return dp_panel->setup_hdr(dp_panel, hdr, dhdr_update,
  2396. core_clk_rate, flush_hdr);
  2397. }
  2398. static int dp_display_setup_colospace(struct dp_display *dp_display,
  2399. void *panel,
  2400. u32 colorspace)
  2401. {
  2402. struct dp_panel *dp_panel;
  2403. struct dp_display_private *dp;
  2404. if (!dp_display || !panel) {
  2405. pr_err("invalid input\n");
  2406. return -EINVAL;
  2407. }
  2408. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2409. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2410. dp_display_state_show("[not enabled]");
  2411. return 0;
  2412. }
  2413. dp_panel = panel;
  2414. return dp_panel->set_colorspace(dp_panel, colorspace);
  2415. }
  2416. static int dp_display_create_workqueue(struct dp_display_private *dp)
  2417. {
  2418. dp->wq = create_singlethread_workqueue("drm_dp");
  2419. if (IS_ERR_OR_NULL(dp->wq)) {
  2420. DP_ERR("Error creating wq\n");
  2421. return -EPERM;
  2422. }
  2423. INIT_DELAYED_WORK(&dp->hdcp_cb_work, dp_display_hdcp_cb_work);
  2424. INIT_WORK(&dp->connect_work, dp_display_connect_work);
  2425. INIT_WORK(&dp->attention_work, dp_display_attention_work);
  2426. return 0;
  2427. }
  2428. static int dp_display_fsa4480_callback(struct notifier_block *self,
  2429. unsigned long event, void *data)
  2430. {
  2431. return 0;
  2432. }
  2433. static int dp_display_init_aux_switch(struct dp_display_private *dp)
  2434. {
  2435. int rc = 0;
  2436. const char *phandle = "qcom,dp-aux-switch";
  2437. struct notifier_block nb;
  2438. if (!dp->pdev->dev.of_node) {
  2439. DP_ERR("cannot find dev.of_node\n");
  2440. rc = -ENODEV;
  2441. goto end;
  2442. }
  2443. dp->aux_switch_node = of_parse_phandle(dp->pdev->dev.of_node,
  2444. phandle, 0);
  2445. if (!dp->aux_switch_node) {
  2446. DP_WARN("cannot parse %s handle\n", phandle);
  2447. rc = -ENODEV;
  2448. goto end;
  2449. }
  2450. nb.notifier_call = dp_display_fsa4480_callback;
  2451. nb.priority = 0;
  2452. rc = fsa4480_reg_notifier(&nb, dp->aux_switch_node);
  2453. if (rc) {
  2454. DP_ERR("failed to register notifier (%d)\n", rc);
  2455. goto end;
  2456. }
  2457. fsa4480_unreg_notifier(&nb, dp->aux_switch_node);
  2458. end:
  2459. return rc;
  2460. }
  2461. static int dp_display_mst_install(struct dp_display *dp_display,
  2462. struct dp_mst_drm_install_info *mst_install_info)
  2463. {
  2464. struct dp_display_private *dp;
  2465. if (!dp_display || !mst_install_info) {
  2466. DP_ERR("invalid input\n");
  2467. return -EINVAL;
  2468. }
  2469. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2470. if (!mst_install_info->cbs->hpd || !mst_install_info->cbs->hpd_irq) {
  2471. DP_ERR("invalid mst cbs\n");
  2472. return -EINVAL;
  2473. }
  2474. dp_display->dp_mst_prv_info = mst_install_info->dp_mst_prv_info;
  2475. if (!dp->parser->has_mst) {
  2476. DP_DEBUG("mst not enabled\n");
  2477. return -EPERM;
  2478. }
  2479. memcpy(&dp->mst.cbs, mst_install_info->cbs, sizeof(dp->mst.cbs));
  2480. dp->mst.drm_registered = true;
  2481. DP_MST_DEBUG("dp mst drm installed\n");
  2482. return 0;
  2483. }
  2484. static int dp_display_mst_uninstall(struct dp_display *dp_display)
  2485. {
  2486. struct dp_display_private *dp;
  2487. if (!dp_display) {
  2488. DP_ERR("invalid input\n");
  2489. return -EINVAL;
  2490. }
  2491. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2492. if (!dp->mst.drm_registered) {
  2493. DP_DEBUG("drm mst not registered\n");
  2494. return -EPERM;
  2495. }
  2496. dp = container_of(dp_display, struct dp_display_private,
  2497. dp_display);
  2498. memset(&dp->mst.cbs, 0, sizeof(dp->mst.cbs));
  2499. dp->mst.drm_registered = false;
  2500. DP_MST_DEBUG("dp mst drm uninstalled\n");
  2501. return 0;
  2502. }
  2503. static int dp_display_mst_connector_install(struct dp_display *dp_display,
  2504. struct drm_connector *connector)
  2505. {
  2506. int rc = 0;
  2507. struct dp_panel_in panel_in;
  2508. struct dp_panel *dp_panel;
  2509. struct dp_display_private *dp;
  2510. struct dp_mst_connector *mst_connector;
  2511. struct dp_mst_connector *cached_connector;
  2512. if (!dp_display || !connector) {
  2513. DP_ERR("invalid input\n");
  2514. return -EINVAL;
  2515. }
  2516. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2517. mutex_lock(&dp->session_lock);
  2518. if (!dp->mst.drm_registered) {
  2519. DP_DEBUG("drm mst not registered\n");
  2520. mutex_unlock(&dp->session_lock);
  2521. return -EPERM;
  2522. }
  2523. panel_in.dev = &dp->pdev->dev;
  2524. panel_in.aux = dp->aux;
  2525. panel_in.catalog = &dp->catalog->panel;
  2526. panel_in.link = dp->link;
  2527. panel_in.connector = connector;
  2528. panel_in.base_panel = dp->panel;
  2529. panel_in.parser = dp->parser;
  2530. dp_panel = dp_panel_get(&panel_in);
  2531. if (IS_ERR(dp_panel)) {
  2532. rc = PTR_ERR(dp_panel);
  2533. DP_ERR("failed to initialize panel, rc = %d\n", rc);
  2534. mutex_unlock(&dp->session_lock);
  2535. return rc;
  2536. }
  2537. dp_panel->audio = dp_audio_get(dp->pdev, dp_panel, &dp->catalog->audio);
  2538. if (IS_ERR(dp_panel->audio)) {
  2539. rc = PTR_ERR(dp_panel->audio);
  2540. DP_ERR("[mst] failed to initialize audio, rc = %d\n", rc);
  2541. dp_panel->audio = NULL;
  2542. mutex_unlock(&dp->session_lock);
  2543. return rc;
  2544. }
  2545. DP_MST_DEBUG("dp mst connector installed. conn:%d\n",
  2546. connector->base.id);
  2547. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  2548. mst_connector = kmalloc(sizeof(struct dp_mst_connector),
  2549. GFP_KERNEL);
  2550. if (!mst_connector) {
  2551. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  2552. mutex_unlock(&dp->session_lock);
  2553. return -ENOMEM;
  2554. }
  2555. cached_connector = &dp->debug->mst_connector_cache;
  2556. if (cached_connector->debug_en) {
  2557. mst_connector->debug_en = true;
  2558. mst_connector->hdisplay = cached_connector->hdisplay;
  2559. mst_connector->vdisplay = cached_connector->vdisplay;
  2560. mst_connector->vrefresh = cached_connector->vrefresh;
  2561. mst_connector->aspect_ratio = cached_connector->aspect_ratio;
  2562. memset(cached_connector, 0, sizeof(*cached_connector));
  2563. dp->debug->set_mst_con(dp->debug, connector->base.id);
  2564. } else {
  2565. mst_connector->debug_en = false;
  2566. }
  2567. mst_connector->conn = connector;
  2568. mst_connector->con_id = connector->base.id;
  2569. mst_connector->state = connector_status_unknown;
  2570. INIT_LIST_HEAD(&mst_connector->list);
  2571. list_add(&mst_connector->list,
  2572. &dp->debug->dp_mst_connector_list.list);
  2573. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  2574. mutex_unlock(&dp->session_lock);
  2575. return 0;
  2576. }
  2577. static int dp_display_mst_connector_uninstall(struct dp_display *dp_display,
  2578. struct drm_connector *connector)
  2579. {
  2580. int rc = 0;
  2581. struct sde_connector *sde_conn;
  2582. struct dp_panel *dp_panel;
  2583. struct dp_display_private *dp;
  2584. struct dp_mst_connector *con_to_remove, *temp_con;
  2585. if (!dp_display || !connector) {
  2586. DP_ERR("invalid input\n");
  2587. return -EINVAL;
  2588. }
  2589. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2590. mutex_lock(&dp->session_lock);
  2591. if (!dp->mst.drm_registered) {
  2592. DP_DEBUG("drm mst not registered\n");
  2593. mutex_unlock(&dp->session_lock);
  2594. return -EPERM;
  2595. }
  2596. sde_conn = to_sde_connector(connector);
  2597. if (!sde_conn->drv_panel) {
  2598. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2599. mutex_unlock(&dp->session_lock);
  2600. return -EINVAL;
  2601. }
  2602. dp_panel = sde_conn->drv_panel;
  2603. dp_audio_put(dp_panel->audio);
  2604. dp_panel_put(dp_panel);
  2605. DP_MST_DEBUG("dp mst connector uninstalled. conn:%d\n",
  2606. connector->base.id);
  2607. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  2608. list_for_each_entry_safe(con_to_remove, temp_con,
  2609. &dp->debug->dp_mst_connector_list.list, list) {
  2610. if (con_to_remove->conn == connector) {
  2611. /*
  2612. * cache any debug info if enabled that can be applied
  2613. * on new connectors.
  2614. */
  2615. if (con_to_remove->debug_en)
  2616. memcpy(&dp->debug->mst_connector_cache,
  2617. con_to_remove,
  2618. sizeof(*con_to_remove));
  2619. list_del(&con_to_remove->list);
  2620. kfree(con_to_remove);
  2621. }
  2622. }
  2623. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  2624. mutex_unlock(&dp->session_lock);
  2625. return rc;
  2626. }
  2627. static int dp_display_mst_get_connector_info(struct dp_display *dp_display,
  2628. struct drm_connector *connector,
  2629. struct dp_mst_connector *mst_conn)
  2630. {
  2631. struct dp_display_private *dp;
  2632. struct dp_mst_connector *conn, *temp_conn;
  2633. if (!connector || !mst_conn) {
  2634. DP_ERR("invalid input\n");
  2635. return -EINVAL;
  2636. }
  2637. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2638. mutex_lock(&dp->session_lock);
  2639. if (!dp->mst.drm_registered) {
  2640. DP_DEBUG("drm mst not registered\n");
  2641. mutex_unlock(&dp->session_lock);
  2642. return -EPERM;
  2643. }
  2644. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  2645. list_for_each_entry_safe(conn, temp_conn,
  2646. &dp->debug->dp_mst_connector_list.list, list) {
  2647. if (conn->con_id == connector->base.id)
  2648. memcpy(mst_conn, conn, sizeof(*mst_conn));
  2649. }
  2650. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  2651. mutex_unlock(&dp->session_lock);
  2652. return 0;
  2653. }
  2654. static int dp_display_mst_connector_update_edid(struct dp_display *dp_display,
  2655. struct drm_connector *connector,
  2656. struct edid *edid)
  2657. {
  2658. int rc = 0;
  2659. struct sde_connector *sde_conn;
  2660. struct dp_panel *dp_panel;
  2661. struct dp_display_private *dp;
  2662. if (!dp_display || !connector || !edid) {
  2663. DP_ERR("invalid input\n");
  2664. return -EINVAL;
  2665. }
  2666. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2667. if (!dp->mst.drm_registered) {
  2668. DP_DEBUG("drm mst not registered\n");
  2669. return -EPERM;
  2670. }
  2671. sde_conn = to_sde_connector(connector);
  2672. if (!sde_conn->drv_panel) {
  2673. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2674. return -EINVAL;
  2675. }
  2676. dp_panel = sde_conn->drv_panel;
  2677. rc = dp_panel->update_edid(dp_panel, edid);
  2678. DP_MST_DEBUG("dp mst connector:%d edid updated. mode_cnt:%d\n",
  2679. connector->base.id, rc);
  2680. return rc;
  2681. }
  2682. static int dp_display_update_pps(struct dp_display *dp_display,
  2683. struct drm_connector *connector, char *pps_cmd)
  2684. {
  2685. struct sde_connector *sde_conn;
  2686. struct dp_panel *dp_panel;
  2687. struct dp_display_private *dp;
  2688. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2689. sde_conn = to_sde_connector(connector);
  2690. if (!sde_conn->drv_panel) {
  2691. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2692. return -EINVAL;
  2693. }
  2694. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2695. dp_display_state_show("[not enabled]");
  2696. return 0;
  2697. }
  2698. dp_panel = sde_conn->drv_panel;
  2699. dp_panel->update_pps(dp_panel, pps_cmd);
  2700. return 0;
  2701. }
  2702. static int dp_display_mst_connector_update_link_info(
  2703. struct dp_display *dp_display,
  2704. struct drm_connector *connector)
  2705. {
  2706. int rc = 0;
  2707. struct sde_connector *sde_conn;
  2708. struct dp_panel *dp_panel;
  2709. struct dp_display_private *dp;
  2710. if (!dp_display || !connector) {
  2711. DP_ERR("invalid input\n");
  2712. return -EINVAL;
  2713. }
  2714. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2715. if (!dp->mst.drm_registered) {
  2716. DP_DEBUG("drm mst not registered\n");
  2717. return -EPERM;
  2718. }
  2719. sde_conn = to_sde_connector(connector);
  2720. if (!sde_conn->drv_panel) {
  2721. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2722. return -EINVAL;
  2723. }
  2724. dp_panel = sde_conn->drv_panel;
  2725. memcpy(dp_panel->dpcd, dp->panel->dpcd,
  2726. DP_RECEIVER_CAP_SIZE + 1);
  2727. memcpy(dp_panel->dsc_dpcd, dp->panel->dsc_dpcd,
  2728. DP_RECEIVER_DSC_CAP_SIZE + 1);
  2729. memcpy(&dp_panel->link_info, &dp->panel->link_info,
  2730. sizeof(dp_panel->link_info));
  2731. DP_MST_DEBUG("dp mst connector:%d link info updated\n",
  2732. connector->base.id);
  2733. return rc;
  2734. }
  2735. static int dp_display_mst_get_fixed_topology_port(
  2736. struct dp_display *dp_display,
  2737. u32 strm_id, u32 *port_num)
  2738. {
  2739. struct dp_display_private *dp;
  2740. u32 port;
  2741. if (!dp_display) {
  2742. DP_ERR("invalid input\n");
  2743. return -EINVAL;
  2744. }
  2745. if (strm_id >= DP_STREAM_MAX) {
  2746. DP_ERR("invalid stream id:%d\n", strm_id);
  2747. return -EINVAL;
  2748. }
  2749. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2750. port = dp->parser->mst_fixed_port[strm_id];
  2751. if (!port || port > 255)
  2752. return -ENOENT;
  2753. if (port_num)
  2754. *port_num = port;
  2755. return 0;
  2756. }
  2757. static int dp_display_get_mst_caps(struct dp_display *dp_display,
  2758. struct dp_mst_caps *mst_caps)
  2759. {
  2760. int rc = 0;
  2761. struct dp_display_private *dp;
  2762. if (!dp_display || !mst_caps) {
  2763. DP_ERR("invalid input\n");
  2764. return -EINVAL;
  2765. }
  2766. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2767. mst_caps->has_mst = dp->parser->has_mst;
  2768. mst_caps->max_streams_supported = (mst_caps->has_mst) ? 2 : 0;
  2769. mst_caps->max_dpcd_transaction_bytes = (mst_caps->has_mst) ? 16 : 0;
  2770. mst_caps->drm_aux = dp->aux->drm_aux;
  2771. return rc;
  2772. }
  2773. static void dp_display_wakeup_phy_layer(struct dp_display *dp_display,
  2774. bool wakeup)
  2775. {
  2776. struct dp_display_private *dp;
  2777. struct dp_hpd *hpd;
  2778. if (!dp_display) {
  2779. DP_ERR("invalid input\n");
  2780. return;
  2781. }
  2782. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2783. if (!dp->mst.drm_registered) {
  2784. DP_DEBUG("drm mst not registered\n");
  2785. return;
  2786. }
  2787. hpd = dp->hpd;
  2788. if (hpd && hpd->wakeup_phy)
  2789. hpd->wakeup_phy(hpd, wakeup);
  2790. }
  2791. static int dp_display_probe(struct platform_device *pdev)
  2792. {
  2793. int rc = 0;
  2794. struct dp_display_private *dp;
  2795. if (!pdev || !pdev->dev.of_node) {
  2796. DP_ERR("pdev not found\n");
  2797. rc = -ENODEV;
  2798. goto bail;
  2799. }
  2800. dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
  2801. if (!dp) {
  2802. rc = -ENOMEM;
  2803. goto bail;
  2804. }
  2805. init_completion(&dp->notification_comp);
  2806. dp->pdev = pdev;
  2807. dp->name = "drm_dp";
  2808. memset(&dp->mst, 0, sizeof(dp->mst));
  2809. rc = dp_display_init_aux_switch(dp);
  2810. if (rc) {
  2811. rc = -EPROBE_DEFER;
  2812. goto error;
  2813. }
  2814. rc = dp_display_create_workqueue(dp);
  2815. if (rc) {
  2816. DP_ERR("Failed to create workqueue\n");
  2817. goto error;
  2818. }
  2819. platform_set_drvdata(pdev, dp);
  2820. g_dp_display = &dp->dp_display;
  2821. g_dp_display->enable = dp_display_enable;
  2822. g_dp_display->post_enable = dp_display_post_enable;
  2823. g_dp_display->pre_disable = dp_display_pre_disable;
  2824. g_dp_display->disable = dp_display_disable;
  2825. g_dp_display->set_mode = dp_display_set_mode;
  2826. g_dp_display->validate_mode = dp_display_validate_mode;
  2827. g_dp_display->get_modes = dp_display_get_modes;
  2828. g_dp_display->prepare = dp_display_prepare;
  2829. g_dp_display->unprepare = dp_display_unprepare;
  2830. g_dp_display->request_irq = dp_request_irq;
  2831. g_dp_display->get_debug = dp_get_debug;
  2832. g_dp_display->post_open = NULL;
  2833. g_dp_display->post_init = dp_display_post_init;
  2834. g_dp_display->config_hdr = dp_display_config_hdr;
  2835. g_dp_display->mst_install = dp_display_mst_install;
  2836. g_dp_display->mst_uninstall = dp_display_mst_uninstall;
  2837. g_dp_display->mst_connector_install = dp_display_mst_connector_install;
  2838. g_dp_display->mst_connector_uninstall =
  2839. dp_display_mst_connector_uninstall;
  2840. g_dp_display->mst_connector_update_edid =
  2841. dp_display_mst_connector_update_edid;
  2842. g_dp_display->mst_connector_update_link_info =
  2843. dp_display_mst_connector_update_link_info;
  2844. g_dp_display->get_mst_caps = dp_display_get_mst_caps;
  2845. g_dp_display->set_stream_info = dp_display_set_stream_info;
  2846. g_dp_display->update_pps = dp_display_update_pps;
  2847. g_dp_display->convert_to_dp_mode = dp_display_convert_to_dp_mode;
  2848. g_dp_display->mst_get_connector_info =
  2849. dp_display_mst_get_connector_info;
  2850. g_dp_display->mst_get_fixed_topology_port =
  2851. dp_display_mst_get_fixed_topology_port;
  2852. g_dp_display->wakeup_phy_layer =
  2853. dp_display_wakeup_phy_layer;
  2854. g_dp_display->set_colorspace = dp_display_setup_colospace;
  2855. g_dp_display->get_available_dp_resources =
  2856. dp_display_get_available_dp_resources;
  2857. rc = component_add(&pdev->dev, &dp_display_comp_ops);
  2858. if (rc) {
  2859. DP_ERR("component add failed, rc=%d\n", rc);
  2860. goto error;
  2861. }
  2862. return 0;
  2863. error:
  2864. devm_kfree(&pdev->dev, dp);
  2865. bail:
  2866. return rc;
  2867. }
  2868. int dp_display_get_displays(void **displays, int count)
  2869. {
  2870. if (!displays) {
  2871. DP_ERR("invalid data\n");
  2872. return -EINVAL;
  2873. }
  2874. if (count != 1) {
  2875. DP_ERR("invalid number of displays\n");
  2876. return -EINVAL;
  2877. }
  2878. displays[0] = g_dp_display;
  2879. return count;
  2880. }
  2881. int dp_display_get_num_of_displays(void)
  2882. {
  2883. if (!g_dp_display)
  2884. return 0;
  2885. return 1;
  2886. }
  2887. int dp_display_get_num_of_streams(void)
  2888. {
  2889. return DP_STREAM_MAX;
  2890. }
  2891. static void dp_display_set_mst_state(void *dp_display,
  2892. enum dp_drv_state mst_state)
  2893. {
  2894. struct dp_display_private *dp;
  2895. if (!g_dp_display) {
  2896. DP_DEBUG("dp display not initialized\n");
  2897. return;
  2898. }
  2899. dp = container_of(g_dp_display, struct dp_display_private, dp_display);
  2900. if (dp->mst.mst_active && dp->mst.cbs.set_drv_state)
  2901. dp->mst.cbs.set_drv_state(g_dp_display, mst_state);
  2902. }
  2903. static int dp_display_remove(struct platform_device *pdev)
  2904. {
  2905. struct dp_display_private *dp;
  2906. if (!pdev)
  2907. return -EINVAL;
  2908. dp = platform_get_drvdata(pdev);
  2909. dp_display_deinit_sub_modules(dp);
  2910. if (dp->wq)
  2911. destroy_workqueue(dp->wq);
  2912. platform_set_drvdata(pdev, NULL);
  2913. devm_kfree(&pdev->dev, dp);
  2914. return 0;
  2915. }
  2916. static int dp_pm_prepare(struct device *dev)
  2917. {
  2918. struct dp_display_private *dp = container_of(g_dp_display,
  2919. struct dp_display_private, dp_display);
  2920. mutex_lock(&dp->session_lock);
  2921. dp_display_set_mst_state(g_dp_display, PM_SUSPEND);
  2922. /*
  2923. * There are a few instances where the DP is hotplugged when the device
  2924. * is in PM suspend state. After hotplug, it is observed the device
  2925. * enters and exits the PM suspend multiple times while aux transactions
  2926. * are taking place. This may sometimes cause an unclocked register
  2927. * access error. So, abort aux transactions when such a situation
  2928. * arises i.e. when DP is connected but display not enabled yet.
  2929. */
  2930. if (dp_display_state_is(DP_STATE_CONNECTED) &&
  2931. !dp_display_state_is(DP_STATE_ENABLED)) {
  2932. dp->aux->abort(dp->aux, true);
  2933. dp->ctrl->abort(dp->ctrl, true);
  2934. }
  2935. dp_display_state_add(DP_STATE_SUSPENDED);
  2936. mutex_unlock(&dp->session_lock);
  2937. return 0;
  2938. }
  2939. static void dp_pm_complete(struct device *dev)
  2940. {
  2941. struct dp_display_private *dp = container_of(g_dp_display,
  2942. struct dp_display_private, dp_display);
  2943. mutex_lock(&dp->session_lock);
  2944. dp_display_set_mst_state(g_dp_display, PM_DEFAULT);
  2945. /*
  2946. * There are multiple PM suspend entry and exits observed before
  2947. * the connect uevent is issued to userspace. The aux transactions are
  2948. * aborted during PM suspend entry in dp_pm_prepare to prevent unclocked
  2949. * register access. On PM suspend exit, there will be no host_init call
  2950. * to reset the abort flags for ctrl and aux incase DP is connected
  2951. * but display not enabled. So, resetting abort flags for aux and ctrl.
  2952. */
  2953. if (dp_display_state_is(DP_STATE_CONNECTED) &&
  2954. !dp_display_state_is(DP_STATE_ENABLED)) {
  2955. dp->aux->abort(dp->aux, false);
  2956. dp->ctrl->abort(dp->ctrl, false);
  2957. }
  2958. dp_display_state_remove(DP_STATE_SUSPENDED);
  2959. mutex_unlock(&dp->session_lock);
  2960. }
  2961. static const struct dev_pm_ops dp_pm_ops = {
  2962. .prepare = dp_pm_prepare,
  2963. .complete = dp_pm_complete,
  2964. };
  2965. static struct platform_driver dp_display_driver = {
  2966. .probe = dp_display_probe,
  2967. .remove = dp_display_remove,
  2968. .driver = {
  2969. .name = "msm-dp-display",
  2970. .of_match_table = dp_dt_match,
  2971. .suppress_bind_attrs = true,
  2972. .pm = &dp_pm_ops,
  2973. },
  2974. };
  2975. void __init dp_display_register(void)
  2976. {
  2977. platform_driver_register(&dp_display_driver);
  2978. }
  2979. void __exit dp_display_unregister(void)
  2980. {
  2981. platform_driver_unregister(&dp_display_driver);
  2982. }