123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
- * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
- */
- #include <linux/debugfs.h>
- #include <linux/slab.h>
- #include <linux/version.h>
- #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0))
- #include <drm/display/drm_dp_mst_helper.h>
- #else
- #include <drm/drm_dp_mst_helper.h>
- #endif
- #include <drm/drm_probe_helper.h>
- #include "dp_power.h"
- #include "dp_catalog.h"
- #include "dp_aux.h"
- #include "dp_debug.h"
- #include "drm/drm_connector.h"
- #include "sde_connector.h"
- #include "dp_display.h"
- #include "dp_pll.h"
- #include "dp_hpd.h"
- #include "dp_mst_sim.h"
- #include "dp_mst_drm.h"
- #define DEBUG_NAME "drm_dp"
- struct dp_debug_private {
- struct dentry *root;
- u32 dpcd_offset;
- u32 dpcd_size;
- u32 mst_con_id;
- u32 mst_edid_idx;
- bool hotplug;
- u32 sim_mode;
- char exe_mode[SZ_32];
- char reg_dump[SZ_32];
- struct dp_hpd *hpd;
- struct dp_link *link;
- struct dp_panel *panel;
- struct dp_aux *aux;
- struct dp_catalog *catalog;
- struct drm_connector **connector;
- struct device *dev;
- struct dp_debug dp_debug;
- struct dp_parser *parser;
- struct dp_ctrl *ctrl;
- struct dp_pll *pll;
- struct dp_display *display;
- struct mutex lock;
- struct dp_aux_bridge *sim_bridge;
- };
- static int dp_debug_sim_hpd_cb(void *arg, bool hpd, bool hpd_irq)
- {
- struct dp_debug_private *debug = arg;
- int vdo = 0;
- if (hpd_irq) {
- vdo |= BIT(7);
- if (hpd)
- vdo |= BIT(8);
- return debug->hpd->simulate_attention(debug->hpd, vdo);
- } else {
- return debug->hpd->simulate_connect(debug->hpd, hpd);
- }
- }
- static int dp_debug_attach_sim_bridge(struct dp_debug_private *debug)
- {
- int ret;
- if (!debug->sim_bridge) {
- ret = dp_sim_create_bridge(debug->dev, &debug->sim_bridge);
- if (ret)
- return ret;
- if (debug->sim_bridge->register_hpd)
- debug->sim_bridge->register_hpd(debug->sim_bridge,
- dp_debug_sim_hpd_cb, debug);
- }
- dp_sim_update_port_num(debug->sim_bridge, 1);
- return 0;
- }
- static void dp_debug_enable_sim_mode(struct dp_debug_private *debug,
- u32 mode_mask)
- {
- /* return if mode is already enabled */
- if ((debug->sim_mode & mode_mask) == mode_mask)
- return;
- /* create bridge if not yet */
- if (dp_debug_attach_sim_bridge(debug))
- return;
- /* switch to bridge mode */
- if (!debug->sim_mode)
- debug->aux->set_sim_mode(debug->aux, debug->sim_bridge);
- /* update sim mode */
- debug->sim_mode |= mode_mask;
- dp_sim_set_sim_mode(debug->sim_bridge, debug->sim_mode);
- }
- static void dp_debug_disable_sim_mode(struct dp_debug_private *debug,
- u32 mode_mask)
- {
- /* return if mode is already disabled */
- if (!(debug->sim_mode & mode_mask))
- return;
- /* update sim mode */
- debug->sim_mode &= ~mode_mask;
- dp_sim_set_sim_mode(debug->sim_bridge, debug->sim_mode);
- dp_sim_update_port_num(debug->sim_bridge, 0);
- /* switch to normal mode */
- if (!debug->sim_mode)
- debug->aux->set_sim_mode(debug->aux, NULL);
- }
- static ssize_t dp_debug_write_edid(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- u8 *buf = NULL, *buf_t = NULL, *edid = NULL;
- const int char_to_nib = 2;
- size_t edid_size = 0;
- size_t size = 0, edid_buf_index = 0;
- ssize_t rc = count;
- if (!debug)
- return -ENODEV;
- mutex_lock(&debug->lock);
- if (*ppos)
- goto bail;
- size = min_t(size_t, count, SZ_1K);
- buf = kzalloc(size, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf)) {
- rc = -ENOMEM;
- goto bail;
- }
- if (copy_from_user(buf, user_buff, size))
- goto bail;
- edid_size = size / char_to_nib;
- buf_t = buf;
- size = edid_size;
- edid = kzalloc(size, GFP_KERNEL);
- if (!edid)
- goto bail;
- while (size--) {
- char t[3];
- int d;
- memcpy(t, buf_t, sizeof(char) * char_to_nib);
- t[char_to_nib] = '\0';
- if (kstrtoint(t, 16, &d)) {
- DP_ERR("kstrtoint error\n");
- goto bail;
- }
- edid[edid_buf_index++] = d;
- buf_t += char_to_nib;
- }
- dp_debug_enable_sim_mode(debug, DP_SIM_MODE_EDID);
- dp_mst_clear_edid_cache(debug->display);
- dp_sim_update_port_edid(debug->sim_bridge, debug->mst_edid_idx,
- edid, edid_size);
- bail:
- kfree(buf);
- kfree(edid);
- mutex_unlock(&debug->lock);
- return rc;
- }
- static ssize_t dp_debug_write_dpcd(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- u8 *buf = NULL, *buf_t = NULL, *dpcd = NULL;
- const int char_to_nib = 2;
- size_t dpcd_size = 0;
- size_t size = 0, dpcd_buf_index = 0;
- ssize_t rc = count;
- char offset_ch[5];
- u32 offset, data_len;
- if (!debug)
- return -ENODEV;
- mutex_lock(&debug->lock);
- if (*ppos)
- goto bail;
- size = min_t(size_t, count, SZ_2K);
- if (size < 4)
- goto bail;
- buf = kzalloc(size, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf)) {
- rc = -ENOMEM;
- goto bail;
- }
- if (copy_from_user(buf, user_buff, size))
- goto bail;
- memcpy(offset_ch, buf, 4);
- offset_ch[4] = '\0';
- if (kstrtoint(offset_ch, 16, &offset)) {
- DP_ERR("offset kstrtoint error\n");
- goto bail;
- }
- debug->dpcd_offset = offset;
- size -= 4;
- if (size < char_to_nib)
- goto bail;
- dpcd_size = size / char_to_nib;
- data_len = dpcd_size;
- buf_t = buf + 4;
- dpcd = kzalloc(dpcd_size, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(dpcd)) {
- rc = -ENOMEM;
- goto bail;
- }
- while (dpcd_size--) {
- char t[3];
- int d;
- memcpy(t, buf_t, sizeof(char) * char_to_nib);
- t[char_to_nib] = '\0';
- if (kstrtoint(t, 16, &d)) {
- DP_ERR("kstrtoint error\n");
- goto bail;
- }
- dpcd[dpcd_buf_index++] = d;
- buf_t += char_to_nib;
- }
- /*
- * if link training status registers are reprogramed,
- * read link training status from simulator, otherwise
- * read link training status from real aux channel.
- */
- if (offset <= DP_LANE0_1_STATUS &&
- offset + dpcd_buf_index > DP_LANE0_1_STATUS)
- dp_debug_enable_sim_mode(debug,
- DP_SIM_MODE_DPCD_READ | DP_SIM_MODE_LINK_TRAIN);
- else
- dp_debug_enable_sim_mode(debug, DP_SIM_MODE_DPCD_READ);
- dp_sim_write_dpcd_reg(debug->sim_bridge,
- dpcd, dpcd_buf_index, offset);
- debug->dpcd_size = dpcd_buf_index;
- bail:
- kfree(buf);
- kfree(dpcd);
- mutex_unlock(&debug->lock);
- return rc;
- }
- static ssize_t dp_debug_read_dpcd(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- int const buf_size = SZ_4K;
- u32 offset = 0;
- u32 len = 0;
- u8 *dpcd;
- if (!debug || !debug->aux)
- return -ENODEV;
- if (*ppos)
- return 0;
- buf = kzalloc(buf_size, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
- mutex_lock(&debug->lock);
- dpcd = kzalloc(buf_size, GFP_KERNEL);
- if (!dpcd)
- goto bail;
- /*
- * In simulation mode, this function returns the last written DPCD node.
- * For a real monitor plug in, it dumps the first byte at the last written DPCD address
- * unless the address is 0, in which case the first 20 bytes are dumped
- */
- if (debug->dp_debug.sim_mode) {
- dp_sim_read_dpcd_reg(debug->sim_bridge, dpcd, debug->dpcd_size, debug->dpcd_offset);
- } else {
- if (debug->dpcd_offset) {
- debug->dpcd_size = 1;
- if (drm_dp_dpcd_read(debug->aux->drm_aux, debug->dpcd_offset, dpcd,
- debug->dpcd_size) != 1)
- goto bail;
- } else {
- debug->dpcd_size = sizeof(debug->panel->dpcd);
- memcpy(dpcd, debug->panel->dpcd, debug->dpcd_size);
- }
- }
- len += scnprintf(buf + len, buf_size - len, "%04x: ", debug->dpcd_offset);
- while (offset < debug->dpcd_size)
- len += scnprintf(buf + len, buf_size - len, "%02x ", dpcd[offset++]);
- kfree(dpcd);
- len = min_t(size_t, count, len);
- if (!copy_to_user(user_buff, buf, len))
- *ppos += len;
- bail:
- mutex_unlock(&debug->lock);
- kfree(buf);
- return len;
- }
- static ssize_t dp_debug_read_crc(struct file *file, char __user *user_buff, size_t count,
- loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- int const buf_size = SZ_4K;
- u32 len = 0;
- u16 src_crc[3] = {0};
- u16 sink_crc[3] = {0};
- struct dp_misr40_data misr40 = {0};
- u32 retries = 2;
- struct drm_connector *drm_conn;
- struct sde_connector *sde_conn;
- struct dp_panel *panel;
- int i;
- int rc;
- if (!debug || !debug->aux)
- return -ENODEV;
- if (*ppos)
- return 0;
- buf = kzalloc(buf_size, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
- mutex_lock(&debug->lock);
- if (!debug->panel || !debug->ctrl)
- goto bail;
- if (debug->panel->mst_state) {
- drm_conn = drm_connector_lookup((*debug->connector)->dev, NULL, debug->mst_con_id);
- if (!drm_conn) {
- DP_ERR("connector %u not in mst list\n", debug->mst_con_id);
- goto bail;
- }
- sde_conn = to_sde_connector(drm_conn);
- panel = sde_conn->drv_panel;
- drm_connector_put(drm_conn);
- if (!panel)
- goto bail;
- } else {
- panel = debug->panel;
- }
- if (!panel->pclk_on)
- goto bail;
- panel->get_sink_crc(panel, sink_crc);
- if (!(sink_crc[0] + sink_crc[1] + sink_crc[2])) {
- panel->sink_crc_enable(panel, true);
- mutex_unlock(&debug->lock);
- msleep(30);
- mutex_lock(&debug->lock);
- panel->get_sink_crc(panel, sink_crc);
- }
- panel->get_src_crc(panel, src_crc);
- len += scnprintf(buf + len, buf_size - len, "FRAME_CRC:\nSource vs Sink\n");
- len += scnprintf(buf + len, buf_size - len, "CRC_R: %04X %04X\n", src_crc[0], sink_crc[0]);
- len += scnprintf(buf + len, buf_size - len, "CRC_G: %04X %04X\n", src_crc[1], sink_crc[1]);
- len += scnprintf(buf + len, buf_size - len, "CRC_B: %04X %04X\n", src_crc[2], sink_crc[2]);
- debug->ctrl->setup_misr(debug->ctrl);
- while (retries--) {
- mutex_unlock(&debug->lock);
- msleep(30);
- mutex_lock(&debug->lock);
- rc = debug->ctrl->read_misr(debug->ctrl, &misr40);
- if (rc != -EAGAIN)
- break;
- }
- len += scnprintf(buf + len, buf_size - len, "\nMISR40:\nCTLR vs PHY\n");
- for (i = 0; i < 4; i++) {
- len += scnprintf(buf + len, buf_size - len, "Lane%d %08X%08X %08X%08X\n", i,
- misr40.ctrl_misr[2 * i], misr40.ctrl_misr[(2 * i) + 1],
- misr40.phy_misr[2 * i], misr40.phy_misr[(2 * i) + 1]);
- }
- len = min_t(size_t, count, len);
- if (!copy_to_user(user_buff, buf, len))
- *ppos += len;
- bail:
- mutex_unlock(&debug->lock);
- kfree(buf);
- return len;
- }
- static ssize_t dp_debug_write_hpd(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- int const hpd_data_mask = 0x7;
- int hpd = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &hpd) != 0)
- goto end;
- hpd &= hpd_data_mask;
- debug->hotplug = !!(hpd & BIT(0));
- debug->dp_debug.psm_enabled = !!(hpd & BIT(1));
- /*
- * print hotplug value as this code is executed
- * only while running in debug mode which is manually
- * triggered by a tester or a script.
- */
- DP_INFO("%s\n", debug->hotplug ? "[CONNECT]" : "[DISCONNECT]");
- debug->hpd->simulate_connect(debug->hpd, debug->hotplug);
- end:
- return len;
- }
- static ssize_t dp_debug_write_edid_modes(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- struct dp_panel *panel;
- char buf[SZ_32];
- size_t len = 0;
- int hdisplay = 0, vdisplay = 0, vrefresh = 0, aspect_ratio;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- goto end;
- panel = debug->panel;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto clear;
- buf[len] = '\0';
- if (sscanf(buf, "%d %d %d %d", &hdisplay, &vdisplay, &vrefresh,
- &aspect_ratio) != 4)
- goto clear;
- if (!hdisplay || !vdisplay || !vrefresh)
- goto clear;
- panel->mode_override = true;
- panel->hdisplay = hdisplay;
- panel->vdisplay = vdisplay;
- panel->vrefresh = vrefresh;
- panel->aspect_ratio = aspect_ratio;
- goto end;
- clear:
- DP_DEBUG("clearing debug modes\n");
- panel->mode_override = false;
- end:
- return len;
- }
- static ssize_t dp_debug_write_edid_modes_mst(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- struct drm_connector *connector;
- struct sde_connector *sde_conn;
- struct dp_panel *panel = NULL;
- char buf[SZ_512];
- char *read_buf;
- size_t len = 0;
- int hdisplay = 0, vdisplay = 0, vrefresh = 0, aspect_ratio = 0;
- int con_id = 0, offset = 0, debug_en = 0;
- if (!debug)
- return -ENODEV;
- mutex_lock(&debug->lock);
- if (*ppos)
- goto end;
- len = min_t(size_t, count, SZ_512 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- read_buf = buf;
- while (sscanf(read_buf, "%d %d %d %d %d %d%n", &debug_en, &con_id,
- &hdisplay, &vdisplay, &vrefresh, &aspect_ratio,
- &offset) == 6) {
- connector = drm_connector_lookup((*debug->connector)->dev,
- NULL, con_id);
- if (connector) {
- sde_conn = to_sde_connector(connector);
- panel = sde_conn->drv_panel;
- if (panel && sde_conn->mst_port) {
- panel->mode_override = debug_en;
- panel->hdisplay = hdisplay;
- panel->vdisplay = vdisplay;
- panel->vrefresh = vrefresh;
- panel->aspect_ratio = aspect_ratio;
- } else {
- DP_ERR("connector id %d is not mst\n", con_id);
- }
- drm_connector_put(connector);
- } else {
- DP_ERR("invalid connector id %d\n", con_id);
- }
- read_buf += offset;
- }
- end:
- mutex_unlock(&debug->lock);
- return len;
- }
- static ssize_t dp_debug_write_mst_con_id(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- struct drm_connector *connector;
- struct sde_connector *sde_conn;
- struct drm_dp_mst_port *mst_port;
- struct dp_panel *dp_panel;
- char buf[SZ_32];
- size_t len = 0;
- int con_id = 0, status;
- if (!debug)
- return -ENODEV;
- mutex_lock(&debug->lock);
- if (*ppos)
- goto end;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto clear;
- buf[len] = '\0';
- if (sscanf(buf, "%d %d", &con_id, &status) != 2)
- goto end;
- if (!con_id)
- goto clear;
- connector = drm_connector_lookup((*debug->connector)->dev,
- NULL, con_id);
- if (!connector) {
- DP_ERR("invalid connector id %u\n", con_id);
- goto end;
- }
- sde_conn = to_sde_connector(connector);
- if (!sde_conn->drv_panel || !sde_conn->mst_port) {
- DP_ERR("invalid connector state %d\n", con_id);
- goto out;
- }
- debug->mst_con_id = con_id;
- if (status == connector_status_unknown)
- goto out;
- if (status == connector_status_connected)
- DP_INFO("plug mst connector %d\n", con_id);
- else if (status == connector_status_disconnected)
- DP_INFO("unplug mst connector %d\n", con_id);
- mst_port = sde_conn->mst_port;
- dp_panel = sde_conn->drv_panel;
- if (!dp_panel)
- goto out;
- if (debug->dp_debug.sim_mode)
- dp_sim_update_port_status(debug->sim_bridge, mst_port->port_num, status);
- else
- dp_panel->mst_hide = (status == connector_status_disconnected);
- drm_kms_helper_hotplug_event(connector->dev);
- out:
- drm_connector_put(connector);
- goto end;
- clear:
- DP_DEBUG("clearing mst_con_id\n");
- debug->mst_con_id = 0;
- end:
- mutex_unlock(&debug->lock);
- return len;
- }
- static ssize_t dp_debug_write_mst_con_add(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_32];
- size_t len = 0;
- const int dp_en = BIT(3), hpd_high = BIT(7), hpd_irq = BIT(8);
- int vdo = dp_en | hpd_high | hpd_irq;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- debug->dp_debug.mst_sim_add_con = true;
- debug->hpd->simulate_attention(debug->hpd, vdo);
- end:
- return len;
- }
- static ssize_t dp_debug_write_mst_con_remove(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- struct drm_connector_list_iter conn_iter;
- struct drm_connector *connector;
- char buf[SZ_32];
- size_t len = 0;
- int con_id = 0;
- bool in_list = false;
- const int dp_en = BIT(3), hpd_high = BIT(7), hpd_irq = BIT(8);
- int vdo = dp_en | hpd_high | hpd_irq;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (sscanf(buf, "%d", &con_id) != 1) {
- len = 0;
- goto end;
- }
- if (!con_id)
- goto end;
- drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
- drm_for_each_connector_iter(connector, &conn_iter) {
- if (connector->base.id == con_id) {
- in_list = true;
- break;
- }
- }
- drm_connector_list_iter_end(&conn_iter);
- if (!in_list) {
- DRM_ERROR("invalid connector id %u\n", con_id);
- goto end;
- }
- debug->dp_debug.mst_sim_remove_con = true;
- debug->dp_debug.mst_sim_remove_con_id = con_id;
- debug->hpd->simulate_attention(debug->hpd, vdo);
- end:
- return len;
- }
- static ssize_t dp_debug_mmrm_clk_cb_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- struct dss_clk_mmrm_cb mmrm_cb_data;
- struct mmrm_client_notifier_data notifier_data;
- struct dp_display *dp_display;
- int cb_type;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- dp_display = debug->display;
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- return 0;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &cb_type) != 0)
- return 0;
- if (cb_type != MMRM_CLIENT_RESOURCE_VALUE_CHANGE)
- return 0;
- notifier_data.cb_type = MMRM_CLIENT_RESOURCE_VALUE_CHANGE;
- mmrm_cb_data.phandle = (void *)dp_display;
- notifier_data.pvt_data = (void *)&mmrm_cb_data;
- dp_display_mmrm_callback(¬ifier_data);
- return len;
- }
- static ssize_t dp_debug_bw_code_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- u32 max_bw_code = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- return 0;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &max_bw_code) != 0)
- return 0;
- if (!is_link_rate_valid(max_bw_code)) {
- DP_ERR("Unsupported bw code %d\n", max_bw_code);
- return len;
- }
- debug->panel->max_bw_code = max_bw_code;
- DP_DEBUG("max_bw_code: %d\n", max_bw_code);
- return len;
- }
- static ssize_t dp_debug_mst_mode_read(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[64];
- ssize_t len;
- len = scnprintf(buf, sizeof(buf),
- "mst_mode = %d, mst_state = %d\n",
- debug->parser->has_mst,
- debug->panel->mst_state);
- return simple_read_from_buffer(user_buff, count, ppos, buf, len);
- }
- static ssize_t dp_debug_mst_mode_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- u32 mst_mode = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- return 0;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &mst_mode) != 0)
- return 0;
- debug->parser->has_mst = mst_mode ? true : false;
- DP_DEBUG("mst_enable: %d\n", mst_mode);
- return len;
- }
- static ssize_t dp_debug_max_pclk_khz_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- u32 max_pclk = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- return 0;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &max_pclk) != 0)
- return 0;
- if (max_pclk > debug->parser->max_pclk_khz)
- DP_ERR("requested: %d, max_pclk_khz:%d\n", max_pclk,
- debug->parser->max_pclk_khz);
- else
- debug->dp_debug.max_pclk_khz = max_pclk;
- DP_DEBUG("max_pclk_khz: %d\n", max_pclk);
- return len;
- }
- static ssize_t dp_debug_max_pclk_khz_read(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf))
- return -ENOMEM;
- len += snprintf(buf + len, (SZ_4K - len),
- "max_pclk_khz = %d, org: %d\n",
- debug->dp_debug.max_pclk_khz,
- debug->parser->max_pclk_khz);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- return -EFAULT;
- }
- *ppos += len;
- kfree(buf);
- return len;
- }
- static ssize_t dp_debug_mst_sideband_mode_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- int mst_sideband_mode = 0;
- u32 mst_port_cnt = 0;
- if (!debug)
- return -ENODEV;
- mutex_lock(&debug->lock);
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- return -EFAULT;
- buf[len] = '\0';
- if (sscanf(buf, "%d %u", &mst_sideband_mode, &mst_port_cnt) != 2) {
- DP_ERR("invalid input\n");
- goto bail;
- }
- if (!mst_port_cnt)
- mst_port_cnt = 1;
- debug->mst_edid_idx = 0;
- if (mst_sideband_mode)
- dp_debug_disable_sim_mode(debug, DP_SIM_MODE_MST);
- else
- dp_debug_enable_sim_mode(debug, DP_SIM_MODE_MST);
- dp_sim_update_port_num(debug->sim_bridge, mst_port_cnt);
- buf[0] = !mst_sideband_mode;
- dp_sim_write_dpcd_reg(debug->sim_bridge, buf, 1, DP_MSTM_CAP);
- DP_DEBUG("mst_sideband_mode: %d port_cnt:%d\n",
- mst_sideband_mode, mst_port_cnt);
- bail:
- mutex_unlock(&debug->lock);
- return count;
- }
- static ssize_t dp_debug_tpg_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- u32 tpg_pattern = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto bail;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &tpg_pattern) != 0)
- goto bail;
- DP_DEBUG("tpg_pattern: %d\n", tpg_pattern);
- if (tpg_pattern == debug->dp_debug.tpg_pattern)
- goto bail;
- if (debug->panel)
- debug->panel->tpg_config(debug->panel, tpg_pattern);
- debug->dp_debug.tpg_pattern = tpg_pattern;
- bail:
- return len;
- }
- static ssize_t dp_debug_write_exe_mode(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_32];
- size_t len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (sscanf(buf, "%3s", debug->exe_mode) != 1)
- goto end;
- if (strcmp(debug->exe_mode, "hw") &&
- strcmp(debug->exe_mode, "sw") &&
- strcmp(debug->exe_mode, "all"))
- goto end;
- debug->catalog->set_exe_mode(debug->catalog, debug->exe_mode);
- end:
- return len;
- }
- static ssize_t dp_debug_read_connected(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- u32 len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len += snprintf(buf, SZ_8, "%d\n", debug->hpd->hpd_high);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len))
- return -EFAULT;
- *ppos += len;
- return len;
- }
- static ssize_t dp_debug_write_hdcp(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- int hdcp = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &hdcp) != 0)
- goto end;
- debug->dp_debug.hdcp_disabled = !hdcp;
- end:
- return len;
- }
- static ssize_t dp_debug_read_hdcp(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- u32 len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len = sizeof(debug->dp_debug.hdcp_status);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, debug->dp_debug.hdcp_status, len))
- return -EFAULT;
- *ppos += len;
- return len;
- }
- static int dp_debug_check_buffer_overflow(int rc, int *max_size, int *len)
- {
- if (rc >= *max_size) {
- DP_ERR("buffer overflow\n");
- return -EINVAL;
- }
- *len += rc;
- *max_size = SZ_4K - *len;
- return 0;
- }
- static ssize_t dp_debug_read_edid_modes(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0, ret = 0, max_size = SZ_4K;
- int rc = 0;
- struct drm_connector *connector;
- struct drm_display_mode *mode;
- if (!debug) {
- DP_ERR("invalid data\n");
- rc = -ENODEV;
- goto error;
- }
- connector = *debug->connector;
- if (!connector) {
- DP_ERR("connector is NULL\n");
- rc = -EINVAL;
- goto error;
- }
- if (*ppos)
- goto error;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf)) {
- rc = -ENOMEM;
- goto error;
- }
- mutex_lock(&connector->dev->mode_config.mutex);
- list_for_each_entry(mode, &connector->modes, head) {
- ret = snprintf(buf + len, max_size,
- "%s %d %d %d %d %d 0x%x\n",
- mode->name, drm_mode_vrefresh(mode), mode->picture_aspect_ratio,
- mode->htotal, mode->vtotal, mode->clock, mode->flags);
- if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
- break;
- }
- mutex_unlock(&connector->dev->mode_config.mutex);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- rc = -EFAULT;
- goto error;
- }
- *ppos += len;
- kfree(buf);
- return len;
- error:
- return rc;
- }
- static ssize_t dp_debug_read_edid_modes_mst(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0, ret = 0, max_size = SZ_4K;
- struct drm_connector *connector;
- struct drm_display_mode *mode;
- if (!debug) {
- DP_ERR("invalid data\n");
- return -ENODEV;
- }
- if (*ppos)
- return 0;
- connector = drm_connector_lookup((*debug->connector)->dev,
- NULL, debug->mst_con_id);
- if (!connector) {
- DP_ERR("connector %u not in mst list\n", debug->mst_con_id);
- return 0;
- }
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (!buf)
- goto clean;
- mutex_lock(&connector->dev->mode_config.mutex);
- list_for_each_entry(mode, &connector->modes, head) {
- ret = snprintf(buf + len, max_size,
- "%s %d %d %d %d %d 0x%x\n",
- mode->name, drm_mode_vrefresh(mode),
- mode->picture_aspect_ratio, mode->htotal,
- mode->vtotal, mode->clock, mode->flags);
- if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
- break;
- }
- mutex_unlock(&connector->dev->mode_config.mutex);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- len = -EFAULT;
- goto clean;
- }
- *ppos += len;
- clean:
- kfree(buf);
- drm_connector_put(connector);
- return len;
- }
- static ssize_t dp_debug_read_mst_con_id(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0, ret = 0, max_size = SZ_4K;
- int rc = 0;
- if (!debug) {
- DP_ERR("invalid data\n");
- rc = -ENODEV;
- goto error;
- }
- if (*ppos)
- goto error;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (!buf) {
- rc = -ENOMEM;
- goto error;
- }
- ret = snprintf(buf, max_size, "%u\n", debug->mst_con_id);
- len += ret;
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- rc = -EFAULT;
- goto error;
- }
- *ppos += len;
- kfree(buf);
- return len;
- error:
- return rc;
- }
- static ssize_t dp_debug_read_mst_conn_info(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- struct drm_connector_list_iter conn_iter;
- struct drm_connector *connector;
- struct sde_connector *sde_conn;
- struct dp_display *display;
- char *buf;
- u32 len = 0, ret = 0, max_size = SZ_4K;
- int rc = 0;
- if (!debug) {
- DP_ERR("invalid data\n");
- rc = -ENODEV;
- goto error;
- }
- if (*ppos)
- goto error;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (!buf) {
- rc = -ENOMEM;
- goto error;
- }
- drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
- drm_for_each_connector_iter(connector, &conn_iter) {
- sde_conn = to_sde_connector(connector);
- display = sde_conn->display;
- if (!sde_conn->mst_port ||
- display->base_connector != (*debug->connector))
- continue;
- ret = scnprintf(buf + len, max_size,
- "conn name:%s, conn id:%d state:%d\n",
- connector->name, connector->base.id,
- connector->status);
- if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
- break;
- }
- drm_connector_list_iter_end(&conn_iter);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- rc = -EFAULT;
- goto error;
- }
- *ppos += len;
- kfree(buf);
- return len;
- error:
- return rc;
- }
- static ssize_t dp_debug_read_info(struct file *file, char __user *user_buff,
- size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0, rc = 0;
- u32 max_size = SZ_4K;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf))
- return -ENOMEM;
- rc = snprintf(buf + len, max_size, "\tstate=0x%x\n", debug->aux->state);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\tlink_rate=%u\n",
- debug->panel->link_info.rate);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\tnum_lanes=%u\n",
- debug->panel->link_info.num_lanes);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\tresolution=%dx%d@%dHz\n",
- debug->panel->pinfo.h_active,
- debug->panel->pinfo.v_active,
- debug->panel->pinfo.refresh_rate);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\tpclock=%dKHz\n",
- debug->panel->pinfo.pixel_clk_khz);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\tbpp=%d\n",
- debug->panel->pinfo.bpp);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- /* Link Information */
- rc = snprintf(buf + len, max_size, "\ttest_req=%s\n",
- dp_link_get_test_name(debug->link->sink_request));
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size,
- "\tlane_count=%d\n", debug->link->link_params.lane_count);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size,
- "\tbw_code=%d\n", debug->link->link_params.bw_code);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size,
- "\tv_level=%d\n", debug->link->phy_params.v_level);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size,
- "\tp_level=%d\n", debug->link->phy_params.p_level);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len))
- goto error;
- *ppos += len;
- kfree(buf);
- return len;
- error:
- kfree(buf);
- return -EINVAL;
- }
- static ssize_t dp_debug_bw_code_read(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf))
- return -ENOMEM;
- len += snprintf(buf + len, (SZ_4K - len),
- "max_bw_code = %d\n", debug->panel->max_bw_code);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- return -EFAULT;
- }
- *ppos += len;
- kfree(buf);
- return len;
- }
- static ssize_t dp_debug_tpg_read(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- u32 len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len += scnprintf(buf, SZ_8, "%d\n", debug->dp_debug.tpg_pattern);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len))
- return -EFAULT;
- *ppos += len;
- return len;
- }
- static int dp_debug_print_hdr_params_to_buf(struct drm_connector *connector,
- char *buf, u32 size)
- {
- int rc;
- u32 i, len = 0, max_size = size;
- struct sde_connector *c_conn;
- struct sde_connector_state *c_state;
- struct drm_msm_ext_hdr_metadata *hdr;
- c_conn = to_sde_connector(connector);
- c_state = to_sde_connector_state(connector->state);
- hdr = &c_state->hdr_meta;
- rc = snprintf(buf + len, max_size,
- "============SINK HDR PARAMETERS===========\n");
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "eotf = %d\n",
- c_conn->hdr_eotf);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "type_one = %d\n",
- c_conn->hdr_metadata_type_one);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "hdr_plus_app_ver = %d\n",
- c_conn->hdr_plus_app_ver);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "max_luminance = %d\n",
- c_conn->hdr_max_luminance);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "avg_luminance = %d\n",
- c_conn->hdr_avg_luminance);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "min_luminance = %d\n",
- c_conn->hdr_min_luminance);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size,
- "============VIDEO HDR PARAMETERS===========\n");
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "hdr_state = %d\n", hdr->hdr_state);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "hdr_supported = %d\n",
- hdr->hdr_supported);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "eotf = %d\n", hdr->eotf);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "white_point_x = %d\n",
- hdr->white_point_x);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "white_point_y = %d\n",
- hdr->white_point_y);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "max_luminance = %d\n",
- hdr->max_luminance);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "min_luminance = %d\n",
- hdr->min_luminance);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "max_content_light_level = %d\n",
- hdr->max_content_light_level);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "min_content_light_level = %d\n",
- hdr->max_average_light_level);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- for (i = 0; i < HDR_PRIMARIES_COUNT; i++) {
- rc = snprintf(buf + len, max_size, "primaries_x[%d] = %d\n",
- i, hdr->display_primaries_x[i]);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "primaries_y[%d] = %d\n",
- i, hdr->display_primaries_y[i]);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- }
- if (hdr->hdr_plus_payload && hdr->hdr_plus_payload_size) {
- u32 rowsize = 16, rem;
- struct sde_connector_dyn_hdr_metadata *dhdr =
- &c_state->dyn_hdr_meta;
- /**
- * Do not use user pointer from hdr->hdr_plus_payload directly,
- * instead use kernel's cached copy of payload data.
- */
- for (i = 0; i < dhdr->dynamic_hdr_payload_size; i += rowsize) {
- rc = snprintf(buf + len, max_size, "DHDR: ");
- if (dp_debug_check_buffer_overflow(rc, &max_size,
- &len))
- goto error;
- rem = dhdr->dynamic_hdr_payload_size - i;
- rc = hex_dump_to_buffer(&dhdr->dynamic_hdr_payload[i],
- min(rowsize, rem), rowsize, 1, buf + len,
- max_size, false);
- if (dp_debug_check_buffer_overflow(rc, &max_size,
- &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\n");
- if (dp_debug_check_buffer_overflow(rc, &max_size,
- &len))
- goto error;
- }
- }
- return len;
- error:
- return -EOVERFLOW;
- }
- static ssize_t dp_debug_read_hdr(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf = NULL;
- u32 len = 0;
- u32 max_size = SZ_4K;
- struct drm_connector *connector;
- if (!debug) {
- DP_ERR("invalid data\n");
- return -ENODEV;
- }
- connector = *debug->connector;
- if (!connector) {
- DP_ERR("connector is NULL\n");
- return -EINVAL;
- }
- if (*ppos)
- return 0;
- buf = kzalloc(max_size, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf))
- return -ENOMEM;
- len = dp_debug_print_hdr_params_to_buf(connector, buf, max_size);
- if (len == -EOVERFLOW) {
- kfree(buf);
- return len;
- }
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- return -EFAULT;
- }
- *ppos += len;
- kfree(buf);
- return len;
- }
- static ssize_t dp_debug_read_hdr_mst(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf = NULL;
- u32 len = 0, max_size = SZ_4K;
- struct drm_connector_list_iter conn_iter;
- struct drm_connector *connector;
- bool in_list = false;
- if (!debug) {
- DP_ERR("invalid data\n");
- return -ENODEV;
- }
- drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
- drm_for_each_connector_iter(connector, &conn_iter) {
- if (connector->base.id == debug->mst_con_id) {
- in_list = true;
- break;
- }
- }
- drm_connector_list_iter_end(&conn_iter);
- if (!in_list) {
- DP_ERR("connector %u not in mst list\n", debug->mst_con_id);
- return -EINVAL;
- }
- if (!connector) {
- DP_ERR("connector is NULL\n");
- return -EINVAL;
- }
- if (*ppos)
- return 0;
- buf = kzalloc(max_size, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf))
- return -ENOMEM;
- len = dp_debug_print_hdr_params_to_buf(connector, buf, max_size);
- if (len == -EOVERFLOW) {
- kfree(buf);
- return len;
- }
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- return -EFAULT;
- }
- *ppos += len;
- kfree(buf);
- return len;
- }
- static void dp_debug_set_sim_mode(struct dp_debug_private *debug, bool sim)
- {
- struct drm_connector_list_iter conn_iter;
- struct drm_connector *connector;
- struct sde_connector *sde_conn;
- struct dp_display *display;
- struct dp_panel *panel;
- if (sim) {
- debug->dp_debug.sim_mode = true;
- dp_debug_enable_sim_mode(debug, DP_SIM_MODE_ALL);
- } else {
- if (debug->hotplug) {
- DP_WARN("sim mode off before hotplug disconnect\n");
- debug->hpd->simulate_connect(debug->hpd, false);
- debug->hotplug = false;
- }
- debug->aux->abort(debug->aux, true);
- debug->ctrl->abort(debug->ctrl, true);
- debug->dp_debug.sim_mode = false;
- debug->mst_edid_idx = 0;
- dp_debug_disable_sim_mode(debug, DP_SIM_MODE_ALL);
- }
- /* clear override settings in panel */
- drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
- drm_for_each_connector_iter(connector, &conn_iter) {
- sde_conn = to_sde_connector(connector);
- display = sde_conn->display;
- if (display->base_connector == (*debug->connector)) {
- panel = sde_conn->drv_panel;
- if (panel) {
- panel->mode_override = false;
- panel->mst_hide = false;
- }
- }
- }
- drm_connector_list_iter_end(&conn_iter);
- /*
- * print simulation status as this code is executed
- * only while running in debug mode which is manually
- * triggered by a tester or a script.
- */
- DP_INFO("%s\n", sim ? "[ON]" : "[OFF]");
- }
- static ssize_t dp_debug_write_sim(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- int sim;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- mutex_lock(&debug->lock);
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &sim) != 0)
- goto end;
- dp_debug_set_sim_mode(debug, sim);
- end:
- mutex_unlock(&debug->lock);
- return len;
- }
- static ssize_t dp_debug_write_attention(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- int vdo;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &vdo) != 0)
- goto end;
- debug->hpd->simulate_attention(debug->hpd, vdo);
- end:
- return len;
- }
- static ssize_t dp_debug_write_dump(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_32];
- size_t len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (sscanf(buf, "%31s", debug->reg_dump) != 1)
- goto end;
- /* qfprom register dump not supported */
- if (!strcmp(debug->reg_dump, "qfprom_physical"))
- strlcpy(debug->reg_dump, "clear", sizeof(debug->reg_dump));
- end:
- return len;
- }
- static ssize_t dp_debug_read_dump(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- int rc = 0;
- struct dp_debug_private *debug = file->private_data;
- u8 *buf = NULL;
- u32 len = 0;
- char prefix[SZ_32];
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- if (!debug->hpd->hpd_high || !strlen(debug->reg_dump))
- goto end;
- rc = debug->catalog->get_reg_dump(debug->catalog,
- debug->reg_dump, &buf, &len);
- if (rc)
- goto end;
- snprintf(prefix, sizeof(prefix), "%s: ", debug->reg_dump);
- print_hex_dump_debug(prefix, DUMP_PREFIX_NONE,
- 16, 4, buf, len, false);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len))
- return -EFAULT;
- *ppos += len;
- end:
- return len;
- }
- static const struct file_operations dp_debug_fops = {
- .open = simple_open,
- .read = dp_debug_read_info,
- };
- static const struct file_operations edid_modes_fops = {
- .open = simple_open,
- .read = dp_debug_read_edid_modes,
- .write = dp_debug_write_edid_modes,
- };
- static const struct file_operations edid_modes_mst_fops = {
- .open = simple_open,
- .read = dp_debug_read_edid_modes_mst,
- .write = dp_debug_write_edid_modes_mst,
- };
- static const struct file_operations mst_conn_info_fops = {
- .open = simple_open,
- .read = dp_debug_read_mst_conn_info,
- };
- static const struct file_operations mst_con_id_fops = {
- .open = simple_open,
- .read = dp_debug_read_mst_con_id,
- .write = dp_debug_write_mst_con_id,
- };
- static const struct file_operations mst_con_add_fops = {
- .open = simple_open,
- .write = dp_debug_write_mst_con_add,
- };
- static const struct file_operations mst_con_remove_fops = {
- .open = simple_open,
- .write = dp_debug_write_mst_con_remove,
- };
- static const struct file_operations hpd_fops = {
- .open = simple_open,
- .write = dp_debug_write_hpd,
- };
- static const struct file_operations edid_fops = {
- .open = simple_open,
- .write = dp_debug_write_edid,
- };
- static const struct file_operations dpcd_fops = {
- .open = simple_open,
- .write = dp_debug_write_dpcd,
- .read = dp_debug_read_dpcd,
- };
- static const struct file_operations crc_fops = {
- .open = simple_open,
- .read = dp_debug_read_crc,
- };
- static const struct file_operations connected_fops = {
- .open = simple_open,
- .read = dp_debug_read_connected,
- };
- static const struct file_operations bw_code_fops = {
- .open = simple_open,
- .read = dp_debug_bw_code_read,
- .write = dp_debug_bw_code_write,
- };
- static const struct file_operations exe_mode_fops = {
- .open = simple_open,
- .write = dp_debug_write_exe_mode,
- };
- static const struct file_operations tpg_fops = {
- .open = simple_open,
- .read = dp_debug_tpg_read,
- .write = dp_debug_tpg_write,
- };
- static const struct file_operations hdr_fops = {
- .open = simple_open,
- .read = dp_debug_read_hdr,
- };
- static const struct file_operations hdr_mst_fops = {
- .open = simple_open,
- .read = dp_debug_read_hdr_mst,
- };
- static const struct file_operations sim_fops = {
- .open = simple_open,
- .write = dp_debug_write_sim,
- };
- static const struct file_operations attention_fops = {
- .open = simple_open,
- .write = dp_debug_write_attention,
- };
- static const struct file_operations dump_fops = {
- .open = simple_open,
- .write = dp_debug_write_dump,
- .read = dp_debug_read_dump,
- };
- static const struct file_operations mst_mode_fops = {
- .open = simple_open,
- .write = dp_debug_mst_mode_write,
- .read = dp_debug_mst_mode_read,
- };
- static const struct file_operations mst_sideband_mode_fops = {
- .open = simple_open,
- .write = dp_debug_mst_sideband_mode_write,
- };
- static const struct file_operations max_pclk_khz_fops = {
- .open = simple_open,
- .write = dp_debug_max_pclk_khz_write,
- .read = dp_debug_max_pclk_khz_read,
- };
- static const struct file_operations hdcp_fops = {
- .open = simple_open,
- .write = dp_debug_write_hdcp,
- .read = dp_debug_read_hdcp,
- };
- static const struct file_operations mmrm_clk_cb_fops = {
- .open = simple_open,
- .write = dp_debug_mmrm_clk_cb_write,
- };
- static int dp_debug_init_mst(struct dp_debug_private *debug, struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("mst_con_id", 0644, dir,
- debug, &mst_con_id_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs create mst_con_id failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("mst_con_info", 0644, dir,
- debug, &mst_conn_info_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs create mst_conn_info failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("mst_con_add", 0644, dir,
- debug, &mst_con_add_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DRM_ERROR("[%s] debugfs create mst_con_add failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("mst_con_remove", 0644, dir,
- debug, &mst_con_remove_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DRM_ERROR("[%s] debugfs create mst_con_remove failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("mst_mode", 0644, dir,
- debug, &mst_mode_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs mst_mode failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("mst_sideband_mode", 0644, dir,
- debug, &mst_sideband_mode_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs mst_sideband_mode failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- debugfs_create_u32("mst_edid_idx", 0644, dir, &debug->mst_edid_idx);
- return rc;
- }
- static int dp_debug_init_link(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("max_bw_code", 0644, dir,
- debug, &bw_code_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs max_bw_code failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("max_pclk_khz", 0644, dir,
- debug, &max_pclk_khz_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs max_pclk_khz failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- debugfs_create_u32("max_lclk_khz", 0644, dir, &debug->parser->max_lclk_khz);
- debugfs_create_u32("lane_count", 0644, dir, &debug->panel->lane_count);
- debugfs_create_u32("link_bw_code", 0644, dir, &debug->panel->link_bw_code);
- debugfs_create_u32("max_bpp", 0644, dir, &debug->panel->max_supported_bpp);
- file = debugfs_create_file("mmrm_clk_cb", 0644, dir, debug, &mmrm_clk_cb_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs mmrm_clk_cb failed, rc=%d\n", DEBUG_NAME, rc);
- return rc;
- }
- return rc;
- }
- static int dp_debug_init_hdcp(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- debugfs_create_bool("hdcp_wait_sink_sync", 0644, dir, &debug->dp_debug.hdcp_wait_sink_sync);
- debugfs_create_bool("force_encryption", 0644, dir, &debug->dp_debug.force_encryption);
- return rc;
- }
- static int dp_debug_init_sink_caps(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("edid_modes", 0644, dir,
- debug, &edid_modes_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs create edid_modes failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("edid_modes_mst", 0644, dir,
- debug, &edid_modes_mst_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs create edid_modes_mst failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("edid", 0644, dir,
- debug, &edid_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs edid failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("dpcd", 0644, dir,
- debug, &dpcd_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs dpcd failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("crc", 0644, dir, debug, &crc_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs crc failed, rc=%d\n", DEBUG_NAME, rc);
- return rc;
- }
- return rc;
- }
- static int dp_debug_init_status(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("dp_debug", 0444, dir,
- debug, &dp_debug_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs create file failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("connected", 0444, dir,
- debug, &connected_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs connected failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("hdr", 0400, dir, debug, &hdr_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs hdr failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("hdr_mst", 0400, dir, debug, &hdr_mst_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs hdr_mst failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("hdcp", 0644, dir, debug, &hdcp_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs hdcp failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- return rc;
- }
- static int dp_debug_init_sim(struct dp_debug_private *debug, struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("hpd", 0644, dir, debug, &hpd_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs hpd failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("sim", 0644, dir, debug, &sim_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs sim failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("attention", 0644, dir,
- debug, &attention_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs attention failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- debugfs_create_bool("skip_uevent", 0644, dir, &debug->dp_debug.skip_uevent);
- debugfs_create_bool("force_multi_func", 0644, dir, &debug->hpd->force_multi_func);
- return rc;
- }
- static int dp_debug_init_dsc_fec(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- debugfs_create_bool("dsc_feature_enable", 0644, dir, &debug->parser->dsc_feature_enable);
- debugfs_create_bool("fec_feature_enable", 0644, dir, &debug->parser->fec_feature_enable);
- return rc;
- }
- static int dp_debug_init_tpg(struct dp_debug_private *debug, struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("tpg_ctrl", 0644, dir,
- debug, &tpg_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs tpg failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- return rc;
- }
- static int dp_debug_init_reg_dump(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("exe_mode", 0644, dir,
- debug, &exe_mode_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs register failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("dump", 0644, dir,
- debug, &dump_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs dump failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- return rc;
- }
- static int dp_debug_init_feature_toggle(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- debugfs_create_bool("ssc_enable", 0644, dir, &debug->pll->ssc_en);
- debugfs_create_bool("widebus_mode", 0644, dir, &debug->parser->has_widebus);
- return rc;
- }
- static int dp_debug_init_configs(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- debugfs_create_ulong("connect_notification_delay_ms", 0644, dir,
- &debug->dp_debug.connect_notification_delay_ms);
- debug->dp_debug.connect_notification_delay_ms =
- DEFAULT_CONNECT_NOTIFICATION_DELAY_MS;
- debugfs_create_u32("disconnect_delay_ms", 0644, dir, &debug->dp_debug.disconnect_delay_ms);
- debug->dp_debug.disconnect_delay_ms = DEFAULT_DISCONNECT_DELAY_MS;
- return rc;
- }
- static int dp_debug_init(struct dp_debug *dp_debug)
- {
- int rc = 0;
- struct dp_debug_private *debug = container_of(dp_debug,
- struct dp_debug_private, dp_debug);
- struct dentry *dir;
- if (!IS_ENABLED(CONFIG_DEBUG_FS)) {
- DP_WARN("Not creating debug root dir.");
- debug->root = NULL;
- return 0;
- }
- dir = debugfs_create_dir(DEBUG_NAME, NULL);
- if (IS_ERR_OR_NULL(dir)) {
- if (!dir)
- rc = -EINVAL;
- else
- rc = PTR_ERR(dir);
- DP_ERR("[%s] debugfs create dir failed, rc = %d\n",
- DEBUG_NAME, rc);
- goto error;
- }
- debug->root = dir;
- rc = dp_debug_init_status(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_sink_caps(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_mst(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_link(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_hdcp(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_sim(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_dsc_fec(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_tpg(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_reg_dump(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_feature_toggle(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_configs(debug, dir);
- if (rc)
- goto error_remove_dir;
- return 0;
- error_remove_dir:
- debugfs_remove_recursive(dir);
- error:
- return rc;
- }
- static void dp_debug_abort(struct dp_debug *dp_debug)
- {
- struct dp_debug_private *debug;
- if (!dp_debug)
- return;
- debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
- mutex_lock(&debug->lock);
- // disconnect has already been handled. so clear hotplug
- debug->hotplug = false;
- dp_debug_set_sim_mode(debug, false);
- mutex_unlock(&debug->lock);
- }
- static void dp_debug_set_mst_con(struct dp_debug *dp_debug, int con_id)
- {
- struct dp_debug_private *debug;
- if (!dp_debug)
- return;
- debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
- mutex_lock(&debug->lock);
- debug->mst_con_id = con_id;
- mutex_unlock(&debug->lock);
- DP_INFO("Selecting mst connector %d\n", con_id);
- }
- struct dp_debug *dp_debug_get(struct dp_debug_in *in)
- {
- int rc = 0;
- struct dp_debug_private *debug;
- struct dp_debug *dp_debug;
- if (!in->dev || !in->panel || !in->hpd || !in->link ||
- !in->catalog || !in->ctrl || !in->pll) {
- DP_ERR("invalid input\n");
- rc = -EINVAL;
- goto error;
- }
- debug = devm_kzalloc(in->dev, sizeof(*debug), GFP_KERNEL);
- if (!debug) {
- rc = -ENOMEM;
- goto error;
- }
- debug->hpd = in->hpd;
- debug->link = in->link;
- debug->panel = in->panel;
- debug->aux = in->aux;
- debug->dev = in->dev;
- debug->connector = in->connector;
- debug->catalog = in->catalog;
- debug->parser = in->parser;
- debug->ctrl = in->ctrl;
- debug->pll = in->pll;
- debug->display = in->display;
- dp_debug = &debug->dp_debug;
- mutex_init(&debug->lock);
- rc = dp_debug_init(dp_debug);
- if (rc) {
- devm_kfree(in->dev, debug);
- goto error;
- }
- debug->aux->access_lock = &debug->lock;
- dp_debug->abort = dp_debug_abort;
- dp_debug->set_mst_con = dp_debug_set_mst_con;
- dp_debug->max_pclk_khz = debug->parser->max_pclk_khz;
- return dp_debug;
- error:
- return ERR_PTR(rc);
- }
- static int dp_debug_deinit(struct dp_debug *dp_debug)
- {
- struct dp_debug_private *debug;
- if (!dp_debug)
- return -EINVAL;
- debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
- debugfs_remove_recursive(debug->root);
- if (debug->sim_bridge)
- dp_sim_destroy_bridge(debug->sim_bridge);
- return 0;
- }
- void dp_debug_put(struct dp_debug *dp_debug)
- {
- struct dp_debug_private *debug;
- if (!dp_debug)
- return;
- debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
- dp_debug_deinit(dp_debug);
- mutex_destroy(&debug->lock);
- devm_kfree(debug->dev, debug);
- }
|