dp_debug.c 50 KB

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