dp_display.c 69 KB

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