dp_display.c 95 KB

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