dp_display.c 75 KB

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