dp_debug.c 49 KB

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