dp_debug.c 57 KB

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