dp_display.c 98 KB

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