dp_display.c 70 KB

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