dp_display.c 95 KB

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