dp_display.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "[drm-dp] %s: " fmt, __func__
  6. #include <linux/module.h>
  7. #include <linux/slab.h>
  8. #include <linux/uaccess.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/component.h>
  11. #include <linux/of_irq.h>
  12. #include <linux/extcon.h>
  13. #include <linux/soc/qcom/fsa4480-i2c.h>
  14. #include <linux/usb/usbpd.h>
  15. #include "sde_connector.h"
  16. #include "msm_drv.h"
  17. #include "dp_hpd.h"
  18. #include "dp_parser.h"
  19. #include "dp_power.h"
  20. #include "dp_catalog.h"
  21. #include "dp_aux.h"
  22. #include "dp_link.h"
  23. #include "dp_panel.h"
  24. #include "dp_ctrl.h"
  25. #include "dp_audio.h"
  26. #include "dp_display.h"
  27. #include "sde_hdcp.h"
  28. #include "dp_debug.h"
  29. #define DP_MST_DEBUG(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
  30. static struct dp_display *g_dp_display;
  31. #define HPD_STRING_SIZE 30
  32. struct dp_hdcp_dev {
  33. void *fd;
  34. struct sde_hdcp_ops *ops;
  35. enum sde_hdcp_version ver;
  36. };
  37. struct dp_hdcp {
  38. void *data;
  39. struct sde_hdcp_ops *ops;
  40. u32 source_cap;
  41. struct dp_hdcp_dev dev[HDCP_VERSION_MAX];
  42. };
  43. struct dp_mst {
  44. bool mst_active;
  45. bool drm_registered;
  46. struct dp_mst_drm_cbs cbs;
  47. };
  48. struct dp_display_private {
  49. char *name;
  50. int irq;
  51. /* state variables */
  52. bool core_initialized;
  53. bool power_on;
  54. bool is_connected;
  55. atomic_t aborted;
  56. struct platform_device *pdev;
  57. struct device_node *aux_switch_node;
  58. struct dentry *root;
  59. struct completion notification_comp;
  60. struct dp_hpd *hpd;
  61. struct dp_parser *parser;
  62. struct dp_power *power;
  63. struct dp_catalog *catalog;
  64. struct dp_aux *aux;
  65. struct dp_link *link;
  66. struct dp_panel *panel;
  67. struct dp_ctrl *ctrl;
  68. struct dp_debug *debug;
  69. struct dp_panel *active_panels[DP_STREAM_MAX];
  70. struct dp_hdcp hdcp;
  71. struct dp_hpd_cb hpd_cb;
  72. struct dp_display_mode mode;
  73. struct dp_display dp_display;
  74. struct msm_drm_private *priv;
  75. struct workqueue_struct *wq;
  76. struct delayed_work hdcp_cb_work;
  77. struct work_struct connect_work;
  78. struct work_struct attention_work;
  79. struct mutex session_lock;
  80. u32 active_stream_cnt;
  81. struct dp_mst mst;
  82. u32 tot_dsc_blks_in_use;
  83. bool process_hpd_connect;
  84. struct notifier_block usb_nb;
  85. };
  86. static const struct of_device_id dp_dt_match[] = {
  87. {.compatible = "qcom,dp-display"},
  88. {}
  89. };
  90. static inline bool dp_display_is_hdcp_enabled(struct dp_display_private *dp)
  91. {
  92. return dp->link->hdcp_status.hdcp_version && dp->hdcp.ops;
  93. }
  94. static irqreturn_t dp_display_irq(int irq, void *dev_id)
  95. {
  96. struct dp_display_private *dp = dev_id;
  97. if (!dp) {
  98. pr_err("invalid data\n");
  99. return IRQ_NONE;
  100. }
  101. /* DP HPD isr */
  102. if (dp->hpd->type == DP_HPD_LPHW)
  103. dp->hpd->isr(dp->hpd);
  104. /* DP controller isr */
  105. dp->ctrl->isr(dp->ctrl);
  106. /* DP aux isr */
  107. dp->aux->isr(dp->aux);
  108. /* HDCP isr */
  109. if (dp_display_is_hdcp_enabled(dp) && dp->hdcp.ops->isr) {
  110. if (dp->hdcp.ops->isr(dp->hdcp.data))
  111. pr_err("dp_hdcp_isr failed\n");
  112. }
  113. return IRQ_HANDLED;
  114. }
  115. static bool dp_display_is_ds_bridge(struct dp_panel *panel)
  116. {
  117. return (panel->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  118. DP_DWN_STRM_PORT_PRESENT);
  119. }
  120. static bool dp_display_is_sink_count_zero(struct dp_display_private *dp)
  121. {
  122. return dp_display_is_ds_bridge(dp->panel) &&
  123. (dp->link->sink_count.count == 0);
  124. }
  125. static bool dp_display_is_ready(struct dp_display_private *dp)
  126. {
  127. return dp->hpd->hpd_high && dp->is_connected &&
  128. !dp_display_is_sink_count_zero(dp) &&
  129. dp->hpd->alt_mode_cfg_done;
  130. }
  131. static void dp_display_update_hdcp_status(struct dp_display_private *dp,
  132. bool reset)
  133. {
  134. if (reset) {
  135. dp->link->hdcp_status.hdcp_state = HDCP_STATE_INACTIVE;
  136. dp->link->hdcp_status.hdcp_version = HDCP_VERSION_NONE;
  137. }
  138. memset(dp->debug->hdcp_status, 0, sizeof(dp->debug->hdcp_status));
  139. snprintf(dp->debug->hdcp_status, sizeof(dp->debug->hdcp_status),
  140. "%s: %s\ncaps: %d\n",
  141. sde_hdcp_version(dp->link->hdcp_status.hdcp_version),
  142. sde_hdcp_state_name(dp->link->hdcp_status.hdcp_state),
  143. dp->hdcp.source_cap);
  144. }
  145. static void dp_display_update_hdcp_info(struct dp_display_private *dp)
  146. {
  147. void *fd = NULL;
  148. struct dp_hdcp_dev *dev = NULL;
  149. struct sde_hdcp_ops *ops = NULL;
  150. int i = HDCP_VERSION_2P2;
  151. dp_display_update_hdcp_status(dp, true);
  152. dp->hdcp.data = NULL;
  153. dp->hdcp.ops = NULL;
  154. if (dp->debug->hdcp_disabled || dp->debug->sim_mode)
  155. return;
  156. while (i) {
  157. dev = &dp->hdcp.dev[i];
  158. ops = dev->ops;
  159. fd = dev->fd;
  160. i >>= 1;
  161. if (!(dp->hdcp.source_cap & dev->ver))
  162. continue;
  163. if (ops->sink_support(fd)) {
  164. dp->hdcp.data = fd;
  165. dp->hdcp.ops = ops;
  166. dp->link->hdcp_status.hdcp_version = dev->ver;
  167. break;
  168. }
  169. }
  170. pr_debug("HDCP version supported: %s\n",
  171. sde_hdcp_version(dp->link->hdcp_status.hdcp_version));
  172. }
  173. static void dp_display_check_source_hdcp_caps(struct dp_display_private *dp)
  174. {
  175. int i;
  176. struct dp_hdcp_dev *hdcp_dev = dp->hdcp.dev;
  177. if (dp->debug->hdcp_disabled) {
  178. pr_debug("hdcp disabled\n");
  179. return;
  180. }
  181. for (i = 0; i < HDCP_VERSION_MAX; i++) {
  182. struct dp_hdcp_dev *dev = &hdcp_dev[i];
  183. struct sde_hdcp_ops *ops = dev->ops;
  184. void *fd = dev->fd;
  185. if (!fd || !ops)
  186. continue;
  187. if (ops->set_mode && ops->set_mode(fd, dp->mst.mst_active))
  188. continue;
  189. if (!(dp->hdcp.source_cap & dev->ver) &&
  190. ops->feature_supported &&
  191. ops->feature_supported(fd))
  192. dp->hdcp.source_cap |= dev->ver;
  193. }
  194. dp_display_update_hdcp_status(dp, false);
  195. }
  196. static void dp_display_hdcp_register_streams(struct dp_display_private *dp)
  197. {
  198. int rc;
  199. size_t i;
  200. struct sde_hdcp_ops *ops = dp->hdcp.ops;
  201. void *data = dp->hdcp.data;
  202. if (dp_display_is_ready(dp) && dp->mst.mst_active && ops &&
  203. ops->register_streams){
  204. struct stream_info streams[DP_STREAM_MAX];
  205. int index = 0;
  206. pr_debug("Registering all active panel streams with HDCP\n");
  207. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  208. if (!dp->active_panels[i])
  209. continue;
  210. streams[index].stream_id = i;
  211. streams[index].virtual_channel =
  212. dp->active_panels[i]->vcpi;
  213. index++;
  214. }
  215. if (index > 0) {
  216. rc = ops->register_streams(data, index, streams);
  217. if (rc)
  218. pr_err("failed to register streams. rc = %d\n",
  219. rc);
  220. }
  221. }
  222. }
  223. static void dp_display_hdcp_deregister_stream(struct dp_display_private *dp,
  224. enum dp_stream_id stream_id)
  225. {
  226. if (dp->hdcp.ops->deregister_streams) {
  227. struct stream_info stream = {stream_id,
  228. dp->active_panels[stream_id]->vcpi};
  229. pr_debug("Deregistering stream within HDCP library\n");
  230. dp->hdcp.ops->deregister_streams(dp->hdcp.data, 1, &stream);
  231. }
  232. }
  233. static void dp_display_hdcp_cb_work(struct work_struct *work)
  234. {
  235. struct dp_display_private *dp;
  236. struct delayed_work *dw = to_delayed_work(work);
  237. struct sde_hdcp_ops *ops;
  238. struct dp_link_hdcp_status *status;
  239. void *data;
  240. int rc = 0;
  241. u32 hdcp_auth_state;
  242. u8 sink_status = 0;
  243. dp = container_of(dw, struct dp_display_private, hdcp_cb_work);
  244. if (!dp->power_on || !dp->is_connected || atomic_read(&dp->aborted))
  245. return;
  246. drm_dp_dpcd_readb(dp->aux->drm_aux, DP_SINK_STATUS, &sink_status);
  247. sink_status &= (DP_RECEIVE_PORT_0_STATUS | DP_RECEIVE_PORT_1_STATUS);
  248. if (sink_status < 1) {
  249. pr_debug("Sink not synchronized. Queuing again then exiting\n");
  250. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  251. return;
  252. }
  253. status = &dp->link->hdcp_status;
  254. if (status->hdcp_state == HDCP_STATE_INACTIVE) {
  255. dp_display_check_source_hdcp_caps(dp);
  256. dp_display_update_hdcp_info(dp);
  257. if (dp_display_is_hdcp_enabled(dp)) {
  258. if (dp->hdcp.ops && dp->hdcp.ops->on &&
  259. dp->hdcp.ops->on(dp->hdcp.data)) {
  260. dp_display_update_hdcp_status(dp, true);
  261. return;
  262. }
  263. status->hdcp_state = HDCP_STATE_AUTHENTICATING;
  264. } else {
  265. dp_display_update_hdcp_status(dp, true);
  266. return;
  267. }
  268. }
  269. rc = dp->catalog->ctrl.read_hdcp_status(&dp->catalog->ctrl);
  270. if (rc >= 0) {
  271. hdcp_auth_state = (rc >> 20) & 0x3;
  272. pr_debug("hdcp auth state %d\n", hdcp_auth_state);
  273. }
  274. ops = dp->hdcp.ops;
  275. data = dp->hdcp.data;
  276. pr_debug("%s: %s\n", sde_hdcp_version(status->hdcp_version),
  277. sde_hdcp_state_name(status->hdcp_state));
  278. dp_display_update_hdcp_status(dp, false);
  279. if (dp->debug->force_encryption && ops && ops->force_encryption)
  280. ops->force_encryption(data, dp->debug->force_encryption);
  281. switch (status->hdcp_state) {
  282. case HDCP_STATE_AUTHENTICATING:
  283. dp_display_hdcp_register_streams(dp);
  284. if (dp->hdcp.ops && dp->hdcp.ops->authenticate)
  285. rc = dp->hdcp.ops->authenticate(data);
  286. break;
  287. case HDCP_STATE_AUTH_FAIL:
  288. if (dp_display_is_ready(dp) && dp->power_on) {
  289. if (ops && ops->on && ops->on(data)) {
  290. dp_display_update_hdcp_status(dp, true);
  291. return;
  292. }
  293. dp_display_hdcp_register_streams(dp);
  294. status->hdcp_state = HDCP_STATE_AUTHENTICATING;
  295. if (ops && ops->reauthenticate) {
  296. rc = ops->reauthenticate(data);
  297. if (rc)
  298. pr_err("failed rc=%d\n", rc);
  299. }
  300. } else {
  301. pr_debug("not reauthenticating, cable disconnected\n");
  302. }
  303. break;
  304. default:
  305. dp_display_hdcp_register_streams(dp);
  306. break;
  307. }
  308. }
  309. static void dp_display_notify_hdcp_status_cb(void *ptr,
  310. enum sde_hdcp_state state)
  311. {
  312. struct dp_display_private *dp = ptr;
  313. if (!dp) {
  314. pr_err("invalid input\n");
  315. return;
  316. }
  317. dp->link->hdcp_status.hdcp_state = state;
  318. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ/4);
  319. }
  320. static void dp_display_deinitialize_hdcp(struct dp_display_private *dp)
  321. {
  322. if (!dp) {
  323. pr_err("invalid input\n");
  324. return;
  325. }
  326. sde_dp_hdcp2p2_deinit(dp->hdcp.data);
  327. }
  328. static int dp_display_initialize_hdcp(struct dp_display_private *dp)
  329. {
  330. struct sde_hdcp_init_data hdcp_init_data;
  331. struct dp_parser *parser;
  332. void *fd;
  333. int rc = 0;
  334. if (!dp) {
  335. pr_err("invalid input\n");
  336. return -EINVAL;
  337. }
  338. parser = dp->parser;
  339. hdcp_init_data.client_id = HDCP_CLIENT_DP;
  340. hdcp_init_data.drm_aux = dp->aux->drm_aux;
  341. hdcp_init_data.cb_data = (void *)dp;
  342. hdcp_init_data.workq = dp->wq;
  343. hdcp_init_data.sec_access = true;
  344. hdcp_init_data.notify_status = dp_display_notify_hdcp_status_cb;
  345. hdcp_init_data.dp_ahb = &parser->get_io(parser, "dp_ahb")->io;
  346. hdcp_init_data.dp_aux = &parser->get_io(parser, "dp_aux")->io;
  347. hdcp_init_data.dp_link = &parser->get_io(parser, "dp_link")->io;
  348. hdcp_init_data.dp_p0 = &parser->get_io(parser, "dp_p0")->io;
  349. hdcp_init_data.qfprom_io = &parser->get_io(parser,
  350. "qfprom_physical")->io;
  351. hdcp_init_data.hdcp_io = &parser->get_io(parser,
  352. "hdcp_physical")->io;
  353. hdcp_init_data.revision = &dp->panel->link_info.revision;
  354. hdcp_init_data.msm_hdcp_dev = dp->parser->msm_hdcp_dev;
  355. fd = sde_hdcp_1x_init(&hdcp_init_data);
  356. if (IS_ERR_OR_NULL(fd)) {
  357. pr_err("Error initializing HDCP 1.x\n");
  358. rc = -EINVAL;
  359. goto error;
  360. }
  361. dp->hdcp.dev[HDCP_VERSION_1X].fd = fd;
  362. dp->hdcp.dev[HDCP_VERSION_1X].ops = sde_hdcp_1x_get(fd);
  363. dp->hdcp.dev[HDCP_VERSION_1X].ver = HDCP_VERSION_1X;
  364. pr_debug("HDCP 1.3 initialized\n");
  365. fd = sde_dp_hdcp2p2_init(&hdcp_init_data);
  366. if (IS_ERR_OR_NULL(fd)) {
  367. pr_err("Error initializing HDCP 2.x\n");
  368. rc = -EINVAL;
  369. goto error;
  370. }
  371. dp->hdcp.dev[HDCP_VERSION_2P2].fd = fd;
  372. dp->hdcp.dev[HDCP_VERSION_2P2].ops = sde_dp_hdcp2p2_get(fd);
  373. dp->hdcp.dev[HDCP_VERSION_2P2].ver = HDCP_VERSION_2P2;
  374. pr_debug("HDCP 2.2 initialized\n");
  375. return 0;
  376. error:
  377. dp_display_deinitialize_hdcp(dp);
  378. return rc;
  379. }
  380. static int dp_display_bind(struct device *dev, struct device *master,
  381. void *data)
  382. {
  383. int rc = 0;
  384. struct dp_display_private *dp;
  385. struct drm_device *drm;
  386. struct platform_device *pdev = to_platform_device(dev);
  387. if (!dev || !pdev || !master) {
  388. pr_err("invalid param(s), dev %pK, pdev %pK, master %pK\n",
  389. dev, pdev, master);
  390. rc = -EINVAL;
  391. goto end;
  392. }
  393. drm = dev_get_drvdata(master);
  394. dp = platform_get_drvdata(pdev);
  395. if (!drm || !dp) {
  396. pr_err("invalid param(s), drm %pK, dp %pK\n",
  397. drm, dp);
  398. rc = -EINVAL;
  399. goto end;
  400. }
  401. dp->dp_display.drm_dev = drm;
  402. dp->priv = drm->dev_private;
  403. end:
  404. return rc;
  405. }
  406. static void dp_display_unbind(struct device *dev, struct device *master,
  407. void *data)
  408. {
  409. struct dp_display_private *dp;
  410. struct platform_device *pdev = to_platform_device(dev);
  411. if (!dev || !pdev) {
  412. pr_err("invalid param(s)\n");
  413. return;
  414. }
  415. dp = platform_get_drvdata(pdev);
  416. if (!dp) {
  417. pr_err("Invalid params\n");
  418. return;
  419. }
  420. if (dp->power)
  421. (void)dp->power->power_client_deinit(dp->power);
  422. if (dp->aux)
  423. (void)dp->aux->drm_aux_deregister(dp->aux);
  424. dp_display_deinitialize_hdcp(dp);
  425. }
  426. static const struct component_ops dp_display_comp_ops = {
  427. .bind = dp_display_bind,
  428. .unbind = dp_display_unbind,
  429. };
  430. static void dp_display_send_hpd_event(struct dp_display_private *dp)
  431. {
  432. struct drm_device *dev = NULL;
  433. struct drm_connector *connector;
  434. char name[HPD_STRING_SIZE], status[HPD_STRING_SIZE],
  435. bpp[HPD_STRING_SIZE], pattern[HPD_STRING_SIZE];
  436. char *envp[5];
  437. if (dp->mst.mst_active) {
  438. pr_debug("skip notification for mst mode\n");
  439. return;
  440. }
  441. connector = dp->dp_display.base_connector;
  442. if (!connector) {
  443. pr_err("connector not set\n");
  444. return;
  445. }
  446. connector->status = connector->funcs->detect(connector, false);
  447. dev = connector->dev;
  448. snprintf(name, HPD_STRING_SIZE, "name=%s", connector->name);
  449. snprintf(status, HPD_STRING_SIZE, "status=%s",
  450. drm_get_connector_status_name(connector->status));
  451. snprintf(bpp, HPD_STRING_SIZE, "bpp=%d",
  452. dp_link_bit_depth_to_bpp(
  453. dp->link->test_video.test_bit_depth));
  454. snprintf(pattern, HPD_STRING_SIZE, "pattern=%d",
  455. dp->link->test_video.test_video_pattern);
  456. pr_debug("[%s]:[%s] [%s] [%s]\n", name, status, bpp, pattern);
  457. envp[0] = name;
  458. envp[1] = status;
  459. envp[2] = bpp;
  460. envp[3] = pattern;
  461. envp[4] = NULL;
  462. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
  463. envp);
  464. }
  465. static int dp_display_send_hpd_notification(struct dp_display_private *dp)
  466. {
  467. int ret = 0;
  468. bool hpd = dp->is_connected;
  469. dp->aux->state |= DP_STATE_NOTIFICATION_SENT;
  470. if (!dp->mst.mst_active)
  471. dp->dp_display.is_sst_connected = hpd;
  472. else
  473. dp->dp_display.is_sst_connected = false;
  474. reinit_completion(&dp->notification_comp);
  475. dp_display_send_hpd_event(dp);
  476. if (hpd && dp->mst.mst_active)
  477. goto skip_wait;
  478. if (!dp->mst.mst_active && (dp->power_on == hpd))
  479. goto skip_wait;
  480. if (!wait_for_completion_timeout(&dp->notification_comp,
  481. HZ * 5)) {
  482. pr_warn("%s timeout\n", hpd ? "connect" : "disconnect");
  483. ret = -EINVAL;
  484. }
  485. return ret;
  486. skip_wait:
  487. return 0;
  488. }
  489. static void dp_display_update_mst_state(struct dp_display_private *dp,
  490. bool state)
  491. {
  492. dp->mst.mst_active = state;
  493. dp->panel->mst_state = state;
  494. }
  495. static void dp_display_process_mst_hpd_high(struct dp_display_private *dp,
  496. bool mst_probe)
  497. {
  498. bool is_mst_receiver;
  499. struct dp_mst_hpd_info info;
  500. int ret;
  501. if (!dp->parser->has_mst || !dp->mst.drm_registered) {
  502. DP_MST_DEBUG("mst not enabled. has_mst:%d, registered:%d\n",
  503. dp->parser->has_mst, dp->mst.drm_registered);
  504. return;
  505. }
  506. DP_MST_DEBUG("mst_hpd_high work. mst_probe:%d\n", mst_probe);
  507. if (!dp->mst.mst_active) {
  508. is_mst_receiver = dp->panel->read_mst_cap(dp->panel);
  509. if (!is_mst_receiver) {
  510. DP_MST_DEBUG("sink doesn't support mst\n");
  511. return;
  512. }
  513. /* clear sink mst state */
  514. drm_dp_dpcd_writeb(dp->aux->drm_aux, DP_MSTM_CTRL, 0);
  515. ret = drm_dp_dpcd_writeb(dp->aux->drm_aux, DP_MSTM_CTRL,
  516. DP_MST_EN | DP_UP_REQ_EN | DP_UPSTREAM_IS_SRC);
  517. if (ret < 0) {
  518. pr_err("sink mst enablement failed\n");
  519. return;
  520. }
  521. dp_display_update_mst_state(dp, true);
  522. } else if (dp->mst.mst_active && mst_probe) {
  523. info.mst_protocol = dp->parser->has_mst_sideband;
  524. info.mst_port_cnt = dp->debug->mst_port_cnt;
  525. info.edid = dp->debug->get_edid(dp->debug);
  526. if (dp->mst.cbs.hpd)
  527. dp->mst.cbs.hpd(&dp->dp_display, true, &info);
  528. }
  529. DP_MST_DEBUG("mst_hpd_high. mst_active:%d\n", dp->mst.mst_active);
  530. }
  531. static void dp_display_host_init(struct dp_display_private *dp)
  532. {
  533. bool flip = false;
  534. bool reset;
  535. if (dp->core_initialized)
  536. return;
  537. if (dp->hpd->orientation == ORIENTATION_CC2)
  538. flip = true;
  539. reset = dp->debug->sim_mode ? false : !dp->hpd->multi_func;
  540. dp->power->init(dp->power, flip);
  541. dp->hpd->host_init(dp->hpd, &dp->catalog->hpd);
  542. dp->ctrl->init(dp->ctrl, flip, reset);
  543. dp->aux->init(dp->aux, dp->parser->aux_cfg);
  544. enable_irq(dp->irq);
  545. dp->panel->init(dp->panel);
  546. dp->core_initialized = true;
  547. /* log this as it results from user action of cable connection */
  548. pr_info("[OK]\n");
  549. }
  550. static void dp_display_host_deinit(struct dp_display_private *dp)
  551. {
  552. if (!dp->core_initialized)
  553. return;
  554. if (dp->active_stream_cnt) {
  555. pr_debug("active stream present\n");
  556. return;
  557. }
  558. dp->aux->deinit(dp->aux);
  559. dp->ctrl->deinit(dp->ctrl);
  560. dp->hpd->host_deinit(dp->hpd, &dp->catalog->hpd);
  561. dp->power->deinit(dp->power);
  562. disable_irq(dp->irq);
  563. dp->core_initialized = false;
  564. dp->aux->state = 0;
  565. /* log this as it results from user action of cable dis-connection */
  566. pr_info("[OK]\n");
  567. }
  568. static int dp_display_process_hpd_high(struct dp_display_private *dp)
  569. {
  570. int rc = -EINVAL;
  571. mutex_lock(&dp->session_lock);
  572. if (dp->is_connected) {
  573. pr_debug("dp already connected, skipping hpd high\n");
  574. mutex_unlock(&dp->session_lock);
  575. rc = -EISCONN;
  576. goto end;
  577. }
  578. dp->is_connected = true;
  579. dp->dp_display.max_pclk_khz = min(dp->parser->max_pclk_khz,
  580. dp->debug->max_pclk_khz);
  581. dp_display_host_init(dp);
  582. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  583. dp->debug->psm_enabled = false;
  584. if (!dp->dp_display.base_connector)
  585. goto end;
  586. rc = dp->panel->read_sink_caps(dp->panel,
  587. dp->dp_display.base_connector, dp->hpd->multi_func);
  588. /*
  589. * ETIMEDOUT --> cable may have been removed
  590. * ENOTCONN --> no downstream device connected
  591. */
  592. if (rc == -ETIMEDOUT || rc == -ENOTCONN) {
  593. dp->is_connected = false;
  594. goto end;
  595. }
  596. dp->link->process_request(dp->link);
  597. dp->panel->handle_sink_request(dp->panel);
  598. dp_display_process_mst_hpd_high(dp, false);
  599. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active,
  600. dp->panel->fec_en, false);
  601. if (rc) {
  602. dp->is_connected = false;
  603. goto end;
  604. }
  605. dp->process_hpd_connect = false;
  606. dp_display_process_mst_hpd_high(dp, true);
  607. end:
  608. mutex_unlock(&dp->session_lock);
  609. if (!rc)
  610. dp_display_send_hpd_notification(dp);
  611. return rc;
  612. }
  613. static void dp_display_process_mst_hpd_low(struct dp_display_private *dp)
  614. {
  615. struct dp_mst_hpd_info info = {0};
  616. if (dp->mst.mst_active) {
  617. DP_MST_DEBUG("mst_hpd_low work\n");
  618. if (dp->mst.cbs.hpd) {
  619. info.mst_protocol = dp->parser->has_mst_sideband;
  620. dp->mst.cbs.hpd(&dp->dp_display, false, &info);
  621. }
  622. dp_display_update_mst_state(dp, false);
  623. }
  624. DP_MST_DEBUG("mst_hpd_low. mst_active:%d\n", dp->mst.mst_active);
  625. }
  626. static int dp_display_process_hpd_low(struct dp_display_private *dp)
  627. {
  628. int rc = 0;
  629. dp->is_connected = false;
  630. dp->process_hpd_connect = false;
  631. dp_display_process_mst_hpd_low(dp);
  632. rc = dp_display_send_hpd_notification(dp);
  633. mutex_lock(&dp->session_lock);
  634. if (!dp->active_stream_cnt)
  635. dp->ctrl->off(dp->ctrl);
  636. mutex_unlock(&dp->session_lock);
  637. dp->panel->video_test = false;
  638. return rc;
  639. }
  640. static int dp_display_usbpd_configure_cb(struct device *dev)
  641. {
  642. int rc = 0;
  643. struct dp_display_private *dp;
  644. if (!dev) {
  645. pr_err("invalid dev\n");
  646. rc = -EINVAL;
  647. goto end;
  648. }
  649. dp = dev_get_drvdata(dev);
  650. if (!dp) {
  651. pr_err("no driver data found\n");
  652. rc = -ENODEV;
  653. goto end;
  654. }
  655. if (!dp->debug->sim_mode && !dp->parser->no_aux_switch
  656. && !dp->parser->gpio_aux_switch) {
  657. rc = dp->aux->aux_switch(dp->aux, true, dp->hpd->orientation);
  658. if (rc)
  659. goto end;
  660. }
  661. mutex_lock(&dp->session_lock);
  662. dp_display_host_init(dp);
  663. /* check for hpd high */
  664. if (dp->hpd->hpd_high)
  665. queue_work(dp->wq, &dp->connect_work);
  666. else
  667. dp->process_hpd_connect = true;
  668. mutex_unlock(&dp->session_lock);
  669. end:
  670. return rc;
  671. }
  672. static int dp_display_stream_pre_disable(struct dp_display_private *dp,
  673. struct dp_panel *dp_panel)
  674. {
  675. dp->ctrl->stream_pre_off(dp->ctrl, dp_panel);
  676. return 0;
  677. }
  678. static void dp_display_stream_disable(struct dp_display_private *dp,
  679. struct dp_panel *dp_panel)
  680. {
  681. if (!dp->active_stream_cnt) {
  682. pr_err("invalid active_stream_cnt (%d)\n",
  683. dp->active_stream_cnt);
  684. return;
  685. }
  686. pr_debug("stream_id=%d, active_stream_cnt=%d\n",
  687. dp_panel->stream_id, dp->active_stream_cnt);
  688. dp->ctrl->stream_off(dp->ctrl, dp_panel);
  689. dp->active_panels[dp_panel->stream_id] = NULL;
  690. dp->active_stream_cnt--;
  691. }
  692. static void dp_display_clean(struct dp_display_private *dp)
  693. {
  694. int idx;
  695. struct dp_panel *dp_panel;
  696. struct dp_link_hdcp_status *status = &dp->link->hdcp_status;
  697. if (dp_display_is_hdcp_enabled(dp) &&
  698. status->hdcp_state != HDCP_STATE_INACTIVE) {
  699. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  700. if (dp->hdcp.ops->off)
  701. dp->hdcp.ops->off(dp->hdcp.data);
  702. dp_display_update_hdcp_status(dp, true);
  703. }
  704. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  705. if (!dp->active_panels[idx])
  706. continue;
  707. dp_panel = dp->active_panels[idx];
  708. dp_display_stream_pre_disable(dp, dp_panel);
  709. dp_display_stream_disable(dp, dp_panel);
  710. dp_panel->deinit(dp_panel, 0);
  711. }
  712. dp->power_on = false;
  713. mutex_lock(&dp->session_lock);
  714. dp->ctrl->off(dp->ctrl);
  715. mutex_unlock(&dp->session_lock);
  716. }
  717. static int dp_display_handle_disconnect(struct dp_display_private *dp)
  718. {
  719. int rc;
  720. rc = dp_display_process_hpd_low(dp);
  721. if (rc) {
  722. /* cancel any pending request */
  723. dp->ctrl->abort(dp->ctrl);
  724. dp->aux->abort(dp->aux);
  725. }
  726. mutex_lock(&dp->session_lock);
  727. if (rc && dp->power_on)
  728. dp_display_clean(dp);
  729. dp_display_host_deinit(dp);
  730. mutex_unlock(&dp->session_lock);
  731. return rc;
  732. }
  733. static void dp_display_disconnect_sync(struct dp_display_private *dp)
  734. {
  735. /* cancel any pending request */
  736. atomic_set(&dp->aborted, 1);
  737. dp->ctrl->abort(dp->ctrl);
  738. dp->aux->abort(dp->aux);
  739. /* wait for idle state */
  740. cancel_work_sync(&dp->connect_work);
  741. cancel_work_sync(&dp->attention_work);
  742. flush_workqueue(dp->wq);
  743. dp_display_handle_disconnect(dp);
  744. /* Reset abort value to allow future connections */
  745. atomic_set(&dp->aborted, 0);
  746. }
  747. static int dp_display_usbpd_disconnect_cb(struct device *dev)
  748. {
  749. int rc = 0;
  750. struct dp_display_private *dp;
  751. if (!dev) {
  752. pr_err("invalid dev\n");
  753. rc = -EINVAL;
  754. goto end;
  755. }
  756. dp = dev_get_drvdata(dev);
  757. if (!dp) {
  758. pr_err("no driver data found\n");
  759. rc = -ENODEV;
  760. goto end;
  761. }
  762. mutex_lock(&dp->session_lock);
  763. if (dp->debug->psm_enabled && dp->core_initialized)
  764. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  765. mutex_unlock(&dp->session_lock);
  766. dp_display_disconnect_sync(dp);
  767. if (!dp->debug->sim_mode && !dp->parser->no_aux_switch
  768. && !dp->parser->gpio_aux_switch)
  769. dp->aux->aux_switch(dp->aux, false, ORIENTATION_NONE);
  770. end:
  771. return rc;
  772. }
  773. static int dp_display_stream_enable(struct dp_display_private *dp,
  774. struct dp_panel *dp_panel)
  775. {
  776. int rc = 0;
  777. rc = dp->ctrl->stream_on(dp->ctrl, dp_panel);
  778. if (dp->debug->tpg_state)
  779. dp_panel->tpg_config(dp_panel, true);
  780. if (!rc) {
  781. dp->active_panels[dp_panel->stream_id] = dp_panel;
  782. dp->active_stream_cnt++;
  783. }
  784. pr_debug("dp active_stream_cnt:%d\n", dp->active_stream_cnt);
  785. return rc;
  786. }
  787. static void dp_display_mst_attention(struct dp_display_private *dp)
  788. {
  789. struct dp_mst_hpd_info hpd_irq = {0};
  790. if (dp->mst.mst_active && dp->mst.cbs.hpd_irq) {
  791. hpd_irq.mst_hpd_sim = dp->debug->mst_hpd_sim;
  792. dp->mst.cbs.hpd_irq(&dp->dp_display, &hpd_irq);
  793. dp->debug->mst_hpd_sim = false;
  794. }
  795. DP_MST_DEBUG("mst_attention_work. mst_active:%d\n", dp->mst.mst_active);
  796. }
  797. static void dp_display_attention_work(struct work_struct *work)
  798. {
  799. struct dp_display_private *dp = container_of(work,
  800. struct dp_display_private, attention_work);
  801. mutex_lock(&dp->session_lock);
  802. if (dp->debug->mst_hpd_sim || !dp->core_initialized) {
  803. mutex_unlock(&dp->session_lock);
  804. goto mst_attention;
  805. }
  806. if (dp->link->process_request(dp->link)) {
  807. mutex_unlock(&dp->session_lock);
  808. goto cp_irq;
  809. }
  810. mutex_unlock(&dp->session_lock);
  811. if (dp->link->sink_request & DS_PORT_STATUS_CHANGED) {
  812. if (dp_display_is_sink_count_zero(dp)) {
  813. dp_display_handle_disconnect(dp);
  814. } else {
  815. if (!dp->mst.mst_active)
  816. queue_work(dp->wq, &dp->connect_work);
  817. }
  818. goto mst_attention;
  819. }
  820. if (dp->link->sink_request & DP_TEST_LINK_VIDEO_PATTERN) {
  821. dp_display_handle_disconnect(dp);
  822. dp->panel->video_test = true;
  823. queue_work(dp->wq, &dp->connect_work);
  824. goto mst_attention;
  825. }
  826. if (dp->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) {
  827. dp->ctrl->process_phy_test_request(dp->ctrl);
  828. goto mst_attention;
  829. }
  830. if (dp->link->sink_request & DP_TEST_LINK_TRAINING) {
  831. dp->link->send_test_response(dp->link);
  832. dp->ctrl->link_maintenance(dp->ctrl);
  833. goto mst_attention;
  834. }
  835. if (dp->link->sink_request & DP_LINK_STATUS_UPDATED)
  836. dp->ctrl->link_maintenance(dp->ctrl);
  837. cp_irq:
  838. if (dp_display_is_hdcp_enabled(dp) && dp->hdcp.ops->cp_irq)
  839. dp->hdcp.ops->cp_irq(dp->hdcp.data);
  840. mst_attention:
  841. dp_display_mst_attention(dp);
  842. }
  843. static int dp_display_usbpd_attention_cb(struct device *dev)
  844. {
  845. struct dp_display_private *dp;
  846. if (!dev) {
  847. pr_err("invalid dev\n");
  848. return -EINVAL;
  849. }
  850. dp = dev_get_drvdata(dev);
  851. if (!dp) {
  852. pr_err("no driver data found\n");
  853. return -ENODEV;
  854. }
  855. pr_debug("hpd_irq:%d, hpd_high:%d, power_on:%d, is_connected:%d\n",
  856. dp->hpd->hpd_irq, dp->hpd->hpd_high,
  857. dp->power_on, dp->is_connected);
  858. if (!dp->hpd->hpd_high)
  859. dp_display_disconnect_sync(dp);
  860. else if ((dp->hpd->hpd_irq && dp->core_initialized) ||
  861. dp->debug->mst_hpd_sim)
  862. queue_work(dp->wq, &dp->attention_work);
  863. else if (dp->process_hpd_connect || !dp->is_connected)
  864. queue_work(dp->wq, &dp->connect_work);
  865. else
  866. pr_debug("ignored\n");
  867. return 0;
  868. }
  869. static void dp_display_connect_work(struct work_struct *work)
  870. {
  871. int rc = 0;
  872. struct dp_display_private *dp = container_of(work,
  873. struct dp_display_private, connect_work);
  874. if (atomic_read(&dp->aborted)) {
  875. pr_warn("HPD off requested\n");
  876. return;
  877. }
  878. if (!dp->hpd->hpd_high) {
  879. pr_warn("Sink disconnected\n");
  880. return;
  881. }
  882. rc = dp_display_process_hpd_high(dp);
  883. if (!rc && dp->panel->video_test)
  884. dp->link->send_test_response(dp->link);
  885. }
  886. static int dp_display_usb_notifier(struct notifier_block *nb,
  887. unsigned long event, void *ptr)
  888. {
  889. struct extcon_dev *edev = ptr;
  890. struct dp_display_private *dp = container_of(nb,
  891. struct dp_display_private, usb_nb);
  892. if (!edev)
  893. goto end;
  894. if (!event && dp->debug->sim_mode) {
  895. dp_display_disconnect_sync(dp);
  896. dp->debug->abort(dp->debug);
  897. }
  898. end:
  899. return NOTIFY_DONE;
  900. }
  901. static int dp_display_get_usb_extcon(struct dp_display_private *dp)
  902. {
  903. struct extcon_dev *edev;
  904. int rc;
  905. edev = extcon_get_edev_by_phandle(&dp->pdev->dev, 0);
  906. if (IS_ERR(edev))
  907. return PTR_ERR(edev);
  908. dp->usb_nb.notifier_call = dp_display_usb_notifier;
  909. dp->usb_nb.priority = 2;
  910. rc = extcon_register_notifier(edev, EXTCON_USB, &dp->usb_nb);
  911. if (rc)
  912. pr_err("failed to register for usb event: %d\n", rc);
  913. return rc;
  914. }
  915. static void dp_display_deinit_sub_modules(struct dp_display_private *dp)
  916. {
  917. dp_audio_put(dp->panel->audio);
  918. dp_ctrl_put(dp->ctrl);
  919. dp_link_put(dp->link);
  920. dp_panel_put(dp->panel);
  921. dp_aux_put(dp->aux);
  922. dp_power_put(dp->power);
  923. dp_catalog_put(dp->catalog);
  924. dp_parser_put(dp->parser);
  925. dp_hpd_put(dp->hpd);
  926. mutex_destroy(&dp->session_lock);
  927. dp_debug_put(dp->debug);
  928. }
  929. static int dp_init_sub_modules(struct dp_display_private *dp)
  930. {
  931. int rc = 0;
  932. bool hdcp_disabled;
  933. struct device *dev = &dp->pdev->dev;
  934. struct dp_hpd_cb *cb = &dp->hpd_cb;
  935. struct dp_ctrl_in ctrl_in = {
  936. .dev = dev,
  937. };
  938. struct dp_panel_in panel_in = {
  939. .dev = dev,
  940. };
  941. struct dp_debug_in debug_in = {
  942. .dev = dev,
  943. };
  944. mutex_init(&dp->session_lock);
  945. dp->parser = dp_parser_get(dp->pdev);
  946. if (IS_ERR(dp->parser)) {
  947. rc = PTR_ERR(dp->parser);
  948. pr_err("failed to initialize parser, rc = %d\n", rc);
  949. dp->parser = NULL;
  950. goto error;
  951. }
  952. rc = dp->parser->parse(dp->parser);
  953. if (rc) {
  954. pr_err("device tree parsing failed\n");
  955. goto error_catalog;
  956. }
  957. g_dp_display->is_mst_supported = dp->parser->has_mst;
  958. dp->catalog = dp_catalog_get(dev, dp->parser);
  959. if (IS_ERR(dp->catalog)) {
  960. rc = PTR_ERR(dp->catalog);
  961. pr_err("failed to initialize catalog, rc = %d\n", rc);
  962. dp->catalog = NULL;
  963. goto error_catalog;
  964. }
  965. dp->power = dp_power_get(dp->parser);
  966. if (IS_ERR(dp->power)) {
  967. rc = PTR_ERR(dp->power);
  968. pr_err("failed to initialize power, rc = %d\n", rc);
  969. dp->power = NULL;
  970. goto error_power;
  971. }
  972. rc = dp->power->power_client_init(dp->power, &dp->priv->phandle,
  973. dp->dp_display.drm_dev);
  974. if (rc) {
  975. pr_err("Power client create failed\n");
  976. goto error_aux;
  977. }
  978. dp->aux = dp_aux_get(dev, &dp->catalog->aux, dp->parser,
  979. dp->aux_switch_node);
  980. if (IS_ERR(dp->aux)) {
  981. rc = PTR_ERR(dp->aux);
  982. pr_err("failed to initialize aux, rc = %d\n", rc);
  983. dp->aux = NULL;
  984. goto error_aux;
  985. }
  986. rc = dp->aux->drm_aux_register(dp->aux);
  987. if (rc) {
  988. pr_err("DRM DP AUX register failed\n");
  989. goto error_link;
  990. }
  991. dp->link = dp_link_get(dev, dp->aux);
  992. if (IS_ERR(dp->link)) {
  993. rc = PTR_ERR(dp->link);
  994. pr_err("failed to initialize link, rc = %d\n", rc);
  995. dp->link = NULL;
  996. goto error_link;
  997. }
  998. panel_in.aux = dp->aux;
  999. panel_in.catalog = &dp->catalog->panel;
  1000. panel_in.link = dp->link;
  1001. panel_in.connector = dp->dp_display.base_connector;
  1002. panel_in.base_panel = NULL;
  1003. panel_in.parser = dp->parser;
  1004. dp->panel = dp_panel_get(&panel_in);
  1005. if (IS_ERR(dp->panel)) {
  1006. rc = PTR_ERR(dp->panel);
  1007. pr_err("failed to initialize panel, rc = %d\n", rc);
  1008. dp->panel = NULL;
  1009. goto error_panel;
  1010. }
  1011. ctrl_in.link = dp->link;
  1012. ctrl_in.panel = dp->panel;
  1013. ctrl_in.aux = dp->aux;
  1014. ctrl_in.power = dp->power;
  1015. ctrl_in.catalog = &dp->catalog->ctrl;
  1016. ctrl_in.parser = dp->parser;
  1017. dp->ctrl = dp_ctrl_get(&ctrl_in);
  1018. if (IS_ERR(dp->ctrl)) {
  1019. rc = PTR_ERR(dp->ctrl);
  1020. pr_err("failed to initialize ctrl, rc = %d\n", rc);
  1021. dp->ctrl = NULL;
  1022. goto error_ctrl;
  1023. }
  1024. dp->panel->audio = dp_audio_get(dp->pdev, dp->panel,
  1025. &dp->catalog->audio);
  1026. if (IS_ERR(dp->panel->audio)) {
  1027. rc = PTR_ERR(dp->panel->audio);
  1028. pr_err("failed to initialize audio, rc = %d\n", rc);
  1029. dp->panel->audio = NULL;
  1030. goto error_audio;
  1031. }
  1032. memset(&dp->mst, 0, sizeof(dp->mst));
  1033. dp->active_stream_cnt = 0;
  1034. cb->configure = dp_display_usbpd_configure_cb;
  1035. cb->disconnect = dp_display_usbpd_disconnect_cb;
  1036. cb->attention = dp_display_usbpd_attention_cb;
  1037. dp->hpd = dp_hpd_get(dev, dp->parser, &dp->catalog->hpd, cb);
  1038. if (IS_ERR(dp->hpd)) {
  1039. rc = PTR_ERR(dp->hpd);
  1040. pr_err("failed to initialize hpd, rc = %d\n", rc);
  1041. dp->hpd = NULL;
  1042. goto error_hpd;
  1043. }
  1044. hdcp_disabled = !!dp_display_initialize_hdcp(dp);
  1045. debug_in.panel = dp->panel;
  1046. debug_in.hpd = dp->hpd;
  1047. debug_in.link = dp->link;
  1048. debug_in.aux = dp->aux;
  1049. debug_in.connector = &dp->dp_display.base_connector;
  1050. debug_in.catalog = dp->catalog;
  1051. debug_in.parser = dp->parser;
  1052. debug_in.ctrl = dp->ctrl;
  1053. dp->debug = dp_debug_get(&debug_in);
  1054. if (IS_ERR(dp->debug)) {
  1055. rc = PTR_ERR(dp->debug);
  1056. pr_err("failed to initialize debug, rc = %d\n", rc);
  1057. dp->debug = NULL;
  1058. goto error_debug;
  1059. }
  1060. dp->tot_dsc_blks_in_use = 0;
  1061. dp->debug->hdcp_disabled = hdcp_disabled;
  1062. dp_display_update_hdcp_status(dp, true);
  1063. dp_display_get_usb_extcon(dp);
  1064. rc = dp->hpd->register_hpd(dp->hpd);
  1065. if (rc) {
  1066. pr_err("failed register hpd\n");
  1067. goto error_hpd_reg;
  1068. }
  1069. return rc;
  1070. error_hpd_reg:
  1071. dp_debug_put(dp->debug);
  1072. error_debug:
  1073. dp_hpd_put(dp->hpd);
  1074. error_hpd:
  1075. dp_audio_put(dp->panel->audio);
  1076. error_audio:
  1077. dp_ctrl_put(dp->ctrl);
  1078. error_ctrl:
  1079. dp_panel_put(dp->panel);
  1080. error_panel:
  1081. dp_link_put(dp->link);
  1082. error_link:
  1083. dp_aux_put(dp->aux);
  1084. error_aux:
  1085. dp_power_put(dp->power);
  1086. error_power:
  1087. dp_catalog_put(dp->catalog);
  1088. error_catalog:
  1089. dp_parser_put(dp->parser);
  1090. error:
  1091. mutex_destroy(&dp->session_lock);
  1092. return rc;
  1093. }
  1094. static int dp_display_post_init(struct dp_display *dp_display)
  1095. {
  1096. int rc = 0;
  1097. struct dp_display_private *dp;
  1098. if (!dp_display) {
  1099. pr_err("invalid input\n");
  1100. rc = -EINVAL;
  1101. goto end;
  1102. }
  1103. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1104. if (IS_ERR_OR_NULL(dp)) {
  1105. pr_err("invalid params\n");
  1106. rc = -EINVAL;
  1107. goto end;
  1108. }
  1109. rc = dp_init_sub_modules(dp);
  1110. if (rc)
  1111. goto end;
  1112. dp_display->post_init = NULL;
  1113. end:
  1114. pr_debug("%s\n", rc ? "failed" : "success");
  1115. return rc;
  1116. }
  1117. static int dp_display_set_mode(struct dp_display *dp_display, void *panel,
  1118. struct dp_display_mode *mode)
  1119. {
  1120. const u32 num_components = 3, default_bpp = 24;
  1121. struct dp_display_private *dp;
  1122. struct dp_panel *dp_panel;
  1123. if (!dp_display || !panel) {
  1124. pr_err("invalid input\n");
  1125. return -EINVAL;
  1126. }
  1127. dp_panel = panel;
  1128. if (!dp_panel->connector) {
  1129. pr_err("invalid connector input\n");
  1130. return -EINVAL;
  1131. }
  1132. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1133. mutex_lock(&dp->session_lock);
  1134. mode->timing.bpp =
  1135. dp_panel->connector->display_info.bpc * num_components;
  1136. if (!mode->timing.bpp)
  1137. mode->timing.bpp = default_bpp;
  1138. mode->timing.bpp = dp->panel->get_mode_bpp(dp->panel,
  1139. mode->timing.bpp, mode->timing.pixel_clk_khz);
  1140. dp_panel->pinfo = mode->timing;
  1141. mutex_unlock(&dp->session_lock);
  1142. return 0;
  1143. }
  1144. static int dp_display_prepare(struct dp_display *dp_display, void *panel)
  1145. {
  1146. struct dp_display_private *dp;
  1147. struct dp_panel *dp_panel;
  1148. int rc = 0;
  1149. if (!dp_display || !panel) {
  1150. pr_err("invalid input\n");
  1151. return -EINVAL;
  1152. }
  1153. dp_panel = panel;
  1154. if (!dp_panel->connector) {
  1155. pr_err("invalid connector input\n");
  1156. return -EINVAL;
  1157. }
  1158. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1159. mutex_lock(&dp->session_lock);
  1160. if (atomic_read(&dp->aborted))
  1161. goto end;
  1162. if (dp->power_on)
  1163. goto end;
  1164. if (!dp_display_is_ready(dp))
  1165. goto end;
  1166. dp_display_host_init(dp);
  1167. if (dp->debug->psm_enabled) {
  1168. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  1169. dp->debug->psm_enabled = false;
  1170. }
  1171. /*
  1172. * Execute the dp controller power on in shallow mode here.
  1173. * In normal cases, controller should have been powered on
  1174. * by now. In some cases like suspend/resume or framework
  1175. * reboot, we end up here without a powered on controller.
  1176. * Cable may have been removed in suspended state. In that
  1177. * case, link training is bound to fail on system resume.
  1178. * So, we execute in shallow mode here to do only minimal
  1179. * and required things.
  1180. */
  1181. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active, dp_panel->fec_en, true);
  1182. if (rc)
  1183. goto end;
  1184. end:
  1185. mutex_unlock(&dp->session_lock);
  1186. return 0;
  1187. }
  1188. static int dp_display_set_stream_info(struct dp_display *dp_display,
  1189. void *panel, u32 strm_id, u32 start_slot,
  1190. u32 num_slots, u32 pbn, int vcpi)
  1191. {
  1192. int rc = 0;
  1193. struct dp_panel *dp_panel;
  1194. struct dp_display_private *dp;
  1195. const int max_slots = 64;
  1196. if (!dp_display) {
  1197. pr_err("invalid input\n");
  1198. return -EINVAL;
  1199. }
  1200. if (strm_id >= DP_STREAM_MAX) {
  1201. pr_err("invalid stream id:%d\n", strm_id);
  1202. return -EINVAL;
  1203. }
  1204. if (start_slot + num_slots > max_slots) {
  1205. pr_err("invalid channel info received. start:%d, slots:%d\n",
  1206. start_slot, num_slots);
  1207. return -EINVAL;
  1208. }
  1209. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1210. mutex_lock(&dp->session_lock);
  1211. dp->ctrl->set_mst_channel_info(dp->ctrl, strm_id,
  1212. start_slot, num_slots);
  1213. if (panel) {
  1214. dp_panel = panel;
  1215. dp_panel->set_stream_info(dp_panel, strm_id, start_slot,
  1216. num_slots, pbn, vcpi);
  1217. }
  1218. mutex_unlock(&dp->session_lock);
  1219. return rc;
  1220. }
  1221. static void dp_display_update_dsc_resources(struct dp_display_private *dp,
  1222. struct dp_panel *panel, bool enable)
  1223. {
  1224. u32 dsc_blk_cnt = 0;
  1225. if (panel->pinfo.comp_info.comp_type == MSM_DISPLAY_COMPRESSION_DSC &&
  1226. panel->pinfo.comp_info.comp_ratio) {
  1227. dsc_blk_cnt = panel->pinfo.h_active /
  1228. dp->parser->max_dp_dsc_input_width_pixs;
  1229. if (panel->pinfo.h_active %
  1230. dp->parser->max_dp_dsc_input_width_pixs)
  1231. dsc_blk_cnt++;
  1232. }
  1233. if (enable) {
  1234. dp->tot_dsc_blks_in_use += dsc_blk_cnt;
  1235. panel->tot_dsc_blks_in_use += dsc_blk_cnt;
  1236. } else {
  1237. dp->tot_dsc_blks_in_use -= dsc_blk_cnt;
  1238. panel->tot_dsc_blks_in_use -= dsc_blk_cnt;
  1239. }
  1240. }
  1241. static int dp_display_enable(struct dp_display *dp_display, void *panel)
  1242. {
  1243. int rc = 0;
  1244. struct dp_display_private *dp;
  1245. if (!dp_display || !panel) {
  1246. pr_err("invalid input\n");
  1247. return -EINVAL;
  1248. }
  1249. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1250. mutex_lock(&dp->session_lock);
  1251. if (!dp->core_initialized) {
  1252. pr_err("host not initialized\n");
  1253. goto end;
  1254. }
  1255. rc = dp_display_stream_enable(dp, panel);
  1256. if (rc)
  1257. goto end;
  1258. dp_display_update_dsc_resources(dp, panel, true);
  1259. dp->power_on = true;
  1260. end:
  1261. mutex_unlock(&dp->session_lock);
  1262. return rc;
  1263. }
  1264. static void dp_display_stream_post_enable(struct dp_display_private *dp,
  1265. struct dp_panel *dp_panel)
  1266. {
  1267. dp_panel->spd_config(dp_panel);
  1268. dp_panel->setup_hdr(dp_panel, NULL, false, 0);
  1269. }
  1270. static int dp_display_post_enable(struct dp_display *dp_display, void *panel)
  1271. {
  1272. struct dp_display_private *dp;
  1273. struct dp_panel *dp_panel;
  1274. if (!dp_display || !panel) {
  1275. pr_err("invalid input\n");
  1276. return -EINVAL;
  1277. }
  1278. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1279. dp_panel = panel;
  1280. mutex_lock(&dp->session_lock);
  1281. if (!dp->power_on) {
  1282. pr_debug("stream not setup, return\n");
  1283. goto end;
  1284. }
  1285. if (atomic_read(&dp->aborted))
  1286. goto end;
  1287. if (!dp_display_is_ready(dp) || !dp->core_initialized) {
  1288. pr_err("display not ready\n");
  1289. goto end;
  1290. }
  1291. dp_display_stream_post_enable(dp, dp_panel);
  1292. if (dp_panel->audio_supported) {
  1293. dp_panel->audio->bw_code = dp->link->link_params.bw_code;
  1294. dp_panel->audio->lane_count = dp->link->link_params.lane_count;
  1295. dp_panel->audio->on(dp_panel->audio);
  1296. }
  1297. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  1298. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  1299. end:
  1300. dp->aux->state |= DP_STATE_CTRL_POWERED_ON;
  1301. complete_all(&dp->notification_comp);
  1302. mutex_unlock(&dp->session_lock);
  1303. return 0;
  1304. }
  1305. static int dp_display_pre_disable(struct dp_display *dp_display, void *panel)
  1306. {
  1307. struct dp_display_private *dp;
  1308. struct dp_panel *dp_panel = panel;
  1309. struct dp_link_hdcp_status *status;
  1310. int rc = 0;
  1311. size_t i;
  1312. if (!dp_display || !panel) {
  1313. pr_err("invalid input\n");
  1314. return -EINVAL;
  1315. }
  1316. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1317. mutex_lock(&dp->session_lock);
  1318. status = &dp->link->hdcp_status;
  1319. if (!dp->power_on) {
  1320. pr_debug("stream already powered off, return\n");
  1321. goto end;
  1322. }
  1323. if (dp_display_is_hdcp_enabled(dp) &&
  1324. status->hdcp_state != HDCP_STATE_INACTIVE) {
  1325. flush_delayed_work(&dp->hdcp_cb_work);
  1326. if (dp->mst.mst_active) {
  1327. dp_display_hdcp_deregister_stream(dp,
  1328. dp_panel->stream_id);
  1329. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  1330. if (i != dp_panel->stream_id &&
  1331. dp->active_panels[i]) {
  1332. pr_debug("Streams are still active. Skip disabling HDCP\n");
  1333. goto stream;
  1334. }
  1335. }
  1336. }
  1337. if (dp->hdcp.ops->off)
  1338. dp->hdcp.ops->off(dp->hdcp.data);
  1339. dp_display_update_hdcp_status(dp, true);
  1340. }
  1341. stream:
  1342. if (dp_panel->audio_supported)
  1343. dp_panel->audio->off(dp_panel->audio);
  1344. rc = dp_display_stream_pre_disable(dp, dp_panel);
  1345. end:
  1346. mutex_unlock(&dp->session_lock);
  1347. return 0;
  1348. }
  1349. static int dp_display_disable(struct dp_display *dp_display, void *panel)
  1350. {
  1351. struct dp_display_private *dp = NULL;
  1352. struct dp_panel *dp_panel = NULL;
  1353. if (!dp_display || !panel) {
  1354. pr_err("invalid input\n");
  1355. return -EINVAL;
  1356. }
  1357. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1358. dp_panel = panel;
  1359. mutex_lock(&dp->session_lock);
  1360. if (!dp->power_on || !dp->core_initialized) {
  1361. pr_debug("Link already powered off, return\n");
  1362. goto end;
  1363. }
  1364. dp_display_stream_disable(dp, dp_panel);
  1365. dp_display_update_dsc_resources(dp, dp_panel, false);
  1366. end:
  1367. mutex_unlock(&dp->session_lock);
  1368. return 0;
  1369. }
  1370. static int dp_request_irq(struct dp_display *dp_display)
  1371. {
  1372. int rc = 0;
  1373. struct dp_display_private *dp;
  1374. if (!dp_display) {
  1375. pr_err("invalid input\n");
  1376. return -EINVAL;
  1377. }
  1378. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1379. dp->irq = irq_of_parse_and_map(dp->pdev->dev.of_node, 0);
  1380. if (dp->irq < 0) {
  1381. rc = dp->irq;
  1382. pr_err("failed to get irq: %d\n", rc);
  1383. return rc;
  1384. }
  1385. rc = devm_request_irq(&dp->pdev->dev, dp->irq, dp_display_irq,
  1386. IRQF_TRIGGER_HIGH, "dp_display_isr", dp);
  1387. if (rc < 0) {
  1388. pr_err("failed to request IRQ%u: %d\n",
  1389. dp->irq, rc);
  1390. return rc;
  1391. }
  1392. disable_irq(dp->irq);
  1393. return 0;
  1394. }
  1395. static struct dp_debug *dp_get_debug(struct dp_display *dp_display)
  1396. {
  1397. struct dp_display_private *dp;
  1398. if (!dp_display) {
  1399. pr_err("invalid input\n");
  1400. return ERR_PTR(-EINVAL);
  1401. }
  1402. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1403. return dp->debug;
  1404. }
  1405. static int dp_display_unprepare(struct dp_display *dp_display, void *panel)
  1406. {
  1407. struct dp_display_private *dp;
  1408. struct dp_panel *dp_panel = panel;
  1409. u32 flags = 0;
  1410. if (!dp_display || !panel) {
  1411. pr_err("invalid input\n");
  1412. return -EINVAL;
  1413. }
  1414. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1415. mutex_lock(&dp->session_lock);
  1416. /*
  1417. * Check if the power off sequence was triggered
  1418. * by a source initialated action like framework
  1419. * reboot or suspend-resume but not from normal
  1420. * hot plug.
  1421. */
  1422. if (dp_display_is_ready(dp))
  1423. flags |= DP_PANEL_SRC_INITIATED_POWER_DOWN;
  1424. if (dp->active_stream_cnt)
  1425. goto end;
  1426. if (flags & DP_PANEL_SRC_INITIATED_POWER_DOWN) {
  1427. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  1428. dp->debug->psm_enabled = true;
  1429. dp->ctrl->off(dp->ctrl);
  1430. dp_display_host_deinit(dp);
  1431. }
  1432. dp->power_on = false;
  1433. dp->aux->state = DP_STATE_CTRL_POWERED_OFF;
  1434. complete_all(&dp->notification_comp);
  1435. /* log this as it results from user action of cable dis-connection */
  1436. pr_info("[OK]\n");
  1437. end:
  1438. dp_panel->deinit(dp_panel, flags);
  1439. mutex_unlock(&dp->session_lock);
  1440. return 0;
  1441. }
  1442. static enum drm_mode_status dp_display_validate_mode(
  1443. struct dp_display *dp_display,
  1444. void *panel, struct drm_display_mode *mode)
  1445. {
  1446. struct dp_display_private *dp;
  1447. struct drm_dp_link *link_info;
  1448. u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
  1449. struct dp_panel *dp_panel;
  1450. struct dp_debug *debug;
  1451. enum drm_mode_status mode_status = MODE_BAD;
  1452. bool in_list = false;
  1453. struct dp_mst_connector *mst_connector;
  1454. int hdis, vdis, vref, ar, _hdis, _vdis, _vref, _ar, rate;
  1455. struct dp_display_mode dp_mode;
  1456. bool dsc_en;
  1457. if (!dp_display || !mode || !panel) {
  1458. pr_err("invalid params\n");
  1459. return mode_status;
  1460. }
  1461. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1462. mutex_lock(&dp->session_lock);
  1463. dp_panel = panel;
  1464. if (!dp_panel->connector) {
  1465. pr_err("invalid connector\n");
  1466. goto end;
  1467. }
  1468. link_info = &dp->panel->link_info;
  1469. debug = dp->debug;
  1470. if (!debug)
  1471. goto end;
  1472. dp_display->convert_to_dp_mode(dp_display, panel, mode, &dp_mode);
  1473. dsc_en = dp_mode.timing.comp_info.comp_ratio ? true : false;
  1474. mode_bpp = dsc_en ? dp_mode.timing.comp_info.dsc_info.bpp :
  1475. dp_mode.timing.bpp;
  1476. mode_rate_khz = mode->clock * mode_bpp;
  1477. rate = drm_dp_bw_code_to_link_rate(dp->link->link_params.bw_code);
  1478. supported_rate_khz = link_info->num_lanes * rate * 8;
  1479. if (mode_rate_khz > supported_rate_khz) {
  1480. DP_MST_DEBUG("pclk:%d, supported_rate:%d\n",
  1481. mode->clock, supported_rate_khz);
  1482. goto end;
  1483. }
  1484. if (mode->clock > dp_display->max_pclk_khz) {
  1485. DP_MST_DEBUG("clk:%d, max:%d\n", mode->clock,
  1486. dp_display->max_pclk_khz);
  1487. goto end;
  1488. }
  1489. /*
  1490. * If the connector exists in the mst connector list and if debug is
  1491. * enabled for that connector, use the mst connector settings from the
  1492. * list for validation. Otherwise, use non-mst default settings.
  1493. */
  1494. mutex_lock(&debug->dp_mst_connector_list.lock);
  1495. if (list_empty(&debug->dp_mst_connector_list.list)) {
  1496. mutex_unlock(&debug->dp_mst_connector_list.lock);
  1497. goto verify_default;
  1498. }
  1499. list_for_each_entry(mst_connector, &debug->dp_mst_connector_list.list,
  1500. list) {
  1501. if (mst_connector->con_id == dp_panel->connector->base.id) {
  1502. in_list = true;
  1503. if (!mst_connector->debug_en) {
  1504. mode_status = MODE_OK;
  1505. mutex_unlock(
  1506. &debug->dp_mst_connector_list.lock);
  1507. goto end;
  1508. }
  1509. hdis = mst_connector->hdisplay;
  1510. vdis = mst_connector->vdisplay;
  1511. vref = mst_connector->vrefresh;
  1512. ar = mst_connector->aspect_ratio;
  1513. _hdis = mode->hdisplay;
  1514. _vdis = mode->vdisplay;
  1515. _vref = mode->vrefresh;
  1516. _ar = mode->picture_aspect_ratio;
  1517. if (hdis == _hdis && vdis == _vdis && vref == _vref &&
  1518. ar == _ar) {
  1519. mode_status = MODE_OK;
  1520. mutex_unlock(
  1521. &debug->dp_mst_connector_list.lock);
  1522. goto end;
  1523. }
  1524. break;
  1525. }
  1526. }
  1527. mutex_unlock(&debug->dp_mst_connector_list.lock);
  1528. if (in_list)
  1529. goto end;
  1530. verify_default:
  1531. if (debug->debug_en && (mode->hdisplay != debug->hdisplay ||
  1532. mode->vdisplay != debug->vdisplay ||
  1533. mode->vrefresh != debug->vrefresh ||
  1534. mode->picture_aspect_ratio != debug->aspect_ratio))
  1535. goto end;
  1536. mode_status = MODE_OK;
  1537. end:
  1538. mutex_unlock(&dp->session_lock);
  1539. return mode_status;
  1540. }
  1541. static int dp_display_get_modes(struct dp_display *dp, void *panel,
  1542. struct dp_display_mode *dp_mode)
  1543. {
  1544. struct dp_display_private *dp_display;
  1545. struct dp_panel *dp_panel;
  1546. int ret = 0;
  1547. if (!dp || !panel) {
  1548. pr_err("invalid params\n");
  1549. return 0;
  1550. }
  1551. dp_panel = panel;
  1552. if (!dp_panel->connector) {
  1553. pr_err("invalid connector\n");
  1554. return 0;
  1555. }
  1556. dp_display = container_of(dp, struct dp_display_private, dp_display);
  1557. ret = dp_panel->get_modes(dp_panel, dp_panel->connector, dp_mode);
  1558. if (dp_mode->timing.pixel_clk_khz)
  1559. dp->max_pclk_khz = dp_mode->timing.pixel_clk_khz;
  1560. return ret;
  1561. }
  1562. static void dp_display_convert_to_dp_mode(struct dp_display *dp_display,
  1563. void *panel,
  1564. const struct drm_display_mode *drm_mode,
  1565. struct dp_display_mode *dp_mode)
  1566. {
  1567. struct dp_display_private *dp;
  1568. struct dp_panel *dp_panel;
  1569. u32 free_dsc_blks = 0, required_dsc_blks = 0;
  1570. if (!dp_display || !drm_mode || !dp_mode || !panel) {
  1571. pr_err("invalid input\n");
  1572. return;
  1573. }
  1574. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1575. dp_panel = panel;
  1576. memset(dp_mode, 0, sizeof(*dp_mode));
  1577. free_dsc_blks = dp->parser->max_dp_dsc_blks -
  1578. dp->tot_dsc_blks_in_use +
  1579. dp_panel->tot_dsc_blks_in_use;
  1580. required_dsc_blks = drm_mode->hdisplay /
  1581. dp->parser->max_dp_dsc_input_width_pixs;
  1582. if (drm_mode->hdisplay % dp->parser->max_dp_dsc_input_width_pixs)
  1583. required_dsc_blks++;
  1584. if (free_dsc_blks >= required_dsc_blks)
  1585. dp_mode->capabilities |= DP_PANEL_CAPS_DSC;
  1586. if (dp_mode->capabilities & DP_PANEL_CAPS_DSC)
  1587. pr_debug("in_use:%d, max:%d, free:%d, req:%d, caps:0x%x, width:%d\n",
  1588. dp->tot_dsc_blks_in_use, dp->parser->max_dp_dsc_blks,
  1589. free_dsc_blks, required_dsc_blks, dp_mode->capabilities,
  1590. dp->parser->max_dp_dsc_input_width_pixs);
  1591. dp_panel->convert_to_dp_mode(dp_panel, drm_mode, dp_mode);
  1592. }
  1593. static int dp_display_config_hdr(struct dp_display *dp_display, void *panel,
  1594. struct drm_msm_ext_hdr_metadata *hdr, bool dhdr_update)
  1595. {
  1596. struct dp_panel *dp_panel;
  1597. struct dp_display_private *dp;
  1598. u64 core_clk_rate;
  1599. if (!dp_display || !panel) {
  1600. pr_err("invalid input\n");
  1601. return -EINVAL;
  1602. }
  1603. dp_panel = panel;
  1604. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1605. core_clk_rate = dp->power->clk_get_rate(dp->power, "core_clk");
  1606. if (!core_clk_rate) {
  1607. pr_err("invalid rate for core_clk\n");
  1608. return -EINVAL;
  1609. }
  1610. return dp_panel->setup_hdr(dp_panel, hdr, dhdr_update, core_clk_rate);
  1611. }
  1612. static int dp_display_create_workqueue(struct dp_display_private *dp)
  1613. {
  1614. dp->wq = create_singlethread_workqueue("drm_dp");
  1615. if (IS_ERR_OR_NULL(dp->wq)) {
  1616. pr_err("Error creating wq\n");
  1617. return -EPERM;
  1618. }
  1619. INIT_DELAYED_WORK(&dp->hdcp_cb_work, dp_display_hdcp_cb_work);
  1620. INIT_WORK(&dp->connect_work, dp_display_connect_work);
  1621. INIT_WORK(&dp->attention_work, dp_display_attention_work);
  1622. return 0;
  1623. }
  1624. static int dp_display_fsa4480_callback(struct notifier_block *self,
  1625. unsigned long event, void *data)
  1626. {
  1627. return 0;
  1628. }
  1629. static int dp_display_init_aux_switch(struct dp_display_private *dp)
  1630. {
  1631. int rc = 0;
  1632. const char *phandle = "qcom,dp-aux-switch";
  1633. struct notifier_block nb;
  1634. if (!dp->pdev->dev.of_node) {
  1635. pr_err("cannot find dev.of_node\n");
  1636. rc = -ENODEV;
  1637. goto end;
  1638. }
  1639. dp->aux_switch_node = of_parse_phandle(dp->pdev->dev.of_node,
  1640. phandle, 0);
  1641. if (!dp->aux_switch_node) {
  1642. pr_warn("cannot parse %s handle\n", phandle);
  1643. rc = -ENODEV;
  1644. goto end;
  1645. }
  1646. nb.notifier_call = dp_display_fsa4480_callback;
  1647. nb.priority = 0;
  1648. rc = fsa4480_reg_notifier(&nb, dp->aux_switch_node);
  1649. if (rc) {
  1650. pr_err("failed to register notifier (%d)\n", rc);
  1651. goto end;
  1652. }
  1653. fsa4480_unreg_notifier(&nb, dp->aux_switch_node);
  1654. end:
  1655. return rc;
  1656. }
  1657. static int dp_display_mst_install(struct dp_display *dp_display,
  1658. struct dp_mst_drm_install_info *mst_install_info)
  1659. {
  1660. struct dp_display_private *dp;
  1661. if (!dp_display || !mst_install_info) {
  1662. pr_err("invalid input\n");
  1663. return -EINVAL;
  1664. }
  1665. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1666. if (!mst_install_info->cbs->hpd || !mst_install_info->cbs->hpd_irq) {
  1667. pr_err("invalid mst cbs\n");
  1668. return -EINVAL;
  1669. }
  1670. dp_display->dp_mst_prv_info = mst_install_info->dp_mst_prv_info;
  1671. if (!dp->parser->has_mst) {
  1672. pr_debug("mst not enabled\n");
  1673. return -EPERM;
  1674. }
  1675. memcpy(&dp->mst.cbs, mst_install_info->cbs, sizeof(dp->mst.cbs));
  1676. dp->mst.drm_registered = true;
  1677. DP_MST_DEBUG("dp mst drm installed\n");
  1678. return 0;
  1679. }
  1680. static int dp_display_mst_uninstall(struct dp_display *dp_display)
  1681. {
  1682. struct dp_display_private *dp;
  1683. if (!dp_display) {
  1684. pr_err("invalid input\n");
  1685. return -EINVAL;
  1686. }
  1687. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1688. if (!dp->mst.drm_registered) {
  1689. pr_debug("drm mst not registered\n");
  1690. return -EPERM;
  1691. }
  1692. dp = container_of(dp_display, struct dp_display_private,
  1693. dp_display);
  1694. memset(&dp->mst.cbs, 0, sizeof(dp->mst.cbs));
  1695. dp->mst.drm_registered = false;
  1696. DP_MST_DEBUG("dp mst drm uninstalled\n");
  1697. return 0;
  1698. }
  1699. static int dp_display_mst_connector_install(struct dp_display *dp_display,
  1700. struct drm_connector *connector)
  1701. {
  1702. int rc = 0;
  1703. struct dp_panel_in panel_in;
  1704. struct dp_panel *dp_panel;
  1705. struct dp_display_private *dp;
  1706. struct dp_mst_connector *mst_connector;
  1707. if (!dp_display || !connector) {
  1708. pr_err("invalid input\n");
  1709. return -EINVAL;
  1710. }
  1711. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1712. mutex_lock(&dp->session_lock);
  1713. if (!dp->mst.drm_registered) {
  1714. pr_debug("drm mst not registered\n");
  1715. mutex_unlock(&dp->session_lock);
  1716. return -EPERM;
  1717. }
  1718. panel_in.dev = &dp->pdev->dev;
  1719. panel_in.aux = dp->aux;
  1720. panel_in.catalog = &dp->catalog->panel;
  1721. panel_in.link = dp->link;
  1722. panel_in.connector = connector;
  1723. panel_in.base_panel = dp->panel;
  1724. panel_in.parser = dp->parser;
  1725. dp_panel = dp_panel_get(&panel_in);
  1726. if (IS_ERR(dp_panel)) {
  1727. rc = PTR_ERR(dp_panel);
  1728. pr_err("failed to initialize panel, rc = %d\n", rc);
  1729. mutex_unlock(&dp->session_lock);
  1730. return rc;
  1731. }
  1732. dp_panel->audio = dp_audio_get(dp->pdev, dp_panel, &dp->catalog->audio);
  1733. if (IS_ERR(dp_panel->audio)) {
  1734. rc = PTR_ERR(dp_panel->audio);
  1735. pr_err("[mst] failed to initialize audio, rc = %d\n", rc);
  1736. dp_panel->audio = NULL;
  1737. mutex_unlock(&dp->session_lock);
  1738. return rc;
  1739. }
  1740. DP_MST_DEBUG("dp mst connector installed. conn:%d\n",
  1741. connector->base.id);
  1742. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  1743. mst_connector = kmalloc(sizeof(struct dp_mst_connector),
  1744. GFP_KERNEL);
  1745. if (!mst_connector) {
  1746. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  1747. mutex_unlock(&dp->session_lock);
  1748. return -ENOMEM;
  1749. }
  1750. mst_connector->debug_en = false;
  1751. mst_connector->conn = connector;
  1752. mst_connector->con_id = connector->base.id;
  1753. mst_connector->state = connector_status_unknown;
  1754. INIT_LIST_HEAD(&mst_connector->list);
  1755. list_add(&mst_connector->list,
  1756. &dp->debug->dp_mst_connector_list.list);
  1757. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  1758. mutex_unlock(&dp->session_lock);
  1759. return 0;
  1760. }
  1761. static int dp_display_mst_connector_uninstall(struct dp_display *dp_display,
  1762. struct drm_connector *connector)
  1763. {
  1764. int rc = 0;
  1765. struct sde_connector *sde_conn;
  1766. struct dp_panel *dp_panel;
  1767. struct dp_display_private *dp;
  1768. struct dp_mst_connector *con_to_remove, *temp_con;
  1769. if (!dp_display || !connector) {
  1770. pr_err("invalid input\n");
  1771. return -EINVAL;
  1772. }
  1773. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1774. mutex_lock(&dp->session_lock);
  1775. if (!dp->mst.drm_registered) {
  1776. pr_debug("drm mst not registered\n");
  1777. mutex_unlock(&dp->session_lock);
  1778. return -EPERM;
  1779. }
  1780. sde_conn = to_sde_connector(connector);
  1781. if (!sde_conn->drv_panel) {
  1782. pr_err("invalid panel for connector:%d\n", connector->base.id);
  1783. mutex_unlock(&dp->session_lock);
  1784. return -EINVAL;
  1785. }
  1786. dp_panel = sde_conn->drv_panel;
  1787. dp_audio_put(dp_panel->audio);
  1788. dp_panel_put(dp_panel);
  1789. DP_MST_DEBUG("dp mst connector uninstalled. conn:%d\n",
  1790. connector->base.id);
  1791. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  1792. list_for_each_entry_safe(con_to_remove, temp_con,
  1793. &dp->debug->dp_mst_connector_list.list, list) {
  1794. if (con_to_remove->conn == connector) {
  1795. list_del(&con_to_remove->list);
  1796. kfree(con_to_remove);
  1797. }
  1798. }
  1799. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  1800. mutex_unlock(&dp->session_lock);
  1801. return rc;
  1802. }
  1803. static int dp_display_mst_get_connector_info(struct dp_display *dp_display,
  1804. struct drm_connector *connector,
  1805. struct dp_mst_connector *mst_conn)
  1806. {
  1807. struct dp_display_private *dp;
  1808. struct dp_mst_connector *conn, *temp_conn;
  1809. if (!connector || !mst_conn) {
  1810. pr_err("invalid input\n");
  1811. return -EINVAL;
  1812. }
  1813. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1814. mutex_lock(&dp->session_lock);
  1815. if (!dp->mst.drm_registered) {
  1816. pr_debug("drm mst not registered\n");
  1817. mutex_unlock(&dp->session_lock);
  1818. return -EPERM;
  1819. }
  1820. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  1821. list_for_each_entry_safe(conn, temp_conn,
  1822. &dp->debug->dp_mst_connector_list.list, list) {
  1823. if (conn->con_id == connector->base.id)
  1824. memcpy(mst_conn, conn, sizeof(*mst_conn));
  1825. }
  1826. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  1827. mutex_unlock(&dp->session_lock);
  1828. return 0;
  1829. }
  1830. static int dp_display_mst_connector_update_edid(struct dp_display *dp_display,
  1831. struct drm_connector *connector,
  1832. struct edid *edid)
  1833. {
  1834. int rc = 0;
  1835. struct sde_connector *sde_conn;
  1836. struct dp_panel *dp_panel;
  1837. struct dp_display_private *dp;
  1838. if (!dp_display || !connector || !edid) {
  1839. pr_err("invalid input\n");
  1840. return -EINVAL;
  1841. }
  1842. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1843. if (!dp->mst.drm_registered) {
  1844. pr_debug("drm mst not registered\n");
  1845. return -EPERM;
  1846. }
  1847. sde_conn = to_sde_connector(connector);
  1848. if (!sde_conn->drv_panel) {
  1849. pr_err("invalid panel for connector:%d\n", connector->base.id);
  1850. return -EINVAL;
  1851. }
  1852. dp_panel = sde_conn->drv_panel;
  1853. rc = dp_panel->update_edid(dp_panel, edid);
  1854. DP_MST_DEBUG("dp mst connector:%d edid updated. mode_cnt:%d\n",
  1855. connector->base.id, rc);
  1856. return rc;
  1857. }
  1858. static int dp_display_update_pps(struct dp_display *dp_display,
  1859. struct drm_connector *connector, char *pps_cmd)
  1860. {
  1861. struct sde_connector *sde_conn;
  1862. struct dp_panel *dp_panel;
  1863. struct dp_display_private *dp;
  1864. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1865. sde_conn = to_sde_connector(connector);
  1866. if (!sde_conn->drv_panel) {
  1867. pr_err("invalid panel for connector:%d\n", connector->base.id);
  1868. return -EINVAL;
  1869. }
  1870. dp_panel = sde_conn->drv_panel;
  1871. dp_panel->update_pps(dp_panel, pps_cmd);
  1872. return 0;
  1873. }
  1874. static int dp_display_mst_connector_update_link_info(
  1875. struct dp_display *dp_display,
  1876. struct drm_connector *connector)
  1877. {
  1878. int rc = 0;
  1879. struct sde_connector *sde_conn;
  1880. struct dp_panel *dp_panel;
  1881. struct dp_display_private *dp;
  1882. if (!dp_display || !connector) {
  1883. pr_err("invalid input\n");
  1884. return -EINVAL;
  1885. }
  1886. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1887. if (!dp->mst.drm_registered) {
  1888. pr_debug("drm mst not registered\n");
  1889. return -EPERM;
  1890. }
  1891. sde_conn = to_sde_connector(connector);
  1892. if (!sde_conn->drv_panel) {
  1893. pr_err("invalid panel for connector:%d\n", connector->base.id);
  1894. return -EINVAL;
  1895. }
  1896. dp_panel = sde_conn->drv_panel;
  1897. memcpy(dp_panel->dpcd, dp->panel->dpcd,
  1898. DP_RECEIVER_CAP_SIZE + 1);
  1899. memcpy(dp_panel->dsc_dpcd, dp->panel->dsc_dpcd,
  1900. DP_RECEIVER_DSC_CAP_SIZE + 1);
  1901. memcpy(&dp_panel->link_info, &dp->panel->link_info,
  1902. sizeof(dp_panel->link_info));
  1903. DP_MST_DEBUG("dp mst connector:%d link info updated\n");
  1904. return rc;
  1905. }
  1906. static int dp_display_mst_get_fixed_topology_port(
  1907. struct dp_display *dp_display,
  1908. u32 strm_id, u32 *port_num)
  1909. {
  1910. struct dp_display_private *dp;
  1911. u32 port;
  1912. if (!dp_display) {
  1913. pr_err("invalid input\n");
  1914. return -EINVAL;
  1915. }
  1916. if (strm_id >= DP_STREAM_MAX) {
  1917. pr_err("invalid stream id:%d\n", strm_id);
  1918. return -EINVAL;
  1919. }
  1920. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1921. port = dp->parser->mst_fixed_port[strm_id];
  1922. if (!port || port > 255)
  1923. return -ENOENT;
  1924. if (port_num)
  1925. *port_num = port;
  1926. return 0;
  1927. }
  1928. static int dp_display_get_mst_caps(struct dp_display *dp_display,
  1929. struct dp_mst_caps *mst_caps)
  1930. {
  1931. int rc = 0;
  1932. struct dp_display_private *dp;
  1933. if (!dp_display || !mst_caps) {
  1934. pr_err("invalid input\n");
  1935. return -EINVAL;
  1936. }
  1937. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1938. mst_caps->has_mst = dp->parser->has_mst;
  1939. mst_caps->max_streams_supported = (mst_caps->has_mst) ? 2 : 0;
  1940. mst_caps->max_dpcd_transaction_bytes = (mst_caps->has_mst) ? 16 : 0;
  1941. mst_caps->drm_aux = dp->aux->drm_aux;
  1942. return rc;
  1943. }
  1944. static int dp_display_probe(struct platform_device *pdev)
  1945. {
  1946. int rc = 0;
  1947. struct dp_display_private *dp;
  1948. if (!pdev || !pdev->dev.of_node) {
  1949. pr_err("pdev not found\n");
  1950. rc = -ENODEV;
  1951. goto bail;
  1952. }
  1953. dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
  1954. if (!dp) {
  1955. rc = -ENOMEM;
  1956. goto bail;
  1957. }
  1958. init_completion(&dp->notification_comp);
  1959. dp->pdev = pdev;
  1960. dp->name = "drm_dp";
  1961. memset(&dp->mst, 0, sizeof(dp->mst));
  1962. atomic_set(&dp->aborted, 0);
  1963. rc = dp_display_init_aux_switch(dp);
  1964. if (rc) {
  1965. rc = -EPROBE_DEFER;
  1966. goto error;
  1967. }
  1968. rc = dp_display_create_workqueue(dp);
  1969. if (rc) {
  1970. pr_err("Failed to create workqueue\n");
  1971. goto error;
  1972. }
  1973. platform_set_drvdata(pdev, dp);
  1974. g_dp_display = &dp->dp_display;
  1975. g_dp_display->enable = dp_display_enable;
  1976. g_dp_display->post_enable = dp_display_post_enable;
  1977. g_dp_display->pre_disable = dp_display_pre_disable;
  1978. g_dp_display->disable = dp_display_disable;
  1979. g_dp_display->set_mode = dp_display_set_mode;
  1980. g_dp_display->validate_mode = dp_display_validate_mode;
  1981. g_dp_display->get_modes = dp_display_get_modes;
  1982. g_dp_display->prepare = dp_display_prepare;
  1983. g_dp_display->unprepare = dp_display_unprepare;
  1984. g_dp_display->request_irq = dp_request_irq;
  1985. g_dp_display->get_debug = dp_get_debug;
  1986. g_dp_display->post_open = NULL;
  1987. g_dp_display->post_init = dp_display_post_init;
  1988. g_dp_display->config_hdr = dp_display_config_hdr;
  1989. g_dp_display->mst_install = dp_display_mst_install;
  1990. g_dp_display->mst_uninstall = dp_display_mst_uninstall;
  1991. g_dp_display->mst_connector_install = dp_display_mst_connector_install;
  1992. g_dp_display->mst_connector_uninstall =
  1993. dp_display_mst_connector_uninstall;
  1994. g_dp_display->mst_connector_update_edid =
  1995. dp_display_mst_connector_update_edid;
  1996. g_dp_display->mst_connector_update_link_info =
  1997. dp_display_mst_connector_update_link_info;
  1998. g_dp_display->get_mst_caps = dp_display_get_mst_caps;
  1999. g_dp_display->set_stream_info = dp_display_set_stream_info;
  2000. g_dp_display->update_pps = dp_display_update_pps;
  2001. g_dp_display->convert_to_dp_mode = dp_display_convert_to_dp_mode;
  2002. g_dp_display->mst_get_connector_info =
  2003. dp_display_mst_get_connector_info;
  2004. g_dp_display->mst_get_fixed_topology_port =
  2005. dp_display_mst_get_fixed_topology_port;
  2006. rc = component_add(&pdev->dev, &dp_display_comp_ops);
  2007. if (rc) {
  2008. pr_err("component add failed, rc=%d\n", rc);
  2009. goto error;
  2010. }
  2011. return 0;
  2012. error:
  2013. devm_kfree(&pdev->dev, dp);
  2014. bail:
  2015. return rc;
  2016. }
  2017. int dp_display_get_displays(void **displays, int count)
  2018. {
  2019. if (!displays) {
  2020. pr_err("invalid data\n");
  2021. return -EINVAL;
  2022. }
  2023. if (count != 1) {
  2024. pr_err("invalid number of displays\n");
  2025. return -EINVAL;
  2026. }
  2027. displays[0] = g_dp_display;
  2028. return count;
  2029. }
  2030. int dp_display_get_num_of_displays(void)
  2031. {
  2032. if (!g_dp_display)
  2033. return 0;
  2034. return 1;
  2035. }
  2036. int dp_display_get_num_of_streams(void)
  2037. {
  2038. return DP_STREAM_MAX;
  2039. }
  2040. static void dp_display_set_mst_state(void *dp_display,
  2041. enum dp_drv_state mst_state)
  2042. {
  2043. struct dp_display_private *dp;
  2044. if (!g_dp_display) {
  2045. pr_debug("dp display not initialized\n");
  2046. return;
  2047. }
  2048. dp = container_of(g_dp_display, struct dp_display_private, dp_display);
  2049. if (dp->mst.mst_active && dp->mst.cbs.set_drv_state)
  2050. dp->mst.cbs.set_drv_state(g_dp_display, mst_state);
  2051. }
  2052. static int dp_display_remove(struct platform_device *pdev)
  2053. {
  2054. struct dp_display_private *dp;
  2055. if (!pdev)
  2056. return -EINVAL;
  2057. dp = platform_get_drvdata(pdev);
  2058. dp_display_deinit_sub_modules(dp);
  2059. if (dp->wq)
  2060. destroy_workqueue(dp->wq);
  2061. platform_set_drvdata(pdev, NULL);
  2062. devm_kfree(&pdev->dev, dp);
  2063. return 0;
  2064. }
  2065. static int dp_pm_prepare(struct device *dev)
  2066. {
  2067. dp_display_set_mst_state(g_dp_display, PM_SUSPEND);
  2068. return 0;
  2069. }
  2070. static void dp_pm_complete(struct device *dev)
  2071. {
  2072. dp_display_set_mst_state(g_dp_display, PM_DEFAULT);
  2073. }
  2074. static const struct dev_pm_ops dp_pm_ops = {
  2075. .prepare = dp_pm_prepare,
  2076. .complete = dp_pm_complete,
  2077. };
  2078. static struct platform_driver dp_display_driver = {
  2079. .probe = dp_display_probe,
  2080. .remove = dp_display_remove,
  2081. .driver = {
  2082. .name = "msm-dp-display",
  2083. .of_match_table = dp_dt_match,
  2084. .suppress_bind_attrs = true,
  2085. .pm = &dp_pm_ops,
  2086. },
  2087. };
  2088. static int __init dp_display_init(void)
  2089. {
  2090. int ret;
  2091. ret = platform_driver_register(&dp_display_driver);
  2092. if (ret) {
  2093. pr_err("driver register failed\n");
  2094. return ret;
  2095. }
  2096. return ret;
  2097. }
  2098. late_initcall(dp_display_init);
  2099. static void __exit dp_display_cleanup(void)
  2100. {
  2101. platform_driver_unregister(&dp_display_driver);
  2102. }
  2103. module_exit(dp_display_cleanup);