dp_debug.c 56 KB

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