dp_display.c 83 KB

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