dp_display.c 70 KB

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