dp_display.c 81 KB

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