dp_display.c 82 KB

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