dp_debug.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/debugfs.h>
  6. #include <linux/slab.h>
  7. #include <drm/drm_dp_mst_helper.h>
  8. #include <drm/drm_probe_helper.h>
  9. #include "dp_power.h"
  10. #include "dp_catalog.h"
  11. #include "dp_aux.h"
  12. #include "dp_debug.h"
  13. #include "drm/drm_connector.h"
  14. #include "sde_connector.h"
  15. #include "dp_display.h"
  16. #include "dp_pll.h"
  17. #include "dp_hpd.h"
  18. #include "dp_mst_sim.h"
  19. #include "dp_mst_drm.h"
  20. #define DEBUG_NAME "drm_dp"
  21. struct dp_debug_private {
  22. struct dentry *root;
  23. u32 dpcd_offset;
  24. u32 dpcd_size;
  25. u32 mst_con_id;
  26. u32 mst_edid_idx;
  27. bool hotplug;
  28. u32 sim_mode;
  29. char exe_mode[SZ_32];
  30. char reg_dump[SZ_32];
  31. struct dp_hpd *hpd;
  32. struct dp_link *link;
  33. struct dp_panel *panel;
  34. struct dp_aux *aux;
  35. struct dp_catalog *catalog;
  36. struct drm_connector **connector;
  37. struct device *dev;
  38. struct dp_debug dp_debug;
  39. struct dp_parser *parser;
  40. struct dp_ctrl *ctrl;
  41. struct dp_pll *pll;
  42. struct dp_display *display;
  43. struct mutex lock;
  44. struct dp_aux_bridge *sim_bridge;
  45. };
  46. static int dp_debug_sim_hpd_cb(void *arg, bool hpd, bool hpd_irq)
  47. {
  48. struct dp_debug_private *debug = arg;
  49. int vdo = 0;
  50. if (hpd_irq) {
  51. vdo |= BIT(7);
  52. if (hpd)
  53. vdo |= BIT(8);
  54. return debug->hpd->simulate_attention(debug->hpd, vdo);
  55. } else {
  56. return debug->hpd->simulate_connect(debug->hpd, hpd);
  57. }
  58. }
  59. static int dp_debug_attach_sim_bridge(struct dp_debug_private *debug)
  60. {
  61. int ret;
  62. if (debug->sim_bridge)
  63. return 0;
  64. ret = dp_sim_create_bridge(debug->dev, &debug->sim_bridge);
  65. if (ret)
  66. return ret;
  67. dp_sim_update_port_num(debug->sim_bridge, 1);
  68. if (debug->sim_bridge->register_hpd)
  69. debug->sim_bridge->register_hpd(debug->sim_bridge,
  70. dp_debug_sim_hpd_cb, debug);
  71. return 0;
  72. }
  73. static void dp_debug_enable_sim_mode(struct dp_debug_private *debug,
  74. u32 mode_mask)
  75. {
  76. /* return if mode is already enabled */
  77. if ((debug->sim_mode & mode_mask) == mode_mask)
  78. return;
  79. /* create bridge if not yet */
  80. if (dp_debug_attach_sim_bridge(debug))
  81. return;
  82. /* switch to bridge mode */
  83. if (!debug->sim_mode)
  84. debug->aux->set_sim_mode(debug->aux, debug->sim_bridge);
  85. /* update sim mode */
  86. debug->sim_mode |= mode_mask;
  87. dp_sim_set_sim_mode(debug->sim_bridge, debug->sim_mode);
  88. }
  89. static void dp_debug_disable_sim_mode(struct dp_debug_private *debug,
  90. u32 mode_mask)
  91. {
  92. /* return if mode is already disabled */
  93. if (!(debug->sim_mode & mode_mask))
  94. return;
  95. /* update sim mode */
  96. debug->sim_mode &= ~mode_mask;
  97. dp_sim_set_sim_mode(debug->sim_bridge, debug->sim_mode);
  98. /* switch to normal mode */
  99. if (!debug->sim_mode)
  100. debug->aux->set_sim_mode(debug->aux, NULL);
  101. }
  102. static ssize_t dp_debug_write_edid(struct file *file,
  103. const char __user *user_buff, size_t count, loff_t *ppos)
  104. {
  105. struct dp_debug_private *debug = file->private_data;
  106. u8 *buf = NULL, *buf_t = NULL, *edid = NULL;
  107. const int char_to_nib = 2;
  108. size_t edid_size = 0;
  109. size_t size = 0, edid_buf_index = 0;
  110. ssize_t rc = count;
  111. if (!debug)
  112. return -ENODEV;
  113. mutex_lock(&debug->lock);
  114. if (*ppos)
  115. goto bail;
  116. size = min_t(size_t, count, SZ_1K);
  117. buf = kzalloc(size, GFP_KERNEL);
  118. if (ZERO_OR_NULL_PTR(buf)) {
  119. rc = -ENOMEM;
  120. goto bail;
  121. }
  122. if (copy_from_user(buf, user_buff, size))
  123. goto bail;
  124. edid_size = size / char_to_nib;
  125. buf_t = buf;
  126. size = edid_size;
  127. edid = kzalloc(size, GFP_KERNEL);
  128. if (!edid)
  129. goto bail;
  130. while (size--) {
  131. char t[3];
  132. int d;
  133. memcpy(t, buf_t, sizeof(char) * char_to_nib);
  134. t[char_to_nib] = '\0';
  135. if (kstrtoint(t, 16, &d)) {
  136. DP_ERR("kstrtoint error\n");
  137. goto bail;
  138. }
  139. edid[edid_buf_index++] = d;
  140. buf_t += char_to_nib;
  141. }
  142. dp_debug_enable_sim_mode(debug, DP_SIM_MODE_EDID);
  143. dp_mst_clear_edid_cache(debug->display);
  144. dp_sim_update_port_edid(debug->sim_bridge, debug->mst_edid_idx,
  145. edid, edid_size);
  146. bail:
  147. kfree(buf);
  148. kfree(edid);
  149. mutex_unlock(&debug->lock);
  150. return rc;
  151. }
  152. static ssize_t dp_debug_write_dpcd(struct file *file,
  153. const char __user *user_buff, size_t count, loff_t *ppos)
  154. {
  155. struct dp_debug_private *debug = file->private_data;
  156. u8 *buf = NULL, *buf_t = NULL, *dpcd = NULL;
  157. const int char_to_nib = 2;
  158. size_t dpcd_size = 0;
  159. size_t size = 0, dpcd_buf_index = 0;
  160. ssize_t rc = count;
  161. char offset_ch[5];
  162. u32 offset, data_len;
  163. if (!debug)
  164. return -ENODEV;
  165. mutex_lock(&debug->lock);
  166. if (*ppos)
  167. goto bail;
  168. size = min_t(size_t, count, SZ_2K);
  169. if (size <= 4)
  170. goto bail;
  171. buf = kzalloc(size, GFP_KERNEL);
  172. if (ZERO_OR_NULL_PTR(buf)) {
  173. rc = -ENOMEM;
  174. goto bail;
  175. }
  176. if (copy_from_user(buf, user_buff, size))
  177. goto bail;
  178. memcpy(offset_ch, buf, 4);
  179. offset_ch[4] = '\0';
  180. if (kstrtoint(offset_ch, 16, &offset)) {
  181. DP_ERR("offset kstrtoint error\n");
  182. goto bail;
  183. }
  184. size -= 4;
  185. if (size == 0)
  186. goto bail;
  187. dpcd_size = size / char_to_nib;
  188. data_len = dpcd_size;
  189. buf_t = buf + 4;
  190. dpcd = kzalloc(dpcd_size, GFP_KERNEL);
  191. if (ZERO_OR_NULL_PTR(dpcd)) {
  192. rc = -ENOMEM;
  193. goto bail;
  194. }
  195. while (dpcd_size--) {
  196. char t[3];
  197. int d;
  198. memcpy(t, buf_t, sizeof(char) * char_to_nib);
  199. t[char_to_nib] = '\0';
  200. if (kstrtoint(t, 16, &d)) {
  201. DP_ERR("kstrtoint error\n");
  202. goto bail;
  203. }
  204. dpcd[dpcd_buf_index++] = d;
  205. buf_t += char_to_nib;
  206. }
  207. /*
  208. * if link training status registers are reprogramed,
  209. * read link training status from simulator, otherwise
  210. * read link training status from real aux channel.
  211. */
  212. if (offset <= DP_LANE0_1_STATUS &&
  213. offset + dpcd_buf_index > DP_LANE0_1_STATUS)
  214. dp_debug_enable_sim_mode(debug,
  215. DP_SIM_MODE_DPCD_READ | DP_SIM_MODE_LINK_TRAIN);
  216. else
  217. dp_debug_enable_sim_mode(debug, DP_SIM_MODE_DPCD_READ);
  218. dp_sim_write_dpcd_reg(debug->sim_bridge,
  219. dpcd, dpcd_buf_index, offset);
  220. debug->dpcd_offset = offset;
  221. debug->dpcd_size = dpcd_buf_index;
  222. bail:
  223. kfree(buf);
  224. kfree(dpcd);
  225. mutex_unlock(&debug->lock);
  226. return rc;
  227. }
  228. static ssize_t dp_debug_read_dpcd(struct file *file,
  229. char __user *user_buff, size_t count, loff_t *ppos)
  230. {
  231. struct dp_debug_private *debug = file->private_data;
  232. char *buf;
  233. int const buf_size = SZ_4K;
  234. u32 offset = 0;
  235. u32 len = 0;
  236. u8 *dpcd;
  237. if (!debug || !debug->aux)
  238. return -ENODEV;
  239. if (*ppos)
  240. return 0;
  241. buf = kzalloc(buf_size, GFP_KERNEL);
  242. if (!buf)
  243. return -ENOMEM;
  244. mutex_lock(&debug->lock);
  245. dpcd = kzalloc(buf_size, GFP_KERNEL);
  246. if (!dpcd)
  247. goto bail;
  248. /*
  249. * In simulation mode, this function returns the last written DPCD node.
  250. * For a real monitor plug in, it always dumps the first 16 DPCD registers.
  251. */
  252. if (debug->dp_debug.sim_mode) {
  253. dp_sim_read_dpcd_reg(debug->sim_bridge, dpcd, debug->dpcd_size, debug->dpcd_offset);
  254. } else {
  255. debug->dpcd_size = sizeof(debug->panel->dpcd);
  256. debug->dpcd_offset = 0;
  257. memcpy(dpcd, debug->panel->dpcd, debug->dpcd_size);
  258. }
  259. len += scnprintf(buf, buf_size, "%04x: ", debug->dpcd_offset);
  260. while (offset < debug->dpcd_size)
  261. len += scnprintf(buf + len, buf_size - len, "%02x ",
  262. dpcd[debug->dpcd_offset + offset++]);
  263. kfree(dpcd);
  264. len = min_t(size_t, count, len);
  265. if (!copy_to_user(user_buff, buf, len))
  266. *ppos += len;
  267. bail:
  268. mutex_unlock(&debug->lock);
  269. kfree(buf);
  270. return len;
  271. }
  272. static ssize_t dp_debug_write_hpd(struct file *file,
  273. const char __user *user_buff, size_t count, loff_t *ppos)
  274. {
  275. struct dp_debug_private *debug = file->private_data;
  276. char buf[SZ_8];
  277. size_t len = 0;
  278. int const hpd_data_mask = 0x7;
  279. int hpd = 0;
  280. if (!debug)
  281. return -ENODEV;
  282. if (*ppos)
  283. return 0;
  284. /* Leave room for termination char */
  285. len = min_t(size_t, count, SZ_8 - 1);
  286. if (copy_from_user(buf, user_buff, len))
  287. goto end;
  288. buf[len] = '\0';
  289. if (kstrtoint(buf, 10, &hpd) != 0)
  290. goto end;
  291. hpd &= hpd_data_mask;
  292. debug->hotplug = !!(hpd & BIT(0));
  293. debug->dp_debug.psm_enabled = !!(hpd & BIT(1));
  294. /*
  295. * print hotplug value as this code is executed
  296. * only while running in debug mode which is manually
  297. * triggered by a tester or a script.
  298. */
  299. DP_INFO("%s\n", debug->hotplug ? "[CONNECT]" : "[DISCONNECT]");
  300. debug->hpd->simulate_connect(debug->hpd, debug->hotplug);
  301. end:
  302. return len;
  303. }
  304. static ssize_t dp_debug_write_edid_modes(struct file *file,
  305. const char __user *user_buff, size_t count, loff_t *ppos)
  306. {
  307. struct dp_debug_private *debug = file->private_data;
  308. struct dp_panel *panel;
  309. char buf[SZ_32];
  310. size_t len = 0;
  311. int hdisplay = 0, vdisplay = 0, vrefresh = 0, aspect_ratio;
  312. if (!debug)
  313. return -ENODEV;
  314. if (*ppos)
  315. goto end;
  316. panel = debug->panel;
  317. /* Leave room for termination char */
  318. len = min_t(size_t, count, SZ_32 - 1);
  319. if (copy_from_user(buf, user_buff, len))
  320. goto clear;
  321. buf[len] = '\0';
  322. if (sscanf(buf, "%d %d %d %d", &hdisplay, &vdisplay, &vrefresh,
  323. &aspect_ratio) != 4)
  324. goto clear;
  325. if (!hdisplay || !vdisplay || !vrefresh)
  326. goto clear;
  327. panel->mode_override = true;
  328. panel->hdisplay = hdisplay;
  329. panel->vdisplay = vdisplay;
  330. panel->vrefresh = vrefresh;
  331. panel->aspect_ratio = aspect_ratio;
  332. goto end;
  333. clear:
  334. DP_DEBUG("clearing debug modes\n");
  335. panel->mode_override = false;
  336. end:
  337. return len;
  338. }
  339. static ssize_t dp_debug_write_edid_modes_mst(struct file *file,
  340. const char __user *user_buff, size_t count, loff_t *ppos)
  341. {
  342. struct dp_debug_private *debug = file->private_data;
  343. struct drm_connector *connector;
  344. struct sde_connector *sde_conn;
  345. struct dp_panel *panel = NULL;
  346. char buf[SZ_512];
  347. char *read_buf;
  348. size_t len = 0;
  349. int hdisplay = 0, vdisplay = 0, vrefresh = 0, aspect_ratio = 0;
  350. int con_id = 0, offset = 0, debug_en = 0;
  351. if (!debug)
  352. return -ENODEV;
  353. mutex_lock(&debug->lock);
  354. if (*ppos)
  355. goto end;
  356. len = min_t(size_t, count, SZ_512 - 1);
  357. if (copy_from_user(buf, user_buff, len))
  358. goto end;
  359. buf[len] = '\0';
  360. read_buf = buf;
  361. while (sscanf(read_buf, "%d %d %d %d %d %d%n", &debug_en, &con_id,
  362. &hdisplay, &vdisplay, &vrefresh, &aspect_ratio,
  363. &offset) == 6) {
  364. connector = drm_connector_lookup((*debug->connector)->dev,
  365. NULL, con_id);
  366. if (connector) {
  367. sde_conn = to_sde_connector(connector);
  368. panel = sde_conn->drv_panel;
  369. if (panel && sde_conn->mst_port) {
  370. panel->mode_override = debug_en;
  371. panel->hdisplay = hdisplay;
  372. panel->vdisplay = vdisplay;
  373. panel->vrefresh = vrefresh;
  374. panel->aspect_ratio = aspect_ratio;
  375. } else {
  376. DP_ERR("connector id %d is not mst\n", con_id);
  377. }
  378. drm_connector_put(connector);
  379. } else {
  380. DP_ERR("invalid connector id %d\n", con_id);
  381. }
  382. read_buf += offset;
  383. }
  384. end:
  385. mutex_unlock(&debug->lock);
  386. return len;
  387. }
  388. static ssize_t dp_debug_write_mst_con_id(struct file *file,
  389. const char __user *user_buff, size_t count, loff_t *ppos)
  390. {
  391. struct dp_debug_private *debug = file->private_data;
  392. struct drm_connector *connector;
  393. struct sde_connector *sde_conn;
  394. struct drm_dp_mst_port *mst_port;
  395. struct dp_panel *dp_panel;
  396. char buf[SZ_32];
  397. size_t len = 0;
  398. int con_id = 0, status;
  399. if (!debug)
  400. return -ENODEV;
  401. mutex_lock(&debug->lock);
  402. if (*ppos)
  403. goto end;
  404. /* Leave room for termination char */
  405. len = min_t(size_t, count, SZ_32 - 1);
  406. if (copy_from_user(buf, user_buff, len))
  407. goto clear;
  408. buf[len] = '\0';
  409. if (sscanf(buf, "%d %d", &con_id, &status) != 2)
  410. goto end;
  411. if (!con_id)
  412. goto clear;
  413. connector = drm_connector_lookup((*debug->connector)->dev,
  414. NULL, con_id);
  415. if (!connector) {
  416. DP_ERR("invalid connector id %u\n", con_id);
  417. goto end;
  418. }
  419. sde_conn = to_sde_connector(connector);
  420. if (!sde_conn->drv_panel || !sde_conn->mst_port) {
  421. DP_ERR("invalid connector state %d\n", con_id);
  422. goto out;
  423. }
  424. debug->mst_con_id = con_id;
  425. if (status == connector_status_connected)
  426. DP_INFO("plug mst connector %d\n", con_id);
  427. else
  428. DP_INFO("unplug mst connector %d\n", con_id);
  429. if (status == connector_status_unknown)
  430. goto out;
  431. mst_port = sde_conn->mst_port;
  432. dp_panel = sde_conn->drv_panel;
  433. if (debug->dp_debug.sim_mode) {
  434. dp_sim_update_port_status(debug->sim_bridge,
  435. mst_port->port_num, status);
  436. } else {
  437. dp_panel->mst_hide = (status == connector_status_disconnected);
  438. drm_kms_helper_hotplug_event(connector->dev);
  439. }
  440. out:
  441. drm_connector_put(connector);
  442. goto end;
  443. clear:
  444. DP_DEBUG("clearing mst_con_id\n");
  445. debug->mst_con_id = 0;
  446. end:
  447. mutex_unlock(&debug->lock);
  448. return len;
  449. }
  450. static ssize_t dp_debug_write_mst_con_add(struct file *file,
  451. const char __user *user_buff, size_t count, loff_t *ppos)
  452. {
  453. struct dp_debug_private *debug = file->private_data;
  454. char buf[SZ_32];
  455. size_t len = 0;
  456. const int dp_en = BIT(3), hpd_high = BIT(7), hpd_irq = BIT(8);
  457. int vdo = dp_en | hpd_high | hpd_irq;
  458. if (!debug)
  459. return -ENODEV;
  460. if (*ppos)
  461. return 0;
  462. /* Leave room for termination char */
  463. len = min_t(size_t, count, SZ_32 - 1);
  464. if (copy_from_user(buf, user_buff, len))
  465. goto end;
  466. debug->dp_debug.mst_sim_add_con = true;
  467. debug->hpd->simulate_attention(debug->hpd, vdo);
  468. end:
  469. return len;
  470. }
  471. static ssize_t dp_debug_write_mst_con_remove(struct file *file,
  472. const char __user *user_buff, size_t count, loff_t *ppos)
  473. {
  474. struct dp_debug_private *debug = file->private_data;
  475. struct drm_connector_list_iter conn_iter;
  476. struct drm_connector *connector;
  477. char buf[SZ_32];
  478. size_t len = 0;
  479. int con_id = 0;
  480. bool in_list = false;
  481. const int dp_en = BIT(3), hpd_high = BIT(7), hpd_irq = BIT(8);
  482. int vdo = dp_en | hpd_high | hpd_irq;
  483. if (!debug)
  484. return -ENODEV;
  485. if (*ppos)
  486. return 0;
  487. /* Leave room for termination char */
  488. len = min_t(size_t, count, SZ_32 - 1);
  489. if (copy_from_user(buf, user_buff, len))
  490. goto end;
  491. buf[len] = '\0';
  492. if (sscanf(buf, "%d", &con_id) != 1) {
  493. len = 0;
  494. goto end;
  495. }
  496. if (!con_id)
  497. goto end;
  498. drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
  499. drm_for_each_connector_iter(connector, &conn_iter) {
  500. if (connector->base.id == con_id) {
  501. in_list = true;
  502. break;
  503. }
  504. }
  505. drm_connector_list_iter_end(&conn_iter);
  506. if (!in_list) {
  507. DRM_ERROR("invalid connector id %u\n", con_id);
  508. goto end;
  509. }
  510. debug->dp_debug.mst_sim_remove_con = true;
  511. debug->dp_debug.mst_sim_remove_con_id = con_id;
  512. debug->hpd->simulate_attention(debug->hpd, vdo);
  513. end:
  514. return len;
  515. }
  516. static ssize_t dp_debug_mmrm_clk_cb_write(struct file *file,
  517. const char __user *user_buff, size_t count, loff_t *ppos)
  518. {
  519. struct dp_debug_private *debug = file->private_data;
  520. char buf[SZ_8];
  521. size_t len = 0;
  522. struct dss_clk_mmrm_cb mmrm_cb_data;
  523. struct mmrm_client_notifier_data notifier_data;
  524. struct dp_display *dp_display;
  525. int cb_type;
  526. if (!debug)
  527. return -ENODEV;
  528. if (*ppos)
  529. return 0;
  530. dp_display = debug->display;
  531. len = min_t(size_t, count, SZ_8 - 1);
  532. if (copy_from_user(buf, user_buff, len))
  533. return 0;
  534. buf[len] = '\0';
  535. if (kstrtoint(buf, 10, &cb_type) != 0)
  536. return 0;
  537. if (cb_type != MMRM_CLIENT_RESOURCE_VALUE_CHANGE)
  538. return 0;
  539. notifier_data.cb_type = MMRM_CLIENT_RESOURCE_VALUE_CHANGE;
  540. mmrm_cb_data.phandle = (void *)dp_display;
  541. notifier_data.pvt_data = (void *)&mmrm_cb_data;
  542. dp_display_mmrm_callback(&notifier_data);
  543. return len;
  544. }
  545. static ssize_t dp_debug_bw_code_write(struct file *file,
  546. const char __user *user_buff, size_t count, loff_t *ppos)
  547. {
  548. struct dp_debug_private *debug = file->private_data;
  549. char buf[SZ_8];
  550. size_t len = 0;
  551. u32 max_bw_code = 0;
  552. if (!debug)
  553. return -ENODEV;
  554. if (*ppos)
  555. return 0;
  556. /* Leave room for termination char */
  557. len = min_t(size_t, count, SZ_8 - 1);
  558. if (copy_from_user(buf, user_buff, len))
  559. return 0;
  560. buf[len] = '\0';
  561. if (kstrtoint(buf, 10, &max_bw_code) != 0)
  562. return 0;
  563. if (!is_link_rate_valid(max_bw_code)) {
  564. DP_ERR("Unsupported bw code %d\n", max_bw_code);
  565. return len;
  566. }
  567. debug->panel->max_bw_code = max_bw_code;
  568. DP_DEBUG("max_bw_code: %d\n", max_bw_code);
  569. return len;
  570. }
  571. static ssize_t dp_debug_mst_mode_read(struct file *file,
  572. char __user *user_buff, size_t count, loff_t *ppos)
  573. {
  574. struct dp_debug_private *debug = file->private_data;
  575. char buf[64];
  576. ssize_t len;
  577. len = scnprintf(buf, sizeof(buf),
  578. "mst_mode = %d, mst_state = %d\n",
  579. debug->parser->has_mst,
  580. debug->panel->mst_state);
  581. return simple_read_from_buffer(user_buff, count, ppos, buf, len);
  582. }
  583. static ssize_t dp_debug_mst_mode_write(struct file *file,
  584. const char __user *user_buff, size_t count, loff_t *ppos)
  585. {
  586. struct dp_debug_private *debug = file->private_data;
  587. char buf[SZ_8];
  588. size_t len = 0;
  589. u32 mst_mode = 0;
  590. if (!debug)
  591. return -ENODEV;
  592. if (*ppos)
  593. return 0;
  594. len = min_t(size_t, count, SZ_8 - 1);
  595. if (copy_from_user(buf, user_buff, len))
  596. return 0;
  597. buf[len] = '\0';
  598. if (kstrtoint(buf, 10, &mst_mode) != 0)
  599. return 0;
  600. debug->parser->has_mst = mst_mode ? true : false;
  601. DP_DEBUG("mst_enable: %d\n", mst_mode);
  602. return len;
  603. }
  604. static ssize_t dp_debug_max_pclk_khz_write(struct file *file,
  605. const char __user *user_buff, size_t count, loff_t *ppos)
  606. {
  607. struct dp_debug_private *debug = file->private_data;
  608. char buf[SZ_8];
  609. size_t len = 0;
  610. u32 max_pclk = 0;
  611. if (!debug)
  612. return -ENODEV;
  613. if (*ppos)
  614. return 0;
  615. len = min_t(size_t, count, SZ_8 - 1);
  616. if (copy_from_user(buf, user_buff, len))
  617. return 0;
  618. buf[len] = '\0';
  619. if (kstrtoint(buf, 10, &max_pclk) != 0)
  620. return 0;
  621. if (max_pclk > debug->parser->max_pclk_khz)
  622. DP_ERR("requested: %d, max_pclk_khz:%d\n", max_pclk,
  623. debug->parser->max_pclk_khz);
  624. else
  625. debug->dp_debug.max_pclk_khz = max_pclk;
  626. DP_DEBUG("max_pclk_khz: %d\n", max_pclk);
  627. return len;
  628. }
  629. static ssize_t dp_debug_max_pclk_khz_read(struct file *file,
  630. char __user *user_buff, size_t count, loff_t *ppos)
  631. {
  632. struct dp_debug_private *debug = file->private_data;
  633. char *buf;
  634. u32 len = 0;
  635. if (!debug)
  636. return -ENODEV;
  637. if (*ppos)
  638. return 0;
  639. buf = kzalloc(SZ_4K, GFP_KERNEL);
  640. if (ZERO_OR_NULL_PTR(buf))
  641. return -ENOMEM;
  642. len += snprintf(buf + len, (SZ_4K - len),
  643. "max_pclk_khz = %d, org: %d\n",
  644. debug->dp_debug.max_pclk_khz,
  645. debug->parser->max_pclk_khz);
  646. len = min_t(size_t, count, len);
  647. if (copy_to_user(user_buff, buf, len)) {
  648. kfree(buf);
  649. return -EFAULT;
  650. }
  651. *ppos += len;
  652. kfree(buf);
  653. return len;
  654. }
  655. static ssize_t dp_debug_mst_sideband_mode_write(struct file *file,
  656. const char __user *user_buff, size_t count, loff_t *ppos)
  657. {
  658. struct dp_debug_private *debug = file->private_data;
  659. char buf[SZ_8];
  660. size_t len = 0;
  661. int mst_sideband_mode = 0;
  662. u32 mst_port_cnt = 0;
  663. if (!debug)
  664. return -ENODEV;
  665. mutex_lock(&debug->lock);
  666. /* Leave room for termination char */
  667. len = min_t(size_t, count, SZ_8 - 1);
  668. if (copy_from_user(buf, user_buff, len))
  669. return -EFAULT;
  670. buf[len] = '\0';
  671. if (sscanf(buf, "%d %u", &mst_sideband_mode, &mst_port_cnt) != 2) {
  672. DP_ERR("invalid input\n");
  673. goto bail;
  674. }
  675. if (!mst_port_cnt)
  676. mst_port_cnt = 1;
  677. debug->mst_edid_idx = 0;
  678. if (mst_sideband_mode)
  679. dp_debug_disable_sim_mode(debug, DP_SIM_MODE_MST);
  680. else
  681. dp_debug_enable_sim_mode(debug, DP_SIM_MODE_MST);
  682. dp_sim_update_port_num(debug->sim_bridge, mst_port_cnt);
  683. buf[0] = !mst_sideband_mode;
  684. dp_sim_write_dpcd_reg(debug->sim_bridge, buf, 1, DP_MSTM_CAP);
  685. DP_DEBUG("mst_sideband_mode: %d port_cnt:%d\n",
  686. mst_sideband_mode, mst_port_cnt);
  687. bail:
  688. mutex_unlock(&debug->lock);
  689. return count;
  690. }
  691. static ssize_t dp_debug_tpg_write(struct file *file,
  692. const char __user *user_buff, size_t count, loff_t *ppos)
  693. {
  694. struct dp_debug_private *debug = file->private_data;
  695. char buf[SZ_8];
  696. size_t len = 0;
  697. u32 tpg_state = 0;
  698. if (!debug)
  699. return -ENODEV;
  700. if (*ppos)
  701. return 0;
  702. /* Leave room for termination char */
  703. len = min_t(size_t, count, SZ_8 - 1);
  704. if (copy_from_user(buf, user_buff, len))
  705. goto bail;
  706. buf[len] = '\0';
  707. if (kstrtoint(buf, 10, &tpg_state) != 0)
  708. goto bail;
  709. tpg_state &= 0x1;
  710. DP_DEBUG("tpg_state: %d\n", tpg_state);
  711. if (tpg_state == debug->dp_debug.tpg_state)
  712. goto bail;
  713. if (debug->panel)
  714. debug->panel->tpg_config(debug->panel, tpg_state);
  715. debug->dp_debug.tpg_state = tpg_state;
  716. bail:
  717. return len;
  718. }
  719. static ssize_t dp_debug_write_exe_mode(struct file *file,
  720. const char __user *user_buff, size_t count, loff_t *ppos)
  721. {
  722. struct dp_debug_private *debug = file->private_data;
  723. char buf[SZ_32];
  724. size_t len = 0;
  725. if (!debug)
  726. return -ENODEV;
  727. if (*ppos)
  728. return 0;
  729. len = min_t(size_t, count, SZ_32 - 1);
  730. if (copy_from_user(buf, user_buff, len))
  731. goto end;
  732. buf[len] = '\0';
  733. if (sscanf(buf, "%3s", debug->exe_mode) != 1)
  734. goto end;
  735. if (strcmp(debug->exe_mode, "hw") &&
  736. strcmp(debug->exe_mode, "sw") &&
  737. strcmp(debug->exe_mode, "all"))
  738. goto end;
  739. debug->catalog->set_exe_mode(debug->catalog, debug->exe_mode);
  740. end:
  741. return len;
  742. }
  743. static ssize_t dp_debug_read_connected(struct file *file,
  744. char __user *user_buff, size_t count, loff_t *ppos)
  745. {
  746. struct dp_debug_private *debug = file->private_data;
  747. char buf[SZ_8];
  748. u32 len = 0;
  749. if (!debug)
  750. return -ENODEV;
  751. if (*ppos)
  752. return 0;
  753. len += snprintf(buf, SZ_8, "%d\n", debug->hpd->hpd_high);
  754. len = min_t(size_t, count, len);
  755. if (copy_to_user(user_buff, buf, len))
  756. return -EFAULT;
  757. *ppos += len;
  758. return len;
  759. }
  760. static ssize_t dp_debug_write_hdcp(struct file *file,
  761. const char __user *user_buff, size_t count, loff_t *ppos)
  762. {
  763. struct dp_debug_private *debug = file->private_data;
  764. char buf[SZ_8];
  765. size_t len = 0;
  766. int hdcp = 0;
  767. if (!debug)
  768. return -ENODEV;
  769. if (*ppos)
  770. return 0;
  771. /* Leave room for termination char */
  772. len = min_t(size_t, count, SZ_8 - 1);
  773. if (copy_from_user(buf, user_buff, len))
  774. goto end;
  775. buf[len] = '\0';
  776. if (kstrtoint(buf, 10, &hdcp) != 0)
  777. goto end;
  778. debug->dp_debug.hdcp_disabled = !hdcp;
  779. end:
  780. return len;
  781. }
  782. static ssize_t dp_debug_read_hdcp(struct file *file,
  783. char __user *user_buff, size_t count, loff_t *ppos)
  784. {
  785. struct dp_debug_private *debug = file->private_data;
  786. u32 len = 0;
  787. if (!debug)
  788. return -ENODEV;
  789. if (*ppos)
  790. return 0;
  791. len = sizeof(debug->dp_debug.hdcp_status);
  792. len = min_t(size_t, count, len);
  793. if (copy_to_user(user_buff, debug->dp_debug.hdcp_status, len))
  794. return -EFAULT;
  795. *ppos += len;
  796. return len;
  797. }
  798. static int dp_debug_check_buffer_overflow(int rc, int *max_size, int *len)
  799. {
  800. if (rc >= *max_size) {
  801. DP_ERR("buffer overflow\n");
  802. return -EINVAL;
  803. }
  804. *len += rc;
  805. *max_size = SZ_4K - *len;
  806. return 0;
  807. }
  808. static ssize_t dp_debug_read_edid_modes(struct file *file,
  809. char __user *user_buff, size_t count, loff_t *ppos)
  810. {
  811. struct dp_debug_private *debug = file->private_data;
  812. char *buf;
  813. u32 len = 0, ret = 0, max_size = SZ_4K;
  814. int rc = 0;
  815. struct drm_connector *connector;
  816. struct drm_display_mode *mode;
  817. if (!debug) {
  818. DP_ERR("invalid data\n");
  819. rc = -ENODEV;
  820. goto error;
  821. }
  822. connector = *debug->connector;
  823. if (!connector) {
  824. DP_ERR("connector is NULL\n");
  825. rc = -EINVAL;
  826. goto error;
  827. }
  828. if (*ppos)
  829. goto error;
  830. buf = kzalloc(SZ_4K, GFP_KERNEL);
  831. if (ZERO_OR_NULL_PTR(buf)) {
  832. rc = -ENOMEM;
  833. goto error;
  834. }
  835. mutex_lock(&connector->dev->mode_config.mutex);
  836. list_for_each_entry(mode, &connector->modes, head) {
  837. ret = snprintf(buf + len, max_size,
  838. "%s %d %d %d %d %d 0x%x\n",
  839. mode->name, drm_mode_vrefresh(mode), mode->picture_aspect_ratio,
  840. mode->htotal, mode->vtotal, mode->clock, mode->flags);
  841. if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
  842. break;
  843. }
  844. mutex_unlock(&connector->dev->mode_config.mutex);
  845. len = min_t(size_t, count, len);
  846. if (copy_to_user(user_buff, buf, len)) {
  847. kfree(buf);
  848. rc = -EFAULT;
  849. goto error;
  850. }
  851. *ppos += len;
  852. kfree(buf);
  853. return len;
  854. error:
  855. return rc;
  856. }
  857. static ssize_t dp_debug_read_edid_modes_mst(struct file *file,
  858. char __user *user_buff, size_t count, loff_t *ppos)
  859. {
  860. struct dp_debug_private *debug = file->private_data;
  861. char *buf;
  862. u32 len = 0, ret = 0, max_size = SZ_4K;
  863. struct drm_connector *connector;
  864. struct drm_display_mode *mode;
  865. if (!debug) {
  866. DP_ERR("invalid data\n");
  867. return -ENODEV;
  868. }
  869. if (*ppos)
  870. return 0;
  871. connector = drm_connector_lookup((*debug->connector)->dev,
  872. NULL, debug->mst_con_id);
  873. if (!connector) {
  874. DP_ERR("connector %u not in mst list\n", debug->mst_con_id);
  875. return 0;
  876. }
  877. buf = kzalloc(SZ_4K, GFP_KERNEL);
  878. if (!buf)
  879. goto clean;
  880. mutex_lock(&connector->dev->mode_config.mutex);
  881. list_for_each_entry(mode, &connector->modes, head) {
  882. ret = snprintf(buf + len, max_size,
  883. "%s %d %d %d %d %d 0x%x\n",
  884. mode->name, drm_mode_vrefresh(mode),
  885. mode->picture_aspect_ratio, mode->htotal,
  886. mode->vtotal, mode->clock, mode->flags);
  887. if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
  888. break;
  889. }
  890. mutex_unlock(&connector->dev->mode_config.mutex);
  891. len = min_t(size_t, count, len);
  892. if (copy_to_user(user_buff, buf, len)) {
  893. len = -EFAULT;
  894. goto clean;
  895. }
  896. *ppos += len;
  897. clean:
  898. kfree(buf);
  899. drm_connector_put(connector);
  900. return len;
  901. }
  902. static ssize_t dp_debug_read_mst_con_id(struct file *file,
  903. char __user *user_buff, size_t count, loff_t *ppos)
  904. {
  905. struct dp_debug_private *debug = file->private_data;
  906. char *buf;
  907. u32 len = 0, ret = 0, max_size = SZ_4K;
  908. int rc = 0;
  909. if (!debug) {
  910. DP_ERR("invalid data\n");
  911. rc = -ENODEV;
  912. goto error;
  913. }
  914. if (*ppos)
  915. goto error;
  916. buf = kzalloc(SZ_4K, GFP_KERNEL);
  917. if (!buf) {
  918. rc = -ENOMEM;
  919. goto error;
  920. }
  921. ret = snprintf(buf, max_size, "%u\n", debug->mst_con_id);
  922. len += ret;
  923. len = min_t(size_t, count, len);
  924. if (copy_to_user(user_buff, buf, len)) {
  925. kfree(buf);
  926. rc = -EFAULT;
  927. goto error;
  928. }
  929. *ppos += len;
  930. kfree(buf);
  931. return len;
  932. error:
  933. return rc;
  934. }
  935. static ssize_t dp_debug_read_mst_conn_info(struct file *file,
  936. char __user *user_buff, size_t count, loff_t *ppos)
  937. {
  938. struct dp_debug_private *debug = file->private_data;
  939. struct drm_connector_list_iter conn_iter;
  940. struct drm_connector *connector;
  941. struct sde_connector *sde_conn;
  942. struct dp_display *display;
  943. char *buf;
  944. u32 len = 0, ret = 0, max_size = SZ_4K;
  945. int rc = 0;
  946. if (!debug) {
  947. DP_ERR("invalid data\n");
  948. rc = -ENODEV;
  949. goto error;
  950. }
  951. if (*ppos)
  952. goto error;
  953. buf = kzalloc(SZ_4K, GFP_KERNEL);
  954. if (!buf) {
  955. rc = -ENOMEM;
  956. goto error;
  957. }
  958. drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
  959. drm_for_each_connector_iter(connector, &conn_iter) {
  960. sde_conn = to_sde_connector(connector);
  961. display = sde_conn->display;
  962. if (!sde_conn->mst_port ||
  963. display->base_connector != (*debug->connector))
  964. continue;
  965. ret = scnprintf(buf + len, max_size,
  966. "conn name:%s, conn id:%d state:%d\n",
  967. connector->name, connector->base.id,
  968. connector->status);
  969. if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
  970. break;
  971. }
  972. drm_connector_list_iter_end(&conn_iter);
  973. len = min_t(size_t, count, len);
  974. if (copy_to_user(user_buff, buf, len)) {
  975. kfree(buf);
  976. rc = -EFAULT;
  977. goto error;
  978. }
  979. *ppos += len;
  980. kfree(buf);
  981. return len;
  982. error:
  983. return rc;
  984. }
  985. static ssize_t dp_debug_read_info(struct file *file, char __user *user_buff,
  986. size_t count, loff_t *ppos)
  987. {
  988. struct dp_debug_private *debug = file->private_data;
  989. char *buf;
  990. u32 len = 0, rc = 0;
  991. u32 max_size = SZ_4K;
  992. if (!debug)
  993. return -ENODEV;
  994. if (*ppos)
  995. return 0;
  996. buf = kzalloc(SZ_4K, GFP_KERNEL);
  997. if (ZERO_OR_NULL_PTR(buf))
  998. return -ENOMEM;
  999. rc = snprintf(buf + len, max_size, "\tstate=0x%x\n", debug->aux->state);
  1000. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1001. goto error;
  1002. rc = snprintf(buf + len, max_size, "\tlink_rate=%u\n",
  1003. debug->panel->link_info.rate);
  1004. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1005. goto error;
  1006. rc = snprintf(buf + len, max_size, "\tnum_lanes=%u\n",
  1007. debug->panel->link_info.num_lanes);
  1008. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1009. goto error;
  1010. rc = snprintf(buf + len, max_size, "\tresolution=%dx%d@%dHz\n",
  1011. debug->panel->pinfo.h_active,
  1012. debug->panel->pinfo.v_active,
  1013. debug->panel->pinfo.refresh_rate);
  1014. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1015. goto error;
  1016. rc = snprintf(buf + len, max_size, "\tpclock=%dKHz\n",
  1017. debug->panel->pinfo.pixel_clk_khz);
  1018. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1019. goto error;
  1020. rc = snprintf(buf + len, max_size, "\tbpp=%d\n",
  1021. debug->panel->pinfo.bpp);
  1022. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1023. goto error;
  1024. /* Link Information */
  1025. rc = snprintf(buf + len, max_size, "\ttest_req=%s\n",
  1026. dp_link_get_test_name(debug->link->sink_request));
  1027. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1028. goto error;
  1029. rc = snprintf(buf + len, max_size,
  1030. "\tlane_count=%d\n", debug->link->link_params.lane_count);
  1031. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1032. goto error;
  1033. rc = snprintf(buf + len, max_size,
  1034. "\tbw_code=%d\n", debug->link->link_params.bw_code);
  1035. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1036. goto error;
  1037. rc = snprintf(buf + len, max_size,
  1038. "\tv_level=%d\n", debug->link->phy_params.v_level);
  1039. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1040. goto error;
  1041. rc = snprintf(buf + len, max_size,
  1042. "\tp_level=%d\n", debug->link->phy_params.p_level);
  1043. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1044. goto error;
  1045. len = min_t(size_t, count, len);
  1046. if (copy_to_user(user_buff, buf, len))
  1047. goto error;
  1048. *ppos += len;
  1049. kfree(buf);
  1050. return len;
  1051. error:
  1052. kfree(buf);
  1053. return -EINVAL;
  1054. }
  1055. static ssize_t dp_debug_bw_code_read(struct file *file,
  1056. char __user *user_buff, size_t count, loff_t *ppos)
  1057. {
  1058. struct dp_debug_private *debug = file->private_data;
  1059. char *buf;
  1060. u32 len = 0;
  1061. if (!debug)
  1062. return -ENODEV;
  1063. if (*ppos)
  1064. return 0;
  1065. buf = kzalloc(SZ_4K, GFP_KERNEL);
  1066. if (ZERO_OR_NULL_PTR(buf))
  1067. return -ENOMEM;
  1068. len += snprintf(buf + len, (SZ_4K - len),
  1069. "max_bw_code = %d\n", debug->panel->max_bw_code);
  1070. len = min_t(size_t, count, len);
  1071. if (copy_to_user(user_buff, buf, len)) {
  1072. kfree(buf);
  1073. return -EFAULT;
  1074. }
  1075. *ppos += len;
  1076. kfree(buf);
  1077. return len;
  1078. }
  1079. static ssize_t dp_debug_tpg_read(struct file *file,
  1080. char __user *user_buff, size_t count, loff_t *ppos)
  1081. {
  1082. struct dp_debug_private *debug = file->private_data;
  1083. char buf[SZ_8];
  1084. u32 len = 0;
  1085. if (!debug)
  1086. return -ENODEV;
  1087. if (*ppos)
  1088. return 0;
  1089. len += snprintf(buf, SZ_8, "%d\n", debug->dp_debug.tpg_state);
  1090. len = min_t(size_t, count, len);
  1091. if (copy_to_user(user_buff, buf, len))
  1092. return -EFAULT;
  1093. *ppos += len;
  1094. return len;
  1095. }
  1096. static int dp_debug_print_hdr_params_to_buf(struct drm_connector *connector,
  1097. char *buf, u32 size)
  1098. {
  1099. int rc;
  1100. u32 i, len = 0, max_size = size;
  1101. struct sde_connector *c_conn;
  1102. struct sde_connector_state *c_state;
  1103. struct drm_msm_ext_hdr_metadata *hdr;
  1104. c_conn = to_sde_connector(connector);
  1105. c_state = to_sde_connector_state(connector->state);
  1106. hdr = &c_state->hdr_meta;
  1107. rc = snprintf(buf + len, max_size,
  1108. "============SINK HDR PARAMETERS===========\n");
  1109. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1110. goto error;
  1111. rc = snprintf(buf + len, max_size, "eotf = %d\n",
  1112. c_conn->hdr_eotf);
  1113. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1114. goto error;
  1115. rc = snprintf(buf + len, max_size, "type_one = %d\n",
  1116. c_conn->hdr_metadata_type_one);
  1117. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1118. goto error;
  1119. rc = snprintf(buf + len, max_size, "hdr_plus_app_ver = %d\n",
  1120. c_conn->hdr_plus_app_ver);
  1121. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1122. goto error;
  1123. rc = snprintf(buf + len, max_size, "max_luminance = %d\n",
  1124. c_conn->hdr_max_luminance);
  1125. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1126. goto error;
  1127. rc = snprintf(buf + len, max_size, "avg_luminance = %d\n",
  1128. c_conn->hdr_avg_luminance);
  1129. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1130. goto error;
  1131. rc = snprintf(buf + len, max_size, "min_luminance = %d\n",
  1132. c_conn->hdr_min_luminance);
  1133. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1134. goto error;
  1135. rc = snprintf(buf + len, max_size,
  1136. "============VIDEO HDR PARAMETERS===========\n");
  1137. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1138. goto error;
  1139. rc = snprintf(buf + len, max_size, "hdr_state = %d\n", hdr->hdr_state);
  1140. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1141. goto error;
  1142. rc = snprintf(buf + len, max_size, "hdr_supported = %d\n",
  1143. hdr->hdr_supported);
  1144. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1145. goto error;
  1146. rc = snprintf(buf + len, max_size, "eotf = %d\n", hdr->eotf);
  1147. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1148. goto error;
  1149. rc = snprintf(buf + len, max_size, "white_point_x = %d\n",
  1150. hdr->white_point_x);
  1151. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1152. goto error;
  1153. rc = snprintf(buf + len, max_size, "white_point_y = %d\n",
  1154. hdr->white_point_y);
  1155. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1156. goto error;
  1157. rc = snprintf(buf + len, max_size, "max_luminance = %d\n",
  1158. hdr->max_luminance);
  1159. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1160. goto error;
  1161. rc = snprintf(buf + len, max_size, "min_luminance = %d\n",
  1162. hdr->min_luminance);
  1163. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1164. goto error;
  1165. rc = snprintf(buf + len, max_size, "max_content_light_level = %d\n",
  1166. hdr->max_content_light_level);
  1167. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1168. goto error;
  1169. rc = snprintf(buf + len, max_size, "min_content_light_level = %d\n",
  1170. hdr->max_average_light_level);
  1171. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1172. goto error;
  1173. for (i = 0; i < HDR_PRIMARIES_COUNT; i++) {
  1174. rc = snprintf(buf + len, max_size, "primaries_x[%d] = %d\n",
  1175. i, hdr->display_primaries_x[i]);
  1176. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1177. goto error;
  1178. rc = snprintf(buf + len, max_size, "primaries_y[%d] = %d\n",
  1179. i, hdr->display_primaries_y[i]);
  1180. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1181. goto error;
  1182. }
  1183. if (hdr->hdr_plus_payload && hdr->hdr_plus_payload_size) {
  1184. u32 rowsize = 16, rem;
  1185. struct sde_connector_dyn_hdr_metadata *dhdr =
  1186. &c_state->dyn_hdr_meta;
  1187. /**
  1188. * Do not use user pointer from hdr->hdr_plus_payload directly,
  1189. * instead use kernel's cached copy of payload data.
  1190. */
  1191. for (i = 0; i < dhdr->dynamic_hdr_payload_size; i += rowsize) {
  1192. rc = snprintf(buf + len, max_size, "DHDR: ");
  1193. if (dp_debug_check_buffer_overflow(rc, &max_size,
  1194. &len))
  1195. goto error;
  1196. rem = dhdr->dynamic_hdr_payload_size - i;
  1197. rc = hex_dump_to_buffer(&dhdr->dynamic_hdr_payload[i],
  1198. min(rowsize, rem), rowsize, 1, buf + len,
  1199. max_size, false);
  1200. if (dp_debug_check_buffer_overflow(rc, &max_size,
  1201. &len))
  1202. goto error;
  1203. rc = snprintf(buf + len, max_size, "\n");
  1204. if (dp_debug_check_buffer_overflow(rc, &max_size,
  1205. &len))
  1206. goto error;
  1207. }
  1208. }
  1209. return len;
  1210. error:
  1211. return -EOVERFLOW;
  1212. }
  1213. static ssize_t dp_debug_read_hdr(struct file *file,
  1214. char __user *user_buff, size_t count, loff_t *ppos)
  1215. {
  1216. struct dp_debug_private *debug = file->private_data;
  1217. char *buf = NULL;
  1218. u32 len = 0;
  1219. u32 max_size = SZ_4K;
  1220. struct drm_connector *connector;
  1221. if (!debug) {
  1222. DP_ERR("invalid data\n");
  1223. return -ENODEV;
  1224. }
  1225. connector = *debug->connector;
  1226. if (!connector) {
  1227. DP_ERR("connector is NULL\n");
  1228. return -EINVAL;
  1229. }
  1230. if (*ppos)
  1231. return 0;
  1232. buf = kzalloc(max_size, GFP_KERNEL);
  1233. if (ZERO_OR_NULL_PTR(buf))
  1234. return -ENOMEM;
  1235. len = dp_debug_print_hdr_params_to_buf(connector, buf, max_size);
  1236. if (len == -EOVERFLOW) {
  1237. kfree(buf);
  1238. return len;
  1239. }
  1240. len = min_t(size_t, count, len);
  1241. if (copy_to_user(user_buff, buf, len)) {
  1242. kfree(buf);
  1243. return -EFAULT;
  1244. }
  1245. *ppos += len;
  1246. kfree(buf);
  1247. return len;
  1248. }
  1249. static ssize_t dp_debug_read_hdr_mst(struct file *file,
  1250. char __user *user_buff, size_t count, loff_t *ppos)
  1251. {
  1252. struct dp_debug_private *debug = file->private_data;
  1253. char *buf = NULL;
  1254. u32 len = 0, max_size = SZ_4K;
  1255. struct drm_connector_list_iter conn_iter;
  1256. struct drm_connector *connector;
  1257. bool in_list = false;
  1258. if (!debug) {
  1259. DP_ERR("invalid data\n");
  1260. return -ENODEV;
  1261. }
  1262. drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
  1263. drm_for_each_connector_iter(connector, &conn_iter) {
  1264. if (connector->base.id == debug->mst_con_id) {
  1265. in_list = true;
  1266. break;
  1267. }
  1268. }
  1269. drm_connector_list_iter_end(&conn_iter);
  1270. if (!in_list) {
  1271. DP_ERR("connector %u not in mst list\n", debug->mst_con_id);
  1272. return -EINVAL;
  1273. }
  1274. if (!connector) {
  1275. DP_ERR("connector is NULL\n");
  1276. return -EINVAL;
  1277. }
  1278. if (*ppos)
  1279. return 0;
  1280. buf = kzalloc(max_size, GFP_KERNEL);
  1281. if (ZERO_OR_NULL_PTR(buf))
  1282. return -ENOMEM;
  1283. len = dp_debug_print_hdr_params_to_buf(connector, buf, max_size);
  1284. if (len == -EOVERFLOW) {
  1285. kfree(buf);
  1286. return len;
  1287. }
  1288. len = min_t(size_t, count, len);
  1289. if (copy_to_user(user_buff, buf, len)) {
  1290. kfree(buf);
  1291. return -EFAULT;
  1292. }
  1293. *ppos += len;
  1294. kfree(buf);
  1295. return len;
  1296. }
  1297. static void dp_debug_set_sim_mode(struct dp_debug_private *debug, bool sim)
  1298. {
  1299. struct drm_connector_list_iter conn_iter;
  1300. struct drm_connector *connector;
  1301. struct sde_connector *sde_conn;
  1302. struct dp_display *display;
  1303. struct dp_panel *panel;
  1304. if (sim) {
  1305. debug->dp_debug.sim_mode = true;
  1306. dp_debug_enable_sim_mode(debug, DP_SIM_MODE_ALL);
  1307. } else {
  1308. if (debug->hotplug) {
  1309. DP_WARN("sim mode off before hotplug disconnect\n");
  1310. debug->hpd->simulate_connect(debug->hpd, false);
  1311. debug->hotplug = false;
  1312. }
  1313. debug->aux->abort(debug->aux, true);
  1314. debug->ctrl->abort(debug->ctrl, true);
  1315. debug->dp_debug.sim_mode = false;
  1316. debug->mst_edid_idx = 0;
  1317. dp_debug_disable_sim_mode(debug, DP_SIM_MODE_ALL);
  1318. }
  1319. /* clear override settings in panel */
  1320. drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
  1321. drm_for_each_connector_iter(connector, &conn_iter) {
  1322. sde_conn = to_sde_connector(connector);
  1323. display = sde_conn->display;
  1324. if (display->base_connector == (*debug->connector)) {
  1325. panel = sde_conn->drv_panel;
  1326. panel->mode_override = false;
  1327. panel->mst_hide = false;
  1328. }
  1329. }
  1330. drm_connector_list_iter_end(&conn_iter);
  1331. /*
  1332. * print simulation status as this code is executed
  1333. * only while running in debug mode which is manually
  1334. * triggered by a tester or a script.
  1335. */
  1336. DP_INFO("%s\n", sim ? "[ON]" : "[OFF]");
  1337. }
  1338. static ssize_t dp_debug_write_sim(struct file *file,
  1339. const char __user *user_buff, size_t count, loff_t *ppos)
  1340. {
  1341. struct dp_debug_private *debug = file->private_data;
  1342. char buf[SZ_8];
  1343. size_t len = 0;
  1344. int sim;
  1345. if (!debug)
  1346. return -ENODEV;
  1347. if (*ppos)
  1348. return 0;
  1349. mutex_lock(&debug->lock);
  1350. /* Leave room for termination char */
  1351. len = min_t(size_t, count, SZ_8 - 1);
  1352. if (copy_from_user(buf, user_buff, len))
  1353. goto end;
  1354. buf[len] = '\0';
  1355. if (kstrtoint(buf, 10, &sim) != 0)
  1356. goto end;
  1357. dp_debug_set_sim_mode(debug, sim);
  1358. end:
  1359. mutex_unlock(&debug->lock);
  1360. return len;
  1361. }
  1362. static ssize_t dp_debug_write_attention(struct file *file,
  1363. const char __user *user_buff, size_t count, loff_t *ppos)
  1364. {
  1365. struct dp_debug_private *debug = file->private_data;
  1366. char buf[SZ_8];
  1367. size_t len = 0;
  1368. int vdo;
  1369. if (!debug)
  1370. return -ENODEV;
  1371. if (*ppos)
  1372. return 0;
  1373. /* Leave room for termination char */
  1374. len = min_t(size_t, count, SZ_8 - 1);
  1375. if (copy_from_user(buf, user_buff, len))
  1376. goto end;
  1377. buf[len] = '\0';
  1378. if (kstrtoint(buf, 10, &vdo) != 0)
  1379. goto end;
  1380. debug->hpd->simulate_attention(debug->hpd, vdo);
  1381. end:
  1382. return len;
  1383. }
  1384. static ssize_t dp_debug_write_dump(struct file *file,
  1385. const char __user *user_buff, size_t count, loff_t *ppos)
  1386. {
  1387. struct dp_debug_private *debug = file->private_data;
  1388. char buf[SZ_32];
  1389. size_t len = 0;
  1390. if (!debug)
  1391. return -ENODEV;
  1392. if (*ppos)
  1393. return 0;
  1394. /* Leave room for termination char */
  1395. len = min_t(size_t, count, SZ_32 - 1);
  1396. if (copy_from_user(buf, user_buff, len))
  1397. goto end;
  1398. buf[len] = '\0';
  1399. if (sscanf(buf, "%31s", debug->reg_dump) != 1)
  1400. goto end;
  1401. /* qfprom register dump not supported */
  1402. if (!strcmp(debug->reg_dump, "qfprom_physical"))
  1403. strlcpy(debug->reg_dump, "clear", sizeof(debug->reg_dump));
  1404. end:
  1405. return len;
  1406. }
  1407. static ssize_t dp_debug_read_dump(struct file *file,
  1408. char __user *user_buff, size_t count, loff_t *ppos)
  1409. {
  1410. int rc = 0;
  1411. struct dp_debug_private *debug = file->private_data;
  1412. u8 *buf = NULL;
  1413. u32 len = 0;
  1414. char prefix[SZ_32];
  1415. if (!debug)
  1416. return -ENODEV;
  1417. if (*ppos)
  1418. return 0;
  1419. if (!debug->hpd->hpd_high || !strlen(debug->reg_dump))
  1420. goto end;
  1421. rc = debug->catalog->get_reg_dump(debug->catalog,
  1422. debug->reg_dump, &buf, &len);
  1423. if (rc)
  1424. goto end;
  1425. snprintf(prefix, sizeof(prefix), "%s: ", debug->reg_dump);
  1426. print_hex_dump_debug(prefix, DUMP_PREFIX_NONE,
  1427. 16, 4, buf, len, false);
  1428. len = min_t(size_t, count, len);
  1429. if (copy_to_user(user_buff, buf, len))
  1430. return -EFAULT;
  1431. *ppos += len;
  1432. end:
  1433. return len;
  1434. }
  1435. static const struct file_operations dp_debug_fops = {
  1436. .open = simple_open,
  1437. .read = dp_debug_read_info,
  1438. };
  1439. static const struct file_operations edid_modes_fops = {
  1440. .open = simple_open,
  1441. .read = dp_debug_read_edid_modes,
  1442. .write = dp_debug_write_edid_modes,
  1443. };
  1444. static const struct file_operations edid_modes_mst_fops = {
  1445. .open = simple_open,
  1446. .read = dp_debug_read_edid_modes_mst,
  1447. .write = dp_debug_write_edid_modes_mst,
  1448. };
  1449. static const struct file_operations mst_conn_info_fops = {
  1450. .open = simple_open,
  1451. .read = dp_debug_read_mst_conn_info,
  1452. };
  1453. static const struct file_operations mst_con_id_fops = {
  1454. .open = simple_open,
  1455. .read = dp_debug_read_mst_con_id,
  1456. .write = dp_debug_write_mst_con_id,
  1457. };
  1458. static const struct file_operations mst_con_add_fops = {
  1459. .open = simple_open,
  1460. .write = dp_debug_write_mst_con_add,
  1461. };
  1462. static const struct file_operations mst_con_remove_fops = {
  1463. .open = simple_open,
  1464. .write = dp_debug_write_mst_con_remove,
  1465. };
  1466. static const struct file_operations hpd_fops = {
  1467. .open = simple_open,
  1468. .write = dp_debug_write_hpd,
  1469. };
  1470. static const struct file_operations edid_fops = {
  1471. .open = simple_open,
  1472. .write = dp_debug_write_edid,
  1473. };
  1474. static const struct file_operations dpcd_fops = {
  1475. .open = simple_open,
  1476. .write = dp_debug_write_dpcd,
  1477. .read = dp_debug_read_dpcd,
  1478. };
  1479. static const struct file_operations connected_fops = {
  1480. .open = simple_open,
  1481. .read = dp_debug_read_connected,
  1482. };
  1483. static const struct file_operations bw_code_fops = {
  1484. .open = simple_open,
  1485. .read = dp_debug_bw_code_read,
  1486. .write = dp_debug_bw_code_write,
  1487. };
  1488. static const struct file_operations exe_mode_fops = {
  1489. .open = simple_open,
  1490. .write = dp_debug_write_exe_mode,
  1491. };
  1492. static const struct file_operations tpg_fops = {
  1493. .open = simple_open,
  1494. .read = dp_debug_tpg_read,
  1495. .write = dp_debug_tpg_write,
  1496. };
  1497. static const struct file_operations hdr_fops = {
  1498. .open = simple_open,
  1499. .read = dp_debug_read_hdr,
  1500. };
  1501. static const struct file_operations hdr_mst_fops = {
  1502. .open = simple_open,
  1503. .read = dp_debug_read_hdr_mst,
  1504. };
  1505. static const struct file_operations sim_fops = {
  1506. .open = simple_open,
  1507. .write = dp_debug_write_sim,
  1508. };
  1509. static const struct file_operations attention_fops = {
  1510. .open = simple_open,
  1511. .write = dp_debug_write_attention,
  1512. };
  1513. static const struct file_operations dump_fops = {
  1514. .open = simple_open,
  1515. .write = dp_debug_write_dump,
  1516. .read = dp_debug_read_dump,
  1517. };
  1518. static const struct file_operations mst_mode_fops = {
  1519. .open = simple_open,
  1520. .write = dp_debug_mst_mode_write,
  1521. .read = dp_debug_mst_mode_read,
  1522. };
  1523. static const struct file_operations mst_sideband_mode_fops = {
  1524. .open = simple_open,
  1525. .write = dp_debug_mst_sideband_mode_write,
  1526. };
  1527. static const struct file_operations max_pclk_khz_fops = {
  1528. .open = simple_open,
  1529. .write = dp_debug_max_pclk_khz_write,
  1530. .read = dp_debug_max_pclk_khz_read,
  1531. };
  1532. static const struct file_operations hdcp_fops = {
  1533. .open = simple_open,
  1534. .write = dp_debug_write_hdcp,
  1535. .read = dp_debug_read_hdcp,
  1536. };
  1537. static const struct file_operations mmrm_clk_cb_fops = {
  1538. .open = simple_open,
  1539. .write = dp_debug_mmrm_clk_cb_write,
  1540. };
  1541. static int dp_debug_init_mst(struct dp_debug_private *debug, struct dentry *dir)
  1542. {
  1543. int rc = 0;
  1544. struct dentry *file;
  1545. file = debugfs_create_file("mst_con_id", 0644, dir,
  1546. debug, &mst_con_id_fops);
  1547. if (IS_ERR_OR_NULL(file)) {
  1548. rc = PTR_ERR(file);
  1549. DP_ERR("[%s] debugfs create mst_con_id failed, rc=%d\n",
  1550. DEBUG_NAME, rc);
  1551. return rc;
  1552. }
  1553. file = debugfs_create_file("mst_con_info", 0644, dir,
  1554. debug, &mst_conn_info_fops);
  1555. if (IS_ERR_OR_NULL(file)) {
  1556. rc = PTR_ERR(file);
  1557. DP_ERR("[%s] debugfs create mst_conn_info failed, rc=%d\n",
  1558. DEBUG_NAME, rc);
  1559. return rc;
  1560. }
  1561. file = debugfs_create_file("mst_con_add", 0644, dir,
  1562. debug, &mst_con_add_fops);
  1563. if (IS_ERR_OR_NULL(file)) {
  1564. rc = PTR_ERR(file);
  1565. DRM_ERROR("[%s] debugfs create mst_con_add failed, rc=%d\n",
  1566. DEBUG_NAME, rc);
  1567. return rc;
  1568. }
  1569. file = debugfs_create_file("mst_con_remove", 0644, dir,
  1570. debug, &mst_con_remove_fops);
  1571. if (IS_ERR_OR_NULL(file)) {
  1572. rc = PTR_ERR(file);
  1573. DRM_ERROR("[%s] debugfs create mst_con_remove failed, rc=%d\n",
  1574. DEBUG_NAME, rc);
  1575. return rc;
  1576. }
  1577. file = debugfs_create_file("mst_mode", 0644, dir,
  1578. debug, &mst_mode_fops);
  1579. if (IS_ERR_OR_NULL(file)) {
  1580. rc = PTR_ERR(file);
  1581. DP_ERR("[%s] debugfs mst_mode failed, rc=%d\n",
  1582. DEBUG_NAME, rc);
  1583. return rc;
  1584. }
  1585. file = debugfs_create_file("mst_sideband_mode", 0644, dir,
  1586. debug, &mst_sideband_mode_fops);
  1587. if (IS_ERR_OR_NULL(file)) {
  1588. rc = PTR_ERR(file);
  1589. DP_ERR("[%s] debugfs mst_sideband_mode failed, rc=%d\n",
  1590. DEBUG_NAME, rc);
  1591. return rc;
  1592. }
  1593. debugfs_create_u32("mst_edid_idx", 0644, dir, &debug->mst_edid_idx);
  1594. return rc;
  1595. }
  1596. static int dp_debug_init_link(struct dp_debug_private *debug,
  1597. struct dentry *dir)
  1598. {
  1599. int rc = 0;
  1600. struct dentry *file;
  1601. file = debugfs_create_file("max_bw_code", 0644, dir,
  1602. debug, &bw_code_fops);
  1603. if (IS_ERR_OR_NULL(file)) {
  1604. rc = PTR_ERR(file);
  1605. DP_ERR("[%s] debugfs max_bw_code failed, rc=%d\n",
  1606. DEBUG_NAME, rc);
  1607. return rc;
  1608. }
  1609. file = debugfs_create_file("max_pclk_khz", 0644, dir,
  1610. debug, &max_pclk_khz_fops);
  1611. if (IS_ERR_OR_NULL(file)) {
  1612. rc = PTR_ERR(file);
  1613. DP_ERR("[%s] debugfs max_pclk_khz failed, rc=%d\n",
  1614. DEBUG_NAME, rc);
  1615. return rc;
  1616. }
  1617. debugfs_create_u32("max_lclk_khz", 0644, dir, &debug->parser->max_lclk_khz);
  1618. debugfs_create_u32("lane_count", 0644, dir, &debug->panel->lane_count);
  1619. debugfs_create_u32("link_bw_code", 0644, dir, &debug->panel->link_bw_code);
  1620. file = debugfs_create_file("mmrm_clk_cb", 0644, dir, debug, &mmrm_clk_cb_fops);
  1621. if (IS_ERR_OR_NULL(file)) {
  1622. rc = PTR_ERR(file);
  1623. DP_ERR("[%s] debugfs mmrm_clk_cb failed, rc=%d\n", DEBUG_NAME, rc);
  1624. return rc;
  1625. }
  1626. return rc;
  1627. }
  1628. static int dp_debug_init_hdcp(struct dp_debug_private *debug,
  1629. struct dentry *dir)
  1630. {
  1631. int rc = 0;
  1632. struct dentry *file;
  1633. file = debugfs_create_bool("hdcp_wait_sink_sync", 0644, dir,
  1634. &debug->dp_debug.hdcp_wait_sink_sync);
  1635. if (IS_ERR_OR_NULL(file)) {
  1636. rc = PTR_ERR(file);
  1637. DP_ERR("[%s] debugfs hdcp_wait_sink_sync failed, rc=%d\n",
  1638. DEBUG_NAME, rc);
  1639. return rc;
  1640. }
  1641. file = debugfs_create_bool("force_encryption", 0644, dir,
  1642. &debug->dp_debug.force_encryption);
  1643. if (IS_ERR_OR_NULL(file)) {
  1644. rc = PTR_ERR(file);
  1645. DP_ERR("[%s] debugfs force_encryption failed, rc=%d\n",
  1646. DEBUG_NAME, rc);
  1647. return rc;
  1648. }
  1649. return rc;
  1650. }
  1651. static int dp_debug_init_sink_caps(struct dp_debug_private *debug,
  1652. struct dentry *dir)
  1653. {
  1654. int rc = 0;
  1655. struct dentry *file;
  1656. file = debugfs_create_file("edid_modes", 0644, dir,
  1657. debug, &edid_modes_fops);
  1658. if (IS_ERR_OR_NULL(file)) {
  1659. rc = PTR_ERR(file);
  1660. DP_ERR("[%s] debugfs create edid_modes failed, rc=%d\n",
  1661. DEBUG_NAME, rc);
  1662. return rc;
  1663. }
  1664. file = debugfs_create_file("edid_modes_mst", 0644, dir,
  1665. debug, &edid_modes_mst_fops);
  1666. if (IS_ERR_OR_NULL(file)) {
  1667. rc = PTR_ERR(file);
  1668. DP_ERR("[%s] debugfs create edid_modes_mst failed, rc=%d\n",
  1669. DEBUG_NAME, rc);
  1670. return rc;
  1671. }
  1672. file = debugfs_create_file("edid", 0644, dir,
  1673. debug, &edid_fops);
  1674. if (IS_ERR_OR_NULL(file)) {
  1675. rc = PTR_ERR(file);
  1676. DP_ERR("[%s] debugfs edid failed, rc=%d\n",
  1677. DEBUG_NAME, rc);
  1678. return rc;
  1679. }
  1680. file = debugfs_create_file("dpcd", 0644, dir,
  1681. debug, &dpcd_fops);
  1682. if (IS_ERR_OR_NULL(file)) {
  1683. rc = PTR_ERR(file);
  1684. DP_ERR("[%s] debugfs dpcd failed, rc=%d\n",
  1685. DEBUG_NAME, rc);
  1686. return rc;
  1687. }
  1688. return rc;
  1689. }
  1690. static int dp_debug_init_status(struct dp_debug_private *debug,
  1691. struct dentry *dir)
  1692. {
  1693. int rc = 0;
  1694. struct dentry *file;
  1695. file = debugfs_create_file("dp_debug", 0444, dir,
  1696. debug, &dp_debug_fops);
  1697. if (IS_ERR_OR_NULL(file)) {
  1698. rc = PTR_ERR(file);
  1699. DP_ERR("[%s] debugfs create file failed, rc=%d\n",
  1700. DEBUG_NAME, rc);
  1701. return rc;
  1702. }
  1703. file = debugfs_create_file("connected", 0444, dir,
  1704. debug, &connected_fops);
  1705. if (IS_ERR_OR_NULL(file)) {
  1706. rc = PTR_ERR(file);
  1707. DP_ERR("[%s] debugfs connected failed, rc=%d\n",
  1708. DEBUG_NAME, rc);
  1709. return rc;
  1710. }
  1711. file = debugfs_create_file("hdr", 0400, dir, debug, &hdr_fops);
  1712. if (IS_ERR_OR_NULL(file)) {
  1713. rc = PTR_ERR(file);
  1714. DP_ERR("[%s] debugfs hdr failed, rc=%d\n",
  1715. DEBUG_NAME, rc);
  1716. return rc;
  1717. }
  1718. file = debugfs_create_file("hdr_mst", 0400, dir, debug, &hdr_mst_fops);
  1719. if (IS_ERR_OR_NULL(file)) {
  1720. rc = PTR_ERR(file);
  1721. DP_ERR("[%s] debugfs hdr_mst failed, rc=%d\n",
  1722. DEBUG_NAME, rc);
  1723. return rc;
  1724. }
  1725. file = debugfs_create_file("hdcp", 0644, dir, debug, &hdcp_fops);
  1726. if (IS_ERR_OR_NULL(file)) {
  1727. rc = PTR_ERR(file);
  1728. DP_ERR("[%s] debugfs hdcp failed, rc=%d\n",
  1729. DEBUG_NAME, rc);
  1730. return rc;
  1731. }
  1732. return rc;
  1733. }
  1734. static int dp_debug_init_sim(struct dp_debug_private *debug, struct dentry *dir)
  1735. {
  1736. int rc = 0;
  1737. struct dentry *file;
  1738. file = debugfs_create_file("hpd", 0644, dir, debug, &hpd_fops);
  1739. if (IS_ERR_OR_NULL(file)) {
  1740. rc = PTR_ERR(file);
  1741. DP_ERR("[%s] debugfs hpd failed, rc=%d\n",
  1742. DEBUG_NAME, rc);
  1743. return rc;
  1744. }
  1745. file = debugfs_create_file("sim", 0644, dir, debug, &sim_fops);
  1746. if (IS_ERR_OR_NULL(file)) {
  1747. rc = PTR_ERR(file);
  1748. DP_ERR("[%s] debugfs sim failed, rc=%d\n",
  1749. DEBUG_NAME, rc);
  1750. return rc;
  1751. }
  1752. file = debugfs_create_file("attention", 0644, dir,
  1753. debug, &attention_fops);
  1754. if (IS_ERR_OR_NULL(file)) {
  1755. rc = PTR_ERR(file);
  1756. DP_ERR("[%s] debugfs attention failed, rc=%d\n",
  1757. DEBUG_NAME, rc);
  1758. return rc;
  1759. }
  1760. file = debugfs_create_bool("skip_uevent", 0644, dir,
  1761. &debug->dp_debug.skip_uevent);
  1762. if (IS_ERR_OR_NULL(file)) {
  1763. rc = PTR_ERR(file);
  1764. DP_ERR("[%s] debugfs skip_uevent failed, rc=%d\n",
  1765. DEBUG_NAME, rc);
  1766. return rc;
  1767. }
  1768. file = debugfs_create_bool("force_multi_func", 0644, dir,
  1769. &debug->hpd->force_multi_func);
  1770. if (IS_ERR_OR_NULL(file)) {
  1771. rc = PTR_ERR(file);
  1772. DP_ERR("[%s] debugfs force_multi_func failed, rc=%d\n",
  1773. DEBUG_NAME, rc);
  1774. return rc;
  1775. }
  1776. return rc;
  1777. }
  1778. static int dp_debug_init_dsc_fec(struct dp_debug_private *debug,
  1779. struct dentry *dir)
  1780. {
  1781. int rc = 0;
  1782. struct dentry *file;
  1783. file = debugfs_create_bool("dsc_feature_enable", 0644, dir,
  1784. &debug->parser->dsc_feature_enable);
  1785. if (IS_ERR_OR_NULL(file)) {
  1786. rc = PTR_ERR(file);
  1787. DP_ERR("[%s] debugfs dsc_feature failed, rc=%d\n",
  1788. DEBUG_NAME, rc);
  1789. return rc;
  1790. }
  1791. file = debugfs_create_bool("fec_feature_enable", 0644, dir,
  1792. &debug->parser->fec_feature_enable);
  1793. if (IS_ERR_OR_NULL(file)) {
  1794. rc = PTR_ERR(file);
  1795. DP_ERR("[%s] debugfs fec_feature_enable failed, rc=%d\n",
  1796. DEBUG_NAME, rc);
  1797. return rc;
  1798. }
  1799. return rc;
  1800. }
  1801. static int dp_debug_init_tpg(struct dp_debug_private *debug, struct dentry *dir)
  1802. {
  1803. int rc = 0;
  1804. struct dentry *file;
  1805. file = debugfs_create_file("tpg_ctrl", 0644, dir,
  1806. debug, &tpg_fops);
  1807. if (IS_ERR_OR_NULL(file)) {
  1808. rc = PTR_ERR(file);
  1809. DP_ERR("[%s] debugfs tpg failed, rc=%d\n",
  1810. DEBUG_NAME, rc);
  1811. return rc;
  1812. }
  1813. return rc;
  1814. }
  1815. static int dp_debug_init_reg_dump(struct dp_debug_private *debug,
  1816. struct dentry *dir)
  1817. {
  1818. int rc = 0;
  1819. struct dentry *file;
  1820. file = debugfs_create_file("exe_mode", 0644, dir,
  1821. debug, &exe_mode_fops);
  1822. if (IS_ERR_OR_NULL(file)) {
  1823. rc = PTR_ERR(file);
  1824. DP_ERR("[%s] debugfs register failed, rc=%d\n",
  1825. DEBUG_NAME, rc);
  1826. return rc;
  1827. }
  1828. file = debugfs_create_file("dump", 0644, dir,
  1829. debug, &dump_fops);
  1830. if (IS_ERR_OR_NULL(file)) {
  1831. rc = PTR_ERR(file);
  1832. DP_ERR("[%s] debugfs dump failed, rc=%d\n",
  1833. DEBUG_NAME, rc);
  1834. return rc;
  1835. }
  1836. return rc;
  1837. }
  1838. static int dp_debug_init_feature_toggle(struct dp_debug_private *debug,
  1839. struct dentry *dir)
  1840. {
  1841. int rc = 0;
  1842. struct dentry *file;
  1843. file = debugfs_create_bool("ssc_enable", 0644, dir,
  1844. &debug->pll->ssc_en);
  1845. if (IS_ERR_OR_NULL(file)) {
  1846. rc = PTR_ERR(file);
  1847. DP_ERR("[%s] debugfs ssc_enable failed, rc=%d\n",
  1848. DEBUG_NAME, rc);
  1849. return rc;
  1850. }
  1851. file = debugfs_create_bool("widebus_mode", 0644, dir,
  1852. &debug->parser->has_widebus);
  1853. if (IS_ERR_OR_NULL(file)) {
  1854. rc = PTR_ERR(file);
  1855. DP_ERR("[%s] debugfs widebus_mode failed, rc=%d\n",
  1856. DEBUG_NAME, rc);
  1857. return rc;
  1858. }
  1859. return rc;
  1860. }
  1861. static int dp_debug_init_configs(struct dp_debug_private *debug,
  1862. struct dentry *dir)
  1863. {
  1864. int rc = 0;
  1865. struct dentry *file;
  1866. file = debugfs_create_ulong("connect_notification_delay_ms", 0644, dir,
  1867. &debug->dp_debug.connect_notification_delay_ms);
  1868. if (IS_ERR_OR_NULL(file)) {
  1869. rc = PTR_ERR(file);
  1870. DP_ERR("[%s] debugfs connect_notification_delay_ms failed, rc=%d\n",
  1871. DEBUG_NAME, rc);
  1872. return rc;
  1873. }
  1874. debug->dp_debug.connect_notification_delay_ms =
  1875. DEFAULT_CONNECT_NOTIFICATION_DELAY_MS;
  1876. debugfs_create_u32("disconnect_delay_ms", 0644, dir, &debug->dp_debug.disconnect_delay_ms);
  1877. debug->dp_debug.disconnect_delay_ms = DEFAULT_DISCONNECT_DELAY_MS;
  1878. return rc;
  1879. }
  1880. static int dp_debug_init(struct dp_debug *dp_debug)
  1881. {
  1882. int rc = 0;
  1883. struct dp_debug_private *debug = container_of(dp_debug,
  1884. struct dp_debug_private, dp_debug);
  1885. struct dentry *dir;
  1886. if (!IS_ENABLED(CONFIG_DEBUG_FS)) {
  1887. DP_WARN("Not creating debug root dir.");
  1888. debug->root = NULL;
  1889. return 0;
  1890. }
  1891. dir = debugfs_create_dir(DEBUG_NAME, NULL);
  1892. if (IS_ERR_OR_NULL(dir)) {
  1893. if (!dir)
  1894. rc = -EINVAL;
  1895. else
  1896. rc = PTR_ERR(dir);
  1897. DP_ERR("[%s] debugfs create dir failed, rc = %d\n",
  1898. DEBUG_NAME, rc);
  1899. goto error;
  1900. }
  1901. debug->root = dir;
  1902. rc = dp_debug_init_status(debug, dir);
  1903. if (rc)
  1904. goto error_remove_dir;
  1905. rc = dp_debug_init_sink_caps(debug, dir);
  1906. if (rc)
  1907. goto error_remove_dir;
  1908. rc = dp_debug_init_mst(debug, dir);
  1909. if (rc)
  1910. goto error_remove_dir;
  1911. rc = dp_debug_init_link(debug, dir);
  1912. if (rc)
  1913. goto error_remove_dir;
  1914. rc = dp_debug_init_hdcp(debug, dir);
  1915. if (rc)
  1916. goto error_remove_dir;
  1917. rc = dp_debug_init_sim(debug, dir);
  1918. if (rc)
  1919. goto error_remove_dir;
  1920. rc = dp_debug_init_dsc_fec(debug, dir);
  1921. if (rc)
  1922. goto error_remove_dir;
  1923. rc = dp_debug_init_tpg(debug, dir);
  1924. if (rc)
  1925. goto error_remove_dir;
  1926. rc = dp_debug_init_reg_dump(debug, dir);
  1927. if (rc)
  1928. goto error_remove_dir;
  1929. rc = dp_debug_init_feature_toggle(debug, dir);
  1930. if (rc)
  1931. goto error_remove_dir;
  1932. rc = dp_debug_init_configs(debug, dir);
  1933. if (rc)
  1934. goto error_remove_dir;
  1935. return 0;
  1936. error_remove_dir:
  1937. debugfs_remove_recursive(dir);
  1938. error:
  1939. return rc;
  1940. }
  1941. static void dp_debug_abort(struct dp_debug *dp_debug)
  1942. {
  1943. struct dp_debug_private *debug;
  1944. if (!dp_debug)
  1945. return;
  1946. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  1947. mutex_lock(&debug->lock);
  1948. dp_debug_set_sim_mode(debug, false);
  1949. mutex_unlock(&debug->lock);
  1950. }
  1951. static void dp_debug_set_mst_con(struct dp_debug *dp_debug, int con_id)
  1952. {
  1953. struct dp_debug_private *debug;
  1954. if (!dp_debug)
  1955. return;
  1956. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  1957. mutex_lock(&debug->lock);
  1958. debug->mst_con_id = con_id;
  1959. mutex_unlock(&debug->lock);
  1960. DP_INFO("Selecting mst connector %d\n", con_id);
  1961. }
  1962. struct dp_debug *dp_debug_get(struct dp_debug_in *in)
  1963. {
  1964. int rc = 0;
  1965. struct dp_debug_private *debug;
  1966. struct dp_debug *dp_debug;
  1967. if (!in->dev || !in->panel || !in->hpd || !in->link ||
  1968. !in->catalog || !in->ctrl || !in->pll) {
  1969. DP_ERR("invalid input\n");
  1970. rc = -EINVAL;
  1971. goto error;
  1972. }
  1973. debug = devm_kzalloc(in->dev, sizeof(*debug), GFP_KERNEL);
  1974. if (!debug) {
  1975. rc = -ENOMEM;
  1976. goto error;
  1977. }
  1978. debug->hpd = in->hpd;
  1979. debug->link = in->link;
  1980. debug->panel = in->panel;
  1981. debug->aux = in->aux;
  1982. debug->dev = in->dev;
  1983. debug->connector = in->connector;
  1984. debug->catalog = in->catalog;
  1985. debug->parser = in->parser;
  1986. debug->ctrl = in->ctrl;
  1987. debug->pll = in->pll;
  1988. debug->display = in->display;
  1989. dp_debug = &debug->dp_debug;
  1990. mutex_init(&debug->lock);
  1991. rc = dp_debug_init(dp_debug);
  1992. if (rc) {
  1993. devm_kfree(in->dev, debug);
  1994. goto error;
  1995. }
  1996. debug->aux->access_lock = &debug->lock;
  1997. dp_debug->abort = dp_debug_abort;
  1998. dp_debug->set_mst_con = dp_debug_set_mst_con;
  1999. dp_debug->max_pclk_khz = debug->parser->max_pclk_khz;
  2000. return dp_debug;
  2001. error:
  2002. return ERR_PTR(rc);
  2003. }
  2004. static int dp_debug_deinit(struct dp_debug *dp_debug)
  2005. {
  2006. struct dp_debug_private *debug;
  2007. if (!dp_debug)
  2008. return -EINVAL;
  2009. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  2010. debugfs_remove_recursive(debug->root);
  2011. if (debug->sim_bridge)
  2012. dp_sim_destroy_bridge(debug->sim_bridge);
  2013. return 0;
  2014. }
  2015. void dp_debug_put(struct dp_debug *dp_debug)
  2016. {
  2017. struct dp_debug_private *debug;
  2018. if (!dp_debug)
  2019. return;
  2020. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  2021. dp_debug_deinit(dp_debug);
  2022. mutex_destroy(&debug->lock);
  2023. devm_kfree(debug->dev, debug);
  2024. }