dp_display.c 100 KB

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