dp_debug.c 57 KB

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