dp_display.c 89 KB

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