dp_display.c 93 KB

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