dp_display.c 98 KB

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