dp_display.c 70 KB

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