dp_debug.c 56 KB

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