dp_display.c 89 KB

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