dp_display.c 94 KB

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