dp_display.c 93 KB

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