dp_display.c 82 KB

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